aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/magnetometer
diff options
context:
space:
mode:
authorPeter Meerwald <pmeerw@pmeerw.net>2014-02-05 04:09:00 -0500
committerJonathan Cameron <jic23@kernel.org>2014-05-03 06:27:52 -0400
commit0828eddc56d38b70f9a9e5cf7a0050328a90e7a1 (patch)
tree98b579d7a35842d5320dc9c8c799297800107d4d /drivers/iio/magnetometer
parent6584891bd0607ec7c67868b82d221bef67558962 (diff)
iio:magnetometer:mag3110: Enable user offset calibration
add IIO_CHAN_INFO_CALIBBIAS Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/magnetometer')
-rw-r--r--drivers/iio/magnetometer/mag3110.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c
index 1b2df75d07d0..e3106b43ef48 100644
--- a/drivers/iio/magnetometer/mag3110.c
+++ b/drivers/iio/magnetometer/mag3110.c
@@ -199,6 +199,13 @@ static int mag3110_read_raw(struct iio_dev *indio_dev,
199 *val = mag3110_samp_freq[i][0]; 199 *val = mag3110_samp_freq[i][0];
200 *val2 = mag3110_samp_freq[i][1]; 200 *val2 = mag3110_samp_freq[i][1];
201 return IIO_VAL_INT_PLUS_MICRO; 201 return IIO_VAL_INT_PLUS_MICRO;
202 case IIO_CHAN_INFO_CALIBBIAS:
203 ret = i2c_smbus_read_word_swapped(data->client,
204 MAG3110_OFF_X + 2 * chan->scan_index);
205 if (ret < 0)
206 return ret;
207 *val = sign_extend32(ret >> 1, 14);
208 return IIO_VAL_INT;
202 } 209 }
203 return -EINVAL; 210 return -EINVAL;
204} 211}
@@ -223,6 +230,11 @@ static int mag3110_write_raw(struct iio_dev *indio_dev,
223 data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT; 230 data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT;
224 return i2c_smbus_write_byte_data(data->client, 231 return i2c_smbus_write_byte_data(data->client,
225 MAG3110_CTRL_REG1, data->ctrl_reg1); 232 MAG3110_CTRL_REG1, data->ctrl_reg1);
233 case IIO_CHAN_INFO_CALIBBIAS:
234 if (val < -10000 || val > 10000)
235 return -EINVAL;
236 return i2c_smbus_write_word_swapped(data->client,
237 MAG3110_OFF_X + 2 * chan->scan_index, val << 1);
226 default: 238 default:
227 return -EINVAL; 239 return -EINVAL;
228 } 240 }
@@ -260,7 +272,8 @@ done:
260 .type = IIO_MAGN, \ 272 .type = IIO_MAGN, \
261 .modified = 1, \ 273 .modified = 1, \
262 .channel2 = IIO_MOD_##axis, \ 274 .channel2 = IIO_MOD_##axis, \
263 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 275 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
276 BIT(IIO_CHAN_INFO_CALIBBIAS), \
264 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 277 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
265 BIT(IIO_CHAN_INFO_SCALE), \ 278 BIT(IIO_CHAN_INFO_SCALE), \
266 .scan_index = idx, \ 279 .scan_index = idx, \
@@ -345,7 +358,7 @@ static int mag3110_probe(struct i2c_client *client,
345 return ret; 358 return ret;
346 359
347 ret = i2c_smbus_write_byte_data(client, MAG3110_CTRL_REG2, 360 ret = i2c_smbus_write_byte_data(client, MAG3110_CTRL_REG2,
348 MAG3110_CTRL_AUTO_MRST_EN | MAG3110_CTRL_RAW); 361 MAG3110_CTRL_AUTO_MRST_EN);
349 if (ret < 0) 362 if (ret < 0)
350 return ret; 363 return ret;
351 364