Skip to content

Commit

Permalink
drivers: adc: sam0: fix compliation for feature SAMs for C21.
Browse files Browse the repository at this point in the history
C21 doesn't have ADC_REFCTRL_REFSEL_AREFB and have different APBs.

Signed-off-by: Kamil Serwus <[email protected]>
  • Loading branch information
benys authored and mbolivar-nordic committed Oct 25, 2022
1 parent 7fccdd1 commit c707f1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/adc/adc_sam0.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ static int adc_sam0_channel_setup(const struct device *dev,
case ADC_REF_EXTERNAL0:
refctrl = ADC_REFCTRL_REFSEL_AREFA;
break;
#ifdef ADC_REFCTRL_REFSEL_AREFB
case ADC_REF_EXTERNAL1:
refctrl = ADC_REFCTRL_REFSEL_AREFB;
break;
#endif
default:
LOG_ERR("Selected reference is not valid");
return -EINVAL;
Expand Down Expand Up @@ -450,7 +452,7 @@ static int adc_sam0_init(const struct device *dev)
#ifdef MCLK
GCLK->PCHCTRL[cfg->gclk_id].reg = cfg->gclk_mask | GCLK_PCHCTRL_CHEN;

MCLK->APBDMASK.reg |= cfg->mclk_mask;
MCLK_ADC |= cfg->mclk_mask;
#else
PM->APBCMASK.bit.ADC_ = 1;

Expand Down
13 changes: 13 additions & 0 deletions soc/arm/atmel_sam0/common/adc_fixup_sam0.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@
#else
# define ADC_SAM0_BIASREFBUF(n) 0
#endif

/*
* The following MCLK clock configuration fix-up symbols map to the applicable
* APB-specific symbols, in order to accommodate different SoC series with the
* ADC core connected to different APBs.
*/
#if defined(MCLK_APBDMASK_ADC) || defined(MCLK_APBDMASK_ADC0)
# define MCLK_ADC (MCLK->APBDMASK.reg)
#elif defined(MCLK_APBCMASK_ADC0)
# define MCLK_ADC (MCLK->APBCMASK.reg)
#else
# error ADC not supported...
#endif
#endif /* MCLK */

/*
Expand Down

0 comments on commit c707f1e

Please sign in to comment.