leds-lp5521.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. Kernel driver for lp5521
  2. ========================
  3. * National Semiconductor LP5521 led driver chip
  4. * Datasheet: http://www.national.com/pf/LP/LP5521.html
  5. Authors: Mathias Nyman, Yuri Zaporozhets, Samu Onkalo
  6. Contact: Samu Onkalo (samu.p.onkalo-at-nokia.com)
  7. Description
  8. -----------
  9. LP5521 can drive up to 3 channels. Leds can be controlled directly via
  10. the led class control interface. Channels have generic names:
  11. lp5521:channelx, where x is 0 .. 2
  12. All three channels can be also controlled using the engine micro programs.
  13. More details of the instructions can be found from the public data sheet.
  14. Control interface for the engines:
  15. x is 1 .. 3
  16. enginex_mode : disabled, load, run
  17. enginex_load : store program (visible only in engine load mode)
  18. Example (start to blink the channel 2 led):
  19. cd /sys/class/leds/lp5521:channel2/device
  20. echo "load" > engine3_mode
  21. echo "037f4d0003ff6000" > engine3_load
  22. echo "run" > engine3_mode
  23. stop the engine:
  24. echo "disabled" > engine3_mode
  25. sysfs contains a selftest entry.
  26. The test communicates with the chip and checks that
  27. the clock mode is automatically set to the requested one.
  28. Each channel has its own led current settings.
  29. /sys/class/leds/lp5521:channel0/led_current - RW
  30. /sys/class/leds/lp5521:channel0/max_current - RO
  31. Format: 10x mA i.e 10 means 1.0 mA
  32. example platform data:
  33. Note: chan_nr can have values between 0 and 2.
  34. The name of each channel can be configurable.
  35. If the name field is not defined, the default name will be set to 'xxxx:channelN'
  36. (XXXX : pdata->label or i2c client name, N : channel number)
  37. static struct lp5521_led_config lp5521_led_config[] = {
  38. {
  39. .name = "red",
  40. .chan_nr = 0,
  41. .led_current = 50,
  42. .max_current = 130,
  43. }, {
  44. .name = "green",
  45. .chan_nr = 1,
  46. .led_current = 0,
  47. .max_current = 130,
  48. }, {
  49. .name = "blue",
  50. .chan_nr = 2,
  51. .led_current = 0,
  52. .max_current = 130,
  53. }
  54. };
  55. static int lp5521_setup(void)
  56. {
  57. /* setup HW resources */
  58. }
  59. static void lp5521_release(void)
  60. {
  61. /* Release HW resources */
  62. }
  63. static void lp5521_enable(bool state)
  64. {
  65. /* Control of chip enable signal */
  66. }
  67. static struct lp5521_platform_data lp5521_platform_data = {
  68. .led_config = lp5521_led_config,
  69. .num_channels = ARRAY_SIZE(lp5521_led_config),
  70. .clock_mode = LP5521_CLOCK_EXT,
  71. .setup_resources = lp5521_setup,
  72. .release_resources = lp5521_release,
  73. .enable = lp5521_enable,
  74. };
  75. If the current is set to 0 in the platform data, that channel is
  76. disabled and it is not visible in the sysfs.
  77. The 'update_config' : CONFIG register (ADDR 08h)
  78. This value is platform-specific data.
  79. If update_config is not defined, the CONFIG register is set with
  80. 'LP5521_PWRSAVE_EN | LP5521_CP_MODE_AUTO | LP5521_R_TO_BATT'.
  81. (Enable auto-powersave, set charge pump to auto, red to battery)
  82. example of update_config :
  83. #define LP5521_CONFIGS (LP5521_PWM_HF | LP5521_PWRSAVE_EN | \
  84. LP5521_CP_MODE_AUTO | LP5521_R_TO_BATT | \
  85. LP5521_CLK_INT)
  86. static struct lp5521_platform_data lp5521_pdata = {
  87. .led_config = lp5521_led_config,
  88. .num_channels = ARRAY_SIZE(lp5521_led_config),
  89. .clock_mode = LP5521_CLOCK_INT,
  90. .update_config = LP5521_CONFIGS,
  91. };
  92. LED patterns : LP5521 has autonomous operation without external control.
  93. Pattern data can be defined in the platform data.
  94. example of led pattern data :
  95. /* RGB(50,5,0) 500ms on, 500ms off, infinite loop */
  96. static u8 pattern_red[] = {
  97. 0x40, 0x32, 0x60, 0x00, 0x40, 0x00, 0x60, 0x00,
  98. };
  99. static u8 pattern_green[] = {
  100. 0x40, 0x05, 0x60, 0x00, 0x40, 0x00, 0x60, 0x00,
  101. };
  102. static struct lp5521_led_pattern board_led_patterns[] = {
  103. {
  104. .r = pattern_red,
  105. .g = pattern_green,
  106. .size_r = ARRAY_SIZE(pattern_red),
  107. .size_g = ARRAY_SIZE(pattern_green),
  108. },
  109. };
  110. static struct lp5521_platform_data lp5521_platform_data = {
  111. .led_config = lp5521_led_config,
  112. .num_channels = ARRAY_SIZE(lp5521_led_config),
  113. .clock_mode = LP5521_CLOCK_EXT,
  114. .patterns = board_led_patterns,
  115. .num_patterns = ARRAY_SIZE(board_led_patterns),
  116. };
  117. Then predefined led pattern(s) can be executed via the sysfs.
  118. To start the pattern #1,
  119. # echo 1 > /sys/bus/i2c/devices/xxxx/led_pattern
  120. (xxxx : i2c bus & slave address)
  121. To end the pattern,
  122. # echo 0 > /sys/bus/i2c/devices/xxxx/led_pattern