History

iio: accel: st_accel: fix LIS3LV02 reading and scaling

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.

Linus Walleij committed 9 years ago

Commit 65e43451 parent 65c8aea3 files · +31 −2Browse files

Showing the changes to include/linux (1 of 3 files). Show all

Unified · Split

include/linux/iio/common/st_sensors.h+12−0
@@ -115,6 +115,16 @@ struct st_sensor_bdu { · 114 unmodified lines
115 u8 mask;115 u8 mask;
116};116};
117 117
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
118/**128/**
119 * struct st_sensor_data_ready_irq - ST sensor device data-ready interrupt129 * struct st_sensor_data_ready_irq - ST sensor device data-ready interrupt
120 * @addr: address of the register.130 * @addr: address of the register.
@@ -185,6 +195,7 @@ struct st_sensor_transfer_function { · 64 unmodified lines
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 { · 9 unmodified lines
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;