diff options
author | Milo(Woogyom) Kim <milo.kim@ti.com> | 2013-02-05 05:21:43 -0500 |
---|---|---|
committer | Bryan Wu <cooloney@gmail.com> | 2013-02-06 18:59:29 -0500 |
commit | 9ca3bd8022d76a0d1b386cedcecaf49004a58644 (patch) | |
tree | bc10df89bca5a34cf4b5410591e96188d80ef6df /drivers/leds/leds-lp5523.c | |
parent | e73c0ce6beaa71bee39b2d11bff0253be84c71a9 (diff) |
leds-lp55xx: code refactoring on selftest function
LP5521 and LP5523 have a selftest function which is run via the sysfs.
Use lp55xx driver data and R/W functions rather than lp5521/5523 private data
and functions.
Additionally, if-statements are changed for code simplicity.
Unused functions, lp5521/5523_read() are 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.c | 53 |
1 files changed, 20 insertions, 33 deletions
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 4192a1ec6062..577059934f58 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c | |||
@@ -178,17 +178,6 @@ static int lp5523_write(struct i2c_client *client, u8 reg, u8 value) | |||
178 | return i2c_smbus_write_byte_data(client, reg, value); | 178 | return i2c_smbus_write_byte_data(client, reg, value); |
179 | } | 179 | } |
180 | 180 | ||
181 | static int lp5523_read(struct i2c_client *client, u8 reg, u8 *buf) | ||
182 | { | ||
183 | s32 ret = i2c_smbus_read_byte_data(client, reg); | ||
184 | |||
185 | if (ret < 0) | ||
186 | return ret; | ||
187 | |||
188 | *buf = ret; | ||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | static int lp5523_post_init_device(struct lp55xx_chip *chip) | 181 | static int lp5523_post_init_device(struct lp55xx_chip *chip) |
193 | { | 182 | { |
194 | int ret; | 183 | int ret; |
@@ -376,35 +365,35 @@ static ssize_t lp5523_selftest(struct device *dev, | |||
376 | struct device_attribute *attr, | 365 | struct device_attribute *attr, |
377 | char *buf) | 366 | char *buf) |
378 | { | 367 | { |
379 | struct i2c_client *client = to_i2c_client(dev); | 368 | struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev)); |
380 | struct lp5523_chip *chip = i2c_get_clientdata(client); | 369 | struct lp55xx_chip *chip = led->chip; |
370 | struct lp55xx_platform_data *pdata = chip->pdata; | ||
381 | int i, ret, pos = 0; | 371 | int i, ret, pos = 0; |
382 | int led = 0; | ||
383 | u8 status, adc, vdd; | 372 | u8 status, adc, vdd; |
384 | 373 | ||
385 | mutex_lock(&chip->lock); | 374 | mutex_lock(&chip->lock); |
386 | 375 | ||
387 | ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status); | 376 | ret = lp55xx_read(chip, LP5523_REG_STATUS, &status); |
388 | if (ret < 0) | 377 | if (ret < 0) |
389 | goto fail; | 378 | goto fail; |
390 | 379 | ||
391 | /* Check that ext clock is really in use if requested */ | 380 | /* Check that ext clock is really in use if requested */ |
392 | if ((chip->pdata) && (chip->pdata->clock_mode == LP5523_CLOCK_EXT)) | 381 | if (pdata->clock_mode == LP55XX_CLOCK_EXT) { |
393 | if ((status & LP5523_EXT_CLK_USED) == 0) | 382 | if ((status & LP5523_EXT_CLK_USED) == 0) |
394 | goto fail; | 383 | goto fail; |
384 | } | ||
395 | 385 | ||
396 | /* Measure VDD (i.e. VBAT) first (channel 16 corresponds to VDD) */ | 386 | /* Measure VDD (i.e. VBAT) first (channel 16 corresponds to VDD) */ |
397 | lp5523_write(chip->client, LP5523_REG_LED_TEST_CTRL, | 387 | lp55xx_write(chip, LP5523_REG_LED_TEST_CTRL, LP5523_EN_LEDTEST | 16); |
398 | LP5523_EN_LEDTEST | 16); | ||
399 | usleep_range(3000, 6000); /* ADC conversion time is typically 2.7 ms */ | 388 | usleep_range(3000, 6000); /* ADC conversion time is typically 2.7 ms */ |
400 | ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status); | 389 | ret = lp55xx_read(chip, LP5523_REG_STATUS, &status); |
401 | if (ret < 0) | 390 | if (ret < 0) |
402 | goto fail; | 391 | goto fail; |
403 | 392 | ||
404 | if (!(status & LP5523_LEDTEST_DONE)) | 393 | if (!(status & LP5523_LEDTEST_DONE)) |
405 | usleep_range(3000, 6000); /* Was not ready. Wait little bit */ | 394 | usleep_range(3000, 6000); /* Was not ready. Wait little bit */ |
406 | 395 | ||
407 | ret = lp5523_read(chip->client, LP5523_REG_LED_TEST_ADC, &vdd); | 396 | ret = lp55xx_read(chip, LP5523_REG_LED_TEST_ADC, &vdd); |
408 | if (ret < 0) | 397 | if (ret < 0) |
409 | goto fail; | 398 | goto fail; |
410 | 399 | ||
@@ -412,41 +401,39 @@ static ssize_t lp5523_selftest(struct device *dev, | |||
412 | 401 | ||
413 | for (i = 0; i < LP5523_MAX_LEDS; i++) { | 402 | for (i = 0; i < LP5523_MAX_LEDS; i++) { |
414 | /* Skip non-existing channels */ | 403 | /* Skip non-existing channels */ |
415 | if (chip->pdata->led_config[i].led_current == 0) | 404 | if (pdata->led_config[i].led_current == 0) |
416 | continue; | 405 | continue; |
417 | 406 | ||
418 | /* Set default current */ | 407 | /* Set default current */ |
419 | lp5523_write(chip->client, | 408 | lp55xx_write(chip, LP5523_REG_LED_CURRENT_BASE + i, |
420 | LP5523_REG_LED_CURRENT_BASE + i, | 409 | pdata->led_config[i].led_current); |
421 | chip->pdata->led_config[i].led_current); | ||
422 | 410 | ||
423 | lp5523_write(chip->client, LP5523_REG_LED_PWM_BASE + i, 0xff); | 411 | lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + i, 0xff); |
424 | /* let current stabilize 2 - 4ms before measurements start */ | 412 | /* let current stabilize 2 - 4ms before measurements start */ |
425 | usleep_range(2000, 4000); | 413 | usleep_range(2000, 4000); |
426 | lp5523_write(chip->client, | 414 | lp55xx_write(chip, LP5523_REG_LED_TEST_CTRL, |
427 | LP5523_REG_LED_TEST_CTRL, | ||
428 | LP5523_EN_LEDTEST | i); | 415 | LP5523_EN_LEDTEST | i); |
429 | /* ADC conversion time is 2.7 ms typically */ | 416 | /* ADC conversion time is 2.7 ms typically */ |
430 | usleep_range(3000, 6000); | 417 | usleep_range(3000, 6000); |
431 | ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status); | 418 | ret = lp55xx_read(chip, LP5523_REG_STATUS, &status); |
432 | if (ret < 0) | 419 | if (ret < 0) |
433 | goto fail; | 420 | goto fail; |
434 | 421 | ||
435 | if (!(status & LP5523_LEDTEST_DONE)) | 422 | if (!(status & LP5523_LEDTEST_DONE)) |
436 | usleep_range(3000, 6000);/* Was not ready. Wait. */ | 423 | usleep_range(3000, 6000);/* Was not ready. Wait. */ |
437 | ret = lp5523_read(chip->client, LP5523_REG_LED_TEST_ADC, &adc); | 424 | |
425 | ret = lp55xx_read(chip, LP5523_REG_LED_TEST_ADC, &adc); | ||
438 | if (ret < 0) | 426 | if (ret < 0) |
439 | goto fail; | 427 | goto fail; |
440 | 428 | ||
441 | if (adc >= vdd || adc < LP5523_ADC_SHORTCIRC_LIM) | 429 | if (adc >= vdd || adc < LP5523_ADC_SHORTCIRC_LIM) |
442 | pos += sprintf(buf + pos, "LED %d FAIL\n", i); | 430 | pos += sprintf(buf + pos, "LED %d FAIL\n", i); |
443 | 431 | ||
444 | lp5523_write(chip->client, LP5523_REG_LED_PWM_BASE + i, 0x00); | 432 | lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + i, 0x00); |
445 | 433 | ||
446 | /* Restore current */ | 434 | /* Restore current */ |
447 | lp5523_write(chip->client, | 435 | lp55xx_write(chip, LP5523_REG_LED_CURRENT_BASE + i, |
448 | LP5523_REG_LED_CURRENT_BASE + i, | 436 | led->led_current); |
449 | chip->leds[led].led_current); | ||
450 | led++; | 437 | led++; |
451 | } | 438 | } |
452 | if (pos == 0) | 439 | if (pos == 0) |