Skip to content
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

drivers: adc: add support for nRF54L internal SAADC inputs #79330

Merged
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
31 changes: 18 additions & 13 deletions drivers/adc/adc_nrfx_saadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#define ADC_CONTEXT_USES_KERNEL_TIMER
#include "adc_context.h"
#include <haly/nrfy_saadc.h>
#include <zephyr/dt-bindings/adc/nrf-adc.h>
#include <zephyr/dt-bindings/adc/nrf-saadc-v3.h>
#include <zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h>
anangl marked this conversation as resolved.
Show resolved Hide resolved
#include <zephyr/linker/devicetree_regions.h>

#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
Expand All @@ -31,7 +32,7 @@
[NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1),
};
#elif defined(CONFIG_SOC_NRF54L15)
static const uint8_t saadc_psels[NRF_SAADC_AIN7 + 1] = {
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),
Expand All @@ -40,6 +41,9 @@
[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,

Check notice on line 45 in drivers/adc/adc_nrfx_saadc.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/adc/adc_nrfx_saadc.c:45 - [NRF_SAADC_VDD] = NRF_SAADC_INPUT_VDD, + [NRF_SAADC_VDD] = NRF_SAADC_INPUT_VDD,
[NRF_SAADC_DVDD] = NRF_SAADC_INPUT_DVDD,
};
#endif

Expand Down Expand Up @@ -273,13 +277,8 @@
m_data.single_ended_channels |= BIT(channel_cfg->channel_id);
}

/* Keep the channel disabled in hardware (set positive input to
* NRF_SAADC_INPUT_DISABLED) until it is selected to be included
* in a sampling sequence.
*/

#if (NRF_SAADC_HAS_AIN_AS_PIN)
if ((channel_cfg->input_positive > NRF_SAADC_AIN7) ||
if ((channel_cfg->input_positive >= ARRAY_SIZE(saadc_psels)) ||
(channel_cfg->input_positive < NRF_SAADC_AIN0)) {
return -EINVAL;
}
Expand All @@ -294,17 +293,18 @@
} else {
input_negative = NRF_SAADC_INPUT_DISABLED;
}

#endif
/* Store the positive input selection in a dedicated array,
* to get it later when the channel is selected for a sampling
* and to mark the channel as configured (ready to be selected).
*/
m_data.positive_inputs[channel_id] = saadc_psels[channel_cfg->input_positive];
#else
m_data.positive_inputs[channel_id] = channel_cfg->input_positive;
#endif

nrf_saadc_channel_init(NRF_SAADC, channel_id, &config);
/* Keep the channel disabled in hardware (set positive input to
* NRF_SAADC_INPUT_DISABLED) until it is selected to be included
* in a sampling sequence.
*/
nrf_saadc_channel_input_set(NRF_SAADC,
channel_id,
NRF_SAADC_INPUT_DISABLED,
Expand Down Expand Up @@ -531,8 +531,13 @@
nrf_saadc_channel_pos_input_set(
NRF_SAADC,
channel_id,
m_data.positive_inputs[channel_id]);
#if NRF_SAADC_HAS_AIN_AS_PIN
saadc_psels[m_data.positive_inputs[channel_id]]
#else
m_data.positive_inputs[channel_id]
#endif
);
++active_channels;

Check notice on line 540 in drivers/adc/adc_nrfx_saadc.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/adc/adc_nrfx_saadc.c:540 - NRF_SAADC, - channel_id, + NRF_SAADC, channel_id, #if NRF_SAADC_HAS_AIN_AS_PIN saadc_psels[m_data.positive_inputs[channel_id]] #else m_data.positive_inputs[channel_id] #endif - ); + );
} else {
nrf_saadc_burst_set(
NRF_SAADC,
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf51822.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

/ {
chosen {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52805.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +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/regulator/nrf5x.h>

/ {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52810.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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/regulator/nrf5x.h>

/ {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52811.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +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/regulator/nrf5x.h>

/ {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52832.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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/regulator/nrf5x.h>

/ {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52833.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +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/regulator/nrf5x.h>

/ {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52840.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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/regulator/nrf5x.h>

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

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

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

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

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

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

/ {
cpus {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf91ns.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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

/ {
cpus {
Expand Down
1 change: 1 addition & 0 deletions dts/common/nordic/nrf54h20.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <mem.h>
#include <nordic/nrf_common.dtsi>

#include <zephyr/dt-bindings/adc/nrf-saadc.h>
#include <zephyr/dt-bindings/misc/nordic-nrf-ficr-nrf54h20.h>
#include <zephyr/dt-bindings/misc/nordic-domain-id-nrf54h20.h>
#include <zephyr/dt-bindings/misc/nordic-owner-id-nrf54h20.h>
Expand Down
1 change: 1 addition & 0 deletions dts/common/nordic/nrf54l15.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <mem.h>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h>
#include <zephyr/dt-bindings/regulator/nrf5x.h>

/delete-node/ &sw_pwm;
Expand Down
1 change: 1 addition & 0 deletions dts/common/nordic/nrf54l20.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <mem.h>
#include <nordic/nrf_common.dtsi>
#include <zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h>
#include <zephyr/dt-bindings/regulator/nrf5x.h>

/delete-node/ &sw_pwm;
Expand Down
2 changes: 1 addition & 1 deletion dts/common/nordic/nrf9280.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <mem.h>
#include <nordic/nrf_common.dtsi>

#include <zephyr/dt-bindings/adc/nrf-saadc.h>
#include <zephyr/dt-bindings/misc/nordic-nrf-ficr-nrf9230-engb.h>
#include <zephyr/dt-bindings/misc/nordic-domain-id-nrf9230.h>
#include <zephyr/dt-bindings/misc/nordic-owner-id-nrf9230.h>
Expand Down
1 change: 0 additions & 1 deletion dts/common/nordic/nrf_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include <zephyr/dt-bindings/adc/adc.h>
#include <zephyr/dt-bindings/adc/nrf-adc.h>
#include <zephyr/dt-bindings/gpio/gpio.h>
#include <zephyr/dt-bindings/i2c/i2c.h>
#include <zephyr/dt-bindings/input/input-event-codes.h>
Expand Down
11 changes: 0 additions & 11 deletions include/zephyr/dt-bindings/adc/nrf-adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,4 @@
#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_ */
15 changes: 15 additions & 0 deletions include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 <zephyr/dt-bindings/adc/nrf-saadc-v2.h>

#define NRF_SAADC_AVDD 10
#define NRF_SAADC_DVDD 11

#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ */
14 changes: 14 additions & 0 deletions include/zephyr/dt-bindings/adc/nrf-saadc-v2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 <zephyr/dt-bindings/adc/nrf-saadc.h>

#define NRF_SAADC_VDD 9

#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ */
14 changes: 14 additions & 0 deletions include/zephyr/dt-bindings/adc/nrf-saadc-v3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 <zephyr/dt-bindings/adc/nrf-saadc-v2.h>

#define NRF_SAADC_VDDHDIV5 13

#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ */
19 changes: 19 additions & 0 deletions include/zephyr/dt-bindings/adc/nrf-saadc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2024 Nordic Semiconductor ASA
*/

#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_
#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_

#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

#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/ {
zephyr,user {
io-channels = <&adc 0>, <&adc 1>, <&adc 7>;
io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>;
};
};

Expand All @@ -33,6 +33,16 @@
zephyr,oversampling = <8>;
};

channel@2 {
reg = <2>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_VDD>;
zephyr,resolution = <12>;
zephyr,oversampling = <8>;
};

channel@7 {
reg = <7>;
zephyr,gain = "ADC_GAIN_1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/ {
zephyr,user {
io-channels = <&adc 0>, <&adc 1>, <&adc 7>;
io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>;
};
};

Expand Down Expand Up @@ -39,6 +39,16 @@
zephyr,oversampling = <8>;
};

channel@2 {
reg = <2>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_DVDD>; /* 0.9 V internal */
zephyr,resolution = <12>;
zephyr,oversampling = <8>;
};

channel@7 {
reg = <7>;
zephyr,gain = "ADC_GAIN_1";
Expand Down
Loading