public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "José Miguel Gonçalves" <jose.goncalves@inov.pt>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Marc Pignat <marc.pignat@hevs.ch>, linux-kernel@vger.kernel.org
Subject: [PATCH] adcxx: Fix for single-channel ADCs
Date: Fri, 12 Feb 2010 14:34:15 +0000	[thread overview]
Message-ID: <4B7566E7.8070507@inov.pt> (raw)

[-- Attachment #1: Type: text/plain, Size: 306 bytes --]

Hi,

While testing a ADC121S021 in an embedded board with a S3C2142 SoC (ARM 
core), I have found that the 'adcxx' driver does not handle correctly 
single channel ADCs from this chip family.
For single channel chips you must only issue one read transfer for 
correct measurement.

Regards,
José Gonçalves

[-- Attachment #2: linux-2.6.git-adcxx1sxxx.patch --]
[-- Type: text/x-patch, Size: 1178 bytes --]

Signed-off-by: Jose Miguel Goncalves <jose.goncalves@inov.pt>

diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c
index 5e9e095..e645ce5 100644
--- a/drivers/hwmon/adcxx.c
+++ b/drivers/hwmon/adcxx.c
@@ -62,18 +62,23 @@ static ssize_t adcxx_read(struct device *dev,
 	struct spi_device *spi = to_spi_device(dev);
 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct adcxx *adc = dev_get_drvdata(&spi->dev);
-	u8 tx_buf[2] = { attr->index << 3 }; /* other bits are don't care */
+	u8 tx_buf[2];
 	u8 rx_buf[2];
 	int status;
-	int value;
+	u32 value;
 
 	if (mutex_lock_interruptible(&adc->lock))
 		return -ERESTARTSYS;
 
-	status = spi_write_then_read(spi, tx_buf, sizeof(tx_buf),
-					rx_buf, sizeof(rx_buf));
+	if (adc->channels == 1) {
+		status = spi_read(spi, rx_buf, sizeof(rx_buf));
+	} else {
+		tx_buf[0] = attr->index << 3; /* other bits are don't care */
+		status = spi_write_then_read(spi, tx_buf, sizeof(tx_buf),
+						rx_buf, sizeof(rx_buf));
+	}
 	if (status < 0) {
-		dev_warn(dev, "spi_write_then_read failed with status %d\n",
+		dev_warn(dev, "SPI synch. transfer failed with status %d\n",
 				status);
 		goto out;
 	}

                 reply	other threads:[~2010-02-12 14:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4B7566E7.8070507@inov.pt \
    --to=jose.goncalves@inov.pt \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.pignat@hevs.ch \
    /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