Skip to content

Commit 43e91e5

Browse files
Ansuellag-linaro
authored andcommitted
leds: leds-lp55xx: Generalize stop_engine function
Generalize stop_engine 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 e35bc5d commit 43e91e5

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

drivers/leds/leds-lp5521.c

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

111-
static void lp5521_stop_engine(struct lp55xx_chip *chip)
112-
{
113-
enum lp55xx_engine_index idx = chip->engine_idx;
114-
static const u8 mask[] = {
115-
[LP55XX_ENGINE_1] = LP5521_MODE_R_M,
116-
[LP55XX_ENGINE_2] = LP5521_MODE_G_M,
117-
[LP55XX_ENGINE_3] = LP5521_MODE_B_M,
118-
};
119-
120-
lp55xx_update_bits(chip, LP5521_REG_OP_MODE, mask[idx], 0);
121-
122-
lp5521_wait_opmode_done();
123-
}
124-
125111
static void lp5521_run_engine(struct lp55xx_chip *chip, bool start)
126112
{
127113
int ret;
128114

129115
/* stop engine */
130116
if (!start) {
131-
lp5521_stop_engine(chip);
117+
lp55xx_stop_engine(chip);
132118
lp55xx_write(chip, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT);
133119
lp5521_wait_opmode_done();
134120
return;
@@ -253,11 +239,11 @@ static ssize_t store_engine_mode(struct device *dev,
253239
lp5521_run_engine(chip, true);
254240
engine->mode = LP55XX_ENGINE_RUN;
255241
} else if (!strncmp(buf, "load", 4)) {
256-
lp5521_stop_engine(chip);
242+
lp55xx_stop_engine(chip);
257243
lp55xx_load_engine(chip);
258244
engine->mode = LP55XX_ENGINE_LOAD;
259245
} else if (!strncmp(buf, "disabled", 8)) {
260-
lp5521_stop_engine(chip);
246+
lp55xx_stop_engine(chip);
261247
engine->mode = LP55XX_ENGINE_DISABLED;
262248
}
263249

drivers/leds/leds-lp5523.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,11 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip)
153153
return lp5523_init_program_engine(chip);
154154
}
155155

156-
static void lp5523_stop_engine(struct lp55xx_chip *chip)
157-
{
158-
enum lp55xx_engine_index idx = chip->engine_idx;
159-
static const u8 mask[] = {
160-
[LP55XX_ENGINE_1] = LP5523_MODE_ENG1_M,
161-
[LP55XX_ENGINE_2] = LP5523_MODE_ENG2_M,
162-
[LP55XX_ENGINE_3] = LP5523_MODE_ENG3_M,
163-
};
164-
165-
lp55xx_update_bits(chip, LP5523_REG_OP_MODE, mask[idx], 0);
166-
167-
lp5523_wait_opmode_done();
168-
}
169-
170156
static void lp5523_run_engine(struct lp55xx_chip *chip, bool start)
171157
{
172158
/* stop engine */
173159
if (!start) {
174-
lp5523_stop_engine(chip);
160+
lp55xx_stop_engine(chip);
175161
lp55xx_turn_off_channels(chip);
176162
return;
177163
}
@@ -277,11 +263,11 @@ static ssize_t store_engine_mode(struct device *dev,
277263
lp5523_run_engine(chip, true);
278264
engine->mode = LP55XX_ENGINE_RUN;
279265
} else if (!strncmp(buf, "load", 4)) {
280-
lp5523_stop_engine(chip);
266+
lp55xx_stop_engine(chip);
281267
lp55xx_load_engine(chip);
282268
engine->mode = LP55XX_ENGINE_LOAD;
283269
} else if (!strncmp(buf, "disabled", 8)) {
284-
lp5523_stop_engine(chip);
270+
lp55xx_stop_engine(chip);
285271
engine->mode = LP55XX_ENGINE_DISABLED;
286272
}
287273

drivers/leds/leds-lp55xx-common.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ void lp55xx_turn_off_channels(struct lp55xx_chip *chip)
298298
}
299299
EXPORT_SYMBOL_GPL(lp55xx_turn_off_channels);
300300

301+
void lp55xx_stop_engine(struct lp55xx_chip *chip)
302+
{
303+
enum lp55xx_engine_index idx = chip->engine_idx;
304+
const struct lp55xx_device_config *cfg = chip->cfg;
305+
u8 mask;
306+
307+
mask = LP55xx_MODE_ENGn_MASK(idx, cfg->reg_op_mode.shift);
308+
lp55xx_update_bits(chip, cfg->reg_op_mode.addr, mask, 0);
309+
310+
lp55xx_wait_opmode_done(chip);
311+
}
312+
EXPORT_SYMBOL_GPL(lp55xx_stop_engine);
313+
301314
static void lp55xx_reset_device(struct lp55xx_chip *chip)
302315
{
303316
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
@@ -221,6 +221,7 @@ extern int lp55xx_led_brightness(struct lp55xx_led *led);
221221
extern int lp55xx_multicolor_brightness(struct lp55xx_led *led);
222222
extern void lp55xx_set_led_current(struct lp55xx_led *led, u8 led_current);
223223
extern void lp55xx_turn_off_channels(struct lp55xx_chip *chip);
224+
extern void lp55xx_stop_engine(struct lp55xx_chip *chip);
224225

225226
/* common probe/remove function */
226227
extern int lp55xx_probe(struct i2c_client *client);

0 commit comments

Comments
 (0)