From a94a5561dc2a959e3cc586f0c5ca63f9de0a810a Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Fri, 5 Dec 2014 23:02:54 -0800 Subject: [PATCH] samus: turn on PP5000 when AC is attached in G3 Turn on PP5000 when AC is plugged in in G3 so that the PD MCU can accurately measure the CC voltage. BUG=chrome-os-partner:33909 BRANCH=samus TEST=test with various type-C chargers. verify that in G3 the pp5000 rail is on when AC is plugged in, but off when AC is unplugged used reported battery current to estimate that turning on PP5000 rail in G3 consumes an extra 30mW of power, but that shouldn't matter much when AC is connected. Change-Id: I3cdd2aaf3e7688d69a65e5d11e38e5b9cf16e703 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/233734 Reviewed-by: Bill Richardson --- board/samus/extpower.c | 6 ++++++ board/samus/power_sequence.c | 23 +++++++++++++++++++++-- common/usb_pd_protocol.c | 9 +++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/board/samus/extpower.c b/board/samus/extpower.c index 60f97a4da2..9262c06d17 100644 --- a/board/samus/extpower.c +++ b/board/samus/extpower.c @@ -31,12 +31,18 @@ static void extpower_deferred(void) if (extpower && !extpower_prev) { charger_discharge_on_ac(0); + /* If in G3, enable PP5000 for accurate sensing of CC */ + if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) + gpio_set_level(GPIO_PP5000_EN, 1); } else if (extpower && extpower_prev) { /* glitch on AC_PRESENT, attempt to recover from backboost */ charger_discharge_on_ac(1); charger_discharge_on_ac(0); } else { charger_discharge_on_ac(1); + /* If in G3, make sure PP5000 is off when no AC */ + if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) + gpio_set_level(GPIO_PP5000_EN, 0); } extpower_prev = extpower; diff --git a/board/samus/power_sequence.c b/board/samus/power_sequence.c index ffa8999b0a..b5d2e9a176 100644 --- a/board/samus/power_sequence.c +++ b/board/samus/power_sequence.c @@ -9,6 +9,7 @@ #include "chipset.h" #include "common.h" #include "console.h" +#include "extpower.h" #include "gpio.h" #include "hooks.h" #include "host_command.h" @@ -85,7 +86,12 @@ static void chipset_force_g3(void) gpio_set_level(GPIO_PP1800_EN, 0); gpio_set_level(GPIO_PP3300_DSW_GATED_EN, 0); gpio_set_level(GPIO_PP5000_USB_EN, 0); - gpio_set_level(GPIO_PP5000_EN, 0); + /* + * Don't disable PP5000 if AC is attached because we need + * it for accurate CC line voltage measurement on PD MCU. + */ + if (!extpower_is_present()) + gpio_set_level(GPIO_PP5000_EN, 0); gpio_set_level(GPIO_PCH_RSMRST_L, 0); gpio_set_level(GPIO_PCH_DPWROK, 0); gpio_set_level(GPIO_PP3300_DSW_EN, 0); @@ -468,7 +474,13 @@ enum power_state power_handle_state(enum power_state state) /* Turn off power rails enabled in S5 */ gpio_set_level(GPIO_PP1050_EN, 0); - gpio_set_level(GPIO_PP5000_EN, 0); + + /* + * Don't disable PP5000 if AC is attached because we need + * it for accurate CC line voltage measurement on PD MCU. + */ + if (!extpower_is_present()) + gpio_set_level(GPIO_PP5000_EN, 0); /* Disable 3.3V DSW */ gpio_set_level(GPIO_PP3300_DSW_EN, 0); @@ -490,6 +502,13 @@ int lb_power(int enabled) if (!chipset_in_state(CHIPSET_STATE_ANY_OFF)) return 0; + /* + * Don't disable PP5000 if AC is attached because we need it for + * accurate CC line voltage measurement on PD MCU. + */ + if (!enabled && extpower_is_present()) + return 0; + /* * If the AP is off, we can still turn the lightbar on briefly. * When turning on, we have to wait for the rails to come up fully diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 952d7066c8..82a3e5a91c 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -1972,6 +1972,15 @@ void pd_task(void) #ifdef CONFIG_CHARGE_MANAGER timeout = PD_T_SINK_ADJ - PD_T_DEBOUNCE; + /* + * If we didn't come from disconnected, must have + * come from some path that did not set typec + * current limit. So, set to 0 so that we guarantee + * this is revised below. + */ + if (pd[port].last_state != PD_STATE_SNK_DISCONNECTED) + typec_curr = 0; + /* Check if CC pull-up has changed */ cc1_volt = pd_adc_read(port, pd[port].polarity); if (typec_curr != get_typec_current_limit(cc1_volt)) {