ukyopon.c revision 1.1.4.2 1 1.1.4.2 kent /* $NetBSD: ukyopon.c,v 1.1.4.2 2005/04/29 11:29:18 kent Exp $ */
2 1.1.4.2 kent
3 1.1.4.2 kent /*
4 1.1.4.2 kent * Copyright (c) 1998, 2005 The NetBSD Foundation, Inc.
5 1.1.4.2 kent * All rights reserved.
6 1.1.4.2 kent *
7 1.1.4.2 kent * This code is derived from software contributed to The NetBSD Foundation
8 1.1.4.2 kent * by Lennart Augustsson (lennart (at) augustsson.net) at
9 1.1.4.2 kent * Carlstedt Research & Technology.
10 1.1.4.2 kent *
11 1.1.4.2 kent * This code is derived from software contributed to The NetBSD Foundation
12 1.1.4.2 kent * by ITOH Yasufumi.
13 1.1.4.2 kent *
14 1.1.4.2 kent * Redistribution and use in source and binary forms, with or without
15 1.1.4.2 kent * modification, are permitted provided that the following conditions
16 1.1.4.2 kent * are met:
17 1.1.4.2 kent * 1. Redistributions of source code must retain the above copyright
18 1.1.4.2 kent * notice, this list of conditions and the following disclaimer.
19 1.1.4.2 kent * 2. Redistributions in binary form must reproduce the above copyright
20 1.1.4.2 kent * notice, this list of conditions and the following disclaimer in the
21 1.1.4.2 kent * documentation and/or other materials provided with the distribution.
22 1.1.4.2 kent * 3. All advertising materials mentioning features or use of this software
23 1.1.4.2 kent * must display the following acknowledgement:
24 1.1.4.2 kent * This product includes software developed by the NetBSD
25 1.1.4.2 kent * Foundation, Inc. and its contributors.
26 1.1.4.2 kent * 4. Neither the name of The NetBSD Foundation nor the names of its
27 1.1.4.2 kent * contributors may be used to endorse or promote products derived
28 1.1.4.2 kent * from this software without specific prior written permission.
29 1.1.4.2 kent *
30 1.1.4.2 kent * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31 1.1.4.2 kent * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 1.1.4.2 kent * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 1.1.4.2 kent * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34 1.1.4.2 kent * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 1.1.4.2 kent * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 1.1.4.2 kent * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 1.1.4.2 kent * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 1.1.4.2 kent * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 1.1.4.2 kent * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 1.1.4.2 kent * POSSIBILITY OF SUCH DAMAGE.
41 1.1.4.2 kent */
42 1.1.4.2 kent
43 1.1.4.2 kent #include <sys/cdefs.h>
44 1.1.4.2 kent __KERNEL_RCSID(0, "$NetBSD: ukyopon.c,v 1.1.4.2 2005/04/29 11:29:18 kent Exp $");
45 1.1.4.2 kent
46 1.1.4.2 kent #include <sys/param.h>
47 1.1.4.2 kent #include <sys/systm.h>
48 1.1.4.2 kent #include <sys/kernel.h>
49 1.1.4.2 kent #include <sys/ioctl.h>
50 1.1.4.2 kent #include <sys/conf.h>
51 1.1.4.2 kent #include <sys/tty.h>
52 1.1.4.2 kent #include <sys/file.h>
53 1.1.4.2 kent #include <sys/select.h>
54 1.1.4.2 kent #include <sys/proc.h>
55 1.1.4.2 kent #include <sys/vnode.h>
56 1.1.4.2 kent #include <sys/device.h>
57 1.1.4.2 kent #include <sys/poll.h>
58 1.1.4.2 kent
59 1.1.4.2 kent #include <machine/bus.h>
60 1.1.4.2 kent
61 1.1.4.2 kent #include <dev/usb/usb.h>
62 1.1.4.2 kent #include <dev/usb/usbcdc.h>
63 1.1.4.2 kent
64 1.1.4.2 kent #include <dev/usb/usbdi.h>
65 1.1.4.2 kent #include <dev/usb/usbdi_util.h>
66 1.1.4.2 kent #include <dev/usb/usbdivar.h>
67 1.1.4.2 kent #include <dev/usb/usbdevs.h>
68 1.1.4.2 kent #include <dev/usb/usb_quirks.h>
69 1.1.4.2 kent
70 1.1.4.2 kent #include <dev/usb/usbdevs.h>
71 1.1.4.2 kent #include <dev/usb/ucomvar.h>
72 1.1.4.2 kent #include <dev/usb/umodemvar.h>
73 1.1.4.2 kent #include <dev/usb/ukyopon.h>
74 1.1.4.2 kent
75 1.1.4.2 kent #ifdef UKYOPON_DEBUG
76 1.1.4.2 kent #define DPRINTFN(n, x) if (ukyopondebug > (n)) logprintf x
77 1.1.4.2 kent int ukyopondebug = 0;
78 1.1.4.2 kent #else
79 1.1.4.2 kent #define DPRINTFN(n, x)
80 1.1.4.2 kent #endif
81 1.1.4.2 kent #define DPRINTF(x) DPRINTFN(0, x)
82 1.1.4.2 kent
83 1.1.4.2 kent struct ukyopon_softc {
84 1.1.4.2 kent /* generic umodem device */
85 1.1.4.2 kent struct umodem_softc sc_umodem;
86 1.1.4.2 kent
87 1.1.4.2 kent /* ukyopon addition */
88 1.1.4.2 kent enum ukyopon_port sc_porttype;
89 1.1.4.2 kent };
90 1.1.4.2 kent
91 1.1.4.2 kent #define UKYOPON_MODEM_IFACE_INDEX 0
92 1.1.4.2 kent #define UKYOPON_DATA_IFACE_INDEX 3
93 1.1.4.2 kent
94 1.1.4.2 kent Static int ukyopon_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr);
95 1.1.4.2 kent
96 1.1.4.2 kent Static struct ucom_methods ukyopon_methods = {
97 1.1.4.2 kent umodem_get_status,
98 1.1.4.2 kent umodem_set,
99 1.1.4.2 kent umodem_param,
100 1.1.4.2 kent ukyopon_ioctl,
101 1.1.4.2 kent umodem_open,
102 1.1.4.2 kent umodem_close,
103 1.1.4.2 kent NULL,
104 1.1.4.2 kent NULL,
105 1.1.4.2 kent };
106 1.1.4.2 kent
107 1.1.4.2 kent USB_DECLARE_DRIVER(ukyopon);
108 1.1.4.2 kent
109 1.1.4.2 kent USB_MATCH(ukyopon)
110 1.1.4.2 kent {
111 1.1.4.2 kent USB_MATCH_START(ukyopon, uaa);
112 1.1.4.2 kent usb_device_descriptor_t *dd;
113 1.1.4.2 kent usb_interface_descriptor_t *id;
114 1.1.4.2 kent
115 1.1.4.2 kent if (uaa->iface == NULL)
116 1.1.4.2 kent return (UMATCH_NONE);
117 1.1.4.2 kent
118 1.1.4.2 kent id = usbd_get_interface_descriptor(uaa->iface);
119 1.1.4.2 kent dd = usbd_get_device_descriptor(uaa->device);
120 1.1.4.2 kent if (id == NULL || dd == NULL)
121 1.1.4.2 kent return (UMATCH_NONE);
122 1.1.4.2 kent
123 1.1.4.2 kent if (UGETW(dd->idVendor) == USB_VENDOR_KYOCERA &&
124 1.1.4.2 kent UGETW(dd->idProduct) == USB_PRODUCT_KYOCERA_AHK3001V &&
125 1.1.4.2 kent (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX ||
126 1.1.4.2 kent uaa->ifaceno == UKYOPON_DATA_IFACE_INDEX))
127 1.1.4.2 kent return (UMATCH_VENDOR_PRODUCT);
128 1.1.4.2 kent
129 1.1.4.2 kent return (UMATCH_NONE);
130 1.1.4.2 kent }
131 1.1.4.2 kent
132 1.1.4.2 kent USB_ATTACH(ukyopon)
133 1.1.4.2 kent {
134 1.1.4.2 kent USB_ATTACH_START(ukyopon, sc, uaa);
135 1.1.4.2 kent struct ucom_attach_args uca;
136 1.1.4.2 kent
137 1.1.4.2 kent sc->sc_porttype = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
138 1.1.4.2 kent UKYOPON_PORT_MODEM : UKYOPON_PORT_DATA;
139 1.1.4.2 kent
140 1.1.4.2 kent uca.portno = UCOM_UNK_PORTNO;
141 1.1.4.2 kent uca.methods = &ukyopon_methods;
142 1.1.4.2 kent uca.info = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
143 1.1.4.2 kent "modem port" : "data transfer port";
144 1.1.4.2 kent
145 1.1.4.2 kent if (umodem_common_attach(self, &sc->sc_umodem, uaa, &uca))
146 1.1.4.2 kent USB_ATTACH_ERROR_RETURN;
147 1.1.4.2 kent USB_ATTACH_SUCCESS_RETURN;
148 1.1.4.2 kent }
149 1.1.4.2 kent
150 1.1.4.2 kent Static int
151 1.1.4.2 kent ukyopon_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
152 1.1.4.2 kent usb_proc_ptr p)
153 1.1.4.2 kent {
154 1.1.4.2 kent struct ukyopon_softc *sc = addr;
155 1.1.4.2 kent struct ukyopon_identify *arg_id = (void*)data;
156 1.1.4.2 kent int error = 0;
157 1.1.4.2 kent
158 1.1.4.2 kent switch (cmd) {
159 1.1.4.2 kent case UKYOPON_IDENTIFY:
160 1.1.4.2 kent strncpy(arg_id->ui_name, UKYOPON_NAME, sizeof arg_id->ui_name);
161 1.1.4.2 kent arg_id->ui_busno =
162 1.1.4.2 kent USBDEVUNIT(*(device_ptr_t)sc->sc_umodem.sc_udev->bus->usbctl);
163 1.1.4.2 kent arg_id->ui_address = sc->sc_umodem.sc_udev->address;
164 1.1.4.2 kent arg_id->ui_model = UKYOPON_MODEL_UNKNOWN;
165 1.1.4.2 kent arg_id->ui_porttype = sc->sc_porttype;
166 1.1.4.2 kent break;
167 1.1.4.2 kent
168 1.1.4.2 kent default:
169 1.1.4.2 kent error = umodem_ioctl(addr, portno, cmd, data, flag, p);
170 1.1.4.2 kent break;
171 1.1.4.2 kent }
172 1.1.4.2 kent
173 1.1.4.2 kent return (error);
174 1.1.4.2 kent }
175 1.1.4.2 kent
176 1.1.4.2 kent #ifdef __strong_alias
177 1.1.4.2 kent __strong_alias(ukyopon_activate,umodem_common_activate)
178 1.1.4.2 kent #else
179 1.1.4.2 kent int
180 1.1.4.2 kent ukyopon_activate(device_ptr_t self, enum devact act)
181 1.1.4.2 kent {
182 1.1.4.2 kent struct ukyopon_softc *sc = (struct ukyopon_softc *)self;
183 1.1.4.2 kent
184 1.1.4.2 kent return umodem_common_activate(&sc->sc_umodem, act);
185 1.1.4.2 kent }
186 1.1.4.2 kent #endif
187 1.1.4.2 kent
188 1.1.4.2 kent USB_DETACH(ukyopon)
189 1.1.4.2 kent {
190 1.1.4.2 kent USB_DETACH_START(ukyopon, sc);
191 1.1.4.2 kent #ifdef __FreeBSD__
192 1.1.4.2 kent int flags = 0;
193 1.1.4.2 kent #endif
194 1.1.4.2 kent
195 1.1.4.2 kent return umodem_common_detach(&sc->sc_umodem, flags);
196 1.1.4.2 kent }
197