Skip to content

Commit b0eed39

Browse files
Ansuellag-linaro
authored andcommitted
leds: leds-lp5569: Enable chip after chip configuration
Documentation say that clock internal config needs to be set BEFORE chip is enabled. Align code to this and move the CHIP enable after the CHIP is configured. While at it also make use of STATUS reg and check when STARTUP is completed instead of sleep for 1-2 ms. Signed-off-by: Christian Marangi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 2a498d6 commit b0eed39

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/leds/leds-lp5569.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/delay.h>
99
#include <linux/firmware.h>
1010
#include <linux/i2c.h>
11+
#include <linux/iopoll.h>
1112
#include <linux/leds.h>
1213
#include <linux/module.h>
1314
#include <linux/mutex.h>
@@ -92,6 +93,8 @@
9293
#define LP5569_ENG2_MUX_ADDR 0xd0
9394
#define LP5569_ENG3_MUX_ADDR 0xe0
9495

96+
#define LP5569_STARTUP_SLEEP 500
97+
9598
#define LEDn_STATUS_FAULT(n, status) ((status) >> (n) & BIT(0))
9699

97100
#define LP5569_DEFAULT_CONFIG \
@@ -169,14 +172,7 @@ static int lp5569_init_program_engine(struct lp55xx_chip *chip)
169172
static int lp5569_post_init_device(struct lp55xx_chip *chip)
170173
{
171174
int ret;
172-
int val;
173-
174-
ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE);
175-
if (ret)
176-
return ret;
177-
178-
/* Chip startup time is 500 us, 1 - 2 ms gives some margin */
179-
usleep_range(1000, 2000);
175+
u8 val;
180176

181177
val = LP5569_DEFAULT_CONFIG;
182178
val |= FIELD_PREP(LP5569_CP_MODE_MASK, chip->pdata->charge_pump_mode);
@@ -199,6 +195,13 @@ static int lp5569_post_init_device(struct lp55xx_chip *chip)
199195
return ret;
200196
}
201197

198+
ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE);
199+
if (ret)
200+
return ret;
201+
202+
read_poll_timeout(lp55xx_read, ret, !(val & LP5569_STARTUP_BUSY),
203+
LP5569_STARTUP_SLEEP, LP5569_STARTUP_SLEEP * 10, false,
204+
chip, LP5569_REG_STATUS, &val);
202205

203206
return lp5569_init_program_engine(chip);
204207
}

0 commit comments

Comments
 (0)