Add some Sierra Wireless devices found in Linux sierra driver to ugensa(4).
[dragonfly.git] / sys / dev / usbmisc / ugensa / ugensa.c
CommitLineData
31ac3aa2 1/* $DragonFly: src/sys/dev/usbmisc/ugensa/ugensa.c,v 1.2 2008/02/20 09:00:55 hasso Exp $ */
7024d87b 2/* $OpenBSD: umsm.c,v 1.15 2007/06/14 10:11:16 mbalmer Exp $ */
2d0688d7
HT
3
4/*
5 * Copyright (c) 2006 Jonathan Gray <jsg@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
7024d87b
HT
20/*
21 * Generic USB serial driver used for devices where hardware specific
22 * don't apply or doesn't make sense (for example Qualcomm MSM EVDO, UMTS
23 * and other similar communication devices).
24 */
2d0688d7
HT
25
26#include <sys/param.h>
27#include <sys/systm.h>
28#include <sys/kernel.h>
29#include <sys/device.h>
30#include <sys/conf.h>
31#include <sys/tty.h>
32#include <sys/types.h>
33#include <sys/bus.h>
34#include <sys/module.h>
35
36#include <bus/usb/usb.h>
37#include <bus/usb/usbdi.h>
38#include <bus/usb/usbdi_util.h>
2d0688d7
HT
39#include <dev/usbmisc/ucom/ucomvar.h>
40
7024d87b
HT
41#ifdef UGENSA_DEBUG
42static int ugensadebug = 1;
43#define DPRINTFN(n, x) do { if (ugensadebug > (n)) kprintf x; } while (0)
2d0688d7
HT
44#else
45#define DPRINTFN(n, x)
46#endif
47#define DPRINTF(x) DPRINTFN(0, x)
48
7024d87b 49#define UGENSABUFSZ 4096
2d0688d7 50
7024d87b 51struct ugensa_softc {
2d0688d7
HT
52 struct ucom_softc sc_ucom;
53};
54
7024d87b 55struct ucom_callback ugensa_callback = {
2d0688d7
HT
56 NULL,
57 NULL,
58 NULL,
59 NULL,
60 NULL,
61 NULL,
62 NULL,
63 NULL
64};
65
7024d87b 66static const struct usb_devno ugensa_devs[] = {
3f56796e
HT
67 { USB_DEVICE(0x05c6, 0x6613) }, /* Qualcomm HSDPA MSM */
68 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera KPC650 */
69 { USB_DEVICE(0x0f3d, 0x0112) }, /* AirPrime PC5220 */
70 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
71 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
72 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
73 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
31ac3aa2
HT
74 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
75 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
76 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */
3f56796e 77 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
31ac3aa2 78 { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
3f56796e
HT
79 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
80 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
81 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
82 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
13cbf073 83 { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8755 */
31ac3aa2
HT
84 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
85 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780 */
86 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */
87 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
88 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
89 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */
90 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */
a57be96d 91 { USB_DEVICE(0x12d1, 0x1001) }, /* Huawei Mobile Connect */
3f56796e
HT
92 { USB_DEVICE(0x1410, 0x1100) }, /* Novatel Wireless ExpressCard 3G */
93 { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin V620 */
94 { USB_DEVICE(0x1410, 0x1130) }, /* Novatel Wireless S720 */
7024d87b 95 { USB_DEVICE(0x1410, 0x1410) }, /* Novatel Wireless U740 */
3f56796e
HT
96 { USB_DEVICE(0x1410, 0x1430) }, /* Novatel Wireless XU870 */
97 { USB_DEVICE(0x1410, 0x2100) }, /* Novatel Wireless ES620 */
98 { USB_DEVICE(0x1410, 0x2110) }, /* Novatel Wireless U720 */
99 { USB_DEVICE(0x413c, 0x8115) }, /* Dell W5500 */
2d0688d7
HT
100};
101
7024d87b
HT
102static device_probe_t ugensa_match;
103static device_attach_t ugensa_attach;
104static device_detach_t ugensa_detach;
2d0688d7 105
7024d87b 106static device_method_t ugensa_methods[] = {
2d0688d7 107 /* Device interface */
7024d87b
HT
108 DEVMETHOD(device_probe, ugensa_match),
109 DEVMETHOD(device_attach, ugensa_attach),
110 DEVMETHOD(device_detach, ugensa_detach),
2d0688d7
HT
111 { 0, 0 }
112};
113
7024d87b 114static driver_t ugensa_driver = {
2d0688d7 115 "ucom",
7024d87b
HT
116 ugensa_methods,
117 sizeof (struct ugensa_softc)
2d0688d7
HT
118};
119
7024d87b
HT
120DRIVER_MODULE(ugensa, uhub, ugensa_driver, ucom_devclass, usbd_driver_load, 0);
121MODULE_DEPEND(ugensa, usb, 1, 1, 1);
122MODULE_DEPEND(ugensa, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
123MODULE_VERSION(ugensa, 1);
2d0688d7
HT
124
125static int
7024d87b 126ugensa_match(device_t self)
2d0688d7
HT
127{
128 struct usb_attach_arg *uaa = device_get_ivars(self);
129
a57be96d 130 if (uaa->iface == NULL)
2d0688d7
HT
131 return UMATCH_NONE;
132
7024d87b 133 return (usb_lookup(ugensa_devs, uaa->vendor, uaa->product) != NULL) ?
a57be96d 134 UMATCH_VENDOR_IFACESUBCLASS : UMATCH_NONE;
2d0688d7
HT
135}
136
137static int
7024d87b 138ugensa_attach(device_t self)
2d0688d7 139{
7024d87b 140 struct ugensa_softc *sc = device_get_softc(self);
2d0688d7
HT
141 struct usb_attach_arg *uaa = device_get_ivars(self);
142 struct ucom_softc *ucom;
143 usb_interface_descriptor_t *id;
144 usb_endpoint_descriptor_t *ed;
2d0688d7
HT
145 int i;
146
2d0688d7 147 ucom = &sc->sc_ucom;
7024d87b 148 bzero(sc, sizeof (struct ugensa_softc));
2d0688d7 149
2d0688d7 150 ucom->sc_dev = self;
2d0688d7
HT
151 ucom->sc_udev = uaa->device;
152 ucom->sc_iface = uaa->iface;
153
2d0688d7
HT
154 id = usbd_get_interface_descriptor(ucom->sc_iface);
155
156 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
157 for (i = 0; i < id->bNumEndpoints; i++) {
158 ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
159 if (ed == NULL) {
71f2bf84
HT
160 device_printf(ucom->sc_dev, "no endpoint descriptor "
161 "found for %d\n", i);
2d0688d7
HT
162 goto error;
163 }
164
165 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
166 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK)
167 ucom->sc_bulkin_no = ed->bEndpointAddress;
168 else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
169 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK)
170 ucom->sc_bulkout_no = ed->bEndpointAddress;
171 }
172 if (ucom->sc_bulkin_no == -1 || ucom->sc_bulkout_no == -1) {
71f2bf84 173 device_printf(ucom->sc_dev, "missing endpoint\n");
2d0688d7
HT
174 goto error;
175 }
176
177 ucom->sc_parent = sc;
178 ucom->sc_portno = UCOM_UNK_PORTNO;
7024d87b
HT
179 ucom->sc_ibufsize = UGENSABUFSZ;
180 ucom->sc_obufsize = UGENSABUFSZ;
181 ucom->sc_ibufsizepad = UGENSABUFSZ;
2d0688d7 182 ucom->sc_opkthdrlen = 0;
7024d87b 183 ucom->sc_callback = &ugensa_callback;
2d0688d7
HT
184
185 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
186 ucom->sc_dev);
187
a57be96d
HT
188 DPRINTF(("%s: in = 0x%x, out = 0x%x\n",
189 device_get_nameunit(ucom->sc_dev), ucom->sc_bulkin_no,
190 ucom->sc_bulkout_no));
2d0688d7
HT
191
192 ucom_attach(&sc->sc_ucom);
193
194 return 0;
195
196error:
197 ucom->sc_dying = 1;
198 return ENXIO;
199}
200
201static int
7024d87b 202ugensa_detach(device_t self)
2d0688d7 203{
7024d87b 204 struct ugensa_softc *sc = device_get_softc(self);
2d0688d7
HT
205 int rv = 0;
206
7024d87b 207 DPRINTF(("ugensa_detach: sc=%p\n", sc));
2d0688d7
HT
208 sc->sc_ucom.sc_dying = 1;
209 rv = ucom_detach(&sc->sc_ucom);
210 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_ucom.sc_udev,
211 sc->sc_ucom.sc_dev);
212
213 return (rv);
214}
215
216#if 0 /* not yet */
217int
7024d87b 218ugensa_activate(struct device *self, enum devact act)
2d0688d7 219{
7024d87b 220 struct ugensa_softc *sc = (struct ugensa_softc *)self;
2d0688d7
HT
221 int rv = 0;
222
223 switch (act) {
224 case DVACT_ACTIVATE:
225 break;
226
227 case DVACT_DEACTIVATE:
228 if (sc->sc_subdev != NULL)
229 rv = config_deactivate(sc->sc_subdev);
230 sc->sc_dying = 1;
231 break;
232 }
233 return (rv);
234}
235#endif