summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--baseboard/dragonegg/baseboard.c1
-rw-r--r--baseboard/grunt/baseboard.c2
-rw-r--r--baseboard/hatch/baseboard.c1
-rw-r--r--baseboard/kukui/baseboard.c2
-rw-r--r--baseboard/octopus/baseboard.c2
-rw-r--r--baseboard/trogdor/baseboard.c2
-rw-r--r--baseboard/volteer/baseboard.c2
-rw-r--r--baseboard/zork/variant_dalboz.c2
-rw-r--r--baseboard/zork/variant_trembyle.c1
-rw-r--r--board/asurada/board.c1
-rw-r--r--board/atlas/board.c2
-rw-r--r--board/boten/board.c1
-rw-r--r--board/cheza/board.c2
-rw-r--r--board/coral/board.c1
-rw-r--r--board/damu/board.c1
-rw-r--r--board/drawcia/board.c1
-rw-r--r--board/elm/board.c1
-rw-r--r--board/eve/board.c1
-rw-r--r--board/flapjack/board.c1
-rw-r--r--board/glkrvp/board.c2
-rw-r--r--board/glkrvp_ite/board.c2
-rw-r--r--board/hammer/board.c1
-rw-r--r--board/host/charger.c2
-rw-r--r--board/jacuzzi/board.c1
-rw-r--r--board/jerry/board.c1
-rw-r--r--board/jslrvp_ite/board.c2
-rw-r--r--board/nami/board.c2
-rw-r--r--board/nautilus/board.c2
-rw-r--r--board/nocturne/board.c2
-rw-r--r--board/oak/board.c1
-rw-r--r--board/poppy/board.c2
-rw-r--r--board/rammus/board.c2
-rw-r--r--board/reef/board.c1
-rw-r--r--board/reef_it8320/board.c1
-rw-r--r--board/reef_mchp/board.c1
-rw-r--r--board/samus/board.c1
-rw-r--r--board/scarlet/board.c1
-rw-r--r--board/strago/board.c1
-rw-r--r--board/tglrvpu_ite/board.c2
-rw-r--r--board/waddledee/board.c1
-rw-r--r--board/waddledoo/board.c1
-rw-r--r--board/wheelie/board.c1
-rw-r--r--common/charge_state_v2.c2
-rw-r--r--common/charger.c60
-rw-r--r--driver/charger/isl923x.c2
-rw-r--r--include/charger.h3
46 files changed, 39 insertions, 88 deletions
diff --git a/baseboard/dragonegg/baseboard.c b/baseboard/dragonegg/baseboard.c
index e737530570..5841bef1b1 100644
--- a/baseboard/dragonegg/baseboard.c
+++ b/baseboard/dragonegg/baseboard.c
@@ -89,7 +89,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bq25710_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/******************************************************************************/
/* PWROK signal configuration */
diff --git a/baseboard/grunt/baseboard.c b/baseboard/grunt/baseboard.c
index 26b9ac5bae..a6192e8789 100644
--- a/baseboard/grunt/baseboard.c
+++ b/baseboard/grunt/baseboard.c
@@ -370,8 +370,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
const int usb_port_enable[USB_PORT_COUNT] = {
GPIO_EN_USB_A0_5V,
diff --git a/baseboard/hatch/baseboard.c b/baseboard/hatch/baseboard.c
index 07b018443e..841f398b9b 100644
--- a/baseboard/hatch/baseboard.c
+++ b/baseboard/hatch/baseboard.c
@@ -83,7 +83,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bq25710_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/******************************************************************************/
/* Chipset callbacks/hooks */
diff --git a/baseboard/kukui/baseboard.c b/baseboard/kukui/baseboard.c
index 0d88f21510..baf915407a 100644
--- a/baseboard/kukui/baseboard.c
+++ b/baseboard/kukui/baseboard.c
@@ -35,8 +35,6 @@ const struct charger_config_t chg_chips[] = {
};
#endif /* VARIANT_KUKUI_CHARGER_* */
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
#endif /* CONFIG_CHARGER_RUNTIME_CONFIG */
void board_reset_pd_mcu(void)
diff --git a/baseboard/octopus/baseboard.c b/baseboard/octopus/baseboard.c
index bea8447ef3..105a3bf71c 100644
--- a/baseboard/octopus/baseboard.c
+++ b/baseboard/octopus/baseboard.c
@@ -88,8 +88,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &isl923x_drv,
},
};
-
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
#endif
/******************************************************************************/
diff --git a/baseboard/trogdor/baseboard.c b/baseboard/trogdor/baseboard.c
index 4f112d8e5c..2b59d87c87 100644
--- a/baseboard/trogdor/baseboard.c
+++ b/baseboard/trogdor/baseboard.c
@@ -75,5 +75,3 @@ const struct charger_config_t chg_chips[] = {
.drv = &isl923x_drv,
},
};
-
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
diff --git a/baseboard/volteer/baseboard.c b/baseboard/volteer/baseboard.c
index 7213ff7137..8a12c6576e 100644
--- a/baseboard/volteer/baseboard.c
+++ b/baseboard/volteer/baseboard.c
@@ -122,8 +122,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
/******************************************************************************/
/*
* PWROK signal configuration, see the PWROK Generation Flow Diagram (Figure
diff --git a/baseboard/zork/variant_dalboz.c b/baseboard/zork/variant_dalboz.c
index 1f990737c6..a9ce52daf1 100644
--- a/baseboard/zork/variant_dalboz.c
+++ b/baseboard/zork/variant_dalboz.c
@@ -150,5 +150,3 @@ const struct charger_config_t chg_chips[] = {
.drv = &isl9241_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
diff --git a/baseboard/zork/variant_trembyle.c b/baseboard/zork/variant_trembyle.c
index 71816c6e45..5a6151ed5f 100644
--- a/baseboard/zork/variant_trembyle.c
+++ b/baseboard/zork/variant_trembyle.c
@@ -102,7 +102,6 @@ struct charger_config_t chg_chips[] = {
.drv = &isl9241_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/*
* If the charger is found on the V0 I2C port then re-map the port.
diff --git a/board/asurada/board.c b/board/asurada/board.c
index 09266ca5ec..0aab621486 100644
--- a/board/asurada/board.c
+++ b/board/asurada/board.c
@@ -63,7 +63,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &isl923x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/*
* PWM channels. Must be in the exactly same order as in enum pwm_channel.
diff --git a/board/atlas/board.c b/board/atlas/board.c
index 64bd8f1171..0ef9a591da 100644
--- a/board/atlas/board.c
+++ b/board/atlas/board.c
@@ -161,8 +161,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
/* TCPC mux configuration */
const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
{
diff --git a/board/boten/board.c b/board/boten/board.c
index 160beff602..8a11679fc2 100644
--- a/board/boten/board.c
+++ b/board/boten/board.c
@@ -81,7 +81,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &isl923x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* TCPCs */
const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
diff --git a/board/cheza/board.c b/board/cheza/board.c
index ed9282523f..d8901bc845 100644
--- a/board/cheza/board.c
+++ b/board/cheza/board.c
@@ -285,8 +285,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
/*
* Port-0 USB mux driver.
*
diff --git a/board/coral/board.c b/board/coral/board.c
index ccb686451e..829b057d77 100644
--- a/board/coral/board.c
+++ b/board/coral/board.c
@@ -247,7 +247,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bd9995x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
uint16_t tcpc_get_alert_status(void)
{
diff --git a/board/damu/board.c b/board/damu/board.c
index 244b9b933c..f2eb2a4739 100644
--- a/board/damu/board.c
+++ b/board/damu/board.c
@@ -168,7 +168,6 @@ struct charger_config_t chg_chips[] = {
.drv = &isl923x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* Board version depends on ADCs, so init i2c port after ADC */
static void charger_config_complete(void)
diff --git a/board/drawcia/board.c b/board/drawcia/board.c
index 19c69057f8..6b6a433787 100644
--- a/board/drawcia/board.c
+++ b/board/drawcia/board.c
@@ -164,7 +164,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &sm5803_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* TCPCs */
const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
diff --git a/board/elm/board.c b/board/elm/board.c
index 578e7ac312..a893a57416 100644
--- a/board/elm/board.c
+++ b/board/elm/board.c
@@ -177,7 +177,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &isl923x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/**
* Reset PD MCU
diff --git a/board/eve/board.c b/board/eve/board.c
index d8329d27ea..e06c02e7d7 100644
--- a/board/eve/board.c
+++ b/board/eve/board.c
@@ -241,7 +241,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bd9995x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/**
* Power on (or off) a single TCPC.
diff --git a/board/flapjack/board.c b/board/flapjack/board.c
index 4474442b9f..065df1edf9 100644
--- a/board/flapjack/board.c
+++ b/board/flapjack/board.c
@@ -254,7 +254,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &rt946x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* power signal list. Must match order of enum power_signal. */
const struct power_signal_info power_signal_list[] = {
diff --git a/board/glkrvp/board.c b/board/glkrvp/board.c
index 6c3a734f89..c4b3ce6e38 100644
--- a/board/glkrvp/board.c
+++ b/board/glkrvp/board.c
@@ -64,8 +64,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
/* Wake-up pins for hibernate */
const enum gpio_signal hibernate_wake_pins[] = {
GPIO_AC_PRESENT,
diff --git a/board/glkrvp_ite/board.c b/board/glkrvp_ite/board.c
index e86d1083b7..b1102092b0 100644
--- a/board/glkrvp_ite/board.c
+++ b/board/glkrvp_ite/board.c
@@ -53,8 +53,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
/* Wake-up pins for hibernate */
const enum gpio_signal hibernate_wake_pins[] = {
GPIO_AC_PRESENT,
diff --git a/board/hammer/board.c b/board/hammer/board.c
index 9b26322e49..c6149a678c 100644
--- a/board/hammer/board.c
+++ b/board/hammer/board.c
@@ -109,7 +109,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
#endif
#ifdef HAS_BACKLIGHT
diff --git a/board/host/charger.c b/board/host/charger.c
index d71f1e8994..01f29571d0 100644
--- a/board/host/charger.c
+++ b/board/host/charger.c
@@ -173,5 +173,3 @@ const struct charger_config_t chg_chips[] = {
.drv = &mock_drv,
},
};
-
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
diff --git a/board/jacuzzi/board.c b/board/jacuzzi/board.c
index 101a80222b..637079d417 100644
--- a/board/jacuzzi/board.c
+++ b/board/jacuzzi/board.c
@@ -170,7 +170,6 @@ struct charger_config_t chg_chips[] = {
.drv = &isl923x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* Board version depends on ADCs, so init i2c port after ADC */
static void charger_config_complete(void)
diff --git a/board/jerry/board.c b/board/jerry/board.c
index c99c6ac8a3..9583f7ef41 100644
--- a/board/jerry/board.c
+++ b/board/jerry/board.c
@@ -55,7 +55,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bq24715_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
void board_config_pre_init(void)
{
diff --git a/board/jslrvp_ite/board.c b/board/jslrvp_ite/board.c
index 5ea6f057b6..6a8cc3972b 100644
--- a/board/jslrvp_ite/board.c
+++ b/board/jslrvp_ite/board.c
@@ -100,8 +100,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
/******************************************************************************/
/* PWROK signal configuration */
/*
diff --git a/board/nami/board.c b/board/nami/board.c
index 5e3f75fbd3..3ffed42ae0 100644
--- a/board/nami/board.c
+++ b/board/nami/board.c
@@ -293,8 +293,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
void board_reset_pd_mcu(void)
{
if (oem == PROJECT_AKALI && board_version < 0x0200) {
diff --git a/board/nautilus/board.c b/board/nautilus/board.c
index 9b191cbd70..e538010814 100644
--- a/board/nautilus/board.c
+++ b/board/nautilus/board.c
@@ -204,8 +204,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
void board_reset_pd_mcu(void)
{
/* Assert reset */
diff --git a/board/nocturne/board.c b/board/nocturne/board.c
index b7ddc2aa74..b5472ee456 100644
--- a/board/nocturne/board.c
+++ b/board/nocturne/board.c
@@ -340,8 +340,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
void board_chipset_startup(void)
{
gpio_set_level(GPIO_EN_5V, 1);
diff --git a/board/oak/board.c b/board/oak/board.c
index b282daf2a3..eb16c03ab1 100644
--- a/board/oak/board.c
+++ b/board/oak/board.c
@@ -168,7 +168,6 @@ const struct charger_config_t chg_chips[] = {
},
};
#endif /* OAK_REV1 */
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/*
* Temperature sensors data; must be in same order as enum temp_sensor_id.
diff --git a/board/poppy/board.c b/board/poppy/board.c
index dccf04a3cd..e01446b316 100644
--- a/board/poppy/board.c
+++ b/board/poppy/board.c
@@ -242,8 +242,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
/**
* Power on (or off) a single TCPC.
diff --git a/board/rammus/board.c b/board/rammus/board.c
index b46aece2a9..06210b2134 100644
--- a/board/rammus/board.c
+++ b/board/rammus/board.c
@@ -155,8 +155,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
/* TCPC mux configuration */
struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
[USB_PD_PORT_PS8751] = {
diff --git a/board/reef/board.c b/board/reef/board.c
index 72decd3c40..e6856f3f55 100644
--- a/board/reef/board.c
+++ b/board/reef/board.c
@@ -252,7 +252,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bd9995x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
uint16_t tcpc_get_alert_status(void)
{
diff --git a/board/reef_it8320/board.c b/board/reef_it8320/board.c
index 630f3f950f..e45174e9e1 100644
--- a/board/reef_it8320/board.c
+++ b/board/reef_it8320/board.c
@@ -172,7 +172,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bd9995x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* Called by APL power state machine when transitioning from G3 to S5 */
void chipset_pre_init_callback(void)
diff --git a/board/reef_mchp/board.c b/board/reef_mchp/board.c
index 373668b195..04d1438799 100644
--- a/board/reef_mchp/board.c
+++ b/board/reef_mchp/board.c
@@ -249,7 +249,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bd9995x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* Return the two slave addresses the specified
* controller will respond to when controller
diff --git a/board/samus/board.c b/board/samus/board.c
index 7e76833241..211d000e86 100644
--- a/board/samus/board.c
+++ b/board/samus/board.c
@@ -141,7 +141,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bq2477x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
#define TEMP_U40_REG_ADDR_FLAGS (0x40 | I2C_FLAG_BIG_ENDIAN)
#define TEMP_U41_REG_ADDR_FLAGS (0x44 | I2C_FLAG_BIG_ENDIAN)
diff --git a/board/scarlet/board.c b/board/scarlet/board.c
index ca4c7eb13d..ef5dc6f6f1 100644
--- a/board/scarlet/board.c
+++ b/board/scarlet/board.c
@@ -90,7 +90,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &rt946x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* power signal list. Must match order of enum power_signal. */
const struct power_signal_info power_signal_list[] = {
diff --git a/board/strago/board.c b/board/strago/board.c
index 308c4ee8ce..14be616184 100644
--- a/board/strago/board.c
+++ b/board/strago/board.c
@@ -185,7 +185,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &bq2477x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/**
* Reset PD MCU
diff --git a/board/tglrvpu_ite/board.c b/board/tglrvpu_ite/board.c
index f62a90d177..888b893d03 100644
--- a/board/tglrvpu_ite/board.c
+++ b/board/tglrvpu_ite/board.c
@@ -118,8 +118,6 @@ const struct charger_config_t chg_chips[] = {
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
-
/******************************************************************************/
/* PWROK signal configuration */
/*
diff --git a/board/waddledee/board.c b/board/waddledee/board.c
index ddf23ef917..5a61565804 100644
--- a/board/waddledee/board.c
+++ b/board/waddledee/board.c
@@ -152,7 +152,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &sm5803_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* TCPCs */
const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
diff --git a/board/waddledoo/board.c b/board/waddledoo/board.c
index b28c9a8153..1b69a24a73 100644
--- a/board/waddledoo/board.c
+++ b/board/waddledoo/board.c
@@ -392,7 +392,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &isl923x_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = {
{
diff --git a/board/wheelie/board.c b/board/wheelie/board.c
index 65c75124c3..4ccf93b0d5 100644
--- a/board/wheelie/board.c
+++ b/board/wheelie/board.c
@@ -90,7 +90,6 @@ const struct charger_config_t chg_chips[] = {
.drv = &sm5803_drv,
},
};
-const unsigned int chg_cnt = ARRAY_SIZE(chg_chips);
/* TCPCs */
const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 5f240dd2a6..15eff47076 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -2472,7 +2472,7 @@ int charge_set_input_current_limit(int ma, int mv)
#ifdef CONFIG_OCPC
void charge_set_active_chg_chip(int idx)
{
- ASSERT(idx < (int)chg_cnt);
+ ASSERT(idx < (int)board_get_charger_chip_count());
if (idx == curr.ocpc.active_chg_chip)
return;
diff --git a/common/charger.c b/common/charger.c
index 3a980d99df..68f8f71ced 100644
--- a/common/charger.c
+++ b/common/charger.c
@@ -41,6 +41,15 @@ static void dptf_disable_hook(void)
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, dptf_disable_hook, HOOK_PRIO_DEFAULT);
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, dptf_disable_hook, HOOK_PRIO_DEFAULT);
+/*
+ * Boards should override this function if their count may vary during run-time
+ * due to different DB options.
+ */
+__overridable uint8_t board_get_charger_chip_count(void)
+{
+ return CHARGER_NUM;
+}
+
int charger_closest_voltage(int voltage)
{
const struct charger_info *info = charger_get_info();
@@ -236,7 +245,7 @@ static void charger_chips_init(void)
{
int chip;
- for (chip = 0; chip < chg_cnt; chip++) {
+ for (chip = 0; chip < board_get_charger_chip_count(); chip++) {
if (chg_chips[chip].drv->init)
chg_chips[chip].drv->init(chip);
}
@@ -248,7 +257,7 @@ enum ec_error_list charger_post_init(void)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -264,7 +273,7 @@ const struct charger_info *charger_get_info(void)
int chgnum = 0;
const struct charger_info *ret = NULL;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return NULL;
}
@@ -280,7 +289,7 @@ enum ec_error_list charger_get_status(int *status)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -296,7 +305,7 @@ enum ec_error_list charger_set_mode(int mode)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -312,7 +321,7 @@ enum ec_error_list charger_enable_otg_power(int enabled)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -329,7 +338,7 @@ enum ec_error_list charger_set_otg_current_voltage(int output_current,
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -346,7 +355,7 @@ int charger_is_sourcing_otg_power(int port)
int chgnum = 0;
int rv = 0;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return 0;
}
@@ -361,10 +370,11 @@ enum ec_error_list charger_get_current(int chgnum, int *current)
{
int rv = EC_ERROR_UNIMPLEMENTED;
+ /* Note: chgnum may be -1 if no active port is selected */
if (chgnum < 0)
return EC_ERROR_INVAL;
- if (chgnum >= chg_cnt) {
+ if (chgnum >= board_get_charger_chip_count()) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -379,7 +389,7 @@ enum ec_error_list charger_set_current(int chgnum, int current)
{
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -397,7 +407,7 @@ enum ec_error_list charger_get_voltage(int chgnum, int *voltage)
if (chgnum < 0)
return EC_ERROR_INVAL;
- if (chgnum >= chg_cnt) {
+ if (chgnum >= board_get_charger_chip_count()) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -412,7 +422,7 @@ enum ec_error_list charger_set_voltage(int chgnum, int voltage)
{
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -428,7 +438,7 @@ enum ec_error_list charger_discharge_on_ac(int enable)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -448,7 +458,7 @@ enum ec_error_list charger_get_vbus_voltage(int port, int *voltage)
if (!IS_ENABLED(CONFIG_CHARGER_SINGLE_CHIP))
chgnum = port;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return 0;
}
@@ -464,7 +474,7 @@ enum ec_error_list charger_set_input_current(int chgnum, int input_current)
{
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -483,7 +493,7 @@ enum ec_error_list charger_get_input_current(int chgnum, int *input_current)
if (chgnum < 0)
return EC_ERROR_INVAL;
- if (chgnum >= chg_cnt) {
+ if (chgnum >= board_get_charger_chip_count()) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -500,7 +510,7 @@ enum ec_error_list charger_manufacturer_id(int *id)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -516,7 +526,7 @@ enum ec_error_list charger_device_id(int *id)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -532,7 +542,7 @@ enum ec_error_list charger_get_option(int *option)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -548,7 +558,7 @@ enum ec_error_list charger_set_option(int option)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -564,7 +574,7 @@ enum ec_error_list charger_set_hw_ramp(int enable)
int chgnum = 0;
int rv = EC_ERROR_UNIMPLEMENTED;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
@@ -581,7 +591,7 @@ int chg_ramp_is_stable(void)
int chgnum = 0;
int rv = 0;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return 0;
}
@@ -597,7 +607,7 @@ int chg_ramp_is_detected(void)
int chgnum = 0;
int rv = 0;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return 0;
}
@@ -613,7 +623,7 @@ int chg_ramp_get_current_limit(void)
int chgnum = 0;
int rv = 0;
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return 0;
}
@@ -630,7 +640,7 @@ enum ec_error_list charger_set_vsys_compensation(int chgnum,
int current_ma,
int voltage_mv)
{
- if ((chgnum < 0) || (chgnum >= chg_cnt)) {
+ if ((chgnum < 0) || (chgnum >= board_get_charger_chip_count())) {
CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
return EC_ERROR_INVAL;
}
diff --git a/driver/charger/isl923x.c b/driver/charger/isl923x.c
index ce2d6bfc69..3faa6cdb7a 100644
--- a/driver/charger/isl923x.c
+++ b/driver/charger/isl923x.c
@@ -563,7 +563,7 @@ void raa489000_hibernate(int chgnum)
{
int rv, regval;
- if ((chgnum < 0) || (chgnum > chg_cnt)) {
+ if ((chgnum < 0) || (chgnum > board_get_charger_chip_count())) {
CPRINTS("%s: Invalid chgnum! (%d)", __func__, chgnum);
return;
}
diff --git a/include/charger.h b/include/charger.h
index 41f22adfad..246edec1ab 100644
--- a/include/charger.h
+++ b/include/charger.h
@@ -130,7 +130,8 @@ extern const struct charger_config_t chg_chips[];
#else
extern struct charger_config_t chg_chips[];
#endif
-extern const unsigned int chg_cnt;
+
+__override_proto uint8_t board_get_charger_chip_count(void);
#ifdef CONFIG_CHARGER_SINGLE_CHIP
enum chg_id {