@@ -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;
@@ -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
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(+)