From bd4f46b1ffaf0f87a8e554ff6b50650db5cc3db0 Mon Sep 17 00:00:00 2001
From: Joerg Wunsch <j@uriah.heep.sax.de>
Date: Sat, 27 Nov 2021 15:48:30 +0000
Subject: [PATCH] patch #10030: linuxspi: Support inverted GPIO pin Submitted
 by Alex Sverdlin: * linuxspi.c (linuxspi_open): Clear the inversion mask on
 request and set default state to avoid short glitches on the GPIO line.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1494 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 ChangeLog  | 7 +++++++
 NEWS       | 1 +
 linuxspi.c | 3 ++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 1ab59c42..161e66d3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-11-27  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
+
+	Submitted by Alex Sverdlin:
+	patch #10030: linuxspi: Support inverted GPIO pin
+	* linuxspi.c (linuxspi_open): Clear the inversion mask on request
+	and set default state to avoid short glitches on the GPIO line.
+
 2021-11-27  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	Submitted by Alex Sverdlin:
diff --git a/NEWS b/NEWS
index 9d6777a8..e1e20885 100644
--- a/NEWS
+++ b/NEWS
@@ -120,6 +120,7 @@ Current:
     patch #10027: linuxspi: Add reset pulse, according to AVR programming algorithm
     patch #10028: linuxspi: close() only when necessary
     patch #10029: linuxspi: Report GPIO_GET_LINEHANDLE_IOCTL errors
+    patch #10030: linuxspi: Support inverted GPIO pin
 
   * Internals:
     - New avrdude.conf keyword "family_id", used to verify SIB attributes
diff --git a/linuxspi.c b/linuxspi.c
index 6675f48a..da2821f2 100644
--- a/linuxspi.c
+++ b/linuxspi.c
@@ -164,7 +164,8 @@ static int linuxspi_open(PROGRAMMER *pgm, char *port)
 
     strcpy(req.consumer_label, progname);
     req.lines = 1;
-    req.lineoffsets[0] = pgm->pinno[PIN_AVR_RESET];
+    req.lineoffsets[0] = pgm->pinno[PIN_AVR_RESET] & ~PIN_INVERSE;
+    req.default_values[0] = !!(pgm->pinno[PIN_AVR_RESET] & PIN_INVERSE);
     req.flags = GPIOHANDLE_REQUEST_OUTPUT;
 
     ret = ioctl(fd_gpiochip, GPIO_GET_LINEHANDLE_IOCTL, &req);