aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-12-30 17:54:18 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-12 05:39:21 -0500
commit96a0c8ee7ce6a32c455ff87d4fc4a69fc87c70d1 (patch)
tree34be2e2e940ce840b41b07b56f4e4f5816befc1b
parenta673f99884e355284eba0d6ffa82bc8ec5365554 (diff)
iio: accel: st_accel: fix LIS3LV02 reading and scaling
commit 65e4345c8ef8811bbb4860fe5f2df10646b7f2e1 upstream. The LIS3LV02 has a special bit that need to be set to get the read values left aligned. Before this patch we get gibberish like this: iio_generic_buffer -a -c10 -n lis3lv02dl_accel (...) 0.000000 -0.010042 -0.642688 19155832931907 0.000000 -0.010042 -0.642688 19155858751073 Which is because we read a raw value for 1g as 64 which is the nominal 1024 for 1g shifted 4 bits to the left by being right-aligned rather than left aligned. Since all other sensors are left aligned, add some code to set the special DAS (data alignment setting) bit to 1 so that the right value is now read like this: iio_generic_buffer -a -c10 -n lis3lv02dl_accel (...) 0.000000 -0.147095 -10.120135 24761614364956 -0.029419 -0.176514 -10.120135 24761631624540 The scaling was weird as well: we have a gain of 1000 for 1g and 3000 for 6g. I don't even remember how I came up with the old values but they are wrong. Fixes: 3acddf74f807 ("iio: st-sensors: add support for lis3lv02d accelerometer") Cc: Lorenzo Bianconi <lorenzo.bianconi@st.com> Cc: Giuseppe Barba <giuseppe.barba@st.com> Cc: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/iio/accel/st_accel_core.c12
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c9
-rw-r--r--include/linux/iio/common/st_sensors.h12
3 files changed, 31 insertions, 2 deletions
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index ce69048c88e9..3a557e3181ea 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -154,8 +154,8 @@
154#define ST_ACCEL_4_FS_MASK 0x80 154#define ST_ACCEL_4_FS_MASK 0x80
155#define ST_ACCEL_4_FS_AVL_2_VAL 0X00 155#define ST_ACCEL_4_FS_AVL_2_VAL 0X00
156#define ST_ACCEL_4_FS_AVL_6_VAL 0X01 156#define ST_ACCEL_4_FS_AVL_6_VAL 0X01
157#define ST_ACCEL_4_FS_AVL_2_GAIN IIO_G_TO_M_S_2(1024) 157#define ST_ACCEL_4_FS_AVL_2_GAIN IIO_G_TO_M_S_2(1000)
158#define ST_ACCEL_4_FS_AVL_6_GAIN IIO_G_TO_M_S_2(340) 158#define ST_ACCEL_4_FS_AVL_6_GAIN IIO_G_TO_M_S_2(3000)
159#define ST_ACCEL_4_BDU_ADDR 0x21 159#define ST_ACCEL_4_BDU_ADDR 0x21
160#define ST_ACCEL_4_BDU_MASK 0x40 160#define ST_ACCEL_4_BDU_MASK 0x40
161#define ST_ACCEL_4_DRDY_IRQ_ADDR 0x21 161#define ST_ACCEL_4_DRDY_IRQ_ADDR 0x21
@@ -346,6 +346,14 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
346 .addr = ST_ACCEL_1_BDU_ADDR, 346 .addr = ST_ACCEL_1_BDU_ADDR,
347 .mask = ST_ACCEL_1_BDU_MASK, 347 .mask = ST_ACCEL_1_BDU_MASK,
348 }, 348 },
349 /*
350 * Data Alignment Setting - needs to be set to get
351 * left-justified data like all other sensors.
352 */
353 .das = {
354 .addr = 0x21,
355 .mask = 0x01,
356 },
349 .drdy_irq = { 357 .drdy_irq = {
350 .addr = ST_ACCEL_1_DRDY_IRQ_ADDR, 358 .addr = ST_ACCEL_1_DRDY_IRQ_ADDR,
351 .mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK, 359 .mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK,
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index d5cf7f31eaf9..79c8c7cd70d5 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -401,6 +401,15 @@ int st_sensors_init_sensor(struct iio_dev *indio_dev,
401 return err; 401 return err;
402 } 402 }
403 403
404 /* set DAS */
405 if (sdata->sensor_settings->das.addr) {
406 err = st_sensors_write_data_with_mask(indio_dev,
407 sdata->sensor_settings->das.addr,
408 sdata->sensor_settings->das.mask, 1);
409 if (err < 0)
410 return err;
411 }
412
404 if (sdata->int_pin_open_drain) { 413 if (sdata->int_pin_open_drain) {
405 dev_info(&indio_dev->dev, 414 dev_info(&indio_dev->dev,
406 "set interrupt line to open drain mode\n"); 415 "set interrupt line to open drain mode\n");
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 228bd44efa4c..497f2b3a5a62 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -116,6 +116,16 @@ struct st_sensor_bdu {
116}; 116};
117 117
118/** 118/**
119 * struct st_sensor_das - ST sensor device data alignment selection
120 * @addr: address of the register.
121 * @mask: mask to write the das flag for left alignment.
122 */
123struct st_sensor_das {
124 u8 addr;
125 u8 mask;
126};
127
128/**
119 * struct st_sensor_data_ready_irq - ST sensor device data-ready interrupt 129 * struct st_sensor_data_ready_irq - ST sensor device data-ready interrupt
120 * @addr: address of the register. 130 * @addr: address of the register.
121 * @mask_int1: mask to enable/disable IRQ on INT1 pin. 131 * @mask_int1: mask to enable/disable IRQ on INT1 pin.
@@ -185,6 +195,7 @@ struct st_sensor_transfer_function {
185 * @enable_axis: Enable one or more axis of the sensor. 195 * @enable_axis: Enable one or more axis of the sensor.
186 * @fs: Full scale register and full scale list available. 196 * @fs: Full scale register and full scale list available.
187 * @bdu: Block data update register. 197 * @bdu: Block data update register.
198 * @das: Data Alignment Selection register.
188 * @drdy_irq: Data ready register of the sensor. 199 * @drdy_irq: Data ready register of the sensor.
189 * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read. 200 * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read.
190 * @bootime: samples to discard when sensor passing from power-down to power-up. 201 * @bootime: samples to discard when sensor passing from power-down to power-up.
@@ -200,6 +211,7 @@ struct st_sensor_settings {
200 struct st_sensor_axis enable_axis; 211 struct st_sensor_axis enable_axis;
201 struct st_sensor_fullscale fs; 212 struct st_sensor_fullscale fs;
202 struct st_sensor_bdu bdu; 213 struct st_sensor_bdu bdu;
214 struct st_sensor_das das;
203 struct st_sensor_data_ready_irq drdy_irq; 215 struct st_sensor_data_ready_irq drdy_irq;
204 bool multi_read_bit; 216 bool multi_read_bit;
205 unsigned int bootime; 217 unsigned int bootime;