diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2023-09-26 23:48:11 +0200 |
---|---|---|
committer | Bartosz Golaszewski <bartosz.golaszewski@linaro.org> | 2023-10-02 09:45:43 +0200 |
commit | 3bb5c9ddf46bf35bd86293cf77f1d88689689fc2 (patch) | |
tree | 94dd4768cbda3bfd970079b1cb1554294380dfdd /drivers/gpio/gpiolib-of.c | |
parent | 46d0825104b8e62ea5b3f0f749e656ecfdcc20da (diff) | |
download | linux-3bb5c9ddf46bf35bd86293cf77f1d88689689fc2.tar.gz linux-3bb5c9ddf46bf35bd86293cf77f1d88689689fc2.tar.bz2 linux-3bb5c9ddf46bf35bd86293cf77f1d88689689fc2.zip |
gpiolib: of: Allow "trigger-sources" to reference a GPIO
The "trigger-sources" phandle used for LED triggers are special:
the DT bindings mandate that such triggers have the same phandle
references no matter what the trigger is. A GPIO is just another
kind of device that can trigger a LED.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Diffstat (limited to 'drivers/gpio/gpiolib-of.c')
-rw-r--r-- | drivers/gpio/gpiolib-of.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 58c0bbe9d569..a904586c3c5f 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -620,6 +620,33 @@ static struct gpio_desc *of_find_mt2701_gpio(struct device_node *np, return desc; } +/* + * Trigger sources are special, they allow us to use any GPIO as a LED trigger + * and have the name "trigger-sources" no matter which kind of phandle it is + * pointing to, whether to a GPIO, a USB host, a network PHY etc. So in this case + * we allow looking something up that is not named "foo-gpios". + */ +static struct gpio_desc *of_find_trigger_gpio(struct device_node *np, + const char *con_id, + unsigned int idx, + enum of_gpio_flags *of_flags) +{ + struct gpio_desc *desc; + + if (!IS_ENABLED(CONFIG_LEDS_TRIGGER_GPIO)) + return ERR_PTR(-ENOENT); + + if (!con_id || strcmp(con_id, "trigger-sources")) + return ERR_PTR(-ENOENT); + + desc = of_get_named_gpiod_flags(np, con_id, idx, of_flags); + if (!gpiod_not_found(desc)) + pr_debug("%s is used as a trigger\n", of_node_full_name(np)); + + return desc; +} + + typedef struct gpio_desc *(*of_find_gpio_quirk)(struct device_node *np, const char *con_id, unsigned int idx, @@ -627,6 +654,7 @@ typedef struct gpio_desc *(*of_find_gpio_quirk)(struct device_node *np, static const of_find_gpio_quirk of_find_gpio_quirks[] = { of_find_gpio_rename, of_find_mt2701_gpio, + of_find_trigger_gpio, NULL }; |