Skip to content

Commit a3df190

Browse files
Ansuellag-linaro
authored andcommitted
leds: leds-lp55xx: Generalize firmware_loaded function
Generalize firmware_loaded function as lp55xx based LED driver all share the same logic. Suggested-by: Lee Jones <[email protected]> Signed-off-by: Christian Marangi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 31379a5 commit a3df190

File tree

6 files changed

+30
-88
lines changed

6 files changed

+30
-88
lines changed

drivers/leds/leds-lp5521.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,6 @@ static void lp5521_run_engine(struct lp55xx_chip *chip, bool start)
146146
lp5521_wait_enable_done();
147147
}
148148

149-
static void lp5521_firmware_loaded(struct lp55xx_chip *chip)
150-
{
151-
const struct firmware *fw = chip->fw;
152-
153-
if (fw->size > LP5521_PROGRAM_LENGTH) {
154-
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
155-
fw->size);
156-
return;
157-
}
158-
159-
/*
160-
* Program memory sequence
161-
* 1) set engine mode to "LOAD"
162-
* 2) write firmware data into program memory
163-
*/
164-
165-
lp55xx_load_engine(chip);
166-
lp55xx_update_program_memory(chip, fw->data, fw->size);
167-
}
168-
169149
static int lp5521_post_init_device(struct lp55xx_chip *chip)
170150
{
171151
int ret;
@@ -413,7 +393,7 @@ static struct lp55xx_device_config lp5521_cfg = {
413393
.brightness_fn = lp5521_led_brightness,
414394
.multicolor_brightness_fn = lp5521_multicolor_brightness,
415395
.set_led_current = lp5521_set_led_current,
416-
.firmware_cb = lp5521_firmware_loaded,
396+
.firmware_cb = lp55xx_firmware_loaded_cb,
417397
.run_engine = lp5521_run_engine,
418398
.dev_attr_group = &lp5521_group,
419399
};

drivers/leds/leds-lp5523.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -254,26 +254,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip)
254254
return ret;
255255
}
256256

257-
static void lp5523_firmware_loaded(struct lp55xx_chip *chip)
258-
{
259-
const struct firmware *fw = chip->fw;
260-
261-
if (fw->size > LP5523_PROGRAM_LENGTH) {
262-
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
263-
fw->size);
264-
return;
265-
}
266-
267-
/*
268-
* Program memory sequence
269-
* 1) set engine mode to "LOAD"
270-
* 2) write firmware data into program memory
271-
*/
272-
273-
lp55xx_load_engine(chip);
274-
lp55xx_update_program_memory(chip, fw->data, fw->size);
275-
}
276-
277257
static ssize_t show_engine_mode(struct device *dev,
278258
struct device_attribute *attr,
279259
char *buf, int nr)
@@ -785,7 +765,7 @@ static struct lp55xx_device_config lp5523_cfg = {
785765
.brightness_fn = lp5523_led_brightness,
786766
.multicolor_brightness_fn = lp5523_multicolor_brightness,
787767
.set_led_current = lp5523_set_led_current,
788-
.firmware_cb = lp5523_firmware_loaded,
768+
.firmware_cb = lp55xx_firmware_loaded_cb,
789769
.run_engine = lp5523_run_engine,
790770
.dev_attr_group = &lp5523_group,
791771
};

drivers/leds/leds-lp5562.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,6 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start)
144144
lp5562_wait_enable_done();
145145
}
146146

147-
static void lp5562_firmware_loaded(struct lp55xx_chip *chip)
148-
{
149-
const struct firmware *fw = chip->fw;
150-
151-
/*
152-
* the firmware is encoded in ascii hex character, with 2 chars
153-
* per byte
154-
*/
155-
if (fw->size > (LP5562_PROGRAM_LENGTH * 2)) {
156-
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
157-
fw->size);
158-
return;
159-
}
160-
161-
/*
162-
* Program memory sequence
163-
* 1) set engine mode to "LOAD"
164-
* 2) write firmware data into program memory
165-
*/
166-
167-
lp55xx_load_engine(chip);
168-
lp55xx_update_program_memory(chip, fw->data, fw->size);
169-
}
170-
171147
static int lp5562_post_init_device(struct lp55xx_chip *chip)
172148
{
173149
int ret;
@@ -404,7 +380,7 @@ static struct lp55xx_device_config lp5562_cfg = {
404380
.set_led_current = lp5562_set_led_current,
405381
.brightness_fn = lp5562_led_brightness,
406382
.run_engine = lp5562_run_engine,
407-
.firmware_cb = lp5562_firmware_loaded,
383+
.firmware_cb = lp55xx_firmware_loaded_cb,
408384
.dev_attr_group = &lp5562_group,
409385
};
410386

drivers/leds/leds-lp55xx-common.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,31 @@ int lp55xx_update_program_memory(struct lp55xx_chip *chip,
217217
}
218218
EXPORT_SYMBOL_GPL(lp55xx_update_program_memory);
219219

220+
void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip)
221+
{
222+
const struct firmware *fw = chip->fw;
223+
224+
/*
225+
* the firmware is encoded in ascii hex character, with 2 chars
226+
* per byte
227+
*/
228+
if (fw->size > LP55xx_PROGRAM_LENGTH * 2) {
229+
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
230+
fw->size);
231+
return;
232+
}
233+
234+
/*
235+
* Program memory sequence
236+
* 1) set engine mode to "LOAD"
237+
* 2) write firmware data into program memory
238+
*/
239+
240+
lp55xx_load_engine(chip);
241+
lp55xx_update_program_memory(chip, fw->data, fw->size);
242+
}
243+
EXPORT_SYMBOL_GPL(lp55xx_firmware_loaded_cb);
244+
220245
static void lp55xx_reset_device(struct lp55xx_chip *chip)
221246
{
222247
const struct lp55xx_device_config *cfg = chip->cfg;

drivers/leds/leds-lp55xx-common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ extern void lp55xx_load_engine(struct lp55xx_chip *chip);
212212
extern int lp55xx_run_engine_common(struct lp55xx_chip *chip);
213213
extern int lp55xx_update_program_memory(struct lp55xx_chip *chip,
214214
const u8 *data, size_t size);
215+
extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip);
215216

216217
/* common probe/remove function */
217218
extern int lp55xx_probe(struct i2c_client *client);

drivers/leds/leds-lp8501.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,6 @@ static void lp8501_run_engine(struct lp55xx_chip *chip, bool start)
137137
lp55xx_run_engine_common(chip);
138138
}
139139

140-
static void lp8501_firmware_loaded(struct lp55xx_chip *chip)
141-
{
142-
const struct firmware *fw = chip->fw;
143-
144-
if (fw->size > LP8501_PROGRAM_LENGTH) {
145-
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
146-
fw->size);
147-
return;
148-
}
149-
150-
/*
151-
* Program memory sequence
152-
* 1) set engine mode to "LOAD"
153-
* 2) write firmware data into program memory
154-
*/
155-
156-
lp55xx_load_engine(chip);
157-
lp55xx_update_program_memory(chip, fw->data, fw->size);
158-
}
159-
160140
static int lp8501_led_brightness(struct lp55xx_led *led)
161141
{
162142
struct lp55xx_chip *chip = led->chip;
@@ -198,7 +178,7 @@ static struct lp55xx_device_config lp8501_cfg = {
198178
.post_init_device = lp8501_post_init_device,
199179
.brightness_fn = lp8501_led_brightness,
200180
.set_led_current = lp8501_set_led_current,
201-
.firmware_cb = lp8501_firmware_loaded,
181+
.firmware_cb = lp55xx_firmware_loaded_cb,
202182
.run_engine = lp8501_run_engine,
203183
};
204184

0 commit comments

Comments
 (0)