Thread (34 messages) 34 messages, 7 authors, 2025-11-18

Re: [PATCH v2 04/10] gpio: shared-proxy: implement the shared GPIO proxy driver

From: Andy Shevchenko <hidden>
Date: 2025-10-22 18:04:30
Also in: linux-arm-msm, linux-gpio, linux-hardening, linux-sound, lkml

On Wed, Oct 22, 2025 at 03:10:43PM +0200, Bartosz Golaszewski wrote:
Add a virtual GPIO proxy driver which arbitrates access to a single
shared GPIO by multiple users. It works together with the core shared
GPIO support from GPIOLIB and functions by acquiring a reference to a
shared GPIO descriptor exposed by gpiolib-shared and making sure that
the state of the GPIO stays consistent.

In general: if there's only one user at the moment: allow it to do
anything as if this was a normal GPIO (in essence: just propagate calls
to the underlying real hardware driver). If there are more users: don't
allow to change the direction set by the initial user, allow to change
configuration options but warn about possible conflicts and finally:
treat the output-high value as a reference counted, logical "GPIO
enabled" setting, meaning: the GPIO value is set to high when the first
user requests it to be high and back to low once the last user stops
"voting" for high.
I have two Q:s about the design:
1) why can't the value be counted on the struct gpio_desc level?
2) can gpio-aggregator facilities be reused (to some extent)?

...
+#include <linux/auxiliary_bus.h>
+#include <linux/cleanup.h>
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/driver.h>
+#include <linux/module.h>
+ types.h
+#include "gpiolib-shared.h"
...
+out:
+	if (shared_desc->highcnt)
+		dev_dbg(proxy->dev,
+			"Voted for value '%s', effective value is 'high', number of votes for 'high': %u\n",
+			value ? "high" : "low", shared_desc->highcnt);
+	else
+		dev_dbg(proxy->dev, "Voted for value 'low', effective value is 'low'\n");
You can unify and maybe save a few bytes here and there by doing something like
this:

	const char *tmp; // name is a placeholder

	tmp = str_high_low(shared_desc->highcnt);
	dev_dbg(proxy->dev,
		"Voted for value '%s', effective value is '%s', number of votes for '%s': %u\n",
		str_high_low(value), tmp, tmp, shared_desc->highcnt);

...
+		dev_dbg(proxy->dev,
+			"Only one user of this shared GPIO, allowing to set direction to output with value '%s'\n",
+			value ? "high" : "low");
str_high_low() ?
+		ret = gpiod_direction_output(desc, value);
+		if (ret)
+			return ret;
+
+		if (value) {
+			proxy->voted_high = true;
+			shared_desc->highcnt = 1;
+		} else {
+			proxy->voted_high = false;
+			shared_desc->highcnt = 0;
+		}
+
+		return 0;
+	}
-- 
With Best Regards,
Andy Shevchenko


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help