Skip to content

Commit 645beff

Browse files
cx-anuj-pathakcarlescufi
authored andcommitted
drivers: led: lp5562: reuse engine already linked
Right now "lp5562_led_blink" unconditionally find and assign a engine that is not executing at the moment. This is an issue, if 3 "led" are already using an engine. That is a call to "lp5562_led_blink" could terminate with error, even if the "led" is already using an engine. This commit fixes this issue by adding a check to see if engine is linked and reuse it, otherwise assign a free engine. Signed-off-by: Anuj Pathak <[email protected]>
1 parent 7f3c08b commit 645beff

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

drivers/led/lp5562.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,27 @@ static int lp5562_led_blink(const struct device *dev, uint32_t led,
769769
enum lp5562_led_sources engine;
770770
uint8_t command_index = 0U;
771771

772-
ret = lp5562_get_available_engine(dev, &engine);
772+
/*
773+
* Read current "led" source setting. This is to check
774+
* whether the "led" is in PWM mode or using an Engine.
775+
*/
776+
ret = lp5562_get_led_source(dev, led, &engine);
773777
if (ret) {
774778
return ret;
775779
}
776780

777-
ret = lp5562_set_led_source(dev, led, engine);
778-
if (ret) {
779-
LOG_ERR("Failed to set LED source.");
780-
return ret;
781+
/* Find and assign new engine only if the "led" is not using any. */
782+
if (engine == LP5562_SOURCE_PWM) {
783+
ret = lp5562_get_available_engine(dev, &engine);
784+
if (ret) {
785+
return ret;
786+
}
787+
788+
ret = lp5562_set_led_source(dev, led, engine);
789+
if (ret) {
790+
LOG_ERR("Failed to set LED source.");
791+
return ret;
792+
}
781793
}
782794

783795
ret = lp5562_set_engine_op_mode(dev, engine, LP5562_OP_MODE_LOAD);

0 commit comments

Comments
 (0)