Skip to content

Commit 156d111

Browse files
committed
drivers: led: gpio: Add pinctrl support
Allow specifying pinmuxing in gpio-leds. A lot of board have on-board LEDs, so allowing specifying pinmux in these nodes helps keep the base GPIO node cleaner, and easier to write overlays for. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
1 parent c35bb0d commit 156d111

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/led/led_gpio.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
#include <zephyr/drivers/gpio.h>
1616
#include <zephyr/device.h>
1717
#include <zephyr/kernel.h>
18+
#include <zephyr/drivers/pinctrl.h>
1819

1920
#include <zephyr/logging/log.h>
2021
LOG_MODULE_REGISTER(led_gpio, CONFIG_LED_LOG_LEVEL);
2122

2223
struct led_gpio_config {
2324
size_t num_leds;
2425
const struct gpio_dt_spec *led;
26+
const struct pinctrl_dev_config *pcfg;
2527
};
2628

2729
static int led_gpio_set_brightness(const struct device *dev, uint32_t led, uint8_t value)
@@ -59,6 +61,12 @@ static int led_gpio_init(const struct device *dev)
5961
err = -ENODEV;
6062
}
6163

64+
err = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
65+
if (err < 0 && err != -ENOENT) {
66+
LOG_ERR("failed to apply pinctrl");
67+
return err;
68+
}
69+
6270
for (size_t i = 0; (i < config->num_leds) && !err; i++) {
6371
const struct gpio_dt_spec *led = &config->led[i];
6472

@@ -84,6 +92,7 @@ static DEVICE_API(led, led_gpio_api) = {
8492
};
8593

8694
#define LED_GPIO_DEVICE(i) \
95+
PINCTRL_DT_INST_DEFINE(i); \
8796
\
8897
static const struct gpio_dt_spec gpio_dt_spec_##i[] = { \
8998
DT_INST_FOREACH_CHILD_SEP_VARGS(i, GPIO_DT_SPEC_GET, (,), gpios) \
@@ -92,6 +101,7 @@ static const struct gpio_dt_spec gpio_dt_spec_##i[] = { \
92101
static const struct led_gpio_config led_gpio_config_##i = { \
93102
.num_leds = ARRAY_SIZE(gpio_dt_spec_##i), \
94103
.led = gpio_dt_spec_##i, \
104+
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(i), \
95105
}; \
96106
\
97107
DEVICE_DT_INST_DEFINE(i, &led_gpio_init, NULL, \

0 commit comments

Comments
 (0)