The branch main has been updated by vexeduxr:

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

commit 4fd32b1e7f54811bd3a6f362493d256db40bb686
Author:     Ahmad Khalifa <vexed...@freebsd.org>
AuthorDate: 2025-08-27 21:25:39 +0000
Commit:     Ahmad Khalifa <vexed...@freebsd.org>
CommitDate: 2025-08-27 21:38:32 +0000

    gpio: add GPIO_GET_PIN_LIST
    
    While most GPIO controllers provide pins from 0 .. N in a sequential
    manner, not all controllers start with pin 0, and not all controllers
    order their pins sequentially. Allow callers to get a pin list from the
    controller. The default behaviour is to fill pin_list with pins 0 to
    GPIO_PIN_MAX().
    
    Suggested by:   mmel
    Reviewed by:    mmel
    Approved by:    imp (mentor)
    Differential Revision:  https://reviews.freebsd.org/D52172
---
 sys/dev/gpio/gpio_if.m | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/sys/dev/gpio/gpio_if.m b/sys/dev/gpio/gpio_if.m
index 5501b2b5c0e7..0b6988ceba79 100644
--- a/sys/dev/gpio/gpio_if.m
+++ b/sys/dev/gpio/gpio_if.m
@@ -62,6 +62,22 @@ CODE {
 
                return (0);
        }
+
+       static int
+       gpio_default_get_pin_list(device_t dev, uint32_t *pin_list)
+       {
+               uint32_t maxpin;
+               int err;
+
+               err = GPIO_PIN_MAX(dev, &maxpin);
+               if (err != 0)
+                       return (ENXIO);
+
+               for (int i = 0; i <= maxpin; i++)
+                       pin_list[i] = i;
+
+               return (0);
+       }
 };
 
 HEADER {
@@ -185,3 +201,13 @@ METHOD int pin_config_32 {
        uint32_t num_pins;
        uint32_t *pin_flags;
 } DEFAULT gpio_default_nosupport;
+
+#
+# Get the controller's pin numbers. pin_list is expected to be an array with at
+# least GPIO_PIN_MAX() elements. Populates pin_list from 0 to GPIO_PIN_MAX() by
+# default.
+#
+METHOD int get_pin_list {
+       device_t dev;
+       uint32_t *pin_list;
+} DEFAULT gpio_default_get_pin_list;

Reply via email to