All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
@ 2013-03-15 16:26 Naveen Krishna Chatradhi
  2013-03-15 21:53   ` Lars-Peter Clausen
                   ` (2 more replies)
  0 siblings, 3 replies; 39+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-03-15 16:26 UTC (permalink / raw)
  To: linux-iio
  Cc: linux-kernel, linux-samsung-soc, dianders, gregkh,
	naveenkrishna.ch, lars

This patch does the following
1. Handle the return values of wait_for_completion_interruptible_timeout
2. Add spin locks to avoid race conditions during ISR.

Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
---
Discussion thread for this patch can be found at
http://www.gossamer-threads.com/lists/linux/kernel/1693284?page=last

I've not seen any reference to spin lock usage in IIO.
Kindly, suggest me if there is a better way to avoid the race.

Thanks,
Naveen
 drivers/iio/adc/exynos_adc.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index ed6fdd7..4de28ae 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -91,6 +91,7 @@ struct exynos_adc {
 
 	struct completion	completion;
 
+	spinlock_t		reg_lock;
 	u32			value;
 	unsigned int            version;
 };
@@ -117,7 +118,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				long mask)
 {
 	struct exynos_adc *info = iio_priv(indio_dev);
-	unsigned long timeout;
+	long timeout;
 	u32 con1, con2;
 
 	if (mask != IIO_CHAN_INFO_RAW)
@@ -143,15 +144,19 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				ADC_V1_CON(info->regs));
 	}
 
+	INIT_COMPLETION(info->completion);
+
 	timeout = wait_for_completion_interruptible_timeout
 			(&info->completion, EXYNOS_ADC_TIMEOUT);
+
 	*val = info->value;
 
 	mutex_unlock(&indio_dev->mlock);
 
 	if (timeout == 0)
 		return -ETIMEDOUT;
-
+	else if (timeout < 0)
+		return timeout;
 	return IIO_VAL_INT;
 }
 
@@ -159,6 +164,8 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
 {
 	struct exynos_adc *info = (struct exynos_adc *)dev_id;
 
+	spin_lock(&info->reg_lock);
+
 	/* Read value */
 	info->value = readl(ADC_V1_DATX(info->regs)) &
 						ADC_DATX_MASK;
@@ -170,6 +177,8 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
 
 	complete(&info->completion);
 
+	spin_unlock(&info->reg_lock);
+
 	return IRQ_HANDLED;
 }
 
@@ -327,6 +336,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
 	else
 		indio_dev->num_channels = MAX_ADC_V2_CHANNELS;
 
+	spin_lock_init(&info->reg_lock);
 	ret = iio_device_register(indio_dev);
 	if (ret)
 		goto err_irq;
-- 
1.7.9.5


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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
       [not found] ` <1363364801-23684-1-git-send-email-ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
@ 2013-03-15 21:53   ` Lars-Peter Clausen
  0 siblings, 0 replies; 39+ messages in thread
From: Lars-Peter Clausen @ 2013-03-15 21:53 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi
  Cc: linux-iio, linux-kernel, linux-samsung-soc, dianders, gregkh,
	naveenkrishna.ch

On 03/15/2013 05:26 PM, Naveen Krishna Chatradhi wrote:
> This patch does the following
> 1. Handle the return values of wait_for_completion_interruptible_timeout
> 2. Add spin locks to avoid race conditions during ISR.
> 
> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
> Cc: Doug Anderson <dianders@chromium.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> ---
> Discussion thread for this patch can be found at
> http://www.gossamer-threads.com/lists/linux/kernel/1693284?page=last
> 
> I've not seen any reference to spin lock usage in IIO.
> Kindly, suggest me if there is a better way to avoid the race.
> 
> Thanks,
> Naveen
>  drivers/iio/adc/exynos_adc.c |   14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index ed6fdd7..4de28ae 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -91,6 +91,7 @@ struct exynos_adc {
>  
>  	struct completion	completion;
>  
> +	spinlock_t		reg_lock;
>  	u32			value;
>  	unsigned int            version;
>  };
> @@ -117,7 +118,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>  				long mask)
>  {
>  	struct exynos_adc *info = iio_priv(indio_dev);
> -	unsigned long timeout;
> +	long timeout;
>  	u32 con1, con2;
>  
>  	if (mask != IIO_CHAN_INFO_RAW)
> @@ -143,15 +144,19 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>  				ADC_V1_CON(info->regs));
>  	}
>  
> +	INIT_COMPLETION(info->completion);
> +

This needs to happen before you start the transfer.


>  	timeout = wait_for_completion_interruptible_timeout
>  			(&info->completion, EXYNOS_ADC_TIMEOUT);
> +
>  	*val = info->value;
>  
>  	mutex_unlock(&indio_dev->mlock);
>  
>  	if (timeout == 0)
>  		return -ETIMEDOUT;
> -
> +	else if (timeout < 0)
> +		return timeout;
>  	return IIO_VAL_INT;
>  }
>  
> @@ -159,6 +164,8 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
>  {
>  	struct exynos_adc *info = (struct exynos_adc *)dev_id;
>  
> +	spin_lock(&info->reg_lock);
> +
>  	/* Read value */
>  	info->value = readl(ADC_V1_DATX(info->regs)) &
>  						ADC_DATX_MASK;
> @@ -170,6 +177,8 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
>  
>  	complete(&info->completion);
>  
> +	spin_unlock(&info->reg_lock);
> +

What exactly is the spinlock protecting against here? Concurrent runs of
exynos_adc_isr? This is probably not issue in the first place.

What you want to protect against is that completion is completed between the
call to INIT_COMPLETION() and the start of a new conversion. So the sections
that need to be under the spinlock are the complete call here and the point
from INIT_COMPLETION until the transfer is started in exynos_read_raw(). Make
sure to use spin_lock_irq there.

>  	return IRQ_HANDLED;
>  }
>  
> @@ -327,6 +336,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
>  	else
>  		indio_dev->num_channels = MAX_ADC_V2_CHANNELS;
>  
> +	spin_lock_init(&info->reg_lock);
>  	ret = iio_device_register(indio_dev);
>  	if (ret)
>  		goto err_irq;


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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
@ 2013-03-15 21:53   ` Lars-Peter Clausen
  0 siblings, 0 replies; 39+ messages in thread
From: Lars-Peter Clausen @ 2013-03-15 21:53 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	dianders-F7+t8E8rja9g9hUCZPvPmw,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w

On 03/15/2013 05:26 PM, Naveen Krishna Chatradhi wrote:
> This patch does the following
> 1. Handle the return values of wait_for_completion_interruptible_timeout
> 2. Add spin locks to avoid race conditions during ISR.
> 
> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
> Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Cc: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
> ---
> Discussion thread for this patch can be found at
> http://www.gossamer-threads.com/lists/linux/kernel/1693284?page=last
> 
> I've not seen any reference to spin lock usage in IIO.
> Kindly, suggest me if there is a better way to avoid the race.
> 
> Thanks,
> Naveen
>  drivers/iio/adc/exynos_adc.c |   14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index ed6fdd7..4de28ae 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -91,6 +91,7 @@ struct exynos_adc {
>  
>  	struct completion	completion;
>  
> +	spinlock_t		reg_lock;
>  	u32			value;
>  	unsigned int            version;
>  };
> @@ -117,7 +118,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>  				long mask)
>  {
>  	struct exynos_adc *info = iio_priv(indio_dev);
> -	unsigned long timeout;
> +	long timeout;
>  	u32 con1, con2;
>  
>  	if (mask != IIO_CHAN_INFO_RAW)
> @@ -143,15 +144,19 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>  				ADC_V1_CON(info->regs));
>  	}
>  
> +	INIT_COMPLETION(info->completion);
> +

This needs to happen before you start the transfer.


>  	timeout = wait_for_completion_interruptible_timeout
>  			(&info->completion, EXYNOS_ADC_TIMEOUT);
> +
>  	*val = info->value;
>  
>  	mutex_unlock(&indio_dev->mlock);
>  
>  	if (timeout == 0)
>  		return -ETIMEDOUT;
> -
> +	else if (timeout < 0)
> +		return timeout;
>  	return IIO_VAL_INT;
>  }
>  
> @@ -159,6 +164,8 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
>  {
>  	struct exynos_adc *info = (struct exynos_adc *)dev_id;
>  
> +	spin_lock(&info->reg_lock);
> +
>  	/* Read value */
>  	info->value = readl(ADC_V1_DATX(info->regs)) &
>  						ADC_DATX_MASK;
> @@ -170,6 +177,8 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
>  
>  	complete(&info->completion);
>  
> +	spin_unlock(&info->reg_lock);
> +

What exactly is the spinlock protecting against here? Concurrent runs of
exynos_adc_isr? This is probably not issue in the first place.

What you want to protect against is that completion is completed between the
call to INIT_COMPLETION() and the start of a new conversion. So the sections
that need to be under the spinlock are the complete call here and the point
from INIT_COMPLETION until the transfer is started in exynos_read_raw(). Make
sure to use spin_lock_irq there.

>  	return IRQ_HANDLED;
>  }
>  
> @@ -327,6 +336,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
>  	else
>  		indio_dev->num_channels = MAX_ADC_V2_CHANNELS;
>  
> +	spin_lock_init(&info->reg_lock);
>  	ret = iio_device_register(indio_dev);
>  	if (ret)
>  		goto err_irq;

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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
  2013-03-15 21:53   ` Lars-Peter Clausen
  (?)
@ 2013-03-16  0:37   ` Doug Anderson
  2013-03-16 14:41       ` Lars-Peter Clausen
  -1 siblings, 1 reply; 39+ messages in thread
From: Doug Anderson @ 2013-03-16  0:37 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
	linux-samsung-soc, Greg Kroah-Hartman, Naveen Krishna

On Fri, Mar 15, 2013 at 2:53 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
> What exactly is the spinlock protecting against here? Concurrent runs of
> exynos_adc_isr? This is probably not issue in the first place.
>
> What you want to protect against is that completion is completed between the
> call to INIT_COMPLETION() and the start of a new conversion. So the sections
> that need to be under the spinlock are the complete call here and the point
> from INIT_COMPLETION until the transfer is started in exynos_read_raw(). Make
> sure to use spin_lock_irq there.

...and at that point I _think_ you won't also need the mutex.

A reasonable way to test to see if you've got this all correct would be to:

* Start two processes that are reading from different ADCs that will
report very different values (maybe add a device tree node for adc1 or
adc7 and use those since they're not really connected to
thermistors?).

* Have your two processes read as fast as they can.  This could just
be "while true; do cat /sys/class/hwmon/hwmon0/device/temp1_input;
done"

* Decrease your timeout and maybe(?) sprinkle some random udelays in
the irq handler so that the timeouts happen sometimes but not others.

* Periodically cancel one of the readers with Ctrl-C

If all is working well then you should always get back the right value
from the right reader (and get no crashes).

-Doug

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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
@ 2013-03-16 14:41       ` Lars-Peter Clausen
  0 siblings, 0 replies; 39+ messages in thread
From: Lars-Peter Clausen @ 2013-03-16 14:41 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
	linux-samsung-soc, Greg Kroah-Hartman, Naveen Krishna

On 03/16/2013 01:37 AM, Doug Anderson wrote:
> On Fri, Mar 15, 2013 at 2:53 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>> What exactly is the spinlock protecting against here? Concurrent runs of
>> exynos_adc_isr? This is probably not issue in the first place.
>>
>> What you want to protect against is that completion is completed between the
>> call to INIT_COMPLETION() and the start of a new conversion. So the sections
>> that need to be under the spinlock are the complete call here and the point
>> from INIT_COMPLETION until the transfer is started in exynos_read_raw(). Make
>> sure to use spin_lock_irq there.
> 
> ...and at that point I _think_ you won't also need the mutex.
> 
> A reasonable way to test to see if you've got this all correct would be to:
> 
> * Start two processes that are reading from different ADCs that will
> report very different values (maybe add a device tree node for adc1 or
> adc7 and use those since they're not really connected to
> thermistors?).
> 
> * Have your two processes read as fast as they can.  This could just
> be "while true; do cat /sys/class/hwmon/hwmon0/device/temp1_input;
> done"
> 
> * Decrease your timeout and maybe(?) sprinkle some random udelays in
> the irq handler so that the timeouts happen sometimes but not others.
> 
> * Periodically cancel one of the readers with Ctrl-C
> 
> If all is working well then you should always get back the right value
> from the right reader (and get no crashes).
> 


I think you still need the mutex for serialization, otherwise the requests
would just cancel each other out. Btw. what happens if you start a conversion
while another is still in progress? Is it possible to abort a conversion?

- Lars

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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
@ 2013-03-16 14:41       ` Lars-Peter Clausen
  0 siblings, 0 replies; 39+ messages in thread
From: Lars-Peter Clausen @ 2013-03-16 14:41 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Naveen Krishna Chatradhi, linux-iio,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA, Greg Kroah-Hartman,
	Naveen Krishna

On 03/16/2013 01:37 AM, Doug Anderson wrote:
> On Fri, Mar 15, 2013 at 2:53 PM, Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org> wrote:
>> What exactly is the spinlock protecting against here? Concurrent runs of
>> exynos_adc_isr? This is probably not issue in the first place.
>>
>> What you want to protect against is that completion is completed between the
>> call to INIT_COMPLETION() and the start of a new conversion. So the sections
>> that need to be under the spinlock are the complete call here and the point
>> from INIT_COMPLETION until the transfer is started in exynos_read_raw(). Make
>> sure to use spin_lock_irq there.
> 
> ...and at that point I _think_ you won't also need the mutex.
> 
> A reasonable way to test to see if you've got this all correct would be to:
> 
> * Start two processes that are reading from different ADCs that will
> report very different values (maybe add a device tree node for adc1 or
> adc7 and use those since they're not really connected to
> thermistors?).
> 
> * Have your two processes read as fast as they can.  This could just
> be "while true; do cat /sys/class/hwmon/hwmon0/device/temp1_input;
> done"
> 
> * Decrease your timeout and maybe(?) sprinkle some random udelays in
> the irq handler so that the timeouts happen sometimes but not others.
> 
> * Periodically cancel one of the readers with Ctrl-C
> 
> If all is working well then you should always get back the right value
> from the right reader (and get no crashes).
> 


I think you still need the mutex for serialization, otherwise the requests
would just cancel each other out. Btw. what happens if you start a conversion
while another is still in progress? Is it possible to abort a conversion?

- Lars

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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
@ 2013-04-03 17:06         ` Doug Anderson
  0 siblings, 0 replies; 39+ messages in thread
From: Doug Anderson @ 2013-04-03 17:06 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
	linux-samsung-soc, Greg Kroah-Hartman, Naveen Krishna

Lars,

On Sat, Mar 16, 2013 at 7:41 AM, Lars-Peter Clausen <lars@metafoo.de> wrote:
> I think you still need the mutex for serialization, otherwise the requests
> would just cancel each other out. Btw. what happens if you start a conversion
> while another is still in progress? Is it possible to abort a conversion?

I was thinking that the spinlock would just replace the mutex for the
purposes of serialization.

I stepped back a bit, though, and I'm wondering if we're over-thinking
things.  The timeout case should certainly be handled properly (thanks
for pointing it out), but getting a timeout is really not expected and
adding a lot of extra overhead to handle it elegantly seems a bit
much?

Specifically, the mutex means that we have one user of the ADC at a
time, and ADC conversion has nothing variable about it.  The user
manual that I have access to talks about 12-bit conversion happening
in 1 microsecond with a 5MHz input clock or 5 microseconds with a 1MHz
input clock.  Even if someone has clocks configured very differently,
it would be hard to imagine a conversion actually taking a full
second.

...so that means that if the timeout actually fires then something
else fairly drastic has gone wrong.  It's _very_ unlikely that the IRQ
will still go off for this conversion sometime in the future.

To me, total modifications to what's landed already ought to be:

* Change timeout to long (from unsigned long)

* Make sure we return errors (negative results) from
wait_for_completion_interruptible_timeout() properly.

* If we get back a value of 0 from
wait_for_completion_interruptible_timeout() then we should print a
warning and attempt machinations to reset the ADC.  Without ever
seeing real-world situtations that would cause a real timeout these
machinations would be a bit of a guess (is resetting the adc useful
when it's more likely that someone accidentally messed with the clock
tree or power gated the ADC?)...  ...or perhaps a warning and a TODO
in the code would be enough?


Thoughts?

-Doug

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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
@ 2013-04-03 17:06         ` Doug Anderson
  0 siblings, 0 replies; 39+ messages in thread
From: Doug Anderson @ 2013-04-03 17:06 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Naveen Krishna Chatradhi, linux-iio,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA, Greg Kroah-Hartman,
	Naveen Krishna

Lars,

On Sat, Mar 16, 2013 at 7:41 AM, Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org> wrote:
> I think you still need the mutex for serialization, otherwise the requests
> would just cancel each other out. Btw. what happens if you start a conversion
> while another is still in progress? Is it possible to abort a conversion?

I was thinking that the spinlock would just replace the mutex for the
purposes of serialization.

I stepped back a bit, though, and I'm wondering if we're over-thinking
things.  The timeout case should certainly be handled properly (thanks
for pointing it out), but getting a timeout is really not expected and
adding a lot of extra overhead to handle it elegantly seems a bit
much?

Specifically, the mutex means that we have one user of the ADC at a
time, and ADC conversion has nothing variable about it.  The user
manual that I have access to talks about 12-bit conversion happening
in 1 microsecond with a 5MHz input clock or 5 microseconds with a 1MHz
input clock.  Even if someone has clocks configured very differently,
it would be hard to imagine a conversion actually taking a full
second.

...so that means that if the timeout actually fires then something
else fairly drastic has gone wrong.  It's _very_ unlikely that the IRQ
will still go off for this conversion sometime in the future.

To me, total modifications to what's landed already ought to be:

* Change timeout to long (from unsigned long)

* Make sure we return errors (negative results) from
wait_for_completion_interruptible_timeout() properly.

* If we get back a value of 0 from
wait_for_completion_interruptible_timeout() then we should print a
warning and attempt machinations to reset the ADC.  Without ever
seeing real-world situtations that would cause a real timeout these
machinations would be a bit of a guess (is resetting the adc useful
when it's more likely that someone accidentally messed with the clock
tree or power gated the ADC?)...  ...or perhaps a warning and a TODO
in the code would be enough?


Thoughts?

-Doug

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

* [PATCH 14/14] temp: iio: adc: exynos_adc: Handle timeout issues
  2013-03-15 16:26 [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions Naveen Krishna Chatradhi
  2013-03-15 21:53   ` Lars-Peter Clausen
@ 2013-04-04  3:59 ` Naveen Krishna Chatradhi
  2013-04-04  4:09   ` Naveen Krishna Ch
       [not found] ` <1363364801-23684-1-git-send-email-ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
  2 siblings, 1 reply; 39+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-04-04  3:59 UTC (permalink / raw)
  To: linux-iio
  Cc: --linux-samsung, jic23, Naveen Krishna Chatradhi, Doug Anderson,
	Lars-Peter Clausen

From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>

This patch does the following
1. Handle the return values of wait_for_completion_interruptible_timeout
2. Reset software if a timeout happes.

Note: submitted for review at https://patchwork.kernel.org/patch/2279591/

BUG=None
TEST=None

Change-Id: I9858d19ba40353e72ae38a6cbf7e6f400e6d3c22
Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
---
As per the comments from Doug at
http://marc.info/?l=linux-kernel&m=136500878406955&w=3

Changes since v1:
1. Remove the spin lock implememtation and the INIT_COMPLETION
2. Rearrange the code and reset the ADC in cases of timeout.

 drivers/iio/adc/exynos_adc.c | 73 ++++++++++++++++++++++++++------------------
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 5ab0dfd..a6c4df5 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -111,6 +111,35 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
 	return (unsigned int)match->data;
 }
 
+static void exynos_adc_hw_init(struct exynos_adc *info)
+{
+	u32 con1, con2;
+	int delay;
+
+	if (info->version == ADC_V2) {
+		con1 = ADC_V2_CON1_SOFT_RESET;
+		writel(con1, ADC_V2_CON1(info->regs));
+
+		/* ADC H/W requires 25PCLKs before other register access */
+		delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info->clk));
+		udelay(delay);
+
+		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
+			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
+		writel(con2, ADC_V2_CON2(info->regs));
+
+		/* Enable interrupts */
+		writel(1, ADC_V2_INT_EN(info->regs));
+	} else {
+		/* set default prescaler values and Enable prescaler */
+		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
+
+		/* Enable 12-bit ADC resolution */
+		con1 |= ADC_V1_CON_RES;
+		writel(con1, ADC_V1_CON(info->regs));
+	}
+}
+
 static int exynos_read_raw(struct iio_dev *indio_dev,
 				struct iio_chan_spec const *chan,
 				int *val,
@@ -118,8 +147,9 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				long mask)
 {
 	struct exynos_adc *info = iio_priv(indio_dev);
-	unsigned long timeout;
+	long timeout;
 	u32 con1, con2;
+	int ret;
 
 	if (mask != IIO_CHAN_INFO_RAW)
 		return -EINVAL;
@@ -146,14 +176,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 
 	timeout = wait_for_completion_interruptible_timeout
 			(&info->completion, EXYNOS_ADC_TIMEOUT);
-	*val = info->value;
 
-	mutex_unlock(&indio_dev->mlock);
+	if (timeout == 0) {
+		dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
+		exynos_adc_hw_init(info);
+		ret = -ETIMEDOUT;
+	} else if (timeout < 0) {
+		ret = timeout;
+	} else {
+		*val = info->value;
+		ret = IIO_VAL_INT;
+	}
 
-	if (timeout == 0)
-		return -ETIMEDOUT;
+	mutex_unlock(&indio_dev->mlock);
 
-	return IIO_VAL_INT;
+	return ret;
 }
 
 static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
@@ -225,30 +262,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
 	return 0;
 }
 
-static void exynos_adc_hw_init(struct exynos_adc *info)
-{
-	u32 con1, con2;
-
-	if (info->version == ADC_V2) {
-		con1 = ADC_V2_CON1_SOFT_RESET;
-		writel(con1, ADC_V2_CON1(info->regs));
-
-		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
-			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
-		writel(con2, ADC_V2_CON2(info->regs));
-
-		/* Enable interrupts */
-		writel(1, ADC_V2_INT_EN(info->regs));
-	} else {
-		/* set default prescaler values and Enable prescaler */
-		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
-
-		/* Enable 12-bit ADC resolution */
-		con1 |= ADC_V1_CON_RES;
-		writel(con1, ADC_V1_CON(info->regs));
-	}
-}
-
 static int exynos_adc_probe(struct platform_device *pdev)
 {
 	struct exynos_adc *info = NULL;
-- 
1.7.12.4


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

* [PATCH] iio: adc: exynos_adc: Handle timeout issues
  2013-03-15 16:26 [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions Naveen Krishna Chatradhi
@ 2013-04-04  4:06     ` Naveen Krishna Chatradhi
  2013-04-04  3:59 ` [PATCH 14/14] temp: iio: adc: exynos_adc: Handle timeout issues Naveen Krishna Chatradhi
       [not found] ` <1363364801-23684-1-git-send-email-ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
  2 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-04-04  4:06 UTC (permalink / raw)
  To: linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	jic23-KWPb1pKIrIJaa/9Udqfwiw, Naveen Krishna Chatradhi,
	Doug Anderson, Lars-Peter Clausen

From: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>

This patch does the following
1. Handle the return values of wait_for_completion_interruptible_timeout
2. Reset software if a timeout happes.

Note: submitted for review at https://patchwork.kernel.org/patch/2279591/

Signed-off-by: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
---
As per the comments from Doug at
http://marc.info/?l=linux-kernel&m=136500878406955&w=3

Changes since v1:
1. Remove the spin lock implememtation and the INIT_COMPLETION
2. Rearrange the code and reset the ADC in cases of timeout.

 drivers/iio/adc/exynos_adc.c | 73 ++++++++++++++++++++++++++------------------
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 5ab0dfd..a6c4df5 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -111,6 +111,35 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
 	return (unsigned int)match->data;
 }
 
+static void exynos_adc_hw_init(struct exynos_adc *info)
+{
+	u32 con1, con2;
+	int delay;
+
+	if (info->version == ADC_V2) {
+		con1 = ADC_V2_CON1_SOFT_RESET;
+		writel(con1, ADC_V2_CON1(info->regs));
+
+		/* ADC H/W requires 25PCLKs before other register access */
+		delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info->clk));
+		udelay(delay);
+
+		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
+			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
+		writel(con2, ADC_V2_CON2(info->regs));
+
+		/* Enable interrupts */
+		writel(1, ADC_V2_INT_EN(info->regs));
+	} else {
+		/* set default prescaler values and Enable prescaler */
+		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
+
+		/* Enable 12-bit ADC resolution */
+		con1 |= ADC_V1_CON_RES;
+		writel(con1, ADC_V1_CON(info->regs));
+	}
+}
+
 static int exynos_read_raw(struct iio_dev *indio_dev,
 				struct iio_chan_spec const *chan,
 				int *val,
@@ -118,8 +147,9 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				long mask)
 {
 	struct exynos_adc *info = iio_priv(indio_dev);
-	unsigned long timeout;
+	long timeout;
 	u32 con1, con2;
+	int ret;
 
 	if (mask != IIO_CHAN_INFO_RAW)
 		return -EINVAL;
@@ -146,14 +176,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 
 	timeout = wait_for_completion_interruptible_timeout
 			(&info->completion, EXYNOS_ADC_TIMEOUT);
-	*val = info->value;
 
-	mutex_unlock(&indio_dev->mlock);
+	if (timeout == 0) {
+		dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
+		exynos_adc_hw_init(info);
+		ret = -ETIMEDOUT;
+	} else if (timeout < 0) {
+		ret = timeout;
+	} else {
+		*val = info->value;
+		ret = IIO_VAL_INT;
+	}
 
-	if (timeout == 0)
-		return -ETIMEDOUT;
+	mutex_unlock(&indio_dev->mlock);
 
-	return IIO_VAL_INT;
+	return ret;
 }
 
 static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
@@ -225,30 +262,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
 	return 0;
 }
 
-static void exynos_adc_hw_init(struct exynos_adc *info)
-{
-	u32 con1, con2;
-
-	if (info->version == ADC_V2) {
-		con1 = ADC_V2_CON1_SOFT_RESET;
-		writel(con1, ADC_V2_CON1(info->regs));
-
-		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
-			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
-		writel(con2, ADC_V2_CON2(info->regs));
-
-		/* Enable interrupts */
-		writel(1, ADC_V2_INT_EN(info->regs));
-	} else {
-		/* set default prescaler values and Enable prescaler */
-		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
-
-		/* Enable 12-bit ADC resolution */
-		con1 |= ADC_V1_CON_RES;
-		writel(con1, ADC_V1_CON(info->regs));
-	}
-}
-
 static int exynos_adc_probe(struct platform_device *pdev)
 {
 	struct exynos_adc *info = NULL;
-- 
1.7.12.4

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

* [PATCH] iio: adc: exynos_adc: Handle timeout issues
@ 2013-04-04  4:06     ` Naveen Krishna Chatradhi
  0 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-04-04  4:06 UTC (permalink / raw)
  To: linux-iio
  Cc: linux-samsung-soc, jic23, Naveen Krishna Chatradhi,
	Doug Anderson, Lars-Peter Clausen

From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>

This patch does the following
1. Handle the return values of wait_for_completion_interruptible_timeout
2. Reset software if a timeout happes.

Note: submitted for review at https://patchwork.kernel.org/patch/2279591/

Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
---
As per the comments from Doug at
http://marc.info/?l=linux-kernel&m=136500878406955&w=3

Changes since v1:
1. Remove the spin lock implememtation and the INIT_COMPLETION
2. Rearrange the code and reset the ADC in cases of timeout.

 drivers/iio/adc/exynos_adc.c | 73 ++++++++++++++++++++++++++------------------
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 5ab0dfd..a6c4df5 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -111,6 +111,35 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
 	return (unsigned int)match->data;
 }
 
+static void exynos_adc_hw_init(struct exynos_adc *info)
+{
+	u32 con1, con2;
+	int delay;
+
+	if (info->version == ADC_V2) {
+		con1 = ADC_V2_CON1_SOFT_RESET;
+		writel(con1, ADC_V2_CON1(info->regs));
+
+		/* ADC H/W requires 25PCLKs before other register access */
+		delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info->clk));
+		udelay(delay);
+
+		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
+			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
+		writel(con2, ADC_V2_CON2(info->regs));
+
+		/* Enable interrupts */
+		writel(1, ADC_V2_INT_EN(info->regs));
+	} else {
+		/* set default prescaler values and Enable prescaler */
+		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
+
+		/* Enable 12-bit ADC resolution */
+		con1 |= ADC_V1_CON_RES;
+		writel(con1, ADC_V1_CON(info->regs));
+	}
+}
+
 static int exynos_read_raw(struct iio_dev *indio_dev,
 				struct iio_chan_spec const *chan,
 				int *val,
@@ -118,8 +147,9 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				long mask)
 {
 	struct exynos_adc *info = iio_priv(indio_dev);
-	unsigned long timeout;
+	long timeout;
 	u32 con1, con2;
+	int ret;
 
 	if (mask != IIO_CHAN_INFO_RAW)
 		return -EINVAL;
@@ -146,14 +176,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 
 	timeout = wait_for_completion_interruptible_timeout
 			(&info->completion, EXYNOS_ADC_TIMEOUT);
-	*val = info->value;
 
-	mutex_unlock(&indio_dev->mlock);
+	if (timeout == 0) {
+		dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
+		exynos_adc_hw_init(info);
+		ret = -ETIMEDOUT;
+	} else if (timeout < 0) {
+		ret = timeout;
+	} else {
+		*val = info->value;
+		ret = IIO_VAL_INT;
+	}
 
-	if (timeout == 0)
-		return -ETIMEDOUT;
+	mutex_unlock(&indio_dev->mlock);
 
-	return IIO_VAL_INT;
+	return ret;
 }
 
 static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
@@ -225,30 +262,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
 	return 0;
 }
 
-static void exynos_adc_hw_init(struct exynos_adc *info)
-{
-	u32 con1, con2;
-
-	if (info->version == ADC_V2) {
-		con1 = ADC_V2_CON1_SOFT_RESET;
-		writel(con1, ADC_V2_CON1(info->regs));
-
-		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
-			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
-		writel(con2, ADC_V2_CON2(info->regs));
-
-		/* Enable interrupts */
-		writel(1, ADC_V2_INT_EN(info->regs));
-	} else {
-		/* set default prescaler values and Enable prescaler */
-		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
-
-		/* Enable 12-bit ADC resolution */
-		con1 |= ADC_V1_CON_RES;
-		writel(con1, ADC_V1_CON(info->regs));
-	}
-}
-
 static int exynos_adc_probe(struct platform_device *pdev)
 {
 	struct exynos_adc *info = NULL;
-- 
1.7.12.4


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

* Re: [PATCH 14/14] temp: iio: adc: exynos_adc: Handle timeout issues
  2013-04-04  3:59 ` [PATCH 14/14] temp: iio: adc: exynos_adc: Handle timeout issues Naveen Krishna Chatradhi
@ 2013-04-04  4:09   ` Naveen Krishna Ch
  0 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Ch @ 2013-04-04  4:09 UTC (permalink / raw)
  To: linux-iio
  Cc: jic23, Naveen Krishna Chatradhi, Doug Anderson, Lars-Peter Clausen

On 3 April 2013 20:59, Naveen Krishna Chatradhi
<naveenkrishna.ch@gmail.com> wrote:
> From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
>
> This patch does the following
> 1. Handle the return values of wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happes.
>
> Note: submitted for review at https://patchwork.kernel.org/patch/2279591/
>
> BUG=None
> TEST=None
>
> Change-Id: I9858d19ba40353e72ae38a6cbf7e6f400e6d3c22
Apologize for sending the patch with local changes.

> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
> Cc: Doug Anderson <dianders@chromium.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> ---
> As per the comments from Doug at
> http://marc.info/?l=linux-kernel&m=136500878406955&w=3
>
> Changes since v1:
> 1. Remove the spin lock implememtation and the INIT_COMPLETION
> 2. Rearrange the code and reset the ADC in cases of timeout.
>
>  drivers/iio/adc/exynos_adc.c | 73 ++++++++++++++++++++++++++------------------
>  1 file changed, 43 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index 5ab0dfd..a6c4df5 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -111,6 +111,35 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
>         return (unsigned int)match->data;
>  }
>
> +static void exynos_adc_hw_init(struct exynos_adc *info)
> +{
> +       u32 con1, con2;
> +       int delay;
> +
> +       if (info->version == ADC_V2) {
> +               con1 = ADC_V2_CON1_SOFT_RESET;
> +               writel(con1, ADC_V2_CON1(info->regs));
> +
> +               /* ADC H/W requires 25PCLKs before other register access */
> +               delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info->clk));
> +               udelay(delay);
> +
> +               con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> +                       ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> +               writel(con2, ADC_V2_CON2(info->regs));
> +
> +               /* Enable interrupts */
> +               writel(1, ADC_V2_INT_EN(info->regs));
> +       } else {
> +               /* set default prescaler values and Enable prescaler */
> +               con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> +
> +               /* Enable 12-bit ADC resolution */
> +               con1 |= ADC_V1_CON_RES;
> +               writel(con1, ADC_V1_CON(info->regs));
> +       }
> +}
> +
>  static int exynos_read_raw(struct iio_dev *indio_dev,
>                                 struct iio_chan_spec const *chan,
>                                 int *val,
> @@ -118,8 +147,9 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>                                 long mask)
>  {
>         struct exynos_adc *info = iio_priv(indio_dev);
> -       unsigned long timeout;
> +       long timeout;
>         u32 con1, con2;
> +       int ret;
>
>         if (mask != IIO_CHAN_INFO_RAW)
>                 return -EINVAL;
> @@ -146,14 +176,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>
>         timeout = wait_for_completion_interruptible_timeout
>                         (&info->completion, EXYNOS_ADC_TIMEOUT);
> -       *val = info->value;
>
> -       mutex_unlock(&indio_dev->mlock);
> +       if (timeout == 0) {
> +               dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
> +               exynos_adc_hw_init(info);
> +               ret = -ETIMEDOUT;
> +       } else if (timeout < 0) {
> +               ret = timeout;
> +       } else {
> +               *val = info->value;
> +               ret = IIO_VAL_INT;
> +       }
>
> -       if (timeout == 0)
> -               return -ETIMEDOUT;
> +       mutex_unlock(&indio_dev->mlock);
>
> -       return IIO_VAL_INT;
> +       return ret;
>  }
>
>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
> @@ -225,30 +262,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
>         return 0;
>  }
>
> -static void exynos_adc_hw_init(struct exynos_adc *info)
> -{
> -       u32 con1, con2;
> -
> -       if (info->version == ADC_V2) {
> -               con1 = ADC_V2_CON1_SOFT_RESET;
> -               writel(con1, ADC_V2_CON1(info->regs));
> -
> -               con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> -                       ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> -               writel(con2, ADC_V2_CON2(info->regs));
> -
> -               /* Enable interrupts */
> -               writel(1, ADC_V2_INT_EN(info->regs));
> -       } else {
> -               /* set default prescaler values and Enable prescaler */
> -               con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> -
> -               /* Enable 12-bit ADC resolution */
> -               con1 |= ADC_V1_CON_RES;
> -               writel(con1, ADC_V1_CON(info->regs));
> -       }
> -}
> -
>  static int exynos_adc_probe(struct platform_device *pdev)
>  {
>         struct exynos_adc *info = NULL;
> --
> 1.7.12.4
>



--
Shine bright,
(: Nav :)

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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
  2013-04-03 17:06         ` Doug Anderson
  (?)
@ 2013-04-05  8:53         ` Lars-Peter Clausen
  2013-04-05 14:56             ` Doug Anderson
  -1 siblings, 1 reply; 39+ messages in thread
From: Lars-Peter Clausen @ 2013-04-05  8:53 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
	linux-samsung-soc, Greg Kroah-Hartman, Naveen Krishna

On 04/03/2013 07:06 PM, Doug Anderson wrote:
> Lars,
> 
> On Sat, Mar 16, 2013 at 7:41 AM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>> I think you still need the mutex for serialization, otherwise the requests
>> would just cancel each other out. Btw. what happens if you start a conversion
>> while another is still in progress? Is it possible to abort a conversion?
> 
> I was thinking that the spinlock would just replace the mutex for the
> purposes of serialization.
> 

Since we sleep inside the protected section we need to use a mutex.

> I stepped back a bit, though, and I'm wondering if we're over-thinking
> things.  The timeout case should certainly be handled properly (thanks
> for pointing it out), but getting a timeout is really not expected and
> adding a lot of extra overhead to handle it elegantly seems a bit
> much?
> 
> Specifically, the mutex means that we have one user of the ADC at a
> time, and ADC conversion has nothing variable about it.  The user
> manual that I have access to talks about 12-bit conversion happening
> in 1 microsecond with a 5MHz input clock or 5 microseconds with a 1MHz
> input clock.  Even if someone has clocks configured very differently,
> it would be hard to imagine a conversion actually taking a full
> second.
> 
> ...so that means that if the timeout actually fires then something
> else fairly drastic has gone wrong.  It's _very_ unlikely that the IRQ
> will still go off for this conversion sometime in the future.
> 

It's not the timeout case I'm worried about, but the case where the transfer
is interrupted by the user. Even though it is rather unlikely for the
problem to occur we should still try to avoid it, this is one of these
annoying heisenbugs that happen once in a while and nobody is able to
reproduce them.

> To me, total modifications to what's landed already ought to be:
> 
> * Change timeout to long (from unsigned long)
> 
> * Make sure we return errors (negative results) from
> wait_for_completion_interruptible_timeout() properly.
> 
> * If we get back a value of 0 from
> wait_for_completion_interruptible_timeout() then we should print a
> warning and attempt machinations to reset the ADC.  Without ever
> seeing real-world situtations that would cause a real timeout these
> machinations would be a bit of a guess (is resetting the adc useful
> when it's more likely that someone accidentally messed with the clock
> tree or power gated the ADC?)...  ...or perhaps a warning and a TODO
> in the code would be enough?
> 
> 
> Thoughts?

I think most of this is already implemented and Naveen sent a patch to reset
the controller in case of a timeout, which is a good idea and works fine,
but you still should handle the case where the user aborted the transfer.
Just resetting the core should work as well in that case.

- Lars

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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
@ 2013-04-05 14:56             ` Doug Anderson
  0 siblings, 0 replies; 39+ messages in thread
From: Doug Anderson @ 2013-04-05 14:56 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
	linux-samsung-soc, Greg Kroah-Hartman, Naveen Krishna

Lars,

On Fri, Apr 5, 2013 at 1:53 AM, Lars-Peter Clausen <lars@metafoo.de> wrote:
> Since we sleep inside the protected section we need to use a mutex.

Ah, good point.

> It's not the timeout case I'm worried about, but the case where the transfer
> is interrupted by the user. Even though it is rather unlikely for the
> problem to occur we should still try to avoid it, this is one of these
> annoying heisenbugs that happen once in a while and nobody is able to
> reproduce them.

Yes, of course.  Then we can also get extra confidence that the reset
logic works well by stressing out this case...  :)

This makes me think, though.  Given how fast we expect the ADC
transaction to finish, would there be any benefit to making the wait
non-interruptible and then shortening the timeout a whole lot.  If we
shortened to 1ms then we're really not "non-interruptible" for very
long and there's less chance of subtle bugs in the way that reset
works.

-Doug

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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
@ 2013-04-05 14:56             ` Doug Anderson
  0 siblings, 0 replies; 39+ messages in thread
From: Doug Anderson @ 2013-04-05 14:56 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Naveen Krishna Chatradhi, linux-iio,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA, Greg Kroah-Hartman,
	Naveen Krishna

Lars,

On Fri, Apr 5, 2013 at 1:53 AM, Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org> wrote:
> Since we sleep inside the protected section we need to use a mutex.

Ah, good point.

> It's not the timeout case I'm worried about, but the case where the transfer
> is interrupted by the user. Even though it is rather unlikely for the
> problem to occur we should still try to avoid it, this is one of these
> annoying heisenbugs that happen once in a while and nobody is able to
> reproduce them.

Yes, of course.  Then we can also get extra confidence that the reset
logic works well by stressing out this case...  :)

This makes me think, though.  Given how fast we expect the ADC
transaction to finish, would there be any benefit to making the wait
non-interruptible and then shortening the timeout a whole lot.  If we
shortened to 1ms then we're really not "non-interruptible" for very
long and there's less chance of subtle bugs in the way that reset
works.

-Doug

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

* Re: [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions
  2013-04-05 14:56             ` Doug Anderson
  (?)
@ 2013-04-05 16:38             ` Lars-Peter Clausen
  -1 siblings, 0 replies; 39+ messages in thread
From: Lars-Peter Clausen @ 2013-04-05 16:38 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
	linux-samsung-soc, Greg Kroah-Hartman, Naveen Krishna

On 04/05/2013 04:56 PM, Doug Anderson wrote:
> Lars,
> 
> On Fri, Apr 5, 2013 at 1:53 AM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>> Since we sleep inside the protected section we need to use a mutex.
> 
> Ah, good point.
> 
>> It's not the timeout case I'm worried about, but the case where the transfer
>> is interrupted by the user. Even though it is rather unlikely for the
>> problem to occur we should still try to avoid it, this is one of these
>> annoying heisenbugs that happen once in a while and nobody is able to
>> reproduce them.
> 
> Yes, of course.  Then we can also get extra confidence that the reset
> logic works well by stressing out this case...  :)
> 
> This makes me think, though.  Given how fast we expect the ADC
> transaction to finish, would there be any benefit to making the wait
> non-interruptible and then shortening the timeout a whole lot.  If we
> shortened to 1ms then we're really not "non-interruptible" for very
> long and there's less chance of subtle bugs in the way that reset
> works.

Yes, that could also work.

- Lars

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

* Re: [PATCH] iio: adc: exynos_adc: Handle timeout issues
  2013-04-04  4:06     ` Naveen Krishna Chatradhi
@ 2013-04-13  4:36         ` Naveen Krishna Ch
  -1 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Ch @ 2013-04-13  4:36 UTC (permalink / raw)
  To: linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	jic23-KWPb1pKIrIJaa/9Udqfwiw, Naveen Krishna Chatradhi,
	Doug Anderson, Lars-Peter Clausen

On 4 April 2013 09:36, Naveen Krishna Chatradhi
<naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> From: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
>
> This patch does the following
> 1. Handle the return values of wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happes.
>
> Note: submitted for review at https://patchwork.kernel.org/patch/2279591/
>
> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
> Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Cc: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
> ---
> As per the comments from Doug at
> http://marc.info/?l=linux-kernel&m=136500878406955&w=3
>
> Changes since v1:
> 1. Remove the spin lock implememtation and the INIT_COMPLETION
> 2. Rearrange the code and reset the ADC in cases of timeout.
>
>  drivers/iio/adc/exynos_adc.c | 73 ++++++++++++++++++++++++++------------------
>  1 file changed, 43 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index 5ab0dfd..a6c4df5 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -111,6 +111,35 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
>         return (unsigned int)match->data;
>  }
>
> +static void exynos_adc_hw_init(struct exynos_adc *info)
> +{
> +       u32 con1, con2;
> +       int delay;
> +
> +       if (info->version == ADC_V2) {
> +               con1 = ADC_V2_CON1_SOFT_RESET;
> +               writel(con1, ADC_V2_CON1(info->regs));
> +
> +               /* ADC H/W requires 25PCLKs before other register access */
> +               delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info->clk));
> +               udelay(delay);
> +
> +               con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> +                       ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> +               writel(con2, ADC_V2_CON2(info->regs));
> +
> +               /* Enable interrupts */
> +               writel(1, ADC_V2_INT_EN(info->regs));
> +       } else {
> +               /* set default prescaler values and Enable prescaler */
> +               con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> +
> +               /* Enable 12-bit ADC resolution */
> +               con1 |= ADC_V1_CON_RES;
> +               writel(con1, ADC_V1_CON(info->regs));
> +       }
> +}
> +
>  static int exynos_read_raw(struct iio_dev *indio_dev,
>                                 struct iio_chan_spec const *chan,
>                                 int *val,
> @@ -118,8 +147,9 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>                                 long mask)
>  {
>         struct exynos_adc *info = iio_priv(indio_dev);
> -       unsigned long timeout;
> +       long timeout;
>         u32 con1, con2;
> +       int ret;
>
>         if (mask != IIO_CHAN_INFO_RAW)
>                 return -EINVAL;
> @@ -146,14 +176,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>
>         timeout = wait_for_completion_interruptible_timeout
>                         (&info->completion, EXYNOS_ADC_TIMEOUT);
> -       *val = info->value;
>
> -       mutex_unlock(&indio_dev->mlock);
> +       if (timeout == 0) {
> +               dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
> +               exynos_adc_hw_init(info);
> +               ret = -ETIMEDOUT;
> +       } else if (timeout < 0) {
> +               ret = timeout;
> +       } else {
> +               *val = info->value;
> +               ret = IIO_VAL_INT;
> +       }
>
> -       if (timeout == 0)
> -               return -ETIMEDOUT;
> +       mutex_unlock(&indio_dev->mlock);
>
> -       return IIO_VAL_INT;
> +       return ret;
>  }
>
>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
> @@ -225,30 +262,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
>         return 0;
>  }
>
> -static void exynos_adc_hw_init(struct exynos_adc *info)
> -{
> -       u32 con1, con2;
> -
> -       if (info->version == ADC_V2) {
> -               con1 = ADC_V2_CON1_SOFT_RESET;
> -               writel(con1, ADC_V2_CON1(info->regs));
> -
> -               con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> -                       ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> -               writel(con2, ADC_V2_CON2(info->regs));
> -
> -               /* Enable interrupts */
> -               writel(1, ADC_V2_INT_EN(info->regs));
> -       } else {
> -               /* set default prescaler values and Enable prescaler */
> -               con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> -
> -               /* Enable 12-bit ADC resolution */
> -               con1 |= ADC_V1_CON_RES;
> -               writel(con1, ADC_V1_CON(info->regs));
> -       }
> -}
> -
>  static int exynos_adc_probe(struct platform_device *pdev)
>  {
>         struct exynos_adc *info = NULL;
> --
> 1.7.12.4
Hello All,

Can some one review this and get this fix into the tree.
>



--
Shine bright,
(: Nav :)

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

* Re: [PATCH] iio: adc: exynos_adc: Handle timeout issues
@ 2013-04-13  4:36         ` Naveen Krishna Ch
  0 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Ch @ 2013-04-13  4:36 UTC (permalink / raw)
  To: linux-iio
  Cc: linux-samsung-soc, jic23, Naveen Krishna Chatradhi,
	Doug Anderson, Lars-Peter Clausen

On 4 April 2013 09:36, Naveen Krishna Chatradhi
<naveenkrishna.ch@gmail.com> wrote:
> From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
>
> This patch does the following
> 1. Handle the return values of wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happes.
>
> Note: submitted for review at https://patchwork.kernel.org/patch/2279591/
>
> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
> Cc: Doug Anderson <dianders@chromium.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> ---
> As per the comments from Doug at
> http://marc.info/?l=linux-kernel&m=136500878406955&w=3
>
> Changes since v1:
> 1. Remove the spin lock implememtation and the INIT_COMPLETION
> 2. Rearrange the code and reset the ADC in cases of timeout.
>
>  drivers/iio/adc/exynos_adc.c | 73 ++++++++++++++++++++++++++------------------
>  1 file changed, 43 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index 5ab0dfd..a6c4df5 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -111,6 +111,35 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
>         return (unsigned int)match->data;
>  }
>
> +static void exynos_adc_hw_init(struct exynos_adc *info)
> +{
> +       u32 con1, con2;
> +       int delay;
> +
> +       if (info->version == ADC_V2) {
> +               con1 = ADC_V2_CON1_SOFT_RESET;
> +               writel(con1, ADC_V2_CON1(info->regs));
> +
> +               /* ADC H/W requires 25PCLKs before other register access */
> +               delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info->clk));
> +               udelay(delay);
> +
> +               con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> +                       ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> +               writel(con2, ADC_V2_CON2(info->regs));
> +
> +               /* Enable interrupts */
> +               writel(1, ADC_V2_INT_EN(info->regs));
> +       } else {
> +               /* set default prescaler values and Enable prescaler */
> +               con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> +
> +               /* Enable 12-bit ADC resolution */
> +               con1 |= ADC_V1_CON_RES;
> +               writel(con1, ADC_V1_CON(info->regs));
> +       }
> +}
> +
>  static int exynos_read_raw(struct iio_dev *indio_dev,
>                                 struct iio_chan_spec const *chan,
>                                 int *val,
> @@ -118,8 +147,9 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>                                 long mask)
>  {
>         struct exynos_adc *info = iio_priv(indio_dev);
> -       unsigned long timeout;
> +       long timeout;
>         u32 con1, con2;
> +       int ret;
>
>         if (mask != IIO_CHAN_INFO_RAW)
>                 return -EINVAL;
> @@ -146,14 +176,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>
>         timeout = wait_for_completion_interruptible_timeout
>                         (&info->completion, EXYNOS_ADC_TIMEOUT);
> -       *val = info->value;
>
> -       mutex_unlock(&indio_dev->mlock);
> +       if (timeout == 0) {
> +               dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
> +               exynos_adc_hw_init(info);
> +               ret = -ETIMEDOUT;
> +       } else if (timeout < 0) {
> +               ret = timeout;
> +       } else {
> +               *val = info->value;
> +               ret = IIO_VAL_INT;
> +       }
>
> -       if (timeout == 0)
> -               return -ETIMEDOUT;
> +       mutex_unlock(&indio_dev->mlock);
>
> -       return IIO_VAL_INT;
> +       return ret;
>  }
>
>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
> @@ -225,30 +262,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
>         return 0;
>  }
>
> -static void exynos_adc_hw_init(struct exynos_adc *info)
> -{
> -       u32 con1, con2;
> -
> -       if (info->version == ADC_V2) {
> -               con1 = ADC_V2_CON1_SOFT_RESET;
> -               writel(con1, ADC_V2_CON1(info->regs));
> -
> -               con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> -                       ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> -               writel(con2, ADC_V2_CON2(info->regs));
> -
> -               /* Enable interrupts */
> -               writel(1, ADC_V2_INT_EN(info->regs));
> -       } else {
> -               /* set default prescaler values and Enable prescaler */
> -               con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> -
> -               /* Enable 12-bit ADC resolution */
> -               con1 |= ADC_V1_CON_RES;
> -               writel(con1, ADC_V1_CON(info->regs));
> -       }
> -}
> -
>  static int exynos_adc_probe(struct platform_device *pdev)
>  {
>         struct exynos_adc *info = NULL;
> --
> 1.7.12.4
Hello All,

Can some one review this and get this fix into the tree.
>



--
Shine bright,
(: Nav :)

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

* Re: [PATCH] iio: adc: exynos_adc: Handle timeout issues
  2013-04-13  4:36         ` Naveen Krishna Ch
@ 2013-04-15 16:01             ` Doug Anderson
  -1 siblings, 0 replies; 39+ messages in thread
From: Doug Anderson @ 2013-04-15 16:01 UTC (permalink / raw)
  To: Naveen Krishna Ch
  Cc: linux-iio, linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	Jonathan Cameron, Naveen Krishna Chatradhi, Lars-Peter Clausen

Naveen,

On Fri, Apr 12, 2013 at 9:36 PM, Naveen Krishna Ch
<naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Can some one review this and get this fix into the tree.

I think the ball is in your court.  Lars responded to your RFC patch
here and requested that you do a reset of the bus in the case of being
interrupted.

https://lkml.org/lkml/2013/4/5/91

I made a comment about perhaps just using non-interruptable and then
shortening the timeout and Lars thought that would be OK.  ...but I've
since thought about it and I think Lars' suggestion is best.

The reason I no longer like my suggestion of just using a 1ms
non-interruptable tiemout is that I'm slightly worried about running
into some case where the interrupt gets blocked for a while and then
we get timeouts for no reasons.  Perhaps I'm worrying over nothing,
but Lars' suggestion doesn't have this issue.

-Doug

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

* Re: [PATCH] iio: adc: exynos_adc: Handle timeout issues
@ 2013-04-15 16:01             ` Doug Anderson
  0 siblings, 0 replies; 39+ messages in thread
From: Doug Anderson @ 2013-04-15 16:01 UTC (permalink / raw)
  To: Naveen Krishna Ch
  Cc: linux-iio, linux-samsung-soc, Jonathan Cameron,
	Naveen Krishna Chatradhi, Lars-Peter Clausen

Naveen,

On Fri, Apr 12, 2013 at 9:36 PM, Naveen Krishna Ch
<naveenkrishna.ch@gmail.com> wrote:
> Can some one review this and get this fix into the tree.

I think the ball is in your court.  Lars responded to your RFC patch
here and requested that you do a reset of the bus in the case of being
interrupted.

https://lkml.org/lkml/2013/4/5/91

I made a comment about perhaps just using non-interruptable and then
shortening the timeout and Lars thought that would be OK.  ...but I've
since thought about it and I think Lars' suggestion is best.

The reason I no longer like my suggestion of just using a 1ms
non-interruptable tiemout is that I'm slightly worried about running
into some case where the interrupt gets blocked for a while and then
we get timeouts for no reasons.  Perhaps I'm worrying over nothing,
but Lars' suggestion doesn't have this issue.

-Doug

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

* [PATCH v2] iio: adc: exynos_adc: Handle timeout issues
  2013-04-04  4:06     ` Naveen Krishna Chatradhi
  (?)
  (?)
@ 2013-05-02 18:01     ` Naveen Krishna Chatradhi
       [not found]       ` <1367517663-12225-1-git-send-email-naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  -1 siblings, 1 reply; 39+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-05-02 18:01 UTC (permalink / raw)
  To: linux-iio, linux-samsung-soc
  Cc: jic23, naveen, Naveen Krishna Chatradhi, Doug Anderson,
	Lars-Peter Clausen

From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>

This patch does the following
1. use wait_for_completion_timeout instead of
   wait_for_completion_interruptible_timeout
2. Reset software if a timeout happens.
3. Also reduce the timeout to 100milli secs

Note: submitted for review at https://patchwork.kernel.org/patch/2279591/

Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
---
Changes since v1:
As per discussion at 
http://marc.info/?l=linux-kernel&m=136517637228869&w=3

This patch does the following
1. use wait_for_completion_timeout instead of
   wait_for_completion_interruptible_timeout
2. Reset software if a timeout happens.
3. Also reduce the timeout to 100milli secs

 drivers/iio/adc/exynos_adc.c |   73 ++++++++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 31 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 9f3a8ef..a400bb8 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -81,7 +81,7 @@ enum adc_version {
 #define ADC_CON_EN_START	(1u << 0)
 #define ADC_DATX_MASK		0xFFF
 
-#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(1000))
+#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(100))
 
 struct exynos_adc {
 	void __iomem		*regs;
@@ -111,6 +111,35 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
 	return (unsigned int)match->data;
 }
 
+static void exynos_adc_hw_init(struct exynos_adc *info)
+{
+	u32 con1, con2;
+	int delay;
+
+	if (info->version == ADC_V2) {
+		con1 = ADC_V2_CON1_SOFT_RESET;
+		writel(con1, ADC_V2_CON1(info->regs));
+
+		/* ADC H/W requires 25PCLKs before other register access */
+		delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info->clk));
+		udelay(delay);
+
+		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
+			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
+		writel(con2, ADC_V2_CON2(info->regs));
+
+		/* Enable interrupts */
+		writel(1, ADC_V2_INT_EN(info->regs));
+	} else {
+		/* set default prescaler values and Enable prescaler */
+		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
+
+		/* Enable 12-bit ADC resolution */
+		con1 |= ADC_V1_CON_RES;
+		writel(con1, ADC_V1_CON(info->regs));
+	}
+}
+
 static int exynos_read_raw(struct iio_dev *indio_dev,
 				struct iio_chan_spec const *chan,
 				int *val,
@@ -120,6 +149,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 	struct exynos_adc *info = iio_priv(indio_dev);
 	unsigned long timeout;
 	u32 con1, con2;
+	int ret;
 
 	if (mask != IIO_CHAN_INFO_RAW)
 		return -EINVAL;
@@ -144,16 +174,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				ADC_V1_CON(info->regs));
 	}
 
-	timeout = wait_for_completion_interruptible_timeout
+	timeout = wait_for_completion_timeout
 			(&info->completion, EXYNOS_ADC_TIMEOUT);
-	*val = info->value;
 
-	mutex_unlock(&indio_dev->mlock);
+	if (timeout == 0) {
+		dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
+		exynos_adc_hw_init(info);
+		ret = -ETIMEDOUT;
+	} else {
+		*val = info->value;
+		ret = IIO_VAL_INT;
+	}
 
-	if (timeout == 0)
-		return -ETIMEDOUT;
+	mutex_unlock(&indio_dev->mlock);
 
-	return IIO_VAL_INT;
+	return ret;
 }
 
 static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
@@ -225,30 +260,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
 	return 0;
 }
 
-static void exynos_adc_hw_init(struct exynos_adc *info)
-{
-	u32 con1, con2;
-
-	if (info->version == ADC_V2) {
-		con1 = ADC_V2_CON1_SOFT_RESET;
-		writel(con1, ADC_V2_CON1(info->regs));
-
-		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
-			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
-		writel(con2, ADC_V2_CON2(info->regs));
-
-		/* Enable interrupts */
-		writel(1, ADC_V2_INT_EN(info->regs));
-	} else {
-		/* set default prescaler values and Enable prescaler */
-		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
-
-		/* Enable 12-bit ADC resolution */
-		con1 |= ADC_V1_CON_RES;
-		writel(con1, ADC_V1_CON(info->regs));
-	}
-}
-
 static int exynos_adc_probe(struct platform_device *pdev)
 {
 	struct exynos_adc *info = NULL;
-- 
1.7.9.5

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

* Re: [PATCH v2] iio: adc: exynos_adc: Handle timeout issues
  2013-05-02 18:01     ` [PATCH v2] " Naveen Krishna Chatradhi
@ 2013-05-02 18:10           ` Tomasz Figa
  0 siblings, 0 replies; 39+ messages in thread
From: Tomasz Figa @ 2013-05-02 18:10 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	jic23-KWPb1pKIrIJaa/9Udqfwiw, naveen-F7+t8E8rja9g9hUCZPvPmw,
	Naveen Krishna Chatradhi, Doug Anderson, Lars-Peter Clausen

Hi Naveen,

On Thursday 02 of May 2013 11:01:03 Naveen Krishna Chatradhi wrote:
> From: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
> 
> This patch does the following
> 1. use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happens.
> 3. Also reduce the timeout to 100milli secs

I wonder what this patch is trying to fix. In what conditions can an ADC 
conversion time out?

Sorry if it was already explained in discussion. Still, I think that 
commit message of a patch should explain why it is needed.

Best regards,
Tomasz
 
> Note: submitted for review at
> https://patchwork.kernel.org/patch/2279591/
> 
> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
> Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Cc: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
> ---
> Changes since v1:
> As per discussion at
> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
> 
> This patch does the following
> 1. use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happens.
> 3. Also reduce the timeout to 100milli secs
> 
>  drivers/iio/adc/exynos_adc.c |   73
> ++++++++++++++++++++++++------------------ 1 file changed, 42
> insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index 9f3a8ef..a400bb8 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -81,7 +81,7 @@ enum adc_version {
>  #define ADC_CON_EN_START	(1u << 0)
>  #define ADC_DATX_MASK		0xFFF
> 
> -#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(1000))
> +#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(100))
> 
>  struct exynos_adc {
>  	void __iomem		*regs;
> @@ -111,6 +111,35 @@ static inline unsigned int
> exynos_adc_get_version(struct platform_device *pdev) return (unsigned
> int)match->data;
>  }
> 
> +static void exynos_adc_hw_init(struct exynos_adc *info)
> +{
> +	u32 con1, con2;
> +	int delay;
> +
> +	if (info->version == ADC_V2) {
> +		con1 = ADC_V2_CON1_SOFT_RESET;
> +		writel(con1, ADC_V2_CON1(info->regs));
> +
> +		/* ADC H/W requires 25PCLKs before other register access 
*/
> +		delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info-
>clk));
> +		udelay(delay);
> +
> +		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> +			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> +		writel(con2, ADC_V2_CON2(info->regs));
> +
> +		/* Enable interrupts */
> +		writel(1, ADC_V2_INT_EN(info->regs));
> +	} else {
> +		/* set default prescaler values and Enable prescaler */
> +		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> +
> +		/* Enable 12-bit ADC resolution */
> +		con1 |= ADC_V1_CON_RES;
> +		writel(con1, ADC_V1_CON(info->regs));
> +	}
> +}
> +
>  static int exynos_read_raw(struct iio_dev *indio_dev,
>  				struct iio_chan_spec const *chan,
>  				int *val,
> @@ -120,6 +149,7 @@ static int exynos_read_raw(struct iio_dev
> *indio_dev, struct exynos_adc *info = iio_priv(indio_dev);
>  	unsigned long timeout;
>  	u32 con1, con2;
> +	int ret;
> 
>  	if (mask != IIO_CHAN_INFO_RAW)
>  		return -EINVAL;
> @@ -144,16 +174,21 @@ static int exynos_read_raw(struct iio_dev
> *indio_dev, ADC_V1_CON(info->regs));
>  	}
> 
> -	timeout = wait_for_completion_interruptible_timeout
> +	timeout = wait_for_completion_timeout
>  			(&info->completion, EXYNOS_ADC_TIMEOUT);
> -	*val = info->value;
> 
> -	mutex_unlock(&indio_dev->mlock);
> +	if (timeout == 0) {
> +		dev_warn(&indio_dev->dev, "Conversion timed out 
reseting\n");
> +		exynos_adc_hw_init(info);
> +		ret = -ETIMEDOUT;
> +	} else {
> +		*val = info->value;
> +		ret = IIO_VAL_INT;
> +	}
> 
> -	if (timeout == 0)
> -		return -ETIMEDOUT;
> +	mutex_unlock(&indio_dev->mlock);
> 
> -	return IIO_VAL_INT;
> +	return ret;
>  }
> 
>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
> @@ -225,30 +260,6 @@ static int exynos_adc_remove_devices(struct device
> *dev, void *c) return 0;
>  }
> 
> -static void exynos_adc_hw_init(struct exynos_adc *info)
> -{
> -	u32 con1, con2;
> -
> -	if (info->version == ADC_V2) {
> -		con1 = ADC_V2_CON1_SOFT_RESET;
> -		writel(con1, ADC_V2_CON1(info->regs));
> -
> -		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> -			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> -		writel(con2, ADC_V2_CON2(info->regs));
> -
> -		/* Enable interrupts */
> -		writel(1, ADC_V2_INT_EN(info->regs));
> -	} else {
> -		/* set default prescaler values and Enable prescaler */
> -		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> -
> -		/* Enable 12-bit ADC resolution */
> -		con1 |= ADC_V1_CON_RES;
> -		writel(con1, ADC_V1_CON(info->regs));
> -	}
> -}
> -
>  static int exynos_adc_probe(struct platform_device *pdev)
>  {
>  	struct exynos_adc *info = NULL;

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

* Re: [PATCH v2] iio: adc: exynos_adc: Handle timeout issues
@ 2013-05-02 18:10           ` Tomasz Figa
  0 siblings, 0 replies; 39+ messages in thread
From: Tomasz Figa @ 2013-05-02 18:10 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi
  Cc: linux-iio, linux-samsung-soc, jic23, naveen,
	Naveen Krishna Chatradhi, Doug Anderson, Lars-Peter Clausen

Hi Naveen,

On Thursday 02 of May 2013 11:01:03 Naveen Krishna Chatradhi wrote:
> From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
> 
> This patch does the following
> 1. use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happens.
> 3. Also reduce the timeout to 100milli secs

I wonder what this patch is trying to fix. In what conditions can an ADC 
conversion time out?

Sorry if it was already explained in discussion. Still, I think that 
commit message of a patch should explain why it is needed.

Best regards,
Tomasz
 
> Note: submitted for review at
> https://patchwork.kernel.org/patch/2279591/
> 
> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
> Cc: Doug Anderson <dianders@chromium.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> ---
> Changes since v1:
> As per discussion at
> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
> 
> This patch does the following
> 1. use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happens.
> 3. Also reduce the timeout to 100milli secs
> 
>  drivers/iio/adc/exynos_adc.c |   73
> ++++++++++++++++++++++++------------------ 1 file changed, 42
> insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index 9f3a8ef..a400bb8 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -81,7 +81,7 @@ enum adc_version {
>  #define ADC_CON_EN_START	(1u << 0)
>  #define ADC_DATX_MASK		0xFFF
> 
> -#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(1000))
> +#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(100))
> 
>  struct exynos_adc {
>  	void __iomem		*regs;
> @@ -111,6 +111,35 @@ static inline unsigned int
> exynos_adc_get_version(struct platform_device *pdev) return (unsigned
> int)match->data;
>  }
> 
> +static void exynos_adc_hw_init(struct exynos_adc *info)
> +{
> +	u32 con1, con2;
> +	int delay;
> +
> +	if (info->version == ADC_V2) {
> +		con1 = ADC_V2_CON1_SOFT_RESET;
> +		writel(con1, ADC_V2_CON1(info->regs));
> +
> +		/* ADC H/W requires 25PCLKs before other register access 
*/
> +		delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info-
>clk));
> +		udelay(delay);
> +
> +		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> +			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> +		writel(con2, ADC_V2_CON2(info->regs));
> +
> +		/* Enable interrupts */
> +		writel(1, ADC_V2_INT_EN(info->regs));
> +	} else {
> +		/* set default prescaler values and Enable prescaler */
> +		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> +
> +		/* Enable 12-bit ADC resolution */
> +		con1 |= ADC_V1_CON_RES;
> +		writel(con1, ADC_V1_CON(info->regs));
> +	}
> +}
> +
>  static int exynos_read_raw(struct iio_dev *indio_dev,
>  				struct iio_chan_spec const *chan,
>  				int *val,
> @@ -120,6 +149,7 @@ static int exynos_read_raw(struct iio_dev
> *indio_dev, struct exynos_adc *info = iio_priv(indio_dev);
>  	unsigned long timeout;
>  	u32 con1, con2;
> +	int ret;
> 
>  	if (mask != IIO_CHAN_INFO_RAW)
>  		return -EINVAL;
> @@ -144,16 +174,21 @@ static int exynos_read_raw(struct iio_dev
> *indio_dev, ADC_V1_CON(info->regs));
>  	}
> 
> -	timeout = wait_for_completion_interruptible_timeout
> +	timeout = wait_for_completion_timeout
>  			(&info->completion, EXYNOS_ADC_TIMEOUT);
> -	*val = info->value;
> 
> -	mutex_unlock(&indio_dev->mlock);
> +	if (timeout == 0) {
> +		dev_warn(&indio_dev->dev, "Conversion timed out 
reseting\n");
> +		exynos_adc_hw_init(info);
> +		ret = -ETIMEDOUT;
> +	} else {
> +		*val = info->value;
> +		ret = IIO_VAL_INT;
> +	}
> 
> -	if (timeout == 0)
> -		return -ETIMEDOUT;
> +	mutex_unlock(&indio_dev->mlock);
> 
> -	return IIO_VAL_INT;
> +	return ret;
>  }
> 
>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
> @@ -225,30 +260,6 @@ static int exynos_adc_remove_devices(struct device
> *dev, void *c) return 0;
>  }
> 
> -static void exynos_adc_hw_init(struct exynos_adc *info)
> -{
> -	u32 con1, con2;
> -
> -	if (info->version == ADC_V2) {
> -		con1 = ADC_V2_CON1_SOFT_RESET;
> -		writel(con1, ADC_V2_CON1(info->regs));
> -
> -		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> -			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> -		writel(con2, ADC_V2_CON2(info->regs));
> -
> -		/* Enable interrupts */
> -		writel(1, ADC_V2_INT_EN(info->regs));
> -	} else {
> -		/* set default prescaler values and Enable prescaler */
> -		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> -
> -		/* Enable 12-bit ADC resolution */
> -		con1 |= ADC_V1_CON_RES;
> -		writel(con1, ADC_V1_CON(info->regs));
> -	}
> -}
> -
>  static int exynos_adc_probe(struct platform_device *pdev)
>  {
>  	struct exynos_adc *info = NULL;

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

* Re: [PATCH v2] iio: adc: exynos_adc: Handle timeout issues
  2013-05-02 18:10           ` Tomasz Figa
@ 2013-05-02 18:22             ` Naveen Krishna Ch
  -1 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Ch @ 2013-05-02 18:22 UTC (permalink / raw)
  To: Tomasz Figa
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	jic23-KWPb1pKIrIJaa/9Udqfwiw, Naveen Krishna,
	Naveen Krishna Chatradhi, Doug Anderson, Lars-Peter Clausen

On 2 May 2013 11:10, Tomasz Figa <tomasz.figa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Hi Naveen,
>
> On Thursday 02 of May 2013 11:01:03 Naveen Krishna Chatradhi wrote:
>> From: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
>>
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>
> I wonder what this patch is trying to fix. In what conditions can an ADC
> conversion time out?
>
> Sorry if it was already explained in discussion. Still, I think that
> commit message of a patch should explain why it is needed.
The discussion started with a bug reported by Dan Carpenter
http://www.gossamer-threads.com/lists/linux/kernel/1693284?page=last

and during the discussion we found out the return cases of
wait_for_completion_interruptible_timeout() were not handled properly.
so we implemented hw_reset during the error cases.

As such ISR only does a regiser access.  Which may never timeout.
This patch reduces the timeout and removes the use of interruptible.
As, ADC's ISR would be too fast to handle the interruptible operation.

Now i see, there is nothing much this driver is fixing.
As you suggest, the subject can be little less harsh.
>
> Best regards,
> Tomasz

Thanks for the review.
Naveen
>
>> Note: submitted for review at
>> https://patchwork.kernel.org/patch/2279591/
>>
>> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
>> Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
>> Cc: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
>> ---
>> Changes since v1:
>> As per discussion at
>> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
>>
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>>
>>  drivers/iio/adc/exynos_adc.c |   73
>> ++++++++++++++++++++++++------------------ 1 file changed, 42
>> insertions(+), 31 deletions(-)
>>
>> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
>> index 9f3a8ef..a400bb8 100644
>> --- a/drivers/iio/adc/exynos_adc.c
>> +++ b/drivers/iio/adc/exynos_adc.c
>> @@ -81,7 +81,7 @@ enum adc_version {
>>  #define ADC_CON_EN_START     (1u << 0)
>>  #define ADC_DATX_MASK                0xFFF
>>
>> -#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(1000))
>> +#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(100))
>>
>>  struct exynos_adc {
>>       void __iomem            *regs;
>> @@ -111,6 +111,35 @@ static inline unsigned int
>> exynos_adc_get_version(struct platform_device *pdev) return (unsigned
>> int)match->data;
>>  }
>>
>> +static void exynos_adc_hw_init(struct exynos_adc *info)
>> +{
>> +     u32 con1, con2;
>> +     int delay;
>> +
>> +     if (info->version == ADC_V2) {
>> +             con1 = ADC_V2_CON1_SOFT_RESET;
>> +             writel(con1, ADC_V2_CON1(info->regs));
>> +
>> +             /* ADC H/W requires 25PCLKs before other register access
> */
>> +             delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info-
>>clk));
>> +             udelay(delay);
>> +
>> +             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> +                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> +             writel(con2, ADC_V2_CON2(info->regs));
>> +
>> +             /* Enable interrupts */
>> +             writel(1, ADC_V2_INT_EN(info->regs));
>> +     } else {
>> +             /* set default prescaler values and Enable prescaler */
>> +             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> +
>> +             /* Enable 12-bit ADC resolution */
>> +             con1 |= ADC_V1_CON_RES;
>> +             writel(con1, ADC_V1_CON(info->regs));
>> +     }
>> +}
>> +
>>  static int exynos_read_raw(struct iio_dev *indio_dev,
>>                               struct iio_chan_spec const *chan,
>>                               int *val,
>> @@ -120,6 +149,7 @@ static int exynos_read_raw(struct iio_dev
>> *indio_dev, struct exynos_adc *info = iio_priv(indio_dev);
>>       unsigned long timeout;
>>       u32 con1, con2;
>> +     int ret;
>>
>>       if (mask != IIO_CHAN_INFO_RAW)
>>               return -EINVAL;
>> @@ -144,16 +174,21 @@ static int exynos_read_raw(struct iio_dev
>> *indio_dev, ADC_V1_CON(info->regs));
>>       }
>>
>> -     timeout = wait_for_completion_interruptible_timeout
>> +     timeout = wait_for_completion_timeout
>>                       (&info->completion, EXYNOS_ADC_TIMEOUT);
>> -     *val = info->value;
>>
>> -     mutex_unlock(&indio_dev->mlock);
>> +     if (timeout == 0) {
>> +             dev_warn(&indio_dev->dev, "Conversion timed out
> reseting\n");
>> +             exynos_adc_hw_init(info);
>> +             ret = -ETIMEDOUT;
>> +     } else {
>> +             *val = info->value;
>> +             ret = IIO_VAL_INT;
>> +     }
>>
>> -     if (timeout == 0)
>> -             return -ETIMEDOUT;
>> +     mutex_unlock(&indio_dev->mlock);
>>
>> -     return IIO_VAL_INT;
>> +     return ret;
>>  }
>>
>>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
>> @@ -225,30 +260,6 @@ static int exynos_adc_remove_devices(struct device
>> *dev, void *c) return 0;
>>  }
>>
>> -static void exynos_adc_hw_init(struct exynos_adc *info)
>> -{
>> -     u32 con1, con2;
>> -
>> -     if (info->version == ADC_V2) {
>> -             con1 = ADC_V2_CON1_SOFT_RESET;
>> -             writel(con1, ADC_V2_CON1(info->regs));
>> -
>> -             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> -                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> -             writel(con2, ADC_V2_CON2(info->regs));
>> -
>> -             /* Enable interrupts */
>> -             writel(1, ADC_V2_INT_EN(info->regs));
>> -     } else {
>> -             /* set default prescaler values and Enable prescaler */
>> -             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> -
>> -             /* Enable 12-bit ADC resolution */
>> -             con1 |= ADC_V1_CON_RES;
>> -             writel(con1, ADC_V1_CON(info->regs));
>> -     }
>> -}
>> -
>>  static int exynos_adc_probe(struct platform_device *pdev)
>>  {
>>       struct exynos_adc *info = NULL;



--
Shine bright,
(: Nav :)

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

* Re: [PATCH v2] iio: adc: exynos_adc: Handle timeout issues
@ 2013-05-02 18:22             ` Naveen Krishna Ch
  0 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Ch @ 2013-05-02 18:22 UTC (permalink / raw)
  To: Tomasz Figa
  Cc: linux-iio, linux-samsung-soc, jic23, Naveen Krishna,
	Naveen Krishna Chatradhi, Doug Anderson, Lars-Peter Clausen

On 2 May 2013 11:10, Tomasz Figa <tomasz.figa@gmail.com> wrote:
> Hi Naveen,
>
> On Thursday 02 of May 2013 11:01:03 Naveen Krishna Chatradhi wrote:
>> From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
>>
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>
> I wonder what this patch is trying to fix. In what conditions can an ADC
> conversion time out?
>
> Sorry if it was already explained in discussion. Still, I think that
> commit message of a patch should explain why it is needed.
The discussion started with a bug reported by Dan Carpenter
http://www.gossamer-threads.com/lists/linux/kernel/1693284?page=last

and during the discussion we found out the return cases of
wait_for_completion_interruptible_timeout() were not handled properly.
so we implemented hw_reset during the error cases.

As such ISR only does a regiser access.  Which may never timeout.
This patch reduces the timeout and removes the use of interruptible.
As, ADC's ISR would be too fast to handle the interruptible operation.

Now i see, there is nothing much this driver is fixing.
As you suggest, the subject can be little less harsh.
>
> Best regards,
> Tomasz

Thanks for the review.
Naveen
>
>> Note: submitted for review at
>> https://patchwork.kernel.org/patch/2279591/
>>
>> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
>> Cc: Doug Anderson <dianders@chromium.org>
>> Cc: Lars-Peter Clausen <lars@metafoo.de>
>> ---
>> Changes since v1:
>> As per discussion at
>> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
>>
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>>
>>  drivers/iio/adc/exynos_adc.c |   73
>> ++++++++++++++++++++++++------------------ 1 file changed, 42
>> insertions(+), 31 deletions(-)
>>
>> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
>> index 9f3a8ef..a400bb8 100644
>> --- a/drivers/iio/adc/exynos_adc.c
>> +++ b/drivers/iio/adc/exynos_adc.c
>> @@ -81,7 +81,7 @@ enum adc_version {
>>  #define ADC_CON_EN_START     (1u << 0)
>>  #define ADC_DATX_MASK                0xFFF
>>
>> -#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(1000))
>> +#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(100))
>>
>>  struct exynos_adc {
>>       void __iomem            *regs;
>> @@ -111,6 +111,35 @@ static inline unsigned int
>> exynos_adc_get_version(struct platform_device *pdev) return (unsigned
>> int)match->data;
>>  }
>>
>> +static void exynos_adc_hw_init(struct exynos_adc *info)
>> +{
>> +     u32 con1, con2;
>> +     int delay;
>> +
>> +     if (info->version == ADC_V2) {
>> +             con1 = ADC_V2_CON1_SOFT_RESET;
>> +             writel(con1, ADC_V2_CON1(info->regs));
>> +
>> +             /* ADC H/W requires 25PCLKs before other register access
> */
>> +             delay = DIV_ROUND_UP(25 * 1000000, clk_get_rate(info-
>>clk));
>> +             udelay(delay);
>> +
>> +             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> +                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> +             writel(con2, ADC_V2_CON2(info->regs));
>> +
>> +             /* Enable interrupts */
>> +             writel(1, ADC_V2_INT_EN(info->regs));
>> +     } else {
>> +             /* set default prescaler values and Enable prescaler */
>> +             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> +
>> +             /* Enable 12-bit ADC resolution */
>> +             con1 |= ADC_V1_CON_RES;
>> +             writel(con1, ADC_V1_CON(info->regs));
>> +     }
>> +}
>> +
>>  static int exynos_read_raw(struct iio_dev *indio_dev,
>>                               struct iio_chan_spec const *chan,
>>                               int *val,
>> @@ -120,6 +149,7 @@ static int exynos_read_raw(struct iio_dev
>> *indio_dev, struct exynos_adc *info = iio_priv(indio_dev);
>>       unsigned long timeout;
>>       u32 con1, con2;
>> +     int ret;
>>
>>       if (mask != IIO_CHAN_INFO_RAW)
>>               return -EINVAL;
>> @@ -144,16 +174,21 @@ static int exynos_read_raw(struct iio_dev
>> *indio_dev, ADC_V1_CON(info->regs));
>>       }
>>
>> -     timeout = wait_for_completion_interruptible_timeout
>> +     timeout = wait_for_completion_timeout
>>                       (&info->completion, EXYNOS_ADC_TIMEOUT);
>> -     *val = info->value;
>>
>> -     mutex_unlock(&indio_dev->mlock);
>> +     if (timeout == 0) {
>> +             dev_warn(&indio_dev->dev, "Conversion timed out
> reseting\n");
>> +             exynos_adc_hw_init(info);
>> +             ret = -ETIMEDOUT;
>> +     } else {
>> +             *val = info->value;
>> +             ret = IIO_VAL_INT;
>> +     }
>>
>> -     if (timeout == 0)
>> -             return -ETIMEDOUT;
>> +     mutex_unlock(&indio_dev->mlock);
>>
>> -     return IIO_VAL_INT;
>> +     return ret;
>>  }
>>
>>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
>> @@ -225,30 +260,6 @@ static int exynos_adc_remove_devices(struct device
>> *dev, void *c) return 0;
>>  }
>>
>> -static void exynos_adc_hw_init(struct exynos_adc *info)
>> -{
>> -     u32 con1, con2;
>> -
>> -     if (info->version == ADC_V2) {
>> -             con1 = ADC_V2_CON1_SOFT_RESET;
>> -             writel(con1, ADC_V2_CON1(info->regs));
>> -
>> -             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> -                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> -             writel(con2, ADC_V2_CON2(info->regs));
>> -
>> -             /* Enable interrupts */
>> -             writel(1, ADC_V2_INT_EN(info->regs));
>> -     } else {
>> -             /* set default prescaler values and Enable prescaler */
>> -             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> -
>> -             /* Enable 12-bit ADC resolution */
>> -             con1 |= ADC_V1_CON_RES;
>> -             writel(con1, ADC_V1_CON(info->regs));
>> -     }
>> -}
>> -
>>  static int exynos_adc_probe(struct platform_device *pdev)
>>  {
>>       struct exynos_adc *info = NULL;



--
Shine bright,
(: Nav :)

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

* Re: [PATCH v2] iio: adc: exynos_adc: Handle timeout issues
  2013-05-02 18:22             ` Naveen Krishna Ch
@ 2013-05-02 18:36                 ` Tomasz Figa
  -1 siblings, 0 replies; 39+ messages in thread
From: Tomasz Figa @ 2013-05-02 18:36 UTC (permalink / raw)
  To: Naveen Krishna Ch
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	jic23-KWPb1pKIrIJaa/9Udqfwiw, Naveen Krishna,
	Naveen Krishna Chatradhi, Doug Anderson, Lars-Peter Clausen

On Thursday 02 of May 2013 11:22:27 Naveen Krishna Ch wrote:
> On 2 May 2013 11:10, Tomasz Figa <tomasz.figa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Hi Naveen,
> > 
> > On Thursday 02 of May 2013 11:01:03 Naveen Krishna Chatradhi wrote:
> >> From: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
> >> 
> >> This patch does the following
> >> 1. use wait_for_completion_timeout instead of
> >> 
> >>    wait_for_completion_interruptible_timeout
> >> 
> >> 2. Reset software if a timeout happens.
> >> 3. Also reduce the timeout to 100milli secs
> > 
> > I wonder what this patch is trying to fix. In what conditions can an
> > ADC conversion time out?
> > 
> > Sorry if it was already explained in discussion. Still, I think that
> > commit message of a patch should explain why it is needed.
> 
> The discussion started with a bug reported by Dan Carpenter
> http://www.gossamer-threads.com/lists/linux/kernel/1693284?page=last
> 
> and during the discussion we found out the return cases of
> wait_for_completion_interruptible_timeout() were not handled properly.
> so we implemented hw_reset during the error cases.
> 
> As such ISR only does a regiser access.  Which may never timeout.
> This patch reduces the timeout and removes the use of interruptible.
> As, ADC's ISR would be too fast to handle the interruptible operation.
> 
> Now i see, there is nothing much this driver is fixing.
> As you suggest, the subject can be little less harsh.

OK, thanks for the explanation.

Best regards,
Tomasz

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

* Re: [PATCH v2] iio: adc: exynos_adc: Handle timeout issues
@ 2013-05-02 18:36                 ` Tomasz Figa
  0 siblings, 0 replies; 39+ messages in thread
From: Tomasz Figa @ 2013-05-02 18:36 UTC (permalink / raw)
  To: Naveen Krishna Ch
  Cc: linux-iio, linux-samsung-soc, jic23, Naveen Krishna,
	Naveen Krishna Chatradhi, Doug Anderson, Lars-Peter Clausen

On Thursday 02 of May 2013 11:22:27 Naveen Krishna Ch wrote:
> On 2 May 2013 11:10, Tomasz Figa <tomasz.figa@gmail.com> wrote:
> > Hi Naveen,
> > 
> > On Thursday 02 of May 2013 11:01:03 Naveen Krishna Chatradhi wrote:
> >> From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
> >> 
> >> This patch does the following
> >> 1. use wait_for_completion_timeout instead of
> >> 
> >>    wait_for_completion_interruptible_timeout
> >> 
> >> 2. Reset software if a timeout happens.
> >> 3. Also reduce the timeout to 100milli secs
> > 
> > I wonder what this patch is trying to fix. In what conditions can an
> > ADC conversion time out?
> > 
> > Sorry if it was already explained in discussion. Still, I think that
> > commit message of a patch should explain why it is needed.
> 
> The discussion started with a bug reported by Dan Carpenter
> http://www.gossamer-threads.com/lists/linux/kernel/1693284?page=last
> 
> and during the discussion we found out the return cases of
> wait_for_completion_interruptible_timeout() were not handled properly.
> so we implemented hw_reset during the error cases.
> 
> As such ISR only does a regiser access.  Which may never timeout.
> This patch reduces the timeout and removes the use of interruptible.
> As, ADC's ISR would be too fast to handle the interruptible operation.
> 
> Now i see, there is nothing much this driver is fixing.
> As you suggest, the subject can be little less harsh.

OK, thanks for the explanation.

Best regards,
Tomasz


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

* [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
  2013-04-04  4:06     ` Naveen Krishna Chatradhi
                       ` (2 preceding siblings ...)
  (?)
@ 2013-10-11  8:23     ` Naveen Krishna Chatradhi
  2013-10-11 14:30         ` Lars-Peter Clausen
                         ` (3 more replies)
  -1 siblings, 4 replies; 39+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-10-11  8:23 UTC (permalink / raw)
  To: linux-iio
  Cc: linux-kernel, linux-samsung-soc, dianders, gregkh,
	naveenkrishna.ch, lars, tomasz.figa

This patch does the following
1. use wait_for_completion_timeout instead of
   wait_for_completion_interruptible_timeout
2. Reset software if a timeout happens.
3. Also reduce the timeout to 100milli secs

Note: submitted for review at https://patchwork.kernel.org/patch/2279591/

Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
---
Changes since v1:
As per discussion at
http://marc.info/?l=linux-kernel&m=136517637228869&w=3

This patch does the following
1. use wait_for_completion_timeout instead of
   wait_for_completion_interruptible_timeout
2. Reset software if a timeout happens.
3. Also reduce the timeout to 100milli secs

Changes since v2:
None.
Rebased and reposting.

---
 drivers/iio/adc/exynos_adc.c |   66 +++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index d25b262..f18ed7e 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -82,7 +82,7 @@ enum adc_version {
 #define ADC_CON_EN_START	(1u << 0)
 #define ADC_DATX_MASK		0xFFF
 
-#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(1000))
+#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(100))
 
 struct exynos_adc {
 	void __iomem		*regs;
@@ -112,6 +112,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
 	return (unsigned int)match->data;
 }
 
+static void exynos_adc_hw_init(struct exynos_adc *info)
+{
+	u32 con1, con2;
+
+	if (info->version == ADC_V2) {
+		con1 = ADC_V2_CON1_SOFT_RESET;
+		writel(con1, ADC_V2_CON1(info->regs));
+
+		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
+			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
+		writel(con2, ADC_V2_CON2(info->regs));
+
+		/* Enable interrupts */
+		writel(1, ADC_V2_INT_EN(info->regs));
+	} else {
+		/* set default prescaler values and Enable prescaler */
+		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
+
+		/* Enable 12-bit ADC resolution */
+		con1 |= ADC_V1_CON_RES;
+		writel(con1, ADC_V1_CON(info->regs));
+	}
+}
+
 static int exynos_read_raw(struct iio_dev *indio_dev,
 				struct iio_chan_spec const *chan,
 				int *val,
@@ -121,6 +145,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 	struct exynos_adc *info = iio_priv(indio_dev);
 	unsigned long timeout;
 	u32 con1, con2;
+	int ret;
 
 	if (mask != IIO_CHAN_INFO_RAW)
 		return -EINVAL;
@@ -145,16 +170,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				ADC_V1_CON(info->regs));
 	}
 
-	timeout = wait_for_completion_interruptible_timeout
+	timeout = wait_for_completion_timeout
 			(&info->completion, EXYNOS_ADC_TIMEOUT);
+	if (timeout == 0) {
+		dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
+		exynos_adc_hw_init(info);
+		ret = -ETIMEDOUT;
+	} else {
+		*val = info->value;
+		ret = IIO_VAL_INT;
+	}
 	*val = info->value;
 
 	mutex_unlock(&indio_dev->mlock);
 
-	if (timeout == 0)
-		return -ETIMEDOUT;
-
-	return IIO_VAL_INT;
+	return ret;
 }
 
 static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
@@ -226,30 +256,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
 	return 0;
 }
 
-static void exynos_adc_hw_init(struct exynos_adc *info)
-{
-	u32 con1, con2;
-
-	if (info->version == ADC_V2) {
-		con1 = ADC_V2_CON1_SOFT_RESET;
-		writel(con1, ADC_V2_CON1(info->regs));
-
-		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
-			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
-		writel(con2, ADC_V2_CON2(info->regs));
-
-		/* Enable interrupts */
-		writel(1, ADC_V2_INT_EN(info->regs));
-	} else {
-		/* set default prescaler values and Enable prescaler */
-		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
-
-		/* Enable 12-bit ADC resolution */
-		con1 |= ADC_V1_CON_RES;
-		writel(con1, ADC_V1_CON(info->regs));
-	}
-}
-
 static int exynos_adc_probe(struct platform_device *pdev)
 {
 	struct exynos_adc *info = NULL;
-- 
1.7.10.4


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

* Re: [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
@ 2013-10-11 14:30         ` Lars-Peter Clausen
  0 siblings, 0 replies; 39+ messages in thread
From: Lars-Peter Clausen @ 2013-10-11 14:30 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi
  Cc: linux-iio, linux-kernel, linux-samsung-soc, dianders, gregkh,
	naveenkrishna.ch, tomasz.figa

On 10/11/2013 10:23 AM, Naveen Krishna Chatradhi wrote:
> This patch does the following
> 1. use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happens.
> 3. Also reduce the timeout to 100milli secs

It is always good to have a description of why a chance should be done in
the commit message. It is obvious what the patch does by just looking at the
changed lines, it is not that obvious though why those lines had to be changed.

> 
> Note: submitted for review at https://patchwork.kernel.org/patch/2279591/
> 
> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
> Cc: Doug Anderson <dianders@chromium.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> ---
> Changes since v1:
> As per discussion at
> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
> 
> This patch does the following
> 1. use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happens.
> 3. Also reduce the timeout to 100milli secs
> 
> Changes since v2:
> None.
> Rebased and reposting.
> 
> ---
>  drivers/iio/adc/exynos_adc.c |   66 +++++++++++++++++++++++-------------------
>  1 file changed, 36 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index d25b262..f18ed7e 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -82,7 +82,7 @@ enum adc_version {
>  #define ADC_CON_EN_START	(1u << 0)
>  #define ADC_DATX_MASK		0xFFF
>  
> -#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(1000))
> +#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(100))
>  
>  struct exynos_adc {
>  	void __iomem		*regs;
> @@ -112,6 +112,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
>  	return (unsigned int)match->data;
>  }
>  
> +static void exynos_adc_hw_init(struct exynos_adc *info)
> +{
> +	u32 con1, con2;
> +
> +	if (info->version == ADC_V2) {
> +		con1 = ADC_V2_CON1_SOFT_RESET;
> +		writel(con1, ADC_V2_CON1(info->regs));
> +
> +		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> +			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> +		writel(con2, ADC_V2_CON2(info->regs));
> +
> +		/* Enable interrupts */
> +		writel(1, ADC_V2_INT_EN(info->regs));
> +	} else {
> +		/* set default prescaler values and Enable prescaler */
> +		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> +
> +		/* Enable 12-bit ADC resolution */
> +		con1 |= ADC_V1_CON_RES;
> +		writel(con1, ADC_V1_CON(info->regs));
> +	}
> +}
> +
>  static int exynos_read_raw(struct iio_dev *indio_dev,
>  				struct iio_chan_spec const *chan,
>  				int *val,
> @@ -121,6 +145,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>  	struct exynos_adc *info = iio_priv(indio_dev);
>  	unsigned long timeout;
>  	u32 con1, con2;
> +	int ret;
>  
>  	if (mask != IIO_CHAN_INFO_RAW)
>  		return -EINVAL;
> @@ -145,16 +170,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>  				ADC_V1_CON(info->regs));
>  	}
>  
> -	timeout = wait_for_completion_interruptible_timeout
> +	timeout = wait_for_completion_timeout
>  			(&info->completion, EXYNOS_ADC_TIMEOUT);

Nitpick: It would be nice to put the &info->completion on the same line as
the wait_for_completion...

> +	if (timeout == 0) {
> +		dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
> +		exynos_adc_hw_init(info);
> +		ret = -ETIMEDOUT;
> +	} else {
> +		*val = info->value;
> +		ret = IIO_VAL_INT;
> +	}
>  	*val = info->value;

This line above should probably be removed.

>  
>  	mutex_unlock(&indio_dev->mlock);
>  
> -	if (timeout == 0)
> -		return -ETIMEDOUT;
> -
> -	return IIO_VAL_INT;
> +	return ret;
>  }
>  
>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
> @@ -226,30 +256,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
>  	return 0;
>  }
>  
> -static void exynos_adc_hw_init(struct exynos_adc *info)
> -{
> -	u32 con1, con2;
> -
> -	if (info->version == ADC_V2) {
> -		con1 = ADC_V2_CON1_SOFT_RESET;
> -		writel(con1, ADC_V2_CON1(info->regs));
> -
> -		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> -			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> -		writel(con2, ADC_V2_CON2(info->regs));
> -
> -		/* Enable interrupts */
> -		writel(1, ADC_V2_INT_EN(info->regs));
> -	} else {
> -		/* set default prescaler values and Enable prescaler */
> -		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> -
> -		/* Enable 12-bit ADC resolution */
> -		con1 |= ADC_V1_CON_RES;
> -		writel(con1, ADC_V1_CON(info->regs));
> -	}
> -}
> -
>  static int exynos_adc_probe(struct platform_device *pdev)
>  {
>  	struct exynos_adc *info = NULL;
> 


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

* Re: [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
@ 2013-10-11 14:30         ` Lars-Peter Clausen
  0 siblings, 0 replies; 39+ messages in thread
From: Lars-Peter Clausen @ 2013-10-11 14:30 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	dianders-F7+t8E8rja9g9hUCZPvPmw,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w,
	tomasz.figa-Re5JQEeQqe8AvxtiuMwx3w

On 10/11/2013 10:23 AM, Naveen Krishna Chatradhi wrote:
> This patch does the following
> 1. use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happens.
> 3. Also reduce the timeout to 100milli secs

It is always good to have a description of why a chance should be done in
the commit message. It is obvious what the patch does by just looking at the
changed lines, it is not that obvious though why those lines had to be changed.

> 
> Note: submitted for review at https://patchwork.kernel.org/patch/2279591/
> 
> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
> Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Cc: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
> ---
> Changes since v1:
> As per discussion at
> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
> 
> This patch does the following
> 1. use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 2. Reset software if a timeout happens.
> 3. Also reduce the timeout to 100milli secs
> 
> Changes since v2:
> None.
> Rebased and reposting.
> 
> ---
>  drivers/iio/adc/exynos_adc.c |   66 +++++++++++++++++++++++-------------------
>  1 file changed, 36 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index d25b262..f18ed7e 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -82,7 +82,7 @@ enum adc_version {
>  #define ADC_CON_EN_START	(1u << 0)
>  #define ADC_DATX_MASK		0xFFF
>  
> -#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(1000))
> +#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(100))
>  
>  struct exynos_adc {
>  	void __iomem		*regs;
> @@ -112,6 +112,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
>  	return (unsigned int)match->data;
>  }
>  
> +static void exynos_adc_hw_init(struct exynos_adc *info)
> +{
> +	u32 con1, con2;
> +
> +	if (info->version == ADC_V2) {
> +		con1 = ADC_V2_CON1_SOFT_RESET;
> +		writel(con1, ADC_V2_CON1(info->regs));
> +
> +		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> +			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> +		writel(con2, ADC_V2_CON2(info->regs));
> +
> +		/* Enable interrupts */
> +		writel(1, ADC_V2_INT_EN(info->regs));
> +	} else {
> +		/* set default prescaler values and Enable prescaler */
> +		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> +
> +		/* Enable 12-bit ADC resolution */
> +		con1 |= ADC_V1_CON_RES;
> +		writel(con1, ADC_V1_CON(info->regs));
> +	}
> +}
> +
>  static int exynos_read_raw(struct iio_dev *indio_dev,
>  				struct iio_chan_spec const *chan,
>  				int *val,
> @@ -121,6 +145,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>  	struct exynos_adc *info = iio_priv(indio_dev);
>  	unsigned long timeout;
>  	u32 con1, con2;
> +	int ret;
>  
>  	if (mask != IIO_CHAN_INFO_RAW)
>  		return -EINVAL;
> @@ -145,16 +170,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>  				ADC_V1_CON(info->regs));
>  	}
>  
> -	timeout = wait_for_completion_interruptible_timeout
> +	timeout = wait_for_completion_timeout
>  			(&info->completion, EXYNOS_ADC_TIMEOUT);

Nitpick: It would be nice to put the &info->completion on the same line as
the wait_for_completion...

> +	if (timeout == 0) {
> +		dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
> +		exynos_adc_hw_init(info);
> +		ret = -ETIMEDOUT;
> +	} else {
> +		*val = info->value;
> +		ret = IIO_VAL_INT;
> +	}
>  	*val = info->value;

This line above should probably be removed.

>  
>  	mutex_unlock(&indio_dev->mlock);
>  
> -	if (timeout == 0)
> -		return -ETIMEDOUT;
> -
> -	return IIO_VAL_INT;
> +	return ret;
>  }
>  
>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
> @@ -226,30 +256,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
>  	return 0;
>  }
>  
> -static void exynos_adc_hw_init(struct exynos_adc *info)
> -{
> -	u32 con1, con2;
> -
> -	if (info->version == ADC_V2) {
> -		con1 = ADC_V2_CON1_SOFT_RESET;
> -		writel(con1, ADC_V2_CON1(info->regs));
> -
> -		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
> -			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
> -		writel(con2, ADC_V2_CON2(info->regs));
> -
> -		/* Enable interrupts */
> -		writel(1, ADC_V2_INT_EN(info->regs));
> -	} else {
> -		/* set default prescaler values and Enable prescaler */
> -		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
> -
> -		/* Enable 12-bit ADC resolution */
> -		con1 |= ADC_V1_CON_RES;
> -		writel(con1, ADC_V1_CON(info->regs));
> -	}
> -}
> -
>  static int exynos_adc_probe(struct platform_device *pdev)
>  {
>  	struct exynos_adc *info = NULL;
> 

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

* Re: [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
@ 2013-10-12  6:40           ` Naveen Krishna Ch
  0 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Ch @ 2013-10-12  6:40 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
	linux-samsung-soc, dianders, gregkh, tomasz.figa

On 11 October 2013 20:00, Lars-Peter Clausen <lars@metafoo.de> wrote:
> On 10/11/2013 10:23 AM, Naveen Krishna Chatradhi wrote:
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>
> It is always good to have a description of why a chance should be done in
> the commit message. It is obvious what the patch does by just looking at the
> changed lines, it is not that obvious though why those lines had to be changed.
>
>>
>> Note: submitted for review at https://patchwork.kernel.org/patch/2279591/
>>
>> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
>> Cc: Doug Anderson <dianders@chromium.org>
>> Cc: Lars-Peter Clausen <lars@metafoo.de>
>> ---
>> Changes since v1:
>> As per discussion at
>> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
>>
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>>
>> Changes since v2:
>> None.
>> Rebased and reposting.
>>
>> ---
>>  drivers/iio/adc/exynos_adc.c |   66 +++++++++++++++++++++++-------------------
>>  1 file changed, 36 insertions(+), 30 deletions(-)
>>
>> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
>> index d25b262..f18ed7e 100644
>> --- a/drivers/iio/adc/exynos_adc.c
>> +++ b/drivers/iio/adc/exynos_adc.c
>> @@ -82,7 +82,7 @@ enum adc_version {
>>  #define ADC_CON_EN_START     (1u << 0)
>>  #define ADC_DATX_MASK                0xFFF
>>
>> -#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(1000))
>> +#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(100))
>>
>>  struct exynos_adc {
>>       void __iomem            *regs;
>> @@ -112,6 +112,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
>>       return (unsigned int)match->data;
>>  }
>>
>> +static void exynos_adc_hw_init(struct exynos_adc *info)
>> +{
>> +     u32 con1, con2;
>> +
>> +     if (info->version == ADC_V2) {
>> +             con1 = ADC_V2_CON1_SOFT_RESET;
>> +             writel(con1, ADC_V2_CON1(info->regs));
>> +
>> +             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> +                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> +             writel(con2, ADC_V2_CON2(info->regs));
>> +
>> +             /* Enable interrupts */
>> +             writel(1, ADC_V2_INT_EN(info->regs));
>> +     } else {
>> +             /* set default prescaler values and Enable prescaler */
>> +             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> +
>> +             /* Enable 12-bit ADC resolution */
>> +             con1 |= ADC_V1_CON_RES;
>> +             writel(con1, ADC_V1_CON(info->regs));
>> +     }
>> +}
>> +
>>  static int exynos_read_raw(struct iio_dev *indio_dev,
>>                               struct iio_chan_spec const *chan,
>>                               int *val,
>> @@ -121,6 +145,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>>       struct exynos_adc *info = iio_priv(indio_dev);
>>       unsigned long timeout;
>>       u32 con1, con2;
>> +     int ret;
>>
>>       if (mask != IIO_CHAN_INFO_RAW)
>>               return -EINVAL;
>> @@ -145,16 +170,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>>                               ADC_V1_CON(info->regs));
>>       }
>>
>> -     timeout = wait_for_completion_interruptible_timeout
>> +     timeout = wait_for_completion_timeout
>>                       (&info->completion, EXYNOS_ADC_TIMEOUT);
>
> Nitpick: It would be nice to put the &info->completion on the same line as
> the wait_for_completion...
I received a comment from Grant regarding the same.
I'm away from work this weekend. Will submit the code once i get back,
>
>> +     if (timeout == 0) {
>> +             dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
>> +             exynos_adc_hw_init(info);
>> +             ret = -ETIMEDOUT;
>> +     } else {
>> +             *val = info->value;
>> +             ret = IIO_VAL_INT;
>> +     }
>>       *val = info->value;
>
> This line above should probably be removed.
Yes this is unnecessary. Will remove this.
>
>>
>>       mutex_unlock(&indio_dev->mlock);
>>
>> -     if (timeout == 0)
>> -             return -ETIMEDOUT;
>> -
>> -     return IIO_VAL_INT;
>> +     return ret;
>>  }
>>
>>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
>> @@ -226,30 +256,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
>>       return 0;
>>  }
>>
>> -static void exynos_adc_hw_init(struct exynos_adc *info)
>> -{
>> -     u32 con1, con2;
>> -
>> -     if (info->version == ADC_V2) {
>> -             con1 = ADC_V2_CON1_SOFT_RESET;
>> -             writel(con1, ADC_V2_CON1(info->regs));
>> -
>> -             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> -                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> -             writel(con2, ADC_V2_CON2(info->regs));
>> -
>> -             /* Enable interrupts */
>> -             writel(1, ADC_V2_INT_EN(info->regs));
>> -     } else {
>> -             /* set default prescaler values and Enable prescaler */
>> -             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> -
>> -             /* Enable 12-bit ADC resolution */
>> -             con1 |= ADC_V1_CON_RES;
>> -             writel(con1, ADC_V1_CON(info->regs));
>> -     }
>> -}
>> -
>>  static int exynos_adc_probe(struct platform_device *pdev)
>>  {
>>       struct exynos_adc *info = NULL;
>>
>
Thanks for the review.



-- 
Shine bright,
(: Nav :)

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

* Re: [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
@ 2013-10-12  6:40           ` Naveen Krishna Ch
  0 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Ch @ 2013-10-12  6:40 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Naveen Krishna Chatradhi, linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	dianders-F7+t8E8rja9g9hUCZPvPmw,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	tomasz.figa-Re5JQEeQqe8AvxtiuMwx3w

On 11 October 2013 20:00, Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org> wrote:
> On 10/11/2013 10:23 AM, Naveen Krishna Chatradhi wrote:
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>
> It is always good to have a description of why a chance should be done in
> the commit message. It is obvious what the patch does by just looking at the
> changed lines, it is not that obvious though why those lines had to be changed.
>
>>
>> Note: submitted for review at https://patchwork.kernel.org/patch/2279591/
>>
>> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
>> Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
>> Cc: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
>> ---
>> Changes since v1:
>> As per discussion at
>> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
>>
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>>
>> Changes since v2:
>> None.
>> Rebased and reposting.
>>
>> ---
>>  drivers/iio/adc/exynos_adc.c |   66 +++++++++++++++++++++++-------------------
>>  1 file changed, 36 insertions(+), 30 deletions(-)
>>
>> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
>> index d25b262..f18ed7e 100644
>> --- a/drivers/iio/adc/exynos_adc.c
>> +++ b/drivers/iio/adc/exynos_adc.c
>> @@ -82,7 +82,7 @@ enum adc_version {
>>  #define ADC_CON_EN_START     (1u << 0)
>>  #define ADC_DATX_MASK                0xFFF
>>
>> -#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(1000))
>> +#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(100))
>>
>>  struct exynos_adc {
>>       void __iomem            *regs;
>> @@ -112,6 +112,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
>>       return (unsigned int)match->data;
>>  }
>>
>> +static void exynos_adc_hw_init(struct exynos_adc *info)
>> +{
>> +     u32 con1, con2;
>> +
>> +     if (info->version == ADC_V2) {
>> +             con1 = ADC_V2_CON1_SOFT_RESET;
>> +             writel(con1, ADC_V2_CON1(info->regs));
>> +
>> +             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> +                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> +             writel(con2, ADC_V2_CON2(info->regs));
>> +
>> +             /* Enable interrupts */
>> +             writel(1, ADC_V2_INT_EN(info->regs));
>> +     } else {
>> +             /* set default prescaler values and Enable prescaler */
>> +             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> +
>> +             /* Enable 12-bit ADC resolution */
>> +             con1 |= ADC_V1_CON_RES;
>> +             writel(con1, ADC_V1_CON(info->regs));
>> +     }
>> +}
>> +
>>  static int exynos_read_raw(struct iio_dev *indio_dev,
>>                               struct iio_chan_spec const *chan,
>>                               int *val,
>> @@ -121,6 +145,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>>       struct exynos_adc *info = iio_priv(indio_dev);
>>       unsigned long timeout;
>>       u32 con1, con2;
>> +     int ret;
>>
>>       if (mask != IIO_CHAN_INFO_RAW)
>>               return -EINVAL;
>> @@ -145,16 +170,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>>                               ADC_V1_CON(info->regs));
>>       }
>>
>> -     timeout = wait_for_completion_interruptible_timeout
>> +     timeout = wait_for_completion_timeout
>>                       (&info->completion, EXYNOS_ADC_TIMEOUT);
>
> Nitpick: It would be nice to put the &info->completion on the same line as
> the wait_for_completion...
I received a comment from Grant regarding the same.
I'm away from work this weekend. Will submit the code once i get back,
>
>> +     if (timeout == 0) {
>> +             dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
>> +             exynos_adc_hw_init(info);
>> +             ret = -ETIMEDOUT;
>> +     } else {
>> +             *val = info->value;
>> +             ret = IIO_VAL_INT;
>> +     }
>>       *val = info->value;
>
> This line above should probably be removed.
Yes this is unnecessary. Will remove this.
>
>>
>>       mutex_unlock(&indio_dev->mlock);
>>
>> -     if (timeout == 0)
>> -             return -ETIMEDOUT;
>> -
>> -     return IIO_VAL_INT;
>> +     return ret;
>>  }
>>
>>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
>> @@ -226,30 +256,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
>>       return 0;
>>  }
>>
>> -static void exynos_adc_hw_init(struct exynos_adc *info)
>> -{
>> -     u32 con1, con2;
>> -
>> -     if (info->version == ADC_V2) {
>> -             con1 = ADC_V2_CON1_SOFT_RESET;
>> -             writel(con1, ADC_V2_CON1(info->regs));
>> -
>> -             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> -                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> -             writel(con2, ADC_V2_CON2(info->regs));
>> -
>> -             /* Enable interrupts */
>> -             writel(1, ADC_V2_INT_EN(info->regs));
>> -     } else {
>> -             /* set default prescaler values and Enable prescaler */
>> -             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> -
>> -             /* Enable 12-bit ADC resolution */
>> -             con1 |= ADC_V1_CON_RES;
>> -             writel(con1, ADC_V1_CON(info->regs));
>> -     }
>> -}
>> -
>>  static int exynos_adc_probe(struct platform_device *pdev)
>>  {
>>       struct exynos_adc *info = NULL;
>>
>
Thanks for the review.



-- 
Shine bright,
(: Nav :)

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

* Re: [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
@ 2013-10-12  6:40           ` Naveen Krishna Ch
  0 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Ch @ 2013-10-12  6:40 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
	linux-samsung-soc, dianders, gregkh, tomasz.figa

On 11 October 2013 20:00, Lars-Peter Clausen <lars@metafoo.de> wrote:
> On 10/11/2013 10:23 AM, Naveen Krishna Chatradhi wrote:
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>
> It is always good to have a description of why a chance should be done in
> the commit message. It is obvious what the patch does by just looking at the
> changed lines, it is not that obvious though why those lines had to be changed.
>
>>
>> Note: submitted for review at https://patchwork.kernel.org/patch/2279591/
>>
>> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
>> Cc: Doug Anderson <dianders@chromium.org>
>> Cc: Lars-Peter Clausen <lars@metafoo.de>
>> ---
>> Changes since v1:
>> As per discussion at
>> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
>>
>> This patch does the following
>> 1. use wait_for_completion_timeout instead of
>>    wait_for_completion_interruptible_timeout
>> 2. Reset software if a timeout happens.
>> 3. Also reduce the timeout to 100milli secs
>>
>> Changes since v2:
>> None.
>> Rebased and reposting.
>>
>> ---
>>  drivers/iio/adc/exynos_adc.c |   66 +++++++++++++++++++++++-------------------
>>  1 file changed, 36 insertions(+), 30 deletions(-)
>>
>> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
>> index d25b262..f18ed7e 100644
>> --- a/drivers/iio/adc/exynos_adc.c
>> +++ b/drivers/iio/adc/exynos_adc.c
>> @@ -82,7 +82,7 @@ enum adc_version {
>>  #define ADC_CON_EN_START     (1u << 0)
>>  #define ADC_DATX_MASK                0xFFF
>>
>> -#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(1000))
>> +#define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(100))
>>
>>  struct exynos_adc {
>>       void __iomem            *regs;
>> @@ -112,6 +112,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
>>       return (unsigned int)match->data;
>>  }
>>
>> +static void exynos_adc_hw_init(struct exynos_adc *info)
>> +{
>> +     u32 con1, con2;
>> +
>> +     if (info->version == ADC_V2) {
>> +             con1 = ADC_V2_CON1_SOFT_RESET;
>> +             writel(con1, ADC_V2_CON1(info->regs));
>> +
>> +             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> +                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> +             writel(con2, ADC_V2_CON2(info->regs));
>> +
>> +             /* Enable interrupts */
>> +             writel(1, ADC_V2_INT_EN(info->regs));
>> +     } else {
>> +             /* set default prescaler values and Enable prescaler */
>> +             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> +
>> +             /* Enable 12-bit ADC resolution */
>> +             con1 |= ADC_V1_CON_RES;
>> +             writel(con1, ADC_V1_CON(info->regs));
>> +     }
>> +}
>> +
>>  static int exynos_read_raw(struct iio_dev *indio_dev,
>>                               struct iio_chan_spec const *chan,
>>                               int *val,
>> @@ -121,6 +145,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>>       struct exynos_adc *info = iio_priv(indio_dev);
>>       unsigned long timeout;
>>       u32 con1, con2;
>> +     int ret;
>>
>>       if (mask != IIO_CHAN_INFO_RAW)
>>               return -EINVAL;
>> @@ -145,16 +170,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>>                               ADC_V1_CON(info->regs));
>>       }
>>
>> -     timeout = wait_for_completion_interruptible_timeout
>> +     timeout = wait_for_completion_timeout
>>                       (&info->completion, EXYNOS_ADC_TIMEOUT);
>
> Nitpick: It would be nice to put the &info->completion on the same line as
> the wait_for_completion...
I received a comment from Grant regarding the same.
I'm away from work this weekend. Will submit the code once i get back,
>
>> +     if (timeout == 0) {
>> +             dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
>> +             exynos_adc_hw_init(info);
>> +             ret = -ETIMEDOUT;
>> +     } else {
>> +             *val = info->value;
>> +             ret = IIO_VAL_INT;
>> +     }
>>       *val = info->value;
>
> This line above should probably be removed.
Yes this is unnecessary. Will remove this.
>
>>
>>       mutex_unlock(&indio_dev->mlock);
>>
>> -     if (timeout == 0)
>> -             return -ETIMEDOUT;
>> -
>> -     return IIO_VAL_INT;
>> +     return ret;
>>  }
>>
>>  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
>> @@ -226,30 +256,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
>>       return 0;
>>  }
>>
>> -static void exynos_adc_hw_init(struct exynos_adc *info)
>> -{
>> -     u32 con1, con2;
>> -
>> -     if (info->version == ADC_V2) {
>> -             con1 = ADC_V2_CON1_SOFT_RESET;
>> -             writel(con1, ADC_V2_CON1(info->regs));
>> -
>> -             con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
>> -                     ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
>> -             writel(con2, ADC_V2_CON2(info->regs));
>> -
>> -             /* Enable interrupts */
>> -             writel(1, ADC_V2_INT_EN(info->regs));
>> -     } else {
>> -             /* set default prescaler values and Enable prescaler */
>> -             con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
>> -
>> -             /* Enable 12-bit ADC resolution */
>> -             con1 |= ADC_V1_CON_RES;
>> -             writel(con1, ADC_V1_CON(info->regs));
>> -     }
>> -}
>> -
>>  static int exynos_adc_probe(struct platform_device *pdev)
>>  {
>>       struct exynos_adc *info = NULL;
>>
>
Thanks for the review.



-- 
Shine bright,
(: Nav :)

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

* [PATCH v4] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
  2013-10-11  8:23     ` [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible Naveen Krishna Chatradhi
  2013-10-11 14:30         ` Lars-Peter Clausen
@ 2013-10-15  5:15       ` Naveen Krishna Chatradhi
  2013-10-25 15:42         ` Doug Anderson
  2013-10-28  5:41       ` [PATCH v5] " Naveen Krishna Chatradhi
  2013-11-05  9:45       ` [PATCH v6] " Naveen Krishna Chatradhi
  3 siblings, 1 reply; 39+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-10-15  5:15 UTC (permalink / raw)
  To: linux-iio
  Cc: linux-kernel, linux-samsung-soc, dianders, gregkh,
	naveenkrishna.ch, lars, cpgs

This patch does the following
1. The irq routine is so simple (just one register read) shouldn't be long
   Hence, reduce the timeout to 100milli secs,
2. With 100ms of wait time, interruptible is very much unnecessary.
   Hence, use wait_for_completion_timeout instead of
   wait_for_completion_interruptible_timeout
3. Reset software if a timeout happens.
4. Add INIT_COMPLETION before the wait_for_completion_timeout in raw_read()

Note: submitted for review at https://patchwork.kernel.org/patch/2279591/

Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
---
Changes since v1:
As per discussion at
http://marc.info/?l=linux-kernel&m=136517637228869&w=3

Changes since v2:
None.
Rebased and reposting.

Changes since v3:
1. commit message change and
2. removed an unncessary assignment

 drivers/iio/adc/exynos_adc.c |   69 +++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 31 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index d25b262..ac25e3e 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -82,7 +82,7 @@ enum adc_version {
 #define ADC_CON_EN_START	(1u << 0)
 #define ADC_DATX_MASK		0xFFF
 
-#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(1000))
+#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(100))
 
 struct exynos_adc {
 	void __iomem		*regs;
@@ -112,6 +112,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
 	return (unsigned int)match->data;
 }
 
+static void exynos_adc_hw_init(struct exynos_adc *info)
+{
+	u32 con1, con2;
+
+	if (info->version == ADC_V2) {
+		con1 = ADC_V2_CON1_SOFT_RESET;
+		writel(con1, ADC_V2_CON1(info->regs));
+
+		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
+			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
+		writel(con2, ADC_V2_CON2(info->regs));
+
+		/* Enable interrupts */
+		writel(1, ADC_V2_INT_EN(info->regs));
+	} else {
+		/* set default prescaler values and Enable prescaler */
+		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
+
+		/* Enable 12-bit ADC resolution */
+		con1 |= ADC_V1_CON_RES;
+		writel(con1, ADC_V1_CON(info->regs));
+	}
+}
+
 static int exynos_read_raw(struct iio_dev *indio_dev,
 				struct iio_chan_spec const *chan,
 				int *val,
@@ -121,6 +145,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 	struct exynos_adc *info = iio_priv(indio_dev);
 	unsigned long timeout;
 	u32 con1, con2;
+	int ret;
 
 	if (mask != IIO_CHAN_INFO_RAW)
 		return -EINVAL;
@@ -145,16 +170,22 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				ADC_V1_CON(info->regs));
 	}
 
-	timeout = wait_for_completion_interruptible_timeout
+	INIT_COMPLETION(info->completion);
+
+	timeout = wait_for_completion_timeout
 			(&info->completion, EXYNOS_ADC_TIMEOUT);
-	*val = info->value;
+	if (timeout == 0) {
+		dev_warn(&indio_dev->dev, "Conversion timed out reseting\n");
+		exynos_adc_hw_init(info);
+		ret = -ETIMEDOUT;
+	} else {
+		*val = info->value;
+		ret = IIO_VAL_INT;
+	}
 
 	mutex_unlock(&indio_dev->mlock);
 
-	if (timeout == 0)
-		return -ETIMEDOUT;
-
-	return IIO_VAL_INT;
+	return ret;
 }
 
 static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
@@ -226,30 +257,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
 	return 0;
 }
 
-static void exynos_adc_hw_init(struct exynos_adc *info)
-{
-	u32 con1, con2;
-
-	if (info->version == ADC_V2) {
-		con1 = ADC_V2_CON1_SOFT_RESET;
-		writel(con1, ADC_V2_CON1(info->regs));
-
-		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
-			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
-		writel(con2, ADC_V2_CON2(info->regs));
-
-		/* Enable interrupts */
-		writel(1, ADC_V2_INT_EN(info->regs));
-	} else {
-		/* set default prescaler values and Enable prescaler */
-		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
-
-		/* Enable 12-bit ADC resolution */
-		con1 |= ADC_V1_CON_RES;
-		writel(con1, ADC_V1_CON(info->regs));
-	}
-}
-
 static int exynos_adc_probe(struct platform_device *pdev)
 {
 	struct exynos_adc *info = NULL;
-- 
1.7.10.4


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

* Re: [PATCH v4] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
  2013-10-15  5:15       ` [PATCH v4] " Naveen Krishna Chatradhi
@ 2013-10-25 15:42         ` Doug Anderson
  0 siblings, 0 replies; 39+ messages in thread
From: Doug Anderson @ 2013-10-25 15:42 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi, Grant Grundler
  Cc: linux-iio, linux-kernel, linux-samsung-soc, Greg Kroah-Hartman,
	Naveen Krishna, Lars-Peter Clausen, cpgs .

Naveen,

On Mon, Oct 14, 2013 at 10:15 PM, Naveen Krishna Chatradhi
<ch.naveen@samsung.com> wrote:
> This patch does the following
> 1. The irq routine is so simple (just one register read) shouldn't be long
>    Hence, reduce the timeout to 100milli secs,
> 2. With 100ms of wait time, interruptible is very much unnecessary.
>    Hence, use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 3. Reset software if a timeout happens.
> 4. Add INIT_COMPLETION before the wait_for_completion_timeout in raw_read()
>
> Note: submitted for review at https://patchwork.kernel.org/patch/2279591/
>
> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
> Cc: Doug Anderson <dianders@chromium.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> ---
> Changes since v1:
> As per discussion at
> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
>
> Changes since v2:
> None.
> Rebased and reposting.
>
> Changes since v3:
> 1. commit message change and
> 2. removed an unncessary assignment
>
>  drivers/iio/adc/exynos_adc.c |   69 +++++++++++++++++++++++-------------------
>  1 file changed, 38 insertions(+), 31 deletions(-)

Please spin to match the changes that Grant requested on our gerrit at
<https://chromium-review.googlesource.com/172724>.  Thanks!  :)

-Doug

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

* [PATCH v5] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
  2013-10-11  8:23     ` [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible Naveen Krishna Chatradhi
  2013-10-11 14:30         ` Lars-Peter Clausen
  2013-10-15  5:15       ` [PATCH v4] " Naveen Krishna Chatradhi
@ 2013-10-28  5:41       ` Naveen Krishna Chatradhi
  2013-11-05  9:45       ` [PATCH v6] " Naveen Krishna Chatradhi
  3 siblings, 0 replies; 39+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-10-28  5:41 UTC (permalink / raw)
  To: linux-iio
  Cc: linux-kernel, linux-samsung-soc, dianders, gregkh,
	naveenkrishna.ch, lars, grundler, cpgs

1. The irq routine is so simple (just one register read) shouldn't be long
   Hence, reduce the timeout to 100milli secs,
2. With 100ms of wait time, interruptible is very much unnecessary.
   Hence, use wait_for_completion_timeout instead of
   wait_for_completion_interruptible_timeout
3. Reset software if a timeout happens.
4. Add INIT_COMPLETION before the wait_for_completion_timeout in raw_read()

Note: submitted for review at https://patchwork.kernel.org/patch/2279591/

Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-on: https://chromium-review.googlesource.com/172724
Reviewed-by: Doug Anderson <dianders@chromium.org>
---
Changes since v1:
As per discussion at
http://marc.info/?l=linux-kernel&m=136517637228869&w=3

Changes since v2:
None.
Rebased and reposting.

Changes since v3:
1. commit message change and
2. removed an unncessary assignment

Changes since v4:
Moved INIT_COMPLETION call to the starting of the function


 drivers/iio/adc/exynos_adc.c | 69 ++++++++++++++++++++++++--------------------
 1 file changed, 38 insertions(+), 31 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 0f2ca60..a675751 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -81,7 +81,7 @@ enum adc_version {
 #define ADC_CON_EN_START	(1u << 0)
 #define ADC_DATX_MASK		0xFFF
 
-#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(1000))
+#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(100))
 
 struct exynos_adc {
 	void __iomem		*regs;
@@ -111,6 +111,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
 	return (unsigned int)match->data;
 }
 
+static void exynos_adc_hw_init(struct exynos_adc *info)
+{
+	u32 con1, con2;
+
+	if (info->version == ADC_V2) {
+		con1 = ADC_V2_CON1_SOFT_RESET;
+		writel(con1, ADC_V2_CON1(info->regs));
+
+		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
+			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
+		writel(con2, ADC_V2_CON2(info->regs));
+
+		/* Enable interrupts */
+		writel(1, ADC_V2_INT_EN(info->regs));
+	} else {
+		/* set default prescaler values and Enable prescaler */
+		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
+
+		/* Enable 12-bit ADC resolution */
+		con1 |= ADC_V1_CON_RES;
+		writel(con1, ADC_V1_CON(info->regs));
+	}
+}
+
 static int exynos_read_raw(struct iio_dev *indio_dev,
 				struct iio_chan_spec const *chan,
 				int *val,
@@ -120,11 +144,13 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 	struct exynos_adc *info = iio_priv(indio_dev);
 	unsigned long timeout;
 	u32 con1, con2;
+	int ret;
 
 	if (mask != IIO_CHAN_INFO_RAW)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
+	INIT_COMPLETION(info->completion);
 
 	/* Select the channel to be used and Trigger conversion */
 	if (info->version == ADC_V2) {
@@ -144,16 +170,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				ADC_V1_CON(info->regs));
 	}
 
-	timeout = wait_for_completion_interruptible_timeout
+	timeout = wait_for_completion_timeout
 			(&info->completion, EXYNOS_ADC_TIMEOUT);
-	*val = info->value;
+	if (timeout == 0) {
+		dev_warn(&indio_dev->dev, "Conversion timed out! Resetting\n");
+		exynos_adc_hw_init(info);
+		ret = -ETIMEDOUT;
+	} else {
+		*val = info->value;
+		*val2 = 0;
+		ret = IIO_VAL_INT;
+	}
 
 	mutex_unlock(&indio_dev->mlock);
 
-	if (timeout == 0)
-		return -ETIMEDOUT;
-
-	return IIO_VAL_INT;
+	return ret;
 }
 
 static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
@@ -225,30 +256,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
 	return 0;
 }
 
-static void exynos_adc_hw_init(struct exynos_adc *info)
-{
-	u32 con1, con2;
-
-	if (info->version == ADC_V2) {
-		con1 = ADC_V2_CON1_SOFT_RESET;
-		writel(con1, ADC_V2_CON1(info->regs));
-
-		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
-			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
-		writel(con2, ADC_V2_CON2(info->regs));
-
-		/* Enable interrupts */
-		writel(1, ADC_V2_INT_EN(info->regs));
-	} else {
-		/* set default prescaler values and Enable prescaler */
-		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
-
-		/* Enable 12-bit ADC resolution */
-		con1 |= ADC_V1_CON_RES;
-		writel(con1, ADC_V1_CON(info->regs));
-	}
-}
-
 static int exynos_adc_probe(struct platform_device *pdev)
 {
 	struct exynos_adc *info = NULL;
-- 
1.7.12.4


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

* [PATCH v6] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
  2013-10-11  8:23     ` [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible Naveen Krishna Chatradhi
                         ` (2 preceding siblings ...)
  2013-10-28  5:41       ` [PATCH v5] " Naveen Krishna Chatradhi
@ 2013-11-05  9:45       ` Naveen Krishna Chatradhi
  2013-11-10 12:48           ` Tomasz Figa
  3 siblings, 1 reply; 39+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-11-05  9:45 UTC (permalink / raw)
  To: linux-iio
  Cc: linux-kernel, linux-samsung-soc, dianders, gregkh,
	naveenkrishna.ch, lars, grundler, cpgs

1. The irq routine is so simple (just one register read) shouldn't be long
   Hence, reduce the timeout to 100milli secs,
2. With 100ms of wait time, interruptible is very much unnecessary.
   Hence, use wait_for_completion_timeout instead of
   wait_for_completion_interruptible_timeout
3. Reset software if a timeout happens.
4. Add reinit_completion() before the wait_for_completion_timeout in raw_read()

Note: submitted for review at https://patchwork.kernel.org/patch/2279591/

Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-on: https://chromium-review.googlesource.com/172724
Reviewed-by: Doug Anderson <dianders@chromium.org>
---
Changes since v1:
As per discussion at
http://marc.info/?l=linux-kernel&m=136517637228869&w=3

Changes since v2:
None.
Rebased and reposting.

Changes since v3:
1. commit message change and
2. removed an unncessary assignment

Changes since v4:
Moved INIT_COMPLETION call to the starting of the function

Changes since v5:
INIT_COMPLETION was replaced by reinit_completion
("tree-wide: use reinit_completion instead of INIT_COMPLETION").
Use it to avoid the following build error:
undefined identifier 'INIT_COMPLETION'


 drivers/iio/adc/exynos_adc.c | 69 ++++++++++++++++++++++++--------------------
 1 file changed, 38 insertions(+), 31 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 0f2ca60..a675751 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -81,7 +81,7 @@ enum adc_version {
 #define ADC_CON_EN_START	(1u << 0)
 #define ADC_DATX_MASK		0xFFF
 
-#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(1000))
+#define EXYNOS_ADC_TIMEOUT	(msecs_to_jiffies(100))
 
 struct exynos_adc {
 	void __iomem		*regs;
@@ -111,6 +111,30 @@ static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
 	return (unsigned int)match->data;
 }
 
+static void exynos_adc_hw_init(struct exynos_adc *info)
+{
+	u32 con1, con2;
+
+	if (info->version == ADC_V2) {
+		con1 = ADC_V2_CON1_SOFT_RESET;
+		writel(con1, ADC_V2_CON1(info->regs));
+
+		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
+			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
+		writel(con2, ADC_V2_CON2(info->regs));
+
+		/* Enable interrupts */
+		writel(1, ADC_V2_INT_EN(info->regs));
+	} else {
+		/* set default prescaler values and Enable prescaler */
+		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
+
+		/* Enable 12-bit ADC resolution */
+		con1 |= ADC_V1_CON_RES;
+		writel(con1, ADC_V1_CON(info->regs));
+	}
+}
+
 static int exynos_read_raw(struct iio_dev *indio_dev,
 				struct iio_chan_spec const *chan,
 				int *val,
@@ -120,11 +144,13 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 	struct exynos_adc *info = iio_priv(indio_dev);
 	unsigned long timeout;
 	u32 con1, con2;
+	int ret;
 
 	if (mask != IIO_CHAN_INFO_RAW)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
+	reinit_completion(&info->completion);
 
 	/* Select the channel to be used and Trigger conversion */
 	if (info->version == ADC_V2) {
@@ -144,16 +170,21 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 				ADC_V1_CON(info->regs));
 	}
 
-	timeout = wait_for_completion_interruptible_timeout
+	timeout = wait_for_completion_timeout
 			(&info->completion, EXYNOS_ADC_TIMEOUT);
-	*val = info->value;
+	if (timeout == 0) {
+		dev_warn(&indio_dev->dev, "Conversion timed out! Resetting\n");
+		exynos_adc_hw_init(info);
+		ret = -ETIMEDOUT;
+	} else {
+		*val = info->value;
+		*val2 = 0;
+		ret = IIO_VAL_INT;
+	}
 
 	mutex_unlock(&indio_dev->mlock);
 
-	if (timeout == 0)
-		return -ETIMEDOUT;
-
-	return IIO_VAL_INT;
+	return ret;
 }
 
 static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
@@ -225,30 +256,6 @@ static int exynos_adc_remove_devices(struct device *dev, void *c)
 	return 0;
 }
 
-static void exynos_adc_hw_init(struct exynos_adc *info)
-{
-	u32 con1, con2;
-
-	if (info->version == ADC_V2) {
-		con1 = ADC_V2_CON1_SOFT_RESET;
-		writel(con1, ADC_V2_CON1(info->regs));
-
-		con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
-			ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
-		writel(con2, ADC_V2_CON2(info->regs));
-
-		/* Enable interrupts */
-		writel(1, ADC_V2_INT_EN(info->regs));
-	} else {
-		/* set default prescaler values and Enable prescaler */
-		con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
-
-		/* Enable 12-bit ADC resolution */
-		con1 |= ADC_V1_CON_RES;
-		writel(con1, ADC_V1_CON(info->regs));
-	}
-}
-
 static int exynos_adc_probe(struct platform_device *pdev)
 {
 	struct exynos_adc *info = NULL;
-- 
1.7.12.4


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

* Re: [PATCH v6] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
@ 2013-11-10 12:48           ` Tomasz Figa
  0 siblings, 0 replies; 39+ messages in thread
From: Tomasz Figa @ 2013-11-10 12:48 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi
  Cc: linux-iio, linux-kernel, linux-samsung-soc, dianders, gregkh,
	naveenkrishna.ch, lars, grundler, cpgs

Hi Naveen,

On Tuesday 05 of November 2013 15:15:30 Naveen Krishna Chatradhi wrote:
> 1. The irq routine is so simple (just one register read) shouldn't be
> long Hence, reduce the timeout to 100milli secs,

I believe that the timeout value depends mostly on maximum conversion time 
and interrupt handler complexity is not very significant here.

> 2. With 100ms of wait time, interruptible is very much unnecessary.
>    Hence, use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 3. Reset software if a timeout happens.
> 4. Add reinit_completion() before the wait_for_completion_timeout in
> raw_read()

All the four points listed above, even just by the form they are written 
in, suggest that they should be separate four patches.

In addition, patch description should explain why such change is needed, 
i.e. what it fixes, improves or prepares the code for.

> Note: submitted for review at
> https://patchwork.kernel.org/patch/2279591/
> 

This should not be located in patch description, but rather in comments 
section below, as is the change log.

> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
> Cc: Doug Anderson <dianders@chromium.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Reviewed-on: https://chromium-review.googlesource.com/172724
> Reviewed-by: Doug Anderson <dianders@chromium.org>
> ---
> Changes since v1:
> As per discussion at
> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
> 
> Changes since v2:
> None.
> Rebased and reposting.
> 
> Changes since v3:
> 1. commit message change and
> 2. removed an unncessary assignment
> 
> Changes since v4:
> Moved INIT_COMPLETION call to the starting of the function
> 
> Changes since v5:
> INIT_COMPLETION was replaced by reinit_completion
> ("tree-wide: use reinit_completion instead of INIT_COMPLETION").
> Use it to avoid the following build error:
> undefined identifier 'INIT_COMPLETION'

Not really a comment to the patch, but rather a suggestion for future:

It is more convenient to read the change log if it goes from newest to 
oldest order.

Otherwise the changes alone look good.

Best regards,
Tomasz


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

* Re: [PATCH v6] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible
@ 2013-11-10 12:48           ` Tomasz Figa
  0 siblings, 0 replies; 39+ messages in thread
From: Tomasz Figa @ 2013-11-10 12:48 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	dianders-F7+t8E8rja9g9hUCZPvPmw,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w,
	lars-Qo5EllUWu/uELgA04lAiVw, grundler-F7+t8E8rja9g9hUCZPvPmw,
	cpgs-Sze3O3UU22JBDgjK7y7TUQ

Hi Naveen,

On Tuesday 05 of November 2013 15:15:30 Naveen Krishna Chatradhi wrote:
> 1. The irq routine is so simple (just one register read) shouldn't be
> long Hence, reduce the timeout to 100milli secs,

I believe that the timeout value depends mostly on maximum conversion time 
and interrupt handler complexity is not very significant here.

> 2. With 100ms of wait time, interruptible is very much unnecessary.
>    Hence, use wait_for_completion_timeout instead of
>    wait_for_completion_interruptible_timeout
> 3. Reset software if a timeout happens.
> 4. Add reinit_completion() before the wait_for_completion_timeout in
> raw_read()

All the four points listed above, even just by the form they are written 
in, suggest that they should be separate four patches.

In addition, patch description should explain why such change is needed, 
i.e. what it fixes, improves or prepares the code for.

> Note: submitted for review at
> https://patchwork.kernel.org/patch/2279591/
> 

This should not be located in patch description, but rather in comments 
section below, as is the change log.

> Signed-off-by: Naveen Krishna Chatradhi <ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
> Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Cc: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
> Reviewed-on: https://chromium-review.googlesource.com/172724
> Reviewed-by: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> ---
> Changes since v1:
> As per discussion at
> http://marc.info/?l=linux-kernel&m=136517637228869&w=3
> 
> Changes since v2:
> None.
> Rebased and reposting.
> 
> Changes since v3:
> 1. commit message change and
> 2. removed an unncessary assignment
> 
> Changes since v4:
> Moved INIT_COMPLETION call to the starting of the function
> 
> Changes since v5:
> INIT_COMPLETION was replaced by reinit_completion
> ("tree-wide: use reinit_completion instead of INIT_COMPLETION").
> Use it to avoid the following build error:
> undefined identifier 'INIT_COMPLETION'

Not really a comment to the patch, but rather a suggestion for future:

It is more convenient to read the change log if it goes from newest to 
oldest order.

Otherwise the changes alone look good.

Best regards,
Tomasz

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

end of thread, other threads:[~2013-11-10 12:48 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-15 16:26 [RFC: PATCH 2/2] iio: adc: exynos_adc: Handle timeout and race conditions Naveen Krishna Chatradhi
2013-03-15 21:53 ` Lars-Peter Clausen
2013-03-15 21:53   ` Lars-Peter Clausen
2013-03-16  0:37   ` Doug Anderson
2013-03-16 14:41     ` Lars-Peter Clausen
2013-03-16 14:41       ` Lars-Peter Clausen
2013-04-03 17:06       ` Doug Anderson
2013-04-03 17:06         ` Doug Anderson
2013-04-05  8:53         ` Lars-Peter Clausen
2013-04-05 14:56           ` Doug Anderson
2013-04-05 14:56             ` Doug Anderson
2013-04-05 16:38             ` Lars-Peter Clausen
2013-04-04  3:59 ` [PATCH 14/14] temp: iio: adc: exynos_adc: Handle timeout issues Naveen Krishna Chatradhi
2013-04-04  4:09   ` Naveen Krishna Ch
     [not found] ` <1363364801-23684-1-git-send-email-ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2013-04-04  4:06   ` [PATCH] " Naveen Krishna Chatradhi
2013-04-04  4:06     ` Naveen Krishna Chatradhi
     [not found]     ` <1365048389-6364-1-git-send-email-naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-04-13  4:36       ` Naveen Krishna Ch
2013-04-13  4:36         ` Naveen Krishna Ch
     [not found]         ` <CAHfPSqAVUVdFwtMxJYCGaPv_+iO_GEc9_UGNXwuSj9uu_fB81g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-04-15 16:01           ` Doug Anderson
2013-04-15 16:01             ` Doug Anderson
2013-05-02 18:01     ` [PATCH v2] " Naveen Krishna Chatradhi
     [not found]       ` <1367517663-12225-1-git-send-email-naveenkrishna.ch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-05-02 18:10         ` Tomasz Figa
2013-05-02 18:10           ` Tomasz Figa
2013-05-02 18:22           ` Naveen Krishna Ch
2013-05-02 18:22             ` Naveen Krishna Ch
     [not found]             ` <CAHfPSqCc81765zQVur=AtW2Cf+taYef=LYJK008i03cmYPu0WQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-05-02 18:36               ` Tomasz Figa
2013-05-02 18:36                 ` Tomasz Figa
2013-10-11  8:23     ` [PATCH v3] iio: exynos_adc: use wait_for_completion_timeout instead of interruptible Naveen Krishna Chatradhi
2013-10-11 14:30       ` Lars-Peter Clausen
2013-10-11 14:30         ` Lars-Peter Clausen
2013-10-12  6:40         ` Naveen Krishna Ch
2013-10-12  6:40           ` Naveen Krishna Ch
2013-10-12  6:40           ` Naveen Krishna Ch
2013-10-15  5:15       ` [PATCH v4] " Naveen Krishna Chatradhi
2013-10-25 15:42         ` Doug Anderson
2013-10-28  5:41       ` [PATCH v5] " Naveen Krishna Chatradhi
2013-11-05  9:45       ` [PATCH v6] " Naveen Krishna Chatradhi
2013-11-10 12:48         ` Tomasz Figa
2013-11-10 12:48           ` Tomasz Figa

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.