From 77edc2c8526faadb290f05b7c60cfb747ba3f6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Mon, 21 Feb 2022 16:08:54 +0100 Subject: [PATCH] dts: Include ADC DT binding headers from nRF SoC dtsi files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add inclusions of header files with devicetree related ADC definitions to the nRF SoC dtsi files so that those definitions can be used also for nRF SoC based boards. Provide definitions of nRF ADC and SAADC analog inputs suitable for use in devicetree. Signed-off-by: Andrzej Głąbek --- drivers/adc/adc_nrfx_adc.c | 12 +++++++++ drivers/adc/adc_nrfx_saadc.c | 16 ++++++++++++ dts/arm/nordic/nrf_common.dtsi | 4 ++- include/zephyr/dt-bindings/adc/nrf-adc.h | 32 ++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 include/zephyr/dt-bindings/adc/nrf-adc.h diff --git a/drivers/adc/adc_nrfx_adc.c b/drivers/adc/adc_nrfx_adc.c index 9731c0f88ff..794405478b2 100644 --- a/drivers/adc/adc_nrfx_adc.c +++ b/drivers/adc/adc_nrfx_adc.c @@ -7,6 +7,7 @@ #define ADC_CONTEXT_USES_KERNEL_TIMER #include "adc_context.h" #include +#include #define LOG_LEVEL CONFIG_ADC_LOG_LEVEL #include @@ -14,6 +15,17 @@ LOG_MODULE_REGISTER(adc_nrfx_adc); #define DT_DRV_COMPAT nordic_nrf_adc +/* Ensure that definitions in nrf-adc.h match MDK. */ +BUILD_ASSERT((NRF_ADC_AIN0 == NRF_ADC_CONFIG_INPUT_0) && + (NRF_ADC_AIN1 == NRF_ADC_CONFIG_INPUT_1) && + (NRF_ADC_AIN2 == NRF_ADC_CONFIG_INPUT_2) && + (NRF_ADC_AIN3 == NRF_ADC_CONFIG_INPUT_3) && + (NRF_ADC_AIN4 == NRF_ADC_CONFIG_INPUT_4) && + (NRF_ADC_AIN5 == NRF_ADC_CONFIG_INPUT_5) && + (NRF_ADC_AIN6 == NRF_ADC_CONFIG_INPUT_6) && + (NRF_ADC_AIN7 == NRF_ADC_CONFIG_INPUT_7), + "Definitions from nrf-adc.h do not match those from nrf_adc.h"); + struct driver_data { struct adc_context ctx; diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index bc4ecc9dde0..74646f2c809 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -7,6 +7,7 @@ #define ADC_CONTEXT_USES_KERNEL_TIMER #include "adc_context.h" #include +#include #define LOG_LEVEL CONFIG_ADC_LOG_LEVEL #include @@ -14,6 +15,21 @@ LOG_MODULE_REGISTER(adc_nrfx_saadc); #define DT_DRV_COMPAT nordic_nrf_saadc +BUILD_ASSERT((NRF_SAADC_AIN0 == NRF_SAADC_INPUT_AIN0) && + (NRF_SAADC_AIN1 == NRF_SAADC_INPUT_AIN1) && + (NRF_SAADC_AIN2 == NRF_SAADC_INPUT_AIN2) && + (NRF_SAADC_AIN3 == NRF_SAADC_INPUT_AIN3) && + (NRF_SAADC_AIN4 == NRF_SAADC_INPUT_AIN4) && + (NRF_SAADC_AIN5 == NRF_SAADC_INPUT_AIN5) && + (NRF_SAADC_AIN6 == NRF_SAADC_INPUT_AIN6) && + (NRF_SAADC_AIN7 == NRF_SAADC_INPUT_AIN7) && + (NRF_SAADC_AIN7 == NRF_SAADC_INPUT_AIN7) && +#if defined(SAADC_CH_PSELP_PSELP_VDDHDIV5) + (NRF_SAADC_VDDHDIV5 == NRF_SAADC_INPUT_VDDHDIV5) && +#endif + (NRF_SAADC_VDD == NRF_SAADC_INPUT_VDD), + "Definitions from nrf-adc.h do not match those from nrf_saadc.h"); + struct driver_data { struct adc_context ctx; diff --git a/dts/arm/nordic/nrf_common.dtsi b/dts/arm/nordic/nrf_common.dtsi index 76c2a227423..6abd7e2748b 100644 --- a/dts/arm/nordic/nrf_common.dtsi +++ b/dts/arm/nordic/nrf_common.dtsi @@ -4,8 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include +#include #include #include diff --git a/include/zephyr/dt-bindings/adc/nrf-adc.h b/include/zephyr/dt-bindings/adc/nrf-adc.h new file mode 100644 index 00000000000..1d875b8eb35 --- /dev/null +++ b/include/zephyr/dt-bindings/adc/nrf-adc.h @@ -0,0 +1,32 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2022 Nordic Semiconductor ASA + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_ADC_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_ADC_H_ + +#include + +#define NRF_ADC_AIN0 BIT(0) +#define NRF_ADC_AIN1 BIT(1) +#define NRF_ADC_AIN2 BIT(2) +#define NRF_ADC_AIN3 BIT(3) +#define NRF_ADC_AIN4 BIT(4) +#define NRF_ADC_AIN5 BIT(5) +#define NRF_ADC_AIN6 BIT(6) +#define NRF_ADC_AIN7 BIT(7) + +#define NRF_SAADC_AIN0 1 +#define NRF_SAADC_AIN1 2 +#define NRF_SAADC_AIN2 3 +#define NRF_SAADC_AIN3 4 +#define NRF_SAADC_AIN4 5 +#define NRF_SAADC_AIN5 6 +#define NRF_SAADC_AIN6 7 +#define NRF_SAADC_AIN7 8 +#define NRF_SAADC_VDD 9 +#define NRF_SAADC_VDDHDIV5 13 + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_ADC_H_ */