804-v6.5-01-leds-add-APIs-for-LEDs-hw-control.patch 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From ed554d3f945179c5b159bddfad7be34b403fe11a Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Mon, 29 May 2023 18:32:31 +0200
  4. Subject: [PATCH 01/13] leds: add APIs for LEDs hw control
  5. Add an option to permit LED driver to declare support for a specific
  6. trigger to use hw control and setup the LED to blink based on specific
  7. provided modes.
  8. Add APIs for LEDs hw control. These functions will be used to activate
  9. hardware control where a LED will use the provided flags, from an
  10. unique defined supported trigger, to setup the LED to be driven by
  11. hardware.
  12. Add hw_control_is_supported() to ask the LED driver if the requested
  13. mode by the trigger are supported and the LED can be setup to follow
  14. the requested modes.
  15. Deactivate hardware blink control by setting brightness to LED_OFF via
  16. the brightness_set() callback.
  17. Signed-off-by: Christian Marangi <[email protected]>
  18. Reviewed-by: Andrew Lunn <[email protected]>
  19. Signed-off-by: David S. Miller <[email protected]>
  20. ---
  21. include/linux/leds.h | 37 +++++++++++++++++++++++++++++++++++++
  22. 1 file changed, 37 insertions(+)
  23. --- a/include/linux/leds.h
  24. +++ b/include/linux/leds.h
  25. @@ -164,6 +164,43 @@ struct led_classdev {
  26. /* LEDs that have private triggers have this set */
  27. struct led_hw_trigger_type *trigger_type;
  28. +
  29. + /* Unique trigger name supported by LED set in hw control mode */
  30. + const char *hw_control_trigger;
  31. + /*
  32. + * Check if the LED driver supports the requested mode provided by the
  33. + * defined supported trigger to setup the LED to hw control mode.
  34. + *
  35. + * Return 0 on success. Return -EOPNOTSUPP when the passed flags are not
  36. + * supported and software fallback needs to be used.
  37. + * Return a negative error number on any other case for check fail due
  38. + * to various reason like device not ready or timeouts.
  39. + */
  40. + int (*hw_control_is_supported)(struct led_classdev *led_cdev,
  41. + unsigned long flags);
  42. + /*
  43. + * Activate hardware control, LED driver will use the provided flags
  44. + * from the supported trigger and setup the LED to be driven by hardware
  45. + * following the requested mode from the trigger flags.
  46. + * Deactivate hardware blink control by setting brightness to LED_OFF via
  47. + * the brightness_set() callback.
  48. + *
  49. + * Return 0 on success, a negative error number on flags apply fail.
  50. + */
  51. + int (*hw_control_set)(struct led_classdev *led_cdev,
  52. + unsigned long flags);
  53. + /*
  54. + * Get from the LED driver the current mode that the LED is set in hw
  55. + * control mode and put them in flags.
  56. + * Trigger can use this to get the initial state of a LED already set in
  57. + * hardware blink control.
  58. + *
  59. + * Return 0 on success, a negative error number on failing parsing the
  60. + * initial mode. Error from this function is NOT FATAL as the device
  61. + * may be in a not supported initial state by the attached LED trigger.
  62. + */
  63. + int (*hw_control_get)(struct led_classdev *led_cdev,
  64. + unsigned long *flags);
  65. #endif
  66. #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED