leds-class.txt 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. LED handling under Linux
  2. ========================
  3. If you're reading this and thinking about keyboard leds, these are
  4. handled by the input subsystem and the led class is *not* needed.
  5. In its simplest form, the LED class just allows control of LEDs from
  6. userspace. LEDs appear in /sys/class/leds/. The brightness file will
  7. set the brightness of the LED (taking a value 0-255). Most LEDs don't
  8. have hardware brightness support so will just be turned on for non-zero
  9. brightness settings.
  10. The class also introduces the optional concept of an LED trigger. A trigger
  11. is a kernel based source of led events. Triggers can either be simple or
  12. complex. A simple trigger isn't configurable and is designed to slot into
  13. existing subsystems with minimal additional code. Examples are the ide-disk,
  14. nand-disk and sharpsl-charge triggers. With led triggers disabled, the code
  15. optimises away.
  16. Complex triggers whilst available to all LEDs have LED specific
  17. parameters and work on a per LED basis. The timer trigger is an example.
  18. The timer trigger will periodically change the LED brightness between
  19. LED_OFF and the current brightness setting. The "on" and "off" time can
  20. be specified via /sys/class/leds/<device>/delay_{on,off} in milliseconds.
  21. You can change the brightness value of a LED independently of the timer
  22. trigger. However, if you set the brightness value to LED_OFF it will
  23. also disable the timer trigger.
  24. You can change triggers in a similar manner to the way an IO scheduler
  25. is chosen (via /sys/class/leds/<device>/trigger). Trigger specific
  26. parameters can appear in /sys/class/leds/<device> once a given trigger is
  27. selected.
  28. Design Philosophy
  29. =================
  30. The underlying design philosophy is simplicity. LEDs are simple devices
  31. and the aim is to keep a small amount of code giving as much functionality
  32. as possible. Please keep this in mind when suggesting enhancements.
  33. LED Device Naming
  34. =================
  35. Is currently of the form:
  36. "devicename:colour:function"
  37. There have been calls for LED properties such as colour to be exported as
  38. individual led class attributes. As a solution which doesn't incur as much
  39. overhead, I suggest these become part of the device name. The naming scheme
  40. above leaves scope for further attributes should they be needed. If sections
  41. of the name don't apply, just leave that section blank.
  42. Hardware accelerated blink of LEDs
  43. ==================================
  44. Some LEDs can be programmed to blink without any CPU interaction. To
  45. support this feature, a LED driver can optionally implement the
  46. blink_set() function (see <linux/leds.h>). If implemented, triggers can
  47. attempt to use it before falling back to software timers. The blink_set()
  48. function should return 0 if the blink setting is supported, or -EINVAL
  49. otherwise, which means that LED blinking will be handled by software.
  50. The blink_set() function should choose a user friendly blinking
  51. value if it is called with *delay_on==0 && *delay_off==0 parameters. In
  52. this case the driver should give back the chosen value through delay_on
  53. and delay_off parameters to the leds subsystem.
  54. Setting the brightness to zero with brightness_set() callback function
  55. should completely turn off the LED and cancel the previously programmed
  56. hardware blinking function, if any.
  57. Known Issues
  58. ============
  59. The LED Trigger core cannot be a module as the simple trigger functions
  60. would cause nightmare dependency issues. I see this as a minor issue
  61. compared to the benefits the simple trigger functionality brings. The
  62. rest of the LED subsystem can be modular.
  63. Future Development
  64. ==================
  65. At the moment, a trigger can't be created specifically for a single LED.
  66. There are a number of cases where a trigger might only be mappable to a
  67. particular LED (ACPI?). The addition of triggers provided by the LED driver
  68. should cover this option and be possible to add without breaking the
  69. current interface.