Commit a3df1906 authored by Christian Marangi's avatar Christian Marangi Committed by Lee Jones

leds: leds-lp55xx: Generalize firmware_loaded function

Generalize firmware_loaded function as lp55xx based LED driver all share
the same logic.
Suggested-by: default avatarLee Jones <lee@kernel.org>
Signed-off-by: default avatarChristian Marangi <ansuelsmth@gmail.com>
Link: https://lore.kernel.org/r/20240626160027.19703-10-ansuelsmth@gmail.comSigned-off-by: default avatarLee Jones <lee@kernel.org>
parent 31379a57
...@@ -146,26 +146,6 @@ static void lp5521_run_engine(struct lp55xx_chip *chip, bool start) ...@@ -146,26 +146,6 @@ static void lp5521_run_engine(struct lp55xx_chip *chip, bool start)
lp5521_wait_enable_done(); lp5521_wait_enable_done();
} }
static void lp5521_firmware_loaded(struct lp55xx_chip *chip)
{
const struct firmware *fw = chip->fw;
if (fw->size > LP5521_PROGRAM_LENGTH) {
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
fw->size);
return;
}
/*
* Program memory sequence
* 1) set engine mode to "LOAD"
* 2) write firmware data into program memory
*/
lp55xx_load_engine(chip);
lp55xx_update_program_memory(chip, fw->data, fw->size);
}
static int lp5521_post_init_device(struct lp55xx_chip *chip) static int lp5521_post_init_device(struct lp55xx_chip *chip)
{ {
int ret; int ret;
...@@ -413,7 +393,7 @@ static struct lp55xx_device_config lp5521_cfg = { ...@@ -413,7 +393,7 @@ static struct lp55xx_device_config lp5521_cfg = {
.brightness_fn = lp5521_led_brightness, .brightness_fn = lp5521_led_brightness,
.multicolor_brightness_fn = lp5521_multicolor_brightness, .multicolor_brightness_fn = lp5521_multicolor_brightness,
.set_led_current = lp5521_set_led_current, .set_led_current = lp5521_set_led_current,
.firmware_cb = lp5521_firmware_loaded, .firmware_cb = lp55xx_firmware_loaded_cb,
.run_engine = lp5521_run_engine, .run_engine = lp5521_run_engine,
.dev_attr_group = &lp5521_group, .dev_attr_group = &lp5521_group,
}; };
......
...@@ -254,26 +254,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip) ...@@ -254,26 +254,6 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip)
return ret; return ret;
} }
static void lp5523_firmware_loaded(struct lp55xx_chip *chip)
{
const struct firmware *fw = chip->fw;
if (fw->size > LP5523_PROGRAM_LENGTH) {
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
fw->size);
return;
}
/*
* Program memory sequence
* 1) set engine mode to "LOAD"
* 2) write firmware data into program memory
*/
lp55xx_load_engine(chip);
lp55xx_update_program_memory(chip, fw->data, fw->size);
}
static ssize_t show_engine_mode(struct device *dev, static ssize_t show_engine_mode(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf, int nr) char *buf, int nr)
...@@ -785,7 +765,7 @@ static struct lp55xx_device_config lp5523_cfg = { ...@@ -785,7 +765,7 @@ static struct lp55xx_device_config lp5523_cfg = {
.brightness_fn = lp5523_led_brightness, .brightness_fn = lp5523_led_brightness,
.multicolor_brightness_fn = lp5523_multicolor_brightness, .multicolor_brightness_fn = lp5523_multicolor_brightness,
.set_led_current = lp5523_set_led_current, .set_led_current = lp5523_set_led_current,
.firmware_cb = lp5523_firmware_loaded, .firmware_cb = lp55xx_firmware_loaded_cb,
.run_engine = lp5523_run_engine, .run_engine = lp5523_run_engine,
.dev_attr_group = &lp5523_group, .dev_attr_group = &lp5523_group,
}; };
......
...@@ -144,30 +144,6 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start) ...@@ -144,30 +144,6 @@ static void lp5562_run_engine(struct lp55xx_chip *chip, bool start)
lp5562_wait_enable_done(); lp5562_wait_enable_done();
} }
static void lp5562_firmware_loaded(struct lp55xx_chip *chip)
{
const struct firmware *fw = chip->fw;
/*
* the firmware is encoded in ascii hex character, with 2 chars
* per byte
*/
if (fw->size > (LP5562_PROGRAM_LENGTH * 2)) {
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
fw->size);
return;
}
/*
* Program memory sequence
* 1) set engine mode to "LOAD"
* 2) write firmware data into program memory
*/
lp55xx_load_engine(chip);
lp55xx_update_program_memory(chip, fw->data, fw->size);
}
static int lp5562_post_init_device(struct lp55xx_chip *chip) static int lp5562_post_init_device(struct lp55xx_chip *chip)
{ {
int ret; int ret;
...@@ -404,7 +380,7 @@ static struct lp55xx_device_config lp5562_cfg = { ...@@ -404,7 +380,7 @@ static struct lp55xx_device_config lp5562_cfg = {
.set_led_current = lp5562_set_led_current, .set_led_current = lp5562_set_led_current,
.brightness_fn = lp5562_led_brightness, .brightness_fn = lp5562_led_brightness,
.run_engine = lp5562_run_engine, .run_engine = lp5562_run_engine,
.firmware_cb = lp5562_firmware_loaded, .firmware_cb = lp55xx_firmware_loaded_cb,
.dev_attr_group = &lp5562_group, .dev_attr_group = &lp5562_group,
}; };
......
...@@ -217,6 +217,31 @@ int lp55xx_update_program_memory(struct lp55xx_chip *chip, ...@@ -217,6 +217,31 @@ int lp55xx_update_program_memory(struct lp55xx_chip *chip,
} }
EXPORT_SYMBOL_GPL(lp55xx_update_program_memory); EXPORT_SYMBOL_GPL(lp55xx_update_program_memory);
void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip)
{
const struct firmware *fw = chip->fw;
/*
* the firmware is encoded in ascii hex character, with 2 chars
* per byte
*/
if (fw->size > LP55xx_PROGRAM_LENGTH * 2) {
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
fw->size);
return;
}
/*
* Program memory sequence
* 1) set engine mode to "LOAD"
* 2) write firmware data into program memory
*/
lp55xx_load_engine(chip);
lp55xx_update_program_memory(chip, fw->data, fw->size);
}
EXPORT_SYMBOL_GPL(lp55xx_firmware_loaded_cb);
static void lp55xx_reset_device(struct lp55xx_chip *chip) static void lp55xx_reset_device(struct lp55xx_chip *chip)
{ {
const struct lp55xx_device_config *cfg = chip->cfg; const struct lp55xx_device_config *cfg = chip->cfg;
......
...@@ -212,6 +212,7 @@ extern void lp55xx_load_engine(struct lp55xx_chip *chip); ...@@ -212,6 +212,7 @@ extern void lp55xx_load_engine(struct lp55xx_chip *chip);
extern int lp55xx_run_engine_common(struct lp55xx_chip *chip); extern int lp55xx_run_engine_common(struct lp55xx_chip *chip);
extern int lp55xx_update_program_memory(struct lp55xx_chip *chip, extern int lp55xx_update_program_memory(struct lp55xx_chip *chip,
const u8 *data, size_t size); const u8 *data, size_t size);
extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip);
/* common probe/remove function */ /* common probe/remove function */
extern int lp55xx_probe(struct i2c_client *client); extern int lp55xx_probe(struct i2c_client *client);
......
...@@ -137,26 +137,6 @@ static void lp8501_run_engine(struct lp55xx_chip *chip, bool start) ...@@ -137,26 +137,6 @@ static void lp8501_run_engine(struct lp55xx_chip *chip, bool start)
lp55xx_run_engine_common(chip); lp55xx_run_engine_common(chip);
} }
static void lp8501_firmware_loaded(struct lp55xx_chip *chip)
{
const struct firmware *fw = chip->fw;
if (fw->size > LP8501_PROGRAM_LENGTH) {
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
fw->size);
return;
}
/*
* Program memory sequence
* 1) set engine mode to "LOAD"
* 2) write firmware data into program memory
*/
lp55xx_load_engine(chip);
lp55xx_update_program_memory(chip, fw->data, fw->size);
}
static int lp8501_led_brightness(struct lp55xx_led *led) static int lp8501_led_brightness(struct lp55xx_led *led)
{ {
struct lp55xx_chip *chip = led->chip; struct lp55xx_chip *chip = led->chip;
...@@ -198,7 +178,7 @@ static struct lp55xx_device_config lp8501_cfg = { ...@@ -198,7 +178,7 @@ static struct lp55xx_device_config lp8501_cfg = {
.post_init_device = lp8501_post_init_device, .post_init_device = lp8501_post_init_device,
.brightness_fn = lp8501_led_brightness, .brightness_fn = lp8501_led_brightness,
.set_led_current = lp8501_set_led_current, .set_led_current = lp8501_set_led_current,
.firmware_cb = lp8501_firmware_loaded, .firmware_cb = lp55xx_firmware_loaded_cb,
.run_engine = lp8501_run_engine, .run_engine = lp8501_run_engine,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment