Back to home page

OSCL-LXR

 
 

    


0001 =================================================
0002 LP5521/LP5523/LP55231/LP5562/LP8501 Common Driver
0003 =================================================
0004 
0005 Authors: Milo(Woogyom) Kim <milo.kim@ti.com>
0006 
0007 Description
0008 -----------
0009 LP5521, LP5523/55231, LP5562 and LP8501 have common features as below.
0010 
0011   Register access via the I2C
0012   Device initialization/deinitialization
0013   Create LED class devices for multiple output channels
0014   Device attributes for user-space interface
0015   Program memory for running LED patterns
0016 
0017 The LP55xx common driver provides these features using exported functions.
0018 
0019   lp55xx_init_device() / lp55xx_deinit_device()
0020   lp55xx_register_leds() / lp55xx_unregister_leds()
0021   lp55xx_regsister_sysfs() / lp55xx_unregister_sysfs()
0022 
0023 ( Driver Structure Data )
0024 
0025 In lp55xx common driver, two different data structure is used.
0026 
0027 * lp55xx_led
0028     control multi output LED channels such as led current, channel index.
0029 * lp55xx_chip
0030     general chip control such like the I2C and platform data.
0031 
0032 For example, LP5521 has maximum 3 LED channels.
0033 LP5523/55231 has 9 output channels::
0034 
0035   lp55xx_chip for LP5521 ... lp55xx_led #1
0036                              lp55xx_led #2
0037                              lp55xx_led #3
0038 
0039   lp55xx_chip for LP5523 ... lp55xx_led #1
0040                              lp55xx_led #2
0041                                    .
0042                                    .
0043                              lp55xx_led #9
0044 
0045 ( Chip Dependent Code )
0046 
0047 To support device specific configurations, special structure
0048 'lpxx_device_config' is used.
0049 
0050   - Maximum number of channels
0051   - Reset command, chip enable command
0052   - Chip specific initialization
0053   - Brightness control register access
0054   - Setting LED output current
0055   - Program memory address access for running patterns
0056   - Additional device specific attributes
0057 
0058 ( Firmware Interface )
0059 
0060 LP55xx family devices have the internal program memory for running
0061 various LED patterns.
0062 
0063 This pattern data is saved as a file in the user-land or
0064 hex byte string is written into the memory through the I2C.
0065 
0066 LP55xx common driver supports the firmware interface.
0067 
0068 LP55xx chips have three program engines.
0069 
0070 To load and run the pattern, the programming sequence is following.
0071 
0072   (1) Select an engine number (1/2/3)
0073   (2) Mode change to load
0074   (3) Write pattern data into selected area
0075   (4) Mode change to run
0076 
0077 The LP55xx common driver provides simple interfaces as below.
0078 
0079 select_engine:
0080         Select which engine is used for running program
0081 run_engine:
0082         Start program which is loaded via the firmware interface
0083 firmware:
0084         Load program data
0085 
0086 In case of LP5523, one more command is required, 'enginex_leds'.
0087 It is used for selecting LED output(s) at each engine number.
0088 In more details, please refer to 'leds-lp5523.txt'.
0089 
0090 For example, run blinking pattern in engine #1 of LP5521::
0091 
0092         echo 1 > /sys/bus/i2c/devices/xxxx/select_engine
0093         echo 1 > /sys/class/firmware/lp5521/loading
0094         echo "4000600040FF6000" > /sys/class/firmware/lp5521/data
0095         echo 0 > /sys/class/firmware/lp5521/loading
0096         echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
0097 
0098 For example, run blinking pattern in engine #3 of LP55231
0099 
0100 Two LEDs are configured as pattern output channels::
0101 
0102         echo 3 > /sys/bus/i2c/devices/xxxx/select_engine
0103         echo 1 > /sys/class/firmware/lp55231/loading
0104         echo "9d0740ff7e0040007e00a0010000" > /sys/class/firmware/lp55231/data
0105         echo 0 > /sys/class/firmware/lp55231/loading
0106         echo "000001100" > /sys/bus/i2c/devices/xxxx/engine3_leds
0107         echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
0108 
0109 To start blinking patterns in engine #2 and #3 simultaneously::
0110 
0111         for idx in 2 3
0112         do
0113         echo $idx > /sys/class/leds/red/device/select_engine
0114         sleep 0.1
0115         echo 1 > /sys/class/firmware/lp5521/loading
0116         echo "4000600040FF6000" > /sys/class/firmware/lp5521/data
0117         echo 0 > /sys/class/firmware/lp5521/loading
0118         done
0119         echo 1 > /sys/class/leds/red/device/run_engine
0120 
0121 Here is another example for LP5523.
0122 
0123 Full LED strings are selected by 'engine2_leds'::
0124 
0125         echo 2 > /sys/bus/i2c/devices/xxxx/select_engine
0126         echo 1 > /sys/class/firmware/lp5523/loading
0127         echo "9d80400004ff05ff437f0000" > /sys/class/firmware/lp5523/data
0128         echo 0 > /sys/class/firmware/lp5523/loading
0129         echo "111111111" > /sys/bus/i2c/devices/xxxx/engine2_leds
0130         echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
0131 
0132 As soon as 'loading' is set to 0, registered callback is called.
0133 Inside the callback, the selected engine is loaded and memory is updated.
0134 To run programmed pattern, 'run_engine' attribute should be enabled.
0135 
0136 The pattern sequence of LP8501 is similar to LP5523.
0137 
0138 However pattern data is specific.
0139 
0140 Ex 1) Engine 1 is used::
0141 
0142         echo 1 > /sys/bus/i2c/devices/xxxx/select_engine
0143         echo 1 > /sys/class/firmware/lp8501/loading
0144         echo "9d0140ff7e0040007e00a001c000" > /sys/class/firmware/lp8501/data
0145         echo 0 > /sys/class/firmware/lp8501/loading
0146         echo 1 > /sys/bus/i2c/devices/xxxx/run_engine
0147 
0148 Ex 2) Engine 2 and 3 are used at the same time::
0149 
0150         echo 2 > /sys/bus/i2c/devices/xxxx/select_engine
0151         sleep 1
0152         echo 1 > /sys/class/firmware/lp8501/loading
0153         echo "9d0140ff7e0040007e00a001c000" > /sys/class/firmware/lp8501/data
0154         echo 0 > /sys/class/firmware/lp8501/loading
0155         sleep 1
0156         echo 3 > /sys/bus/i2c/devices/xxxx/select_engine
0157         sleep 1
0158         echo 1 > /sys/class/firmware/lp8501/loading
0159         echo "9d0340ff7e0040007e00a001c000" > /sys/class/firmware/lp8501/data
0160         echo 0 > /sys/class/firmware/lp8501/loading
0161         sleep 1
0162         echo 1 > /sys/class/leds/d1/device/run_engine
0163 
0164 ( 'run_engine' and 'firmware_cb' )
0165 
0166 The sequence of running the program data is common.
0167 
0168 But each device has own specific register addresses for commands.
0169 
0170 To support this, 'run_engine' and 'firmware_cb' are configurable in each driver.
0171 
0172 run_engine:
0173         Control the selected engine
0174 firmware_cb:
0175         The callback function after loading the firmware is done.
0176 
0177         Chip specific commands for loading and updating program memory.
0178 
0179 ( Predefined pattern data )
0180 
0181 Without the firmware interface, LP55xx driver provides another method for
0182 loading a LED pattern. That is 'predefined' pattern.
0183 
0184 A predefined pattern is defined in the platform data and load it(or them)
0185 via the sysfs if needed.
0186 
0187 To use the predefined pattern concept, 'patterns' and 'num_patterns' should be
0188 configured.
0189 
0190 Example of predefined pattern data::
0191 
0192   /* mode_1: blinking data */
0193   static const u8 mode_1[] = {
0194                 0x40, 0x00, 0x60, 0x00, 0x40, 0xFF, 0x60, 0x00,
0195                 };
0196 
0197   /* mode_2: always on */
0198   static const u8 mode_2[] = { 0x40, 0xFF, };
0199 
0200   struct lp55xx_predef_pattern board_led_patterns[] = {
0201         {
0202                 .r = mode_1,
0203                 .size_r = ARRAY_SIZE(mode_1),
0204         },
0205         {
0206                 .b = mode_2,
0207                 .size_b = ARRAY_SIZE(mode_2),
0208         },
0209   }
0210 
0211   struct lp55xx_platform_data lp5562_pdata = {
0212   ...
0213         .patterns      = board_led_patterns,
0214         .num_patterns  = ARRAY_SIZE(board_led_patterns),
0215   };
0216 
0217 Then, mode_1 and mode_2 can be run via through the sysfs::
0218 
0219   echo 1 > /sys/bus/i2c/devices/xxxx/led_pattern    # red blinking LED pattern
0220   echo 2 > /sys/bus/i2c/devices/xxxx/led_pattern    # blue LED always on
0221 
0222 To stop running pattern::
0223 
0224   echo 0 > /sys/bus/i2c/devices/xxxx/led_pattern