diff options
author | Diana Z <dzigterman@chromium.org> | 2020-01-14 14:18:08 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-28 20:22:22 +0000 |
commit | 4eb3a5fe699247a5767ae38c66c75872f4afc575 (patch) | |
tree | 81787f2f54ff3470ce326047213abfae234b50a1 /board/host | |
parent | d9a869beb6e1778cec38dcce64f289aba353a8d5 (diff) | |
download | chrome-ec-4eb3a5fe699247a5767ae38c66c75872f4afc575.tar.gz |
Charger: Create charger driver structure
With upcoming boards which use multiple charger chips, the EC codebase
needs to be changed to assume chargers may have different I2C ports.
This commit creates the driver structure and wrapper functions, which
for now are hard-coded to chip 0 for equivalent behavior with previous
code. A general charger config is created for all boards in charger.c
for now, which uses the build information to fill in the structure.
All boards will default to defining CONFIG_CHARGER_SINGLE_CHIP, which in
turn defines a CHARGER_SOLO which can be used by drivers which have code
that needs to determine charger numbers. For boards which have multiple
chips, they may undefine this config and should generate build errors if
their driver is still using the hardcoded charger reference of
CHARGER_SOLO. Older drivers may continue using CHARGER_SOLO in
non-static functions until they're needed in a multiple charger board.
For boards which may be supporting different I2C configurations for the
charger over board versions, they may define
CONFIG_CHARGER_RUNTIME_CONFIG to fill in these fields after boot.
BRANCH=none
BUG=b:147672225
TEST=builds, chargers on hatch and octopus work
Change-Id: I390ede494226252e512595c48099fa1288ffe93e
Signed-off-by: Diana Z <dzigterman@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2008451
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'board/host')
-rw-r--r-- | board/host/charger.c | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/board/host/charger.c b/board/host/charger.c index 1dd972a82e..d71f1e8994 100644 --- a/board/host/charger.c +++ b/board/host/charger.c @@ -32,13 +32,13 @@ static uint32_t mock_current; static uint32_t mock_voltage; static uint32_t mock_input_current; -const struct charger_info *charger_get_info(void) +static const struct charger_info *mock_get_info(int chgnum) { return &mock_charger_info; } -int charger_get_status(int *status) +static enum ec_error_list mock_get_status(int chgnum, int *status) { *status = CHARGER_LEVEL_2; if (mock_mode & CHARGE_FLAG_INHIBIT_CHARGE) @@ -48,7 +48,7 @@ int charger_get_status(int *status) } -int charger_set_mode(int mode) +static enum ec_error_list mock_set_mode(int chgnum, int mode) { if (mode & CHARGE_FLAG_INHIBIT_CHARGE) mock_mode |= OPTION_CHARGE_INHIBIT; @@ -58,16 +58,16 @@ int charger_set_mode(int mode) } -int charger_get_current(int *current) +static enum ec_error_list mock_get_current(int chgnum, int *current) { *current = mock_current; return EC_SUCCESS; } -int charger_set_current(int current) +static enum ec_error_list mock_set_current(int chgnum, int current) { - const struct charger_info *info = charger_get_info(); + const struct charger_info *info = mock_get_info(chgnum); if (current > 0 && current < info->current_min) current = info->current_min; @@ -80,14 +80,14 @@ int charger_set_current(int current) return EC_SUCCESS; } -int charger_get_voltage(int *voltage) +static enum ec_error_list mock_get_voltage(int chgnum, int *voltage) { *voltage = mock_voltage; return EC_SUCCESS; } -int charger_set_voltage(int voltage) +static enum ec_error_list mock_set_voltage(int chgnum, int voltage) { mock_voltage = voltage; ccprintf("Charger set voltage: %d\n", voltage); @@ -95,42 +95,42 @@ int charger_set_voltage(int voltage) } -int charger_get_option(int *option) +static enum ec_error_list mock_get_option(int chgnum, int *option) { *option = mock_option; return EC_SUCCESS; } -int charger_set_option(int option) +static enum ec_error_list mock_set_option(int chgnum, int option) { mock_option = option; return EC_SUCCESS; } -int charger_manufacturer_id(int *id) +static enum ec_error_list mock_manufacturer_id(int chgnum, int *id) { return EC_SUCCESS; } -int charger_device_id(int *id) +static enum ec_error_list mock_device_id(int chgnum, int *id) { return EC_SUCCESS; } -int charger_get_input_current(int *input_current) +static enum ec_error_list mock_get_input_current(int chgnum, int *input_current) { *input_current = mock_input_current; return EC_SUCCESS; } -int charger_set_input_current(int current) +static enum ec_error_list mock_set_input_current(int chgnum, int current) { - const struct charger_info *info = charger_get_info(); + const struct charger_info *info = mock_get_info(chgnum); if (current < info->input_current_min) current = info->input_current_min; @@ -145,8 +145,33 @@ int charger_set_input_current(int current) } -int charger_post_init(void) +static enum ec_error_list mock_post_init(int chgnum) { mock_current = mock_input_current = CONFIG_CHARGER_INPUT_CURRENT; return EC_SUCCESS; } + +const struct charger_drv mock_drv = { + .post_init = &mock_post_init, + .get_info = &mock_get_info, + .get_status = &mock_get_status, + .set_mode = &mock_set_mode, + .get_current = &mock_get_current, + .set_current = &mock_set_current, + .get_voltage = &mock_get_voltage, + .set_voltage = &mock_set_voltage, + .set_input_current = &mock_set_input_current, + .get_input_current = &mock_get_input_current, + .manufacturer_id = &mock_manufacturer_id, + .device_id = &mock_device_id, + .get_option = &mock_get_option, + .set_option = &mock_set_option, +}; + +const struct charger_config_t chg_chips[] = { + { + .drv = &mock_drv, + }, +}; + +const unsigned int chg_cnt = ARRAY_SIZE(chg_chips); |