ukyopon.c revision 1.10 1 1.10 cube /* $NetBSD: ukyopon.c,v 1.10 2008/05/24 16:40:58 cube 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 *
23 1.1 itohy * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1 itohy * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1 itohy * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1 itohy * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1 itohy * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1 itohy * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1 itohy * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 itohy * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1 itohy * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1 itohy * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 itohy * POSSIBILITY OF SUCH DAMAGE.
34 1.1 itohy */
35 1.1 itohy
36 1.1 itohy #include <sys/cdefs.h>
37 1.10 cube __KERNEL_RCSID(0, "$NetBSD: ukyopon.c,v 1.10 2008/05/24 16:40:58 cube Exp $");
38 1.1 itohy
39 1.1 itohy #include <sys/param.h>
40 1.1 itohy #include <sys/systm.h>
41 1.1 itohy #include <sys/kernel.h>
42 1.1 itohy #include <sys/ioctl.h>
43 1.1 itohy #include <sys/conf.h>
44 1.1 itohy #include <sys/tty.h>
45 1.1 itohy #include <sys/file.h>
46 1.1 itohy #include <sys/select.h>
47 1.1 itohy #include <sys/proc.h>
48 1.1 itohy #include <sys/vnode.h>
49 1.1 itohy #include <sys/device.h>
50 1.1 itohy #include <sys/poll.h>
51 1.1 itohy
52 1.8 ad #include <sys/bus.h>
53 1.1 itohy
54 1.1 itohy #include <dev/usb/usb.h>
55 1.1 itohy #include <dev/usb/usbcdc.h>
56 1.1 itohy
57 1.1 itohy #include <dev/usb/usbdi.h>
58 1.1 itohy #include <dev/usb/usbdi_util.h>
59 1.1 itohy #include <dev/usb/usbdivar.h>
60 1.1 itohy #include <dev/usb/usbdevs.h>
61 1.1 itohy #include <dev/usb/usb_quirks.h>
62 1.1 itohy
63 1.1 itohy #include <dev/usb/ucomvar.h>
64 1.1 itohy #include <dev/usb/umodemvar.h>
65 1.1 itohy #include <dev/usb/ukyopon.h>
66 1.1 itohy
67 1.1 itohy #ifdef UKYOPON_DEBUG
68 1.1 itohy #define DPRINTFN(n, x) if (ukyopondebug > (n)) logprintf x
69 1.1 itohy int ukyopondebug = 0;
70 1.1 itohy #else
71 1.1 itohy #define DPRINTFN(n, x)
72 1.1 itohy #endif
73 1.1 itohy #define DPRINTF(x) DPRINTFN(0, x)
74 1.1 itohy
75 1.1 itohy struct ukyopon_softc {
76 1.1 itohy /* generic umodem device */
77 1.1 itohy struct umodem_softc sc_umodem;
78 1.1 itohy
79 1.1 itohy /* ukyopon addition */
80 1.1 itohy };
81 1.1 itohy
82 1.1 itohy #define UKYOPON_MODEM_IFACE_INDEX 0
83 1.1 itohy #define UKYOPON_DATA_IFACE_INDEX 3
84 1.1 itohy
85 1.3 itohy Static void ukyopon_get_status(void *, int, u_char *, u_char *);
86 1.6 christos Static int ukyopon_ioctl(void *, int, u_long, void *, int, usb_proc_ptr);
87 1.1 itohy
88 1.1 itohy Static struct ucom_methods ukyopon_methods = {
89 1.3 itohy ukyopon_get_status,
90 1.1 itohy umodem_set,
91 1.1 itohy umodem_param,
92 1.1 itohy ukyopon_ioctl,
93 1.1 itohy umodem_open,
94 1.1 itohy umodem_close,
95 1.1 itohy NULL,
96 1.1 itohy NULL,
97 1.1 itohy };
98 1.1 itohy
99 1.1 itohy USB_DECLARE_DRIVER(ukyopon);
100 1.1 itohy
101 1.1 itohy USB_MATCH(ukyopon)
102 1.1 itohy {
103 1.7 drochner USB_IFMATCH_START(ukyopon, uaa);
104 1.1 itohy
105 1.7 drochner if (uaa->vendor == USB_VENDOR_KYOCERA &&
106 1.7 drochner uaa->product == USB_PRODUCT_KYOCERA_AHK3001V &&
107 1.1 itohy (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX ||
108 1.1 itohy uaa->ifaceno == UKYOPON_DATA_IFACE_INDEX))
109 1.1 itohy return (UMATCH_VENDOR_PRODUCT);
110 1.1 itohy
111 1.1 itohy return (UMATCH_NONE);
112 1.1 itohy }
113 1.1 itohy
114 1.1 itohy USB_ATTACH(ukyopon)
115 1.1 itohy {
116 1.7 drochner USB_IFATTACH_START(ukyopon, sc, uaa);
117 1.1 itohy struct ucom_attach_args uca;
118 1.1 itohy
119 1.2 itohy uca.portno = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
120 1.1 itohy UKYOPON_PORT_MODEM : UKYOPON_PORT_DATA;
121 1.1 itohy uca.methods = &ukyopon_methods;
122 1.1 itohy uca.info = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
123 1.1 itohy "modem port" : "data transfer port";
124 1.1 itohy
125 1.1 itohy if (umodem_common_attach(self, &sc->sc_umodem, uaa, &uca))
126 1.1 itohy USB_ATTACH_ERROR_RETURN;
127 1.1 itohy USB_ATTACH_SUCCESS_RETURN;
128 1.1 itohy }
129 1.1 itohy
130 1.3 itohy Static void
131 1.3 itohy ukyopon_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
132 1.3 itohy {
133 1.3 itohy struct ukyopon_softc *sc = addr;
134 1.3 itohy
135 1.3 itohy /*
136 1.3 itohy * The device doesn't set DCD (Data Carrier Detect) bit properly.
137 1.3 itohy * Assume DCD is always present.
138 1.3 itohy */
139 1.3 itohy if ((sc->sc_umodem.sc_msr & UMSR_DCD) == 0)
140 1.3 itohy sc->sc_umodem.sc_msr |= UMSR_DCD;
141 1.3 itohy
142 1.3 itohy return umodem_get_status(addr, portno, lsr, msr);
143 1.3 itohy }
144 1.3 itohy
145 1.1 itohy Static int
146 1.6 christos ukyopon_ioctl(void *addr, int portno, u_long cmd, void *data, int flag,
147 1.1 itohy usb_proc_ptr p)
148 1.1 itohy {
149 1.1 itohy struct ukyopon_softc *sc = addr;
150 1.1 itohy struct ukyopon_identify *arg_id = (void*)data;
151 1.1 itohy int error = 0;
152 1.1 itohy
153 1.1 itohy switch (cmd) {
154 1.1 itohy case UKYOPON_IDENTIFY:
155 1.1 itohy strncpy(arg_id->ui_name, UKYOPON_NAME, sizeof arg_id->ui_name);
156 1.1 itohy arg_id->ui_busno =
157 1.10 cube USBDEVUNIT(sc->sc_umodem.sc_udev->bus->usbctl);
158 1.1 itohy arg_id->ui_address = sc->sc_umodem.sc_udev->address;
159 1.1 itohy arg_id->ui_model = UKYOPON_MODEL_UNKNOWN;
160 1.2 itohy arg_id->ui_porttype = portno;
161 1.1 itohy break;
162 1.1 itohy
163 1.1 itohy default:
164 1.1 itohy error = umodem_ioctl(addr, portno, cmd, data, flag, p);
165 1.1 itohy break;
166 1.1 itohy }
167 1.1 itohy
168 1.1 itohy return (error);
169 1.1 itohy }
170 1.1 itohy
171 1.1 itohy #ifdef __strong_alias
172 1.1 itohy __strong_alias(ukyopon_activate,umodem_common_activate)
173 1.1 itohy #else
174 1.1 itohy int
175 1.1 itohy ukyopon_activate(device_ptr_t self, enum devact act)
176 1.1 itohy {
177 1.10 cube struct ukyopon_softc *sc = device_private(self);
178 1.1 itohy
179 1.1 itohy return umodem_common_activate(&sc->sc_umodem, act);
180 1.1 itohy }
181 1.1 itohy #endif
182 1.1 itohy
183 1.1 itohy USB_DETACH(ukyopon)
184 1.1 itohy {
185 1.1 itohy USB_DETACH_START(ukyopon, sc);
186 1.1 itohy #ifdef __FreeBSD__
187 1.1 itohy int flags = 0;
188 1.1 itohy #endif
189 1.1 itohy
190 1.1 itohy return umodem_common_detach(&sc->sc_umodem, flags);
191 1.1 itohy }
192