Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/5] iio: stmpe-adc: Add compatible name
@ 2019-05-07 14:36 Philippe Schenker
  2019-05-07 14:36 ` [PATCH 2/5] iio: stmpe-adc: Reinit completion struct on begin conversion Philippe Schenker
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Philippe Schenker @ 2019-05-07 14:36 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, Stefan Agner, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler
  Cc: Marcel Ziswiler, David Laight, dev, Philippe Schenker,
	Max Krummenacher, Alexandre Torgue, linux-kernel, Lee Jones,
	Maxime Coquelin, linux-stm32, linux-arm-kernel

From: Philippe Schenker <philippe.schenker@toradex.com>

Add the compatible name to the driver so it gets loaded when the proper
node in DT is detected.

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

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

diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
index 37f4b74a5d32..9ec338ba3440 100644
--- a/drivers/iio/adc/stmpe-adc.c
+++ b/drivers/iio/adc/stmpe-adc.c
@@ -354,9 +354,14 @@ static struct platform_driver stmpe_adc_driver = {
 		.pm	= &stmpe_adc_pm_ops,
 	},
 };
-
 module_platform_driver(stmpe_adc_driver);
 
+static const struct of_device_id stmpe_adc_ids[] = {
+	{ .compatible = "st,stmpe-adc", },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, stmpe_adc_ids);
+
 MODULE_AUTHOR("Stefan Agner <stefan.agner@toradex.com>");
 MODULE_DESCRIPTION("STMPEXXX ADC driver");
 MODULE_LICENSE("GPL v2");
-- 
2.21.0


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

* [PATCH 2/5] iio: stmpe-adc: Reinit completion struct on begin conversion
  2019-05-07 14:36 [PATCH 1/5] iio: stmpe-adc: Add compatible name Philippe Schenker
@ 2019-05-07 14:36 ` Philippe Schenker
  2019-05-11 10:08   ` Jonathan Cameron
  2019-05-07 14:36 ` [PATCH 3/5] iio: stmpe-adc: Enable all stmpe-adc interrupts just once Philippe Schenker
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Philippe Schenker @ 2019-05-07 14:36 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, Stefan Agner, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler
  Cc: Marcel Ziswiler, David Laight, dev, Philippe Schenker,
	Max Krummenacher, Alexandre Torgue, linux-kernel, Lee Jones,
	Maxime Coquelin, linux-stm32, linux-arm-kernel

From: Philippe Schenker <philippe.schenker@toradex.com>

In some cases, the wait_completion got interrupted. This caused the
error-handling to mutex_unlock the function. The before turned on
interrupt then got called anyway. In the ISR then completion() was
called causing wrong adc-values returned in a following adc-readout.

Reinitialise completion struct to make sure the counter is zero
when beginning a new adc-conversion.

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

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

diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
index 9ec338ba3440..b3872eb37293 100644
--- a/drivers/iio/adc/stmpe-adc.c
+++ b/drivers/iio/adc/stmpe-adc.c
@@ -65,6 +65,8 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 
 	mutex_lock(&info->lock);
 
+	reinit_completion(&info->completion);
+
 	info->channel = (u8)chan->channel;
 
 	if (info->channel > STMPE_ADC_LAST_NR) {
@@ -105,6 +107,8 @@ static int stmpe_read_temp(struct stmpe_adc *info,
 
 	mutex_lock(&info->lock);
 
+	reinit_completion(&info->completion);
+
 	info->channel = (u8)chan->channel;
 
 	if (info->channel != STMPE_TEMP_CHANNEL) {
-- 
2.21.0


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

* [PATCH 3/5] iio: stmpe-adc: Enable all stmpe-adc interrupts just once
  2019-05-07 14:36 [PATCH 1/5] iio: stmpe-adc: Add compatible name Philippe Schenker
  2019-05-07 14:36 ` [PATCH 2/5] iio: stmpe-adc: Reinit completion struct on begin conversion Philippe Schenker
@ 2019-05-07 14:36 ` Philippe Schenker
  2019-05-11 10:09   ` Jonathan Cameron
  2019-05-07 14:36 ` [PATCH 4/5] iio: stmpe-adc: Use wait_for_completion_timeout Philippe Schenker
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Philippe Schenker @ 2019-05-07 14:36 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, Stefan Agner, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler
  Cc: Marcel Ziswiler, David Laight, dev, Philippe Schenker,
	Max Krummenacher, Alexandre Torgue, linux-kernel, Lee Jones,
	Maxime Coquelin, linux-stm32, linux-arm-kernel

From: Philippe Schenker <philippe.schenker@toradex.com>

This commit will enable the interrupts of all channels handled by this
driver only once in the probe function.

This will improve performance because one byte less has to be written over
i2c on each read out of the adc. On the fastest ADC mode this will improve
read out speed by 15%.

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

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

diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
index b3872eb37293..82b43e4522b6 100644
--- a/drivers/iio/adc/stmpe-adc.c
+++ b/drivers/iio/adc/stmpe-adc.c
@@ -74,9 +74,6 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 		return -EINVAL;
 	}
 
-	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
-			STMPE_ADC_CH(info->channel));
-
 	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
 			STMPE_ADC_CH(info->channel));
 
@@ -336,6 +333,9 @@ static int stmpe_adc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
+			~(norequest_mask & 0xFF));
+
 	return devm_iio_device_register(&pdev->dev, indio_dev);
 }
 
-- 
2.21.0


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

* [PATCH 4/5] iio: stmpe-adc: Use wait_for_completion_timeout
  2019-05-07 14:36 [PATCH 1/5] iio: stmpe-adc: Add compatible name Philippe Schenker
  2019-05-07 14:36 ` [PATCH 2/5] iio: stmpe-adc: Reinit completion struct on begin conversion Philippe Schenker
  2019-05-07 14:36 ` [PATCH 3/5] iio: stmpe-adc: Enable all stmpe-adc interrupts just once Philippe Schenker
@ 2019-05-07 14:36 ` Philippe Schenker
  2019-05-11 10:15   ` Jonathan Cameron
  2019-05-07 14:36 ` [PATCH 5/5] iio: stmpe-adc: Reset possible interrupts Philippe Schenker
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Philippe Schenker @ 2019-05-07 14:36 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, Stefan Agner, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler
  Cc: Marcel Ziswiler, David Laight, dev, Philippe Schenker,
	Max Krummenacher, Alexandre Torgue, linux-kernel, Lee Jones,
	Maxime Coquelin, linux-stm32, linux-arm-kernel

From: Philippe Schenker <philippe.schenker@toradex.com>

Use wait_for_completion_timeout instead of
wait_for_completion_interuptible_timeout.

The interruptible variant gets constantly interrupted if a user
program is compiled with the -pg option.
The killable variant was not used due to the fact that a second
program, reading on this device, that gets killed is then also killing
that wait.

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

 drivers/iio/adc/stmpe-adc.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
index 82b43e4522b6..cc752a47444c 100644
--- a/drivers/iio/adc/stmpe-adc.c
+++ b/drivers/iio/adc/stmpe-adc.c
@@ -77,17 +77,11 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
 	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
 			STMPE_ADC_CH(info->channel));
 
-	*val = info->value;
-
-	ret = wait_for_completion_interruptible_timeout
-		(&info->completion, STMPE_ADC_TIMEOUT);
+	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
 	if (ret <= 0) {
 		mutex_unlock(&info->lock);
-		if (ret == 0)
-			return -ETIMEDOUT;
-		else
-			return ret;
+		return -ETIMEDOUT;
 	}
 
 	*val = info->value;
@@ -116,15 +110,11 @@ static int stmpe_read_temp(struct stmpe_adc *info,
 	stmpe_reg_write(info->stmpe, STMPE_REG_TEMP_CTRL,
 			STMPE_START_ONE_TEMP_CONV);
 
-	ret = wait_for_completion_interruptible_timeout
-		(&info->completion, STMPE_ADC_TIMEOUT);
+	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
 
 	if (ret <= 0) {
 		mutex_unlock(&info->lock);
-		if (ret == 0)
-			return -ETIMEDOUT;
-		else
-			return ret;
+		return -ETIMEDOUT;
 	}
 
 	/*
-- 
2.21.0


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

* [PATCH 5/5] iio: stmpe-adc: Reset possible interrupts
  2019-05-07 14:36 [PATCH 1/5] iio: stmpe-adc: Add compatible name Philippe Schenker
                   ` (2 preceding siblings ...)
  2019-05-07 14:36 ` [PATCH 4/5] iio: stmpe-adc: Use wait_for_completion_timeout Philippe Schenker
@ 2019-05-07 14:36 ` Philippe Schenker
  2019-05-11 10:24   ` Jonathan Cameron
  2019-05-08  7:01 ` [PATCH 1/5] iio: stmpe-adc: Add compatible name Lee Jones
  2019-05-11  9:58 ` Jonathan Cameron
  5 siblings, 1 reply; 15+ messages in thread
From: Philippe Schenker @ 2019-05-07 14:36 UTC (permalink / raw)
  To: linux-iio, Jonathan Cameron, Stefan Agner, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler
  Cc: Marcel Ziswiler, David Laight, dev, Philippe Schenker,
	Max Krummenacher, Alexandre Torgue, linux-kernel, Lee Jones,
	Maxime Coquelin, linux-stm32, linux-arm-kernel

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(+)

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);
 }
 
-- 
2.21.0


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

* Re: [PATCH 1/5] iio: stmpe-adc: Add compatible name
  2019-05-07 14:36 [PATCH 1/5] iio: stmpe-adc: Add compatible name Philippe Schenker
                   ` (3 preceding siblings ...)
  2019-05-07 14:36 ` [PATCH 5/5] iio: stmpe-adc: Reset possible interrupts Philippe Schenker
@ 2019-05-08  7:01 ` Lee Jones
  2019-05-08  7:28   ` Philippe Schenker
  2019-05-11  9:58 ` Jonathan Cameron
  5 siblings, 1 reply; 15+ messages in thread
From: Lee Jones @ 2019-05-08  7:01 UTC (permalink / raw)
  To: Philippe Schenker
  Cc: linux-iio, Jonathan Cameron, Stefan Agner, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, Marcel Ziswiler,
	David Laight, Philippe Schenker, Max Krummenacher,
	Alexandre Torgue, linux-kernel, Maxime Coquelin, linux-stm32,
	linux-arm-kernel

On Tue, 07 May 2019, Philippe Schenker wrote:

> From: Philippe Schenker <philippe.schenker@toradex.com>
> 
> Add the compatible name to the driver so it gets loaded when the proper
> node in DT is detected.
> 
> Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
> ---
> 
>  drivers/iio/adc/stmpe-adc.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Why have you sent this set to me?

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH 1/5] iio: stmpe-adc: Add compatible name
  2019-05-08  7:01 ` [PATCH 1/5] iio: stmpe-adc: Add compatible name Lee Jones
@ 2019-05-08  7:28   ` Philippe Schenker
  0 siblings, 0 replies; 15+ messages in thread
From: Philippe Schenker @ 2019-05-08  7:28 UTC (permalink / raw)
  To: lee.jones
  Cc: linux-stm32, stefan, Marcel Ziswiler, David.Laight, linux-iio,
	alexandre.torgue, jic23, lars, knaack.h, pmeerw,
	Max Krummenacher, linux-arm-kernel, linux-kernel,
	mcoquelin.stm32

On Wed, 2019-05-08 at 08:01 +0100, Lee Jones wrote:
> On Tue, 07 May 2019, Philippe Schenker wrote:
> 
> > From: Philippe Schenker <philippe.schenker@toradex.com>
> > 
> > Add the compatible name to the driver so it gets loaded when the proper
> > node in DT is detected.
> > 
> > Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
> > ---
> > 
> >  drivers/iio/adc/stmpe-adc.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> Why have you sent this set to me?
> 

get_maintainer.pl returned you as a commit signer. You signed the initial commit
of this driver and pulled it back then because it is part of a mfd.

Philippe

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

* Re: [PATCH 1/5] iio: stmpe-adc: Add compatible name
  2019-05-07 14:36 [PATCH 1/5] iio: stmpe-adc: Add compatible name Philippe Schenker
                   ` (4 preceding siblings ...)
  2019-05-08  7:01 ` [PATCH 1/5] iio: stmpe-adc: Add compatible name Lee Jones
@ 2019-05-11  9:58 ` Jonathan Cameron
  5 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2019-05-11  9:58 UTC (permalink / raw)
  To: Philippe Schenker
  Cc: linux-iio, Stefan Agner, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Marcel Ziswiler, David Laight,
	Philippe Schenker, Max Krummenacher, Alexandre Torgue,
	linux-kernel, Lee Jones, Maxime Coquelin, linux-stm32,
	linux-arm-kernel

On Tue,  7 May 2019 16:36:11 +0200
Philippe Schenker <dev@pschenker.ch> wrote:

> From: Philippe Schenker <philippe.schenker@toradex.com>
> 
> Add the compatible name to the driver so it gets loaded when the proper
> node in DT is detected.
> 
> Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
Applied thanks,

Jonathan

> ---
> 
>  drivers/iio/adc/stmpe-adc.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
> index 37f4b74a5d32..9ec338ba3440 100644
> --- a/drivers/iio/adc/stmpe-adc.c
> +++ b/drivers/iio/adc/stmpe-adc.c
> @@ -354,9 +354,14 @@ static struct platform_driver stmpe_adc_driver = {
>  		.pm	= &stmpe_adc_pm_ops,
>  	},
>  };
> -
>  module_platform_driver(stmpe_adc_driver);
>  
> +static const struct of_device_id stmpe_adc_ids[] = {
> +	{ .compatible = "st,stmpe-adc", },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, stmpe_adc_ids);
> +
>  MODULE_AUTHOR("Stefan Agner <stefan.agner@toradex.com>");
>  MODULE_DESCRIPTION("STMPEXXX ADC driver");
>  MODULE_LICENSE("GPL v2");


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

* Re: [PATCH 2/5] iio: stmpe-adc: Reinit completion struct on begin conversion
  2019-05-07 14:36 ` [PATCH 2/5] iio: stmpe-adc: Reinit completion struct on begin conversion Philippe Schenker
@ 2019-05-11 10:08   ` Jonathan Cameron
  2019-05-13  7:26     ` Philippe Schenker
  0 siblings, 1 reply; 15+ messages in thread
From: Jonathan Cameron @ 2019-05-11 10:08 UTC (permalink / raw)
  To: Philippe Schenker
  Cc: linux-iio, Stefan Agner, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Marcel Ziswiler, David Laight,
	Philippe Schenker, Max Krummenacher, Alexandre Torgue,
	linux-kernel, Lee Jones, Maxime Coquelin, linux-stm32,
	linux-arm-kernel

On Tue,  7 May 2019 16:36:12 +0200
Philippe Schenker <dev@pschenker.ch> wrote:

> From: Philippe Schenker <philippe.schenker@toradex.com>
> 
> In some cases, the wait_completion got interrupted. This caused the
> error-handling to mutex_unlock the function. The before turned on
> interrupt then got called anyway. In the ISR then completion() was
> called causing wrong adc-values returned in a following adc-readout.
> 
> Reinitialise completion struct to make sure the counter is zero
> when beginning a new adc-conversion.
> 
> Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
Hi Philippe, 

To me this looks like a fix that we should consider applying to stable.
However, as it is in the middle of this series I'm not going to take
it via the fast route (during rc's). If people want to backport it
they will have to wait until after the next merge window.
If anyone has an urgent need, then shout in the next week and I'll
pull this version out and we can restructure the set.

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 | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
> index 9ec338ba3440..b3872eb37293 100644
> --- a/drivers/iio/adc/stmpe-adc.c
> +++ b/drivers/iio/adc/stmpe-adc.c
> @@ -65,6 +65,8 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
>  
>  	mutex_lock(&info->lock);
>  
> +	reinit_completion(&info->completion);
> +
>  	info->channel = (u8)chan->channel;
>  
>  	if (info->channel > STMPE_ADC_LAST_NR) {
> @@ -105,6 +107,8 @@ static int stmpe_read_temp(struct stmpe_adc *info,
>  
>  	mutex_lock(&info->lock);
>  
> +	reinit_completion(&info->completion);
> +
>  	info->channel = (u8)chan->channel;
>  
>  	if (info->channel != STMPE_TEMP_CHANNEL) {


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

* Re: [PATCH 3/5] iio: stmpe-adc: Enable all stmpe-adc interrupts just once
  2019-05-07 14:36 ` [PATCH 3/5] iio: stmpe-adc: Enable all stmpe-adc interrupts just once Philippe Schenker
@ 2019-05-11 10:09   ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2019-05-11 10:09 UTC (permalink / raw)
  To: Philippe Schenker
  Cc: linux-iio, Stefan Agner, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Marcel Ziswiler, David Laight,
	Philippe Schenker, Max Krummenacher, Alexandre Torgue,
	linux-kernel, Lee Jones, Maxime Coquelin, linux-stm32,
	linux-arm-kernel

On Tue,  7 May 2019 16:36:13 +0200
Philippe Schenker <dev@pschenker.ch> wrote:

> From: Philippe Schenker <philippe.schenker@toradex.com>
> 
> This commit will enable the interrupts of all channels handled by this
> driver only once in the probe function.
> 
> This will improve performance because one byte less has to be written over
> i2c on each read out of the adc. On the fastest ADC mode this will improve
> read out speed by 15%.
> 
> Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
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 | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
> index b3872eb37293..82b43e4522b6 100644
> --- a/drivers/iio/adc/stmpe-adc.c
> +++ b/drivers/iio/adc/stmpe-adc.c
> @@ -74,9 +74,6 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
>  		return -EINVAL;
>  	}
>  
> -	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
> -			STMPE_ADC_CH(info->channel));
> -
>  	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
>  			STMPE_ADC_CH(info->channel));
>  
> @@ -336,6 +333,9 @@ static int stmpe_adc_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> +	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN,
> +			~(norequest_mask & 0xFF));
> +
>  	return devm_iio_device_register(&pdev->dev, indio_dev);
>  }
>  


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

* Re: [PATCH 4/5] iio: stmpe-adc: Use wait_for_completion_timeout
  2019-05-07 14:36 ` [PATCH 4/5] iio: stmpe-adc: Use wait_for_completion_timeout Philippe Schenker
@ 2019-05-11 10:15   ` Jonathan Cameron
  2019-05-13  7:28     ` Philippe Schenker
  0 siblings, 1 reply; 15+ messages in thread
From: Jonathan Cameron @ 2019-05-11 10:15 UTC (permalink / raw)
  To: Philippe Schenker
  Cc: linux-iio, Stefan Agner, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Marcel Ziswiler, David Laight,
	Philippe Schenker, Max Krummenacher, Alexandre Torgue,
	linux-kernel, Lee Jones, Maxime Coquelin, linux-stm32,
	linux-arm-kernel

On Tue,  7 May 2019 16:36:14 +0200
Philippe Schenker <dev@pschenker.ch> wrote:

> From: Philippe Schenker <philippe.schenker@toradex.com>
> 
> Use wait_for_completion_timeout instead of
> wait_for_completion_interuptible_timeout.
> 
> The interruptible variant gets constantly interrupted if a user
> program is compiled with the -pg option.
> The killable variant was not used due to the fact that a second
> program, reading on this device, that gets killed is then also killing
> that wait.
> 
> Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
Hi Phillippe

This one clashed a little bit with our earlier patch to remove the
unnecessary assignment.  I've applied it by hand but please check it.

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 | 18 ++++--------------
>  1 file changed, 4 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
> index 82b43e4522b6..cc752a47444c 100644
> --- a/drivers/iio/adc/stmpe-adc.c
> +++ b/drivers/iio/adc/stmpe-adc.c
> @@ -77,17 +77,11 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
>  	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
>  			STMPE_ADC_CH(info->channel));
>  
> -	*val = info->value;
> -
> -	ret = wait_for_completion_interruptible_timeout
> -		(&info->completion, STMPE_ADC_TIMEOUT);
> +	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
>  
>  	if (ret <= 0) {
>  		mutex_unlock(&info->lock);
> -		if (ret == 0)
> -			return -ETIMEDOUT;
> -		else
> -			return ret;
> +		return -ETIMEDOUT;
>  	}
>  
>  	*val = info->value;
> @@ -116,15 +110,11 @@ static int stmpe_read_temp(struct stmpe_adc *info,
>  	stmpe_reg_write(info->stmpe, STMPE_REG_TEMP_CTRL,
>  			STMPE_START_ONE_TEMP_CONV);
>  
> -	ret = wait_for_completion_interruptible_timeout
> -		(&info->completion, STMPE_ADC_TIMEOUT);
> +	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
>  
>  	if (ret <= 0) {
>  		mutex_unlock(&info->lock);
> -		if (ret == 0)
> -			return -ETIMEDOUT;
> -		else
> -			return ret;
> +		return -ETIMEDOUT;
>  	}
>  
>  	/*


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

* Re: [PATCH 5/5] iio: stmpe-adc: Reset possible interrupts
  2019-05-07 14:36 ` [PATCH 5/5] iio: stmpe-adc: Reset possible interrupts Philippe Schenker
@ 2019-05-11 10:24   ` Jonathan Cameron
  2019-05-13  7:47     ` Philippe Schenker
  0 siblings, 1 reply; 15+ messages in thread
From: Jonathan Cameron @ 2019-05-11 10:24 UTC (permalink / raw)
  To: Philippe Schenker
  Cc: linux-iio, Stefan Agner, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Marcel Ziswiler, David Laight,
	Philippe Schenker, Max Krummenacher, Alexandre Torgue,
	linux-kernel, Lee Jones, Maxime Coquelin, linux-stm32,
	linux-arm-kernel

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);
>  }
>  


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

* Re: [PATCH 2/5] iio: stmpe-adc: Reinit completion struct on begin conversion
  2019-05-11 10:08   ` Jonathan Cameron
@ 2019-05-13  7:26     ` Philippe Schenker
  0 siblings, 0 replies; 15+ messages in thread
From: Philippe Schenker @ 2019-05-13  7:26 UTC (permalink / raw)
  To: jic23
  Cc: linux-stm32, stefan, Marcel Ziswiler, David.Laight,
	Max Krummenacher, linux-iio, lee.jones, pmeerw, knaack.h,
	mcoquelin.stm32, lars, linux-arm-kernel, linux-kernel,
	alexandre.torgue

On Sat, 2019-05-11 at 11:08 +0100, Jonathan Cameron wrote:
> On Tue,  7 May 2019 16:36:12 +0200
> Philippe Schenker <dev@pschenker.ch> wrote:
> 
> > From: Philippe Schenker <philippe.schenker@toradex.com>
> > 
> > In some cases, the wait_completion got interrupted. This caused the
> > error-handling to mutex_unlock the function. The before turned on
> > interrupt then got called anyway. In the ISR then completion() was
> > called causing wrong adc-values returned in a following adc-readout.
> > 
> > Reinitialise completion struct to make sure the counter is zero
> > when beginning a new adc-conversion.
> > 
> > Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
> Hi Philippe, 
> 
> To me this looks like a fix that we should consider applying to stable.
> However, as it is in the middle of this series I'm not going to take
> it via the fast route (during rc's). If people want to backport it
> they will have to wait until after the next merge window.
> If anyone has an urgent need, then shout in the next week and I'll
> pull this version out and we can restructure the set.
> 
> Applied to the togreg branch of iio.git and pushed out as testing
> for the autobuilders to play with it.
> 
> Thanks,
> 
> Jonathan

Hi Jonathan! I don't think that's necessary. As long as it gets into stable at
some point. Our customer use downstream anyway. Where I'm about to apply it now.

Thanks,
Philippe
> 
> > ---
> > 
> >  drivers/iio/adc/stmpe-adc.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
> > index 9ec338ba3440..b3872eb37293 100644
> > --- a/drivers/iio/adc/stmpe-adc.c
> > +++ b/drivers/iio/adc/stmpe-adc.c
> > @@ -65,6 +65,8 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
> >  
> >  	mutex_lock(&info->lock);
> >  
> > +	reinit_completion(&info->completion);
> > +
> >  	info->channel = (u8)chan->channel;
> >  
> >  	if (info->channel > STMPE_ADC_LAST_NR) {
> > @@ -105,6 +107,8 @@ static int stmpe_read_temp(struct stmpe_adc *info,
> >  
> >  	mutex_lock(&info->lock);
> >  
> > +	reinit_completion(&info->completion);
> > +
> >  	info->channel = (u8)chan->channel;
> >  
> >  	if (info->channel != STMPE_TEMP_CHANNEL) {

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

* Re: [PATCH 4/5] iio: stmpe-adc: Use wait_for_completion_timeout
  2019-05-11 10:15   ` Jonathan Cameron
@ 2019-05-13  7:28     ` Philippe Schenker
  0 siblings, 0 replies; 15+ messages in thread
From: Philippe Schenker @ 2019-05-13  7:28 UTC (permalink / raw)
  To: jic23
  Cc: linux-stm32, stefan, Marcel Ziswiler, David.Laight,
	Max Krummenacher, linux-iio, lee.jones, pmeerw, knaack.h,
	mcoquelin.stm32, lars, linux-arm-kernel, linux-kernel,
	alexandre.torgue

On Sat, 2019-05-11 at 11:15 +0100, Jonathan Cameron wrote:
> On Tue,  7 May 2019 16:36:14 +0200
> Philippe Schenker <dev@pschenker.ch> wrote:
> 
> > From: Philippe Schenker <philippe.schenker@toradex.com>
> > 
> > Use wait_for_completion_timeout instead of
> > wait_for_completion_interuptible_timeout.
> > 
> > The interruptible variant gets constantly interrupted if a user
> > program is compiled with the -pg option.
> > The killable variant was not used due to the fact that a second
> > program, reading on this device, that gets killed is then also killing
> > that wait.
> > 
> > Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
> Hi Phillippe
> 
> This one clashed a little bit with our earlier patch to remove the
> unnecessary assignment.  I've applied it by hand but please check it.
> 
> Applied to the togreg branch of iio.git and pushed out as testing
> for the autobuilders to play with it.
> 
> Thanks,
> 
> Jonathan

Hmm, yeah I see it sorry for that! Somehow that line went in again in this
patch. Don't know why... Anyway I checked it and it looks good. Thank you!

Philippe

> > ---
> > 
> >  drivers/iio/adc/stmpe-adc.c | 18 ++++--------------
> >  1 file changed, 4 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/stmpe-adc.c b/drivers/iio/adc/stmpe-adc.c
> > index 82b43e4522b6..cc752a47444c 100644
> > --- a/drivers/iio/adc/stmpe-adc.c
> > +++ b/drivers/iio/adc/stmpe-adc.c
> > @@ -77,17 +77,11 @@ static int stmpe_read_voltage(struct stmpe_adc *info,
> >  	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
> >  			STMPE_ADC_CH(info->channel));
> >  
> > -	*val = info->value;
> > -
> > -	ret = wait_for_completion_interruptible_timeout
> > -		(&info->completion, STMPE_ADC_TIMEOUT);
> > +	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
> >  
> >  	if (ret <= 0) {
> >  		mutex_unlock(&info->lock);
> > -		if (ret == 0)
> > -			return -ETIMEDOUT;
> > -		else
> > -			return ret;
> > +		return -ETIMEDOUT;
> >  	}
> >  
> >  	*val = info->value;
> > @@ -116,15 +110,11 @@ static int stmpe_read_temp(struct stmpe_adc *info,
> >  	stmpe_reg_write(info->stmpe, STMPE_REG_TEMP_CTRL,
> >  			STMPE_START_ONE_TEMP_CONV);
> >  
> > -	ret = wait_for_completion_interruptible_timeout
> > -		(&info->completion, STMPE_ADC_TIMEOUT);
> > +	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);
> >  
> >  	if (ret <= 0) {
> >  		mutex_unlock(&info->lock);
> > -		if (ret == 0)
> > -			return -ETIMEDOUT;
> > -		else
> > -			return ret;
> > +		return -ETIMEDOUT;
> >  	}
> >  
> >  	/*

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

* Re: [PATCH 5/5] iio: stmpe-adc: Reset possible interrupts
  2019-05-11 10:24   ` Jonathan Cameron
@ 2019-05-13  7:47     ` Philippe Schenker
  0 siblings, 0 replies; 15+ messages in thread
From: Philippe Schenker @ 2019-05-13  7:47 UTC (permalink / raw)
  To: jic23
  Cc: linux-stm32, stefan, Marcel Ziswiler, David.Laight,
	Max Krummenacher, linux-iio, lee.jones, pmeerw, knaack.h,
	mcoquelin.stm32, lars, linux-arm-kernel, linux-kernel,
	alexandre.torgue

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);
> >  }
> >  

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

end of thread, back to index

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-07 14:36 [PATCH 1/5] iio: stmpe-adc: Add compatible name Philippe Schenker
2019-05-07 14:36 ` [PATCH 2/5] iio: stmpe-adc: Reinit completion struct on begin conversion Philippe Schenker
2019-05-11 10:08   ` Jonathan Cameron
2019-05-13  7:26     ` Philippe Schenker
2019-05-07 14:36 ` [PATCH 3/5] iio: stmpe-adc: Enable all stmpe-adc interrupts just once Philippe Schenker
2019-05-11 10:09   ` Jonathan Cameron
2019-05-07 14:36 ` [PATCH 4/5] iio: stmpe-adc: Use wait_for_completion_timeout Philippe Schenker
2019-05-11 10:15   ` Jonathan Cameron
2019-05-13  7:28     ` Philippe Schenker
2019-05-07 14:36 ` [PATCH 5/5] iio: stmpe-adc: Reset possible interrupts Philippe Schenker
2019-05-11 10:24   ` Jonathan Cameron
2019-05-13  7:47     ` Philippe Schenker
2019-05-08  7:01 ` [PATCH 1/5] iio: stmpe-adc: Add compatible name Lee Jones
2019-05-08  7:28   ` Philippe Schenker
2019-05-11  9:58 ` Jonathan Cameron

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox