led: Only report auto control for supported LEDs.
BRANCH=None
TEST=make -j buildall
Commit-Ready: Aseda Aboagye
Tested-by: Aseda Aboagye
@@ -19,12 +19,16 @@ static uint32_t led_auto_control_flags = ~0x00;
static int led_is_supported(enum ec_led_id led_id)
{
int i;
+ static int supported_leds = -1;
+
+ if (supported_leds == -1) {
+ supported_leds = 0;
for (i = 0; i < supported_led_ids_count; i++)
- if (led_id == supported_led_ids[i])
- return 1;
+ supported_leds |= (1 << supported_led_ids[i]);
+ }
- return 0;
+ return ((1 << (int)led_id) & supported_leds);
}
void led_auto_control(enum ec_led_id led_id, int enable)
@@ -37,6 +41,9 @@ void led_auto_control(enum ec_led_id led_id, int enable)
int led_auto_control_is_enabled(enum ec_led_id led_id)
{
+ if (!led_is_supported(led_id))
+ return 0;
+
return (led_auto_control_flags & LED_AUTO_CONTROL_FLAG(led_id)) != 0;
}
