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