From 720922913c40f9cf287ec35fa2fd11bfba3bf630 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Fri, 10 Jan 2025 13:27:41 +0100 Subject: [PATCH] drivers: ftdi-gpio: Add second USB disconnect GPIO Some boards have more than one USB port. In that case, there is a second GPIO on the debug board to simulate a USB disconnection for those. Add the option to describe both USB disconnect GPIOs using "usb0_disconnect" and "usb1_disconnect" and change both of them when disabling USB power. In the future it might be useful to control them separately, but for now this ensures that power to the board is cut properly when the board is powered off. --- config-samples/sample8.yaml | 29 +++++++++++++++++++++++++++++ drivers/ftdi-gpio.c | 14 ++++++++++---- schema.yaml | 2 +- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/config-samples/sample8.yaml b/config-samples/sample8.yaml index 67c7427..10733f0 100644 --- a/config-samples/sample8.yaml +++ b/config-samples/sample8.yaml @@ -73,3 +73,32 @@ devices: power: interface: D line: 6 + - board: myboard-5 + name: "My Board 5" + description: | + My super awesome board Number 5 + console: /dev/ttyABC1 + fastboot: cacafada + ftdi_gpio: + vendor: "0x0403" + product: "0x6011" + index: 0 + power: + interface: B + line: 1 + active_low: true + fastboot_key: + interface: B + line: 0 + active_low: true + power_key: + interface: B + line: 2 + usb0_disconnect: + interface: C + line: 7 + active_low: true + usb1_disconnect: + interface: A + line: 4 + active_low: true diff --git a/drivers/ftdi-gpio.c b/drivers/ftdi-gpio.c index 95b9cb7..8c0bb7a 100644 --- a/drivers/ftdi-gpio.c +++ b/drivers/ftdi-gpio.c @@ -31,7 +31,8 @@ enum { GPIO_POWER = 0, // Power input enable GPIO_FASTBOOT_KEY, // Usually volume key GPIO_POWER_KEY, // Key to power the device - GPIO_USB_DISCONNECT, // Simulate main USB connection + GPIO_USB0_DISCONNECT, // Simulate main USB connection + GPIO_USB1_DISCONNECT, // Simulate secondary USB connection GPIO_OUTPUT_ENABLE, // Enable FTDI signals to flow to the board GPIO_COUNT }; @@ -131,7 +132,7 @@ static void ftdi_gpio_parse_config(struct ftdi_gpio_options *options, char *valu else if (strncmp("POWER_KEY", name, off - name - 1) == 0) gpio_type = GPIO_POWER_KEY; else if (strncmp("USB_DISCONNECT", name, off - name - 1) == 0) - gpio_type = GPIO_USB_DISCONNECT; + gpio_type = GPIO_USB0_DISCONNECT; else if (strncmp("OUTPUT_ENABLE", name, off - name - 1) == 0) gpio_type = GPIO_OUTPUT_ENABLE; else @@ -182,7 +183,11 @@ void *ftdi_gpio_parse_options(struct device_parser *dp) } else if (!strcmp(key, "power_key")) { gpio_id = GPIO_POWER_KEY; } else if (!strcmp(key, "usb_disconnect")) { - gpio_id = GPIO_USB_DISCONNECT; + gpio_id = GPIO_USB0_DISCONNECT; + } else if (!strcmp(key, "usb0_disconnect")) { + gpio_id = GPIO_USB0_DISCONNECT; + } else if (!strcmp(key, "usb1_disconnect")) { + gpio_id = GPIO_USB1_DISCONNECT; } else if (!strcmp(key, "output_enable")) { gpio_id = GPIO_OUTPUT_ENABLE; } else { @@ -357,7 +362,8 @@ 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) { - ftdi_gpio_toggle_io(ftdi_gpio, GPIO_USB_DISCONNECT, on); + ftdi_gpio_toggle_io(ftdi_gpio, GPIO_USB0_DISCONNECT, on); + ftdi_gpio_toggle_io(ftdi_gpio, GPIO_USB1_DISCONNECT, on); } static int ftdi_gpio_power(struct device *dev, bool on) diff --git a/schema.yaml b/schema.yaml index b892a8f..5f9ad54 100644 --- a/schema.yaml +++ b/schema.yaml @@ -124,7 +124,7 @@ properties: devicenode: $ref: "#/$defs/device_path" patternProperties: - "^power|fastboot_key|power_key|usb_disconnect|output_enable$": + "^power|fastboot_key|power_key|usb[01]?_disconnect|output_enable$": $ref: "#/$defs/ftdi_gpio" additionalProperties: false