diff options
author | Peter Marheine <pmarheine@chromium.org> | 2021-11-30 13:41:01 +1100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-03 00:00:44 +0000 |
commit | a1bfe80a94eb3386057d80e5d765db8cea15d0fd (patch) | |
tree | e699bd2e8932f251ce0cc03280314bf0717e7b2b | |
parent | 18f6c4d3b2a56635ce880788047083115637885c (diff) | |
download | chrome-ec-a1bfe80a94eb3386057d80e5d765db8cea15d0fd.tar.gz |
zephyr: use a chosen DT node to find ADC devices
This change adds a cros-ec,adc chosen node to the device tree, to be used
by the ADC shim to locate the device to which all analog channels are
bound (rather than assuming it is named adc0). It also makes the
configuration happen at compile-time, saving some runtime indirection and
failing faster (at build rather than runtime) if misconfigured.
BUG=b:205615358
TEST=zmake testall
BRANCH=none
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Change-Id: I71bdf7329b76eb4cda06478f27bb76418e6b0b78
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3308335
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/include/cros/ite/it8xxx2.dtsi | 1 | ||||
-rw-r--r-- | zephyr/include/cros/nuvoton/npcx.dtsi | 1 | ||||
-rw-r--r-- | zephyr/shim/src/adc.c | 7 | ||||
-rw-r--r-- | zephyr/test/drivers/overlay.dts | 4 |
4 files changed, 8 insertions, 5 deletions
diff --git a/zephyr/include/cros/ite/it8xxx2.dtsi b/zephyr/include/cros/ite/it8xxx2.dtsi index 96f5875e78..df6207117a 100644 --- a/zephyr/include/cros/ite/it8xxx2.dtsi +++ b/zephyr/include/cros/ite/it8xxx2.dtsi @@ -8,6 +8,7 @@ / { chosen { cros-ec,flash = &fiu0; + cros-ec,adc = &adc0; }; named-bbram-regions { diff --git a/zephyr/include/cros/nuvoton/npcx.dtsi b/zephyr/include/cros/nuvoton/npcx.dtsi index 705935d25e..1a59a1cb8d 100644 --- a/zephyr/include/cros/nuvoton/npcx.dtsi +++ b/zephyr/include/cros/nuvoton/npcx.dtsi @@ -12,6 +12,7 @@ / { chosen { cros-ec,flash = &fiu0; + cros-ec,adc = &adc0; }; named-bbram-regions { diff --git a/zephyr/shim/src/adc.c b/zephyr/shim/src/adc.c index 4f66774466..6f7291db9c 100644 --- a/zephyr/shim/src/adc.c +++ b/zephyr/shim/src/adc.c @@ -10,8 +10,7 @@ LOG_MODULE_REGISTER(shim_adc, LOG_LEVEL_ERR); -#define ADC_NODE DT_NODELABEL(adc0) -const struct device *adc_dev; +#define adc_dev DEVICE_DT_GET(DT_CHOSEN(cros_ec_adc)) #define HAS_NAMED_ADC_CHANNELS DT_NODE_EXISTS(DT_INST(0, named_adc_channels)) @@ -43,11 +42,9 @@ const struct adc_t adc_channels[] = { DT_FOREACH_CHILD( static int init_device_bindings(const struct device *device) { ARG_UNUSED(device); - adc_dev = DEVICE_DT_GET(ADC_NODE); if (!device_is_ready(adc_dev)) { - LOG_ERR("Error: device %s is not ready", adc_dev->name); - return -1; + k_oops(); } #if HAS_NAMED_ADC_CHANNELS diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts index 8025cd5c6f..3d56485094 100644 --- a/zephyr/test/drivers/overlay.dts +++ b/zephyr/test/drivers/overlay.dts @@ -8,6 +8,10 @@ #include <freq.h> / { + chosen { + cros-ec,adc = &adc0; + }; + aliases { bmi260-int = &ms_bmi260_accel; bmi160-int = &ms_bmi160_accel; |