Skip to content

Commit

Permalink
ftdi_gpio: add output_enable gpio type
Browse files Browse the repository at this point in the history
Since the FTDI is hot-pluggable, the output lines can be protected
for unwanted changes by a supplementary GPIO that allows the FTDI
gpio outputs to be enabled for the required functions.

Closes: #43

Signed-off-by: Neil Armstrong <[email protected]>
  • Loading branch information
superna9999 committed Oct 30, 2023
1 parent df832c0 commit 92ecd9b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ftdi-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum {
GPIO_FASTBOOT_KEY, // Usually volume key
GPIO_POWER_KEY, // Key to power the device
GPIO_USB_DISCONNECT, // Simulate main USB connection
GPIO_OUTPUT_ENABLE, // Enable FTDI signals to flow to the board
GPIO_COUNT
};

Expand All @@ -70,6 +71,7 @@ struct ftdi_gpio {

static int ftdi_gpio_device_power(struct ftdi_gpio *ftdi_gpio, bool on);
static void ftdi_gpio_device_usb(struct ftdi_gpio *ftdi_gpio, bool on);
static int ftdi_gpio_toggle_io(struct ftdi_gpio *ftdi_gpio, unsigned int gpio, bool on);

/*
* fdio_gpio parameter: <libftdi description>;[<interface>[;<gpios>...]]
Expand Down Expand Up @@ -139,6 +141,8 @@ static void ftdi_gpio_parse_config(struct ftdi_gpio *ftdi_gpio, char *control_de
gpio_type = GPIO_POWER_KEY;
else if (strncmp("USB_DISCONNECT", name, off - name - 1) == 0)
gpio_type = GPIO_USB_DISCONNECT;
else if (strncmp("OUTPUT_ENABLE", name, off - name - 1) == 0)
gpio_type = GPIO_OUTPUT_ENABLE;
else
errx(1, "GPIOs type invalid: '%s'", name);

Expand Down Expand Up @@ -189,6 +193,9 @@ static void *ftdi_gpio_open(struct device *dev)
else
ftdi_gpio_device_usb(ftdi_gpio, 0);

if (ftdi_gpio->gpio_present[GPIO_OUTPUT_ENABLE])
ftdi_gpio_toggle_io(ftdi_gpio, GPIO_OUTPUT_ENABLE, 1);

usleep(500000);

return ftdi_gpio;
Expand Down

0 comments on commit 92ecd9b

Please sign in to comment.