Home | History | Annotate | Line # | Download | only in usb
ukyopon.c revision 1.16.16.2
      1  1.16.16.2     skrll /*	$NetBSD: ukyopon.c,v 1.16.16.2 2014/12/06 08:37:30 skrll 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.16.16.2     skrll __KERNEL_RCSID(0, "$NetBSD: ukyopon.c,v 1.16.16.2 2014/12/06 08:37:30 skrll 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.12    dyoung #define DPRINTFN(n, x)	if (ukyopondebug > (n)) printf 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.12    dyoung Static int	ukyopon_ioctl(void *, int, u_long, void *, int, proc_t *);
     87        1.1     itohy 
     88        1.1     itohy Static struct ucom_methods ukyopon_methods = {
     89  1.16.16.2     skrll 	.ucom_get_status = ukyopon_get_status,
     90  1.16.16.2     skrll 	.ucom_set = umodem_set,
     91  1.16.16.2     skrll 	.ucom_param = umodem_param,
     92  1.16.16.2     skrll 	.ucom_ioctl = ukyopon_ioctl,
     93  1.16.16.2     skrll 	.ucom_open = umodem_open,
     94  1.16.16.2     skrll 	.ucom_close = umodem_close,
     95  1.16.16.2     skrll 	.ucom_read = NULL,
     96  1.16.16.2     skrll 	.ucom_write = NULL,
     97        1.1     itohy };
     98        1.1     itohy 
     99       1.12    dyoung int             ukyopon_match(device_t, cfdata_t, void *);
    100       1.12    dyoung void            ukyopon_attach(device_t, device_t, void *);
    101       1.12    dyoung int             ukyopon_detach(device_t, int);
    102       1.12    dyoung int             ukyopon_activate(device_t, enum devact);
    103       1.12    dyoung extern struct cfdriver ukyopon_cd;
    104       1.12    dyoung CFATTACH_DECL_NEW(ukyopon, sizeof(struct ukyopon_softc), ukyopon_match, ukyopon_attach, ukyopon_detach, ukyopon_activate);
    105        1.1     itohy 
    106       1.15  jakllsch int
    107       1.12    dyoung ukyopon_match(device_t parent, cfdata_t match, void *aux)
    108        1.1     itohy {
    109       1.12    dyoung 	struct usbif_attach_arg *uaa = aux;
    110        1.1     itohy 
    111        1.7  drochner 	if (uaa->vendor == USB_VENDOR_KYOCERA &&
    112        1.7  drochner 	    uaa->product == USB_PRODUCT_KYOCERA_AHK3001V &&
    113        1.1     itohy 	    (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX ||
    114        1.1     itohy 	     uaa->ifaceno == UKYOPON_DATA_IFACE_INDEX))
    115        1.1     itohy 		return (UMATCH_VENDOR_PRODUCT);
    116        1.1     itohy 
    117        1.1     itohy 	return (UMATCH_NONE);
    118        1.1     itohy }
    119        1.1     itohy 
    120       1.15  jakllsch void
    121       1.12    dyoung ukyopon_attach(device_t parent, device_t self, void *aux)
    122        1.1     itohy {
    123       1.12    dyoung 	struct ukyopon_softc *sc = device_private(self);
    124       1.12    dyoung 	struct usbif_attach_arg *uaa = aux;
    125        1.1     itohy 	struct ucom_attach_args uca;
    126        1.1     itohy 
    127        1.2     itohy 	uca.portno = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
    128        1.1     itohy 		UKYOPON_PORT_MODEM : UKYOPON_PORT_DATA;
    129        1.1     itohy 	uca.methods = &ukyopon_methods;
    130        1.1     itohy 	uca.info = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
    131        1.1     itohy 	    "modem port" : "data transfer port";
    132        1.1     itohy 
    133        1.1     itohy 	if (umodem_common_attach(self, &sc->sc_umodem, uaa, &uca))
    134       1.12    dyoung 		return;
    135       1.12    dyoung 	return;
    136        1.1     itohy }
    137        1.1     itohy 
    138        1.3     itohy Static void
    139        1.3     itohy ukyopon_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
    140        1.3     itohy {
    141        1.3     itohy 	struct ukyopon_softc *sc = addr;
    142        1.3     itohy 
    143        1.3     itohy 	/*
    144        1.3     itohy 	 * The device doesn't set DCD (Data Carrier Detect) bit properly.
    145        1.3     itohy 	 * Assume DCD is always present.
    146        1.3     itohy 	 */
    147        1.3     itohy 	if ((sc->sc_umodem.sc_msr & UMSR_DCD) == 0)
    148        1.3     itohy 		sc->sc_umodem.sc_msr |= UMSR_DCD;
    149        1.3     itohy 
    150       1.13     njoly 	umodem_get_status(addr, portno, lsr, msr);
    151        1.3     itohy }
    152        1.3     itohy 
    153        1.1     itohy Static int
    154        1.6  christos ukyopon_ioctl(void *addr, int portno, u_long cmd, void *data, int flag,
    155       1.12    dyoung 	      proc_t *p)
    156        1.1     itohy {
    157        1.1     itohy 	struct ukyopon_softc *sc = addr;
    158        1.1     itohy 	struct ukyopon_identify *arg_id = (void*)data;
    159        1.1     itohy 	int error = 0;
    160        1.1     itohy 
    161        1.1     itohy 	switch (cmd) {
    162        1.1     itohy 	case UKYOPON_IDENTIFY:
    163        1.1     itohy 		strncpy(arg_id->ui_name, UKYOPON_NAME, sizeof arg_id->ui_name);
    164        1.1     itohy 		arg_id->ui_busno =
    165  1.16.16.1     skrll 		    device_unit(sc->sc_umodem.sc_udev->ud_bus->ub_usbctl);
    166  1.16.16.1     skrll 		arg_id->ui_address = sc->sc_umodem.sc_udev->ud_addr;
    167        1.1     itohy 		arg_id->ui_model = UKYOPON_MODEL_UNKNOWN;
    168        1.2     itohy 		arg_id->ui_porttype = portno;
    169        1.1     itohy 		break;
    170        1.1     itohy 
    171        1.1     itohy 	default:
    172        1.1     itohy 		error = umodem_ioctl(addr, portno, cmd, data, flag, p);
    173        1.1     itohy 		break;
    174        1.1     itohy 	}
    175        1.1     itohy 
    176        1.1     itohy 	return (error);
    177        1.1     itohy }
    178        1.1     itohy 
    179        1.1     itohy int
    180       1.12    dyoung ukyopon_activate(device_t self, enum devact act)
    181        1.1     itohy {
    182       1.10      cube 	struct ukyopon_softc *sc = device_private(self);
    183        1.1     itohy 
    184        1.1     itohy 	return umodem_common_activate(&sc->sc_umodem, act);
    185        1.1     itohy }
    186        1.1     itohy 
    187       1.15  jakllsch int
    188       1.12    dyoung ukyopon_detach(device_t self, int flags)
    189        1.1     itohy {
    190       1.12    dyoung 	struct ukyopon_softc *sc = device_private(self);
    191        1.1     itohy 
    192        1.1     itohy 	return umodem_common_detach(&sc->sc_umodem, flags);
    193        1.1     itohy }
    194