mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 01:49:46 +00:00
iio: adc: imx93_adc: load calibrated values even calibration failed
[ Upstream commit 12c9b09e98 ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
71cb5d38a7
commit
5a46feb458
@@ -38,6 +38,7 @@
|
||||
#define IMX93_ADC_PCDR6 0x118
|
||||
#define IMX93_ADC_PCDR7 0x11c
|
||||
#define IMX93_ADC_CALSTAT 0x39C
|
||||
#define IMX93_ADC_CALCFG0 0x3A0
|
||||
|
||||
/* ADC bit shift */
|
||||
#define IMX93_ADC_MCR_MODE_MASK BIT(29)
|
||||
@@ -58,6 +59,8 @@
|
||||
#define IMX93_ADC_IMR_ECH_MASK BIT(0)
|
||||
#define IMX93_ADC_PCDR_CDATA_MASK GENMASK(11, 0)
|
||||
|
||||
#define IMX93_ADC_CALCFG0_LDFAIL_MASK BIT(4)
|
||||
|
||||
/* ADC status */
|
||||
#define IMX93_ADC_MSR_ADCSTATUS_IDLE 0
|
||||
#define IMX93_ADC_MSR_ADCSTATUS_POWER_DOWN 1
|
||||
@@ -145,7 +148,7 @@ static void imx93_adc_config_ad_clk(struct imx93_adc *adc)
|
||||
|
||||
static int imx93_adc_calibration(struct imx93_adc *adc)
|
||||
{
|
||||
u32 mcr, msr;
|
||||
u32 mcr, msr, calcfg;
|
||||
int ret;
|
||||
|
||||
/* make sure ADC in power down mode */
|
||||
@@ -158,6 +161,11 @@ static int imx93_adc_calibration(struct imx93_adc *adc)
|
||||
|
||||
imx93_adc_power_up(adc);
|
||||
|
||||
/* Enable loading of calibrated values even in fail condition */
|
||||
calcfg = readl(adc->regs + IMX93_ADC_CALCFG0);
|
||||
calcfg |= IMX93_ADC_CALCFG0_LDFAIL_MASK;
|
||||
writel(calcfg, adc->regs + IMX93_ADC_CALCFG0);
|
||||
|
||||
/*
|
||||
* TODO: we use the default TSAMP/NRSMPL/AVGEN in MCR,
|
||||
* can add the setting of these bit if need in future.
|
||||
@@ -180,9 +188,13 @@ static int imx93_adc_calibration(struct imx93_adc *adc)
|
||||
/* check whether calbration is success or not */
|
||||
msr = readl(adc->regs + IMX93_ADC_MSR);
|
||||
if (msr & IMX93_ADC_MSR_CALFAIL_MASK) {
|
||||
/*
|
||||
* Only give warning here, this means the noise of the
|
||||
* reference voltage do not meet the requirement:
|
||||
* ADC reference voltage Noise < 1.8V * 1/2^ENOB
|
||||
* And the resault of ADC is not that accurate.
|
||||
*/
|
||||
dev_warn(adc->dev, "ADC calibration failed!\n");
|
||||
imx93_adc_power_down(adc);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user