aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafał Miłecki <rafal@milecki.pl>2017-03-06 00:19:44 -0500
committerJacek Anaszewski <jacek.anaszewski@gmail.com>2017-03-08 15:10:01 -0500
commit442c609830e98919faa78b797e9b89c53bab9cbf (patch)
tree80c777f7864a0477d5fd64b4fc24b71f776c0a52
parentab768386116d0d88b944d0ef958adff082c088a8 (diff)
leds: core: add OF variants of LED registering functions
These new functions allow passing an additional device_node argument that will be internally set for created LED device. Thanks to this LED core code and triggers will be able to access DT node for reading extra info. The easiest solution for achieving this was reworking old functions to more generic ones & adding simple defines for API compatibility. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
-rw-r--r--drivers/leds/led-class.c26
-rw-r--r--include/linux/leds.h14
2 files changed, 26 insertions, 14 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index f2b0a80a62b4..b0e2d55acbd6 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -244,11 +244,14 @@ static int led_classdev_next_name(const char *init_name, char *name,
244} 244}
245 245
246/** 246/**
247 * led_classdev_register - register a new object of led_classdev class. 247 * of_led_classdev_register - register a new object of led_classdev class.
248 * @parent: The device to register. 248 *
249 * @parent: parent of LED device
249 * @led_cdev: the led_classdev structure for this device. 250 * @led_cdev: the led_classdev structure for this device.
251 * @np: DT node describing this LED
250 */ 252 */
251int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) 253int of_led_classdev_register(struct device *parent, struct device_node *np,
254 struct led_classdev *led_cdev)
252{ 255{
253 char name[LED_MAX_NAME_SIZE]; 256 char name[LED_MAX_NAME_SIZE];
254 int ret; 257 int ret;
@@ -261,6 +264,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
261 led_cdev, led_cdev->groups, "%s", name); 264 led_cdev, led_cdev->groups, "%s", name);
262 if (IS_ERR(led_cdev->dev)) 265 if (IS_ERR(led_cdev->dev))
263 return PTR_ERR(led_cdev->dev); 266 return PTR_ERR(led_cdev->dev);
267 led_cdev->dev->of_node = np;
264 268
265 if (ret) 269 if (ret)
266 dev_warn(parent, "Led %s renamed to %s due to name collision", 270 dev_warn(parent, "Led %s renamed to %s due to name collision",
@@ -303,7 +307,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
303 307
304 return 0; 308 return 0;
305} 309}
306EXPORT_SYMBOL_GPL(led_classdev_register); 310EXPORT_SYMBOL_GPL(of_led_classdev_register);
307 311
308/** 312/**
309 * led_classdev_unregister - unregisters a object of led_properties class. 313 * led_classdev_unregister - unregisters a object of led_properties class.
@@ -348,12 +352,14 @@ static void devm_led_classdev_release(struct device *dev, void *res)
348} 352}
349 353
350/** 354/**
351 * devm_led_classdev_register - resource managed led_classdev_register() 355 * devm_of_led_classdev_register - resource managed led_classdev_register()
352 * @parent: The device to register. 356 *
357 * @parent: parent of LED device
353 * @led_cdev: the led_classdev structure for this device. 358 * @led_cdev: the led_classdev structure for this device.
354 */ 359 */
355int devm_led_classdev_register(struct device *parent, 360int devm_of_led_classdev_register(struct device *parent,
356 struct led_classdev *led_cdev) 361 struct device_node *np,
362 struct led_classdev *led_cdev)
357{ 363{
358 struct led_classdev **dr; 364 struct led_classdev **dr;
359 int rc; 365 int rc;
@@ -362,7 +368,7 @@ int devm_led_classdev_register(struct device *parent,
362 if (!dr) 368 if (!dr)
363 return -ENOMEM; 369 return -ENOMEM;
364 370
365 rc = led_classdev_register(parent, led_cdev); 371 rc = of_led_classdev_register(parent, np, led_cdev);
366 if (rc) { 372 if (rc) {
367 devres_free(dr); 373 devres_free(dr);
368 return rc; 374 return rc;
@@ -373,7 +379,7 @@ int devm_led_classdev_register(struct device *parent,
373 379
374 return 0; 380 return 0;
375} 381}
376EXPORT_SYMBOL_GPL(devm_led_classdev_register); 382EXPORT_SYMBOL_GPL(devm_of_led_classdev_register);
377 383
378static int devm_led_classdev_match(struct device *dev, void *res, void *data) 384static int devm_led_classdev_match(struct device *dev, void *res, void *data)
379{ 385{
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 38c0bd7ca107..64c56d454f7d 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -122,10 +122,16 @@ struct led_classdev {
122 struct mutex led_access; 122 struct mutex led_access;
123}; 123};
124 124
125extern int led_classdev_register(struct device *parent, 125extern int of_led_classdev_register(struct device *parent,
126 struct led_classdev *led_cdev); 126 struct device_node *np,
127extern int devm_led_classdev_register(struct device *parent, 127 struct led_classdev *led_cdev);
128 struct led_classdev *led_cdev); 128#define led_classdev_register(parent, led_cdev) \
129 of_led_classdev_register(parent, NULL, led_cdev)
130extern int devm_of_led_classdev_register(struct device *parent,
131 struct device_node *np,
132 struct led_classdev *led_cdev);
133#define devm_led_classdev_register(parent, led_cdev) \
134 devm_of_led_classdev_register(parent, NULL, led_cdev)
129extern void led_classdev_unregister(struct led_classdev *led_cdev); 135extern void led_classdev_unregister(struct led_classdev *led_cdev);
130extern void devm_led_classdev_unregister(struct device *parent, 136extern void devm_led_classdev_unregister(struct device *parent,
131 struct led_classdev *led_cdev); 137 struct led_classdev *led_cdev);