summaryrefslogtreecommitdiffstats
path: root/Documentation/leds/leds-lp5521.txt
blob: 0e542ab3d4a0f0d21cf915672c0686bf105a2e23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Kernel driver for lp5521
========================

* National Semiconductor LP5521 led driver chip
* Datasheet: http://www.national.com/pf/LP/LP5521.html

Authors: Mathias Nyman, Yuri Zaporozhets, Samu Onkalo
Contact: Samu Onkalo (samu.p.onkalo-at-nokia.com)

Description
-----------

LP5521 can drive up to 3 channels. Leds can be controlled directly via
the led class control interface. Channels have generic names:
lp5521:channelx, where x is 0 .. 2

All three channels can be also controlled using the engine micro programs.
More details of the instructions can be found from the public data sheet.

Control interface for the engines:
x is 1 .. 3
enginex_mode : disabled, load, run
enginex_load : store program (visible only in engine load mode)

Example (start to blink the channel 2 led):
cd   /sys/class/leds/lp5521:channel2/device
echo "load" > engine3_mode
echo "037f4d0003ff6000" > engine3_load
echo "run" > engine3_mode

stop the engine:
echo "disabled" > engine3_mode

sysfs contains a selftest entry.
The test communicates with the chip and checks that
the clock mode is automatically set to the requested one.

Each channel has its own led current settings.
/sys/class/leds/lp5521:channel0/led_current - RW
/sys/class/leds/lp5521:channel0/max_current - RO
Format: 10x mA i.e 10 means 1.0 mA

example platform data:

Note: chan_nr can have values between 0 and 2.
The name of each channel can be configurable.
If the name field is not defined, the default name will be set to 'xxxx:channelN'
(XXXX : pdata->label or i2c client name, N : channel number)

static struct lp5521_led_config lp5521_led_config[] = {
        {
		.name = "red",
                .chan_nr        = 0,
                .led_current    = 50,
		.max_current    = 130,
        }, {
		.name = "green",
                .chan_nr        = 1,
                .led_current    = 0,
		.max_current    = 130,
        }, {
		.name = "blue",
                .chan_nr        = 2,
                .led_current    = 0,
		.max_current    = 130,
        }
};

static int lp5521_setup(void)
{
	/* setup HW resources */
}

static void lp5521_release(void)
{
	/* Release HW resources */
}

static void lp5521_enable(bool state)
{
	/* Control of chip enable signal */
}

static struct lp5521_platform_data lp5521_platform_data = {
        .led_config     = lp5521_led_config,
        .num_channels   = ARRAY_SIZE(lp5521_led_config),
        .clock_mode     = LP5521_CLOCK_EXT,
        .setup_resources   = lp5521_setup,
        .release_resources = lp5521_release,
        .enable            = lp5521_enable,
};

If the current is set to 0 in the platform data, that channel is
disabled and it is not visible in the sysfs.

The 'update_config' : CONFIG register (ADDR 08h)
This value is platform-specific data.
If update_config is not defined, the CONFIG register is set with
'LP5521_PWRSAVE_EN | LP5521_CP_MODE_AUTO | LP5521_R_TO_BATT'.
(Enable auto-powersave, set charge pump to auto, red to battery)

example of update_config :

#define LP5521_CONFIGS	(LP5521_PWM_HF | LP5521_PWRSAVE_EN | \
			LP5521_CP_MODE_AUTO | LP5521_R_TO_BATT | \
			LP5521_CLK_INT)

static struct lp5521_platform_data lp5521_pdata = {
	.led_config = lp5521_led_config,
	.num_channels = ARRAY_SIZE(lp5521_led_config),
	.clock_mode = LP5521_CLOCK_INT,
	.update_config = LP5521_CONFIGS,
};

LED patterns : LP5521 has autonomous operation without external control.
Pattern data can be defined in the platform data.

example of led pattern data :

/* RGB(50,5,0) 500ms on, 500ms off, infinite loop */
static u8 pattern_red[] = {
		0x40, 0x32, 0x60, 0x00,	0x40, 0x00, 0x60, 0x00,
		};

static u8 pattern_green[] = {
		0x40, 0x05, 0x60, 0x00, 0x40, 0x00, 0x60, 0x00,
		};

static struct lp5521_led_pattern board_led_patterns[] = {
	{
		.r = pattern_red,
		.g = pattern_green,
		.size_r = ARRAY_SIZE(pattern_red),
		.size_g = ARRAY_SIZE(pattern_green),
	},
};

static struct lp5521_platform_data lp5521_platform_data = {
        .led_config     = lp5521_led_config,
        .num_channels   = ARRAY_SIZE(lp5521_led_config),
        .clock_mode     = LP5521_CLOCK_EXT,
	.patterns = board_led_patterns,
	.num_patterns = ARRAY_SIZE(board_led_patterns),
};

Then predefined led pattern(s) can be executed via the sysfs.
To start the pattern #1,
# echo 1 > /sys/bus/i2c/devices/xxxx/led_pattern
(xxxx : i2c bus & slave address)
To end the pattern,
# echo 0 > /sys/bus/i2c/devices/xxxx/led_pattern