summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek Anaszewski <jacek.anaszewski@gmail.com>2019-06-09 14:19:03 -0400
committerJacek Anaszewski <jacek.anaszewski@gmail.com>2019-07-25 14:07:50 -0400
commitb2b998c0f944993c9ef435569651e407d607af41 (patch)
tree28d4f69784e203114b5feb8b5bde12510e9c42ee
parent7d9d60bdfa45181e439b50bb067e97168b99f89e (diff)
leds: class: Improve LED and LED flash class registration API
Replace of_led_classdev_register() with led_classdev_register_ext(), which accepts easily extendable struct led_init_data, instead of the fixed struct device_node argument. The latter can be now passed in an fwnode property of the struct led_init_data. The modification is driven by the need for passing additional arguments required for the forthcoming generic mechanism for composing LED names. Currently the LED name is conveyed in the "name" char pointer property of the struct led_classdev. This is redundant since LED class device name is accessible throughout the whole LED class device life time via associated struct device's kobj->name property. The change will not break any existing clients since the patch alters also existing led_classdev{_flash}_register() macro wrappers, that pass NULL in place of init_data, which leads to using legacy name initialization path basing on the struct led_classdev's "name" property. Three existing users of devm_of_led_classdev_registers() are modified to use devm_led_classdev_register(), which will not impact their operation since they in fact didn't need to pass struct device_node on registration from the beginning. Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com> Cc: Baolin Wang <baolin.wang@linaro.org> Cc: Dan Murphy <dmurphy@ti.com> Cc: Daniel Mack <daniel@zonque.org> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Oleh Kravchenko <oleg@kaa.org.ua> Cc: Sakari Ailus <sakari.ailus@linux.intel.com> Cc: Simon Shields <simon@lineageos.org> Acked-by: Pavel Machek <pavel@ucw.cz>
-rw-r--r--drivers/leds/led-class-flash.c9
-rw-r--r--drivers/leds/led-class.c29
-rw-r--r--drivers/leds/leds-cr0014114.c3
-rw-r--r--drivers/leds/leds-gpio.c2
-rw-r--r--drivers/leds/leds-max77650.c2
-rw-r--r--drivers/leds/leds-pwm.c3
-rw-r--r--include/linux/led-class-flash.h15
-rw-r--r--include/linux/leds.h34
8 files changed, 60 insertions, 37 deletions
diff --git a/drivers/leds/led-class-flash.c b/drivers/leds/led-class-flash.c
index 94980c654d89..60c3de5c6b9f 100644
--- a/drivers/leds/led-class-flash.c
+++ b/drivers/leds/led-class-flash.c
@@ -282,8 +282,9 @@ static void led_flash_init_sysfs_groups(struct led_classdev_flash *fled_cdev)
282 led_cdev->groups = flash_groups; 282 led_cdev->groups = flash_groups;
283} 283}
284 284
285int led_classdev_flash_register(struct device *parent, 285int led_classdev_flash_register_ext(struct device *parent,
286 struct led_classdev_flash *fled_cdev) 286 struct led_classdev_flash *fled_cdev,
287 struct led_init_data *init_data)
287{ 288{
288 struct led_classdev *led_cdev; 289 struct led_classdev *led_cdev;
289 const struct led_flash_ops *ops; 290 const struct led_flash_ops *ops;
@@ -309,13 +310,13 @@ int led_classdev_flash_register(struct device *parent,
309 } 310 }
310 311
311 /* Register led class device */ 312 /* Register led class device */
312 ret = led_classdev_register(parent, led_cdev); 313 ret = led_classdev_register_ext(parent, led_cdev, init_data);
313 if (ret < 0) 314 if (ret < 0)
314 return ret; 315 return ret;
315 316
316 return 0; 317 return 0;
317} 318}
318EXPORT_SYMBOL_GPL(led_classdev_flash_register); 319EXPORT_SYMBOL_GPL(led_classdev_flash_register_ext);
319 320
320void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) 321void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev)
321{ 322{
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 4793e77808e2..242122f49333 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -14,6 +14,7 @@
14#include <linux/leds.h> 14#include <linux/leds.h>
15#include <linux/list.h> 15#include <linux/list.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/of.h>
17#include <linux/slab.h> 18#include <linux/slab.h>
18#include <linux/spinlock.h> 19#include <linux/spinlock.h>
19#include <linux/timer.h> 20#include <linux/timer.h>
@@ -242,14 +243,16 @@ static int led_classdev_next_name(const char *init_name, char *name,
242} 243}
243 244
244/** 245/**
245 * of_led_classdev_register - register a new object of led_classdev class. 246 * led_classdev_register_ext - register a new object of led_classdev class
247 * with init data.
246 * 248 *
247 * @parent: parent of LED device 249 * @parent: parent of LED device
248 * @led_cdev: the led_classdev structure for this device. 250 * @led_cdev: the led_classdev structure for this device.
249 * @np: DT node describing this LED 251 * @init_data: LED class device initialization data
250 */ 252 */
251int of_led_classdev_register(struct device *parent, struct device_node *np, 253int led_classdev_register_ext(struct device *parent,
252 struct led_classdev *led_cdev) 254 struct led_classdev *led_cdev,
255 struct led_init_data *init_data)
253{ 256{
254 char name[LED_MAX_NAME_SIZE]; 257 char name[LED_MAX_NAME_SIZE];
255 int ret; 258 int ret;
@@ -266,7 +269,8 @@ int of_led_classdev_register(struct device *parent, struct device_node *np,
266 mutex_unlock(&led_cdev->led_access); 269 mutex_unlock(&led_cdev->led_access);
267 return PTR_ERR(led_cdev->dev); 270 return PTR_ERR(led_cdev->dev);
268 } 271 }
269 led_cdev->dev->of_node = np; 272 if (init_data && init_data->fwnode)
273 led_cdev->dev->of_node = to_of_node(init_data->fwnode);
270 274
271 if (ret) 275 if (ret)
272 dev_warn(parent, "Led %s renamed to %s due to name collision", 276 dev_warn(parent, "Led %s renamed to %s due to name collision",
@@ -311,7 +315,7 @@ int of_led_classdev_register(struct device *parent, struct device_node *np,
311 315
312 return 0; 316 return 0;
313} 317}
314EXPORT_SYMBOL_GPL(of_led_classdev_register); 318EXPORT_SYMBOL_GPL(led_classdev_register_ext);
315 319
316/** 320/**
317 * led_classdev_unregister - unregisters a object of led_properties class. 321 * led_classdev_unregister - unregisters a object of led_properties class.
@@ -356,14 +360,15 @@ static void devm_led_classdev_release(struct device *dev, void *res)
356} 360}
357 361
358/** 362/**
359 * devm_of_led_classdev_register - resource managed led_classdev_register() 363 * devm_led_classdev_register_ext - resource managed led_classdev_register_ext()
360 * 364 *
361 * @parent: parent of LED device 365 * @parent: parent of LED device
362 * @led_cdev: the led_classdev structure for this device. 366 * @led_cdev: the led_classdev structure for this device.
367 * @init_data: LED class device initialization data
363 */ 368 */
364int devm_of_led_classdev_register(struct device *parent, 369int devm_led_classdev_register_ext(struct device *parent,
365 struct device_node *np, 370 struct led_classdev *led_cdev,
366 struct led_classdev *led_cdev) 371 struct led_init_data *init_data)
367{ 372{
368 struct led_classdev **dr; 373 struct led_classdev **dr;
369 int rc; 374 int rc;
@@ -372,7 +377,7 @@ int devm_of_led_classdev_register(struct device *parent,
372 if (!dr) 377 if (!dr)
373 return -ENOMEM; 378 return -ENOMEM;
374 379
375 rc = of_led_classdev_register(parent, np, led_cdev); 380 rc = led_classdev_register_ext(parent, led_cdev, init_data);
376 if (rc) { 381 if (rc) {
377 devres_free(dr); 382 devres_free(dr);
378 return rc; 383 return rc;
@@ -383,7 +388,7 @@ int devm_of_led_classdev_register(struct device *parent,
383 388
384 return 0; 389 return 0;
385} 390}
386EXPORT_SYMBOL_GPL(devm_of_led_classdev_register); 391EXPORT_SYMBOL_GPL(devm_led_classdev_register_ext);
387 392
388static int devm_led_classdev_match(struct device *dev, void *res, void *data) 393static int devm_led_classdev_match(struct device *dev, void *res, void *data)
389{ 394{
diff --git a/drivers/leds/leds-cr0014114.c b/drivers/leds/leds-cr0014114.c
index 0e4262462cb9..1c82152764d2 100644
--- a/drivers/leds/leds-cr0014114.c
+++ b/drivers/leds/leds-cr0014114.c
@@ -207,8 +207,7 @@ static int cr0014114_probe_dt(struct cr0014114 *priv)
207 led->ldev.max_brightness = CR_MAX_BRIGHTNESS; 207 led->ldev.max_brightness = CR_MAX_BRIGHTNESS;
208 led->ldev.brightness_set_blocking = cr0014114_set_sync; 208 led->ldev.brightness_set_blocking = cr0014114_set_sync;
209 209
210 ret = devm_of_led_classdev_register(priv->dev, np, 210 ret = devm_led_classdev_register(priv->dev, &led->ldev);
211 &led->ldev);
212 if (ret) { 211 if (ret) {
213 dev_err(priv->dev, 212 dev_err(priv->dev,
214 "failed to register LED device %s, err %d", 213 "failed to register LED device %s, err %d",
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index bdc98ddca1dc..8f463c912db8 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -108,7 +108,7 @@ static int create_gpio_led(const struct gpio_led *template,
108 if (ret < 0) 108 if (ret < 0)
109 return ret; 109 return ret;
110 110
111 return devm_of_led_classdev_register(parent, np, &led_dat->cdev); 111 return devm_led_classdev_register(parent, &led_dat->cdev);
112} 112}
113 113
114struct gpio_leds_priv { 114struct gpio_leds_priv {
diff --git a/drivers/leds/leds-max77650.c b/drivers/leds/leds-max77650.c
index 04738324b3e6..5a14f9775b0e 100644
--- a/drivers/leds/leds-max77650.c
+++ b/drivers/leds/leds-max77650.c
@@ -118,7 +118,7 @@ static int max77650_led_probe(struct platform_device *pdev)
118 of_property_read_string(child, "linux,default-trigger", 118 of_property_read_string(child, "linux,default-trigger",
119 &led->cdev.default_trigger); 119 &led->cdev.default_trigger);
120 120
121 rv = devm_of_led_classdev_register(dev, child, &led->cdev); 121 rv = devm_led_classdev_register(dev, &led->cdev);
122 if (rv) 122 if (rv)
123 goto err_node_put; 123 goto err_node_put;
124 124
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index 48d068f80f11..d0e1f2710351 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -111,8 +111,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
111 if (!led_data->period && (led->pwm_period_ns > 0)) 111 if (!led_data->period && (led->pwm_period_ns > 0))
112 led_data->period = led->pwm_period_ns; 112 led_data->period = led->pwm_period_ns;
113 113
114 ret = devm_of_led_classdev_register(dev, to_of_node(fwnode), 114 ret = devm_led_classdev_register(dev, &led_data->cdev);
115 &led_data->cdev);
116 if (ret == 0) { 115 if (ret == 0) {
117 priv->num_leds++; 116 priv->num_leds++;
118 led_pwm_set(&led_data->cdev, led_data->cdev.brightness); 117 led_pwm_set(&led_data->cdev, led_data->cdev.brightness);
diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h
index f52713f0a269..1e824963af17 100644
--- a/include/linux/led-class-flash.h
+++ b/include/linux/led-class-flash.h
@@ -86,15 +86,20 @@ static inline struct led_classdev_flash *lcdev_to_flcdev(
86} 86}
87 87
88/** 88/**
89 * led_classdev_flash_register - register a new object of led_classdev class 89 * led_classdev_flash_register_ext - register a new object of LED class with
90 * with support for flash LEDs 90 * init data and with support for flash LEDs
91 * @parent: the flash LED to register 91 * @parent: LED flash controller device this flash LED is driven by
92 * @fled_cdev: the led_classdev_flash structure for this device 92 * @fled_cdev: the led_classdev_flash structure for this device
93 * @init_data: the LED class flash device initialization data
93 * 94 *
94 * Returns: 0 on success or negative error value on failure 95 * Returns: 0 on success or negative error value on failure
95 */ 96 */
96extern int led_classdev_flash_register(struct device *parent, 97extern int led_classdev_flash_register_ext(struct device *parent,
97 struct led_classdev_flash *fled_cdev); 98 struct led_classdev_flash *fled_cdev,
99 struct led_init_data *init_data);
100
101#define led_classdev_flash_register(parent, fled_cdev) \
102 led_classdev_flash_register_ext(parent, fled_cdev, NULL)
98 103
99/** 104/**
100 * led_classdev_flash_unregister - unregisters an object of led_classdev class 105 * led_classdev_flash_unregister - unregisters an object of led_classdev class
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 9b2bf574a17a..2bbe8a38fe39 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -30,6 +30,11 @@ enum led_brightness {
30 LED_FULL = 255, 30 LED_FULL = 255,
31}; 31};
32 32
33struct led_init_data {
34 /* device fwnode handle */
35 struct fwnode_handle *fwnode;
36};
37
33struct led_classdev { 38struct led_classdev {
34 const char *name; 39 const char *name;
35 enum led_brightness brightness; 40 enum led_brightness brightness;
@@ -125,16 +130,25 @@ struct led_classdev {
125 struct mutex led_access; 130 struct mutex led_access;
126}; 131};
127 132
128extern int of_led_classdev_register(struct device *parent, 133/**
129 struct device_node *np, 134 * led_classdev_register_ext - register a new object of LED class with
130 struct led_classdev *led_cdev); 135 * init data
131#define led_classdev_register(parent, led_cdev) \ 136 * @parent: LED controller device this LED is driven by
132 of_led_classdev_register(parent, NULL, led_cdev) 137 * @led_cdev: the led_classdev structure for this device
133extern int devm_of_led_classdev_register(struct device *parent, 138 * @init_data: the LED class device initialization data
134 struct device_node *np, 139 *
135 struct led_classdev *led_cdev); 140 * Returns: 0 on success or negative error value on failure
136#define devm_led_classdev_register(parent, led_cdev) \ 141 */
137 devm_of_led_classdev_register(parent, NULL, led_cdev) 142extern int led_classdev_register_ext(struct device *parent,
143 struct led_classdev *led_cdev,
144 struct led_init_data *init_data);
145#define led_classdev_register(parent, led_cdev) \
146 led_classdev_register_ext(parent, led_cdev, NULL)
147extern int devm_led_classdev_register_ext(struct device *parent,
148 struct led_classdev *led_cdev,
149 struct led_init_data *init_data);
150#define devm_led_classdev_register(parent, led_cdev) \
151 devm_led_classdev_register_ext(parent, led_cdev, NULL)
138extern void led_classdev_unregister(struct led_classdev *led_cdev); 152extern void led_classdev_unregister(struct led_classdev *led_cdev);
139extern void devm_led_classdev_unregister(struct device *parent, 153extern void devm_led_classdev_unregister(struct device *parent,
140 struct led_classdev *led_cdev); 154 struct led_classdev *led_cdev);