summaryrefslogtreecommitdiff
path: root/board/lazor
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-03-18 10:15:45 -0600
committerCommit Bot <commit-bot@chromium.org>2021-03-19 22:51:43 +0000
commit6c837a35edd6cd6ecc8d71f7a497acb652e1870f (patch)
treedb60b7084b306b451e6235d6128581d188ad19d9 /board/lazor
parent977a6125900860a2e2635cc7a64005d9d7fd32b1 (diff)
downloadchrome-ec-6c837a35edd6cd6ecc8d71f7a497acb652e1870f.tar.gz
lazor: separate out switchcap code
Separate the switchcap implementation to another file so it can be more readily used by the Zephyr OS build. BUG=b:183054226 BRANCH=none TEST=power sequence lazor (on CrOS EC OS build) Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Iefa08412ac3708e667c5bee14be70128aa50eade Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2774364 Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'board/lazor')
-rw-r--r--board/lazor/board.c118
-rw-r--r--board/lazor/build.mk2
-rw-r--r--board/lazor/gpio.inc2
-rw-r--r--board/lazor/switchcap.c128
4 files changed, 130 insertions, 120 deletions
diff --git a/board/lazor/board.c b/board/lazor/board.c
index 1886779009..9e72e39cd9 100644
--- a/board/lazor/board.c
+++ b/board/lazor/board.c
@@ -49,7 +49,6 @@ static void usb1_evt(enum gpio_signal signal);
static void usba_oc_interrupt(enum gpio_signal signal);
static void ppc_interrupt(enum gpio_signal signal);
static void board_connect_c0_sbu(enum gpio_signal s);
-static void switchcap_interrupt(enum gpio_signal signal);
#include "gpio_list.h"
@@ -126,11 +125,6 @@ static void board_connect_c0_sbu(enum gpio_signal s)
hook_call_deferred(&board_connect_c0_sbu_deferred_data, 0);
}
-static void switchcap_interrupt(enum gpio_signal signal)
-{
- ln9310_interrupt(signal);
-}
-
/* Keyboard scan setting */
struct keyboard_scan_config keyscan_config = {
/* Use 80 us, because KSO_02 passes through the H1. */
@@ -211,12 +205,6 @@ const struct pwm_t pwm_channels[] = {
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
-/* LN9310 switchcap */
-const struct ln9310_config_t ln9310_config = {
- .i2c_port = I2C_PORT_POWER,
- .i2c_addr_flags = LN9310_I2C_ADDR_0_FLAGS,
-};
-
/* Power Path Controller */
struct ppc_config_t ppc_chips[] = {
{
@@ -603,86 +591,6 @@ static void sku_init(void)
}
DECLARE_HOOK(HOOK_INIT, sku_init, HOOK_PRIO_INIT_I2C + 1);
-static int board_has_ln9310(void)
-{
- static int ln9310_present = -1;
- int status, val;
-
- /* Cache the status of LN9310 present or not */
- if (ln9310_present == -1) {
- status = i2c_read8(ln9310_config.i2c_port,
- ln9310_config.i2c_addr_flags,
- LN9310_REG_CHIP_ID,
- &val);
-
- /*
- * Any error reading LN9310 CHIP_ID over I2C means the chip
- * not present. Fallback to use DA9313 switchcap.
- */
- ln9310_present = !status && val == LN9310_CHIP_ID;
- }
-
- return ln9310_present;
-}
-
-static void board_switchcap_init(void)
-{
- if (board_has_ln9310()) {
- CPRINTS("Use switchcap: LN9310");
-
- /* Configure and enable interrupt for LN9310 */
- gpio_set_flags(GPIO_SWITCHCAP_PG_INT_L, GPIO_INT_FALLING);
- gpio_enable_interrupt(GPIO_SWITCHCAP_PG_INT_L);
-
- /*
- * Configure LN9310 enable, open-drain output. Don't set the
- * level here; otherwise, it will override its value and
- * shutdown the switchcap when sysjump to RW.
- *
- * Note that the gpio.inc configures it GPIO_OUT_LOW. When
- * sysjump to RW, will output push-pull a short period of
- * time. As it outputs LOW, should be fine.
- *
- * This GPIO changes like:
- * (1) EC boots from RO -> high-Z
- * (2) GPIO init according to gpio.inc -> push-pull LOW
- * (3) This function configures it -> open-drain HIGH
- * (4) Power sequence turns on the switchcap -> open-drain LOW
- * (5) EC sysjumps to RW
- * (6) GPIO init according to gpio.inc -> push-pull LOW
- * (7) This function configures it -> open-drain LOW
- */
- gpio_set_flags(GPIO_SWITCHCAP_ON_L,
- GPIO_OUTPUT | GPIO_OPEN_DRAIN);
-
- /* Only configure the switchcap if not sysjump */
- if (!system_jumped_late()) {
- /*
- * Deassert the enable pin (set it HIGH), so the
- * switchcap won't be enabled after the switchcap is
- * configured from standby mode to switching mode.
- */
- gpio_set_level(GPIO_SWITCHCAP_ON_L, 1);
- ln9310_init();
- }
- } else {
- CPRINTS("Use switchcap: DA9313");
-
- /*
- * When the chip in power down mode, it outputs high-Z.
- * Set pull-down to avoid floating.
- */
- gpio_set_flags(GPIO_DA9313_GPIO0, GPIO_INPUT | GPIO_PULL_DOWN);
-
- /*
- * Configure DA9313 enable, push-pull output. Don't set the
- * level here; otherwise, it will override its value and
- * shutdown the switchcap when sysjump to RW.
- */
- gpio_set_flags(GPIO_SWITCHCAP_ON, GPIO_OUTPUT);
- }
-}
-
/* Initialize board. */
static void board_init(void)
{
@@ -702,8 +610,6 @@ static void board_init(void)
/* Set the backlight duty cycle to 0. AP will override it later. */
pwm_set_duty(PWM_CH_DISPLIGHT, 0);
-
- board_switchcap_init();
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
@@ -799,30 +705,6 @@ static void board_chipset_resume(void)
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT);
-void board_set_switchcap_power(int enable)
-{
- if (board_has_ln9310())
- gpio_set_level(GPIO_SWITCHCAP_ON_L, !enable);
- else
- gpio_set_level(GPIO_SWITCHCAP_ON, enable);
-}
-
-int board_is_switchcap_enabled(void)
-{
- if (board_has_ln9310())
- return !gpio_get_level(GPIO_SWITCHCAP_ON_L);
- else
- return gpio_get_level(GPIO_SWITCHCAP_ON);
-}
-
-int board_is_switchcap_power_good(void)
-{
- if (board_has_ln9310())
- return ln9310_power_good();
- else
- return gpio_get_level(GPIO_DA9313_GPIO0);
-}
-
void board_reset_pd_mcu(void)
{
cprints(CC_USB, "Resetting TCPCs...");
diff --git a/board/lazor/build.mk b/board/lazor/build.mk
index a044fa58cb..d06a4457f0 100644
--- a/board/lazor/build.mk
+++ b/board/lazor/build.mk
@@ -11,4 +11,4 @@ CHIP_FAMILY:=npcx7
CHIP_VARIANT:=npcx7m6fc
BASEBOARD:=trogdor
-board-y=battery.o board.o led.o
+board-y=battery.o board.o led.o switchcap.o
diff --git a/board/lazor/gpio.inc b/board/lazor/gpio.inc
index 49eb60064f..76447bf32a 100644
--- a/board/lazor/gpio.inc
+++ b/board/lazor/gpio.inc
@@ -48,7 +48,7 @@ GPIO_INT(ACCEL_GYRO_INT_L, PIN(A, 0), GPIO_INT_FALLING, motion_interrupt) /* A
* For DA9313 SKUs, it is GPIO0 of DA9313. The GPIO0 is configured as PVC_PG.
* For LN9310 SKUs, it is the interrupt line of LN9310.
*/
-GPIO_INT(DA9313_GPIO0, PIN(E, 2), GPIO_INT_FALLING, switchcap_interrupt)
+GPIO_INT(DA9313_GPIO0, PIN(E, 2), GPIO_INT_FALLING, ln9310_interrupt)
/*
* EC_RST_ODL used to be a wake source from PSL mode. However, we disabled
diff --git a/board/lazor/switchcap.c b/board/lazor/switchcap.c
new file mode 100644
index 0000000000..d00e973961
--- /dev/null
+++ b/board/lazor/switchcap.c
@@ -0,0 +1,128 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "common.h"
+#include "config.h"
+#include "console.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "ln9310.h"
+#include "power/sc7180.h"
+#include "system.h"
+
+#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args)
+
+/* LN9310 switchcap */
+const struct ln9310_config_t ln9310_config = {
+ .i2c_port = I2C_PORT_POWER,
+ .i2c_addr_flags = LN9310_I2C_ADDR_0_FLAGS,
+};
+
+static int board_has_ln9310(void)
+{
+ static int ln9310_present = -1;
+ int status, val;
+
+ /* Cache the status of LN9310 present or not */
+ if (ln9310_present == -1) {
+ status = i2c_read8(ln9310_config.i2c_port,
+ ln9310_config.i2c_addr_flags,
+ LN9310_REG_CHIP_ID,
+ &val);
+
+ /*
+ * Any error reading LN9310 CHIP_ID over I2C means the chip
+ * not present. Fallback to use DA9313 switchcap.
+ */
+ ln9310_present = !status && val == LN9310_CHIP_ID;
+ }
+
+ return ln9310_present;
+}
+
+static void switchcap_init(void)
+{
+ if (board_has_ln9310()) {
+ CPRINTS("Use switchcap: LN9310");
+
+ /* Configure and enable interrupt for LN9310 */
+ gpio_set_flags(GPIO_SWITCHCAP_PG_INT_L, GPIO_INT_FALLING);
+ gpio_enable_interrupt(GPIO_SWITCHCAP_PG_INT_L);
+
+ /*
+ * Configure LN9310 enable, open-drain output. Don't set the
+ * level here; otherwise, it will override its value and
+ * shutdown the switchcap when sysjump to RW.
+ *
+ * Note that the gpio.inc configures it GPIO_OUT_LOW. When
+ * sysjump to RW, will output push-pull a short period of
+ * time. As it outputs LOW, should be fine.
+ *
+ * This GPIO changes like:
+ * (1) EC boots from RO -> high-Z
+ * (2) GPIO init according to gpio.inc -> push-pull LOW
+ * (3) This function configures it -> open-drain HIGH
+ * (4) Power sequence turns on the switchcap -> open-drain LOW
+ * (5) EC sysjumps to RW
+ * (6) GPIO init according to gpio.inc -> push-pull LOW
+ * (7) This function configures it -> open-drain LOW
+ */
+ gpio_set_flags(GPIO_SWITCHCAP_ON_L,
+ GPIO_OUTPUT | GPIO_OPEN_DRAIN);
+
+ /* Only configure the switchcap if not sysjump */
+ if (!system_jumped_late()) {
+ /*
+ * Deassert the enable pin (set it HIGH), so the
+ * switchcap won't be enabled after the switchcap is
+ * configured from standby mode to switching mode.
+ */
+ gpio_set_level(GPIO_SWITCHCAP_ON_L, 1);
+ ln9310_init();
+ }
+ } else {
+ CPRINTS("Use switchcap: DA9313");
+
+ /*
+ * When the chip in power down mode, it outputs high-Z.
+ * Set pull-down to avoid floating.
+ */
+ gpio_set_flags(GPIO_DA9313_GPIO0, GPIO_INPUT | GPIO_PULL_DOWN);
+
+ /*
+ * Configure DA9313 enable, push-pull output. Don't set the
+ * level here; otherwise, it will override its value and
+ * shutdown the switchcap when sysjump to RW.
+ */
+ gpio_set_flags(GPIO_SWITCHCAP_ON, GPIO_OUTPUT);
+ }
+}
+DECLARE_HOOK(HOOK_INIT, switchcap_init, HOOK_PRIO_DEFAULT);
+
+void board_set_switchcap_power(int enable)
+{
+ if (board_has_ln9310())
+ gpio_set_level(GPIO_SWITCHCAP_ON_L, !enable);
+ else
+ gpio_set_level(GPIO_SWITCHCAP_ON, enable);
+}
+
+int board_is_switchcap_enabled(void)
+{
+ if (board_has_ln9310())
+ return !gpio_get_level(GPIO_SWITCHCAP_ON_L);
+ else
+ return gpio_get_level(GPIO_SWITCHCAP_ON);
+}
+
+int board_is_switchcap_power_good(void)
+{
+ if (board_has_ln9310())
+ return ln9310_power_good();
+ else
+ return gpio_get_level(GPIO_DA9313_GPIO0);
+}