[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250911081540.GD9224@google.com>
Date: Thu, 11 Sep 2025 09:15:40 +0100
From: Lee Jones <lee@...nel.org>
To: Aleksandrs Vinarskis <alex@...arskis.com>
Cc: Hans de Goede <hansg@...nel.org>, Pavel Machek <pavel@...nel.org>,
Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Bryan O'Donoghue <bryan.odonoghue@...aro.org>,
Jingoo Han <jingoohan1@...il.com>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Jean-Jacques Hiblot <jjhiblot@...phandler.com>,
Jacopo Mondi <jacopo@...ndi.org>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
Bjorn Andersson <andersson@...nel.org>,
Konrad Dybcio <konradybcio@...nel.org>,
Daniel Thompson <danielt@...nel.org>, linux-leds@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
dri-devel@...ts.freedesktop.org, linux-media@...r.kernel.org,
linux-arm-msm@...r.kernel.org, threeway@...il.com,
Andy Shevchenko <andy.shevchenko@...il.com>,
Linus Walleij <linus.walleij@...aro.org>
Subject: Re: [PATCH v5 3/4] leds: led-class: Add devicetree support to
led_get()
On Wed, 10 Sep 2025, Aleksandrs Vinarskis wrote:
> From: Hans de Goede <hansg@...nel.org>
>
> Add 'name' argument to of_led_get() such that it can lookup LEDs in
> devicetree by either name or index.
>
> And use this modified function to add devicetree support to the generic
> (non devicetree specific) [devm_]led_get() function.
>
> This uses the standard devicetree pattern of adding a -names string array
> to map names to the indexes for an array of resources.
>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@...il.com>
> Reviewed-by: Lee Jones <lee@...nel.org>
Remind me why this can't go in through LED again?
> Reviewed-by: Linus Walleij <linus.walleij@...aro.org>
> Signed-off-by: Hans de Goede <hansg@...nel.org>
> Signed-off-by: Aleksandrs Vinarskis <alex@...arskis.com>
> ---
> drivers/leds/led-class.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index 15633fbf3c166aa4f521774d245f6399a642bced..f3faf37f9a08ac762ed87b91cb3cab5faa8eacb0 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -252,15 +252,23 @@ static const struct class leds_class = {
> * of_led_get() - request a LED device via the LED framework
> * @np: device node to get the LED device from
> * @index: the index of the LED
> + * @name: the name of the LED used to map it to its function, if present
> *
> * Returns the LED device parsed from the phandle specified in the "leds"
> * property of a device tree node or a negative error-code on failure.
> */
> -static struct led_classdev *of_led_get(struct device_node *np, int index)
> +static struct led_classdev *of_led_get(struct device_node *np, int index,
> + const char *name)
> {
> struct device *led_dev;
> struct device_node *led_node;
>
> + /*
> + * For named LEDs, first look up the name in the "led-names" property.
> + * If it cannot be found, then of_parse_phandle() will propagate the error.
> + */
> + if (name)
> + index = of_property_match_string(np, "led-names", name);
> led_node = of_parse_phandle(np, "leds", index);
> if (!led_node)
> return ERR_PTR(-ENOENT);
> @@ -324,7 +332,7 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev,
> if (!dev)
> return ERR_PTR(-EINVAL);
>
> - led = of_led_get(dev->of_node, index);
> + led = of_led_get(dev->of_node, index, NULL);
> if (IS_ERR(led))
> return led;
>
> @@ -342,9 +350,14 @@ EXPORT_SYMBOL_GPL(devm_of_led_get);
> struct led_classdev *led_get(struct device *dev, char *con_id)
> {
> struct led_lookup_data *lookup;
> + struct led_classdev *led_cdev;
> const char *provider = NULL;
> struct device *led_dev;
>
> + led_cdev = of_led_get(dev->of_node, -1, con_id);
> + if (!IS_ERR(led_cdev) || PTR_ERR(led_cdev) != -ENOENT)
> + return led_cdev;
> +
> mutex_lock(&leds_lookup_lock);
> list_for_each_entry(lookup, &leds_lookup_list, list) {
> if (!strcmp(lookup->dev_id, dev_name(dev)) &&
>
> --
> 2.48.1
>
>
--
Lee Jones [李琼斯]
Powered by blists - more mailing lists