Skip to contentSkip to conversation

enable motion events for st_lsm6dsx

PATCH Superseded Sean Nyekjaer 2 participants 11 messages Sep 12, 2019 – Sep 13, 2019

Subsystems (2)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v7 cover enable motion events for st_lsm6dsx

This patchset depends on:
[PATCH 0/2] enable LIR and clear_on_read for st_lsm6dsx

Sean Nyekjaer (5):
iio: imu: st_lsm6dsx: move interrupt thread to core
iio: imu: st_lsm6dsx: add motion events
iio: imu: st_lsm6dsx: add wakeup-source option
iio: imu: st_lsm6dsx: always enter interrupt thread
iio: imu: st_lsm6dsx: add motion report function and call from
interrupt

 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h       |  46 +++
 .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    |  78 +---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c  | 361 +++++++++++++++++-
 3 files changed, 404 insertions(+), 81 deletions(-)
Signature · 1 line
2.23.0
#1 lore raw

PATCH v7 1/5 iio: imu: st_lsm6dsx: move interrupt thread to core

This prepares the interrupt to be used for other stuff than fifo reading + event readings.

---
 .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    | 78 +---------------
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c  | 88 +++++++++++++++++++
 2 files changed, 89 insertions(+), 77 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +1 -77
index b0f3da1976e4..ef579650fd52 100644
@@ -30,8 +30,6 @@
  * Denis Ciocca <[email protected]>
  */
 #include <linux/module.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
 #include <linux/iio/kfifo_buf.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
@@ -42,10 +40,6 @@
 
 #include "st_lsm6dsx.h"
 
-#define ST_LSM6DSX_REG_HLACTIVE_ADDR		0x12
-#define ST_LSM6DSX_REG_HLACTIVE_MASK		BIT(5)
-#define ST_LSM6DSX_REG_PP_OD_ADDR		0x12
-#define ST_LSM6DSX_REG_PP_OD_MASK		BIT(4)
 #define ST_LSM6DSX_REG_FIFO_MODE_ADDR		0x0a
 #define ST_LSM6DSX_FIFO_MODE_MASK		GENMASK(2, 0)
 #define ST_LSM6DSX_FIFO_ODR_MASK		GENMASK(6, 3)
@@ -654,25 +648,6 @@ int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable)
 	return err;
 }
 
-static irqreturn_t st_lsm6dsx_handler_irq(int irq, void *private)
-{
-	struct st_lsm6dsx_hw *hw = private;
-
-	return hw->sip > 0 ? IRQ_WAKE_THREAD : IRQ_NONE;
-}
-
-static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
-{
-	struct st_lsm6dsx_hw *hw = private;
-	int count;
-
-	mutex_lock(&hw->fifo_lock);
-	count = hw->settings->fifo_ops.read_fifo(hw);
-	mutex_unlock(&hw->fifo_lock);
-
-	return count ? IRQ_HANDLED : IRQ_NONE;
-}
-
 static int st_lsm6dsx_buffer_preenable(struct iio_dev *iio_dev)
 {
 	struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
@@ -702,59 +677,8 @@ static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = {
 
 int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
 {
-	struct device_node *np = hw->dev->of_node;
-	struct st_sensors_platform_data *pdata;
 	struct iio_buffer *buffer;
-	unsigned long irq_type;
-	bool irq_active_low;
-	int i, err;
-
-	irq_type = irqd_get_trigger_type(irq_get_irq_data(hw->irq));
-
-	switch (irq_type) {
-	case IRQF_TRIGGER_HIGH:
-	case IRQF_TRIGGER_RISING:
-		irq_active_low = false;
-		break;
-	case IRQF_TRIGGER_LOW:
-	case IRQF_TRIGGER_FALLING:
-		irq_active_low = true;
-		break;
-	default:
-		dev_info(hw->dev, "mode %lx unsupported\n", irq_type);
-		return -EINVAL;
-	}
-
-	err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_HLACTIVE_ADDR,
-				 ST_LSM6DSX_REG_HLACTIVE_MASK,
-				 FIELD_PREP(ST_LSM6DSX_REG_HLACTIVE_MASK,
-					    irq_active_low));
-	if (err < 0)
-		return err;
-
-	pdata = (struct st_sensors_platform_data *)hw->dev->platform_data;
-	if ((np && of_property_read_bool(np, "drive-open-drain")) ||
-	    (pdata && pdata->open_drain)) {
-		err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_PP_OD_ADDR,
-					 ST_LSM6DSX_REG_PP_OD_MASK,
-					 FIELD_PREP(ST_LSM6DSX_REG_PP_OD_MASK,
-						    1));
-		if (err < 0)
-			return err;
-
-		irq_type |= IRQF_SHARED;
-	}
-
-	err = devm_request_threaded_irq(hw->dev, hw->irq,
-					st_lsm6dsx_handler_irq,
-					st_lsm6dsx_handler_thread,
-					irq_type | IRQF_ONESHOT,
-					"lsm6dsx", hw);
-	if (err) {
-		dev_err(hw->dev, "failed to request trigger irq %d\n",
-			hw->irq);
-		return err;
-	}
+	int i;
 
 	for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
 		if (!hw->iio_devs[i])
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +88 -0

112 lines not on this page · raw message

Signature · 1 line
2.23.0
#2 lore raw

PATCH v7 2/5 iio: imu: st_lsm6dsx: add motion events

In reply to Sean Nyekjaer

Add event channels that controls the creation of motion events. Tested on ISM330DLC

---
Changes since v4:
* Added check for event support
* Added registers for more devices that support this event

Changes since v5:
* Moved wakeup_src masks to PATCH 5/6

 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  41 ++++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 191 ++++++++++++++++++-
 2 files changed, 228 insertions(+), 4 deletions(-)

Changes since v6:
* None

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +41 -0
index fefd9042590a..449c2798f7ed 100644
@@ -12,6 +12,7 @@
 #define ST_LSM6DSX_H
 
 #include <linux/device.h>
+#include <linux/iio/iio.h>
 
 #define ST_LSM6DS3_DEV_NAME	"lsm6ds3"
 #define ST_LSM6DS3H_DEV_NAME	"lsm6ds3h"
@@ -54,6 +55,26 @@ enum st_lsm6dsx_hw_id {
 					 * ST_LSM6DSX_TAGGED_SAMPLE_SIZE)
 #define ST_LSM6DSX_SHIFT_VAL(val, mask)	(((val) << __ffs(mask)) & (mask))
 
+#define ST_LSM6DSX_CHANNEL_ACC(chan_type, addr, mod, scan_idx)		\
+{									\
+	.type = chan_type,						\
+	.address = addr,						\
+	.modified = 1,							\
+	.channel2 = mod,						\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
+	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),		\
+	.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
+	.scan_index = scan_idx,						\
+	.scan_type = {							\
+		.sign = 's',						\
+		.realbits = 16,						\
+		.storagebits = 16,					\
+		.endianness = IIO_LE,					\
+	},								\
+	.event_spec = &st_lsm6dsx_event,				\
+	.num_event_specs = 1,						\
+}
+
 #define ST_LSM6DSX_CHANNEL(chan_type, addr, mod, scan_idx)		\
 {									\
 	.type = chan_type,						\
@@ -162,6 +183,11 @@ struct st_lsm6dsx_shub_settings {
 	u8 batch_en;
 };
 
+struct st_lsm6dsx_event_settings {
+	struct st_lsm6dsx_reg enable_reg;
+	struct st_lsm6dsx_reg wakeup_reg;
+};
+
 enum st_lsm6dsx_ext_sensor_id {
 	ST_LSM6DSX_ID_MAGN,
 };
@@ -225,6 +251,9 @@ struct st_lsm6dsx_settings {
 	u8 wai;
 	u8 int1_addr;
 	u8 int2_addr;
+	u8 int1_func_addr;
+	u8 int2_func_addr;
+	u8 int_func_mask;
 	u8 reset_addr;
 	u16 max_fifo_size;
 	struct {
@@ -244,6 +273,7 @@ struct st_lsm6dsx_settings {
 	struct st_lsm6dsx_fifo_ops fifo_ops;
 	struct st_lsm6dsx_hw_ts_settings ts_settings;
 	struct st_lsm6dsx_shub_settings shub_settings;
+	struct st_lsm6dsx_event_settings event_settings;
 };
 
 enum st_lsm6dsx_sensor_id {
@@ -324,6 +354,10 @@ struct st_lsm6dsx_hw {
 	u8 ts_sip;
 	u8 sip;
 
+	u8 event_threshold;
+	bool enable_event;
+	struct st_lsm6dsx_reg irq_routing;
+
 	u8 *buff;
 
 	struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX];
@@ -331,6 +365,13 @@ struct st_lsm6dsx_hw {
 	const struct st_lsm6dsx_settings *settings;
 };
 
+static const struct iio_event_spec st_lsm6dsx_event = {
+	.type = IIO_EV_TYPE_THRESH,
+	.dir = IIO_EV_DIR_EITHER,
+	.mask_separate = BIT(IIO_EV_INFO_VALUE) |
+			 BIT(IIO_EV_INFO_ENABLE)
+};
+
 static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0};
 extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
 
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +187 -4

281 lines not on this page · raw message

Signature · 1 line
2.23.0
#3 lore raw

PATCH v7 3/5 iio: imu: st_lsm6dsx: add wakeup-source option

In reply to Sean Nyekjaer

This add ways for the SoC to wake from accelerometer wake events.

In the suspend function we skip disabling the sensor if wakeup-source and events are activated.

---
Changes since v4:
* More devices supports wakeup

Changes since v5:
* None

Changes since v6:
* None

 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +14 -0
index 4198ba263d03..f79978a2870f 100644
@@ -1858,6 +1858,9 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 			return err;
 	}
 
+	if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source"))
+		device_init_wakeup(dev, true);
+
 	return 0;
 }
 EXPORT_SYMBOL(st_lsm6dsx_probe);
@@ -1876,6 +1879,12 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
 		if (!(hw->enable_mask & BIT(sensor->id)))
 			continue;
 
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			/* Enable wake from IRQ */
+			enable_irq_wake(hw->irq);
+			continue;
+		}
+
 		if (sensor->id == ST_LSM6DSX_ID_EXT0 ||
 		    sensor->id == ST_LSM6DSX_ID_EXT1 ||
 		    sensor->id == ST_LSM6DSX_ID_EXT2)
@@ -1908,6 +1917,11 @@ static int __maybe_unused st_lsm6dsx_resume(struct device *dev)
 		if (!(hw->suspend_mask & BIT(sensor->id)))
 			continue;
 
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			disable_irq_wake(hw->irq);
+			continue;
+		}
+
 		if (sensor->id == ST_LSM6DSX_ID_EXT0 ||
 		    sensor->id == ST_LSM6DSX_ID_EXT1 ||
 		    sensor->id == ST_LSM6DSX_ID_EXT2)
Signature · 1 line
2.23.0
#4 lore raw

Re: [PATCH v7 3/5] iio: imu: st_lsm6dsx: add wakeup-source option

Quoted 47 lines · Sean Nyekjaer

This add ways for the SoC to wake from accelerometer wake events.

In the suspend function we skip disabling the sensor if wakeup-source and events are activated.

---
Changes since v4:
* More devices supports wakeup

Changes since v5:
* None

Changes since v6:
* None

  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +9 -0
index 4198ba263d03..f79978a2870f 100644
@@ -1858,6 +1858,9 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
  			return err;
  	}
 
+	if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source"))
+		device_init_wakeup(dev, true);
+
  	return 0;
  }
  EXPORT_SYMBOL(st_lsm6dsx_probe);
@@ -1876,6 +1879,12 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
  		if (!(hw->enable_mask & BIT(sensor->id)))
  			continue;
 
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			/* Enable wake from IRQ */
+			enable_irq_wake(hw->irq);
+			continue;
+		}
+
  		if (sensor->id == ST_LSM6DSX_ID_EXT0 ||
  		    sensor->id == ST_LSM6DSX_ID_EXT1 ||
  		    sensor->id == ST_LSM6DSX_ID_EXT2)

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int __maybe_unused st_lsm6dsx_resume(struct device *dev) · line 1924

Quoted 8 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +5 -0
@@ -1908,6 +1917,11 @@ static int __maybe_unused st_lsm6dsx_resume(struct device *dev)
  		if (!(hw->suspend_mask & BIT(sensor->id)))
  			continue;
 
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			disable_irq_wake(hw->irq);
+			continue;
+		}
+

This section needs to move above:

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int __maybe_unused st_lsm6dsx_suspend(struct device *dev) · line 1879

Quoted 1 line
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +0 -0
  		if (!(hw->enable_mask & BIT(sensor->id)))

In the current configuration it will never be reached in event only mode

With the bug mentioned above fixed, have tested suspend/wake with and without FIFO enabled.

maintainer
#5 lore raw

Re: [PATCH v7 3/5] iio: imu: st_lsm6dsx: add wakeup-source option

Quoted 34 lines · Sean Nyekjaer
Quoted 31 lines

This add ways for the SoC to wake from accelerometer wake events.

In the suspend function we skip disabling the sensor if wakeup-source and events are activated.

---
Changes since v4:
* More devices supports wakeup

Changes since v5:
* None

Changes since v6:
* None

  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +3 -0
index 4198ba263d03..f79978a2870f 100644
@@ -1858,6 +1858,9 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
  			return err;
  	}
+	if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source"))
+		device_init_wakeup(dev, true);
+
  	return 0;
  }
Quoted 8 lines

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int __maybe_unused st_lsm6dsx_suspend(struct device *dev) · line 1884

Quoted 8 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4 -0
  EXPORT_SYMBOL(st_lsm6dsx_probe);
@@ -1876,6 +1879,12 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
  		if (!(hw->enable_mask & BIT(sensor->id)))
  			continue;
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			/* Enable wake from IRQ */
+			enable_irq_wake(hw->irq);
+			continue;

I guess here we need even to check hw->event_enable, don't we?

Quoted 6 lines
Quoted 6 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +2 -0
+		}
+
  		if (sensor->id == ST_LSM6DSX_ID_EXT0 ||
  		    sensor->id == ST_LSM6DSX_ID_EXT1 ||
  		    sensor->id == ST_LSM6DSX_ID_EXT2)
@@ -1908,6 +1917,11 @@ static int __maybe_unused st_lsm6dsx_resume(struct device *dev)
Quoted 8 lines

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int __maybe_unused st_lsm6dsx_resume(struct device *dev) · line 1924

Quoted 7 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +5 -0
  		if (!(hw->suspend_mask & BIT(sensor->id)))
  			continue;
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			disable_irq_wake(hw->irq);
+			continue;
+		}
+

This section needs to move above:

agree, and we probably do not need 'continue'. Moreover I guess we should check hw->event_enable even here, right?

Quoted 5 lines

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int __maybe_unused st_lsm6dsx_suspend(struct device *dev) · line 1879

Quoted 1 line
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +0 -0
  		if (!(hw->enable_mask & BIT(sensor->id)))

In the current configuration it will never be reached in event only mode

With the bug mentioned above fixed, have tested suspend/wake with and without FIFO enabled.

#6 lore raw

Re: [PATCH v7 3/5] iio: imu: st_lsm6dsx: add wakeup-source option

Quoted 36 lines · Lorenzo Bianconi
Quoted 36 lines · Sean Nyekjaer
Quoted 33 lines

This add ways for the SoC to wake from accelerometer wake events.

In the suspend function we skip disabling the sensor if wakeup-source and events are activated.

---
Changes since v4:
* More devices supports wakeup

Changes since v5:
* None

Changes since v6:
* None

   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +3 -0
index 4198ba263d03..f79978a2870f 100644
@@ -1858,6 +1858,9 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
   			return err;
   	}
+	if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source"))
+		device_init_wakeup(dev, true);
+
   	return 0;
   }
   EXPORT_SYMBOL(st_lsm6dsx_probe);
@@ -1876,6 +1879,12 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
Quoted 8 lines
Quoted 6 lines

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int __maybe_unused st_lsm6dsx_suspend(struct device *dev) · line 1885

Quoted 6 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4 -0
   		if (!(hw->enable_mask & BIT(sensor->id)))
   			continue;
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			/* Enable wake from IRQ */
+			enable_irq_wake(hw->irq);
+			continue;

I guess here we need even to check hw->event_enable, don't we?

Good idea :)

Quoted 16 lines
Quoted 15 lines
Quoted 7 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +2 -0
+		}
+
   		if (sensor->id == ST_LSM6DSX_ID_EXT0 ||
   		    sensor->id == ST_LSM6DSX_ID_EXT1 ||
   		    sensor->id == ST_LSM6DSX_ID_EXT2)

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int __maybe_unused st_lsm6dsx_resume(struct device *dev) · line 1923

Quoted 7 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +5 -0
@@ -1908,6 +1917,11 @@ static int __maybe_unused st_lsm6dsx_resume(struct device *dev)
   		if (!(hw->suspend_mask & BIT(sensor->id)))
   			continue;
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			disable_irq_wake(hw->irq);
+			continue;
+		}
+

This section needs to move above:

Quoted 2 lines

agree, and we probably do not need 'continue'. Moreover I guess we should check hw->event_enable even here, right?

Correct we don't need the 'continue' here... The 'hw->suspend_mask' is not set as we skip it in the resume part. I'll add the 'hw->enable_event' check here as well.

Is there more stuff that blocks this series from your point of view?

/Sean

maintainer
#7 lore raw

Re: [PATCH v7 3/5] iio: imu: st_lsm6dsx: add wakeup-source option

Quoted 65 lines · Lorenzo Bianconi
Quoted 36 lines
Quoted 36 lines · Sean Nyekjaer
Quoted 33 lines

This add ways for the SoC to wake from accelerometer wake events.

In the suspend function we skip disabling the sensor if wakeup-source and events are activated.

---
Changes since v4:
* More devices supports wakeup

Changes since v5:
* None

Changes since v6:
* None

   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +3 -0
index 4198ba263d03..f79978a2870f 100644
@@ -1858,6 +1858,9 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
   			return err;
   	}
+	if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source"))
+		device_init_wakeup(dev, true);
+
   	return 0;
   }
   EXPORT_SYMBOL(st_lsm6dsx_probe);
@@ -1876,6 +1879,12 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
Quoted 8 lines
Quoted 6 lines

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int __maybe_unused st_lsm6dsx_suspend(struct device *dev) · line 1885

Quoted 6 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4 -0
   		if (!(hw->enable_mask & BIT(sensor->id)))
   			continue;
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			/* Enable wake from IRQ */
+			enable_irq_wake(hw->irq);
+			continue;

I guess here we need even to check hw->event_enable, don't we?

Good idea :)

Quoted 16 lines
Quoted 15 lines
Quoted 7 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +2 -0
+		}
+
   		if (sensor->id == ST_LSM6DSX_ID_EXT0 ||
   		    sensor->id == ST_LSM6DSX_ID_EXT1 ||
   		    sensor->id == ST_LSM6DSX_ID_EXT2)

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int __maybe_unused st_lsm6dsx_resume(struct device *dev) · line 1923

Quoted 7 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +5 -0
@@ -1908,6 +1917,11 @@ static int __maybe_unused st_lsm6dsx_resume(struct device *dev)
   		if (!(hw->suspend_mask & BIT(sensor->id)))
   			continue;
+		if (device_may_wakeup(dev) && i == ST_LSM6DSX_ID_ACC) {
+			disable_irq_wake(hw->irq);
+			continue;
+		}
+

This section needs to move above:

Quoted 8 lines
Quoted 2 lines

agree, and we probably do not need 'continue'. Moreover I guess we should check hw->event_enable even here, right?

Correct we don't need the 'continue' here... The 'hw->suspend_mask' is not set as we skip it in the resume part.
I'll add the 'hw->enable_event' check here as well.

Is there more stuff that blocks this series from your point of view?

Actually I have not tested, just compiled. Looking at the code seems fine.

Regards,
Lorenzo

Quoted 2 lines

/Sean

#8 lore raw

Re: [PATCH v7 3/5] iio: imu: st_lsm6dsx: add wakeup-source option

Quoted 4 lines · Lorenzo Bianconi

Actually I have not tested, just compiled. Looking at the code seems fine.

Regards,
Lorenzo

I'll post V8 with updated [PATCH 3/5] for Jonathan :-)

/Sean

#9 lore raw

PATCH v7 4/5 iio: imu: st_lsm6dsx: always enter interrupt thread

In reply to Sean Nyekjaer

The interrupt source can come from multiple sources, fifo and wake interrupts.
Enter interrupt thread to check which interrupt that has fired.

---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +1 -3
index f79978a2870f..c0568ab69a77 100644
@@ -1717,9 +1717,7 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
 
 static irqreturn_t st_lsm6dsx_handler_irq(int irq, void *private)
 {
-	struct st_lsm6dsx_hw *hw = private;
-
-	return hw->sip > 0 ? IRQ_WAKE_THREAD : IRQ_NONE;
+	return IRQ_WAKE_THREAD;
 }
 
 static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
Signature · 1 line
2.23.0
#10 lore raw

PATCH v7 5/5 iio: imu: st_lsm6dsx: add motion report function and call from interrupt

In reply to Sean Nyekjaer

Report iio motion events to iio subsystem

---
Changes since v4:
* Updated bitmask as pr Jonathans comments

Changes since v5:
* None

Changes since v6:
* None

 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  5 ++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 70 ++++++++++++++++++++
 2 files changed, 75 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +5 -0
index 449c2798f7ed..7c50fac7b85c 100644
@@ -186,6 +186,11 @@ struct st_lsm6dsx_shub_settings {
 struct st_lsm6dsx_event_settings {
 	struct st_lsm6dsx_reg enable_reg;
 	struct st_lsm6dsx_reg wakeup_reg;
+	u8 wakeup_src_reg;
+	u8 wakeup_src_status_mask;
+	u8 wakeup_src_z_mask;
+	u8 wakeup_src_y_mask;
+	u8 wakeup_src_x_mask;
 };
 
 enum st_lsm6dsx_ext_sensor_id {
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +70 -0

118 lines not on this page · raw message

Signature · 1 line
2.23.0