diff options
author | Caveh Jalali <caveh@chromium.org> | 2021-08-23 18:33:49 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-27 01:27:45 +0000 |
commit | 1943b1cb01ac1ee67cd8cfead61a2f1acdcdff08 (patch) | |
tree | 42d659c13d912a3d3e766d5c527e9aca41d25900 | |
parent | 61eb74b2ebe6c246d0d16caac9472ad880bf71fe (diff) | |
download | chrome-ec-1943b1cb01ac1ee67cd8cfead61a2f1acdcdff08.tar.gz |
adc: Allow runtime config of adc_channels
This adds the CONFIG_ADC_CHANNELS_RUNTIME_CONFIG config option to allow
the adc_channels array to be tweaked at runtime.
BRANCH=none
BUG=b:183452273,b:181271666
TEST=buildall passes
Change-Id: I1241012b6e36c19baa7fe80853a6c6de4affeefa
Signed-off-by: Caveh Jalali <caveh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3116990
Reviewed-by: Boris Mittelberg <bmbm@google.com>
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | include/adc.h | 4 | ||||
-rw-r--r-- | include/config.h | 5 | ||||
-rw-r--r-- | zephyr/Kconfig.adc | 14 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 5 | ||||
-rw-r--r-- | zephyr/shim/src/adc.c | 5 |
5 files changed, 33 insertions, 0 deletions
diff --git a/include/adc.h b/include/adc.h index b52798419a..8342bc1fb6 100644 --- a/include/adc.h +++ b/include/adc.h @@ -21,7 +21,11 @@ * Boards must provide this list of ADC channel definitions. This must match * the enum adc_channel list provided by the board. */ +#ifndef CONFIG_ADC_CHANNELS_RUNTIME_CONFIG extern const struct adc_t adc_channels[]; +#else +extern struct adc_t adc_channels[]; +#endif /* * Boards which use the ADC interface must provide enum adc_channel in the diff --git a/include/config.h b/include/config.h index 057ae9b8b7..807fd52f17 100644 --- a/include/config.h +++ b/include/config.h @@ -299,6 +299,11 @@ #undef CONFIG_ADC /* + * Allow runtime configuration of the adc_channels[] array + */ +#undef CONFIG_ADC_CHANNELS_RUNTIME_CONFIG + +/* * ADC sample time selection. The value is chip-dependent. * TODO: Replace this with CONFIG_ADC_PROFILE entries. */ diff --git a/zephyr/Kconfig.adc b/zephyr/Kconfig.adc index 68680a8706..a1e3bd63eb 100644 --- a/zephyr/Kconfig.adc +++ b/zephyr/Kconfig.adc @@ -45,4 +45,18 @@ config PLATFORM_EC_ADC_OVERSAMPLING help in providing more stable readings. The supported oversampling values depend on specific hardware. +config PLATFORM_EC_ADC_CHANNELS_RUNTIME_CONFIG + bool "ADC runtime config" + default n + help + Allows the configuration of the ADC channels to be set up at + runtime. This makes the adc_channels[] array writable, + i.e. not const. It should be declared as such in the board + config. + + This is useful when the board has runtime information that + changes the configuration, such as board revision information. + Without this, multiple EC images would need to be installed + depending on the board. + endif # PLATFORM_EC_ADC diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index ec4db3f146..d8d5880133 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -386,6 +386,11 @@ #define CONFIG_ADC #endif +#undef CONFIG_ADC_CHANNELS_RUNTIME_CONFIG +#ifdef CONFIG_PLATFORM_EC_ADC_CHANNELS_RUNTIME_CONFIG +#define CONFIG_ADC_CHANNELS_RUNTIME_CONFIG +#endif + #undef CONFIG_CMD_ADC #ifdef CONFIG_PLATFORM_EC_ADC_CMD #define CONFIG_CMD_ADC diff --git a/zephyr/shim/src/adc.c b/zephyr/shim/src/adc.c index 93a99c3973..c8b90b0211 100644 --- a/zephyr/shim/src/adc.c +++ b/zephyr/shim/src/adc.c @@ -31,8 +31,13 @@ const struct device *adc_dev; .differential = DT_PROP(node_id, differential), \ }, \ }, +#ifdef CONFIG_ADC_CHANNELS_RUNTIME_CONFIG +struct adc_t adc_channels[] = { DT_FOREACH_CHILD( + DT_INST(0, named_adc_channels), ADC_CHANNEL_COMMA) }; +#else const struct adc_t adc_channels[] = { DT_FOREACH_CHILD( DT_INST(0, named_adc_channels), ADC_CHANNEL_COMMA) }; +#endif #endif /* named_adc_channels */ static int init_device_bindings(const struct device *device) |