aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilo Kim <milo.kim@ti.com>2013-08-08 00:57:35 -0400
committerBryan Wu <cooloney@gmail.com>2013-08-26 20:22:13 -0400
commit224604389a5295360ef36b50ca5a51806a235fcf (patch)
tree0ab2104290e4a7c740ee5c14adc2542c7a067e6c
parentb9e1730b295087f5561477a184878783fd3d96d2 (diff)
leds: lp5523: LED MUX configuration on initializing
LED MUX start and stop address should be updated in the program memory on LP5523 initialization. LED pattern doesn't work without additional MUX address configuration. This handling is done by new function, lp5523_init_program_engine(). Eventually, it's called during device initialization, lp5523_post_init_device(). This is a conflict after git commit 632418bf65503405df3f9a6a1616f5a95f91db85 (leds-lp5523: clean up lp5523_configure()). So it should be fixed. Cc: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Milo Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
-rw-r--r--drivers/leds/leds-lp5523.c70
1 files changed, 69 insertions, 1 deletions
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index b50948060a02..29c8b19a445e 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -49,6 +49,9 @@
49#define LP5523_REG_RESET 0x3D 49#define LP5523_REG_RESET 0x3D
50#define LP5523_REG_LED_TEST_CTRL 0x41 50#define LP5523_REG_LED_TEST_CTRL 0x41
51#define LP5523_REG_LED_TEST_ADC 0x42 51#define LP5523_REG_LED_TEST_ADC 0x42
52#define LP5523_REG_CH1_PROG_START 0x4C
53#define LP5523_REG_CH2_PROG_START 0x4D
54#define LP5523_REG_CH3_PROG_START 0x4E
52#define LP5523_REG_PROG_PAGE_SEL 0x4F 55#define LP5523_REG_PROG_PAGE_SEL 0x4F
53#define LP5523_REG_PROG_MEM 0x50 56#define LP5523_REG_PROG_MEM 0x50
54 57
@@ -65,6 +68,7 @@
65#define LP5523_RESET 0xFF 68#define LP5523_RESET 0xFF
66#define LP5523_ADC_SHORTCIRC_LIM 80 69#define LP5523_ADC_SHORTCIRC_LIM 80
67#define LP5523_EXT_CLK_USED 0x08 70#define LP5523_EXT_CLK_USED 0x08
71#define LP5523_ENG_STATUS_MASK 0x07
68 72
69/* Memory Page Selection */ 73/* Memory Page Selection */
70#define LP5523_PAGE_ENG1 0 74#define LP5523_PAGE_ENG1 0
@@ -99,6 +103,8 @@ enum lp5523_chip_id {
99 LP55231, 103 LP55231,
100}; 104};
101 105
106static int lp5523_init_program_engine(struct lp55xx_chip *chip);
107
102static inline void lp5523_wait_opmode_done(void) 108static inline void lp5523_wait_opmode_done(void)
103{ 109{
104 usleep_range(1000, 2000); 110 usleep_range(1000, 2000);
@@ -134,7 +140,11 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip)
134 if (ret) 140 if (ret)
135 return ret; 141 return ret;
136 142
137 return lp55xx_write(chip, LP5523_REG_ENABLE_LEDS_LSB, 0xff); 143 ret = lp55xx_write(chip, LP5523_REG_ENABLE_LEDS_LSB, 0xff);
144 if (ret)
145 return ret;
146
147 return lp5523_init_program_engine(chip);
138} 148}
139 149
140static void lp5523_load_engine(struct lp55xx_chip *chip) 150static void lp5523_load_engine(struct lp55xx_chip *chip)
@@ -233,6 +243,64 @@ static void lp5523_run_engine(struct lp55xx_chip *chip, bool start)
233 lp55xx_update_bits(chip, LP5523_REG_ENABLE, LP5523_EXEC_M, exec); 243 lp55xx_update_bits(chip, LP5523_REG_ENABLE, LP5523_EXEC_M, exec);
234} 244}
235 245
246static int lp5523_init_program_engine(struct lp55xx_chip *chip)
247{
248 int i;
249 int j;
250 int ret;
251 u8 status;
252 /* one pattern per engine setting LED MUX start and stop addresses */
253 static const u8 pattern[][LP5523_PROGRAM_LENGTH] = {
254 { 0x9c, 0x30, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0},
255 { 0x9c, 0x40, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0},
256 { 0x9c, 0x50, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0},
257 };
258
259 /* hardcode 32 bytes of memory for each engine from program memory */
260 ret = lp55xx_write(chip, LP5523_REG_CH1_PROG_START, 0x00);
261 if (ret)
262 return ret;
263
264 ret = lp55xx_write(chip, LP5523_REG_CH2_PROG_START, 0x10);
265 if (ret)
266 return ret;
267
268 ret = lp55xx_write(chip, LP5523_REG_CH3_PROG_START, 0x20);
269 if (ret)
270 return ret;
271
272 /* write LED MUX address space for each engine */
273 for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) {
274 chip->engine_idx = i;
275 lp5523_load_engine_and_select_page(chip);
276
277 for (j = 0; j < LP5523_PROGRAM_LENGTH; j++) {
278 ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + j,
279 pattern[i - 1][j]);
280 if (ret)
281 goto out;
282 }
283 }
284
285 lp5523_run_engine(chip, true);
286
287 /* Let the programs run for couple of ms and check the engine status */
288 usleep_range(3000, 6000);
289 lp55xx_read(chip, LP5523_REG_STATUS, &status);
290 status &= LP5523_ENG_STATUS_MASK;
291
292 if (status != LP5523_ENG_STATUS_MASK) {
293 dev_err(&chip->cl->dev,
294 "cound not configure LED engine, status = 0x%.2x\n",
295 status);
296 ret = -1;
297 }
298
299out:
300 lp5523_stop_engine(chip);
301 return ret;
302}
303
236static int lp5523_update_program_memory(struct lp55xx_chip *chip, 304static int lp5523_update_program_memory(struct lp55xx_chip *chip,
237 const u8 *data, size_t size) 305 const u8 *data, size_t size)
238{ 306{