Skip to content

Commit d1f13dc

Browse files
LorenzoBianconigregkh
authored andcommitted
iio: st_sensors: add register mask for status register
[ Upstream commit e72a060 ] Introduce register mask for data-ready status register since pressure sensors (e.g. LPS22HB) export just two channels (BIT(0) and BIT(1)) and BIT(2) is marked reserved while in st_sensors_new_samples_available() value read from status register is masked using 0x7. Moreover do not mask status register using active_scan_mask since now status value is properly masked and if the result is not zero the interrupt has to be consumed by the driver. This fix an issue on LPS25H and LPS331AP where channel definition is swapped respect to status register. Furthermore that change allows to properly support new devices (e.g LIS2DW12) that report just ZYXDA (data-ready) field in status register to figure out if the interrupt has been generated by the device. Fixes: 97865fe (iio: st_sensors: verify interrupt event to status) Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c817cb5 commit d1f13dc

7 files changed

Lines changed: 70 additions & 30 deletions

File tree

‎drivers/iio/accel/st_accel_core.c‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
164164
.mask_int2 = 0x00,
165165
.addr_ihl = 0x25,
166166
.mask_ihl = 0x02,
167-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
167+
.stat_drdy = {
168+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
169+
.mask = 0x07,
170+
},
168171
},
169172
.sim = {
170173
.addr = 0x23,
@@ -236,7 +239,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
236239
.mask_ihl = 0x80,
237240
.addr_od = 0x22,
238241
.mask_od = 0x40,
239-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
242+
.stat_drdy = {
243+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
244+
.mask = 0x07,
245+
},
240246
},
241247
.sim = {
242248
.addr = 0x23,
@@ -318,7 +324,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
318324
.mask_int2 = 0x00,
319325
.addr_ihl = 0x23,
320326
.mask_ihl = 0x40,
321-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
327+
.stat_drdy = {
328+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
329+
.mask = 0x07,
330+
},
322331
.ig1 = {
323332
.en_addr = 0x23,
324333
.en_mask = 0x08,
@@ -389,7 +398,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
389398
.drdy_irq = {
390399
.addr = 0x21,
391400
.mask_int1 = 0x04,
392-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
401+
.stat_drdy = {
402+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
403+
.mask = 0x07,
404+
},
393405
},
394406
.sim = {
395407
.addr = 0x21,
@@ -451,7 +463,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
451463
.mask_ihl = 0x80,
452464
.addr_od = 0x22,
453465
.mask_od = 0x40,
454-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
466+
.stat_drdy = {
467+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
468+
.mask = 0x07,
469+
},
455470
},
456471
.sim = {
457472
.addr = 0x21,
@@ -569,7 +584,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
569584
.drdy_irq = {
570585
.addr = 0x21,
571586
.mask_int1 = 0x04,
572-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
587+
.stat_drdy = {
588+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
589+
.mask = 0x07,
590+
},
573591
},
574592
.sim = {
575593
.addr = 0x21,
@@ -640,7 +658,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
640658
.mask_int2 = 0x00,
641659
.addr_ihl = 0x25,
642660
.mask_ihl = 0x02,
643-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
661+
.stat_drdy = {
662+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
663+
.mask = 0x07,
664+
},
644665
},
645666
.sim = {
646667
.addr = 0x23,

‎drivers/iio/common/st_sensors/st_sensors_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable)
470470
* different one. Take into account irq status register
471471
* to understand if irq trigger can be properly supported
472472
*/
473-
if (sdata->sensor_settings->drdy_irq.addr_stat_drdy)
473+
if (sdata->sensor_settings->drdy_irq.stat_drdy.addr)
474474
sdata->hw_irq_trigger = enable;
475475
return 0;
476476
}

‎drivers/iio/common/st_sensors/st_sensors_trigger.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,23 @@ static int st_sensors_new_samples_available(struct iio_dev *indio_dev,
3131
int ret;
3232

3333
/* How would I know if I can't check it? */
34-
if (!sdata->sensor_settings->drdy_irq.addr_stat_drdy)
34+
if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr)
3535
return -EINVAL;
3636

3737
/* No scan mask, no interrupt */
3838
if (!indio_dev->active_scan_mask)
3939
return 0;
4040

4141
ret = sdata->tf->read_byte(&sdata->tb, sdata->dev,
42-
sdata->sensor_settings->drdy_irq.addr_stat_drdy,
42+
sdata->sensor_settings->drdy_irq.stat_drdy.addr,
4343
&status);
4444
if (ret < 0) {
4545
dev_err(sdata->dev,
4646
"error checking samples available\n");
4747
return ret;
4848
}
49-
/*
50-
* the lower bits of .active_scan_mask[0] is directly mapped
51-
* to the channels on the sensor: either bit 0 for
52-
* one-dimensional sensors, or e.g. x,y,z for accelerometers,
53-
* gyroscopes or magnetometers. No sensor use more than 3
54-
* channels, so cut the other status bits here.
55-
*/
56-
status &= 0x07;
5749

58-
if (status & (u8)indio_dev->active_scan_mask[0])
50+
if (status & sdata->sensor_settings->drdy_irq.stat_drdy.mask)
5951
return 1;
6052

6153
return 0;
@@ -212,7 +204,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
212204
* it was "our" interrupt.
213205
*/
214206
if (sdata->int_pin_open_drain &&
215-
sdata->sensor_settings->drdy_irq.addr_stat_drdy)
207+
sdata->sensor_settings->drdy_irq.stat_drdy.addr)
216208
irq_trig |= IRQF_SHARED;
217209

218210
err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev),

‎drivers/iio/gyro/st_gyro_core.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
118118
* drain settings, but only for INT1 and not
119119
* for the DRDY line on INT2.
120120
*/
121-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
121+
.stat_drdy = {
122+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
123+
.mask = 0x07,
124+
},
122125
},
123126
.multi_read_bit = true,
124127
.bootime = 2,
@@ -188,7 +191,10 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
188191
* drain settings, but only for INT1 and not
189192
* for the DRDY line on INT2.
190193
*/
191-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
194+
.stat_drdy = {
195+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
196+
.mask = 0x07,
197+
},
192198
},
193199
.multi_read_bit = true,
194200
.bootime = 2,
@@ -253,7 +259,10 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
253259
* drain settings, but only for INT1 and not
254260
* for the DRDY line on INT2.
255261
*/
256-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
262+
.stat_drdy = {
263+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
264+
.mask = 0x07,
265+
},
257266
},
258267
.multi_read_bit = true,
259268
.bootime = 2,

‎drivers/iio/magnetometer/st_magn_core.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
317317
},
318318
.drdy_irq = {
319319
/* drdy line is routed drdy pin */
320-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
320+
.stat_drdy = {
321+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
322+
.mask = 0x07,
323+
},
321324
},
322325
.multi_read_bit = true,
323326
.bootime = 2,
@@ -361,7 +364,10 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
361364
.drdy_irq = {
362365
.addr = 0x62,
363366
.mask_int1 = 0x01,
364-
.addr_stat_drdy = 0x67,
367+
.stat_drdy = {
368+
.addr = 0x67,
369+
.mask = 0x07,
370+
},
365371
},
366372
.multi_read_bit = false,
367373
.bootime = 2,

‎drivers/iio/pressure/st_pressure_core.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,10 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
287287
.mask_ihl = 0x80,
288288
.addr_od = 0x22,
289289
.mask_od = 0x40,
290-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
290+
.stat_drdy = {
291+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
292+
.mask = 0x03,
293+
},
291294
},
292295
.multi_read_bit = true,
293296
.bootime = 2,
@@ -395,7 +398,10 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
395398
.mask_ihl = 0x80,
396399
.addr_od = 0x22,
397400
.mask_od = 0x40,
398-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
401+
.stat_drdy = {
402+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
403+
.mask = 0x03,
404+
},
399405
},
400406
.multi_read_bit = true,
401407
.bootime = 2,
@@ -454,7 +460,10 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
454460
.mask_ihl = 0x80,
455461
.addr_od = 0x12,
456462
.mask_od = 0x40,
457-
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
463+
.stat_drdy = {
464+
.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
465+
.mask = 0x03,
466+
},
458467
},
459468
.multi_read_bit = false,
460469
.bootime = 2,

‎include/linux/iio/common/st_sensors.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct st_sensor_das {
139139
* @mask_ihl: mask to enable/disable active low on the INT lines.
140140
* @addr_od: address to enable/disable Open Drain on the INT lines.
141141
* @mask_od: mask to enable/disable Open Drain on the INT lines.
142-
* @addr_stat_drdy: address to read status of DRDY (data ready) interrupt
142+
* struct stat_drdy - status register of DRDY (data ready) interrupt.
143143
* struct ig1 - represents the Interrupt Generator 1 of sensors.
144144
* @en_addr: address of the enable ig1 register.
145145
* @en_mask: mask to write the on/off value for enable.
@@ -152,7 +152,10 @@ struct st_sensor_data_ready_irq {
152152
u8 mask_ihl;
153153
u8 addr_od;
154154
u8 mask_od;
155-
u8 addr_stat_drdy;
155+
struct {
156+
u8 addr;
157+
u8 mask;
158+
} stat_drdy;
156159
struct {
157160
u8 en_addr;
158161
u8 en_mask;

0 commit comments

Comments
 (0)