1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
2 Date: Mon, 6 Mar 2017 06:19:44 +0100
3 Subject: [PATCH] leds: core: add OF variants of LED registering functions
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
8 These new functions allow passing an additional device_node argument
9 that will be internally set for created LED device. Thanks to this LED
10 core code and triggers will be able to access DT node for reading extra
13 The easiest solution for achieving this was reworking old functions to
14 more generic ones & adding simple defines for API compatibility.
16 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 Acked-by: Pavel Machek <pavel@ucw.cz>
18 Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
20 drivers/leds/led-class.c | 26 ++++++++++++++++----------
21 include/linux/leds.h | 14 ++++++++++----
22 2 files changed, 26 insertions(+), 14 deletions(-)
24 --- a/drivers/leds/led-class.c
25 +++ b/drivers/leds/led-class.c
26 @@ -181,11 +181,14 @@ static int led_classdev_next_name(const
30 - * led_classdev_register - register a new object of led_classdev class.
31 - * @parent: The device to register.
32 + * of_led_classdev_register - register a new object of led_classdev class.
34 + * @parent: parent of LED device
35 * @led_cdev: the led_classdev structure for this device.
36 + * @np: DT node describing this LED
38 -int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
39 +int of_led_classdev_register(struct device *parent, struct device_node *np,
40 + struct led_classdev *led_cdev)
44 @@ -198,6 +201,7 @@ int led_classdev_register(struct device
45 led_cdev, led_cdev->groups, "%s", name);
46 if (IS_ERR(led_cdev->dev))
47 return PTR_ERR(led_cdev->dev);
48 + led_cdev->dev->of_node = np;
51 dev_warn(parent, "Led %s renamed to %s due to name collision",
52 @@ -228,7 +232,7 @@ int led_classdev_register(struct device
56 -EXPORT_SYMBOL_GPL(led_classdev_register);
57 +EXPORT_SYMBOL_GPL(of_led_classdev_register);
60 * led_classdev_unregister - unregisters a object of led_properties class.
61 @@ -270,12 +274,14 @@ static void devm_led_classdev_release(st
65 - * devm_led_classdev_register - resource managed led_classdev_register()
66 - * @parent: The device to register.
67 + * devm_of_led_classdev_register - resource managed led_classdev_register()
69 + * @parent: parent of LED device
70 * @led_cdev: the led_classdev structure for this device.
72 -int devm_led_classdev_register(struct device *parent,
73 - struct led_classdev *led_cdev)
74 +int devm_of_led_classdev_register(struct device *parent,
75 + struct device_node *np,
76 + struct led_classdev *led_cdev)
78 struct led_classdev **dr;
80 @@ -284,7 +290,7 @@ int devm_led_classdev_register(struct de
84 - rc = led_classdev_register(parent, led_cdev);
85 + rc = of_led_classdev_register(parent, np, led_cdev);
89 @@ -295,7 +301,7 @@ int devm_led_classdev_register(struct de
93 -EXPORT_SYMBOL_GPL(devm_led_classdev_register);
94 +EXPORT_SYMBOL_GPL(devm_of_led_classdev_register);
96 static int devm_led_classdev_match(struct device *dev, void *res, void *data)
98 --- a/include/linux/leds.h
99 +++ b/include/linux/leds.h
100 @@ -109,10 +109,16 @@ struct led_classdev {
101 struct mutex led_access;
104 -extern int led_classdev_register(struct device *parent,
105 - struct led_classdev *led_cdev);
106 -extern int devm_led_classdev_register(struct device *parent,
107 - struct led_classdev *led_cdev);
108 +extern int of_led_classdev_register(struct device *parent,
109 + struct device_node *np,
110 + struct led_classdev *led_cdev);
111 +#define led_classdev_register(parent, led_cdev) \
112 + of_led_classdev_register(parent, NULL, led_cdev)
113 +extern int devm_of_led_classdev_register(struct device *parent,
114 + struct device_node *np,
115 + struct led_classdev *led_cdev);
116 +#define devm_led_classdev_register(parent, led_cdev) \
117 + devm_of_led_classdev_register(parent, NULL, led_cdev)
118 extern void led_classdev_unregister(struct led_classdev *led_cdev);
119 extern void devm_led_classdev_unregister(struct device *parent,
120 struct led_classdev *led_cdev);