From patchwork Mon May 6 12:48:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_L=C3=BCbbe?= X-Patchwork-Id: 2524001 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 91E91DF230 for ; Mon, 6 May 2013 12:49:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753008Ab3EFMtU (ORCPT ); Mon, 6 May 2013 08:49:20 -0400 Received: from metis.ext.pengutronix.de ([92.198.50.35]:38565 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753090Ab3EFMtU (ORCPT ); Mon, 6 May 2013 08:49:20 -0400 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1UZKqx-0007ai-E7; Mon, 06 May 2013 14:49:15 +0200 Received: from jlu by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1UZKqv-0006Ry-Cu; Mon, 06 May 2013 14:49:13 +0200 From: Jan Luebbe To: Pantelis Antoniou Cc: rachna@ti.com, linux-iio@vger.kernel.org, linux-omap@vger.kernel.org, Koen Kooi , Jan Luebbe Subject: [PATCH 2/2] iio: adc: ti_am335x_adc: make tiadc_read_raw() more robust Date: Mon, 6 May 2013 14:48:59 +0200 Message-Id: <1367844539-6812-3-git-send-email-jlu@pengutronix.de> X-Mailer: git-send-email 1.8.2.rc2 In-Reply-To: <1367844539-6812-1-git-send-email-jlu@pengutronix.de> References: <1351698938-3839-1-git-send-email-panto@antoniou-consulting.com> <1367844539-6812-1-git-send-email-jlu@pengutronix.de> X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: jlu@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-omap@vger.kernel.org Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Check that mask is actually IIO_CHAN_INFO_RAW. Also handle the case where not enough data is in the fifo. Signed-off-by: Jan Luebbe --- drivers/iio/adc/ti_am335x_adc.c | 48 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c index 620cc0c..4b764a9 100644 --- a/drivers/iio/adc/ti_am335x_adc.c +++ b/drivers/iio/adc/ti_am335x_adc.c @@ -157,26 +157,34 @@ static int tiadc_read_raw(struct iio_dev *indio_dev, int i; unsigned int fifo1count, readx1; - /* - * When the sub-system is first enabled, - * the sequencer will always start with the - * lowest step (1) and continue until step (16). - * For ex: If we have enabled 4 ADC channels and - * currently use only 1 out of them, the - * sequencer still configures all the 4 steps, - * leading to 3 unwanted data. - * Hence we need to flush out this data. - */ + switch (mask) { + case IIO_CHAN_INFO_RAW: + /* + * When the sub-system is first enabled, + * the sequencer will always start with the + * lowest step (1) and continue until step (16). + * For ex: If we have enabled 4 ADC channels and + * currently use only 1 out of them, the + * sequencer still configures all the 4 steps, + * leading to 3 unwanted data. + * Hence we need to flush out this data. + */ + + fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); + for (i = 0; i < fifo1count; i++) { + readx1 = tiadc_readl(adc_dev, REG_FIFO1); + if (i == chan->channel) + *val = readx1 & 0xfff; + } + tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB); - fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); - for (i = 0; i < fifo1count; i++) { - readx1 = tiadc_readl(adc_dev, REG_FIFO1); - if (i == chan->channel) - *val = readx1 & 0xfff; - } - tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB); + if (fifo1count <= chan->channel) + return -EINVAL; - return IIO_VAL_INT; + return IIO_VAL_INT; + default: + return -EINVAL; + } } static const struct iio_info tiadc_info = { @@ -213,7 +221,7 @@ static int tiadc_probe(struct platform_device *pdev) else { node = of_get_child_by_name(node, "adc"); if (!node) - return -EINVAL; + return -EINVAL; else { err = of_property_read_u32(node, "ti,adc-channels", &val32); @@ -310,7 +318,7 @@ static const struct dev_pm_ops tiadc_pm_ops = { static struct platform_driver tiadc_driver = { .driver = { - .name = "tiadc", + .name = "tiadc", .owner = THIS_MODULE, .pm = TIADC_PM_OPS, },