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