led-class-multicolor.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* LED Multicolor class interface
  3. * Copyright (C) 2019-20 Texas Instruments Incorporated - http://www.ti.com/
  4. */
  5. #ifndef _LINUX_MULTICOLOR_LEDS_H_INCLUDED
  6. #define _LINUX_MULTICOLOR_LEDS_H_INCLUDED
  7. #include <linux/leds.h>
  8. #include <dt-bindings/leds/common.h>
  9. struct mc_subled {
  10. unsigned int color_index;
  11. unsigned int brightness;
  12. unsigned int intensity;
  13. unsigned int channel;
  14. };
  15. struct led_classdev_mc {
  16. /* led class device */
  17. struct led_classdev led_cdev;
  18. unsigned int num_colors;
  19. struct mc_subled *subled_info;
  20. };
  21. static inline struct led_classdev_mc *lcdev_to_mccdev(
  22. struct led_classdev *led_cdev)
  23. {
  24. return container_of(led_cdev, struct led_classdev_mc, led_cdev);
  25. }
  26. #if IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR)
  27. /**
  28. * led_classdev_multicolor_register_ext - register a new object of led_classdev
  29. * class with support for multicolor LEDs
  30. * @parent: the multicolor LED to register
  31. * @mcled_cdev: the led_classdev_mc structure for this device
  32. * @init_data: the LED class multicolor device initialization data
  33. *
  34. * Returns: 0 on success or negative error value on failure
  35. */
  36. int led_classdev_multicolor_register_ext(struct device *parent,
  37. struct led_classdev_mc *mcled_cdev,
  38. struct led_init_data *init_data);
  39. static inline int led_classdev_multicolor_register(struct device *parent,
  40. struct led_classdev_mc *mcled_cdev)
  41. {
  42. return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL);
  43. }
  44. /**
  45. * led_classdev_multicolor_unregister - unregisters an object of led_classdev
  46. * class with support for multicolor LEDs
  47. * @mcled_cdev: the multicolor LED to unregister
  48. *
  49. * Unregister a previously registered via led_classdev_multicolor_register
  50. * object
  51. */
  52. void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev);
  53. /* Calculate brightness for the monochrome LED cluster */
  54. int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev,
  55. enum led_brightness brightness);
  56. int devm_led_classdev_multicolor_register_ext(struct device *parent,
  57. struct led_classdev_mc *mcled_cdev,
  58. struct led_init_data *init_data);
  59. static inline int devm_led_classdev_multicolor_register(struct device *parent,
  60. struct led_classdev_mc *mcled_cdev)
  61. {
  62. return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev,
  63. NULL);
  64. }
  65. void devm_led_classdev_multicolor_unregister(struct device *parent,
  66. struct led_classdev_mc *mcled_cdev);
  67. #else
  68. static inline int led_classdev_multicolor_register_ext(struct device *parent,
  69. struct led_classdev_mc *mcled_cdev,
  70. struct led_init_data *init_data)
  71. {
  72. return -EINVAL;
  73. }
  74. static inline int led_classdev_multicolor_register(struct device *parent,
  75. struct led_classdev_mc *mcled_cdev)
  76. {
  77. return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL);
  78. }
  79. static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {};
  80. static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev,
  81. enum led_brightness brightness)
  82. {
  83. return -EINVAL;
  84. }
  85. static inline int devm_led_classdev_multicolor_register_ext(struct device *parent,
  86. struct led_classdev_mc *mcled_cdev,
  87. struct led_init_data *init_data)
  88. {
  89. return -EINVAL;
  90. }
  91. static inline int devm_led_classdev_multicolor_register(struct device *parent,
  92. struct led_classdev_mc *mcled_cdev)
  93. {
  94. return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev,
  95. NULL);
  96. }
  97. static inline void devm_led_classdev_multicolor_unregister(struct device *parent,
  98. struct led_classdev_mc *mcled_cdev)
  99. {};
  100. #endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */
  101. #endif /* _LINUX_MULTICOLOR_LEDS_H_INCLUDED */