Skip to content

Commit 01e0290

Browse files
Ansuellag-linaro
authored andcommitted
leds: leds-lp55xx: Generalize set_led_current function
Generalize set_led_current function as the implementation is the same for most of the lp55xx based LED driver. 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 794826b commit 01e0290

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

drivers/leds/leds-lp5521.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ static inline void lp5521_wait_enable_done(void)
108108
usleep_range(500, 600);
109109
}
110110

111-
static void lp5521_set_led_current(struct lp55xx_led *led, u8 led_current)
112-
{
113-
led->led_current = led_current;
114-
lp55xx_write(led->chip, LP5521_REG_LED_CURRENT_BASE + led->chan_nr,
115-
led_current);
116-
}
117-
118111
static void lp5521_stop_engine(struct lp55xx_chip *chip)
119112
{
120113
enum lp55xx_engine_index idx = chip->engine_idx;
@@ -359,11 +352,14 @@ static struct lp55xx_device_config lp5521_cfg = {
359352
.reg_led_pwm_base = {
360353
.addr = LP5521_REG_LED_PWM_BASE,
361354
},
355+
.reg_led_current_base = {
356+
.addr = LP5521_REG_LED_CURRENT_BASE,
357+
},
362358
.max_channel = LP5521_MAX_LEDS,
363359
.post_init_device = lp5521_post_init_device,
364360
.brightness_fn = lp55xx_led_brightness,
365361
.multicolor_brightness_fn = lp55xx_multicolor_brightness,
366-
.set_led_current = lp5521_set_led_current,
362+
.set_led_current = lp55xx_set_led_current,
367363
.firmware_cb = lp55xx_firmware_loaded_cb,
368364
.run_engine = lp5521_run_engine,
369365
.dev_attr_group = &lp5521_group,

drivers/leds/leds-lp5523.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ static inline void lp5523_wait_opmode_done(void)
122122
usleep_range(1000, 2000);
123123
}
124124

125-
static void lp5523_set_led_current(struct lp55xx_led *led, u8 led_current)
126-
{
127-
led->led_current = led_current;
128-
lp55xx_write(led->chip, LP5523_REG_LED_CURRENT_BASE + led->chan_nr,
129-
led_current);
130-
}
131-
132125
static int lp5523_post_init_device(struct lp55xx_chip *chip)
133126
{
134127
int ret;
@@ -731,12 +724,15 @@ static struct lp55xx_device_config lp5523_cfg = {
731724
.reg_led_pwm_base = {
732725
.addr = LP5523_REG_LED_PWM_BASE,
733726
},
727+
.reg_led_current_base = {
728+
.addr = LP5523_REG_LED_CURRENT_BASE,
729+
},
734730
.pages_per_engine = LP5523_PAGES_PER_ENGINE,
735731
.max_channel = LP5523_MAX_LEDS,
736732
.post_init_device = lp5523_post_init_device,
737733
.brightness_fn = lp55xx_led_brightness,
738734
.multicolor_brightness_fn = lp55xx_multicolor_brightness,
739-
.set_led_current = lp5523_set_led_current,
735+
.set_led_current = lp55xx_set_led_current,
740736
.firmware_cb = lp55xx_firmware_loaded_cb,
741737
.run_engine = lp5523_run_engine,
742738
.dev_attr_group = &lp5523_group,

drivers/leds/leds-lp55xx-common.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,17 @@ int lp55xx_multicolor_brightness(struct lp55xx_led *led)
277277
}
278278
EXPORT_SYMBOL_GPL(lp55xx_multicolor_brightness);
279279

280+
void lp55xx_set_led_current(struct lp55xx_led *led, u8 led_current)
281+
{
282+
struct lp55xx_chip *chip = led->chip;
283+
const struct lp55xx_device_config *cfg = chip->cfg;
284+
285+
led->led_current = led_current;
286+
lp55xx_write(led->chip, cfg->reg_led_current_base.addr + led->chan_nr,
287+
led_current);
288+
}
289+
EXPORT_SYMBOL_GPL(lp55xx_set_led_current);
290+
280291
static void lp55xx_reset_device(struct lp55xx_chip *chip)
281292
{
282293
const struct lp55xx_device_config *cfg = chip->cfg;

drivers/leds/leds-lp55xx-common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct lp55xx_reg {
101101
* @enable : Chip specific enable command
102102
* @prog_mem_base : Chip specific base reg address for chip SMEM programming
103103
* @reg_led_pwm_base : Chip specific base reg address for LED PWM conf
104+
* @reg_led_current_base : Chip specific base reg address for LED current conf
104105
* @pages_per_engine : Assigned pages for each engine
105106
* (if not set chip doesn't support pages)
106107
* @max_channel : Maximum number of channels
@@ -120,6 +121,7 @@ struct lp55xx_device_config {
120121
const struct lp55xx_reg enable;
121122
const struct lp55xx_reg prog_mem_base;
122123
const struct lp55xx_reg reg_led_pwm_base;
124+
const struct lp55xx_reg reg_led_current_base;
123125
const int pages_per_engine;
124126
const int max_channel;
125127

@@ -217,6 +219,7 @@ extern int lp55xx_update_program_memory(struct lp55xx_chip *chip,
217219
extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip);
218220
extern int lp55xx_led_brightness(struct lp55xx_led *led);
219221
extern int lp55xx_multicolor_brightness(struct lp55xx_led *led);
222+
extern void lp55xx_set_led_current(struct lp55xx_led *led, u8 led_current);
220223

221224
/* common probe/remove function */
222225
extern int lp55xx_probe(struct i2c_client *client);

drivers/leds/leds-lp8501.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ static inline void lp8501_wait_opmode_done(void)
8484
usleep_range(1000, 2000);
8585
}
8686

87-
static void lp8501_set_led_current(struct lp55xx_led *led, u8 led_current)
88-
{
89-
led->led_current = led_current;
90-
lp55xx_write(led->chip, LP8501_REG_LED_CURRENT_BASE + led->chan_nr,
91-
led_current);
92-
}
93-
9487
static int lp8501_post_init_device(struct lp55xx_chip *chip)
9588
{
9689
int ret;
@@ -163,11 +156,14 @@ static struct lp55xx_device_config lp8501_cfg = {
163156
.reg_led_pwm_base = {
164157
.addr = LP8501_REG_LED_PWM_BASE,
165158
},
159+
.reg_led_current_base = {
160+
.addr = LP8501_REG_LED_CURRENT_BASE,
161+
},
166162
.pages_per_engine = LP8501_PAGES_PER_ENGINE,
167163
.max_channel = LP8501_MAX_LEDS,
168164
.post_init_device = lp8501_post_init_device,
169165
.brightness_fn = lp55xx_led_brightness,
170-
.set_led_current = lp8501_set_led_current,
166+
.set_led_current = lp55xx_set_led_current,
171167
.firmware_cb = lp55xx_firmware_loaded_cb,
172168
.run_engine = lp8501_run_engine,
173169
};

0 commit comments

Comments
 (0)