lkml.org 
[lkml]   [2018]   [Sep]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC] USB: serial: ftdi_sio: add support for FT232R CBUS gpios
Date
Enable support for the CBUS gpios on FT232R. The cbus configuration is
stored in one word in the EEPROM at offset 0x0a with the mux config for
CBUS1, CBUS2, CBUS3 and CBUS4 in bits 0..3, 4..7, 8..11 and 12..15,
respectively.

Tested using FT232RL with all CBUS pins in IO mode.

Applies on top of Karoly's CBUS gpio patch.

FIXME: use common eeprom_read helper
FIXME: return the number of gpios instead of setting gc.ngpio?
FIXME: verify each mux setting
Signed-off-by: Johan Hovold <johan@kernel.org>
---

This is a cleaned up version of some code I've been using to test
Karoly's patch using an FT232RL in case anyone wants to give that a try.

May also be useful to get an idea of how the current setup code can be
refactored. This one needs to be rebased to use a common eeprom helper
eventually for example.

Johan


drivers/usb/serial/ftdi_sio.c | 49 +++++++++++++++++++++++++++++++++++
drivers/usb/serial/ftdi_sio.h | 1 +
2 files changed, 50 insertions(+)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 1df9c553710b..4d63863bfb3f 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -43,6 +43,9 @@
#ifdef CONFIG_GPIOLIB
#include <linux/gpio/driver.h>
#endif
+
+#include <asm/unaligned.h>
+
#include "ftdi_sio.h"
#include "ftdi_sio_ids.h"

@@ -1920,6 +1923,49 @@ static int ftdi_sio_gpio_direction_output(struct gpio_chip *gc,
FTDI_SIO_GPIO_MODE_CBUS);
}

+static int ftdi_ft232r_gpioconf_init(struct usb_serial_port *port)
+{
+ struct ftdi_private *priv = usb_get_serial_port_data(port);
+ struct usb_device *udev = port->serial->dev;
+ u16 tmp;
+ u8 *buf;
+ int res;
+ int i;
+
+ buf = kmalloc(2, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+ FTDI_SIO_READ_EEPROM_REQUEST,
+ FTDI_SIO_READ_EEPROM_REQUEST_TYPE,
+ 0, 0x0a, buf, 2,
+ WDR_TIMEOUT);
+ if (res < 2) {
+ if (res >= 0)
+ res = -EIO;
+ goto out_free;
+ }
+
+ tmp = get_unaligned_le16(buf);
+ dev_dbg(&port->dev, "cbus_config = 0x%04x\n", tmp);
+
+ priv->gc.ngpio = 4;
+ priv->gpio_altfunc = 0xff;
+
+ for (i = 0; i < priv->gc.ngpio; ++i) {
+ if ((tmp & 0xf) == FTDI_FT232R_CBUS_MUX_IOMODE)
+ priv->gpio_altfunc &= ~BIT(i);
+ tmp >>= 4;
+ }
+
+ res = 0;
+out_free:
+ kfree(buf);
+
+ return res;
+}
+
static int ftx_gpioconf_init(struct usb_serial_port *port)
{
struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1980,6 +2026,9 @@ static int ftdi_sio_gpio_init(struct usb_serial_port *port)

/* Device-specific initializations */
switch (priv->chip_type) {
+ case FT232RL:
+ result = ftdi_ft232r_gpioconf_init(port);
+ break;
case FTX:
result = ftx_gpioconf_init(port);
break;
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 5046d02fe3ac..eed72608382b 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -458,6 +458,7 @@ enum ftdi_sio_baudrate {
#define FTDI_SIO_GPIO_MODE_RESET 0x00

#define FTDI_SIO_CBUS_MUX_GPIO 8
+#define FTDI_FT232R_CBUS_MUX_IOMODE 0xa


/* Descriptors returned by the device
--
2.18.0
\
 
 \ /
  Last update: 2018-09-05 12:50    [W:0.036 / U:5.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site