From 0d59aa1ab478103a141d417f1b90b6e344ed1ab4 Mon Sep 17 00:00:00 2001 From: Mulin Chao Date: Tue, 26 Sep 2023 23:13:39 -0700 Subject: [PATCH] sensor: adc_cmp: npcx: use BUILD_ASSERT to check `thr-sel` value This CL uses BUILD_ASSERT macro to check whether `thr-sel` is out of range instead of using NPCX series definitions. Signed-off-by: Mulin Chao --- .../nuvoton_adc_cmp_npcx/adc_cmp_npcx.c | 35 ++++++++++--------- include/zephyr/drivers/sensor/adc_cmp_npcx.h | 2 -- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/sensor/nuvoton_adc_cmp_npcx/adc_cmp_npcx.c b/drivers/sensor/nuvoton_adc_cmp_npcx/adc_cmp_npcx.c index ff1871e8a40..cba37069ce9 100644 --- a/drivers/sensor/nuvoton_adc_cmp_npcx/adc_cmp_npcx.c +++ b/drivers/sensor/nuvoton_adc_cmp_npcx/adc_cmp_npcx.c @@ -251,20 +251,23 @@ static const struct sensor_driver_api adc_cmp_npcx_api = { .channel_get = adc_cmp_npcx_channel_get, }; -#define NPCX_ADC_CMP_INIT(inst) \ - static struct adc_cmp_npcx_data adc_cmp_npcx_data_##inst; \ - static const struct adc_cmp_npcx_config adc_cmp_npcx_config_##inst = {\ - .adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \ - .chnsel = DT_INST_IO_CHANNELS_INPUT(inst), \ - .th_sel = DT_INST_STRING_TOKEN_OR(inst, thr_sel, inst), \ - .thr_mv = DT_INST_PROP_OR(inst, threshold_mv, \ - ADC_CMP_NPCX_UNDEFINED), \ - .comparison = DT_INST_STRING_TOKEN_OR(inst, \ - comparison, ADC_CMP_NPCX_UNDEFINED) \ - }; \ - SENSOR_DEVICE_DT_INST_DEFINE(inst, adc_cmp_npcx_init, NULL, \ - &adc_cmp_npcx_data_##inst, \ - &adc_cmp_npcx_config_##inst, POST_KERNEL, \ - CONFIG_SENSOR_INIT_PRIORITY, \ - &adc_cmp_npcx_api); +#define NPCX_ADC_CMP_INIT(inst) \ + static struct adc_cmp_npcx_data adc_cmp_npcx_data_##inst; \ + static const struct adc_cmp_npcx_config adc_cmp_npcx_config_##inst = { \ + .adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \ + .chnsel = DT_INST_IO_CHANNELS_INPUT(inst), \ + .th_sel = DT_INST_STRING_TOKEN_OR(inst, thr_sel, inst), \ + .thr_mv = DT_INST_PROP_OR(inst, threshold_mv, \ + ADC_CMP_NPCX_UNDEFINED), \ + .comparison = DT_INST_STRING_TOKEN_OR(inst, \ + comparison, ADC_CMP_NPCX_UNDEFINED) \ + }; \ + SENSOR_DEVICE_DT_INST_DEFINE(inst, adc_cmp_npcx_init, NULL, \ + &adc_cmp_npcx_data_##inst, \ + &adc_cmp_npcx_config_##inst, POST_KERNEL, \ + CONFIG_SENSOR_INIT_PRIORITY, \ + &adc_cmp_npcx_api); \ + BUILD_ASSERT(DT_INST_STRING_TOKEN_OR(inst, thr_sel, inst) < \ + DT_PROP(DT_INST_IO_CHANNELS_CTLR(inst), threshold_count), \ + "Exceed the number of threshold detectors adc supports"); DT_INST_FOREACH_STATUS_OKAY(NPCX_ADC_CMP_INIT) diff --git a/include/zephyr/drivers/sensor/adc_cmp_npcx.h b/include/zephyr/drivers/sensor/adc_cmp_npcx.h index 5e986dd1be7..0fa7f14ca1f 100644 --- a/include/zephyr/drivers/sensor/adc_cmp_npcx.h +++ b/include/zephyr/drivers/sensor/adc_cmp_npcx.h @@ -17,11 +17,9 @@ enum npcx_adc_cmp_thrctl { ADC_CMP_NPCX_THRCTL1, ADC_CMP_NPCX_THRCTL2, ADC_CMP_NPCX_THRCTL3, -#if !defined(CONFIG_SOC_SERIES_NPCX7) ADC_CMP_NPCX_THRCTL4, ADC_CMP_NPCX_THRCTL5, ADC_CMP_NPCX_THRCTL6, -#endif ADC_CMP_NPCX_THRCTL_COUNT, };