summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--baseboard/volteer/led.c9
-rw-r--r--board/atlas/led.c16
-rw-r--r--board/dragonegg/led.c8
-rw-r--r--board/grunt/led.c9
-rw-r--r--board/liara/led.c9
-rw-r--r--board/nocturne/led.c16
-rw-r--r--common/led_pwm.c27
-rw-r--r--include/led_pwm.h9
8 files changed, 64 insertions, 39 deletions
diff --git a/baseboard/volteer/led.c b/baseboard/volteer/led.c
index a6b533d8a7..3d67b7a394 100644
--- a/baseboard/volteer/led.c
+++ b/baseboard/volteer/led.c
@@ -9,6 +9,7 @@
#include "ec_commands.h"
#include "led_common.h"
#include "led_pwm.h"
+#include "pwm.h"
const enum ec_led_id supported_led_ids[] = {
EC_LED_ID_POWER_LED,
@@ -31,9 +32,11 @@ struct pwm_led led_color_map[] = {
struct pwm_led pwm_leds[] = {
/* 2 RGB diffusers controlled by 1 set of 3 channels. */
[PWM_LED0] = {
- PWM_CH_LED3_RED,
- PWM_CH_LED2_GREEN,
- PWM_CH_LED1_BLUE,
+ .ch0 = PWM_CH_LED3_RED,
+ .ch1 = PWM_CH_LED2_GREEN,
+ .ch2 = PWM_CH_LED1_BLUE,
+ .enable = &pwm_enable,
+ .set_duty = &pwm_set_duty,
},
};
diff --git a/board/atlas/led.c b/board/atlas/led.c
index 74568e9af2..ec46d9d206 100644
--- a/board/atlas/led.c
+++ b/board/atlas/led.c
@@ -35,15 +35,19 @@ struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = {
struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = {
[PWM_LED0] = {
/* left port LEDs */
- PWM_CH_DB1_LED_RED,
- PWM_CH_DB1_LED_GREEN,
- PWM_CH_DB1_LED_BLUE,
+ .ch0 = PWM_CH_DB1_LED_RED,
+ .ch1 = PWM_CH_DB1_LED_GREEN,
+ .ch2 = PWM_CH_DB1_LED_BLUE,
+ .enable = &pwm_enable,
+ .set_duty = &pwm_set_duty,
},
[PWM_LED1] = {
/* right port LEDs */
- PWM_CH_DB0_LED_RED,
- PWM_CH_DB0_LED_GREEN,
- PWM_CH_DB0_LED_BLUE,
+ .ch0 = PWM_CH_DB0_LED_RED,
+ .ch1 = PWM_CH_DB0_LED_GREEN,
+ .ch2 = PWM_CH_DB0_LED_BLUE,
+ .enable = &pwm_enable,
+ .set_duty = &pwm_set_duty,
},
};
diff --git a/board/dragonegg/led.c b/board/dragonegg/led.c
index 961e65f953..45e944619d 100644
--- a/board/dragonegg/led.c
+++ b/board/dragonegg/led.c
@@ -33,9 +33,11 @@ struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = {
struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = {
[PWM_LED0] = {
/* left port LEDs */
- PWM_CH_LED_RED,
- PWM_CH_LED_GREEN,
- PWM_CH_LED_BLUE,
+ .ch0 = PWM_CH_LED_RED,
+ .ch1 = PWM_CH_LED_GREEN,
+ .ch2 = PWM_CH_LED_BLUE,
+ .enable = &pwm_enable,
+ .set_duty = &pwm_set_duty,
},
};
diff --git a/board/grunt/led.c b/board/grunt/led.c
index fc6f427cd2..9cd1122665 100644
--- a/board/grunt/led.c
+++ b/board/grunt/led.c
@@ -6,6 +6,7 @@
#include "common.h"
#include "ec_commands.h"
#include "led_pwm.h"
+#include "pwm.h"
#include "util.h"
const enum ec_led_id supported_led_ids[] = {
@@ -30,9 +31,11 @@ struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = {
/* One logical LED with amber and blue channels. */
struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = {
{
- PWM_CH_LED1_AMBER,
- PWM_CH_LED2_BLUE,
- PWM_LED_NO_CHANNEL,
+ .ch0 = PWM_CH_LED1_AMBER,
+ .ch1 = PWM_CH_LED2_BLUE,
+ .ch2 = PWM_LED_NO_CHANNEL,
+ .enable = &pwm_enable,
+ .set_duty = &pwm_set_duty,
},
};
diff --git a/board/liara/led.c b/board/liara/led.c
index 7451c4b72e..8efb6150fc 100644
--- a/board/liara/led.c
+++ b/board/liara/led.c
@@ -6,6 +6,7 @@
#include "common.h"
#include "ec_commands.h"
#include "led_pwm.h"
+#include "pwm.h"
#include "util.h"
const enum ec_led_id supported_led_ids[] = {
@@ -30,9 +31,11 @@ struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = {
/* One logical LED with amber and blue channels. */
struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = {
{
- PWM_CH_LED1_WHITE,
- PWM_CH_LED2_AMBER,
- PWM_LED_NO_CHANNEL,
+ .ch0 = PWM_CH_LED1_WHITE,
+ .ch1 = PWM_CH_LED2_AMBER,
+ .ch2 = PWM_LED_NO_CHANNEL,
+ .enable = &pwm_enable,
+ .set_duty = &pwm_set_duty,
},
};
diff --git a/board/nocturne/led.c b/board/nocturne/led.c
index 993e0c4c1a..7489fe7289 100644
--- a/board/nocturne/led.c
+++ b/board/nocturne/led.c
@@ -30,15 +30,19 @@ struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = {
/* Two tri-color LEDs with red, green, and blue channels. */
struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = {
{
- PWM_CH_DB0_LED_RED,
- PWM_CH_DB0_LED_GREEN,
- PWM_CH_DB0_LED_BLUE,
+ .ch0 = PWM_CH_DB0_LED_RED,
+ .ch1 = PWM_CH_DB0_LED_GREEN,
+ .ch2 = PWM_CH_DB0_LED_BLUE,
+ .enable = &pwm_enable,
+ .set_duty = &pwm_set_duty,
},
{
- PWM_CH_DB1_LED_RED,
- PWM_CH_DB1_LED_GREEN,
- PWM_CH_DB1_LED_BLUE,
+ .ch0 = PWM_CH_DB1_LED_RED,
+ .ch1 = PWM_CH_DB1_LED_GREEN,
+ .ch2 = PWM_CH_DB1_LED_BLUE,
+ .enable = &pwm_enable,
+ .set_duty = &pwm_set_duty,
},
};
diff --git a/common/led_pwm.c b/common/led_pwm.c
index dd8f33a137..b9aeb1e805 100644
--- a/common/led_pwm.c
+++ b/common/led_pwm.c
@@ -55,6 +55,7 @@ static int get_led_id_color(enum pwm_led_id id, int color)
void set_pwm_led_color(enum pwm_led_id id, int color)
{
struct pwm_led duty = { 0 };
+ const struct pwm_led *led = &pwm_leds[id];
if ((id >= CONFIG_LED_PWM_COUNT) || (id < 0) ||
(color >= EC_LED_COLOR_COUNT) || (color < -1))
@@ -66,12 +67,12 @@ void set_pwm_led_color(enum pwm_led_id id, int color)
duty.ch2 = led_color_map[color].ch2;
}
- if (pwm_leds[id].ch0 != PWM_LED_NO_CHANNEL)
- pwm_set_duty(pwm_leds[id].ch0, duty.ch0);
- if (pwm_leds[id].ch1 != PWM_LED_NO_CHANNEL)
- pwm_set_duty(pwm_leds[id].ch1, duty.ch1);
- if (pwm_leds[id].ch2 != PWM_LED_NO_CHANNEL)
- pwm_set_duty(pwm_leds[id].ch2, duty.ch2);
+ if (led->ch0 != PWM_LED_NO_CHANNEL)
+ led->set_duty(led->ch0, duty.ch0);
+ if (led->ch1 != PWM_LED_NO_CHANNEL)
+ led->set_duty(led->ch1, duty.ch1);
+ if (led->ch2 != PWM_LED_NO_CHANNEL)
+ led->set_duty(led->ch2, duty.ch2);
}
static void set_led_color(int color)
@@ -92,15 +93,17 @@ static void set_led_color(int color)
static void set_pwm_led_enable(enum pwm_led_id id, int enable)
{
+ const struct pwm_led *led = &pwm_leds[id];
+
if ((id >= CONFIG_LED_PWM_COUNT) || (id < 0))
return;
- if (pwm_leds[id].ch0 != PWM_LED_NO_CHANNEL)
- pwm_enable(pwm_leds[id].ch0, enable);
- if (pwm_leds[id].ch1 != PWM_LED_NO_CHANNEL)
- pwm_enable(pwm_leds[id].ch1, enable);
- if (pwm_leds[id].ch2 != PWM_LED_NO_CHANNEL)
- pwm_enable(pwm_leds[id].ch2, enable);
+ if (led->ch0 != PWM_LED_NO_CHANNEL)
+ led->enable(led->ch0, enable);
+ if (led->ch1 != PWM_LED_NO_CHANNEL)
+ led->enable(led->ch1, enable);
+ if (led->ch2 != PWM_LED_NO_CHANNEL)
+ led->enable(led->ch2, enable);
}
static void init_leds_off(void)
diff --git a/include/led_pwm.h b/include/led_pwm.h
index 8814023d42..42f2f5caad 100644
--- a/include/led_pwm.h
+++ b/include/led_pwm.h
@@ -11,9 +11,12 @@
#define PWM_LED_NO_CHANNEL -1
struct pwm_led {
- int ch0;
- int ch1;
- int ch2;
+ enum pwm_channel ch0;
+ enum pwm_channel ch1;
+ enum pwm_channel ch2;
+
+ void (*enable)(enum pwm_channel ch, int enabled);
+ void (*set_duty)(enum pwm_channel ch, int percent);
};
enum pwm_led_id {