summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2017-09-06 14:28:05 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-09-11 21:34:22 +0000
commit781ae9b7a7d1c96e70e1254445f46a2bc41d1f9b (patch)
tree5a5681c0805d7adddcc0bfa65c6ba51f3a99fa53 /board
parent58c58000843a5c544a0f74abdb51d2985353642f (diff)
downloadchrome-ec-781ae9b7a7d1c96e70e1254445f46a2bc41d1f9b.tar.gz
cr50: Defragment code
For historical reasons, CCD, reset, and power button control were scattered around several files. Consolidate the code in more sensible (in retrospect) places. No functional changes, just moving code. BUG=none BRANCH=cr50 TEST=make buildall; boot cr50 Change-Id: Ic381a5a5d0627753cc771189aa377e88b81b155e Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/653766 Reviewed-by: Mary Ruthven <mruthven@chromium.org> (cherry picked from commit ccb151d013d429337a1bb07adfdb55469f3543ba) Reviewed-on: https://chromium-review.googlesource.com/660893 Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'board')
-rw-r--r--board/cr50/ap_state.c1
-rw-r--r--board/cr50/board.c78
-rw-r--r--board/cr50/build.mk2
-rw-r--r--board/cr50/ec_state.c3
-rw-r--r--board/cr50/power_button.c118
-rw-r--r--board/cr50/rdd.c114
-rw-r--r--board/cr50/usb_i2c.c1
-rw-r--r--board/cr50/usb_spi.c2
-rw-r--r--board/cr50/wp.c84
9 files changed, 209 insertions, 194 deletions
diff --git a/board/cr50/ap_state.c b/board/cr50/ap_state.c
index 0a42e9a41a..e9ddea5640 100644
--- a/board/cr50/ap_state.c
+++ b/board/cr50/ap_state.c
@@ -4,6 +4,7 @@
*
* AP state machine
*/
+#include "ccd_config.h"
#include "common.h"
#include "console.h"
#include "gpio.h"
diff --git a/board/cr50/board.c b/board/cr50/board.c
index 238ee2eea5..1cc92e56b3 100644
--- a/board/cr50/board.c
+++ b/board/cr50/board.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
#include "board_id.h"
-#include "case_closed_debug.h"
+#include "ccd_config.h"
#include "clock.h"
#include "common.h"
#include "console.h"
@@ -915,6 +915,48 @@ void board_reboot_ap(void)
deassert_sys_rst();
}
+/**
+ * Console command to toggle system (AP) reset
+ */
+static int command_sys_rst(int argc, char **argv)
+{
+ int val;
+ char *e;
+ int ms = 20;
+
+ if (argc > 1) {
+ if (!ccd_is_cap_enabled(CCD_CAP_REBOOT_EC_AP))
+ return EC_ERROR_ACCESS_DENIED;
+
+ if (!strcasecmp("pulse", argv[1])) {
+ if (argc == 3) {
+ ms = strtoi(argv[2], &e, 0);
+ if (*e)
+ return EC_ERROR_PARAM2;
+ }
+ ccprintf("Pulsing AP reset for %dms\n", ms);
+ assert_sys_rst();
+ msleep(ms);
+ deassert_sys_rst();
+ } else if (parse_bool(argv[1], &val)) {
+ if (val)
+ assert_sys_rst();
+ else
+ deassert_sys_rst();
+ } else
+ return EC_ERROR_PARAM1;
+ }
+
+ ccprintf("SYS_RST_L is %s\n", is_sys_rst_asserted() ?
+ "asserted" : "deasserted");
+
+ return EC_SUCCESS;
+
+}
+DECLARE_SAFE_CONSOLE_COMMAND(sysrst, command_sys_rst,
+ "[pulse [time] | <BOOLEAN>]",
+ "Assert/deassert SYS_RST_L to reset the AP");
+
void assert_ec_rst(void)
{
GWRITE(RBOX, ASSERT_EC_RST, 1);
@@ -929,6 +971,40 @@ int is_ec_rst_asserted(void)
return GREAD(RBOX, ASSERT_EC_RST);
}
+/**
+ * Console command to toggle EC reset
+ */
+static int command_ec_rst(int argc, char **argv)
+{
+ int val;
+
+ if (argc > 1) {
+ if (!ccd_is_cap_enabled(CCD_CAP_REBOOT_EC_AP))
+ return EC_ERROR_ACCESS_DENIED;
+
+ if (!strcasecmp("pulse", argv[1])) {
+ ccprintf("Pulsing EC reset\n");
+ assert_ec_rst();
+ usleep(200);
+ deassert_ec_rst();
+ } else if (parse_bool(argv[1], &val)) {
+ if (val)
+ assert_ec_rst();
+ else
+ deassert_ec_rst();
+ } else
+ return EC_ERROR_PARAM1;
+ }
+
+ ccprintf("EC_RST_L is %s\n", is_ec_rst_asserted() ?
+ "asserted" : "deasserted");
+
+ return EC_SUCCESS;
+}
+DECLARE_SAFE_CONSOLE_COMMAND(ecrst, command_ec_rst,
+ "[pulse | <BOOLEAN>]",
+ "Assert/deassert EC_RST_L to reset the EC (and AP)");
+
/*
* This function duplicates some of the functionality in chip/g/gpio.c in order
* to configure a given strap pin to be either a low gpio output, a gpio input
diff --git a/board/cr50/build.mk b/board/cr50/build.mk
index d6b40c294e..15e1f1f2a3 100644
--- a/board/cr50/build.mk
+++ b/board/cr50/build.mk
@@ -29,7 +29,7 @@ dirs-y += chip/$(CHIP)/dcrypto
dirs-y += $(BDIR)/tpm2
# Objects that we need to build
-board-y = board.o ap_state.o ec_state.o servo_state.o
+board-y = board.o ap_state.o ec_state.o power_button.o servo_state.o
board-${CONFIG_RDD} += rdd.o
board-${CONFIG_USB_SPI} += usb_spi.o
board-${CONFIG_USB_I2C} += usb_i2c.o
diff --git a/board/cr50/ec_state.c b/board/cr50/ec_state.c
index 4fe8400568..a208cbfd2c 100644
--- a/board/cr50/ec_state.c
+++ b/board/cr50/ec_state.c
@@ -2,8 +2,9 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
- * EC detect state machine.
+ * EC state machine
*/
+#include "ccd_config.h"
#include "common.h"
#include "console.h"
#include "gpio.h"
diff --git a/board/cr50/power_button.c b/board/cr50/power_button.c
new file mode 100644
index 0000000000..bf178e893f
--- /dev/null
+++ b/board/cr50/power_button.c
@@ -0,0 +1,118 @@
+/* Copyright 2017 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 "console.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "physical_presence.h"
+#include "rbox.h"
+#include "registers.h"
+#include "system.h"
+#include "system_chip.h"
+#include "task.h"
+#include "timer.h"
+
+#define CPRINTS(format, args...) cprints(CC_RBOX, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_RBOX, format, ## args)
+
+/**
+ * Enable/disable power button interrupt.
+ *
+ * @param enable Enable (!=0) or disable (==0)
+ */
+static void power_button_enable_interrupt(int enable)
+{
+ if (enable) {
+ /* Clear any leftover power button interrupts */
+ GWRITE_FIELD(RBOX, INT_STATE, INTR_PWRB_IN_FED, 1);
+
+ /* Enable power button interrupt */
+ GWRITE_FIELD(RBOX, INT_ENABLE, INTR_PWRB_IN_FED, 1);
+ task_enable_irq(GC_IRQNUM_RBOX0_INTR_PWRB_IN_FED_INT);
+ } else {
+ GWRITE_FIELD(RBOX, INT_ENABLE, INTR_PWRB_IN_FED, 0);
+ task_disable_irq(GC_IRQNUM_RBOX0_INTR_PWRB_IN_FED_INT);
+ }
+}
+
+static void power_button_handler(void)
+{
+ CPRINTS("power button pressed");
+
+ if (physical_detect_press() != EC_SUCCESS) {
+ /* Not consumed by physical detect */
+#ifdef CONFIG_U2F
+ /* Track last power button press for U2F */
+ power_button_record();
+#endif
+ }
+
+ GWRITE_FIELD(RBOX, INT_STATE, INTR_PWRB_IN_FED, 1);
+}
+DECLARE_IRQ(GC_IRQNUM_RBOX0_INTR_PWRB_IN_FED_INT, power_button_handler, 1);
+
+#ifdef CONFIG_U2F
+static void power_button_init(void)
+{
+ /*
+ * Enable power button interrupts all the time for U2F.
+ *
+ * Ideally U2F should only enable physical presence after the start of
+ * a U2F request (using atomic operations for the PP enable mask so it
+ * plays nicely with CCD config), but that doesn't happen yet.
+ */
+ power_button_enable_interrupt(1);
+}
+DECLARE_HOOK(HOOK_INIT, power_button_init, HOOK_PRIO_DEFAULT);
+#endif /* CONFIG_U2F */
+
+void board_physical_presence_enable(int enable)
+{
+#ifndef CONFIG_U2F
+ /* Enable/disable power button interrupts */
+ power_button_enable_interrupt(enable);
+#endif
+
+ /* Stay awake while we're doing this, just in case. */
+ if (enable)
+ disable_sleep(SLEEP_MASK_PHYSICAL_PRESENCE);
+ else
+ enable_sleep(SLEEP_MASK_PHYSICAL_PRESENCE);
+}
+
+static int command_powerbtn(int argc, char **argv)
+{
+ char *e;
+ int ms = 200;
+
+ if (argc > 1) {
+ if (!strcasecmp("pulse", argv[1])) {
+ if (argc == 3) {
+ ms = strtoi(argv[2], &e, 0);
+ if (*e)
+ return EC_ERROR_PARAM2;
+ }
+
+ ccprintf("Force %dms power button press\n", ms);
+
+ rbox_powerbtn_press();
+ msleep(ms);
+ rbox_powerbtn_release();
+ } else if (!strcasecmp("press", argv[1])) {
+ rbox_powerbtn_press();
+ } else if (!strcasecmp("release", argv[1])) {
+ rbox_powerbtn_release();
+ } else
+ return EC_ERROR_PARAM1;
+ }
+
+ ccprintf("powerbtn: %s\n",
+ rbox_powerbtn_override_is_enabled() ? "forced press" :
+ rbox_powerbtn_is_pressed() ? "pressed\n" : "released\n");
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn,
+ "[pulse [ms] | press | release]",
+ "get/set the state of the power button");
diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c
index 037d5bbc7d..26a3f2b507 100644
--- a/board/cr50/rdd.c
+++ b/board/cr50/rdd.c
@@ -3,7 +3,8 @@
* found in the LICENSE file.
*/
-#include "case_closed_debug.h"
+#include "case_closed_debug.h" /* For ccd_ext_is_enabled() */
+#include "ccd_config.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
@@ -126,6 +127,11 @@ enum ccd_state_flag {
CCD_ENABLE_SPI = (1 << 6),
};
+int console_is_restricted(void)
+{
+ return !ccd_is_cap_enabled(CCD_CAP_GSC_RESTRICTED_CONSOLE);
+}
+
/**
* Return the currently enabled state flags (see enum ccd_state_flag).
*/
@@ -347,8 +353,6 @@ static void ccd_ext_detect(void)
}
DECLARE_HOOK(HOOK_SECOND, ccd_ext_detect, HOOK_PRIO_DEFAULT);
-/*****************************************************************************/
-
static int command_ccd_state(int argc, char **argv)
{
print_ap_state();
@@ -369,107 +373,3 @@ DECLARE_CONSOLE_COMMAND(ccdstate, command_ccd_state,
"",
"Print the case closed debug device state");
-static int command_sys_rst(int argc, char **argv)
-{
- int val;
- char *e;
- int ms = 20;
-
- if (argc > 1) {
- if (!ccd_is_cap_enabled(CCD_CAP_REBOOT_EC_AP))
- return EC_ERROR_ACCESS_DENIED;
-
- if (!strcasecmp("pulse", argv[1])) {
- if (argc == 3) {
- ms = strtoi(argv[2], &e, 0);
- if (*e)
- return EC_ERROR_PARAM2;
- }
- ccprintf("Pulsing AP reset for %dms\n", ms);
- assert_sys_rst();
- msleep(ms);
- deassert_sys_rst();
- } else if (parse_bool(argv[1], &val)) {
- if (val)
- assert_sys_rst();
- else
- deassert_sys_rst();
- } else
- return EC_ERROR_PARAM1;
- }
-
- ccprintf("SYS_RST_L is %s\n", is_sys_rst_asserted() ?
- "asserted" : "deasserted");
-
- return EC_SUCCESS;
-
-}
-DECLARE_SAFE_CONSOLE_COMMAND(sysrst, command_sys_rst,
- "[pulse [time] | <BOOLEAN>]",
- "Assert/deassert SYS_RST_L to reset the AP");
-
-static int command_ec_rst(int argc, char **argv)
-{
- int val;
-
- if (argc > 1) {
- if (!ccd_is_cap_enabled(CCD_CAP_REBOOT_EC_AP))
- return EC_ERROR_ACCESS_DENIED;
-
- if (!strcasecmp("pulse", argv[1])) {
- ccprintf("Pulsing EC reset\n");
- assert_ec_rst();
- usleep(200);
- deassert_ec_rst();
- } else if (parse_bool(argv[1], &val)) {
- if (val)
- assert_ec_rst();
- else
- deassert_ec_rst();
- } else
- return EC_ERROR_PARAM1;
- }
-
- ccprintf("EC_RST_L is %s\n", is_ec_rst_asserted() ?
- "asserted" : "deasserted");
-
- return EC_SUCCESS;
-}
-DECLARE_SAFE_CONSOLE_COMMAND(ecrst, command_ec_rst,
- "[pulse | <BOOLEAN>]",
- "Assert/deassert EC_RST_L to reset the EC (and AP)");
-
-static int command_powerbtn(int argc, char **argv)
-{
- char *e;
- int ms = 200;
-
- if (argc > 1) {
- if (!strcasecmp("pulse", argv[1])) {
- if (argc == 3) {
- ms = strtoi(argv[2], &e, 0);
- if (*e)
- return EC_ERROR_PARAM2;
- }
-
- ccprintf("Force %dms power button press\n", ms);
-
- rbox_powerbtn_press();
- msleep(ms);
- rbox_powerbtn_release();
- } else if (!strcasecmp("press", argv[1])) {
- rbox_powerbtn_press();
- } else if (!strcasecmp("release", argv[1])) {
- rbox_powerbtn_release();
- } else
- return EC_ERROR_PARAM1;
- }
-
- ccprintf("powerbtn: %s\n",
- rbox_powerbtn_override_is_enabled() ? "forced press" :
- rbox_powerbtn_is_pressed() ? "pressed\n" : "released\n");
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn,
- "[pulse [ms] | press | release]",
- "get/set the state of the power button");
diff --git a/board/cr50/usb_i2c.c b/board/cr50/usb_i2c.c
index 6536e00ca7..1aa18012c3 100644
--- a/board/cr50/usb_i2c.c
+++ b/board/cr50/usb_i2c.c
@@ -4,6 +4,7 @@
*/
#include "case_closed_debug.h"
+#include "ccd_config.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
diff --git a/board/cr50/usb_spi.c b/board/cr50/usb_spi.c
index 1fa67fbdf5..31b900109f 100644
--- a/board/cr50/usb_spi.c
+++ b/board/cr50/usb_spi.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "case_closed_debug.h"
+#include "ccd_config.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
diff --git a/board/cr50/wp.c b/board/cr50/wp.c
index 74a44f8ee0..0edb681fcd 100644
--- a/board/cr50/wp.c
+++ b/board/cr50/wp.c
@@ -3,22 +3,16 @@
* found in the LICENSE file.
*/
-#include "common.h"
-#include "case_closed_debug.h"
+#include "ccd_config.h"
#include "console.h"
#include "crc8.h"
#include "extension.h"
#include "gpio.h"
#include "hooks.h"
-#include "nvmem.h"
-#include "nvmem_vars.h"
-#include "physical_presence.h"
#include "registers.h"
#include "scratch_reg1.h"
#include "system.h"
#include "system_chip.h"
-#include "task.h"
-#include "timer.h"
#include "tpm_nvmem_read.h"
#include "tpm_registers.h"
#include "util.h"
@@ -321,82 +315,6 @@ int board_fwmp_allows_unlock(void)
}
/****************************************************************************/
-/* Console control */
-
-int console_is_restricted(void)
-{
- return !ccd_is_cap_enabled(CCD_CAP_GSC_RESTRICTED_CONSOLE);
-}
-
-/****************************************************************************/
-/* Stuff for the unlock sequence */
-
-/**
- * Enable/disable power button interrupt.
- *
- * @param enable Enable (!=0) or disable (==0)
- */
-static void power_button_enable_interrupt(int enable)
-{
- if (enable) {
- /* Clear any leftover power button interrupts */
- GWRITE_FIELD(RBOX, INT_STATE, INTR_PWRB_IN_FED, 1);
-
- /* Enable power button interrupt */
- GWRITE_FIELD(RBOX, INT_ENABLE, INTR_PWRB_IN_FED, 1);
- task_enable_irq(GC_IRQNUM_RBOX0_INTR_PWRB_IN_FED_INT);
- } else {
- GWRITE_FIELD(RBOX, INT_ENABLE, INTR_PWRB_IN_FED, 0);
- task_disable_irq(GC_IRQNUM_RBOX0_INTR_PWRB_IN_FED_INT);
- }
-}
-
-static void power_button_handler(void)
-{
- CPRINTS("power button pressed");
-
- if (physical_detect_press() != EC_SUCCESS) {
- /* Not consumed by physical detect */
-#ifdef CONFIG_U2F
- /* Track last power button press for U2F */
- power_button_record();
-#endif
- }
-
- GWRITE_FIELD(RBOX, INT_STATE, INTR_PWRB_IN_FED, 1);
-}
-DECLARE_IRQ(GC_IRQNUM_RBOX0_INTR_PWRB_IN_FED_INT, power_button_handler, 1);
-
-#ifdef CONFIG_U2F
-static void power_button_init(void)
-{
- /*
- * Enable power button interrupts all the time for U2F.
- *
- * Ideally U2F should only enable physical presence after the start of
- * a U2F request (using atomic operations for the PP enable mask so it
- * plays nicely with CCD config), but that doesn't happen yet.
- */
- power_button_enable_interrupt(1);
-}
-DECLARE_HOOK(HOOK_INIT, power_button_init, HOOK_PRIO_DEFAULT);
-#endif /* CONFIG_U2F */
-
-void board_physical_presence_enable(int enable)
-{
-#ifndef CONFIG_U2F
- /* Enable/disable power button interrupts */
- power_button_enable_interrupt(enable);
-#endif
-
- /* Stay awake while we're doing this, just in case. */
- if (enable)
- disable_sleep(SLEEP_MASK_PHYSICAL_PRESENCE);
- else
- enable_sleep(SLEEP_MASK_PHYSICAL_PRESENCE);
-}
-
-/****************************************************************************/
/* TPM vendor-specific commands */
static enum vendor_cmd_rc vc_lock(enum vendor_cmd_cc code,