Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Jul 2025 20:26:09 GMT
From:      Ahmad Khalifa <vexeduxr@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 4a21713278a8 - main - gpiobus: add gpio_pin_acquire
Message-ID:  <202507042026.564KQ9to096862@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by vexeduxr:

URL: https://cgit.FreeBSD.org/src/commit/?id=4a21713278a865906e853b69357cf59a379df93a

commit 4a21713278a865906e853b69357cf59a379df93a
Author:     Ahmad Khalifa <vexeduxr@FreeBSD.org>
AuthorDate: 2025-07-04 20:03:04 +0000
Commit:     Ahmad Khalifa <vexeduxr@FreeBSD.org>
CommitDate: 2025-07-04 20:24:31 +0000

    gpiobus: add gpio_pin_acquire
    
    In some cases, drivers may need to acquire an existing gpio_pin_t. With
    the functions gpiobus currently exposes, this isn't possible as they
    allocate a new pin then acquire that. Add a new gpio_pin_acquire
    function which accepts an existing gpiobus_pin structure.
    
    Reviewed by:    mmel, imp
    Approved by:    imp (mentor)
    Differential Revision:  https://reviews.freebsd.org/D50869
---
 sys/dev/gpio/gpiobus.c    | 22 ++++++++++++++++++++++
 sys/dev/gpio/gpiobusvar.h |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/sys/dev/gpio/gpiobus.c b/sys/dev/gpio/gpiobus.c
index c28fac66115b..84980f3d6546 100644
--- a/sys/dev/gpio/gpiobus.c
+++ b/sys/dev/gpio/gpiobus.c
@@ -213,6 +213,28 @@ gpio_pin_is_active(gpio_pin_t pin, bool *active)
 	return (0);
 }
 
+/*
+ * Note that this function should only
+ * be used in cases where a pre-existing
+ * gpiobus_pin structure exists. In most
+ * cases, the gpio_pin_get_by_* functions
+ * suffice.
+ */
+int
+gpio_pin_acquire(gpio_pin_t gpio)
+{
+	device_t busdev;
+
+	KASSERT(gpio != NULL, ("GPIO pin is NULL."));
+	KASSERT(gpio->dev != NULL, ("GPIO pin device is NULL."));
+
+	busdev = GPIO_GET_BUS(gpio->dev);
+	if (busdev == NULL)
+		return (ENXIO);
+
+	return (gpiobus_acquire_pin(busdev, gpio->pin));
+}
+
 void
 gpio_pin_release(gpio_pin_t gpio)
 {
diff --git a/sys/dev/gpio/gpiobusvar.h b/sys/dev/gpio/gpiobusvar.h
index 975788e84a83..972e1f196399 100644
--- a/sys/dev/gpio/gpiobusvar.h
+++ b/sys/dev/gpio/gpiobusvar.h
@@ -156,6 +156,8 @@ int gpio_pin_get_by_bus_pinnum(device_t _bus, uint32_t _pinnum, gpio_pin_t *_gp)
 /* Acquire a pin by child and index (used by direct children of gpiobus). */
 int gpio_pin_get_by_child_index(device_t _child, uint32_t _idx, gpio_pin_t *_gp);
 
+/* Acquire a pin from an existing gpio_pin_t. */
+int gpio_pin_acquire(gpio_pin_t gpio);
 /* Release a pin acquired via any gpio_pin_get_xxx() function. */
 void gpio_pin_release(gpio_pin_t gpio);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202507042026.564KQ9to096862>