The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/usb/uftdi.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: e61b73aee16596adcfc9ae6473106cbe


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.