int uslcom_param(void *vsc, int portno, struct termios *t) { struct uslcom_softc *sc = (struct uslcom_softc *)vsc; usbd_status err; usb_device_request_t req; int data; if (t->c_ospeed <= 0 || t->c_ospeed > 921600) return (EINVAL); req.bmRequestType = USLCOM_WRITE; req.bRequest = USLCOM_BAUD_RATE; USETW(req.wValue, USLCOM_BAUD_REF / t->c_ospeed); USETW(req.wIndex, portno); USETW(req.wLength, 0); err = usbd_do_request(sc->sc_udev, &req, NULL); if (err) return (EIO); if (ISSET(t->c_cflag, CSTOPB)) data = USLCOM_STOP_BITS_2; else data = USLCOM_STOP_BITS_1; if (ISSET(t->c_cflag, PARENB)) { if (ISSET(t->c_cflag, PARODD)) data |= USLCOM_PARITY_ODD; else data |= USLCOM_PARITY_EVEN; } else data |= USLCOM_PARITY_NONE; switch (ISSET(t->c_cflag, CSIZE)) { case CS5: data |= USLCOM_SET_DATA_BITS(5); break; case CS6: data |= USLCOM_SET_DATA_BITS(6); break; case CS7: data |= USLCOM_SET_DATA_BITS(7); break; case CS8: data |= USLCOM_SET_DATA_BITS(8); break; } req.bmRequestType = USLCOM_WRITE; req.bRequest = USLCOM_DATA; USETW(req.wValue, data); USETW(req.wIndex, portno); USETW(req.wLength, 0); err = usbd_do_request(sc->sc_udev, &req, NULL); if (err) return (EIO); #if 0 /* XXX flow control */ if (ISSET(t->c_cflag, CRTSCTS)) /* rts/cts flow ctl */ } else if (ISSET(t->c_iflag, IXON|IXOFF)) {
int uslcom_param(void *vsc, int portno, struct termios *t) { struct uslcom_softc *sc = (struct uslcom_softc *)vsc; usbd_status err; usb_device_request_t req; uint32_t baudrate, flowctrl[4]; int data; if (t->c_ospeed <= 0 || t->c_ospeed > 921600) return (EINVAL); baudrate = t->c_ospeed; req.bmRequestType = USLCOM_WRITE; req.bRequest = USLCOM_SET_BAUD_RATE; USETW(req.wValue, 0); USETW(req.wIndex, portno); USETW(req.wLength, sizeof(baudrate)); err = usbd_do_request(sc->sc_udev, &req, &baudrate); if (err) return (EIO); if (ISSET(t->c_cflag, CSTOPB)) data = USLCOM_STOP_BITS_2; else data = USLCOM_STOP_BITS_1; if (ISSET(t->c_cflag, PARENB)) { if (ISSET(t->c_cflag, PARODD)) data |= USLCOM_PARITY_ODD; else data |= USLCOM_PARITY_EVEN; } else data |= USLCOM_PARITY_NONE; switch (ISSET(t->c_cflag, CSIZE)) { case CS5: data |= USLCOM_SET_DATA_BITS(5); break; case CS6: data |= USLCOM_SET_DATA_BITS(6); break; case CS7: data |= USLCOM_SET_DATA_BITS(7); break; case CS8: data |= USLCOM_SET_DATA_BITS(8); break; } req.bmRequestType = USLCOM_WRITE; req.bRequest = USLCOM_DATA; USETW(req.wValue, data); USETW(req.wIndex, portno); USETW(req.wLength, 0); err = usbd_do_request(sc->sc_udev, &req, NULL); if (err) return (EIO); if (ISSET(t->c_cflag, CRTSCTS)) { /* rts/cts flow ctl */ flowctrl[0] = htole32(USLCOM_FLOW_DTR_ON | USLCOM_FLOW_CTS_HS); flowctrl[1] = htole32(USLCOM_FLOW_RTS_HS); } else { /* disable flow ctl */ flowctrl[0] = htole32(USLCOM_FLOW_DTR_ON); flowctrl[1] = htole32(USLCOM_FLOW_RTS_ON); } flowctrl[2] = 0; flowctrl[3] = 0; req.bmRequestType = USLCOM_WRITE; req.bRequest = USLCOM_SET_FLOW; USETW(req.wValue, 0); USETW(req.wIndex, portno); USETW(req.wLength, sizeof(flowctrl)); err = usbd_do_request(sc->sc_udev, &req, flowctrl); if (err) return (EIO); return (0); }