From: Jan Luebbe <jlu-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Pantelis Antoniou
<panto-wVdstyuyKrO8r51toPun2/C9HSW9iNxf@public.gmane.org>
Cc: rachna-l0cyMroinI0@public.gmane.org,
linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Koen Kooi
<koen-QLwJDigV5abLmq1fohREcCpxlwaOVQ5f@public.gmane.org>,
Jan Luebbe <jlu-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Subject: [PATCH 2/2] iio: adc: ti_am335x_adc: make tiadc_read_raw() more robust
Date: Mon, 6 May 2013 14:48:59 +0200 [thread overview]
Message-ID: <1367844539-6812-3-git-send-email-jlu@pengutronix.de> (raw)
In-Reply-To: <1367844539-6812-1-git-send-email-jlu-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.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 <jlu-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
---
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,
},
--
1.8.2.rc2
next prev parent reply other threads:[~2013-05-06 12:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-31 15:55 [PATCH] ti_tscadc: Update with IIO map interface & deal with partial activation Pantelis Antoniou
2012-10-30 18:28 ` Lars-Peter Clausen
[not found] ` <1351698938-3839-1-git-send-email-panto-wVdstyuyKrO8r51toPun2/C9HSW9iNxf@public.gmane.org>
2013-05-06 12:48 ` Jan Luebbe
[not found] ` <1367844539-6812-1-git-send-email-jlu-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-05-06 12:48 ` [PATCH 1/2] iio: adc: ti_am335x_adc: revert info_mask removal Jan Luebbe
2013-05-06 12:48 ` Jan Luebbe [this message]
2013-05-06 16:12 ` [PATCH] ti_tscadc: Update with IIO map interface & deal with partial activation Jonathan Cameron
2013-05-07 13:08 ` Pantelis Antoniou
2013-05-07 14:09 ` Jan Lübbe
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=1367844539-6812-3-git-send-email-jlu@pengutronix.de \
--to=jlu-bicnvbalz9megne8c9+irq@public.gmane.org \
--cc=koen-QLwJDigV5abLmq1fohREcCpxlwaOVQ5f@public.gmane.org \
--cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=panto-wVdstyuyKrO8r51toPun2/C9HSW9iNxf@public.gmane.org \
--cc=rachna-l0cyMroinI0@public.gmane.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