aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlison Schofield <amsfield22@gmail.com>2016-08-08 14:14:36 -0400
committerJonathan Cameron <jic23@kernel.org>2016-08-15 12:01:53 -0400
commit0d9dcf852334b796bacc7020364afba3122db81e (patch)
tree50f92a193082137339b924d676025a3d454a7be5
parent31f453eac56bdc41f434126bc2d5933b9fb720ec (diff)
iio: humidity: hdc100x: fix sensor data reads of temp and humidity
Replace the i2c_smbus_read_byte commmands used to retrieve the sensor data with an i2c_master_recv command. The smbus read byte method fails because the device does not expect a stop condition after sending the first byte. When we issue the second read, we are getting the first byte again. Net effect is that of the 14 bits used for the measurement, the 8 most significant bits are correct, the lower 6 are not. None of the smbus read protocols follow the pattern this device requires (S Addr Rd [A] Data [A] Data NA P), hence the switch to an i2c receive transaction. Applicable from original introduction of this driver, but will require backporting due to churn in the code. Signed-off-by: Alison Schofield <amsfield22@gmail.com> Cc: Daniel Baluta <daniel.baluta@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/humidity/hdc100x.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
index a03832a5fc95..e0c9c70c2a4a 100644
--- a/drivers/iio/humidity/hdc100x.c
+++ b/drivers/iio/humidity/hdc100x.c
@@ -142,7 +142,7 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,
142 struct i2c_client *client = data->client; 142 struct i2c_client *client = data->client;
143 int delay = data->adc_int_us[chan->address]; 143 int delay = data->adc_int_us[chan->address];
144 int ret; 144 int ret;
145 int val; 145 __be16 val;
146 146
147 /* start measurement */ 147 /* start measurement */
148 ret = i2c_smbus_write_byte(client, chan->address); 148 ret = i2c_smbus_write_byte(client, chan->address);
@@ -154,26 +154,13 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,
154 /* wait for integration time to pass */ 154 /* wait for integration time to pass */
155 usleep_range(delay, delay + 1000); 155 usleep_range(delay, delay + 1000);
156 156
157 /* 157 /* read measurement */
158 * i2c_smbus_read_word_data cannot() be used here due to the command 158 ret = i2c_master_recv(data->client, (char *)&val, sizeof(val));
159 * value not being understood and causes NAKs preventing any reading
160 * from being accessed.
161 */
162 ret = i2c_smbus_read_byte(client);
163 if (ret < 0) { 159 if (ret < 0) {
164 dev_err(&client->dev, "cannot read high byte measurement"); 160 dev_err(&client->dev, "cannot read sensor data\n");
165 return ret; 161 return ret;
166 } 162 }
167 val = ret << 8; 163 return be16_to_cpu(val);
168
169 ret = i2c_smbus_read_byte(client);
170 if (ret < 0) {
171 dev_err(&client->dev, "cannot read low byte measurement");
172 return ret;
173 }
174 val |= ret;
175
176 return val;
177} 164}
178 165
179static int hdc100x_get_heater_status(struct hdc100x_data *data) 166static int hdc100x_get_heater_status(struct hdc100x_data *data)
@@ -272,8 +259,8 @@ static int hdc100x_probe(struct i2c_client *client,
272 struct iio_dev *indio_dev; 259 struct iio_dev *indio_dev;
273 struct hdc100x_data *data; 260 struct hdc100x_data *data;
274 261
275 if (!i2c_check_functionality(client->adapter, 262 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
276 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE)) 263 I2C_FUNC_SMBUS_BYTE | I2C_FUNC_I2C))
277 return -EOPNOTSUPP; 264 return -EOPNOTSUPP;
278 265
279 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 266 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));