Print this page
3419 usbftdi needs to support the BeagleBone

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/usb/clients/usbser/usbftdi/uftdi_dsd.c
          +++ new/usr/src/uts/common/io/usb/clients/usbser/usbftdi/uftdi_dsd.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
  27   27  /*
       28 + * Copyright 2012 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
       29 + */
       30 +
       31 +/*
  28   32   * FTDI FT232R USB UART device-specific driver
  29   33   *
  30   34   * May work on the (many) devices based on earlier versions of the chip.
  31   35   */
  32   36  
  33   37  #include <sys/types.h>
  34   38  #include <sys/param.h>
  35   39  #include <sys/conf.h>
  36   40  #include <sys/stream.h>
  37   41  #include <sys/strsun.h>
↓ open down ↓ 175 lines elided ↑ open up ↑
 213  217              &uftdi_errlevel, &uftdi_errmask, &uftdi_instance_debug, 0);
 214  218  
 215  219          /*
 216  220           * This device and its clones has numerous physical instantiations.
 217  221           */
 218  222          recognized = B_TRUE;
 219  223          dd = uf->uf_dev_data->dev_descr;
 220  224          switch (dd->idVendor) {
 221  225          case USB_VENDOR_FTDI:
 222  226                  switch (dd->idProduct) {
      227 +                case USB_PRODUCT_FTDI_SERIAL_2232C:
 223  228                  case USB_PRODUCT_FTDI_SERIAL_8U232AM:
 224  229                  case USB_PRODUCT_FTDI_SEMC_DSS20:
 225  230                  case USB_PRODUCT_FTDI_CFA_631:
 226  231                  case USB_PRODUCT_FTDI_CFA_632:
 227  232                  case USB_PRODUCT_FTDI_CFA_633:
 228  233                  case USB_PRODUCT_FTDI_CFA_634:
 229  234                  case USB_PRODUCT_FTDI_CFA_635:
 230  235                  case USB_PRODUCT_FTDI_USBSERIAL:
 231  236                  case USB_PRODUCT_FTDI_MX2_3:
 232  237                  case USB_PRODUCT_FTDI_MX4_5:
↓ open down ↓ 88 lines elided ↑ open up ↑
 321  326                  uftdi_cleanup(uf, 3);
 322  327                  return (USB_FAILURE);
 323  328          }
 324  329  
 325  330          if (usb_register_event_cbs(uf->uf_dip,
 326  331              uf->uf_usb_events, 0) != USB_SUCCESS) {
 327  332                  uftdi_cleanup(uf, 4);
 328  333                  return (USB_FAILURE);
 329  334          }
 330  335  
 331      -        if (usb_pipe_get_max_bulk_transfer_size(uf->uf_dip,
 332      -            &uf->uf_xfer_sz) != USB_SUCCESS) {
 333      -                uftdi_cleanup(uf, 5);
 334      -                return (USB_FAILURE);
 335      -        }
 336      -
 337      -        /*
 338      -         * TODO: modern ftdi devices have deeper (and asymmetric)
 339      -         * fifos than this minimal 64 bytes .. but how to tell
 340      -         * -safely- ?
 341      -         */
 342      -
 343      -#define FTDI_MAX_XFERSIZE       64
 344      -
 345      -        if (uf->uf_xfer_sz > FTDI_MAX_XFERSIZE)
 346      -                uf->uf_xfer_sz = FTDI_MAX_XFERSIZE;
 347      -
 348  336          if (uftdi_dev_attach(uf) != USB_SUCCESS) {
 349  337                  uftdi_cleanup(uf, 5);
 350  338                  return (USB_FAILURE);
 351  339          }
 352  340  
 353  341          return (USB_SUCCESS);
 354  342  }
 355  343  
 356  344  #define FTDI_CLEANUP_LEVEL_MAX  6
 357  345  
↓ open down ↓ 1136 lines elided ↑ open up ↑
1494 1482  
1495 1483  /*
1496 1484   * pipe operations
1497 1485   */
1498 1486  static int
1499 1487  uftdi_open_pipes(uftdi_state_t *uf)
1500 1488  {
1501 1489          int ifc, alt;
1502 1490          usb_pipe_policy_t policy;
1503 1491          usb_ep_data_t *in_data, *out_data;
     1492 +        size_t max_xfer_sz;
1504 1493  
     1494 +        /* get max transfer size */
     1495 +        if (usb_pipe_get_max_bulk_transfer_size(uf->uf_dip, &max_xfer_sz)
     1496 +            != USB_SUCCESS)
     1497 +                return (USB_FAILURE);
     1498 +
1505 1499          /* get ep data */
1506 1500          ifc = uf->uf_dev_data->dev_curr_if;
1507 1501          alt = 0;
1508 1502  
1509 1503          in_data = usb_lookup_ep_data(uf->uf_dip, uf->uf_dev_data, ifc, alt,
1510 1504              0, USB_EP_ATTR_BULK, USB_EP_DIR_IN);
1511 1505  
1512 1506          out_data = usb_lookup_ep_data(uf->uf_dip, uf->uf_dev_data, ifc, alt,
1513 1507              0, USB_EP_ATTR_BULK, USB_EP_DIR_OUT);
1514 1508  
1515 1509          if (in_data == NULL || out_data == NULL) {
1516 1510                  USB_DPRINTF_L2(DPRINT_ATTACH, uf->uf_lh,
1517 1511                      "uftdi_open_pipes: can't get ep data");
1518 1512                  return (USB_FAILURE);
1519 1513          }
1520 1514  
     1515 +        /*
     1516 +         * Set buffer sizes. Default to UFTDI_XFER_SZ_MAX.
     1517 +         * Use wMaxPacketSize from endpoint descriptor if it is nonzero..
     1518 +         * Cap at a max transfer size of host controller.
     1519 +         */
     1520 +        uf->uf_ibuf_sz = uf->uf_obuf_sz = UFTDI_XFER_SZ_MAX;
     1521 +
     1522 +        if (in_data->ep_descr.wMaxPacketSize)
     1523 +                uf->uf_ibuf_sz = in_data->ep_descr.wMaxPacketSize;
     1524 +        uf->uf_ibuf_sz = min(uf->uf_ibuf_sz, max_xfer_sz);
     1525 +
     1526 +        if (out_data->ep_descr.wMaxPacketSize)
     1527 +                uf->uf_obuf_sz = out_data->ep_descr.wMaxPacketSize;
     1528 +        uf->uf_obuf_sz = min(uf->uf_obuf_sz, max_xfer_sz);
     1529 +
1521 1530          /* open pipes */
1522 1531          policy.pp_max_async_reqs = 2;
1523 1532  
1524 1533          if (usb_pipe_open(uf->uf_dip, &in_data->ep_descr, &policy,
1525 1534              USB_FLAGS_SLEEP, &uf->uf_bulkin_ph) != USB_SUCCESS)
1526 1535                  return (USB_FAILURE);
1527 1536  
1528 1537          if (usb_pipe_open(uf->uf_dip, &out_data->ep_descr, &policy,
1529 1538              USB_FLAGS_SLEEP, &uf->uf_bulkout_ph) != USB_SUCCESS) {
1530 1539                  usb_pipe_close(uf->uf_dip, uf->uf_bulkin_ph, USB_FLAGS_SLEEP,
↓ open down ↓ 268 lines elided ↑ open up ↑
1799 1808          usb_bulk_req_t *br;
1800 1809          int rval;
1801 1810  
1802 1811          USB_DPRINTF_L4(DPRINT_OUT_PIPE, uf->uf_lh, "uftdi_rx_start");
1803 1812  
1804 1813          ASSERT(mutex_owned(&uf->uf_lock));
1805 1814  
1806 1815          uf->uf_bulkin_state = UFTDI_PIPE_BUSY;
1807 1816          mutex_exit(&uf->uf_lock);
1808 1817  
1809      -        br = usb_alloc_bulk_req(uf->uf_dip, uf->uf_xfer_sz, USB_FLAGS_SLEEP);
1810      -        br->bulk_len = uf->uf_xfer_sz;
     1818 +        br = usb_alloc_bulk_req(uf->uf_dip, uf->uf_ibuf_sz, USB_FLAGS_SLEEP);
     1819 +        br->bulk_len = uf->uf_ibuf_sz;
1811 1820          br->bulk_timeout = UFTDI_BULKIN_TIMEOUT;
1812 1821          br->bulk_cb = uftdi_bulkin_cb;
1813 1822          br->bulk_exc_cb = uftdi_bulkin_cb;
1814 1823          br->bulk_client_private = (usb_opaque_t)uf;
1815 1824          br->bulk_attributes = USB_ATTRS_AUTOCLEARING | USB_ATTRS_SHORT_XFER_OK;
1816 1825  
1817 1826          rval = usb_pipe_bulk_xfer(uf->uf_bulkin_ph, br, 0);
1818 1827  
1819 1828          if (rval != USB_SUCCESS) {
1820 1829                  USB_DPRINTF_L2(DPRINT_IN_PIPE, uf->uf_lh,
↓ open down ↓ 33 lines elided ↑ open up ↑
1854 1863                  return;
1855 1864          }
1856 1865          if (uf->uf_bulkout_state != UFTDI_PIPE_IDLE) {
1857 1866                  USB_DPRINTF_L4(DPRINT_OUT_PIPE, uf->uf_lh,
1858 1867                      "uftdi_tx_start: pipe busy");
1859 1868                  return;
1860 1869          }
1861 1870          ASSERT(MBLKL(uf->uf_tx_mp) > 0);
1862 1871  
1863 1872          /* send as much data as port can receive */
1864      -        len = min(msgdsize(uf->uf_tx_mp), uf->uf_xfer_sz);
     1873 +        len = min(msgdsize(uf->uf_tx_mp), uf->uf_obuf_sz);
1865 1874  
1866 1875          if (len <= 0)
1867 1876                  return;
1868 1877          if ((data = allocb(len, BPRI_LO)) == NULL)
1869 1878                  return;
1870 1879  
1871 1880          /*
1872 1881           * copy no more than 'len' bytes from mblk chain to transmit mblk 'data'
1873 1882           */
1874 1883          data_len = 0;
↓ open down ↓ 230 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX