summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-04-06 13:49:14 -0600
committerCommit Bot <commit-bot@chromium.org>2021-04-07 07:13:40 +0000
commit7fba0e12ffa1d48c9f9f6da9d18125adc9aa75b4 (patch)
treee3835222dd51a8ed68bd8dca5e43c8e3c9273351
parent2cbfce23cb57f4d625fa796109116420c352c541 (diff)
downloadchrome-ec-7fba0e12ffa1d48c9f9f6da9d18125adc9aa75b4.tar.gz
zephyr: fix initialization priority to be forward compatible
In upstream Zephyr the initialization of the GPIO module (and most other drivers) was changed. This breaks our gpio and in return also flash initialization. Update both gpio and flash initialization to work with Kconfig and add a compile time validation to be able to catch this sooner in the future. BRANCH=none BUG=none TEST=zmake testall Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I44e5867dbf4cb3d5934bf0d0807dcc1aa6c778e1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2808335 Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--zephyr/Kconfig1
-rw-r--r--zephyr/Kconfig.init_priority17
-rw-r--r--zephyr/shim/src/flash.c6
-rw-r--r--zephyr/shim/src/gpio.c5
4 files changed, 27 insertions, 2 deletions
diff --git a/zephyr/Kconfig b/zephyr/Kconfig
index f0fb5c4115..b0937203ab 100644
--- a/zephyr/Kconfig
+++ b/zephyr/Kconfig
@@ -41,6 +41,7 @@ rsource "Kconfig.debug_assert"
rsource "Kconfig.espi"
rsource "Kconfig.flash"
rsource "Kconfig.header"
+rsource "Kconfig.init_priority"
rsource "Kconfig.keyboard"
rsource "Kconfig.led"
rsource "Kconfig.panic"
diff --git a/zephyr/Kconfig.init_priority b/zephyr/Kconfig.init_priority
new file mode 100644
index 0000000000..b8b3ab7195
--- /dev/null
+++ b/zephyr/Kconfig.init_priority
@@ -0,0 +1,17 @@
+# 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.
+
+config PLATFORM_EC_FLASH_INIT_PRIORITY
+ int "Init priority of the flash module"
+ default 52
+ help
+ The initialization priority of the flash module. This should always be
+ greater than PLATFORM_EC_GPIO_INIT_PRIORITY.
+
+config PLATFORM_EC_GPIO_INIT_PRIORITY
+ int "Init priority of the GPIO module"
+ default 51
+ help
+ The initialization priority of the GPIO module. This should always happen
+ after the gpio drivers are initialized.
diff --git a/zephyr/shim/src/flash.c b/zephyr/shim/src/flash.c
index baac38af92..064067a2bc 100644
--- a/zephyr/shim/src/flash.c
+++ b/zephyr/shim/src/flash.c
@@ -418,4 +418,8 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags)
* The priority flash_dev_init should be lower than GPIO initialization because
* it calls gpio_get_level function.
*/
-SYS_INIT(flash_dev_init, PRE_KERNEL_1, 51);
+#if CONFIG_PLATFORM_EC_FLASH_INIT_PRIORITY <= \
+ CONFIG_PLATFORM_EC_GPIO_INIT_PRIORITY
+#error "Flash must be initialized after GPIOs"
+#endif
+SYS_INIT(flash_dev_init, POST_KERNEL, CONFIG_PLATFORM_EC_FLASH_INIT_PRIORITY);
diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c
index fc9a77c1bf..020cb54d31 100644
--- a/zephyr/shim/src/gpio.c
+++ b/zephyr/shim/src/gpio.c
@@ -258,7 +258,10 @@ static int init_gpios(const struct device *unused)
return 0;
}
-SYS_INIT(init_gpios, PRE_KERNEL_1, 50);
+#if CONFIG_PLATFORM_EC_GPIO_INIT_PRIORITY <= CONFIG_KERNEL_INIT_PRIORITY_DEFAULT
+#error "GPIOs must initialize after the kernel default initialization"
+#endif
+SYS_INIT(init_gpios, POST_KERNEL, CONFIG_PLATFORM_EC_GPIO_INIT_PRIORITY);
int gpio_enable_interrupt(enum gpio_signal signal)
{