Skip to content

Commit 7209229

Browse files
committed
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.
1 parent 8bd8eed commit 7209229

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

config-samples/sample8.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,32 @@ devices:
7373
power:
7474
interface: D
7575
line: 6
76+
- board: myboard-5
77+
name: "My Board 5"
78+
description: |
79+
My super awesome board Number 5
80+
console: /dev/ttyABC1
81+
fastboot: cacafada
82+
ftdi_gpio:
83+
vendor: "0x0403"
84+
product: "0x6011"
85+
index: 0
86+
power:
87+
interface: B
88+
line: 1
89+
active_low: true
90+
fastboot_key:
91+
interface: B
92+
line: 0
93+
active_low: true
94+
power_key:
95+
interface: B
96+
line: 2
97+
usb0_disconnect:
98+
interface: C
99+
line: 7
100+
active_low: true
101+
usb1_disconnect:
102+
interface: A
103+
line: 4
104+
active_low: true

drivers/ftdi-gpio.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ enum {
3131
GPIO_POWER = 0, // Power input enable
3232
GPIO_FASTBOOT_KEY, // Usually volume key
3333
GPIO_POWER_KEY, // Key to power the device
34-
GPIO_USB_DISCONNECT, // Simulate main USB connection
34+
GPIO_USB0_DISCONNECT, // Simulate main USB connection
35+
GPIO_USB1_DISCONNECT, // Simulate secondary USB connection
3536
GPIO_OUTPUT_ENABLE, // Enable FTDI signals to flow to the board
3637
GPIO_COUNT
3738
};
@@ -131,7 +132,7 @@ static void ftdi_gpio_parse_config(struct ftdi_gpio_options *options, char *valu
131132
else if (strncmp("POWER_KEY", name, off - name - 1) == 0)
132133
gpio_type = GPIO_POWER_KEY;
133134
else if (strncmp("USB_DISCONNECT", name, off - name - 1) == 0)
134-
gpio_type = GPIO_USB_DISCONNECT;
135+
gpio_type = GPIO_USB0_DISCONNECT;
135136
else if (strncmp("OUTPUT_ENABLE", name, off - name - 1) == 0)
136137
gpio_type = GPIO_OUTPUT_ENABLE;
137138
else
@@ -182,7 +183,11 @@ void *ftdi_gpio_parse_options(struct device_parser *dp)
182183
} else if (!strcmp(key, "power_key")) {
183184
gpio_id = GPIO_POWER_KEY;
184185
} else if (!strcmp(key, "usb_disconnect")) {
185-
gpio_id = GPIO_USB_DISCONNECT;
186+
gpio_id = GPIO_USB0_DISCONNECT;
187+
} else if (!strcmp(key, "usb0_disconnect")) {
188+
gpio_id = GPIO_USB0_DISCONNECT;
189+
} else if (!strcmp(key, "usb1_disconnect")) {
190+
gpio_id = GPIO_USB1_DISCONNECT;
186191
} else if (!strcmp(key, "output_enable")) {
187192
gpio_id = GPIO_OUTPUT_ENABLE;
188193
} else {
@@ -357,7 +362,8 @@ static int ftdi_gpio_device_power(struct ftdi_gpio *ftdi_gpio, bool on)
357362

358363
static void ftdi_gpio_device_usb(struct ftdi_gpio *ftdi_gpio, bool on)
359364
{
360-
ftdi_gpio_toggle_io(ftdi_gpio, GPIO_USB_DISCONNECT, on);
365+
ftdi_gpio_toggle_io(ftdi_gpio, GPIO_USB0_DISCONNECT, on);
366+
ftdi_gpio_toggle_io(ftdi_gpio, GPIO_USB1_DISCONNECT, on);
361367
}
362368

363369
static int ftdi_gpio_power(struct device *dev, bool on)

schema.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ properties:
124124
devicenode:
125125
$ref: "#/$defs/device_path"
126126
patternProperties:
127-
"^power|fastboot_key|power_key|usb_disconnect|output_enable$":
127+
"^power|fastboot_key|power_key|usb[01]?_disconnect|output_enable$":
128128
$ref: "#/$defs/ftdi_gpio"
129129
additionalProperties: false
130130

0 commit comments

Comments
 (0)