leds-lp55xx.rst 6.7 KB

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