]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
leds: lp5562: Add multicolor brightness control
authorMichal Vokáč <michal.vokac@ysoft.com>
Wed, 9 Oct 2024 09:56:35 +0000 (11:56 +0200)
committerLee Jones <lee@kernel.org>
Tue, 15 Oct 2024 11:58:41 +0000 (12:58 +0100)
The framework for multicolor brightness control is already in place
in the lp55xx-common code but the function to control the multicolor
brightness for this particular chip is still missing.

Implement the multicolor_brightness_fn function to allow multicolor
brightness control of LEDs connected to the LP5562 LED driver.

Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com>
Link: https://lore.kernel.org/r/20241009095635.2790613-1-michal.vokac@ysoft.com
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/leds/leds-lp5562.c

index b26bcc81d079797d6ec868ed492e134b755a6b16..14a4af361b267697d30976e61ad6cfe59dd8dd4b 100644 (file)
@@ -161,6 +161,30 @@ static int lp5562_post_init_device(struct lp55xx_chip *chip)
        return 0;
 }
 
+static int lp5562_multicolor_brightness(struct lp55xx_led *led)
+{
+       struct lp55xx_chip *chip = led->chip;
+       static const u8 addr[] = {
+               LP5562_REG_R_PWM,
+               LP5562_REG_G_PWM,
+               LP5562_REG_B_PWM,
+               LP5562_REG_W_PWM,
+       };
+       int ret;
+       int i;
+
+       guard(mutex)(&chip->lock);
+       for (i = 0; i < led->mc_cdev.num_colors; i++) {
+               ret = lp55xx_write(chip,
+                                  addr[led->mc_cdev.subled_info[i].channel],
+                                  led->mc_cdev.subled_info[i].brightness);
+               if (ret)
+                       break;
+       }
+
+       return ret;
+}
+
 static int lp5562_led_brightness(struct lp55xx_led *led)
 {
        struct lp55xx_chip *chip = led->chip;
@@ -364,6 +388,7 @@ static struct lp55xx_device_config lp5562_cfg = {
        .post_init_device   = lp5562_post_init_device,
        .set_led_current    = lp5562_set_led_current,
        .brightness_fn      = lp5562_led_brightness,
+       .multicolor_brightness_fn = lp5562_multicolor_brightness,
        .run_engine         = lp5562_run_engine,
        .firmware_cb        = lp55xx_firmware_loaded_cb,
        .dev_attr_group     = &lp5562_group,