Home | History | Annotate | Line # | Download | only in usb
ukyopon.c revision 1.23
      1  1.23       mrg /*	$NetBSD: ukyopon.c,v 1.23 2019/05/05 03:17:54 mrg 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.23       mrg __KERNEL_RCSID(0, "$NetBSD: ukyopon.c,v 1.23 2019/05/05 03:17:54 mrg Exp $");
     38  1.19     skrll 
     39  1.19     skrll #ifdef _KERNEL_OPT
     40  1.19     skrll #include "opt_usb.h"
     41  1.19     skrll #endif
     42   1.1     itohy 
     43   1.1     itohy #include <sys/param.h>
     44   1.1     itohy #include <sys/systm.h>
     45   1.1     itohy #include <sys/kernel.h>
     46   1.1     itohy #include <sys/ioctl.h>
     47   1.1     itohy #include <sys/conf.h>
     48   1.1     itohy #include <sys/tty.h>
     49   1.1     itohy #include <sys/file.h>
     50   1.1     itohy #include <sys/select.h>
     51   1.1     itohy #include <sys/proc.h>
     52   1.1     itohy #include <sys/vnode.h>
     53   1.1     itohy #include <sys/device.h>
     54   1.1     itohy #include <sys/poll.h>
     55   1.1     itohy 
     56   1.8        ad #include <sys/bus.h>
     57   1.1     itohy 
     58   1.1     itohy #include <dev/usb/usb.h>
     59   1.1     itohy #include <dev/usb/usbcdc.h>
     60   1.1     itohy 
     61   1.1     itohy #include <dev/usb/usbdi.h>
     62   1.1     itohy #include <dev/usb/usbdi_util.h>
     63   1.1     itohy #include <dev/usb/usbdivar.h>
     64   1.1     itohy #include <dev/usb/usbdevs.h>
     65   1.1     itohy #include <dev/usb/usb_quirks.h>
     66   1.1     itohy 
     67   1.1     itohy #include <dev/usb/ucomvar.h>
     68   1.1     itohy #include <dev/usb/umodemvar.h>
     69   1.1     itohy #include <dev/usb/ukyopon.h>
     70   1.1     itohy 
     71   1.1     itohy #ifdef UKYOPON_DEBUG
     72  1.12    dyoung #define DPRINTFN(n, x)	if (ukyopondebug > (n)) printf x
     73   1.1     itohy int	ukyopondebug = 0;
     74   1.1     itohy #else
     75   1.1     itohy #define DPRINTFN(n, x)
     76   1.1     itohy #endif
     77   1.1     itohy #define DPRINTF(x) DPRINTFN(0, x)
     78   1.1     itohy 
     79   1.1     itohy struct ukyopon_softc {
     80   1.1     itohy 	/* generic umodem device */
     81   1.1     itohy 	struct umodem_softc	sc_umodem;
     82   1.1     itohy 
     83   1.1     itohy 	/* ukyopon addition */
     84   1.1     itohy };
     85   1.1     itohy 
     86   1.1     itohy #define UKYOPON_MODEM_IFACE_INDEX	0
     87   1.1     itohy #define UKYOPON_DATA_IFACE_INDEX	3
     88   1.1     itohy 
     89  1.22       mrg static void	ukyopon_get_status(void *, int, u_char *, u_char *);
     90  1.22       mrg static int	ukyopon_ioctl(void *, int, u_long, void *, int, proc_t *);
     91  1.22       mrg static void	ukyopon_set(void *, int, int, int);
     92  1.22       mrg static int	ukyopon_param(void *, int, struct termios *);
     93  1.22       mrg static int	ukyopon_open(void *, int);
     94  1.22       mrg static void	ukyopon_close(void *, int);
     95   1.1     itohy 
     96  1.22       mrg static struct ucom_methods ukyopon_methods = {
     97  1.17     skrll 	.ucom_get_status = ukyopon_get_status,
     98  1.22       mrg 	.ucom_set = ukyopon_set,
     99  1.22       mrg 	.ucom_param = ukyopon_param,
    100  1.17     skrll 	.ucom_ioctl = ukyopon_ioctl,
    101  1.22       mrg 	.ucom_open = ukyopon_open,
    102  1.22       mrg 	.ucom_close = ukyopon_close,
    103   1.1     itohy };
    104   1.1     itohy 
    105  1.22       mrg static int	ukyopon_match(device_t, cfdata_t, void *);
    106  1.22       mrg static void	ukyopon_attach(device_t, device_t, void *);
    107  1.22       mrg static int	ukyopon_detach(device_t, int);
    108  1.22       mrg static int	ukyopon_activate(device_t, enum devact);
    109  1.23       mrg 
    110  1.18   msaitoh CFATTACH_DECL_NEW(ukyopon, sizeof(struct ukyopon_softc), ukyopon_match,
    111  1.18   msaitoh     ukyopon_attach, ukyopon_detach, ukyopon_activate);
    112   1.1     itohy 
    113  1.22       mrg static int
    114  1.12    dyoung ukyopon_match(device_t parent, cfdata_t match, void *aux)
    115   1.1     itohy {
    116  1.17     skrll 	struct usbif_attach_arg *uiaa = aux;
    117   1.1     itohy 
    118  1.17     skrll 	if (uiaa->uiaa_vendor == USB_VENDOR_KYOCERA &&
    119  1.17     skrll 	    uiaa->uiaa_product == USB_PRODUCT_KYOCERA_AHK3001V &&
    120  1.17     skrll 	    (uiaa->uiaa_ifaceno == UKYOPON_MODEM_IFACE_INDEX ||
    121  1.17     skrll 	     uiaa->uiaa_ifaceno == UKYOPON_DATA_IFACE_INDEX))
    122  1.20     skrll 		return UMATCH_VENDOR_PRODUCT;
    123   1.1     itohy 
    124  1.20     skrll 	return UMATCH_NONE;
    125   1.1     itohy }
    126   1.1     itohy 
    127  1.22       mrg static void
    128  1.12    dyoung ukyopon_attach(device_t parent, device_t self, void *aux)
    129   1.1     itohy {
    130  1.12    dyoung 	struct ukyopon_softc *sc = device_private(self);
    131  1.17     skrll 	struct usbif_attach_arg *uiaa = aux;
    132  1.17     skrll 	struct ucom_attach_args ucaa;
    133   1.1     itohy 
    134  1.17     skrll 	ucaa.ucaa_portno = (uiaa->uiaa_ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
    135   1.1     itohy 		UKYOPON_PORT_MODEM : UKYOPON_PORT_DATA;
    136  1.17     skrll 	ucaa.ucaa_methods = &ukyopon_methods;
    137  1.17     skrll 	ucaa.ucaa_info = (uiaa->uiaa_ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
    138   1.1     itohy 	    "modem port" : "data transfer port";
    139   1.1     itohy 
    140  1.17     skrll 	if (umodem_common_attach(self, &sc->sc_umodem, uiaa, &ucaa))
    141  1.12    dyoung 		return;
    142  1.12    dyoung 	return;
    143   1.1     itohy }
    144   1.1     itohy 
    145  1.22       mrg static void
    146   1.3     itohy ukyopon_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
    147   1.3     itohy {
    148   1.3     itohy 	struct ukyopon_softc *sc = addr;
    149   1.3     itohy 
    150   1.3     itohy 	/*
    151   1.3     itohy 	 * The device doesn't set DCD (Data Carrier Detect) bit properly.
    152   1.3     itohy 	 * Assume DCD is always present.
    153   1.3     itohy 	 */
    154   1.3     itohy 	if ((sc->sc_umodem.sc_msr & UMSR_DCD) == 0)
    155   1.3     itohy 		sc->sc_umodem.sc_msr |= UMSR_DCD;
    156   1.3     itohy 
    157  1.13     njoly 	umodem_get_status(addr, portno, lsr, msr);
    158   1.3     itohy }
    159   1.3     itohy 
    160  1.22       mrg static void
    161  1.22       mrg ukyopon_set(void *addr, int portno, int reg, int onoff)
    162  1.22       mrg {
    163  1.22       mrg 	struct ukyopon_softc *sc = addr;
    164  1.22       mrg 
    165  1.22       mrg 	umodem_set(&sc->sc_umodem, portno, reg, onoff);
    166  1.22       mrg }
    167  1.22       mrg 
    168  1.22       mrg static int
    169  1.22       mrg ukyopon_param(void *addr, int portno, struct termios *t)
    170  1.22       mrg {
    171  1.22       mrg 	struct ukyopon_softc *sc = addr;
    172  1.22       mrg 
    173  1.22       mrg 	return umodem_param(&sc->sc_umodem, portno, t);
    174  1.22       mrg }
    175  1.22       mrg 
    176  1.22       mrg static int
    177  1.22       mrg ukyopon_open(void *addr, int portno)
    178  1.22       mrg {
    179  1.22       mrg 	struct ukyopon_softc *sc = addr;
    180  1.22       mrg 
    181  1.22       mrg 	return umodem_open(&sc->sc_umodem, portno);
    182  1.22       mrg }
    183  1.22       mrg 
    184  1.22       mrg static void
    185  1.22       mrg ukyopon_close(void *addr, int portno)
    186  1.22       mrg {
    187  1.22       mrg 	struct ukyopon_softc *sc = addr;
    188  1.22       mrg 
    189  1.22       mrg 	umodem_close(&sc->sc_umodem, portno);
    190  1.22       mrg }
    191  1.22       mrg 
    192  1.22       mrg 
    193  1.22       mrg static int
    194   1.6  christos ukyopon_ioctl(void *addr, int portno, u_long cmd, void *data, int flag,
    195  1.12    dyoung 	      proc_t *p)
    196   1.1     itohy {
    197   1.1     itohy 	struct ukyopon_softc *sc = addr;
    198   1.1     itohy 	struct ukyopon_identify *arg_id = (void*)data;
    199   1.1     itohy 	int error = 0;
    200   1.1     itohy 
    201   1.1     itohy 	switch (cmd) {
    202   1.1     itohy 	case UKYOPON_IDENTIFY:
    203  1.17     skrll 		strncpy(arg_id->ui_name, UKYOPON_NAME, sizeof(arg_id->ui_name));
    204   1.1     itohy 		arg_id->ui_busno =
    205  1.17     skrll 		    device_unit(sc->sc_umodem.sc_udev->ud_bus->ub_usbctl);
    206  1.17     skrll 		arg_id->ui_address = sc->sc_umodem.sc_udev->ud_addr;
    207   1.1     itohy 		arg_id->ui_model = UKYOPON_MODEL_UNKNOWN;
    208   1.2     itohy 		arg_id->ui_porttype = portno;
    209   1.1     itohy 		break;
    210   1.1     itohy 
    211   1.1     itohy 	default:
    212   1.1     itohy 		error = umodem_ioctl(addr, portno, cmd, data, flag, p);
    213   1.1     itohy 		break;
    214   1.1     itohy 	}
    215   1.1     itohy 
    216  1.20     skrll 	return error;
    217   1.1     itohy }
    218   1.1     itohy 
    219   1.1     itohy int
    220  1.12    dyoung ukyopon_activate(device_t self, enum devact act)
    221   1.1     itohy {
    222  1.10      cube 	struct ukyopon_softc *sc = device_private(self);
    223   1.1     itohy 
    224   1.1     itohy 	return umodem_common_activate(&sc->sc_umodem, act);
    225   1.1     itohy }
    226   1.1     itohy 
    227  1.17     skrll int
    228  1.12    dyoung ukyopon_detach(device_t self, int flags)
    229   1.1     itohy {
    230  1.12    dyoung 	struct ukyopon_softc *sc = device_private(self);
    231   1.1     itohy 
    232   1.1     itohy 	return umodem_common_detach(&sc->sc_umodem, flags);
    233   1.1     itohy }
    234