leds-lp55xx.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. LP5521/LP5523/LP55231/LP5562/LP8501 Common Driver
  2. =================================================
  3. Authors: Milo(Woogyom) Kim <milo.kim@ti.com>
  4. Description
  5. -----------
  6. LP5521, LP5523/55231, LP5562 and LP8501 have common features as below.
  7. Register access via the I2C
  8. Device initialization/deinitialization
  9. Create LED class devices for multiple output channels
  10. Device attributes for user-space interface
  11. Program memory for running LED patterns
  12. The LP55xx common driver provides these features using exported functions.
  13. lp55xx_init_device() / lp55xx_deinit_device()
  14. lp55xx_register_leds() / lp55xx_unregister_leds()
  15. lp55xx_regsister_sysfs() / lp55xx_unregister_sysfs()
  16. ( Driver Structure Data )
  17. In lp55xx common driver, two different data structure is used.
  18. o lp55xx_led
  19. control multi output LED channels such as led current, channel index.
  20. o lp55xx_chip
  21. general chip control such like the I2C and platform data.
  22. For example, LP5521 has maximum 3 LED channels.
  23. LP5523/55231 has 9 output channels.
  24. lp55xx_chip for LP5521 ... lp55xx_led #1
  25. lp55xx_led #2
  26. lp55xx_led #3
  27. lp55xx_chip for LP5523 ... lp55xx_led #1
  28. lp55xx_led #2
  29. .
  30. .
  31. lp55xx_led #9
  32. ( Chip Dependent Code )
  33. To support device specific configurations, special structure
  34. 'lpxx_device_config' is used.
  35. Maximum number of channels
  36. Reset command, chip enable command
  37. Chip specific initialization
  38. Brightness control register access
  39. Setting LED output current
  40. Program memory address access for running patterns
  41. Additional device specific attributes
  42. ( Firmware Interface )
  43. LP55xx family devices have the internal program memory for running
  44. various LED patterns.
  45. This pattern data is saved as a file in the user-land or
  46. hex byte string is written into the memory through the I2C.
  47. LP55xx common driver supports the firmware interface.
  48. LP55xx chips have three program engines.
  49. To load and run the pattern, the programming sequence is following.
  50. (1) Select an engine number (1/2/3)
  51. (2) Mode change to load
  52. (3) Write pattern data into selected area
  53. (4) Mode change to run
  54. The LP55xx common driver provides simple interfaces as below.
  55. select_engine : Select which engine is used for running program
  56. run_engine : Start program which is loaded via the firmware interface
  57. firmware : Load program data
  58. In case of LP5523, one more command is required, 'enginex_leds'.
  59. It is used for selecting LED output(s) at each engine number.
  60. In more details, please refer to 'leds-lp5523.txt'.
  61. For example, run blinking pattern in engine #1 of LP5521
  62. echo 1 > /sys/bus/i2c/devices/xxxx/select_engine
  63. echo 1 > /sys/class/firmware/lp5521/loading
  64. echo "4000600040FF6000" > /sys/class/firmware/lp5521/data
  65. echo 0 > /sys/class/firmware/lp5521/loading
  66. echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
  67. For example, run blinking pattern in engine #3 of LP55231
  68. Two LEDs are configured as pattern output channels.
  69. echo 3 > /sys/bus/i2c/devices/xxxx/select_engine
  70. echo 1 > /sys/class/firmware/lp55231/loading
  71. echo "9d0740ff7e0040007e00a0010000" > /sys/class/firmware/lp55231/data
  72. echo 0 > /sys/class/firmware/lp55231/loading
  73. echo "000001100" > /sys/bus/i2c/devices/xxxx/engine3_leds
  74. echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
  75. To start blinking patterns in engine #2 and #3 simultaneously,
  76. for idx in 2 3
  77. do
  78. echo $idx > /sys/class/leds/red/device/select_engine
  79. sleep 0.1
  80. echo 1 > /sys/class/firmware/lp5521/loading
  81. echo "4000600040FF6000" > /sys/class/firmware/lp5521/data
  82. echo 0 > /sys/class/firmware/lp5521/loading
  83. done
  84. echo 1 > /sys/class/leds/red/device/run_engine
  85. Here is another example for LP5523.
  86. Full LED strings are selected by 'engine2_leds'.
  87. echo 2 > /sys/bus/i2c/devices/xxxx/select_engine
  88. echo 1 > /sys/class/firmware/lp5523/loading
  89. echo "9d80400004ff05ff437f0000" > /sys/class/firmware/lp5523/data
  90. echo 0 > /sys/class/firmware/lp5523/loading
  91. echo "111111111" > /sys/bus/i2c/devices/xxxx/engine2_leds
  92. echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
  93. As soon as 'loading' is set to 0, registered callback is called.
  94. Inside the callback, the selected engine is loaded and memory is updated.
  95. To run programmed pattern, 'run_engine' attribute should be enabled.
  96. The pattern sqeuence of LP8501 is similar to LP5523.
  97. However pattern data is specific.
  98. Ex 1) Engine 1 is used
  99. echo 1 > /sys/bus/i2c/devices/xxxx/select_engine
  100. echo 1 > /sys/class/firmware/lp8501/loading
  101. echo "9d0140ff7e0040007e00a001c000" > /sys/class/firmware/lp8501/data
  102. echo 0 > /sys/class/firmware/lp8501/loading
  103. echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
  104. Ex 2) Engine 2 and 3 are used at the same time
  105. echo 2 > /sys/bus/i2c/devices/xxxx/select_engine
  106. sleep 1
  107. echo 1 > /sys/class/firmware/lp8501/loading
  108. echo "9d0140ff7e0040007e00a001c000" > /sys/class/firmware/lp8501/data
  109. echo 0 > /sys/class/firmware/lp8501/loading
  110. sleep 1
  111. echo 3 > /sys/bus/i2c/devices/xxxx/select_engine
  112. sleep 1
  113. echo 1 > /sys/class/firmware/lp8501/loading
  114. echo "9d0340ff7e0040007e00a001c000" > /sys/class/firmware/lp8501/data
  115. echo 0 > /sys/class/firmware/lp8501/loading
  116. sleep 1
  117. echo 1 > /sys/class/leds/d1/device/run_engine
  118. ( 'run_engine' and 'firmware_cb' )
  119. The sequence of running the program data is common.
  120. But each device has own specific register addresses for commands.
  121. To support this, 'run_engine' and 'firmware_cb' are configurable in each driver.
  122. run_engine : Control the selected engine
  123. firmware_cb : The callback function after loading the firmware is done.
  124. Chip specific commands for loading and updating program memory.
  125. ( Predefined pattern data )
  126. Without the firmware interface, LP55xx driver provides another method for
  127. loading a LED pattern. That is 'predefined' pattern.
  128. A predefined pattern is defined in the platform data and load it(or them)
  129. via the sysfs if needed.
  130. To use the predefined pattern concept, 'patterns' and 'num_patterns' should be
  131. configured.
  132. Example of predefined pattern data:
  133. /* mode_1: blinking data */
  134. static const u8 mode_1[] = {
  135. 0x40, 0x00, 0x60, 0x00, 0x40, 0xFF, 0x60, 0x00,
  136. };
  137. /* mode_2: always on */
  138. static const u8 mode_2[] = { 0x40, 0xFF, };
  139. struct lp55xx_predef_pattern board_led_patterns[] = {
  140. {
  141. .r = mode_1,
  142. .size_r = ARRAY_SIZE(mode_1),
  143. },
  144. {
  145. .b = mode_2,
  146. .size_b = ARRAY_SIZE(mode_2),
  147. },
  148. }
  149. struct lp55xx_platform_data lp5562_pdata = {
  150. ...
  151. .patterns = board_led_patterns,
  152. .num_patterns = ARRAY_SIZE(board_led_patterns),
  153. };
  154. Then, mode_1 and mode_2 can be run via through the sysfs.
  155. echo 1 > /sys/bus/i2c/devices/xxxx/led_pattern # red blinking LED pattern
  156. echo 2 > /sys/bus/i2c/devices/xxxx/led_pattern # blue LED always on
  157. To stop running pattern,
  158. echo 0 > /sys/bus/i2c/devices/xxxx/led_pattern