drivers/hwmon/adcxx.c: fix for single-channel ADCs
While testing an 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. Signed-off-by: Jose Miguel Goncalves <jose.goncalves@inov.pt> Cc: Marc Pignat <marc.pignat@hevs.ch> Cc: Anton Vorontsov <avorontsov@ru.mvista.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
4cae787840
commit
5748150eab
1 changed files with 10 additions and 5 deletions
|
@ -62,18 +62,23 @@ static ssize_t adcxx_read(struct device *dev,
|
||||||
struct spi_device *spi = to_spi_device(dev);
|
struct spi_device *spi = to_spi_device(dev);
|
||||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||||
struct adcxx *adc = dev_get_drvdata(&spi->dev);
|
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];
|
u8 rx_buf[2];
|
||||||
int status;
|
int status;
|
||||||
int value;
|
u32 value;
|
||||||
|
|
||||||
if (mutex_lock_interruptible(&adc->lock))
|
if (mutex_lock_interruptible(&adc->lock))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
status = spi_write_then_read(spi, tx_buf, sizeof(tx_buf),
|
if (adc->channels == 1) {
|
||||||
rx_buf, sizeof(rx_buf));
|
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) {
|
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);
|
status);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue