Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: imx93_adc: load calibrated values even calibration failed

ADC calibration might fail because of the noise on reference voltage.
To avoid calibration fail, need to meet the following requirement:
ADC reference voltage Noise < 1.8V * 1/2^ENOB

For the case which the ADC reference voltage on board do not meet
the requirement, still load the calibrated values, so ADC can also
work but maybe not that accurate.

Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Primoz Fiser <primoz.fiser@norik.com>
Link: https://patch.msgid.link/20250812-adc-v2-2-0260833f13b8@nxp.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Haibo Chen and committed by
Jonathan Cameron
12c9b09e 6830d3ed

+15 -3
+15 -3
drivers/iio/adc/imx93_adc.c
··· 38 38 #define IMX93_ADC_PCDR6 0x118 39 39 #define IMX93_ADC_PCDR7 0x11C 40 40 #define IMX93_ADC_CALSTAT 0x39C 41 + #define IMX93_ADC_CALCFG0 0x3A0 41 42 42 43 /* ADC bit shift */ 43 44 #define IMX93_ADC_MCR_MODE_MASK BIT(29) ··· 58 57 #define IMX93_ADC_IMR_EOC_MASK BIT(1) 59 58 #define IMX93_ADC_IMR_ECH_MASK BIT(0) 60 59 #define IMX93_ADC_PCDR_CDATA_MASK GENMASK(11, 0) 60 + 61 + #define IMX93_ADC_CALCFG0_LDFAIL_MASK BIT(4) 61 62 62 63 /* ADC status */ 63 64 #define IMX93_ADC_MSR_ADCSTATUS_IDLE 0 ··· 148 145 149 146 static int imx93_adc_calibration(struct imx93_adc *adc) 150 147 { 151 - u32 mcr, msr; 148 + u32 mcr, msr, calcfg; 152 149 int ret; 153 150 154 151 /* make sure ADC in power down mode */ ··· 160 157 writel(mcr, adc->regs + IMX93_ADC_MCR); 161 158 162 159 imx93_adc_power_up(adc); 160 + 161 + /* Enable loading of calibrated values even in fail condition */ 162 + calcfg = readl(adc->regs + IMX93_ADC_CALCFG0); 163 + calcfg |= IMX93_ADC_CALCFG0_LDFAIL_MASK; 164 + writel(calcfg, adc->regs + IMX93_ADC_CALCFG0); 163 165 164 166 /* 165 167 * TODO: we use the default TSAMP/NRSMPL/AVGEN in MCR, ··· 188 180 /* check whether calbration is success or not */ 189 181 msr = readl(adc->regs + IMX93_ADC_MSR); 190 182 if (msr & IMX93_ADC_MSR_CALFAIL_MASK) { 183 + /* 184 + * Only give warning here, this means the noise of the 185 + * reference voltage do not meet the requirement: 186 + * ADC reference voltage Noise < 1.8V * 1/2^ENOB 187 + * And the resault of ADC is not that accurate. 188 + */ 191 189 dev_warn(adc->dev, "ADC calibration failed!\n"); 192 - imx93_adc_power_down(adc); 193 - return -EAGAIN; 194 190 } 195 191 196 192 return 0;