iio: st_sensors: add register mask for status register
authorLorenzo Bianconi <lorenzo.bianconi83@gmail.com>
Wed, 30 Aug 2017 11:50:39 +0000 (13:50 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Dec 2017 13:26:26 +0000 (14:26 +0100)
[ Upstream commit e72a060151e5bb673af24993665e270fc4f674a7 ]

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: 97865fe41322 (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>
drivers/iio/accel/st_accel_core.c
drivers/iio/common/st_sensors/st_sensors_core.c
drivers/iio/common/st_sensors/st_sensors_trigger.c
drivers/iio/gyro/st_gyro_core.c
drivers/iio/magnetometer/st_magn_core.c
drivers/iio/pressure/st_pressure_core.c
include/linux/iio/common/st_sensors.h

index 752856b3a84970ffd5b7ad4cced46929eb4e43da..379de1829cdb4bf5ec8932fddf555426e469d888 100644 (file)
@@ -164,7 +164,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
                        .mask_int2 = 0x00,
                        .addr_ihl = 0x25,
                        .mask_ihl = 0x02,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .sim = {
                        .addr = 0x23,
@@ -236,7 +239,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
                        .mask_ihl = 0x80,
                        .addr_od = 0x22,
                        .mask_od = 0x40,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .sim = {
                        .addr = 0x23,
@@ -318,7 +324,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
                        .mask_int2 = 0x00,
                        .addr_ihl = 0x23,
                        .mask_ihl = 0x40,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                        .ig1 = {
                                .en_addr = 0x23,
                                .en_mask = 0x08,
@@ -389,7 +398,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
                .drdy_irq = {
                        .addr = 0x21,
                        .mask_int1 = 0x04,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .sim = {
                        .addr = 0x21,
@@ -451,7 +463,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
                        .mask_ihl = 0x80,
                        .addr_od = 0x22,
                        .mask_od = 0x40,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .sim = {
                        .addr = 0x21,
@@ -569,7 +584,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
                .drdy_irq = {
                        .addr = 0x21,
                        .mask_int1 = 0x04,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .sim = {
                        .addr = 0x21,
@@ -640,7 +658,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
                        .mask_int2 = 0x00,
                        .addr_ihl = 0x25,
                        .mask_ihl = 0x02,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .sim = {
                        .addr = 0x23,
index 02e833b14db08db9460b073f10a74f1942d3c752..34115f05d5c46450d82f00fdf9cebecbbdeebd78 100644 (file)
@@ -470,7 +470,7 @@ int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable)
                 * different one. Take into account irq status register
                 * to understand if irq trigger can be properly supported
                 */
-               if (sdata->sensor_settings->drdy_irq.addr_stat_drdy)
+               if (sdata->sensor_settings->drdy_irq.stat_drdy.addr)
                        sdata->hw_irq_trigger = enable;
                return 0;
        }
index fa73e679535985531ec5943f8b3d38d2e863511d..fdcc5a8919587b90033b018c4b69f37f40ba5ca0 100644 (file)
@@ -31,7 +31,7 @@ static int st_sensors_new_samples_available(struct iio_dev *indio_dev,
        int ret;
 
        /* How would I know if I can't check it? */
-       if (!sdata->sensor_settings->drdy_irq.addr_stat_drdy)
+       if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr)
                return -EINVAL;
 
        /* No scan mask, no interrupt */
@@ -39,23 +39,15 @@ static int st_sensors_new_samples_available(struct iio_dev *indio_dev,
                return 0;
 
        ret = sdata->tf->read_byte(&sdata->tb, sdata->dev,
-                       sdata->sensor_settings->drdy_irq.addr_stat_drdy,
+                       sdata->sensor_settings->drdy_irq.stat_drdy.addr,
                        &status);
        if (ret < 0) {
                dev_err(sdata->dev,
                        "error checking samples available\n");
                return ret;
        }
-       /*
-        * the lower bits of .active_scan_mask[0] is directly mapped
-        * to the channels on the sensor: either bit 0 for
-        * one-dimensional sensors, or e.g. x,y,z for accelerometers,
-        * gyroscopes or magnetometers. No sensor use more than 3
-        * channels, so cut the other status bits here.
-        */
-       status &= 0x07;
 
-       if (status & (u8)indio_dev->active_scan_mask[0])
+       if (status & sdata->sensor_settings->drdy_irq.stat_drdy.mask)
                return 1;
 
        return 0;
@@ -212,7 +204,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
         * it was "our" interrupt.
         */
        if (sdata->int_pin_open_drain &&
-           sdata->sensor_settings->drdy_irq.addr_stat_drdy)
+           sdata->sensor_settings->drdy_irq.stat_drdy.addr)
                irq_trig |= IRQF_SHARED;
 
        err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev),
index e366422e85127f27f2ab1df6a47019755af8d52d..2536a8400c98965a2b6e846926a662386f11f46f 100644 (file)
@@ -118,7 +118,10 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
                         * drain settings, but only for INT1 and not
                         * for the DRDY line on INT2.
                         */
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .multi_read_bit = true,
                .bootime = 2,
@@ -188,7 +191,10 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
                         * drain settings, but only for INT1 and not
                         * for the DRDY line on INT2.
                         */
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .multi_read_bit = true,
                .bootime = 2,
@@ -253,7 +259,10 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
                         * drain settings, but only for INT1 and not
                         * for the DRDY line on INT2.
                         */
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .multi_read_bit = true,
                .bootime = 2,
index 08aafba4481c66345b7ef770b3e44ce8b464f843..19031a7bce235f70f9567f242dd319cd9bd19816 100644 (file)
@@ -317,7 +317,10 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
                },
                .drdy_irq = {
                        /* drdy line is routed drdy pin */
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x07,
+                       },
                },
                .multi_read_bit = true,
                .bootime = 2,
@@ -361,7 +364,10 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
                .drdy_irq = {
                        .addr = 0x62,
                        .mask_int1 = 0x01,
-                       .addr_stat_drdy = 0x67,
+                       .stat_drdy = {
+                               .addr = 0x67,
+                               .mask = 0x07,
+                       },
                },
                .multi_read_bit = false,
                .bootime = 2,
index 34611a8ea2cea55f7d1e576e225df516ebc7f475..ea075fcd5a6f6f5c42a9364c896ce4e67dcc7613 100644 (file)
@@ -287,7 +287,10 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
                        .mask_ihl = 0x80,
                        .addr_od = 0x22,
                        .mask_od = 0x40,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x03,
+                       },
                },
                .multi_read_bit = true,
                .bootime = 2,
@@ -395,7 +398,10 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
                        .mask_ihl = 0x80,
                        .addr_od = 0x22,
                        .mask_od = 0x40,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x03,
+                       },
                },
                .multi_read_bit = true,
                .bootime = 2,
@@ -454,7 +460,10 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
                        .mask_ihl = 0x80,
                        .addr_od = 0x12,
                        .mask_od = 0x40,
-                       .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
+                       .stat_drdy = {
+                               .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+                               .mask = 0x03,
+                       },
                },
                .multi_read_bit = false,
                .bootime = 2,
index 7b0fa8b5c120d42a7b85e58f6d02f27018f3ee6f..ce0ef1c0a30ab40cb38687905bf5af3643690f62 100644 (file)
@@ -139,7 +139,7 @@ struct st_sensor_das {
  * @mask_ihl: mask to enable/disable active low on the INT lines.
  * @addr_od: address to enable/disable Open Drain on the INT lines.
  * @mask_od: mask to enable/disable Open Drain on the INT lines.
- * @addr_stat_drdy: address to read status of DRDY (data ready) interrupt
+ * struct stat_drdy - status register of DRDY (data ready) interrupt.
  * struct ig1 - represents the Interrupt Generator 1 of sensors.
  * @en_addr: address of the enable ig1 register.
  * @en_mask: mask to write the on/off value for enable.
@@ -152,7 +152,10 @@ struct st_sensor_data_ready_irq {
        u8 mask_ihl;
        u8 addr_od;
        u8 mask_od;
-       u8 addr_stat_drdy;
+       struct {
+               u8 addr;
+               u8 mask;
+       } stat_drdy;
        struct {
                u8 en_addr;
                u8 en_mask;