summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatryk Duda <pdk@semihalf.com>2021-03-18 13:45:17 +0000
committerCommit Bot <commit-bot@chromium.org>2021-03-29 16:29:26 +0000
commitf4b27032e1c508b693bba1f2d6572ad14d42f319 (patch)
treed69d14be564e34efbb81417f9ada83122b7a3c44
parent6f00183c755fe7c9e77adffb308626443e0b274a (diff)
downloadchrome-ec-f4b27032e1c508b693bba1f2d6572ad14d42f319.tar.gz
Use generic voltage reduce function instead of provided by board
This patch switches implementation of input voltage reduction to generic one. It removes reduce_input_voltage_when_full() function from board code and defines CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV with appropriate voltage. Affected boards: - Ampton - Asurada - Cherry - Dratini - Jinlon - Liara - Nocturne BUG=b:182546058 BRANCH=none TEST=Compile firmware for affected boards. TEST=Flash EC ToT on one of affected boards. Charge battery to full. Shutdown board and check if voltage is reduced. Power on board, check if previous voltage is restored. Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: I8f285e75c11f84f4711d5e6a4008174b6fb639cf Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2773219 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--board/ampton/battery.c34
-rw-r--r--board/ampton/board.h2
-rw-r--r--board/asurada/battery.c28
-rw-r--r--board/asurada/board.h2
-rw-r--r--board/cherry/battery.c28
-rw-r--r--board/cherry/board.h2
-rw-r--r--board/dratini/battery.c24
-rw-r--r--board/dratini/board.h2
-rw-r--r--board/jinlon/battery.c24
-rw-r--r--board/jinlon/board.h2
-rw-r--r--board/liara/battery.c24
-rw-r--r--board/liara/board.h2
-rw-r--r--board/nocturne/battery.c26
-rw-r--r--board/nocturne/board.h1
14 files changed, 13 insertions, 188 deletions
diff --git a/board/ampton/battery.c b/board/ampton/battery.c
index dab93a4869..ee9b9b96e9 100644
--- a/board/ampton/battery.c
+++ b/board/ampton/battery.c
@@ -120,37 +120,3 @@ const struct board_batt_params board_battery_info[] = {
BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_C214;
-static int saved_input_voltage = -1;
-
-/* Lower our input voltage to 5V in S5/G3 when battery is full. */
-static void reduce_input_voltage_when_full(void)
-{
- int max_pd_voltage_mv = pd_get_max_voltage();
- int port;
-
- if (charge_get_percent() == 100 &&
- chipset_in_or_transitioning_to_state(CHIPSET_STATE_ANY_OFF) &&
- max_pd_voltage_mv != 5000) {
- saved_input_voltage = max_pd_voltage_mv;
- max_pd_voltage_mv = 5000;
- }
- else if (saved_input_voltage != -1) {
- /*
- * Chipset is not in S5/G3 or battery is not full and input
- * voltage is reduced
- */
- max_pd_voltage_mv = saved_input_voltage;
- saved_input_voltage = -1;
- }
-
- if (pd_get_max_voltage() != max_pd_voltage_mv) {
- for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++)
- pd_set_external_voltage_limit(port, max_pd_voltage_mv);
- }
-}
-DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
diff --git a/board/ampton/board.h b/board/ampton/board.h
index 69304cb7c8..c72378d625 100644
--- a/board/ampton/board.h
+++ b/board/ampton/board.h
@@ -26,6 +26,8 @@
#define CONFIG_LED_COMMON
+#define CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV 5000
+
/* Sensors */
#define CONFIG_TEMP_SENSOR
#define CONFIG_THERMISTOR
diff --git a/board/asurada/battery.c b/board/asurada/battery.c
index 570d263c4a..6237a5058c 100644
--- a/board/asurada/battery.c
+++ b/board/asurada/battery.c
@@ -45,31 +45,3 @@ const struct board_batt_params board_battery_info[] = {
BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_C235;
-
-static void reduce_input_voltage_when_full(void)
-{
- struct batt_params batt;
- int max_pd_voltage_mv;
- int active_chg_port;
-
- if (!system_is_locked())
- return;
-
- active_chg_port = charge_manager_get_active_charge_port();
- if (active_chg_port == CHARGE_PORT_NONE)
- return;
-
- battery_get_params(&batt);
- /* Lower our input voltage to 9V when battery is full. */
- if (!(batt.flags & BATT_FLAG_BAD_STATUS) &&
- (batt.status & STATUS_FULLY_CHARGED) &&
- chipset_in_state(CHIPSET_STATE_ANY_OFF))
- max_pd_voltage_mv = 9000;
- else
- max_pd_voltage_mv = PD_MAX_VOLTAGE_MV;
-
- if (pd_get_max_voltage() != max_pd_voltage_mv)
- pd_set_external_voltage_limit(active_chg_port,
- max_pd_voltage_mv);
-}
-DECLARE_HOOK(HOOK_SECOND, reduce_input_voltage_when_full, HOOK_PRIO_DEFAULT);
diff --git a/board/asurada/board.h b/board/asurada/board.h
index c4a17ac4cb..08a56ac0b4 100644
--- a/board/asurada/board.h
+++ b/board/asurada/board.h
@@ -41,6 +41,8 @@
#define CONFIG_CMD_SCRATCHPAD
#define CONFIG_CMD_STACKOVERFLOW
+#define CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV 9000
+
/* Sensor */
#define CONFIG_GMR_TABLET_MODE
#define CONFIG_TABLET_MODE
diff --git a/board/cherry/battery.c b/board/cherry/battery.c
index f681008b98..f07c38e1b8 100644
--- a/board/cherry/battery.c
+++ b/board/cherry/battery.c
@@ -45,31 +45,3 @@ const struct board_batt_params board_battery_info[] = {
BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_C235;
-
-static void reduce_input_voltage_when_full(void)
-{
- struct batt_params batt;
- int max_pd_voltage_mv;
- int active_chg_port;
-
- if (!system_is_locked())
- return;
-
- active_chg_port = charge_manager_get_active_charge_port();
- if (active_chg_port == CHARGE_PORT_NONE)
- return;
-
- battery_get_params(&batt);
- /* Lower our input voltage to 9V when battery is full. */
- if (!(batt.flags & BATT_FLAG_BAD_STATUS) &&
- (batt.status & STATUS_FULLY_CHARGED) &&
- chipset_in_state(CHIPSET_STATE_ANY_OFF))
- max_pd_voltage_mv = 9000;
- else
- max_pd_voltage_mv = PD_MAX_VOLTAGE_MV;
-
- if (pd_get_max_voltage() != max_pd_voltage_mv)
- pd_set_external_voltage_limit(active_chg_port,
- max_pd_voltage_mv);
-}
-DECLARE_HOOK(HOOK_SECOND, reduce_input_voltage_when_full, HOOK_PRIO_DEFAULT);
diff --git a/board/cherry/board.h b/board/cherry/board.h
index 5795c61f1c..c9e898e945 100644
--- a/board/cherry/board.h
+++ b/board/cherry/board.h
@@ -37,6 +37,8 @@
#define CONFIG_CMD_SCRATCHPAD
#define CONFIG_CMD_STACKOVERFLOW
+#define CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV 9000
+
/* Sensor */
#define CONFIG_GMR_TABLET_MODE
#define CONFIG_TABLET_MODE
diff --git a/board/dratini/battery.c b/board/dratini/battery.c
index dafd0c9425..77c84cd973 100644
--- a/board/dratini/battery.c
+++ b/board/dratini/battery.c
@@ -96,27 +96,3 @@ const struct board_batt_params board_battery_info[] = {
BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_SIMPLO_COS;
-
-/* Lower our input voltage to 5V in S5/G3 when battery is full. */
-static void reduce_input_voltage_when_full(void)
-{
- int max_pd_voltage_mv;
- int port;
-
- if (charge_get_percent() == 100 &&
- chipset_in_or_transitioning_to_state(CHIPSET_STATE_ANY_OFF))
- max_pd_voltage_mv = 5000;
- else
- max_pd_voltage_mv = PD_MAX_VOLTAGE_MV;
-
- if (pd_get_max_voltage() != max_pd_voltage_mv) {
- for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++)
- pd_set_external_voltage_limit(port, max_pd_voltage_mv);
- }
-}
-DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
diff --git a/board/dratini/board.h b/board/dratini/board.h
index 8f25d7362a..5878f17af1 100644
--- a/board/dratini/board.h
+++ b/board/dratini/board.h
@@ -33,6 +33,8 @@
#undef CONFIG_POWER_BUTTON_INIT_TIMEOUT
#define CONFIG_POWER_BUTTON_INIT_TIMEOUT 6
+#define CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV 5000
+
/* Sensors */
/* BMI160 Base accel/gyro */
#define CONFIG_ACCEL_INTERRUPTS
diff --git a/board/jinlon/battery.c b/board/jinlon/battery.c
index cf3941221c..e21df14734 100644
--- a/board/jinlon/battery.c
+++ b/board/jinlon/battery.c
@@ -67,27 +67,3 @@ const struct board_batt_params board_battery_info[] = {
BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_DANAPACK_COS;
-
-/* Lower our input voltage to 5V in S5/G3 when battery is full. */
-static void reduce_input_voltage_when_full(void)
-{
- int max_pd_voltage_mv;
- int port;
-
- if (charge_get_percent() == 100 &&
- chipset_in_or_transitioning_to_state(CHIPSET_STATE_ANY_OFF))
- max_pd_voltage_mv = 5000;
- else
- max_pd_voltage_mv = PD_MAX_VOLTAGE_MV;
-
- if (pd_get_max_voltage() != max_pd_voltage_mv) {
- for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++)
- pd_set_external_voltage_limit(port, max_pd_voltage_mv);
- }
-}
-DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
diff --git a/board/jinlon/board.h b/board/jinlon/board.h
index f898b90c9a..9ef601877f 100644
--- a/board/jinlon/board.h
+++ b/board/jinlon/board.h
@@ -35,6 +35,8 @@
#undef CONFIG_POWER_BUTTON_INIT_TIMEOUT
#define CONFIG_POWER_BUTTON_INIT_TIMEOUT 6
+#define CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV 5000
+
/* Sensors */
/* BMI160 Base accel/gyro */
#define CONFIG_ACCEL_INTERRUPTS
diff --git a/board/liara/battery.c b/board/liara/battery.c
index 25df841018..bf244125b0 100644
--- a/board/liara/battery.c
+++ b/board/liara/battery.c
@@ -165,27 +165,3 @@ const struct board_batt_params board_battery_info[] = {
BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_PANASONIC;
-
-/* Lower our input voltage to 5V in S5/G3 when battery is full. */
-static void reduce_input_voltage_when_full(void)
-{
- int max_pd_voltage_mv;
- int port;
-
- if (charge_get_percent() == 100 &&
- chipset_in_or_transitioning_to_state(CHIPSET_STATE_ANY_OFF))
- max_pd_voltage_mv = 5000;
- else
- max_pd_voltage_mv = PD_MAX_VOLTAGE_MV;
-
- if (pd_get_max_voltage() != max_pd_voltage_mv) {
- for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++)
- pd_set_external_voltage_limit(port, max_pd_voltage_mv);
- }
-}
-DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, reduce_input_voltage_when_full,
- HOOK_PRIO_DEFAULT);
diff --git a/board/liara/board.h b/board/liara/board.h
index b869f9f8c1..ae4494115b 100644
--- a/board/liara/board.h
+++ b/board/liara/board.h
@@ -23,6 +23,8 @@
#define CONFIG_MKBP_USE_HOST_EVENT
+#define CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV 5000
+
/* Power and battery LEDs */
#define CONFIG_LED_COMMON
#define CONFIG_LED_PWM_CHARGE_STATE_ONLY
diff --git a/board/nocturne/battery.c b/board/nocturne/battery.c
index 67c5346063..ff3f16fa33 100644
--- a/board/nocturne/battery.c
+++ b/board/nocturne/battery.c
@@ -99,32 +99,6 @@ enum battery_disconnect_state battery_get_disconnect_state(void)
return BATTERY_DISCONNECTED;
}
-static void reduce_input_voltage_when_full(void)
-{
- struct batt_params batt;
- int max_pd_voltage_mv;
- int active_chg_port;
-
- active_chg_port = charge_manager_get_active_charge_port();
- if (active_chg_port == CHARGE_PORT_NONE)
- return;
-
- battery_get_params(&batt);
- if (!(batt.flags & BATT_FLAG_BAD_STATUS)) {
- /* Lower our input voltage to 9V when battery is full. */
- if ((batt.status & STATUS_FULLY_CHARGED) &&
- chipset_in_state(CHIPSET_STATE_ANY_OFF))
- max_pd_voltage_mv = 9000;
- else
- max_pd_voltage_mv = PD_MAX_VOLTAGE_MV;
-
- if (pd_get_max_voltage() != max_pd_voltage_mv)
- pd_set_external_voltage_limit(active_chg_port,
- max_pd_voltage_mv);
- }
-}
-DECLARE_HOOK(HOOK_SECOND, reduce_input_voltage_when_full, HOOK_PRIO_DEFAULT);
-
enum ec_status charger_profile_override_get_param(uint32_t param,
uint32_t *value)
{
diff --git a/board/nocturne/board.h b/board/nocturne/board.h
index cd840629d0..046b41d7db 100644
--- a/board/nocturne/board.h
+++ b/board/nocturne/board.h
@@ -60,6 +60,7 @@
#define CONFIG_BATTERY_SMART
#define CONFIG_BATTERY_REVIVE_DISCONNECT
#define CONFIG_BATTERY_PRESENT_GPIO GPIO_BAT_PRESENT_L
+#define CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV 9000
/* Buttons / Switches */
#define CONFIG_BASE_ATTACHED_SWITCH