Skip to content

Commit 4fd32b1

Browse files
committed
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
1 parent 59e74fd commit 4fd32b1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

sys/dev/gpio/gpio_if.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@
6262

6363
return (0);
6464
}
65+
66+
static int
67+
gpio_default_get_pin_list(device_t dev, uint32_t *pin_list)
68+
{
69+
uint32_t maxpin;
70+
int err;
71+
72+
err = GPIO_PIN_MAX(dev, &maxpin);
73+
if (err != 0)
74+
return (ENXIO);
75+
76+
for (int i = 0; i <= maxpin; i++)
77+
pin_list[i] = i;
78+
79+
return (0);
80+
}
6581
};
6682

6783
HEADER {
@@ -185,3 +201,13 @@
185201
uint32_t num_pins;
186202
uint32_t *pin_flags;
187203
} DEFAULT gpio_default_nosupport;
204+
205+
#
206+
# Get the controller's pin numbers. pin_list is expected to be an array with at
207+
# least GPIO_PIN_MAX() elements. Populates pin_list from 0 to GPIO_PIN_MAX() by
208+
# default.
209+
#
210+
METHOD int get_pin_list {
211+
device_t dev;
212+
uint32_t *pin_list;
213+
} DEFAULT gpio_default_get_pin_list;

0 commit comments

Comments
 (0)