aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lp5523.c
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 04:04:50 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-06 18:59:27 -0500
commit632418bf65503405df3f9a6a1616f5a95f91db85 (patch)
tree15399857e1908e6e92abebc1ab58565b58c02e30 /drivers/leds/leds-lp5523.c
parent9448217403462c4b17bc56690a0348a0c02e5ba2 (diff)
leds-lp5523: clean up lp5523_configure()
This patch is a preceding step for making common lp55xx init function. Return code: Do not use 'OR' arithmetic for the result. If some error occurs, just return it. Remove engine verification code: To check whether internal engine works or not, many lines of code are executed. However, this job is unnecessary during the chip initialization because the engine usage is not mandatory but optional function. LED engines are enabled when specific LED pattern is loaded. Therefore, this verification code is removed. Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds/leds-lp5523.c')
-rw-r--r--drivers/leds/leds-lp5523.c67
1 files changed, 9 insertions, 58 deletions
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index 71bda3670ff0..2ca41c5af719 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -199,77 +199,28 @@ static int lp5523_detect(struct i2c_client *client)
199 199
200static int lp5523_configure(struct i2c_client *client) 200static int lp5523_configure(struct i2c_client *client)
201{ 201{
202 struct lp5523_chip *chip = i2c_get_clientdata(client);
203 int ret = 0; 202 int ret = 0;
204 u8 status;
205 203
206 /* one pattern per engine setting led mux start and stop addresses */ 204 ret = lp5523_write(client, LP5523_REG_ENABLE, LP5523_ENABLE);
207 static const u8 pattern[][LP5523_PROGRAM_LENGTH] = { 205 if (ret)
208 { 0x9c, 0x30, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0}, 206 return ret;
209 { 0x9c, 0x40, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0},
210 { 0x9c, 0x50, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0},
211 };
212 207
213 ret |= lp5523_write(client, LP5523_REG_ENABLE, LP5523_ENABLE);
214 /* Chip startup time is 500 us, 1 - 2 ms gives some margin */ 208 /* Chip startup time is 500 us, 1 - 2 ms gives some margin */
215 usleep_range(1000, 2000); 209 usleep_range(1000, 2000);
216 210
217 ret |= lp5523_write(client, LP5523_REG_CONFIG, 211 ret = lp5523_write(client, LP5523_REG_CONFIG,
218 LP5523_AUTO_INC | LP5523_PWR_SAVE | 212 LP5523_AUTO_INC | LP5523_PWR_SAVE |
219 LP5523_CP_AUTO | LP5523_AUTO_CLK | 213 LP5523_CP_AUTO | LP5523_AUTO_CLK |
220 LP5523_PWM_PWR_SAVE); 214 LP5523_PWM_PWR_SAVE);
215 if (ret)
216 return ret;
221 217
222 /* turn on all leds */ 218 /* turn on all leds */
223 ret |= lp5523_write(client, LP5523_REG_ENABLE_LEDS_MSB, 0x01); 219 ret = lp5523_write(client, LP5523_REG_ENABLE_LEDS_MSB, 0x01);
224 ret |= lp5523_write(client, LP5523_REG_ENABLE_LEDS_LSB, 0xff); 220 if (ret)
225
226 /* hardcode 32 bytes of memory for each engine from program memory */
227 ret |= lp5523_write(client, LP5523_REG_CH1_PROG_START, 0x00);
228 ret |= lp5523_write(client, LP5523_REG_CH2_PROG_START, 0x10);
229 ret |= lp5523_write(client, LP5523_REG_CH3_PROG_START, 0x20);
230
231 /* write led mux address space for each channel */
232 ret |= lp5523_load_program(&chip->engines[0], pattern[0]);
233 ret |= lp5523_load_program(&chip->engines[1], pattern[1]);
234 ret |= lp5523_load_program(&chip->engines[2], pattern[2]);
235
236 if (ret) {
237 dev_err(&client->dev, "could not load mux programs\n");
238 return -1;
239 }
240
241 /* set all engines exec state and mode to run 00101010 */
242 ret |= lp5523_write(client, LP5523_REG_ENABLE,
243 (LP5523_CMD_RUN | LP5523_ENABLE));
244
245 ret |= lp5523_write(client, LP5523_REG_OP_MODE, LP5523_CMD_RUN);
246
247 if (ret) {
248 dev_err(&client->dev, "could not start mux programs\n");
249 return -1;
250 }
251
252 /* Let the programs run for couple of ms and check the engine status */
253 usleep_range(3000, 6000);
254 ret = lp5523_read(client, LP5523_REG_STATUS, &status);
255 if (ret < 0)
256 return ret; 221 return ret;
257 222
258 status &= LP5523_ENG_STATUS_MASK; 223 return lp5523_write(client, LP5523_REG_ENABLE_LEDS_LSB, 0xff);
259
260 if (status == LP5523_ENG_STATUS_MASK) {
261 dev_dbg(&client->dev, "all engines configured\n");
262 } else {
263 dev_info(&client->dev, "status == %x\n", status);
264 dev_err(&client->dev, "cound not configure LED engine\n");
265 return -1;
266 }
267
268 dev_info(&client->dev, "disabling engines\n");
269
270 ret |= lp5523_write(client, LP5523_REG_OP_MODE, LP5523_CMD_DISABLED);
271
272 return ret;
273} 224}
274 225
275static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode) 226static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode)