1 /* $OpenBSD: uslcom.c,v 1.17 2007/11/24 10:52:12 jsg Exp $ */
4 * Copyright (c) 2006 Jonathan Gray <jsg@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/stdint.h>
20 #include <sys/param.h>
21 #include <sys/queue.h>
22 #include <sys/types.h>
23 #include <sys/systm.h>
24 #include <sys/kernel.h>
26 #include <sys/module.h>
28 #include <sys/condvar.h>
29 #include <sys/sysctl.h>
30 #include <sys/unistd.h>
31 #include <sys/callout.h>
32 #include <sys/malloc.h>
35 #include <bus/u4b/usb.h>
36 #include <bus/u4b/usbdi.h>
37 #include <bus/u4b/usbdi_util.h>
38 #include <bus/u4b/usb_ioctl.h>
39 #include <bus/u4b/usbdevs.h>
41 #define USB_DEBUG_VAR uslcom_debug
42 #include <bus/u4b/usb_debug.h>
43 #include <bus/u4b/usb_process.h>
45 #include <bus/u4b/serial/usb_serial.h>
48 static int uslcom_debug = 0;
50 static SYSCTL_NODE(_hw_usb, OID_AUTO, uslcom, CTLFLAG_RW, 0, "USB uslcom");
51 SYSCTL_INT(_hw_usb_uslcom, OID_AUTO, debug, CTLFLAG_RW,
52 &uslcom_debug, 0, "Debug level");
55 #define USLCOM_BULK_BUF_SIZE 1024
56 #define USLCOM_CONFIG_INDEX 0
57 #define USLCOM_IFACE_INDEX 0
59 #define USLCOM_SET_DATA_BITS(x) ((x) << 8)
62 #define USLCOM_WRITE 0x41
63 #define USLCOM_READ 0xc1
66 #define USLCOM_UART 0x00
67 #define USLCOM_BAUD_RATE 0x01
68 #define USLCOM_DATA 0x03
69 #define USLCOM_BREAK 0x05
70 #define USLCOM_CTRL 0x07
71 #define USLCOM_RCTRL 0x08
72 #define USLCOM_SET_FLOWCTRL 0x13
73 #define USLCOM_VENDOR_SPECIFIC 0xff
75 /* USLCOM_UART values */
76 #define USLCOM_UART_DISABLE 0x00
77 #define USLCOM_UART_ENABLE 0x01
79 /* USLCOM_CTRL/USLCOM_RCTRL values */
80 #define USLCOM_CTRL_DTR_ON 0x0001
81 #define USLCOM_CTRL_DTR_SET 0x0100
82 #define USLCOM_CTRL_RTS_ON 0x0002
83 #define USLCOM_CTRL_RTS_SET 0x0200
84 #define USLCOM_CTRL_CTS 0x0010
85 #define USLCOM_CTRL_DSR 0x0020
86 #define USLCOM_CTRL_RI 0x0040
87 #define USLCOM_CTRL_DCD 0x0080
89 /* USLCOM_BAUD_RATE values */
90 #define USLCOM_BAUD_REF 0x384000
92 /* USLCOM_DATA values */
93 #define USLCOM_STOP_BITS_1 0x00
94 #define USLCOM_STOP_BITS_2 0x02
95 #define USLCOM_PARITY_NONE 0x00
96 #define USLCOM_PARITY_ODD 0x10
97 #define USLCOM_PARITY_EVEN 0x20
99 #define USLCOM_PORT_NO 0x0000
101 /* USLCOM_BREAK values */
102 #define USLCOM_BREAK_OFF 0x00
103 #define USLCOM_BREAK_ON 0x01
105 /* USLCOM_SET_FLOWCTRL values - 1st word */
106 #define USLCOM_FLOW_DTR_ON 0x00000001 /* DTR static active */
107 #define USLCOM_FLOW_CTS_HS 0x00000008 /* CTS handshake */
108 /* USLCOM_SET_FLOWCTRL values - 2nd word */
109 #define USLCOM_FLOW_RTS_ON 0x00000040 /* RTS static active */
110 #define USLCOM_FLOW_RTS_HS 0x00000080 /* RTS handshake */
112 /* USLCOM_VENDOR_SPECIFIC values */
113 #define USLCOM_WRITE_LATCH 0x37E1
114 #define USLCOM_READ_LATCH 0x00C2
123 struct uslcom_softc {
124 struct ucom_super_softc sc_super_ucom;
125 struct ucom_softc sc_ucom;
126 struct usb_callout sc_watchdog;
128 struct usb_xfer *sc_xfer[USLCOM_N_TRANSFER];
129 struct usb_device *sc_udev;
136 static device_probe_t uslcom_probe;
137 static device_attach_t uslcom_attach;
138 static device_detach_t uslcom_detach;
140 static usb_callback_t uslcom_write_callback;
141 static usb_callback_t uslcom_read_callback;
142 static usb_callback_t uslcom_control_callback;
144 static void uslcom_open(struct ucom_softc *);
145 static void uslcom_close(struct ucom_softc *);
146 static void uslcom_set_dtr(struct ucom_softc *, uint8_t);
147 static void uslcom_set_rts(struct ucom_softc *, uint8_t);
148 static void uslcom_set_break(struct ucom_softc *, uint8_t);
149 static int uslcom_ioctl(struct ucom_softc *, uint32_t, caddr_t, int,
151 static int uslcom_pre_param(struct ucom_softc *, struct termios *);
152 static void uslcom_param(struct ucom_softc *, struct termios *);
153 static void uslcom_get_status(struct ucom_softc *, uint8_t *, uint8_t *);
154 static void uslcom_start_read(struct ucom_softc *);
155 static void uslcom_stop_read(struct ucom_softc *);
156 static void uslcom_start_write(struct ucom_softc *);
157 static void uslcom_stop_write(struct ucom_softc *);
158 static void uslcom_poll(struct ucom_softc *ucom);
160 static const struct usb_config uslcom_config[USLCOM_N_TRANSFER] = {
162 [USLCOM_BULK_DT_WR] = {
164 .endpoint = UE_ADDR_ANY,
165 .direction = UE_DIR_OUT,
166 .bufsize = USLCOM_BULK_BUF_SIZE,
167 .flags = {.pipe_bof = 1,},
168 .callback = &uslcom_write_callback,
171 [USLCOM_BULK_DT_RD] = {
173 .endpoint = UE_ADDR_ANY,
174 .direction = UE_DIR_IN,
175 .bufsize = USLCOM_BULK_BUF_SIZE,
176 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
177 .callback = &uslcom_read_callback,
179 [USLCOM_CTRL_DT_RD] = {
182 .direction = UE_DIR_ANY,
183 .bufsize = sizeof(struct usb_device_request) + 8,
184 .flags = {.pipe_bof = 1,},
185 .callback = &uslcom_control_callback,
186 .timeout = 1000, /* 1 second timeout */
190 static struct ucom_callback uslcom_callback = {
191 .ucom_cfg_open = &uslcom_open,
192 .ucom_cfg_close = &uslcom_close,
193 .ucom_cfg_get_status = &uslcom_get_status,
194 .ucom_cfg_set_dtr = &uslcom_set_dtr,
195 .ucom_cfg_set_rts = &uslcom_set_rts,
196 .ucom_cfg_set_break = &uslcom_set_break,
197 .ucom_ioctl = &uslcom_ioctl,
198 .ucom_cfg_param = &uslcom_param,
199 .ucom_pre_param = &uslcom_pre_param,
200 .ucom_start_read = &uslcom_start_read,
201 .ucom_stop_read = &uslcom_stop_read,
202 .ucom_start_write = &uslcom_start_write,
203 .ucom_stop_write = &uslcom_stop_write,
204 .ucom_poll = &uslcom_poll,
207 static const STRUCT_USB_HOST_ID uslcom_devs[] = {
208 #define USLCOM_DEV(v,p) { USB_VP(USB_VENDOR_##v, USB_PRODUCT_##v##_##p) }
209 USLCOM_DEV(BALTECH, CARDREADER),
210 USLCOM_DEV(CLIPSAL, 5500PCU),
211 USLCOM_DEV(DATAAPEX, MULTICOM),
212 USLCOM_DEV(DELL, DW700),
213 USLCOM_DEV(DIGIANSWER, ZIGBEE802154),
214 USLCOM_DEV(DYNASTREAM, ANTDEVBOARD),
215 USLCOM_DEV(DYNASTREAM, ANTDEVBOARD2),
216 USLCOM_DEV(DYNASTREAM, ANT2USB),
217 USLCOM_DEV(ELV, USBI2C),
218 USLCOM_DEV(FOXCONN, PIRELLI_DP_L10),
219 USLCOM_DEV(FOXCONN, TCOM_TC_300),
220 USLCOM_DEV(GEMALTO, PROXPU),
221 USLCOM_DEV(JABLOTRON, PC60B),
222 USLCOM_DEV(MEI, CASHFLOW_SC),
223 USLCOM_DEV(MEI, S2000),
224 USLCOM_DEV(JABLOTRON, PC60B),
225 USLCOM_DEV(OWEN, AC4),
226 USLCOM_DEV(PHILIPS, ACE1001),
227 USLCOM_DEV(PLX, CA42),
228 USLCOM_DEV(RENESAS, RX610),
229 USLCOM_DEV(SILABS, AEROCOMM),
230 USLCOM_DEV(SILABS, AMBER_AMB2560),
231 USLCOM_DEV(SILABS, ARGUSISP),
232 USLCOM_DEV(SILABS, ARKHAM_DS101_A),
233 USLCOM_DEV(SILABS, ARKHAM_DS101_M),
234 USLCOM_DEV(SILABS, ARYGON_MIFARE),
235 USLCOM_DEV(SILABS, AVIT_USB_TTL),
236 USLCOM_DEV(SILABS, B_G_H3000),
237 USLCOM_DEV(SILABS, BALLUFF_RFID),
238 USLCOM_DEV(SILABS, BEI_VCP),
239 USLCOM_DEV(SILABS, BSM7DUSB),
240 USLCOM_DEV(SILABS, BURNSIDE),
241 USLCOM_DEV(SILABS, C2_EDGE_MODEM),
242 USLCOM_DEV(SILABS, CP2102),
243 USLCOM_DEV(SILABS, CP210X_2),
244 USLCOM_DEV(SILABS, CRUMB128),
245 USLCOM_DEV(SILABS, CYGNAL),
246 USLCOM_DEV(SILABS, CYGNAL_DEBUG),
247 USLCOM_DEV(SILABS, CYGNAL_GPS),
248 USLCOM_DEV(SILABS, DEGREE),
249 USLCOM_DEV(SILABS, EMS_C1007),
250 USLCOM_DEV(SILABS, HELICOM),
251 USLCOM_DEV(SILABS, IMS_USB_RS422),
252 USLCOM_DEV(SILABS, INFINITY_MIC),
253 USLCOM_DEV(SILABS, INSYS_MODEM),
254 USLCOM_DEV(SILABS, KYOCERA_GPS),
255 USLCOM_DEV(SILABS, LIPOWSKY_HARP),
256 USLCOM_DEV(SILABS, LIPOWSKY_JTAG),
257 USLCOM_DEV(SILABS, LIPOWSKY_LIN),
258 USLCOM_DEV(SILABS, MC35PU),
259 USLCOM_DEV(SILABS, MJS_TOSLINK),
260 USLCOM_DEV(SILABS, MSD_DASHHAWK),
261 USLCOM_DEV(SILABS, POLOLU),
262 USLCOM_DEV(SILABS, PROCYON_AVS),
263 USLCOM_DEV(SILABS, SB_PARAMOUNT_ME),
264 USLCOM_DEV(SILABS, SUUNTO),
265 USLCOM_DEV(SILABS, TAMSMASTER),
266 USLCOM_DEV(SILABS, TELEGESIS_ETRX2),
267 USLCOM_DEV(SILABS, TRACIENT),
268 USLCOM_DEV(SILABS, TRAQMATE),
269 USLCOM_DEV(SILABS, USBCOUNT50),
270 USLCOM_DEV(SILABS, USBPULSE100),
271 USLCOM_DEV(SILABS, USBSCOPE50),
272 USLCOM_DEV(SILABS, USBWAVE12),
273 USLCOM_DEV(SILABS, VSTABI),
274 USLCOM_DEV(SILABS, WAVIT),
275 USLCOM_DEV(SILABS, WMRBATT),
276 USLCOM_DEV(SILABS, WMRRIGBLASTER),
277 USLCOM_DEV(SILABS, WMRRIGTALK),
278 USLCOM_DEV(SILABS, ZEPHYR_BIO),
279 USLCOM_DEV(SILABS2, DCU11CLONE),
280 USLCOM_DEV(SILABS3, GPRS_MODEM),
281 USLCOM_DEV(SILABS4, 100EU_MODEM),
282 USLCOM_DEV(SYNTECH, CYPHERLAB100),
283 USLCOM_DEV(USI, MC60),
284 USLCOM_DEV(VAISALA, CABLE),
285 USLCOM_DEV(WAGO, SERVICECABLE),
286 USLCOM_DEV(WAVESENSE, JAZZ),
287 USLCOM_DEV(WIENERPLEINBAUS, PL512),
288 USLCOM_DEV(WIENERPLEINBAUS, RCM),
289 USLCOM_DEV(WIENERPLEINBAUS, MPOD),
290 USLCOM_DEV(WIENERPLEINBAUS, CML),
294 static device_method_t uslcom_methods[] = {
295 DEVMETHOD(device_probe, uslcom_probe),
296 DEVMETHOD(device_attach, uslcom_attach),
297 DEVMETHOD(device_detach, uslcom_detach),
301 static devclass_t uslcom_devclass;
303 static driver_t uslcom_driver = {
305 .methods = uslcom_methods,
306 .size = sizeof(struct uslcom_softc),
309 DRIVER_MODULE(uslcom, uhub, uslcom_driver, uslcom_devclass, NULL, 0);
310 MODULE_DEPEND(uslcom, ucom, 1, 1, 1);
311 MODULE_DEPEND(uslcom, usb, 1, 1, 1);
312 MODULE_VERSION(uslcom, 1);
315 uslcom_watchdog(void *arg)
317 struct uslcom_softc *sc = arg;
319 KKASSERT(lockowned(&sc->sc_lock));
321 usbd_transfer_start(sc->sc_xfer[USLCOM_CTRL_DT_RD]);
323 usb_callout_reset(&sc->sc_watchdog,
324 hz / 4, &uslcom_watchdog, sc);
328 uslcom_probe(device_t dev)
330 struct usb_attach_arg *uaa = device_get_ivars(dev);
334 if (uaa->usb_mode != USB_MODE_HOST) {
337 if (uaa->info.bConfigIndex != USLCOM_CONFIG_INDEX) {
340 if (uaa->info.bIfaceIndex != USLCOM_IFACE_INDEX) {
343 return (usbd_lookup_id_by_uaa(uslcom_devs, sizeof(uslcom_devs), uaa));
347 uslcom_attach(device_t dev)
349 struct usb_attach_arg *uaa = device_get_ivars(dev);
350 struct uslcom_softc *sc = device_get_softc(dev);
355 device_set_usb_desc(dev);
356 lockinit(&sc->sc_lock, "uslcom", 0, LK_CANRECURSE);
357 usb_callout_init_mtx(&sc->sc_watchdog, &sc->sc_lock, 0);
359 sc->sc_udev = uaa->device;
361 error = usbd_transfer_setup(uaa->device,
362 &uaa->info.bIfaceIndex, sc->sc_xfer, uslcom_config,
363 USLCOM_N_TRANSFER, sc, &sc->sc_lock);
365 DPRINTF("one or more missing USB endpoints, "
366 "error=%s\n", usbd_errstr(error));
369 /* clear stall at first run */
370 lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
371 usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_WR]);
372 usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_RD]);
373 lockmgr(&sc->sc_lock, LK_RELEASE);
375 error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
376 &uslcom_callback, &sc->sc_lock);
380 ucom_set_pnpinfo_usb(&sc->sc_super_ucom, dev);
390 uslcom_detach(device_t dev)
392 struct uslcom_softc *sc = device_get_softc(dev);
394 DPRINTF("sc=%p\n", sc);
396 ucom_detach(&sc->sc_super_ucom, &sc->sc_ucom);
397 usbd_transfer_unsetup(sc->sc_xfer, USLCOM_N_TRANSFER);
399 usb_callout_drain(&sc->sc_watchdog);
400 lockuninit(&sc->sc_lock);
406 uslcom_open(struct ucom_softc *ucom)
408 struct uslcom_softc *sc = ucom->sc_parent;
409 struct usb_device_request req;
411 req.bmRequestType = USLCOM_WRITE;
412 req.bRequest = USLCOM_UART;
413 USETW(req.wValue, USLCOM_UART_ENABLE);
414 USETW(req.wIndex, USLCOM_PORT_NO);
415 USETW(req.wLength, 0);
417 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
418 &req, NULL, 0, 1000)) {
419 DPRINTF("UART enable failed (ignored)\n");
422 /* start polling status */
427 uslcom_close(struct ucom_softc *ucom)
429 struct uslcom_softc *sc = ucom->sc_parent;
430 struct usb_device_request req;
432 /* stop polling status */
433 usb_callout_stop(&sc->sc_watchdog);
435 req.bmRequestType = USLCOM_WRITE;
436 req.bRequest = USLCOM_UART;
437 USETW(req.wValue, USLCOM_UART_DISABLE);
438 USETW(req.wIndex, USLCOM_PORT_NO);
439 USETW(req.wLength, 0);
441 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
442 &req, NULL, 0, 1000)) {
443 DPRINTF("UART disable failed (ignored)\n");
448 uslcom_set_dtr(struct ucom_softc *ucom, uint8_t onoff)
450 struct uslcom_softc *sc = ucom->sc_parent;
451 struct usb_device_request req;
454 DPRINTF("onoff = %d\n", onoff);
456 ctl = onoff ? USLCOM_CTRL_DTR_ON : 0;
457 ctl |= USLCOM_CTRL_DTR_SET;
459 req.bmRequestType = USLCOM_WRITE;
460 req.bRequest = USLCOM_CTRL;
461 USETW(req.wValue, ctl);
462 USETW(req.wIndex, USLCOM_PORT_NO);
463 USETW(req.wLength, 0);
465 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
466 &req, NULL, 0, 1000)) {
467 DPRINTF("Setting DTR failed (ignored)\n");
472 uslcom_set_rts(struct ucom_softc *ucom, uint8_t onoff)
474 struct uslcom_softc *sc = ucom->sc_parent;
475 struct usb_device_request req;
478 DPRINTF("onoff = %d\n", onoff);
480 ctl = onoff ? USLCOM_CTRL_RTS_ON : 0;
481 ctl |= USLCOM_CTRL_RTS_SET;
483 req.bmRequestType = USLCOM_WRITE;
484 req.bRequest = USLCOM_CTRL;
485 USETW(req.wValue, ctl);
486 USETW(req.wIndex, USLCOM_PORT_NO);
487 USETW(req.wLength, 0);
489 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
490 &req, NULL, 0, 1000)) {
491 DPRINTF("Setting DTR failed (ignored)\n");
496 uslcom_pre_param(struct ucom_softc *ucom, struct termios *t)
498 if (t->c_ospeed <= 0 || t->c_ospeed > 921600)
504 uslcom_param(struct ucom_softc *ucom, struct termios *t)
506 struct uslcom_softc *sc = ucom->sc_parent;
507 struct usb_device_request req;
508 uint32_t flowctrl[4];
513 req.bmRequestType = USLCOM_WRITE;
514 req.bRequest = USLCOM_BAUD_RATE;
515 USETW(req.wValue, USLCOM_BAUD_REF / t->c_ospeed);
516 USETW(req.wIndex, USLCOM_PORT_NO);
517 USETW(req.wLength, 0);
519 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
520 &req, NULL, 0, 1000)) {
521 DPRINTF("Set baudrate failed (ignored)\n");
524 if (t->c_cflag & CSTOPB)
525 data = USLCOM_STOP_BITS_2;
527 data = USLCOM_STOP_BITS_1;
528 if (t->c_cflag & PARENB) {
529 if (t->c_cflag & PARODD)
530 data |= USLCOM_PARITY_ODD;
532 data |= USLCOM_PARITY_EVEN;
534 data |= USLCOM_PARITY_NONE;
535 switch (t->c_cflag & CSIZE) {
537 data |= USLCOM_SET_DATA_BITS(5);
540 data |= USLCOM_SET_DATA_BITS(6);
543 data |= USLCOM_SET_DATA_BITS(7);
546 data |= USLCOM_SET_DATA_BITS(8);
550 req.bmRequestType = USLCOM_WRITE;
551 req.bRequest = USLCOM_DATA;
552 USETW(req.wValue, data);
553 USETW(req.wIndex, USLCOM_PORT_NO);
554 USETW(req.wLength, 0);
556 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
557 &req, NULL, 0, 1000)) {
558 DPRINTF("Set format failed (ignored)\n");
561 if (t->c_cflag & CRTSCTS) {
562 flowctrl[0] = htole32(USLCOM_FLOW_DTR_ON | USLCOM_FLOW_CTS_HS);
563 flowctrl[1] = htole32(USLCOM_FLOW_RTS_HS);
567 flowctrl[0] = htole32(USLCOM_FLOW_DTR_ON);
568 flowctrl[1] = htole32(USLCOM_FLOW_RTS_ON);
572 req.bmRequestType = USLCOM_WRITE;
573 req.bRequest = USLCOM_SET_FLOWCTRL;
574 USETW(req.wValue, 0);
575 USETW(req.wIndex, USLCOM_PORT_NO);
576 USETW(req.wLength, sizeof(flowctrl));
578 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
579 &req, flowctrl, 0, 1000)) {
580 DPRINTF("Set flowcontrol failed (ignored)\n");
585 uslcom_get_status(struct ucom_softc *ucom, uint8_t *lsr, uint8_t *msr)
587 struct uslcom_softc *sc = ucom->sc_parent;
596 uslcom_set_break(struct ucom_softc *ucom, uint8_t onoff)
598 struct uslcom_softc *sc = ucom->sc_parent;
599 struct usb_device_request req;
600 uint16_t brk = onoff ? USLCOM_BREAK_ON : USLCOM_BREAK_OFF;
602 req.bmRequestType = USLCOM_WRITE;
603 req.bRequest = USLCOM_BREAK;
604 USETW(req.wValue, brk);
605 USETW(req.wIndex, USLCOM_PORT_NO);
606 USETW(req.wLength, 0);
608 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
609 &req, NULL, 0, 1000)) {
610 DPRINTF("Set BREAK failed (ignored)\n");
615 uslcom_ioctl(struct ucom_softc *ucom, uint32_t cmd, caddr_t data,
616 int flag, struct thread *td)
618 struct uslcom_softc *sc = ucom->sc_parent;
619 struct usb_device_request req;
623 DPRINTF("cmd=0x%08x\n", cmd);
627 req.bmRequestType = USLCOM_READ;
628 req.bRequest = USLCOM_VENDOR_SPECIFIC;
629 USETW(req.wValue, USLCOM_READ_LATCH);
630 USETW(req.wIndex, 0);
631 USETW(req.wLength, sizeof(latch));
633 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
634 &req, &latch, 0, 1000)) {
635 DPRINTF("Get LATCH failed\n");
638 *(int *)data = latch;
642 req.bmRequestType = USLCOM_WRITE;
643 req.bRequest = USLCOM_VENDOR_SPECIFIC;
644 USETW(req.wValue, USLCOM_WRITE_LATCH);
645 USETW(req.wIndex, (*(int *)data));
646 USETW(req.wLength, 0);
648 if (ucom_cfg_do_request(sc->sc_udev, &sc->sc_ucom,
649 &req, NULL, 0, 1000)) {
650 DPRINTF("Set LATCH failed\n");
656 DPRINTF("Unknown IOCTL\n");
664 uslcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
666 struct uslcom_softc *sc = usbd_xfer_softc(xfer);
667 struct usb_page_cache *pc;
670 switch (USB_GET_STATE(xfer)) {
672 case USB_ST_TRANSFERRED:
674 pc = usbd_xfer_get_frame(xfer, 0);
675 if (ucom_get_data(&sc->sc_ucom, pc, 0,
676 USLCOM_BULK_BUF_SIZE, &actlen)) {
678 DPRINTF("actlen = %d\n", actlen);
680 usbd_xfer_set_frame_len(xfer, 0, actlen);
681 usbd_transfer_submit(xfer);
686 if (error != USB_ERR_CANCELLED) {
687 /* try to clear stall first */
688 usbd_xfer_set_stall(xfer);
696 uslcom_read_callback(struct usb_xfer *xfer, usb_error_t error)
698 struct uslcom_softc *sc = usbd_xfer_softc(xfer);
699 struct usb_page_cache *pc;
702 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
704 switch (USB_GET_STATE(xfer)) {
705 case USB_ST_TRANSFERRED:
706 pc = usbd_xfer_get_frame(xfer, 0);
707 ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
711 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
712 usbd_transfer_submit(xfer);
716 if (error != USB_ERR_CANCELLED) {
717 /* try to clear stall first */
718 usbd_xfer_set_stall(xfer);
726 uslcom_control_callback(struct usb_xfer *xfer, usb_error_t error)
728 struct uslcom_softc *sc = usbd_xfer_softc(xfer);
729 struct usb_page_cache *pc;
730 struct usb_device_request req;
734 switch (USB_GET_STATE(xfer)) {
735 case USB_ST_TRANSFERRED:
736 pc = usbd_xfer_get_frame(xfer, 1);
737 usbd_copy_out(pc, 0, &buf, sizeof(buf));
738 if (buf & USLCOM_CTRL_CTS)
740 if (buf & USLCOM_CTRL_DSR)
742 if (buf & USLCOM_CTRL_RI)
744 if (buf & USLCOM_CTRL_DCD)
747 if (msr != sc->sc_msr) {
748 DPRINTF("status change msr=0x%02x "
749 "(was 0x%02x)\n", msr, sc->sc_msr);
751 ucom_status_change(&sc->sc_ucom);
756 req.bmRequestType = USLCOM_READ;
757 req.bRequest = USLCOM_RCTRL;
758 USETW(req.wValue, 0);
759 USETW(req.wIndex, USLCOM_PORT_NO);
760 USETW(req.wLength, sizeof(buf));
762 usbd_xfer_set_frames(xfer, 2);
763 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
764 usbd_xfer_set_frame_len(xfer, 1, sizeof(buf));
766 pc = usbd_xfer_get_frame(xfer, 0);
767 usbd_copy_in(pc, 0, &req, sizeof(req));
768 usbd_transfer_submit(xfer);
772 if (error != USB_ERR_CANCELLED)
773 DPRINTF("error=%s\n", usbd_errstr(error));
779 uslcom_start_read(struct ucom_softc *ucom)
781 struct uslcom_softc *sc = ucom->sc_parent;
783 /* start read endpoint */
784 usbd_transfer_start(sc->sc_xfer[USLCOM_BULK_DT_RD]);
788 uslcom_stop_read(struct ucom_softc *ucom)
790 struct uslcom_softc *sc = ucom->sc_parent;
792 /* stop read endpoint */
793 usbd_transfer_stop(sc->sc_xfer[USLCOM_BULK_DT_RD]);
797 uslcom_start_write(struct ucom_softc *ucom)
799 struct uslcom_softc *sc = ucom->sc_parent;
801 usbd_transfer_start(sc->sc_xfer[USLCOM_BULK_DT_WR]);
805 uslcom_stop_write(struct ucom_softc *ucom)
807 struct uslcom_softc *sc = ucom->sc_parent;
809 usbd_transfer_stop(sc->sc_xfer[USLCOM_BULK_DT_WR]);
813 uslcom_poll(struct ucom_softc *ucom)
815 struct uslcom_softc *sc = ucom->sc_parent;
816 usbd_transfer_poll(sc->sc_xfer, USLCOM_N_TRANSFER);