From 611acbf5ebde696554815672cb61aefc9b6b394d Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 22 Jul 2025 09:59:36 +0200 Subject: [PATCH 1/5] [nrf fromlist] dt-bindings: adc: nrf-saadc: Remove platform dependencies Remove platform dependencies to make dt-bindings more generic. Upstream PR #: 93497 Signed-off-by: Jakub Zymelka --- .../dt-bindings/adc/nrf-saadc-haltium.h | 19 --------- .../zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h | 15 ------- include/zephyr/dt-bindings/adc/nrf-saadc-v2.h | 14 ------- include/zephyr/dt-bindings/adc/nrf-saadc-v3.h | 14 ------- include/zephyr/dt-bindings/adc/nrf-saadc.h | 41 +++++++++++++++---- 5 files changed, 32 insertions(+), 71 deletions(-) delete mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-haltium.h delete mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h delete mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-v2.h delete mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-v3.h diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-haltium.h b/include/zephyr/dt-bindings/adc/nrf-saadc-haltium.h deleted file mode 100644 index e0552297522..00000000000 --- a/include/zephyr/dt-bindings/adc/nrf-saadc-haltium.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2025 Nordic Semiconductor ASA - */ - -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_HALTIUM_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_HALTIUM_H_ - -#include - -#define NRF_SAADC_AIN8 9 -#define NRF_SAADC_AIN9 10 -#define NRF_SAADC_AIN10 11 -#define NRF_SAADC_AIN11 12 -#define NRF_SAADC_AIN12 13 -#define NRF_SAADC_AIN13 14 - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_HALTIUM_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h b/include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h deleted file mode 100644 index 19da4ff6020..00000000000 --- a/include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2024 Nordic Semiconductor ASA - */ - -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ - -#include - -#define NRF_SAADC_AVDD 10 -#define NRF_SAADC_DVDD 11 - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-v2.h b/include/zephyr/dt-bindings/adc/nrf-saadc-v2.h deleted file mode 100644 index f5f72bec829..00000000000 --- a/include/zephyr/dt-bindings/adc/nrf-saadc-v2.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2024 Nordic Semiconductor ASA - */ - -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ - -#include - -#define NRF_SAADC_VDD 9 - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-v3.h b/include/zephyr/dt-bindings/adc/nrf-saadc-v3.h deleted file mode 100644 index c51bab1a91e..00000000000 --- a/include/zephyr/dt-bindings/adc/nrf-saadc-v3.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2024 Nordic Semiconductor ASA - */ - -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ - -#include - -#define NRF_SAADC_VDDHDIV5 13 - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc.h b/include/zephyr/dt-bindings/adc/nrf-saadc.h index e5a86150cd4..21f9cf9fb2f 100644 --- a/include/zephyr/dt-bindings/adc/nrf-saadc.h +++ b/include/zephyr/dt-bindings/adc/nrf-saadc.h @@ -7,6 +7,21 @@ #ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ #define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ +#define NRF_SAADC_AIN0 0 +#define NRF_SAADC_AIN1 1 +#define NRF_SAADC_AIN2 2 +#define NRF_SAADC_AIN3 3 +#define NRF_SAADC_AIN4 4 +#define NRF_SAADC_AIN5 5 +#define NRF_SAADC_AIN6 6 +#define NRF_SAADC_AIN7 7 +#define NRF_SAADC_AIN8 8 +#define NRF_SAADC_AIN9 9 +#define NRF_SAADC_AIN10 10 +#define NRF_SAADC_AIN11 11 +#define NRF_SAADC_AIN12 12 +#define NRF_SAADC_AIN13 13 + /** * @brief Short ADC negative input to ground * @@ -30,14 +45,22 @@ * zephyr,input-positive = ; * @endcode */ -#define NRF_SAADC_GND 0 -#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_GND (NRF_SAADC_AIN_VDD_SHIM_OFFSET - 1) + +#define NRF_SAADC_AIN_VDD_SHIM_OFFSET 128 +#define NRF_SAADC_VDD (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 0) +#define NRF_SAADC_VDDDIV2 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 1) +#define NRF_SAADC_AVDD (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 2) +#define NRF_SAADC_DVDD (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 3) +#define NRF_SAADC_VDDHDIV5 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 4) +#define NRF_SAADC_VDDL (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 5) +#define NRF_SAADC_DECB (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 6) +#define NRF_SAADC_VSS (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 7) +#define NRF_SAADC_VDDAO3V0 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 8) +#define NRF_SAADC_VDDAO1V8 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 9) +#define NRF_SAADC_VDDAO0V8 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 10) +#define NRF_SAADC_VDDRF (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 11) +#define NRF_SAADC_VBAT (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 12) +#define NRF_SAADC_AIN_DISABLED 255 /* UINT8_MAX */ #endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ */ From 5d22a72d1b484ab0105472e5aa97e51ab0c098b4 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 22 Jul 2025 10:19:26 +0200 Subject: [PATCH 2/5] [nrf fromlist] dts: nordic: Switch saadc pin definitions for generic ones Switch saadc pin definitions for generic ones defined in nrf-saadc.h Upstream PR #: 93497 Signed-off-by: Jakub Zymelka --- dts/arm/nordic/nrf52805.dtsi | 2 +- dts/arm/nordic/nrf52810.dtsi | 2 +- dts/arm/nordic/nrf52811.dtsi | 2 +- dts/arm/nordic/nrf52832.dtsi | 2 +- dts/arm/nordic/nrf52833.dtsi | 2 +- dts/arm/nordic/nrf52840.dtsi | 2 +- dts/arm/nordic/nrf5340_cpuapp.dtsi | 2 +- dts/arm/nordic/nrf5340_cpuappns.dtsi | 2 +- dts/arm/nordic/nrf91.dtsi | 2 +- dts/arm/nordic/nrf91ns.dtsi | 2 +- dts/vendor/nordic/nrf54h20.dtsi | 2 +- dts/vendor/nordic/nrf54l_05_10_15.dtsi | 2 +- dts/vendor/nordic/nrf54lm20a.dtsi | 2 +- dts/vendor/nordic/nrf9280.dtsi | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index 2134605c9f8..7951c9516ad 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index 6e09220e78b..4a1ef2bcedd 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -2,7 +2,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index 12d0a0ea4d6..d0321b85736 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index eef2297c43b..1513c0da811 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -2,7 +2,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index 1b3620aa01c..114399a0c28 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index f19383ba7e7..18354d20197 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -2,7 +2,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf5340_cpuapp.dtsi b/dts/arm/nordic/nrf5340_cpuapp.dtsi index b4c077ea2bf..15d4f487f82 100644 --- a/dts/arm/nordic/nrf5340_cpuapp.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include / { cpus { diff --git a/dts/arm/nordic/nrf5340_cpuappns.dtsi b/dts/arm/nordic/nrf5340_cpuappns.dtsi index 763e9ca7839..25b2d870c11 100644 --- a/dts/arm/nordic/nrf5340_cpuappns.dtsi +++ b/dts/arm/nordic/nrf5340_cpuappns.dtsi @@ -8,7 +8,7 @@ #include #include -#include +#include / { cpus { diff --git a/dts/arm/nordic/nrf91.dtsi b/dts/arm/nordic/nrf91.dtsi index 7b7d4891651..9bcac2bd929 100644 --- a/dts/arm/nordic/nrf91.dtsi +++ b/dts/arm/nordic/nrf91.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include / { cpus { diff --git a/dts/arm/nordic/nrf91ns.dtsi b/dts/arm/nordic/nrf91ns.dtsi index e44bbcde0a4..9ab22c6f7ca 100644 --- a/dts/arm/nordic/nrf91ns.dtsi +++ b/dts/arm/nordic/nrf91ns.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include / { cpus { diff --git a/dts/vendor/nordic/nrf54h20.dtsi b/dts/vendor/nordic/nrf54h20.dtsi index 4644cb383ec..8a468bd846d 100644 --- a/dts/vendor/nordic/nrf54h20.dtsi +++ b/dts/vendor/nordic/nrf54h20.dtsi @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/dts/vendor/nordic/nrf54l_05_10_15.dtsi b/dts/vendor/nordic/nrf54l_05_10_15.dtsi index 95c27375038..cb2dbf0e467 100644 --- a/dts/vendor/nordic/nrf54l_05_10_15.dtsi +++ b/dts/vendor/nordic/nrf54l_05_10_15.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include /delete-node/ &sw_pwm; diff --git a/dts/vendor/nordic/nrf54lm20a.dtsi b/dts/vendor/nordic/nrf54lm20a.dtsi index d1e6d1b0d28..a49d6b2f914 100644 --- a/dts/vendor/nordic/nrf54lm20a.dtsi +++ b/dts/vendor/nordic/nrf54lm20a.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include /delete-node/ &sw_pwm; diff --git a/dts/vendor/nordic/nrf9280.dtsi b/dts/vendor/nordic/nrf9280.dtsi index fb27488e9dc..e1a448292ef 100644 --- a/dts/vendor/nordic/nrf9280.dtsi +++ b/dts/vendor/nordic/nrf9280.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include From b6e1e39240607d27093ed583b1177af96454e837 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 22 Jul 2025 12:40:20 +0200 Subject: [PATCH 3/5] [nrf fromlist] drivers: adc: nrfx_saadc: Remove platform dependencies Make the saadc driver more generic by including a generic header file for analog peripherals and removing platform dependencies. Upstream PR #: 93497 Signed-off-by: Jakub Zymelka --- drivers/adc/adc_nrfx_saadc.c | 176 ++++------------------------------- 1 file changed, 18 insertions(+), 158 deletions(-) diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index 06035e2c3c5..f4b29886609 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -6,9 +6,7 @@ #include "adc_context.h" #include -#include -#include -#include +#include #include #include #include @@ -18,91 +16,22 @@ LOG_MODULE_REGISTER(adc_nrfx_saadc, CONFIG_ADC_LOG_LEVEL); #define DT_DRV_COMPAT nordic_nrf_saadc -#if (NRF_SAADC_HAS_AIN_AS_PIN) - -#if defined(CONFIG_NRF_PLATFORM_HALTIUM) -static const uint32_t saadc_psels[NRF_SAADC_AIN13 + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - [NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - [NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - [NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - [NRF_SAADC_AIN8] = NRF_PIN_PORT_TO_PIN_NUMBER(0U, 9), - [NRF_SAADC_AIN9] = NRF_PIN_PORT_TO_PIN_NUMBER(1U, 9), - [NRF_SAADC_AIN10] = NRF_PIN_PORT_TO_PIN_NUMBER(2U, 9), - [NRF_SAADC_AIN11] = NRF_PIN_PORT_TO_PIN_NUMBER(3U, 9), - [NRF_SAADC_AIN12] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 9), - [NRF_SAADC_AIN13] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 9), -}; -#elif defined(CONFIG_SOC_NRF54L05) || defined(CONFIG_SOC_NRF54L10) || defined(CONFIG_SOC_NRF54L15) -static const uint32_t saadc_psels[NRF_SAADC_DVDD + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - [NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), - [NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), - [NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1), - [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1), - [NRF_SAADC_VDD] = NRF_SAADC_INPUT_VDD, - [NRF_SAADC_AVDD] = NRF_SAADC_INPUT_AVDD, - [NRF_SAADC_DVDD] = NRF_SAADC_INPUT_DVDD, -}; -#elif defined(NRF54LM20A_ENGA_XXAA) -static const uint32_t saadc_psels[NRF_SAADC_DVDD + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(31U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(30U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(29U, 1), - [NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - [NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - [NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - [NRF_SAADC_VDD] = NRF_SAADC_INPUT_VDD, - [NRF_SAADC_AVDD] = NRF_SAADC_INPUT_AVDD, - [NRF_SAADC_DVDD] = NRF_SAADC_INPUT_DVDD, -}; -#elif defined(NRF54LV10A_ENGA_XXAA) -static const uint32_t saadc_psels[NRF_SAADC_AIN7 + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - [NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - [NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(10U, 1), - [NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), - [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), -}; -#elif defined(NRF54LS05B_ENGA_XXAA) -static const uint32_t saadc_psels[NRF_SAADC_AIN3 + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), -}; -#endif - -#else -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) && +BUILD_ASSERT((NRF_SAADC_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0) && + (NRF_SAADC_AIN1 == NRFX_ANALOG_EXTERNAL_AIN1) && + (NRF_SAADC_AIN2 == NRFX_ANALOG_EXTERNAL_AIN2) && + (NRF_SAADC_AIN3 == NRFX_ANALOG_EXTERNAL_AIN3) && + (NRF_SAADC_AIN4 == NRFX_ANALOG_EXTERNAL_AIN4) && + (NRF_SAADC_AIN5 == NRFX_ANALOG_EXTERNAL_AIN5) && + (NRF_SAADC_AIN6 == NRFX_ANALOG_EXTERNAL_AIN6) && + (NRF_SAADC_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7) && #if defined(SAADC_CH_PSELP_PSELP_VDDHDIV5) - (NRF_SAADC_VDDHDIV5 == NRF_SAADC_INPUT_VDDHDIV5) && + (NRF_SAADC_VDDHDIV5 == NRFX_ANALOG_INTERNAL_VDDHDIV5) && #endif #if defined(SAADC_CH_PSELP_PSELP_VDD) - (NRF_SAADC_VDD == NRF_SAADC_INPUT_VDD) && + (NRF_SAADC_VDD == NRFX_ANALOG_INTERNAL_VDD) && #endif 1, - "Definitions from nrf-adc.h do not match those from nrf_saadc.h"); -#endif + "Definitions from nrf-saadc.h do not match those from nrfx_analog_common.h"); struct driver_data { struct adc_context ctx; @@ -184,46 +113,6 @@ static int acq_time_set(nrf_saadc_channel_config_t *ch_cfg, uint16_t acquisition return 0; } -static int input_assign(nrf_saadc_input_t *pin_p, - nrf_saadc_input_t *pin_n, - const struct adc_channel_cfg *channel_cfg) -{ -#if (NRF_SAADC_HAS_AIN_AS_PIN) - if (channel_cfg->input_positive > ARRAY_SIZE(saadc_psels) || - channel_cfg->input_positive < NRF_SAADC_AIN0) { - LOG_ERR("Invalid analog positive input number: %d", channel_cfg->input_positive); - return -EINVAL; - } - - *pin_p = saadc_psels[channel_cfg->input_positive]; - - if (channel_cfg->differential) { - if (channel_cfg->input_negative > ARRAY_SIZE(saadc_psels) || - (IS_ENABLED(CONFIG_NRF_PLATFORM_HALTIUM) && - (channel_cfg->input_positive > NRF_SAADC_AIN7) != - (channel_cfg->input_negative > NRF_SAADC_AIN7))) { - LOG_ERR("Invalid analog negative input number: %d", - channel_cfg->input_negative); - return -EINVAL; - } - *pin_n = channel_cfg->input_negative == NRF_SAADC_GND ? - NRF_SAADC_INPUT_DISABLED : - saadc_psels[channel_cfg->input_negative]; - } else { - *pin_n = NRF_SAADC_INPUT_DISABLED; - } -#else - *pin_p = channel_cfg->input_positive; - *pin_n = (channel_cfg->differential && (channel_cfg->input_negative != NRF_SAADC_GND)) - ? channel_cfg->input_negative - : NRF_SAADC_INPUT_DISABLED; -#endif - LOG_DBG("ADC positive input: %d", *pin_p); - LOG_DBG("ADC negative input: %d", *pin_n); - - return 0; -} - static int gain_set(nrf_saadc_channel_config_t *ch_cfg, enum adc_gain gain) { #if NRF_SAADC_HAS_CH_GAIN @@ -333,6 +222,11 @@ static int adc_nrfx_channel_setup(const struct device *dev, #endif }, .channel_index = channel_cfg->channel_id, + .pin_p = channel_cfg->input_positive, + .pin_n = (channel_cfg->differential && + (channel_cfg->input_negative != NRF_SAADC_GND)) + ? channel_cfg->input_negative + : NRF_SAADC_AIN_DISABLED, }; if (channel_cfg->channel_id >= SAADC_CH_NUM) { @@ -342,11 +236,6 @@ static int adc_nrfx_channel_setup(const struct device *dev, ch_cfg = &cfg.channel_config; - err = input_assign(&cfg.pin_p, &cfg.pin_n, channel_cfg); - if (err != 0) { - return err; - } - err = gain_set(ch_cfg, channel_cfg->gain); if (err != 0) { return err; @@ -803,38 +692,9 @@ static DEVICE_API(adc, adc_nrfx_driver_api) = { #ifdef CONFIG_ADC_ASYNC .read_async = adc_nrfx_read_async, #endif -#if defined(NRF54LV10A_ENGA_XXAA) - .ref_internal = 1300, -#elif defined(CONFIG_SOC_COMPATIBLE_NRF54LX) - .ref_internal = 900, -#elif defined(CONFIG_NRF_PLATFORM_HALTIUM) - .ref_internal = 1024, -#else - .ref_internal = 600, -#endif + .ref_internal = NRFX_SAADC_REF_INTERNAL_VALUE, }; -#if defined(CONFIG_NRF_PLATFORM_HALTIUM) -/* AIN8-AIN14 inputs are on 3v3 GPIO port and they cannot be mixed with other - * analog inputs (from 1v8 ports) in differential mode. - */ -#define CH_IS_3V3(val) (val >= NRF_SAADC_AIN8) - -#define MIXED_3V3_1V8_INPUTS(node) \ - (DT_NODE_HAS_PROP(node, zephyr_input_negative) && \ - (CH_IS_3V3(DT_PROP_OR(node, zephyr_input_negative, 0)) != \ - CH_IS_3V3(DT_PROP_OR(node, zephyr_input_positive, 0)))) -#else -#define MIXED_3V3_1V8_INPUTS(node) false -#endif - -#define VALIDATE_CHANNEL_CONFIG(node) \ - BUILD_ASSERT(MIXED_3V3_1V8_INPUTS(node) == false, \ - "1v8 inputs cannot be mixed with 3v3 inputs"); - -/* Validate configuration of all channels. */ -DT_FOREACH_CHILD(DT_DRV_INST(0), VALIDATE_CHANNEL_CONFIG) - NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(DT_DRV_INST(0)); DEVICE_DT_INST_DEFINE(0, init_saadc, NULL, NULL, NULL, POST_KERNEL, From 5e8f817b07ec844cd0015e4477a43aef768f6d92 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 22 Jul 2025 12:44:12 +0200 Subject: [PATCH 4/5] [nrf fromlist] drivers: comparator: nordic: Remove platform dependencies Remove platform dependencies and replace the analog pin mapping method with the generic one from the (LP)COMP driver. Upstream PR #: 93497 Signed-off-by: Jakub Zymelka --- drivers/comparator/comparator_nrf_common.h | 53 ----- drivers/comparator/comparator_nrf_comp.c | 212 ++---------------- drivers/comparator/comparator_nrf_lpcomp.c | 123 +--------- .../zephyr/dt-bindings/comparator/nrf-comp.h | 6 +- 4 files changed, 31 insertions(+), 363 deletions(-) delete mode 100644 drivers/comparator/comparator_nrf_common.h diff --git a/drivers/comparator/comparator_nrf_common.h b/drivers/comparator/comparator_nrf_common.h deleted file mode 100644 index e86fc9f6369..00000000000 --- a/drivers/comparator/comparator_nrf_common.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2025 Nordic Semiconductor ASA - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_DRIVERS_COMPARATOR_NRF_COMMON_H_ -#define ZEPHYR_DRIVERS_COMPARATOR_NRF_COMMON_H_ - -#include - -#if (NRF_COMP_HAS_AIN_AS_PIN || NRF_LPCOMP_HAS_AIN_AS_PIN) -static const uint32_t shim_nrf_comp_ain_map[] = { -#if defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280) - NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), -#elif defined(CONFIG_SOC_NRF54L05) || defined(CONFIG_SOC_NRF54L10) || defined(CONFIG_SOC_NRF54L15) - NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1), -#elif defined(NRF54LM20A_ENGA_XXAA) - NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(31U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(30U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(29U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), -#elif defined(NRF54LV10A_ENGA_XXAA) - NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(10U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), -#endif -}; -#endif - -#endif /* ZEPHYR_DRIVERS_COMPARATOR_NRF_COMMON_H_ */ diff --git a/drivers/comparator/comparator_nrf_comp.c b/drivers/comparator/comparator_nrf_comp.c index 6c5acdf5c08..675d5f8dad3 100644 --- a/drivers/comparator/comparator_nrf_comp.c +++ b/drivers/comparator/comparator_nrf_comp.c @@ -9,7 +9,6 @@ #include #include #include -#include "comparator_nrf_common.h" #define DT_DRV_COMPAT nordic_nrf_comp @@ -71,51 +70,22 @@ BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_DOWN(0) < 64); BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_UP(0) < 64); #endif -#if (NRF_COMP_HAS_AIN_AS_PIN) -BUILD_ASSERT(NRF_COMP_AIN0 == 0); -BUILD_ASSERT(NRF_COMP_AIN7 == 7); -#else -BUILD_ASSERT((NRF_COMP_AIN0 == NRF_COMP_INPUT_0) && - (NRF_COMP_AIN1 == NRF_COMP_INPUT_1) && - (NRF_COMP_AIN2 == NRF_COMP_INPUT_2) && - (NRF_COMP_AIN3 == NRF_COMP_INPUT_3) && -#if defined(COMP_PSEL_PSEL_AnalogInput4) - (NRF_COMP_AIN4 == NRF_COMP_INPUT_4) && -#endif -#if defined(COMP_PSEL_PSEL_AnalogInput5) - (NRF_COMP_AIN5 == NRF_COMP_INPUT_5) && -#endif -#if defined(COMP_PSEL_PSEL_AnalogInput6) - (NRF_COMP_AIN6 == NRF_COMP_INPUT_6) && -#endif -#if defined(COMP_PSEL_PSEL_AnalogInput7) - (NRF_COMP_AIN7 == NRF_COMP_INPUT_7) && -#endif - (NRF_COMP_AIN0 == NRF_COMP_EXT_REF_0) && - (NRF_COMP_AIN1 == NRF_COMP_EXT_REF_1) && - (NRF_COMP_AIN2 == NRF_COMP_EXT_REF_2) && - (NRF_COMP_AIN3 == NRF_COMP_EXT_REF_3) && -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4) - (NRF_COMP_AIN4 == NRF_COMP_EXT_REF_4) && -#endif -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5) - (NRF_COMP_AIN5 == NRF_COMP_EXT_REF_5) && -#endif -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6) - (NRF_COMP_AIN6 == NRF_COMP_EXT_REF_6) && -#endif -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7) - (NRF_COMP_AIN7 == NRF_COMP_EXT_REF_7) && +BUILD_ASSERT((NRF_COMP_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0) && + (NRF_COMP_AIN1 == NRFX_ANALOG_EXTERNAL_AIN1) && + (NRF_COMP_AIN2 == NRFX_ANALOG_EXTERNAL_AIN2) && + (NRF_COMP_AIN3 == NRFX_ANALOG_EXTERNAL_AIN3) && + (NRF_COMP_AIN4 == NRFX_ANALOG_EXTERNAL_AIN4) && + (NRF_COMP_AIN5 == NRFX_ANALOG_EXTERNAL_AIN5) && + (NRF_COMP_AIN6 == NRFX_ANALOG_EXTERNAL_AIN6) && + (NRF_COMP_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7) && +#if defined(COMP_PSEL_PSEL_VddhDiv5) + (NRF_COMP_AIN_VDDH_DIV5 == NRFX_ANALOG_INTERNAL_VDDHDIV5) && #endif #if defined(COMP_PSEL_PSEL_VddDiv2) - (NRF_COMP_VDD_DIV2 == NRF_COMP_VDD_DIV2) && -#endif -#if defined(COMP_PSEL_PSEL_VddhDiv5) - (NRF_COMP_VDDH_DIV5 == NRF_COMP_VDDH_DIV5) && + (NRF_COMP_AIN_VDD_DIV2 == NRFX_ANALOG_INTERNAL_VDDDIV2) && #endif 1, - "Definitions from nrf-comp.h do not match those from HAL"); -#endif + "Definitions from nrf-comp.h do not match those from nrfx_analog_common.h"); #ifndef COMP_MODE_SP_Normal BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_SP_MODE(0) != COMP_NRF_COMP_SP_MODE_NORMAL); @@ -240,82 +210,6 @@ static int shim_nrf_comp_pm_callback(const struct device *dev, enum pm_device_ac return 0; } -#if (NRF_COMP_HAS_AIN_AS_PIN) -static int shim_nrf_comp_psel_to_nrf(uint8_t shim, - nrf_comp_input_t *nrf) -{ - if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { - return -EINVAL; - } - - *nrf = shim_nrf_comp_ain_map[shim]; - return 0; -} -#else -static int shim_nrf_comp_psel_to_nrf(uint8_t shim, - nrf_comp_input_t *nrf) -{ - switch (shim) { - case NRF_COMP_AIN0: - *nrf = NRF_COMP_INPUT_0; - break; - - case NRF_COMP_AIN1: - *nrf = NRF_COMP_INPUT_1; - break; - - case NRF_COMP_AIN2: - *nrf = NRF_COMP_INPUT_2; - break; - - case NRF_COMP_AIN3: - *nrf = NRF_COMP_INPUT_3; - break; - -#if defined(COMP_PSEL_PSEL_AnalogInput4) - case NRF_COMP_AIN4: - *nrf = NRF_COMP_INPUT_4; - break; -#endif - -#if defined(COMP_PSEL_PSEL_AnalogInput5) - case NRF_COMP_AIN5: - *nrf = NRF_COMP_INPUT_5; - break; -#endif - -#if defined(COMP_PSEL_PSEL_AnalogInput6) - case NRF_COMP_AIN6: - *nrf = NRF_COMP_INPUT_6; - break; -#endif - -#if defined(COMP_PSEL_PSEL_AnalogInput7) - case NRF_COMP_AIN7: - *nrf = NRF_COMP_INPUT_7; - break; -#endif - -#if defined(COMP_PSEL_PSEL_VddDiv2) - case NRF_COMP_AIN_VDD_DIV2: - *nrf = NRF_COMP_VDD_DIV2; - break; -#endif - -#if defined(COMP_PSEL_PSEL_VddhDiv5) - case NRF_COMP_AIN_VDDH_DIV5: - *nrf = NRF_COMP_VDDH_DIV5; - break; -#endif - - default: - return -EINVAL; - } - - return 0; -} -#endif - static int shim_nrf_comp_sp_mode_to_nrf(enum comp_nrf_comp_sp_mode shim, nrf_comp_sp_mode_t *nrf) { @@ -376,70 +270,6 @@ static int shim_nrf_comp_isource_to_nrf(enum comp_nrf_comp_isource shim, } #endif -#if (NRF_COMP_HAS_AIN_AS_PIN) -static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim, - nrf_comp_ext_ref_t *nrf) -{ - if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { - return -EINVAL; - } - - *nrf = shim_nrf_comp_ain_map[shim]; - return 0; -} -#else -static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim, - nrf_comp_ext_ref_t *nrf) -{ - switch (shim) { - case NRF_COMP_AIN0: - *nrf = NRF_COMP_EXT_REF_0; - break; - - case NRF_COMP_AIN1: - *nrf = NRF_COMP_EXT_REF_1; - break; - - case NRF_COMP_AIN2: - *nrf = NRF_COMP_EXT_REF_2; - break; - - case NRF_COMP_AIN3: - *nrf = NRF_COMP_EXT_REF_3; - break; - -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4) - case NRF_COMP_AIN4: - *nrf = NRF_COMP_EXT_REF_4; - break; -#endif - -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5) - case NRF_COMP_AIN5: - *nrf = NRF_COMP_EXT_REF_5; - break; -#endif - -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6) - case NRF_COMP_AIN6: - *nrf = NRF_COMP_EXT_REF_6; - break; -#endif - -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7) - case NRF_COMP_AIN7: - *nrf = NRF_COMP_EXT_REF_7; - break; -#endif - - default: - return -EINVAL; - } - - return 0; -} -#endif - static int shim_nrf_comp_refsel_to_nrf(enum comp_nrf_comp_refsel shim, nrf_comp_ref_t *nrf) { @@ -490,9 +320,8 @@ static int shim_nrf_comp_se_config_to_nrf(const struct comp_nrf_comp_se_config * return -EINVAL; } - if (shim_nrf_comp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) { - return -EINVAL; - } + nrf->ext_ref = (nrfx_analog_input_t)shim->extrefsel; + nrf->input = (nrfx_analog_input_t)shim->psel; nrf->main_mode = NRF_COMP_MAIN_MODE_SE; @@ -519,10 +348,6 @@ static int shim_nrf_comp_se_config_to_nrf(const struct comp_nrf_comp_se_config * } #endif - if (shim_nrf_comp_psel_to_nrf(shim->psel, &nrf->input)) { - return -EINVAL; - } - nrf->interrupt_priority = 0; return 0; } @@ -532,9 +357,8 @@ static int shim_nrf_comp_diff_config_to_nrf(const struct comp_nrf_comp_diff_conf { nrf->reference = NRF_COMP_REF_AREF; - if (shim_nrf_comp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) { - return -EINVAL; - } + nrf->ext_ref = (nrfx_analog_input_t)shim->extrefsel; + nrf->input = (nrfx_analog_input_t)shim->psel; nrf->main_mode = NRF_COMP_MAIN_MODE_DIFF; nrf->threshold.th_down = 0; @@ -566,10 +390,6 @@ static int shim_nrf_comp_diff_config_to_nrf(const struct comp_nrf_comp_diff_conf } #endif - if (shim_nrf_comp_psel_to_nrf(shim->psel, &nrf->input)) { - return -EINVAL; - } - nrf->interrupt_priority = 0; return 0; } diff --git a/drivers/comparator/comparator_nrf_lpcomp.c b/drivers/comparator/comparator_nrf_lpcomp.c index 6faba2b8669..36b4c440f4b 100644 --- a/drivers/comparator/comparator_nrf_lpcomp.c +++ b/drivers/comparator/comparator_nrf_lpcomp.c @@ -9,7 +9,6 @@ #include #include #include -#include "comparator_nrf_common.h" #include @@ -37,22 +36,15 @@ struct shim_nrf_lpcomp_data { void *user_data; }; -#if (NRF_LPCOMP_HAS_AIN_AS_PIN) -BUILD_ASSERT(NRF_COMP_AIN0 == 0); -BUILD_ASSERT(NRF_COMP_AIN7 == 7); -#else -BUILD_ASSERT((NRF_COMP_AIN0 == NRF_LPCOMP_INPUT_0) && - (NRF_COMP_AIN1 == NRF_LPCOMP_INPUT_1) && - (NRF_COMP_AIN2 == NRF_LPCOMP_INPUT_2) && - (NRF_COMP_AIN3 == NRF_LPCOMP_INPUT_3) && - (NRF_COMP_AIN4 == NRF_LPCOMP_INPUT_4) && - (NRF_COMP_AIN5 == NRF_LPCOMP_INPUT_5) && - (NRF_COMP_AIN6 == NRF_LPCOMP_INPUT_6) && - (NRF_COMP_AIN7 == NRF_LPCOMP_INPUT_7) && - (NRF_COMP_AIN0 == NRF_LPCOMP_EXT_REF_REF0) && - (NRF_COMP_AIN1 == NRF_LPCOMP_EXT_REF_REF1), - "Definitions from nrf-comp.h do not match those from HAL"); -#endif +BUILD_ASSERT((NRF_COMP_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0) && + (NRF_COMP_AIN1 == NRFX_ANALOG_EXTERNAL_AIN1) && + (NRF_COMP_AIN2 == NRFX_ANALOG_EXTERNAL_AIN2) && + (NRF_COMP_AIN3 == NRFX_ANALOG_EXTERNAL_AIN3) && + (NRF_COMP_AIN4 == NRFX_ANALOG_EXTERNAL_AIN4) && + (NRF_COMP_AIN5 == NRFX_ANALOG_EXTERNAL_AIN5) && + (NRF_COMP_AIN6 == NRFX_ANALOG_EXTERNAL_AIN6) && + (NRF_COMP_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7), + "Definitions from nrf-comp.h do not match those from nrfx_analog_common.h"); #if (LPCOMP_REFSEL_RESOLUTION == 8) BUILD_ASSERT((SHIM_NRF_LPCOMP_DT_INST_REFSEL(0) < COMP_NRF_LPCOMP_REFSEL_VDD_1_16) || @@ -133,94 +125,6 @@ static int shim_nrf_lpcomp_pm_callback(const struct device *dev, enum pm_device_ return 0; } -#if (NRF_LPCOMP_HAS_AIN_AS_PIN) -static int shim_nrf_lpcomp_psel_to_nrf(uint8_t shim, - nrf_lpcomp_input_t *nrf) -{ - if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { - return -EINVAL; - } - - *nrf = shim_nrf_comp_ain_map[shim]; - return 0; -} -#else -static int shim_nrf_lpcomp_psel_to_nrf(uint8_t shim, - nrf_lpcomp_input_t *nrf) -{ - switch (shim) { - case NRF_COMP_AIN0: - *nrf = NRF_LPCOMP_INPUT_0; - break; - - case NRF_COMP_AIN1: - *nrf = NRF_LPCOMP_INPUT_1; - break; - - case NRF_COMP_AIN2: - *nrf = NRF_LPCOMP_INPUT_2; - break; - - case NRF_COMP_AIN3: - *nrf = NRF_LPCOMP_INPUT_3; - break; - - case NRF_COMP_AIN4: - *nrf = NRF_LPCOMP_INPUT_4; - break; - - case NRF_COMP_AIN5: - *nrf = NRF_LPCOMP_INPUT_5; - break; - - case NRF_COMP_AIN6: - *nrf = NRF_LPCOMP_INPUT_6; - break; - - case NRF_COMP_AIN7: - *nrf = NRF_LPCOMP_INPUT_7; - break; - - default: - return -EINVAL; - } - - return 0; -} -#endif - -#if (NRF_LPCOMP_HAS_AIN_AS_PIN) -static int shim_nrf_lpcomp_extrefsel_to_nrf(uint8_t shim, - nrf_lpcomp_ext_ref_t *nrf) -{ - if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { - return -EINVAL; - } - - *nrf = shim_nrf_comp_ain_map[shim]; - return 0; -} -#else -static int shim_nrf_lpcomp_extrefsel_to_nrf(uint8_t shim, - nrf_lpcomp_ext_ref_t *nrf) -{ - switch (shim) { - case NRF_COMP_AIN0: - *nrf = NRF_LPCOMP_EXT_REF_REF0; - break; - - case NRF_COMP_AIN1: - *nrf = NRF_LPCOMP_EXT_REF_REF1; - break; - - default: - return -EINVAL; - } - - return 0; -} -#endif - static int shim_nrf_lpcomp_refsel_to_nrf(enum comp_nrf_lpcomp_refsel shim, nrf_lpcomp_ref_t *nrf) { @@ -305,9 +209,8 @@ static int shim_nrf_lpcomp_config_to_nrf(const struct comp_nrf_lpcomp_config *sh return -EINVAL; } - if (shim_nrf_lpcomp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) { - return -EINVAL; - } + nrf->ext_ref = (nrfx_analog_input_t)shim->extrefsel; + nrf->input = (nrfx_analog_input_t)shim->psel; #if NRF_LPCOMP_HAS_HYST if (shim->enable_hyst) { @@ -321,10 +224,6 @@ static int shim_nrf_lpcomp_config_to_nrf(const struct comp_nrf_lpcomp_config *sh } #endif - if (shim_nrf_lpcomp_psel_to_nrf(shim->psel, &nrf->input)) { - return -EINVAL; - } - return 0; } diff --git a/include/zephyr/dt-bindings/comparator/nrf-comp.h b/include/zephyr/dt-bindings/comparator/nrf-comp.h index 1a5407554a1..13314bc963c 100644 --- a/include/zephyr/dt-bindings/comparator/nrf-comp.h +++ b/include/zephyr/dt-bindings/comparator/nrf-comp.h @@ -15,7 +15,9 @@ #define NRF_COMP_AIN5 5 /** AIN5 external input */ #define NRF_COMP_AIN6 6 /** AIN6 external input */ #define NRF_COMP_AIN7 7 /** AIN7 external input */ -#define NRF_COMP_AIN_VDD_DIV2 8 /** VDD / 2 */ -#define NRF_COMP_AIN_VDDH_DIV5 9 /** VDDH / 5 */ + +#define NRF_COMP_AIN_VDD_SHIM_OFFSET 128 +#define NRF_COMP_AIN_VDD_DIV2 (NRF_COMP_AIN_VDD_SHIM_OFFSET + 1) +#define NRF_COMP_AIN_VDDH_DIV5 (NRF_COMP_AIN_VDD_SHIM_OFFSET + 4) #endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_COMP_H_ */ From 29ce7c1059368880dbdf86a7c1ff241822f8ecad Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Mon, 13 Oct 2025 09:34:46 +0200 Subject: [PATCH 5/5] [nrf noup] dts: nordic: Switch saadc pin definitions for generic ones Switch saadc pin definitions for generic ones defined in nrf-saadc.h Signed-off-by: Jakub Zymelka --- dts/vendor/nordic/nrf54l09.dtsi | 2 +- dts/vendor/nordic/nrf54l20.dtsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dts/vendor/nordic/nrf54l09.dtsi b/dts/vendor/nordic/nrf54l09.dtsi index 90ecc49b877..1558dfeadee 100644 --- a/dts/vendor/nordic/nrf54l09.dtsi +++ b/dts/vendor/nordic/nrf54l09.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include /delete-node/ &sw_pwm; diff --git a/dts/vendor/nordic/nrf54l20.dtsi b/dts/vendor/nordic/nrf54l20.dtsi index bee70effa0e..38a4c4e5560 100644 --- a/dts/vendor/nordic/nrf54l20.dtsi +++ b/dts/vendor/nordic/nrf54l20.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include /delete-node/ &sw_pwm;