From: Naveen Krishna Chatradhi <naveenkrishna.ch@gmail.com>
To: linux-iio@vger.kernel.org
Cc: linux-samsung-soc@vger.kernel.org, jic23@cam.ac.uk,
Naveen Krishna Chatradhi <ch.naveen@samsung.com>,
Doug Anderson <dianders@chromium.org>,
Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH] iio: adc: exynos_adc: Handle timeout issues
Date: Wed, 3 Apr 2013 21:06:28 -0700 [thread overview]
Message-ID: <1365048389-6364-1-git-send-email-naveenkrishna.ch@gmail.com> (raw)
In-Reply-To: <1363364801-23684-1-git-send-email-ch.naveen@samsung.com>
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
next prev parent reply other threads:[~2013-04-04 4:06 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
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-16 0:37 ` Doug Anderson
2013-03-16 14:41 ` Lars-Peter Clausen
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 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
2013-04-04 4:06 ` Naveen Krishna Chatradhi [this message]
2013-04-13 4:36 ` [PATCH] " Naveen Krishna Ch
2013-04-15 16:01 ` Doug Anderson
2013-05-02 18:01 ` [PATCH v2] " Naveen Krishna Chatradhi
2013-05-02 18:10 ` Tomasz Figa
2013-05-02 18:22 ` Naveen Krishna Ch
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-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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1365048389-6364-1-git-send-email-naveenkrishna.ch@gmail.com \
--to=naveenkrishna.ch@gmail.com \
--cc=ch.naveen@samsung.com \
--cc=dianders@chromium.org \
--cc=jic23@cam.ac.uk \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).