Skip to content

Commit 6d95341

Browse files
committed
ftdi_gpio: align structs with local_gpio
Signed-off-by: Neil Armstrong <[email protected]>
1 parent 494b048 commit 6d95341

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

ftdi-gpio.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,17 @@ enum {
5454
GPIO_COUNT
5555
};
5656

57-
enum {
58-
GPIO_ACTIVE_HIGH = 0,
59-
GPIO_ACTIVE_LOW,
60-
};
61-
6257
struct ftdi_gpio {
58+
struct {
59+
char *description;
60+
unsigned int interface;
61+
} ftdi;
62+
struct {
63+
bool present;
64+
unsigned int offset;
65+
bool active_low;
66+
} gpios[GPIO_COUNT];
6367
struct ftdi_context *gpio;
64-
char *ftdi_device;
65-
unsigned int ftdi_interface;
66-
unsigned int gpio_present[GPIO_COUNT];
67-
unsigned int gpio_offset[GPIO_COUNT];
68-
unsigned int gpio_polarity[GPIO_COUNT];
6968
unsigned char gpio_lines;
7069
};
7170

@@ -85,19 +84,19 @@ static int ftdi_gpio_toggle_io(struct ftdi_gpio *ftdi_gpio, unsigned int gpio, b
8584
* Example: s:0xVEND:0xPROD:SERIAL;D;POWER,0,ACTIVE_LOW;FASTBOOT_KEY,1,ACTIVE_HIGH;POWER_KEY,2,ACTIVE_HIGH;USB_DISCONNECT,3,ACTIVE_LOW
8685
*/
8786

88-
static void ftdi_gpio_parse_config(struct ftdi_gpio *ftdi_gpio, char *control_dev)
87+
static void ftdi_gpio_parse_config(struct ftdi_gpio *ftdi_gpio, char *value)
8988
{
9089
char *c, *interface;
9190
size_t device_len;
9291

9392
// First libftdi description
94-
c = strchr(control_dev, ';');
93+
c = strchr(value, ';');
9594
if (!c)
96-
device_len = strlen(control_dev);
95+
device_len = strlen(value);
9796
else
98-
device_len = c - control_dev;
97+
device_len = c - value;
9998

100-
ftdi_gpio->ftdi_device = strndup(control_dev, device_len);
99+
ftdi_gpio->ftdi.description = strndup(value, device_len);
101100

102101
if (!c)
103102
return;
@@ -110,7 +109,7 @@ static void ftdi_gpio_parse_config(struct ftdi_gpio *ftdi_gpio, char *control_de
110109
*interface != 'D') {
111110
errx(1, "Invalid interface '%c'", *interface);
112111
}
113-
ftdi_gpio->ftdi_interface = *interface - 'A';
112+
ftdi_gpio->ftdi.interface = *interface - 'A';
114113

115114
c = strchr(interface, ';');
116115

@@ -119,7 +118,7 @@ static void ftdi_gpio_parse_config(struct ftdi_gpio *ftdi_gpio, char *control_de
119118
char *name, *off, *pol;
120119
unsigned gpio_type;
121120
unsigned gpio_offset;
122-
unsigned gpio_polarity;
121+
bool active_low;
123122

124123
name = c + 1;
125124
off = strchr(name, ',');
@@ -151,15 +150,15 @@ static void ftdi_gpio_parse_config(struct ftdi_gpio *ftdi_gpio, char *control_de
151150
errx(1, "GPIOs offset invalid: '%u'", gpio_offset);
152151

153152
if (strncmp("ACTIVE_HIGH", pol, c - pol - 1) == 0)
154-
gpio_polarity = GPIO_ACTIVE_HIGH;
153+
active_low = false;
155154
else if (strncmp("ACTIVE_LOW", pol, c - pol - 1) == 0)
156-
gpio_polarity = GPIO_ACTIVE_LOW;
155+
active_low = true;
157156
else
158157
errx(1, "GPIOs polarity invalid: '%s'", pol);
159158

160-
ftdi_gpio->gpio_present[gpio_type] = 1;
161-
ftdi_gpio->gpio_offset[gpio_type] = gpio_offset;
162-
ftdi_gpio->gpio_polarity[gpio_type] = gpio_polarity;
159+
ftdi_gpio->gpios[gpio_type].present = true;
160+
ftdi_gpio->gpios[gpio_type].offset = gpio_offset;
161+
ftdi_gpio->gpios[gpio_type].active_low = active_low;
163162
}
164163
}
165164

@@ -175,15 +174,16 @@ static void *ftdi_gpio_open(struct device *dev)
175174
if ((ftdi_gpio->gpio = ftdi_new()) == 0)
176175
errx(1, "failed to allocate ftdi gpio struct");
177176

178-
ftdi_set_interface(ftdi_gpio->gpio, INTERFACE_A + ftdi_gpio->ftdi_interface);
177+
ftdi_set_interface(ftdi_gpio->gpio, INTERFACE_A + ftdi_gpio->ftdi.interface);
179178

180-
ret = ftdi_usb_open_string(ftdi_gpio->gpio, ftdi_gpio->ftdi_device);
179+
ret = ftdi_usb_open_string(ftdi_gpio->gpio, ftdi_gpio->ftdi.description);
181180
if (ret < 0)
182-
errx(1, "failed to open ftdi gpio device '%s' (%d)", ftdi_gpio->ftdi_device, ret);
181+
errx(1, "failed to open ftdi gpio device '%s' (%d)",
182+
ftdi_gpio->ftdi.description, ret);
183183

184184
ftdi_set_bitmode(ftdi_gpio->gpio, 0xFF, BITMODE_BITBANG);
185185

186-
if (ftdi_gpio->gpio_present[GPIO_POWER_KEY])
186+
if (ftdi_gpio->gpios[GPIO_POWER_KEY].present)
187187
dev->has_power_key = true;
188188

189189
ftdi_gpio_device_power(ftdi_gpio, 0);
@@ -205,12 +205,12 @@ static int ftdi_gpio_toggle_io(struct ftdi_gpio *ftdi_gpio, unsigned int gpio, b
205205
{
206206
unsigned int bit;
207207

208-
if (!ftdi_gpio->gpio_present[gpio])
208+
if (!ftdi_gpio->gpios[gpio].present)
209209
return -EINVAL;
210210

211-
bit = ftdi_gpio->gpio_offset[gpio];
211+
bit = ftdi_gpio->gpios[gpio].offset;
212212

213-
if (ftdi_gpio->gpio_polarity[gpio])
213+
if (ftdi_gpio->gpios[gpio].active_low)
214214
on = !on;
215215

216216
if (on)

0 commit comments

Comments
 (0)