[RK3288][Android6.0] Documentation/leds/leds-lp55xx.txt

Platform: RK3288
OS: Android 6.0
Kernel: 3.10.92

LP5521/LP5523/LP55231 Common Driver

Authors: Milo(Woogyom) Kim [email protected]

Description

LP5521, LP5523/55231 and LP5562 have common features as below.
LP5521, LP5523/55231以及LP5562有如下共同特性,所以被单独拎出来放到通用驱动里。

Register access via the I2C
Device initialization/deinitialization
Create LED class devices for multiple output channels
Device attributes for user-space interface
Program memory for running LED patterns

通过I2C访问寄存器
设备初始化
为多个channel差功能键LED class设备
在用户空间提供设备属性接口供访问控制
内部有可编程的memory用于跑不同的LED patterns.

The LP55xx common driver provides these features using exported functions.
The LP55xx通用驱动通过如下接口来实现上面说的功能。
lp55xx_init_device() / lp55xx_deinit_device()
lp55xx_register_leds() / lp55xx_unregister_leds()
lp55xx_regsister_sysfs() / lp55xx_unregister_sysfs()

( Driver Structure Data )
驱动数据结构
In lp55xx common driver, two different data structure is used.
驱动中两种不同的数据结构被使用。
o lp55xx_led
control multi output LED channels such as led current, channel index.
lp55xx_led用于控制多个LED通道里的参数,如LED电流。
o lp55xx_chip
general chip control such like the I2C and platform data.
lp55xx_chip结构用于保存像I2C和Platform data等数据。

For example, LP5521 has maximum 3 LED channels.
LP5523/55231 has 9 output channels.

如下是不同种类IC的配置,比如LP5521有三个通道,LP5523/LP55231有9个通道。
lp55xx_chip for LP5521 … lp55xx_led #1
lp55xx_led #2
lp55xx_led #3

lp55xx_chip for LP5523 … lp55xx_led #1
lp55xx_led #2
.
.
lp55xx_led #9

( Chip Dependent Code )
芯片独立部分
To support device specific configurations, special structure
‘lpxx_device_config’ is used.
各个芯片寄存器配置等是不一样的,驱动使用lpxx_device_config结构来支持此功能。

Maximum number of channels
Reset command, chip enable command
Chip specific initialization
Brightness control register access
Setting LED output current
Program memory address access for running patterns
Additional device specific attributes

最大通道数
复位命令,芯片使能命令
芯片级初始化
亮度控制寄存器访问控制
LED输出电流设置
Program memory地址访问控制
其他设备相关属性

( Firmware Interface )
固件接口

LP55xx family devices have the internal program memory for running
various LED patterns.
This pattern data is saved as a file in the user-land or
hex byte string is written into the memory through the I2C.
LP55xx common driver supports the firmware interface.
LP55xx系列芯片内部有一块memory用于执行不同LED patterns。
Pattrens可以以文件形式保存在操作系统上,或者直接以string的形式通过I2C写到memory中。
LP55xx通用驱动提供了固件接口用于写入Patterns.

LP55xx chips have three program engines.
To load and run the pattern, the programming sequence is following.
(1) Select an engine number (1/2/3)
(2) Mode change to load
(3) Write pattern data into selected area
(4) Mode change to run

LP55xx芯片有三个engines,操作顺序如下:
1. 选择其中一个engine
2. 切换其到load模式
3. 写入pattern data到选择区域
4. 切换到run模式

The LP55xx common driver provides simple interfaces as below.
select_engine : Select which engine is used for running program
run_engine : Start program which is loaded via the firmware interface
firmware : Load program data
因此,LP55xx驱动提供了"选择engine, 运行engine以及写入pattern data"三个接口。

LP5521闪烁操作接口例子如下:
For example, run blinking pattern in engine #1 of LP5521
echo 1 > /sys/bus/i2c/devices/xxxx/select_engine
echo 1 > /sys/class/firmware/lp5521/loading
echo “4000600040FF6000” > /sys/class/firmware/lp5521/data
echo 0 > /sys/class/firmware/lp5521/loading
echo 1 > /sys/bus/i2c/devices/xxxx/run_engine

LP55231闪烁操作接口例子如下:
For example, run blinking pattern in engine #3 of LP55231
echo 3 > /sys/bus/i2c/devices/xxxx/select_engine
echo 1 > /sys/class/firmware/lp55231/loading
echo “9d0740ff7e0040007e00a0010000” > /sys/class/firmware/lp55231/data
echo 0 > /sys/class/firmware/lp55231/loading
echo 1 > /sys/bus/i2c/devices/xxxx/run_engine

如果要同时操作engine2和engine3,可以使用脚本实现。
To start blinking patterns in engine #2 and #3 simultaneously,
for idx in 2 3
do
echo $idx > /sys/class/leds/red/device/select_engine
sleep 0.1
echo 1 > /sys/class/firmware/lp5521/loading
echo “4000600040FF6000” > /sys/class/firmware/lp5521/data
echo 0 > /sys/class/firmware/lp5521/loading
done
echo 1 > /sys/class/leds/red/device/run_engine

Here is another example for LP5523.
echo 2 > /sys/bus/i2c/devices/xxxx/select_engine
echo 1 > /sys/class/firmware/lp5523/loading
echo “9d80400004ff05ff437f0000” > /sys/class/firmware/lp5523/data
echo 0 > /sys/class/firmware/lp5523/loading
echo 1 > /sys/bus/i2c/devices/xxxx/run_engine

As soon as ‘loading’ is set to 0, registered callback is called.
Inside the callback, the selected engine is loaded and memory is updated.
To run programmed pattern, ‘run_engine’ attribute should be enabled. ( ‘run_engine’ and ‘firmware_cb’ ) The sequence of running the program data is common. But each device has own specific register addresses for commands. To support this, ‘run_engine’ and ‘firmware_cb’ are configurable in each driver. run_engine : Control the selected engine firmware_cb : The callback function after loading the firmware is done. Chip specific commands for loading and updating program memory.
只要loading文件被设置成0, 注册的回调接口就会被调用。
此回调函数中完成engine的选择以及memory的更新。
如果要运行pattern,run_engine文件要被设置成enabled.








各个芯片的运行和写pattern data的流程是一样的,但由于它们的寄存器不一样,因此驱动提供了"run_engine"和"firmware_cb"两个回调接口。

( Predefined pattern data )
预定义pattern data
Without the firmware interface, LP55xx driver provides another method for
loading a LED pattern. That is ‘predefined’ pattern.
A predefined pattern is defined in the platform data and load it(or them)
via the sysfs if needed.
To use the predefined pattern concept, ‘patterns’ and ‘num_patterns’ should be configured.
如果没有firmware接口,LP55xx驱动也提供了另一种方法来写LED pattern。
预定义pattern data被定义在platform data然后通过sysfs接口执行。
如果要用此功能,那么“pattern”和“num_patterns”需要配置。
如下是例子:

Example of predefined pattern data:

/* mode_1: blinking data */
static const u8 mode_1[] = {
0x40, 0x00, 0x60, 0x00, 0x40, 0xFF, 0x60, 0x00,
};

/* mode_2: always on */
static const u8 mode_2[] = { 0x40, 0xFF, };

struct lp55xx_predef_pattern board_led_patterns[] = {
{
.r = mode_1,
.size_r = ARRAY_SIZE(mode_1),
},
{
.b = mode_2,
.size_b = ARRAY_SIZE(mode_2),
},
}

struct lp55xx_platform_data lp5562_pdata = {

.patterns = board_led_patterns,
.num_patterns = ARRAY_SIZE(board_led_patterns),
};

Then, mode_1 and mode_2 can be run via through the sysfs.
配置后通过sysfs操作执行:
echo 1 > /sys/bus/i2c/devices/xxxx/led_pattern # red blinking LED pattern
echo 2 > /sys/bus/i2c/devices/xxxx/led_pattern # blue LED always on

停止执行pattern
To stop running pattern,
echo 0 > /sys/bus/i2c/devices/xxxx/led_pattern

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325987944&siteId=291194637