kernel: fix of_node handling in LEDs core code
[openwrt/openwrt.git] / target / linux / generic / patches-4.9 / 080-0001-leds-core-add-OF-variants-of-LED-registering-functio.patch
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
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
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
11 info.
12
13 The easiest solution for achieving this was reworking old functions to
14 more generic ones & adding simple defines for API compatibility.
15
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>
19 ---
20 drivers/leds/led-class.c | 26 ++++++++++++++++----------
21 include/linux/leds.h | 14 ++++++++++----
22 2 files changed, 26 insertions(+), 14 deletions(-)
23
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
27 }
28
29 /**
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.
33 + *
34 + * @parent: parent of LED device
35 * @led_cdev: the led_classdev structure for this device.
36 + * @np: DT node describing this LED
37 */
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)
41 {
42 char name[64];
43 int ret;
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;
49
50 if (ret)
51 dev_warn(parent, "Led %s renamed to %s due to name collision",
52 @@ -228,7 +232,7 @@ int led_classdev_register(struct device
53
54 return 0;
55 }
56 -EXPORT_SYMBOL_GPL(led_classdev_register);
57 +EXPORT_SYMBOL_GPL(of_led_classdev_register);
58
59 /**
60 * led_classdev_unregister - unregisters a object of led_properties class.
61 @@ -270,12 +274,14 @@ static void devm_led_classdev_release(st
62 }
63
64 /**
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()
68 + *
69 + * @parent: parent of LED device
70 * @led_cdev: the led_classdev structure for this device.
71 */
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)
77 {
78 struct led_classdev **dr;
79 int rc;
80 @@ -284,7 +290,7 @@ int devm_led_classdev_register(struct de
81 if (!dr)
82 return -ENOMEM;
83
84 - rc = led_classdev_register(parent, led_cdev);
85 + rc = of_led_classdev_register(parent, np, led_cdev);
86 if (rc) {
87 devres_free(dr);
88 return rc;
89 @@ -295,7 +301,7 @@ int devm_led_classdev_register(struct de
90
91 return 0;
92 }
93 -EXPORT_SYMBOL_GPL(devm_led_classdev_register);
94 +EXPORT_SYMBOL_GPL(devm_of_led_classdev_register);
95
96 static int devm_led_classdev_match(struct device *dev, void *res, void *data)
97 {
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;
102 };
103
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);