102ac6454SAndrew Thompson /* $OpenBSD: uark.c,v 1.1 2006/08/14 08:30:22 jsg Exp $ */ 202ac6454SAndrew Thompson 302ac6454SAndrew Thompson /* 402ac6454SAndrew Thompson * Copyright (c) 2006 Jonathan Gray <jsg@openbsd.org> 502ac6454SAndrew Thompson * 602ac6454SAndrew Thompson * Permission to use, copy, modify, and distribute this software for any 702ac6454SAndrew Thompson * purpose with or without fee is hereby granted, provided that the above 802ac6454SAndrew Thompson * copyright notice and this permission notice appear in all copies. 902ac6454SAndrew Thompson * 1002ac6454SAndrew Thompson * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1102ac6454SAndrew Thompson * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1202ac6454SAndrew Thompson * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1302ac6454SAndrew Thompson * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1402ac6454SAndrew Thompson * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1502ac6454SAndrew Thompson * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1602ac6454SAndrew Thompson * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1702ac6454SAndrew Thompson * 1802ac6454SAndrew Thompson * $FreeBSD$ 1902ac6454SAndrew Thompson */ 2002ac6454SAndrew Thompson 2102ac6454SAndrew Thompson /* 2202ac6454SAndrew Thompson * NOTE: all function names beginning like "uark_cfg_" can only 2302ac6454SAndrew Thompson * be called from within the config thread function ! 2402ac6454SAndrew Thompson */ 2502ac6454SAndrew Thompson 2602ac6454SAndrew Thompson #include "usbdevs.h" 2702ac6454SAndrew Thompson #include <dev/usb/usb.h> 2802ac6454SAndrew Thompson #include <dev/usb/usb_mfunc.h> 2902ac6454SAndrew Thompson #include <dev/usb/usb_error.h> 3002ac6454SAndrew Thompson #include <dev/usb/usb_cdc.h> 3102ac6454SAndrew Thompson 3202ac6454SAndrew Thompson #define USB_DEBUG_VAR usb2_debug 3302ac6454SAndrew Thompson 3402ac6454SAndrew Thompson #include <dev/usb/usb_core.h> 3502ac6454SAndrew Thompson #include <dev/usb/usb_debug.h> 3602ac6454SAndrew Thompson #include <dev/usb/usb_process.h> 3702ac6454SAndrew Thompson #include <dev/usb/usb_request.h> 3802ac6454SAndrew Thompson #include <dev/usb/usb_lookup.h> 3902ac6454SAndrew Thompson #include <dev/usb/usb_util.h> 4002ac6454SAndrew Thompson 4102ac6454SAndrew Thompson #include <dev/usb/serial/usb_serial.h> 4202ac6454SAndrew Thompson 4302ac6454SAndrew Thompson #define UARK_BUF_SIZE 1024 /* bytes */ 4402ac6454SAndrew Thompson 4502ac6454SAndrew Thompson #define UARK_SET_DATA_BITS(x) ((x) - 5) 4602ac6454SAndrew Thompson 4702ac6454SAndrew Thompson #define UARK_PARITY_NONE 0x00 4802ac6454SAndrew Thompson #define UARK_PARITY_ODD 0x08 4902ac6454SAndrew Thompson #define UARK_PARITY_EVEN 0x18 5002ac6454SAndrew Thompson 5102ac6454SAndrew Thompson #define UARK_STOP_BITS_1 0x00 5202ac6454SAndrew Thompson #define UARK_STOP_BITS_2 0x04 5302ac6454SAndrew Thompson 5402ac6454SAndrew Thompson #define UARK_BAUD_REF 3000000 5502ac6454SAndrew Thompson 5602ac6454SAndrew Thompson #define UARK_WRITE 0x40 5702ac6454SAndrew Thompson #define UARK_READ 0xc0 5802ac6454SAndrew Thompson 5902ac6454SAndrew Thompson #define UARK_REQUEST 0xfe 6002ac6454SAndrew Thompson 6102ac6454SAndrew Thompson #define UARK_CONFIG_INDEX 0 6202ac6454SAndrew Thompson #define UARK_IFACE_INDEX 0 6302ac6454SAndrew Thompson 6402ac6454SAndrew Thompson enum { 6502ac6454SAndrew Thompson UARK_BULK_DT_WR, 6602ac6454SAndrew Thompson UARK_BULK_DT_RD, 6702ac6454SAndrew Thompson UARK_N_TRANSFER, 6802ac6454SAndrew Thompson }; 6902ac6454SAndrew Thompson 7002ac6454SAndrew Thompson struct uark_softc { 7102ac6454SAndrew Thompson struct usb2_com_super_softc sc_super_ucom; 7202ac6454SAndrew Thompson struct usb2_com_softc sc_ucom; 7302ac6454SAndrew Thompson 7402ac6454SAndrew Thompson struct usb2_xfer *sc_xfer[UARK_N_TRANSFER]; 7502ac6454SAndrew Thompson struct usb2_device *sc_udev; 7602ac6454SAndrew Thompson 7702ac6454SAndrew Thompson uint8_t sc_msr; 7802ac6454SAndrew Thompson uint8_t sc_lsr; 7902ac6454SAndrew Thompson }; 8002ac6454SAndrew Thompson 8102ac6454SAndrew Thompson /* prototypes */ 8202ac6454SAndrew Thompson 8302ac6454SAndrew Thompson static device_probe_t uark_probe; 8402ac6454SAndrew Thompson static device_attach_t uark_attach; 8502ac6454SAndrew Thompson static device_detach_t uark_detach; 8602ac6454SAndrew Thompson 8702ac6454SAndrew Thompson static usb2_callback_t uark_bulk_write_callback; 8802ac6454SAndrew Thompson static usb2_callback_t uark_bulk_read_callback; 8902ac6454SAndrew Thompson 9002ac6454SAndrew Thompson static void uark_start_read(struct usb2_com_softc *); 9102ac6454SAndrew Thompson static void uark_stop_read(struct usb2_com_softc *); 9202ac6454SAndrew Thompson static void uark_start_write(struct usb2_com_softc *); 9302ac6454SAndrew Thompson static void uark_stop_write(struct usb2_com_softc *); 9402ac6454SAndrew Thompson static int uark_pre_param(struct usb2_com_softc *, struct termios *); 9502ac6454SAndrew Thompson static void uark_cfg_param(struct usb2_com_softc *, struct termios *); 9602ac6454SAndrew Thompson static void uark_cfg_get_status(struct usb2_com_softc *, uint8_t *, 9702ac6454SAndrew Thompson uint8_t *); 9802ac6454SAndrew Thompson static void uark_cfg_set_break(struct usb2_com_softc *, uint8_t); 9902ac6454SAndrew Thompson static void uark_cfg_write(struct uark_softc *, uint16_t, uint16_t); 10002ac6454SAndrew Thompson 10102ac6454SAndrew Thompson static const struct usb2_config 10202ac6454SAndrew Thompson uark_xfer_config[UARK_N_TRANSFER] = { 10302ac6454SAndrew Thompson 10402ac6454SAndrew Thompson [UARK_BULK_DT_WR] = { 10502ac6454SAndrew Thompson .type = UE_BULK, 10602ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 10702ac6454SAndrew Thompson .direction = UE_DIR_OUT, 10802ac6454SAndrew Thompson .mh.bufsize = UARK_BUF_SIZE, 10902ac6454SAndrew Thompson .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 11002ac6454SAndrew Thompson .mh.callback = &uark_bulk_write_callback, 11102ac6454SAndrew Thompson }, 11202ac6454SAndrew Thompson 11302ac6454SAndrew Thompson [UARK_BULK_DT_RD] = { 11402ac6454SAndrew Thompson .type = UE_BULK, 11502ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 11602ac6454SAndrew Thompson .direction = UE_DIR_IN, 11702ac6454SAndrew Thompson .mh.bufsize = UARK_BUF_SIZE, 11802ac6454SAndrew Thompson .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 11902ac6454SAndrew Thompson .mh.callback = &uark_bulk_read_callback, 12002ac6454SAndrew Thompson }, 12102ac6454SAndrew Thompson }; 12202ac6454SAndrew Thompson 12302ac6454SAndrew Thompson static const struct usb2_com_callback uark_callback = { 12402ac6454SAndrew Thompson .usb2_com_cfg_get_status = &uark_cfg_get_status, 12502ac6454SAndrew Thompson .usb2_com_cfg_set_break = &uark_cfg_set_break, 12602ac6454SAndrew Thompson .usb2_com_cfg_param = &uark_cfg_param, 12702ac6454SAndrew Thompson .usb2_com_pre_param = &uark_pre_param, 12802ac6454SAndrew Thompson .usb2_com_start_read = &uark_start_read, 12902ac6454SAndrew Thompson .usb2_com_stop_read = &uark_stop_read, 13002ac6454SAndrew Thompson .usb2_com_start_write = &uark_start_write, 13102ac6454SAndrew Thompson .usb2_com_stop_write = &uark_stop_write, 13202ac6454SAndrew Thompson }; 13302ac6454SAndrew Thompson 13402ac6454SAndrew Thompson static device_method_t uark_methods[] = { 13502ac6454SAndrew Thompson /* Device methods */ 13602ac6454SAndrew Thompson DEVMETHOD(device_probe, uark_probe), 13702ac6454SAndrew Thompson DEVMETHOD(device_attach, uark_attach), 13802ac6454SAndrew Thompson DEVMETHOD(device_detach, uark_detach), 13902ac6454SAndrew Thompson {0, 0} 14002ac6454SAndrew Thompson }; 14102ac6454SAndrew Thompson 14202ac6454SAndrew Thompson static devclass_t uark_devclass; 14302ac6454SAndrew Thompson 14402ac6454SAndrew Thompson static driver_t uark_driver = { 14502ac6454SAndrew Thompson .name = "uark", 14602ac6454SAndrew Thompson .methods = uark_methods, 14702ac6454SAndrew Thompson .size = sizeof(struct uark_softc), 14802ac6454SAndrew Thompson }; 14902ac6454SAndrew Thompson 15002ac6454SAndrew Thompson DRIVER_MODULE(uark, ushub, uark_driver, uark_devclass, NULL, 0); 15102ac6454SAndrew Thompson MODULE_DEPEND(uark, ucom, 1, 1, 1); 15202ac6454SAndrew Thompson MODULE_DEPEND(uark, usb, 1, 1, 1); 15302ac6454SAndrew Thompson 15402ac6454SAndrew Thompson static const struct usb2_device_id uark_devs[] = { 15502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ARKMICRO, USB_PRODUCT_ARKMICRO_ARK3116, 0)}, 15602ac6454SAndrew Thompson }; 15702ac6454SAndrew Thompson 15802ac6454SAndrew Thompson static int 15902ac6454SAndrew Thompson uark_probe(device_t dev) 16002ac6454SAndrew Thompson { 16102ac6454SAndrew Thompson struct usb2_attach_arg *uaa = device_get_ivars(dev); 16202ac6454SAndrew Thompson 16302ac6454SAndrew Thompson if (uaa->usb2_mode != USB_MODE_HOST) { 16402ac6454SAndrew Thompson return (ENXIO); 16502ac6454SAndrew Thompson } 16602ac6454SAndrew Thompson if (uaa->info.bConfigIndex != 0) { 16702ac6454SAndrew Thompson return (ENXIO); 16802ac6454SAndrew Thompson } 16902ac6454SAndrew Thompson if (uaa->info.bIfaceIndex != UARK_IFACE_INDEX) { 17002ac6454SAndrew Thompson return (ENXIO); 17102ac6454SAndrew Thompson } 17202ac6454SAndrew Thompson return (usb2_lookup_id_by_uaa(uark_devs, sizeof(uark_devs), uaa)); 17302ac6454SAndrew Thompson } 17402ac6454SAndrew Thompson 17502ac6454SAndrew Thompson static int 17602ac6454SAndrew Thompson uark_attach(device_t dev) 17702ac6454SAndrew Thompson { 17802ac6454SAndrew Thompson struct usb2_attach_arg *uaa = device_get_ivars(dev); 17902ac6454SAndrew Thompson struct uark_softc *sc = device_get_softc(dev); 18002ac6454SAndrew Thompson int32_t error; 18102ac6454SAndrew Thompson uint8_t iface_index; 18202ac6454SAndrew Thompson 18302ac6454SAndrew Thompson device_set_usb2_desc(dev); 18402ac6454SAndrew Thompson 18502ac6454SAndrew Thompson sc->sc_udev = uaa->device; 18602ac6454SAndrew Thompson 18702ac6454SAndrew Thompson iface_index = UARK_IFACE_INDEX; 18802ac6454SAndrew Thompson error = usb2_transfer_setup 18902ac6454SAndrew Thompson (uaa->device, &iface_index, sc->sc_xfer, 19002ac6454SAndrew Thompson uark_xfer_config, UARK_N_TRANSFER, sc, &Giant); 19102ac6454SAndrew Thompson 19202ac6454SAndrew Thompson if (error) { 19302ac6454SAndrew Thompson device_printf(dev, "allocating control USB " 19402ac6454SAndrew Thompson "transfers failed!\n"); 19502ac6454SAndrew Thompson goto detach; 19602ac6454SAndrew Thompson } 19702ac6454SAndrew Thompson /* clear stall at first run */ 19802ac6454SAndrew Thompson usb2_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_WR]); 19902ac6454SAndrew Thompson usb2_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_RD]); 20002ac6454SAndrew Thompson 20102ac6454SAndrew Thompson error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 20202ac6454SAndrew Thompson &uark_callback, &Giant); 20302ac6454SAndrew Thompson if (error) { 20402ac6454SAndrew Thompson DPRINTF("usb2_com_attach failed\n"); 20502ac6454SAndrew Thompson goto detach; 20602ac6454SAndrew Thompson } 20702ac6454SAndrew Thompson return (0); /* success */ 20802ac6454SAndrew Thompson 20902ac6454SAndrew Thompson detach: 21002ac6454SAndrew Thompson uark_detach(dev); 21102ac6454SAndrew Thompson return (ENXIO); /* failure */ 21202ac6454SAndrew Thompson } 21302ac6454SAndrew Thompson 21402ac6454SAndrew Thompson static int 21502ac6454SAndrew Thompson uark_detach(device_t dev) 21602ac6454SAndrew Thompson { 21702ac6454SAndrew Thompson struct uark_softc *sc = device_get_softc(dev); 21802ac6454SAndrew Thompson 21902ac6454SAndrew Thompson usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1); 22002ac6454SAndrew Thompson 22102ac6454SAndrew Thompson usb2_transfer_unsetup(sc->sc_xfer, UARK_N_TRANSFER); 22202ac6454SAndrew Thompson 22302ac6454SAndrew Thompson return (0); 22402ac6454SAndrew Thompson } 22502ac6454SAndrew Thompson 22602ac6454SAndrew Thompson static void 22702ac6454SAndrew Thompson uark_bulk_write_callback(struct usb2_xfer *xfer) 22802ac6454SAndrew Thompson { 22902ac6454SAndrew Thompson struct uark_softc *sc = xfer->priv_sc; 23002ac6454SAndrew Thompson uint32_t actlen; 23102ac6454SAndrew Thompson 23202ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 23302ac6454SAndrew Thompson case USB_ST_SETUP: 23402ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 23502ac6454SAndrew Thompson tr_setup: 23602ac6454SAndrew Thompson if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0, 23702ac6454SAndrew Thompson UARK_BUF_SIZE, &actlen)) { 23802ac6454SAndrew Thompson xfer->frlengths[0] = actlen; 23902ac6454SAndrew Thompson usb2_start_hardware(xfer); 24002ac6454SAndrew Thompson } 24102ac6454SAndrew Thompson return; 24202ac6454SAndrew Thompson 24302ac6454SAndrew Thompson default: /* Error */ 24402ac6454SAndrew Thompson if (xfer->error != USB_ERR_CANCELLED) { 24502ac6454SAndrew Thompson /* try to clear stall first */ 24602ac6454SAndrew Thompson xfer->flags.stall_pipe = 1; 24702ac6454SAndrew Thompson goto tr_setup; 24802ac6454SAndrew Thompson } 24902ac6454SAndrew Thompson return; 25002ac6454SAndrew Thompson 25102ac6454SAndrew Thompson } 25202ac6454SAndrew Thompson } 25302ac6454SAndrew Thompson 25402ac6454SAndrew Thompson static void 25502ac6454SAndrew Thompson uark_bulk_read_callback(struct usb2_xfer *xfer) 25602ac6454SAndrew Thompson { 25702ac6454SAndrew Thompson struct uark_softc *sc = xfer->priv_sc; 25802ac6454SAndrew Thompson 25902ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 26002ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 26102ac6454SAndrew Thompson usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, 26202ac6454SAndrew Thompson xfer->actlen); 26302ac6454SAndrew Thompson 26402ac6454SAndrew Thompson case USB_ST_SETUP: 26502ac6454SAndrew Thompson tr_setup: 26602ac6454SAndrew Thompson xfer->frlengths[0] = xfer->max_data_length; 26702ac6454SAndrew Thompson usb2_start_hardware(xfer); 26802ac6454SAndrew Thompson return; 26902ac6454SAndrew Thompson 27002ac6454SAndrew Thompson default: /* Error */ 27102ac6454SAndrew Thompson if (xfer->error != USB_ERR_CANCELLED) { 27202ac6454SAndrew Thompson /* try to clear stall first */ 27302ac6454SAndrew Thompson xfer->flags.stall_pipe = 1; 27402ac6454SAndrew Thompson goto tr_setup; 27502ac6454SAndrew Thompson } 27602ac6454SAndrew Thompson return; 27702ac6454SAndrew Thompson } 27802ac6454SAndrew Thompson } 27902ac6454SAndrew Thompson 28002ac6454SAndrew Thompson static void 28102ac6454SAndrew Thompson uark_start_read(struct usb2_com_softc *ucom) 28202ac6454SAndrew Thompson { 28302ac6454SAndrew Thompson struct uark_softc *sc = ucom->sc_parent; 28402ac6454SAndrew Thompson 28502ac6454SAndrew Thompson usb2_transfer_start(sc->sc_xfer[UARK_BULK_DT_RD]); 28602ac6454SAndrew Thompson } 28702ac6454SAndrew Thompson 28802ac6454SAndrew Thompson static void 28902ac6454SAndrew Thompson uark_stop_read(struct usb2_com_softc *ucom) 29002ac6454SAndrew Thompson { 29102ac6454SAndrew Thompson struct uark_softc *sc = ucom->sc_parent; 29202ac6454SAndrew Thompson 29302ac6454SAndrew Thompson usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_RD]); 29402ac6454SAndrew Thompson } 29502ac6454SAndrew Thompson 29602ac6454SAndrew Thompson static void 29702ac6454SAndrew Thompson uark_start_write(struct usb2_com_softc *ucom) 29802ac6454SAndrew Thompson { 29902ac6454SAndrew Thompson struct uark_softc *sc = ucom->sc_parent; 30002ac6454SAndrew Thompson 30102ac6454SAndrew Thompson usb2_transfer_start(sc->sc_xfer[UARK_BULK_DT_WR]); 30202ac6454SAndrew Thompson } 30302ac6454SAndrew Thompson 30402ac6454SAndrew Thompson static void 30502ac6454SAndrew Thompson uark_stop_write(struct usb2_com_softc *ucom) 30602ac6454SAndrew Thompson { 30702ac6454SAndrew Thompson struct uark_softc *sc = ucom->sc_parent; 30802ac6454SAndrew Thompson 30902ac6454SAndrew Thompson usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_WR]); 31002ac6454SAndrew Thompson } 31102ac6454SAndrew Thompson 31202ac6454SAndrew Thompson static int 31302ac6454SAndrew Thompson uark_pre_param(struct usb2_com_softc *ucom, struct termios *t) 31402ac6454SAndrew Thompson { 31502ac6454SAndrew Thompson if ((t->c_ospeed < 300) || (t->c_ospeed > 115200)) 31602ac6454SAndrew Thompson return (EINVAL); 31702ac6454SAndrew Thompson return (0); 31802ac6454SAndrew Thompson } 31902ac6454SAndrew Thompson 32002ac6454SAndrew Thompson static void 32102ac6454SAndrew Thompson uark_cfg_param(struct usb2_com_softc *ucom, struct termios *t) 32202ac6454SAndrew Thompson { 32302ac6454SAndrew Thompson struct uark_softc *sc = ucom->sc_parent; 32402ac6454SAndrew Thompson uint32_t speed = t->c_ospeed; 32502ac6454SAndrew Thompson uint16_t data; 32602ac6454SAndrew Thompson 32702ac6454SAndrew Thompson /* 32802ac6454SAndrew Thompson * NOTE: When reverse computing the baud rate from the "data" all 32902ac6454SAndrew Thompson * allowed baud rates are within 3% of the initial baud rate. 33002ac6454SAndrew Thompson */ 33102ac6454SAndrew Thompson data = (UARK_BAUD_REF + (speed / 2)) / speed; 33202ac6454SAndrew Thompson 33302ac6454SAndrew Thompson uark_cfg_write(sc, 3, 0x83); 33402ac6454SAndrew Thompson uark_cfg_write(sc, 0, data & 0xFF); 33502ac6454SAndrew Thompson uark_cfg_write(sc, 1, data >> 8); 33602ac6454SAndrew Thompson uark_cfg_write(sc, 3, 0x03); 33702ac6454SAndrew Thompson 33802ac6454SAndrew Thompson if (t->c_cflag & CSTOPB) 33902ac6454SAndrew Thompson data = UARK_STOP_BITS_2; 34002ac6454SAndrew Thompson else 34102ac6454SAndrew Thompson data = UARK_STOP_BITS_1; 34202ac6454SAndrew Thompson 34302ac6454SAndrew Thompson if (t->c_cflag & PARENB) { 34402ac6454SAndrew Thompson if (t->c_cflag & PARODD) 34502ac6454SAndrew Thompson data |= UARK_PARITY_ODD; 34602ac6454SAndrew Thompson else 34702ac6454SAndrew Thompson data |= UARK_PARITY_EVEN; 34802ac6454SAndrew Thompson } else 34902ac6454SAndrew Thompson data |= UARK_PARITY_NONE; 35002ac6454SAndrew Thompson 35102ac6454SAndrew Thompson switch (t->c_cflag & CSIZE) { 35202ac6454SAndrew Thompson case CS5: 35302ac6454SAndrew Thompson data |= UARK_SET_DATA_BITS(5); 35402ac6454SAndrew Thompson break; 35502ac6454SAndrew Thompson case CS6: 35602ac6454SAndrew Thompson data |= UARK_SET_DATA_BITS(6); 35702ac6454SAndrew Thompson break; 35802ac6454SAndrew Thompson case CS7: 35902ac6454SAndrew Thompson data |= UARK_SET_DATA_BITS(7); 36002ac6454SAndrew Thompson break; 36102ac6454SAndrew Thompson default: 36202ac6454SAndrew Thompson case CS8: 36302ac6454SAndrew Thompson data |= UARK_SET_DATA_BITS(8); 36402ac6454SAndrew Thompson break; 36502ac6454SAndrew Thompson } 36602ac6454SAndrew Thompson uark_cfg_write(sc, 3, 0x00); 36702ac6454SAndrew Thompson uark_cfg_write(sc, 3, data); 36802ac6454SAndrew Thompson } 36902ac6454SAndrew Thompson 37002ac6454SAndrew Thompson static void 37102ac6454SAndrew Thompson uark_cfg_get_status(struct usb2_com_softc *ucom, uint8_t *lsr, uint8_t *msr) 37202ac6454SAndrew Thompson { 37302ac6454SAndrew Thompson struct uark_softc *sc = ucom->sc_parent; 37402ac6454SAndrew Thompson 37502ac6454SAndrew Thompson *lsr = sc->sc_lsr; 37602ac6454SAndrew Thompson *msr = sc->sc_msr; 37702ac6454SAndrew Thompson } 37802ac6454SAndrew Thompson 37902ac6454SAndrew Thompson static void 38002ac6454SAndrew Thompson uark_cfg_set_break(struct usb2_com_softc *ucom, uint8_t onoff) 38102ac6454SAndrew Thompson { 38202ac6454SAndrew Thompson struct uark_softc *sc = ucom->sc_parent; 38302ac6454SAndrew Thompson 38402ac6454SAndrew Thompson DPRINTF("onoff=%d\n", onoff); 38502ac6454SAndrew Thompson 38602ac6454SAndrew Thompson uark_cfg_write(sc, 4, onoff ? 0x01 : 0x00); 38702ac6454SAndrew Thompson } 38802ac6454SAndrew Thompson 38902ac6454SAndrew Thompson static void 39002ac6454SAndrew Thompson uark_cfg_write(struct uark_softc *sc, uint16_t index, uint16_t value) 39102ac6454SAndrew Thompson { 39202ac6454SAndrew Thompson struct usb2_device_request req; 39302ac6454SAndrew Thompson usb2_error_t err; 39402ac6454SAndrew Thompson 39502ac6454SAndrew Thompson req.bmRequestType = UARK_WRITE; 39602ac6454SAndrew Thompson req.bRequest = UARK_REQUEST; 39702ac6454SAndrew Thompson USETW(req.wValue, value); 39802ac6454SAndrew Thompson USETW(req.wIndex, index); 39902ac6454SAndrew Thompson USETW(req.wLength, 0); 40002ac6454SAndrew Thompson 40102ac6454SAndrew Thompson err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 40202ac6454SAndrew Thompson &req, NULL, 0, 1000); 40302ac6454SAndrew Thompson if (err) { 40402ac6454SAndrew Thompson DPRINTFN(0, "device request failed, err=%s " 40502ac6454SAndrew Thompson "(ignored)\n", usb2_errstr(err)); 40602ac6454SAndrew Thompson } 40702ac6454SAndrew Thompson } 408