diff options
author | Johan Hovold <johan@kernel.org> | 2018-09-30 08:27:03 -0400 |
---|---|---|
committer | Johan Hovold <johan@kernel.org> | 2018-10-05 02:57:06 -0400 |
commit | ff32d97e39e7053fdc1d316bd2e2eff70b77fdd2 (patch) | |
tree | 01ecdc02233d27560d2dc6fc3c87e4f713c258ad | |
parent | e0658e3074231d68f6546be1c5916ba2f4dc1295 (diff) |
USB: serial: ftdi_sio: add support for FT232R CBUS gpios
Enable support for cbus gpios on FT232R. The cbus configuration is
stored in one word in the EEPROM at offset 0x0a (byte-offset 0x14) with
the mux config for CBUS0, CBUS1, CBUS2 and CBUS3 in bits 0..3, 4..7,
8..11 and 12..15, respectively.
Tested using FT232RL by configuring one cbus pin at a time.
Signed-off-by: Johan Hovold <johan@kernel.org>
-rw-r--r-- | drivers/usb/serial/ftdi_sio.c | 40 | ||||
-rw-r--r-- | drivers/usb/serial/ftdi_sio.h | 3 |
2 files changed, 40 insertions, 3 deletions
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index be50b2a200aa..f1eb20acb3bb 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -2007,7 +2007,40 @@ static int ftdi_read_eeprom(struct usb_serial *serial, void *dst, u16 addr, | |||
2007 | return 0; | 2007 | return 0; |
2008 | } | 2008 | } |
2009 | 2009 | ||
2010 | static int ftx_gpioconf_init(struct usb_serial_port *port) | 2010 | static int ftdi_gpio_init_ft232r(struct usb_serial_port *port) |
2011 | { | ||
2012 | struct ftdi_private *priv = usb_get_serial_port_data(port); | ||
2013 | u16 cbus_config; | ||
2014 | u8 *buf; | ||
2015 | int ret; | ||
2016 | int i; | ||
2017 | |||
2018 | buf = kmalloc(2, GFP_KERNEL); | ||
2019 | if (!buf) | ||
2020 | return -ENOMEM; | ||
2021 | |||
2022 | ret = ftdi_read_eeprom(port->serial, buf, 0x14, 2); | ||
2023 | if (ret < 0) | ||
2024 | goto out_free; | ||
2025 | |||
2026 | cbus_config = le16_to_cpup((__le16 *)buf); | ||
2027 | dev_dbg(&port->dev, "cbus_config = 0x%04x\n", cbus_config); | ||
2028 | |||
2029 | priv->gc.ngpio = 4; | ||
2030 | |||
2031 | priv->gpio_altfunc = 0xff; | ||
2032 | for (i = 0; i < priv->gc.ngpio; ++i) { | ||
2033 | if ((cbus_config & 0xf) == FTDI_FT232R_CBUS_MUX_GPIO) | ||
2034 | priv->gpio_altfunc &= ~BIT(i); | ||
2035 | cbus_config >>= 4; | ||
2036 | } | ||
2037 | out_free: | ||
2038 | kfree(buf); | ||
2039 | |||
2040 | return ret; | ||
2041 | } | ||
2042 | |||
2043 | static int ftdi_gpio_init_ftx(struct usb_serial_port *port) | ||
2011 | { | 2044 | { |
2012 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 2045 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
2013 | struct usb_serial *serial = port->serial; | 2046 | struct usb_serial *serial = port->serial; |
@@ -2049,8 +2082,11 @@ static int ftdi_gpio_init(struct usb_serial_port *port) | |||
2049 | int result; | 2082 | int result; |
2050 | 2083 | ||
2051 | switch (priv->chip_type) { | 2084 | switch (priv->chip_type) { |
2085 | case FT232RL: | ||
2086 | result = ftdi_gpio_init_ft232r(port); | ||
2087 | break; | ||
2052 | case FTX: | 2088 | case FTX: |
2053 | result = ftx_gpioconf_init(port); | 2089 | result = ftdi_gpio_init_ftx(port); |
2054 | break; | 2090 | break; |
2055 | default: | 2091 | default: |
2056 | return 0; | 2092 | return 0; |
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h index 6cfe682f8348..a79a1325b4d9 100644 --- a/drivers/usb/serial/ftdi_sio.h +++ b/drivers/usb/serial/ftdi_sio.h | |||
@@ -457,7 +457,8 @@ enum ftdi_sio_baudrate { | |||
457 | #define FTDI_SIO_READ_EEPROM_REQUEST_TYPE 0xc0 | 457 | #define FTDI_SIO_READ_EEPROM_REQUEST_TYPE 0xc0 |
458 | #define FTDI_SIO_READ_EEPROM_REQUEST FTDI_SIO_READ_EEPROM | 458 | #define FTDI_SIO_READ_EEPROM_REQUEST FTDI_SIO_READ_EEPROM |
459 | 459 | ||
460 | #define FTDI_FTX_CBUS_MUX_GPIO 8 | 460 | #define FTDI_FTX_CBUS_MUX_GPIO 0x8 |
461 | #define FTDI_FT232R_CBUS_MUX_GPIO 0xa | ||
461 | 462 | ||
462 | 463 | ||
463 | /* Descriptors returned by the device | 464 | /* Descriptors returned by the device |