summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlschyi <lschyi@google.com>2022-07-06 17:15:04 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-07 08:37:18 +0000
commitc39eac58cfc60e6937eadc4dca1dbdd1762e6410 (patch)
treec3d775f76622dde9eb75c42afc590f0a56668b5f
parentc426eac8c09f59a0e594c636c4178ff3f5b21dce (diff)
downloadchrome-ec-c39eac58cfc60e6937eadc4dca1dbdd1762e6410.tar.gz
tentacruel: extract LED dtsi shared with krabby
Tentacruel and krabby shares the same LED DTS settings. Extract these settings as a base dtsi, and covert tentacruel to use DTS to control the LED behavior. BUG=b:236796813 TEST=use `battfake` in EC console, set battery to different level and check LED behavior matches to the DTS settings. BRANCH=none Signed-off-by: lschyi <lschyi@google.com> Change-Id: I1e09e5c7d05e91b919a113280c228ebab317b25d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3748017 Tested-by: Sung-Chi Li <lschyi@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Sung-Chi Li <lschyi@chromium.org>
-rw-r--r--zephyr/projects/corsola/CMakeLists.txt2
-rw-r--r--zephyr/projects/corsola/led_it81202_base.dtsi182
-rw-r--r--zephyr/projects/corsola/led_krabby.dts170
-rw-r--r--zephyr/projects/corsola/led_tentacruel.dts76
-rw-r--r--zephyr/projects/corsola/src/krabby/led_tentacruel.c181
5 files changed, 225 insertions, 386 deletions
diff --git a/zephyr/projects/corsola/CMakeLists.txt b/zephyr/projects/corsola/CMakeLists.txt
index 4aec794c79..9cc9bd9451 100644
--- a/zephyr/projects/corsola/CMakeLists.txt
+++ b/zephyr/projects/corsola/CMakeLists.txt
@@ -54,8 +54,6 @@ elseif(DEFINED CONFIG_BOARD_TENTACRUEL)
zephyr_library_sources("src/krabby/hooks.c"
"src/krabby/charger_workaround.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C "src/krabby/i2c.c")
- zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON
- "src/krabby/led_tentacruel.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC
"src/krabby/usb_pd_policy.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC
diff --git a/zephyr/projects/corsola/led_it81202_base.dtsi b/zephyr/projects/corsola/led_it81202_base.dtsi
new file mode 100644
index 0000000000..24a0efd93e
--- /dev/null
+++ b/zephyr/projects/corsola/led_it81202_base.dtsi
@@ -0,0 +1,182 @@
+/* Copyright 2022 The ChromiumOS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include <dt-bindings/battery.h>
+
+/ {
+ led_colors: led-colors {
+ compatible = "cros-ec,led-colors";
+
+ bat-power-state-charge {
+ charge-state = "PWR_STATE_CHARGE";
+
+ color-0 {
+ led-color = <&color_battery_amber>;
+ };
+ };
+
+ bat-power-state-near-full {
+ charge-state = "PWR_STATE_CHARGE_NEAR_FULL";
+
+ color-0 {
+ led-color = <&color_battery_white>;
+ };
+ };
+
+ bat-power-state-discharge {
+ charge-state = "PWR_STATE_DISCHARGE";
+
+ color-0 {
+ led-color = <&color_battery_off>;
+ };
+ };
+
+ bat-power-state-discharge-s0-bat-low {
+ charge-state = "PWR_STATE_DISCHARGE";
+ chipset-state = "POWER_S0";
+ batt-lvl = <BATTERY_LEVEL_EMPTY BATTERY_LEVEL_LOW>;
+
+ color-0 {
+ led-color = <&color_battery_amber>;
+ period-ms = <1000>;
+ };
+
+ color-1 {
+ led-color = <&color_battery_off>;
+ period-ms = <3000>;
+ };
+ };
+
+ bat-power-state-error {
+ charge-state = "PWR_STATE_ERROR";
+
+ color-0 {
+ led-color = <&color_battery_amber>;
+ period-ms = <1000>;
+ };
+
+ color-1 {
+ led-color = <&color_battery_off>;
+ period-ms = <1000>;
+ };
+ };
+
+ pwr-power-state-off {
+ color-0 {
+ led-color = <&color_power_off>;
+ };
+ };
+
+ pwr-power-state-on {
+ chipset-state = "POWER_S0";
+
+ color-0 {
+ led-color = <&color_power_white>;
+ };
+ };
+
+ pwr-power-state-s3 {
+ chipset-state = "POWER_S3";
+
+ color-0 {
+ led-color = <&color_power_white>;
+ period-ms = <1000>;
+ };
+
+ color-1 {
+ led-color = <&color_power_off>;
+ period-ms = <3000>;
+ };
+ };
+ };
+
+ pwmleds {
+ compatible = "cros-ec,pwm-pin-config";
+
+ /* NOTE: &pwm number needs same with channel number */
+ led_power_white: ec_led1_odl {
+ #led-pin-cells = <1>;
+ pwms = <&pwm0
+ PWM_CHANNEL_0
+ PWM_HZ(324)
+ PWM_POLARITY_INVERTED>;
+ };
+ led_battery_amber: ec_led2_odl {
+ #led-pin-cells = <1>;
+ pwms = <&pwm1
+ PWM_CHANNEL_1
+ PWM_HZ(324)
+ PWM_POLARITY_INVERTED>;
+ };
+ led_battery_white: ec_led3_odl {
+ #led-pin-cells = <1>;
+ pwms = <&pwm2
+ PWM_CHANNEL_2
+ PWM_HZ(324)
+ PWM_POLARITY_INVERTED>;
+ };
+ };
+
+ pwm-led-pins {
+ compatible = "cros-ec,pwm-led-pins";
+ pwm-frequency = <324>;
+
+ color_power_off: color-power-off {
+ led-color = "LED_OFF";
+ led-id = "EC_LED_ID_POWER_LED";
+ led-pins = <&led_power_white 0>;
+ };
+
+ color_power_white: color-power-white {
+ led-color = "LED_WHITE";
+ led-id = "EC_LED_ID_POWER_LED";
+ led-pins = <&led_power_white 100>;
+ };
+
+ color_battery_off: color-battery-off {
+ led-color = "LED_OFF";
+ led-id = "EC_LED_ID_BATTERY_LED";
+ led-pins = <&led_battery_amber 0>,
+ <&led_battery_white 0>;
+ };
+
+ color_battery_amber: color-battery-amber {
+ led-color = "LED_AMBER";
+ led-id = "EC_LED_ID_BATTERY_LED";
+ led-pins = <&led_battery_amber 100>,
+ <&led_battery_white 0>;
+ };
+
+ color_battery_white: color-battery-white {
+ led-color = "LED_WHITE";
+ led-id = "EC_LED_ID_BATTERY_LED";
+ led-pins = <&led_battery_amber 0>,
+ <&led_battery_white 100>;
+ };
+ };
+};
+
+/* LED1 */
+&pwm0 {
+ status = "okay";
+ prescaler-cx = <PWM_PRESCALER_C4>;
+ pinctrl-0 = <&pwm0_gpa0_default>;
+ pinctrl-names = "default";
+};
+
+/* LED2 */
+&pwm1 {
+ status = "okay";
+ prescaler-cx = <PWM_PRESCALER_C4>;
+ pinctrl-0 = <&pwm1_gpa1_default>;
+ pinctrl-names = "default";
+};
+
+/* LED3 */
+&pwm2 {
+ status = "okay";
+ prescaler-cx = <PWM_PRESCALER_C4>;
+ pinctrl-0 = <&pwm2_gpa2_default>;
+ pinctrl-names = "default";
+};
diff --git a/zephyr/projects/corsola/led_krabby.dts b/zephyr/projects/corsola/led_krabby.dts
index 6cad04aace..aa7e3a5f7d 100644
--- a/zephyr/projects/corsola/led_krabby.dts
+++ b/zephyr/projects/corsola/led_krabby.dts
@@ -2,172 +2,4 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include <dt-bindings/battery.h>
-
-/ {
- led-colors {
- compatible = "cros-ec,led-colors";
-
- bat-power-state-charge {
- charge-state = "PWR_STATE_CHARGE";
-
- color-0 {
- led-color = <&color_battery_amber>;
- };
- };
-
- bat-power-state-near-full {
- charge-state = "PWR_STATE_CHARGE_NEAR_FULL";
-
- color-0 {
- led-color = <&color_battery_white>;
- };
- };
-
- bat-power-state-discharge {
- charge-state = "PWR_STATE_DISCHARGE";
-
- color-0 {
- led-color = <&color_battery_off>;
- };
- };
-
- bat-power-state-discharge-s0-bat-low {
- charge-state = "PWR_STATE_DISCHARGE";
- chipset-state = "POWER_S0";
- batt-lvl = <BATTERY_LEVEL_EMPTY BATTERY_LEVEL_LOW>;
-
- color-0 {
- led-color = <&color_battery_amber>;
- period-ms = <1000>;
- };
-
- color-1 {
- led-color = <&color_battery_off>;
- period-ms = <3000>;
- };
- };
-
- bat-power-state-error {
- charge-state = "PWR_STATE_ERROR";
-
- color-0 {
- led-color = <&color_battery_amber>;
- period-ms = <1000>;
- };
-
- color-1 {
- led-color = <&color_battery_off>;
- period-ms = <1000>;
- };
- };
-
- pwr-power-state-off {
- color-0 {
- led-color = <&color_power_off>;
- };
- };
-
- pwr-power-state-on {
- chipset-state = "POWER_S0";
-
- color-0 {
- led-color = <&color_power_white>;
- };
- };
-
- pwr-power-state-s3 {
- chipset-state = "POWER_S3";
-
- color-0 {
- led-color = <&color_power_white>;
- period-ms = <1000>;
- };
-
- color-1 {
- led-color = <&color_power_off>;
- period-ms = <3000>;
- };
- };
- };
-
- pwmleds {
- compatible = "cros-ec,pwm-pin-config";
-
- /* NOTE: &pwm number needs same with channel number */
- led_power_white: ec_led1_odl {
- #led-pin-cells = <1>;
- pwms = <&pwm0 PWM_CHANNEL_0 PWM_HZ(324) PWM_POLARITY_INVERTED>;
- };
- led_battery_amber: ec_led2_odl {
- #led-pin-cells = <1>;
- pwms = <&pwm1 PWM_CHANNEL_1 PWM_HZ(324) PWM_POLARITY_INVERTED>;
- };
- led_battery_white: ec_led3_odl {
- #led-pin-cells = <1>;
- pwms = <&pwm2 PWM_CHANNEL_2 PWM_HZ(324) PWM_POLARITY_INVERTED>;
- };
- };
-
- pwm-led-pins {
- compatible = "cros-ec,pwm-led-pins";
- pwm-frequency = <324>;
-
- color_power_off: color-power-off {
- led-color = "LED_OFF";
- led-id = "EC_LED_ID_POWER_LED";
- led-pins = <&led_power_white 0>;
- };
-
- color_power_white: color-power-white {
- led-color = "LED_WHITE";
- led-id = "EC_LED_ID_POWER_LED";
- led-pins = <&led_power_white 100>;
- };
-
- color_battery_off: color-battery-off {
- led-color = "LED_OFF";
- led-id = "EC_LED_ID_BATTERY_LED";
- led-pins = <&led_battery_amber 0>,
- <&led_battery_white 0>;
- };
-
- color_battery_amber: color-battery-amber {
- led-color = "LED_AMBER";
- led-id = "EC_LED_ID_BATTERY_LED";
- led-pins = <&led_battery_amber 100>,
- <&led_battery_white 0>;
- };
-
- color_battery_white: color-battery-white {
- led-color = "LED_WHITE";
- led-id = "EC_LED_ID_BATTERY_LED";
- led-pins = <&led_battery_amber 0>,
- <&led_battery_white 100>;
- };
- };
-};
-
-/* LED1 */
-&pwm0 {
- status = "okay";
- prescaler-cx = <PWM_PRESCALER_C4>;
- pinctrl-0 = <&pwm0_gpa0_default>;
- pinctrl-names = "default";
-};
-
-/* LED2 */
-&pwm1 {
- status = "okay";
- prescaler-cx = <PWM_PRESCALER_C4>;
- pinctrl-0 = <&pwm1_gpa1_default>;
- pinctrl-names = "default";
-};
-
-/* LED3 */
-&pwm2 {
- status = "okay";
- prescaler-cx = <PWM_PRESCALER_C4>;
- pinctrl-0 = <&pwm2_gpa2_default>;
- pinctrl-names = "default";
-};
+#include "led_it81202_base.dtsi"
diff --git a/zephyr/projects/corsola/led_tentacruel.dts b/zephyr/projects/corsola/led_tentacruel.dts
index 42843c6cb6..b2233033e0 100644
--- a/zephyr/projects/corsola/led_tentacruel.dts
+++ b/zephyr/projects/corsola/led_tentacruel.dts
@@ -2,46 +2,54 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "led_it81202_base.dtsi"
-/ {
- pwmleds {
- compatible = "pwm-leds";
- /* NOTE: &pwm number needs same with channel number */
- led_power_white: ec_led1_odl {
- pwms = <&pwm0 PWM_CHANNEL_0 PWM_HZ(324)
- PWM_POLARITY_INVERTED>;
+&led_colors {
+ bat-power-state-discharge-s0 {
+ charge-state = "PWR_STATE_DISCHARGE";
+ chipset-state = "POWER_S0";
+
+ color-0 {
+ led-color = <&color_battery_white>;
};
- led_battery_amber: ec_led2_odl {
- pwms = <&pwm1 PWM_CHANNEL_1 PWM_HZ(324)
- PWM_POLARITY_INVERTED>;
+ };
+
+ bat-power-state-discharge-s3 {
+ charge-state = "PWR_STATE_DISCHARGE";
+ chipset-state = "POWER_S3";
+
+ color-0 {
+ led-color = <&color_battery_white>;
+ period-ms = <1000>;
};
- led_battery_white: ec_led3_odl {
- pwms = <&pwm2 PWM_CHANNEL_2 PWM_HZ(324)
- PWM_POLARITY_INVERTED>;
+
+ color-1 {
+ led-color = <&color_battery_off>;
+ period-ms = <3000>;
};
};
-};
-/* LED1 */
-&pwm0 {
- status = "okay";
- prescaler-cx = <PWM_PRESCALER_C4>;
- pinctrl-0 = <&pwm0_gpa0_default>;
- pinctrl-names = "default";
-};
+ bat-power-state-error-s3 {
+ charge-state = "PWR_STATE_ERROR";
+ chipset-state = "POWER_S3";
-/* LED2 */
-&pwm1 {
- status = "okay";
- prescaler-cx = <PWM_PRESCALER_C4>;
- pinctrl-0 = <&pwm1_gpa1_default>;
- pinctrl-names = "default";
-};
+ color-0 {
+ led-color = <&color_battery_white>;
+ period-ms = <1000>;
+ };
+
+ color-1 {
+ led-color = <&color_battery_off>;
+ period-ms = <1000>;
+ };
+ };
-/* LED3 */
-&pwm2 {
- status = "okay";
- prescaler-cx = <PWM_PRESCALER_C4>;
- pinctrl-0 = <&pwm2_gpa2_default>;
- pinctrl-names = "default";
+ bat-power-state-error-s5 {
+ charge-state = "PWR_STATE_ERROR";
+ chipset-state = "POWER_S5";
+
+ color-0 {
+ led-color = <&color_battery_off>;
+ };
+ };
};
diff --git a/zephyr/projects/corsola/src/krabby/led_tentacruel.c b/zephyr/projects/corsola/src/krabby/led_tentacruel.c
deleted file mode 100644
index 18a66752e2..0000000000
--- a/zephyr/projects/corsola/src/krabby/led_tentacruel.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/* Copyright 2022 The ChromiumOS Authors.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <zephyr/drivers/pwm.h>
-#include <zephyr/logging/log.h>
-#include "board_led.h"
-#include "chipset.h"
-#include "common.h"
-#include "led_common.h"
-#include "led_onoff_states.h"
-#include "util.h"
-
-LOG_MODULE_REGISTER(board_led, LOG_LEVEL_ERR);
-
-/*If we need pwm output in ITE chip power saving mode, then we should set
- * frequency <= 324Hz.
- */
-#define BOARD_LED_PWM_PERIOD_NS BOARD_LED_HZ_TO_PERIOD_NS(324)
-
-static const struct board_led_pwm_dt_channel board_led_power_white =
- BOARD_LED_PWM_DT_CHANNEL_INITIALIZER(DT_NODELABEL(led_power_white));
-static const struct board_led_pwm_dt_channel board_led_battery_amber =
- BOARD_LED_PWM_DT_CHANNEL_INITIALIZER(DT_NODELABEL(led_battery_amber));
-static const struct board_led_pwm_dt_channel board_led_battery_white =
- BOARD_LED_PWM_DT_CHANNEL_INITIALIZER(DT_NODELABEL(led_battery_white));
-
-__override const int led_charge_lvl_1 = 5;
-__override const int led_charge_lvl_2 = 95;
-
-__override struct led_descriptor
- led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = {
- [STATE_CHARGING_LVL_1] = { { EC_LED_COLOR_AMBER,
- LED_INDEFINITE } },
- [STATE_CHARGING_LVL_2] = { { EC_LED_COLOR_AMBER,
- LED_INDEFINITE } },
- [STATE_CHARGING_FULL_CHARGE] = { { EC_LED_COLOR_WHITE,
- LED_INDEFINITE } },
- [STATE_DISCHARGE_S0] = { { EC_LED_COLOR_WHITE,
- LED_INDEFINITE } },
- [STATE_DISCHARGE_S0_BAT_LOW] = { { EC_LED_COLOR_AMBER,
- 1 * LED_ONE_SEC },
- { LED_OFF, 3 * LED_ONE_SEC } },
- [STATE_DISCHARGE_S3] = { { EC_LED_COLOR_WHITE,
- 1 * LED_ONE_SEC },
- { LED_OFF, 3 * LED_ONE_SEC } },
- [STATE_DISCHARGE_S5] = { { LED_OFF, LED_INDEFINITE } },
- [STATE_BATTERY_ERROR] = { { EC_LED_COLOR_AMBER,
- 1 * LED_ONE_SEC },
- { LED_OFF, 1 * LED_ONE_SEC } },
- [STATE_FACTORY_TEST] = { { EC_LED_COLOR_WHITE,
- 2 * LED_ONE_SEC },
- { EC_LED_COLOR_AMBER,
- 2 * LED_ONE_SEC } },
- };
-
-__override const struct led_descriptor
- led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES] = {
- [PWR_LED_STATE_ON] = { { EC_LED_COLOR_WHITE, LED_INDEFINITE } },
- [PWR_LED_STATE_SUSPEND_AC] = { { EC_LED_COLOR_WHITE,
- 1 * LED_ONE_SEC },
- { LED_OFF, 3 * LED_ONE_SEC } },
- [PWR_LED_STATE_SUSPEND_NO_AC] = { { EC_LED_COLOR_WHITE,
- 1 * LED_ONE_SEC },
- { LED_OFF,
- 3 * LED_ONE_SEC } },
- [PWR_LED_STATE_OFF] = { { LED_OFF, LED_INDEFINITE } },
- };
-
-const enum ec_led_id supported_led_ids[] = {
- EC_LED_ID_BATTERY_LED,
- EC_LED_ID_POWER_LED,
-};
-
-const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
-
-static void board_led_pwm_set_duty(const struct board_led_pwm_dt_channel *ch,
- int percent)
-{
- uint32_t pulse_ns;
- int rv;
-
- if (!device_is_ready(ch->dev)) {
- LOG_ERR("PWM device %s not ready", ch->dev->name);
- return;
- }
-
- pulse_ns = DIV_ROUND_NEAREST(BOARD_LED_PWM_PERIOD_NS * percent, 100);
-
- LOG_DBG("Board LED PWM %s set percent (%d), pulse %d", ch->dev->name,
- percent, pulse_ns);
-
- rv = pwm_set(ch->dev, ch->channel, BOARD_LED_PWM_PERIOD_NS, pulse_ns,
- ch->flags);
- if (rv) {
- LOG_ERR("pwm_set() failed %s (%d)", ch->dev->name, rv);
- }
-}
-
-__override void led_set_color_battery(enum ec_led_colors color)
-{
- switch (color) {
- case EC_LED_COLOR_AMBER:
- board_led_pwm_set_duty(&board_led_battery_amber, 100);
- board_led_pwm_set_duty(&board_led_battery_white, 0);
- break;
- case EC_LED_COLOR_WHITE:
- board_led_pwm_set_duty(&board_led_battery_amber, 0);
- board_led_pwm_set_duty(&board_led_battery_white, 100);
- break;
- default:
- board_led_pwm_set_duty(&board_led_battery_amber, 0);
- board_led_pwm_set_duty(&board_led_battery_white, 0);
- break;
- }
-}
-
-__override void led_set_color_power(enum ec_led_colors color)
-{
- switch (color) {
- case EC_LED_COLOR_WHITE:
- board_led_pwm_set_duty(&board_led_power_white, 100);
- break;
- default:
- board_led_pwm_set_duty(&board_led_power_white, 0);
- break;
- }
-}
-
-void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
-{
- if (led_id == EC_LED_ID_BATTERY_LED) {
- brightness_range[EC_LED_COLOR_AMBER] = 1;
- brightness_range[EC_LED_COLOR_WHITE] = 1;
- } else if (led_id == EC_LED_ID_POWER_LED) {
- brightness_range[EC_LED_COLOR_WHITE] = 1;
- }
-}
-
-int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
-{
- if (led_id == EC_LED_ID_BATTERY_LED) {
- 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 {
- led_set_color_battery(LED_OFF);
- }
- } else if (led_id == EC_LED_ID_POWER_LED) {
- if (brightness[EC_LED_COLOR_WHITE] != 0) {
- led_set_color_power(EC_LED_COLOR_WHITE);
- } else {
- led_set_color_power(LED_OFF);
- }
- }
-
- return EC_SUCCESS;
-}
-
-__override enum led_states board_led_get_state(enum led_states desired_state)
-{
- /*
- * Battery error LED behavior as below:
- * S0: Blinking Amber LED, 1s on/ 1s off
- * S3/S5: following S3/S5 behavior
- * Add function to let battery error LED follow S3/S5 behavior in S3/S5.
- */
-
- if (desired_state == STATE_BATTERY_ERROR) {
- if (chipset_in_state(CHIPSET_STATE_ON)) {
- return desired_state;
- } else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) {
- return STATE_DISCHARGE_S3;
- } else {
- return STATE_DISCHARGE_S5;
- }
- }
- return desired_state;
-}