diff mbox series

[2/4] iio: imu: inv_mpu6050: add WoM event inside accel channels

Message ID 20240225160027.200092-3-inv.git-commit@tdk.com (mailing list archive)
State Changes Requested
Headers show
Series Add WoM feature as an IIO event | expand

Commit Message

inv.git-commit@tdk.com Feb. 25, 2024, 4 p.m. UTC
From: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>

Add WoM (mag_adaptive rising) event in accel channels for all
chips >= MPU-6500. This requires to create new MPU-6500 channels
as default and MPU-6050 channels for older chips.

Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 132 ++++++++++++++-------
 1 file changed, 89 insertions(+), 43 deletions(-)

Comments

Jonathan Cameron March 3, 2024, 4:58 p.m. UTC | #1
On Sun, 25 Feb 2024 16:00:25 +0000
inv.git-commit@tdk.com wrote:

> From: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
> 
> Add WoM (mag_adaptive rising) event in accel channels for all
> chips >= MPU-6500. This requires to create new MPU-6500 channels
> as default and MPU-6050 channels for older chips.
> 
> Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Trivial comment inline - otherwise looks good beyond question of 
event type.

Jonathan

> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 132 ++++++++++++++-------
>  1 file changed, 89 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index fca7fc1ba4e2..d2544c758815 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -1303,23 +1303,34 @@ static const struct iio_chan_spec_ext_info inv_ext_info[] = {
>  	{ }
>  };
>  
> -#define INV_MPU6050_CHAN(_type, _channel2, _index)                    \
> -	{                                                             \
> -		.type = _type,                                        \
> -		.modified = 1,                                        \
> -		.channel2 = _channel2,                                \
> -		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
> -		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |	      \
> -				      BIT(IIO_CHAN_INFO_CALIBBIAS),   \
> -		.scan_index = _index,                                 \
> -		.scan_type = {                                        \
> -				.sign = 's',                          \
> -				.realbits = 16,                       \
> -				.storagebits = 16,                    \
> -				.shift = 0,                           \
> -				.endianness = IIO_BE,                 \
> -			     },                                       \
> -		.ext_info = inv_ext_info,                             \
> +static const struct iio_event_spec inv_accel_events[] = {
> +	{
> +		.type = IIO_EV_TYPE_MAG_ADAPTIVE,
> +		.dir = IIO_EV_DIR_RISING,
> +		.mask_shared_by_type = BIT(IIO_EV_INFO_ENABLE) |
> +				       BIT(IIO_EV_INFO_VALUE),
> +	},
> +};
> +
> +#define INV_MPU6050_CHAN(_type, _channel2, _index, _events, _events_nb) \
> +	{                                                               \
> +		.type = _type,                                          \
> +		.modified = 1,                                          \
> +		.channel2 = _channel2,                                  \
> +		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |	        \
> +				      BIT(IIO_CHAN_INFO_CALIBBIAS),     \
> +		.event_spec = _events,                                  \
> +		.num_event_specs = _events_nb,                          \
> +		.scan_index = _index,                                   \
> +		.scan_type = {                                          \
> +				.sign = 's',                            \
Maybe take opportunity to tidy up these intents. One tab is enough.
			.sign = 's',

> +				.realbits = 16,                         \
> +				.storagebits = 16,                      \
> +				.shift = 0,                             \
> +				.endianness = IIO_BE,                   \
> +			     },                                         \
		},
> +		.ext_info = inv_ext_info,                               \
>  	}
diff mbox series

Patch

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index fca7fc1ba4e2..d2544c758815 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1303,23 +1303,34 @@  static const struct iio_chan_spec_ext_info inv_ext_info[] = {
 	{ }
 };
 
-#define INV_MPU6050_CHAN(_type, _channel2, _index)                    \
-	{                                                             \
-		.type = _type,                                        \
-		.modified = 1,                                        \
-		.channel2 = _channel2,                                \
-		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
-		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |	      \
-				      BIT(IIO_CHAN_INFO_CALIBBIAS),   \
-		.scan_index = _index,                                 \
-		.scan_type = {                                        \
-				.sign = 's',                          \
-				.realbits = 16,                       \
-				.storagebits = 16,                    \
-				.shift = 0,                           \
-				.endianness = IIO_BE,                 \
-			     },                                       \
-		.ext_info = inv_ext_info,                             \
+static const struct iio_event_spec inv_accel_events[] = {
+	{
+		.type = IIO_EV_TYPE_MAG_ADAPTIVE,
+		.dir = IIO_EV_DIR_RISING,
+		.mask_shared_by_type = BIT(IIO_EV_INFO_ENABLE) |
+				       BIT(IIO_EV_INFO_VALUE),
+	},
+};
+
+#define INV_MPU6050_CHAN(_type, _channel2, _index, _events, _events_nb) \
+	{                                                               \
+		.type = _type,                                          \
+		.modified = 1,                                          \
+		.channel2 = _channel2,                                  \
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |	        \
+				      BIT(IIO_CHAN_INFO_CALIBBIAS),     \
+		.event_spec = _events,                                  \
+		.num_event_specs = _events_nb,                          \
+		.scan_index = _index,                                   \
+		.scan_type = {                                          \
+				.sign = 's',                            \
+				.realbits = 16,                         \
+				.storagebits = 16,                      \
+				.shift = 0,                             \
+				.endianness = IIO_BE,                   \
+			     },                                         \
+		.ext_info = inv_ext_info,                               \
 	}
 
 #define INV_MPU6050_TEMP_CHAN(_index)				\
@@ -1338,18 +1349,35 @@  static const struct iio_chan_spec_ext_info inv_ext_info[] = {
 		},						\
 	}
 
-static const struct iio_chan_spec inv_mpu_channels[] = {
+static const struct iio_chan_spec inv_mpu6050_channels[] = {
+	IIO_CHAN_SOFT_TIMESTAMP(INV_MPU6050_SCAN_TIMESTAMP),
+
+	INV_MPU6050_TEMP_CHAN(INV_MPU6050_SCAN_TEMP),
+
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z, NULL, 0),
+
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z, NULL, 0),
+};
+
+static const struct iio_chan_spec inv_mpu6500_channels[] = {
 	IIO_CHAN_SOFT_TIMESTAMP(INV_MPU6050_SCAN_TIMESTAMP),
 
 	INV_MPU6050_TEMP_CHAN(INV_MPU6050_SCAN_TEMP),
 
-	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X),
-	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y),
-	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z, NULL, 0),
 
-	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X),
-	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y),
-	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X,
+			 inv_accel_events, ARRAY_SIZE(inv_accel_events)),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y,
+			 inv_accel_events, ARRAY_SIZE(inv_accel_events)),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z,
+			 inv_accel_events, ARRAY_SIZE(inv_accel_events)),
 };
 
 #define INV_MPU6050_SCAN_MASK_3AXIS_ACCEL	\
@@ -1401,13 +1429,13 @@  static const struct iio_chan_spec inv_mpu9150_channels[] = {
 
 	INV_MPU6050_TEMP_CHAN(INV_MPU6050_SCAN_TEMP),
 
-	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X),
-	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y),
-	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z, NULL, 0),
 
-	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X),
-	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y),
-	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z, NULL, 0),
 
 	/* Magnetometer resolution is 13 bits */
 	INV_MPU9X50_MAGN_CHAN(IIO_MOD_X, 13, INV_MPU9X50_SCAN_MAGN_X),
@@ -1420,13 +1448,16 @@  static const struct iio_chan_spec inv_mpu9250_channels[] = {
 
 	INV_MPU6050_TEMP_CHAN(INV_MPU6050_SCAN_TEMP),
 
-	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X),
-	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y),
-	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y, NULL, 0),
+	INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z, NULL, 0),
 
-	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X),
-	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y),
-	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X,
+			 inv_accel_events, ARRAY_SIZE(inv_accel_events)),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y,
+			 inv_accel_events, ARRAY_SIZE(inv_accel_events)),
+	INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z,
+			 inv_accel_events, ARRAY_SIZE(inv_accel_events)),
 
 	/* Magnetometer resolution is 16 bits */
 	INV_MPU9X50_MAGN_CHAN(IIO_MOD_X, 16, INV_MPU9X50_SCAN_MAGN_X),
@@ -1831,6 +1862,12 @@  int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 		return result;
 
 	switch (chip_type) {
+	case INV_MPU6000:
+	case INV_MPU6050:
+		indio_dev->channels = inv_mpu6050_channels;
+		indio_dev->num_channels = ARRAY_SIZE(inv_mpu6050_channels);
+		indio_dev->available_scan_masks = inv_mpu_scan_masks;
+		break;
 	case INV_MPU9150:
 		indio_dev->channels = inv_mpu9150_channels;
 		indio_dev->num_channels = ARRAY_SIZE(inv_mpu9150_channels);
@@ -1844,13 +1881,13 @@  int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 		break;
 	case INV_ICM20600:
 	case INV_ICM20602:
-		indio_dev->channels = inv_mpu_channels;
-		indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels);
+		indio_dev->channels = inv_mpu6500_channels;
+		indio_dev->num_channels = ARRAY_SIZE(inv_mpu6500_channels);
 		indio_dev->available_scan_masks = inv_icm20602_scan_masks;
 		break;
 	default:
-		indio_dev->channels = inv_mpu_channels;
-		indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels);
+		indio_dev->channels = inv_mpu6500_channels;
+		indio_dev->num_channels = ARRAY_SIZE(inv_mpu6500_channels);
 		indio_dev->available_scan_masks = inv_mpu_scan_masks;
 		break;
 	}
@@ -1859,9 +1896,18 @@  int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 	 * auxiliary device in use. Otherwise Going back to 6-axis only.
 	 */
 	if (st->magn_disabled) {
-		indio_dev->channels = inv_mpu_channels;
-		indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels);
-		indio_dev->available_scan_masks = inv_mpu_scan_masks;
+		switch (chip_type) {
+		case INV_MPU9150:
+			indio_dev->channels = inv_mpu6050_channels;
+			indio_dev->num_channels = ARRAY_SIZE(inv_mpu6050_channels);
+			indio_dev->available_scan_masks = inv_mpu_scan_masks;
+			break;
+		default:
+			indio_dev->channels = inv_mpu6500_channels;
+			indio_dev->num_channels = ARRAY_SIZE(inv_mpu6500_channels);
+			indio_dev->available_scan_masks = inv_mpu_scan_masks;
+			break;
+		}
 	}
 
 	indio_dev->info = &mpu_info;