Skip to content

Commit 6951160

Browse files
nandojvembolivar-nordic
authored andcommitted
drivers: afec: sam: Enable sam4e SoCs
Add support to Atmel SAM SAM4E AFEC feature. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 6634d6b commit 6951160

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed

boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
#include <dt-bindings/pinctrl/sam4eXe-pinctrl.h>
77

88
&pinctrl {
9+
afec0_default: afec0_default {
10+
group1 {
11+
pinmux = <PA17X_AFEC0_AD0>,
12+
<PC13X_AFEC0_AD6>;
13+
};
14+
};
15+
afec1_default: afec1_default {
16+
group1 {
17+
pinmux = <PB2X_AFEC1_AD0>,
18+
<PB3X_AFEC1_AD1>;
19+
};
20+
};
21+
922
gmac_mii: gmac_mii {
1023
group1 {
1124
pinmux = <PD0A_GMAC_GTXCK>,

boards/arm/sam4e_xpro/sam4e_xpro.dts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@
126126
clock-frequency = <120000000>;
127127
};
128128

129+
&afec0 {
130+
status = "okay";
131+
132+
pinctrl-0 = <&afec0_default>;
133+
pinctrl-names = "default";
134+
};
135+
136+
&afec1 {
137+
status = "okay";
138+
139+
pinctrl-0 = <&afec1_default>;
140+
pinctrl-names = "default";
141+
};
142+
129143
&twi0 {
130144
status = "okay";
131145

drivers/adc/adc_sam_afec.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2017 comsuisse AG
33
* Copyright (c) 2018 Justin Watson
4+
* Copyright (c) 2023 Gerson Fernando Budke
45
*
56
* SPDX-License-Identifier: Apache-2.0
67
*/
@@ -33,8 +34,10 @@
3334
LOG_MODULE_REGISTER(adc_sam_afec);
3435

3536
#define NUM_CHANNELS 12
36-
3737
#define CONF_ADC_PRESCALER ((SOC_ATMEL_SAM_MCK_FREQ_HZ / 15000000) - 1)
38+
#ifndef AFEC_MR_ONE
39+
#define AFEC_MR_ONE AFEC_MR_ANACH
40+
#endif
3841

3942
typedef void (*cfg_func_t)(const struct device *dev);
4043

@@ -106,11 +109,13 @@ static int adc_sam_channel_setup(const struct device *dev,
106109
return -EINVAL;
107110
}
108111

112+
#ifdef AFEC_11147
109113
/* Set single ended channels to unsigned and differential channels
110114
* to signed conversions.
111115
*/
112116
afec->AFEC_EMR &= ~(AFEC_EMR_SIGNMODE(
113117
AFEC_EMR_SIGNMODE_SE_UNSG_DF_SIGN_Val));
118+
#endif
114119

115120
return 0;
116121
}
@@ -284,9 +289,12 @@ static int adc_sam_init(const struct device *dev)
284289
}
285290

286291
/* Enable PGA and Current Bias. */
287-
afec->AFEC_ACR = AFEC_ACR_PGA0EN
292+
afec->AFEC_ACR = AFEC_ACR_IBCTL(1)
293+
#ifdef AFEC_11147
294+
| AFEC_ACR_PGA0EN
288295
| AFEC_ACR_PGA1EN
289-
| AFEC_ACR_IBCTL(1);
296+
#endif
297+
;
290298

291299
/* Enable AFEC clock in PMC */
292300
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,

dts/arm/atmel/sam4e.dtsi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@
5050
compatible = "mmio-sram";
5151
};
5252

53+
afec0: adc@400b0000 {
54+
compatible = "atmel,sam-afec";
55+
reg = <0x400b0000 0x4000>;
56+
interrupts = <30 0>;
57+
clocks = <&pmc PMC_TYPE_PERIPHERAL 30>;
58+
status = "disabled";
59+
#io-channel-cells = <1>;
60+
};
61+
62+
afec1: adc@400b4000 {
63+
compatible = "atmel,sam-afec";
64+
reg = <0x400b4000 0x4000>;
65+
interrupts = <31 0>;
66+
clocks = <&pmc PMC_TYPE_PERIPHERAL 31>;
67+
status = "disabled";
68+
#io-channel-cells = <1>;
69+
};
70+
5371
eefc: flash-controller@400e0a00 {
5472
compatible = "atmel,sam-flash-controller";
5573
reg = <0x400e0a00 0x200>;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2023, Gerson Fernando Budke
5+
*/
6+
7+
#include <zephyr/dt-bindings/adc/adc.h>
8+
9+
/ {
10+
zephyr,user {
11+
/* adjust channel number according to pinmux in board.dts */
12+
io-channels = <&afec0 0>, <&afec0 6>;
13+
};
14+
};
15+
16+
&afec0 {
17+
#address-cells = <1>;
18+
#size-cells = <0>;
19+
20+
channel@0 {
21+
reg = <0>;
22+
zephyr,gain = "ADC_GAIN_1";
23+
zephyr,reference = "ADC_REF_INTERNAL";
24+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
25+
zephyr,resolution = <12>;
26+
};
27+
28+
channel@6 {
29+
reg = <6>;
30+
zephyr,gain = "ADC_GAIN_1";
31+
zephyr,reference = "ADC_REF_INTERNAL";
32+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
33+
zephyr,resolution = <12>;
34+
};
35+
};

0 commit comments

Comments
 (0)