summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Chi <peter_chi@wistron.corp-partner.google.com>2022-04-20 20:56:15 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-03 07:57:25 +0000
commit404fbb8297704c7a9110b1dfc31ed3d428657136 (patch)
tree14f5f96d28db4be34ad1bd04670c9adb398a7835
parent8eb4cf1b73b358ed24e3b8753b2a5416a568f5c3 (diff)
downloadchrome-ec-404fbb8297704c7a9110b1dfc31ed3d428657136.tar.gz
crota: Configure LED behavior
BUG=b:229935118 BRANCH=None TEST=make -j BOARD=crota Signed-off-by: Peter Chi <peter_chi@wistron.corp-partner.google.com> Change-Id: I49529350cde85fbd0ae045e396d4bc97735bc3a7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3596380 Reviewed-by: Boris Mittelberg <bmbm@google.com>
-rw-r--r--board/crota/board.h18
-rw-r--r--board/crota/gpio.inc5
-rw-r--r--board/crota/led.c120
-rw-r--r--board/crota/pwm.c16
4 files changed, 66 insertions, 93 deletions
diff --git a/board/crota/board.h b/board/crota/board.h
index f4c2ddda11..5d65b855a5 100644
--- a/board/crota/board.h
+++ b/board/crota/board.h
@@ -21,18 +21,6 @@
#define CONFIG_MP2964
-/* LED */
-#define CONFIG_LED_PWM
-#define CONFIG_LED_PWM_COUNT 2
-#undef CONFIG_LED_PWM_NEAR_FULL_COLOR
-#undef CONFIG_LED_PWM_SOC_ON_COLOR
-#undef CONFIG_LED_PWM_SOC_SUSPEND_COLOR
-#undef CONFIG_LED_PWM_LOW_BATT_COLOR
-#define CONFIG_LED_PWM_NEAR_FULL_COLOR EC_LED_COLOR_WHITE
-#define CONFIG_LED_PWM_SOC_ON_COLOR EC_LED_COLOR_WHITE
-#define CONFIG_LED_PWM_SOC_SUSPEND_COLOR EC_LED_COLOR_WHITE
-#define CONFIG_LED_PWM_LOW_BATT_COLOR EC_LED_COLOR_AMBER
-
/* Sensors */
#define CONFIG_ACCELGYRO_LSM6DSO /* Base accel */
#define CONFIG_ACCEL_LSM6DSO_INT_EVENT \
@@ -195,6 +183,10 @@
#define CONFIG_FANS FAN_CH_COUNT
+/* LED defines */
+#define CONFIG_LED_ONOFF_STATES
+#define CONFIG_LED_ONOFF_STATES_BAT_LOW 10
+
/* Charger defines */
#define CONFIG_CHARGER_BQ25720
#define CONFIG_CHARGER_BQ25720_VSYS_TH2_CUSTOM
@@ -253,11 +245,9 @@ enum battery_type {
enum pwm_channel {
PWM_CH_LED2 = 0, /* PWM0 (white charger) */
- PWM_CH_LED3, /* PWM1 (orange on DB) */
PWM_CH_LED1, /* PWM2 (orange charger) */
PWM_CH_KBLIGHT, /* PWM3 */
PWM_CH_FAN, /* PWM5 */
- PWM_CH_LED4, /* PWM7 (white on DB) */
PWM_CH_COUNT
};
diff --git a/board/crota/gpio.inc b/board/crota/gpio.inc
index eccf10a36c..ab8d6ae381 100644
--- a/board/crota/gpio.inc
+++ b/board/crota/gpio.inc
@@ -83,10 +83,9 @@ ALTERNATE(PIN_MASK(D, 0x03), 0, MODULE_I2C, 0) /* GPIOD1/I2C3_SCL0
/* PWM alternate functions */
ALTERNATE(PIN_MASK(4, 0x01), 0, MODULE_PWM, 0) /* GPIO40/TA1 */
-ALTERNATE(PIN_MASK(6, 0x01), 0, MODULE_PWM, 0) /* GPIO60/PWM7 */
ALTERNATE(PIN_MASK(8, 0x01), 0, MODULE_PWM, 0) /* GPIO80/PWM3 */
ALTERNATE(PIN_MASK(B, 0x80), 0, MODULE_PWM, 0) /* GPIOB7/PWM5 */
-ALTERNATE(PIN_MASK(C, 0x1c), 0, MODULE_PWM, 0) /* GPIOC4/PWM2, GPIOC3/PWM0, GPIOC2/PWM1/I2C6_SCL0 */
+ALTERNATE(PIN_MASK(C, 0x18), 0, MODULE_PWM, 0) /* GPIOC4/PWM2, GPIOC3/PWM0 */
/* ADC alternate functions */
ALTERNATE(PIN_MASK(3, 0x10), 0, MODULE_ADC, 0) /* GPIO34/PS2_DAT2/ADC6 */
@@ -123,6 +122,8 @@ UNUSED(PIN(9, 4)) /* GPIO94 */
UNUSED(PIN(9, 6)) /* F_DIO1/GPIO96 */
UNUSED(PIN(A, 0)) /* F_CS0#/GPIOA0 */
UNUSED(PIN(0, 2)) /* GPIO02/PSL_IN4#&GPI02 */
+UNUSED(PIN(6, 0)) /* GPIO60/PWM7 */
+UNUSED(PIN(C, 2)) /* GPIOC2/PWM1/I2C6_SCL0 */
/* Pre-configured PSL balls: J8 K6 */
diff --git a/board/crota/led.c b/board/crota/led.c
index be2b832237..0a9c9503fe 100644
--- a/board/crota/led.c
+++ b/board/crota/led.c
@@ -3,91 +3,87 @@
* found in the LICENSE file.
*/
-/* Brya specific PWM LED settings: there are 2 LEDs on each side of the board,
- * each one can be controlled separately. The LED colors are white or amber,
- * and the default behavior is tied to the charging process: both sides are
- * amber while charging the battery and white when the battery is charged.
- */
+/* Crota specific PWM LED settings. */
#include <stdint.h>
+#include "charge_manager.h"
#include "common.h"
#include "compile_time_macros.h"
#include "ec_commands.h"
-#include "led_pwm.h"
+#include "gpio.h"
+#include "led_common.h"
+#include "led_onoff_states.h"
#include "pwm.h"
#include "util.h"
-const enum ec_led_id supported_led_ids[] = {
- EC_LED_ID_LEFT_LED,
- EC_LED_ID_RIGHT_LED,
-};
+#define BAT_LED_ON_LVL 100
+#define BAT_LED_OFF_LVL 0
-const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
+__override const int led_charge_lvl_1 = 5;
+__override const int led_charge_lvl_2 = 100;
-/*
- * We only have a white and an amber LED, so setting any other color results in
- * both LEDs being off. Cap at 50% to save power.
- */
-struct pwm_led_color_map led_color_map[EC_LED_COLOR_COUNT] = {
- /* Amber, White */
- [EC_LED_COLOR_RED] = { 0, 0 },
- [EC_LED_COLOR_GREEN] = { 0, 0 },
- [EC_LED_COLOR_BLUE] = { 0, 0 },
- [EC_LED_COLOR_YELLOW] = { 0, 0 },
- [EC_LED_COLOR_WHITE] = { 0, 50 },
- [EC_LED_COLOR_AMBER] = { 50, 0 },
+__override struct led_descriptor
+ led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = {
+ [STATE_CHARGING_LVL_1] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} },
+ [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} },
+ [STATE_CHARGING_FULL_CHARGE] = {{LED_OFF, LED_INDEFINITE} },
+ [STATE_DISCHARGE_S0] = {{LED_OFF, LED_INDEFINITE} },
+ [STATE_DISCHARGE_S0_BAT_LOW] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} },
+ [STATE_DISCHARGE_S3] = {{LED_OFF, LED_INDEFINITE} },
+ [STATE_DISCHARGE_S5] = {{LED_OFF, LED_INDEFINITE} },
+ [STATE_BATTERY_ERROR] = {{LED_OFF, LED_INDEFINITE} },
+ [STATE_FACTORY_TEST] = {
+ {EC_LED_COLOR_WHITE, 1 * LED_ONE_SEC},
+ {LED_OFF, 1 * LED_ONE_SEC}
+ },
};
-/* Two logical LEDs with amber and white channels. */
-struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = {
- {
- .ch0 = PWM_CH_LED1,
- .ch1 = PWM_CH_LED2,
- .ch2 = PWM_LED_NO_CHANNEL,
- .enable = &pwm_enable,
- .set_duty = &pwm_set_duty,
- },
- {
- .ch0 = PWM_CH_LED3,
- .ch1 = PWM_CH_LED4,
- .ch2 = PWM_LED_NO_CHANNEL,
- .enable = &pwm_enable,
- .set_duty = &pwm_set_duty,
- },
+const enum ec_led_id supported_led_ids[] = {
+ EC_LED_ID_BATTERY_LED,
};
-void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
-{
- memset(brightness_range, '\0',
- sizeof(*brightness_range) * EC_LED_COLOR_COUNT);
- brightness_range[EC_LED_COLOR_AMBER] = 100;
- brightness_range[EC_LED_COLOR_WHITE] = 100;
-}
+const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
-int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
+__override void led_set_color_battery(enum ec_led_colors color)
{
- enum pwm_led_id pwm_id;
+ /* There are two battery leds, LED1/LED2 are on MB side.
+ * All leds are OFF by default.
+ */
+ int led1_duty, led2_duty;
+
+ led1_duty = led2_duty = BAT_LED_OFF_LVL;
- /* Convert ec_led_id to pwm_led_id. */
- switch (led_id) {
- case EC_LED_ID_LEFT_LED:
- pwm_id = PWM_LED0;
+ switch (color) {
+ case EC_LED_COLOR_AMBER:
+ led1_duty = BAT_LED_ON_LVL;
break;
- case EC_LED_ID_RIGHT_LED:
- pwm_id = PWM_LED1;
+ case EC_LED_COLOR_WHITE:
+ led2_duty = BAT_LED_ON_LVL;
+ break;
+ default: /* LED_OFF and other unsupported colors */
break;
- default:
- return EC_ERROR_UNKNOWN;
}
- 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);
+ pwm_set_duty(PWM_CH_LED1, led1_duty);
+ pwm_set_duty(PWM_CH_LED2, led2_duty);
+}
+
+void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
+{
+ brightness_range[EC_LED_COLOR_AMBER] = 1;
+ brightness_range[EC_LED_COLOR_WHITE] = 1;
+}
+
+int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
+{
+ led_auto_control(led_id, 0);
+ if (brightness[EC_LED_COLOR_AMBER] != 0)
+ led_set_color_battery(EC_LED_COLOR_AMBER);
+ else if (brightness[EC_LED_COLOR_WHITE] != 0)
+ led_set_color_battery(EC_LED_COLOR_WHITE);
else
- /* Otherwise, the "color" is "off". */
- set_pwm_led_color(pwm_id, -1);
+ led_set_color_battery(LED_OFF);
return EC_SUCCESS;
}
diff --git a/board/crota/pwm.c b/board/crota/pwm.c
index de19f15cd5..15cf80eea9 100644
--- a/board/crota/pwm.c
+++ b/board/crota/pwm.c
@@ -3,8 +3,8 @@
* found in the LICENSE file.
*/
+#include "chipset.h"
#include "common.h"
-
#include "compile_time_macros.h"
#include "hooks.h"
#include "pwm.h"
@@ -16,11 +16,6 @@ const struct pwm_t pwm_channels[] = {
.flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP,
.freq = 4800,
},
- [PWM_CH_LED3] = {
- .channel = 1,
- .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP,
- .freq = 4800,
- },
[PWM_CH_LED1] = {
.channel = 2,
.flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP,
@@ -42,11 +37,6 @@ const struct pwm_t pwm_channels[] = {
.flags = PWM_CONFIG_OPEN_DRAIN | PWM_CONFIG_DSLEEP,
.freq = 1000
},
- [PWM_CH_LED4] = {
- .channel = 7,
- .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP,
- .freq = 4800,
- },
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
@@ -60,10 +50,6 @@ static void board_pwm_init(void)
pwm_set_duty(PWM_CH_LED1, 0);
pwm_enable(PWM_CH_LED2, 1);
pwm_set_duty(PWM_CH_LED2, 0);
- pwm_enable(PWM_CH_LED3, 1);
- pwm_set_duty(PWM_CH_LED3, 0);
- pwm_enable(PWM_CH_LED4, 1);
- pwm_set_duty(PWM_CH_LED4, 0);
pwm_enable(PWM_CH_KBLIGHT, 1);
pwm_set_duty(PWM_CH_KBLIGHT, 50);