Skip to content

Commit 794826b

Browse files
Ansuellag-linaro
authored andcommitted
leds: leds-lp55xx: Generalize multicolor_brightness function
Generalize multicolor_brightness 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 c63580b commit 794826b

File tree

4 files changed

+24
-40
lines changed

4 files changed

+24
-40
lines changed

drivers/leds/leds-lp5521.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,25 +222,6 @@ static int lp5521_run_selftest(struct lp55xx_chip *chip, char *buf)
222222
return 0;
223223
}
224224

225-
static int lp5521_multicolor_brightness(struct lp55xx_led *led)
226-
{
227-
struct lp55xx_chip *chip = led->chip;
228-
int ret;
229-
int i;
230-
231-
mutex_lock(&chip->lock);
232-
for (i = 0; i < led->mc_cdev.num_colors; i++) {
233-
ret = lp55xx_write(chip,
234-
LP5521_REG_LED_PWM_BASE +
235-
led->mc_cdev.subled_info[i].channel,
236-
led->mc_cdev.subled_info[i].brightness);
237-
if (ret)
238-
break;
239-
}
240-
mutex_unlock(&chip->lock);
241-
return ret;
242-
}
243-
244225
static ssize_t show_engine_mode(struct device *dev,
245226
struct device_attribute *attr,
246227
char *buf, int nr)
@@ -381,7 +362,7 @@ static struct lp55xx_device_config lp5521_cfg = {
381362
.max_channel = LP5521_MAX_LEDS,
382363
.post_init_device = lp5521_post_init_device,
383364
.brightness_fn = lp55xx_led_brightness,
384-
.multicolor_brightness_fn = lp5521_multicolor_brightness,
365+
.multicolor_brightness_fn = lp55xx_multicolor_brightness,
385366
.set_led_current = lp5521_set_led_current,
386367
.firmware_cb = lp55xx_firmware_loaded_cb,
387368
.run_engine = lp5521_run_engine,

drivers/leds/leds-lp5523.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -664,25 +664,6 @@ static ssize_t store_master_fader_leds(struct device *dev,
664664
return ret;
665665
}
666666

667-
static int lp5523_multicolor_brightness(struct lp55xx_led *led)
668-
{
669-
struct lp55xx_chip *chip = led->chip;
670-
int ret;
671-
int i;
672-
673-
mutex_lock(&chip->lock);
674-
for (i = 0; i < led->mc_cdev.num_colors; i++) {
675-
ret = lp55xx_write(chip,
676-
LP5523_REG_LED_PWM_BASE +
677-
led->mc_cdev.subled_info[i].channel,
678-
led->mc_cdev.subled_info[i].brightness);
679-
if (ret)
680-
break;
681-
}
682-
mutex_unlock(&chip->lock);
683-
return ret;
684-
}
685-
686667
static LP55XX_DEV_ATTR_RW(engine1_mode, show_engine1_mode, store_engine1_mode);
687668
static LP55XX_DEV_ATTR_RW(engine2_mode, show_engine2_mode, store_engine2_mode);
688669
static LP55XX_DEV_ATTR_RW(engine3_mode, show_engine3_mode, store_engine3_mode);
@@ -754,7 +735,7 @@ static struct lp55xx_device_config lp5523_cfg = {
754735
.max_channel = LP5523_MAX_LEDS,
755736
.post_init_device = lp5523_post_init_device,
756737
.brightness_fn = lp55xx_led_brightness,
757-
.multicolor_brightness_fn = lp5523_multicolor_brightness,
738+
.multicolor_brightness_fn = lp55xx_multicolor_brightness,
758739
.set_led_current = lp5523_set_led_current,
759740
.firmware_cb = lp55xx_firmware_loaded_cb,
760741
.run_engine = lp5523_run_engine,

drivers/leds/leds-lp55xx-common.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,27 @@ int lp55xx_led_brightness(struct lp55xx_led *led)
256256
}
257257
EXPORT_SYMBOL_GPL(lp55xx_led_brightness);
258258

259+
int lp55xx_multicolor_brightness(struct lp55xx_led *led)
260+
{
261+
struct lp55xx_chip *chip = led->chip;
262+
const struct lp55xx_device_config *cfg = chip->cfg;
263+
int ret;
264+
int i;
265+
266+
mutex_lock(&chip->lock);
267+
for (i = 0; i < led->mc_cdev.num_colors; i++) {
268+
ret = lp55xx_write(chip,
269+
cfg->reg_led_pwm_base.addr +
270+
led->mc_cdev.subled_info[i].channel,
271+
led->mc_cdev.subled_info[i].brightness);
272+
if (ret)
273+
break;
274+
}
275+
mutex_unlock(&chip->lock);
276+
return ret;
277+
}
278+
EXPORT_SYMBOL_GPL(lp55xx_multicolor_brightness);
279+
259280
static void lp55xx_reset_device(struct lp55xx_chip *chip)
260281
{
261282
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
@@ -216,6 +216,7 @@ extern int lp55xx_update_program_memory(struct lp55xx_chip *chip,
216216
const u8 *data, size_t size);
217217
extern void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip);
218218
extern int lp55xx_led_brightness(struct lp55xx_led *led);
219+
extern int lp55xx_multicolor_brightness(struct lp55xx_led *led);
219220

220221
/* common probe/remove function */
221222
extern int lp55xx_probe(struct i2c_client *client);

0 commit comments

Comments
 (0)