summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--baseboard/brya/charger_bq25720.c7
-rw-r--r--baseboard/grunt/baseboard.c5
-rw-r--r--baseboard/grunt/baseboard.h1
-rw-r--r--baseboard/octopus/baseboard.c7
-rw-r--r--baseboard/octopus/baseboard.h4
-rw-r--r--board/anahera/board.c12
-rw-r--r--board/anahera/board.h2
-rw-r--r--board/anahera/charger.c4
-rw-r--r--board/atlas/board.c17
-rw-r--r--board/atlas/board.h1
-rw-r--r--board/beetley/board.c5
-rw-r--r--board/beetley/board.h5
-rw-r--r--board/bellis/board.c1
-rw-r--r--board/bellis/board.h1
-rw-r--r--board/blipper/board.c6
-rw-r--r--board/blipper/board.h5
-rw-r--r--board/boten/board.c6
-rw-r--r--board/boten/board.h5
-rw-r--r--board/brya/charger.c4
-rw-r--r--board/bugzzy/board.c6
-rw-r--r--board/bugzzy/board.h5
-rw-r--r--board/burnet/board.c1
-rw-r--r--board/burnet/board.h1
-rw-r--r--board/cappy2/board.c6
-rw-r--r--board/cappy2/board.h5
-rw-r--r--board/cerise/board.c1
-rw-r--r--board/cerise/board.h1
-rw-r--r--board/coachz/board.c1
-rw-r--r--board/coachz/board.h2
-rw-r--r--board/coral/board.c1
-rw-r--r--board/coral/board.h1
-rw-r--r--board/corori/board.c6
-rw-r--r--board/corori/board.h5
-rw-r--r--board/corori2/board.c6
-rw-r--r--board/corori2/board.h5
-rw-r--r--board/cret/board.c6
-rw-r--r--board/cret/board.h5
-rw-r--r--board/damu/board.c1
-rw-r--r--board/damu/board.h1
-rw-r--r--board/driblee/board.c6
-rw-r--r--board/driblee/board.h5
-rw-r--r--board/drobit/board.c5
-rw-r--r--board/drobit/board.h1
-rw-r--r--board/eldrid/board.c6
-rw-r--r--board/eldrid/board.h2
-rw-r--r--board/elm/board.c2
-rw-r--r--board/elm/board.h1
-rw-r--r--board/eve/board.c1
-rw-r--r--board/eve/board.h1
-rw-r--r--board/ezkinil/board.c6
-rw-r--r--board/ezkinil/board.h3
-rw-r--r--board/felwinter/board.h1
-rw-r--r--board/felwinter/charger_isl9241.c5
-rw-r--r--board/fennel/board.c1
-rw-r--r--board/fennel/board.h1
-rw-r--r--board/gelarshie/board.c1
-rw-r--r--board/gelarshie/board.h3
-rw-r--r--board/gimble/board.c13
-rw-r--r--board/gimble/board.h2
-rw-r--r--board/gimble/charger.c4
-rw-r--r--board/gooey/board.c6
-rw-r--r--board/gooey/board.h5
-rw-r--r--board/homestar/board.c1
-rw-r--r--board/homestar/board.h3
-rw-r--r--board/icarus/board.c1
-rw-r--r--board/icarus/board.h1
-rw-r--r--board/jacuzzi/board.c1
-rw-r--r--board/jacuzzi/board.h1
-rw-r--r--board/kappa/board.c1
-rw-r--r--board/kappa/board.h1
-rw-r--r--board/lalala/board.c6
-rw-r--r--board/lalala/board.h5
-rw-r--r--board/madoo/board.c7
-rw-r--r--board/madoo/board.h5
-rw-r--r--board/magolor/board.c6
-rw-r--r--board/magolor/board.h5
-rw-r--r--board/makomo/board.c1
-rw-r--r--board/makomo/board.h1
-rw-r--r--board/metaknight/board.c6
-rw-r--r--board/metaknight/board.h5
-rw-r--r--board/mithrax/board.h1
-rw-r--r--board/mithrax/charger_isl9241.c1
-rw-r--r--board/mrbland/board.c1
-rw-r--r--board/mrbland/board.h2
-rw-r--r--board/munna/board.c1
-rw-r--r--board/munna/board.h1
-rw-r--r--board/nautilus/board.c5
-rw-r--r--board/nautilus/board.h1
-rw-r--r--board/nocturne/board.c6
-rw-r--r--board/nocturne/board.h5
-rw-r--r--board/pico/board.c1
-rw-r--r--board/pico/board.h1
-rw-r--r--board/pompom/board.c1
-rw-r--r--board/pompom/board.h2
-rw-r--r--board/primus/charger.c7
-rw-r--r--board/quackingstick/board.c1
-rw-r--r--board/quackingstick/board.h2
-rw-r--r--board/rammus/board.c5
-rw-r--r--board/rammus/board.h1
-rw-r--r--board/reef/board.c1
-rw-r--r--board/reef/board.h1
-rw-r--r--board/reef_it8320/board.c1
-rw-r--r--board/reef_it8320/board.h1
-rw-r--r--board/reef_mchp/board.c1
-rw-r--r--board/reef_mchp/board.h1
-rw-r--r--board/sasuke/board.c6
-rw-r--r--board/sasuke/board.h5
-rw-r--r--board/sasukette/board.c6
-rw-r--r--board/sasukette/board.h5
-rw-r--r--board/stern/board.c1
-rw-r--r--board/stern/board.h1
-rw-r--r--board/storo/board.c6
-rw-r--r--board/storo/board.h5
-rw-r--r--board/taeko/board.c13
-rw-r--r--board/taeko/board.h3
-rw-r--r--board/taeko/charger.c4
-rw-r--r--board/taniks/board.c13
-rw-r--r--board/taniks/board.h3
-rw-r--r--board/taniks/charger.c4
-rw-r--r--board/vell/board.h2
-rw-r--r--board/vell/charger.c5
-rw-r--r--board/vilboz/board.c6
-rw-r--r--board/vilboz/board.h1
-rw-r--r--board/waddledoo/board.c6
-rw-r--r--board/waddledoo/board.h5
-rw-r--r--board/waddledoo2/board.c6
-rw-r--r--board/waddledoo2/board.h5
-rw-r--r--board/willow/board.c1
-rw-r--r--board/willow/board.h1
-rw-r--r--board/wormdingler/board.c1
-rw-r--r--board/wormdingler/board.h2
-rw-r--r--common/charge_state_v2.c7
-rw-r--r--include/charge_state_v2.h3
-rw-r--r--include/config.h15
-rw-r--r--zephyr/Kconfig.usbc16
-rw-r--r--zephyr/program/corsola/program.conf3
-rw-r--r--zephyr/program/corsola/src/usbc_config.c7
-rw-r--r--zephyr/program/nissa/program.conf2
-rw-r--r--zephyr/program/nissa/src/common.c7
-rw-r--r--zephyr/program/nissa/xivu/project.conf2
-rw-r--r--zephyr/program/skyrim/Kconfig6
-rw-r--r--zephyr/program/skyrim/prj_frostflow.conf2
-rw-r--r--zephyr/program/skyrim/src/usbc_config.c2
-rw-r--r--zephyr/shim/include/config_chip.h6
-rw-r--r--zephyr/test/drivers/common_charger/src/test_charge_state_v2.c17
-rw-r--r--zephyr/test/drivers/testcase.yaml1
146 files changed, 254 insertions, 311 deletions
diff --git a/baseboard/brya/charger_bq25720.c b/baseboard/brya/charger_bq25720.c
index a4fa209246..7fabd2082e 100644
--- a/baseboard/brya/charger_bq25720.c
+++ b/baseboard/brya/charger_bq25720.c
@@ -81,10 +81,3 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-
-__overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
-{
- charge_set_input_current_limit(
- MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
-}
diff --git a/baseboard/grunt/baseboard.c b/baseboard/grunt/baseboard.c
index 5fbf2823be..50db1887f1 100644
--- a/baseboard/grunt/baseboard.c
+++ b/baseboard/grunt/baseboard.c
@@ -467,11 +467,6 @@ int board_set_active_charge_port(int port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- /*
- * Limit the input current to 95% negotiated limit,
- * to account for the charger chip margin.
- */
- charge_ma = charge_ma * 95 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/baseboard/grunt/baseboard.h b/baseboard/grunt/baseboard.h
index 1c19c05330..b83b274d49 100644
--- a/baseboard/grunt/baseboard.h
+++ b/baseboard/grunt/baseboard.h
@@ -73,6 +73,7 @@
* See also b/111214767
*/
#define CONFIG_CHARGER_INPUT_CURRENT 512
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_ISL9238
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20
diff --git a/baseboard/octopus/baseboard.c b/baseboard/octopus/baseboard.c
index 0f012d1352..b35bbcd67b 100644
--- a/baseboard/octopus/baseboard.c
+++ b/baseboard/octopus/baseboard.c
@@ -301,13 +301,6 @@ int board_set_active_charge_port(int port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- /*
- * Empirically, the charger seems to draw a little more current that
- * it is set to, so we reduce our limit by 5%.
- */
-#if defined(CONFIG_CHARGER_BQ25710) || defined(CONFIG_CHARGER_ISL9238)
- charge_ma = (charge_ma * 95) / 100;
-#endif
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/baseboard/octopus/baseboard.h b/baseboard/octopus/baseboard.h
index 724540d0f0..8662749c98 100644
--- a/baseboard/octopus/baseboard.h
+++ b/baseboard/octopus/baseboard.h
@@ -125,6 +125,8 @@
*/
#undef CONFIG_EXTPOWER_DEBOUNCE_MS
#define CONFIG_EXTPOWER_DEBOUNCE_MS 200
+/* Charger seems to overdraw by about 5% */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#elif defined(VARIANT_OCTOPUS_CHARGER_BQ25703)
#define CONFIG_CHARGER_BQ25703
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
@@ -133,6 +135,8 @@
*/
#undef CONFIG_EXTPOWER_DEBOUNCE_MS
#define CONFIG_EXTPOWER_DEBOUNCE_MS 50
+/* Charger seems to overdraw by about 5% */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#elif defined(CONFIG_CHARGER_RUNTIME_CONFIG)
#define CONFIG_CHARGER_ISL9238
#define CONFIG_CHARGER_BQ25710
diff --git a/board/anahera/board.c b/board/anahera/board.c
index e087d629a7..cd9eb30870 100644
--- a/board/anahera/board.c
+++ b/board/anahera/board.c
@@ -64,15 +64,3 @@ enum battery_present battery_hw_present(void)
/* The GPIO is low when the battery is physically present */
return gpio_get_level(GPIO_EC_BATT_PRES_ODL) ? BP_NO : BP_YES;
}
-
-__override void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
-{
- /*
- * Limit the input current to 95% negotiated limit,
- * to account for the charger chip margin.
- */
- charge_ma = charge_ma * 95 / 100;
- charge_set_input_current_limit(
- MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
-}
diff --git a/board/anahera/board.h b/board/anahera/board.h
index 18360171e3..82ba5a4e1c 100644
--- a/board/anahera/board.h
+++ b/board/anahera/board.h
@@ -33,6 +33,8 @@
#define CONFIG_USB_PORT_POWER_DUMB
#define CONFIG_USBC_RETIMER_PS8811
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* USB Type C and USB PD defines */
#define CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY
diff --git a/board/anahera/charger.c b/board/anahera/charger.c
index a4fa209246..29211bc033 100644
--- a/board/anahera/charger.c
+++ b/board/anahera/charger.c
@@ -82,8 +82,8 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-__overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
+__override void board_set_charge_limit(int port, int supplier, int charge_ma,
+ int max_ma, int charge_mv)
{
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
diff --git a/board/atlas/board.c b/board/atlas/board.c
index 6fbbb64b16..633543b51f 100644
--- a/board/atlas/board.c
+++ b/board/atlas/board.c
@@ -531,20 +531,12 @@ int board_set_active_charge_port(int charge_port)
return EC_SUCCESS;
}
-/*
- * Limit the input current to 95% negotiated limit,
- * to account for the charger chip margin.
- */
-
-static int charger_derate(int current)
-{
- return current * 95 / 100;
-}
-
static void board_charger_init(void)
{
- charger_set_input_current_limit(CHARGER_SOLO,
- charger_derate(PD_MAX_CURRENT_MA));
+ charger_set_input_current_limit(
+ CHARGER_SOLO,
+ PD_MAX_CURRENT_MA *
+ (100 - CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT) / 100);
}
DECLARE_HOOK(HOOK_INIT, board_charger_init, HOOK_PRIO_DEFAULT);
@@ -559,7 +551,6 @@ DECLARE_HOOK(HOOK_INIT, board_charger_init, HOOK_PRIO_DEFAULT);
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = charger_derate(charge_ma);
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/atlas/board.h b/board/atlas/board.h
index 9718ab7cdd..97f6d67e49 100644
--- a/board/atlas/board.h
+++ b/board/atlas/board.h
@@ -78,6 +78,7 @@
#define CONFIG_CHARGER_ISL9238
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 512
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_PROFILE_OVERRIDE
#define CONFIG_CHARGER_PSYS
#define CONFIG_CHARGER_PSYS_READ
diff --git a/board/beetley/board.c b/board/beetley/board.c
index f6b1f1008c..e0ba900a70 100644
--- a/board/beetley/board.c
+++ b/board/beetley/board.c
@@ -389,11 +389,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/beetley/board.h b/board/beetley/board.h
index a70ee73ebb..b05b8e2eb5 100644
--- a/board/beetley/board.h
+++ b/board/beetley/board.h
@@ -27,6 +27,11 @@
/* Charger */
#define CONFIG_CHARGE_RAMP_HW
#define CONFIG_CHARGER_RAA489000
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
#define PD_MAX_VOLTAGE_MV 20000
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
#define CONFIG_CHARGER_SENSE_RESISTOR 10
diff --git a/board/bellis/board.c b/board/bellis/board.c
index e03ae1c36c..fc960749f3 100644
--- a/board/bellis/board.c
+++ b/board/bellis/board.c
@@ -239,7 +239,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/bellis/board.h b/board/bellis/board.h
index d502c4c5ef..0741de5dc7 100644
--- a/board/bellis/board.h
+++ b/board/bellis/board.h
@@ -40,6 +40,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/blipper/board.c b/board/blipper/board.c
index 766f55579c..b7782a8af9 100644
--- a/board/blipper/board.c
+++ b/board/blipper/board.c
@@ -540,12 +540,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/blipper/board.h b/board/blipper/board.h
index 379a92a007..896ebec76a 100644
--- a/board/blipper/board.h
+++ b/board/blipper/board.h
@@ -29,6 +29,11 @@
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/* DAC for PSYS */
#define CONFIG_DAC
diff --git a/board/boten/board.c b/board/boten/board.c
index c47b9e46f0..9a54a4a341 100644
--- a/board/boten/board.c
+++ b/board/boten/board.c
@@ -248,12 +248,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/boten/board.h b/board/boten/board.h
index ec5d25ff9f..2e607f73c1 100644
--- a/board/boten/board.h
+++ b/board/boten/board.h
@@ -32,6 +32,11 @@
*/
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/* DAC for PSYS */
#define CONFIG_DAC
diff --git a/board/brya/charger.c b/board/brya/charger.c
index a4fa209246..b1a29c725b 100644
--- a/board/brya/charger.c
+++ b/board/brya/charger.c
@@ -82,8 +82,8 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-__overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
+void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
+ int charge_mv)
{
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
diff --git a/board/bugzzy/board.c b/board/bugzzy/board.c
index 5a28fb2c25..b6a015999e 100644
--- a/board/bugzzy/board.c
+++ b/board/bugzzy/board.c
@@ -397,12 +397,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/bugzzy/board.h b/board/bugzzy/board.h
index b1d8568ee1..45bdfdc9f3 100644
--- a/board/bugzzy/board.h
+++ b/board/bugzzy/board.h
@@ -43,6 +43,11 @@
#undef CONFIG_CHARGER_SINGLE_CHIP
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
#define CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS
#define CONFIG_CHARGER_PROFILE_OVERRIDE
diff --git a/board/burnet/board.c b/board/burnet/board.c
index aa378ca289..923a7a76ce 100644
--- a/board/burnet/board.c
+++ b/board/burnet/board.c
@@ -225,7 +225,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/burnet/board.h b/board/burnet/board.h
index 6870ccc2d2..17ca27daea 100644
--- a/board/burnet/board.h
+++ b/board/burnet/board.h
@@ -28,6 +28,7 @@
#define CONFIG_BATTERY_COUNT 1
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_BC12_DETECT_PI3USB9201
diff --git a/board/cappy2/board.c b/board/cappy2/board.c
index de651ac874..d81e731ebf 100644
--- a/board/cappy2/board.c
+++ b/board/cappy2/board.c
@@ -233,12 +233,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/cappy2/board.h b/board/cappy2/board.h
index b21a20d6e5..8f503b1bcc 100644
--- a/board/cappy2/board.h
+++ b/board/cappy2/board.h
@@ -39,6 +39,11 @@
#define CONFIG_CHARGER_PROFILE_OVERRIDE
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/* Keyboard */
#undef CONFIG_PWM_KBLIGHT
diff --git a/board/cerise/board.c b/board/cerise/board.c
index e3fa60c76a..62fbc69254 100644
--- a/board/cerise/board.c
+++ b/board/cerise/board.c
@@ -239,7 +239,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/cerise/board.h b/board/cerise/board.h
index 41d86b956d..d2c58e9f6e 100644
--- a/board/cerise/board.h
+++ b/board/cerise/board.h
@@ -28,6 +28,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/coachz/board.c b/board/coachz/board.c
index 723078036a..96ed26b819 100644
--- a/board/coachz/board.c
+++ b/board/coachz/board.c
@@ -697,7 +697,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
charge_ma = max_ma;
}
- charge_ma = charge_ma * 95 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/coachz/board.h b/board/coachz/board.h
index c332b98c34..70594d3efa 100644
--- a/board/coachz/board.h
+++ b/board/coachz/board.h
@@ -40,6 +40,8 @@
#define CONFIG_BATTERY_FUEL_GAUGE
#define CONFIG_BATTERY_VENDOR_PARAM
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* BC 1.2 Charger */
#define CONFIG_BC12_DETECT_PI3USB9201
diff --git a/board/coral/board.c b/board/coral/board.c
index c63a2f6ddc..922a19e97c 100644
--- a/board/coral/board.c
+++ b/board/coral/board.c
@@ -566,7 +566,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
if (bd9995x_bc12_enable_charging(port, bc12_enable))
return;
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/coral/board.h b/board/coral/board.h
index bc6226152c..eee201669c 100644
--- a/board/coral/board.h
+++ b/board/coral/board.h
@@ -25,6 +25,7 @@
#define CONFIG_CMD_CHARGER_ADC_AMON_BMON
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define BD9995X_IOUT_GAIN_SELECT \
BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_20V
diff --git a/board/corori/board.c b/board/corori/board.c
index 4fe1e01fec..09baf1eabf 100644
--- a/board/corori/board.c
+++ b/board/corori/board.c
@@ -315,12 +315,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/corori/board.h b/board/corori/board.h
index 75e0e4eec6..646b14227d 100644
--- a/board/corori/board.h
+++ b/board/corori/board.h
@@ -28,6 +28,11 @@
#undef CONFIG_CMD_CHARGER_DUMP
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/* LED defines */
#define CONFIG_LED_COMMON
diff --git a/board/corori2/board.c b/board/corori2/board.c
index efebc3af2e..c06ccbb15b 100644
--- a/board/corori2/board.c
+++ b/board/corori2/board.c
@@ -458,12 +458,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/corori2/board.h b/board/corori2/board.h
index 79c57c98bb..c62cade1c3 100644
--- a/board/corori2/board.h
+++ b/board/corori2/board.h
@@ -50,6 +50,11 @@
#undef CONFIG_CHARGER_SINGLE_CHIP
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/*
* GPIO for C1 interrupts, for baseboard use
diff --git a/board/cret/board.c b/board/cret/board.c
index c9c34d6d32..90bfc7d41a 100644
--- a/board/cret/board.c
+++ b/board/cret/board.c
@@ -308,12 +308,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/cret/board.h b/board/cret/board.h
index 2080185c7c..eb6b261cdf 100644
--- a/board/cret/board.h
+++ b/board/cret/board.h
@@ -34,6 +34,11 @@
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
#define CONFIG_CHARGER_PROFILE_OVERRIDE
#define CHARGING_CURRENT_1100MA 1100
diff --git a/board/damu/board.c b/board/damu/board.c
index ddc8885e22..a2415f228d 100644
--- a/board/damu/board.c
+++ b/board/damu/board.c
@@ -239,7 +239,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/damu/board.h b/board/damu/board.h
index 49875e6883..16e03cf45c 100644
--- a/board/damu/board.h
+++ b/board/damu/board.h
@@ -28,6 +28,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/driblee/board.c b/board/driblee/board.c
index 30075e683e..5c78dbda06 100644
--- a/board/driblee/board.c
+++ b/board/driblee/board.c
@@ -342,12 +342,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/driblee/board.h b/board/driblee/board.h
index f6a3ac9130..514fe584ff 100644
--- a/board/driblee/board.h
+++ b/board/driblee/board.h
@@ -31,6 +31,11 @@
#undef CONFIG_CMD_CHARGER_DUMP
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
#define CONFIG_MATH_UTIL
#define CONFIG_CHARGER_PROFILE_OVERRIDE
#define CHARGING_CURRENT_1100MA 1100
diff --git a/board/drobit/board.c b/board/drobit/board.c
index 1a20870d1f..c2bdbec773 100644
--- a/board/drobit/board.c
+++ b/board/drobit/board.c
@@ -481,11 +481,6 @@ DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT);
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- /*
- * Limit the input current to 98% negotiated limit,
- * to account for the charger chip margin.
- */
- charge_ma = charge_ma * 98 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/drobit/board.h b/board/drobit/board.h
index d6fda98f3d..bf3e64ae5a 100644
--- a/board/drobit/board.h
+++ b/board/drobit/board.h
@@ -89,6 +89,7 @@
/* charger defines */
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 2
/*
* Macros for GPIO signals used in common code that don't match the
diff --git a/board/eldrid/board.c b/board/eldrid/board.c
index 81fdf22ffc..6212c6a375 100644
--- a/board/eldrid/board.c
+++ b/board/eldrid/board.c
@@ -182,12 +182,6 @@ __override void board_set_charge_limit(int port, int supplier, int charge_ma,
else
isl9241_set_ac_prochot(0, 3328);
- /*
- * Follow OEM request to limit the input current to
- * 90% negotiated limit.
- */
- charge_ma = charge_ma * 90 / 100;
-
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/eldrid/board.h b/board/eldrid/board.h
index 1bbe183425..8cfac4d8bc 100644
--- a/board/eldrid/board.h
+++ b/board/eldrid/board.h
@@ -93,6 +93,8 @@
/* charger defines */
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
+/* OEM requested 10% derating */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 10
/* Retimer */
#undef CONFIG_USBC_RETIMER_INTEL_BB
diff --git a/board/elm/board.c b/board/elm/board.c
index 4007d34379..329c411c8a 100644
--- a/board/elm/board.c
+++ b/board/elm/board.c
@@ -340,8 +340,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- /* Limit input current 95% ratio on elm board for safety */
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
pd_send_host_event(PD_EVENT_POWER_CHANGE);
diff --git a/board/elm/board.h b/board/elm/board.h
index 2dc53dab75..31a6ec7b61 100644
--- a/board/elm/board.h
+++ b/board/elm/board.h
@@ -44,6 +44,7 @@
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20
#define CONFIG_CHARGER_DISCHARGE_ON_AC
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHIPSET_MT817X
#define CONFIG_CMD_TYPEC
#define CONFIG_EXTPOWER_GPIO
diff --git a/board/eve/board.c b/board/eve/board.c
index 3f5da1a83a..77e5b403a0 100644
--- a/board/eve/board.c
+++ b/board/eve/board.c
@@ -646,7 +646,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
if (bd9995x_bc12_enable_charging(port, bc12_enable))
return;
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/eve/board.h b/board/eve/board.h
index 064bce4b60..361f2ddd53 100644
--- a/board/eve/board.h
+++ b/board/eve/board.h
@@ -101,6 +101,7 @@
#define CONFIG_CHARGER_BD9995X_CHGEN
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 512
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_MAINTAIN_VBAT
#define CONFIG_CHARGER_PROFILE_OVERRIDE
#define CONFIG_CHARGER_PSYS_READ
diff --git a/board/ezkinil/board.c b/board/ezkinil/board.c
index c9e1aca267..2173a2062d 100644
--- a/board/ezkinil/board.c
+++ b/board/ezkinil/board.c
@@ -869,12 +869,6 @@ int fan_percent_to_rpm(int fan, int pct)
__override void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
- /*
- * Limit the input current to 95% negotiated limit,
- * to account for the charger chip margin.
- */
- charge_ma = charge_ma * 95 / 100;
-
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/ezkinil/board.h b/board/ezkinil/board.h
index aa1fe065f4..c5e6ce1771 100644
--- a/board/ezkinil/board.h
+++ b/board/ezkinil/board.h
@@ -15,6 +15,9 @@
#define CONFIG_KEYBOARD_FACTORY_TEST
+/* charger margin */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* Motion sensing drivers */
#define CONFIG_ACCELGYRO_ICM426XX
#define CONFIG_ACCELGYRO_ICM426XX_INT_EVENT \
diff --git a/board/felwinter/board.h b/board/felwinter/board.h
index 17e1cf9246..0ca6a59b9c 100644
--- a/board/felwinter/board.h
+++ b/board/felwinter/board.h
@@ -179,6 +179,7 @@
#define CONFIG_CHARGE_RAMP_SW
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 10
#define CONFIG_KEYBOARD_REFRESH_ROW3
diff --git a/board/felwinter/charger_isl9241.c b/board/felwinter/charger_isl9241.c
index dd2535ea7c..7d4026b818 100644
--- a/board/felwinter/charger_isl9241.c
+++ b/board/felwinter/charger_isl9241.c
@@ -80,10 +80,9 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-__overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
+void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
+ int charge_mv)
{
- charge_ma = (charge_ma * 90) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/fennel/board.c b/board/fennel/board.c
index 563f680dee..e583a21285 100644
--- a/board/fennel/board.c
+++ b/board/fennel/board.c
@@ -240,7 +240,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/fennel/board.h b/board/fennel/board.h
index 6bb90ef0f3..42e1fcd451 100644
--- a/board/fennel/board.h
+++ b/board/fennel/board.h
@@ -26,6 +26,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/gelarshie/board.c b/board/gelarshie/board.c
index 7ae2e06372..dfa85037a2 100644
--- a/board/gelarshie/board.c
+++ b/board/gelarshie/board.c
@@ -696,7 +696,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
charge_ma = max_ma;
}
- charge_ma = charge_ma * 95 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/gelarshie/board.h b/board/gelarshie/board.h
index 34e5d47f0c..737f005639 100644
--- a/board/gelarshie/board.h
+++ b/board/gelarshie/board.h
@@ -43,6 +43,9 @@
#define CONFIG_BATTERY_FUEL_GAUGE
#define CONFIG_BATTERY_VENDOR_PARAM
+/* charger margin */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* Enable PD3.0 */
#define CONFIG_USB_PD_REV30
/* BC 1.2 Charger */
diff --git a/board/gimble/board.c b/board/gimble/board.c
index 0ca135b9fd..5373eb2bff 100644
--- a/board/gimble/board.c
+++ b/board/gimble/board.c
@@ -185,16 +185,3 @@ __overridable void board_ps8xxx_tcpc_init(int port)
CPRINTS("ps8815: fail to write reg 0x%02x",
PS8815_REG_RX_EQ_AT_5G);
}
-
-__override void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
-{
- /*
- * Follow OEM request to limit the input current to
- * 90% negotiated limit.
- */
- charge_ma = charge_ma * 90 / 100;
-
- charge_set_input_current_limit(
- MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
-}
diff --git a/board/gimble/board.h b/board/gimble/board.h
index 015f3f78e6..1d4099e7eb 100644
--- a/board/gimble/board.h
+++ b/board/gimble/board.h
@@ -196,6 +196,8 @@
#define CONFIG_CHARGER_BQ25710_SENSE_RESISTOR 10
#define CONFIG_CHARGER_BQ25710_SENSE_RESISTOR_AC 10
#define CONFIG_CHARGER_BQ25710_PSYS_SENSING
+/* OEM requested 10% derating */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 10
/* PROCHOT defines */
#define BATT_MAX_CONTINUE_DISCHARGE_WATT 45
diff --git a/board/gimble/charger.c b/board/gimble/charger.c
index a4fa209246..b1a29c725b 100644
--- a/board/gimble/charger.c
+++ b/board/gimble/charger.c
@@ -82,8 +82,8 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-__overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
+void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
+ int charge_mv)
{
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
diff --git a/board/gooey/board.c b/board/gooey/board.c
index 250f6afd61..9acbadd10d 100644
--- a/board/gooey/board.c
+++ b/board/gooey/board.c
@@ -263,12 +263,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/gooey/board.h b/board/gooey/board.h
index b586c0f334..fde32f8866 100644
--- a/board/gooey/board.h
+++ b/board/gooey/board.h
@@ -32,6 +32,11 @@
*/
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/* DAC for PSYS */
#define CONFIG_DAC
diff --git a/board/homestar/board.c b/board/homestar/board.c
index 1964bc86eb..b1a136dd67 100644
--- a/board/homestar/board.c
+++ b/board/homestar/board.c
@@ -644,7 +644,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
charge_ma = max_ma;
}
- charge_ma = charge_ma * 95 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/homestar/board.h b/board/homestar/board.h
index 230aa6e7d3..60d943b300 100644
--- a/board/homestar/board.h
+++ b/board/homestar/board.h
@@ -27,6 +27,9 @@
#define CONFIG_BATTERY_FUEL_GAUGE
#define CONFIG_BATTERY_VENDOR_PARAM
+/* charger margin */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* Enable PD3.0 */
#define CONFIG_USB_PD_REV30
diff --git a/board/icarus/board.c b/board/icarus/board.c
index be464e3a77..d0a98c901e 100644
--- a/board/icarus/board.c
+++ b/board/icarus/board.c
@@ -207,7 +207,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/icarus/board.h b/board/icarus/board.h
index 98b6da3fd5..ca1a236307 100644
--- a/board/icarus/board.h
+++ b/board/icarus/board.h
@@ -24,6 +24,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/jacuzzi/board.c b/board/jacuzzi/board.c
index 129b75f8e2..6df0b8dc82 100644
--- a/board/jacuzzi/board.c
+++ b/board/jacuzzi/board.c
@@ -247,7 +247,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/jacuzzi/board.h b/board/jacuzzi/board.h
index 0fd5f6496d..d5d0523790 100644
--- a/board/jacuzzi/board.h
+++ b/board/jacuzzi/board.h
@@ -34,6 +34,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/kappa/board.c b/board/kappa/board.c
index c04b24d3ed..e3e374e18d 100644
--- a/board/kappa/board.c
+++ b/board/kappa/board.c
@@ -220,7 +220,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/kappa/board.h b/board/kappa/board.h
index 6b6461ae83..5c49053a7b 100644
--- a/board/kappa/board.h
+++ b/board/kappa/board.h
@@ -26,6 +26,7 @@
#define CONFIG_BATTERY_COUNT 1
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_BC12_DETECT_PI3USB9201
diff --git a/board/lalala/board.c b/board/lalala/board.c
index 78404d6821..feedfe0262 100644
--- a/board/lalala/board.c
+++ b/board/lalala/board.c
@@ -401,12 +401,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/lalala/board.h b/board/lalala/board.h
index 4967e49752..2996ad3613 100644
--- a/board/lalala/board.h
+++ b/board/lalala/board.h
@@ -33,6 +33,11 @@
#undef CONFIG_CMD_CHARGER_DUMP
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/* GPIO for C1 interrupts, for baseboard use */
#define GPIO_USB_C1_INT_ODL GPIO_SUB_USB_C1_INT_ODL
diff --git a/board/madoo/board.c b/board/madoo/board.c
index eedf8e6fdd..9f2021cf99 100644
--- a/board/madoo/board.c
+++ b/board/madoo/board.c
@@ -316,13 +316,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- reduce
- * our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/madoo/board.h b/board/madoo/board.h
index 82cfa30b0e..0d5e24c2a0 100644
--- a/board/madoo/board.h
+++ b/board/madoo/board.h
@@ -19,6 +19,11 @@
#define CONFIG_OCPC_DEF_RBATT_MOHMS \
22 /* R_DS(on) 11.6mOhm + 10mOhm sns rstr \
*/
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
#define CONFIG_OCPC
#undef CONFIG_CHARGER_SINGLE_CHIP
diff --git a/board/magolor/board.c b/board/magolor/board.c
index bfa77375e5..57f6791ae3 100644
--- a/board/magolor/board.c
+++ b/board/magolor/board.c
@@ -597,12 +597,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/magolor/board.h b/board/magolor/board.h
index 481856323f..beb2cc279c 100644
--- a/board/magolor/board.h
+++ b/board/magolor/board.h
@@ -45,6 +45,11 @@
#undef CONFIG_CMD_CHARGER_DUMP
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/* GPIO for C1 interrupts, for baseboard use */
#define GPIO_USB_C1_INT_ODL GPIO_SUB_C1_INT_EN_RAILS_ODL
diff --git a/board/makomo/board.c b/board/makomo/board.c
index 24b34d9a75..09fe5fdd74 100644
--- a/board/makomo/board.c
+++ b/board/makomo/board.c
@@ -238,7 +238,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/makomo/board.h b/board/makomo/board.h
index bf705e9560..86e5e78862 100644
--- a/board/makomo/board.h
+++ b/board/makomo/board.h
@@ -27,6 +27,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/metaknight/board.c b/board/metaknight/board.c
index 5aa3a21cc0..f075f58ee4 100644
--- a/board/metaknight/board.c
+++ b/board/metaknight/board.c
@@ -400,12 +400,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/metaknight/board.h b/board/metaknight/board.h
index 5bd3c56a83..79027a3e9c 100644
--- a/board/metaknight/board.h
+++ b/board/metaknight/board.h
@@ -22,6 +22,11 @@
#undef CONFIG_CHARGER_SINGLE_CHIP
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/*
* GPIO for C1 interrupts, for baseboard use
diff --git a/board/mithrax/board.h b/board/mithrax/board.h
index d12375d678..0b6ea04bd4 100644
--- a/board/mithrax/board.h
+++ b/board/mithrax/board.h
@@ -176,6 +176,7 @@
#define CONFIG_CHARGE_RAMP_SW
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 10
/* RGB Keyboard */
#ifdef SECTION_IS_RW
diff --git a/board/mithrax/charger_isl9241.c b/board/mithrax/charger_isl9241.c
index a9eafe353e..88f5b85a41 100644
--- a/board/mithrax/charger_isl9241.c
+++ b/board/mithrax/charger_isl9241.c
@@ -83,7 +83,6 @@ int board_set_active_charge_port(int port)
__overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
- charge_ma = (charge_ma * 90) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/mrbland/board.c b/board/mrbland/board.c
index 50ba008512..04fef6ec82 100644
--- a/board/mrbland/board.c
+++ b/board/mrbland/board.c
@@ -598,7 +598,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
charge_ma = max_ma;
}
- charge_ma = charge_ma * 95 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/mrbland/board.h b/board/mrbland/board.h
index 0f78db50d9..cc6207ca83 100644
--- a/board/mrbland/board.h
+++ b/board/mrbland/board.h
@@ -24,6 +24,8 @@
#define CONFIG_BATTERY_FUEL_GAUGE
#define CONFIG_BATTERY_VENDOR_PARAM
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* Enable PD3.0 */
#define CONFIG_USB_PD_REV30
diff --git a/board/munna/board.c b/board/munna/board.c
index f6996b8460..408a81d47d 100644
--- a/board/munna/board.c
+++ b/board/munna/board.c
@@ -239,7 +239,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/munna/board.h b/board/munna/board.h
index 5dc35c68df..20194bed88 100644
--- a/board/munna/board.h
+++ b/board/munna/board.h
@@ -40,6 +40,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/nautilus/board.c b/board/nautilus/board.c
index 3cdd7abaf1..36b79aa0c7 100644
--- a/board/nautilus/board.c
+++ b/board/nautilus/board.c
@@ -538,11 +538,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- /*
- * Limit the input current to 96% negotiated limit,
- * to account for the charger chip margin.
- */
- charge_ma = charge_ma * 96 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/nautilus/board.h b/board/nautilus/board.h
index cbca28a71f..f40b2f00b5 100644
--- a/board/nautilus/board.h
+++ b/board/nautilus/board.h
@@ -84,6 +84,7 @@
#define CONFIG_CHARGER_PSYS
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4 /* margining */
#define CONFIG_CMD_CHARGER_ADC_AMON_BMON
#define CONFIG_HOSTCMD_PD_CONTROL
#define CONFIG_EXTPOWER_GPIO
diff --git a/board/nocturne/board.c b/board/nocturne/board.c
index d32f036844..dbe5f50b68 100644
--- a/board/nocturne/board.c
+++ b/board/nocturne/board.c
@@ -764,12 +764,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * Nocturne seems to overdraw its set input current limit by about 5%.
- * Request at most 95% of what's desired.
- */
- icl = icl * 95 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/nocturne/board.h b/board/nocturne/board.h
index 9f54c1a51d..7c38e48ee3 100644
--- a/board/nocturne/board.h
+++ b/board/nocturne/board.h
@@ -72,6 +72,11 @@
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 128
#define CONFIG_CHARGER_ISL9238
+/*
+ * Nocturne seems to overdraw its set input current limit by about 5%.
+ * Request at most 95% of what's desired.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#undef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON
#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1
#define CONFIG_CHARGER_PROFILE_OVERRIDE
diff --git a/board/pico/board.c b/board/pico/board.c
index f884545b6d..8dbfcdec12 100644
--- a/board/pico/board.c
+++ b/board/pico/board.c
@@ -323,7 +323,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/pico/board.h b/board/pico/board.h
index 665cf59691..97128b54f1 100644
--- a/board/pico/board.h
+++ b/board/pico/board.h
@@ -28,6 +28,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/pompom/board.c b/board/pompom/board.c
index 394f06be8e..b46e347f88 100644
--- a/board/pompom/board.c
+++ b/board/pompom/board.c
@@ -469,7 +469,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
charge_ma = max_ma;
}
- charge_ma = charge_ma * 95 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/pompom/board.h b/board/pompom/board.h
index 40e7185c16..1282ecdb41 100644
--- a/board/pompom/board.h
+++ b/board/pompom/board.h
@@ -23,6 +23,8 @@
/* BC 1.2 Charger */
#define CONFIG_BC12_DETECT_PI3USB9201
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* USB */
#define CONFIG_USB_PD_TCPM_MULTI_PS8XXX
#define CONFIG_USB_PD_TCPM_PS8751
diff --git a/board/primus/charger.c b/board/primus/charger.c
index a4fa209246..7fabd2082e 100644
--- a/board/primus/charger.c
+++ b/board/primus/charger.c
@@ -81,10 +81,3 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-
-__overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
-{
- charge_set_input_current_limit(
- MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
-}
diff --git a/board/quackingstick/board.c b/board/quackingstick/board.c
index 6cdf814c74..8985254a23 100644
--- a/board/quackingstick/board.c
+++ b/board/quackingstick/board.c
@@ -625,7 +625,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
charge_ma = max_ma;
}
- charge_ma = charge_ma * 95 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/quackingstick/board.h b/board/quackingstick/board.h
index 9b50237b4d..a8ec5a4231 100644
--- a/board/quackingstick/board.h
+++ b/board/quackingstick/board.h
@@ -32,6 +32,8 @@
#define CONFIG_BATTERY_FUEL_GAUGE
#define CONFIG_BATTERY_VENDOR_PARAM
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* BC 1.2 Charger */
#define CONFIG_BC12_DETECT_PI3USB9201
diff --git a/board/rammus/board.c b/board/rammus/board.c
index 8cbc6c6856..3696733047 100644
--- a/board/rammus/board.c
+++ b/board/rammus/board.c
@@ -569,11 +569,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- /*
- * Limit the input current to 96% negotiated limit,
- * to account for the charger chip margin.
- */
- charge_ma = charge_ma * 96 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/rammus/board.h b/board/rammus/board.h
index c0c8238c3e..83f0f35c57 100644
--- a/board/rammus/board.h
+++ b/board/rammus/board.h
@@ -88,6 +88,7 @@
#define CONFIG_CHARGER_PSYS
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4 /* charger margin */
#define CONFIG_CMD_CHARGER_ADC_AMON_BMON
#define CONFIG_HOSTCMD_PD_CONTROL
#define CONFIG_EXTPOWER_GPIO
diff --git a/board/reef/board.c b/board/reef/board.c
index e41921a436..b3732f6be9 100644
--- a/board/reef/board.c
+++ b/board/reef/board.c
@@ -555,7 +555,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
if (bd9995x_bc12_enable_charging(port, bc12_enable))
return;
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/reef/board.h b/board/reef/board.h
index fc25024dff..bce20f4645 100644
--- a/board/reef/board.h
+++ b/board/reef/board.h
@@ -51,6 +51,7 @@
#define CONFIG_CHARGER_BD9995X_CHGEN
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 512
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 1
#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 18000
#define CONFIG_CHARGER_MAINTAIN_VBAT
diff --git a/board/reef_it8320/board.c b/board/reef_it8320/board.c
index b00e451842..6196f1967a 100644
--- a/board/reef_it8320/board.c
+++ b/board/reef_it8320/board.c
@@ -311,7 +311,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
if (bd9995x_bc12_enable_charging(port, bc12_enable))
return;
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/reef_it8320/board.h b/board/reef_it8320/board.h
index 45abf34151..fc1ca0079d 100644
--- a/board/reef_it8320/board.h
+++ b/board/reef_it8320/board.h
@@ -49,6 +49,7 @@
#define CONFIG_CHARGER_BD9995X_CHGEN
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 512
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 1
#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 18000
#define CONFIG_CHARGER_MAINTAIN_VBAT
diff --git a/board/reef_mchp/board.c b/board/reef_mchp/board.c
index 0a40f5dd04..67cbfa5aa9 100644
--- a/board/reef_mchp/board.c
+++ b/board/reef_mchp/board.c
@@ -748,7 +748,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
if (bd9995x_bc12_enable_charging(port, bc12_enable))
return;
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/reef_mchp/board.h b/board/reef_mchp/board.h
index bde2d831d3..3cc3d2b77f 100644
--- a/board/reef_mchp/board.h
+++ b/board/reef_mchp/board.h
@@ -54,6 +54,7 @@
#define CONFIG_CHARGER_BD9995X_CHGEN
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 512
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 1
#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 18000
#define CONFIG_CHARGER_MAINTAIN_VBAT
diff --git a/board/sasuke/board.c b/board/sasuke/board.c
index ddd5279d62..567dc8cee7 100644
--- a/board/sasuke/board.c
+++ b/board/sasuke/board.c
@@ -399,12 +399,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/sasuke/board.h b/board/sasuke/board.h
index 64c830df0f..df390d2d99 100644
--- a/board/sasuke/board.h
+++ b/board/sasuke/board.h
@@ -29,6 +29,11 @@
#define CONFIG_OCPC_DEF_RBATT_MOHMS \
22 /* R_DS(on) 11.6mOhm + 10mOhm sns rstr \
*/
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
#define CONFIG_OCPC
#define CONFIG_CHARGER_PROFILE_OVERRIDE
#define CONFIG_CHARGE_RAMP_HW
diff --git a/board/sasukette/board.c b/board/sasukette/board.c
index e45213a63a..019df9348a 100644
--- a/board/sasukette/board.c
+++ b/board/sasukette/board.c
@@ -255,12 +255,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/sasukette/board.h b/board/sasukette/board.h
index 44cb65239a..f06a89a5f0 100644
--- a/board/sasukette/board.h
+++ b/board/sasukette/board.h
@@ -36,6 +36,11 @@
#define CONFIG_CHARGER_PROFILE_OVERRIDE
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC)
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
/* LED */
#define CONFIG_LED_COMMON
diff --git a/board/stern/board.c b/board/stern/board.c
index 26576ede86..41f63d40a4 100644
--- a/board/stern/board.c
+++ b/board/stern/board.c
@@ -239,7 +239,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/stern/board.h b/board/stern/board.h
index eedbc2a44c..d7d96ea67c 100644
--- a/board/stern/board.h
+++ b/board/stern/board.h
@@ -28,6 +28,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/storo/board.c b/board/storo/board.c
index f6f3ed5750..e4f2ad2fb9 100644
--- a/board/storo/board.c
+++ b/board/storo/board.c
@@ -435,12 +435,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/storo/board.h b/board/storo/board.h
index 93dd573ba1..1f33ce53b0 100644
--- a/board/storo/board.h
+++ b/board/storo/board.h
@@ -31,6 +31,11 @@
#define CONFIG_OCPC_DEF_RBATT_MOHMS \
22 /* R_DS(on) 11.6mOhm + 10mOhm sns rstr \
*/
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
#define CONFIG_OCPC
#undef CONFIG_CHARGER_SINGLE_CHIP
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
diff --git a/board/taeko/board.c b/board/taeko/board.c
index 79ef4029d6..9f0d21b8b8 100644
--- a/board/taeko/board.c
+++ b/board/taeko/board.c
@@ -136,16 +136,3 @@ enum battery_present battery_hw_present(void)
/* The GPIO is low when the battery is physically present */
return gpio_get_level(GPIO_EC_BATT_PRES_ODL) ? BP_NO : BP_YES;
}
-
-__override void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
-{
- /*
- * Follow OEM request to limit the input current to
- * 95% negotiated limit.
- */
- charge_ma = charge_ma * 95 / 100;
-
- charge_set_input_current_limit(
- MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
-}
diff --git a/board/taeko/board.h b/board/taeko/board.h
index c3193c8847..a3ae9abb00 100644
--- a/board/taeko/board.h
+++ b/board/taeko/board.h
@@ -26,6 +26,9 @@
#define CONFIG_MP2964
+/* OEM requested 5% charger current margin */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* LED */
#define CONFIG_LED_ONOFF_STATES
diff --git a/board/taeko/charger.c b/board/taeko/charger.c
index a4fa209246..29211bc033 100644
--- a/board/taeko/charger.c
+++ b/board/taeko/charger.c
@@ -82,8 +82,8 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-__overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
+__override void board_set_charge_limit(int port, int supplier, int charge_ma,
+ int max_ma, int charge_mv)
{
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
diff --git a/board/taniks/board.c b/board/taniks/board.c
index 5da998524b..f8501d761b 100644
--- a/board/taniks/board.c
+++ b/board/taniks/board.c
@@ -115,16 +115,3 @@ enum battery_present battery_hw_present(void)
/* The GPIO is low when the battery is physically present */
return gpio_get_level(GPIO_EC_BATT_PRES_ODL) ? BP_NO : BP_YES;
}
-
-__override void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
-{
- /*
- * Follow OEM request to limit the input current to
- * 95% negotiated limit.
- */
- charge_ma = charge_ma * 95 / 100;
-
- charge_set_input_current_limit(
- MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
-}
diff --git a/board/taniks/board.h b/board/taniks/board.h
index 6cd42ad7bb..a301f3b458 100644
--- a/board/taniks/board.h
+++ b/board/taniks/board.h
@@ -36,6 +36,9 @@
*/
#define CONFIG_HIBERNATE_PSL_VCC1_RST_WAKEUP
+/* OEM requested 5% charger margin */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* LED */
#define CONFIG_LED_ONOFF_STATES
diff --git a/board/taniks/charger.c b/board/taniks/charger.c
index a4fa209246..b1a29c725b 100644
--- a/board/taniks/charger.c
+++ b/board/taniks/charger.c
@@ -82,8 +82,8 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-__overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
+void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
+ int charge_mv)
{
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
diff --git a/board/vell/board.h b/board/vell/board.h
index 4b3d527901..3a7d97858c 100644
--- a/board/vell/board.h
+++ b/board/vell/board.h
@@ -61,6 +61,8 @@
#undef CONFIG_SYV682X_HV_ILIM
#define CONFIG_SYV682X_HV_ILIM SYV682X_HV_ILIM_5_50
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
+
/* TODO: b/177608416 - measure and check these values on brya */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 30000 /* us */
diff --git a/board/vell/charger.c b/board/vell/charger.c
index e33a0ed44a..a153d57704 100644
--- a/board/vell/charger.c
+++ b/board/vell/charger.c
@@ -84,11 +84,6 @@ int board_set_active_charge_port(int port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- /*
- * Limit the input current to 96% negotiated limit,
- * to account for the charger chip margin.
- */
- charge_ma = charge_ma * 96 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/vilboz/board.c b/board/vilboz/board.c
index 7c74794d9d..fe0b8ee32e 100644
--- a/board/vilboz/board.c
+++ b/board/vilboz/board.c
@@ -508,12 +508,6 @@ const int usb_port_enable[USBA_PORT_COUNT] = {
__override void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
- /*
- * Limit the input current to 95% negotiated limit,
- * to account for the charger chip margin.
- */
- charge_ma = charge_ma * 95 / 100;
-
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/vilboz/board.h b/board/vilboz/board.h
index 5160abbc26..8a7c86824d 100644
--- a/board/vilboz/board.h
+++ b/board/vilboz/board.h
@@ -20,6 +20,7 @@
#define GPIO_USB2_ILIM_SEL GPIO_USB_A1_CHARGE_EN_DB_L
#define CONFIG_CHARGER_PROFILE_OVERRIDE
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
/* Motion sensing drivers */
#define CONFIG_ACCELGYRO_LSM6DSM
diff --git a/board/waddledoo/board.c b/board/waddledoo/board.c
index e207e59456..e71151f6b5 100644
--- a/board/waddledoo/board.c
+++ b/board/waddledoo/board.c
@@ -394,12 +394,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/waddledoo/board.h b/board/waddledoo/board.h
index c13dbe37c9..23a89c84d6 100644
--- a/board/waddledoo/board.h
+++ b/board/waddledoo/board.h
@@ -43,6 +43,11 @@
#define CONFIG_OCPC_DEF_RBATT_MOHMS \
22 /* R_DS(on) 11.6mOhm + 10mOhm sns rstr \
*/
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
#define CONFIG_OCPC
#undef CONFIG_CHARGER_SINGLE_CHIP
#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE
diff --git a/board/waddledoo2/board.c b/board/waddledoo2/board.c
index fd12aec449..b1417d8ee2 100644
--- a/board/waddledoo2/board.c
+++ b/board/waddledoo2/board.c
@@ -401,12 +401,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * b/147463641: The charger IC seems to overdraw ~4%, therefore we
- * reduce our target accordingly.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/board/waddledoo2/board.h b/board/waddledoo2/board.h
index 93f0a0f108..3b4587037d 100644
--- a/board/waddledoo2/board.h
+++ b/board/waddledoo2/board.h
@@ -28,6 +28,11 @@
#define CONFIG_OCPC_DEF_RBATT_MOHMS \
22 /* R_DS(on) 11.6mOhm + 10mOhm sns rstr \
*/
+/*
+ * b/147463641: The charger IC seems to overdraw ~4%, therefore we
+ * reduce our target accordingly.
+ */
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 4
#define CONFIG_OCPC
#undef CONFIG_CHARGER_SINGLE_CHIP
#undef CONFIG_CMD_CHARGER_DUMP
diff --git a/board/willow/board.c b/board/willow/board.c
index 826df6940c..3bd5c4633b 100644
--- a/board/willow/board.c
+++ b/board/willow/board.c
@@ -237,7 +237,6 @@ int board_set_active_charge_port(int charge_port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * 95) / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/willow/board.h b/board/willow/board.h
index 18745a07a4..315c206a07 100644
--- a/board/willow/board.h
+++ b/board/willow/board.h
@@ -27,6 +27,7 @@
#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
#define CONFIG_CHARGER_PSYS
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
#define CONFIG_CHARGER_RUNTIME_CONFIG
diff --git a/board/wormdingler/board.c b/board/wormdingler/board.c
index 273c41d1a7..8705e0d2cb 100644
--- a/board/wormdingler/board.c
+++ b/board/wormdingler/board.c
@@ -643,7 +643,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
charge_ma = max_ma;
}
- charge_ma = charge_ma * 95 / 100;
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/board/wormdingler/board.h b/board/wormdingler/board.h
index 3c3ba6ead5..447846c509 100644
--- a/board/wormdingler/board.h
+++ b/board/wormdingler/board.h
@@ -24,6 +24,8 @@
#define CONFIG_BATTERY_FUEL_GAUGE
#define CONFIG_BATTERY_VENDOR_PARAM
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 5
+
/* Enable PD3.0 */
#define CONFIG_USB_PD_REV30
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index cd1b5988e2..6967cf5333 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -2330,6 +2330,13 @@ int charge_set_input_current_limit(int ma, int mv)
{
__maybe_unused int chgnum = 0;
+#ifdef CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT
+ if (CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT != 0) {
+ ma = (ma * (100 - CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT)) /
+ 100;
+ }
+#endif
+
if (IS_ENABLED(CONFIG_OCPC))
chgnum = charge_get_active_chg_chip();
#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h
index 0817204774..5f886257d3 100644
--- a/include/charge_state_v2.h
+++ b/include/charge_state_v2.h
@@ -71,6 +71,9 @@ int charge_set_output_current_limit(int chgnum, int ma, int mv);
* Set the charge input current limit. This value is stored and sent every
* time AC is applied.
*
+ * The input current limit is automatically derated by
+ * CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT, if configured.
+ *
* @param ma New input current limit in mA
* @param mv Negotiated charge voltage in mV.
* @return EC_SUCCESS or error
diff --git a/include/config.h b/include/config.h
index 10de8f80bf..baf86db418 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1038,6 +1038,21 @@
#undef CONFIG_CHARGER_INPUT_CURRENT
/*
+ * Percentage derating factor applied to charger input current limits.
+ *
+ * Desired charger current is reduced by this many percent when programming
+ * chargers via the charge manager, which is usually used to account for
+ * chargers that draw slightly more current than the programmed limit or to
+ * provide some margin for accuracy. For example, if this value is set to 4
+ * and input current is limited to 1000 mA, the charger will be given a limit
+ * of 960 mA.
+ *
+ * Boards requiring more complex control over input current should leave this
+ * undefined and override board_set_charge_limit instead.
+ */
+#undef CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT
+
+/*
* This config option is used to enable IDCHG trigger for prochot. This macro
* should be set to the desired current limit to draw from the battery before
* triggering prochot. Note that is has a 512 mA granularity. The function that
diff --git a/zephyr/Kconfig.usbc b/zephyr/Kconfig.usbc
index 903cf575c6..5350c1cbbf 100644
--- a/zephyr/Kconfig.usbc
+++ b/zephyr/Kconfig.usbc
@@ -44,6 +44,22 @@ config PLATFORM_EC_CHARGER_INPUT_CURRENT
chargers, this should be set to 512 mA in order to not brown-out
low-current USB charge ports in accordance with USB-PD r3.0 Sec. 7.3
+config PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT
+ int "Charger input current derating percentage"
+ default 0
+ depends on PLATFORM_EC_CHARGE_MANAGER
+ help
+ Setting this to a nonzero value causes actual charger current limits
+ to be adjusted by the given percentage. For example, setting this to
+ 4 and requesting a current limit of 1000 mA causes the charge manager
+ to program an actual current limit of 960 mA.
+
+ This is useful if a charger consistently draws more current than the
+ programmed limit, or if it is desired to derate for other
+ safety-related reasons. If a more complex (non-linear) adjustment is
+ required, boards should override the board_set_charge_limit()
+ function instead of configuring this option.
+
config PLATFORM_EC_USBC_OCP
bool
help
diff --git a/zephyr/program/corsola/program.conf b/zephyr/program/corsola/program.conf
index 402f8ab1cf..86bd30aaed 100644
--- a/zephyr/program/corsola/program.conf
+++ b/zephyr/program/corsola/program.conf
@@ -86,6 +86,9 @@ CONFIG_PLATFORM_EC_I2C_VIRTUAL_BATTERY=y
# Charger
CONFIG_PLATFORM_EC_BC12_CLIENT_MODE_ONLY_PI3USB9201=y
CONFIG_PLATFORM_EC_CHARGE_MANAGER=y
+# b:257167723: Adapter output current exceeds the spec on heavy-load.
+# Preserve a margin in case of charger overdraw.
+CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT=3
# Button
CONFIG_PLATFORM_EC_CMD_BUTTON=y
diff --git a/zephyr/program/corsola/src/usbc_config.c b/zephyr/program/corsola/src/usbc_config.c
index b776bc1ca9..838f676694 100644
--- a/zephyr/program/corsola/src/usbc_config.c
+++ b/zephyr/program/corsola/src/usbc_config.c
@@ -129,12 +129,7 @@ __override enum pd_dual_role_states pd_get_drp_state_in_s0(void)
__override void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
- int icl = charge_ma * 97 / 100;
- /*
- * b:257167723: Adapter output current exceeds the spec on heavy-load.
- * Preserve a margin in case of charger overdraw.
- */
- charge_set_input_current_limit(icl, charge_mv);
+ charge_set_input_current_limit(charge_ma, charge_mv);
}
void board_pd_vconn_ctrl(int port, enum usbpd_cc_pin cc_pin, int enabled)
diff --git a/zephyr/program/nissa/program.conf b/zephyr/program/nissa/program.conf
index 02dc458a61..a8a2ec3319 100644
--- a/zephyr/program/nissa/program.conf
+++ b/zephyr/program/nissa/program.conf
@@ -134,6 +134,8 @@ CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR_AC=10
CONFIG_PLATFORM_EC_CHARGER_DISCHARGE_ON_AC=y
CONFIG_PLATFORM_EC_CHARGER_DISCHARGE_ON_AC_CHARGER=y
CONFIG_PLATFORM_EC_OCPC_DEF_DRIVELIMIT_MILLIVOLTS=200
+# Assume 4% overdraw, which could be changed with actual characterization
+CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT=4
# Dynamically select PD voltage to maximize charger efficiency
CONFIG_PLATFORM_EC_USB_PD_DPS=y
diff --git a/zephyr/program/nissa/src/common.c b/zephyr/program/nissa/src/common.c
index e278387a84..4f27d1d84f 100644
--- a/zephyr/program/nissa/src/common.c
+++ b/zephyr/program/nissa/src/common.c
@@ -85,13 +85,6 @@ __overridable void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
-
- /*
- * Assume charger overdraws by about 4%, keeping the actual draw
- * within spec. This adjustment can be changed with characterization
- * of actual hardware.
- */
- icl = icl * 96 / 100;
charge_set_input_current_limit(icl, charge_mv);
}
diff --git a/zephyr/program/nissa/xivu/project.conf b/zephyr/program/nissa/xivu/project.conf
index fe56a9d562..d686f5bd0b 100644
--- a/zephyr/program/nissa/xivu/project.conf
+++ b/zephyr/program/nissa/xivu/project.conf
@@ -6,6 +6,8 @@ CONFIG_BOARD_XIVU=y
CONFIG_PLATFORM_EC_OCPC=y
CONFIG_PLATFORM_EC_ACCELGYRO_LSM6DSO=y
+CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT=10
+
# LED
CONFIG_PLATFORM_EC_LED_COMMON=n
CONFIG_PLATFORM_EC_LED_DT=y
diff --git a/zephyr/program/skyrim/Kconfig b/zephyr/program/skyrim/Kconfig
index fbb797f6fc..896958e446 100644
--- a/zephyr/program/skyrim/Kconfig
+++ b/zephyr/program/skyrim/Kconfig
@@ -26,12 +26,6 @@ config BOARD_FROSTFLOW
Build Google Frostflow reference board. This board uses an AMD SoC
and NPCX9 EC
-config BOARD_INPUT_CURRENT_SCALE_FACTOR
- int "Input current scale factor"
- default 100
- help
- Limit input current to fraction of negotiated limit.
-
config BOARD_USB_HUB_RESET
bool "Support USB hub reset or not"
default y
diff --git a/zephyr/program/skyrim/prj_frostflow.conf b/zephyr/program/skyrim/prj_frostflow.conf
index caae3ba985..835230be67 100644
--- a/zephyr/program/skyrim/prj_frostflow.conf
+++ b/zephyr/program/skyrim/prj_frostflow.conf
@@ -4,7 +4,7 @@
# Frostflow reference-board-specific Kconfig settings.
CONFIG_BOARD_FROSTFLOW=y
-CONFIG_BOARD_INPUT_CURRENT_SCALE_FACTOR=90
+CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT=10
# TODO(b/215404321): Remove later in board development
CONFIG_PLATFORM_EC_EEPROM_CBI_WP=y
diff --git a/zephyr/program/skyrim/src/usbc_config.c b/zephyr/program/skyrim/src/usbc_config.c
index dec9f928b5..1795cb2b1e 100644
--- a/zephyr/program/skyrim/src/usbc_config.c
+++ b/zephyr/program/skyrim/src/usbc_config.c
@@ -193,8 +193,6 @@ int board_set_active_charge_port(int port)
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
int charge_mv)
{
- charge_ma = (charge_ma * CONFIG_BOARD_INPUT_CURRENT_SCALE_FACTOR) / 100;
-
charge_set_input_current_limit(
MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index 1d88f1832e..f8e69fe55d 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -1077,6 +1077,12 @@ extern char mock_jump_data[sizeof(struct jump_data) + 256];
#define CONFIG_CHARGER_INPUT_CURRENT CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT
#endif
+#undef CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT
+#ifdef CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT
+#define CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT \
+ CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT
+#endif
+
#undef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON
#ifdef CONFIG_PLATFORM_EC_CHARGER_MIN_BAT_PCT_FOR_POWER_ON
#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON \
diff --git a/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c b/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c
index d6504b92f9..e1c602e86d 100644
--- a/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c
+++ b/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c
@@ -97,3 +97,20 @@ ZTEST(charge_state_v2, test_battery_temperature_range)
(batt_info->charging_max_c + batt_info->charging_min_c) / 2);
zassert_ok(battery_outside_charging_temperature());
}
+
+ZTEST(charge_state_v2, test_current_limit_derating)
+{
+ int charger_current_limit;
+
+ charge_set_input_current_limit(1000, 5000);
+ zassert_ok(charger_get_input_current_limit(0, &charger_current_limit));
+ /*
+ * ISL923x sets ICL in multiples of 20 mA, so 950 mA gets rounded down
+ * to the nearest multiple of 20.
+ */
+ zassert_equal(
+ charger_current_limit, 944,
+ "%d%% derating of 1A should be 944 mA, but charger is set for %d mA",
+ CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT,
+ charger_current_limit);
+}
diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml
index 8a68a2af23..9548596026 100644
--- a/zephyr/test/drivers/testcase.yaml
+++ b/zephyr/test/drivers/testcase.yaml
@@ -51,6 +51,7 @@ tests:
- CONFIG_PLATFORM_EC_CBI_GPIO=y
drivers.common_charger:
extra_configs:
+ - CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT=5
- CONFIG_LINK_TEST_SUITE_COMMON_CHARGER=y
# Set to focus testing for Herobrine
# Config is y only in nissa