From patchwork Thu Apr 4 04:06:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen Krishna Ch X-Patchwork-Id: 2390471 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 75E723FD8C for ; Thu, 4 Apr 2013 04:06:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750759Ab3DDEGf (ORCPT ); Thu, 4 Apr 2013 00:06:35 -0400 Received: from mail-pb0-f50.google.com ([209.85.160.50]:40565 "EHLO mail-pb0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750699Ab3DDEGf (ORCPT ); Thu, 4 Apr 2013 00:06:35 -0400 Received: by mail-pb0-f50.google.com with SMTP id jt11so1192817pbb.23 for ; Wed, 03 Apr 2013 21:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=esj7HGRIKd974GDCS9VAPXeOz/hEMXQOxOXKc4UikMY=; b=nBHc+BHniXJjwMbPNEakfIdHw6J0tQdzBt594ajqcIHqgpfgsybewP4wc+fQtcAMzm iEf/XxZUjZ+QuQ4GIAcES/MJ5T0AfkwU7D2gQ8pIDd95/UaPhnRvGoVmu36K7Pn7nGb6 FmQrYQ9Hf88ffuqotlm7ZrUgexPhTEOwrni+XMqlYMYv3zYSWJnYfkahX9OG1q8H9kIv 0EFgxbtncdJwOSgy2rSlzwoB4ESjlTJJtXPZSUgOet/TcPbrbIWRJOW9Dap0sARB6hq5 cJppMEH9KmWG0pcYKHWceMht/54F04wm9Ewgnbp7uovbuf0FvaA9eRCFnqqmAAG0rEmS q8HQ== X-Received: by 10.68.253.137 with SMTP id aa9mr6588040pbd.26.1365048394547; Wed, 03 Apr 2013 21:06:34 -0700 (PDT) Received: from daisy.corp.google.com (dhcp-172-22-52-238.mtv.corp.google.com [172.22.52.238]) by mx.google.com with ESMTPS id ri1sm8480080pbc.16.2013.04.03.21.06.33 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 21:06:34 -0700 (PDT) From: Naveen Krishna Chatradhi To: linux-iio@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org, jic23@cam.ac.uk, Naveen Krishna Chatradhi , Doug Anderson , Lars-Peter Clausen Subject: [PATCH] iio: adc: exynos_adc: Handle timeout issues Date: Wed, 3 Apr 2013 21:06:28 -0700 Message-Id: <1365048389-6364-1-git-send-email-naveenkrishna.ch@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363364801-23684-1-git-send-email-ch.naveen@samsung.com> References: <1363364801-23684-1-git-send-email-ch.naveen@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org From: Naveen Krishna Chatradhi 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 Cc: Doug Anderson Cc: Lars-Peter Clausen --- 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;