]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
leds: leds-lp55xx: Generalize stop_engine function
authorChristian Marangi <ansuelsmth@gmail.com>
Wed, 26 Jun 2024 16:00:19 +0000 (18:00 +0200)
committerLee Jones <lee@kernel.org>
Wed, 26 Jun 2024 16:08:31 +0000 (17:08 +0100)
Generalize stop_engine function as the implementation is the same for
most of the lp55xx based LED driver.

Suggested-by: Lee Jones <lee@kernel.org>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Link: https://lore.kernel.org/r/20240626160027.19703-15-ansuelsmth@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/leds/leds-lp5521.c
drivers/leds/leds-lp5523.c
drivers/leds/leds-lp55xx-common.c
drivers/leds/leds-lp55xx-common.h

index a1a3bf0ff7039fa254e21291bd19898eb911d1e3..4afae0c70d19053692bd1a53ba9acb06f466583b 100644 (file)
@@ -108,27 +108,13 @@ static inline void lp5521_wait_enable_done(void)
        usleep_range(500, 600);
 }
 
-static void lp5521_stop_engine(struct lp55xx_chip *chip)
-{
-       enum lp55xx_engine_index idx = chip->engine_idx;
-       static const u8 mask[] = {
-               [LP55XX_ENGINE_1] = LP5521_MODE_R_M,
-               [LP55XX_ENGINE_2] = LP5521_MODE_G_M,
-               [LP55XX_ENGINE_3] = LP5521_MODE_B_M,
-       };
-
-       lp55xx_update_bits(chip, LP5521_REG_OP_MODE, mask[idx], 0);
-
-       lp5521_wait_opmode_done();
-}
-
 static void lp5521_run_engine(struct lp55xx_chip *chip, bool start)
 {
        int ret;
 
        /* stop engine */
        if (!start) {
-               lp5521_stop_engine(chip);
+               lp55xx_stop_engine(chip);
                lp55xx_write(chip, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT);
                lp5521_wait_opmode_done();
                return;
@@ -253,11 +239,11 @@ static ssize_t store_engine_mode(struct device *dev,
                lp5521_run_engine(chip, true);
                engine->mode = LP55XX_ENGINE_RUN;
        } else if (!strncmp(buf, "load", 4)) {
-               lp5521_stop_engine(chip);
+               lp55xx_stop_engine(chip);
                lp55xx_load_engine(chip);
                engine->mode = LP55XX_ENGINE_LOAD;
        } else if (!strncmp(buf, "disabled", 8)) {
-               lp5521_stop_engine(chip);
+               lp55xx_stop_engine(chip);
                engine->mode = LP55XX_ENGINE_DISABLED;
        }
 
index 4a4463cb44a4b206750496e4fae942912299157c..1dd909a0fff52ea01a7ca2a3500d2e7e771f9b27 100644 (file)
@@ -153,25 +153,11 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip)
        return lp5523_init_program_engine(chip);
 }
 
-static void lp5523_stop_engine(struct lp55xx_chip *chip)
-{
-       enum lp55xx_engine_index idx = chip->engine_idx;
-       static const u8 mask[] = {
-               [LP55XX_ENGINE_1] = LP5523_MODE_ENG1_M,
-               [LP55XX_ENGINE_2] = LP5523_MODE_ENG2_M,
-               [LP55XX_ENGINE_3] = LP5523_MODE_ENG3_M,
-       };
-
-       lp55xx_update_bits(chip, LP5523_REG_OP_MODE, mask[idx], 0);
-
-       lp5523_wait_opmode_done();
-}
-
 static void lp5523_run_engine(struct lp55xx_chip *chip, bool start)
 {
        /* stop engine */
        if (!start) {
-               lp5523_stop_engine(chip);
+               lp55xx_stop_engine(chip);
                lp55xx_turn_off_channels(chip);
                return;
        }
@@ -277,11 +263,11 @@ static ssize_t store_engine_mode(struct device *dev,
                lp5523_run_engine(chip, true);
                engine->mode = LP55XX_ENGINE_RUN;
        } else if (!strncmp(buf, "load", 4)) {
-               lp5523_stop_engine(chip);
+               lp55xx_stop_engine(chip);
                lp55xx_load_engine(chip);
                engine->mode = LP55XX_ENGINE_LOAD;
        } else if (!strncmp(buf, "disabled", 8)) {
-               lp5523_stop_engine(chip);
+               lp55xx_stop_engine(chip);
                engine->mode = LP55XX_ENGINE_DISABLED;
        }
 
index 58121f27f17bb5418eadcae96609f37d08393e53..cecff34e6e150b49c8ac4a4fc02243fe9c03c3a4 100644 (file)
@@ -298,6 +298,19 @@ void lp55xx_turn_off_channels(struct lp55xx_chip *chip)
 }
 EXPORT_SYMBOL_GPL(lp55xx_turn_off_channels);
 
+void lp55xx_stop_engine(struct lp55xx_chip *chip)
+{
+       enum lp55xx_engine_index idx = chip->engine_idx;
+       const struct lp55xx_device_config *cfg = chip->cfg;
+       u8 mask;
+
+       mask = LP55xx_MODE_ENGn_MASK(idx, cfg->reg_op_mode.shift);
+       lp55xx_update_bits(chip, cfg->reg_op_mode.addr, mask, 0);
+
+       lp55xx_wait_opmode_done(chip);
+}
+EXPORT_SYMBOL_GPL(lp55xx_stop_engine);
+
 static void lp55xx_reset_device(struct lp55xx_chip *chip)
 {
        const struct lp55xx_device_config *cfg = chip->cfg;
index 531fbb0acb2e040ff64fba5612f57d4d99adaf86..0aba6955a3af327562b79c7453c9e73f5c0874ab 100644 (file)
@@ -221,6 +221,7 @@ extern int lp55xx_led_brightness(struct lp55xx_led *led);
 extern int lp55xx_multicolor_brightness(struct lp55xx_led *led);
 extern void lp55xx_set_led_current(struct lp55xx_led *led, u8 led_current);
 extern void lp55xx_turn_off_channels(struct lp55xx_chip *chip);
+extern void lp55xx_stop_engine(struct lp55xx_chip *chip);
 
 /* common probe/remove function */
 extern int lp55xx_probe(struct i2c_client *client);