All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
@ 2022-11-29 16:45 ` Frank Li
  0 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2022-11-29 16:45 UTC (permalink / raw)
  To: Cai Huoqing, Haibo Chen, Jonathan Cameron, Lars-Peter Clausen,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx

irq flood happen when run
    cat /sys/bus/iio/devices/iio:device0/in_voltage1_raw

imx8qxp_adc_read_raw()
{
	...
	enable irq
	/* adc start */
	writel(1, adc->regs + IMX8QXP_ADR_ADC_SWTRIG);
	^^^^ trigger irq flood.
	wait_for_completion_interruptible_timeout();
	readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO);
	^^^^ clear irq here.
	...
}

There is only FIFO watermark interrupt at this ADC controller.
IRQ line will be assert until software read data from FIFO.
So IRQ flood happen during wait_for_completion_interruptible_timeout().

Move FIFO read into irq handle to avoid irq flood.

Fixes: 1e23dcaa1a9f ("iio: imx8qxp-adc: Add driver support for NXP IMX8QXP ADC")
Cc: stable@vger.kernel.org

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/iio/adc/imx8qxp-adc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c
index 36777b827165..3cfba5c0fa34 100644
--- a/drivers/iio/adc/imx8qxp-adc.c
+++ b/drivers/iio/adc/imx8qxp-adc.c
@@ -86,6 +86,8 @@
 
 #define IMX8QXP_ADC_TIMEOUT		msecs_to_jiffies(100)
 
+#define IMX8QXP_ADC_MAX_FIFO_SIZE		16
+
 struct imx8qxp_adc {
 	struct device *dev;
 	void __iomem *regs;
@@ -95,6 +97,7 @@ struct imx8qxp_adc {
 	/* Serialise ADC channel reads */
 	struct mutex lock;
 	struct completion completion;
+	u32 fifo[IMX8QXP_ADC_MAX_FIFO_SIZE];
 };
 
 #define IMX8QXP_ADC_CHAN(_idx) {				\
@@ -238,8 +241,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev *indio_dev,
 			return ret;
 		}
 
-		*val = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
-				 readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
+		*val = adc->fifo[0];
 
 		mutex_unlock(&adc->lock);
 		return IIO_VAL_INT;
@@ -265,6 +267,7 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
 {
 	struct imx8qxp_adc *adc = dev_id;
 	u32 fifo_count;
+	int i;
 
 	fifo_count = FIELD_GET(IMX8QXP_ADC_FCTRL_FCOUNT_MASK,
 			       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
@@ -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
 	if (fifo_count)
 		complete(&adc->completion);
 
+	for (i = 0; i < fifo_count; i++)
+		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
+				readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
+
 	return IRQ_HANDLED;
 }
 
-- 
2.34.1


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

* [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
@ 2022-11-29 16:45 ` Frank Li
  0 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2022-11-29 16:45 UTC (permalink / raw)
  To: Cai Huoqing, Haibo Chen, Jonathan Cameron, Lars-Peter Clausen,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx

irq flood happen when run
    cat /sys/bus/iio/devices/iio:device0/in_voltage1_raw

imx8qxp_adc_read_raw()
{
	...
	enable irq
	/* adc start */
	writel(1, adc->regs + IMX8QXP_ADR_ADC_SWTRIG);
	^^^^ trigger irq flood.
	wait_for_completion_interruptible_timeout();
	readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO);
	^^^^ clear irq here.
	...
}

There is only FIFO watermark interrupt at this ADC controller.
IRQ line will be assert until software read data from FIFO.
So IRQ flood happen during wait_for_completion_interruptible_timeout().

Move FIFO read into irq handle to avoid irq flood.

Fixes: 1e23dcaa1a9f ("iio: imx8qxp-adc: Add driver support for NXP IMX8QXP ADC")
Cc: stable@vger.kernel.org

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/iio/adc/imx8qxp-adc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c
index 36777b827165..3cfba5c0fa34 100644
--- a/drivers/iio/adc/imx8qxp-adc.c
+++ b/drivers/iio/adc/imx8qxp-adc.c
@@ -86,6 +86,8 @@
 
 #define IMX8QXP_ADC_TIMEOUT		msecs_to_jiffies(100)
 
+#define IMX8QXP_ADC_MAX_FIFO_SIZE		16
+
 struct imx8qxp_adc {
 	struct device *dev;
 	void __iomem *regs;
@@ -95,6 +97,7 @@ struct imx8qxp_adc {
 	/* Serialise ADC channel reads */
 	struct mutex lock;
 	struct completion completion;
+	u32 fifo[IMX8QXP_ADC_MAX_FIFO_SIZE];
 };
 
 #define IMX8QXP_ADC_CHAN(_idx) {				\
@@ -238,8 +241,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev *indio_dev,
 			return ret;
 		}
 
-		*val = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
-				 readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
+		*val = adc->fifo[0];
 
 		mutex_unlock(&adc->lock);
 		return IIO_VAL_INT;
@@ -265,6 +267,7 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
 {
 	struct imx8qxp_adc *adc = dev_id;
 	u32 fifo_count;
+	int i;
 
 	fifo_count = FIELD_GET(IMX8QXP_ADC_FCTRL_FCOUNT_MASK,
 			       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
@@ -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
 	if (fifo_count)
 		complete(&adc->completion);
 
+	for (i = 0; i < fifo_count; i++)
+		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
+				readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
+
 	return IRQ_HANDLED;
 }
 
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
  2022-11-29 16:45 ` Frank Li
@ 2022-11-29 16:45   ` Frank Li
  -1 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2022-11-29 16:45 UTC (permalink / raw)
  To: Cai Huoqing, Haibo Chen, Jonathan Cameron, Lars-Peter Clausen,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx

irq flood happen when run
    cat /sys/bus/iio/devices/iio:device0/in_voltage1_raw

imx8qxp_adc_read_raw()
{
	...
	enable irq
	/* adc start */
	writel(1, adc->regs + IMX8QXP_ADR_ADC_SWTRIG);
	^^^^ trigger irq flood.
	wait_for_completion_interruptible_timeout();
	readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO);
	^^^^ clear irq here.
	...
}

There is only FIFO watermark interrupt at this ADC controller.
IRQ line will be assert until software read data from FIFO.
So IRQ flood happen during wait_for_completion_interruptible_timeout().

Move FIFO read into irq handle to avoid irq flood.

Fixes: 1e23dcaa1a9f ("iio: imx8qxp-adc: Add driver support for NXP IMX8QXP ADC")
Cc: stable@vger.kernel.org

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/iio/adc/imx8qxp-adc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c
index 36777b827165..3cfba5c0fa34 100644
--- a/drivers/iio/adc/imx8qxp-adc.c
+++ b/drivers/iio/adc/imx8qxp-adc.c
@@ -86,6 +86,8 @@
 
 #define IMX8QXP_ADC_TIMEOUT		msecs_to_jiffies(100)
 
+#define IMX8QXP_ADC_MAX_FIFO_SIZE		16
+
 struct imx8qxp_adc {
 	struct device *dev;
 	void __iomem *regs;
@@ -95,6 +97,7 @@ struct imx8qxp_adc {
 	/* Serialise ADC channel reads */
 	struct mutex lock;
 	struct completion completion;
+	u32 fifo[IMX8QXP_ADC_MAX_FIFO_SIZE];
 };
 
 #define IMX8QXP_ADC_CHAN(_idx) {				\
@@ -238,8 +241,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev *indio_dev,
 			return ret;
 		}
 
-		*val = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
-				 readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
+		*val = adc->fifo[0];
 
 		mutex_unlock(&adc->lock);
 		return IIO_VAL_INT;
@@ -265,6 +267,7 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
 {
 	struct imx8qxp_adc *adc = dev_id;
 	u32 fifo_count;
+	int i;
 
 	fifo_count = FIELD_GET(IMX8QXP_ADC_FCTRL_FCOUNT_MASK,
 			       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
@@ -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
 	if (fifo_count)
 		complete(&adc->completion);
 
+	for (i = 0; i < fifo_count; i++)
+		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
+				readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
+
 	return IRQ_HANDLED;
 }
 
-- 
2.34.1


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

* [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
@ 2022-11-29 16:45   ` Frank Li
  0 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2022-11-29 16:45 UTC (permalink / raw)
  To: Cai Huoqing, Haibo Chen, Jonathan Cameron, Lars-Peter Clausen,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx

irq flood happen when run
    cat /sys/bus/iio/devices/iio:device0/in_voltage1_raw

imx8qxp_adc_read_raw()
{
	...
	enable irq
	/* adc start */
	writel(1, adc->regs + IMX8QXP_ADR_ADC_SWTRIG);
	^^^^ trigger irq flood.
	wait_for_completion_interruptible_timeout();
	readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO);
	^^^^ clear irq here.
	...
}

There is only FIFO watermark interrupt at this ADC controller.
IRQ line will be assert until software read data from FIFO.
So IRQ flood happen during wait_for_completion_interruptible_timeout().

Move FIFO read into irq handle to avoid irq flood.

Fixes: 1e23dcaa1a9f ("iio: imx8qxp-adc: Add driver support for NXP IMX8QXP ADC")
Cc: stable@vger.kernel.org

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/iio/adc/imx8qxp-adc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c
index 36777b827165..3cfba5c0fa34 100644
--- a/drivers/iio/adc/imx8qxp-adc.c
+++ b/drivers/iio/adc/imx8qxp-adc.c
@@ -86,6 +86,8 @@
 
 #define IMX8QXP_ADC_TIMEOUT		msecs_to_jiffies(100)
 
+#define IMX8QXP_ADC_MAX_FIFO_SIZE		16
+
 struct imx8qxp_adc {
 	struct device *dev;
 	void __iomem *regs;
@@ -95,6 +97,7 @@ struct imx8qxp_adc {
 	/* Serialise ADC channel reads */
 	struct mutex lock;
 	struct completion completion;
+	u32 fifo[IMX8QXP_ADC_MAX_FIFO_SIZE];
 };
 
 #define IMX8QXP_ADC_CHAN(_idx) {				\
@@ -238,8 +241,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev *indio_dev,
 			return ret;
 		}
 
-		*val = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
-				 readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
+		*val = adc->fifo[0];
 
 		mutex_unlock(&adc->lock);
 		return IIO_VAL_INT;
@@ -265,6 +267,7 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
 {
 	struct imx8qxp_adc *adc = dev_id;
 	u32 fifo_count;
+	int i;
 
 	fifo_count = FIELD_GET(IMX8QXP_ADC_FCTRL_FCOUNT_MASK,
 			       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
@@ -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
 	if (fifo_count)
 		complete(&adc->completion);
 
+	for (i = 0; i < fifo_count; i++)
+		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
+				readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
+
 	return IRQ_HANDLED;
 }
 
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
  2022-11-29 16:45 ` Frank Li
@ 2022-11-29 18:23   ` Lars-Peter Clausen
  -1 siblings, 0 replies; 12+ messages in thread
From: Lars-Peter Clausen @ 2022-11-29 18:23 UTC (permalink / raw)
  To: Frank Li, Cai Huoqing, Haibo Chen, Jonathan Cameron, Shawn Guo,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx

On 11/29/22 08:45, Frank Li wrote:
		       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
> @@ -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
>   	if (fifo_count)
>   		complete(&adc->completion);

Shouldn't the completion be triggered after the reading of the samples? 
otherwise you have a race condition on a multi-processor system.

>   
> +	for (i = 0; i < fifo_count; i++)
> +		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> +				readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
> +
>   	return IRQ_HANDLED;
>   }
>   


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
@ 2022-11-29 18:23   ` Lars-Peter Clausen
  0 siblings, 0 replies; 12+ messages in thread
From: Lars-Peter Clausen @ 2022-11-29 18:23 UTC (permalink / raw)
  To: Frank Li, Cai Huoqing, Haibo Chen, Jonathan Cameron, Shawn Guo,
	Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx

On 11/29/22 08:45, Frank Li wrote:
		       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
> @@ -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
>   	if (fifo_count)
>   		complete(&adc->completion);

Shouldn't the completion be triggered after the reading of the samples? 
otherwise you have a race condition on a multi-processor system.

>   
> +	for (i = 0; i < fifo_count; i++)
> +		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> +				readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
> +
>   	return IRQ_HANDLED;
>   }
>   


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

* Re: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
  2022-11-29 18:23   ` Lars-Peter Clausen
@ 2022-11-29 19:49     ` Frank Li
  -1 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2022-11-29 19:49 UTC (permalink / raw)
  To: Lars-Peter Clausen, Cai Huoqing, Bough Chen, Jonathan Cameron,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	dl-linux-imx, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx


> On 11/29/22 08:45, Frank Li wrote:
>                        readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
> > @@ -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void
> *dev_id)
> >       if (fifo_count)
> >               complete(&adc->completion);
> 
> Shouldn't the completion be triggered after the reading of the samples?
> otherwise you have a race condition on a multi-processor system.

Yes, you are right. I will send updated patch soon.

> 
> >
> > +     for (i = 0; i < fifo_count; i++)
> > +             adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> > +                             readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
> > +
> >       return IRQ_HANDLED;
> >   }
> >


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

* Re: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
@ 2022-11-29 19:49     ` Frank Li
  0 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2022-11-29 19:49 UTC (permalink / raw)
  To: Lars-Peter Clausen, Cai Huoqing, Bough Chen, Jonathan Cameron,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	dl-linux-imx, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx


> On 11/29/22 08:45, Frank Li wrote:
>                        readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
> > @@ -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void
> *dev_id)
> >       if (fifo_count)
> >               complete(&adc->completion);
> 
> Shouldn't the completion be triggered after the reading of the samples?
> otherwise you have a race condition on a multi-processor system.

Yes, you are right. I will send updated patch soon.

> 
> >
> > +     for (i = 0; i < fifo_count; i++)
> > +             adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> > +                             readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
> > +
> >       return IRQ_HANDLED;
> >   }
> >

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* RE: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
  2022-11-29 16:45   ` Frank Li
@ 2022-11-30  9:58     ` Bough Chen
  -1 siblings, 0 replies; 12+ messages in thread
From: Bough Chen @ 2022-11-30  9:58 UTC (permalink / raw)
  To: Frank Li, Cai Huoqing, Jonathan Cameron, Lars-Peter Clausen,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	dl-linux-imx, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx

> -----Original Message-----
> From: Frank Li <frank.li@nxp.com>
> Sent: 2022年11月30日 0:46
> To: Cai Huoqing <cai.huoqing@linux.dev>; Bough Chen <haibo.chen@nxp.com>;
> Jonathan Cameron <jic23@kernel.org>; Lars-Peter Clausen <lars@metafoo.de>;
> Shawn Guo <shawnguo@kernel.org>; Sascha Hauer <s.hauer@pengutronix.de>;
> Pengutronix Kernel Team <kernel@pengutronix.de>; Fabio Estevam
> <festevam@gmail.com>; dl-linux-imx <linux-imx@nxp.com>; open list:NXP i.MX
> 8QXP ADC DRIVER <linux-iio@vger.kernel.org>; moderated
> list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE
> <linux-arm-kernel@lists.infradead.org>; open list <linux-kernel@vger.kernel.org>
> Cc: imx@lists.linux.dev
> Subject: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call
> imx8qxp_adc_read_raw()
> 
> irq flood happen when run
>     cat /sys/bus/iio/devices/iio:device0/in_voltage1_raw
> 
> imx8qxp_adc_read_raw()
> {
> 	...
> 	enable irq
> 	/* adc start */
> 	writel(1, adc->regs + IMX8QXP_ADR_ADC_SWTRIG);
> 	^^^^ trigger irq flood.
> 	wait_for_completion_interruptible_timeout();
> 	readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO);
> 	^^^^ clear irq here.
> 	...
> }
> 
> There is only FIFO watermark interrupt at this ADC controller.
> IRQ line will be assert until software read data from FIFO.
> So IRQ flood happen during wait_for_completion_interruptible_timeout().
> 
> Move FIFO read into irq handle to avoid irq flood.
> 
> Fixes: 1e23dcaa1a9f ("iio: imx8qxp-adc: Add driver support for NXP IMX8QXP
> ADC")
> Cc: stable@vger.kernel.org
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
>  drivers/iio/adc/imx8qxp-adc.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c index
> 36777b827165..3cfba5c0fa34 100644
> --- a/drivers/iio/adc/imx8qxp-adc.c
> +++ b/drivers/iio/adc/imx8qxp-adc.c
> @@ -86,6 +86,8 @@
> 
>  #define IMX8QXP_ADC_TIMEOUT		msecs_to_jiffies(100)
> 
> +#define IMX8QXP_ADC_MAX_FIFO_SIZE		16
> +
>  struct imx8qxp_adc {
>  	struct device *dev;
>  	void __iomem *regs;
> @@ -95,6 +97,7 @@ struct imx8qxp_adc {
>  	/* Serialise ADC channel reads */
>  	struct mutex lock;
>  	struct completion completion;
> +	u32 fifo[IMX8QXP_ADC_MAX_FIFO_SIZE];
>  };
> 
>  #define IMX8QXP_ADC_CHAN(_idx) {				\
> @@ -238,8 +241,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev
> *indio_dev,
>  			return ret;
>  		}
> 
> -		*val = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> -				 readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
> +		*val = adc->fifo[0];
> 
>  		mutex_unlock(&adc->lock);
>  		return IIO_VAL_INT;
> @@ -265,6 +267,7 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
> {
>  	struct imx8qxp_adc *adc = dev_id;
>  	u32 fifo_count;
> +	int i;
> 
>  	fifo_count = FIELD_GET(IMX8QXP_ADC_FCTRL_FCOUNT_MASK,
>  			       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL)); @@
> -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
>  	if (fifo_count)
>  		complete(&adc->completion);
> 
> +	for (i = 0; i < fifo_count; i++)
> +		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> +				readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));

Hi Frank,

Since the ADC mode is config as single-ended 12-bit conversion, every time when trigger the ADC conversion, only one 12-bit data push into fifo.
And we also config the fifo watermark as 1. So here only need to read once. I already confirmed on my board.

Best Regards
Haibo Chen
> +
>  	return IRQ_HANDLED;
>  }
> 
> --
> 2.34.1


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

* RE: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
@ 2022-11-30  9:58     ` Bough Chen
  0 siblings, 0 replies; 12+ messages in thread
From: Bough Chen @ 2022-11-30  9:58 UTC (permalink / raw)
  To: Frank Li, Cai Huoqing, Jonathan Cameron, Lars-Peter Clausen,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	dl-linux-imx, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx

> -----Original Message-----
> From: Frank Li <frank.li@nxp.com>
> Sent: 2022年11月30日 0:46
> To: Cai Huoqing <cai.huoqing@linux.dev>; Bough Chen <haibo.chen@nxp.com>;
> Jonathan Cameron <jic23@kernel.org>; Lars-Peter Clausen <lars@metafoo.de>;
> Shawn Guo <shawnguo@kernel.org>; Sascha Hauer <s.hauer@pengutronix.de>;
> Pengutronix Kernel Team <kernel@pengutronix.de>; Fabio Estevam
> <festevam@gmail.com>; dl-linux-imx <linux-imx@nxp.com>; open list:NXP i.MX
> 8QXP ADC DRIVER <linux-iio@vger.kernel.org>; moderated
> list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE
> <linux-arm-kernel@lists.infradead.org>; open list <linux-kernel@vger.kernel.org>
> Cc: imx@lists.linux.dev
> Subject: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call
> imx8qxp_adc_read_raw()
> 
> irq flood happen when run
>     cat /sys/bus/iio/devices/iio:device0/in_voltage1_raw
> 
> imx8qxp_adc_read_raw()
> {
> 	...
> 	enable irq
> 	/* adc start */
> 	writel(1, adc->regs + IMX8QXP_ADR_ADC_SWTRIG);
> 	^^^^ trigger irq flood.
> 	wait_for_completion_interruptible_timeout();
> 	readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO);
> 	^^^^ clear irq here.
> 	...
> }
> 
> There is only FIFO watermark interrupt at this ADC controller.
> IRQ line will be assert until software read data from FIFO.
> So IRQ flood happen during wait_for_completion_interruptible_timeout().
> 
> Move FIFO read into irq handle to avoid irq flood.
> 
> Fixes: 1e23dcaa1a9f ("iio: imx8qxp-adc: Add driver support for NXP IMX8QXP
> ADC")
> Cc: stable@vger.kernel.org
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
>  drivers/iio/adc/imx8qxp-adc.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c index
> 36777b827165..3cfba5c0fa34 100644
> --- a/drivers/iio/adc/imx8qxp-adc.c
> +++ b/drivers/iio/adc/imx8qxp-adc.c
> @@ -86,6 +86,8 @@
> 
>  #define IMX8QXP_ADC_TIMEOUT		msecs_to_jiffies(100)
> 
> +#define IMX8QXP_ADC_MAX_FIFO_SIZE		16
> +
>  struct imx8qxp_adc {
>  	struct device *dev;
>  	void __iomem *regs;
> @@ -95,6 +97,7 @@ struct imx8qxp_adc {
>  	/* Serialise ADC channel reads */
>  	struct mutex lock;
>  	struct completion completion;
> +	u32 fifo[IMX8QXP_ADC_MAX_FIFO_SIZE];
>  };
> 
>  #define IMX8QXP_ADC_CHAN(_idx) {				\
> @@ -238,8 +241,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev
> *indio_dev,
>  			return ret;
>  		}
> 
> -		*val = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> -				 readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));
> +		*val = adc->fifo[0];
> 
>  		mutex_unlock(&adc->lock);
>  		return IIO_VAL_INT;
> @@ -265,6 +267,7 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
> {
>  	struct imx8qxp_adc *adc = dev_id;
>  	u32 fifo_count;
> +	int i;
> 
>  	fifo_count = FIELD_GET(IMX8QXP_ADC_FCTRL_FCOUNT_MASK,
>  			       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL)); @@
> -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
>  	if (fifo_count)
>  		complete(&adc->completion);
> 
> +	for (i = 0; i < fifo_count; i++)
> +		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> +				readl_relaxed(adc->regs + IMX8QXP_ADR_ADC_RESFIFO));

Hi Frank,

Since the ADC mode is config as single-ended 12-bit conversion, every time when trigger the ADC conversion, only one 12-bit data push into fifo.
And we also config the fifo watermark as 1. So here only need to read once. I already confirmed on my board.

Best Regards
Haibo Chen
> +
>  	return IRQ_HANDLED;
>  }
> 
> --
> 2.34.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* RE: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
  2022-11-30  9:58     ` Bough Chen
@ 2022-11-30 14:09       ` Frank Li
  -1 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2022-11-30 14:09 UTC (permalink / raw)
  To: Bough Chen, Cai Huoqing, Jonathan Cameron, Lars-Peter Clausen,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	dl-linux-imx, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx



> -----Original Message-----
> From: Bough Chen <haibo.chen@nxp.com>
> Sent: Wednesday, November 30, 2022 3:58 AM
> To: Frank Li <frank.li@nxp.com>; Cai Huoqing <cai.huoqing@linux.dev>;
> Jonathan Cameron <jic23@kernel.org>; Lars-Peter Clausen
> <lars@metafoo.de>; Shawn Guo <shawnguo@kernel.org>; Sascha Hauer
> <s.hauer@pengutronix.de>; Pengutronix Kernel Team
> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; dl-linux-
> imx <linux-imx@nxp.com>; open list:NXP i.MX 8QXP ADC DRIVER <linux-
> iio@vger.kernel.org>; moderated list:ARM/FREESCALE IMX / MXC ARM
> ARCHITECTURE <linux-arm-kernel@lists.infradead.org>; open list <linux-
> kernel@vger.kernel.org>
> Cc: imx@lists.linux.dev
> Subject: RE: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call
> imx8qxp_adc_read_raw()
> 
> > -----Original Message-----
> > From: Frank Li <frank.li@nxp.com>
> > Sent: 2022年11月30日 0:46
> > To: Cai Huoqing <cai.huoqing@linux.dev>; Bough Chen
> <haibo.chen@nxp.com>;
> > Jonathan Cameron <jic23@kernel.org>; Lars-Peter Clausen
> <lars@metafoo.de>;
> > Shawn Guo <shawnguo@kernel.org>; Sascha Hauer
> <s.hauer@pengutronix.de>;
> > Pengutronix Kernel Team <kernel@pengutronix.de>; Fabio Estevam
> > <festevam@gmail.com>; dl-linux-imx <linux-imx@nxp.com>; open list:NXP
> i.MX
> > 8QXP ADC DRIVER <linux-iio@vger.kernel.org>; moderated
> > list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE
> > <linux-arm-kernel@lists.infradead.org>; open list <linux-
> kernel@vger.kernel.org>
> > Cc: imx@lists.linux.dev
> > Subject: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call
> > imx8qxp_adc_read_raw()
> >
> > irq flood happen when run
> >     cat /sys/bus/iio/devices/iio:device0/in_voltage1_raw
> >
> > imx8qxp_adc_read_raw()
> > {
> > 	...
> > 	enable irq
> > 	/* adc start */
> > 	writel(1, adc->regs + IMX8QXP_ADR_ADC_SWTRIG);
> > 	^^^^ trigger irq flood.
> > 	wait_for_completion_interruptible_timeout();
> > 	readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO);
> > 	^^^^ clear irq here.
> > 	...
> > }
> >
> > There is only FIFO watermark interrupt at this ADC controller.
> > IRQ line will be assert until software read data from FIFO.
> > So IRQ flood happen during wait_for_completion_interruptible_timeout().
> >
> > Move FIFO read into irq handle to avoid irq flood.
> >
> > Fixes: 1e23dcaa1a9f ("iio: imx8qxp-adc: Add driver support for NXP
> IMX8QXP
> > ADC")
> > Cc: stable@vger.kernel.org
> >
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> >  drivers/iio/adc/imx8qxp-adc.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c
> index
> > 36777b827165..3cfba5c0fa34 100644
> > --- a/drivers/iio/adc/imx8qxp-adc.c
> > +++ b/drivers/iio/adc/imx8qxp-adc.c
> > @@ -86,6 +86,8 @@
> >
> >  #define IMX8QXP_ADC_TIMEOUT		msecs_to_jiffies(100)
> >
> > +#define IMX8QXP_ADC_MAX_FIFO_SIZE		16
> > +
> >  struct imx8qxp_adc {
> >  	struct device *dev;
> >  	void __iomem *regs;
> > @@ -95,6 +97,7 @@ struct imx8qxp_adc {
> >  	/* Serialise ADC channel reads */
> >  	struct mutex lock;
> >  	struct completion completion;
> > +	u32 fifo[IMX8QXP_ADC_MAX_FIFO_SIZE];
> >  };
> >
> >  #define IMX8QXP_ADC_CHAN(_idx) {				\
> > @@ -238,8 +241,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev
> > *indio_dev,
> >  			return ret;
> >  		}
> >
> > -		*val = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> > -				 readl(adc->regs +
> IMX8QXP_ADR_ADC_RESFIFO));
> > +		*val = adc->fifo[0];
> >
> >  		mutex_unlock(&adc->lock);
> >  		return IIO_VAL_INT;
> > @@ -265,6 +267,7 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void
> *dev_id)
> > {
> >  	struct imx8qxp_adc *adc = dev_id;
> >  	u32 fifo_count;
> > +	int i;
> >
> >  	fifo_count = FIELD_GET(IMX8QXP_ADC_FCTRL_FCOUNT_MASK,
> >  			       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
> @@
> > -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
> >  	if (fifo_count)
> >  		complete(&adc->completion);
> >
> > +	for (i = 0; i < fifo_count; i++)
> > +		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> > +				readl_relaxed(adc->regs +
> IMX8QXP_ADR_ADC_RESFIFO));
> 
> Hi Frank,
> 
> Since the ADC mode is config as single-ended 12-bit conversion, every time
> when trigger the ADC conversion, only one 12-bit data push into fifo.
> And we also config the fifo watermark as 1. So here only need to read once. I
> already confirmed on my board.

Interrupt handle should guarantee read all data from FIFO.  If somewhere increase
Watermark or set auto continue sample,  irq flood will be happen again.

Best regards
Frank Li 

> 
> Best Regards
> Haibo Chen
> > +
> >  	return IRQ_HANDLED;
> >  }
> >
> > --
> > 2.34.1


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

* RE: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw()
@ 2022-11-30 14:09       ` Frank Li
  0 siblings, 0 replies; 12+ messages in thread
From: Frank Li @ 2022-11-30 14:09 UTC (permalink / raw)
  To: Bough Chen, Cai Huoqing, Jonathan Cameron, Lars-Peter Clausen,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	dl-linux-imx, open list:NXP i.MX 8QXP ADC DRIVER,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	open list
  Cc: imx



> -----Original Message-----
> From: Bough Chen <haibo.chen@nxp.com>
> Sent: Wednesday, November 30, 2022 3:58 AM
> To: Frank Li <frank.li@nxp.com>; Cai Huoqing <cai.huoqing@linux.dev>;
> Jonathan Cameron <jic23@kernel.org>; Lars-Peter Clausen
> <lars@metafoo.de>; Shawn Guo <shawnguo@kernel.org>; Sascha Hauer
> <s.hauer@pengutronix.de>; Pengutronix Kernel Team
> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; dl-linux-
> imx <linux-imx@nxp.com>; open list:NXP i.MX 8QXP ADC DRIVER <linux-
> iio@vger.kernel.org>; moderated list:ARM/FREESCALE IMX / MXC ARM
> ARCHITECTURE <linux-arm-kernel@lists.infradead.org>; open list <linux-
> kernel@vger.kernel.org>
> Cc: imx@lists.linux.dev
> Subject: RE: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call
> imx8qxp_adc_read_raw()
> 
> > -----Original Message-----
> > From: Frank Li <frank.li@nxp.com>
> > Sent: 2022年11月30日 0:46
> > To: Cai Huoqing <cai.huoqing@linux.dev>; Bough Chen
> <haibo.chen@nxp.com>;
> > Jonathan Cameron <jic23@kernel.org>; Lars-Peter Clausen
> <lars@metafoo.de>;
> > Shawn Guo <shawnguo@kernel.org>; Sascha Hauer
> <s.hauer@pengutronix.de>;
> > Pengutronix Kernel Team <kernel@pengutronix.de>; Fabio Estevam
> > <festevam@gmail.com>; dl-linux-imx <linux-imx@nxp.com>; open list:NXP
> i.MX
> > 8QXP ADC DRIVER <linux-iio@vger.kernel.org>; moderated
> > list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE
> > <linux-arm-kernel@lists.infradead.org>; open list <linux-
> kernel@vger.kernel.org>
> > Cc: imx@lists.linux.dev
> > Subject: [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call
> > imx8qxp_adc_read_raw()
> >
> > irq flood happen when run
> >     cat /sys/bus/iio/devices/iio:device0/in_voltage1_raw
> >
> > imx8qxp_adc_read_raw()
> > {
> > 	...
> > 	enable irq
> > 	/* adc start */
> > 	writel(1, adc->regs + IMX8QXP_ADR_ADC_SWTRIG);
> > 	^^^^ trigger irq flood.
> > 	wait_for_completion_interruptible_timeout();
> > 	readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO);
> > 	^^^^ clear irq here.
> > 	...
> > }
> >
> > There is only FIFO watermark interrupt at this ADC controller.
> > IRQ line will be assert until software read data from FIFO.
> > So IRQ flood happen during wait_for_completion_interruptible_timeout().
> >
> > Move FIFO read into irq handle to avoid irq flood.
> >
> > Fixes: 1e23dcaa1a9f ("iio: imx8qxp-adc: Add driver support for NXP
> IMX8QXP
> > ADC")
> > Cc: stable@vger.kernel.org
> >
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> >  drivers/iio/adc/imx8qxp-adc.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/adc/imx8qxp-adc.c b/drivers/iio/adc/imx8qxp-adc.c
> index
> > 36777b827165..3cfba5c0fa34 100644
> > --- a/drivers/iio/adc/imx8qxp-adc.c
> > +++ b/drivers/iio/adc/imx8qxp-adc.c
> > @@ -86,6 +86,8 @@
> >
> >  #define IMX8QXP_ADC_TIMEOUT		msecs_to_jiffies(100)
> >
> > +#define IMX8QXP_ADC_MAX_FIFO_SIZE		16
> > +
> >  struct imx8qxp_adc {
> >  	struct device *dev;
> >  	void __iomem *regs;
> > @@ -95,6 +97,7 @@ struct imx8qxp_adc {
> >  	/* Serialise ADC channel reads */
> >  	struct mutex lock;
> >  	struct completion completion;
> > +	u32 fifo[IMX8QXP_ADC_MAX_FIFO_SIZE];
> >  };
> >
> >  #define IMX8QXP_ADC_CHAN(_idx) {				\
> > @@ -238,8 +241,7 @@ static int imx8qxp_adc_read_raw(struct iio_dev
> > *indio_dev,
> >  			return ret;
> >  		}
> >
> > -		*val = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> > -				 readl(adc->regs +
> IMX8QXP_ADR_ADC_RESFIFO));
> > +		*val = adc->fifo[0];
> >
> >  		mutex_unlock(&adc->lock);
> >  		return IIO_VAL_INT;
> > @@ -265,6 +267,7 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void
> *dev_id)
> > {
> >  	struct imx8qxp_adc *adc = dev_id;
> >  	u32 fifo_count;
> > +	int i;
> >
> >  	fifo_count = FIELD_GET(IMX8QXP_ADC_FCTRL_FCOUNT_MASK,
> >  			       readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL));
> @@
> > -272,6 +275,10 @@ static irqreturn_t imx8qxp_adc_isr(int irq, void *dev_id)
> >  	if (fifo_count)
> >  		complete(&adc->completion);
> >
> > +	for (i = 0; i < fifo_count; i++)
> > +		adc->fifo[i] = FIELD_GET(IMX8QXP_ADC_RESFIFO_VAL_MASK,
> > +				readl_relaxed(adc->regs +
> IMX8QXP_ADR_ADC_RESFIFO));
> 
> Hi Frank,
> 
> Since the ADC mode is config as single-ended 12-bit conversion, every time
> when trigger the ADC conversion, only one 12-bit data push into fifo.
> And we also config the fifo watermark as 1. So here only need to read once. I
> already confirmed on my board.

Interrupt handle should guarantee read all data from FIFO.  If somewhere increase
Watermark or set auto continue sample,  irq flood will be happen again.

Best regards
Frank Li 

> 
> Best Regards
> Haibo Chen
> > +
> >  	return IRQ_HANDLED;
> >  }
> >
> > --
> > 2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-11-30 14:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-29 16:45 [PATCH 1/1] iio: imx8qxp-adc: fix irq flood when call imx8qxp_adc_read_raw() Frank Li
2022-11-29 16:45 ` Frank Li
2022-11-29 16:45 ` Frank Li
2022-11-29 16:45   ` Frank Li
2022-11-30  9:58   ` Bough Chen
2022-11-30  9:58     ` Bough Chen
2022-11-30 14:09     ` Frank Li
2022-11-30 14:09       ` Frank Li
2022-11-29 18:23 ` Lars-Peter Clausen
2022-11-29 18:23   ` Lars-Peter Clausen
2022-11-29 19:49   ` Frank Li
2022-11-29 19:49     ` Frank Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.