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