summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2017-08-23 13:18:44 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-08-24 11:29:02 -0700
commit1029239bc18c1a8e1bff5f7aad040cdfe421dbd2 (patch)
tree95a1275901cc5e95f7d70e6a0646c87695b3e716
parentc859c057e16c13d637326e7fae333e1d1eb80d7a (diff)
downloadchrome-ec-1029239bc18c1a8e1bff5f7aad040cdfe421dbd2.tar.gz
g: Move chip pre-init to chip_pre_init()
Currently, chip/g uses jtag_pre_init() to do some chip pre-initialization that isn't actually related to JTAG. This has been harmless, but it's currently the only chip which actually does "JTAG" pre-init, and we'd like to get rid of that. So, move that functionality to a new optional chip_pre_init() function. BUG=chromium:747629 BRANCH=cr50 TEST=make buildall boot cr50 make all dis; confirm chip_pre_init() is called early in <main> Change-Id: I3cae0747ab0c3cc974fce9f108947207b38e035f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/629876 Reviewed-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--chip/g/build.mk2
-rw-r--r--chip/g/config_chip.h3
-rw-r--r--chip/g/jtag.c22
-rw-r--r--chip/g/pre_init.c28
-rw-r--r--common/main.c4
-rw-r--r--include/board_config.h13
-rw-r--r--include/config.h8
7 files changed, 57 insertions, 23 deletions
diff --git a/chip/g/build.mk b/chip/g/build.mk
index fa850b2d23..d3a228cdd3 100644
--- a/chip/g/build.mk
+++ b/chip/g/build.mk
@@ -20,7 +20,7 @@ CPPFLAGS += -I$(CRYPTOCLIB)/include
endif
# Required chip modules
-chip-y = clock.o gpio.o hwtimer.o jtag.o system.o
+chip-y = clock.o gpio.o hwtimer.o jtag.o pre_init.o system.o
chip-$(CONFIG_BOARD_ID_SUPPORT) += board_id.o
ifeq ($(CONFIG_POLLING_UART),y)
chip-y += polling_uart.o
diff --git a/chip/g/config_chip.h b/chip/g/config_chip.h
index bfcd912914..0e6e319007 100644
--- a/chip/g/config_chip.h
+++ b/chip/g/config_chip.h
@@ -67,6 +67,9 @@
/* We'll have some special commands of our own */
#define CONFIG_EXTENSION_COMMAND 0xbaccd00a
+/* Chip needs to do custom pre-init */
+#define CONFIG_CHIP_PRE_INIT
+
/*
* The flash memory is implemented in two halves. The SoC bootrom will look for
* the first-stage bootloader at the beginning of each of the two halves and
diff --git a/chip/g/jtag.c b/chip/g/jtag.c
index 59a53100e3..6d700d9680 100644
--- a/chip/g/jtag.c
+++ b/chip/g/jtag.c
@@ -3,28 +3,6 @@
* found in the LICENSE file.
*/
-#include "registers.h"
-
void jtag_pre_init(void)
{
- /*
- * We don't need to do anything for JTAG, but if we're resuming from
- * deep sleep we need to undo some stuff as soon as possible and this
- * is the first init function that's called.
- *
- * It doesn't hurt anything if this setup is not needed, but we don't
- * investigate the reset cause until much later (and doing so is
- * destructive), so we'll just do the post-deep-sleep setup every time.
- */
-
- /* Disable the deep sleep triggers */
- GR_PMU_LOW_POWER_DIS = 0;
- GR_PMU_EXITPD_MASK = 0;
-
- /* Unfreeze the USB module */
- GWRITE_FIELD(USB, PCGCCTL, STOPPCLK, 0);
- GWRITE_FIELD(USB, PCGCCTL, RSTPDWNMODULE, 0);
- GWRITE_FIELD(USB, PCGCCTL, PWRCLMP, 0);
-
-
}
diff --git a/chip/g/pre_init.c b/chip/g/pre_init.c
new file mode 100644
index 0000000000..0fe7a7dbe8
--- /dev/null
+++ b/chip/g/pre_init.c
@@ -0,0 +1,28 @@
+/* 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 "board_config.h"
+#include "registers.h"
+
+void chip_pre_init(void)
+{
+ /*
+ * If we're resuming from deep sleep we need to undo some stuff as soon
+ * as possible and this is the first init function that's called.
+ *
+ * It doesn't hurt anything if this setup is not needed, but we don't
+ * investigate the reset cause until much later (and doing so is
+ * destructive), so we'll just do the post-deep-sleep setup every time.
+ */
+
+ /* Disable the deep sleep triggers */
+ GR_PMU_LOW_POWER_DIS = 0;
+ GR_PMU_EXITPD_MASK = 0;
+
+ /* Unfreeze the USB module */
+ GWRITE_FIELD(USB, PCGCCTL, STOPPCLK, 0);
+ GWRITE_FIELD(USB, PCGCCTL, RSTPDWNMODULE, 0);
+ GWRITE_FIELD(USB, PCGCCTL, PWRCLMP, 0);
+}
diff --git a/common/main.c b/common/main.c
index d1ea65d0d1..b2eb2eebe4 100644
--- a/common/main.c
+++ b/common/main.c
@@ -56,6 +56,10 @@ test_mockable __keep int main(void)
board_config_pre_init();
#endif
+#ifdef CONFIG_CHIP_PRE_INIT
+ chip_pre_init();
+#endif
+
#ifdef CONFIG_MPU
mpu_pre_init();
#endif
diff --git a/include/board_config.h b/include/board_config.h
index 6742573bc2..f408db8cd6 100644
--- a/include/board_config.h
+++ b/include/board_config.h
@@ -1,6 +1,8 @@
/* Copyright (c) 2013 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.
+ *
+ * Extra hooks for board and chip initialization/configuration
*/
#ifndef __CROS_EC_BOARD_CONFIG_H
@@ -48,4 +50,15 @@ void board_config_post_gpio_init(void);
void board_before_rsmrst(int rsmrst);
#endif
+/**
+ * Configure chip early in main(), just after board_config_pre_init().
+ *
+ * Most chip configuration is not particularly timing critical and can be done
+ * in other chip driver initialization such as system_pre_init() or HOOK_INIT
+ * handlers. Chip pre-init should be reserved for small amounts of critical
+ * functionality that can't wait that long. Think very hard before putting
+ * code here.
+ */
+void chip_pre_init(void);
+
#endif /* __CROS_EC_BOARD_CONFIG_H */
diff --git a/include/config.h b/include/config.h
index 200dce82de..ff63e58213 100644
--- a/include/config.h
+++ b/include/config.h
@@ -617,6 +617,14 @@
#undef CONFIG_TRICKLE_CHARGING
/*****************************************************************************/
+
+/*
+ * Chip needs to do pre-init very early in main(), and provides chip_pre_init()
+ * to do so.
+ */
+#undef CONFIG_CHIP_PRE_INIT
+
+/*****************************************************************************/
/* Chipset config */
/* AP chipset support; pick at most one */