From 6584891bd0607ec7c67868b82d221bef67558962 Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Wed, 5 Feb 2014 09:09:00 +0000 Subject: iio:magnetometer:mag3110: Fix initialization of ctrl_reg1 DR bits need to be shifted; since MAG3110_CTRL_DR_DEFAULT is zero, the change has no effect Signed-off-by: Peter Meerwald Signed-off-by: Jonathan Cameron --- drivers/iio/magnetometer/mag3110.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/iio/magnetometer/mag3110.c') diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c index 8b77782474d7..1b2df75d07d0 100644 --- a/drivers/iio/magnetometer/mag3110.c +++ b/drivers/iio/magnetometer/mag3110.c @@ -338,7 +338,7 @@ static int mag3110_probe(struct i2c_client *client, indio_dev->num_channels = ARRAY_SIZE(mag3110_channels); indio_dev->available_scan_masks = mag3110_scan_masks; - data->ctrl_reg1 = MAG3110_CTRL_DR_DEFAULT; + data->ctrl_reg1 = MAG3110_CTRL_DR_DEFAULT << MAG3110_CTRL_DR_SHIFT; ret = i2c_smbus_write_byte_data(client, MAG3110_CTRL_REG1, data->ctrl_reg1); if (ret < 0) -- cgit v1.2.3 From 0828eddc56d38b70f9a9e5cf7a0050328a90e7a1 Mon Sep 17 00:00:00 2001 From: Peter Meerwald Date: Wed, 5 Feb 2014 09:09:00 +0000 Subject: iio:magnetometer:mag3110: Enable user offset calibration add IIO_CHAN_INFO_CALIBBIAS Signed-off-by: Peter Meerwald Signed-off-by: Jonathan Cameron --- drivers/iio/magnetometer/mag3110.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'drivers/iio/magnetometer/mag3110.c') 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, *val = mag3110_samp_freq[i][0]; *val2 = mag3110_samp_freq[i][1]; return IIO_VAL_INT_PLUS_MICRO; + case IIO_CHAN_INFO_CALIBBIAS: + ret = i2c_smbus_read_word_swapped(data->client, + MAG3110_OFF_X + 2 * chan->scan_index); + if (ret < 0) + return ret; + *val = sign_extend32(ret >> 1, 14); + return IIO_VAL_INT; } return -EINVAL; } @@ -223,6 +230,11 @@ static int mag3110_write_raw(struct iio_dev *indio_dev, data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT; return i2c_smbus_write_byte_data(data->client, MAG3110_CTRL_REG1, data->ctrl_reg1); + case IIO_CHAN_INFO_CALIBBIAS: + if (val < -10000 || val > 10000) + return -EINVAL; + return i2c_smbus_write_word_swapped(data->client, + MAG3110_OFF_X + 2 * chan->scan_index, val << 1); default: return -EINVAL; } @@ -260,7 +272,8 @@ done: .type = IIO_MAGN, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_CALIBBIAS), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ BIT(IIO_CHAN_INFO_SCALE), \ .scan_index = idx, \ @@ -345,7 +358,7 @@ static int mag3110_probe(struct i2c_client *client, return ret; ret = i2c_smbus_write_byte_data(client, MAG3110_CTRL_REG2, - MAG3110_CTRL_AUTO_MRST_EN | MAG3110_CTRL_RAW); + MAG3110_CTRL_AUTO_MRST_EN); if (ret < 0) return ret; -- cgit v1.2.3