- Fix compiling umsm(4) with UMSM_DEBUG
[dragonfly.git] / sys / dev / usbmisc / umsm / umsm.c
blob036bb17c9cfb407a61774c2ed2606a3a2073ccc9
1 /* $DragonFly: src/sys/dev/usbmisc/umsm/Attic/umsm.c,v 1.6 2008/01/11 12:25:30 hasso Exp $ */
2 /* $OpenBSD: umsm.c,v 1.15 2007/06/14 10:11:16 mbalmer Exp $ */
4 /*
5 * Copyright (c) 2006 Jonathan Gray <jsg@openbsd.org>
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.
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.
20 /* Driver for Qualcomm MSM EVDO and UMTS communication devices */
22 #include <sys/param.h>
23 #include <sys/systm.h>
24 #include <sys/kernel.h>
25 #include <sys/device.h>
26 #include <sys/conf.h>
27 #include <sys/tty.h>
28 #include <sys/types.h>
29 #include <sys/bus.h>
30 #include <sys/module.h>
32 #include <bus/usb/usb.h>
33 #include <bus/usb/usbdi.h>
34 #include <bus/usb/usbdi_util.h>
35 #include <dev/usbmisc/ucom/ucomvar.h>
37 #ifdef UMSM_DEBUG
38 static int umsmdebug = 1;
39 #define DPRINTFN(n, x) do { if (umsmdebug > (n)) kprintf x; } while (0)
40 #else
41 #define DPRINTFN(n, x)
42 #endif
43 #define DPRINTF(x) DPRINTFN(0, x)
45 #define UMSMBUFSZ 2048
47 struct umsm_softc {
48 struct ucom_softc sc_ucom;
51 struct ucom_callback umsm_callback = {
52 NULL,
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 NULL,
58 NULL,
59 NULL
62 static const struct usb_devno umsm_devs[] = {
63 { USB_DEVICE(0x05c6, 0x6613) }, /* Qualcomm HSDPA MSM */
64 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera KPC650 */
65 { USB_DEVICE(0x0f3d, 0x0112) }, /* AirPrime PC5220 */
66 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
67 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
68 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
69 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
70 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless Aircard 580 */
71 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
72 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
73 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
74 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
75 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
76 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless Aircard 875 */
77 { USB_DEVICE(0x12d1, 0x1001) }, /* Huawei Mobile Connect */
78 { USB_DEVICE(0x1410, 0x1100) }, /* Novatel Wireless ExpressCard 3G */
79 { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin V620 */
80 { USB_DEVICE(0x1410, 0x1130) }, /* Novatel Wireless S720 */
81 { USB_DEVICE(0x1410, 0x1430) }, /* Novatel Wireless XU870 */
82 { USB_DEVICE(0x1410, 0x2100) }, /* Novatel Wireless ES620 */
83 { USB_DEVICE(0x1410, 0x2110) }, /* Novatel Wireless U720 */
84 { USB_DEVICE(0x413c, 0x8115) }, /* Dell W5500 */
87 static device_probe_t umsm_match;
88 static device_attach_t umsm_attach;
89 static device_detach_t umsm_detach;
91 static device_method_t umsm_methods[] = {
92 /* Device interface */
93 DEVMETHOD(device_probe, umsm_match),
94 DEVMETHOD(device_attach, umsm_attach),
95 DEVMETHOD(device_detach, umsm_detach),
96 { 0, 0 }
99 static driver_t umsm_driver = {
100 "ucom",
101 umsm_methods,
102 sizeof (struct umsm_softc)
105 DRIVER_MODULE(umsm, uhub, umsm_driver, ucom_devclass, usbd_driver_load, 0);
106 MODULE_DEPEND(umsm, usb, 1, 1, 1);
107 MODULE_DEPEND(umsm, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
108 MODULE_VERSION(umsm, 1);
110 static int
111 umsm_match(device_t self)
113 struct usb_attach_arg *uaa = device_get_ivars(self);
115 if (uaa->iface == NULL)
116 return UMATCH_NONE;
118 return (usb_lookup(umsm_devs, uaa->vendor, uaa->product) != NULL) ?
119 UMATCH_VENDOR_IFACESUBCLASS : UMATCH_NONE;
122 static int
123 umsm_attach(device_t self)
125 struct umsm_softc *sc = device_get_softc(self);
126 struct usb_attach_arg *uaa = device_get_ivars(self);
127 struct ucom_softc *ucom;
128 usb_interface_descriptor_t *id;
129 usb_endpoint_descriptor_t *ed;
130 int i;
132 ucom = &sc->sc_ucom;
133 bzero(sc, sizeof (struct umsm_softc));
135 ucom->sc_dev = self;
136 ucom->sc_udev = uaa->device;
137 ucom->sc_iface = uaa->iface;
139 id = usbd_get_interface_descriptor(ucom->sc_iface);
141 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
142 for (i = 0; i < id->bNumEndpoints; i++) {
143 ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
144 if (ed == NULL) {
145 device_printf(ucom->sc_dev, "no endpoint descriptor "
146 "found for %d\n", i);
147 goto error;
150 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
151 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK)
152 ucom->sc_bulkin_no = ed->bEndpointAddress;
153 else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
154 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK)
155 ucom->sc_bulkout_no = ed->bEndpointAddress;
157 if (ucom->sc_bulkin_no == -1 || ucom->sc_bulkout_no == -1) {
158 device_printf(ucom->sc_dev, "missing endpoint\n");
159 goto error;
162 ucom->sc_parent = sc;
163 ucom->sc_portno = UCOM_UNK_PORTNO;
164 ucom->sc_ibufsize = UMSMBUFSZ;
165 ucom->sc_obufsize = UMSMBUFSZ;
166 ucom->sc_ibufsizepad = UMSMBUFSZ;
167 ucom->sc_opkthdrlen = 0;
168 ucom->sc_callback = &umsm_callback;
170 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
171 ucom->sc_dev);
173 DPRINTF(("%s: in = 0x%x, out = 0x%x\n",
174 device_get_nameunit(ucom->sc_dev), ucom->sc_bulkin_no,
175 ucom->sc_bulkout_no));
177 ucom_attach(&sc->sc_ucom);
179 return 0;
181 error:
182 ucom->sc_dying = 1;
183 return ENXIO;
186 static int
187 umsm_detach(device_t self)
189 struct umsm_softc *sc = device_get_softc(self);
190 int rv = 0;
192 DPRINTF(("umsm_detach: sc=%p\n", sc));
193 sc->sc_ucom.sc_dying = 1;
194 rv = ucom_detach(&sc->sc_ucom);
195 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_ucom.sc_udev,
196 sc->sc_ucom.sc_dev);
198 return (rv);
201 #if 0 /* not yet */
203 umsm_activate(struct device *self, enum devact act)
205 struct umsm_softc *sc = (struct umsm_softc *)self;
206 int rv = 0;
208 switch (act) {
209 case DVACT_ACTIVATE:
210 break;
212 case DVACT_DEACTIVATE:
213 if (sc->sc_subdev != NULL)
214 rv = config_deactivate(sc->sc_subdev);
215 sc->sc_dying = 1;
216 break;
218 return (rv);
220 #endif