diff options
-rw-r--r-- | baseboard/volteer/baseboard.c | 45 | ||||
-rw-r--r-- | baseboard/volteer/baseboard.h | 17 | ||||
-rw-r--r-- | baseboard/volteer/build.mk | 1 | ||||
-rw-r--r-- | baseboard/volteer/led.c | 72 |
4 files changed, 135 insertions, 0 deletions
diff --git a/baseboard/volteer/baseboard.c b/baseboard/volteer/baseboard.c index 4f589a2c8b..be0370074f 100644 --- a/baseboard/volteer/baseboard.c +++ b/baseboard/volteer/baseboard.c @@ -4,8 +4,13 @@ */ /* Volteer family-specific configuration */ +#include "baseboard.h" +#include "battery.h" +#include "charge_state.h" #include "gpio.h" #include "i2c.h" +#include "pwm.h" +#include "pwm_chip.h" /******************************************************************************/ /* Wake up pins */ @@ -66,3 +71,43 @@ const struct i2c_port_t i2c_ports[] = { }, }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); + +const struct pwm_t pwm_channels[] = { + [PWM_CH_LED1_BLUE] = { + .channel = 2, + .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + .freq = 100, + }, + [PWM_CH_LED2_GREEN] = { + .channel = 0, + .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + .freq = 100, + }, + [PWM_CH_LED3_RED] = { + .channel = 1, + .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + .freq = 100, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); + +/* Stub out battery and charging functions to compile common LED code. + * TODO(b/140557020): Define these for real. + */ +#ifdef CONFIG_CHARGER +#error "Write real definitions for charger and battery functions." +#endif +enum charge_state charge_get_state(void) +{ + return PWR_STATE_UNCHANGE; +} + +enum battery_present battery_is_present(void) +{ + return BP_NOT_SURE; +} + +int charge_get_percent(void) +{ + return 0; +} diff --git a/baseboard/volteer/baseboard.h b/baseboard/volteer/baseboard.h index f7a6f6793c..e2ebea1c21 100644 --- a/baseboard/volteer/baseboard.h +++ b/baseboard/volteer/baseboard.h @@ -22,6 +22,16 @@ #define CONFIG_CRC8 #define CONFIG_CROS_BOARD_INFO #define CONFIG_HIBERNATE_PSL +#define CONFIG_LED_COMMON +/* TODO(b/140557020): Define CONFIG_LED_ONOFF_STATES and + * CONFIG_LED_ONOFF_STATES_BAT_LOW when CONFIG_CHARGER is defined. + */ +#define CONFIG_LED_PWM +/* TODO(b/140557020): Remove this when CONFIG_CHARGER is defined. */ +#define CONFIG_LED_PWM_CHARGE_STATE_ONLY +/* Although there are 2 LEDs, they are both controlled by the same lines. */ +#define CONFIG_LED_PWM_COUNT 1 +#define CONFIG_PWM #define CONFIG_VBOOT_HASH #define CONFIG_VSTORE #define CONFIG_VSTORE_SLOT_COUNT 1 @@ -68,6 +78,13 @@ #ifndef __ASSEMBLER__ +enum pwm_channel { + PWM_CH_LED1_BLUE = 0, + PWM_CH_LED2_GREEN, + PWM_CH_LED3_RED, + PWM_CH_COUNT +}; + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BASEBOARD_H */ diff --git a/baseboard/volteer/build.mk b/baseboard/volteer/build.mk index 03a91ceda7..bb7e57ad6a 100644 --- a/baseboard/volteer/build.mk +++ b/baseboard/volteer/build.mk @@ -7,3 +7,4 @@ # baseboard-y=baseboard.o +baseboard-y+=led.o diff --git a/baseboard/volteer/led.c b/baseboard/volteer/led.c new file mode 100644 index 0000000000..f063956a4c --- /dev/null +++ b/baseboard/volteer/led.c @@ -0,0 +1,72 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Power and battery LED control for Volteer + */ + +#include "common.h" +#include "ec_commands.h" +#include "led_common.h" +#include "led_pwm.h" + +const enum ec_led_id supported_led_ids[] = { + EC_LED_ID_BATTERY_LED, +}; +const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); + +struct pwm_led led_color_map[] = { + /* Red, Green, Blue */ + [EC_LED_COLOR_RED] = { 100, 0, 0 }, + [EC_LED_COLOR_GREEN] = { 0, 100, 0 }, + [EC_LED_COLOR_BLUE] = { 0, 0, 100 }, + [EC_LED_COLOR_YELLOW] = { 100, 100, 0 }, + [EC_LED_COLOR_WHITE] = { 100, 100, 100 }, + [EC_LED_COLOR_AMBER] = { 100, 75, 0 }, +}; + +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, + }, +}; + +void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) +{ + /* TODO(b/139554899): Consider letting these go up to 255. */ + brightness_range[EC_LED_COLOR_RED] = 100; + brightness_range[EC_LED_COLOR_GREEN] = 100; + brightness_range[EC_LED_COLOR_BLUE] = 100; +} + +int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) +{ + enum pwm_led_id pwm_id; + + /* Convert ec_led_id to pwm_led_id. */ + if (led_id == EC_LED_ID_BATTERY_LED) + pwm_id = PWM_LED0; + else + return EC_ERROR_UNKNOWN; + + if (brightness[EC_LED_COLOR_RED]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_RED); + else if (brightness[EC_LED_COLOR_GREEN]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_GREEN); + else if (brightness[EC_LED_COLOR_BLUE]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_BLUE); + else if (brightness[EC_LED_COLOR_YELLOW]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_YELLOW); + else if (brightness[EC_LED_COLOR_WHITE]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_WHITE); + else if (brightness[EC_LED_COLOR_AMBER]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_AMBER); + else + /* Otherwise, the "color" is "off". */ + set_pwm_led_color(pwm_id, -1); + + return EC_SUCCESS; +} |