Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

leds: led-class: Add Device Tree support to led_get()

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@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Hans de Goede <hansg@kernel.org>
Signed-off-by: Aleksandrs Vinarskis <alex@vinarskis.com>
Link: https://lore.kernel.org/r/20250910-leds-v5-3-bb90a0f897d5@vinarskis.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Hans de Goede and committed by
Lee Jones
ef381e17 22420da3

+15 -2
+15 -2
drivers/leds/led-class.c
··· 252 252 * of_led_get() - request a LED device via the LED framework 253 253 * @np: device node to get the LED device from 254 254 * @index: the index of the LED 255 + * @name: the name of the LED used to map it to its function, if present 255 256 * 256 257 * Returns the LED device parsed from the phandle specified in the "leds" 257 258 * property of a device tree node or a negative error-code on failure. 258 259 */ 259 - static struct led_classdev *of_led_get(struct device_node *np, int index) 260 + static struct led_classdev *of_led_get(struct device_node *np, int index, 261 + const char *name) 260 262 { 261 263 struct device *led_dev; 262 264 struct device_node *led_node; 263 265 266 + /* 267 + * For named LEDs, first look up the name in the "led-names" property. 268 + * If it cannot be found, then of_parse_phandle() will propagate the error. 269 + */ 270 + if (name) 271 + index = of_property_match_string(np, "led-names", name); 264 272 led_node = of_parse_phandle(np, "leds", index); 265 273 if (!led_node) 266 274 return ERR_PTR(-ENOENT); ··· 332 324 if (!dev) 333 325 return ERR_PTR(-EINVAL); 334 326 335 - led = of_led_get(dev->of_node, index); 327 + led = of_led_get(dev->of_node, index, NULL); 336 328 if (IS_ERR(led)) 337 329 return led; 338 330 ··· 350 342 struct led_classdev *led_get(struct device *dev, char *con_id) 351 343 { 352 344 struct led_lookup_data *lookup; 345 + struct led_classdev *led_cdev; 353 346 const char *provider = NULL; 354 347 struct device *led_dev; 348 + 349 + led_cdev = of_led_get(dev->of_node, -1, con_id); 350 + if (!IS_ERR(led_cdev) || PTR_ERR(led_cdev) != -ENOENT) 351 + return led_cdev; 355 352 356 353 mutex_lock(&leds_lookup_lock); 357 354 list_for_each_entry(lookup, &leds_lookup_list, list) {