summaryrefslogtreecommitdiff
path: root/board/kinox/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/kinox/board.c')
-rw-r--r--board/kinox/board.c58
1 files changed, 29 insertions, 29 deletions
diff --git a/board/kinox/board.c b/board/kinox/board.c
index a814c7a20d..7c55fba876 100644
--- a/board/kinox/board.c
+++ b/board/kinox/board.c
@@ -1,9 +1,9 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include "assert.h"
+#include "builtin/assert.h"
#include "button.h"
#include "charge_manager.h"
#include "charge_state_v2.h"
@@ -11,7 +11,6 @@
#include "compile_time_macros.h"
#include "console.h"
#include "cros_board_info.h"
-#include "fw_config.h"
#include "gpio.h"
#include "gpio_signal.h"
#include "power_button.h"
@@ -21,12 +20,13 @@
#include "throttle_ap.h"
#include "usbc_config.h"
#include "usbc_ppc.h"
+#include "fw_config.h"
#include "gpio_list.h" /* Must come after other header files. */
/* Console output macros */
-#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
/******************************************************************************/
/* USB-A charging control */
@@ -40,8 +40,6 @@ BUILD_ASSERT(ARRAY_SIZE(usb_port_enable) == USB_PORT_COUNT);
int board_set_active_charge_port(int port)
{
- int rv;
-
CPRINTS("Requested charge port change to %d", port);
/*
@@ -64,15 +62,23 @@ int board_set_active_charge_port(int port)
if (board_vbus_source_enabled(port))
return EC_ERROR_INVAL;
- /* Don't change the charge port */
- if (charge_manager_get_active_charge_port() != CHARGE_PORT_NONE)
- return EC_ERROR_INVAL;
-
- /* Make sure BJ adapter is sourcing power */
- if (port == CHARGE_PORT_BARRELJACK &&
- gpio_get_level(GPIO_BJ_ADP_PRESENT_ODL)) {
- CPRINTS("BJ port selected, but not present!");
- return EC_ERROR_INVAL;
+ if (!chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
+ int bj_active, bj_requested;
+
+ if (charge_manager_get_active_charge_port() != CHARGE_PORT_NONE)
+ /* Change is only permitted while the system is off */
+ return EC_ERROR_INVAL;
+
+ /*
+ * Current setting is no charge port but the AP is on, so the
+ * charge manager is out of sync (probably because we're
+ * reinitializing after sysjump). Reject requests that aren't
+ * in sync with our outputs.
+ */
+ bj_active = !gpio_get_level(GPIO_EN_PPVAR_BJ_ADP_L);
+ bj_requested = port == CHARGE_PORT_BARRELJACK;
+ if (bj_active != bj_requested)
+ return EC_ERROR_INVAL;
}
CPRINTS("New charger p%d", port);
@@ -80,19 +86,12 @@ int board_set_active_charge_port(int port)
switch (port) {
case CHARGE_PORT_TYPEC0:
gpio_set_level(GPIO_EN_PPVAR_BJ_ADP_L, 1);
- rv = ppc_vbus_sink_enable(CHARGE_PORT_TYPEC0, 1);
- if (rv) {
- CPRINTS("Failed to enable C0 sink path");
- return rv;
- }
break;
case CHARGE_PORT_BARRELJACK:
- rv = ppc_vbus_sink_enable(CHARGE_PORT_TYPEC0, 0);
- if (rv) {
- CPRINTS("Failed to disable C0 sink path");
- return rv;
- }
- gpio_set_level(GPIO_EN_PPVAR_BJ_ADP_L, 0);
+ /* Make sure BJ adapter is sourcing power */
+ if (gpio_get_level(GPIO_BJ_ADP_PRESENT_ODL))
+ return EC_ERROR_INVAL;
+ ppc_vbus_sink_enable(0, 0);
break;
default:
return EC_ERROR_INVAL;
@@ -101,8 +100,8 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
+void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
+ int charge_mv)
{
}
@@ -122,5 +121,6 @@ DECLARE_HOOK(HOOK_INIT, adp_state_init, HOOK_PRIO_INIT_CHARGE_MANAGER + 1);
static void board_init(void)
{
+ gpio_enable_interrupt(GPIO_BJ_ADP_PRESENT_ODL);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);