diff options
Diffstat (limited to 'drivers/hwmon/adcxx.c')
-rw-r--r-- | drivers/hwmon/adcxx.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c index 5e9e095f1136..fbdc7655303b 100644 --- a/drivers/hwmon/adcxx.c +++ b/drivers/hwmon/adcxx.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/init.h> | 37 | #include <linux/init.h> |
38 | #include <linux/module.h> | 38 | #include <linux/module.h> |
39 | #include <linux/kernel.h> | 39 | #include <linux/kernel.h> |
40 | #include <linux/slab.h> | ||
40 | #include <linux/device.h> | 41 | #include <linux/device.h> |
41 | #include <linux/err.h> | 42 | #include <linux/err.h> |
42 | #include <linux/sysfs.h> | 43 | #include <linux/sysfs.h> |
@@ -62,18 +63,23 @@ static ssize_t adcxx_read(struct device *dev, | |||
62 | struct spi_device *spi = to_spi_device(dev); | 63 | struct spi_device *spi = to_spi_device(dev); |
63 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 64 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
64 | struct adcxx *adc = dev_get_drvdata(&spi->dev); | 65 | struct adcxx *adc = dev_get_drvdata(&spi->dev); |
65 | u8 tx_buf[2] = { attr->index << 3 }; /* other bits are don't care */ | 66 | u8 tx_buf[2]; |
66 | u8 rx_buf[2]; | 67 | u8 rx_buf[2]; |
67 | int status; | 68 | int status; |
68 | int value; | 69 | u32 value; |
69 | 70 | ||
70 | if (mutex_lock_interruptible(&adc->lock)) | 71 | if (mutex_lock_interruptible(&adc->lock)) |
71 | return -ERESTARTSYS; | 72 | return -ERESTARTSYS; |
72 | 73 | ||
73 | status = spi_write_then_read(spi, tx_buf, sizeof(tx_buf), | 74 | if (adc->channels == 1) { |
74 | rx_buf, sizeof(rx_buf)); | 75 | status = spi_read(spi, rx_buf, sizeof(rx_buf)); |
76 | } else { | ||
77 | tx_buf[0] = attr->index << 3; /* other bits are don't care */ | ||
78 | status = spi_write_then_read(spi, tx_buf, sizeof(tx_buf), | ||
79 | rx_buf, sizeof(rx_buf)); | ||
80 | } | ||
75 | if (status < 0) { | 81 | if (status < 0) { |
76 | dev_warn(dev, "spi_write_then_read failed with status %d\n", | 82 | dev_warn(dev, "SPI synch. transfer failed with status %d\n", |
77 | status); | 83 | status); |
78 | goto out; | 84 | goto out; |
79 | } | 85 | } |