Skip to content

Commit 67a4a34

Browse files
glneolag-linaro
authored andcommitted
leds: lp8860: Hold lock for all of EEPROM programming
The lock is taken while unlocking the EEPROM but then released, it should instead be held for the whole EEPROM programming process. To do this merge in the lp8860_unlock_eeprom() function to the only call site in the lp8860_init() function. This way we hold the lock for all steps. While here, rename this function to lp8860_program_eeprom() to better represent what it really does. Signed-off-by: Andrew Davis <afd@ti.com> Link: https://patch.msgid.link/20260305203706.841384-3-afd@ti.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 665e064 commit 67a4a34

1 file changed

Lines changed: 17 additions & 30 deletions

File tree

drivers/leds/leds-lp8860.c

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -125,32 +125,6 @@ static const struct reg_sequence lp8860_eeprom_disp_regs[] = {
125125
{ LP8860_EEPROM_REG_24, 0x3E },
126126
};
127127

128-
static int lp8860_unlock_eeprom(struct lp8860_led *led)
129-
{
130-
int ret;
131-
132-
guard(mutex)(&led->lock);
133-
134-
ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_1);
135-
if (ret) {
136-
dev_err(&led->client->dev, "EEPROM Unlock failed\n");
137-
return ret;
138-
}
139-
140-
ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_2);
141-
if (ret) {
142-
dev_err(&led->client->dev, "EEPROM Unlock failed\n");
143-
return ret;
144-
}
145-
ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_3);
146-
if (ret) {
147-
dev_err(&led->client->dev, "EEPROM Unlock failed\n");
148-
return ret;
149-
}
150-
151-
return ret;
152-
}
153-
154128
static int lp8860_fault_check(struct lp8860_led *led)
155129
{
156130
int ret, fault;
@@ -209,11 +183,13 @@ static int lp8860_brightness_set(struct led_classdev *led_cdev,
209183
return 0;
210184
}
211185

212-
static int lp8860_init(struct lp8860_led *led)
186+
static int lp8860_program_eeprom(struct lp8860_led *led)
213187
{
214188
unsigned int read_buf;
215189
int ret, reg_count;
216190

191+
guard(mutex)(&led->lock);
192+
217193
ret = lp8860_fault_check(led);
218194
if (ret)
219195
return ret;
@@ -222,9 +198,20 @@ static int lp8860_init(struct lp8860_led *led)
222198
if (ret)
223199
return ret;
224200

225-
ret = lp8860_unlock_eeprom(led);
201+
ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_1);
202+
if (ret) {
203+
dev_err(&led->client->dev, "EEPROM Unlock failed\n");
204+
return ret;
205+
}
206+
207+
ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_2);
208+
if (ret) {
209+
dev_err(&led->client->dev, "EEPROM Unlock failed\n");
210+
return ret;
211+
}
212+
ret = regmap_write(led->regmap, LP8860_EEPROM_UNLOCK, LP8860_EEPROM_CODE_3);
226213
if (ret) {
227-
dev_err(&led->client->dev, "Failed unlocking EEPROM\n");
214+
dev_err(&led->client->dev, "EEPROM Unlock failed\n");
228215
return ret;
229216
}
230217

@@ -318,7 +305,7 @@ static int lp8860_probe(struct i2c_client *client)
318305
return ret;
319306
}
320307

321-
ret = lp8860_init(led);
308+
ret = lp8860_program_eeprom(led);
322309
if (ret)
323310
return ret;
324311

0 commit comments

Comments
 (0)