All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro
@ 2021-05-17 23:33 Linus Walleij
  2021-05-17 23:33 ` [PATCH 2/5 v2] iio: accel: st_sensors: Support generic mounting matrix Linus Walleij
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Linus Walleij @ 2021-05-17 23:33 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Linus Walleij, Andy Shevchenko, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

Extend ST_SENSORS_LSM_CHANNELS() to a version that will accept extended
attributes named ST_SENSORS_LSM_CHANNELS_EXT() and wrap the former as a
specialized version of the former.

Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Denis Ciocca <denis.ciocca@st.com>
Cc: Daniel Drake <drake@endlessm.com>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- New helper patch from Stephan.
---
 include/linux/iio/common/st_sensors.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 33e939977444..704217a5c3ba 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -46,8 +46,8 @@
 #define ST_SENSORS_MAX_NAME			17
 #define ST_SENSORS_MAX_4WAI			8
 
-#define ST_SENSORS_LSM_CHANNELS(device_type, mask, index, mod, \
-					ch2, s, endian, rbits, sbits, addr) \
+#define ST_SENSORS_LSM_CHANNELS_EXT(device_type, mask, index, mod, \
+				    ch2, s, endian, rbits, sbits, addr, ext) \
 { \
 	.type = device_type, \
 	.modified = mod, \
@@ -63,8 +63,14 @@
 		.storagebits = sbits, \
 		.endianness = endian, \
 	}, \
+	.ext_info = ext, \
 }
 
+#define ST_SENSORS_LSM_CHANNELS(device_type, mask, index, mod, \
+				ch2, s, endian, rbits, sbits, addr)	\
+	ST_SENSORS_LSM_CHANNELS_EXT(device_type, mask, index, mod,	\
+				    ch2, s, endian, rbits, sbits, addr, NULL)
+
 #define ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL() \
 		IIO_DEV_ATTR_SAMP_FREQ_AVAIL( \
 			st_sensors_sysfs_sampling_frequency_avail)
-- 
2.31.1


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

* [PATCH 2/5 v2] iio: accel: st_sensors: Support generic mounting matrix
  2021-05-17 23:33 [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Linus Walleij
@ 2021-05-17 23:33 ` Linus Walleij
  2021-05-18 11:03   ` Andy Shevchenko
  2021-05-17 23:33 ` [PATCH 3/5 v2] iio: accel: st_sensors: Stop copying channels Linus Walleij
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Linus Walleij @ 2021-05-17 23:33 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Linus Walleij, Andy Shevchenko, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

The ST accelerators support a special type of quirky mounting matrix found
in ACPI systems, but not a generic mounting matrix such as from the device
tree.

Augment the ACPI hack to be a bit more generic and accept a mounting
matrix from device properties.

This makes it possible to fix orientation on the Ux500 HREF device.

Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Denis Ciocca <denis.ciocca@st.com>
Cc: Daniel Drake <drake@endlessm.com>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Make the .mount_matrix member of st_sensor_data a full member
  instead of a pointer so we get rid of a bunch of unneeded
  allocations that could fail.
- Make a drive-by fix to the kerneldoc.
- Use the new ST_SENSORS_LSM_CHANNELS_EXT() to define the channels
  with the extended attribute for mounting matrix.
- Demote the error message at the end of apply_acpi_orientation()
  to dev_dbg() and only print it of ret != 0.
---
 drivers/iio/accel/st_accel_core.c     | 110 +++++++++++++-------------
 include/linux/iio/common/st_sensors.h |   4 +-
 2 files changed, 60 insertions(+), 54 deletions(-)

diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 43c50167d220..8044b8ae7ead 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -41,51 +41,74 @@
 #define ST_ACCEL_FS_AVL_200G			200
 #define ST_ACCEL_FS_AVL_400G			400
 
+static const struct iio_mount_matrix *
+st_accel_get_mount_matrix(const struct iio_dev *indio_dev,
+			  const struct iio_chan_spec *chan)
+{
+	struct st_sensor_data *adata = iio_priv(indio_dev);
+
+	return &adata->mount_matrix;
+}
+
+static const struct iio_chan_spec_ext_info st_accel_mount_matrix_ext_info[] = {
+	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_accel_get_mount_matrix),
+	{ },
+};
+
 static const struct iio_chan_spec st_accel_8bit_channels[] = {
-	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 8, 8,
-			ST_ACCEL_DEFAULT_OUT_X_L_ADDR+1),
-	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
+			ST_ACCEL_DEFAULT_OUT_X_L_ADDR+1,
+			st_accel_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 8, 8,
-			ST_ACCEL_DEFAULT_OUT_Y_L_ADDR+1),
-	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
+			ST_ACCEL_DEFAULT_OUT_Y_L_ADDR+1,
+			st_accel_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 8, 8,
-			ST_ACCEL_DEFAULT_OUT_Z_L_ADDR+1),
+			ST_ACCEL_DEFAULT_OUT_Z_L_ADDR+1,
+			st_accel_mount_matrix_ext_info),
 	IIO_CHAN_SOFT_TIMESTAMP(3)
 };
 
 static const struct iio_chan_spec st_accel_12bit_channels[] = {
-	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 12, 16,
-			ST_ACCEL_DEFAULT_OUT_X_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
+			ST_ACCEL_DEFAULT_OUT_X_L_ADDR,
+			st_accel_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 12, 16,
-			ST_ACCEL_DEFAULT_OUT_Y_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
+			ST_ACCEL_DEFAULT_OUT_Y_L_ADDR,
+			st_accel_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 12, 16,
-			ST_ACCEL_DEFAULT_OUT_Z_L_ADDR),
+			ST_ACCEL_DEFAULT_OUT_Z_L_ADDR,
+			st_accel_mount_matrix_ext_info),
 	IIO_CHAN_SOFT_TIMESTAMP(3)
 };
 
 static const struct iio_chan_spec st_accel_16bit_channels[] = {
-	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
-			ST_ACCEL_DEFAULT_OUT_X_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
+			ST_ACCEL_DEFAULT_OUT_X_L_ADDR,
+			st_accel_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
-			ST_ACCEL_DEFAULT_OUT_Y_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
+			ST_ACCEL_DEFAULT_OUT_Y_L_ADDR,
+			st_accel_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
-			ST_ACCEL_DEFAULT_OUT_Z_L_ADDR),
+			ST_ACCEL_DEFAULT_OUT_Z_L_ADDR,
+			st_accel_mount_matrix_ext_info),
 	IIO_CHAN_SOFT_TIMESTAMP(3)
 };
 
@@ -1070,25 +1093,10 @@ static const struct iio_trigger_ops st_accel_trigger_ops = {
 #endif
 
 #ifdef CONFIG_ACPI
-static const struct iio_mount_matrix *
-get_mount_matrix(const struct iio_dev *indio_dev,
-		 const struct iio_chan_spec *chan)
-{
-	struct st_sensor_data *adata = iio_priv(indio_dev);
-
-	return adata->mount_matrix;
-}
-
-static const struct iio_chan_spec_ext_info mount_matrix_ext_info[] = {
-	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, get_mount_matrix),
-	{ },
-};
-
 /* Read ST-specific _ONT orientation data from ACPI and generate an
  * appropriate mount matrix.
  */
-static int apply_acpi_orientation(struct iio_dev *indio_dev,
-				  struct iio_chan_spec *channels)
+static int apply_acpi_orientation(struct iio_dev *indio_dev)
 {
 	struct st_sensor_data *adata = iio_priv(indio_dev);
 	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
@@ -1177,14 +1185,6 @@ static int apply_acpi_orientation(struct iio_dev *indio_dev,
 	}
 
 	/* Convert our integer matrix to a string-based iio_mount_matrix */
-	adata->mount_matrix = devm_kmalloc(&indio_dev->dev,
-					   sizeof(*adata->mount_matrix),
-					   GFP_KERNEL);
-	if (!adata->mount_matrix) {
-		ret = -ENOMEM;
-		goto out;
-	}
-
 	for (i = 0; i < 3; i++) {
 		for (j = 0; j < 3; j++) {
 			int matrix_val = final_ont[i][j];
@@ -1203,26 +1203,25 @@ static int apply_acpi_orientation(struct iio_dev *indio_dev,
 			default:
 				goto out;
 			}
-			adata->mount_matrix->rotation[i * 3 + j] = str_value;
+			adata->mount_matrix.rotation[i * 3 + j] = str_value;
 		}
 	}
 
-	/* Expose the mount matrix via ext_info */
-	for (i = 0; i < indio_dev->num_channels; i++)
-		channels[i].ext_info = mount_matrix_ext_info;
-
 	ret = 0;
 	dev_info(&indio_dev->dev, "computed mount matrix from ACPI\n");
 
 out:
 	kfree(buffer.pointer);
+	if (ret)
+		dev_dbg(&indio_dev->dev,
+			"failed to apply ACPI orientation data: %d\n", ret);
+
 	return ret;
 }
 #else /* !CONFIG_ACPI */
-static int apply_acpi_orientation(struct iio_dev *indio_dev,
-				  struct iio_chan_spec *channels)
+static int apply_acpi_orientation(struct iio_dev *indio_dev)
 {
-	return 0;
+	return -EINVAL;
 }
 #endif
 
@@ -1275,9 +1274,14 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
 		goto st_accel_power_off;
 	}
 
-	if (apply_acpi_orientation(indio_dev, channels))
-		dev_warn(&indio_dev->dev,
-			 "failed to apply ACPI orientation data: %d\n", err);
+	/* First try ACPI orientation then try the generic function */
+	err = apply_acpi_orientation(indio_dev);
+	if (err) {
+		err = iio_read_mount_matrix(adata->dev, "mount-matrix",
+					    &adata->mount_matrix);
+		if (err)
+			goto st_accel_power_off;
+	}
 
 	indio_dev->channels = channels;
 	adata->current_fullscale = &adata->sensor_settings->fs.fs_avl[0];
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 704217a5c3ba..9ac456973688 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -13,6 +13,7 @@
 #include <linux/i2c.h>
 #include <linux/spi/spi.h>
 #include <linux/irqreturn.h>
+#include <linux/iio/iio.h>
 #include <linux/iio/trigger.h>
 #include <linux/bitops.h>
 #include <linux/regulator/consumer.h>
@@ -219,6 +220,7 @@ struct st_sensor_settings {
  * struct st_sensor_data - ST sensor device status
  * @dev: Pointer to instance of struct device (I2C or SPI).
  * @trig: The trigger in use by the core driver.
+ * @mount_matrix: The mounting matrix of the sensor.
  * @sensor_settings: Pointer to the specific sensor settings in use.
  * @current_fullscale: Maximum range of measure by the sensor.
  * @vdd: Pointer to sensor's Vdd power supply
@@ -238,7 +240,7 @@ struct st_sensor_settings {
 struct st_sensor_data {
 	struct device *dev;
 	struct iio_trigger *trig;
-	struct iio_mount_matrix *mount_matrix;
+	struct iio_mount_matrix mount_matrix;
 	struct st_sensor_settings *sensor_settings;
 	struct st_sensor_fullscale_avl *current_fullscale;
 	struct regulator *vdd;
-- 
2.31.1


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

* [PATCH 3/5 v2] iio: accel: st_sensors: Stop copying channels
  2021-05-17 23:33 [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Linus Walleij
  2021-05-17 23:33 ` [PATCH 2/5 v2] iio: accel: st_sensors: Support generic mounting matrix Linus Walleij
@ 2021-05-17 23:33 ` Linus Walleij
  2021-05-17 23:33 ` [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix Linus Walleij
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Linus Walleij @ 2021-05-17 23:33 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Linus Walleij, Andy Shevchenko, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

The channels were copied only so that the .ext_info member should become
assignable. We now have compile-time static assignment so drop this code.

Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Denis Ciocca <denis.ciocca@st.com>
Cc: Daniel Drake <drake@endlessm.com>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Improvement found by Stephan.
---
 drivers/iio/accel/st_accel_core.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 8044b8ae7ead..fa06a3ef84e7 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -1247,8 +1247,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
 {
 	struct st_sensor_data *adata = iio_priv(indio_dev);
 	struct st_sensors_platform_data *pdata = dev_get_platdata(adata->dev);
-	struct iio_chan_spec *channels;
-	size_t channels_size;
 	int err;
 
 	indio_dev->modes = INDIO_DIRECT_MODE;
@@ -1263,17 +1261,9 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
 		goto st_accel_power_off;
 
 	adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS;
+	indio_dev->channels = adata->sensor_settings->ch;
 	indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
 
-	channels_size = indio_dev->num_channels * sizeof(struct iio_chan_spec);
-	channels = devm_kmemdup(&indio_dev->dev,
-				adata->sensor_settings->ch,
-				channels_size, GFP_KERNEL);
-	if (!channels) {
-		err = -ENOMEM;
-		goto st_accel_power_off;
-	}
-
 	/* First try ACPI orientation then try the generic function */
 	err = apply_acpi_orientation(indio_dev);
 	if (err) {
@@ -1283,7 +1273,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
 			goto st_accel_power_off;
 	}
 
-	indio_dev->channels = channels;
 	adata->current_fullscale = &adata->sensor_settings->fs.fs_avl[0];
 	adata->odr = adata->sensor_settings->odr.odr_avl[0].hz;
 
-- 
2.31.1


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

* [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix
  2021-05-17 23:33 [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Linus Walleij
  2021-05-17 23:33 ` [PATCH 2/5 v2] iio: accel: st_sensors: Support generic mounting matrix Linus Walleij
  2021-05-17 23:33 ` [PATCH 3/5 v2] iio: accel: st_sensors: Stop copying channels Linus Walleij
@ 2021-05-17 23:33 ` Linus Walleij
  2021-05-18  9:01   ` Stephan Gerhold
  2021-05-18 11:05   ` Andy Shevchenko
  2021-05-17 23:33 ` [PATCH 5/5 v2] iio: gyro: st_gyro: " Linus Walleij
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 13+ messages in thread
From: Linus Walleij @ 2021-05-17 23:33 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Linus Walleij, Andy Shevchenko, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

Add support to read and present the mounting matrix on ST magnetometers.

Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Denis Ciocca <denis.ciocca@st.com>
Cc: Daniel Drake <drake@endlessm.com>
Cc: Stephan Gerhold <stephan@gerhold.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- New patch because why not.
---
 drivers/iio/magnetometer/st_magn_core.c | 64 ++++++++++++++++++-------
 1 file changed, 46 insertions(+), 18 deletions(-)

diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 71faebd07feb..fa587975cb85 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -53,51 +53,74 @@
 #define ST_MAGN_3_OUT_Y_L_ADDR			0x6a
 #define ST_MAGN_3_OUT_Z_L_ADDR			0x6c
 
+static const struct iio_mount_matrix *
+st_magn_get_mount_matrix(const struct iio_dev *indio_dev,
+			 const struct iio_chan_spec *chan)
+{
+	struct st_sensor_data *mdata = iio_priv(indio_dev);
+
+	return &mdata->mount_matrix;
+}
+
+static const struct iio_chan_spec_ext_info st_magn_mount_matrix_ext_info[] = {
+	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_magn_get_mount_matrix),
+	{ },
+};
+
 static const struct iio_chan_spec st_magn_16bit_channels[] = {
-	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_BE, 16, 16,
-			ST_MAGN_DEFAULT_OUT_X_H_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+			ST_MAGN_DEFAULT_OUT_X_H_ADDR,
+			st_magn_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_BE, 16, 16,
-			ST_MAGN_DEFAULT_OUT_Y_H_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+			ST_MAGN_DEFAULT_OUT_Y_H_ADDR,
+			st_magn_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_BE, 16, 16,
-			ST_MAGN_DEFAULT_OUT_Z_H_ADDR),
+			ST_MAGN_DEFAULT_OUT_Z_H_ADDR,
+			st_magn_mount_matrix_ext_info),
 	IIO_CHAN_SOFT_TIMESTAMP(3)
 };
 
 static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
-	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
-			ST_MAGN_2_OUT_X_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+			ST_MAGN_2_OUT_X_L_ADDR,
+			st_magn_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
-			ST_MAGN_2_OUT_Y_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+			ST_MAGN_2_OUT_Y_L_ADDR,
+			st_magn_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
-			ST_MAGN_2_OUT_Z_L_ADDR),
+			ST_MAGN_2_OUT_Z_L_ADDR,
+			st_magn_mount_matrix_ext_info),
 	IIO_CHAN_SOFT_TIMESTAMP(3)
 };
 
 static const struct iio_chan_spec st_magn_3_16bit_channels[] = {
-	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
-			ST_MAGN_3_OUT_X_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+			ST_MAGN_3_OUT_X_L_ADDR,
+			st_magn_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
-			ST_MAGN_3_OUT_Y_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+			ST_MAGN_3_OUT_Y_L_ADDR,
+			st_magn_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
-			ST_MAGN_3_OUT_Z_L_ADDR),
+			ST_MAGN_3_OUT_Z_L_ADDR,
+			st_magn_mount_matrix_ext_info),
 	IIO_CHAN_SOFT_TIMESTAMP(3)
 };
 
@@ -507,6 +530,11 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
 	indio_dev->channels = mdata->sensor_settings->ch;
 	indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
 
+	err = iio_read_mount_matrix(mdata->dev, "mount-matrix",
+				    &mdata->mount_matrix);
+	if (err)
+		goto st_magn_power_off;
+
 	mdata->current_fullscale = &mdata->sensor_settings->fs.fs_avl[0];
 	mdata->odr = mdata->sensor_settings->odr.odr_avl[0].hz;
 
-- 
2.31.1


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

* [PATCH 5/5 v2] iio: gyro: st_gyro: Support mount matrix
  2021-05-17 23:33 [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Linus Walleij
                   ` (2 preceding siblings ...)
  2021-05-17 23:33 ` [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix Linus Walleij
@ 2021-05-17 23:33 ` Linus Walleij
  2021-05-18 11:06   ` Andy Shevchenko
  2021-05-18 18:06   ` Jonathan Cameron
  2021-05-18  9:04 ` [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Andy Shevchenko
  2021-05-18 11:07 ` Andy Shevchenko
  5 siblings, 2 replies; 13+ messages in thread
From: Linus Walleij @ 2021-05-17 23:33 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Linus Walleij, Andy Shevchenko, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

Add support to read and present the mounting matrix on ST gyroscopes.

Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Denis Ciocca <denis.ciocca@st.com>
Cc: Daniel Drake <drake@endlessm.com>
Cc: Stephan Gerhold <stephan@gerhold.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- New patch because why not.
---
 drivers/iio/gyro/st_gyro_core.c | 34 +++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index c8aa051995d3..bf06a531bed3 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -37,19 +37,36 @@
 #define ST_GYRO_FS_AVL_500DPS			500
 #define ST_GYRO_FS_AVL_2000DPS			2000
 
+static const struct iio_mount_matrix *
+st_gyro_get_mount_matrix(const struct iio_dev *indio_dev,
+			 const struct iio_chan_spec *chan)
+{
+	struct st_sensor_data *gdata = iio_priv(indio_dev);
+
+	return &gdata->mount_matrix;
+}
+
+static const struct iio_chan_spec_ext_info st_gyro_mount_matrix_ext_info[] = {
+	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_gyro_get_mount_matrix),
+	{ },
+};
+
 static const struct iio_chan_spec st_gyro_16bit_channels[] = {
-	ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ANGL_VEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
-			ST_GYRO_DEFAULT_OUT_X_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
+			ST_GYRO_DEFAULT_OUT_X_L_ADDR,
+			st_gyro_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ANGL_VEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
-			ST_GYRO_DEFAULT_OUT_Y_L_ADDR),
-	ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
+			ST_GYRO_DEFAULT_OUT_Y_L_ADDR,
+			st_gyro_mount_matrix_ext_info),
+	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ANGL_VEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
-			ST_GYRO_DEFAULT_OUT_Z_L_ADDR),
+			ST_GYRO_DEFAULT_OUT_Z_L_ADDR,
+			st_gyro_mount_matrix_ext_info),
 	IIO_CHAN_SOFT_TIMESTAMP(3)
 };
 
@@ -478,6 +495,11 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
 	indio_dev->channels = gdata->sensor_settings->ch;
 	indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
 
+	err = iio_read_mount_matrix(gdata->dev, "mount-matrix",
+				    &gdata->mount_matrix);
+	if (err)
+		goto st_gyro_power_off;
+
 	gdata->current_fullscale = &gdata->sensor_settings->fs.fs_avl[0];
 	gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz;
 
-- 
2.31.1


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

* Re: [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix
  2021-05-17 23:33 ` [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix Linus Walleij
@ 2021-05-18  9:01   ` Stephan Gerhold
  2021-05-18 18:09     ` Jonathan Cameron
  2021-05-18 11:05   ` Andy Shevchenko
  1 sibling, 1 reply; 13+ messages in thread
From: Stephan Gerhold @ 2021-05-18  9:01 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Jonathan Cameron, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Andy Shevchenko, Denis Ciocca,
	Daniel Drake

Hi,

On Tue, May 18, 2021 at 01:33:21AM +0200, Linus Walleij wrote:
> Add support to read and present the mounting matrix on ST magnetometers.
> 
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Denis Ciocca <denis.ciocca@st.com>
> Cc: Daniel Drake <drake@endlessm.com>
> Cc: Stephan Gerhold <stephan@gerhold.net>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v1->v2:
> - New patch because why not.

Thanks for patching the other ST drivers as well!
That reminds me about something I was thinking about when I was making
the changes a week ago. :)

> ---
>  drivers/iio/magnetometer/st_magn_core.c | 64 ++++++++++++++++++-------
>  1 file changed, 46 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
> index 71faebd07feb..fa587975cb85 100644
> --- a/drivers/iio/magnetometer/st_magn_core.c
> +++ b/drivers/iio/magnetometer/st_magn_core.c
> @@ -53,51 +53,74 @@
>  #define ST_MAGN_3_OUT_Y_L_ADDR			0x6a
>  #define ST_MAGN_3_OUT_Z_L_ADDR			0x6c
>  
> +static const struct iio_mount_matrix *
> +st_magn_get_mount_matrix(const struct iio_dev *indio_dev,
> +			 const struct iio_chan_spec *chan)
> +{
> +	struct st_sensor_data *mdata = iio_priv(indio_dev);
> +
> +	return &mdata->mount_matrix;
> +}
> +
> +static const struct iio_chan_spec_ext_info st_magn_mount_matrix_ext_info[] = {
> +	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_magn_get_mount_matrix),
> +	{ },
> +};
> +

I'm not sure if this is worth it (or even a particularly good idea),
but we could share this function and struct in st_sensors_core.c
since it's exactly the same for st_accel/magn/gyro AFAICT.
(It just operates on the common struct st_sensor_data).

This could be done with a macro like ST_SENSORS_LSM_CHANNELS_MOUNT_MATRIX(...)
(maybe a bit long and clumsy) instead of _EXT(...) and pointing to
a struct iio_chan_spec_ext_info somewhere in st_sensors_core.c.

The disadvantage however is that st_accel/magn/gyro couldn't add other
(sensor-specific) ext_info later. Not sure if that is realistic though.

I wasn't entirely sure myself that's why I went with the _EXT(...)
instead (especially since I only wanted to patch st_accel).
Just wanted to mention it :)

Stephan

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

* Re: [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro
  2021-05-17 23:33 [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Linus Walleij
                   ` (3 preceding siblings ...)
  2021-05-17 23:33 ` [PATCH 5/5 v2] iio: gyro: st_gyro: " Linus Walleij
@ 2021-05-18  9:04 ` Andy Shevchenko
  2021-05-18 11:07 ` Andy Shevchenko
  5 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2021-05-18  9:04 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Jonathan Cameron, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

On Tue, May 18, 2021 at 01:33:18AM +0200, Linus Walleij wrote:
> Extend ST_SENSORS_LSM_CHANNELS() to a version that will accept extended
> attributes named ST_SENSORS_LSM_CHANNELS_EXT() and wrap the former as a
> specialized version of the former.

Missed to Cc Hans?

Btw, I have scripted the series submission [1]. Feel free to use it, I found it
much easier and less error prone (like forgetting maintainers or key contributors).

[1]: https://github.com/andy-shev/home-bin-tools/blob/master/ge2maintainer.sh

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 2/5 v2] iio: accel: st_sensors: Support generic mounting matrix
  2021-05-17 23:33 ` [PATCH 2/5 v2] iio: accel: st_sensors: Support generic mounting matrix Linus Walleij
@ 2021-05-18 11:03   ` Andy Shevchenko
  0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2021-05-18 11:03 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Jonathan Cameron, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

On Tue, May 18, 2021 at 01:33:19AM +0200, Linus Walleij wrote:
> The ST accelerators support a special type of quirky mounting matrix found
> in ACPI systems, but not a generic mounting matrix such as from the device
> tree.
> 
> Augment the ACPI hack to be a bit more generic and accept a mounting
> matrix from device properties.
> 
> This makes it possible to fix orientation on the Ux500 HREF device.

...

> +static const struct iio_chan_spec_ext_info st_accel_mount_matrix_ext_info[] = {
> +	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_accel_get_mount_matrix),
> +	{ },

Comma is not needed for terminator lines.

> +};

...

> +	/* First try ACPI orientation then try the generic function */

It's a bit confusing, because the generic also tries ACPI.

Perhaps "...try specific ACPI methods to retrieve orientation, then..."?

> +	err = apply_acpi_orientation(indio_dev);
> +	if (err) {
> +		err = iio_read_mount_matrix(adata->dev, "mount-matrix",
> +					    &adata->mount_matrix);
> +		if (err)
> +			goto st_accel_power_off;
> +	}

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix
  2021-05-17 23:33 ` [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix Linus Walleij
  2021-05-18  9:01   ` Stephan Gerhold
@ 2021-05-18 11:05   ` Andy Shevchenko
  1 sibling, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2021-05-18 11:05 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Jonathan Cameron, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

On Tue, May 18, 2021 at 01:33:21AM +0200, Linus Walleij wrote:
> Add support to read and present the mounting matrix on ST magnetometers.

...

> +static const struct iio_chan_spec_ext_info st_magn_mount_matrix_ext_info[] = {
> +	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_magn_get_mount_matrix),
> +	{ },

No need to have comma in terminator line.

> +};

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 5/5 v2] iio: gyro: st_gyro: Support mount matrix
  2021-05-17 23:33 ` [PATCH 5/5 v2] iio: gyro: st_gyro: " Linus Walleij
@ 2021-05-18 11:06   ` Andy Shevchenko
  2021-05-18 18:06   ` Jonathan Cameron
  1 sibling, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2021-05-18 11:06 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Jonathan Cameron, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

On Tue, May 18, 2021 at 01:33:22AM +0200, Linus Walleij wrote:
> Add support to read and present the mounting matrix on ST gyroscopes.

...

> +static const struct iio_chan_spec_ext_info st_gyro_mount_matrix_ext_info[] = {
> +	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_gyro_get_mount_matrix),
> +	{ },

Unneeded comma.

> +};

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro
  2021-05-17 23:33 [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Linus Walleij
                   ` (4 preceding siblings ...)
  2021-05-18  9:04 ` [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Andy Shevchenko
@ 2021-05-18 11:07 ` Andy Shevchenko
  5 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2021-05-18 11:07 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Jonathan Cameron, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Denis Ciocca, Daniel Drake,
	Stephan Gerhold

On Tue, May 18, 2021 at 01:33:18AM +0200, Linus Walleij wrote:
> Extend ST_SENSORS_LSM_CHANNELS() to a version that will accept extended
> attributes named ST_SENSORS_LSM_CHANNELS_EXT() and wrap the former as a
> specialized version of the former.

After addressing comments

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

for the entire series.

P.S. I think I can send one patch that should prepend your series, stay tuned!

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 5/5 v2] iio: gyro: st_gyro: Support mount matrix
  2021-05-17 23:33 ` [PATCH 5/5 v2] iio: gyro: st_gyro: " Linus Walleij
  2021-05-18 11:06   ` Andy Shevchenko
@ 2021-05-18 18:06   ` Jonathan Cameron
  1 sibling, 0 replies; 13+ messages in thread
From: Jonathan Cameron @ 2021-05-18 18:06 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Andy Shevchenko, Denis Ciocca,
	Daniel Drake, Stephan Gerhold

On Tue, 18 May 2021 01:33:22 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> Add support to read and present the mounting matrix on ST gyroscopes.
> 
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Denis Ciocca <denis.ciocca@st.com>
> Cc: Daniel Drake <drake@endlessm.com>
> Cc: Stephan Gerhold <stephan@gerhold.net>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

See below for the exciting reason I noticed, but this needs a rebase
on top of Andy's series that added support for the lsm9ds0
as it changed a bunch of stuff in probe / remove.

> ---
> ChangeLog v1->v2:
> - New patch because why not.
> ---
>  drivers/iio/gyro/st_gyro_core.c | 34 +++++++++++++++++++++++++++------
>  1 file changed, 28 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
> index c8aa051995d3..bf06a531bed3 100644
> --- a/drivers/iio/gyro/st_gyro_core.c
> +++ b/drivers/iio/gyro/st_gyro_core.c
> @@ -37,19 +37,36 @@
>  #define ST_GYRO_FS_AVL_500DPS			500
>  #define ST_GYRO_FS_AVL_2000DPS			2000
>  
> +static const struct iio_mount_matrix *
> +st_gyro_get_mount_matrix(const struct iio_dev *indio_dev,
> +			 const struct iio_chan_spec *chan)
> +{
> +	struct st_sensor_data *gdata = iio_priv(indio_dev);
> +
> +	return &gdata->mount_matrix;
> +}
> +
> +static const struct iio_chan_spec_ext_info st_gyro_mount_matrix_ext_info[] = {
> +	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_gyro_get_mount_matrix),
> +	{ },
> +};
> +
>  static const struct iio_chan_spec st_gyro_16bit_channels[] = {
> -	ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
> +	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ANGL_VEL,
>  			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
>  			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
> -			ST_GYRO_DEFAULT_OUT_X_L_ADDR),
> -	ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
> +			ST_GYRO_DEFAULT_OUT_X_L_ADDR,
> +			st_gyro_mount_matrix_ext_info),
> +	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ANGL_VEL,
>  			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
>  			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
> -			ST_GYRO_DEFAULT_OUT_Y_L_ADDR),
> -	ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
> +			ST_GYRO_DEFAULT_OUT_Y_L_ADDR,
> +			st_gyro_mount_matrix_ext_info),
> +	ST_SENSORS_LSM_CHANNELS_EXT(IIO_ANGL_VEL,
>  			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
>  			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
> -			ST_GYRO_DEFAULT_OUT_Z_L_ADDR),
> +			ST_GYRO_DEFAULT_OUT_Z_L_ADDR,
> +			st_gyro_mount_matrix_ext_info),
>  	IIO_CHAN_SOFT_TIMESTAMP(3)
>  };
>  
> @@ -478,6 +495,11 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
>  	indio_dev->channels = gdata->sensor_settings->ch;
>  	indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
>  
> +	err = iio_read_mount_matrix(gdata->dev, "mount-matrix",
> +				    &gdata->mount_matrix);
> +	if (err)
> +		goto st_gyro_power_off;

That label doesn't exist because Andy reworked the power handling recently.

> +
>  	gdata->current_fullscale = &gdata->sensor_settings->fs.fs_avl[0];
>  	gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz;
>  


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

* Re: [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix
  2021-05-18  9:01   ` Stephan Gerhold
@ 2021-05-18 18:09     ` Jonathan Cameron
  0 siblings, 0 replies; 13+ messages in thread
From: Jonathan Cameron @ 2021-05-18 18:09 UTC (permalink / raw)
  To: Stephan Gerhold
  Cc: Linus Walleij, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Andy Shevchenko, Denis Ciocca,
	Daniel Drake

On Tue, 18 May 2021 11:01:37 +0200
Stephan Gerhold <stephan@gerhold.net> wrote:

> Hi,
> 
> On Tue, May 18, 2021 at 01:33:21AM +0200, Linus Walleij wrote:
> > Add support to read and present the mounting matrix on ST magnetometers.
> > 
> > Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Cc: Denis Ciocca <denis.ciocca@st.com>
> > Cc: Daniel Drake <drake@endlessm.com>
> > Cc: Stephan Gerhold <stephan@gerhold.net>
> > Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> > ---
> > ChangeLog v1->v2:
> > - New patch because why not.  
> 
> Thanks for patching the other ST drivers as well!
> That reminds me about something I was thinking about when I was making
> the changes a week ago. :)
> 
> > ---
> >  drivers/iio/magnetometer/st_magn_core.c | 64 ++++++++++++++++++-------
> >  1 file changed, 46 insertions(+), 18 deletions(-)
> > 
> > diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
> > index 71faebd07feb..fa587975cb85 100644
> > --- a/drivers/iio/magnetometer/st_magn_core.c
> > +++ b/drivers/iio/magnetometer/st_magn_core.c
> > @@ -53,51 +53,74 @@
> >  #define ST_MAGN_3_OUT_Y_L_ADDR			0x6a
> >  #define ST_MAGN_3_OUT_Z_L_ADDR			0x6c
> >  
> > +static const struct iio_mount_matrix *
> > +st_magn_get_mount_matrix(const struct iio_dev *indio_dev,
> > +			 const struct iio_chan_spec *chan)
> > +{
> > +	struct st_sensor_data *mdata = iio_priv(indio_dev);
> > +
> > +	return &mdata->mount_matrix;
> > +}
> > +
> > +static const struct iio_chan_spec_ext_info st_magn_mount_matrix_ext_info[] = {
> > +	IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_magn_get_mount_matrix),
> > +	{ },
> > +};
> > +  
> 
> I'm not sure if this is worth it (or even a particularly good idea),
> but we could share this function and struct in st_sensors_core.c
> since it's exactly the same for st_accel/magn/gyro AFAICT.
> (It just operates on the common struct st_sensor_data).
> 
> This could be done with a macro like ST_SENSORS_LSM_CHANNELS_MOUNT_MATRIX(...)
> (maybe a bit long and clumsy) instead of _EXT(...) and pointing to
> a struct iio_chan_spec_ext_info somewhere in st_sensors_core.c.
> 
> The disadvantage however is that st_accel/magn/gyro couldn't add other
> (sensor-specific) ext_info later. Not sure if that is realistic though.

My gut feeling is it's not worth the effort for such a small bit of
repetition, but I don't feel that strongly about it so will take
whatever comes in v3 ;)

Jonathan


> 
> I wasn't entirely sure myself that's why I went with the _EXT(...)
> instead (especially since I only wanted to patch st_accel).
> Just wanted to mention it :)
> 
> Stephan


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

end of thread, other threads:[~2021-05-18 18:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 23:33 [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Linus Walleij
2021-05-17 23:33 ` [PATCH 2/5 v2] iio: accel: st_sensors: Support generic mounting matrix Linus Walleij
2021-05-18 11:03   ` Andy Shevchenko
2021-05-17 23:33 ` [PATCH 3/5 v2] iio: accel: st_sensors: Stop copying channels Linus Walleij
2021-05-17 23:33 ` [PATCH 4/5 v2] iio: magnetometer: st_magn: Support mount matrix Linus Walleij
2021-05-18  9:01   ` Stephan Gerhold
2021-05-18 18:09     ` Jonathan Cameron
2021-05-18 11:05   ` Andy Shevchenko
2021-05-17 23:33 ` [PATCH 5/5 v2] iio: gyro: st_gyro: " Linus Walleij
2021-05-18 11:06   ` Andy Shevchenko
2021-05-18 18:06   ` Jonathan Cameron
2021-05-18  9:04 ` [PATCH 1/5 v2] iio: st_sensors: Create extended attr macro Andy Shevchenko
2021-05-18 11:07 ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.