aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Ranostay <mranostay@gmail.com>2016-05-29 22:52:02 -0400
committerJonathan Cameron <jic23@kernel.org>2016-06-03 08:25:33 -0400
commit94bef000f1d4aa111f4ddda1482cf3b30ad069ce (patch)
tree214790b811c6b2d18b4b557d83d64ae32756a76e
parent590b92a30242dd3f73de3d9a51d9924f1ab33e93 (diff)
iio: hudmidity: hdc100x: fix incorrect shifting and scaling
Shifting sensor data to the right 2 bits was incorrect and caused the scaling values + offsets to be invalid. Reported-by: Alison Schofield <amsfield22@gmail.com> Signed-off-by: Matt Ranostay <mranostay@gmail.com> Tested-by: Alison Schofield <amsfield22@gmail.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/humidity/hdc100x.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
index 30709838dcdc..a03832a5fc95 100644
--- a/drivers/iio/humidity/hdc100x.c
+++ b/drivers/iio/humidity/hdc100x.c
@@ -164,14 +164,14 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,
164 dev_err(&client->dev, "cannot read high byte measurement"); 164 dev_err(&client->dev, "cannot read high byte measurement");
165 return ret; 165 return ret;
166 } 166 }
167 val = ret << 6; 167 val = ret << 8;
168 168
169 ret = i2c_smbus_read_byte(client); 169 ret = i2c_smbus_read_byte(client);
170 if (ret < 0) { 170 if (ret < 0) {
171 dev_err(&client->dev, "cannot read low byte measurement"); 171 dev_err(&client->dev, "cannot read low byte measurement");
172 return ret; 172 return ret;
173 } 173 }
174 val |= ret >> 2; 174 val |= ret;
175 175
176 return val; 176 return val;
177} 177}
@@ -212,17 +212,17 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev,
212 case IIO_CHAN_INFO_SCALE: 212 case IIO_CHAN_INFO_SCALE:
213 if (chan->type == IIO_TEMP) { 213 if (chan->type == IIO_TEMP) {
214 *val = 165000; 214 *val = 165000;
215 *val2 = 65536 >> 2; 215 *val2 = 65536;
216 return IIO_VAL_FRACTIONAL; 216 return IIO_VAL_FRACTIONAL;
217 } else { 217 } else {
218 *val = 0; 218 *val = 100;
219 *val2 = 10000; 219 *val2 = 65536;
220 return IIO_VAL_INT_PLUS_MICRO; 220 return IIO_VAL_FRACTIONAL;
221 } 221 }
222 break; 222 break;
223 case IIO_CHAN_INFO_OFFSET: 223 case IIO_CHAN_INFO_OFFSET:
224 *val = -3971; 224 *val = -15887;
225 *val2 = 879096; 225 *val2 = 515151;
226 return IIO_VAL_INT_PLUS_MICRO; 226 return IIO_VAL_INT_PLUS_MICRO;
227 default: 227 default:
228 return -EINVAL; 228 return -EINVAL;