summaryrefslogtreecommitdiff
path: root/board/puff/board.c
diff options
context:
space:
mode:
authorPeter Marheine <pmarheine@chromium.org>2019-12-23 15:14:07 +1100
committerCommit Bot <commit-bot@chromium.org>2019-12-31 04:43:34 +0000
commit76f1cb778934bf14ffb830a8983f339b323f8b48 (patch)
tree5e47858c3a8935b3a864ae389823987075fa336c /board/puff/board.c
parent14a1dcc4325e062a61f77df67c24c81c4dd13cd3 (diff)
downloadchrome-ec-76f1cb778934bf14ffb830a8983f339b323f8b48.tar.gz
puff: prevent AP boot when there isn't enough power
The common x86 state machine does this, but the EC-controlled sequencing did not. Since trying to boot the AP without enough power will cause the system to brown out, we need to do it too. TEST=boot prevented on hardware BRANCH=none BUG=b:146515963 Change-Id: I7dbe6ab962fbe47d4d866be98d4174291c757c72 Signed-off-by: Peter Marheine <pmarheine@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1980104 Reviewed-by: Andrew McRae <amcrae@chromium.org>
Diffstat (limited to 'board/puff/board.c')
-rw-r--r--board/puff/board.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/board/puff/board.c b/board/puff/board.c
index 590085e8a5..1889ca8467 100644
--- a/board/puff/board.c
+++ b/board/puff/board.c
@@ -157,26 +157,17 @@ static void port_ocp_interrupt(enum gpio_signal signal)
*/
#define ADP_DEBOUNCE_MS 1000 /* Debounce time for BJ plug/unplug */
/* Debounced connection state of the barrel jack */
-static int adp_connected = 1;
-static void adp_state_init(void)
-{
- adp_connected = !gpio_get_level(GPIO_BJ_ADP_PRESENT_L);
-
- /* Disable BJ power if not connected (we're on USB-C). */
- gpio_set_level(GPIO_EN_PPVAR_BJ_ADP_L, !adp_connected);
-}
-DECLARE_HOOK(HOOK_INIT, adp_state_init, HOOK_PRIO_INIT_EXTPOWER);
-
+static int8_t adp_connected = -1;
static void adp_connect_deferred(void)
{
struct charge_port_info pi = { 0 };
- int connected = gpio_get_level(GPIO_BJ_ADP_PRESENT_L);
+ int connected = !gpio_get_level(GPIO_BJ_ADP_PRESENT_L);
/* Debounce */
if (connected == adp_connected)
return;
if (connected) {
- pi.voltage = 19500;
+ pi.voltage = 19000;
if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
/*
* TODO(b:143975429) set current according to SKU.
@@ -191,11 +182,6 @@ static void adp_connect_deferred(void)
}
charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED,
DEDICATED_CHARGE_PORT, &pi);
- /*
- * Explicitly notifies the host that BJ is plugged or unplugged
- * (when running on a type-c adapter).
- */
- pd_send_host_event(PD_EVENT_POWER_CHANGE);
adp_connected = connected;
}
DECLARE_DEFERRED(adp_connect_deferred);
@@ -203,11 +189,26 @@ DECLARE_DEFERRED(adp_connect_deferred);
/* IRQ for BJ plug/unplug. It shouldn't be called if BJ is the power source. */
void adp_connect_interrupt(enum gpio_signal signal)
{
- if (adp_connected == !gpio_get_level(GPIO_BJ_ADP_PRESENT_L))
- return;
hook_call_deferred(&adp_connect_deferred_data, ADP_DEBOUNCE_MS * MSEC);
}
+static void adp_state_init(void)
+{
+ /*
+ * Initialize all charge suppliers to 0. The charge manager waits until
+ * all ports have reported in before doing anything.
+ */
+ for (int i = 0; i < CHARGE_PORT_COUNT; i++) {
+ for (int j = 0; j < CHARGE_SUPPLIER_COUNT; j++)
+ charge_manager_update_charge(j, i, NULL);
+ }
+
+ /* Report charge state from the barrel jack. */
+ adp_connect_deferred();
+}
+DECLARE_HOOK(HOOK_INIT, adp_state_init, HOOK_PRIO_CHARGE_MANAGER_INIT + 1);
+
+
#include "gpio_list.h" /* Must come after other header files. */
/******************************************************************************/