diff mbox series

[5/5] iio: stmpe-adc: Reset possible interrupts

Message ID 20190507143615.28477-5-dev@pschenker.ch (mailing list archive)
State New, archived
Headers show
Series [1/5] iio: stmpe-adc: Add compatible name | expand

Commit Message

Philippe Schenker May 7, 2019, 2:36 p.m. UTC
From: Philippe Schenker <philippe.schenker@toradex.com>

Clear any interrupt that still is on the device on every channel
this driver is activated for in probe and specific channels in
the timeout handler.

Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>

---

 drivers/iio/adc/stmpe-adc.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Jonathan Cameron May 11, 2019, 10:24 a.m. UTC | #1
On Tue,  7 May 2019 16:36:15 +0200
Philippe Schenker <dev@pschenker.ch> wrote:

> From: Philippe Schenker <philippe.schenker@toradex.com>
> 
> Clear any interrupt that still is on the device on every channel
> this driver is activated for in probe and specific channels in
> the timeout handler.
> 
> Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
I'm never particularly clean on blanket resets as they do tend to
hide bugs. However, the probe one is something that would happen anyway
if there was a 'reset' function.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> 
> ---
> 
>  drivers/iio/adc/stmpe-adc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
> index cc752a47444c..a5990e9f2c80 100644
> --- a/drivers/iio/adc/stmpe-adc.c
> +++ b/drivers/iio/adc/stmpe-adc.c
> @@ -80,6 +80,8 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
>  	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
>  
>  	if (ret <= 0) {
> +		stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
> +				STMPE_ADC_CH(info->channel));
>  		mutex_unlock(&info->lock);
>  		return -ETIMEDOUT;
>  	}
> @@ -326,6 +328,9 @@ static int stmpe_adc_probe(struct platform_device *pdev)
>  	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
>  			~(norequest_mask & 0xFF));
>  
> +	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
> +			~(norequest_mask & 0xFF));
> +
>  	return devm_iio_device_register(&pdev->dev, indio_dev);
>  }
>
Philippe Schenker May 13, 2019, 7:47 a.m. UTC | #2
On Sat, 2019-05-11 at 11:24 +0100, Jonathan Cameron wrote:
> On Tue,  7 May 2019 16:36:15 +0200
> Philippe Schenker <dev@pschenker.ch> wrote:
> 
> > From: Philippe Schenker <philippe.schenker@toradex.com>
> > 
> > Clear any interrupt that still is on the device on every channel
> > this driver is activated for in probe and specific channels in
> > the timeout handler.
> > 
> > Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
> I'm never particularly clean on blanket resets as they do tend to
> hide bugs. However, the probe one is something that would happen anyway
> if there was a 'reset' function.
> 
> Applied to the togreg branch of iio.git and pushed out as testing
> for the autobuilders to play with it.
> 
> Thanks,
> 
> Jonathan

You're right about hiding bugs. But if the interrupt for whatever (hardware?)
reason does not occur, it prevents further interrupts as it does not get reset.

So this reset takes care that after a timeout one is still able to read out the
ADC.

Philippe

> 
> > ---
> > 
> >  drivers/iio/adc/stmpe-adc.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
> > index cc752a47444c..a5990e9f2c80 100644
> > --- a/drivers/iio/adc/stmpe-adc.c
> > +++ b/drivers/iio/adc/stmpe-adc.c
> > @@ -80,6 +80,8 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
> >  	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
> >  
> >  	if (ret <= 0) {
> > +		stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
> > +				STMPE_ADC_CH(info->channel));
> >  		mutex_unlock(&info->lock);
> >  		return -ETIMEDOUT;
> >  	}
> > @@ -326,6 +328,9 @@ static int stmpe_adc_probe(struct platform_device *pdev)
> >  	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
> >  			~(norequest_mask & 0xFF));
> >  
> > +	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
> > +			~(norequest_mask & 0xFF));
> > +
> >  	return devm_iio_device_register(&pdev->dev, indio_dev);
> >  }
> >
diff mbox series

Patch

diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
index cc752a47444c..a5990e9f2c80 100644
--- a/drivers/iio/adc/stmpe-adc.c
+++ b/drivers/iio/adc/stmpe-adc.c
@@ -80,6 +80,8 @@  static int stmpe_read_voltage(struct stmpe_adc *info,
 	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
 	if (ret <= 0) {
+		stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
+				STMPE_ADC_CH(info->channel));
 		mutex_unlock(&info->lock);
 		return -ETIMEDOUT;
 	}
@@ -326,6 +328,9 @@  static int stmpe_adc_probe(struct platform_device *pdev)
 	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
 			~(norequest_mask & 0xFF));
 
+	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
+			~(norequest_mask & 0xFF));
+
 	return devm_iio_device_register(&pdev->dev, indio_dev);
 }