public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] iio: adc: imx93_adc: load calibrated values even calibration failed
@ 2025-04-23  8:02 Haibo Chen
  2025-04-23 16:43 ` Andy Shevchenko
  2025-06-17  3:07 ` Bough Chen
  0 siblings, 2 replies; 4+ messages in thread
From: Haibo Chen @ 2025-04-23  8:02 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam
  Cc: linux-iio, imx, linux-arm-kernel, linux-kernel, Haibo Chen

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>
---
 drivers/iio/adc/imx93_adc.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/imx93_adc.c b/drivers/iio/adc/imx93_adc.c
index 7feaafd2316f246bd0c32fea99309900b5c65099..ebf976db746f02431a315b1faa86f151bb67132e 100644
--- a/drivers/iio/adc/imx93_adc.c
+++ b/drivers/iio/adc/imx93_adc.c
@@ -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.
@@ -179,11 +187,14 @@ 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) {
+	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 reault of ADC is not that accurate.
+		 */
 		dev_warn(adc->dev, "ADC calibration failed!\n");
-		imx93_adc_power_down(adc);
-		return -EAGAIN;
-	}
 
 	return 0;
 }

---
base-commit: bc8aa6cdadcc00862f2b5720e5de2e17f696a081
change-id: 20250423-adcpatch-cb59c5255961

Best regards,
-- 
Haibo Chen <haibo.chen@nxp.com>



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: adc: imx93_adc: load calibrated values even calibration failed
  2025-04-23  8:02 [PATCH] iio: adc: imx93_adc: load calibrated values even calibration failed Haibo Chen
@ 2025-04-23 16:43 ` Andy Shevchenko
  2025-06-17  3:07 ` Bough Chen
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-04-23 16:43 UTC (permalink / raw)
  To: Haibo Chen
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Shawn Guo,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, linux-iio,
	imx, linux-arm-kernel, linux-kernel

On Wed, Apr 23, 2025 at 04:02:48PM +0800, Haibo Chen wrote:
> 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.

...

>  #define IMX93_ADC_PCDR6		0x118
>  #define IMX93_ADC_PCDR7		0x11c
>  #define IMX93_ADC_CALSTAT	0x39C
> +#define IMX93_ADC_CALCFG0	0X3A0

Please, keep one style of the hex values.
If the small letters are less used, prepare a patch to convert them, otherwise
do that for capital letters.

...

> +	if (msr & IMX93_ADC_MSR_CALFAIL_MASK)

Please keep {} as the body is quite long and it's easy to make a mistake in a
long term.

> +		/*
> +		 * 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 reault of ADC is not that accurate.
> +		 */
>  		dev_warn(adc->dev, "ADC calibration failed!\n");
> -		imx93_adc_power_down(adc);
> -		return -EAGAIN;
> -	}

-- 
With Best Regards,
Andy Shevchenko




^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] iio: adc: imx93_adc: load calibrated values even calibration failed
  2025-04-23  8:02 [PATCH] iio: adc: imx93_adc: load calibrated values even calibration failed Haibo Chen
  2025-04-23 16:43 ` Andy Shevchenko
@ 2025-06-17  3:07 ` Bough Chen
  2025-06-21 15:58   ` Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: Bough Chen @ 2025-06-17  3:07 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam
  Cc: linux-iio@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org

Any comment for this patch?

> -----Original Message-----
> From: Bough Chen <haibo.chen@nxp.com>
> Sent: 2025年4月23日 16:03
> To: Jonathan Cameron <jic23@kernel.org>; David Lechner
> <dlechner@baylibre.com>; Nuno Sá <nuno.sa@analog.com>; Andy Shevchenko
> <andy@kernel.org>; Shawn Guo <shawnguo@kernel.org>; Sascha Hauer
> <s.hauer@pengutronix.de>; Pengutronix Kernel Team
> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>
> Cc: linux-iio@vger.kernel.org; imx@lists.linux.dev;
> linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; Bough
> Chen <haibo.chen@nxp.com>
> Subject: [PATCH] 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>
> ---
>  drivers/iio/adc/imx93_adc.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/adc/imx93_adc.c b/drivers/iio/adc/imx93_adc.c index
> 7feaafd2316f246bd0c32fea99309900b5c65099..ebf976db746f02431a315b1faa
> 86f151bb67132e 100644
> --- a/drivers/iio/adc/imx93_adc.c
> +++ b/drivers/iio/adc/imx93_adc.c
> @@ -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.
> @@ -179,11 +187,14 @@ 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) {
> +	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 reault of ADC is not that accurate.
> +		 */
>  		dev_warn(adc->dev, "ADC calibration failed!\n");
> -		imx93_adc_power_down(adc);
> -		return -EAGAIN;
> -	}
> 
>  	return 0;
>  }
> 
> ---
> base-commit: bc8aa6cdadcc00862f2b5720e5de2e17f696a081
> change-id: 20250423-adcpatch-cb59c5255961
> 
> Best regards,
> --
> Haibo Chen <haibo.chen@nxp.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: adc: imx93_adc: load calibrated values even calibration failed
  2025-06-17  3:07 ` Bough Chen
@ 2025-06-21 15:58   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2025-06-21 15:58 UTC (permalink / raw)
  To: Bough Chen
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, Shawn Guo,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	linux-iio@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org

On Tue, 17 Jun 2025 03:07:11 +0000
Bough Chen <haibo.chen@nxp.com> wrote:

> Any comment for this patch?
I guess you didn't receive this mail from Andy for some reason?

https://lore.kernel.org/all/aAkYvE6VtoQItM5o@smile.fi.intel.com/

There were a few minor requested changes in there.
> 
> > -----Original Message-----
> > From: Bough Chen <haibo.chen@nxp.com>
> > Sent: 2025年4月23日 16:03
> > To: Jonathan Cameron <jic23@kernel.org>; David Lechner
> > <dlechner@baylibre.com>; Nuno Sá <nuno.sa@analog.com>; Andy Shevchenko
> > <andy@kernel.org>; Shawn Guo <shawnguo@kernel.org>; Sascha Hauer
> > <s.hauer@pengutronix.de>; Pengutronix Kernel Team
> > <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>
> > Cc: linux-iio@vger.kernel.org; imx@lists.linux.dev;
> > linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; Bough
> > Chen <haibo.chen@nxp.com>
> > Subject: [PATCH] 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>
> > ---
> >  drivers/iio/adc/imx93_adc.c | 21 ++++++++++++++++-----
> >  1 file changed, 16 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/imx93_adc.c b/drivers/iio/adc/imx93_adc.c index
> > 7feaafd2316f246bd0c32fea99309900b5c65099..ebf976db746f02431a315b1faa
> > 86f151bb67132e 100644
> > --- a/drivers/iio/adc/imx93_adc.c
> > +++ b/drivers/iio/adc/imx93_adc.c
> > @@ -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.
> > @@ -179,11 +187,14 @@ 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) {
> > +	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 reault of ADC is not that accurate.
> > +		 */
> >  		dev_warn(adc->dev, "ADC calibration failed!\n");
> > -		imx93_adc_power_down(adc);
> > -		return -EAGAIN;
> > -	}
> > 
> >  	return 0;
> >  }
> > 
> > ---
> > base-commit: bc8aa6cdadcc00862f2b5720e5de2e17f696a081
> > change-id: 20250423-adcpatch-cb59c5255961
> > 
> > Best regards,
> > --
> > Haibo Chen <haibo.chen@nxp.com>  
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-21 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23  8:02 [PATCH] iio: adc: imx93_adc: load calibrated values even calibration failed Haibo Chen
2025-04-23 16:43 ` Andy Shevchenko
2025-06-17  3:07 ` Bough Chen
2025-06-21 15:58   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox