History

leds: core: Add support for composing LED class device names

Add generic support for composing LED class device name. The newly introduced led_compose_name() function composes device name according to either <color:function> or <devicename:color:function> pattern, depending on the configuration of initialization data. Backward compatibility with in-driver hard-coded LED class device names is assured thanks to the default_label and devicename properties of newly introduced struct led_init_data. In case none of the aforementioned properties was found, then, for OF nodes, the node name is adopted for LED class device name. At the occassion of amending the Documentation/leds/leds-class.txt unify spelling: colour -> color. Alongside these changes added is a new tool - tools/leds/get_led_device_info.sh. The tool allows retrieving details of a LED class device's parent device, which proves that using vendor or product name for devicename part of LED name doesn't convey any added value since that information had been already available in sysfs. The script performs also basic validation of a LED class device name.

Jacek Anaszewski committed 7 years ago

Commit bb4e9af1 parent c5d18dd6 files · +458 −6Browse files

Showing the changes to include/linux (1 of 6 files). Show all

Unified · Split

include/linux/leds.h+45−0
@@ -8,6 +8,7 @@ · 7 unmodified lines
8#ifndef __LINUX_LEDS_H_INCLUDED8#ifndef __LINUX_LEDS_H_INCLUDED
9#define __LINUX_LEDS_H_INCLUDED9#define __LINUX_LEDS_H_INCLUDED
10 10
11#include <dt-bindings/leds/common.h>
11#include <linux/device.h>12#include <linux/device.h>
12#include <linux/kernfs.h>13#include <linux/kernfs.h>
13#include <linux/list.h>14#include <linux/list.h>
@@ -33,6 +34,25 @@ enum led_brightness { · 19 unmodified lines
33struct led_init_data {34struct led_init_data {
34 /* device fwnode handle */35 /* device fwnode handle */
35 struct fwnode_handle *fwnode;36 struct fwnode_handle *fwnode;
37 /*
38 * default <color:function> tuple, for backward compatibility
39 * with in-driver hard-coded LED names used as a fallback when
40 * DT "label" property is absent; it should be set to NULL
41 * in new LED class drivers.
42 */
43 const char *default_label;
44 /*
45 * string to be used for devicename section of LED class device
46 * either for label based LED name composition path or for fwnode
47 * based when devname_mandatory is true
48 */
49 const char *devicename;
50 /*
51 * indicates if LED name should always comprise devicename section;
52 * only LEDs exposed by drivers of hot-pluggable devices should
53 * set it to true
54 */
55 bool devname_mandatory;
36};56};
37 57
38struct led_classdev {58struct led_classdev {
@@ -257,6 +277,22 @@ extern void led_sysfs_disable(struct led_classdev *led_cdev); · 218 unmodified lines
257 */277 */
258extern void led_sysfs_enable(struct led_classdev *led_cdev);278extern void led_sysfs_enable(struct led_classdev *led_cdev);
259 279
280/**
281 * led_compose_name - compose LED class device name
282 * @dev: LED controller device object
283 * @child: child fwnode_handle describing a LED or a group of synchronized LEDs;
284 * it must be provided only for fwnode based LEDs
285 * @led_classdev_name: composed LED class device name
286 *
287 * Create LED class device name basing on the provided init_data argument.
288 * The name can have <devicename:color:function> or <color:function>.
289 * form, depending on the init_data configuration.
290 *
291 * Returns: 0 on success or negative error value on failure
292 */
293extern int led_compose_name(struct device *dev, struct led_init_data *init_data,
294 char *led_classdev_name);
295
260/**296/**
261 * led_sysfs_is_disabled - check if LED sysfs interface is disabled297 * led_sysfs_is_disabled - check if LED sysfs interface is disabled
262 * @led_cdev: the LED to query298 * @led_cdev: the LED to query
@@ -434,6 +470,15 @@ struct led_platform_data { · 171 unmodified lines
434 struct led_info *leds;470 struct led_info *leds;
435};471};
436 472
473struct led_properties {
474 u32 color;
475 bool color_present;
476 const char *function;
477 u32 func_enum;
478 bool func_enum_present;
479 const char *label;
480};
481
437struct gpio_desc;482struct gpio_desc;
438typedef int (*gpio_blink_set_t)(struct gpio_desc *desc, int state,483typedef int (*gpio_blink_set_t)(struct gpio_desc *desc, int state,
439 unsigned long *delay_on,484 unsigned long *delay_on,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t