Factorize timestamp module
Subsystems (3)
cover Factorize timestamp module
From: Jean-Baptiste Maneyrol <[email protected]>
The purpose if this series is to make timestamping from inv_icm42600 driver an independent module and use it for both inv_icm42600 and inv_mpu6050 drivers.
Create a new inv_sensors_timestamp common module based on inv_icm42600 driver and use it in the 2 drivers.
WARNING: this patch requires following commit in fixes-togreg bbaae0c79ebd ("iio: imu: inv_icm42600: fix timestamp reset")
Jean-Baptiste Maneyrol (4):
iio: imu: inv_icm42600: make timestamp module chip independent
iio: move inv_icm42600 timestamp module in common
iio: make invensense timestamp module generic
iio: imu: inv_mpu6050: use the common inv_sensors timestamp module
drivers/iio/common/Kconfig | 1 +
drivers/iio/common/Makefile | 1 +
drivers/iio/common/inv_sensors/Kconfig | 7 ++
drivers/iio/common/inv_sensors/Makefile | 6 +
.../inv_sensors/inv_sensors_timestamp.c} | 105 +++++++++---------
drivers/iio/imu/inv_icm42600/Kconfig | 1 +
drivers/iio/imu/inv_icm42600/Makefile | 1 -
.../iio/imu/inv_icm42600/inv_icm42600_accel.c | 32 ++++--
.../imu/inv_icm42600/inv_icm42600_buffer.c | 30 ++---
.../iio/imu/inv_icm42600/inv_icm42600_core.c | 13 ++-
.../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 32 ++++--
.../imu/inv_icm42600/inv_icm42600_timestamp.h | 85 --------------
drivers/iio/imu/inv_mpu6050/Kconfig | 1 +
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 26 ++++-
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 9 +-
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 83 ++------------
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 3 +-
.../linux/iio/common/inv_sensors_timestamp.h | 89 +++++++++++++++
18 files changed, 255 insertions(+), 270 deletions(-)
create mode 100644 drivers/iio/common/inv_sensors/Kconfig
create mode 100644 drivers/iio/common/inv_sensors/Makefile
rename drivers/iio/{imu/inv_icm42600/inv_icm42600_timestamp.c => common/inv_sensors/inv_sensors_timestamp.c} (55%)
delete mode 100644 drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h
create mode 100644 include/linux/iio/common/inv_sensors_timestamp.hSignature · 1 line
2.34.1
PATCH 1/4 iio: imu: inv_icm42600: make timestamp module chip independant
From: Jean-Baptiste Maneyrol <[email protected]>
Move icm42600 dependent function inside the core module.
--- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 11 +++++++++++ .../iio/imu/inv_icm42600/inv_icm42600_timestamp.c | 14 +------------- .../iio/imu/inv_icm42600/inv_icm42600_timestamp.h | 4 ---- 3 files changed, 12 insertions(+), 17 deletions(-)
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +11 -0
@@ -516,6 +516,17 @@ static int inv_icm42600_irq_init(struct inv_icm42600_state *st, int irq, "inv_icm42600", st); } +static int inv_icm42600_timestamp_setup (struct inv_icm42600_state *st) +{ +unsigned int val; + +/* enable timestamp register */ + val =INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN | +INV_ICM42600_TMST_CONFIG_TMST_EN ; +return regmap_update_bits (st->map,INV_ICM42600_REG_TMST_CONFIG , +INV_ICM42600_TMST_CONFIG_MASK , val); +} +static int inv_icm42600_enable_regulator_vddio (struct inv_icm42600_state *st) {int ret;
drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1 -13
@@ -4,10 +4,9 @@*/ #include <linux/kernel.h> -#include <linux/regmap.h> #include <linux/math64.h> +#include <linux/errno.h> -#include "inv_icm42600.h" #include "inv_icm42600_timestamp.h" /* internal chip period is 32kHz, 31250ns */
@@ -56,17 +55,6 @@ void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts,inv_update_acc (&ts->chip_period,INV_ICM42600_TIMESTAMP_PERIOD ); } -int inv_icm42600_timestamp_setup (struct inv_icm42600_state *st) -{ -unsigned int val; - -/* enable timestamp register */ - val =INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN | -INV_ICM42600_TMST_CONFIG_TMST_EN ; -return regmap_update_bits (st->map,INV_ICM42600_REG_TMST_CONFIG , -INV_ICM42600_TMST_CONFIG_MASK , val); -} -int inv_icm42600_timestamp_update_odr (struct inv_icm42600_timestamp *ts,uint32_t period,bool fifo) {
drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h +0 -4
@@ -8,8 +8,6 @@#include <linux/kernel.h> -struct inv_icm42600_state ; -/** * struct inv_icm42600_timestamp_interval - timestamps interval * @lo: interval lower bound
@@ -53,8 +51,6 @@ struct inv_icm42600_timestamp {void inv_icm42600_timestamp_init (struct inv_icm42600_timestamp *ts,uint32_t period); -int inv_icm42600_timestamp_setup (struct inv_icm42600_state *st); -int inv_icm42600_timestamp_update_odr (struct inv_icm42600_timestamp *ts,uint32_t period,bool fifo);
Signature · 1 line
2.34.1
Re: [PATCH 1/4] iio: imu: inv_icm42600: make timestamp module chip independant
Wed, May 31, 2023 at 02:25:10PM +0000, [email protected] kirjoitti:
Quoted 3 lines
From: Jean-Baptiste Maneyrol <[email protected]>
Move icm42600 dependent function inside the core module.
...
drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c line 8
Quoted 4 lines
#include <
linux/kernel.h>drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1
-1-#include <linux/regmap.h> #include <linux/math64.h> +#include <linux/errno.h>
Can this be more ordered?
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 2/4 iio: move inv_icm42600 timestamp module in common
In reply to [email protected]From: Jean-Baptiste Maneyrol <[email protected]>
Create new inv_sensors common modules and move inv_icm42600 timestamp module inside.
Modify inv_icm42600 driver to use timestamp module.
---
drivers/iio/common/Kconfig | 1 +
drivers/iio/common/Makefile | 1 +
drivers/iio/common/inv_sensors/Kconfig | 7 +++++++
drivers/iio/common/inv_sensors/Makefile | 6 ++++++
.../inv_sensors}/inv_icm42600_timestamp.c | 12 ++++++++++--
drivers/iio/imu/inv_icm42600/Kconfig | 1 +
drivers/iio/imu/inv_icm42600/Makefile | 1 -
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 2 +-
drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 2 +-
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 3 ++-
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 2 +-
.../linux/iio/common}/inv_icm42600_timestamp.h | 0
12 files changed, 31 insertions(+), 7 deletions(-)
create mode 100644 drivers/iio/common/inv_sensors/Kconfig
create mode 100644 drivers/iio/common/inv_sensors/Makefile
rename drivers/iio/{imu/inv_icm42600 => common/inv_sensors}/inv_icm42600_timestamp.c (91%)
rename {drivers/iio/imu/inv_icm42600 => include/linux/iio/common}/inv_icm42600_timestamp.h (100%)drivers/iio/common/Kconfig +1 -0
@@ -5,6 +5,7 @@ source "drivers/iio/common/cros_ec_sensors/Kconfig" source "drivers/iio/common/hid-sensors/Kconfig" +source "drivers/iio/common/inv_sensors/Kconfig" source "drivers/iio/common/ms_sensors/Kconfig" source "drivers/iio/common/scmi_sensors/Kconfig" source "drivers/iio/common/ssp_sensors/Kconfig"
drivers/iio/common/Makefile +1 -0
@@ -10,6 +10,7 @@ # When adding new entries keep the list in alphabetical order obj-y += cros_ec_sensors/ obj-y += hid-sensors/ +obj-y += inv_sensors/ obj-y += ms_sensors/ obj-y += scmi_sensors/ obj-y += ssp_sensors/
drivers/iio/common/inv_sensors/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# TDK-InvenSense sensors common library +# + +config IIO_INV_SENSORS_TIMESTAMP + tristate
drivers/iio/common/inv_sensors/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for TDK-InvenSense sensors module. +# + +obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_icm42600_timestamp.o
drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +10 -2
@@ -5,9 +5,9 @@#include <linux/kernel.h> #include <linux/math64.h> +#include <linux/module.h> #include <linux/errno.h> - -#include "inv_icm42600_timestamp.h" +#include <linux/iio/common/inv_icm42600_timestamp.h> /* internal chip period is 32kHz, 31250ns */ #define INV_ICM42600_TIMESTAMP_PERIOD 31250
@@ -54,6 +54,7 @@ void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts,/* use theoretical value for chip period */ inv_update_acc (&ts->chip_period,INV_ICM42600_TIMESTAMP_PERIOD ); } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_init,IIO_INV_SENSORS_TIMESTAMP );int inv_icm42600_timestamp_update_odr (struct inv_icm42600_timestamp *ts,uint32_t period,bool fifo)
@@ -66,6 +67,7 @@ int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts,return 0 ; } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_update_odr,IIO_INV_SENSORS_TIMESTAMP );static bool inv_validate_period (uint32_t period,uint32_t mult) {
@@ -153,6 +155,7 @@ void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts,if (valid)inv_align_timestamp_it (ts); } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_interrupt,IIO_INV_SENSORS_TIMESTAMP ); void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, uint32_t fifo_period, size_t fifo_nb,
@@ -184,3 +187,8 @@ void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, ts->timestamp = ts->it.up - interval; } } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_apply_odr,IIO_INV_SENSORS_TIMESTAMP ); + +MODULE_AUTHOR ("InvenSense, Inc." ); +MODULE_DESCRIPTION ("InvenSense sensors timestamp module" ); +MODULE_LICENSE ("GPL" );
drivers/iio/imu/inv_icm42600/Kconfig +1 -0
@@ -3,6 +3,7 @@ config INV_ICM42600 tristate select IIO_BUFFER + select IIO_INV_SENSORS_TIMESTAMP config INV_ICM42600_I2C tristate "InvenSense ICM-426xx I2C driver"
drivers/iio/imu/inv_icm42600/Makefile +0 -1
@@ -6,7 +6,6 @@ inv-icm42600-y += inv_icm42600_gyro.o inv-icm42600-y += inv_icm42600_accel.o inv-icm42600-y += inv_icm42600_temp.o inv-icm42600-y += inv_icm42600_buffer.o -inv-icm42600-y += inv_icm42600_timestamp.o obj-$(CONFIG_INV_ICM42600_I2C) += inv-icm42600-i2c.o inv-icm42600-i2c-y += inv_icm42600_i2c.o
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +1 -1
@@ -12,12 +12,12 @@#include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include <linux/iio/kfifo_buf.h> #include "inv_icm42600.h" #include "inv_icm42600_temp.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h" #define INV_ICM42600_ACCEL_CHAN (_modifier, _index, _ext_info) \ { \
drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +1 -1
@@ -11,9 +11,9 @@#include <linux/delay.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include "inv_icm42600.h" -#include "inv_icm42600_timestamp.h" #include "inv_icm42600_buffer.h" /* FIFO header: 1 byte */
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +2 -1
@@ -16,10 +16,10 @@#include <linux/property.h> #include <linux/regmap.h> #include <linux/iio/iio.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include "inv_icm42600.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h" static const struct regmap_range_cfg inv_icm42600_regmap_ranges[] = { {
@@ -799,3 +799,4 @@ EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42600_pm_ops, IIO_ICM42600) = {MODULE_AUTHOR ("InvenSense, Inc." );MODULE_DESCRIPTION ("InvenSense ICM-426xx device driver" );MODULE_LICENSE ("GPL" ); +MODULE_IMPORT_NS (IIO_INV_SENSORS_TIMESTAMP );
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +1 -1
@@ -12,12 +12,12 @@#include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include <linux/iio/kfifo_buf.h> #include "inv_icm42600.h" #include "inv_icm42600_temp.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h" #define INV_ICM42600_GYRO_CHAN (_modifier, _index, _ext_info) \ { \
include/linux/iio/common/inv_icm42600_timestamp.h renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h +0 -0
Signature · 1 line
2.34.1
Re: [PATCH 2/4] iio: move inv_icm42600 timestamp module in common
Wed, May 31, 2023 at 02:25:11PM +0000, [email protected] kirjoitti:
Quoted 5 lines
From: Jean-Baptiste Maneyrol <[email protected]>
Create new
inv_sensorscommon modules and moveinv_icm42600timestamp module inside.
Modifyinv_icm42600driver to use timestamp module.
...
drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c
Quoted 6 lines
#include <
linux/kernel.h>
#include <linux/math64.h>drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1
-1+#include <linux/module.h> #include <linux/errno.h> -
Leave this blank line. It helps to divide generic headers and IIO (subsystem) related.
Quoted 2 lines
drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1
-1-#include "inv_icm42600_timestamp.h" +#include <linux/iio/common/inv_icm42600_timestamp.h>
...
Quoted 1 line
#include <
linux/delay.h>
+ Blank line?
Quoted 1 line
#include <
linux/iio/iio.h>
Keep it ordered? (But yeah, this one probably out of scope of the series.)
Quoted 6 lines
#include <
linux/iio/buffer.h>drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +1
-1+#include <linux/iio/common/inv_icm42600_timestamp.h> #include "inv_icm42600.h" -#include "inv_icm42600_timestamp.h" #include "inv_icm42600_buffer.h"
...
Quoted 2 lines
#include <
linux/property.h>
#include <linux/regmap.h>
+ Blank line?
Quoted 2 lines
#include <
linux/iio/iio.h>
+#include <linux/iio/common/inv_icm42600_timestamp.h>
Keep it ordered?
Quoted 4 lines
#include "
inv_icm42600.h"
#include "inv_icm42600_buffer.h"
-#include "inv_icm42600_timestamp.h"
...
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c line 20
Quoted 10 lines
#include <
linux/math64.h>
#include <linux/iio/iio.h>
#include <linux/iio/buffer.h>drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +1
-1+#include <linux/iio/common/inv_icm42600_timestamp.h> #include <linux/iio/kfifo_buf.h> #include "inv_icm42600.h" #include "inv_icm42600_temp.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h"
As per above comments.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH 2/4] iio: move inv_icm42600 timestamp module in common
In reply to [email protected]Quoted 7 lines · On Wed, 31 May 2023 14:25:11 +0000 [email protected] wrote:
From: Jean-Baptiste Maneyrol <[email protected]>
Create new
inv_sensorscommon modules and moveinv_icm42600timestamp module inside.
Modifyinv_icm42600driver to use timestamp module.Signed-off-by Jean-Baptiste Maneyrol <[email protected]>
Hi Jean-Baptiste,
Any plan to use this outside of IMU drivers? If not I'd be tempted to keep it more local.
drivers/iio/imu/inv_common/ or similar and avoid the global header by using a "../inv_common/" include path.
Changes themselves look fine to me.
Jonathan
Quoted 220 lines
--- drivers/iio/common/Kconfig | 1 + drivers/iio/common/Makefile | 1 + drivers/iio/common/inv_sensors/Kconfig | 7 +++++++ drivers/iio/common/inv_sensors/Makefile | 6 ++++++ .../inv_sensors}/inv_icm42600_timestamp.c | 12 ++++++++++-- drivers/iio/imu/inv_icm42600/Kconfig | 1 + drivers/iio/imu/inv_icm42600/Makefile | 1 - drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 2 +- drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 2 +- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 3 ++- drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 2 +- .../linux/iio/common}/inv_icm42600_timestamp.h | 0 12 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 drivers/iio/common/inv_sensors/Kconfig create mode 100644 drivers/iio/common/inv_sensors/Makefile rename drivers/iio/{imu/inv_icm42600 => common/inv_sensors}/inv_icm42600_timestamp.c (91%) rename {drivers/iio/imu/inv_icm42600 => include/linux/iio/common}/inv_icm42600_timestamp.h (100%)drivers/iio/common/Kconfig +1
-0@@ -5,6 +5,7 @@ source "drivers/iio/common/cros_ec_sensors/Kconfig" source "drivers/iio/common/hid-sensors/Kconfig" +source "drivers/iio/common/inv_sensors/Kconfig" source "drivers/iio/common/ms_sensors/Kconfig" source "drivers/iio/common/scmi_sensors/Kconfig" source "drivers/iio/common/ssp_sensors/Kconfig"drivers/iio/common/Makefile +1
-0@@ -10,6 +10,7 @@ # When adding new entries keep the list in alphabetical order obj-y += cros_ec_sensors/ obj-y += hid-sensors/ +obj-y += inv_sensors/ obj-y += ms_sensors/ obj-y += scmi_sensors/ obj-y += ssp_sensors/drivers/iio/common/inv_sensors/Kconfig new file +7
-0@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# TDK-InvenSense sensors common library +# + +config IIO_INV_SENSORS_TIMESTAMP + tristatedrivers/iio/common/inv_sensors/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for TDK-InvenSense sensors module. +# + +obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_icm42600_timestamp.odrivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +10
-2@@ -5,9 +5,9 @@#include <linux/kernel.h> #include <linux/math64.h> +#include <linux/module.h> #include <linux/errno.h> - -#include "inv_icm42600_timestamp.h" +#include <linux/iio/common/inv_icm42600_timestamp.h> /* internal chip period is 32kHz, 31250ns */ #define INV_ICM42600_TIMESTAMP_PERIOD 31250@@ -54,6 +54,7 @@ void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts,/* use theoretical value for chip period */ inv_update_acc (&ts->chip_period,INV_ICM42600_TIMESTAMP_PERIOD ); } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_init,IIO_INV_SENSORS_TIMESTAMP );int inv_icm42600_timestamp_update_odr (struct inv_icm42600_timestamp *ts,uint32_t period,bool fifo)@@ -66,6 +67,7 @@ int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts,return 0 ; } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_update_odr,IIO_INV_SENSORS_TIMESTAMP );static bool inv_validate_period (uint32_t period,uint32_t mult) {@@ -153,6 +155,7 @@ void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts,if (valid)inv_align_timestamp_it (ts); } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_interrupt,IIO_INV_SENSORS_TIMESTAMP ); void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, uint32_t fifo_period, size_t fifo_nb,@@ -184,3 +187,8 @@ void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, ts->timestamp = ts->it.up - interval; } } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_apply_odr,IIO_INV_SENSORS_TIMESTAMP ); + +MODULE_AUTHOR ("InvenSense, Inc." ); +MODULE_DESCRIPTION ("InvenSense sensors timestamp module" ); +MODULE_LICENSE ("GPL" );drivers/iio/imu/inv_icm42600/Kconfig +1
-0@@ -3,6 +3,7 @@ config INV_ICM42600 tristate select IIO_BUFFER + select IIO_INV_SENSORS_TIMESTAMP config INV_ICM42600_I2C tristate "InvenSense ICM-426xx I2C driver"drivers/iio/imu/inv_icm42600/Makefile +0
-1@@ -6,7 +6,6 @@ inv-icm42600-y += inv_icm42600_gyro.o inv-icm42600-y += inv_icm42600_accel.o inv-icm42600-y += inv_icm42600_temp.o inv-icm42600-y += inv_icm42600_buffer.o -inv-icm42600-y += inv_icm42600_timestamp.o obj-$(CONFIG_INV_ICM42600_I2C) += inv-icm42600-i2c.o inv-icm42600-i2c-y += inv_icm42600_i2c.odrivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +1
-1@@ -12,12 +12,12 @@#include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include <linux/iio/kfifo_buf.h> #include "inv_icm42600.h" #include "inv_icm42600_temp.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h" #define INV_ICM42600_ACCEL_CHAN (_modifier, _index, _ext_info) \ { \drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +1
-1@@ -11,9 +11,9 @@#include <linux/delay.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include "inv_icm42600.h" -#include "inv_icm42600_timestamp.h" #include "inv_icm42600_buffer.h" /* FIFO header: 1 byte */ drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +2
-1@@ -16,10 +16,10 @@#include <linux/property.h> #include <linux/regmap.h> #include <linux/iio/iio.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include "inv_icm42600.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h" static const struct regmap_range_cfg inv_icm42600_regmap_ranges[] = { {@@ -799,3 +799,4 @@ EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42600_pm_ops, IIO_ICM42600) = {MODULE_AUTHOR ("InvenSense, Inc." );MODULE_DESCRIPTION ("InvenSense ICM-426xx device driver" );MODULE_LICENSE ("GPL" ); +MODULE_IMPORT_NS (IIO_INV_SENSORS_TIMESTAMP );drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +1
-1@@ -12,12 +12,12 @@#include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include <linux/iio/kfifo_buf.h> #include "inv_icm42600.h" #include "inv_icm42600_temp.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h" #define INV_ICM42600_GYRO_CHAN (_modifier, _index, _ext_info) \ { \include/linux/iio/common/inv_icm42600_timestamp.h renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h +0
-0
Jean-Baptiste Maneyrol
maintainerRe: [PATCH 2/4] iio: move inv_icm42600 timestamp module in common
Hello Jonathan,
currently only IMU drivers will be using this timestamp module. But we have other new chips (pressure sensor for example) that could use it in the future.
So I prefer keeping this module more general to avoid being obliged to move it in the future.
Thanks,
JB
From: Jonathan Cameron <[email protected]>
Sent: Sunday, June 4, 2023 12:58
To: INV Git Commit <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>
Subject: Re: [PATCH 2/4] iio: move inv_icm42600 timestamp module in common
[CAUTION] This is an EXTERNAL email. Do not click links or open attachments unless you recognize the sender and know the content is safe.
======================================================================
Quoted 7 lines · On Wed, 31 May 2023 14:25:11 +0000 [email protected] wrote:
From: Jean-Baptiste Maneyrol <[email protected]>
Create new
inv_sensorscommon modules and moveinv_icm42600timestamp module inside.
Modifyinv_icm42600driver to use timestamp module.Signed-off-by Jean-Baptiste Maneyrol <[email protected]>
Hi Jean-Baptiste,
Any plan to use this outside of IMU drivers? If not I'd be tempted to keep it more local.
drivers/iio/imu/inv_common/ or similar and avoid the global header by using a "../inv_common/" include path.
Changes themselves look fine to me.
Jonathan
Quoted 220 lines
---
drivers/iio/common/Kconfig | 1 + drivers/iio/common/Makefile | 1 + drivers/iio/common/inv_sensors/Kconfig | 7 +++++++ drivers/iio/common/inv_sensors/Makefile | 6 ++++++ .../inv_sensors}/inv_icm42600_timestamp.c | 12 ++++++++++-- drivers/iio/imu/inv_icm42600/Kconfig | 1 + drivers/iio/imu/inv_icm42600/Makefile | 1 - drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 2 +- drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 2 +- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 3 ++- drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 2 +- .../linux/iio/common}/inv_icm42600_timestamp.h | 012 files changed, 31 insertions(+), 7 deletions(-)create mode 100644
drivers/iio/common/inv_sensors/Kconfig
create mode 100644drivers/iio/common/inv_sensors/Makefile
renamedrivers/iio/{imu/inv_icm42600=>common/inv_sensors}/inv_icm42600_timestamp.c(91%) rename {drivers/iio/imu/inv_icm42600=>include/linux/iio/common}/inv_icm42600_timestamp.h(100%)drivers/iio/common/Kconfig +0
-0@@ -5,6 +5,7 @@
source "drivers/iio/common/cros_ec_sensors/Kconfig" source "drivers/iio/common/hid-sensors/Kconfig" +source "drivers/iio/common/inv_sensors/Kconfig" source "drivers/iio/common/ms_sensors/Kconfig" source "drivers/iio/common/scmi_sensors/Kconfig" source "drivers/iio/common/ssp_sensors/Kconfig"drivers/iio/common/Makefile +0
-0@@ -10,6 +10,7 @@ # When adding new entries keep the list in alphabetical orderobj-y += cros_ec_sensors/
obj-y += hid-sensors/
+obj-y += inv_sensors/
obj-y += ms_sensors/
obj-y += scmi_sensors/
obj-y += ssp_sensors/drivers/iio/common/inv_sensors/Kconfig new file +7
-0@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# TDK-InvenSense sensors common library +# + +config IIO_INV_SENSORS_TIMESTAMP + tristatedrivers/iio/common/inv_sensors/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for TDK-InvenSense sensors module. +# + +obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_icm42600_timestamp.odrivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +0
-0@@ -5,9 +5,9 @@
#include <linux/kernel.h>
#include <linux/math64.h>
+#include <linux/module.h>
#include <linux/errno.h>drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1
-2- -#include "inv_icm42600_timestamp.h" +#include <linux/iio/common/inv_icm42600_timestamp.h>
/* internal chip period is 32kHz, 31250ns */ #define INV_ICM42600_TIMESTAMP_PERIOD 31250drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1
-0@@ -54,6 +54,7 @@ void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts, /* use theoretical value for chip period */ inv_update_acc(&ts->chip_period, INV_ICM42600_TIMESTAMP_PERIOD); } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_init,IIO_INV_SENSORS_TIMESTAMP );
intinv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts, uint32_t period, bool fifo)drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +0
-0@@ -66,6 +67,7 @@ int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts,
return 0;
}
+EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_update_odr,IIO_INV_SENSORS_TIMESTAMP);
static boolinv_validate_period(uint32_t period, uint32_t mult)
{drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1
-0@@ -153,6 +155,7 @@ void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts, if (valid) inv_align_timestamp_it(ts); } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_interrupt,IIO_INV_SENSORS_TIMESTAMP );
void inv_icm42600_timestamp_apply_odr(structinv_icm42600_timestamp*ts,uint32_tfifo_period,size_tfifo_nb,drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +5
-0@@ -184,3 +187,8 @@ void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, ts->timestamp = ts->it.up - interval; } } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_apply_odr,IIO_INV_SENSORS_TIMESTAMP ); + +MODULE_AUTHOR ("InvenSense, Inc." ); +MODULE_DESCRIPTION ("InvenSense sensors timestamp module" ); +MODULE_LICENSE ("GPL" );drivers/iio/imu/inv_icm42600/Kconfig +0
-0@@ -3,6 +3,7 @@config
INV_ICM42600
tristate
selectIIO_BUFFER
+ selectIIO_INV_SENSORS_TIMESTAMP
configINV_ICM42600_I2C
tristate "InvenSense ICM-426xx I2C driver"drivers/iio/imu/inv_icm42600/Makefile +0
-0@@ -6,7 +6,6 @@ inv-icm42600-y += inv_icm42600_gyro.oinv-icm42600-y += inv_icm42600_accel.o inv-icm42600-y += inv_icm42600_temp.o inv-icm42600-y += inv_icm42600_buffer.o -inv-icm42600-y += inv_icm42600_timestamp.o
obj-$(CONFIG_INV_ICM42600_I2C) += inv-icm42600-i2c.o inv-icm42600-i2c-y += inv_icm42600_i2c.odrivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +1
-0@@ -12,12 +12,12 @@ #include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include <linux/iio/kfifo_buf.h>
#include "inv_icm42600.h"
#include "inv_icm42600_temp.h"
#include "inv_icm42600_buffer.h"
-#include "inv_icm42600_timestamp.h"
#defineINV_ICM42600_ACCEL_CHAN(_modifier, _index, _ext_info)\
{ \drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +1
-0@@ -11,9 +11,9 @@ #include <linux/delay.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h>
#include "inv_icm42600.h"
-#include "inv_icm42600_timestamp.h"
#include "inv_icm42600_buffer.h"
/* FIFO header: 1 byte */drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +1
-0@@ -16,10 +16,10 @@ #include <linux/property.h> #include <linux/regmap.h> #include <linux/iio/iio.h> +#include <linux/iio/common/inv_icm42600_timestamp.h>
#include "inv_icm42600.h"
#include "inv_icm42600_buffer.h"
-#include "inv_icm42600_timestamp.h"
static const structregmap_range_cfginv_icm42600_regmap_ranges[] = { {drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +1
-0@@ -799,3 +799,4 @@ EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42600_pm_ops, IIO_ICM42600) = { MODULE_AUTHOR("InvenSense, Inc."); MODULE_DESCRIPTION("InvenSense ICM-426xx device driver"); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS (IIO_INV_SENSORS_TIMESTAMP );drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +1
-0@@ -12,12 +12,12 @@ #include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include <linux/iio/kfifo_buf.h>
#include "inv_icm42600.h"
#include "inv_icm42600_temp.h"
#include "inv_icm42600_buffer.h"
-#include "inv_icm42600_timestamp.h"
#defineINV_ICM42600_GYRO_CHAN(_modifier, _index, _ext_info)\
{ \include/linux/iio/common/inv_icm42600_timestamp.h renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h +0
-0
Jonathan Cameron
maintainerRe: [PATCH 2/4] iio: move inv_icm42600 timestamp module in common
Quoted 5 lines · On Mon, 5 Jun 2023 19:07:38 +0000 Jean-Baptiste Maneyrol…
Hello Jonathan,
currently only IMU drivers will be using this timestamp module. But we have other new chips (pressure sensor for example) that could use it in the future.
So I prefer keeping this module more general to avoid being obliged to move it in the future.
Fair enough. Perhaps add a note on that to the patch description.
Jonathan
Quoted 256 lines
Thanks,
JBFrom: Jonathan Cameron <[email protected]>
Sent: Sunday, June 4, 2023 12:58
To: INV Git Commit <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>
Subject: Re: [PATCH 2/4] iio: moveinv_icm42600timestamp module in common
[CAUTION] This is an EXTERNAL email. Do not click links or open attachments unless you recognize the sender and know the content is safe.======================================================================
Quoted 7 lines · On Wed, 31 May 2023 14:25:11 +0000 [email protected] wrote:
From: Jean-Baptiste Maneyrol <[email protected]>
Create new
inv_sensorscommon modules and moveinv_icm42600timestamp module inside.
Modifyinv_icm42600driver to use timestamp module.Signed-off-by Jean-Baptiste Maneyrol <[email protected]>Hi Jean-Baptiste,
Any plan to use this outside of IMU drivers? If not I'd be tempted to keep it more local.
drivers/iio/imu/inv_common/or similar and avoid the global header by using a "../inv_common/" include path.Changes themselves look fine to me.
Jonathan
Quoted 220 lines
---
drivers/iio/common/Kconfig | 1 + drivers/iio/common/Makefile | 1 + drivers/iio/common/inv_sensors/Kconfig | 7 +++++++ drivers/iio/common/inv_sensors/Makefile | 6 ++++++ .../inv_sensors}/inv_icm42600_timestamp.c | 12 ++++++++++-- drivers/iio/imu/inv_icm42600/Kconfig | 1 + drivers/iio/imu/inv_icm42600/Makefile | 1 - drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 2 +- drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 2 +- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 3 ++- drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 2 +- .../linux/iio/common}/inv_icm42600_timestamp.h | 012 files changed, 31 insertions(+), 7 deletions(-)create mode 100644
drivers/iio/common/inv_sensors/Kconfig
create mode 100644drivers/iio/common/inv_sensors/Makefile
renamedrivers/iio/{imu/inv_icm42600=>common/inv_sensors}/inv_icm42600_timestamp.c(91%) rename {drivers/iio/imu/inv_icm42600=>include/linux/iio/common}/inv_icm42600_timestamp.h(100%)drivers/iio/common/Kconfig +0
-0@@ -5,6 +5,7 @@
source "drivers/iio/common/cros_ec_sensors/Kconfig" source "drivers/iio/common/hid-sensors/Kconfig" +source "drivers/iio/common/inv_sensors/Kconfig" source "drivers/iio/common/ms_sensors/Kconfig" source "drivers/iio/common/scmi_sensors/Kconfig" source "drivers/iio/common/ssp_sensors/Kconfig"drivers/iio/common/Makefile +0
-0@@ -10,6 +10,7 @@ # When adding new entries keep the list in alphabetical orderobj-y += cros_ec_sensors/
obj-y += hid-sensors/
+obj-y += inv_sensors/
obj-y += ms_sensors/
obj-y += scmi_sensors/
obj-y += ssp_sensors/drivers/iio/common/inv_sensors/Kconfig new file +7
-0@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# TDK-InvenSense sensors common library +# + +config IIO_INV_SENSORS_TIMESTAMP + tristatedrivers/iio/common/inv_sensors/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for TDK-InvenSense sensors module. +# + +obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_icm42600_timestamp.odrivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +0
-0@@ -5,9 +5,9 @@
#include <linux/kernel.h>
#include <linux/math64.h>
+#include <linux/module.h>
#include <linux/errno.h>drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1
-2- -#include "inv_icm42600_timestamp.h" +#include <linux/iio/common/inv_icm42600_timestamp.h>
/* internal chip period is 32kHz, 31250ns */ #define INV_ICM42600_TIMESTAMP_PERIOD 31250drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1
-0@@ -54,6 +54,7 @@ void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts, /* use theoretical value for chip period */ inv_update_acc(&ts->chip_period, INV_ICM42600_TIMESTAMP_PERIOD); } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_init,IIO_INV_SENSORS_TIMESTAMP );
intinv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts, uint32_t period, bool fifo)drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +0
-0@@ -66,6 +67,7 @@ int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts,
return 0;
}
+EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_update_odr,IIO_INV_SENSORS_TIMESTAMP);
static boolinv_validate_period(uint32_t period, uint32_t mult)
{drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +1
-0@@ -153,6 +155,7 @@ void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts, if (valid) inv_align_timestamp_it(ts); } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_interrupt,IIO_INV_SENSORS_TIMESTAMP );
void inv_icm42600_timestamp_apply_odr(structinv_icm42600_timestamp*ts,uint32_tfifo_period,size_tfifo_nb,drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +5
-0@@ -184,3 +187,8 @@ void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, ts->timestamp = ts->it.up - interval; } } +EXPORT_SYMBOL_NS_GPL (inv_icm42600_timestamp_apply_odr,IIO_INV_SENSORS_TIMESTAMP ); + +MODULE_AUTHOR ("InvenSense, Inc." ); +MODULE_DESCRIPTION ("InvenSense sensors timestamp module" ); +MODULE_LICENSE ("GPL" );drivers/iio/imu/inv_icm42600/Kconfig +0
-0@@ -3,6 +3,7 @@config
INV_ICM42600
tristate
selectIIO_BUFFER
+ selectIIO_INV_SENSORS_TIMESTAMP
configINV_ICM42600_I2C
tristate "InvenSense ICM-426xx I2C driver"drivers/iio/imu/inv_icm42600/Makefile +0
-0@@ -6,7 +6,6 @@ inv-icm42600-y += inv_icm42600_gyro.oinv-icm42600-y += inv_icm42600_accel.o inv-icm42600-y += inv_icm42600_temp.o inv-icm42600-y += inv_icm42600_buffer.o -inv-icm42600-y += inv_icm42600_timestamp.o
obj-$(CONFIG_INV_ICM42600_I2C) += inv-icm42600-i2c.o inv-icm42600-i2c-y += inv_icm42600_i2c.odrivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +1
-0@@ -12,12 +12,12 @@ #include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include <linux/iio/kfifo_buf.h>
#include "inv_icm42600.h"
#include "inv_icm42600_temp.h"
#include "inv_icm42600_buffer.h"
-#include "inv_icm42600_timestamp.h"
#defineINV_ICM42600_ACCEL_CHAN(_modifier, _index, _ext_info)\
{ \drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +1
-0@@ -11,9 +11,9 @@ #include <linux/delay.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h>
#include "inv_icm42600.h"
-#include "inv_icm42600_timestamp.h"
#include "inv_icm42600_buffer.h"
/* FIFO header: 1 byte */drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +1
-0@@ -16,10 +16,10 @@ #include <linux/property.h> #include <linux/regmap.h> #include <linux/iio/iio.h> +#include <linux/iio/common/inv_icm42600_timestamp.h>
#include "inv_icm42600.h"
#include "inv_icm42600_buffer.h"
-#include "inv_icm42600_timestamp.h"
static const structregmap_range_cfginv_icm42600_regmap_ranges[] = { {drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +1
-0@@ -799,3 +799,4 @@ EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42600_pm_ops, IIO_ICM42600) = { MODULE_AUTHOR("InvenSense, Inc."); MODULE_DESCRIPTION("InvenSense ICM-426xx device driver"); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS (IIO_INV_SENSORS_TIMESTAMP );drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +1
-0@@ -12,12 +12,12 @@ #include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_icm42600_timestamp.h> #include <linux/iio/kfifo_buf.h>
#include "inv_icm42600.h"
#include "inv_icm42600_temp.h"
#include "inv_icm42600_buffer.h"
-#include "inv_icm42600_timestamp.h"
#defineINV_ICM42600_GYRO_CHAN(_modifier, _index, _ext_info)\
{ \include/linux/iio/common/inv_icm42600_timestamp.h renamed from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h +0
-0
PATCH 3/4 iio: make invensense timestamp module generic
In reply to [email protected]From: Jean-Baptiste Maneyrol <[email protected]>
Rename common module to inv_sensors_timestamp, add configuration at init (chip internal clock, acceptable jitter, ...) and update inv_icm42600 driver integration.
---
drivers/iio/common/inv_sensors/Makefile | 2 +-
...00_timestamp.c => inv_sensors_timestamp.c} | 89 +++++++++----------
.../iio/imu/inv_icm42600/inv_icm42600_accel.c | 32 ++++---
.../imu/inv_icm42600/inv_icm42600_buffer.c | 30 +++----
.../iio/imu/inv_icm42600/inv_icm42600_core.c | 1 -
.../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 32 ++++---
.../linux/iio/common/inv_icm42600_timestamp.h | 81 -----------------
.../linux/iio/common/inv_sensors_timestamp.h | 89 +++++++++++++++++++
8 files changed, 189 insertions(+), 167 deletions(-)
rename drivers/iio/common/inv_sensors/{inv_icm42600_timestamp.c => inv_sensors_timestamp.c} (57%)
delete mode 100644 include/linux/iio/common/inv_icm42600_timestamp.h
create mode 100644 include/linux/iio/common/inv_sensors_timestamp.hdrivers/iio/common/inv_sensors/Makefile +1 -1
@@ -3,4 +3,4 @@ # Makefile for TDK-InvenSense sensors module. # -obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_icm42600_timestamp.o +obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_sensors_timestamp.o
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c renamed from drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c +44 -45
176 lines not on this page · raw message
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +20 -12
@@ -12,7 +12,7 @@#include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> -#include <linux/iio/common/inv_icm42600_timestamp.h> +#include <linux/iio/common/inv_sensors_timestamp.h> #include <linux/iio/kfifo_buf.h> #include "inv_icm42600.h"
@@ -98,7 +98,7 @@ static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) {struct inv_icm42600_state *st =iio_device_get_drvdata (indio_dev); -struct inv_icm42600_timestamp *ts =iio_priv (indio_dev); +struct inv_sensors_timestamp *ts =iio_priv (indio_dev);struct inv_icm42600_sensor_conf conf =INV_ICM42600_SENSOR_CONF_INIT ;unsigned int fifo_en =0 ;unsigned int sleep_temp =0 ;
@@ -126,7 +126,7 @@ static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev, }/* update data FIFO write */ -inv_icm42600_timestamp_apply_odr (ts,0 ,0 ,0 ); +inv_sensors_timestamp_apply_odr (ts,0 ,0 ,0 ); ret =inv_icm42600_buffer_set_fifo_en (st, fifo_en | st->fifo.en);if (ret) goto out_unlock;
@@ -311,7 +311,7 @@ static int inv_icm42600_accel_write_odr(struct iio_dev *indio_dev, int val, int val2) {struct inv_icm42600_state *st =iio_device_get_drvdata (indio_dev); -struct inv_icm42600_timestamp *ts =iio_priv (indio_dev); +struct inv_sensors_timestamp *ts =iio_priv (indio_dev);struct device *dev =regmap_get_device (st->map);unsigned int idx;struct inv_icm42600_sensor_conf conf =INV_ICM42600_SENSOR_CONF_INIT ;
@@ -330,8 +330,8 @@ static int inv_icm42600_accel_write_odr(struct iio_dev *indio_dev,pm_runtime_get_sync (dev);mutex_lock (&st->lock); - ret =inv_icm42600_timestamp_update_odr (ts,inv_icm42600_odr_to_period (conf.odr), -iio_buffer_enabled (indio_dev)); + ret =inv_sensors_timestamp_update_odr (ts,inv_icm42600_odr_to_period (conf.odr), +iio_buffer_enabled (indio_dev));if (ret) goto out_unlock;
@@ -707,7 +707,8 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st) {struct device *dev =regmap_get_device (st->map);const char *name; -struct inv_icm42600_timestamp *ts; +struct inv_sensors_timestamp_chip ts_chip; +struct inv_sensors_timestamp *ts;struct iio_dev *indio_dev;int ret;
@@ -719,8 +720,15 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st)if (!indio_dev)return ERR_PTR (-ENOMEM ); +/* +* clock period is 32kHz (31250ns) +* jitter is +/- 2% (20 per mille) +*/ + ts_chip.clock_period =31250 ; + ts_chip.jitter =20 ; + ts_chip.init_period =inv_icm42600_odr_to_period (st->conf.accel.odr); ts =iio_priv (indio_dev); -inv_icm42600_timestamp_init (ts,inv_icm42600_odr_to_period (st->conf.accel.odr)); +inv_sensors_timestamp_init (ts, &ts_chip);iio_device_set_drvdata (indio_dev, st); indio_dev->name = name;
@@ -745,7 +753,7 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st)int inv_icm42600_accel_parse_fifo (struct iio_dev *indio_dev) {struct inv_icm42600_state *st =iio_device_get_drvdata (indio_dev); -struct inv_icm42600_timestamp *ts =iio_priv (indio_dev); +struct inv_sensors_timestamp *ts =iio_priv (indio_dev);ssize_t i, size;unsigned int no;const void *accel, *gyro, *timestamp;
@@ -768,15 +776,15 @@ int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev)/* update odr */ if (odr &INV_ICM42600_SENSOR_ACCEL ) -inv_icm42600_timestamp_apply_odr (ts, st->fifo.period, - st->fifo.nb.total, no); +inv_sensors_timestamp_apply_odr (ts, st->fifo.period, + st->fifo.nb.total, no);/* buffer is copied to userspace, zeroing it to avoid any data leak */ memset (&buffer,0 ,sizeof (buffer));memcpy (&buffer.accel, accel,sizeof (buffer.accel));/* convert 8 bits FIFO temperature in high resolution format */ buffer.temp = temp ? (*temp *64 ) :0 ; - ts_val =inv_icm42600_timestamp_pop (ts); + ts_val =inv_sensors_timestamp_pop (ts);iio_push_to_buffers_with_timestamp (indio_dev, &buffer, ts_val); }
drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +15 -15
@@ -11,7 +11,7 @@#include <linux/delay.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> -#include <linux/iio/common/inv_icm42600_timestamp.h> +#include <linux/iio/common/inv_sensors_timestamp.h> #include "inv_icm42600.h" #include "inv_icm42600_buffer.h"
@@ -275,12 +275,12 @@ static int inv_icm42600_buffer_preenable(struct iio_dev *indio_dev) {struct inv_icm42600_state *st =iio_device_get_drvdata (indio_dev);struct device *dev =regmap_get_device (st->map); -struct inv_icm42600_timestamp *ts =iio_priv (indio_dev); +struct inv_sensors_timestamp *ts =iio_priv (indio_dev);pm_runtime_get_sync (dev);mutex_lock (&st->lock); -inv_icm42600_timestamp_reset (ts); +inv_sensors_timestamp_reset (ts);mutex_unlock (&st->lock);return 0 ;
@@ -504,7 +504,7 @@ int inv_icm42600_buffer_fifo_read(struct inv_icm42600_state *st,int inv_icm42600_buffer_fifo_parse (struct inv_icm42600_state *st) { -struct inv_icm42600_timestamp *ts; +struct inv_sensors_timestamp *ts;int ret;if (st->fifo.nb.total ==0 )
@@ -512,8 +512,8 @@ int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st)/* handle gyroscope timestamp and FIFO data parsing */ ts =iio_priv (st->indio_gyro); -inv_icm42600_timestamp_interrupt (ts, st->fifo.period, st->fifo.nb.total, - st->fifo.nb.gyro, st->timestamp.gyro); +inv_sensors_timestamp_interrupt (ts, st->fifo.period, st->fifo.nb.total, + st->fifo.nb.gyro, st->timestamp.gyro);if (st->fifo.nb.gyro >0 ) { ret =inv_icm42600_gyro_parse_fifo (st->indio_gyro);if (ret)
@@ -522,8 +522,8 @@ int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st)/* handle accelerometer timestamp and FIFO data parsing */ ts =iio_priv (st->indio_accel); -inv_icm42600_timestamp_interrupt (ts, st->fifo.period, st->fifo.nb.total, - st->fifo.nb.accel, st->timestamp.accel); +inv_sensors_timestamp_interrupt (ts, st->fifo.period, st->fifo.nb.total, + st->fifo.nb.accel, st->timestamp.accel);if (st->fifo.nb.accel >0 ) { ret =inv_icm42600_accel_parse_fifo (st->indio_accel);if (ret)
@@ -536,7 +536,7 @@ int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st)int inv_icm42600_buffer_hwfifo_flush (struct inv_icm42600_state *st,unsigned int count) { -struct inv_icm42600_timestamp *ts; +struct inv_sensors_timestamp *ts;int64_t gyro_ts, accel_ts;int ret;
@@ -552,9 +552,9 @@ int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st,if (st->fifo.nb.gyro >0 ) { ts =iio_priv (st->indio_gyro); -inv_icm42600_timestamp_interrupt (ts, st->fifo.period, - st->fifo.nb.total, st->fifo.nb.gyro, - gyro_ts); +inv_sensors_timestamp_interrupt (ts, st->fifo.period, + st->fifo.nb.total, st->fifo.nb.gyro, + gyro_ts); ret =inv_icm42600_gyro_parse_fifo (st->indio_gyro);if (ret)return ret;
@@ -562,9 +562,9 @@ int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st,if (st->fifo.nb.accel >0 ) { ts =iio_priv (st->indio_accel); -inv_icm42600_timestamp_interrupt (ts, st->fifo.period, - st->fifo.nb.total, st->fifo.nb.accel, - accel_ts); +inv_sensors_timestamp_interrupt (ts, st->fifo.period, + st->fifo.nb.total, st->fifo.nb.accel, + accel_ts); ret =inv_icm42600_accel_parse_fifo (st->indio_accel);if (ret)return ret;
drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +0 -1
@@ -16,7 +16,6 @@#include <linux/property.h> #include <linux/regmap.h> #include <linux/iio/iio.h> -#include <linux/iio/common/inv_icm42600_timestamp.h> #include "inv_icm42600.h" #include "inv_icm42600_buffer.h"
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +20 -12
@@ -12,7 +12,7 @@#include <linux/math64.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> -#include <linux/iio/common/inv_icm42600_timestamp.h> +#include <linux/iio/common/inv_sensors_timestamp.h> #include <linux/iio/kfifo_buf.h> #include "inv_icm42600.h"
@@ -98,7 +98,7 @@ static int inv_icm42600_gyro_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) {struct inv_icm42600_state *st =iio_device_get_drvdata (indio_dev); -struct inv_icm42600_timestamp *ts =iio_priv (indio_dev); +struct inv_sensors_timestamp *ts =iio_priv (indio_dev);struct inv_icm42600_sensor_conf conf =INV_ICM42600_SENSOR_CONF_INIT ;unsigned int fifo_en =0 ;unsigned int sleep_gyro =0 ;
@@ -126,7 +126,7 @@ static int inv_icm42600_gyro_update_scan_mode(struct iio_dev *indio_dev, }/* update data FIFO write */ -inv_icm42600_timestamp_apply_odr (ts,0 ,0 ,0 ); +inv_sensors_timestamp_apply_odr (ts,0 ,0 ,0 ); ret =inv_icm42600_buffer_set_fifo_en (st, fifo_en | st->fifo.en);if (ret) goto out_unlock;
@@ -323,7 +323,7 @@ static int inv_icm42600_gyro_write_odr(struct iio_dev *indio_dev, int val, int val2) {struct inv_icm42600_state *st =iio_device_get_drvdata (indio_dev); -struct inv_icm42600_timestamp *ts =iio_priv (indio_dev); +struct inv_sensors_timestamp *ts =iio_priv (indio_dev);struct device *dev =regmap_get_device (st->map);unsigned int idx;struct inv_icm42600_sensor_conf conf =INV_ICM42600_SENSOR_CONF_INIT ;
@@ -342,8 +342,8 @@ static int inv_icm42600_gyro_write_odr(struct iio_dev *indio_dev,pm_runtime_get_sync (dev);mutex_lock (&st->lock); - ret =inv_icm42600_timestamp_update_odr (ts,inv_icm42600_odr_to_period (conf.odr), -iio_buffer_enabled (indio_dev)); + ret =inv_sensors_timestamp_update_odr (ts,inv_icm42600_odr_to_period (conf.odr), +iio_buffer_enabled (indio_dev));if (ret) goto out_unlock;
@@ -718,7 +718,8 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st) {struct device *dev =regmap_get_device (st->map);const char *name; -struct inv_icm42600_timestamp *ts; +struct inv_sensors_timestamp_chip ts_chip; +struct inv_sensors_timestamp *ts;struct iio_dev *indio_dev;int ret;
@@ -730,8 +731,15 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st)if (!indio_dev)return ERR_PTR (-ENOMEM ); +/* +* clock period is 32kHz (31250ns) +* jitter is +/- 2% (20 per mille) +*/ + ts_chip.clock_period =31250 ; + ts_chip.jitter =20 ; + ts_chip.init_period =inv_icm42600_odr_to_period (st->conf.accel.odr); ts =iio_priv (indio_dev); -inv_icm42600_timestamp_init (ts,inv_icm42600_odr_to_period (st->conf.gyro.odr)); +inv_sensors_timestamp_init (ts, &ts_chip);iio_device_set_drvdata (indio_dev, st); indio_dev->name = name;
@@ -757,7 +765,7 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st)int inv_icm42600_gyro_parse_fifo (struct iio_dev *indio_dev) {struct inv_icm42600_state *st =iio_device_get_drvdata (indio_dev); -struct inv_icm42600_timestamp *ts =iio_priv (indio_dev); +struct inv_sensors_timestamp *ts =iio_priv (indio_dev);ssize_t i, size;unsigned int no;const void *accel, *gyro, *timestamp;
@@ -780,15 +788,15 @@ int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev)/* update odr */ if (odr &INV_ICM42600_SENSOR_GYRO ) -inv_icm42600_timestamp_apply_odr (ts, st->fifo.period, - st->fifo.nb.total, no); +inv_sensors_timestamp_apply_odr (ts, st->fifo.period, + st->fifo.nb.total, no);/* buffer is copied to userspace, zeroing it to avoid any data leak */ memset (&buffer,0 ,sizeof (buffer));memcpy (&buffer.gyro, gyro,sizeof (buffer.gyro));/* convert 8 bits FIFO temperature in high resolution format */ buffer.temp = temp ? (*temp *64 ) :0 ; - ts_val =inv_icm42600_timestamp_pop (ts); + ts_val =inv_sensors_timestamp_pop (ts);iio_push_to_buffers_with_timestamp (indio_dev, &buffer, ts_val); }
include/linux/iio/common/inv_icm42600_timestamp.h deleted +0 -81
81 lines not on this page · raw message
include/linux/iio/common/inv_sensors_timestamp.h new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 3/4] iio: make invensense timestamp module generic
Wed, May 31, 2023 at 02:25:12PM +0000, [email protected] kirjoitti:
Quoted 5 lines
From: Jean-Baptiste Maneyrol <[email protected]>
Rename common module to
inv_sensors_timestamp, add configuration at init (chip internal clock, acceptable jitter, ...) and updateinv_icm42600driver integration.
...
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c static void inv_update_acc(struct inv_icm42600_timestamp_acc *acc, uint32_t val) · line 78
Quoted 5 lines
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c renamed from drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c +2
-2/* check that period is acceptable */ - period_min =INV_ICM42600_TIMESTAMP_MIN_PERIOD (chip_period) * mult; - period_max =INV_ICM42600_TIMESTAMP_MAX_PERIOD (chip_period) * mult; + period_min = ts->min_period * mult; + period_max = ts->max_period * mult;
Side note: wondering if linear_range.h APIs can somehow help with this.
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c static void inv_update_acc(struct inv_icm42600_timestamp_acc *acc, uint32_t val) · line 82
Quoted 4 lines
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c renamed from drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c +0
-0if (period > period_min && period < period_max)return true;else return false;
Another side note: this can be simplified in a follow up at some point.
...
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts, · line 153
Quoted 2 lines
drivers/iio/common/inv_sensors/inv_sensors_timestamp.c renamed from drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c +1
-1-/* if interrupt interval is valid, sync with interrupt timestamp */ +/* if interrupt interval is valid, align with interrupt timestamp */
Not sure why this change, but probably it's inline with the rest of the changes.
...
include/linux/iio/common/inv_sensors_timestamp.h
Quoted 2 lines
include/linux/iio/common/inv_sensors_timestamp.h new file +0
-0
Have you used -M -C for git-format-patch?
...
include/linux/iio/common/inv_sensors_timestamp.h line 9
Quoted 4 lines
include/linux/iio/common/inv_sensors_timestamp.h new file +3
-0+#ifndef INV_SENSORS_TIMESTAMP_H_ +#define INV_SENSORS_TIMESTAMP_H_ +#include <linux/kernel.h>
While I see this in the original code, I have found no evidence this header is used here in any possible way.
Actually kernel.h in the _headers_ is quite discouraged.
Quoted 1 line
+#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH 3/4] iio: make invensense timestamp module generic
In reply to [email protected]Quoted 7 lines · On Wed, 31 May 2023 14:25:12 +0000 [email protected] wrote:
From: Jean-Baptiste Maneyrol <[email protected]>
Rename common module to
inv_sensors_timestamp, add configuration at init (chip internal clock, acceptable jitter, ...) and updateinv_icm42600driver integration.Signed-off-by Jean-Baptiste Maneyrol <[email protected]>
Docs update needed below.
Quoted 6 lines
include/linux/iio/common/inv_sensors_timestamp.h new file +0
-0
include/linux/iio/common/inv_sensors_timestamp.h line 47
Quoted 10 lines
include/linux/iio/common/inv_sensors_timestamp.h new file +10
-0+ +/** +* struct inv_sensors_timestamp - timestamp management states +* @chip: chip internal characteristics +* @it: interrupts interval timestamps +* @timestamp: store last timestamp for computing next data timestamp +* @mult: current internal period multiplier +* @new_mult: new set internal period multiplier (not yet effective) +* @period: measured current period of the sensor +* @chip_period: accumulator for computing internal chip period
Docs need an update.
Quoted 13 lines
+ */
include/linux/iio/common/inv_sensors_timestamp.h new file +12
-0+struct inv_sensors_timestamp { +struct inv_sensors_timestamp_chip chip; +uint32_t min_period; +uint32_t max_period; +struct inv_sensors_timestamp_interval it; +int64_t timestamp; +uint32_t mult; +uint32_t new_mult; +uint32_t period; +struct inv_sensors_timestamp_acc chip_period; +}; +
PATCH 4/4 iio: imu: inv_mpu6050: use the common inv_sensors timestamp module
In reply to [email protected]From: Jean-Baptiste Maneyrol <[email protected]>
Replace timestamping by the new common inv_sensors timestamp module.
--- drivers/iio/imu/inv_mpu6050/Kconfig | 1 + drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 26 ++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 9 +- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 83 ++----------------- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 3 +- 5 files changed, 33 insertions(+), 89 deletions(-)
drivers/iio/imu/inv_mpu6050/Kconfig +1 -0
@@ -7,6 +7,7 @@ config INV_MPU6050_IIO tristate select IIO_BUFFER select IIO_TRIGGERED_BUFFER + select IIO_INV_SENSORS_TIMESTAMP config INV_MPU6050_I2C tristate "Invensense MPU6050 devices (I2C)"
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +20 -6
@@ -13,6 +13,7 @@#include <linux/irq.h> #include <linux/interrupt.h> #include <linux/iio/iio.h> +#include <linux/iio/common/inv_sensors_timestamp.h> #include <linux/acpi.h> #include <linux/platform_device.h> #include <linux/regulator/consumer.h>
@@ -521,6 +522,7 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)int result;u8 d;struct inv_mpu6050_state *st =iio_priv (indio_dev); +struct inv_sensors_timestamp_chip timestamp; result =inv_mpu6050_set_gyro_fsr (st, st->chip_config.fsr);if (result)
@@ -544,12 +546,12 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)if (result)return result; -/* -* Internal chip period is 1ms (1kHz). -* Let's use at the beginning the theorical value before measuring -* with interrupt timestamps. -*/ - st->chip_period =NSEC_PER_MSEC ; +/* clock jitter is +/- 2% */ + timestamp.clock_period =NSEC_PER_SEC /INV_MPU6050_INTERNAL_FREQ_HZ ; + timestamp.jitter =20 ; + timestamp.init_period = +NSEC_PER_SEC /INV_MPU6050_DIVIDER_TO_FIFO_RATE (st->chip_config.divider); +inv_sensors_timestamp_init (&st->timestamp, ×tamp);/* magn chip init, noop if not present in the chip */ result =inv_mpu_magn_probe (st);
@@ -936,6 +938,8 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int fifo_rate; +u32 fifo_period; +bool fifo_on;u8 d;int result;struct iio_dev *indio_dev =dev_to_iio_dev (dev);
@@ -952,12 +956,21 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, d =INV_MPU6050_FIFO_RATE_TO_DIVIDER (fifo_rate);/* compute back the fifo rate to handle truncation cases */ fifo_rate =INV_MPU6050_DIVIDER_TO_FIFO_RATE (d); + fifo_period =NSEC_PER_SEC / fifo_rate;mutex_lock (&st->lock);if (d == st->chip_config.divider) { result =0 ; goto fifo_rate_fail_unlock; } + + fifo_on = st->chip_config.accl_fifo_enable || + st->chip_config.gyro_fifo_enable || + st->chip_config.magn_fifo_enable; + result =inv_sensors_timestamp_update_odr (&st->timestamp, fifo_period, fifo_on); +if (result) + goto fifo_rate_fail_unlock; + result =pm_runtime_resume_and_get (pdev);if (result) goto fifo_rate_fail_unlock;
@@ -1785,3 +1798,4 @@ EXPORT_NS_GPL_DEV_PM_OPS(inv_mpu_pmops, IIO_MPU6050) = {MODULE_AUTHOR ("Invensense Corporation" );MODULE_DESCRIPTION ("Invensense device MPU6050 driver" );MODULE_LICENSE ("GPL" ); +MODULE_IMPORT_NS (IIO_INV_SENSORS_TIMESTAMP );
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +3 -6
@@ -11,6 +11,7 @@#include <linux/mutex.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h> +#include <linux/iio/common/inv_sensors_timestamp.h> #include <linux/regmap.h> #include <linux/iio/sysfs.h> #include <linux/iio/kfifo_buf.h>
@@ -170,9 +171,7 @@ struct inv_mpu6050_hw {* @map regmap pointer. * @irq interrupt number. * @irq_mask the int_pin_cfg mask to configure interrupt type. -* @chip_period: chip internal period estimation (~1kHz). -* @it_timestamp: timestamp from previous interrupt. -* @data_timestamp: timestamp for next data sample. +* @timestamp: timestamping module * @vdd_supply: VDD voltage regulator for the chip. * @vddio_supply I/O voltage regulator for the chip. * @magn_disabled: magnetometer disabled for backward compatibility reason.
@@ -196,9 +195,7 @@ struct inv_mpu6050_state {int irq;u8 irq_mask;unsigned skip_samples; -s64 chip_period; -s64 it_timestamp; -s64 data_timestamp; +struct inv_sensors_timestamp timestamp;struct regulator *vdd_supply;struct regulator *vddio_supply;bool magn_disabled;
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +7 -76
109 lines not on this page · raw message
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +2 -1
@@ -106,7 +106,8 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable)int ret;if (enable) { - st->it_timestamp =0 ; +/* reset timestamping */ +inv_sensors_timestamp_reset (&st->timestamp);/* reset FIFO */ d = st->chip_config.user_ctrl |INV_MPU6050_BIT_FIFO_RST ; ret =regmap_write (st->map, st->reg->user_ctrl, d);
Signature · 1 line
2.34.1
Re: [PATCH 4/4] iio: imu: inv_mpu6050: use the common inv_sensors timestamp module
Wed, May 31, 2023 at 02:25:13PM +0000, [email protected] kirjoitti:
Quoted 4 lines
From: Jean-Baptiste Maneyrol <[email protected]>
Replace timestamping by the new common
inv_sensorstimestamp module.
...
Quoted 5 lines
#include <
linux/irq.h>
#include <linux/interrupt.h>#include <
linux/iio/iio.h>
+#include <linux/iio/common/inv_sensors_timestamp.h>
While at it, can you split it to a separate group of headers that may be located after generic linux/* ?
Also would be nice to keep them in order.
Quoted 11 lines
#include <
linux/acpi.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>#include <
linux/mutex.h>
#include <linux/iio/iio.h>
#include <linux/iio/buffer.h>
+#include <linux/iio/common/inv_sensors_timestamp.h>
#include <linux/regmap.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/kfifo_buf.h>
Same.
This actually a mess, but it's another story.
...
Quoted 3 lines
#include <
linux/interrupt.h>
#include <linux/poll.h>
#include <linux/math64.h>
+ Blank line
Quoted 1 line
+#include <
linux/iio/common/inv_sensors_timestamp.h>
+ Blank line.
Quoted 1 line
#include "
inv_mpu_iio.h"
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH 4/4] iio: imu: inv_mpu6050: use the common inv_sensors timestamp module
In reply to [email protected]Quoted 4 lines · On Wed, 31 May 2023 14:25:13 +0000 [email protected] wrote:
From: Jean-Baptiste Maneyrol <[email protected]>
Replace timestamping by the new common
inv_sensorstimestamp module.
Are there functional changes as a result of this, or were the two algorithms identical?
I don't mind changes, but should call out if there are any when unifying code like this,
Jonathan
Quoted 2 lines
Signed-off-by Jean-Baptiste Maneyrol <[email protected]>
Jean-Baptiste Maneyrol
maintainerRe: [PATCH 4/4] iio: imu: inv_mpu6050: use the common inv_sensors timestamp module
Hi Jonathan,
the 2 algorithms are very similar, but the new one in module is better (less jitter, better average value using a moving window, ...).
So switching to the new one will lead to better timestamping, while keeping a very similar approach.
Thanks,
JB
From: Jonathan Cameron <[email protected]>
Sent: Sunday, June 4, 2023 13:08
To: INV Git Commit <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>
Subject: Re: [PATCH 4/4] iio: imu: inv_mpu6050: use the common inv_sensors timestamp module
[CAUTION] This is an EXTERNAL email. Do not click links or open attachments unless you recognize the sender and know the content is safe.
======================================================================
Quoted 4 lines · On Wed, 31 May 2023 14:25:13 +0000 [email protected] wrote:
From: Jean-Baptiste Maneyrol <[email protected]>
Replace timestamping by the new common
inv_sensorstimestamp module.
Are there functional changes as a result of this, or were the two algorithms identical?
I don't mind changes, but should call out if there are any when unifying code like this,
Jonathan
Quoted 2 lines
Signed-off-by Jean-Baptiste Maneyrol <[email protected]>
Jonathan Cameron
maintainerRe: [PATCH 4/4] iio: imu: inv_mpu6050: use the common inv_sensors timestamp module
Quoted 5 lines · On Mon, 5 Jun 2023 19:09:51 +0000 Jean-Baptiste Maneyrol…
Hi Jonathan,
the 2 algorithms are very similar, but the new one in module is better (less jitter, better average value using a moving window, ...).
So switching to the new one will lead to better timestamping, while keeping a very similar approach.
That's fine. Add this info to the patch description for next version.
Thanks,
Jonathan
Quoted 31 lines
Thanks,
JBFrom: Jonathan Cameron <[email protected]>
Sent: Sunday, June 4, 2023 13:08
To: INV Git Commit <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>
Subject: Re: [PATCH 4/4] iio: imu:inv_mpu6050: use the commoninv_sensorstimestamp module
[CAUTION] This is an EXTERNAL email. Do not click links or open attachments unless you recognize the sender and know the content is safe.======================================================================
Quoted 4 lines · On Wed, 31 May 2023 14:25:13 +0000 [email protected] wrote:
From: Jean-Baptiste Maneyrol <[email protected]>
Replace timestamping by the new common
inv_sensorstimestamp module.Are there functional changes as a result of this, or were the two algorithms identical?
I don't mind changes, but should call out if there are any when unifying code like this,
Jonathan
Quoted 2 lines
Signed-off-by Jean-Baptiste Maneyrol <[email protected]
Wed, May 31, 2023 at 02:25:09PM +0000, [email protected] kirjoitti:
Quoted 11 lines
From: Jean-Baptiste Maneyrol <[email protected]>
The purpose if this series is to make timestamping from
inv_icm42600driver an independent module and use it for bothinv_icm42600andinv_mpu6050drivers.Create a new
inv_sensors_timestampcommon module based oninv_icm42600driver and use it in the 2 drivers.WARNING: this patch requires following commit in fixes-togreg
bbaae0c79ebd("iio: imu:inv_icm42600: fix timestamp reset")
This is so nicely prepared series, but I have a few style nit-picks (individually commented) and one to address, i.e. kernel.h inclusion.
With that addressed,
Thank you!
Signature · 2 lines
With Best Regards, Andy Shevchenko