linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] various st_lsm6dsx fixes and missing bits
@ 2019-10-06 13:21 Lorenzo Bianconi
  2019-10-06 13:21 ` [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event Lorenzo Bianconi
                   ` (13 more replies)
  0 siblings, 14 replies; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:21 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

This series fixes some corner cases introduced with LSM9DS1 support and with
the one that has added wake-up event support. In particular it fixes a crash
due to missing HW FIFO support for LSM9DS1.
Moreover I introduced the missing wake-up event support for LSM6DSO/LSM6DSOX
sensor
Add missing dts documentation for wake-up event and the capability to enable it
through platformdata.
Code cleanup.

Lorenzo Bianconi (13):
  iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in
    st_lsm6dsx_report_motion_event
  iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
  iio: imu: st_lsm6dsx: move irq related definitions in irq_config
  iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not
    supported
  iio: imu: st_lsm6dsx: move bdu/boot and reset register info in
    hw_settings
  iio: imu: st_lsm6dsx: always check enable_reg in
    st_lsm6dsx_event_setup
  iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked
    configuring events
  iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config
  iio: imu: st_lsm6dsx: fix checkpatch warning
  iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data
  iio: imu: st_lsm6dsx: add missing kernel documenation
  dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source
    property
  iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO

 .../bindings/iio/imu/st_lsm6dsx.txt           |   1 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h       |  35 +-
 .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    |   3 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c  | 588 ++++++++++++------
 .../linux/platform_data/st_sensors_pdata.h    |   2 +
 5 files changed, 440 insertions(+), 189 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
@ 2019-10-06 13:21 ` Lorenzo Bianconi
  2019-10-07  7:54   ` Sean Nyekjaer
  2019-10-12 12:08   ` Jonathan Cameron
  2019-10-06 13:21 ` [PATCH 02/13] iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer Lorenzo Bianconi
                   ` (12 subsequent siblings)
  13 siblings, 2 replies; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:21 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Rely on st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event since
it can run concurrently with sensor hub configuration. Move event
related code in st_lsm6dsx_report_motion_event

Fixes: 1aabad1fb5e9 ("iio: imu: st_lsm6dsx: add motion report function and call from interrupt")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 34 ++++++++++++--------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 8a813ddba19c..df270905f21d 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1757,10 +1757,23 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
 	return iio_dev;
 }
 
-static void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data)
+static bool
+st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw)
 {
-	s64 timestamp = iio_get_time_ns(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
+	const struct st_lsm6dsx_event_settings *event_settings;
+	int err, data;
+	s64 timestamp;
 
+	if (!hw->enable_event)
+		return false;
+
+	event_settings = &hw->settings->event_settings;
+	err = st_lsm6dsx_read_locked(hw, event_settings->wakeup_src_reg,
+				     &data, sizeof(data));
+	if (err < 0)
+		return false;
+
+	timestamp = iio_get_time_ns(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
 	if ((data & hw->settings->event_settings.wakeup_src_z_mask) &&
 	    (hw->enable_event & BIT(IIO_MOD_Z)))
 		iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC],
@@ -1790,30 +1803,23 @@ static void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data)
 						  IIO_EV_TYPE_THRESH,
 						  IIO_EV_DIR_EITHER),
 						  timestamp);
+
+	return data & event_settings->wakeup_src_status_mask;
 }
 
 static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
 {
 	struct st_lsm6dsx_hw *hw = private;
+	bool event;
 	int count;
-	int data, err;
-
-	if (hw->enable_event) {
-		err = regmap_read(hw->regmap,
-				  hw->settings->event_settings.wakeup_src_reg,
-				  &data);
-		if (err < 0)
-			return IRQ_NONE;
 
-		if (data & hw->settings->event_settings.wakeup_src_status_mask)
-			st_lsm6dsx_report_motion_event(hw, data);
-	}
+	event = st_lsm6dsx_report_motion_event(hw);
 
 	mutex_lock(&hw->fifo_lock);
 	count = hw->settings->fifo_ops.read_fifo(hw);
 	mutex_unlock(&hw->fifo_lock);
 
-	return count ? IRQ_HANDLED : IRQ_NONE;
+	return count || event ? IRQ_HANDLED : IRQ_NONE;
 }
 
 static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 02/13] iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
  2019-10-06 13:21 ` [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event Lorenzo Bianconi
@ 2019-10-06 13:21 ` Lorenzo Bianconi
  2019-10-06 13:21 ` [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config Lorenzo Bianconi
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:21 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Check read_fifo pointer before using it since we can't assume it
is always set adding new sensors. This patch fixes the following crash:

irq 277: nobody cared (try booting with the "irqpoll" option)
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.3.0-rc5-00322-g792b824-dirty #7
Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[<c0112750>] (unwind_backtrace) from [<c010d018>] (show_stack+0x10/0x14)
[<c010d018>] (show_stack) from [<c0c2bfc8>] (dump_stack+0xd8/0x10c)
[<c0c2bfc8>] (dump_stack) from [<c01923fc>] (__report_bad_irq+0x24/0xc0)
[<c01923fc>] (__report_bad_irq) from [<c0192820>] (note_interrupt+0x27c/0x2dc)
[<c0192820>] (note_interrupt) from [<c018f174>] (handle_irq_event_percpu+0x54/0x7c)
[<c018f174>] (handle_irq_event_percpu) from [<c018f1d4>] (handle_irq_event+0x38/0x5c)
[<c018f1d4>] (handle_irq_event) from [<c0193664>] (handle_level_irq+0xc8/0x154)
[<c0193664>] (handle_level_irq) from [<c018df58>] (generic_handle_irq+0x20/0x34)
[<c018df58>] (generic_handle_irq) from [<c053c348>] (mxc_gpio_irq_handler+0xc4/0xf8)
[<c053c348>] (mxc_gpio_irq_handler) from [<c053c3e0>] (mx3_gpio_irq_handler+0x64/0xb8)
[<c053c3e0>] (mx3_gpio_irq_handler) from [<c018df58>] (generic_handle_irq+0x20/0x34)
[<c018df58>] (generic_handle_irq) from [<c018e550>] (__handle_domain_irq+0x64/0xe0)
[<c018e550>] (__handle_domain_irq) from [<c0529610>] (gic_handle_irq+0x4c/0xa0)
[<c0529610>] (gic_handle_irq) from [<c0101a70>] (__irq_svc+0x70/0x98)
Exception stack(0xc1301f10 to 0xc1301f58
1f00: 00000001 00000006 00000000 c130c340
1f20: c1300000 c1308928 00000001 c1308960 00000000 c12b9db0 c1308908 00000000
1f40: 00000000 c1301f60 c0182010 c0109508 20000013 ffffffff
[<c0101a70>] (__irq_svc) from [<c0109508>] (arch_cpu_idle+0x20/0x3c)
[<c0109508>] (arch_cpu_idle) from [<c015ed70>] (do_idle+0x1bc/0x2bc)
[<c015ed70>] (do_idle) from [<c015f204>] (cpu_startup_entry+0x18/0x1c)
[<c015f204>] (cpu_startup_entry) from [<c1200e68>] (start_kernel+0x440/0x504)
[<c1200e68>] (start_kernel) from [<00000000>] (0x0)
handlers:
[<62052c0d>] st_lsm6dsx_handler_irq threaded
[<f2004b92>] st_lsm6dsx_handler_thread

Fixes: 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")
Tested-by: Bobby Jones <rjones@gateworks.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 3 +++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c   | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index ef579650fd52..cabd4bfeab17 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -586,6 +586,9 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw)
 {
 	int err;
 
+	if (!hw->settings->fifo_ops.read_fifo)
+		return -ENOTSUPP;
+
 	mutex_lock(&hw->fifo_lock);
 
 	hw->settings->fifo_ops.read_fifo(hw);
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index df270905f21d..eac695663b6f 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1815,6 +1815,9 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
 
 	event = st_lsm6dsx_report_motion_event(hw);
 
+	if (!hw->settings->fifo_ops.read_fifo)
+		return event ? IRQ_HANDLED : IRQ_NONE;
+
 	mutex_lock(&hw->fifo_lock);
 	count = hw->settings->fifo_ops.read_fifo(hw);
 	mutex_unlock(&hw->fifo_lock);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
  2019-10-06 13:21 ` [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event Lorenzo Bianconi
  2019-10-06 13:21 ` [PATCH 02/13] iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer Lorenzo Bianconi
@ 2019-10-06 13:21 ` Lorenzo Bianconi
  2019-10-07  7:54   ` Sean Nyekjaer
  2019-10-06 13:21 ` [PATCH 04/13] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported Lorenzo Bianconi
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:21 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Group irq related definition in irq_config structure in
st_lsm6dsx_settings. This is a preliminary patch to move
OpenDrain/Active low registers in st_lsm6dsx_settings.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  22 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 265 ++++++++++++-------
 2 files changed, 179 insertions(+), 108 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index fd02d0e184f3..873ec3b8fd69 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -236,29 +236,21 @@ struct st_lsm6dsx_ext_dev_settings {
 /**
  * struct st_lsm6dsx_settings - ST IMU sensor settings
  * @wai: Sensor WhoAmI default value.
- * @int1_addr: Control Register address for INT1
- * @int2_addr: Control Register address for INT2
  * @reset_addr: register address for reset/reboot
  * @max_fifo_size: Sensor max fifo length in FIFO words.
  * @id: List of hw id/device name supported by the driver configuration.
  * @channels: IIO channels supported by the device.
+ * @irq_config: interrupts related registers.
  * @odr_table: Hw sensors odr table (Hz + val).
  * @fs_table: Hw sensors gain table (gain + val).
  * @decimator: List of decimator register info (addr + mask).
  * @batch: List of FIFO batching register info (addr + mask).
- * @lir: Latched interrupt register info (addr + mask).
- * @clear_on_read: Clear on read register info (addr + mask).
  * @fifo_ops: Sensor hw FIFO parameters.
  * @ts_settings: Hw timer related settings.
  * @shub_settings: i2c controller related settings.
  */
 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 {
@@ -269,12 +261,18 @@ struct st_lsm6dsx_settings {
 		const struct iio_chan_spec *chan;
 		int len;
 	} channels[2];
+	struct {
+		struct st_lsm6dsx_reg irq1;
+		struct st_lsm6dsx_reg irq2;
+		struct st_lsm6dsx_reg irq1_func;
+		struct st_lsm6dsx_reg irq2_func;
+		struct st_lsm6dsx_reg lir;
+		struct st_lsm6dsx_reg clear_on_read;
+	} irq_config;
 	struct st_lsm6dsx_odr_table_entry odr_table[2];
 	struct st_lsm6dsx_fs_table_entry fs_table[2];
 	struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
 	struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
-	struct st_lsm6dsx_reg lir;
-	struct st_lsm6dsx_reg clear_on_read;
 	struct st_lsm6dsx_fifo_ops fifo_ops;
 	struct st_lsm6dsx_hw_ts_settings ts_settings;
 	struct st_lsm6dsx_shub_settings shub_settings;
@@ -359,9 +357,9 @@ struct st_lsm6dsx_hw {
 	u8 ts_sip;
 	u8 sip;
 
+	const struct st_lsm6dsx_reg *irq_routing;
 	u8 event_threshold;
 	u8 enable_event;
-	struct st_lsm6dsx_reg irq_routing;
 
 	u8 *buff;
 
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index eac695663b6f..23d67caa24ed 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -61,7 +61,6 @@
 
 #include "st_lsm6dsx.h"
 
-#define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK	BIT(3)
 #define ST_LSM6DSX_REG_WHOAMI_ADDR		0x0f
 #define ST_LSM6DSX_REG_RESET_MASK		BIT(0)
 #define ST_LSM6DSX_REG_BOOT_MASK		BIT(7)
@@ -97,8 +96,6 @@ static const struct iio_chan_spec st_lsm6ds0_gyro_channels[] = {
 static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	{
 		.wai = 0x68,
-		.int1_addr = 0x0c,
-		.int2_addr = 0x0d,
 		.reset_addr = 0x22,
 		.max_fifo_size = 32,
 		.id = {
@@ -164,14 +161,19 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[2] = { IIO_DEGREE_TO_RAD(2000), 0x3 },
 			},
 		},
+		.irq_config = {
+			.irq1 = {
+				.addr = 0x0c,
+				.mask = BIT(3),
+			},
+			.irq2 = {
+				.addr = 0x0d,
+				.mask = BIT(3),
+			},
+		},
 	},
 	{
 		.wai = 0x69,
-		.int1_addr = 0x0d,
-		.int2_addr = 0x0e,
-		.int1_func_addr = 0x5e,
-		.int2_func_addr = 0x5f,
-		.int_func_mask = BIT(5),
 		.reset_addr = 0x12,
 		.max_fifo_size = 1365,
 		.id = {
@@ -238,6 +240,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
 			},
 		},
+		.irq_config = {
+			.irq1 = {
+				.addr = 0x0d,
+				.mask = BIT(3),
+			},
+			.irq2 = {
+				.addr = 0x0e,
+				.mask = BIT(3),
+			},
+			.lir = {
+				.addr = 0x58,
+				.mask = BIT(0),
+			},
+			.irq1_func = {
+				.addr = 0x5e,
+				.mask = BIT(5),
+			},
+			.irq2_func = {
+				.addr = 0x5f,
+				.mask = BIT(5),
+			},
+		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x08,
@@ -248,10 +272,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.mask = GENMASK(5, 3),
 			},
 		},
-		.lir = {
-			.addr = 0x58,
-			.mask = BIT(0),
-		},
 		.fifo_ops = {
 			.update_fifo = st_lsm6dsx_update_fifo,
 			.read_fifo = st_lsm6dsx_read_fifo,
@@ -297,11 +317,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x69,
-		.int1_addr = 0x0d,
-		.int2_addr = 0x0e,
-		.int1_func_addr = 0x5e,
-		.int2_func_addr = 0x5f,
-		.int_func_mask = BIT(5),
 		.reset_addr = 0x12,
 		.max_fifo_size = 682,
 		.id = {
@@ -368,6 +383,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
 			},
 		},
+		.irq_config = {
+			.irq1 = {
+				.addr = 0x0d,
+				.mask = BIT(3),
+			},
+			.irq2 = {
+				.addr = 0x0e,
+				.mask = BIT(3),
+			},
+			.lir = {
+				.addr = 0x58,
+				.mask = BIT(0),
+			},
+			.irq1_func = {
+				.addr = 0x5e,
+				.mask = BIT(5),
+			},
+			.irq2_func = {
+				.addr = 0x5f,
+				.mask = BIT(5),
+			},
+		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x08,
@@ -378,10 +415,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.mask = GENMASK(5, 3),
 			},
 		},
-		.lir = {
-			.addr = 0x58,
-			.mask = BIT(0),
-		},
 		.fifo_ops = {
 			.update_fifo = st_lsm6dsx_update_fifo,
 			.read_fifo = st_lsm6dsx_read_fifo,
@@ -427,11 +460,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x6a,
-		.int1_addr = 0x0d,
-		.int2_addr = 0x0e,
-		.int1_func_addr = 0x5e,
-		.int2_func_addr = 0x5f,
-		.int_func_mask = BIT(5),
 		.reset_addr = 0x12,
 		.max_fifo_size = 682,
 		.id = {
@@ -507,6 +535,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
 			},
 		},
+		.irq_config = {
+			.irq1 = {
+				.addr = 0x0d,
+				.mask = BIT(3),
+			},
+			.irq2 = {
+				.addr = 0x0e,
+				.mask = BIT(3),
+			},
+			.lir = {
+				.addr = 0x58,
+				.mask = BIT(0),
+			},
+			.irq1_func = {
+				.addr = 0x5e,
+				.mask = BIT(5),
+			},
+			.irq2_func = {
+				.addr = 0x5f,
+				.mask = BIT(5),
+			},
+		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x08,
@@ -517,10 +567,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.mask = GENMASK(5, 3),
 			},
 		},
-		.lir = {
-			.addr = 0x58,
-			.mask = BIT(0),
-		},
 		.fifo_ops = {
 			.update_fifo = st_lsm6dsx_update_fifo,
 			.read_fifo = st_lsm6dsx_read_fifo,
@@ -570,8 +616,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x6c,
-		.int1_addr = 0x0d,
-		.int2_addr = 0x0e,
 		.reset_addr = 0x12,
 		.max_fifo_size = 512,
 		.id = {
@@ -641,6 +685,24 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
 			},
 		},
+		.irq_config = {
+			.irq1 = {
+				.addr = 0x0d,
+				.mask = BIT(3),
+			},
+			.irq2 = {
+				.addr = 0x0e,
+				.mask = BIT(3),
+			},
+			.lir = {
+				.addr = 0x56,
+				.mask = BIT(0),
+			},
+			.clear_on_read = {
+				.addr = 0x56,
+				.mask = BIT(6),
+			},
+		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x09,
@@ -651,14 +713,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.mask = GENMASK(7, 4),
 			},
 		},
-		.lir = {
-			.addr = 0x56,
-			.mask = BIT(0),
-		},
-		.clear_on_read = {
-			.addr = 0x56,
-			.mask = BIT(6),
-		},
 		.fifo_ops = {
 			.update_fifo = st_lsm6dsx_update_fifo,
 			.read_fifo = st_lsm6dsx_read_tagged_fifo,
@@ -711,11 +765,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x6b,
-		.int1_addr = 0x0d,
-		.int2_addr = 0x0e,
-		.int1_func_addr = 0x5e,
-		.int2_func_addr = 0x5f,
-		.int_func_mask = BIT(5),
 		.reset_addr = 0x12,
 		.max_fifo_size = 512,
 		.id = {
@@ -782,6 +831,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
 			},
 		},
+		.irq_config = {
+			.irq1 = {
+				.addr = 0x0d,
+				.mask = BIT(3),
+			},
+			.irq2 = {
+				.addr = 0x0e,
+				.mask = BIT(3),
+			},
+			.lir = {
+				.addr = 0x56,
+				.mask = BIT(0),
+			},
+			.clear_on_read = {
+				.addr = 0x56,
+				.mask = BIT(6),
+			},
+			.irq1_func = {
+				.addr = 0x5e,
+				.mask = BIT(5),
+			},
+			.irq2_func = {
+				.addr = 0x5f,
+				.mask = BIT(5),
+			},
+		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x09,
@@ -792,14 +867,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.mask = GENMASK(7, 4),
 			},
 		},
-		.lir = {
-			.addr = 0x56,
-			.mask = BIT(0),
-		},
-		.clear_on_read = {
-			.addr = 0x56,
-			.mask = BIT(6),
-		},
 		.fifo_ops = {
 			.update_fifo = st_lsm6dsx_update_fifo,
 			.read_fifo = st_lsm6dsx_read_tagged_fifo,
@@ -841,11 +908,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x6b,
-		.int1_addr = 0x0d,
-		.int2_addr = 0x0e,
-		.int1_func_addr = 0x5e,
-		.int2_func_addr = 0x5f,
-		.int_func_mask = BIT(5),
 		.reset_addr = 0x12,
 		.max_fifo_size = 512,
 		.id = {
@@ -915,6 +977,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
 			},
 		},
+		.irq_config = {
+			.irq1 = {
+				.addr = 0x0d,
+				.mask = BIT(3),
+			},
+			.irq2 = {
+				.addr = 0x0e,
+				.mask = BIT(3),
+			},
+			.lir = {
+				.addr = 0x56,
+				.mask = BIT(0),
+			},
+			.clear_on_read = {
+				.addr = 0x56,
+				.mask = BIT(6),
+			},
+			.irq1_func = {
+				.addr = 0x5e,
+				.mask = BIT(5),
+			},
+			.irq2_func = {
+				.addr = 0x5f,
+				.mask = BIT(5),
+			},
+		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
 				.addr = 0x09,
@@ -925,14 +1013,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.mask = GENMASK(7, 4),
 			},
 		},
-		.lir = {
-			.addr = 0x56,
-			.mask = BIT(0),
-		},
-		.clear_on_read = {
-			.addr = 0x56,
-			.mask = BIT(6),
-		},
 		.fifo_ops = {
 			.update_fifo = st_lsm6dsx_update_fifo,
 			.read_fifo = st_lsm6dsx_read_tagged_fifo,
@@ -1281,7 +1361,7 @@ static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
 	int err;
 	u8 enable = 0;
 
-	if (!hw->settings->int1_func_addr)
+	if (!hw->settings->irq_config.irq1_func.addr)
 		return -ENOTSUPP;
 
 	enable = state ? hw->settings->event_settings.enable_reg.mask : 0;
@@ -1293,12 +1373,11 @@ static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
 	if (err < 0)
 		return err;
 
-	enable = state ? hw->irq_routing.mask : 0;
+	enable = state ? hw->irq_routing->mask : 0;
 
 	/* Enable wakeup interrupt */
-	return regmap_update_bits(hw->regmap, hw->irq_routing.addr,
-				  hw->irq_routing.mask,
-				  enable);
+	return regmap_update_bits(hw->regmap, hw->irq_routing->addr,
+				  hw->irq_routing->mask, enable);
 }
 
 static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
@@ -1527,7 +1606,9 @@ static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
 	return of_property_read_u32(np, "st,drdy-int-pin", drdy_pin);
 }
 
-static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
+static int
+st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
+			const struct st_lsm6dsx_reg **drdy_reg)
 {
 	int err = 0, drdy_pin;
 
@@ -1541,14 +1622,12 @@ static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
 
 	switch (drdy_pin) {
 	case 1:
-		*drdy_reg = hw->settings->int1_addr;
-		hw->irq_routing.addr = hw->settings->int1_func_addr;
-		hw->irq_routing.mask = hw->settings->int_func_mask;
+		hw->irq_routing = &hw->settings->irq_config.irq1_func;
+		*drdy_reg = &hw->settings->irq_config.irq1;
 		break;
 	case 2:
-		*drdy_reg = hw->settings->int2_addr;
-		hw->irq_routing.addr = hw->settings->int2_func_addr;
-		hw->irq_routing.mask = hw->settings->int_func_mask;
+		hw->irq_routing = &hw->settings->irq_config.irq2_func;
+		*drdy_reg = &hw->settings->irq_config.irq2;
 		break;
 	default:
 		dev_err(hw->dev, "unsupported data ready pin\n");
@@ -1644,7 +1723,7 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
 
 static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
 {
-	u8 drdy_int_reg;
+	const struct st_lsm6dsx_reg *reg;
 	int err;
 
 	/* device sw reset */
@@ -1673,35 +1752,29 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
 		return err;
 
 	/* enable FIFO watermak interrupt */
-	err = st_lsm6dsx_get_drdy_reg(hw, &drdy_int_reg);
+	err = st_lsm6dsx_get_drdy_reg(hw, &reg);
 	if (err < 0)
 		return err;
 
-	err = regmap_update_bits(hw->regmap, drdy_int_reg,
-				 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK,
-				 FIELD_PREP(ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK,
-					    1));
+	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
+				 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
 	if (err < 0)
 		return err;
 
 	/* enable Latched interrupts for device events */
-	if (hw->settings->lir.addr) {
-		unsigned int data;
-
-		data = ST_LSM6DSX_SHIFT_VAL(1, hw->settings->lir.mask);
-		err = regmap_update_bits(hw->regmap, hw->settings->lir.addr,
-					 hw->settings->lir.mask, data);
+	if (hw->settings->irq_config.lir.addr) {
+		reg = &hw->settings->irq_config.lir;
+		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
+					 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
 		if (err < 0)
 			return err;
 
 		/* enable clear on read for latched interrupts */
-		if (hw->settings->clear_on_read.addr) {
-			data = ST_LSM6DSX_SHIFT_VAL(1,
-					hw->settings->clear_on_read.mask);
+		if (hw->settings->irq_config.clear_on_read.addr) {
+			reg = &hw->settings->irq_config.clear_on_read;
 			err = regmap_update_bits(hw->regmap,
-					hw->settings->clear_on_read.addr,
-					hw->settings->clear_on_read.mask,
-					data);
+					reg->addr, reg->mask,
+					ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
 			if (err < 0)
 				return err;
 		}
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 04/13] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (2 preceding siblings ...)
  2019-10-06 13:21 ` [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config Lorenzo Bianconi
@ 2019-10-06 13:21 ` Lorenzo Bianconi
  2019-10-12 12:14   ` Jonathan Cameron
  2019-10-06 13:21 ` [PATCH 05/13] iio: imu: st_lsm6dsx: move bdu/boot and reset register info in hw_settings Lorenzo Bianconi
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:21 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Move active low and open drain register definitions in hw_settings
register map since not all supported sensors (e.g lsm9ds1) rely on the
same definitions

Fixes: 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  2 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 79 ++++++++++++++++----
 2 files changed, 67 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 873ec3b8fd69..8e002a51595e 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -268,6 +268,8 @@ struct st_lsm6dsx_settings {
 		struct st_lsm6dsx_reg irq2_func;
 		struct st_lsm6dsx_reg lir;
 		struct st_lsm6dsx_reg clear_on_read;
+		struct st_lsm6dsx_reg hla;
+		struct st_lsm6dsx_reg od;
 	} irq_config;
 	struct st_lsm6dsx_odr_table_entry odr_table[2];
 	struct st_lsm6dsx_fs_table_entry fs_table[2];
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 23d67caa24ed..a598cc8e9343 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -67,11 +67,6 @@
 #define ST_LSM6DSX_REG_BDU_ADDR			0x12
 #define ST_LSM6DSX_REG_BDU_MASK			BIT(6)
 
-#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)
-
 static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
 	ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
 	ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL, 0x2a, IIO_MOD_Y, 1),
@@ -170,6 +165,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.addr = 0x0d,
 				.mask = BIT(3),
 			},
+			.hla = {
+				.addr = 0x22,
+				.mask = BIT(5),
+			},
+			.od = {
+				.addr = 0x22,
+				.mask = BIT(4),
+			},
 		},
 	},
 	{
@@ -261,6 +264,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.addr = 0x5f,
 				.mask = BIT(5),
 			},
+			.hla = {
+				.addr = 0x12,
+				.mask = BIT(5),
+			},
+			.od = {
+				.addr = 0x12,
+				.mask = BIT(4),
+			},
 		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
@@ -404,6 +415,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.addr = 0x5f,
 				.mask = BIT(5),
 			},
+			.hla = {
+				.addr = 0x12,
+				.mask = BIT(5),
+			},
+			.od = {
+				.addr = 0x12,
+				.mask = BIT(4),
+			},
 		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
@@ -556,6 +575,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.addr = 0x5f,
 				.mask = BIT(5),
 			},
+			.hla = {
+				.addr = 0x12,
+				.mask = BIT(5),
+			},
+			.od = {
+				.addr = 0x12,
+				.mask = BIT(4),
+			},
 		},
 		.decimator = {
 			[ST_LSM6DSX_ID_ACC] = {
@@ -702,6 +729,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.addr = 0x56,
 				.mask = BIT(6),
 			},
+			.hla = {
+				.addr = 0x12,
+				.mask = BIT(5),
+			},
+			.od = {
+				.addr = 0x12,
+				.mask = BIT(4),
+			},
 		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
@@ -856,6 +891,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.addr = 0x5f,
 				.mask = BIT(5),
 			},
+			.hla = {
+				.addr = 0x12,
+				.mask = BIT(5),
+			},
+			.od = {
+				.addr = 0x12,
+				.mask = BIT(4),
+			},
 		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
@@ -1002,6 +1045,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.addr = 0x5f,
 				.mask = BIT(5),
 			},
+			.hla = {
+				.addr = 0x12,
+				.mask = BIT(5),
+			},
+			.od = {
+				.addr = 0x12,
+				.mask = BIT(4),
+			},
 		},
 		.batch = {
 			[ST_LSM6DSX_ID_ACC] = {
@@ -1900,8 +1951,9 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
 
 static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 {
-	struct st_sensors_platform_data *pdata;
 	struct device_node *np = hw->dev->of_node;
+	struct st_sensors_platform_data *pdata;
+	const struct st_lsm6dsx_reg *reg;
 	unsigned long irq_type;
 	bool irq_active_low;
 	int err;
@@ -1922,20 +1974,19 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 		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));
+	reg = &hw->settings->irq_config.hla;
+	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
+				 ST_LSM6DSX_SHIFT_VAL(irq_active_low,
+						      reg->mask));
 	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));
+		reg = &hw->settings->irq_config.od;
+		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
+					 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
 		if (err < 0)
 			return err;
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 05/13] iio: imu: st_lsm6dsx: move bdu/boot and reset register info in hw_settings
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (3 preceding siblings ...)
  2019-10-06 13:21 ` [PATCH 04/13] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported Lorenzo Bianconi
@ 2019-10-06 13:21 ` Lorenzo Bianconi
  2019-10-12 12:19   ` Jonathan Cameron
  2019-10-06 13:22 ` [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup Lorenzo Bianconi
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:21 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Move bdu, boot and reset register definitions in hw_settings register
map since not all supported sensors (e.g lsm9ds1) rely on the same
definitions

Fixes: 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |   8 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 113 +++++++++++++++----
 2 files changed, 99 insertions(+), 22 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 8e002a51595e..5692ea695f04 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -236,7 +236,9 @@ struct st_lsm6dsx_ext_dev_settings {
 /**
  * struct st_lsm6dsx_settings - ST IMU sensor settings
  * @wai: Sensor WhoAmI default value.
- * @reset_addr: register address for reset/reboot
+ * @reset: register address for reset.
+ * @boot: register address for boot.
+ * @bdu: register address for Block Data Update.
  * @max_fifo_size: Sensor max fifo length in FIFO words.
  * @id: List of hw id/device name supported by the driver configuration.
  * @channels: IIO channels supported by the device.
@@ -251,7 +253,9 @@ struct st_lsm6dsx_ext_dev_settings {
  */
 struct st_lsm6dsx_settings {
 	u8 wai;
-	u8 reset_addr;
+	struct st_lsm6dsx_reg reset;
+	struct st_lsm6dsx_reg boot;
+	struct st_lsm6dsx_reg bdu;
 	u16 max_fifo_size;
 	struct {
 		enum st_lsm6dsx_hw_id hw_id;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index a598cc8e9343..5df382b9d8f9 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -62,10 +62,6 @@
 #include "st_lsm6dsx.h"
 
 #define ST_LSM6DSX_REG_WHOAMI_ADDR		0x0f
-#define ST_LSM6DSX_REG_RESET_MASK		BIT(0)
-#define ST_LSM6DSX_REG_BOOT_MASK		BIT(7)
-#define ST_LSM6DSX_REG_BDU_ADDR			0x12
-#define ST_LSM6DSX_REG_BDU_MASK			BIT(6)
 
 static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
 	ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
@@ -91,7 +87,18 @@ static const struct iio_chan_spec st_lsm6ds0_gyro_channels[] = {
 static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	{
 		.wai = 0x68,
-		.reset_addr = 0x22,
+		.reset = {
+			.addr = 0x22,
+			.mask = BIT(0),
+		},
+		.boot = {
+			.addr = 0x22,
+			.mask = BIT(7),
+		},
+		.bdu = {
+			.addr = 0x22,
+			.mask = BIT(6),
+		},
 		.max_fifo_size = 32,
 		.id = {
 			{
@@ -177,7 +184,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x69,
-		.reset_addr = 0x12,
+		.reset = {
+			.addr = 0x12,
+			.mask = BIT(0),
+		},
+		.boot = {
+			.addr = 0x12,
+			.mask = BIT(7),
+		},
+		.bdu = {
+			.addr = 0x12,
+			.mask = BIT(6),
+		},
 		.max_fifo_size = 1365,
 		.id = {
 			{
@@ -328,7 +346,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x69,
-		.reset_addr = 0x12,
+		.reset = {
+			.addr = 0x12,
+			.mask = BIT(0),
+		},
+		.boot = {
+			.addr = 0x12,
+			.mask = BIT(7),
+		},
+		.bdu = {
+			.addr = 0x12,
+			.mask = BIT(6),
+		},
 		.max_fifo_size = 682,
 		.id = {
 			{
@@ -479,7 +508,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x6a,
-		.reset_addr = 0x12,
+		.reset = {
+			.addr = 0x12,
+			.mask = BIT(0),
+		},
+		.boot = {
+			.addr = 0x12,
+			.mask = BIT(7),
+		},
+		.bdu = {
+			.addr = 0x12,
+			.mask = BIT(6),
+		},
 		.max_fifo_size = 682,
 		.id = {
 			{
@@ -643,7 +683,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x6c,
-		.reset_addr = 0x12,
+		.reset = {
+			.addr = 0x12,
+			.mask = BIT(0),
+		},
+		.boot = {
+			.addr = 0x12,
+			.mask = BIT(7),
+		},
+		.bdu = {
+			.addr = 0x12,
+			.mask = BIT(6),
+		},
 		.max_fifo_size = 512,
 		.id = {
 			{
@@ -800,7 +851,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x6b,
-		.reset_addr = 0x12,
+		.reset = {
+			.addr = 0x12,
+			.mask = BIT(0),
+		},
+		.boot = {
+			.addr = 0x12,
+			.mask = BIT(7),
+		},
+		.bdu = {
+			.addr = 0x12,
+			.mask = BIT(6),
+		},
 		.max_fifo_size = 512,
 		.id = {
 			{
@@ -951,7 +1013,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 	},
 	{
 		.wai = 0x6b,
-		.reset_addr = 0x12,
+		.reset = {
+			.addr = 0x12,
+			.mask = BIT(0),
+		},
+		.boot = {
+			.addr = 0x12,
+			.mask = BIT(7),
+		},
+		.bdu = {
+			.addr = 0x12,
+			.mask = BIT(6),
+		},
 		.max_fifo_size = 512,
 		.id = {
 			{
@@ -1778,27 +1851,27 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
 	int err;
 
 	/* device sw reset */
-	err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
-				 ST_LSM6DSX_REG_RESET_MASK,
-				 FIELD_PREP(ST_LSM6DSX_REG_RESET_MASK, 1));
+	reg = &hw->settings->reset;
+	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
+				 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
 	if (err < 0)
 		return err;
 
 	msleep(50);
 
 	/* reload trimming parameter */
-	err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
-				 ST_LSM6DSX_REG_BOOT_MASK,
-				 FIELD_PREP(ST_LSM6DSX_REG_BOOT_MASK, 1));
+	reg = &hw->settings->boot;
+	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
+				 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
 	if (err < 0)
 		return err;
 
 	msleep(50);
 
 	/* enable Block Data Update */
-	err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_BDU_ADDR,
-				 ST_LSM6DSX_REG_BDU_MASK,
-				 FIELD_PREP(ST_LSM6DSX_REG_BDU_MASK, 1));
+	reg = &hw->settings->bdu;
+	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
+				 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
 	if (err < 0)
 		return err;
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (4 preceding siblings ...)
  2019-10-06 13:21 ` [PATCH 05/13] iio: imu: st_lsm6dsx: move bdu/boot and reset register info in hw_settings Lorenzo Bianconi
@ 2019-10-06 13:22 ` Lorenzo Bianconi
  2019-10-07  7:55   ` Sean Nyekjaer
  2019-10-06 13:22 ` [PATCH 07/13] iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked configuring events Lorenzo Bianconi
                   ` (7 subsequent siblings)
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Check if enable_reg of event_settings data structure is defined before
writing on it

Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 23 ++++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 5df382b9d8f9..7e9e1ef81742 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1482,26 +1482,25 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
 
 static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
 {
+	const struct st_lsm6dsx_reg *reg;
 	int err;
-	u8 enable = 0;
 
 	if (!hw->settings->irq_config.irq1_func.addr)
 		return -ENOTSUPP;
 
-	enable = state ? hw->settings->event_settings.enable_reg.mask : 0;
-
-	err = regmap_update_bits(hw->regmap,
-				 hw->settings->event_settings.enable_reg.addr,
-				 hw->settings->event_settings.enable_reg.mask,
-				 enable);
-	if (err < 0)
-		return err;
-
-	enable = state ? hw->irq_routing->mask : 0;
+	reg = &hw->settings->event_settings.enable_reg;
+	if (reg->addr) {
+		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
+					 ST_LSM6DSX_SHIFT_VAL(state, reg->mask));
+		if (err < 0)
+			return err;
+	}
 
 	/* Enable wakeup interrupt */
 	return regmap_update_bits(hw->regmap, hw->irq_routing->addr,
-				  hw->irq_routing->mask, enable);
+				  hw->irq_routing->mask,
+				  ST_LSM6DSX_SHIFT_VAL(state,
+					hw->irq_routing->mask));
 }
 
 static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 07/13] iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked configuring events
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (5 preceding siblings ...)
  2019-10-06 13:22 ` [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup Lorenzo Bianconi
@ 2019-10-06 13:22 ` Lorenzo Bianconi
  2019-10-12 12:22   ` Jonathan Cameron
  2019-10-06 13:22 ` [PATCH 08/13] iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config Lorenzo Bianconi
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Rely on st_lsm6dsx_update_bits_locked in st_lsm6dsx_write_event and
st_lsm6dsx_event_setup routines since they can run concurrently with
sensor hub configuration

Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 25 +++++++++++---------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 7e9e1ef81742..023646762b4a 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1483,6 +1483,7 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
 static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
 {
 	const struct st_lsm6dsx_reg *reg;
+	unsigned int data;
 	int err;
 
 	if (!hw->settings->irq_config.irq1_func.addr)
@@ -1490,17 +1491,17 @@ static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
 
 	reg = &hw->settings->event_settings.enable_reg;
 	if (reg->addr) {
-		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
-					 ST_LSM6DSX_SHIFT_VAL(state, reg->mask));
+		data = ST_LSM6DSX_SHIFT_VAL(state, reg->mask);
+		err = st_lsm6dsx_update_bits_locked(hw, reg->addr,
+						    reg->mask, data);
 		if (err < 0)
 			return err;
 	}
 
 	/* Enable wakeup interrupt */
-	return regmap_update_bits(hw->regmap, hw->irq_routing->addr,
-				  hw->irq_routing->mask,
-				  ST_LSM6DSX_SHIFT_VAL(state,
-					hw->irq_routing->mask));
+	data = ST_LSM6DSX_SHIFT_VAL(state, hw->irq_routing->mask);
+	return st_lsm6dsx_update_bits_locked(hw, hw->irq_routing->addr,
+					     hw->irq_routing->mask, data);
 }
 
 static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
@@ -1531,6 +1532,8 @@ static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
 {
 	struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
 	struct st_lsm6dsx_hw *hw = sensor->hw;
+	const struct st_lsm6dsx_reg *reg;
+	unsigned int data;
 	int err;
 
 	if (type != IIO_EV_TYPE_THRESH)
@@ -1539,11 +1542,11 @@ static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
 	if (val < 0 || val > 31)
 		return -EINVAL;
 
-	err = regmap_update_bits(hw->regmap,
-				 hw->settings->event_settings.wakeup_reg.addr,
-				 hw->settings->event_settings.wakeup_reg.mask,
-				 val);
-	if (err)
+	reg = &hw->settings->event_settings.wakeup_reg;
+	data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask);
+	err = st_lsm6dsx_update_bits_locked(hw, reg->addr,
+					    reg->mask, data);
+	if (err < 0)
 		return -EINVAL;
 
 	hw->event_threshold = val;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 08/13] iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (6 preceding siblings ...)
  2019-10-06 13:22 ` [PATCH 07/13] iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked configuring events Lorenzo Bianconi
@ 2019-10-06 13:22 ` Lorenzo Bianconi
  2019-10-12 12:23   ` Jonathan Cameron
  2019-10-06 13:22 ` [PATCH 09/13] iio: imu: st_lsm6dsx: fix checkpatch warning Lorenzo Bianconi
                   ` (5 subsequent siblings)
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Always grub conf mutex in st_lsm6dsx_write_event_config since it can run
concurrently with FIFO configuration

Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 023646762b4a..04231710ab9c 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1604,7 +1604,9 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
 	if (err < 0)
 		return err;
 
+	mutex_lock(&hw->conf_lock);
 	err = st_lsm6dsx_sensor_set_enable(sensor, state);
+	mutex_unlock(&hw->conf_lock);
 	if (err < 0)
 		return err;
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 09/13] iio: imu: st_lsm6dsx: fix checkpatch warning
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (7 preceding siblings ...)
  2019-10-06 13:22 ` [PATCH 08/13] iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config Lorenzo Bianconi
@ 2019-10-06 13:22 ` Lorenzo Bianconi
  2019-10-12 12:24   ` Jonathan Cameron
  2019-10-06 13:22 ` [PATCH 10/13] iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data Lorenzo Bianconi
                   ` (4 subsequent siblings)
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Fix following checkpatch warnings:

CHECK: Alignment should match open parenthesis
+static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
+				   const struct iio_chan_spec *chan,

CHECK: Alignment should match open parenthesis
+static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
+				    const struct iio_chan_spec *chan,

CHECK: Alignment should match open parenthesis
+static int st_lsm6dsx_read_event_config(struct iio_dev *iio_dev,
+					  const struct iio_chan_spec *chan,

CHECK: Alignment should match open parenthesis
+static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
+					   const struct iio_chan_spec *chan,

WARNING: line over 80 characters
+	if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source"))

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 35 +++++++++++---------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 04231710ab9c..b0623b837abd 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1523,12 +1523,13 @@ static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
 	return IIO_VAL_INT;
 }
 
-static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
-				    const struct iio_chan_spec *chan,
-				    enum iio_event_type type,
-				    enum iio_event_direction dir,
-				    enum iio_event_info info,
-				    int val, int val2)
+static int
+st_lsm6dsx_write_event(struct iio_dev *iio_dev,
+		       const struct iio_chan_spec *chan,
+		       enum iio_event_type type,
+		       enum iio_event_direction dir,
+		       enum iio_event_info info,
+		       int val, int val2)
 {
 	struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
 	struct st_lsm6dsx_hw *hw = sensor->hw;
@@ -1554,10 +1555,11 @@ static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
 	return 0;
 }
 
-static int st_lsm6dsx_read_event_config(struct iio_dev *iio_dev,
-					  const struct iio_chan_spec *chan,
-					  enum iio_event_type type,
-					  enum iio_event_direction dir)
+static int
+st_lsm6dsx_read_event_config(struct iio_dev *iio_dev,
+			     const struct iio_chan_spec *chan,
+			     enum iio_event_type type,
+			     enum iio_event_direction dir)
 {
 	struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
 	struct st_lsm6dsx_hw *hw = sensor->hw;
@@ -1568,11 +1570,11 @@ static int st_lsm6dsx_read_event_config(struct iio_dev *iio_dev,
 	return !!(hw->enable_event & BIT(chan->channel2));
 }
 
-static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
-					   const struct iio_chan_spec *chan,
-					   enum iio_event_type type,
-					   enum iio_event_direction dir,
-					   int state)
+static int
+st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
+			      const struct iio_chan_spec *chan,
+			      enum iio_event_type type,
+			      enum iio_event_direction dir, int state)
 {
 	struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
 	struct st_lsm6dsx_hw *hw = sensor->hw;
@@ -2150,7 +2152,8 @@ 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"))
+	if (dev->of_node &&
+	    of_property_read_bool(dev->of_node, "wakeup-source"))
 		device_init_wakeup(dev, true);
 
 	return 0;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 10/13] iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (8 preceding siblings ...)
  2019-10-06 13:22 ` [PATCH 09/13] iio: imu: st_lsm6dsx: fix checkpatch warning Lorenzo Bianconi
@ 2019-10-06 13:22 ` Lorenzo Bianconi
  2019-10-12 12:25   ` Jonathan Cameron
  2019-10-06 13:22 ` [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation Lorenzo Bianconi
                   ` (3 subsequent siblings)
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Add the possibility to enable/disable wakeup source through
st_sensors_platform_data and not only through device tree

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c   | 6 ++++--
 include/linux/platform_data/st_sensors_pdata.h | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index b0623b837abd..a2a0ac81e3d3 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -2089,7 +2089,9 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 		     struct regmap *regmap)
 {
+	struct st_sensors_platform_data *pdata = dev->platform_data;
 	const struct st_lsm6dsx_shub_settings *hub_settings;
+	struct device_node *np = dev->of_node;
 	struct st_lsm6dsx_hw *hw;
 	const char *name = NULL;
 	int i, err;
@@ -2152,8 +2154,8 @@ 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"))
+	if ((np && of_property_read_bool(np, "wakeup-source")) ||
+	    (pdata && pdata->wakeup_source))
 		device_init_wakeup(dev, true);
 
 	return 0;
diff --git a/include/linux/platform_data/st_sensors_pdata.h b/include/linux/platform_data/st_sensors_pdata.h
index 30929c22227d..e40b28ca892e 100644
--- a/include/linux/platform_data/st_sensors_pdata.h
+++ b/include/linux/platform_data/st_sensors_pdata.h
@@ -18,12 +18,14 @@
  * @open_drain: set the interrupt line to be open drain if possible.
  * @spi_3wire: enable spi-3wire mode.
  * @pullups: enable/disable i2c controller pullup resistors.
+ * @wakeup_source: enable/disable device as wakeup generator.
  */
 struct st_sensors_platform_data {
 	u8 drdy_int_pin;
 	bool open_drain;
 	bool spi_3wire;
 	bool pullups;
+	bool wakeup_source;
 };
 
 #endif /* ST_SENSORS_PDATA_H */
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (9 preceding siblings ...)
  2019-10-06 13:22 ` [PATCH 10/13] iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data Lorenzo Bianconi
@ 2019-10-06 13:22 ` Lorenzo Bianconi
  2019-10-07  7:56   ` Sean Nyekjaer
  2019-10-06 13:22 ` [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property Lorenzo Bianconi
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Add missing kernel doc for st_lsm6dsx_hw data structure

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 5692ea695f04..40532f99ba4b 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -345,6 +345,9 @@ struct st_lsm6dsx_sensor {
  * @ts_sip: Total number of timestamp samples in a given pattern.
  * @sip: Total number of samples (acc/gyro/ts) in a given pattern.
  * @buff: Device read buffer.
+ * @irq_routing: pointer to interrupt routing configuration.
+ * @event_threshold: wakeup event threshold.
+ * @enable_event: enabled event bitmask.
  * @iio_devs: Pointers to acc/gyro iio_dev instances.
  * @settings: Pointer to the specific sensor settings in use.
  */
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (10 preceding siblings ...)
  2019-10-06 13:22 ` [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation Lorenzo Bianconi
@ 2019-10-06 13:22 ` Lorenzo Bianconi
  2019-10-07  7:56   ` Sean Nyekjaer
  2019-10-15 20:34   ` Rob Herring
  2019-10-06 13:22 ` [PATCH 13/13] iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO Lorenzo Bianconi
  2019-10-12 12:20 ` [PATCH 00/13] various st_lsm6dsx fixes and missing bits Jonathan Cameron
  13 siblings, 2 replies; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
index 6d0c050d89fe..1a07d38c813f 100644
--- a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
+++ b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
@@ -31,6 +31,7 @@ Optional properties:
 - interrupts: interrupt mapping for IRQ. It should be configured with
   flags IRQ_TYPE_LEVEL_HIGH, IRQ_TYPE_EDGE_RISING, IRQ_TYPE_LEVEL_LOW or
   IRQ_TYPE_EDGE_FALLING.
+- wakeup-source: Enables wake up of host system on event.
 
   Refer to interrupt-controller/interrupts.txt for generic interrupt
   client node bindings.
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 13/13] iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (11 preceding siblings ...)
  2019-10-06 13:22 ` [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property Lorenzo Bianconi
@ 2019-10-06 13:22 ` Lorenzo Bianconi
  2019-10-12 12:28   ` Jonathan Cameron
  2019-10-12 12:20 ` [PATCH 00/13] various st_lsm6dsx fixes and missing bits Jonathan Cameron
  13 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-06 13:22 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

Add missing wake-up register info for LSM6DSO/LSM6DSOX sensor

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 25 +++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index a2a0ac81e3d3..876f59cedc8b 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -780,6 +780,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.addr = 0x56,
 				.mask = BIT(6),
 			},
+			.irq1_func = {
+				.addr = 0x5e,
+				.mask = BIT(5),
+			},
+			.irq2_func = {
+				.addr = 0x5f,
+				.mask = BIT(5),
+			},
 			.hla = {
 				.addr = 0x12,
 				.mask = BIT(5),
@@ -847,7 +855,22 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 			.slv0_addr = 0x15,
 			.dw_slv0_addr = 0x21,
 			.batch_en = BIT(3),
-		}
+		},
+		.event_settings = {
+			.enable_reg = {
+				.addr = 0x58,
+				.mask = BIT(7),
+			},
+			.wakeup_reg = {
+				.addr = 0x5b,
+				.mask = GENMASK(5, 0),
+			},
+			.wakeup_src_reg = 0x1b,
+			.wakeup_src_status_mask = BIT(3),
+			.wakeup_src_z_mask = BIT(0),
+			.wakeup_src_y_mask = BIT(1),
+			.wakeup_src_x_mask = BIT(2),
+		},
 	},
 	{
 		.wai = 0x6b,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event
  2019-10-06 13:21 ` [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event Lorenzo Bianconi
@ 2019-10-07  7:54   ` Sean Nyekjaer
  2019-10-12 12:08   ` Jonathan Cameron
  1 sibling, 0 replies; 34+ messages in thread
From: Sean Nyekjaer @ 2019-10-07  7:54 UTC (permalink / raw)
  To: Lorenzo Bianconi, jic23
  Cc: linux-iio, martin, rjones, lorenzo.bianconi, devicetree



On 06/10/2019 15.21, Lorenzo Bianconi wrote:
> Rely on st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event since
> it can run concurrently with sensor hub configuration. Move event
> related code in st_lsm6dsx_report_motion_event
> 
> Fixes: 1aabad1fb5e9 ("iio: imu: st_lsm6dsx: add motion report function and call from interrupt")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Tested-by: Sean Nyekjaer <sean@geanix.com>
> ---
>   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 34 ++++++++++++--------
>   1 file changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 8a813ddba19c..df270905f21d 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1757,10 +1757,23 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
>   	return iio_dev;
>   }
>   
> -static void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data)
> +static bool
> +st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw)
>   {
> -	s64 timestamp = iio_get_time_ns(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
> +	const struct st_lsm6dsx_event_settings *event_settings;
> +	int err, data;
> +	s64 timestamp;
>   
> +	if (!hw->enable_event)
> +		return false;
> +
> +	event_settings = &hw->settings->event_settings;
> +	err = st_lsm6dsx_read_locked(hw, event_settings->wakeup_src_reg,
> +				     &data, sizeof(data));
> +	if (err < 0)
> +		return false;
> +
> +	timestamp = iio_get_time_ns(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
>   	if ((data & hw->settings->event_settings.wakeup_src_z_mask) &&
>   	    (hw->enable_event & BIT(IIO_MOD_Z)))
>   		iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC],
> @@ -1790,30 +1803,23 @@ static void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data)
>   						  IIO_EV_TYPE_THRESH,
>   						  IIO_EV_DIR_EITHER),
>   						  timestamp);
> +
> +	return data & event_settings->wakeup_src_status_mask;
>   }
>   
>   static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
>   {
>   	struct st_lsm6dsx_hw *hw = private;
> +	bool event;
>   	int count;
> -	int data, err;
> -
> -	if (hw->enable_event) {
> -		err = regmap_read(hw->regmap,
> -				  hw->settings->event_settings.wakeup_src_reg,
> -				  &data);
> -		if (err < 0)
> -			return IRQ_NONE;
>   
> -		if (data & hw->settings->event_settings.wakeup_src_status_mask)
> -			st_lsm6dsx_report_motion_event(hw, data);
> -	}
> +	event = st_lsm6dsx_report_motion_event(hw);
>   
>   	mutex_lock(&hw->fifo_lock);
>   	count = hw->settings->fifo_ops.read_fifo(hw);
>   	mutex_unlock(&hw->fifo_lock);
>   
> -	return count ? IRQ_HANDLED : IRQ_NONE;
> +	return count || event ? IRQ_HANDLED : IRQ_NONE;
>   }
>   
>   static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config
  2019-10-06 13:21 ` [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config Lorenzo Bianconi
@ 2019-10-07  7:54   ` Sean Nyekjaer
  2019-10-12 12:13     ` Jonathan Cameron
  0 siblings, 1 reply; 34+ messages in thread
From: Sean Nyekjaer @ 2019-10-07  7:54 UTC (permalink / raw)
  To: Lorenzo Bianconi, jic23
  Cc: linux-iio, martin, rjones, lorenzo.bianconi, devicetree



On 06/10/2019 15.21, Lorenzo Bianconi wrote:
> Group irq related definition in irq_config structure in
> st_lsm6dsx_settings. This is a preliminary patch to move
> OpenDrain/Active low registers in st_lsm6dsx_settings.
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Tested-by: Sean Nyekjaer <sean@geanix.com>
> ---
>   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  22 +-
>   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 265 ++++++++++++-------
>   2 files changed, 179 insertions(+), 108 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index fd02d0e184f3..873ec3b8fd69 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -236,29 +236,21 @@ struct st_lsm6dsx_ext_dev_settings {
>   /**
>    * struct st_lsm6dsx_settings - ST IMU sensor settings
>    * @wai: Sensor WhoAmI default value.
> - * @int1_addr: Control Register address for INT1
> - * @int2_addr: Control Register address for INT2
>    * @reset_addr: register address for reset/reboot
>    * @max_fifo_size: Sensor max fifo length in FIFO words.
>    * @id: List of hw id/device name supported by the driver configuration.
>    * @channels: IIO channels supported by the device.
> + * @irq_config: interrupts related registers.
>    * @odr_table: Hw sensors odr table (Hz + val).
>    * @fs_table: Hw sensors gain table (gain + val).
>    * @decimator: List of decimator register info (addr + mask).
>    * @batch: List of FIFO batching register info (addr + mask).
> - * @lir: Latched interrupt register info (addr + mask).
> - * @clear_on_read: Clear on read register info (addr + mask).
>    * @fifo_ops: Sensor hw FIFO parameters.
>    * @ts_settings: Hw timer related settings.
>    * @shub_settings: i2c controller related settings.
>    */
>   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 {
> @@ -269,12 +261,18 @@ struct st_lsm6dsx_settings {
>   		const struct iio_chan_spec *chan;
>   		int len;
>   	} channels[2];
> +	struct {
> +		struct st_lsm6dsx_reg irq1;
> +		struct st_lsm6dsx_reg irq2;
> +		struct st_lsm6dsx_reg irq1_func;
> +		struct st_lsm6dsx_reg irq2_func;
> +		struct st_lsm6dsx_reg lir;
> +		struct st_lsm6dsx_reg clear_on_read;
> +	} irq_config;
>   	struct st_lsm6dsx_odr_table_entry odr_table[2];
>   	struct st_lsm6dsx_fs_table_entry fs_table[2];
>   	struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
>   	struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
> -	struct st_lsm6dsx_reg lir;
> -	struct st_lsm6dsx_reg clear_on_read;
>   	struct st_lsm6dsx_fifo_ops fifo_ops;
>   	struct st_lsm6dsx_hw_ts_settings ts_settings;
>   	struct st_lsm6dsx_shub_settings shub_settings;
> @@ -359,9 +357,9 @@ struct st_lsm6dsx_hw {
>   	u8 ts_sip;
>   	u8 sip;
>   
> +	const struct st_lsm6dsx_reg *irq_routing;
>   	u8 event_threshold;
>   	u8 enable_event;
> -	struct st_lsm6dsx_reg irq_routing;
>   
>   	u8 *buff;
>   
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index eac695663b6f..23d67caa24ed 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -61,7 +61,6 @@
>   
>   #include "st_lsm6dsx.h"
>   
> -#define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK	BIT(3)
>   #define ST_LSM6DSX_REG_WHOAMI_ADDR		0x0f
>   #define ST_LSM6DSX_REG_RESET_MASK		BIT(0)
>   #define ST_LSM6DSX_REG_BOOT_MASK		BIT(7)
> @@ -97,8 +96,6 @@ static const struct iio_chan_spec st_lsm6ds0_gyro_channels[] = {
>   static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   	{
>   		.wai = 0x68,
> -		.int1_addr = 0x0c,
> -		.int2_addr = 0x0d,
>   		.reset_addr = 0x22,
>   		.max_fifo_size = 32,
>   		.id = {
> @@ -164,14 +161,19 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.fs_avl[2] = { IIO_DEGREE_TO_RAD(2000), 0x3 },
>   			},
>   		},
> +		.irq_config = {
> +			.irq1 = {
> +				.addr = 0x0c,
> +				.mask = BIT(3),
> +			},
> +			.irq2 = {
> +				.addr = 0x0d,
> +				.mask = BIT(3),
> +			},
> +		},
>   	},
>   	{
>   		.wai = 0x69,
> -		.int1_addr = 0x0d,
> -		.int2_addr = 0x0e,
> -		.int1_func_addr = 0x5e,
> -		.int2_func_addr = 0x5f,
> -		.int_func_mask = BIT(5),
>   		.reset_addr = 0x12,
>   		.max_fifo_size = 1365,
>   		.id = {
> @@ -238,6 +240,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
>   			},
>   		},
> +		.irq_config = {
> +			.irq1 = {
> +				.addr = 0x0d,
> +				.mask = BIT(3),
> +			},
> +			.irq2 = {
> +				.addr = 0x0e,
> +				.mask = BIT(3),
> +			},
> +			.lir = {
> +				.addr = 0x58,
> +				.mask = BIT(0),
> +			},
> +			.irq1_func = {
> +				.addr = 0x5e,
> +				.mask = BIT(5),
> +			},
> +			.irq2_func = {
> +				.addr = 0x5f,
> +				.mask = BIT(5),
> +			},
> +		},
>   		.decimator = {
>   			[ST_LSM6DSX_ID_ACC] = {
>   				.addr = 0x08,
> @@ -248,10 +272,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.mask = GENMASK(5, 3),
>   			},
>   		},
> -		.lir = {
> -			.addr = 0x58,
> -			.mask = BIT(0),
> -		},
>   		.fifo_ops = {
>   			.update_fifo = st_lsm6dsx_update_fifo,
>   			.read_fifo = st_lsm6dsx_read_fifo,
> @@ -297,11 +317,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   	},
>   	{
>   		.wai = 0x69,
> -		.int1_addr = 0x0d,
> -		.int2_addr = 0x0e,
> -		.int1_func_addr = 0x5e,
> -		.int2_func_addr = 0x5f,
> -		.int_func_mask = BIT(5),
>   		.reset_addr = 0x12,
>   		.max_fifo_size = 682,
>   		.id = {
> @@ -368,6 +383,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
>   			},
>   		},
> +		.irq_config = {
> +			.irq1 = {
> +				.addr = 0x0d,
> +				.mask = BIT(3),
> +			},
> +			.irq2 = {
> +				.addr = 0x0e,
> +				.mask = BIT(3),
> +			},
> +			.lir = {
> +				.addr = 0x58,
> +				.mask = BIT(0),
> +			},
> +			.irq1_func = {
> +				.addr = 0x5e,
> +				.mask = BIT(5),
> +			},
> +			.irq2_func = {
> +				.addr = 0x5f,
> +				.mask = BIT(5),
> +			},
> +		},
>   		.decimator = {
>   			[ST_LSM6DSX_ID_ACC] = {
>   				.addr = 0x08,
> @@ -378,10 +415,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.mask = GENMASK(5, 3),
>   			},
>   		},
> -		.lir = {
> -			.addr = 0x58,
> -			.mask = BIT(0),
> -		},
>   		.fifo_ops = {
>   			.update_fifo = st_lsm6dsx_update_fifo,
>   			.read_fifo = st_lsm6dsx_read_fifo,
> @@ -427,11 +460,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   	},
>   	{
>   		.wai = 0x6a,
> -		.int1_addr = 0x0d,
> -		.int2_addr = 0x0e,
> -		.int1_func_addr = 0x5e,
> -		.int2_func_addr = 0x5f,
> -		.int_func_mask = BIT(5),
>   		.reset_addr = 0x12,
>   		.max_fifo_size = 682,
>   		.id = {
> @@ -507,6 +535,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
>   			},
>   		},
> +		.irq_config = {
> +			.irq1 = {
> +				.addr = 0x0d,
> +				.mask = BIT(3),
> +			},
> +			.irq2 = {
> +				.addr = 0x0e,
> +				.mask = BIT(3),
> +			},
> +			.lir = {
> +				.addr = 0x58,
> +				.mask = BIT(0),
> +			},
> +			.irq1_func = {
> +				.addr = 0x5e,
> +				.mask = BIT(5),
> +			},
> +			.irq2_func = {
> +				.addr = 0x5f,
> +				.mask = BIT(5),
> +			},
> +		},
>   		.decimator = {
>   			[ST_LSM6DSX_ID_ACC] = {
>   				.addr = 0x08,
> @@ -517,10 +567,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.mask = GENMASK(5, 3),
>   			},
>   		},
> -		.lir = {
> -			.addr = 0x58,
> -			.mask = BIT(0),
> -		},
>   		.fifo_ops = {
>   			.update_fifo = st_lsm6dsx_update_fifo,
>   			.read_fifo = st_lsm6dsx_read_fifo,
> @@ -570,8 +616,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   	},
>   	{
>   		.wai = 0x6c,
> -		.int1_addr = 0x0d,
> -		.int2_addr = 0x0e,
>   		.reset_addr = 0x12,
>   		.max_fifo_size = 512,
>   		.id = {
> @@ -641,6 +685,24 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
>   			},
>   		},
> +		.irq_config = {
> +			.irq1 = {
> +				.addr = 0x0d,
> +				.mask = BIT(3),
> +			},
> +			.irq2 = {
> +				.addr = 0x0e,
> +				.mask = BIT(3),
> +			},
> +			.lir = {
> +				.addr = 0x56,
> +				.mask = BIT(0),
> +			},
> +			.clear_on_read = {
> +				.addr = 0x56,
> +				.mask = BIT(6),
> +			},
> +		},
>   		.batch = {
>   			[ST_LSM6DSX_ID_ACC] = {
>   				.addr = 0x09,
> @@ -651,14 +713,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.mask = GENMASK(7, 4),
>   			},
>   		},
> -		.lir = {
> -			.addr = 0x56,
> -			.mask = BIT(0),
> -		},
> -		.clear_on_read = {
> -			.addr = 0x56,
> -			.mask = BIT(6),
> -		},
>   		.fifo_ops = {
>   			.update_fifo = st_lsm6dsx_update_fifo,
>   			.read_fifo = st_lsm6dsx_read_tagged_fifo,
> @@ -711,11 +765,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   	},
>   	{
>   		.wai = 0x6b,
> -		.int1_addr = 0x0d,
> -		.int2_addr = 0x0e,
> -		.int1_func_addr = 0x5e,
> -		.int2_func_addr = 0x5f,
> -		.int_func_mask = BIT(5),
>   		.reset_addr = 0x12,
>   		.max_fifo_size = 512,
>   		.id = {
> @@ -782,6 +831,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
>   			},
>   		},
> +		.irq_config = {
> +			.irq1 = {
> +				.addr = 0x0d,
> +				.mask = BIT(3),
> +			},
> +			.irq2 = {
> +				.addr = 0x0e,
> +				.mask = BIT(3),
> +			},
> +			.lir = {
> +				.addr = 0x56,
> +				.mask = BIT(0),
> +			},
> +			.clear_on_read = {
> +				.addr = 0x56,
> +				.mask = BIT(6),
> +			},
> +			.irq1_func = {
> +				.addr = 0x5e,
> +				.mask = BIT(5),
> +			},
> +			.irq2_func = {
> +				.addr = 0x5f,
> +				.mask = BIT(5),
> +			},
> +		},
>   		.batch = {
>   			[ST_LSM6DSX_ID_ACC] = {
>   				.addr = 0x09,
> @@ -792,14 +867,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.mask = GENMASK(7, 4),
>   			},
>   		},
> -		.lir = {
> -			.addr = 0x56,
> -			.mask = BIT(0),
> -		},
> -		.clear_on_read = {
> -			.addr = 0x56,
> -			.mask = BIT(6),
> -		},
>   		.fifo_ops = {
>   			.update_fifo = st_lsm6dsx_update_fifo,
>   			.read_fifo = st_lsm6dsx_read_tagged_fifo,
> @@ -841,11 +908,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   	},
>   	{
>   		.wai = 0x6b,
> -		.int1_addr = 0x0d,
> -		.int2_addr = 0x0e,
> -		.int1_func_addr = 0x5e,
> -		.int2_func_addr = 0x5f,
> -		.int_func_mask = BIT(5),
>   		.reset_addr = 0x12,
>   		.max_fifo_size = 512,
>   		.id = {
> @@ -915,6 +977,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
>   			},
>   		},
> +		.irq_config = {
> +			.irq1 = {
> +				.addr = 0x0d,
> +				.mask = BIT(3),
> +			},
> +			.irq2 = {
> +				.addr = 0x0e,
> +				.mask = BIT(3),
> +			},
> +			.lir = {
> +				.addr = 0x56,
> +				.mask = BIT(0),
> +			},
> +			.clear_on_read = {
> +				.addr = 0x56,
> +				.mask = BIT(6),
> +			},
> +			.irq1_func = {
> +				.addr = 0x5e,
> +				.mask = BIT(5),
> +			},
> +			.irq2_func = {
> +				.addr = 0x5f,
> +				.mask = BIT(5),
> +			},
> +		},
>   		.batch = {
>   			[ST_LSM6DSX_ID_ACC] = {
>   				.addr = 0x09,
> @@ -925,14 +1013,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>   				.mask = GENMASK(7, 4),
>   			},
>   		},
> -		.lir = {
> -			.addr = 0x56,
> -			.mask = BIT(0),
> -		},
> -		.clear_on_read = {
> -			.addr = 0x56,
> -			.mask = BIT(6),
> -		},
>   		.fifo_ops = {
>   			.update_fifo = st_lsm6dsx_update_fifo,
>   			.read_fifo = st_lsm6dsx_read_tagged_fifo,
> @@ -1281,7 +1361,7 @@ static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
>   	int err;
>   	u8 enable = 0;
>   
> -	if (!hw->settings->int1_func_addr)
> +	if (!hw->settings->irq_config.irq1_func.addr)
>   		return -ENOTSUPP;
>   
>   	enable = state ? hw->settings->event_settings.enable_reg.mask : 0;
> @@ -1293,12 +1373,11 @@ static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
>   	if (err < 0)
>   		return err;
>   
> -	enable = state ? hw->irq_routing.mask : 0;
> +	enable = state ? hw->irq_routing->mask : 0;
>   
>   	/* Enable wakeup interrupt */
> -	return regmap_update_bits(hw->regmap, hw->irq_routing.addr,
> -				  hw->irq_routing.mask,
> -				  enable);
> +	return regmap_update_bits(hw->regmap, hw->irq_routing->addr,
> +				  hw->irq_routing->mask, enable);
>   }
>   
>   static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
> @@ -1527,7 +1606,9 @@ static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
>   	return of_property_read_u32(np, "st,drdy-int-pin", drdy_pin);
>   }
>   
> -static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
> +static int
> +st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
> +			const struct st_lsm6dsx_reg **drdy_reg)
>   {
>   	int err = 0, drdy_pin;
>   
> @@ -1541,14 +1622,12 @@ static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
>   
>   	switch (drdy_pin) {
>   	case 1:
> -		*drdy_reg = hw->settings->int1_addr;
> -		hw->irq_routing.addr = hw->settings->int1_func_addr;
> -		hw->irq_routing.mask = hw->settings->int_func_mask;
> +		hw->irq_routing = &hw->settings->irq_config.irq1_func;
> +		*drdy_reg = &hw->settings->irq_config.irq1;
>   		break;
>   	case 2:
> -		*drdy_reg = hw->settings->int2_addr;
> -		hw->irq_routing.addr = hw->settings->int2_func_addr;
> -		hw->irq_routing.mask = hw->settings->int_func_mask;
> +		hw->irq_routing = &hw->settings->irq_config.irq2_func;
> +		*drdy_reg = &hw->settings->irq_config.irq2;
>   		break;
>   	default:
>   		dev_err(hw->dev, "unsupported data ready pin\n");
> @@ -1644,7 +1723,7 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
>   
>   static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
>   {
> -	u8 drdy_int_reg;
> +	const struct st_lsm6dsx_reg *reg;
>   	int err;
>   
>   	/* device sw reset */
> @@ -1673,35 +1752,29 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
>   		return err;
>   
>   	/* enable FIFO watermak interrupt */
> -	err = st_lsm6dsx_get_drdy_reg(hw, &drdy_int_reg);
> +	err = st_lsm6dsx_get_drdy_reg(hw, &reg);
>   	if (err < 0)
>   		return err;
>   
> -	err = regmap_update_bits(hw->regmap, drdy_int_reg,
> -				 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK,
> -				 FIELD_PREP(ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK,
> -					    1));
> +	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> +				 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
>   	if (err < 0)
>   		return err;
>   
>   	/* enable Latched interrupts for device events */
> -	if (hw->settings->lir.addr) {
> -		unsigned int data;
> -
> -		data = ST_LSM6DSX_SHIFT_VAL(1, hw->settings->lir.mask);
> -		err = regmap_update_bits(hw->regmap, hw->settings->lir.addr,
> -					 hw->settings->lir.mask, data);
> +	if (hw->settings->irq_config.lir.addr) {
> +		reg = &hw->settings->irq_config.lir;
> +		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> +					 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
>   		if (err < 0)
>   			return err;
>   
>   		/* enable clear on read for latched interrupts */
> -		if (hw->settings->clear_on_read.addr) {
> -			data = ST_LSM6DSX_SHIFT_VAL(1,
> -					hw->settings->clear_on_read.mask);
> +		if (hw->settings->irq_config.clear_on_read.addr) {
> +			reg = &hw->settings->irq_config.clear_on_read;
>   			err = regmap_update_bits(hw->regmap,
> -					hw->settings->clear_on_read.addr,
> -					hw->settings->clear_on_read.mask,
> -					data);
> +					reg->addr, reg->mask,
> +					ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
>   			if (err < 0)
>   				return err;
>   		}
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup
  2019-10-06 13:22 ` [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup Lorenzo Bianconi
@ 2019-10-07  7:55   ` Sean Nyekjaer
  2019-10-12 12:21     ` Jonathan Cameron
  0 siblings, 1 reply; 34+ messages in thread
From: Sean Nyekjaer @ 2019-10-07  7:55 UTC (permalink / raw)
  To: Lorenzo Bianconi, jic23
  Cc: linux-iio, martin, rjones, lorenzo.bianconi, devicetree



On 06/10/2019 15.22, Lorenzo Bianconi wrote:
> Check if enable_reg of event_settings data structure is defined before
> writing on it
> 
> Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Tested-by: Sean Nyekjaer <sean@geanix.com>
> ---
>   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 23 ++++++++++----------
>   1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 5df382b9d8f9..7e9e1ef81742 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1482,26 +1482,25 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
>   
>   static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
>   {
> +	const struct st_lsm6dsx_reg *reg;
>   	int err;
> -	u8 enable = 0;
>   
>   	if (!hw->settings->irq_config.irq1_func.addr)
>   		return -ENOTSUPP;
>   
> -	enable = state ? hw->settings->event_settings.enable_reg.mask : 0;
> -
> -	err = regmap_update_bits(hw->regmap,
> -				 hw->settings->event_settings.enable_reg.addr,
> -				 hw->settings->event_settings.enable_reg.mask,
> -				 enable);
> -	if (err < 0)
> -		return err;
> -
> -	enable = state ? hw->irq_routing->mask : 0;
> +	reg = &hw->settings->event_settings.enable_reg;
> +	if (reg->addr) {
> +		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> +					 ST_LSM6DSX_SHIFT_VAL(state, reg->mask));
> +		if (err < 0)
> +			return err;
> +	}
>   
>   	/* Enable wakeup interrupt */
>   	return regmap_update_bits(hw->regmap, hw->irq_routing->addr,
> -				  hw->irq_routing->mask, enable);
> +				  hw->irq_routing->mask,
> +				  ST_LSM6DSX_SHIFT_VAL(state,
> +					hw->irq_routing->mask));
>   }
>   
>   static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation
  2019-10-06 13:22 ` [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation Lorenzo Bianconi
@ 2019-10-07  7:56   ` Sean Nyekjaer
  2019-10-12 12:26     ` Jonathan Cameron
  0 siblings, 1 reply; 34+ messages in thread
From: Sean Nyekjaer @ 2019-10-07  7:56 UTC (permalink / raw)
  To: Lorenzo Bianconi, jic23
  Cc: linux-iio, martin, rjones, lorenzo.bianconi, devicetree



On 06/10/2019 15.22, Lorenzo Bianconi wrote:
> Add missing kernel doc for st_lsm6dsx_hw data structure
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Reviewed-by: Sean Nyekjaer <sean@geanix.com>
> ---
>   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index 5692ea695f04..40532f99ba4b 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -345,6 +345,9 @@ struct st_lsm6dsx_sensor {
>    * @ts_sip: Total number of timestamp samples in a given pattern.
>    * @sip: Total number of samples (acc/gyro/ts) in a given pattern.
>    * @buff: Device read buffer.
> + * @irq_routing: pointer to interrupt routing configuration.
> + * @event_threshold: wakeup event threshold.
> + * @enable_event: enabled event bitmask.
>    * @iio_devs: Pointers to acc/gyro iio_dev instances.
>    * @settings: Pointer to the specific sensor settings in use.
>    */
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property
  2019-10-06 13:22 ` [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property Lorenzo Bianconi
@ 2019-10-07  7:56   ` Sean Nyekjaer
  2019-10-15 20:34   ` Rob Herring
  1 sibling, 0 replies; 34+ messages in thread
From: Sean Nyekjaer @ 2019-10-07  7:56 UTC (permalink / raw)
  To: Lorenzo Bianconi, jic23
  Cc: linux-iio, martin, rjones, lorenzo.bianconi, devicetree



On 06/10/2019 15.22, Lorenzo Bianconi wrote:
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Reviewed-by: Sean Nyekjaer <sean@geanix.com>
> ---
>   Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
> index 6d0c050d89fe..1a07d38c813f 100644
> --- a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
> +++ b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
> @@ -31,6 +31,7 @@ Optional properties:
>   - interrupts: interrupt mapping for IRQ. It should be configured with
>     flags IRQ_TYPE_LEVEL_HIGH, IRQ_TYPE_EDGE_RISING, IRQ_TYPE_LEVEL_LOW or
>     IRQ_TYPE_EDGE_FALLING.
> +- wakeup-source: Enables wake up of host system on event.
>   
>     Refer to interrupt-controller/interrupts.txt for generic interrupt
>     client node bindings.
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event
  2019-10-06 13:21 ` [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event Lorenzo Bianconi
  2019-10-07  7:54   ` Sean Nyekjaer
@ 2019-10-12 12:08   ` Jonathan Cameron
  1 sibling, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:08 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:21:55 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Rely on st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event since
> it can run concurrently with sensor hub configuration. Move event
> related code in st_lsm6dsx_report_motion_event
> 
> Fixes: 1aabad1fb5e9 ("iio: imu: st_lsm6dsx: add motion report function and call from interrupt")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 34 ++++++++++++--------
>  1 file changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 8a813ddba19c..df270905f21d 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1757,10 +1757,23 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
>  	return iio_dev;
>  }
>  
> -static void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data)
> +static bool
> +st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw)
>  {
> -	s64 timestamp = iio_get_time_ns(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
> +	const struct st_lsm6dsx_event_settings *event_settings;
> +	int err, data;
> +	s64 timestamp;
>  
> +	if (!hw->enable_event)
> +		return false;
> +
> +	event_settings = &hw->settings->event_settings;
> +	err = st_lsm6dsx_read_locked(hw, event_settings->wakeup_src_reg,
> +				     &data, sizeof(data));
> +	if (err < 0)
> +		return false;
> +
> +	timestamp = iio_get_time_ns(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
>  	if ((data & hw->settings->event_settings.wakeup_src_z_mask) &&
>  	    (hw->enable_event & BIT(IIO_MOD_Z)))
>  		iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC],
> @@ -1790,30 +1803,23 @@ static void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data)
>  						  IIO_EV_TYPE_THRESH,
>  						  IIO_EV_DIR_EITHER),
>  						  timestamp);
> +
> +	return data & event_settings->wakeup_src_status_mask;
>  }
>  
>  static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
>  {
>  	struct st_lsm6dsx_hw *hw = private;
> +	bool event;
>  	int count;
> -	int data, err;
> -
> -	if (hw->enable_event) {
> -		err = regmap_read(hw->regmap,
> -				  hw->settings->event_settings.wakeup_src_reg,
> -				  &data);
> -		if (err < 0)
> -			return IRQ_NONE;
>  
> -		if (data & hw->settings->event_settings.wakeup_src_status_mask)
> -			st_lsm6dsx_report_motion_event(hw, data);
> -	}
> +	event = st_lsm6dsx_report_motion_event(hw);
>  
>  	mutex_lock(&hw->fifo_lock);
>  	count = hw->settings->fifo_ops.read_fifo(hw);
>  	mutex_unlock(&hw->fifo_lock);
>  
> -	return count ? IRQ_HANDLED : IRQ_NONE;
> +	return count || event ? IRQ_HANDLED : IRQ_NONE;
>  }
>  
>  static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config
  2019-10-07  7:54   ` Sean Nyekjaer
@ 2019-10-12 12:13     ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:13 UTC (permalink / raw)
  To: Sean Nyekjaer
  Cc: Lorenzo Bianconi, linux-iio, martin, rjones, lorenzo.bianconi,
	devicetree

On Mon, 7 Oct 2019 09:54:55 +0200
Sean Nyekjaer <sean@geanix.com> wrote:

> On 06/10/2019 15.21, Lorenzo Bianconi wrote:
> > Group irq related definition in irq_config structure in
> > st_lsm6dsx_settings. This is a preliminary patch to move
> > OpenDrain/Active low registers in st_lsm6dsx_settings.
> > 
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>  
> Tested-by: Sean Nyekjaer <sean@geanix.com>

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> > ---
> >   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  22 +-
> >   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 265 ++++++++++++-------
> >   2 files changed, 179 insertions(+), 108 deletions(-)
> > 
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> > index fd02d0e184f3..873ec3b8fd69 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> > @@ -236,29 +236,21 @@ struct st_lsm6dsx_ext_dev_settings {
> >   /**
> >    * struct st_lsm6dsx_settings - ST IMU sensor settings
> >    * @wai: Sensor WhoAmI default value.
> > - * @int1_addr: Control Register address for INT1
> > - * @int2_addr: Control Register address for INT2
> >    * @reset_addr: register address for reset/reboot
> >    * @max_fifo_size: Sensor max fifo length in FIFO words.
> >    * @id: List of hw id/device name supported by the driver configuration.
> >    * @channels: IIO channels supported by the device.
> > + * @irq_config: interrupts related registers.
> >    * @odr_table: Hw sensors odr table (Hz + val).
> >    * @fs_table: Hw sensors gain table (gain + val).
> >    * @decimator: List of decimator register info (addr + mask).
> >    * @batch: List of FIFO batching register info (addr + mask).
> > - * @lir: Latched interrupt register info (addr + mask).
> > - * @clear_on_read: Clear on read register info (addr + mask).
> >    * @fifo_ops: Sensor hw FIFO parameters.
> >    * @ts_settings: Hw timer related settings.
> >    * @shub_settings: i2c controller related settings.
> >    */
> >   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 {
> > @@ -269,12 +261,18 @@ struct st_lsm6dsx_settings {
> >   		const struct iio_chan_spec *chan;
> >   		int len;
> >   	} channels[2];
> > +	struct {
> > +		struct st_lsm6dsx_reg irq1;
> > +		struct st_lsm6dsx_reg irq2;
> > +		struct st_lsm6dsx_reg irq1_func;
> > +		struct st_lsm6dsx_reg irq2_func;
> > +		struct st_lsm6dsx_reg lir;
> > +		struct st_lsm6dsx_reg clear_on_read;
> > +	} irq_config;
> >   	struct st_lsm6dsx_odr_table_entry odr_table[2];
> >   	struct st_lsm6dsx_fs_table_entry fs_table[2];
> >   	struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
> >   	struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
> > -	struct st_lsm6dsx_reg lir;
> > -	struct st_lsm6dsx_reg clear_on_read;
> >   	struct st_lsm6dsx_fifo_ops fifo_ops;
> >   	struct st_lsm6dsx_hw_ts_settings ts_settings;
> >   	struct st_lsm6dsx_shub_settings shub_settings;
> > @@ -359,9 +357,9 @@ struct st_lsm6dsx_hw {
> >   	u8 ts_sip;
> >   	u8 sip;
> >   
> > +	const struct st_lsm6dsx_reg *irq_routing;
> >   	u8 event_threshold;
> >   	u8 enable_event;
> > -	struct st_lsm6dsx_reg irq_routing;
> >   
> >   	u8 *buff;
> >   
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > index eac695663b6f..23d67caa24ed 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > @@ -61,7 +61,6 @@
> >   
> >   #include "st_lsm6dsx.h"
> >   
> > -#define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK	BIT(3)
> >   #define ST_LSM6DSX_REG_WHOAMI_ADDR		0x0f
> >   #define ST_LSM6DSX_REG_RESET_MASK		BIT(0)
> >   #define ST_LSM6DSX_REG_BOOT_MASK		BIT(7)
> > @@ -97,8 +96,6 @@ static const struct iio_chan_spec st_lsm6ds0_gyro_channels[] = {
> >   static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   	{
> >   		.wai = 0x68,
> > -		.int1_addr = 0x0c,
> > -		.int2_addr = 0x0d,
> >   		.reset_addr = 0x22,
> >   		.max_fifo_size = 32,
> >   		.id = {
> > @@ -164,14 +161,19 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.fs_avl[2] = { IIO_DEGREE_TO_RAD(2000), 0x3 },
> >   			},
> >   		},
> > +		.irq_config = {
> > +			.irq1 = {
> > +				.addr = 0x0c,
> > +				.mask = BIT(3),
> > +			},
> > +			.irq2 = {
> > +				.addr = 0x0d,
> > +				.mask = BIT(3),
> > +			},
> > +		},
> >   	},
> >   	{
> >   		.wai = 0x69,
> > -		.int1_addr = 0x0d,
> > -		.int2_addr = 0x0e,
> > -		.int1_func_addr = 0x5e,
> > -		.int2_func_addr = 0x5f,
> > -		.int_func_mask = BIT(5),
> >   		.reset_addr = 0x12,
> >   		.max_fifo_size = 1365,
> >   		.id = {
> > @@ -238,6 +240,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> >   			},
> >   		},
> > +		.irq_config = {
> > +			.irq1 = {
> > +				.addr = 0x0d,
> > +				.mask = BIT(3),
> > +			},
> > +			.irq2 = {
> > +				.addr = 0x0e,
> > +				.mask = BIT(3),
> > +			},
> > +			.lir = {
> > +				.addr = 0x58,
> > +				.mask = BIT(0),
> > +			},
> > +			.irq1_func = {
> > +				.addr = 0x5e,
> > +				.mask = BIT(5),
> > +			},
> > +			.irq2_func = {
> > +				.addr = 0x5f,
> > +				.mask = BIT(5),
> > +			},
> > +		},
> >   		.decimator = {
> >   			[ST_LSM6DSX_ID_ACC] = {
> >   				.addr = 0x08,
> > @@ -248,10 +272,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.mask = GENMASK(5, 3),
> >   			},
> >   		},
> > -		.lir = {
> > -			.addr = 0x58,
> > -			.mask = BIT(0),
> > -		},
> >   		.fifo_ops = {
> >   			.update_fifo = st_lsm6dsx_update_fifo,
> >   			.read_fifo = st_lsm6dsx_read_fifo,
> > @@ -297,11 +317,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   	},
> >   	{
> >   		.wai = 0x69,
> > -		.int1_addr = 0x0d,
> > -		.int2_addr = 0x0e,
> > -		.int1_func_addr = 0x5e,
> > -		.int2_func_addr = 0x5f,
> > -		.int_func_mask = BIT(5),
> >   		.reset_addr = 0x12,
> >   		.max_fifo_size = 682,
> >   		.id = {
> > @@ -368,6 +383,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> >   			},
> >   		},
> > +		.irq_config = {
> > +			.irq1 = {
> > +				.addr = 0x0d,
> > +				.mask = BIT(3),
> > +			},
> > +			.irq2 = {
> > +				.addr = 0x0e,
> > +				.mask = BIT(3),
> > +			},
> > +			.lir = {
> > +				.addr = 0x58,
> > +				.mask = BIT(0),
> > +			},
> > +			.irq1_func = {
> > +				.addr = 0x5e,
> > +				.mask = BIT(5),
> > +			},
> > +			.irq2_func = {
> > +				.addr = 0x5f,
> > +				.mask = BIT(5),
> > +			},
> > +		},
> >   		.decimator = {
> >   			[ST_LSM6DSX_ID_ACC] = {
> >   				.addr = 0x08,
> > @@ -378,10 +415,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.mask = GENMASK(5, 3),
> >   			},
> >   		},
> > -		.lir = {
> > -			.addr = 0x58,
> > -			.mask = BIT(0),
> > -		},
> >   		.fifo_ops = {
> >   			.update_fifo = st_lsm6dsx_update_fifo,
> >   			.read_fifo = st_lsm6dsx_read_fifo,
> > @@ -427,11 +460,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   	},
> >   	{
> >   		.wai = 0x6a,
> > -		.int1_addr = 0x0d,
> > -		.int2_addr = 0x0e,
> > -		.int1_func_addr = 0x5e,
> > -		.int2_func_addr = 0x5f,
> > -		.int_func_mask = BIT(5),
> >   		.reset_addr = 0x12,
> >   		.max_fifo_size = 682,
> >   		.id = {
> > @@ -507,6 +535,28 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> >   			},
> >   		},
> > +		.irq_config = {
> > +			.irq1 = {
> > +				.addr = 0x0d,
> > +				.mask = BIT(3),
> > +			},
> > +			.irq2 = {
> > +				.addr = 0x0e,
> > +				.mask = BIT(3),
> > +			},
> > +			.lir = {
> > +				.addr = 0x58,
> > +				.mask = BIT(0),
> > +			},
> > +			.irq1_func = {
> > +				.addr = 0x5e,
> > +				.mask = BIT(5),
> > +			},
> > +			.irq2_func = {
> > +				.addr = 0x5f,
> > +				.mask = BIT(5),
> > +			},
> > +		},
> >   		.decimator = {
> >   			[ST_LSM6DSX_ID_ACC] = {
> >   				.addr = 0x08,
> > @@ -517,10 +567,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.mask = GENMASK(5, 3),
> >   			},
> >   		},
> > -		.lir = {
> > -			.addr = 0x58,
> > -			.mask = BIT(0),
> > -		},
> >   		.fifo_ops = {
> >   			.update_fifo = st_lsm6dsx_update_fifo,
> >   			.read_fifo = st_lsm6dsx_read_fifo,
> > @@ -570,8 +616,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   	},
> >   	{
> >   		.wai = 0x6c,
> > -		.int1_addr = 0x0d,
> > -		.int2_addr = 0x0e,
> >   		.reset_addr = 0x12,
> >   		.max_fifo_size = 512,
> >   		.id = {
> > @@ -641,6 +685,24 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> >   			},
> >   		},
> > +		.irq_config = {
> > +			.irq1 = {
> > +				.addr = 0x0d,
> > +				.mask = BIT(3),
> > +			},
> > +			.irq2 = {
> > +				.addr = 0x0e,
> > +				.mask = BIT(3),
> > +			},
> > +			.lir = {
> > +				.addr = 0x56,
> > +				.mask = BIT(0),
> > +			},
> > +			.clear_on_read = {
> > +				.addr = 0x56,
> > +				.mask = BIT(6),
> > +			},
> > +		},
> >   		.batch = {
> >   			[ST_LSM6DSX_ID_ACC] = {
> >   				.addr = 0x09,
> > @@ -651,14 +713,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.mask = GENMASK(7, 4),
> >   			},
> >   		},
> > -		.lir = {
> > -			.addr = 0x56,
> > -			.mask = BIT(0),
> > -		},
> > -		.clear_on_read = {
> > -			.addr = 0x56,
> > -			.mask = BIT(6),
> > -		},
> >   		.fifo_ops = {
> >   			.update_fifo = st_lsm6dsx_update_fifo,
> >   			.read_fifo = st_lsm6dsx_read_tagged_fifo,
> > @@ -711,11 +765,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   	},
> >   	{
> >   		.wai = 0x6b,
> > -		.int1_addr = 0x0d,
> > -		.int2_addr = 0x0e,
> > -		.int1_func_addr = 0x5e,
> > -		.int2_func_addr = 0x5f,
> > -		.int_func_mask = BIT(5),
> >   		.reset_addr = 0x12,
> >   		.max_fifo_size = 512,
> >   		.id = {
> > @@ -782,6 +831,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> >   			},
> >   		},
> > +		.irq_config = {
> > +			.irq1 = {
> > +				.addr = 0x0d,
> > +				.mask = BIT(3),
> > +			},
> > +			.irq2 = {
> > +				.addr = 0x0e,
> > +				.mask = BIT(3),
> > +			},
> > +			.lir = {
> > +				.addr = 0x56,
> > +				.mask = BIT(0),
> > +			},
> > +			.clear_on_read = {
> > +				.addr = 0x56,
> > +				.mask = BIT(6),
> > +			},
> > +			.irq1_func = {
> > +				.addr = 0x5e,
> > +				.mask = BIT(5),
> > +			},
> > +			.irq2_func = {
> > +				.addr = 0x5f,
> > +				.mask = BIT(5),
> > +			},
> > +		},
> >   		.batch = {
> >   			[ST_LSM6DSX_ID_ACC] = {
> >   				.addr = 0x09,
> > @@ -792,14 +867,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.mask = GENMASK(7, 4),
> >   			},
> >   		},
> > -		.lir = {
> > -			.addr = 0x56,
> > -			.mask = BIT(0),
> > -		},
> > -		.clear_on_read = {
> > -			.addr = 0x56,
> > -			.mask = BIT(6),
> > -		},
> >   		.fifo_ops = {
> >   			.update_fifo = st_lsm6dsx_update_fifo,
> >   			.read_fifo = st_lsm6dsx_read_tagged_fifo,
> > @@ -841,11 +908,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   	},
> >   	{
> >   		.wai = 0x6b,
> > -		.int1_addr = 0x0d,
> > -		.int2_addr = 0x0e,
> > -		.int1_func_addr = 0x5e,
> > -		.int2_func_addr = 0x5f,
> > -		.int_func_mask = BIT(5),
> >   		.reset_addr = 0x12,
> >   		.max_fifo_size = 512,
> >   		.id = {
> > @@ -915,6 +977,32 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.fs_avl[3] = { IIO_DEGREE_TO_RAD(70000), 0x3 },
> >   			},
> >   		},
> > +		.irq_config = {
> > +			.irq1 = {
> > +				.addr = 0x0d,
> > +				.mask = BIT(3),
> > +			},
> > +			.irq2 = {
> > +				.addr = 0x0e,
> > +				.mask = BIT(3),
> > +			},
> > +			.lir = {
> > +				.addr = 0x56,
> > +				.mask = BIT(0),
> > +			},
> > +			.clear_on_read = {
> > +				.addr = 0x56,
> > +				.mask = BIT(6),
> > +			},
> > +			.irq1_func = {
> > +				.addr = 0x5e,
> > +				.mask = BIT(5),
> > +			},
> > +			.irq2_func = {
> > +				.addr = 0x5f,
> > +				.mask = BIT(5),
> > +			},
> > +		},
> >   		.batch = {
> >   			[ST_LSM6DSX_ID_ACC] = {
> >   				.addr = 0x09,
> > @@ -925,14 +1013,6 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> >   				.mask = GENMASK(7, 4),
> >   			},
> >   		},
> > -		.lir = {
> > -			.addr = 0x56,
> > -			.mask = BIT(0),
> > -		},
> > -		.clear_on_read = {
> > -			.addr = 0x56,
> > -			.mask = BIT(6),
> > -		},
> >   		.fifo_ops = {
> >   			.update_fifo = st_lsm6dsx_update_fifo,
> >   			.read_fifo = st_lsm6dsx_read_tagged_fifo,
> > @@ -1281,7 +1361,7 @@ static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
> >   	int err;
> >   	u8 enable = 0;
> >   
> > -	if (!hw->settings->int1_func_addr)
> > +	if (!hw->settings->irq_config.irq1_func.addr)
> >   		return -ENOTSUPP;
> >   
> >   	enable = state ? hw->settings->event_settings.enable_reg.mask : 0;
> > @@ -1293,12 +1373,11 @@ static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
> >   	if (err < 0)
> >   		return err;
> >   
> > -	enable = state ? hw->irq_routing.mask : 0;
> > +	enable = state ? hw->irq_routing->mask : 0;
> >   
> >   	/* Enable wakeup interrupt */
> > -	return regmap_update_bits(hw->regmap, hw->irq_routing.addr,
> > -				  hw->irq_routing.mask,
> > -				  enable);
> > +	return regmap_update_bits(hw->regmap, hw->irq_routing->addr,
> > +				  hw->irq_routing->mask, enable);
> >   }
> >   
> >   static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
> > @@ -1527,7 +1606,9 @@ static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
> >   	return of_property_read_u32(np, "st,drdy-int-pin", drdy_pin);
> >   }
> >   
> > -static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
> > +static int
> > +st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
> > +			const struct st_lsm6dsx_reg **drdy_reg)
> >   {
> >   	int err = 0, drdy_pin;
> >   
> > @@ -1541,14 +1622,12 @@ static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
> >   
> >   	switch (drdy_pin) {
> >   	case 1:
> > -		*drdy_reg = hw->settings->int1_addr;
> > -		hw->irq_routing.addr = hw->settings->int1_func_addr;
> > -		hw->irq_routing.mask = hw->settings->int_func_mask;
> > +		hw->irq_routing = &hw->settings->irq_config.irq1_func;
> > +		*drdy_reg = &hw->settings->irq_config.irq1;
> >   		break;
> >   	case 2:
> > -		*drdy_reg = hw->settings->int2_addr;
> > -		hw->irq_routing.addr = hw->settings->int2_func_addr;
> > -		hw->irq_routing.mask = hw->settings->int_func_mask;
> > +		hw->irq_routing = &hw->settings->irq_config.irq2_func;
> > +		*drdy_reg = &hw->settings->irq_config.irq2;
> >   		break;
> >   	default:
> >   		dev_err(hw->dev, "unsupported data ready pin\n");
> > @@ -1644,7 +1723,7 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
> >   
> >   static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> >   {
> > -	u8 drdy_int_reg;
> > +	const struct st_lsm6dsx_reg *reg;
> >   	int err;
> >   
> >   	/* device sw reset */
> > @@ -1673,35 +1752,29 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> >   		return err;
> >   
> >   	/* enable FIFO watermak interrupt */
> > -	err = st_lsm6dsx_get_drdy_reg(hw, &drdy_int_reg);
> > +	err = st_lsm6dsx_get_drdy_reg(hw, &reg);
> >   	if (err < 0)
> >   		return err;
> >   
> > -	err = regmap_update_bits(hw->regmap, drdy_int_reg,
> > -				 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK,
> > -				 FIELD_PREP(ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK,
> > -					    1));
> > +	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > +				 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
> >   	if (err < 0)
> >   		return err;
> >   
> >   	/* enable Latched interrupts for device events */
> > -	if (hw->settings->lir.addr) {
> > -		unsigned int data;
> > -
> > -		data = ST_LSM6DSX_SHIFT_VAL(1, hw->settings->lir.mask);
> > -		err = regmap_update_bits(hw->regmap, hw->settings->lir.addr,
> > -					 hw->settings->lir.mask, data);
> > +	if (hw->settings->irq_config.lir.addr) {
> > +		reg = &hw->settings->irq_config.lir;
> > +		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > +					 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
> >   		if (err < 0)
> >   			return err;
> >   
> >   		/* enable clear on read for latched interrupts */
> > -		if (hw->settings->clear_on_read.addr) {
> > -			data = ST_LSM6DSX_SHIFT_VAL(1,
> > -					hw->settings->clear_on_read.mask);
> > +		if (hw->settings->irq_config.clear_on_read.addr) {
> > +			reg = &hw->settings->irq_config.clear_on_read;
> >   			err = regmap_update_bits(hw->regmap,
> > -					hw->settings->clear_on_read.addr,
> > -					hw->settings->clear_on_read.mask,
> > -					data);
> > +					reg->addr, reg->mask,
> > +					ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
> >   			if (err < 0)
> >   				return err;
> >   		}
> >   


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 04/13] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported
  2019-10-06 13:21 ` [PATCH 04/13] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported Lorenzo Bianconi
@ 2019-10-12 12:14   ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:14 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:21:58 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Move active low and open drain register definitions in hw_settings
> register map since not all supported sensors (e.g lsm9ds1) rely on the
> same definitions
> 
> Fixes: 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied on the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  2 +
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 79 ++++++++++++++++----
>  2 files changed, 67 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index 873ec3b8fd69..8e002a51595e 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -268,6 +268,8 @@ struct st_lsm6dsx_settings {
>  		struct st_lsm6dsx_reg irq2_func;
>  		struct st_lsm6dsx_reg lir;
>  		struct st_lsm6dsx_reg clear_on_read;
> +		struct st_lsm6dsx_reg hla;
> +		struct st_lsm6dsx_reg od;
>  	} irq_config;
>  	struct st_lsm6dsx_odr_table_entry odr_table[2];
>  	struct st_lsm6dsx_fs_table_entry fs_table[2];
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 23d67caa24ed..a598cc8e9343 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -67,11 +67,6 @@
>  #define ST_LSM6DSX_REG_BDU_ADDR			0x12
>  #define ST_LSM6DSX_REG_BDU_MASK			BIT(6)
>  
> -#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)
> -
>  static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
>  	ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
>  	ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL, 0x2a, IIO_MOD_Y, 1),
> @@ -170,6 +165,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.addr = 0x0d,
>  				.mask = BIT(3),
>  			},
> +			.hla = {
> +				.addr = 0x22,
> +				.mask = BIT(5),
> +			},
> +			.od = {
> +				.addr = 0x22,
> +				.mask = BIT(4),
> +			},
>  		},
>  	},
>  	{
> @@ -261,6 +264,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.addr = 0x5f,
>  				.mask = BIT(5),
>  			},
> +			.hla = {
> +				.addr = 0x12,
> +				.mask = BIT(5),
> +			},
> +			.od = {
> +				.addr = 0x12,
> +				.mask = BIT(4),
> +			},
>  		},
>  		.decimator = {
>  			[ST_LSM6DSX_ID_ACC] = {
> @@ -404,6 +415,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.addr = 0x5f,
>  				.mask = BIT(5),
>  			},
> +			.hla = {
> +				.addr = 0x12,
> +				.mask = BIT(5),
> +			},
> +			.od = {
> +				.addr = 0x12,
> +				.mask = BIT(4),
> +			},
>  		},
>  		.decimator = {
>  			[ST_LSM6DSX_ID_ACC] = {
> @@ -556,6 +575,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.addr = 0x5f,
>  				.mask = BIT(5),
>  			},
> +			.hla = {
> +				.addr = 0x12,
> +				.mask = BIT(5),
> +			},
> +			.od = {
> +				.addr = 0x12,
> +				.mask = BIT(4),
> +			},
>  		},
>  		.decimator = {
>  			[ST_LSM6DSX_ID_ACC] = {
> @@ -702,6 +729,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.addr = 0x56,
>  				.mask = BIT(6),
>  			},
> +			.hla = {
> +				.addr = 0x12,
> +				.mask = BIT(5),
> +			},
> +			.od = {
> +				.addr = 0x12,
> +				.mask = BIT(4),
> +			},
>  		},
>  		.batch = {
>  			[ST_LSM6DSX_ID_ACC] = {
> @@ -856,6 +891,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.addr = 0x5f,
>  				.mask = BIT(5),
>  			},
> +			.hla = {
> +				.addr = 0x12,
> +				.mask = BIT(5),
> +			},
> +			.od = {
> +				.addr = 0x12,
> +				.mask = BIT(4),
> +			},
>  		},
>  		.batch = {
>  			[ST_LSM6DSX_ID_ACC] = {
> @@ -1002,6 +1045,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.addr = 0x5f,
>  				.mask = BIT(5),
>  			},
> +			.hla = {
> +				.addr = 0x12,
> +				.mask = BIT(5),
> +			},
> +			.od = {
> +				.addr = 0x12,
> +				.mask = BIT(4),
> +			},
>  		},
>  		.batch = {
>  			[ST_LSM6DSX_ID_ACC] = {
> @@ -1900,8 +1951,9 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
>  
>  static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
>  {
> -	struct st_sensors_platform_data *pdata;
>  	struct device_node *np = hw->dev->of_node;
> +	struct st_sensors_platform_data *pdata;
> +	const struct st_lsm6dsx_reg *reg;
>  	unsigned long irq_type;
>  	bool irq_active_low;
>  	int err;
> @@ -1922,20 +1974,19 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
>  		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));
> +	reg = &hw->settings->irq_config.hla;
> +	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> +				 ST_LSM6DSX_SHIFT_VAL(irq_active_low,
> +						      reg->mask));
>  	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));
> +		reg = &hw->settings->irq_config.od;
> +		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> +					 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
>  		if (err < 0)
>  			return err;
>  


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 05/13] iio: imu: st_lsm6dsx: move bdu/boot and reset register info in hw_settings
  2019-10-06 13:21 ` [PATCH 05/13] iio: imu: st_lsm6dsx: move bdu/boot and reset register info in hw_settings Lorenzo Bianconi
@ 2019-10-12 12:19   ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:19 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:21:59 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Move bdu, boot and reset register definitions in hw_settings register
> map since not all supported sensors (e.g lsm9ds1) rely on the same
> definitions
> 
> Fixes: 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied.

Note that I'm applying this series to the togreg branch of iio.git simply
to avoid the complexity of trying to unwind what should go to stable
at this point and what should not.  Not sure what else we can do
with this driver as it is in a fairly large state of flux.

You may need to do backports by hand to cover 5.4.

Thanks,

Jonathan


> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |   8 +-
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 113 +++++++++++++++----
>  2 files changed, 99 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index 8e002a51595e..5692ea695f04 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -236,7 +236,9 @@ struct st_lsm6dsx_ext_dev_settings {
>  /**
>   * struct st_lsm6dsx_settings - ST IMU sensor settings
>   * @wai: Sensor WhoAmI default value.
> - * @reset_addr: register address for reset/reboot
> + * @reset: register address for reset.
> + * @boot: register address for boot.
> + * @bdu: register address for Block Data Update.
>   * @max_fifo_size: Sensor max fifo length in FIFO words.
>   * @id: List of hw id/device name supported by the driver configuration.
>   * @channels: IIO channels supported by the device.
> @@ -251,7 +253,9 @@ struct st_lsm6dsx_ext_dev_settings {
>   */
>  struct st_lsm6dsx_settings {
>  	u8 wai;
> -	u8 reset_addr;
> +	struct st_lsm6dsx_reg reset;
> +	struct st_lsm6dsx_reg boot;
> +	struct st_lsm6dsx_reg bdu;
>  	u16 max_fifo_size;
>  	struct {
>  		enum st_lsm6dsx_hw_id hw_id;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index a598cc8e9343..5df382b9d8f9 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -62,10 +62,6 @@
>  #include "st_lsm6dsx.h"
>  
>  #define ST_LSM6DSX_REG_WHOAMI_ADDR		0x0f
> -#define ST_LSM6DSX_REG_RESET_MASK		BIT(0)
> -#define ST_LSM6DSX_REG_BOOT_MASK		BIT(7)
> -#define ST_LSM6DSX_REG_BDU_ADDR			0x12
> -#define ST_LSM6DSX_REG_BDU_MASK			BIT(6)
>  
>  static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
>  	ST_LSM6DSX_CHANNEL_ACC(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
> @@ -91,7 +87,18 @@ static const struct iio_chan_spec st_lsm6ds0_gyro_channels[] = {
>  static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  	{
>  		.wai = 0x68,
> -		.reset_addr = 0x22,
> +		.reset = {
> +			.addr = 0x22,
> +			.mask = BIT(0),
> +		},
> +		.boot = {
> +			.addr = 0x22,
> +			.mask = BIT(7),
> +		},
> +		.bdu = {
> +			.addr = 0x22,
> +			.mask = BIT(6),
> +		},
>  		.max_fifo_size = 32,
>  		.id = {
>  			{
> @@ -177,7 +184,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  	},
>  	{
>  		.wai = 0x69,
> -		.reset_addr = 0x12,
> +		.reset = {
> +			.addr = 0x12,
> +			.mask = BIT(0),
> +		},
> +		.boot = {
> +			.addr = 0x12,
> +			.mask = BIT(7),
> +		},
> +		.bdu = {
> +			.addr = 0x12,
> +			.mask = BIT(6),
> +		},
>  		.max_fifo_size = 1365,
>  		.id = {
>  			{
> @@ -328,7 +346,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  	},
>  	{
>  		.wai = 0x69,
> -		.reset_addr = 0x12,
> +		.reset = {
> +			.addr = 0x12,
> +			.mask = BIT(0),
> +		},
> +		.boot = {
> +			.addr = 0x12,
> +			.mask = BIT(7),
> +		},
> +		.bdu = {
> +			.addr = 0x12,
> +			.mask = BIT(6),
> +		},
>  		.max_fifo_size = 682,
>  		.id = {
>  			{
> @@ -479,7 +508,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  	},
>  	{
>  		.wai = 0x6a,
> -		.reset_addr = 0x12,
> +		.reset = {
> +			.addr = 0x12,
> +			.mask = BIT(0),
> +		},
> +		.boot = {
> +			.addr = 0x12,
> +			.mask = BIT(7),
> +		},
> +		.bdu = {
> +			.addr = 0x12,
> +			.mask = BIT(6),
> +		},
>  		.max_fifo_size = 682,
>  		.id = {
>  			{
> @@ -643,7 +683,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  	},
>  	{
>  		.wai = 0x6c,
> -		.reset_addr = 0x12,
> +		.reset = {
> +			.addr = 0x12,
> +			.mask = BIT(0),
> +		},
> +		.boot = {
> +			.addr = 0x12,
> +			.mask = BIT(7),
> +		},
> +		.bdu = {
> +			.addr = 0x12,
> +			.mask = BIT(6),
> +		},
>  		.max_fifo_size = 512,
>  		.id = {
>  			{
> @@ -800,7 +851,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  	},
>  	{
>  		.wai = 0x6b,
> -		.reset_addr = 0x12,
> +		.reset = {
> +			.addr = 0x12,
> +			.mask = BIT(0),
> +		},
> +		.boot = {
> +			.addr = 0x12,
> +			.mask = BIT(7),
> +		},
> +		.bdu = {
> +			.addr = 0x12,
> +			.mask = BIT(6),
> +		},
>  		.max_fifo_size = 512,
>  		.id = {
>  			{
> @@ -951,7 +1013,18 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  	},
>  	{
>  		.wai = 0x6b,
> -		.reset_addr = 0x12,
> +		.reset = {
> +			.addr = 0x12,
> +			.mask = BIT(0),
> +		},
> +		.boot = {
> +			.addr = 0x12,
> +			.mask = BIT(7),
> +		},
> +		.bdu = {
> +			.addr = 0x12,
> +			.mask = BIT(6),
> +		},
>  		.max_fifo_size = 512,
>  		.id = {
>  			{
> @@ -1778,27 +1851,27 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
>  	int err;
>  
>  	/* device sw reset */
> -	err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
> -				 ST_LSM6DSX_REG_RESET_MASK,
> -				 FIELD_PREP(ST_LSM6DSX_REG_RESET_MASK, 1));
> +	reg = &hw->settings->reset;
> +	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> +				 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
>  	if (err < 0)
>  		return err;
>  
>  	msleep(50);
>  
>  	/* reload trimming parameter */
> -	err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
> -				 ST_LSM6DSX_REG_BOOT_MASK,
> -				 FIELD_PREP(ST_LSM6DSX_REG_BOOT_MASK, 1));
> +	reg = &hw->settings->boot;
> +	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> +				 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
>  	if (err < 0)
>  		return err;
>  
>  	msleep(50);
>  
>  	/* enable Block Data Update */
> -	err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_BDU_ADDR,
> -				 ST_LSM6DSX_REG_BDU_MASK,
> -				 FIELD_PREP(ST_LSM6DSX_REG_BDU_MASK, 1));
> +	reg = &hw->settings->bdu;
> +	err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> +				 ST_LSM6DSX_SHIFT_VAL(1, reg->mask));
>  	if (err < 0)
>  		return err;
>  


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 00/13] various st_lsm6dsx fixes and missing bits
  2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
                   ` (12 preceding siblings ...)
  2019-10-06 13:22 ` [PATCH 13/13] iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO Lorenzo Bianconi
@ 2019-10-12 12:20 ` Jonathan Cameron
  2019-10-12 12:26   ` Lorenzo Bianconi
  13 siblings, 1 reply; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:20 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:21:54 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> This series fixes some corner cases introduced with LSM9DS1 support and with
> the one that has added wake-up event support. In particular it fixes a crash
> due to missing HW FIFO support for LSM9DS1.
> Moreover I introduced the missing wake-up event support for LSM6DSO/LSM6DSOX
> sensor
> Add missing dts documentation for wake-up event and the capability to enable it
> through platformdata.
> Code cleanup.

Hmm. This is going to be very messy.  In theory quite a few of these apply
to stuff in 5.4 but I assume won't cleanly apply given other changes.  You
may want to think about doing backports of the important parts to 5.4.

I'll apply the lot for 5.5.

Thanks,

Jonathan

> 
> Lorenzo Bianconi (13):
>   iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in
>     st_lsm6dsx_report_motion_event
>   iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
>   iio: imu: st_lsm6dsx: move irq related definitions in irq_config
>   iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not
>     supported
>   iio: imu: st_lsm6dsx: move bdu/boot and reset register info in
>     hw_settings
>   iio: imu: st_lsm6dsx: always check enable_reg in
>     st_lsm6dsx_event_setup
>   iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked
>     configuring events
>   iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config
>   iio: imu: st_lsm6dsx: fix checkpatch warning
>   iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data
>   iio: imu: st_lsm6dsx: add missing kernel documenation
>   dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source
>     property
>   iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO
> 
>  .../bindings/iio/imu/st_lsm6dsx.txt           |   1 +
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h       |  35 +-
>  .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    |   3 +
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c  | 588 ++++++++++++------
>  .../linux/platform_data/st_sensors_pdata.h    |   2 +
>  5 files changed, 440 insertions(+), 189 deletions(-)
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup
  2019-10-07  7:55   ` Sean Nyekjaer
@ 2019-10-12 12:21     ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:21 UTC (permalink / raw)
  To: Sean Nyekjaer
  Cc: Lorenzo Bianconi, linux-iio, martin, rjones, lorenzo.bianconi,
	devicetree

On Mon, 7 Oct 2019 09:55:14 +0200
Sean Nyekjaer <sean@geanix.com> wrote:

> On 06/10/2019 15.22, Lorenzo Bianconi wrote:
> > Check if enable_reg of event_settings data structure is defined before
> > writing on it
> > 
> > Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>  
> Tested-by: Sean Nyekjaer <sean@geanix.com>
Applied
> > ---
> >   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 23 ++++++++++----------
> >   1 file changed, 11 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > index 5df382b9d8f9..7e9e1ef81742 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > @@ -1482,26 +1482,25 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
> >   
> >   static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
> >   {
> > +	const struct st_lsm6dsx_reg *reg;
> >   	int err;
> > -	u8 enable = 0;
> >   
> >   	if (!hw->settings->irq_config.irq1_func.addr)
> >   		return -ENOTSUPP;
> >   
> > -	enable = state ? hw->settings->event_settings.enable_reg.mask : 0;
> > -
> > -	err = regmap_update_bits(hw->regmap,
> > -				 hw->settings->event_settings.enable_reg.addr,
> > -				 hw->settings->event_settings.enable_reg.mask,
> > -				 enable);
> > -	if (err < 0)
> > -		return err;
> > -
> > -	enable = state ? hw->irq_routing->mask : 0;
> > +	reg = &hw->settings->event_settings.enable_reg;
> > +	if (reg->addr) {
> > +		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > +					 ST_LSM6DSX_SHIFT_VAL(state, reg->mask));
> > +		if (err < 0)
> > +			return err;
> > +	}
> >   
> >   	/* Enable wakeup interrupt */
> >   	return regmap_update_bits(hw->regmap, hw->irq_routing->addr,
> > -				  hw->irq_routing->mask, enable);
> > +				  hw->irq_routing->mask,
> > +				  ST_LSM6DSX_SHIFT_VAL(state,
> > +					hw->irq_routing->mask));
> >   }
> >   
> >   static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
> >   


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 07/13] iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked configuring events
  2019-10-06 13:22 ` [PATCH 07/13] iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked configuring events Lorenzo Bianconi
@ 2019-10-12 12:22   ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:22 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:22:01 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Rely on st_lsm6dsx_update_bits_locked in st_lsm6dsx_write_event and
> st_lsm6dsx_event_setup routines since they can run concurrently with
> sensor hub configuration
> 
> Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 25 +++++++++++---------
>  1 file changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 7e9e1ef81742..023646762b4a 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1483,6 +1483,7 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
>  static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
>  {
>  	const struct st_lsm6dsx_reg *reg;
> +	unsigned int data;
>  	int err;
>  
>  	if (!hw->settings->irq_config.irq1_func.addr)
> @@ -1490,17 +1491,17 @@ static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
>  
>  	reg = &hw->settings->event_settings.enable_reg;
>  	if (reg->addr) {
> -		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> -					 ST_LSM6DSX_SHIFT_VAL(state, reg->mask));
> +		data = ST_LSM6DSX_SHIFT_VAL(state, reg->mask);
> +		err = st_lsm6dsx_update_bits_locked(hw, reg->addr,
> +						    reg->mask, data);
>  		if (err < 0)
>  			return err;
>  	}
>  
>  	/* Enable wakeup interrupt */
> -	return regmap_update_bits(hw->regmap, hw->irq_routing->addr,
> -				  hw->irq_routing->mask,
> -				  ST_LSM6DSX_SHIFT_VAL(state,
> -					hw->irq_routing->mask));
> +	data = ST_LSM6DSX_SHIFT_VAL(state, hw->irq_routing->mask);
> +	return st_lsm6dsx_update_bits_locked(hw, hw->irq_routing->addr,
> +					     hw->irq_routing->mask, data);
>  }
>  
>  static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
> @@ -1531,6 +1532,8 @@ static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
>  {
>  	struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
>  	struct st_lsm6dsx_hw *hw = sensor->hw;
> +	const struct st_lsm6dsx_reg *reg;
> +	unsigned int data;
>  	int err;
>  
>  	if (type != IIO_EV_TYPE_THRESH)
> @@ -1539,11 +1542,11 @@ static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
>  	if (val < 0 || val > 31)
>  		return -EINVAL;
>  
> -	err = regmap_update_bits(hw->regmap,
> -				 hw->settings->event_settings.wakeup_reg.addr,
> -				 hw->settings->event_settings.wakeup_reg.mask,
> -				 val);
> -	if (err)
> +	reg = &hw->settings->event_settings.wakeup_reg;
> +	data = ST_LSM6DSX_SHIFT_VAL(val, reg->mask);
> +	err = st_lsm6dsx_update_bits_locked(hw, reg->addr,
> +					    reg->mask, data);
> +	if (err < 0)
>  		return -EINVAL;
>  
>  	hw->event_threshold = val;


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 08/13] iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config
  2019-10-06 13:22 ` [PATCH 08/13] iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config Lorenzo Bianconi
@ 2019-10-12 12:23   ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:23 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:22:02 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Always grub conf mutex in st_lsm6dsx_write_event_config since it can run
> concurrently with FIFO configuration
> 
> Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
applied.

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 023646762b4a..04231710ab9c 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1604,7 +1604,9 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
>  	if (err < 0)
>  		return err;
>  
> +	mutex_lock(&hw->conf_lock);
>  	err = st_lsm6dsx_sensor_set_enable(sensor, state);
> +	mutex_unlock(&hw->conf_lock);
>  	if (err < 0)
>  		return err;
>  


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 09/13] iio: imu: st_lsm6dsx: fix checkpatch warning
  2019-10-06 13:22 ` [PATCH 09/13] iio: imu: st_lsm6dsx: fix checkpatch warning Lorenzo Bianconi
@ 2019-10-12 12:24   ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:24 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:22:03 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Fix following checkpatch warnings:
> 
> CHECK: Alignment should match open parenthesis
> +static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
> +				   const struct iio_chan_spec *chan,
> 
> CHECK: Alignment should match open parenthesis
> +static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
> +				    const struct iio_chan_spec *chan,
> 
> CHECK: Alignment should match open parenthesis
> +static int st_lsm6dsx_read_event_config(struct iio_dev *iio_dev,
> +					  const struct iio_chan_spec *chan,
> 
> CHECK: Alignment should match open parenthesis
> +static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
> +					   const struct iio_chan_spec *chan,
> 
> WARNING: line over 80 characters
> +	if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source"))
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied.
> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 35 +++++++++++---------
>  1 file changed, 19 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 04231710ab9c..b0623b837abd 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1523,12 +1523,13 @@ static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
>  	return IIO_VAL_INT;
>  }
>  
> -static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
> -				    const struct iio_chan_spec *chan,
> -				    enum iio_event_type type,
> -				    enum iio_event_direction dir,
> -				    enum iio_event_info info,
> -				    int val, int val2)
> +static int
> +st_lsm6dsx_write_event(struct iio_dev *iio_dev,
> +		       const struct iio_chan_spec *chan,
> +		       enum iio_event_type type,
> +		       enum iio_event_direction dir,
> +		       enum iio_event_info info,
> +		       int val, int val2)
>  {
>  	struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
>  	struct st_lsm6dsx_hw *hw = sensor->hw;
> @@ -1554,10 +1555,11 @@ static int st_lsm6dsx_write_event(struct iio_dev *iio_dev,
>  	return 0;
>  }
>  
> -static int st_lsm6dsx_read_event_config(struct iio_dev *iio_dev,
> -					  const struct iio_chan_spec *chan,
> -					  enum iio_event_type type,
> -					  enum iio_event_direction dir)
> +static int
> +st_lsm6dsx_read_event_config(struct iio_dev *iio_dev,
> +			     const struct iio_chan_spec *chan,
> +			     enum iio_event_type type,
> +			     enum iio_event_direction dir)
>  {
>  	struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
>  	struct st_lsm6dsx_hw *hw = sensor->hw;
> @@ -1568,11 +1570,11 @@ static int st_lsm6dsx_read_event_config(struct iio_dev *iio_dev,
>  	return !!(hw->enable_event & BIT(chan->channel2));
>  }
>  
> -static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
> -					   const struct iio_chan_spec *chan,
> -					   enum iio_event_type type,
> -					   enum iio_event_direction dir,
> -					   int state)
> +static int
> +st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
> +			      const struct iio_chan_spec *chan,
> +			      enum iio_event_type type,
> +			      enum iio_event_direction dir, int state)
>  {
>  	struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
>  	struct st_lsm6dsx_hw *hw = sensor->hw;
> @@ -2150,7 +2152,8 @@ 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"))
> +	if (dev->of_node &&
> +	    of_property_read_bool(dev->of_node, "wakeup-source"))
>  		device_init_wakeup(dev, true);
>  
>  	return 0;


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 10/13] iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data
  2019-10-06 13:22 ` [PATCH 10/13] iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data Lorenzo Bianconi
@ 2019-10-12 12:25   ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:25 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:22:04 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Add the possibility to enable/disable wakeup source through
> st_sensors_platform_data and not only through device tree
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
I'm going to assume you need this for something... In general
I'm not that keen on expanding platform data support.

Applied,

Thanks,

Jonathan

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c   | 6 ++++--
>  include/linux/platform_data/st_sensors_pdata.h | 2 ++
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index b0623b837abd..a2a0ac81e3d3 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -2089,7 +2089,9 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
>  int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
>  		     struct regmap *regmap)
>  {
> +	struct st_sensors_platform_data *pdata = dev->platform_data;
>  	const struct st_lsm6dsx_shub_settings *hub_settings;
> +	struct device_node *np = dev->of_node;
>  	struct st_lsm6dsx_hw *hw;
>  	const char *name = NULL;
>  	int i, err;
> @@ -2152,8 +2154,8 @@ 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"))
> +	if ((np && of_property_read_bool(np, "wakeup-source")) ||
> +	    (pdata && pdata->wakeup_source))
>  		device_init_wakeup(dev, true);
>  
>  	return 0;
> diff --git a/include/linux/platform_data/st_sensors_pdata.h b/include/linux/platform_data/st_sensors_pdata.h
> index 30929c22227d..e40b28ca892e 100644
> --- a/include/linux/platform_data/st_sensors_pdata.h
> +++ b/include/linux/platform_data/st_sensors_pdata.h
> @@ -18,12 +18,14 @@
>   * @open_drain: set the interrupt line to be open drain if possible.
>   * @spi_3wire: enable spi-3wire mode.
>   * @pullups: enable/disable i2c controller pullup resistors.
> + * @wakeup_source: enable/disable device as wakeup generator.
>   */
>  struct st_sensors_platform_data {
>  	u8 drdy_int_pin;
>  	bool open_drain;
>  	bool spi_3wire;
>  	bool pullups;
> +	bool wakeup_source;
>  };
>  
>  #endif /* ST_SENSORS_PDATA_H */


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 00/13] various st_lsm6dsx fixes and missing bits
  2019-10-12 12:20 ` [PATCH 00/13] various st_lsm6dsx fixes and missing bits Jonathan Cameron
@ 2019-10-12 12:26   ` Lorenzo Bianconi
  2019-10-12 13:26     ` Jonathan Cameron
  0 siblings, 1 reply; 34+ messages in thread
From: Lorenzo Bianconi @ 2019-10-12 12:26 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lorenzo Bianconi, linux-iio, Sean Nyekjaer, martin, Bobby Jones,
	Lorenzo Bianconi, devicetree

>
> On Sun,  6 Oct 2019 15:21:54 +0200
> Lorenzo Bianconi <lorenzo@kernel.org> wrote:
>
> > This series fixes some corner cases introduced with LSM9DS1 support and with
> > the one that has added wake-up event support. In particular it fixes a crash
> > due to missing HW FIFO support for LSM9DS1.
> > Moreover I introduced the missing wake-up event support for LSM6DSO/LSM6DSOX
> > sensor
> > Add missing dts documentation for wake-up event and the capability to enable it
> > through platformdata.
> > Code cleanup.
>
> Hmm. This is going to be very messy.  In theory quite a few of these apply
> to stuff in 5.4 but I assume won't cleanly apply given other changes.  You
> may want to think about doing backports of the important parts to 5.4.
>
> I'll apply the lot for 5.5.

AFAIU just LSM9DS1 support will go in 5.4 (correct? Sean's series will
go in 5.5) so I will backport just LSM9DS1 fixes to 5.4 (I guess 3-4
patches).

Regards,
Lorenzo

>
> Thanks,
>
> Jonathan
>
> >
> > Lorenzo Bianconi (13):
> >   iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in
> >     st_lsm6dsx_report_motion_event
> >   iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
> >   iio: imu: st_lsm6dsx: move irq related definitions in irq_config
> >   iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not
> >     supported
> >   iio: imu: st_lsm6dsx: move bdu/boot and reset register info in
> >     hw_settings
> >   iio: imu: st_lsm6dsx: always check enable_reg in
> >     st_lsm6dsx_event_setup
> >   iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked
> >     configuring events
> >   iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config
> >   iio: imu: st_lsm6dsx: fix checkpatch warning
> >   iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data
> >   iio: imu: st_lsm6dsx: add missing kernel documenation
> >   dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source
> >     property
> >   iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO
> >
> >  .../bindings/iio/imu/st_lsm6dsx.txt           |   1 +
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h       |  35 +-
> >  .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    |   3 +
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c  | 588 ++++++++++++------
> >  .../linux/platform_data/st_sensors_pdata.h    |   2 +
> >  5 files changed, 440 insertions(+), 189 deletions(-)
> >
>


-- 
UNIX is Sexy: who | grep -i blonde | talk; cd ~; wine; talk; touch;
unzip; touch; strip; gasp; finger; gasp; mount; fsck; more; yes; gasp;
umount; make clean; sleep

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation
  2019-10-07  7:56   ` Sean Nyekjaer
@ 2019-10-12 12:26     ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:26 UTC (permalink / raw)
  To: Sean Nyekjaer
  Cc: Lorenzo Bianconi, linux-iio, martin, rjones, lorenzo.bianconi,
	devicetree

On Mon, 7 Oct 2019 09:56:10 +0200
Sean Nyekjaer <sean@geanix.com> wrote:

> On 06/10/2019 15.22, Lorenzo Bianconi wrote:
> > Add missing kernel doc for st_lsm6dsx_hw data structure
> > 
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>  
> Reviewed-by: Sean Nyekjaer <sean@geanix.com>
Applied.

Thanks,

J
> > ---
> >   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 3 +++
> >   1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> > index 5692ea695f04..40532f99ba4b 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> > @@ -345,6 +345,9 @@ struct st_lsm6dsx_sensor {
> >    * @ts_sip: Total number of timestamp samples in a given pattern.
> >    * @sip: Total number of samples (acc/gyro/ts) in a given pattern.
> >    * @buff: Device read buffer.
> > + * @irq_routing: pointer to interrupt routing configuration.
> > + * @event_threshold: wakeup event threshold.
> > + * @enable_event: enabled event bitmask.
> >    * @iio_devs: Pointers to acc/gyro iio_dev instances.
> >    * @settings: Pointer to the specific sensor settings in use.
> >    */
> >   


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 13/13] iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO
  2019-10-06 13:22 ` [PATCH 13/13] iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO Lorenzo Bianconi
@ 2019-10-12 12:28   ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 12:28 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:22:07 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Add missing wake-up register info for LSM6DSO/LSM6DSOX sensor
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to poke at it.

Thanks,

Jonathan

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 25 +++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index a2a0ac81e3d3..876f59cedc8b 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -780,6 +780,14 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.addr = 0x56,
>  				.mask = BIT(6),
>  			},
> +			.irq1_func = {
> +				.addr = 0x5e,
> +				.mask = BIT(5),
> +			},
> +			.irq2_func = {
> +				.addr = 0x5f,
> +				.mask = BIT(5),
> +			},
>  			.hla = {
>  				.addr = 0x12,
>  				.mask = BIT(5),
> @@ -847,7 +855,22 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  			.slv0_addr = 0x15,
>  			.dw_slv0_addr = 0x21,
>  			.batch_en = BIT(3),
> -		}
> +		},
> +		.event_settings = {
> +			.enable_reg = {
> +				.addr = 0x58,
> +				.mask = BIT(7),
> +			},
> +			.wakeup_reg = {
> +				.addr = 0x5b,
> +				.mask = GENMASK(5, 0),
> +			},
> +			.wakeup_src_reg = 0x1b,
> +			.wakeup_src_status_mask = BIT(3),
> +			.wakeup_src_z_mask = BIT(0),
> +			.wakeup_src_y_mask = BIT(1),
> +			.wakeup_src_x_mask = BIT(2),
> +		},
>  	},
>  	{
>  		.wai = 0x6b,


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 00/13] various st_lsm6dsx fixes and missing bits
  2019-10-12 12:26   ` Lorenzo Bianconi
@ 2019-10-12 13:26     ` Jonathan Cameron
  0 siblings, 0 replies; 34+ messages in thread
From: Jonathan Cameron @ 2019-10-12 13:26 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Lorenzo Bianconi, linux-iio, Sean Nyekjaer, martin, Bobby Jones,
	Lorenzo Bianconi, devicetree

On Sat, 12 Oct 2019 14:26:24 +0200
Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> wrote:

> >
> > On Sun,  6 Oct 2019 15:21:54 +0200
> > Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> >  
> > > This series fixes some corner cases introduced with LSM9DS1 support and with
> > > the one that has added wake-up event support. In particular it fixes a crash
> > > due to missing HW FIFO support for LSM9DS1.
> > > Moreover I introduced the missing wake-up event support for LSM6DSO/LSM6DSOX
> > > sensor
> > > Add missing dts documentation for wake-up event and the capability to enable it
> > > through platformdata.
> > > Code cleanup.  
> >
> > Hmm. This is going to be very messy.  In theory quite a few of these apply
> > to stuff in 5.4 but I assume won't cleanly apply given other changes.  You
> > may want to think about doing backports of the important parts to 5.4.
> >
> > I'll apply the lot for 5.5.  
> 
> AFAIU just LSM9DS1 support will go in 5.4 (correct? Sean's series will
> go in 5.5) so I will backport just LSM9DS1 fixes to 5.4 (I guess 3-4
> patches).
> 
That is what I'd expect.

Thanks,

Jonathan

> Regards,
> Lorenzo
> 
> >
> > Thanks,
> >
> > Jonathan
> >  
> > >
> > > Lorenzo Bianconi (13):
> > >   iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in
> > >     st_lsm6dsx_report_motion_event
> > >   iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
> > >   iio: imu: st_lsm6dsx: move irq related definitions in irq_config
> > >   iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not
> > >     supported
> > >   iio: imu: st_lsm6dsx: move bdu/boot and reset register info in
> > >     hw_settings
> > >   iio: imu: st_lsm6dsx: always check enable_reg in
> > >     st_lsm6dsx_event_setup
> > >   iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked
> > >     configuring events
> > >   iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config
> > >   iio: imu: st_lsm6dsx: fix checkpatch warning
> > >   iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data
> > >   iio: imu: st_lsm6dsx: add missing kernel documenation
> > >   dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source
> > >     property
> > >   iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO
> > >
> > >  .../bindings/iio/imu/st_lsm6dsx.txt           |   1 +
> > >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h       |  35 +-
> > >  .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    |   3 +
> > >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c  | 588 ++++++++++++------
> > >  .../linux/platform_data/st_sensors_pdata.h    |   2 +
> > >  5 files changed, 440 insertions(+), 189 deletions(-)
> > >  
> >  
> 
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property
  2019-10-06 13:22 ` [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property Lorenzo Bianconi
  2019-10-07  7:56   ` Sean Nyekjaer
@ 2019-10-15 20:34   ` Rob Herring
  1 sibling, 0 replies; 34+ messages in thread
From: Rob Herring @ 2019-10-15 20:34 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: jic23, linux-iio, sean, martin, rjones, lorenzo.bianconi, devicetree

On Sun,  6 Oct 2019 15:22:06 +0200, Lorenzo Bianconi wrote:
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 1 +
>  1 file changed, 1 insertion(+)
> 

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2019-10-15 20:34 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
2019-10-06 13:21 ` [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event Lorenzo Bianconi
2019-10-07  7:54   ` Sean Nyekjaer
2019-10-12 12:08   ` Jonathan Cameron
2019-10-06 13:21 ` [PATCH 02/13] iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer Lorenzo Bianconi
2019-10-06 13:21 ` [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config Lorenzo Bianconi
2019-10-07  7:54   ` Sean Nyekjaer
2019-10-12 12:13     ` Jonathan Cameron
2019-10-06 13:21 ` [PATCH 04/13] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported Lorenzo Bianconi
2019-10-12 12:14   ` Jonathan Cameron
2019-10-06 13:21 ` [PATCH 05/13] iio: imu: st_lsm6dsx: move bdu/boot and reset register info in hw_settings Lorenzo Bianconi
2019-10-12 12:19   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup Lorenzo Bianconi
2019-10-07  7:55   ` Sean Nyekjaer
2019-10-12 12:21     ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 07/13] iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked configuring events Lorenzo Bianconi
2019-10-12 12:22   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 08/13] iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config Lorenzo Bianconi
2019-10-12 12:23   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 09/13] iio: imu: st_lsm6dsx: fix checkpatch warning Lorenzo Bianconi
2019-10-12 12:24   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 10/13] iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data Lorenzo Bianconi
2019-10-12 12:25   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation Lorenzo Bianconi
2019-10-07  7:56   ` Sean Nyekjaer
2019-10-12 12:26     ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property Lorenzo Bianconi
2019-10-07  7:56   ` Sean Nyekjaer
2019-10-15 20:34   ` Rob Herring
2019-10-06 13:22 ` [PATCH 13/13] iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO Lorenzo Bianconi
2019-10-12 12:28   ` Jonathan Cameron
2019-10-12 12:20 ` [PATCH 00/13] various st_lsm6dsx fixes and missing bits Jonathan Cameron
2019-10-12 12:26   ` Lorenzo Bianconi
2019-10-12 13:26     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).