Skip to content

Commit 18fe8ef

Browse files
committed
patch #10031: linuxspi: Support GPIO uAPI v2
Submitted by Alex Sverdlin: * linuxspi.c (linuxspi_reset_mcu, linuxspi_open): Since Linux v5.10 GPIO ABI Version 1 is optional and depends on CONFIG_GPIO_CDEV_V1. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1495 81a1dc3b-b13d-400b-aceb-764788c761c2
1 parent bd4f46b commit 18fe8ef

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2021-11-27 Joerg Wunsch <[email protected]>
2+
3+
Submitted by Alex Sverdlin:
4+
patch #10031: linuxspi: Support GPIO uAPI v2
5+
* linuxspi.c (linuxspi_reset_mcu, linuxspi_open): Since Linux
6+
v5.10 GPIO ABI Version 1 is optional and depends on
7+
CONFIG_GPIO_CDEV_V1.
8+
19
2021-11-27 Joerg Wunsch <[email protected]>
210

311
Submitted by Alex Sverdlin:

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Current:
121121
patch #10028: linuxspi: close() only when necessary
122122
patch #10029: linuxspi: Report GPIO_GET_LINEHANDLE_IOCTL errors
123123
patch #10030: linuxspi: Support inverted GPIO pin
124+
patch #10031: linuxspi: Support GPIO uAPI v2
124125

125126
* Internals:
126127
- New avrdude.conf keyword "family_id", used to verify SIB attributes

linuxspi.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ static int linuxspi_reset_mcu(PROGRAMMER *pgm, bool active)
109109
*/
110110
data.values[0] = active ^ !(pgm->pinno[PIN_AVR_RESET] & PIN_INVERSE);
111111
ret = ioctl(fd_linehandle, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
112+
#ifdef GPIO_V2_LINE_SET_VALUES_IOCTL
113+
if (ret == -1) {
114+
struct gpio_v2_line_values val;
115+
116+
val.mask = 1;
117+
val.bits = active ^ !(pgm->pinno[PIN_AVR_RESET] & PIN_INVERSE);
118+
119+
ret = ioctl(fd_linehandle, GPIO_V2_LINE_SET_VALUES_IOCTL, &val);
120+
}
121+
#endif
112122
if (ret == -1) {
113123
ret = -errno;
114124
avrdude_message(MSG_INFO, "%s error: Unable to set GPIO line %d value\n",
@@ -169,15 +179,34 @@ static int linuxspi_open(PROGRAMMER *pgm, char *port)
169179
req.flags = GPIOHANDLE_REQUEST_OUTPUT;
170180

171181
ret = ioctl(fd_gpiochip, GPIO_GET_LINEHANDLE_IOCTL, &req);
182+
if (ret != -1)
183+
fd_linehandle = req.fd;
184+
#ifdef GPIO_V2_GET_LINE_IOCTL
185+
if (ret == -1) {
186+
struct gpio_v2_line_request reqv2;
187+
188+
memset(&reqv2, 0, sizeof(reqv2));
189+
reqv2.offsets[0] = pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE;
190+
strncpy(reqv2.consumer, progname, sizeof(reqv2.consumer) - 1);
191+
reqv2.config.flags = GPIO_V2_LINE_FLAG_OUTPUT;
192+
reqv2.config.num_attrs = 1;
193+
reqv2.config.attrs[0].attr.id = GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES;
194+
reqv2.config.attrs[0].attr.values = !!(pgm->pinno[PIN_AVR_RESET] & PIN_INVERSE);
195+
reqv2.config.attrs[0].mask = 1;
196+
reqv2.num_lines = 1;
197+
198+
ret = ioctl(fd_gpiochip, GPIO_V2_GET_LINE_IOCTL, &reqv2);
199+
if (ret != -1)
200+
fd_linehandle = reqv2.fd;
201+
}
202+
#endif
172203
if (ret == -1) {
173204
ret = -errno;
174205
avrdude_message(MSG_INFO, "%s error: Unable to get GPIO line %d\n",
175206
progname, pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE);
176207
goto close_gpiochip;
177208
}
178209

179-
fd_linehandle = req.fd;
180-
181210
ret = linuxspi_reset_mcu(pgm, true);
182211
if (ret)
183212
goto close_out;

0 commit comments

Comments
 (0)