There is no reason to be so verbose.
[dragonfly.git] / sys / dev / usbmisc / uftdi / uftdi.c
CommitLineData
62ade751 1/*
1550dfd9
MD
2 * $NetBSD: uftdi.c,v 1.13 2002/09/23 05:51:23 simonb Exp $
3 * $FreeBSD: src/sys/dev/usb/uftdi.c,v 1.10 2003/08/24 17:55:55 obrien Exp $
e785a5d9 4 * $DragonFly: src/sys/dev/usbmisc/uftdi/uftdi.c,v 1.14 2007/07/01 21:24:03 hasso Exp $
62ade751 5 */
984263bc
MD
6
7/*
8 * Copyright (c) 2000 The NetBSD Foundation, Inc.
9 * All rights reserved.
10 *
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Lennart Augustsson (lennart@augustsson.net).
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the NetBSD
25 * Foundation, Inc. and its contributors.
26 * 4. Neither the name of The NetBSD Foundation nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
41 */
42
43/*
44 * FTDI FT8U100AX serial adapter driver
45 */
46
984263bc
MD
47#include <sys/cdefs.h>
48
49#include <sys/param.h>
50#include <sys/systm.h>
51#include <sys/kernel.h>
52#include <sys/malloc.h>
53#include <sys/bus.h>
54#include <sys/ioccom.h>
55#include <sys/fcntl.h>
56#include <sys/conf.h>
57#include <sys/tty.h>
58#include <sys/file.h>
59
984263bc 60#include <sys/select.h>
984263bc
MD
61
62#include <sys/sysctl.h>
63
1f2de5d4
MD
64#include <bus/usb/usb.h>
65#include <bus/usb/usbhid.h>
984263bc 66
1f2de5d4
MD
67#include <bus/usb/usbdi.h>
68#include <bus/usb/usbdi_util.h>
69#include <bus/usb/usbdevs.h>
984263bc 70
1f2de5d4 71#include "../ucom/ucomvar.h"
984263bc 72
1f2de5d4 73#include "uftdireg.h"
984263bc
MD
74
75#ifdef USB_DEBUG
76static int uftdidebug = 0;
77SYSCTL_NODE(_hw_usb, OID_AUTO, uftdi, CTLFLAG_RW, 0, "USB uftdi");
78SYSCTL_INT(_hw_usb_uftdi, OID_AUTO, debug, CTLFLAG_RW,
79 &uftdidebug, 0, "uftdi debug level");
80#define DPRINTF(x) do { \
81 if (uftdidebug) \
fc1ef497 82 kprintf x; \
984263bc
MD
83 } while (0)
84
85#define DPRINTFN(n, x) do { \
86 if (uftdidebug > (n)) \
fc1ef497 87 kprintf x; \
984263bc
MD
88 } while (0)
89
90#else
91#define DPRINTF(x)
92#define DPRINTFN(n,x)
93#endif
94
95#define UFTDI_CONFIG_INDEX 0
96#define UFTDI_IFACE_INDEX 0
97
98
99/*
100 * These are the maximum number of bytes transferred per frame.
101 * The output buffer size cannot be increased due to the size encoding.
102 */
103#define UFTDIIBUFSIZE 64
104#define UFTDIOBUFSIZE 64
105
106struct uftdi_softc {
107 struct ucom_softc sc_ucom;
1550dfd9 108
984263bc
MD
109 usbd_interface_handle sc_iface; /* interface */
110
111 enum uftdi_type sc_type;
112 u_int sc_hdrlen;
113
114 u_char sc_msr;
115 u_char sc_lsr;
116
984263bc
MD
117 u_int last_lcr;
118};
119
6ed427ca
HT
120static void uftdi_get_status(void *, int portno, u_char *lsr, u_char *msr);
121static void uftdi_set(void *, int, int, int);
122static int uftdi_param(void *, int, struct termios *);
123static int uftdi_open(void *sc, int portno);
124static void uftdi_read(void *sc, int portno, u_char **ptr,u_int32_t *count);
125static void uftdi_write(void *sc, int portno, u_char *to, u_char *from,
984263bc 126 u_int32_t *count);
6ed427ca 127static void uftdi_break(void *sc, int portno, int onoff);
984263bc
MD
128
129struct ucom_callback uftdi_callback = {
130 uftdi_get_status,
131 uftdi_set,
132 uftdi_param,
133 NULL,
134 uftdi_open,
135 NULL,
136 uftdi_read,
137 uftdi_write,
138};
139
e785a5d9
HT
140static int
141uftdi_match(device_t self)
984263bc 142{
e785a5d9 143 struct usb_attach_arg *uaa = device_get_ivars(self);
984263bc
MD
144
145 if (uaa->iface != NULL)
146 return (UMATCH_NONE);
147
148 DPRINTFN(20,("uftdi: vendor=0x%x, product=0x%x\n",
149 uaa->vendor, uaa->product));
150
151 if (uaa->vendor == USB_VENDOR_FTDI &&
152 (uaa->product == USB_PRODUCT_FTDI_SERIAL_8U100AX ||
153 uaa->product == USB_PRODUCT_FTDI_SERIAL_8U232AM))
154 return (UMATCH_VENDOR_PRODUCT);
155
156 return (UMATCH_NONE);
157}
158
e785a5d9
HT
159static int
160uftdi_attach(device_t self)
984263bc 161{
e785a5d9
HT
162 struct uftdi_softc *sc = device_get_softc(self);
163 struct usb_attach_arg *uaa = device_get_ivars(self);
984263bc
MD
164 usbd_device_handle dev = uaa->device;
165 usbd_interface_handle iface;
166 usb_interface_descriptor_t *id;
167 usb_endpoint_descriptor_t *ed;
168 char *devinfo;
169 const char *devname;
170 int i;
171 usbd_status err;
172 struct ucom_softc *ucom = &sc->sc_ucom;
173 DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc));
efda3bd0 174 devinfo = kmalloc(1024, M_USBDEV, M_INTWAIT);
984263bc
MD
175
176 ucom->sc_dev = self;
177 ucom->sc_udev = dev;
178
6ed427ca 179 devname = device_get_nameunit(ucom->sc_dev);
984263bc
MD
180
181 /* Move the device into the configured state. */
182 err = usbd_set_config_index(dev, UFTDI_CONFIG_INDEX, 1);
183 if (err) {
e3869ec7 184 kprintf("\n%s: failed to set configuration, err=%s\n",
984263bc
MD
185 devname, usbd_errstr(err));
186 goto bad;
187 }
188
189 err = usbd_device2interface_handle(dev, UFTDI_IFACE_INDEX, &iface);
190 if (err) {
e3869ec7 191 kprintf("\n%s: failed to get interface, err=%s\n",
984263bc
MD
192 devname, usbd_errstr(err));
193 goto bad;
194 }
195
196 usbd_devinfo(dev, 0, devinfo);
197 /* USB_ATTACH_SETUP;*/
e3869ec7 198 kprintf("%s: %s\n", devname, devinfo);
984263bc
MD
199
200 id = usbd_get_interface_descriptor(iface);
201 ucom->sc_iface = iface;
202 switch( uaa->product ){
203 case USB_PRODUCT_FTDI_SERIAL_8U100AX:
204 sc->sc_type = UFTDI_TYPE_SIO;
205 sc->sc_hdrlen = 1;
206 break;
207 case USB_PRODUCT_FTDI_SERIAL_8U232AM:
208 sc->sc_type = UFTDI_TYPE_8U232AM;
209 sc->sc_hdrlen = 0;
210 break;
211
212 default: /* Can't happen */
213 goto bad;
214 }
1550dfd9 215
984263bc 216 ucom->sc_bulkin_no = ucom->sc_bulkout_no = -1;
1550dfd9 217
984263bc
MD
218 for (i = 0; i < id->bNumEndpoints; i++) {
219 int addr, dir, attr;
220 ed = usbd_interface2endpoint_descriptor(iface, i);
221 if (ed == NULL) {
e3869ec7 222 kprintf("%s: could not read endpoint descriptor"
984263bc
MD
223 ": %s\n", devname, usbd_errstr(err));
224 goto bad;
225 }
1550dfd9 226
984263bc
MD
227 addr = ed->bEndpointAddress;
228 dir = UE_GET_DIR(ed->bEndpointAddress);
229 attr = ed->bmAttributes & UE_XFERTYPE;
230 if (dir == UE_DIR_IN && attr == UE_BULK)
231 ucom->sc_bulkin_no = addr;
232 else if (dir == UE_DIR_OUT && attr == UE_BULK)
233 ucom->sc_bulkout_no = addr;
234 else {
e3869ec7 235 kprintf("%s: unexpected endpoint\n", devname);
984263bc
MD
236 goto bad;
237 }
238 }
239 if (ucom->sc_bulkin_no == -1) {
e3869ec7 240 kprintf("%s: Could not find data bulk in\n",
984263bc
MD
241 devname);
242 goto bad;
243 }
244 if (ucom->sc_bulkout_no == -1) {
e3869ec7 245 kprintf("%s: Could not find data bulk out\n",
984263bc
MD
246 devname);
247 goto bad;
248 }
249 ucom->sc_parent = sc;
250 ucom->sc_portno = FTDI_PIT_SIOA;
251 /* bulkin, bulkout set above */
252
253 ucom->sc_ibufsize = UFTDIIBUFSIZE;
254 ucom->sc_obufsize = UFTDIOBUFSIZE - sc->sc_hdrlen;
255 ucom->sc_ibufsizepad = UFTDIIBUFSIZE;
256 ucom->sc_opkthdrlen = sc->sc_hdrlen;
257
258
259 ucom->sc_callback = &uftdi_callback;
260#if 0
261 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
2939c544 262 ucom->sc_dev);
984263bc
MD
263#endif
264 DPRINTF(("uftdi: in=0x%x out=0x%x\n", ucom->sc_bulkin_no, ucom->sc_bulkout_no));
265 ucom_attach(&sc->sc_ucom);
efda3bd0 266 kfree(devinfo, M_USBDEV);
1550dfd9 267
e785a5d9 268 return 0;
984263bc
MD
269
270bad:
271 DPRINTF(("uftdi_attach: ATTACH ERROR\n"));
272 ucom->sc_dying = 1;
efda3bd0 273 kfree(devinfo, M_USBDEV);
984263bc 274
e785a5d9 275 return ENXIO;
984263bc
MD
276}
277#if 0
278int
6ed427ca 279uftdi_activate(device_t self, enum devact act)
984263bc
MD
280{
281 struct uftdi_softc *sc = (struct uftdi_softc *)self;
282 int rv = 0;
283
284 switch (act) {
285 case DVACT_ACTIVATE:
286 return (EOPNOTSUPP);
984263bc
MD
287
288 case DVACT_DEACTIVATE:
289 if (sc->sc_subdev != NULL)
290 rv = config_deactivate(sc->sc_subdev);
62ade751 291 sc->sc_ucom.sc_dying = 1;
984263bc
MD
292 break;
293 }
294 return (rv);
295}
296#endif
297#if 1
e785a5d9
HT
298static int
299uftdi_detach(device_t self)
984263bc 300{
e785a5d9 301 struct uftdi_softc *sc = device_get_softc(self);
1550dfd9 302
984263bc
MD
303 int rv = 0;
304
305 DPRINTF(("uftdi_detach: sc=%p\n", sc));
62ade751 306 sc->sc_ucom.sc_dying = 1;
984263bc
MD
307 rv = ucom_detach(&sc->sc_ucom);
308
309 return rv;
310}
311#endif
6ed427ca 312static int
984263bc
MD
313uftdi_open(void *vsc, int portno)
314{
315 struct uftdi_softc *sc = vsc;
62ade751 316 struct ucom_softc *ucom = &sc->sc_ucom;
984263bc
MD
317 usb_device_request_t req;
318 usbd_status err;
319 struct termios t;
320
321 DPRINTF(("uftdi_open: sc=%p\n", sc));
322
62ade751 323 if (ucom->sc_dying)
984263bc
MD
324 return (EIO);
325
326 /* Perform a full reset on the device */
327 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
328 req.bRequest = FTDI_SIO_RESET;
329 USETW(req.wValue, FTDI_SIO_RESET_SIO);
330 USETW(req.wIndex, portno);
331 USETW(req.wLength, 0);
332 err = usbd_do_request(ucom->sc_udev, &req, NULL);
333 if (err)
334 return (EIO);
335
336 /* Set 9600 baud, 2 stop bits, no parity, 8 bits */
337 t.c_ospeed = 9600;
338 t.c_cflag = CSTOPB | CS8;
339 (void)uftdi_param(sc, portno, &t);
340
341 /* Turn on RTS/CTS flow control */
342 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
343 req.bRequest = FTDI_SIO_SET_FLOW_CTRL;
344 USETW(req.wValue, 0);
345 USETW2(req.wIndex, FTDI_SIO_RTS_CTS_HS, portno);
346 USETW(req.wLength, 0);
347 err = usbd_do_request(ucom->sc_udev, &req, NULL);
348 if (err)
349 return (EIO);
350
351 return (0);
352}
353
6ed427ca 354static void
984263bc
MD
355uftdi_read(void *vsc, int portno, u_char **ptr, u_int32_t *count)
356{
357 struct uftdi_softc *sc = vsc;
358 u_char msr, lsr;
359
360 DPRINTFN(15,("uftdi_read: sc=%p, port=%d count=%d\n", sc, portno,
361 *count));
362
363 msr = FTDI_GET_MSR(*ptr);
364 lsr = FTDI_GET_LSR(*ptr);
365
366#ifdef USB_DEBUG
367 if (*count != 2)
368 DPRINTFN(10,("uftdi_read: sc=%p, port=%d count=%d data[0]="
369 "0x%02x\n", sc, portno, *count, (*ptr)[2]));
370#endif
371
372 if (sc->sc_msr != msr ||
373 (sc->sc_lsr & FTDI_LSR_MASK) != (lsr & FTDI_LSR_MASK)) {
374 DPRINTF(("uftdi_read: status change msr=0x%02x(0x%02x) "
375 "lsr=0x%02x(0x%02x)\n", msr, sc->sc_msr,
376 lsr, sc->sc_lsr));
377 sc->sc_msr = msr;
378 sc->sc_lsr = lsr;
379 ucom_status_change(&sc->sc_ucom);
380 }
381
382 /* Pick up status and adjust data part. */
383 *ptr += 2;
384 *count -= 2;
385}
386
6ed427ca 387static void
984263bc
MD
388uftdi_write(void *vsc, int portno, u_char *to, u_char *from, u_int32_t *count)
389{
390 struct uftdi_softc *sc = vsc;
391
392 DPRINTFN(10,("uftdi_write: sc=%p, port=%d count=%u data[0]=0x%02x\n",
393 vsc, portno, *count, from[0]));
394
395 /* Make length tag and copy data */
396 if (sc->sc_hdrlen > 0)
397 *to = FTDI_OUT_TAG(*count, portno);
398
399 memcpy(to + sc->sc_hdrlen, from, *count);
400 *count += sc->sc_hdrlen;
401}
402
6ed427ca 403static void
984263bc
MD
404uftdi_set(void *vsc, int portno, int reg, int onoff)
405{
406 struct uftdi_softc *sc = vsc;
407 struct ucom_softc *ucom = vsc;
408 usb_device_request_t req;
409 int ctl;
410
411 DPRINTF(("uftdi_set: sc=%p, port=%d reg=%d onoff=%d\n", vsc, portno,
412 reg, onoff));
413
414 switch (reg) {
415 case UCOM_SET_DTR:
416 ctl = onoff ? FTDI_SIO_SET_DTR_HIGH : FTDI_SIO_SET_DTR_LOW;
417 break;
418 case UCOM_SET_RTS:
419 ctl = onoff ? FTDI_SIO_SET_RTS_HIGH : FTDI_SIO_SET_RTS_LOW;
420 break;
421 case UCOM_SET_BREAK:
422 uftdi_break(sc, portno, onoff);
423 return;
424 default:
425 return;
426 }
427 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
428 req.bRequest = FTDI_SIO_MODEM_CTRL;
429 USETW(req.wValue, ctl);
430 USETW(req.wIndex, portno);
431 USETW(req.wLength, 0);
432 DPRINTFN(2,("uftdi_set: reqtype=0x%02x req=0x%02x value=0x%04x "
433 "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
434 UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
435 (void)usbd_do_request(ucom->sc_udev, &req, NULL);
436}
437
6ed427ca 438static int
984263bc
MD
439uftdi_param(void *vsc, int portno, struct termios *t)
440{
441 struct uftdi_softc *sc = vsc;
62ade751 442 struct ucom_softc *ucom = &sc->sc_ucom;
984263bc
MD
443 usb_device_request_t req;
444 usbd_status err;
445 int rate=0, data, flow;
446
447 DPRINTF(("uftdi_param: sc=%p\n", sc));
448
62ade751 449 if (ucom->sc_dying)
984263bc
MD
450 return (EIO);
451
452 switch (sc->sc_type) {
453 case UFTDI_TYPE_SIO:
454 switch (t->c_ospeed) {
455 case 300: rate = ftdi_sio_b300; break;
456 case 600: rate = ftdi_sio_b600; break;
457 case 1200: rate = ftdi_sio_b1200; break;
458 case 2400: rate = ftdi_sio_b2400; break;
459 case 4800: rate = ftdi_sio_b4800; break;
460 case 9600: rate = ftdi_sio_b9600; break;
461 case 19200: rate = ftdi_sio_b19200; break;
462 case 38400: rate = ftdi_sio_b38400; break;
463 case 57600: rate = ftdi_sio_b57600; break;
464 case 115200: rate = ftdi_sio_b115200; break;
465 default:
466 return (EINVAL);
467 }
468 break;
469
470 case UFTDI_TYPE_8U232AM:
471 switch(t->c_ospeed) {
472 case 300: rate = ftdi_8u232am_b300; break;
473 case 600: rate = ftdi_8u232am_b600; break;
474 case 1200: rate = ftdi_8u232am_b1200; break;
475 case 2400: rate = ftdi_8u232am_b2400; break;
476 case 4800: rate = ftdi_8u232am_b4800; break;
477 case 9600: rate = ftdi_8u232am_b9600; break;
478 case 19200: rate = ftdi_8u232am_b19200; break;
479 case 38400: rate = ftdi_8u232am_b38400; break;
480 case 57600: rate = ftdi_8u232am_b57600; break;
481 case 115200: rate = ftdi_8u232am_b115200; break;
482 case 230400: rate = ftdi_8u232am_b230400; break;
483 case 460800: rate = ftdi_8u232am_b460800; break;
484 case 921600: rate = ftdi_8u232am_b921600; break;
485 default:
486 return (EINVAL);
487 }
488 break;
489 }
490 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
491 req.bRequest = FTDI_SIO_SET_BAUD_RATE;
492 USETW(req.wValue, rate);
493 USETW(req.wIndex, portno);
494 USETW(req.wLength, 0);
495 DPRINTFN(2,("uftdi_param: reqtype=0x%02x req=0x%02x value=0x%04x "
496 "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
497 UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
498 err = usbd_do_request(ucom->sc_udev, &req, NULL);
499 if (err)
500 return (EIO);
501
502 if (ISSET(t->c_cflag, CSTOPB))
503 data = FTDI_SIO_SET_DATA_STOP_BITS_2;
504 else
505 data = FTDI_SIO_SET_DATA_STOP_BITS_1;
506 if (ISSET(t->c_cflag, PARENB)) {
507 if (ISSET(t->c_cflag, PARODD))
508 data |= FTDI_SIO_SET_DATA_PARITY_ODD;
509 else
510 data |= FTDI_SIO_SET_DATA_PARITY_EVEN;
511 } else
512 data |= FTDI_SIO_SET_DATA_PARITY_NONE;
513 switch (ISSET(t->c_cflag, CSIZE)) {
514 case CS5:
515 data |= FTDI_SIO_SET_DATA_BITS(5);
516 break;
517 case CS6:
518 data |= FTDI_SIO_SET_DATA_BITS(6);
519 break;
520 case CS7:
521 data |= FTDI_SIO_SET_DATA_BITS(7);
522 break;
523 case CS8:
524 data |= FTDI_SIO_SET_DATA_BITS(8);
525 break;
526 }
527 sc->last_lcr = data;
528
529 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
530 req.bRequest = FTDI_SIO_SET_DATA;
531 USETW(req.wValue, data);
532 USETW(req.wIndex, portno);
533 USETW(req.wLength, 0);
534 DPRINTFN(2,("uftdi_param: reqtype=0x%02x req=0x%02x value=0x%04x "
535 "index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
536 UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
537 err = usbd_do_request(ucom->sc_udev, &req, NULL);
538 if (err)
539 return (EIO);
540
541 if (ISSET(t->c_cflag, CRTSCTS)) {
542 flow = FTDI_SIO_RTS_CTS_HS;
543 USETW(req.wValue, 0);
544 } else if (ISSET(t->c_iflag, IXON|IXOFF)) {
545 flow = FTDI_SIO_XON_XOFF_HS;
546 USETW2(req.wValue, t->c_cc[VSTOP], t->c_cc[VSTART]);
547 } else {
548 flow = FTDI_SIO_DISABLE_FLOW_CTRL;
549 USETW(req.wValue, 0);
550 }
551 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
552 req.bRequest = FTDI_SIO_SET_FLOW_CTRL;
553 USETW2(req.wIndex, flow, portno);
554 USETW(req.wLength, 0);
555 err = usbd_do_request(ucom->sc_udev, &req, NULL);
556 if (err)
557 return (EIO);
558
559 return (0);
560}
561
562void
563uftdi_get_status(void *vsc, int portno, u_char *lsr, u_char *msr)
564{
565 struct uftdi_softc *sc = vsc;
566
567 DPRINTF(("uftdi_status: msr=0x%02x lsr=0x%02x\n",
568 sc->sc_msr, sc->sc_lsr));
569
570 if (msr != NULL)
571 *msr = sc->sc_msr;
572 if (lsr != NULL)
573 *lsr = sc->sc_lsr;
574}
575
576void
577uftdi_break(void *vsc, int portno, int onoff)
578{
579 struct uftdi_softc *sc = vsc;
580 struct ucom_softc *ucom = vsc;
581
582 usb_device_request_t req;
583 int data;
584
585 DPRINTF(("uftdi_break: sc=%p, port=%d onoff=%d\n", vsc, portno,
586 onoff));
587
588 if (onoff) {
589 data = sc->last_lcr | FTDI_SIO_SET_BREAK;
590 } else {
591 data = sc->last_lcr;
592 }
593
594 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
595 req.bRequest = FTDI_SIO_SET_DATA;
596 USETW(req.wValue, data);
597 USETW(req.wIndex, portno);
598 USETW(req.wLength, 0);
599 (void)usbd_do_request(ucom->sc_udev, &req, NULL);
600}
601
6ed427ca 602static device_method_t uftdi_methods[] = {
984263bc
MD
603 /* Device interface */
604 DEVMETHOD(device_probe, uftdi_match),
605 DEVMETHOD(device_attach, uftdi_attach),
606 DEVMETHOD(device_detach, uftdi_detach),
607
608 { 0, 0 }
609};
610
6ed427ca 611static driver_t uftdi_driver = {
984263bc
MD
612 "ucom",
613 uftdi_methods,
614 sizeof (struct uftdi_softc)
615};
616
617DRIVER_MODULE(uftdi, uhub, uftdi_driver, ucom_devclass, usbd_driver_load, 0);
618MODULE_DEPEND(uftdi, usb, 1, 1, 1);
619MODULE_DEPEND(uftdi, ucom,UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);