various st_lsm6dsx fixes and missing bits
Subsystems (3)
Lorenzo Bianconi
maintainercover various st_lsm6dsx fixes and missing bits
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(-)
Signature · 1 line
2.21.0
Lorenzo Bianconi
maintainerPATCH 1/13 iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event
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
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 34 ++++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +20 -14
@@ -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)
Signature · 1 line
2.21.0
Re: [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event
Quoted 6 lines · Lorenzo Bianconi
Rely on
st_lsm6dsx_read_lockedinst_lsm6dsx_report_motion_eventsince it can run concurrently with sensor hub configuration. Move event related code inst_lsm6dsx_report_motion_eventFixes 1aabad1fb5e9 ("iio: imu: st_lsm6dsx: add motion report function and call from interrupt")Signed-off-by Lorenzo Bianconi <[email protected]>
Quoted 71 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 34 ++++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +20
-14@@ -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)
Jonathan Cameron
maintainerRe: [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event
In reply to Lorenzo BianconiQuoted 6 lines · On Sun, 6 Oct 2019 15:21:55 +0200 Lorenzo Bianconi <[email protected]> wrote:
Rely on
st_lsm6dsx_read_lockedinst_lsm6dsx_report_motion_eventsince it can run concurrently with sensor hub configuration. Move event related code inst_lsm6dsx_report_motion_eventFixes 1aabad1fb5e9 ("iio: imu: st_lsm6dsx: add motion report function and call from interrupt")Signed-off-by Lorenzo Bianconi <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 70 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 34 ++++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +20
-14@@ -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)
Lorenzo Bianconi
maintainerPATCH 2/13 iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
In reply to Lorenzo BianconiCheck 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
--- 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(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +3 -0
@@ -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);
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +3 -0
@@ -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);
Signature · 1 line
2.21.0
Lorenzo Bianconi
maintainerPATCH 3/13 iio: imu: st_lsm6dsx: move irq related definitions in irq_config
In reply to Lorenzo BianconiGroup 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.
--- 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(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +10 -12
@@ -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;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +169 -96
440 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config
Quoted 5 lines · Lorenzo Bianconi
Group irq related definition in
irq_configstructure inst_lsm6dsx_settings. This is a preliminary patch to move OpenDrain/Active low registers inst_lsm6dsx_settings.Signed-off-by Lorenzo Bianconi <[email protected]>
Quoted 543 lines
--- 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(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +10
-12@@ -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;drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +169
-96@@ -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, ®);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; }
Jonathan Cameron
maintainerRe: [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config
Quoted 7 lines · On Mon, 7 Oct 2019 09:54:55 +0200 Sean Nyekjaer <[email protected]> wrote:
Quoted 5 lines · Lorenzo Bianconi
Group irq related definition in
irq_configstructure inst_lsm6dsx_settings. This is a preliminary patch to move OpenDrain/Active low registers inst_lsm6dsx_settings.Signed-off-by Lorenzo Bianconi <[email protected]>Tested-by Sean Nyekjaer <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 543 lines
Quoted 543 lines
--- 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(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +10
-12@@ -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;drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +169
-96@@ -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, ®);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; }
Lorenzo Bianconi
maintainerPATCH 4/13 iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported
In reply to Lorenzo BianconiMove 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
--- 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(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +2 -0
@@ -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 ];
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +65 -14
146 lines not on this page · raw message
Signature · 1 line
2.21.0
Jonathan Cameron
maintainerRe: [PATCH 04/13] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported
Quoted 6 lines · On Sun, 6 Oct 2019 15:21:58 +0200 Lorenzo Bianconi <[email protected]> wrote:
Move active low and open drain register definitions in
hw_settingsregister map since not all supported sensors (e.g lsm9ds1) rely on the same definitionsFixes 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")Signed-off-by Lorenzo Bianconi <[email protected]>
Applied on the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 178 lines
--- 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(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +2
-0@@ -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 ];drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +65
-14@@ -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;
Lorenzo Bianconi
maintainerPATCH 5/13 iio: imu: st_lsm6dsx: move bdu/boot and reset register info in hw_settings
In reply to Lorenzo BianconiMove bdu, boot and reset register definitions in hw_settings register map since not all supported sensors (e.g lsm9ds1) rely on the same definitions
--- 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(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +6 -2
@@ -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;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +93 -20
179 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH 05/13] iio: imu: st_lsm6dsx: move bdu/boot and reset register info in hw_settings
Quoted 6 lines · On Sun, 6 Oct 2019 15:21:59 +0200 Lorenzo Bianconi <[email protected]> wrote:
Move bdu, boot and reset register definitions in
hw_settingsregister map since not all supported sensors (e.g lsm9ds1) rely on the same definitionsFixes 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")Signed-off-by Lorenzo Bianconi <[email protected]>
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
Quoted 223 lines
--- 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(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +6
-2@@ -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;drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +93
-20@@ -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;
Lorenzo Bianconi
maintainerPATCH 6/13 iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup
In reply to Lorenzo BianconiCheck if enable_reg of event_settings data structure is defined before writing on it
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +11 -12
@@ -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,
Signature · 1 line
2.21.0
Re: [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup
Quoted 5 lines · Lorenzo Bianconi
Check if
enable_regofevent_settingsdata structure is defined before writing on itFixes b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")Signed-off-by Lorenzo Bianconi <[email protected]>
Quoted 47 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +11
-12@@ -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,
Re: [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup
Quoted 7 lines · On Mon, 7 Oct 2019 09:55:14 +0200 Sean Nyekjaer <[email protected]> wrote:
Quoted 5 lines · Lorenzo Bianconi
Check if
enable_regofevent_settingsdata structure is defined before writing on itFixes b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")Signed-off-by Lorenzo Bianconi <[email protected]>Tested-by Sean Nyekjaer <[email protected]>
Applied
Quoted 47 lines
Quoted 47 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +11
-12@@ -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,
Lorenzo Bianconi
maintainerPATCH 7/13 iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked configuring events
In reply to Lorenzo BianconiRely 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
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 25 +++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +14 -11
@@ -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;
Signature · 1 line
2.21.0
Jonathan Cameron
maintainerRe: [PATCH 07/13] iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked configuring events
Quoted 6 lines · On Sun, 6 Oct 2019 15:22:01 +0200 Lorenzo Bianconi <[email protected]> wrote:
Rely on
st_lsm6dsx_update_bits_lockedinst_lsm6dsx_write_eventandst_lsm6dsx_event_setuproutines since they can run concurrently with sensor hub configurationFixes b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")Signed-off-by Lorenzo Bianconi <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 66 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 25 +++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +14
-11@@ -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;
Lorenzo Bianconi
maintainerPATCH 8/13 iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config
In reply to Lorenzo BianconiAlways grub conf mutex in st_lsm6dsx_write_event_config since it can run concurrently with FIFO configuration
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +2 -0
@@ -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;
Signature · 1 line
2.21.0
Re: [PATCH 08/13] iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config
Quoted 5 lines · On Sun, 6 Oct 2019 15:22:02 +0200 Lorenzo Bianconi <[email protected]> wrote:
Always grub conf mutex in
st_lsm6dsx_write_event_configsince it can run concurrently with FIFO configurationFixes b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")Signed-off-by Lorenzo Bianconi <[email protected]>
applied.
Quoted 18 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +2
-0@@ -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;
Lorenzo Bianconi
maintainerPATCH 9/13 iio: imu: st_lsm6dsx: fix checkpatch warning
In reply to Lorenzo BianconiFix 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"))
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 35 +++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +19 -16
@@ -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 ;
Signature · 1 line
2.21.0
Re: [PATCH 09/13] iio: imu: st_lsm6dsx: fix checkpatch warning
Quoted 21 lines · On Sun, 6 Oct 2019 15:22:03 +0200 Lorenzo Bianconi <[email protected]> wrote:
Fix following checkpatch warnings:
CHECK: Alignment should match open parenthesis
(quoted diff) +2
-0+static int st_lsm6dsx_read_event(struct iio_dev *iio_dev, + const struct iio_chan_spec *chan,CHECK: Alignment should match open parenthesis
(quoted diff) +2
-0+static int st_lsm6dsx_write_event(struct iio_dev *iio_dev, + const struct iio_chan_spec *chan,CHECK: Alignment should match open parenthesis
(quoted diff) +2
-0+static int st_lsm6dsx_read_event_config(struct iio_dev *iio_dev, + const struct iio_chan_spec *chan,CHECK: Alignment should match open parenthesis
(quoted diff) +2
-0+static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, + const struct iio_chan_spec *chan,WARNING: line over 80 characters
(quoted diff) +1
-0+ if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source"))
Quoted 1 line
Signed-off-by Lorenzo Bianconi <[email protected]>
Applied.
Quoted 71 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 35 +++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +19
-16@@ -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 ;
Lorenzo Bianconi
maintainerPATCH 10/13 iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data
In reply to Lorenzo BianconiAdd the possibility to enable/disable wakeup source through st_sensors_platform_data and not only through device tree
--- 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(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4 -2
@@ -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 ;
include/linux/platform_data/st_sensors_pdata.h +2 -0
@@ -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 */
Signature · 1 line
2.21.0
Re: [PATCH 10/13] iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data
Quoted 4 lines · On Sun, 6 Oct 2019 15:22:04 +0200 Lorenzo Bianconi <[email protected]> wrote:
Add the possibility to enable/disable wakeup source through
st_sensors_platform_dataand not only through device treeSigned-off-by Lorenzo Bianconi <[email protected]>
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
Quoted 49 lines
--- 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(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4
-2@@ -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 ;include/linux/platform_data/st_sensors_pdata.h +2
-0@@ -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 */
Lorenzo Bianconi
maintainerPATCH 11/13 iio: imu: st_lsm6dsx: add missing kernel documenation
In reply to Lorenzo BianconiAdd missing kernel doc for st_lsm6dsx_hw data structure
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +3 -0
@@ -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. */
Signature · 1 line
2.21.0
Re: [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation
Quoted 3 lines · Lorenzo Bianconi
Add missing kernel doc for
st_lsm6dsx_hwdata structureSigned-off-by Lorenzo Bianconi <[email protected]>
Quoted 19 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 3 +++ 1 file changed, 3 insertions(+)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +3
-0@@ -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. */
Re: [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation
Quoted 5 lines · On Mon, 7 Oct 2019 09:56:10 +0200 Sean Nyekjaer <[email protected]> wrote:
Quoted 3 lines · Lorenzo Bianconi
Add missing kernel doc for
st_lsm6dsx_hwdata structureSigned-off-by Lorenzo Bianconi <[email protected]>Reviewed-by Sean Nyekjaer <[email protected]>
Applied.
Thanks,
J
Quoted 19 lines
Quoted 19 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 3 +++ 1 file changed, 3 insertions(+)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +3
-0@@ -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. */
Lorenzo Bianconi
maintainerPATCH 12/13 dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property
In reply to Lorenzo Bianconi--- Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt +1 -0
@@ -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.
Signature · 1 line
2.21.0
Re: [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property
Quoted 1 line · Lorenzo Bianconi
Signed-off-by Lorenzo Bianconi <[email protected]>
Quoted 17 lines
--- Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt +1
-0@@ -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.
Re: [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property
In reply to Lorenzo BianconiQuoted 5 lines · Lorenzo Bianconi
Signed-off-by Lorenzo Bianconi <[email protected]>--- Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 1 + 1 file changed, 1 insertion(+)
Lorenzo Bianconi
maintainerPATCH 13/13 iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO
In reply to Lorenzo BianconiAdd missing wake-up register info for LSM6DSO/LSM6DSOX sensor
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +24 -1
@@ -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,
Signature · 1 line
2.21.0
Jonathan Cameron
maintainerRe: [PATCH 13/13] iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO
Quoted 3 lines · On Sun, 6 Oct 2019 15:22:07 +0200 Lorenzo Bianconi <[email protected]> wrote:
Add missing wake-up register info for LSM6DSO/LSM6DSOX sensor
Signed-off-by Lorenzo Bianconi <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at it.
Thanks,
Jonathan
Quoted 47 lines
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +24
-1@@ -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,
Jonathan Cameron
maintainerQuoted 8 lines · On Sun, 6 Oct 2019 15:21:54 +0200 Lorenzo Bianconi <[email protected]> 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
Quoted 29 lines
Lorenzo Bianconi (13):
iio: imu:st_lsm6dsx: usest_lsm6dsx_read_lockedin
st_lsm6dsx_report_motion_event
iio: imu:st_lsm6dsx: add sanity check forread_fifopointer
iio: imu:st_lsm6dsx: move irq related definitions inirq_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 checkenable_regin
st_lsm6dsx_event_setup
iio: imu:st_lsm6dsx: rely onst_lsm6dsx_update_bits_locked
configuring events
iio: imu:st_lsm6dsx: grab conf mutex inst_lsm6dsx_write_event_config
iio: imu:st_lsm6dsx: fix checkpatch warning
iio: imu:st_lsm6dsx: addwakeup_sourceinst_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(-)
Quoted 13 lines
Quoted 8 lines · On Sun, 6 Oct 2019 15:21:54 +0200 Lorenzo Bianconi <[email protected]> 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.
Quoted 5 lines
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
Quoted 35 lines
Thanks,
Jonathan
Quoted 29 lines
Lorenzo Bianconi (13):
iio: imu:st_lsm6dsx: usest_lsm6dsx_read_lockedin
st_lsm6dsx_report_motion_event
iio: imu:st_lsm6dsx: add sanity check forread_fifopointer
iio: imu:st_lsm6dsx: move irq related definitions inirq_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 checkenable_regin
st_lsm6dsx_event_setup
iio: imu:st_lsm6dsx: rely onst_lsm6dsx_update_bits_locked
configuring events
iio: imu:st_lsm6dsx: grab conf mutex inst_lsm6dsx_write_event_config
iio: imu:st_lsm6dsx: fix checkpatch warning
iio: imu:st_lsm6dsx: addwakeup_sourceinst_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(-)
Signature · 3 lines
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
Jonathan Cameron
maintainerQuoted 17 lines · On Sat, 12 Oct 2019 14:26:24 +0200 Lorenzo Bianconi…
Quoted 17 lines
Quoted 8 lines · On Sun, 6 Oct 2019 15:21:54 +0200 Lorenzo Bianconi <[email protected]> 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.
Quoted 6 lines
Quoted 1 line
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
Quoted 40 lines
Regards,
LorenzoQuoted 35 lines
Thanks,
Jonathan
Quoted 29 lines
Lorenzo Bianconi (13):
iio: imu:st_lsm6dsx: usest_lsm6dsx_read_lockedin
st_lsm6dsx_report_motion_event
iio: imu:st_lsm6dsx: add sanity check forread_fifopointer
iio: imu:st_lsm6dsx: move irq related definitions inirq_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 checkenable_regin
st_lsm6dsx_event_setup
iio: imu:st_lsm6dsx: rely onst_lsm6dsx_update_bits_locked
configuring events
iio: imu:st_lsm6dsx: grab conf mutex inst_lsm6dsx_write_event_config
iio: imu:st_lsm6dsx: fix checkpatch warning
iio: imu:st_lsm6dsx: addwakeup_sourceinst_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(-)