Home | History | Annotate | Line # | Download | only in usb
ukyopon.c revision 1.1.6.1
      1  1.1.6.1   yamt /*	$NetBSD: ukyopon.c,v 1.1.6.1 2006/06/21 15:07:44 yamt 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.1.6.1   yamt __KERNEL_RCSID(0, "$NetBSD: ukyopon.c,v 1.1.6.1 2006/06/21 15:07:44 yamt 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/usbdevs.h>
     71      1.1  itohy #include <dev/usb/ucomvar.h>
     72      1.1  itohy #include <dev/usb/umodemvar.h>
     73      1.1  itohy #include <dev/usb/ukyopon.h>
     74      1.1  itohy 
     75      1.1  itohy #ifdef UKYOPON_DEBUG
     76      1.1  itohy #define DPRINTFN(n, x)	if (ukyopondebug > (n)) logprintf x
     77      1.1  itohy int	ukyopondebug = 0;
     78      1.1  itohy #else
     79      1.1  itohy #define DPRINTFN(n, x)
     80      1.1  itohy #endif
     81      1.1  itohy #define DPRINTF(x) DPRINTFN(0, x)
     82      1.1  itohy 
     83      1.1  itohy struct ukyopon_softc {
     84      1.1  itohy 	/* generic umodem device */
     85      1.1  itohy 	struct umodem_softc	sc_umodem;
     86      1.1  itohy 
     87      1.1  itohy 	/* ukyopon addition */
     88      1.1  itohy };
     89      1.1  itohy 
     90      1.1  itohy #define UKYOPON_MODEM_IFACE_INDEX	0
     91      1.1  itohy #define UKYOPON_DATA_IFACE_INDEX	3
     92      1.1  itohy 
     93  1.1.6.1   yamt Static void	ukyopon_get_status(void *, int, u_char *, u_char *);
     94      1.1  itohy Static int	ukyopon_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr);
     95      1.1  itohy 
     96      1.1  itohy Static struct ucom_methods ukyopon_methods = {
     97  1.1.6.1   yamt 	ukyopon_get_status,
     98      1.1  itohy 	umodem_set,
     99      1.1  itohy 	umodem_param,
    100      1.1  itohy 	ukyopon_ioctl,
    101      1.1  itohy 	umodem_open,
    102      1.1  itohy 	umodem_close,
    103      1.1  itohy 	NULL,
    104      1.1  itohy 	NULL,
    105      1.1  itohy };
    106      1.1  itohy 
    107      1.1  itohy USB_DECLARE_DRIVER(ukyopon);
    108      1.1  itohy 
    109      1.1  itohy USB_MATCH(ukyopon)
    110      1.1  itohy {
    111      1.1  itohy 	USB_MATCH_START(ukyopon, uaa);
    112      1.1  itohy 	usb_device_descriptor_t *dd;
    113      1.1  itohy 	usb_interface_descriptor_t *id;
    114      1.1  itohy 
    115      1.1  itohy 	if (uaa->iface == NULL)
    116      1.1  itohy 		return (UMATCH_NONE);
    117      1.1  itohy 
    118      1.1  itohy 	id = usbd_get_interface_descriptor(uaa->iface);
    119      1.1  itohy 	dd = usbd_get_device_descriptor(uaa->device);
    120      1.1  itohy 	if (id == NULL || dd == NULL)
    121      1.1  itohy 		return (UMATCH_NONE);
    122      1.1  itohy 
    123      1.1  itohy 	if (UGETW(dd->idVendor) == USB_VENDOR_KYOCERA &&
    124      1.1  itohy 	    UGETW(dd->idProduct) == USB_PRODUCT_KYOCERA_AHK3001V &&
    125      1.1  itohy 	    (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX ||
    126      1.1  itohy 	     uaa->ifaceno == UKYOPON_DATA_IFACE_INDEX))
    127      1.1  itohy 		return (UMATCH_VENDOR_PRODUCT);
    128      1.1  itohy 
    129      1.1  itohy 	return (UMATCH_NONE);
    130      1.1  itohy }
    131      1.1  itohy 
    132      1.1  itohy USB_ATTACH(ukyopon)
    133      1.1  itohy {
    134      1.1  itohy 	USB_ATTACH_START(ukyopon, sc, uaa);
    135      1.1  itohy 	struct ucom_attach_args uca;
    136      1.1  itohy 
    137  1.1.6.1   yamt 	uca.portno = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
    138      1.1  itohy 		UKYOPON_PORT_MODEM : UKYOPON_PORT_DATA;
    139      1.1  itohy 	uca.methods = &ukyopon_methods;
    140      1.1  itohy 	uca.info = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
    141      1.1  itohy 	    "modem port" : "data transfer port";
    142      1.1  itohy 
    143      1.1  itohy 	if (umodem_common_attach(self, &sc->sc_umodem, uaa, &uca))
    144      1.1  itohy 		USB_ATTACH_ERROR_RETURN;
    145      1.1  itohy 	USB_ATTACH_SUCCESS_RETURN;
    146      1.1  itohy }
    147      1.1  itohy 
    148  1.1.6.1   yamt Static void
    149  1.1.6.1   yamt ukyopon_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
    150  1.1.6.1   yamt {
    151  1.1.6.1   yamt 	struct ukyopon_softc *sc = addr;
    152  1.1.6.1   yamt 
    153  1.1.6.1   yamt 	/*
    154  1.1.6.1   yamt 	 * The device doesn't set DCD (Data Carrier Detect) bit properly.
    155  1.1.6.1   yamt 	 * Assume DCD is always present.
    156  1.1.6.1   yamt 	 */
    157  1.1.6.1   yamt 	if ((sc->sc_umodem.sc_msr & UMSR_DCD) == 0)
    158  1.1.6.1   yamt 		sc->sc_umodem.sc_msr |= UMSR_DCD;
    159  1.1.6.1   yamt 
    160  1.1.6.1   yamt 	return umodem_get_status(addr, portno, lsr, msr);
    161  1.1.6.1   yamt }
    162  1.1.6.1   yamt 
    163      1.1  itohy Static int
    164      1.1  itohy ukyopon_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
    165      1.1  itohy 	      usb_proc_ptr p)
    166      1.1  itohy {
    167      1.1  itohy 	struct ukyopon_softc *sc = addr;
    168      1.1  itohy 	struct ukyopon_identify *arg_id = (void*)data;
    169      1.1  itohy 	int error = 0;
    170      1.1  itohy 
    171      1.1  itohy 	switch (cmd) {
    172      1.1  itohy 	case UKYOPON_IDENTIFY:
    173      1.1  itohy 		strncpy(arg_id->ui_name, UKYOPON_NAME, sizeof arg_id->ui_name);
    174      1.1  itohy 		arg_id->ui_busno =
    175      1.1  itohy 		    USBDEVUNIT(*(device_ptr_t)sc->sc_umodem.sc_udev->bus->usbctl);
    176      1.1  itohy 		arg_id->ui_address = sc->sc_umodem.sc_udev->address;
    177      1.1  itohy 		arg_id->ui_model = UKYOPON_MODEL_UNKNOWN;
    178  1.1.6.1   yamt 		arg_id->ui_porttype = portno;
    179      1.1  itohy 		break;
    180      1.1  itohy 
    181      1.1  itohy 	default:
    182      1.1  itohy 		error = umodem_ioctl(addr, portno, cmd, data, flag, p);
    183      1.1  itohy 		break;
    184      1.1  itohy 	}
    185      1.1  itohy 
    186      1.1  itohy 	return (error);
    187      1.1  itohy }
    188      1.1  itohy 
    189      1.1  itohy #ifdef __strong_alias
    190      1.1  itohy __strong_alias(ukyopon_activate,umodem_common_activate)
    191      1.1  itohy #else
    192      1.1  itohy int
    193      1.1  itohy ukyopon_activate(device_ptr_t self, enum devact act)
    194      1.1  itohy {
    195      1.1  itohy 	struct ukyopon_softc *sc = (struct ukyopon_softc *)self;
    196      1.1  itohy 
    197      1.1  itohy 	return umodem_common_activate(&sc->sc_umodem, act);
    198      1.1  itohy }
    199      1.1  itohy #endif
    200      1.1  itohy 
    201      1.1  itohy USB_DETACH(ukyopon)
    202      1.1  itohy {
    203      1.1  itohy 	USB_DETACH_START(ukyopon, sc);
    204      1.1  itohy #ifdef __FreeBSD__
    205      1.1  itohy 	int flags = 0;
    206      1.1  itohy #endif
    207      1.1  itohy 
    208      1.1  itohy 	return umodem_common_detach(&sc->sc_umodem, flags);
    209      1.1  itohy }
    210