Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 358617
b: refs/heads/master
c: 9ca3bd8
h: refs/heads/master
i:
  358615: e0bbe7b
v: v3
  • Loading branch information
Milo(Woogyom) Kim authored and Bryan Wu committed Feb 6, 2013
1 parent e33ef09 commit 5785e36
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 53 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e73c0ce6beaa71bee39b2d11bff0253be84c71a9
refs/heads/master: 9ca3bd8022d76a0d1b386cedcecaf49004a58644
30 changes: 11 additions & 19 deletions trunk/drivers/leds/leds-lp5521.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,6 @@ static inline int lp5521_write(struct i2c_client *client, u8 reg, u8 value)
return i2c_smbus_write_byte_data(client, reg, value);
}

static int lp5521_read(struct i2c_client *client, u8 reg, u8 *buf)
{
s32 ret;

ret = i2c_smbus_read_byte_data(client, reg);
if (ret < 0)
return ret;

*buf = ret;
return 0;
}

static void lp5521_load_engine(struct lp55xx_chip *chip)
{
enum lp55xx_engine_index idx = chip->engine_idx;
Expand Down Expand Up @@ -378,19 +366,23 @@ static int lp5521_post_init_device(struct lp55xx_chip *chip)
return 0;
}

static int lp5521_run_selftest(struct lp5521_chip *chip, char *buf)
static int lp5521_run_selftest(struct lp55xx_chip *chip, char *buf)
{
struct lp55xx_platform_data *pdata = chip->pdata;
int ret;
u8 status;

ret = lp5521_read(chip->client, LP5521_REG_STATUS, &status);
ret = lp55xx_read(chip, LP5521_REG_STATUS, &status);
if (ret < 0)
return ret;

if (pdata->clock_mode != LP55XX_CLOCK_EXT)
return 0;

/* Check that ext clock is really in use if requested */
if (chip->pdata && chip->pdata->clock_mode == LP5521_CLOCK_EXT)
if ((status & LP5521_EXT_CLK_USED) == 0)
return -EIO;
if ((status & LP5521_EXT_CLK_USED) == 0)
return -EIO;

return 0;
}

Expand All @@ -410,8 +402,8 @@ static ssize_t lp5521_selftest(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct lp5521_chip *chip = i2c_get_clientdata(client);
struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
struct lp55xx_chip *chip = led->chip;
int ret;

mutex_lock(&chip->lock);
Expand Down
53 changes: 20 additions & 33 deletions trunk/drivers/leds/leds-lp5523.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,6 @@ static int lp5523_write(struct i2c_client *client, u8 reg, u8 value)
return i2c_smbus_write_byte_data(client, reg, value);
}

static int lp5523_read(struct i2c_client *client, u8 reg, u8 *buf)
{
s32 ret = i2c_smbus_read_byte_data(client, reg);

if (ret < 0)
return ret;

*buf = ret;
return 0;
}

static int lp5523_post_init_device(struct lp55xx_chip *chip)
{
int ret;
Expand Down Expand Up @@ -376,77 +365,75 @@ static ssize_t lp5523_selftest(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct lp5523_chip *chip = i2c_get_clientdata(client);
struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
struct lp55xx_chip *chip = led->chip;
struct lp55xx_platform_data *pdata = chip->pdata;
int i, ret, pos = 0;
int led = 0;
u8 status, adc, vdd;

mutex_lock(&chip->lock);

ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status);
ret = lp55xx_read(chip, LP5523_REG_STATUS, &status);
if (ret < 0)
goto fail;

/* Check that ext clock is really in use if requested */
if ((chip->pdata) && (chip->pdata->clock_mode == LP5523_CLOCK_EXT))
if (pdata->clock_mode == LP55XX_CLOCK_EXT) {
if ((status & LP5523_EXT_CLK_USED) == 0)
goto fail;
}

/* Measure VDD (i.e. VBAT) first (channel 16 corresponds to VDD) */
lp5523_write(chip->client, LP5523_REG_LED_TEST_CTRL,
LP5523_EN_LEDTEST | 16);
lp55xx_write(chip, LP5523_REG_LED_TEST_CTRL, LP5523_EN_LEDTEST | 16);
usleep_range(3000, 6000); /* ADC conversion time is typically 2.7 ms */
ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status);
ret = lp55xx_read(chip, LP5523_REG_STATUS, &status);
if (ret < 0)
goto fail;

if (!(status & LP5523_LEDTEST_DONE))
usleep_range(3000, 6000); /* Was not ready. Wait little bit */

ret = lp5523_read(chip->client, LP5523_REG_LED_TEST_ADC, &vdd);
ret = lp55xx_read(chip, LP5523_REG_LED_TEST_ADC, &vdd);
if (ret < 0)
goto fail;

vdd--; /* There may be some fluctuation in measurement */

for (i = 0; i < LP5523_MAX_LEDS; i++) {
/* Skip non-existing channels */
if (chip->pdata->led_config[i].led_current == 0)
if (pdata->led_config[i].led_current == 0)
continue;

/* Set default current */
lp5523_write(chip->client,
LP5523_REG_LED_CURRENT_BASE + i,
chip->pdata->led_config[i].led_current);
lp55xx_write(chip, LP5523_REG_LED_CURRENT_BASE + i,
pdata->led_config[i].led_current);

lp5523_write(chip->client, LP5523_REG_LED_PWM_BASE + i, 0xff);
lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + i, 0xff);
/* let current stabilize 2 - 4ms before measurements start */
usleep_range(2000, 4000);
lp5523_write(chip->client,
LP5523_REG_LED_TEST_CTRL,
lp55xx_write(chip, LP5523_REG_LED_TEST_CTRL,
LP5523_EN_LEDTEST | i);
/* ADC conversion time is 2.7 ms typically */
usleep_range(3000, 6000);
ret = lp5523_read(chip->client, LP5523_REG_STATUS, &status);
ret = lp55xx_read(chip, LP5523_REG_STATUS, &status);
if (ret < 0)
goto fail;

if (!(status & LP5523_LEDTEST_DONE))
usleep_range(3000, 6000);/* Was not ready. Wait. */
ret = lp5523_read(chip->client, LP5523_REG_LED_TEST_ADC, &adc);

ret = lp55xx_read(chip, LP5523_REG_LED_TEST_ADC, &adc);
if (ret < 0)
goto fail;

if (adc >= vdd || adc < LP5523_ADC_SHORTCIRC_LIM)
pos += sprintf(buf + pos, "LED %d FAIL\n", i);

lp5523_write(chip->client, LP5523_REG_LED_PWM_BASE + i, 0x00);
lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + i, 0x00);

/* Restore current */
lp5523_write(chip->client,
LP5523_REG_LED_CURRENT_BASE + i,
chip->leds[led].led_current);
lp55xx_write(chip, LP5523_REG_LED_CURRENT_BASE + i,
led->led_current);
led++;
}
if (pos == 0)
Expand Down

0 comments on commit 5785e36

Please sign in to comment.