Skip to content

Commit c63580b

Browse files
Ansuellag-linaro
authored andcommitted
leds: leds-lp55xx: Generalize led_brightness function
Generalize led_brightness function as the implementation is the same for most of the lp55xx based LED driver. Introduce a new option in device_config, reg_led_pwm_base since the reg value is not the same for every LED chip. 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 a3df190 commit c63580b

File tree

5 files changed

+29
-41
lines changed

5 files changed

+29
-41
lines changed

drivers/leds/leds-lp5521.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,6 @@ static int lp5521_multicolor_brightness(struct lp55xx_led *led)
241241
return ret;
242242
}
243243

244-
static int lp5521_led_brightness(struct lp55xx_led *led)
245-
{
246-
struct lp55xx_chip *chip = led->chip;
247-
int ret;
248-
249-
mutex_lock(&chip->lock);
250-
ret = lp55xx_write(chip, LP5521_REG_LED_PWM_BASE + led->chan_nr,
251-
led->brightness);
252-
mutex_unlock(&chip->lock);
253-
254-
return ret;
255-
}
256-
257244
static ssize_t show_engine_mode(struct device *dev,
258245
struct device_attribute *attr,
259246
char *buf, int nr)
@@ -388,9 +375,12 @@ static struct lp55xx_device_config lp5521_cfg = {
388375
.prog_mem_base = {
389376
.addr = LP5521_REG_R_PROG_MEM,
390377
},
378+
.reg_led_pwm_base = {
379+
.addr = LP5521_REG_LED_PWM_BASE,
380+
},
391381
.max_channel = LP5521_MAX_LEDS,
392382
.post_init_device = lp5521_post_init_device,
393-
.brightness_fn = lp5521_led_brightness,
383+
.brightness_fn = lp55xx_led_brightness,
394384
.multicolor_brightness_fn = lp5521_multicolor_brightness,
395385
.set_led_current = lp5521_set_led_current,
396386
.firmware_cb = lp55xx_firmware_loaded_cb,

drivers/leds/leds-lp5523.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -683,18 +683,6 @@ static int lp5523_multicolor_brightness(struct lp55xx_led *led)
683683
return ret;
684684
}
685685

686-
static int lp5523_led_brightness(struct lp55xx_led *led)
687-
{
688-
struct lp55xx_chip *chip = led->chip;
689-
int ret;
690-
691-
mutex_lock(&chip->lock);
692-
ret = lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + led->chan_nr,
693-
led->brightness);
694-
mutex_unlock(&chip->lock);
695-
return ret;
696-
}
697-
698686
static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode);
699687
static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode);
700688
static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode);
@@ -759,10 +747,13 @@ static struct lp55xx_device_config lp5523_cfg = {
759747
.prog_mem_base = {
760748
.addr = LP5523_REG_PROG_MEM,
761749
},
750+
.reg_led_pwm_base = {
751+
.addr = LP5523_REG_LED_PWM_BASE,
752+
},
762753
.pages_per_engine = LP5523_PAGES_PER_ENGINE,
763754
.max_channel = LP5523_MAX_LEDS,
764755
.post_init_device = lp5523_post_init_device,
765-
.brightness_fn = lp5523_led_brightness,
756+
.brightness_fn = lp55xx_led_brightness,
766757
.multicolor_brightness_fn = lp5523_multicolor_brightness,
767758
.set_led_current = lp5523_set_led_current,
768759
.firmware_cb = lp55xx_firmware_loaded_cb,

drivers/leds/leds-lp55xx-common.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,20 @@ void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip)
242242
}
243243
EXPORT_SYMBOL_GPL(lp55xx_firmware_loaded_cb);
244244

245+
int lp55xx_led_brightness(struct lp55xx_led *led)
246+
{
247+
struct lp55xx_chip *chip = led->chip;
248+
const struct lp55xx_device_config *cfg = chip->cfg;
249+
int ret;
250+
251+
mutex_lock(&chip->lock);
252+
ret = lp55xx_write(chip, cfg->reg_led_pwm_base.addr + led->chan_nr,
253+
led->brightness);
254+
mutex_unlock(&chip->lock);
255+
return ret;
256+
}
257+
EXPORT_SYMBOL_GPL(lp55xx_led_brightness);
258+
245259
static void lp55xx_reset_device(struct lp55xx_chip *chip)
246260
{
247261
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
@@ -100,6 +100,7 @@ struct lp55xx_reg {
100100
* @reset : Chip specific reset command
101101
* @enable : Chip specific enable command
102102
* @prog_mem_base : Chip specific base reg address for chip SMEM programming
103+
* @reg_led_pwm_base : Chip specific base reg address for LED PWM conf
103104
* @pages_per_engine : Assigned pages for each engine
104105
* (if not set chip doesn't support pages)
105106
* @max_channel : Maximum number of channels
@@ -118,6 +119,7 @@ struct lp55xx_device_config {
118119
const struct lp55xx_reg reset;
119120
const struct lp55xx_reg enable;
120121
const struct lp55xx_reg prog_mem_base;
122+
const struct lp55xx_reg reg_led_pwm_base;
121123
const int pages_per_engine;
122124
const int max_channel;
123125

@@ -213,6 +215,7 @@ extern int lp55xx_run_engine_common(struct lp55xx_chip *chip);
213215
extern int lp55xx_update_program_memory(struct lp55xx_chip *chip,
214216
const u8 *data, size_t size);
215217
extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip);
218+
extern int lp55xx_led_brightness(struct lp55xx_led *led);
216219

217220
/* common probe/remove function */
218221
extern int lp55xx_probe(struct i2c_client *client);

drivers/leds/leds-lp8501.c

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

140-
static int lp8501_led_brightness(struct lp55xx_led *led)
141-
{
142-
struct lp55xx_chip *chip = led->chip;
143-
int ret;
144-
145-
mutex_lock(&chip->lock);
146-
ret = lp55xx_write(chip, LP8501_REG_LED_PWM_BASE + led->chan_nr,
147-
led->brightness);
148-
mutex_unlock(&chip->lock);
149-
150-
return ret;
151-
}
152-
153140
/* Chip specific configurations */
154141
static struct lp55xx_device_config lp8501_cfg = {
155142
.reg_op_mode = {
@@ -173,10 +160,13 @@ static struct lp55xx_device_config lp8501_cfg = {
173160
.prog_mem_base = {
174161
.addr = LP8501_REG_PROG_MEM,
175162
},
163+
.reg_led_pwm_base = {
164+
.addr = LP8501_REG_LED_PWM_BASE,
165+
},
176166
.pages_per_engine = LP8501_PAGES_PER_ENGINE,
177167
.max_channel = LP8501_MAX_LEDS,
178168
.post_init_device = lp8501_post_init_device,
179-
.brightness_fn = lp8501_led_brightness,
169+
.brightness_fn = lp55xx_led_brightness,
180170
.set_led_current = lp8501_set_led_current,
181171
.firmware_cb = lp55xx_firmware_loaded_cb,
182172
.run_engine = lp8501_run_engine,

0 commit comments

Comments
 (0)