Skip to contentSkip to conversation

treewide: remove more cruft and

PATCH Superseded Bartosz Golaszewski 5 participants 22 messages Jan 11, 2021 – Jan 28, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover treewide: remove more cruft and

From: Bartosz Golaszewski <[email protected]>

This is another batch of improvements to libgpiod before we overhaul the data structure model.

The last patch adds the kernel uapi header to the repository so that we no longer depend on its presence on the host system.

Bartosz Golaszewski (6):
treewide: remove helpers for opening chips by name & number
treewide: simplify the active-low line property
treewide: rename BIAS_AS_IS to BIAS_NONE
treewide: make drive settings an enum
bindings: cxx: line: reorder bias mapping entries
core: add the kernel uapi header to the repository

 bindings/cxx/chip.cpp                  |  41 +-
 bindings/cxx/examples/gpioinfocxx.cpp  |   3 +-
 bindings/cxx/gpiod.hpp                 |  57 +--
 bindings/cxx/line.cpp                  |  28 +-
 bindings/cxx/tests/tests-chip.cpp      |  97 +----
 bindings/cxx/tests/tests-event.cpp     |  14 +-
 bindings/cxx/tests/tests-iter.cpp      |   2 +-
 bindings/cxx/tests/tests-line.cpp      |  93 ++---
 bindings/python/examples/gpioinfo.py   |   4 +-
 bindings/python/gpiodmodule.c          | 167 +++-----
 bindings/python/tests/gpiod_py_test.py | 173 ++++----
 configure.ac                           |  12 +-
 include/gpiod.h                        |  65 +--
 lib/Makefile.am                        |   2 +-
 lib/core.c                             |  29 +-
 lib/helpers.c                          |  57 ---
 lib/uapi/gpio.h                        | 522 +++++++++++++++++++++++++
 tests/tests-chip.c                     |  41 --
 tests/tests-line.c                     | 100 ++---
 tools/gpiodetect.c                     |   2 +-
 tools/gpiofind.c                       |   2 +-
 tools/gpioget.c                        |   2 +-
 tools/gpioinfo.c                       |  28 +-
 tools/gpiomon.c                        |   2 +-
 tools/gpioset.c                        |   2 +-
 tools/tools-common.c                   |  57 +++
 tools/tools-common.h                   |   3 +
 27 files changed, 903 insertions(+), 702 deletions(-)
 create mode 100644 lib/uapi/gpio.h
Signature · 1 line
2.29.1
#1 lore raw

PATCH 1/6 treewide: remove helpers for opening chips by name & number

From: Bartosz Golaszewski <[email protected]>

Helper wrappers around gpiod_chip_open() shouldn't really be part of the core, low-level library. They assume that devtmpfs is mounted at /dev and that GPIO chips follow the gpiochipX naming convention.

This changeset removes all variants of gpiod_chip_open() other than the one taking the path as argument. We're doing this treewide so C++ and Python bindings lose the 'how' argument that currently allows to change the way the chips are opened by the chip's constructors or the open() method in C++.

The gpio-tools programs still support opening chips by number, name and path but they implement this functionality locally rather than using the library code.

---
 bindings/cxx/chip.cpp                  |  41 +-------
 bindings/cxx/gpiod.hpp                 |  25 +----
 bindings/cxx/tests/tests-chip.cpp      |  97 +++---------------
 bindings/cxx/tests/tests-event.cpp     |  14 +--
 bindings/cxx/tests/tests-iter.cpp      |   2 +-
 bindings/cxx/tests/tests-line.cpp      |  16 +--
 bindings/python/gpiodmodule.c          |  57 ++---------
 bindings/python/tests/gpiod_py_test.py | 133 +++++++++++--------------
 include/gpiod.h                        |  29 ------
 lib/helpers.c                          |  57 -----------
 tests/tests-chip.c                     |  41 --------
 tools/gpiodetect.c                     |   2 +-
 tools/gpiofind.c                       |   2 +-
 tools/gpioget.c                        |   2 +-
 tools/gpioinfo.c                       |   4 +-
 tools/gpiomon.c                        |   2 +-
 tools/gpioset.c                        |   2 +-
 tools/tools-common.c                   |  57 +++++++++++
 tools/tools-common.h                   |   3 +
 19 files changed, 167 insertions(+), 419 deletions(-)
bindings/cxx/chip.cpp +5 -36
index 107088e..59351dd 100644
@@ -15,35 +15,6 @@ namespace gpiod {
 
 namespace {
 
-::gpiod_chip* open_lookup(const ::std::string& device)
-{
-	return ::gpiod_chip_open_lookup(device.c_str());
-}
-
-::gpiod_chip* open_by_path(const ::std::string& device)
-{
-	return ::gpiod_chip_open(device.c_str());
-}
-
-::gpiod_chip* open_by_name(const ::std::string& device)
-{
-	return ::gpiod_chip_open_by_name(device.c_str());
-}
-
-::gpiod_chip* open_by_number(const ::std::string& device)
-{
-	return ::gpiod_chip_open_by_number(::std::stoul(device));
-}
-
-using open_func = ::std::function<::gpiod_chip* (const ::std::string&)>;
-
-const ::std::map<int, open_func> open_funcs = {
-	{ chip::OPEN_LOOKUP,	open_lookup,	},
-	{ chip::OPEN_BY_PATH,	open_by_path,	},
-	{ chip::OPEN_BY_NAME,	open_by_name,	},
-	{ chip::OPEN_BY_NUMBER,	open_by_number,	},
-};
-
 void chip_deleter(::gpiod_chip* chip)
 {
 	::gpiod_chip_close(chip);
@@ -56,10 +27,10 @@ bool is_gpiochip_device(const ::std::string& path)
 	return ::gpiod_is_gpiochip_device(path.c_str());
 }
 
-chip::chip(const ::std::string& device, int how)
+chip::chip(const ::std::string& path)
 	: _m_chip()
 {
-	this->open(device, how);
+	this->open(path);
 }
 
 chip::chip(::gpiod_chip* chip)
@@ -74,14 +45,12 @@ chip::chip(const ::std::weak_ptr<::gpiod_chip>& chip_ptr)
 
 }
 
-void chip::open(const ::std::string& device, int how)
+void chip::open(const ::std::string& path)
 {
-	auto func = open_funcs.at(how);
-
-	::gpiod_chip *chip = func(device);
+	::gpiod_chip *chip = ::gpiod_chip_open(path.c_str());
 	if (!chip)
 		throw ::std::system_error(errno, ::std::system_category(),
-					  "cannot open GPIO device " + device);
+					  "cannot open GPIO device " + path);
 
 	this->_m_chip.reset(chip, chip_deleter);
 }
bindings/cxx/gpiod.hpp +4 -21
index d81ee30..6c9ccd6 100644
@@ -58,10 +58,9 @@ public:
 
 	/**
 	 * @brief Constructor. Opens the chip using chip::open.
-	 * @param device String describing the GPIO chip.
-	 * @param how Indicates how the chip should be opened.
+	 * @param path Path to the GPIO chip device.
 	 */
-	GPIOD_API chip(const ::std::string& device, int how = OPEN_LOOKUP);
+	GPIOD_API chip(const ::std::string& path);
 
 	/**
 	 * @brief Copy constructor. References the object held by other.
@@ -96,13 +95,12 @@ public:
 
 	/**
 	 * @brief Open a GPIO chip.
-	 * @param device String describing the GPIO chip.
-	 * @param how Indicates how the chip should be opened.
+	 * @param path Path to the GPIO chip device.
 	 *
 	 * If the object already holds a reference to an open chip, it will be
 	 * closed and the reference reset.
 	 */
-	GPIOD_API void open(const ::std::string &device, int how = OPEN_LOOKUP);
+	GPIOD_API void open(const ::std::string &path);
 
 	/**
 	 * @brief Reset the internal smart pointer owned by this object.
@@ -184,21 +182,6 @@ public:
 	 */
 	GPIOD_API bool operator!(void) const noexcept;
 
-	/**
-	 * @brief Affect the way in which chip::chip and chip::open will try
-	 *        to open a GPIO chip character device.
-	 */
-	enum : int {
-		OPEN_LOOKUP = 1,
-		/**< Open based on the best guess what the supplied string is. */
-		OPEN_BY_PATH,
-		/**< Assume the string is a path to the GPIO chardev. */
-		OPEN_BY_NAME,
-		/**< Assume the string is the name of the chip */
-		OPEN_BY_NUMBER,
-		/**< Assume the string is the number of the GPIO chip. */
-	};
-
 private:
 
 	chip(::gpiod_chip* chip);
bindings/cxx/tests/tests-chip.cpp +13 -84

158 lines not on this page · raw message

bindings/cxx/tests/tests-event.cpp +7 -7
index 6d1c069..97ea670 100644
@@ -24,7 +24,7 @@ TEST_CASE("Line events can be detected", "[event][line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
 	mockup::event_thread events(0, 4, 200);
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto line = chip.get_line(4);
 	::gpiod::line_request config;
 
@@ -105,7 +105,7 @@ TEST_CASE("Watching line_bulk objects for events works", "[event][bulk]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
 	mockup::event_thread events(0, 2, 200);
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto lines = chip.get_lines({ 0, 1, 2, 3 });
 	::gpiod::line_request config;
 
@@ -133,7 +133,7 @@ TEST_CASE("Watching line_bulk objects for events works", "[event][bulk]")
 TEST_CASE("It's possible to retrieve the event file descriptor", "[event][line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto line = chip.get_line(4);
 	::gpiod::line_request config;
 
@@ -165,7 +165,7 @@ TEST_CASE("Event file descriptors can be used for polling", "[event]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
 	mockup::event_thread events(0, 3, 200);
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto lines = chip.get_lines({ 0, 1, 2, 3, 4, 5 });
 
 	::gpiod::line_request config;
@@ -196,7 +196,7 @@ TEST_CASE("Event file descriptors can be used for polling", "[event]")
 TEST_CASE("It's possible to read a value from a line requested for events", "[event][line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto line = chip.get_line(4);
 	::gpiod::line_request config;
 
@@ -222,7 +222,7 @@ TEST_CASE("It's possible to read a value from a line requested for events", "[ev
 TEST_CASE("It's possible to read values from lines requested for events", "[event][bulk]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto lines = chip.get_lines({ 0, 1, 2, 3, 4 });
 	::gpiod::line_request config;
 
@@ -256,7 +256,7 @@ TEST_CASE("It's possible to read values from lines requested for events", "[even
 TEST_CASE("It's possible to read more than one line event", "[event][line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto line = chip.get_line(4);
 	::gpiod::line_request config;
 
bindings/cxx/tests/tests-iter.cpp +1 -1
index 708709c..0dee754 100644
@@ -15,7 +15,7 @@ using ::gpiod::test::mockup;
 TEST_CASE("Line iterator works", "[iter][line]")
 {
 	mockup::probe_guard mockup_chips({ 4 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	unsigned int count = 0;
 
 	for (auto& it: ::gpiod::line_iter(chip))
bindings/cxx/tests/tests-line.cpp +8 -8
index a5499ac..53b1d03 100644
@@ -21,7 +21,7 @@ const ::std::string consumer = "line-test";
 TEST_CASE("Line information can be correctly retrieved", "[line]")
 {
 	mockup::probe_guard mockup_chips({ 8 }, mockup::FLAG_NAMED_LINES);
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto line = chip.get_line(4);
 
 	SECTION("unexported line")
@@ -167,7 +167,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 TEST_CASE("Line bulk object works correctly", "[line][bulk]")
 {
 	mockup::probe_guard mockup_chips({ 8 }, mockup::FLAG_NAMED_LINES);
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 
 	SECTION("lines can be added, accessed and cleared")
 	{
@@ -210,7 +210,7 @@ TEST_CASE("Line bulk object works correctly", "[line][bulk]")
 TEST_CASE("Line values can be set and read", "[line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	::gpiod::line_request config;
 
 	config.consumer = consumer.c_str();
@@ -308,7 +308,7 @@ TEST_CASE("Line values can be set and read", "[line]")
 TEST_CASE("Line can be reconfigured", "[line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	::gpiod::line_request config;
 
 	config.consumer = consumer.c_str();
@@ -436,7 +436,7 @@ TEST_CASE("Line can be reconfigured", "[line]")
 TEST_CASE("Exported line can be released", "[line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto line = chip.get_line(4);
 	::gpiod::line_request config;
 
@@ -487,7 +487,7 @@ TEST_CASE("Uninitialized GPIO line_bulk behaves correctly", "[line][bulk]")
 TEST_CASE("Cannot request the same line twice", "[line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	::gpiod::line_request config;
 
 	config.consumer = consumer.c_str();
@@ -516,7 +516,7 @@ TEST_CASE("Cannot request the same line twice", "[line]")
 TEST_CASE("Cannot get/set values of unrequested lines", "[line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto line = chip.get_line(3);
 
 	SECTION("get value")
@@ -533,7 +533,7 @@ TEST_CASE("Cannot get/set values of unrequested lines", "[line]")
 TEST_CASE("Line objects can be compared")
 {
 	mockup::probe_guard mockup_chips({ 8 });
-	::gpiod::chip chip(mockup::instance().chip_name(0));
+	::gpiod::chip chip(mockup::instance().chip_path(0));
 	auto line1 = chip.get_line(3);
 	auto line2 = chip.get_line(3);
 	auto line3 = chip.get_line(4);
bindings/python/gpiodmodule.c +6 -51

76 lines not on this page · raw message

bindings/python/tests/gpiod_py_test.py +56 -77

466 lines not on this page · raw message

include/gpiod.h +0 -29
index b82d507..b073b3b 100644
@@ -84,35 +84,6 @@ bool gpiod_is_gpiochip_device(const char *path) GPIOD_API;
  */
 struct gpiod_chip *gpiod_chip_open(const char *path) GPIOD_API;
 
-/**
- * @brief Open a gpiochip by name.
- * @param name Name of the gpiochip to open.
- * @return GPIO chip handle or NULL if an error occurred.
- *
- * This routine appends name to '/dev/' to create the path.
- */
-struct gpiod_chip *gpiod_chip_open_by_name(const char *name) GPIOD_API;
-
-/**
- * @brief Open a gpiochip by number.
- * @param num Number of the gpiochip.
- * @return GPIO chip handle or NULL if an error occurred.
- *
- * This routine appends num to '/dev/gpiochip' to create the path.
- */
-struct gpiod_chip *gpiod_chip_open_by_number(unsigned int num) GPIOD_API;
-
-/**
- * @brief Open a gpiochip based on the best guess what the path is.
- * @param descr String describing the gpiochip.
- * @return GPIO chip handle or NULL if an error occurred.
- *
- * This routine tries to figure out whether the user passed it the path to the
- * GPIO chip, its name or number as a string. Then it tries to open it using
- * one of the gpiod_chip_open** variants.
- */
-struct gpiod_chip *gpiod_chip_open_lookup(const char *descr) GPIOD_API;
-
 /**
  * @brief Close a GPIO chip handle and release all allocated resources.
  * @param chip The GPIO chip object.
lib/helpers.c +0 -57

68 lines not on this page · raw message

tests/tests-chip.c +0 -41

47 lines not on this page · raw message

tools/gpiodetect.c +1 -1
index 8e067f7..6f94f91 100644
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
 		die_perror("unable to scan /dev");
 
 	for (i = 0; i < num_chips; i++) {
-		chip = gpiod_chip_open_by_name(entries[i]->d_name);
+		chip = chip_open_by_name(entries[i]->d_name);
 		if (!chip) {
 			if (errno == EACCES)
 				printf("%s Permission denied\n",
tools/gpiofind.c +1 -1
index 4acf621..3760ada 100644
@@ -70,7 +70,7 @@ int main(int argc, char **argv)
 		die_perror("unable to scan /dev");
 
 	for (i = 0; i < num_chips; i++) {
-		chip = gpiod_chip_open_by_name(entries[i]->d_name);
+		chip = chip_open_by_name(entries[i]->d_name);
 		if (!chip) {
 			if (errno == EACCES)
 				continue;
tools/gpioget.c +1 -1
index 11a9c9f..efbacce 100644
@@ -97,7 +97,7 @@ int main(int argc, char **argv)
 			die("invalid GPIO offset: %s", argv[i + 1]);
 	}
 
-	chip = gpiod_chip_open_lookup(device);
+	chip = chip_open_lookup(device);
 	if (!chip)
 		die_perror("unable to open %s", device);
 
tools/gpioinfo.c +2 -2
index e3dbde7..057a19f 100644
@@ -214,7 +214,7 @@ int main(int argc, char **argv)
 			die_perror("unable to scan /dev");
 
 		for (i = 0; i < num_chips; i++) {
-			chip = gpiod_chip_open_by_name(entries[i]->d_name);
+			chip = chip_open_by_name(entries[i]->d_name);
 			if (!chip) {
 				if (errno == EACCES)
 					printf("%s Permission denied\n",
@@ -230,7 +230,7 @@ int main(int argc, char **argv)
 		}
 	} else {
 		for (i = 0; i < argc; i++) {
-			chip = gpiod_chip_open_lookup(argv[i]);
+			chip = chip_open_lookup(argv[i]);
 			if (!chip)
 				die_perror("looking up chip %s", argv[i]);
 
tools/gpiomon.c +1 -1
index c271913..3586cb4 100644
@@ -253,7 +253,7 @@ int main(int argc, char **argv)
 		num_lines++;
 	}
 
-	chip = gpiod_chip_open_lookup(argv[0]);
+	chip = chip_open_lookup(argv[0]);
 	if (!chip)
 		die_perror("unable to open %s", argv[0]);
 
tools/gpioset.c +1 -1
index 7f4615a..20a7d3b 100644
@@ -288,7 +288,7 @@ int main(int argc, char **argv)
 			die("invalid offset: %s", argv[i + 1]);
 	}
 
-	chip = gpiod_chip_open_lookup(device);
+	chip = chip_open_lookup(device);
 	if (!chip)
 		die_perror("unable to open %s", device);
 
tools/tools-common.c +57 -0

66 lines not on this page · raw message

tools/tools-common.h +3 -0
index 4148dd8..866f809 100644
@@ -9,6 +9,7 @@
 #define __GPIOD_TOOLS_COMMON_H__
 
 #include <dirent.h>
+#include <gpiod.h>
 
 /*
  * Various helpers for the GPIO tools.
@@ -32,5 +33,7 @@ int bias_flags(const char *option);
 void print_bias_help(void);
 int make_signalfd(void);
 int chip_dir_filter(const struct dirent *entry);
+struct gpiod_chip *chip_open_by_name(const char *name);
+struct gpiod_chip *chip_open_lookup(const char *device);
 
 #endif /* __GPIOD_TOOLS_COMMON_H__ */
Signature · 1 line
2.29.1
#2 lore raw

PATCH 2/6 treewide: simplify the active-low line property

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Unlike line direction - where input and output modes are equal, no signal inversion (active-high) is the natural state of the line while active-low is less likely. Let's drop the ACTIVE_STATE enum treewide and provide a boolean property for lines - is_active_low() - to reflect that fact. This function returning false means the line is "active-high".

---
 bindings/cxx/examples/gpioinfocxx.cpp  |  3 +-
 bindings/cxx/gpiod.hpp                 | 16 ++------
 bindings/cxx/line.cpp                  |  6 +--
 bindings/cxx/tests/tests-line.cpp      | 24 ++++++------
 bindings/python/examples/gpioinfo.py   |  4 +-
 bindings/python/gpiodmodule.c          | 45 ++++++----------------
 bindings/python/tests/gpiod_py_test.py | 16 ++++----
 include/gpiod.h                        | 16 ++------
 lib/core.c                             | 12 +++---
 tests/tests-line.c                     | 52 +++++++++-----------------
 tools/gpioinfo.c                       | 10 ++---
 11 files changed, 69 insertions(+), 135 deletions(-)
bindings/cxx/examples/gpioinfocxx.cpp +1 -2
index 2490abd..384286e 100644
@@ -44,8 +44,7 @@ int main(int argc, char **argv)
 				::std::cout << " ";
 
 				::std::cout.width(10);
-				::std::cout << (lit.active_state() == ::gpiod::line::ACTIVE_LOW
-									? "active-low" : "active-high");
+				::std::cout << (lit.is_active_low() ? "active-low" : "active-high");
 
 				::std::cout << ::std::endl;
 			}
bindings/cxx/gpiod.hpp +3 -13
index 6c9ccd6..8b4a8f9 100644
@@ -313,10 +313,10 @@ public:
 	GPIOD_API int direction(void) const;
 
 	/**
-	 * @brief Get current active state of this line.
-	 * @return Current active state setting.
+	 * @brief Check if this line's signal is inverted.
+	 * @return True if this line is "active-low", false otherwise.
 	 */
-	GPIOD_API int active_state(void) const;
+	GPIOD_API bool is_active_low(void) const;
 
 	/**
 	 * @brief Get current bias of this line.
@@ -482,16 +482,6 @@ public:
 		/**< Line's direction setting is output. */
 	};
 
-	/**
-	 * @brief Possible active state settings.
-	 */
-	enum : int {
-		ACTIVE_LOW = 1,
-		/**< Line's active state is low. */
-		ACTIVE_HIGH,
-		/**< Line's active state is high. */
-	};
-
 	/**
 	 * @brief Possible bias settings.
 	 */
bindings/cxx/line.cpp +2 -4
index 54382e2..5a907db 100644
@@ -74,14 +74,12 @@ int line::direction(void) const
 	return dir == GPIOD_LINE_DIRECTION_INPUT ? DIRECTION_INPUT : DIRECTION_OUTPUT;
 }
 
-int line::active_state(void) const
+bool line::is_active_low(void) const
 {
 	this->throw_if_null();
 	line::chip_guard lock_chip(*this);
 
-	int active = ::gpiod_line_active_state(this->_m_line);
-
-	return active == GPIOD_LINE_ACTIVE_STATE_HIGH ? ACTIVE_HIGH : ACTIVE_LOW;
+	return ::gpiod_line_is_active_low(this->_m_line);
 }
 
 int line::bias(void) const
bindings/cxx/tests/tests-line.cpp +12 -12
index 53b1d03..3c7ea39 100644
@@ -29,7 +29,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.offset() == 4);
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_INPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+		REQUIRE_FALSE(line.is_active_low());
 		REQUIRE(line.consumer().empty());
 		REQUIRE_FALSE(line.is_requested());
 		REQUIRE_FALSE(line.is_used());
@@ -49,7 +49,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.offset() == 4);
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+		REQUIRE_FALSE(line.is_active_low());
 		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE_FALSE(line.is_open_drain());
@@ -70,7 +70,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.offset() == 4);
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_LOW);
+		REQUIRE(line.is_active_low());
 		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE(line.is_open_drain());
@@ -90,7 +90,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.offset() == 4);
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+		REQUIRE_FALSE(line.is_active_low());
 		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE_FALSE(line.is_open_drain());
@@ -110,7 +110,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.offset() == 4);
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+		REQUIRE_FALSE(line.is_active_low());
 		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE_FALSE(line.is_open_drain());
@@ -130,7 +130,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.offset() == 4);
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+		REQUIRE_FALSE(line.is_active_low());;
 		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE_FALSE(line.is_open_drain());
@@ -150,7 +150,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.offset() == 4);
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+		REQUIRE_FALSE(line.is_active_low());
 		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE_FALSE(line.is_open_drain());
@@ -320,19 +320,19 @@ TEST_CASE("Line can be reconfigured", "[line]")
 		config.flags = 0;
 		line.request(config);
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_INPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+		REQUIRE_FALSE(line.is_active_low());
 
 		line.set_config(::gpiod::line_request::DIRECTION_OUTPUT,
 			::gpiod::line_request::FLAG_ACTIVE_LOW,1);
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_LOW);
+		REQUIRE(line.is_active_low());
 		REQUIRE(mockup::instance().chip_get_value(0, 3) == 0);
 		line.set_value(0);
 		REQUIRE(mockup::instance().chip_get_value(0, 3) == 1);
 
 		line.set_config(::gpiod::line_request::DIRECTION_OUTPUT, 0);
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+		REQUIRE_FALSE(line.is_active_low());
 		REQUIRE(mockup::instance().chip_get_value(0, 3) == 0);
 		line.set_value(1);
 		REQUIRE(mockup::instance().chip_get_value(0, 3) == 1);
@@ -348,12 +348,12 @@ TEST_CASE("Line can be reconfigured", "[line]")
 
 		line.set_flags(::gpiod::line_request::FLAG_ACTIVE_LOW);
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_LOW);
+		REQUIRE(line.is_active_low());
 		REQUIRE(mockup::instance().chip_get_value(0, 3) == 0);
 
 		line.set_flags(0);
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
-		REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+		REQUIRE_FALSE(line.is_active_low());
 		REQUIRE(mockup::instance().chip_get_value(0, 3) == 1);
 	}
 
bindings/python/examples/gpioinfo.py +2 -2
index 6a47b66..1593337 100755
@@ -23,11 +23,11 @@ if __name__ == '__main__':
                     name = line.name()
                     consumer = line.consumer()
                     direction = line.direction()
-                    active_state = line.active_state()
+                    active_low = line.is_active_low()
 
                     print('\tline {:>3}: {:>18} {:>12} {:>8} {:>10}'.format(
                           offset,
                           'unnamed' if name is None else name,
                           'unused' if consumer is None else consumer,
                           'input' if direction == gpiod.Line.DIRECTION_INPUT else 'output',
-                          'active-low' if active_state == gpiod.Line.ACTIVE_LOW else 'active-high'))
+                          'active-low' if active_low else 'active-high'))
bindings/python/gpiodmodule.c +11 -34

76 lines not on this page · raw message

bindings/python/tests/gpiod_py_test.py +8 -8
index 79294bc..3093a1c 100755
@@ -205,7 +205,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_INPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), None)
             self.assertFalse(line.is_used())
             self.assertFalse(line.is_requested())
@@ -219,7 +219,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_LOW)
+            self.assertTrue(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -235,7 +235,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_LOW)
+            self.assertTrue(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -253,7 +253,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -271,7 +271,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -289,7 +289,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -307,7 +307,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
@@ -325,7 +325,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.offset(), 4)
             self.assertEqual(line.name(), 'gpio-mockup-A-4')
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_OUTPUT)
-            self.assertEqual(line.active_state(), gpiod.Line.ACTIVE_HIGH)
+            self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
include/gpiod.h +3 -13
index b073b3b..75da84c 100644
@@ -280,16 +280,6 @@ enum {
 	/**< Direction is output - we're driving the GPIO line. */
 };
 
-/**
- * @brief Possible active state settings.
- */
-enum {
-	GPIOD_LINE_ACTIVE_STATE_HIGH = 1,
-	/**< The active state of a GPIO is active-high. */
-	GPIOD_LINE_ACTIVE_STATE_LOW,
-	/**< The active state of a GPIO is active-low. */
-};
-
 /**
  * @brief Possible internal bias settings.
  */
@@ -337,11 +327,11 @@ const char *gpiod_line_consumer(struct gpiod_line *line) GPIOD_API;
 int gpiod_line_direction(struct gpiod_line *line) GPIOD_API;
 
 /**
- * @brief Read the GPIO line active state setting.
+ * @brief Check if the signal of this line is inverted.
  * @param line GPIO line object.
- * @return Returns GPIOD_LINE_ACTIVE_STATE_HIGH or GPIOD_LINE_ACTIVE_STATE_LOW.
+ * @return True if this line is "active-low", false otherwise.
  */
-int gpiod_line_active_state(struct gpiod_line *line) GPIOD_API;
+bool gpiod_line_is_active_low(struct gpiod_line *line) GPIOD_API;
 
 /**
  * @brief Read the GPIO line bias setting.
lib/core.c +5 -7
index d96e6cf..c6fb474 100644
@@ -41,8 +41,8 @@ struct gpiod_line {
 	/* The direction of the GPIO line. */
 	int direction;
 
-	/* The active-state configuration. */
-	int active_state;
+	/* Is this line active-low?. */
+	bool active_low;
 
 	/* The logical value last written to the line. */
 	int output_value;
@@ -471,9 +471,9 @@ int gpiod_line_direction(struct gpiod_line *line)
 	return line->direction;
 }
 
-int gpiod_line_active_state(struct gpiod_line *line)
+bool gpiod_line_is_active_low(struct gpiod_line *line)
 {
-	return line->active_state;
+	return line->active_low;
 }
 
 int gpiod_line_bias(struct gpiod_line *line)
@@ -541,9 +541,7 @@ int gpiod_line_update(struct gpiod_line *line)
 						? GPIOD_LINE_DIRECTION_OUTPUT
 						: GPIOD_LINE_DIRECTION_INPUT;
 
-	line->active_state = info.flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW
-						? GPIOD_LINE_ACTIVE_STATE_LOW
-						: GPIOD_LINE_ACTIVE_STATE_HIGH;
+	line->active_low = !!(info.flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW);
 
 	line->info_flags = line_info_v2_to_info_flags(&info);
 
tests/tests-line.c +18 -34

114 lines not on this page · raw message

tools/gpioinfo.c +4 -6
index 057a19f..8d228ab 100644
@@ -117,11 +117,11 @@ static PRINTF(3, 4) void prinfo(bool *of,
 
 static void list_lines(struct gpiod_chip *chip)
 {
-	int direction, active_state;
+	bool flag_printed, of, active_low;
 	const char *name, *consumer;
 	struct gpiod_line *line;
 	unsigned int i, offset;
-	bool flag_printed, of;
+	int direction;
 
 	printf("%s - %u lines:\n",
 	       gpiod_chip_name(chip), gpiod_chip_num_lines(chip));
@@ -134,7 +134,7 @@ static void list_lines(struct gpiod_chip *chip)
 		name = gpiod_line_name(line);
 		consumer = gpiod_line_consumer(line);
 		direction = gpiod_line_direction(line);
-		active_state = gpiod_line_active_state(line);
+		active_low = gpiod_line_is_active_low(line);
 
 		of = false;
 
@@ -157,9 +157,7 @@ static void list_lines(struct gpiod_chip *chip)
 		prinfo(&of, 8, "%s ", direction == GPIOD_LINE_DIRECTION_INPUT
 							? "input" : "output");
 		prinfo(&of, 13, "%s ",
-		       active_state == GPIOD_LINE_ACTIVE_STATE_LOW
-							? "active-low"
-							: "active-high");
+		       active_low ? "active-low" : "active-high");
 
 		flag_printed = false;
 		for (i = 0; i < ARRAY_SIZE(flags); i++) {
Signature · 1 line
2.29.1
#3 lore raw

PATCH 3/6 treewide: rename BIAS_AS_IS to BIAS_NONE

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

When inspecting the current bias setting of a GPIO line, the AS_IS name of one of the possible values really means that there's no bias so it should be renamed to NONE for clarity.

---
 bindings/cxx/gpiod.hpp                 |  2 +-
 bindings/cxx/line.cpp                  |  2 +-
 bindings/cxx/tests/tests-line.cpp      |  8 ++++----
 bindings/python/gpiodmodule.c          | 10 +++++-----
 bindings/python/tests/gpiod_py_test.py |  6 +++---
 include/gpiod.h                        |  4 ++--
 lib/core.c                             |  2 +-
 tests/tests-line.c                     | 12 ++++++------
 8 files changed, 23 insertions(+), 23 deletions(-)
bindings/cxx/gpiod.hpp +1 -1
index 8b4a8f9..fb675fc 100644
@@ -486,7 +486,7 @@ public:
 	 * @brief Possible bias settings.
 	 */
 	enum : int {
-		BIAS_AS_IS = 1,
+		BIAS_NONE = 1,
 		/**< Line's bias state is unknown. */
 		BIAS_DISABLE,
 		/**< Line's internal bias is disabled. */
bindings/cxx/line.cpp +1 -1
index 5a907db..19c974d 100644
@@ -17,7 +17,7 @@ const ::std::map<int, int> bias_mapping = {
 	{ GPIOD_LINE_BIAS_PULL_UP,	line::BIAS_PULL_UP, },
 	{ GPIOD_LINE_BIAS_PULL_DOWN,	line::BIAS_PULL_DOWN, },
 	{ GPIOD_LINE_BIAS_DISABLE,	line::BIAS_DISABLE, },
-	{ GPIOD_LINE_BIAS_AS_IS,	line::BIAS_AS_IS, },
+	{ GPIOD_LINE_BIAS_NONE,		line::BIAS_NONE, },
 };
 
 } /* namespace */
bindings/cxx/tests/tests-line.cpp +4 -4
index 3c7ea39..2a6cdf8 100644
@@ -35,7 +35,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE_FALSE(line.is_used());
 		REQUIRE_FALSE(line.is_open_drain());
 		REQUIRE_FALSE(line.is_open_source());
-		REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS);
+		REQUIRE(line.bias() == ::gpiod::line::BIAS_NONE);
 	}
 
 	SECTION("exported line")
@@ -54,7 +54,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.is_used());
 		REQUIRE_FALSE(line.is_open_drain());
 		REQUIRE_FALSE(line.is_open_source());
-		REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS);
+		REQUIRE(line.bias() == ::gpiod::line::BIAS_NONE);
 	}
 
 	SECTION("exported line with flags")
@@ -75,7 +75,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.is_used());
 		REQUIRE(line.is_open_drain());
 		REQUIRE_FALSE(line.is_open_source());
-		REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS);
+		REQUIRE(line.bias() == ::gpiod::line::BIAS_NONE);
 	}
 
 	SECTION("exported open source line")
@@ -95,7 +95,7 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.is_used());
 		REQUIRE_FALSE(line.is_open_drain());
 		REQUIRE(line.is_open_source());
-		REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS);
+		REQUIRE(line.bias() == ::gpiod::line::BIAS_NONE);
 	}
 
 	SECTION("exported bias disable line")
bindings/python/gpiodmodule.c +5 -5
index b48a83a..228ac73 100644
@@ -68,7 +68,7 @@ enum {
 };
 
 enum {
-	gpiod_BIAS_AS_IS = 1,
+	gpiod_BIAS_NONE = 1,
 	gpiod_BIAS_DISABLE,
 	gpiod_BIAS_PULL_UP,
 	gpiod_BIAS_PULL_DOWN,
@@ -374,9 +374,9 @@ static PyObject *gpiod_Line_bias(gpiod_LineObject *self,
 		return Py_BuildValue("I", gpiod_BIAS_PULL_DOWN);
 	case GPIOD_LINE_BIAS_DISABLE:
 		return Py_BuildValue("I", gpiod_BIAS_DISABLE);
-	case GPIOD_LINE_BIAS_AS_IS:
+	case GPIOD_LINE_BIAS_NONE:
 	default:
-		return Py_BuildValue("I", gpiod_BIAS_AS_IS);
+		return Py_BuildValue("I", gpiod_BIAS_NONE);
 	}
 }
 
@@ -2527,8 +2527,8 @@ static gpiod_ConstDescr gpiod_ConstList[] = {
 	},
 	{
 		.typeobj = &gpiod_LineType,
-		.name = "BIAS_AS_IS",
-		.val = gpiod_BIAS_AS_IS,
+		.name = "BIAS_NONE",
+		.val = gpiod_BIAS_NONE,
 	},
 	{
 		.typeobj = &gpiod_LineType,
bindings/python/tests/gpiod_py_test.py +3 -3
index 3093a1c..d9521de 100755
@@ -241,7 +241,7 @@ class LineInfo(MockupTestCase):
             self.assertTrue(line.is_requested())
             self.assertTrue(line.is_open_drain())
             self.assertFalse(line.is_open_source())
-            self.assertEqual(line.bias(), gpiod.Line.BIAS_AS_IS)
+            self.assertEqual(line.bias(), gpiod.Line.BIAS_NONE)
 
     def test_exported_open_drain_line(self):
         with gpiod.Chip(mockup.chip_path(0)) as chip:
@@ -259,7 +259,7 @@ class LineInfo(MockupTestCase):
             self.assertTrue(line.is_requested())
             self.assertTrue(line.is_open_drain())
             self.assertFalse(line.is_open_source())
-            self.assertEqual(line.bias(), gpiod.Line.BIAS_AS_IS)
+            self.assertEqual(line.bias(), gpiod.Line.BIAS_NONE)
 
     def test_exported_open_source_line(self):
         with gpiod.Chip(mockup.chip_path(0)) as chip:
@@ -277,7 +277,7 @@ class LineInfo(MockupTestCase):
             self.assertTrue(line.is_requested())
             self.assertFalse(line.is_open_drain())
             self.assertTrue(line.is_open_source())
-            self.assertEqual(line.bias(), gpiod.Line.BIAS_AS_IS)
+            self.assertEqual(line.bias(), gpiod.Line.BIAS_NONE)
 
     def test_exported_bias_disable_line(self):
         with gpiod.Chip(mockup.chip_path(0)) as chip:
include/gpiod.h +2 -2
index 75da84c..18017d5 100644
@@ -284,7 +284,7 @@ enum {
  * @brief Possible internal bias settings.
  */
 enum {
-	GPIOD_LINE_BIAS_AS_IS = 1,
+	GPIOD_LINE_BIAS_NONE = 1,
 	/**< The internal bias state is unknown. */
 	GPIOD_LINE_BIAS_DISABLE,
 	/**< The internal bias is disabled. */
@@ -337,7 +337,7 @@ bool gpiod_line_is_active_low(struct gpiod_line *line) GPIOD_API;
  * @brief Read the GPIO line bias setting.
  * @param line GPIO line object.
  * @return Returns GPIOD_LINE_BIAS_PULL_UP, GPIOD_LINE_BIAS_PULL_DOWN,
- *         GPIOD_LINE_BIAS_DISABLE or GPIOD_LINE_BIAS_AS_IS.
+ *         GPIOD_LINE_BIAS_DISABLE or GPIOD_LINE_BIAS_NONE.
  */
 int gpiod_line_bias(struct gpiod_line *line) GPIOD_API;
 
lib/core.c +1 -1
index c6fb474..60b39c6 100644
@@ -485,7 +485,7 @@ int gpiod_line_bias(struct gpiod_line *line)
 	if (line->info_flags & GPIOLINE_FLAG_BIAS_PULL_DOWN)
 		return GPIOD_LINE_BIAS_PULL_DOWN;
 
-	return GPIOD_LINE_BIAS_AS_IS;
+	return GPIOD_LINE_BIAS_NONE;
 }
 
 bool gpiod_line_is_used(struct gpiod_line *line)
tests/tests-line.c +6 -6
index d6264af..07d5601 100644
@@ -418,7 +418,7 @@ GPIOD_TEST_CASE(set_flags_bias, 0, { 8 })
 	ret = gpiod_line_request_input(line, GPIOD_TEST_CONSUMER);
 	g_assert_cmpint(ret, ==, 0);
 	gpiod_test_return_if_failed();
-	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS);
+	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 
 	ret = gpiod_line_set_flags(line,
 		GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE);
@@ -762,7 +762,7 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 })
 	g_assert_false(gpiod_line_is_used(line));
 	g_assert_false(gpiod_line_is_open_drain(line));
 	g_assert_false(gpiod_line_is_open_source(line));
-	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS);
+	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 
 	config.request_type = GPIOD_LINE_REQUEST_DIRECTION_OUTPUT;
 	config.consumer = GPIOD_TEST_CONSUMER;
@@ -775,7 +775,7 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 })
 	g_assert_true(gpiod_line_is_used(line));
 	g_assert_true(gpiod_line_is_open_drain(line));
 	g_assert_false(gpiod_line_is_open_source(line));
-	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS);
+	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 	g_assert_cmpint(gpiod_line_direction(line), ==,
 			GPIOD_LINE_DIRECTION_OUTPUT);
 
@@ -790,7 +790,7 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 })
 	g_assert_true(gpiod_line_is_used(line));
 	g_assert_false(gpiod_line_is_open_drain(line));
 	g_assert_true(gpiod_line_is_open_source(line));
-	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS);
+	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 	g_assert_cmpint(gpiod_line_direction(line), ==,
 			GPIOD_LINE_DIRECTION_OUTPUT);
 
@@ -829,7 +829,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
 	g_assert_true(gpiod_line_is_used(line));
 	g_assert_true(gpiod_line_is_open_drain(line));
 	g_assert_false(gpiod_line_is_open_source(line));
-	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS);
+	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 	g_assert_true(gpiod_line_is_active_low(line));
 	g_assert_cmpint(gpiod_line_direction(line), ==,
 			GPIOD_LINE_DIRECTION_OUTPUT);
@@ -846,7 +846,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
 	g_assert_true(gpiod_line_is_used(line));
 	g_assert_false(gpiod_line_is_open_drain(line));
 	g_assert_true(gpiod_line_is_open_source(line));
-	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS);
+	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 	g_assert_true(gpiod_line_is_active_low(line));
 
 	gpiod_line_release(line);
Signature · 1 line
2.29.1
#4 lore raw

Re: [libgpiod][PATCH 3/6] treewide: rename BIAS_AS_IS to BIAS_NONE

Quoted 6 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

When inspecting the current bias setting of a GPIO line, the AS_IS name of one of the possible values really means that there's no bias so it should be renamed to NONE for clarity.

I disagree this one, as the BIAS_NONE can be confused with BIAS_DISABLED.

Its meaning depends on whether you are setting or reading the value. On write, for backwards compatibility, it means don't change the bias from what it was previously, hence the AS-IS naming.
On read it means unknown, as the uAPI can't determine bias setting unless it set it itself - so if it is set by DT then the cdev can't tell.

If you are going to change it I'd go with BIAS_UNKNOWN.

Cheers,
Kent.

#5 lore raw

PATCH 4/6 treewide: make drive settings an enum

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Open-source and open-drain drive settings are mutually exclusive just like the bias settings. Make them into an enum so that becomes clear.

---
 bindings/cxx/gpiod.hpp                 | 24 +++++----
 bindings/cxx/line.cpp                  | 18 +++----
 bindings/cxx/tests/tests-line.cpp      | 45 ++++++----------
 bindings/python/gpiodmodule.c          | 73 ++++++++++++++------------
 bindings/python/tests/gpiod_py_test.py | 18 +++----
 include/gpiod.h                        | 26 +++++----
 lib/core.c                             | 12 ++---
 tests/tests-line.c                     | 36 ++++++-------
 tools/gpioinfo.c                       | 14 ++++-
 9 files changed, 134 insertions(+), 132 deletions(-)
bindings/cxx/gpiod.hpp +15 -9
index fb675fc..f9c341d 100644
@@ -332,16 +332,10 @@ public:
 	GPIOD_API bool is_used(void) const;
 
 	/**
-	 * @brief Check if this line represents an open-drain GPIO.
-	 * @return True if the line is an open-drain GPIO, false otherwise.
+	 * @brief Get current drive setting of this line.
+	 * @return Current drive setting.
 	 */
-	GPIOD_API bool is_open_drain(void) const;
-
-	/**
-	 * @brief Check if this line represents an open-source GPIO.
-	 * @return True if the line is an open-source GPIO, false otherwise.
-	 */
-	GPIOD_API bool is_open_source(void) const;
+	GPIOD_API int drive(void) const;
 
 	/**
 	 * @brief Request this line.
@@ -482,6 +476,18 @@ public:
 		/**< Line's direction setting is output. */
 	};
 
+	/**
+	 * @brief Possible drive settings.
+	 */
+	enum : int {
+		DRIVE_NONE = 1,
+		/**< Drive setting is unknown. */
+		DRIVE_OPEN_DRAIN,
+		/**< Line output is open-drain. */
+		DRIVE_OPEN_SOURCE,
+		/**< Line output is open-source. */
+	};
+
 	/**
 	 * @brief Possible bias settings.
 	 */
bindings/cxx/line.cpp +8 -10
index 19c974d..04b15f7 100644
@@ -13,6 +13,12 @@ namespace gpiod {
 
 namespace {
 
+const ::std::map<int, int> drive_mapping = {
+	{ GPIOD_LINE_DRIVE_NONE,	line::DRIVE_NONE, },
+	{ GPIOD_LINE_DRIVE_OPEN_DRAIN,	line::DRIVE_OPEN_DRAIN, },
+	{ GPIOD_LINE_DRIVE_OPEN_SOURCE,	line::DRIVE_OPEN_SOURCE, },
+};
+
 const ::std::map<int, int> bias_mapping = {
 	{ GPIOD_LINE_BIAS_PULL_UP,	line::BIAS_PULL_UP, },
 	{ GPIOD_LINE_BIAS_PULL_DOWN,	line::BIAS_PULL_DOWN, },
@@ -98,20 +104,12 @@ bool line::is_used(void) const
 	return ::gpiod_line_is_used(this->_m_line);
 }
 
-bool line::is_open_drain(void) const
-{
-	this->throw_if_null();
-	line::chip_guard lock_chip(*this);
-
-	return ::gpiod_line_is_open_drain(this->_m_line);
-}
-
-bool line::is_open_source(void) const
+int line::drive(void) const
 {
 	this->throw_if_null();
 	line::chip_guard lock_chip(*this);
 
-	return ::gpiod_line_is_open_source(this->_m_line);
+	return drive_mapping.at(::gpiod_line_drive(this->_m_line));
 }
 
 void line::request(const line_request& config, int default_val) const
bindings/cxx/tests/tests-line.cpp +15 -30

117 lines not on this page · raw message

bindings/python/gpiodmodule.c +40 -33

106 lines not on this page · raw message

bindings/python/tests/gpiod_py_test.py +6 -12
index d9521de..4b05f01 100755
@@ -239,8 +239,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
-            self.assertTrue(line.is_open_drain())
-            self.assertFalse(line.is_open_source())
+            self.assertEqual(line.drive(), gpiod.Line.DRIVE_OPEN_DRAIN)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_NONE)
 
     def test_exported_open_drain_line(self):
@@ -257,8 +256,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
-            self.assertTrue(line.is_open_drain())
-            self.assertFalse(line.is_open_source())
+            self.assertEqual(line.drive(), gpiod.Line.DRIVE_OPEN_DRAIN)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_NONE)
 
     def test_exported_open_source_line(self):
@@ -275,8 +273,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
-            self.assertFalse(line.is_open_drain())
-            self.assertTrue(line.is_open_source())
+            self.assertEqual(line.drive(), gpiod.Line.DRIVE_OPEN_SOURCE)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_NONE)
 
     def test_exported_bias_disable_line(self):
@@ -293,8 +290,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
-            self.assertFalse(line.is_open_drain())
-            self.assertFalse(line.is_open_source())
+            self.assertEqual(line.drive(), gpiod.Line.DRIVE_NONE)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_DISABLE)
 
     def test_exported_bias_pull_down_line(self):
@@ -311,8 +307,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
-            self.assertFalse(line.is_open_drain())
-            self.assertFalse(line.is_open_source())
+            self.assertEqual(line.drive(), gpiod.Line.DRIVE_NONE)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_PULL_DOWN)
 
     def test_exported_bias_pull_up_line(self):
@@ -329,8 +324,7 @@ class LineInfo(MockupTestCase):
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
             self.assertTrue(line.is_requested())
-            self.assertFalse(line.is_open_drain())
-            self.assertFalse(line.is_open_source())
+            self.assertEqual(line.drive(), gpiod.Line.DRIVE_NONE)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_PULL_UP)
 
     def test_update_line_info(self):
include/gpiod.h +16 -10
index 18017d5..4e8e47f 100644
@@ -280,6 +280,18 @@ enum {
 	/**< Direction is output - we're driving the GPIO line. */
 };
 
+/**
+ * @brief Possible drive settings.
+ */
+enum {
+	GPIOD_LINE_DRIVE_NONE = 1,
+	/**< Drive setting is unknown. */
+	GPIOD_LINE_DRIVE_OPEN_DRAIN,
+	/**< Line output is open-drain. */
+	GPIOD_LINE_DRIVE_OPEN_SOURCE,
+	/**< Line output is open-source. */
+};
+
 /**
  * @brief Possible internal bias settings.
  */
@@ -353,18 +365,12 @@ int gpiod_line_bias(struct gpiod_line *line) GPIOD_API;
 bool gpiod_line_is_used(struct gpiod_line *line) GPIOD_API;
 
 /**
- * @brief Check if the line is an open-drain GPIO.
- * @param line GPIO line object.
- * @return True if the line is an open-drain GPIO, false otherwise.
- */
-bool gpiod_line_is_open_drain(struct gpiod_line *line) GPIOD_API;
-
-/**
- * @brief Check if the line is an open-source GPIO.
+ * @brief Read the GPIO line drive setting.
  * @param line GPIO line object.
- * @return True if the line is an open-source GPIO, false otherwise.
+ * @return Returns GPIOD_LINE_DRIVE_NONE, GPIOD_LINE_DRIVE_OPEN_DRAIN or
+ *         GPIOD_LINE_DRIVE_OPEN_SOURCE.
  */
-bool gpiod_line_is_open_source(struct gpiod_line *line) GPIOD_API;
+int gpiod_line_drive(struct gpiod_line *line) GPIOD_API;
 
 /**
  * @brief Re-read the line info.
lib/core.c +6 -6
index 60b39c6..9629a4f 100644
@@ -493,14 +493,14 @@ bool gpiod_line_is_used(struct gpiod_line *line)
 	return line->info_flags & GPIOLINE_FLAG_KERNEL;
 }
 
-bool gpiod_line_is_open_drain(struct gpiod_line *line)
+int gpiod_line_drive(struct gpiod_line *line)
 {
-	return line->info_flags & GPIOLINE_FLAG_OPEN_DRAIN;
-}
+	if (line->info_flags & GPIOLINE_FLAG_OPEN_DRAIN)
+		return GPIOD_LINE_DRIVE_OPEN_DRAIN;
+	if (line->info_flags & GPIOLINE_FLAG_OPEN_SOURCE)
+		return GPIOD_LINE_DRIVE_OPEN_SOURCE;
 
-bool gpiod_line_is_open_source(struct gpiod_line *line)
-{
-	return line->info_flags & GPIOLINE_FLAG_OPEN_SOURCE;
+	return GPIOD_LINE_DRIVE_NONE;
 }
 
 static int line_info_v2_to_info_flags(struct gpio_v2_line_info *info)
tests/tests-line.c +16 -20
index 07d5601..e6f0b69 100644
@@ -455,20 +455,19 @@ GPIOD_TEST_CASE(set_flags_drive, 0, { 8 })
 	ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 0);
 	g_assert_cmpint(ret, ==, 0);
 	gpiod_test_return_if_failed();
-	g_assert_cmpint(gpiod_line_is_open_drain(line), ==, false);
-	g_assert_cmpint(gpiod_line_is_open_source(line), ==, false);
+	g_assert_cmpint(gpiod_line_drive(line), ==, GPIOD_LINE_DRIVE_NONE);
 
 	ret = gpiod_line_set_flags(line,
 		GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN);
 	g_assert_cmpint(ret, ==, 0);
-	g_assert_cmpint(gpiod_line_is_open_drain(line), ==, true);
-	g_assert_cmpint(gpiod_line_is_open_source(line), ==, false);
+	g_assert_cmpint(gpiod_line_drive(line), ==,
+			GPIOD_LINE_DRIVE_OPEN_DRAIN);
 
 	ret = gpiod_line_set_flags(line,
 		GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE);
 	g_assert_cmpint(ret, ==, 0);
-	g_assert_cmpint(gpiod_line_is_open_drain(line), ==, false);
-	g_assert_cmpint(gpiod_line_is_open_source(line), ==, true);
+	g_assert_cmpint(gpiod_line_drive(line), ==,
+			GPIOD_LINE_DRIVE_OPEN_SOURCE);
 }
 
 GPIOD_TEST_CASE(set_direction, 0, { 8 })
@@ -760,8 +759,7 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 })
 	gpiod_test_return_if_failed();
 
 	g_assert_false(gpiod_line_is_used(line));
-	g_assert_false(gpiod_line_is_open_drain(line));
-	g_assert_false(gpiod_line_is_open_source(line));
+	g_assert_cmpint(gpiod_line_drive(line), ==, GPIOD_LINE_DRIVE_NONE);
 	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 
 	config.request_type = GPIOD_LINE_REQUEST_DIRECTION_OUTPUT;
@@ -773,8 +771,8 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 })
 	gpiod_test_return_if_failed();
 
 	g_assert_true(gpiod_line_is_used(line));
-	g_assert_true(gpiod_line_is_open_drain(line));
-	g_assert_false(gpiod_line_is_open_source(line));
+	g_assert_cmpint(gpiod_line_drive(line), ==,
+			GPIOD_LINE_DRIVE_OPEN_DRAIN);
 	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 	g_assert_cmpint(gpiod_line_direction(line), ==,
 			GPIOD_LINE_DIRECTION_OUTPUT);
@@ -788,8 +786,8 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 })
 	gpiod_test_return_if_failed();
 
 	g_assert_true(gpiod_line_is_used(line));
-	g_assert_false(gpiod_line_is_open_drain(line));
-	g_assert_true(gpiod_line_is_open_source(line));
+	g_assert_cmpint(gpiod_line_drive(line), ==,
+			GPIOD_LINE_DRIVE_OPEN_SOURCE);
 	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 	g_assert_cmpint(gpiod_line_direction(line), ==,
 			GPIOD_LINE_DIRECTION_OUTPUT);
@@ -827,8 +825,8 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
 	gpiod_test_return_if_failed();
 
 	g_assert_true(gpiod_line_is_used(line));
-	g_assert_true(gpiod_line_is_open_drain(line));
-	g_assert_false(gpiod_line_is_open_source(line));
+	g_assert_cmpint(gpiod_line_drive(line), ==,
+			GPIOD_LINE_DRIVE_OPEN_DRAIN);
 	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 	g_assert_true(gpiod_line_is_active_low(line));
 	g_assert_cmpint(gpiod_line_direction(line), ==,
@@ -844,8 +842,8 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
 	gpiod_test_return_if_failed();
 
 	g_assert_true(gpiod_line_is_used(line));
-	g_assert_false(gpiod_line_is_open_drain(line));
-	g_assert_true(gpiod_line_is_open_source(line));
+	g_assert_cmpint(gpiod_line_drive(line), ==,
+			GPIOD_LINE_DRIVE_OPEN_SOURCE);
 	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_NONE);
 	g_assert_true(gpiod_line_is_active_low(line));
 
@@ -865,8 +863,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
 	gpiod_test_return_if_failed();
 
 	g_assert_true(gpiod_line_is_used(line));
-	g_assert_false(gpiod_line_is_open_drain(line));
-	g_assert_false(gpiod_line_is_open_source(line));
+	g_assert_cmpint(gpiod_line_drive(line), ==, GPIOD_LINE_DRIVE_NONE);
 	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_PULL_DOWN);
 	g_assert_true(gpiod_line_is_active_low(line));
 	g_assert_cmpint(gpiod_line_direction(line), ==,
@@ -885,8 +882,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
 	gpiod_test_return_if_failed();
 
 	g_assert_true(gpiod_line_is_used(line));
-	g_assert_false(gpiod_line_is_open_drain(line));
-	g_assert_false(gpiod_line_is_open_source(line));
+	g_assert_cmpint(gpiod_line_drive(line), ==, GPIOD_LINE_DRIVE_NONE);
 	g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_PULL_UP);
 	g_assert_true(gpiod_line_is_active_low(line));
 	g_assert_cmpint(gpiod_line_direction(line), ==,
tools/gpioinfo.c +12 -2
index 8d228ab..7da9b03 100644
@@ -37,6 +37,16 @@ static bool line_bias_is_disabled(struct gpiod_line *line)
 	return gpiod_line_bias(line) == GPIOD_LINE_BIAS_DISABLE;
 }
 
+static bool line_drive_is_open_drain(struct gpiod_line *line)
+{
+	return gpiod_line_drive(line) == GPIOD_LINE_DRIVE_OPEN_DRAIN;
+}
+
+static bool line_drive_is_open_source(struct gpiod_line *line)
+{
+	return gpiod_line_drive(line) == GPIOD_LINE_DRIVE_OPEN_SOURCE;
+}
+
 static const struct flag flags[] = {
 	{
 		.name = "used",
@@ -44,11 +54,11 @@ static const struct flag flags[] = {
 	},
 	{
 		.name = "open-drain",
-		.is_set = gpiod_line_is_open_drain,
+		.is_set = line_drive_is_open_drain,
 	},
 	{
 		.name = "open-source",
-		.is_set = gpiod_line_is_open_source,
+		.is_set = line_drive_is_open_source,
 	},
 	{
 		.name = "pull-up",
Signature · 1 line
2.29.1
#6 lore raw

Re: [libgpiod][PATCH 4/6] treewide: make drive settings an enum

Quoted 43 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Open-source and open-drain drive settings are mutually exclusive just like the bias settings. Make them into an enum so that becomes clear.

---
 bindings/cxx/gpiod.hpp                 | 24 +++++----
 bindings/cxx/line.cpp                  | 18 +++----
 bindings/cxx/tests/tests-line.cpp      | 45 ++++++----------
 bindings/python/gpiodmodule.c          | 73 ++++++++++++++------------
 bindings/python/tests/gpiod_py_test.py | 18 +++----
 include/gpiod.h                        | 26 +++++----
 lib/core.c                             | 12 ++---
 tests/tests-line.c                     | 36 ++++++-------
 tools/gpioinfo.c                       | 14 ++++-
 9 files changed, 134 insertions(+), 132 deletions(-)
bindings/cxx/gpiod.hpp +3 -9
index fb675fc..f9c341d 100644
@@ -332,16 +332,10 @@ public:
 	GPIOD_API bool is_used(void) const;
 
 	/**
-	 * @brief Check if this line represents an open-drain GPIO.
-	 * @return True if the line is an open-drain GPIO, false otherwise.
+	 * @brief Get current drive setting of this line.
+	 * @return Current drive setting.
 	 */
-	GPIOD_API bool is_open_drain(void) const;
-
-	/**
-	 * @brief Check if this line represents an open-source GPIO.
-	 * @return True if the line is an open-source GPIO, false otherwise.
-	 */
-	GPIOD_API bool is_open_source(void) const;
+	GPIOD_API int drive(void) const;
 
 	/**
 	 * @brief Request this line.

bindings/cxx/gpiod.hpp public: · line 484

Quoted 9 lines
bindings/cxx/gpiod.hpp +6 -0
@@ -482,6 +476,18 @@ public:
 		/**< Line's direction setting is output. */
 	};
 
+	/**
+	 * @brief Possible drive settings.
+	 */
+	enum : int {
+		DRIVE_NONE = 1,
+		/**< Drive setting is unknown. */

Unlike bias, the drive setting is never unknown - if zero the pin is assumed push-pull.

And to me DRIVE_NONE implies a high impedance state.

Cheers,
Kent.

#7 lore raw

Re: [libgpiod][PATCH 4/6] treewide: make drive settings an enum

Quoted 58 lines · Kent Gibson
Quoted 43 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Open-source and open-drain drive settings are mutually exclusive just like the bias settings. Make them into an enum so that becomes clear.

---
 bindings/cxx/gpiod.hpp                 | 24 +++++----
 bindings/cxx/line.cpp                  | 18 +++----
 bindings/cxx/tests/tests-line.cpp      | 45 ++++++----------
 bindings/python/gpiodmodule.c          | 73 ++++++++++++++------------
 bindings/python/tests/gpiod_py_test.py | 18 +++----
 include/gpiod.h                        | 26 +++++----
 lib/core.c                             | 12 ++---
 tests/tests-line.c                     | 36 ++++++-------
 tools/gpioinfo.c                       | 14 ++++-
 9 files changed, 134 insertions(+), 132 deletions(-)
bindings/cxx/gpiod.hpp +3 -9
index fb675fc..f9c341d 100644
@@ -332,16 +332,10 @@ public:
      GPIOD_API bool is_used(void) const;
 
      /**
-      * @brief Check if this line represents an open-drain GPIO.
-      * @return True if the line is an open-drain GPIO, false otherwise.
+      * @brief Get current drive setting of this line.
+      * @return Current drive setting.
       */
-     GPIOD_API bool is_open_drain(void) const;
-
-     /**
-      * @brief Check if this line represents an open-source GPIO.
-      * @return True if the line is an open-source GPIO, false otherwise.
-      */
-     GPIOD_API bool is_open_source(void) const;
+     GPIOD_API int drive(void) const;
 
      /**
       * @brief Request this line.

bindings/cxx/gpiod.hpp public: · line 484

Quoted 9 lines
bindings/cxx/gpiod.hpp +6 -0
@@ -482,6 +476,18 @@ public:
              /**< Line's direction setting is output. */
      };
 
+     /**
+      * @brief Possible drive settings.
+      */
+     enum : int {
+             DRIVE_NONE = 1,
+             /**< Drive setting is unknown. */

Unlike bias, the drive setting is never unknown - if zero the pin is assumed push-pull.

Quoted 2 lines

And to me DRIVE_NONE implies a high impedance state.

Indeed, I'll change it to DRIVE_PUSH_PULL then.

Bart

#8 lore raw

PATCH 5/6 bindings: cxx: line: reorder bias mapping entries

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Reorder the definitions so that they match the order in which they're declared in the class. This is cosmetic only.

---
 bindings/cxx/line.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bindings/cxx/line.cpp +2 -2
index 04b15f7..cb9b6dc 100644
@@ -20,10 +20,10 @@ const ::std::map<int, int> drive_mapping = {
 };
 
 const ::std::map<int, int> bias_mapping = {
+	{ GPIOD_LINE_BIAS_NONE,		line::BIAS_NONE, },
+	{ GPIOD_LINE_BIAS_DISABLE,	line::BIAS_DISABLE, },
 	{ GPIOD_LINE_BIAS_PULL_UP,	line::BIAS_PULL_UP, },
 	{ GPIOD_LINE_BIAS_PULL_DOWN,	line::BIAS_PULL_DOWN, },
-	{ GPIOD_LINE_BIAS_DISABLE,	line::BIAS_DISABLE, },
-	{ GPIOD_LINE_BIAS_NONE,		line::BIAS_NONE, },
 };
 
 } /* namespace */
Signature · 1 line
2.29.1
#9 lore raw

PATCH 6/6 core: add the kernel uapi header to the repository

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

In order to avoid any problems with symbols missing from the host linux kernel headers (for example: if current version of libgpiod supports features that were added recently to the kernel but the host headers are outdated and don't export required symbols) let's add the uapi header to the repository and include it instead of the one in /usr/include/linux.

---
 configure.ac    |  12 +-
 lib/Makefile.am |   2 +-
 lib/core.c      |   3 +-
 lib/uapi/gpio.h | 522 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 528 insertions(+), 11 deletions(-)
 create mode 100644 lib/uapi/gpio.h
configure.ac +3 -9
index ddb9dc2..f6db096 100644
@@ -93,16 +93,10 @@ AC_CHECK_HEADERS([getopt.h], [], [HEADER_NOT_FOUND_LIB([getopt.h])])
 AC_CHECK_HEADERS([dirent.h], [], [HEADER_NOT_FOUND_LIB([dirent.h])])
 AC_CHECK_HEADERS([sys/poll.h], [], [HEADER_NOT_FOUND_LIB([sys/poll.h])])
 AC_CHECK_HEADERS([sys/sysmacros.h], [], [HEADER_NOT_FOUND_LIB([sys/sysmacros.h])])
-AC_CHECK_HEADERS([linux/gpio.h], [], [HEADER_NOT_FOUND_LIB([linux/gpio.h])])
 AC_CHECK_HEADERS([linux/version.h], [], [HEADER_NOT_FOUND_LIB([linux/version.h])])
-
-AC_COMPILE_IFELSE([AC_LANG_SOURCE(
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
-#error
-#endif
-)],
-[], [AC_MSG_ERROR(["libgpiod needs linux headers version >= v5.10.0"])])
+AC_CHECK_HEADERS([linux/const.h], [], [HEADER_NOT_FOUND_LIB([linux/const.h])])
+AC_CHECK_HEADERS([linux/ioctl.h], [], [HEADER_NOT_FOUND_LIB([linux/ioctl.h])])
+AC_CHECK_HEADERS([linux/types.h], [], [HEADER_NOT_FOUND_LIB([linux/types.h])])
 
 AC_ARG_ENABLE([tools],
 	[AS_HELP_STRING([--enable-tools],[enable libgpiod command-line tools [default=no]])],
lib/Makefile.am +1 -1
index 43ebf76..fb0dae9 100644
@@ -7,7 +7,7 @@
 #
 
 lib_LTLIBRARIES = libgpiod.la
-libgpiod_la_SOURCES = core.c helpers.c misc.c
+libgpiod_la_SOURCES = core.c helpers.c misc.c uapi/gpio.h
 libgpiod_la_CFLAGS = -Wall -Wextra -g -std=gnu89
 libgpiod_la_CFLAGS += -fvisibility=hidden -I$(top_srcdir)/include/
 libgpiod_la_CFLAGS += -include $(top_builddir)/config.h
lib/core.c +2 -1
index 9629a4f..5e19c67 100644
@@ -11,7 +11,6 @@
 #include <fcntl.h>
 #include <gpiod.h>
 #include <limits.h>
-#include <linux/gpio.h>
 #include <poll.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -22,6 +21,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "uapi/gpio.h"
+
 #define LINE_REQUEST_MAX_LINES	64
 
 enum {
lib/uapi/gpio.h new file +522 -0

522 lines not on this page · raw message

Signature · 1 line
2.29.1
#10 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 8 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

In order to avoid any problems with symbols missing from the host linux kernel headers (for example: if current version of libgpiod supports features that were added recently to the kernel but the host headers are outdated and don't export required symbols) let's add the uapi header to the repository and include it instead of the one in /usr/include/linux.

I doubt this is a good decision. First of all if the host (or rather target, because host should not influence build of libgpiod) has outdated header it may be for a reason (it runs old kernel). When you run new library on outdated kernel it might produce various of interesting errors (in general, I haven't investigated libgpiod case).
On top of that you make a copy'n'paste source code which is against the Unix way.

Sorry, but I'm in favour of dropping this one.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 8 lines
Quoted 5 lines

In order to avoid any problems with symbols missing from the host linux kernel headers (for example: if current version of libgpiod supports features that were added recently to the kernel but the host headers are outdated and don't export required symbols) let's add the uapi header to the repository and include it instead of the one in /usr/include/linux.

I doubt this is a good decision. First of all if the host (or rather target, because host should not influence build of libgpiod) has

I meant the host as in: the machine on which you build and which contains the headers for the target as well but I see what you mean.

Quoted 9 lines

outdated header it may be for a reason (it runs old kernel). When you run new library on outdated kernel it might produce various of interesting errors (in general, I haven't investigated libgpiod case).
On top of that you make a copy'n'paste source code which is against the Unix way.

Sorry, but I'm in favour of dropping this one.

Cc Thomas

This problem has been raised by the buildroot people when we started requiring different versions of kernel headers to build v1.4 and v1.6. It turns out most projects simply package the uapi headers together with their sources (e.g. wpa_supplicant, libnl, iproute2) to avoid complicated dependencies. It's true that now the library can fail at runtime but I'm fine with that. Also: if we add new features between two kernel versions, we still allow to build the new library version except that these new features won't work on older kernels.

Bartosz

#12 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 31 lines · Bartosz Golaszewski
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 8 lines
Quoted 5 lines

In order to avoid any problems with symbols missing from the host linux kernel headers (for example: if current version of libgpiod supports features that were added recently to the kernel but the host headers are outdated and don't export required symbols) let's add the uapi header to the repository and include it instead of the one in /usr/include/linux.

I doubt this is a good decision. First of all if the host (or rather target, because host should not influence build of libgpiod) has

I meant the host as in: the machine on which you build and which contains the headers for the target as well but I see what you mean.

Quoted 9 lines

outdated header it may be for a reason (it runs old kernel). When you run new library on outdated kernel it might produce various of interesting errors (in general, I haven't investigated libgpiod case).
On top of that you make a copy'n'paste source code which is against the Unix way.

Sorry, but I'm in favour of dropping this one.

Cc Thomas
Quoted 8 lines

This problem has been raised by the buildroot people when we started requiring different versions of kernel headers to build v1.4 and v1.6. It turns out most projects simply package the uapi headers together with their sources (e.g. wpa_supplicant, libnl, iproute2) to avoid complicated dependencies. It's true that now the library can fail at runtime but I'm fine with that. Also: if we add new features between two kernel versions, we still allow to build the new library version except that these new features won't work on older kernels.

I see.

So known ways to solve this are
- provide a header with source tree (see above)
- modify code with ifdeffery against specific kernel versions
- ...something else... ?

Second item is what ALSA used (not sure if they provide a standalone driver anymore). Ugly, but won't require header which may be staled.

Any other solutions in mind?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 49 lines · Andy Shevchenko
Quoted 31 lines · Bartosz Golaszewski
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 8 lines
Quoted 5 lines

In order to avoid any problems with symbols missing from the host linux kernel headers (for example: if current version of libgpiod supports features that were added recently to the kernel but the host headers are outdated and don't export required symbols) let's add the uapi header to the repository and include it instead of the one in /usr/include/linux.

I doubt this is a good decision. First of all if the host (or rather target, because host should not influence build of libgpiod) has

I meant the host as in: the machine on which you build and which contains the headers for the target as well but I see what you mean.

Quoted 9 lines

outdated header it may be for a reason (it runs old kernel). When you run new library on outdated kernel it might produce various of interesting errors (in general, I haven't investigated libgpiod case).
On top of that you make a copy'n'paste source code which is against the Unix way.

Sorry, but I'm in favour of dropping this one.

Cc Thomas
Quoted 8 lines

This problem has been raised by the buildroot people when we started requiring different versions of kernel headers to build v1.4 and v1.6. It turns out most projects simply package the uapi headers together with their sources (e.g. wpa_supplicant, libnl, iproute2) to avoid complicated dependencies. It's true that now the library can fail at runtime but I'm fine with that. Also: if we add new features between two kernel versions, we still allow to build the new library version except that these new features won't work on older kernels.

I see.

So known ways to solve this are
- provide a header with source tree (see above)
- modify code with ifdeffery against specific kernel versions
- ...something else... ?

Quoted 5 lines

Second item is what ALSA used (not sure if they provide a standalone driver anymore). Ugly, but won't require header which may be staled.

Any other solutions in mind?

I tried to go the third way and just ignore the problem but I've received too many emails about that. :)

I don't like the ifdef hell so I prefer to bundle the header. I'm open to other suggestions, although I can't come up with anything else.

Bart

#14 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 54 lines · Bartosz Golaszewski
Quoted 52 lines · Andy Shevchenko
Quoted 31 lines · Bartosz Golaszewski
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 8 lines
Quoted 5 lines

In order to avoid any problems with symbols missing from the host linux kernel headers (for example: if current version of libgpiod supports features that were added recently to the kernel but the host headers are outdated and don't export required symbols) let's add the uapi header to the repository and include it instead of the one in /usr/include/linux.

I doubt this is a good decision. First of all if the host (or rather target, because host should not influence build of libgpiod) has

I meant the host as in: the machine on which you build and which contains the headers for the target as well but I see what you mean.

Quoted 9 lines

outdated header it may be for a reason (it runs old kernel). When you run new library on outdated kernel it might produce various of interesting errors (in general, I haven't investigated libgpiod case).
On top of that you make a copy'n'paste source code which is against the Unix way.

Sorry, but I'm in favour of dropping this one.

Cc Thomas
Quoted 8 lines

This problem has been raised by the buildroot people when we started requiring different versions of kernel headers to build v1.4 and v1.6. It turns out most projects simply package the uapi headers together with their sources (e.g. wpa_supplicant, libnl, iproute2) to avoid complicated dependencies. It's true that now the library can fail at runtime but I'm fine with that. Also: if we add new features between two kernel versions, we still allow to build the new library version except that these new features won't work on older kernels.

I see.

So known ways to solve this are
- provide a header with source tree (see above)
- modify code with ifdeffery against specific kernel versions
- ...something else... ?

Second item is what ALSA used (not sure if they provide a standalone driver anymore). Ugly, but won't require header which may be staled.

Quoted 9 lines
Quoted 2 lines

Any other solutions in mind?

I tried to go the third way and just ignore the problem but I've received too many emails about that. :)

I don't like the ifdef hell so I prefer to bundle the header. I'm open to other suggestions, although I can't come up with anything else.

Going off on a bit of a tangent, but I'm trying to add support for decoding the GPIO ioctls into strace and am running up against a similar issue.

The way strace does it is to check the uAPI header on the host and use it if possible. To handle where it may be stale, local types are defined that mirror any types that may have been added since the header was originally released. If the corresponding type is available in the linux header then it is used, else the local type.

This obviously creates a lot of pointless boilerplate code and preprocessor chicanery so I floated the idea of just including the latest header in the strace tree, as you are doing here for libgpiod. But that raised the issue of licencing, specifically if you copy the linux/gpio.h into a source tree does that mean that the whole project becomes GPL 2.0? That is an issue for strace as it is LGPL 2.1 - as is libgpiod.

The Linux uAPI headers are under the GPL-2.0 WITH Linux-syscall-note, which is also not totally clear on this point[1].

My gut feeling was that using and even copying API headers doesn't constitute a derived work, as per the FSF view quoted in [1], and ethically might even be less of a violation than copying and re-defining individual types, but I'd rather not rely on a gut feeling.

Is there some clear opinion or precedent on this point? i.e. are libgpiod and strace in legal licence jeopardy if they include gpio.h in their source tree?

Cheers,
Kent.

[1] https://lkml.org/lkml/2020/2/21/2193

#15 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 73 lines · Kent Gibson
Quoted 52 lines · Bartosz Golaszewski
Quoted 50 lines · Andy Shevchenko
Quoted 30 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 8 lines
Quoted 5 lines

In order to avoid any problems with symbols missing from the host linux kernel headers (for example: if current version of libgpiod supports features that were added recently to the kernel but the host headers are outdated and don't export required symbols) let's add the uapi header to the repository and include it instead of the one in /usr/include/linux.

I doubt this is a good decision. First of all if the host (or rather target, because host should not influence build of libgpiod) has

I meant the host as in: the machine on which you build and which contains the headers for the target as well but I see what you mean.

Quoted 9 lines

outdated header it may be for a reason (it runs old kernel). When you run new library on outdated kernel it might produce various of interesting errors (in general, I haven't investigated libgpiod case).
On top of that you make a copy'n'paste source code which is against the Unix way.

Sorry, but I'm in favour of dropping this one.

Cc Thomas
Quoted 8 lines

This problem has been raised by the buildroot people when we started requiring different versions of kernel headers to build v1.4 and v1.6. It turns out most projects simply package the uapi headers together with their sources (e.g. wpa_supplicant, libnl, iproute2) to avoid complicated dependencies. It's true that now the library can fail at runtime but I'm fine with that. Also: if we add new features between two kernel versions, we still allow to build the new library version except that these new features won't work on older kernels.

I see.

So known ways to solve this are
- provide a header with source tree (see above)
- modify code with ifdeffery against specific kernel versions
- ...something else... ?

Second item is what ALSA used (not sure if they provide a standalone driver anymore). Ugly, but won't require header which may be staled.

Quoted 9 lines
Quoted 2 lines

Any other solutions in mind?

I tried to go the third way and just ignore the problem but I've received too many emails about that. :)

I don't like the ifdef hell so I prefer to bundle the header. I'm open to other suggestions, although I can't come up with anything else.

Going off on a bit of a tangent, but I'm trying to add support for decoding the GPIO ioctls into strace and am running up against a similar issue.

The way strace does it is to check the uAPI header on the host and use it if possible. To handle where it may be stale, local types are defined that mirror any types that may have been added since the header was originally released. If the corresponding type is available in the linux header then it is used, else the local type.

Quoted 7 lines

This obviously creates a lot of pointless boilerplate code and preprocessor chicanery so I floated the idea of just including the latest header in the strace tree, as you are doing here for libgpiod. But that raised the issue of licencing, specifically if you copy the linux/gpio.h into a source tree does that mean that the whole project becomes GPL 2.0? That is an issue for strace as it is LGPL 2.1 - as is libgpiod.

Very good point!

Quoted 7 lines

The Linux uAPI headers are under the GPL-2.0 WITH Linux-syscall-note, which is also not totally clear on this point[1].

My gut feeling was that using and even copying API headers doesn't constitute a derived work, as per the FSF view quoted in [1], and ethically might even be less of a violation than copying and re-defining individual types, but I'd rather not rely on a gut feeling.

This reminds me of the Google vs. Oracle case where they pointed out the header files (IIRC!).

Quoted 5 lines

Is there some clear opinion or precedent on this point? i.e. are libgpiod and strace in legal licence jeopardy if they include gpio.h in their source tree?

[1] https://lkml.org/lkml/2020/2/21/2193

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

In reply to Kent Gibson
Quoted 1 line · Kent Gibson

[snip!]

Quoted 31 lines
Quoted 4 lines

I don't like the ifdef hell so I prefer to bundle the header. I'm open to other suggestions, although I can't come up with anything else.

Going off on a bit of a tangent, but I'm trying to add support for decoding the GPIO ioctls into strace and am running up against a similar issue.

The way strace does it is to check the uAPI header on the host and use it if possible. To handle where it may be stale, local types are defined that mirror any types that may have been added since the header was originally released. If the corresponding type is available in the linux header then it is used, else the local type.

This obviously creates a lot of pointless boilerplate code and preprocessor chicanery so I floated the idea of just including the latest header in the strace tree, as you are doing here for libgpiod. But that raised the issue of licencing, specifically if you copy the linux/gpio.h into a source tree does that mean that the whole project becomes GPL 2.0? That is an issue for strace as it is LGPL 2.1 - as is libgpiod.

The Linux uAPI headers are under the GPL-2.0 WITH Linux-syscall-note, which is also not totally clear on this point[1].

My gut feeling was that using and even copying API headers doesn't constitute a derived work, as per the FSF view quoted in [1], and ethically might even be less of a violation than copying and re-defining individual types, but I'd rather not rely on a gut feeling.

Quoted 8 lines

Is there some clear opinion or precedent on this point? i.e. are libgpiod and strace in legal licence jeopardy if they include gpio.h in their source tree?

Cheers,
Kent.

[1] https://lkml.org/lkml/2020/2/21/2193

Thanks for pointing that out. I lack the legal knowledge to have an opinion of my own on this.

Cc'ing Greg KH for help.

Greg: do you know if it's fine to bundle a 'GPL-2.0 WITH Linux-syscall-note' uAPI header together with an LGPL-v2.1-or-later user-space shared library?

Best Regards,
Bartosz Golaszewski

#17 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 45 lines · Bartosz Golaszewski
Quoted 1 line · Kent Gibson

[snip!]

Quoted 31 lines
Quoted 4 lines

I don't like the ifdef hell so I prefer to bundle the header. I'm open to other suggestions, although I can't come up with anything else.

Going off on a bit of a tangent, but I'm trying to add support for decoding the GPIO ioctls into strace and am running up against a similar issue.

The way strace does it is to check the uAPI header on the host and use it if possible. To handle where it may be stale, local types are defined that mirror any types that may have been added since the header was originally released. If the corresponding type is available in the linux header then it is used, else the local type.

This obviously creates a lot of pointless boilerplate code and preprocessor chicanery so I floated the idea of just including the latest header in the strace tree, as you are doing here for libgpiod. But that raised the issue of licencing, specifically if you copy the linux/gpio.h into a source tree does that mean that the whole project becomes GPL 2.0? That is an issue for strace as it is LGPL 2.1 - as is libgpiod.

The Linux uAPI headers are under the GPL-2.0 WITH Linux-syscall-note, which is also not totally clear on this point[1].

My gut feeling was that using and even copying API headers doesn't constitute a derived work, as per the FSF view quoted in [1], and ethically might even be less of a violation than copying and re-defining individual types, but I'd rather not rely on a gut feeling.

Quoted 8 lines

Is there some clear opinion or precedent on this point? i.e. are libgpiod and strace in legal licence jeopardy if they include gpio.h in their source tree?

Cheers,
Kent.

[1] https://lkml.org/lkml/2020/2/21/2193

Quoted 8 lines

Thanks for pointing that out. I lack the legal knowledge to have an opinion of my own on this.

Cc'ing Greg KH for help.

Greg: do you know if it's fine to bundle a 'GPL-2.0 WITH Linux-syscall-note' uAPI header together with an LGPL-v2.1-or-later user-space shared library?

How would you "bundle" such a thing as that is not what is in the kernel source tree? If you are going to copy files out of the kernel and do other things with them, well, I recommend asking a lawyer as I am not one :)

good luck!

greg k-h

#18 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 56 lines · Greg Kroah-Hartman
Quoted 45 lines · Bartosz Golaszewski
Quoted 1 line · Kent Gibson

[snip!]

Quoted 31 lines
Quoted 4 lines

I don't like the ifdef hell so I prefer to bundle the header. I'm open to other suggestions, although I can't come up with anything else.

Going off on a bit of a tangent, but I'm trying to add support for decoding the GPIO ioctls into strace and am running up against a similar issue.

The way strace does it is to check the uAPI header on the host and use it if possible. To handle where it may be stale, local types are defined that mirror any types that may have been added since the header was originally released. If the corresponding type is available in the linux header then it is used, else the local type.

This obviously creates a lot of pointless boilerplate code and preprocessor chicanery so I floated the idea of just including the latest header in the strace tree, as you are doing here for libgpiod. But that raised the issue of licencing, specifically if you copy the linux/gpio.h into a source tree does that mean that the whole project becomes GPL 2.0? That is an issue for strace as it is LGPL 2.1 - as is libgpiod.

The Linux uAPI headers are under the GPL-2.0 WITH Linux-syscall-note, which is also not totally clear on this point[1].

My gut feeling was that using and even copying API headers doesn't constitute a derived work, as per the FSF view quoted in [1], and ethically might even be less of a violation than copying and re-defining individual types, but I'd rather not rely on a gut feeling.

Quoted 8 lines

Is there some clear opinion or precedent on this point? i.e. are libgpiod and strace in legal licence jeopardy if they include gpio.h in their source tree?

Cheers,
Kent.

[1] https://lkml.org/lkml/2020/2/21/2193

Quoted 8 lines

Thanks for pointing that out. I lack the legal knowledge to have an opinion of my own on this.

Cc'ing Greg KH for help.

Greg: do you know if it's fine to bundle a 'GPL-2.0 WITH Linux-syscall-note' uAPI header together with an LGPL-v2.1-or-later user-space shared library?

Quoted 8 lines

How would you "bundle" such a thing as that is not what is in the kernel source tree? If you are going to copy files out of the kernel and do other things with them, well, I recommend asking a lawyer as I am not one :)

good luck!

greg k-h

By "bundling" I mean - copying the kernel uAPI header verbatim from the kernel tree into the project repository. The reason for that is the fact that always relying on the toolchain kernel headers leads to build issues if we want to support more recent kernel features in the library while the supplied headers don't define all required symbols.

We can either make the latest supported version of linux headers a hard requirement for building (I did that and buildroot folks yelled at me because two stable versions of the library had different kernel headers requirements) or redefine certain symbols (new symbols since the oldest supported kernel version) or - and this is preferred unless it's against the linux license - include the kernel headers in the source tarball of the library.

I hope this is not a stupid question but obviously I don't know any lawyer well versed in software copyright: can we direct this question to anyone at the Linux Foundation maybe?

Bartosz

#19 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 81 lines · Bartosz Golaszewski
Quoted 56 lines · Greg Kroah-Hartman
Quoted 45 lines · Bartosz Golaszewski
Quoted 1 line · Kent Gibson

[snip!]

Quoted 31 lines
Quoted 4 lines

I don't like the ifdef hell so I prefer to bundle the header. I'm open to other suggestions, although I can't come up with anything else.

Going off on a bit of a tangent, but I'm trying to add support for decoding the GPIO ioctls into strace and am running up against a similar issue.

The way strace does it is to check the uAPI header on the host and use it if possible. To handle where it may be stale, local types are defined that mirror any types that may have been added since the header was originally released. If the corresponding type is available in the linux header then it is used, else the local type.

This obviously creates a lot of pointless boilerplate code and preprocessor chicanery so I floated the idea of just including the latest header in the strace tree, as you are doing here for libgpiod. But that raised the issue of licencing, specifically if you copy the linux/gpio.h into a source tree does that mean that the whole project becomes GPL 2.0? That is an issue for strace as it is LGPL 2.1 - as is libgpiod.

The Linux uAPI headers are under the GPL-2.0 WITH Linux-syscall-note, which is also not totally clear on this point[1].

My gut feeling was that using and even copying API headers doesn't constitute a derived work, as per the FSF view quoted in [1], and ethically might even be less of a violation than copying and re-defining individual types, but I'd rather not rely on a gut feeling.

Quoted 8 lines

Is there some clear opinion or precedent on this point? i.e. are libgpiod and strace in legal licence jeopardy if they include gpio.h in their source tree?

Cheers,
Kent.

[1] https://lkml.org/lkml/2020/2/21/2193

Quoted 8 lines

Thanks for pointing that out. I lack the legal knowledge to have an opinion of my own on this.

Cc'ing Greg KH for help.

Greg: do you know if it's fine to bundle a 'GPL-2.0 WITH Linux-syscall-note' uAPI header together with an LGPL-v2.1-or-later user-space shared library?

Quoted 8 lines

How would you "bundle" such a thing as that is not what is in the kernel source tree? If you are going to copy files out of the kernel and do other things with them, well, I recommend asking a lawyer as I am not one :)

good luck!

greg k-h

By "bundling" I mean - copying the kernel uAPI header verbatim from the kernel tree into the project repository. The reason for that is the fact that always relying on the toolchain kernel headers leads to build issues if we want to support more recent kernel features in the library while the supplied headers don't define all required symbols.

We can either make the latest supported version of linux headers a hard requirement for building (I did that and buildroot folks yelled at me because two stable versions of the library had different kernel headers requirements) or redefine certain symbols (new symbols since the oldest supported kernel version) or - and this is preferred unless it's against the linux license - include the kernel headers in the source tarball of the library.

Quoted 3 lines

I hope this is not a stupid question but obviously I don't know any lawyer well versed in software copyright: can we direct this question to anyone at the Linux Foundation maybe?

Ok, first off, I am not a lawyer so don't take legal advice from me.

But, if you copy the .h file directly, and keep the same license on the file, that should be fine as you would be using it under the "GPLv2 with syscall note" license for your userspace program, right?

So there shouldn't be an issue there that I can determine, as we want userspace programs to be free to use those headers to interact with the kernel.

It's come up in the past that we might want to somehow make this much more obvious, and we have talked about this with the legal community, but that's only in the context of making it more obvious that we want people to write programs of any license to talk to the kernel, not that we would want to keep anyone from doing that :)

thanks,

greg k-h

#20 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 102 lines · Greg Kroah-Hartman
Quoted 81 lines · Bartosz Golaszewski
Quoted 56 lines · Greg Kroah-Hartman
Quoted 45 lines · Bartosz Golaszewski
Quoted 1 line · Kent Gibson

[snip!]

Quoted 31 lines
Quoted 4 lines

I don't like the ifdef hell so I prefer to bundle the header. I'm open to other suggestions, although I can't come up with anything else.

Going off on a bit of a tangent, but I'm trying to add support for decoding the GPIO ioctls into strace and am running up against a similar issue.

The way strace does it is to check the uAPI header on the host and use it if possible. To handle where it may be stale, local types are defined that mirror any types that may have been added since the header was originally released. If the corresponding type is available in the linux header then it is used, else the local type.

This obviously creates a lot of pointless boilerplate code and preprocessor chicanery so I floated the idea of just including the latest header in the strace tree, as you are doing here for libgpiod. But that raised the issue of licencing, specifically if you copy the linux/gpio.h into a source tree does that mean that the whole project becomes GPL 2.0? That is an issue for strace as it is LGPL 2.1 - as is libgpiod.

The Linux uAPI headers are under the GPL-2.0 WITH Linux-syscall-note, which is also not totally clear on this point[1].

My gut feeling was that using and even copying API headers doesn't constitute a derived work, as per the FSF view quoted in [1], and ethically might even be less of a violation than copying and re-defining individual types, but I'd rather not rely on a gut feeling.

Quoted 8 lines

Is there some clear opinion or precedent on this point? i.e. are libgpiod and strace in legal licence jeopardy if they include gpio.h in their source tree?

Cheers,
Kent.

[1] https://lkml.org/lkml/2020/2/21/2193

Quoted 8 lines

Thanks for pointing that out. I lack the legal knowledge to have an opinion of my own on this.

Cc'ing Greg KH for help.

Greg: do you know if it's fine to bundle a 'GPL-2.0 WITH Linux-syscall-note' uAPI header together with an LGPL-v2.1-or-later user-space shared library?

Quoted 8 lines

How would you "bundle" such a thing as that is not what is in the kernel source tree? If you are going to copy files out of the kernel and do other things with them, well, I recommend asking a lawyer as I am not one :)

good luck!

greg k-h

By "bundling" I mean - copying the kernel uAPI header verbatim from the kernel tree into the project repository. The reason for that is the fact that always relying on the toolchain kernel headers leads to build issues if we want to support more recent kernel features in the library while the supplied headers don't define all required symbols.

We can either make the latest supported version of linux headers a hard requirement for building (I did that and buildroot folks yelled at me because two stable versions of the library had different kernel headers requirements) or redefine certain symbols (new symbols since the oldest supported kernel version) or - and this is preferred unless it's against the linux license - include the kernel headers in the source tarball of the library.

Quoted 3 lines

I hope this is not a stupid question but obviously I don't know any lawyer well versed in software copyright: can we direct this question to anyone at the Linux Foundation maybe?

Ok, first off, I am not a lawyer so don't take legal advice from me.

But, if you copy the .h file directly, and keep the same license on the file, that should be fine as you would be using it under the "GPLv2 with syscall note" license for your userspace program, right?

So there shouldn't be an issue there that I can determine, as we want userspace programs to be free to use those headers to interact with the kernel.

It's come up in the past that we might want to somehow make this much more obvious, and we have talked about this with the legal community, but that's only in the context of making it more obvious that we want people to write programs of any license to talk to the kernel, not that we would want to keep anyone from doing that :)

Quoted 3 lines

thanks,

greg k-h

Including Dmitry as he orignally raised the issue and has an interest in its resolution.

Greg: thanks for providing your view. You may not be a lawyer (which is a very good thing, btw), but your opinion carries a lot of weight, and combined with what we already knew I think we're on very solid ground distributing the kernel headers in the libgpiod and strace repositories.

Bart and Dmitry: I submit that we are good to copy the headers into the repositories, but we should take a few steps just to make clear that we are in full compliance with the GPL v2.

Firstly, we are distributing the headers under Section 1 (distribution) of the GPL, so we should keep the headers in a separate directory that contains its own COPYING file as well as the GPL v2 and Linux syscall note
- unless they are already available elsewhere in the repo.

The headers must be copied verbatim so as to not trigger Section 2 (modification). And it is probably good to include in the commit comment what kernel version or commit they were drawn from so that can be easily confirmed.

Section 3 still doesn't apply, as any resulting object code or executables are no more a derived work due to the availability of the header than they were previously. And I don't think anyone is claiming that the repo itself is a derived work - in this context it is just a distribution medium.

The COPYING file, or equivalent, for the project should explicitly exclude any claim on the kernel header directory to make clear we are not trying to sublicense the headers as LGPL - which could breach Section 4.

Other than those points, I don't see anywhere we may be in breach.

As with Greg, IANAL so this is not legal advice. Feel free to disregard any or all of the above if you still consider the legal standing uncertain or too risky.

Cheers,
Kent.

#21 lore raw

Re: [libgpiod][PATCH 6/6] core: add the kernel uapi header to the repository

Quoted 20 lines · Kent Gibson

Bart and Dmitry: I submit that we are good to copy the headers into the repositories, but we should take a few steps just to make clear that we are in full compliance with the GPL v2.

Firstly, we are distributing the headers under Section 1 (distribution) of the GPL, so we should keep the headers in a separate directory that contains its own COPYING file as well as the GPL v2 and Linux syscall note
- unless they are already available elsewhere in the repo.

The headers must be copied verbatim so as to not trigger Section 2 (modification). And it is probably good to include in the commit comment what kernel version or commit they were drawn from so that can be easily confirmed.

Section 3 still doesn't apply, as any resulting object code or executables are no more a derived work due to the availability of the header than they were previously. And I don't think anyone is claiming that the repo itself is a derived work - in this context it is just a distribution medium.

Quoted 6 lines

The COPYING file, or equivalent, for the project should explicitly exclude any claim on the kernel header directory to make clear we are not trying to sublicense the headers as LGPL - which could breach Section 4.

Other than those points, I don't see anywhere we may be in breach.

That looks good, you should also consider following the REUSE specification:
https://reuse.software/
which recommends using a LICENSES/ directory for the different licenses in your project and use SPDX lines at the top of your files to make everything explicit. The reuse lint command line tool should give you lots of hints on good things to fix up in this area.

Good luck!

greg k-h