1 1.26 simonb /* $NetBSD: ukyopon.c,v 1.26 2020/04/12 01:10:54 simonb 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.26 simonb __KERNEL_RCSID(0, "$NetBSD: ukyopon.c,v 1.26 2020/04/12 01:10:54 simonb 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.25 maxv static const 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.23 mrg 109 1.18 msaitoh CFATTACH_DECL_NEW(ukyopon, sizeof(struct ukyopon_softc), ukyopon_match, 110 1.24 mrg ukyopon_attach, ukyopon_detach, NULL); 111 1.1 itohy 112 1.22 mrg static int 113 1.12 dyoung ukyopon_match(device_t parent, cfdata_t match, void *aux) 114 1.1 itohy { 115 1.17 skrll struct usbif_attach_arg *uiaa = aux; 116 1.1 itohy 117 1.17 skrll if (uiaa->uiaa_vendor == USB_VENDOR_KYOCERA && 118 1.17 skrll uiaa->uiaa_product == USB_PRODUCT_KYOCERA_AHK3001V && 119 1.17 skrll (uiaa->uiaa_ifaceno == UKYOPON_MODEM_IFACE_INDEX || 120 1.17 skrll uiaa->uiaa_ifaceno == UKYOPON_DATA_IFACE_INDEX)) 121 1.20 skrll return UMATCH_VENDOR_PRODUCT; 122 1.1 itohy 123 1.20 skrll return UMATCH_NONE; 124 1.1 itohy } 125 1.1 itohy 126 1.22 mrg static void 127 1.12 dyoung ukyopon_attach(device_t parent, device_t self, void *aux) 128 1.1 itohy { 129 1.12 dyoung struct ukyopon_softc *sc = device_private(self); 130 1.17 skrll struct usbif_attach_arg *uiaa = aux; 131 1.17 skrll struct ucom_attach_args ucaa; 132 1.1 itohy 133 1.26 simonb memset(&ucaa, 0, sizeof(ucaa)); 134 1.26 simonb 135 1.17 skrll ucaa.ucaa_portno = (uiaa->uiaa_ifaceno == UKYOPON_MODEM_IFACE_INDEX) ? 136 1.1 itohy UKYOPON_PORT_MODEM : UKYOPON_PORT_DATA; 137 1.17 skrll ucaa.ucaa_methods = &ukyopon_methods; 138 1.17 skrll ucaa.ucaa_info = (uiaa->uiaa_ifaceno == UKYOPON_MODEM_IFACE_INDEX) ? 139 1.1 itohy "modem port" : "data transfer port"; 140 1.1 itohy 141 1.17 skrll if (umodem_common_attach(self, &sc->sc_umodem, uiaa, &ucaa)) 142 1.12 dyoung return; 143 1.12 dyoung return; 144 1.1 itohy } 145 1.1 itohy 146 1.22 mrg static void 147 1.3 itohy ukyopon_get_status(void *addr, int portno, u_char *lsr, u_char *msr) 148 1.3 itohy { 149 1.3 itohy struct ukyopon_softc *sc = addr; 150 1.3 itohy 151 1.3 itohy /* 152 1.3 itohy * The device doesn't set DCD (Data Carrier Detect) bit properly. 153 1.3 itohy * Assume DCD is always present. 154 1.3 itohy */ 155 1.3 itohy if ((sc->sc_umodem.sc_msr & UMSR_DCD) == 0) 156 1.3 itohy sc->sc_umodem.sc_msr |= UMSR_DCD; 157 1.3 itohy 158 1.24 mrg umodem_get_status(&sc->sc_umodem, portno, lsr, msr); 159 1.3 itohy } 160 1.3 itohy 161 1.22 mrg static void 162 1.22 mrg ukyopon_set(void *addr, int portno, int reg, int onoff) 163 1.22 mrg { 164 1.22 mrg struct ukyopon_softc *sc = addr; 165 1.22 mrg 166 1.22 mrg umodem_set(&sc->sc_umodem, portno, reg, onoff); 167 1.22 mrg } 168 1.22 mrg 169 1.22 mrg static int 170 1.22 mrg ukyopon_param(void *addr, int portno, struct termios *t) 171 1.22 mrg { 172 1.22 mrg struct ukyopon_softc *sc = addr; 173 1.22 mrg 174 1.22 mrg return umodem_param(&sc->sc_umodem, portno, t); 175 1.22 mrg } 176 1.22 mrg 177 1.22 mrg static int 178 1.22 mrg ukyopon_open(void *addr, int portno) 179 1.22 mrg { 180 1.22 mrg struct ukyopon_softc *sc = addr; 181 1.22 mrg 182 1.22 mrg return umodem_open(&sc->sc_umodem, portno); 183 1.22 mrg } 184 1.22 mrg 185 1.22 mrg static void 186 1.22 mrg ukyopon_close(void *addr, int portno) 187 1.22 mrg { 188 1.22 mrg struct ukyopon_softc *sc = addr; 189 1.22 mrg 190 1.22 mrg umodem_close(&sc->sc_umodem, portno); 191 1.22 mrg } 192 1.22 mrg 193 1.22 mrg 194 1.22 mrg static int 195 1.6 christos ukyopon_ioctl(void *addr, int portno, u_long cmd, void *data, int flag, 196 1.12 dyoung proc_t *p) 197 1.1 itohy { 198 1.1 itohy struct ukyopon_softc *sc = addr; 199 1.1 itohy struct ukyopon_identify *arg_id = (void*)data; 200 1.1 itohy int error = 0; 201 1.1 itohy 202 1.1 itohy switch (cmd) { 203 1.1 itohy case UKYOPON_IDENTIFY: 204 1.17 skrll strncpy(arg_id->ui_name, UKYOPON_NAME, sizeof(arg_id->ui_name)); 205 1.1 itohy arg_id->ui_busno = 206 1.17 skrll device_unit(sc->sc_umodem.sc_udev->ud_bus->ub_usbctl); 207 1.17 skrll arg_id->ui_address = sc->sc_umodem.sc_udev->ud_addr; 208 1.1 itohy arg_id->ui_model = UKYOPON_MODEL_UNKNOWN; 209 1.2 itohy arg_id->ui_porttype = portno; 210 1.1 itohy break; 211 1.1 itohy 212 1.1 itohy default: 213 1.24 mrg error = umodem_ioctl(&sc->sc_umodem, portno, cmd, data, flag, p); 214 1.1 itohy break; 215 1.1 itohy } 216 1.1 itohy 217 1.20 skrll return error; 218 1.1 itohy } 219 1.1 itohy 220 1.1 itohy int 221 1.12 dyoung ukyopon_detach(device_t self, int flags) 222 1.1 itohy { 223 1.12 dyoung struct ukyopon_softc *sc = device_private(self); 224 1.1 itohy 225 1.1 itohy return umodem_common_detach(&sc->sc_umodem, flags); 226 1.1 itohy } 227