diff options
author | Hank.Xie <hank.xie@quanta.corp-partner.google.com> | 2022-09-07 04:09:16 -0400 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-12 07:27:12 +0000 |
commit | 234a3fd7dd115f1ea06d37b9d8cff7bc83ee7871 (patch) | |
tree | b956cc534393e8aa1cbef457b3ab25c3ed3b19b2 /board | |
parent | 9438d62c74c645ce22c3473901f6d81fc159ddff (diff) | |
download | chrome-ec-234a3fd7dd115f1ea06d37b9d8cff7bc83ee7871.tar.gz |
shotzo: Modify power led behavior when suspending
Modify led control setting as below:
1.Remove the pwm control led related code.
1.Change power led behavior when suspending.
Power led behavior as below:
1.Solid white - active power
2.25% duty cycle white - suspend
3.Blinking quicky white - alert
4.Two long two short white - critical
5.Off - shut down
BUG=b:235791717
BRANCH=none
TEST=check power led works fine on shotzo
Signed-off-by: Hank Xie <hank.xie@quanta.corp-partner.google.com>
Change-Id: I4e094af1734407cc66269e13d4b21df3ed0e815f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3881523
Reviewed-by: Zhuohao Lee <zhuohao@chromium.org>
Reviewed-by: Devin Lu <devin.lu@quantatw.com>
Diffstat (limited to 'board')
-rw-r--r-- | board/shotzo/board.c | 12 | ||||
-rw-r--r-- | board/shotzo/board.h | 8 | ||||
-rw-r--r-- | board/shotzo/gpio.inc | 6 | ||||
-rw-r--r-- | board/shotzo/led.c | 116 |
4 files changed, 27 insertions, 115 deletions
diff --git a/board/shotzo/board.c b/board/shotzo/board.c index eec7a17e9d..abd0284e11 100644 --- a/board/shotzo/board.c +++ b/board/shotzo/board.c @@ -23,8 +23,6 @@ #include "intc.h" #include "power.h" #include "power_button.h" -#include "pwm.h" -#include "pwm_chip.h" #include "switch.h" #include "system.h" #include "task.h" @@ -467,16 +465,6 @@ __override void typec_set_source_current_limit(int port, enum tcpc_rp_value rp) charger_set_otg_current_voltage(port, current, 5000); } -/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ -const struct pwm_t pwm_channels[] = { - [PWM_CH_LED_WHITE] = { - .channel = 1, - .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, - .freq_hz = 2000, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); - /* Thermistors */ const struct temp_sensor_t temp_sensors[] = { [TEMP_SENSOR_1] = { .name = "Memory", diff --git a/board/shotzo/board.h b/board/shotzo/board.h index 9046bc036d..7e63015521 100644 --- a/board/shotzo/board.h +++ b/board/shotzo/board.h @@ -20,9 +20,6 @@ #define CONFIG_USB_PD_5V_CHARGER_CTRL #define CONFIG_CHARGER_OTG -/* PWM */ -#define CONFIG_PWM - /* TCPC */ #define CONFIG_USB_PD_PORT_MAX_COUNT 1 #define CONFIG_USB_PD_TCPM_ITE_ON_CHIP /* C0: ITE EC TCPC */ @@ -81,11 +78,6 @@ #include "gpio_signal.h" #include "registers.h" -enum pwm_channel { - PWM_CH_LED_WHITE, - PWM_CH_COUNT, -}; - /* ADC channels */ enum adc_channel { ADC_VSNS_PP3300_A, /* ADC0 */ diff --git a/board/shotzo/gpio.inc b/board/shotzo/gpio.inc index 5befcf8d2c..113f377b40 100644 --- a/board/shotzo/gpio.inc +++ b/board/shotzo/gpio.inc @@ -142,6 +142,9 @@ GPIO(KSO13_NC, PIN(KSO_H, 5), GPIO_INPUT | GPIO_PULL_DOWN) GPIO(KSO14_NC, PIN(KSO_H, 6), GPIO_INPUT | GPIO_PULL_DOWN) GPIO(KSO15_NC, PIN(KSO_H, 7), GPIO_INPUT | GPIO_PULL_DOWN) +/* LED */ +GPIO(PWR_LED_WHITE_L, PIN(A, 1), GPIO_OUT_HIGH) + /* Alternate functions GPIO definitions */ GPIO(EC_KSO_02_INV, PIN(KSO_L, 2), GPIO_OUT_HIGH) /* KSO2 inverted */ @@ -158,6 +161,3 @@ ALTERNATE(PIN_MASK(A, BIT(4) | BIT(5)), 0, MODULE_I2C, 0) /* I2C5 */ /* ADC */ ALTERNATE(PIN_MASK(L, BIT(0) | BIT(2) | BIT(3)), 0, MODULE_ADC, 0) /* ADC13: EC_SUB_ANALOG, ADC15: TEMP_SENSOR_3, ADC16: TEMP_SENSOR_4 */ ALTERNATE(PIN_MASK(I, BIT(0) | BIT(2) | BIT(3)), 0, MODULE_ADC, 0) /* ADC0: EC_VSNS_PP3300_A, ADC2: TEMP_SENSOR_1, ADC3: TEMP_SENSOR_2 */ - -/* PWM */ -ALTERNATE(PIN_MASK(A, BIT(1)), 0, MODULE_PWM, 0) /* LED_WHITE_PWM */ diff --git a/board/shotzo/led.c b/board/shotzo/led.c index a163831396..0299d87f26 100644 --- a/board/shotzo/led.c +++ b/board/shotzo/led.c @@ -5,7 +5,7 @@ /* Power LED control for Shotzo. * Solid white - active power - * Breathing white, 1s to 100% and 1s to 0% - suspend + * 25% duty cycle white, 1s on and 3s off- suspend * Blinking quicky white, 0.5s on and 0.5s off - alert * 2 long 2 short white, long for 1s, short for 0.5s and interval * is 0.5s - critical @@ -14,9 +14,9 @@ #include "chipset.h" #include "console.h" +#include "gpio.h" #include "hooks.h" #include "led_common.h" -#include "pwm.h" #include "timer.h" #include "util.h" @@ -27,12 +27,8 @@ */ #define LED_CPU_DELAY_MS (2000 * MSEC) -/* When pulsing is enabled, brightness is incremented from 0 to 100% - * in LED_PULSE_US usec. Then it's decremented likewise. - */ -#define LED_PULSE_US (1 * SECOND) -/* 40 msec for nice and smooth transition. */ -#define LED_PULSE_TICK_US (40 * MSEC) +#define POWER_LED_ON 0 +#define POWER_LED_OFF 1 const enum ec_led_id supported_led_ids[] = { EC_LED_ID_POWER_LED }; @@ -44,53 +40,28 @@ enum led_color { LED_COLOR_COUNT /* Number of colors, not a color itself */ }; -static struct { - uint32_t interval; - int duty_inc; - enum led_color color; - int duty; -} led_pulse; - -/* When pulsing is enabled, brightness is incremented by <duty_inc> every - * <interval> usec from 0 to 100% Then it's decremented likewise. - */ -static void config_tick(uint32_t interval, int duty_inc, enum led_color color) -{ - led_pulse.interval = interval; - led_pulse.duty_inc = duty_inc; - led_pulse.color = color; - led_pulse.duty = 0; -} - -#define CONFIGURE_TICK(interval, color) \ - config_tick((interval), 100 / (LED_PULSE_US / (interval)), (color)) - -static int led_set_color_duty(enum led_color color, int duty) +static int led_set_color_power(enum led_color color) { - if (duty < 0 || 100 < duty) - return EC_ERROR_UNKNOWN; - switch (color) { case LED_OFF: - pwm_set_duty(PWM_CH_LED_WHITE, 0); + gpio_set_level(GPIO_PWR_LED_WHITE_L, POWER_LED_OFF); break; case LED_WHITE: - pwm_set_duty(PWM_CH_LED_WHITE, duty); + gpio_set_level(GPIO_PWR_LED_WHITE_L, POWER_LED_ON); break; default: return EC_ERROR_UNKNOWN; } - return EC_SUCCESS; } -static int led_set_color(enum ec_led_id led_id, enum led_color color, int duty) +static int led_set_color(enum ec_led_id led_id, enum led_color color) { int rv; switch (led_id) { case EC_LED_ID_POWER_LED: - rv = led_set_color_duty(color, duty); + rv = led_set_color_power(color); break; default: return EC_ERROR_UNKNOWN; @@ -98,32 +69,6 @@ static int led_set_color(enum ec_led_id led_id, enum led_color color, int duty) return rv; } -static void pulse_power_led(enum led_color color) -{ - led_set_color(EC_LED_ID_POWER_LED, color, led_pulse.duty); - if (led_pulse.duty + led_pulse.duty_inc > 100) - led_pulse.duty_inc = led_pulse.duty_inc * -1; - else if (led_pulse.duty + led_pulse.duty_inc < 0) - led_pulse.duty_inc = led_pulse.duty_inc * -1; - led_pulse.duty += led_pulse.duty_inc; - led_pulse.duty = MIN(100, MAX(led_pulse.duty, 0)); -} - -static void led_tick(void); -DECLARE_DEFERRED(led_tick); -static void led_tick(void) -{ - uint32_t elapsed; - uint32_t next = 0; - uint32_t start = get_time().le.lo; - - if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) - pulse_power_led(led_pulse.color); - elapsed = get_time().le.lo - start; - next = led_pulse.interval > elapsed ? led_pulse.interval - elapsed : 0; - hook_call_deferred(&led_tick_data, next); -} - /* When blinking is enabled, led will blinking according to led_blinking_array. * 1 means led on, 0 means led off, restart from head after reaching the tail. * The interval is LED_BLINKING_MS. @@ -152,11 +97,11 @@ static void led_blinking(void) if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) { switch (signal) { case 0: - led_set_color(EC_LED_ID_POWER_LED, LED_OFF, 0); + led_set_color(EC_LED_ID_POWER_LED, LED_OFF); led_blinking_index += 1; break; case 1: - led_set_color(EC_LED_ID_POWER_LED, LED_WHITE, 100); + led_set_color(EC_LED_ID_POWER_LED, LED_WHITE); led_blinking_index += 1; break; default: @@ -169,23 +114,26 @@ static void led_blinking(void) hook_call_deferred(&led_blinking_data, next); } +static int led_suspend_array[] = { 1, 1, 0, 0, 0, 0, 0, 0 }; +const int led_suspend_count = ARRAY_SIZE(led_suspend_array); static void led_suspend(void) { - CONFIGURE_TICK(LED_PULSE_TICK_US, LED_WHITE); - led_tick(); + led_blinking_array = led_suspend_array; + led_blinking_count = led_suspend_count; + led_blinking_index = 0; + led_blinking(); } DECLARE_DEFERRED(led_suspend); static void led_shutdown(void) { if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) - led_set_color(EC_LED_ID_POWER_LED, LED_OFF, 0); + led_set_color(EC_LED_ID_POWER_LED, LED_OFF); } DECLARE_DEFERRED(led_shutdown); static void led_suspend_hook(void) { - hook_call_deferred(&led_tick_data, -1); hook_call_deferred(&led_blinking_data, -1); hook_call_deferred(&led_shutdown_data, -1); hook_call_deferred(&led_suspend_data, LED_CPU_DELAY_MS); @@ -194,7 +142,6 @@ DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, led_suspend_hook, HOOK_PRIO_DEFAULT); static void led_shutdown_hook(void) { - hook_call_deferred(&led_tick_data, -1); hook_call_deferred(&led_blinking_data, -1); hook_call_deferred(&led_suspend_data, -1); hook_call_deferred(&led_shutdown_data, LED_CPU_DELAY_MS); @@ -203,19 +150,12 @@ DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, led_shutdown_hook, HOOK_PRIO_DEFAULT); static void led_resume_hook(void) { - /* Assume there is no race condition with led_pulse and led_blinking, - * which also runs in hook_task. - */ - hook_call_deferred(&led_tick_data, -1); hook_call_deferred(&led_blinking_data, -1); - /* - * Avoid invoking the suspend/shutdown delayed hooks. - */ hook_call_deferred(&led_suspend_data, -1); hook_call_deferred(&led_shutdown_data, -1); if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) - led_set_color(EC_LED_ID_POWER_LED, LED_WHITE, 100); + led_set_color(EC_LED_ID_POWER_LED, LED_WHITE); } DECLARE_HOOK(HOOK_CHIPSET_RESUME, led_resume_hook, HOOK_PRIO_DEFAULT); @@ -225,7 +165,6 @@ void led_alert(int enable) { if (enable) { /* Overwrite the current signal */ - hook_call_deferred(&led_tick_data, -1); hook_call_deferred(&led_blinking_data, -1); led_blinking_array = led_alert_array; led_blinking_count = led_alert_count; @@ -246,7 +185,6 @@ static int led_critical_array[] = { 1, 1, 0, 1, 1, 0, 1, 0, 1, 0 }; const int led_critical_count = ARRAY_SIZE(led_critical_array); void show_critical_error(void) { - hook_call_deferred(&led_tick_data, -1); hook_call_deferred(&led_blinking_data, -1); led_blinking_array = led_critical_array; led_blinking_count = led_critical_count; @@ -254,17 +192,11 @@ void show_critical_error(void) led_blinking(); } -static void led_init(void) -{ - pwm_enable(PWM_CH_LED_WHITE, 1); -} -DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_INIT_PWM + 1); - void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) { switch (led_id) { case EC_LED_ID_POWER_LED: - brightness_range[EC_LED_COLOR_WHITE] = 100; + brightness_range[EC_LED_COLOR_WHITE] = 1; break; default: break; @@ -274,9 +206,9 @@ void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) int led_set_brightness(enum ec_led_id id, const uint8_t *brightness) { if (brightness[EC_LED_COLOR_WHITE] != 0) - led_set_color(id, LED_WHITE, brightness[EC_LED_COLOR_WHITE]); + led_set_color(id, LED_WHITE); else - led_set_color(id, LED_OFF, 0); + led_set_color(id, LED_OFF); return EC_SUCCESS; } @@ -292,9 +224,9 @@ static int command_led(int argc, const char **argv) led_auto_control(id, !led_auto_control_is_enabled(id)); ccprintf("o%s\n", led_auto_control_is_enabled(id) ? "ff" : "n"); } else if (!strcasecmp(argv[1], "off")) { - led_set_color(id, LED_OFF, 0); + led_set_color(id, LED_OFF); } else if (!strcasecmp(argv[1], "white")) { - led_set_color(id, LED_WHITE, 100); + led_set_color(id, LED_WHITE); } else if (!strcasecmp(argv[1], "alert")) { led_alert(1); } else if (!strcasecmp(argv[1], "crit")) { |