diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2017-12-19 18:17:37 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-12-20 10:14:45 -0800 |
commit | 7c688c0f698ec969ac53dda851b96c3e3cce55b2 (patch) | |
tree | cb969f1656353a466ea9aa959eb23745df2a3c7a /board/fizz/usb_pd_policy.c | |
parent | 66db5b4e8728ef1116d88a4ce1b54f0d403007c3 (diff) | |
download | chrome-ec-7c688c0f698ec969ac53dda851b96c3e3cce55b2.tar.gz |
Fizz: Restore BJ current and voltage after sysjump
This patch makes EC save the max current and voltage of a barrel jack
adapter before sysjump and restore them after sysjump.
BUG=b:64442692
BRANCH=none
TEST=Boot Fizz and let coreboot set the adapter current and voltage.
Verify EC-RW inherits the current and voltage set by coreboot.
Change-Id: Ib1addf6e5ce059a39cb2d8b355515df1138409eb
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/835628
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'board/fizz/usb_pd_policy.c')
-rw-r--r-- | board/fizz/usb_pd_policy.c | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/board/fizz/usb_pd_policy.c b/board/fizz/usb_pd_policy.c index 5e48cb4aa6..e1a0e307af 100644 --- a/board/fizz/usb_pd_policy.c +++ b/board/fizz/usb_pd_policy.c @@ -219,6 +219,29 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload, return 0; } +#define CHARGE_PORT_SYSJUMP_TAG 0x4350 /* "CP" - Charge Port */ +#define CHARGE_PORT_HOOK_VERSION 1 + +static int restore_active_charge_port(struct charge_port_info *cpi) +{ + int version, size; + const struct charge_port_info *prev; + + if (!(system_get_reset_flags() & RESET_FLAG_SYSJUMP)) + return EC_ERROR_UNCHANGED; + + prev = (const struct charge_port_info *)system_get_jump_tag( + CHARGE_PORT_SYSJUMP_TAG, &version, &size); + if (!prev || version != CHARGE_PORT_HOOK_VERSION || + size != sizeof(*prev)) + return EC_ERROR_INVAL; + + cpi->current = prev->current; + cpi->voltage = prev->voltage; + + return EC_SUCCESS; +} + /* * Since fizz has no battery, it must source all of its power from either * USB-C or the barrel jack (preferred). Fizz operates in continuous safe @@ -253,9 +276,12 @@ static void board_charge_manager_init(void) typec_set_input_current_limit(input_port, 3000, input_voltage); break; case CHARGE_PORT_BARRELJACK: - /* Set it to the default. Will be updated by AP. */ - cpi.voltage = 19000; - cpi.current = 3330; + if (restore_active_charge_port(&cpi)) { + /* Set it to the default. Will be updated by AP. */ + CPRINTS("Previous charge info not found. Use default."); + cpi.voltage = 19000; + cpi.current = 3330; + } charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED, DEDICATED_CHARGE_PORT, &cpi); break; @@ -263,6 +289,24 @@ static void board_charge_manager_init(void) } DECLARE_HOOK(HOOK_INIT, board_charge_manager_init, HOOK_PRIO_INIT_ADC + 1); +static void preserve_active_charge_port(void) +{ + struct charge_port_info cpi; + + /* If it's not a dedicated charge port, we don't bother. Saving & + * restoring PD charger info is a much bigger problem. */ + if (charge_manager_get_active_charge_port() != DEDICATED_CHARGE_PORT) + return; + cpi.current = charge_manager_get_charger_current(); + cpi.voltage = charge_manager_get_charger_voltage(); + CPRINTS("Saving charge port info: %dmA %dmV", cpi.current, cpi.voltage); + cflush(); + + system_add_jump_tag(CHARGE_PORT_SYSJUMP_TAG, CHARGE_PORT_HOOK_VERSION, + sizeof(cpi), &cpi); +} +DECLARE_HOOK(HOOK_SYSJUMP, preserve_active_charge_port, HOOK_PRIO_DEFAULT); + int board_set_active_charge_port(int port) { const int active_port = charge_manager_get_active_charge_port(); |