Skip to content

Commit 7ded40d

Browse files
attie-argentumfabiobaltieri
authored andcommitted
soc: atmel_sam0: The ADC reference is locked while enabled for SAML21
For SAML21-based parts, the REFCTRL register is locked while the ADC is enabled. Permit some parts to declare that they need the ADC to be disabled before modifying REFCTRL. Signed-off-by: Attie Grande <[email protected]>
1 parent adeb181 commit 7ded40d

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

drivers/adc/adc_sam0.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,16 @@ static int adc_sam0_channel_setup(const struct device *dev,
160160
return -EINVAL;
161161
}
162162
if (adc->REFCTRL.reg != refctrl) {
163+
#ifdef ADC_SAM0_REFERENCE_ENABLE_PROTECTED
164+
adc->CTRLA.bit.ENABLE = 0;
165+
wait_synchronization(adc);
166+
#endif
163167
adc->REFCTRL.reg = refctrl;
164168
wait_synchronization(adc);
169+
#ifdef ADC_SAM0_REFERENCE_ENABLE_PROTECTED
170+
adc->CTRLA.bit.ENABLE = 1;
171+
wait_synchronization(adc);
172+
#endif
165173
#ifdef ADC_SAM0_REFERENCE_GLITCH
166174
struct adc_sam0_data *data = dev->data;
167175

soc/arm/atmel_sam0/saml21/soc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
#endif /* _ASMLANGUAGE */
4242

43+
#define ADC_SAM0_REFERENCE_ENABLE_PROTECTED
44+
4345
#include "adc_fixup_sam0.h"
4446
#include "../common/soc_port.h"
4547
#include "../common/atmel_sam0_dt.h"

soc/arm/atmel_sam0/samr34/soc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#endif /* _ASMLANGUAGE */
2626

27+
#define ADC_SAM0_REFERENCE_ENABLE_PROTECTED
28+
2729
#include "adc_fixup_sam0.h"
2830
#include "../common/soc_port.h"
2931
#include "../common/atmel_sam0_dt.h"

soc/arm/atmel_sam0/samr35/soc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#endif /* _ASMLANGUAGE */
2626

27+
#define ADC_SAM0_REFERENCE_ENABLE_PROTECTED
28+
2729
#include "adc_fixup_sam0.h"
2830
#include "../common/soc_port.h"
2931
#include "../common/atmel_sam0_dt.h"

0 commit comments

Comments
 (0)