1 /* $NetBSD: ucom.c,v 1.7 1999/01/10 19:13:15 augustss Exp $ */ 2 3 /* 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Lennart Augustsson (augustss@carlstedt.se) at 9 * Carlstedt Research & Technology. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 #include <dev/usb/usb_port.h> 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/kernel.h> 45 #include <sys/malloc.h> 46 #if defined(__NetBSD__) 47 #include <sys/ioctl.h> 48 #include <sys/device.h> 49 #elif defined(__FreeBSD__) 50 #include <sys/module.h> 51 #include <sys/bus.h> 52 #include <sys/ioccom.h> 53 #include <sys/conf.h> 54 #endif 55 #include <sys/tty.h> 56 #include <sys/file.h> 57 #include <sys/select.h> 58 #include <sys/proc.h> 59 #include <sys/vnode.h> 60 #include <sys/poll.h> 61 62 #include <dev/usb/usb.h> 63 #include <dev/usb/usbhid.h> 64 65 #include <dev/usb/usbdi.h> 66 #include <dev/usb/usbdi_util.h> 67 #include <dev/usb/usbdevs.h> 68 #include <dev/usb/usb_quirks.h> 69 #include <dev/usb/hid.h> 70 71 #ifdef USB_DEBUG 72 #define DPRINTF(x) if (ucomdebug) printf x 73 #define DPRINTFN(n,x) if (ucomdebug>(n)) printf x 74 int ucomdebug = 0; 75 #else 76 #define DPRINTF(x) 77 #define DPRINTFN(n,x) 78 #endif 79 80 struct ucom_softc { 81 bdevice sc_dev; /* base device */ 82 usbd_interface_handle sc_iface; /* interface */ 83 }; 84 85 void ucom_intr __P((usbd_request_handle, usbd_private_handle, usbd_status)); 86 void ucom_disco __P((void *)); 87 88 USB_DECLARE_DRIVER(ucom); 89 90 USB_MATCH(ucom) 91 { 92 USB_MATCH_START(ucom, uaa); 93 usb_interface_descriptor_t *id; 94 95 if (!uaa->iface) 96 return (UMATCH_NONE); 97 id = usbd_get_interface_descriptor(uaa->iface); 98 if (id && 99 id->bInterfaceClass != UCLASS_CDC || 100 id->bInterfaceSubClass != USUBCLASS_MODEM) 101 return (UMATCH_NONE); 102 return (UMATCH_IFACECLASS_IFACESUBCLASS); 103 } 104 105 USB_ATTACH(ucom) 106 { 107 USB_ATTACH_START(ucom, sc, uaa); 108 usbd_interface_handle iface = uaa->iface; 109 usb_interface_descriptor_t *id; 110 char devinfo[1024]; 111 112 sc->sc_iface = iface; 113 id = usbd_get_interface_descriptor(iface); 114 usbd_devinfo(uaa->device, 0, devinfo); 115 USB_ATTACH_SETUP; 116 printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev), 117 devinfo, id->bInterfaceClass, id->bInterfaceSubClass); 118 119 USB_ATTACH_SUCCESS_RETURN; 120 } 121 122 #if defined(__FreeBSD__) 123 static int 124 ucom_detach(device_t self) 125 { 126 struct ucom_softc *sc = device_get_softc(self); 127 char *devinfo = (char *) device_get_desc(self); 128 129 if (devinfo) { 130 device_set_desc(self, NULL); 131 free(devinfo, M_USB); 132 } 133 return 0; 134 } 135 #endif 136 137 #if defined(__FreeBSD__) 138 DRIVER_MODULE(ucom, usb, ucom_driver, ucom_devclass, usbd_driver_load, 0); 139 #endif 140 141