Skip to content

drivers: adc: nrfx_saadc: Remove platform dependencies #93497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 21 additions & 131 deletions drivers/adc/adc_nrfx_saadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#define ADC_CONTEXT_USES_KERNEL_TIMER
#include "adc_context.h"
#include <nrfx_saadc.h>
#include <zephyr/dt-bindings/adc/nrf-saadc-v3.h>
#include <zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h>
#include <zephyr/dt-bindings/adc/nrf-saadc-haltium.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>
#include <zephyr/linker/devicetree_regions.h>
#include <zephyr/logging/log.h>
#include <zephyr/irq.h>
Expand All @@ -18,85 +16,23 @@ 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_DVDD + 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),
[NRF_SAADC_VDD] = NRF_SAADC_INPUT_VDD,
[NRF_SAADC_DVDD] = NRF_SAADC_INPUT_DVDD,
};
#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) &&
#if (NRF_SAADC_HAS_AIN_AS_PIN == 0)
BUILD_ASSERT((NRF_SAADC_AIN0 == NRFX_SAADC_AIN0) &&
(NRF_SAADC_AIN1 == NRFX_SAADC_AIN1) &&
(NRF_SAADC_AIN2 == NRFX_SAADC_AIN2) &&
(NRF_SAADC_AIN3 == NRFX_SAADC_AIN3) &&
(NRF_SAADC_AIN4 == NRFX_SAADC_AIN4) &&
(NRF_SAADC_AIN5 == NRFX_SAADC_AIN5) &&
(NRF_SAADC_AIN6 == NRFX_SAADC_AIN6) &&
(NRF_SAADC_AIN7 == NRFX_SAADC_AIN7) &&
#if defined(SAADC_CH_PSELP_PSELP_VDDHDIV5)
(NRF_SAADC_VDDHDIV5 == NRF_SAADC_INPUT_VDDHDIV5) &&
(NRF_SAADC_VDDHDIV5 == NRFX_SAADC_VDDHDIV5) &&
#endif
#if defined(SAADC_CH_PSELP_PSELP_VDD)
(NRF_SAADC_VDD == NRF_SAADC_INPUT_VDD) &&
(NRF_SAADC_VDD == NRFX_SAADC_VDD) &&
#endif
1,
"Definitions from nrf-adc.h do not match those from nrf_saadc.h");
"Definitions from nrf-saadc.h do not match those from nrfx_analog_common.h");
#endif

#if defined(CONFIG_NRF_PLATFORM_HALTIUM)
Expand Down Expand Up @@ -192,34 +128,17 @@ 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);
if (nrfx_saadc_psels_are_valid(channel_cfg->input_positive,
channel_cfg->input_negative,
channel_cfg->differential) != NRFX_SUCCESS) {
LOG_ERR("Invalid ADC input pin configuration");
return -EINVAL;
}

*pin_p = saadc_psels[channel_cfg->input_positive];

if (channel_cfg->differential) {
if (channel_cfg->input_negative > ARRAY_SIZE(saadc_psels) ||
channel_cfg->input_negative < NRF_SAADC_AIN0 ||
(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 = 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
*pin_p = nrfx_saadc_psel_to_nrf(channel_cfg->input_positive);
*pin_n = channel_cfg->differential ? nrfx_saadc_psel_to_nrf(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);

Expand Down Expand Up @@ -679,37 +598,8 @@ 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)

DEVICE_DT_INST_DEFINE(0, init_saadc, NULL, NULL, NULL, POST_KERNEL,
CONFIG_ADC_INIT_PRIORITY, &adc_nrfx_driver_api);
53 changes: 0 additions & 53 deletions drivers/comparator/comparator_nrf_common.h

This file was deleted.

9 changes: 4 additions & 5 deletions drivers/comparator/comparator_nrf_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <zephyr/drivers/comparator/nrf_comp.h>
#include <zephyr/kernel.h>
#include <zephyr/pm/device.h>
#include "comparator_nrf_common.h"

#define DT_DRV_COMPAT nordic_nrf_comp

Expand Down Expand Up @@ -249,11 +248,11 @@ static int shim_nrf_comp_pm_callback(const struct device *dev, enum pm_device_ac
static int shim_nrf_comp_psel_to_nrf(enum comp_nrf_comp_psel shim,
nrf_comp_input_t *nrf)
{
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
if (!nrfx_comp_psel_is_valid(shim)) {
return -EINVAL;
}

*nrf = shim_nrf_comp_ain_map[(uint32_t)shim];
*nrf = nrfx_comp_psel_to_nrf((uint32_t)shim);
return 0;
}
#else
Expand Down Expand Up @@ -385,11 +384,11 @@ static int shim_nrf_comp_isource_to_nrf(enum comp_nrf_comp_isource shim,
static int shim_nrf_comp_extrefsel_to_nrf(enum comp_nrf_comp_extrefsel shim,
nrf_comp_ext_ref_t *nrf)
{
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
if (!nrfx_comp_psel_is_valid(shim)) {
return -EINVAL;
}

*nrf = shim_nrf_comp_ain_map[(uint32_t)shim];
*nrf = nrfx_comp_psel_to_nrf((uint32_t)shim);
return 0;
}
#else
Expand Down
9 changes: 4 additions & 5 deletions drivers/comparator/comparator_nrf_lpcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <zephyr/drivers/comparator/nrf_lpcomp.h>
#include <zephyr/kernel.h>
#include <zephyr/pm/device.h>
#include "comparator_nrf_common.h"

#include <string.h>

Expand Down Expand Up @@ -129,11 +128,11 @@ static int shim_nrf_lpcomp_pm_callback(const struct device *dev, enum pm_device_
static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim,
nrf_lpcomp_input_t *nrf)
{
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
if (!nrfx_lpcomp_psel_is_valid(shim)) {
return -EINVAL;
}

*nrf = shim_nrf_comp_ain_map[(uint32_t)shim];
*nrf = nrfx_lpcomp_psel_to_nrf((uint32_t)shim);
return 0;
}
#else
Expand Down Expand Up @@ -185,11 +184,11 @@ static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim,
static int shim_nrf_lpcomp_extrefsel_to_nrf(enum comp_nrf_lpcomp_extrefsel shim,
nrf_lpcomp_ext_ref_t *nrf)
{
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
if (!nrfx_lpcomp_psel_is_valid(shim)) {
return -EINVAL;
}

*nrf = shim_nrf_comp_ain_map[shim];
*nrf = nrfx_lpcomp_psel_to_nrf((uint32_t)shim);
return 0;
}
#else
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nordic/nrf52805.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <arm/armv7-m.dtsi>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-v2.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>
#include <zephyr/dt-bindings/regulator/nrf5x.h>

/ {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nordic/nrf52810.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <arm/armv7-m.dtsi>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-v2.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>
#include <zephyr/dt-bindings/regulator/nrf5x.h>

/ {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nordic/nrf52811.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <arm/armv7-m.dtsi>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-v2.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>
#include <zephyr/dt-bindings/regulator/nrf5x.h>

/ {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nordic/nrf52832.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <arm/armv7-m.dtsi>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-v2.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>
#include <zephyr/dt-bindings/regulator/nrf5x.h>

/ {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nordic/nrf52833.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <arm/armv7-m.dtsi>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-v3.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>
#include <zephyr/dt-bindings/regulator/nrf5x.h>

/ {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nordic/nrf52840.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <arm/armv7-m.dtsi>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-v3.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>
#include <zephyr/dt-bindings/regulator/nrf5x.h>

/ {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nordic/nrf5340_cpuapp.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <arm/armv8-m.dtsi>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-v3.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>

/ {
cpus {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nordic/nrf5340_cpuappns.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <arm/armv8-m.dtsi>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-v3.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>

/ {
cpus {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nordic/nrf91.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <arm/armv8-m.dtsi>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-v2.h>
#include <zephyr/dt-bindings/adc/nrf-saadc.h>

/ {
cpus {
Expand Down
Loading
Loading