085-0004-leds-core-add-OF-variants-of-LED-registering-functio.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. These new functions allow passing an additional device_node argument
  8. that will be internally set for created LED device. Thanks to this LED
  9. core code and triggers will be able to access DT node for reading extra
  10. info.
  11. The easiest solution for achieving this was reworking old functions to
  12. more generic ones & adding simple defines for API compatibility.
  13. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  14. Acked-by: Pavel Machek <pavel@ucw.cz>
  15. Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
  16. ---
  17. drivers/leds/led-class.c | 26 ++++++++++++++++----------
  18. include/linux/leds.h | 14 ++++++++++----
  19. 2 files changed, 26 insertions(+), 14 deletions(-)
  20. --- a/drivers/leds/led-class.c
  21. +++ b/drivers/leds/led-class.c
  22. @@ -181,11 +181,14 @@ static int led_classdev_next_name(const
  23. }
  24. /**
  25. - * led_classdev_register - register a new object of led_classdev class.
  26. - * @parent: The device to register.
  27. + * of_led_classdev_register - register a new object of led_classdev class.
  28. + *
  29. + * @parent: parent of LED device
  30. * @led_cdev: the led_classdev structure for this device.
  31. + * @np: DT node describing this LED
  32. */
  33. -int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
  34. +int of_led_classdev_register(struct device *parent, struct device_node *np,
  35. + struct led_classdev *led_cdev)
  36. {
  37. char name[64];
  38. int ret;
  39. @@ -198,6 +201,7 @@ int led_classdev_register(struct device
  40. led_cdev, led_cdev->groups, "%s", name);
  41. if (IS_ERR(led_cdev->dev))
  42. return PTR_ERR(led_cdev->dev);
  43. + led_cdev->dev->of_node = np;
  44. if (ret)
  45. dev_warn(parent, "Led %s renamed to %s due to name collision",
  46. @@ -230,7 +234,7 @@ int led_classdev_register(struct device
  47. return 0;
  48. }
  49. -EXPORT_SYMBOL_GPL(led_classdev_register);
  50. +EXPORT_SYMBOL_GPL(of_led_classdev_register);
  51. /**
  52. * led_classdev_unregister - unregisters a object of led_properties class.
  53. @@ -269,12 +273,14 @@ static void devm_led_classdev_release(st
  54. }
  55. /**
  56. - * devm_led_classdev_register - resource managed led_classdev_register()
  57. - * @parent: The device to register.
  58. + * devm_of_led_classdev_register - resource managed led_classdev_register()
  59. + *
  60. + * @parent: parent of LED device
  61. * @led_cdev: the led_classdev structure for this device.
  62. */
  63. -int devm_led_classdev_register(struct device *parent,
  64. - struct led_classdev *led_cdev)
  65. +int devm_of_led_classdev_register(struct device *parent,
  66. + struct device_node *np,
  67. + struct led_classdev *led_cdev)
  68. {
  69. struct led_classdev **dr;
  70. int rc;
  71. @@ -283,7 +289,7 @@ int devm_led_classdev_register(struct de
  72. if (!dr)
  73. return -ENOMEM;
  74. - rc = led_classdev_register(parent, led_cdev);
  75. + rc = of_led_classdev_register(parent, np, led_cdev);
  76. if (rc) {
  77. devres_free(dr);
  78. return rc;
  79. @@ -294,7 +300,7 @@ int devm_led_classdev_register(struct de
  80. return 0;
  81. }
  82. -EXPORT_SYMBOL_GPL(devm_led_classdev_register);
  83. +EXPORT_SYMBOL_GPL(devm_of_led_classdev_register);
  84. static int devm_led_classdev_match(struct device *dev, void *res, void *data)
  85. {
  86. --- a/include/linux/leds.h
  87. +++ b/include/linux/leds.h
  88. @@ -103,10 +103,16 @@ struct led_classdev {
  89. struct mutex led_access;
  90. };
  91. -extern int led_classdev_register(struct device *parent,
  92. - struct led_classdev *led_cdev);
  93. -extern int devm_led_classdev_register(struct device *parent,
  94. - struct led_classdev *led_cdev);
  95. +extern int of_led_classdev_register(struct device *parent,
  96. + struct device_node *np,
  97. + struct led_classdev *led_cdev);
  98. +#define led_classdev_register(parent, led_cdev) \
  99. + of_led_classdev_register(parent, NULL, led_cdev)
  100. +extern int devm_of_led_classdev_register(struct device *parent,
  101. + struct device_node *np,
  102. + struct led_classdev *led_cdev);
  103. +#define devm_led_classdev_register(parent, led_cdev) \
  104. + devm_of_led_classdev_register(parent, NULL, led_cdev)
  105. extern void led_classdev_unregister(struct led_classdev *led_cdev);
  106. extern void devm_led_classdev_unregister(struct device *parent,
  107. struct led_classdev *led_cdev);