iio: accel: add mount matrix support to 18 accelerometer drivers
Subsystems (7)
v2 cover iio: accel: add mount matrix support to 18 accelerometer drivers
These drivers ignore the "mount-matrix" property that other accelerometer drivers already honour, so userspace gets raw sensor axes on any board whose sensor is not mounted axis-aligned with the display. A udev/hwdb override does not cover it either: it keys off the sensor modalias and DMI, which do not tell such boards apart.
Each patch is mechanical and independent: store the matrix in the driver's private data, add an IIO_MOUNT_MATRIX() ext_info entry to the accelerometer channels, and read the property once in probe.
One behaviour change: a board whose firmware describes a matrix with the wrong number of entries now fails to probe with -EINVAL instead of being ignored, which is what the drivers that already support the property do.
Not converted here, because the change would not have the same shape:
adis16201, adis16209 and sca3000 list their channels as array literals, adxl313_core and fxls8962af-core keep the probe in the bus wrappers, and mma9551/mma9553 differ in both. hid-sensor-accel-3d, ssp_accel_sensor and cros_ec_accel_legacy take the orientation from the HID/SSP/EC side rather than from a firmware property.
Changes in v2:
- move stk8ba50 to patch 1
- place the mount matrix before the __aligned(IIO_DMA_MINALIGN) members in adxl345, adxl355, adxl367, adxl380, bma220, bmi088 and sca3300, so the DMA buffers keep their own cacheline
- add the missing blank line after the mount matrix read in probe
- add the @orientation kernel-doc entry for msa311 and sca3300
- shorten the stk8ba50 test note to the behaviour observed on the device
- v1 lost its threading because the sending MTA rewrote Message-IDs while leaving References untouched; v2 is posted as a new series
Build tested with allmodconfig: drivers/iio/accel, 71 objects, no warnings; checkpatch.pl is silent in default and in --strict mode. Only stk8ba50 was tested on hardware; the other 17 are compile tested.
---
He Xin (18):
iio: accel: stk8ba50: support mount matrix
iio: accel: adxl345_core: support mount matrix
iio: accel: adxl355_core: support mount matrix
iio: accel: adxl367: support mount matrix
iio: accel: adxl372: support mount matrix
iio: accel: adxl380: support mount matrix
iio: accel: bma220_core: support mount matrix
iio: accel: bmi088-accel-core: support mount matrix
iio: accel: da280: support mount matrix
iio: accel: da311: support mount matrix
iio: accel: dmard06: support mount matrix
iio: accel: dmard09: support mount matrix
iio: accel: dmard10: support mount matrix
iio: accel: mma7455_core: support mount matrix
iio: accel: msa311: support mount matrix
iio: accel: mxc6255: support mount matrix
iio: accel: sca3300: support mount matrix
iio: accel: stk8312: support mount matrix
drivers/iio/accel/adxl345_core.c | 21 +++++++++++++++++++++ drivers/iio/accel/adxl355_core.c | 21 +++++++++++++++++++++ drivers/iio/accel/adxl367.c | 21 +++++++++++++++++++++ drivers/iio/accel/adxl372.c | 25 +++++++++++++++++++++++++ drivers/iio/accel/adxl380.c | 20 ++++++++++++++++++++ drivers/iio/accel/bma220_core.c | 25 +++++++++++++++++++++++++ drivers/iio/accel/bmi088-accel-core.c | 21 +++++++++++++++++++++ drivers/iio/accel/da280.c | 25 +++++++++++++++++++++++++ drivers/iio/accel/da311.c | 25 +++++++++++++++++++++++++ drivers/iio/accel/dmard06.c | 25 +++++++++++++++++++++++++ drivers/iio/accel/dmard09.c | 21 +++++++++++++++++++++ drivers/iio/accel/dmard10.c | 25 +++++++++++++++++++++++++ drivers/iio/accel/mma7455_core.c | 21 +++++++++++++++++++++ drivers/iio/accel/msa311.c | 22 ++++++++++++++++++++++ drivers/iio/accel/mxc6255.c | 21 +++++++++++++++++++++ drivers/iio/accel/sca3300.c | 26 ++++++++++++++++++++++++++ drivers/iio/accel/stk8312.c | 25 +++++++++++++++++++++++++ drivers/iio/accel/stk8ba50.c | 21 +++++++++++++++++++++ 18 files changed, 411 insertions(+)
---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261130-work-ab0d96ec614e
Best regards,
Signature · 1 line
He Xin <[email protected]>
PATCH v2 1/18 iio: accel: stk8ba50: support mount matrix
The driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
Tested on a tablet whose sensor is mounted rotated 180 degrees about X:
without the patch in_accel_mount_matrix is absent, so iio-sensor-proxy has to fall back to a udev/hwdb override; with it the matrix from _DSD is reported and the orientation comes out correct.
--- drivers/iio/accel/stk8ba50.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/iio/accel/stk8ba50.c +21 -0
@@ -102,10 +102,26 @@ struct stk8ba50_data {s16 chans[3 ];aligned_s64 timetamp; } scan; +struct iio_mount_matrix orientation; +}; + +static const struct iio_mount_matrix * +stk8ba50_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct stk8ba50_data *data =iio_priv (indio_dev); + +return &data->orientation; +} + +static const struct iio_chan_spec_ext_info stk8ba50_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , stk8ba50_get_mount_matrix), + { } };#define STK8BA50_ACCEL_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = stk8ba50_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -395,6 +411,11 @@ static int stk8ba50_probe(struct i2c_client *client)return -ENOMEM ; data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (&client->dev, &data->orientation); +if (ret) +return ret; + data->client = client;i2c_set_clientdata (client, indio_dev);mutex_init (&data->lock);
Signature · 1 line
2.53.0
PATCH v2 2/18 iio: accel: adxl345_core: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/adxl345_core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/iio/accel/adxl345_core.c +21 -0
@@ -203,6 +203,7 @@ struct adxl345_state {u32 tap_latent_us;u32 tap_window_us; +struct iio_mount_matrix orientation;__le16 fifo_buf[ADXL345_DIRS *ADXL345_FIFO_SIZE +1 ]__aligned(IIO_DMA_MINALIGN) ; };
@@ -248,8 +249,23 @@ static const struct iio_event_spec adxl345_events[] = { }, }; +static const struct iio_mount_matrix * +adxl345_core_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct adxl345_state *st =iio_priv (indio_dev); + +return &st->orientation; +} + +static const struct iio_chan_spec_ext_info adxl345_core_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , adxl345_core_get_mount_matrix), + { } +}; +#define ADXL345_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = adxl345_core_ext_info, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ .address = (reg), \
@@ -1902,6 +1918,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,return -ENOMEM ; st =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (dev, &st->orientation); +if (ret) +return ret; + st->regmap = regmap; st->info =device_get_match_data (dev);if (!st->info)
Signature · 1 line
2.53.0
PATCH v2 3/18 iio: accel: adxl355_core: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/adxl355_core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/iio/accel/adxl355_core.c +21 -0
@@ -228,6 +228,7 @@ struct adxl355_data {int calibbias[3 ];int adxl355_hpf_3db_table[7 ][2 ];struct iio_trigger *dready_trig; +struct iio_mount_matrix orientation; union { u8 transf_buf[3]; struct {
@@ -707,8 +708,23 @@ static irqreturn_t adxl355_trigger_handler(int irq, void *p)return IRQ_HANDLED ; } +static const struct iio_mount_matrix * +adxl355_core_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct adxl355_data *data =iio_priv (indio_dev); + +return &data->orientation; +} + +static const struct iio_chan_spec_ext_info adxl355_core_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , adxl355_core_get_mount_matrix), + { } +}; +#define ADXL355_ACCEL_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = adxl355_core_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -792,6 +808,11 @@ int adxl355_core_probe(struct device *dev, struct regmap *regmap,return -ENOMEM ; data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (dev, &data->orientation); +if (ret) +return ret; + data->regmap = regmap; data->dev = dev; data->op_mode =ADXL355_STANDBY ;
Signature · 1 line
2.53.0
PATCH v2 4/18 iio: accel: adxl367: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/adxl367.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/iio/accel/adxl367.c +21 -0
@@ -180,6 +180,7 @@ struct adxl367_state {unsigned int fifo_set_size;unsigned int fifo_watermark; +struct iio_mount_matrix orientation;__be16 fifo_buf[ADXL367_FIFO_SIZE ]__aligned(IIO_DMA_MINALIGN) ;__be16 sample_buf;u8 act_threshold_buf[2 ];
@@ -1336,8 +1337,23 @@ static const struct iio_event_spec adxl367_events[] = { }, }; +static const struct iio_mount_matrix * +adxl367_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct adxl367_state *st =iio_priv (indio_dev); + +return &st->orientation; +} + +static const struct iio_chan_spec_ext_info adxl367_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , adxl367_get_mount_matrix), + { } +}; +#define ADXL367_ACCEL_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = adxl367_ext_info, \ .address = (reg), \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -1477,6 +1493,11 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,return -ENOMEM ; st =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (dev, &st->orientation); +if (ret) +return ret; + st->dev = dev; st->regmap = regmap; st->context = context;
Signature · 1 line
2.53.0
PATCH v2 5/18 iio: accel: adxl372: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/adxl372.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/iio/accel/adxl372.c +25 -0
@@ -315,8 +315,18 @@ static const struct iio_event_spec adxl372_events[] = { }, }; +static const struct iio_mount_matrix * +adxl372_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info adxl372_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , adxl372_get_mount_matrix), + { } +}; +#define ADXL372_ACCEL_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = adxl372_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -368,8 +378,18 @@ struct adxl372_state {__be16 fifo_buf[ADXL372_FIFO_SIZE ];bool peak_fifo_mode_en;struct mutex threshold_m;/* lock for threshold */ +struct iio_mount_matrix orientation; }; +static const struct iio_mount_matrix * +adxl372_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct adxl372_state *st =iio_priv (indio_dev); + +return &st->orientation; +} +static const unsigned long adxl372_channel_masks[] = {BIT (0 ),BIT (1 ),BIT (2 ),BIT (0 ) |BIT (1 ),
@@ -1292,6 +1312,11 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,return -ENOMEM ; st =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (dev, &st->orientation); +if (ret) +return ret; +dev_set_drvdata (dev, indio_dev); st->dev = dev;
Signature · 1 line
2.53.0
PATCH v2 6/18 iio: accel: adxl380: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/adxl380.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/adxl380.c +20 -0
@@ -223,6 +223,7 @@ struct adxl380_state {int lpf_tbl[4 ];int hpf_tbl[7 ][2 ]; +struct iio_mount_matrix orientation;__be16 fifo_buf[ADXL380_FIFO_SAMPLES ]__aligned(IIO_DMA_MINALIGN) ; };
@@ -1785,8 +1786,23 @@ static const struct iio_event_spec adxl380_events[] = { }, }; +static const struct iio_mount_matrix * +adxl380_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct adxl380_state *st =iio_priv (indio_dev); + +return &st->orientation; +} + +static const struct iio_chan_spec_ext_info adxl380_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , adxl380_get_mount_matrix), + { } +}; +#define ADXL380_ACCEL_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = adxl380_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -1978,6 +1994,10 @@ int adxl380_probe(struct device *dev, struct regmap *regmap, st =iio_priv (indio_dev); + ret =iio_read_mount_matrix (dev, &st->orientation); +if (ret) +return ret; + st->dev = dev; st->regmap = regmap; st->chip_info = chip_info;
Signature · 1 line
2.53.0
PATCH v2 7/18 iio: accel: bma220_core: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/bma220_core.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/iio/accel/bma220_core.c +25 -0
@@ -94,8 +94,18 @@#define BMA220_COF_64Hz 0x4#define BMA220_COF_32Hz 0x5 +static const struct iio_mount_matrix * +bma220_core_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info bma220_core_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , bma220_core_get_mount_matrix), + { } +}; +#define BMA220_ACCEL_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = bma220_core_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -130,6 +140,7 @@ struct bma220_data {u8 lpf_3dB_freq_idx;u8 range_idx;struct iio_trigger *trig; +struct iio_mount_matrix orientation;struct {s8 chans[3 ];/* Ensure timestamp is naturally aligned. */
@@ -137,6 +148,15 @@ struct bma220_data { } scan__aligned(IIO_DMA_MINALIGN) ; }; +static const struct iio_mount_matrix * +bma220_core_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct bma220_data *data =iio_priv (indio_dev); + +return &data->orientation; +} +static const struct iio_chan_spec bma220_channels[] = {BMA220_ACCEL_CHANNEL (0 ,BMA220_REG_ACCEL_X ,X ),BMA220_ACCEL_CHANNEL (1 ,BMA220_REG_ACCEL_Y ,Y ),
@@ -508,6 +528,11 @@ int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq)return -ENOMEM ; data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (dev, &data->orientation); +if (ret) +return ret; + data->regmap = regmap; ret =bma220_init (dev, data);
Signature · 1 line
2.53.0
PATCH v2 8/18 iio: accel: bmi088-accel-core: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/bmi088-accel-core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/iio/accel/bmi088-accel-core.c +21 -0
@@ -125,6 +125,7 @@ struct bmi088_accel_chip_info {struct bmi088_accel_data {struct regmap *regmap;const struct bmi088_accel_chip_info *chip_info; +struct iio_mount_matrix orientation;u8 buffer[2 ]__aligned(IIO_DMA_MINALIGN) ;/* shared DMA safe buffer */ };
@@ -433,8 +434,23 @@ static int bmi088_accel_write_raw(struct iio_dev *indio_dev, } } +static const struct iio_mount_matrix * +bmi088_accel_core_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct bmi088_accel_data *data =iio_priv (indio_dev); + +return &data->orientation; +} + +static const struct iio_chan_spec_ext_info bmi088_accel_core_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , bmi088_accel_core_get_mount_matrix), + { } +}; +#define BMI088_ACCEL_CHANNEL (_axis) { \ .type = IIO_ACCEL, \ + .ext_info = bmi088_accel_core_ext_info,\ .modified = 1, \ .channel2 = IIO_MOD_##_axis, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
@@ -555,6 +571,11 @@ int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap,return -ENOMEM ; data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (dev, &data->orientation); +if (ret) +return ret; +dev_set_drvdata (dev, indio_dev); data->regmap = regmap;
Signature · 1 line
2.53.0
PATCH v2 9/18 iio: accel: da280: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/da280.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/iio/accel/da280.c +25 -0
@@ -30,8 +30,18 @@static const int da280_nscale =2395019 ; +static const struct iio_mount_matrix * +da280_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info da280_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , da280_get_mount_matrix), + { } +}; +#define DA280_CHANNEL (reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = da280_ext_info,\ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -52,8 +62,18 @@ struct da280_match_data {struct da280_data {struct i2c_client *client; +struct iio_mount_matrix orientation; }; +static const struct iio_mount_matrix * +da280_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct da280_data *data =iio_priv (indio_dev); + +return &data->orientation; +} +static int da280_enable (struct i2c_client *client,bool enable) {u8 data = enable ?DA280_MODE_ENABLE :DA280_MODE_DISABLE ;
@@ -119,6 +139,11 @@ static int da280_probe(struct i2c_client *client)return -ENOMEM ; data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (&client->dev, &data->orientation); +if (ret) +return ret; + data->client = client; indio_dev->info = &da280_info;
Signature · 1 line
2.53.0
PATCH v2 10/18 iio: accel: da311: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/da311.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/iio/accel/da311.c +25 -0
@@ -77,8 +77,18 @@static const int da311_nscale =9580078 ; +static const struct iio_mount_matrix * +da311_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info da311_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , da311_get_mount_matrix), + { } +}; +#define DA311_CHANNEL (reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = da311_ext_info,\ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -95,8 +105,18 @@ static const struct iio_chan_spec da311_channels[] = {struct da311_data {struct i2c_client *client; +struct iio_mount_matrix orientation; }; +static const struct iio_mount_matrix * +da311_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct da311_data *data =iio_priv (indio_dev); + +return &data->orientation; +} +static int da311_register_mask_write (struct i2c_client *client,u16 addr,u8 mask,u8 data) {
@@ -232,6 +252,11 @@ static int da311_probe(struct i2c_client *client)return -ENOMEM ; data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (&client->dev, &data->orientation); +if (ret) +return ret; + data->client = client; indio_dev->info = &da311_info;
Signature · 1 line
2.53.0
PATCH v2 11/18 iio: accel: dmard06: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/dmard06.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/iio/accel/dmard06.c +25 -0
@@ -34,9 +34,19 @@#define DMARD06_MODE_NORMAL 0x27#define DMARD06_MODE_POWERDOWN 0x00 +static const struct iio_mount_matrix * +dmard06_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info dmard06_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , dmard06_get_mount_matrix), + { } +}; +/* Device channels */ #define DMARD06_ACCEL_CHANNEL (_axis, _reg) { \ .type = IIO_ACCEL, \ + .ext_info = dmard06_ext_info, \ .address = _reg, \ .channel2 = IIO_MOD_##_axis, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
@@ -54,8 +64,18 @@struct dmard06_data {struct i2c_client *client;u8 chip_id; +struct iio_mount_matrix orientation; }; +static const struct iio_mount_matrix * +dmard06_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct dmard06_data *dmard06 =iio_priv (indio_dev); + +return &dmard06->orientation; +} +static const struct iio_chan_spec dmard06_channels[] = {DMARD06_ACCEL_CHANNEL (X ,DMARD06_XOUT_REG ),DMARD06_ACCEL_CHANNEL (Y ,DMARD06_YOUT_REG ),
@@ -140,6 +160,11 @@ static int dmard06_probe(struct i2c_client *client)return -ENOMEM ; dmard06 =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (&client->dev, &dmard06->orientation); +if (ret) +return ret; + dmard06->client = client; ret =i2c_smbus_read_byte_data (dmard06->client,DMARD06_CHIP_ID_REG );
Signature · 1 line
2.53.0
PATCH v2 12/18 iio: accel: dmard09: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/dmard09.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/iio/accel/dmard09.c +21 -0
@@ -30,10 +30,26 @@struct dmard09_data {struct i2c_client *client; +struct iio_mount_matrix orientation; +}; + +static const struct iio_mount_matrix * +dmard09_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct dmard09_data *data =iio_priv (indio_dev); + +return &data->orientation; +} + +static const struct iio_chan_spec_ext_info dmard09_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , dmard09_get_mount_matrix), + { } };#define DMARD09_CHANNEL (_axis, offset) { \ .type = IIO_ACCEL, \ + .ext_info = dmard09_ext_info, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ .modified = 1, \
@@ -106,6 +122,11 @@ static int dmard09_probe(struct i2c_client *client)return -ENOMEM ; data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (&client->dev, &data->orientation); +if (ret) +return ret; + data->client = client; ret =i2c_smbus_read_byte_data (data->client,DMARD09_REG_CHIPID );
Signature · 1 line
2.53.0
PATCH v2 13/18 iio: accel: dmard10: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/dmard10.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/iio/accel/dmard10.c +25 -0
@@ -51,8 +51,18 @@static const int dmard10_nscale =76640625 ; +static const struct iio_mount_matrix * +dmard10_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info dmard10_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , dmard10_get_mount_matrix), + { } +}; +#define DMARD10_CHANNEL (reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = dmard10_ext_info,\ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -68,8 +78,18 @@ static const struct iio_chan_spec dmard10_channels[] = {struct dmard10_data {struct i2c_client *client; +struct iio_mount_matrix orientation; }; +static const struct iio_mount_matrix * +dmard10_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct dmard10_data *data =iio_priv (indio_dev); + +return &data->orientation; +} +/* Init sequence taken from the android driver */ static int dmard10_reset (struct i2c_client *client) {
@@ -195,6 +215,11 @@ static int dmard10_probe(struct i2c_client *client)return -ENOMEM ; data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (&client->dev, &data->orientation); +if (ret) +return ret; + data->client = client; indio_dev->info = &dmard10_info;
Signature · 1 line
2.53.0
PATCH v2 14/18 iio: accel: mma7455_core: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/mma7455_core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/iio/accel/mma7455_core.c +21 -0
@@ -61,6 +61,7 @@ struct mma7455_data {__le16 channels[3 ];aligned_s64 ts; } scan; +struct iio_mount_matrix orientation; };static int mma7455_drdy (struct mma7455_data *mma7455)
@@ -209,8 +210,23 @@ static const struct iio_info mma7455_info = { .write_raw = mma7455_write_raw, }; +static const struct iio_mount_matrix * +mma7455_core_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct mma7455_data *mma7455 =iio_priv (indio_dev); + +return &mma7455->orientation; +} + +static const struct iio_chan_spec_ext_info mma7455_core_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , mma7455_core_get_mount_matrix), + { } +}; +#define MMA7455_CHANNEL (axis, idx) { \ .type = IIO_ACCEL, \ + .ext_info = mma7455_core_ext_info,\ .modified = 1, \ .address = MMA7455_REG_##axis##OUTL,\ .channel2 = IIO_MOD_##axis, \
@@ -267,6 +283,11 @@ int mma7455_core_probe(struct device *dev, struct regmap *regmap,dev_set_drvdata (dev, indio_dev); mma7455 =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (dev, &mma7455->orientation); +if (ret) +return ret; + mma7455->regmap = regmap; indio_dev->info = &mma7455_info;
Signature · 1 line
2.53.0
PATCH v2 15/18 iio: accel: msa311: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/msa311.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/iio/accel/msa311.c +22 -0
@@ -351,6 +351,7 @@ static const struct regmap_config msa311_regmap_config = {* @chip_name: Chip name in the format "msa311-%02x" % partid * @new_data_trig: Optional NEW_DATA interrupt driven trigger used * to notify external consumers a new sample is ready +* @orientation: mount matrix describing the sensor mounting orientation */ struct msa311_priv {struct regmap *regs;
@@ -361,6 +362,7 @@ struct msa311_priv {char *chip_name;struct iio_trigger *new_data_trig; +struct iio_mount_matrix orientation; };enum msa311_si {
@@ -370,8 +372,23 @@ enum msa311_si { MSA311_SI_TIMESTAMP, }; +static const struct iio_mount_matrix * +msa311_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct msa311_priv *msa311 =iio_priv (indio_dev); + +return &msa311->orientation; +} + +static const struct iio_chan_spec_ext_info msa311_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , msa311_get_mount_matrix), + { } +}; +#define MSA311_ACCEL_CHANNEL (axis) { \ .type = IIO_ACCEL, \ + .ext_info = msa311_ext_info, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
@@ -1149,6 +1166,11 @@ static int msa311_probe(struct i2c_client *i2c)return -ENOMEM ; msa311 =iio_priv (indio_dev); + + err =iio_read_mount_matrix (dev, &msa311->orientation); +if (err) +return err; + msa311->dev = dev;i2c_set_clientdata (i2c, indio_dev);
Signature · 1 line
2.53.0
PATCH v2 16/18 iio: accel: mxc6255: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/mxc6255.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/iio/accel/mxc6255.c +21 -0
@@ -42,6 +42,7 @@ enum mxc6255_axis {struct mxc6255_data {struct i2c_client *client;struct regmap *regmap; +struct iio_mount_matrix orientation; }; static int mxc6255_read_raw(struct iio_dev *indio_dev,
@@ -76,8 +77,23 @@ static const struct iio_info mxc6255_info = { .read_raw = mxc6255_read_raw, }; +static const struct iio_mount_matrix * +mxc6255_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct mxc6255_data *data =iio_priv (indio_dev); + +return &data->orientation; +} + +static const struct iio_chan_spec_ext_info mxc6255_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , mxc6255_get_mount_matrix), + { } +}; +#define MXC6255_CHANNEL (_axis, reg) { \ .type = IIO_ACCEL, \ + .ext_info = mxc6255_ext_info, \ .modified = 1, \ .channel2 = IIO_MOD_##_axis, \ .address = reg, \
@@ -130,6 +146,11 @@ static int mxc6255_probe(struct i2c_client *client) } data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (&client->dev, &data->orientation); +if (ret) +return ret; +i2c_set_clientdata (client, indio_dev); data->client = client; data->regmap = regmap;
Signature · 1 line
2.53.0
PATCH v2 17/18 iio: accel: sca3300: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/sca3300.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/iio/accel/sca3300.c +26 -0
@@ -56,8 +56,18 @@ enum sca3300_scan_indexes {SCA3300_SCAN_MAX }; +static const struct iio_mount_matrix * +sca3300_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info sca3300_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , sca3300_get_mount_matrix), + { } +}; +#define SCA3300_ACCEL_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = sca3300_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -184,15 +194,26 @@ struct sca3300_chip_info {* @chip: Sensor chip specific information * @txbuf: Transmit buffer * @rxbuf: Receive buffer +* @orientation: mount matrix describing the sensor mounting orientation */ struct sca3300_data {struct spi_device *spi;struct mutex lock;const struct sca3300_chip_info *chip; +struct iio_mount_matrix orientation;u8 txbuf[4 ]__aligned(IIO_DMA_MINALIGN) ;u8 rxbuf[4 ]; }; +static const struct iio_mount_matrix * +sca3300_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct sca3300_data *sca_data =iio_priv (indio_dev); + +return &sca_data->orientation; +} +static const struct sca3300_chip_info sca3300_chip_tbl[] = { { .name ="sca3300" ,
@@ -619,6 +640,11 @@ static int sca3300_probe(struct spi_device *spi)return -ENOMEM ; sca_data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (&spi->dev, &sca_data->orientation); +if (ret) +return ret; +mutex_init (&sca_data->lock); sca_data->spi = spi;
Signature · 1 line
2.53.0
PATCH v2 18/18 iio: accel: stk8312: support mount matrix
In reply to He XinThe driver ignores the mount matrix described by the firmware (ACPI _DSD "mount-matrix" or the devicetree property), so the orientation reported to userspace is wrong whenever the sensor is not mounted axis-aligned with the display.
Read the mount matrix at probe time and expose it through IIO_MOUNT_MATRIX(), as several other accelerometer drivers already do.
--- drivers/iio/accel/stk8312.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/iio/accel/stk8312.c +25 -0
@@ -78,8 +78,18 @@ static const struct { {12, 500000}, {6, 250000}, {3, 125000} }; +static const struct iio_mount_matrix * +stk8312_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info stk8312_ext_info[] = { +IIO_MOUNT_MATRIX (IIO_SHARED_BY_TYPE , stk8312_get_mount_matrix), + { } +}; +#define STK8312_ACCEL_CHANNEL (index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = stk8312_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
@@ -115,8 +125,18 @@ struct stk8312_data {s8 chans[3 ];aligned_s64 timestamp; } scan; +struct iio_mount_matrix orientation; }; +static const struct iio_mount_matrix * +stk8312_get_mount_matrix (const struct iio_dev *indio_dev, +const struct iio_chan_spec *chan) +{ +struct stk8312_data *data =iio_priv (indio_dev); + +return &data->orientation; +} + static IIO_CONST_ATTR(in_accel_scale_available, STK8312_SCALE_AVAIL); static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("3.125 6.25 12.5 25 50 100 200 400");
@@ -516,6 +536,11 @@ static int stk8312_probe(struct i2c_client *client)return -ENOMEM ; data =iio_priv (indio_dev); + + ret =iio_read_mount_matrix (&client->dev, &data->orientation); +if (ret) +return ret; + data->client = client;i2c_set_clientdata (client, indio_dev);mutex_init (&data->lock);
Signature · 1 line
2.53.0
Quoted 32 lines · On 30-Nov-26 7:29, He Xin via B4 Relay wrote:
These drivers ignore the "mount-matrix" property that other accelerometer drivers already honour, so userspace gets raw sensor axes on any board whose sensor is not mounted axis-aligned with the display. A udev/hwdb override does not cover it either: it keys off the sensor modalias and DMI, which do not tell such boards apart.
Each patch is mechanical and independent: store the matrix in the driver's private data, add an
IIO_MOUNT_MATRIX()ext_infoentry to the accelerometer channels, and read the property once in probe.One behaviour change: a board whose firmware describes a matrix with the wrong number of entries now fails to probe with
-EINVALinstead of being ignored, which is what the drivers that already support the property do.Not converted here, because the change would not have the same shape:
adis16201, adis16209 and sca3000 list their channels as array literals,adxl313_coreand fxls8962af-core keep the probe in the bus wrappers, and mma9551/mma9553 differ in both. hid-sensor-accel-3d,ssp_accel_sensorandcros_ec_accel_legacytake the orientation from the HID/SSP/EC side rather than from a firmware property.Changes in v2:
- move stk8ba50 to patch 1
- place the mount matrix before the__aligned(IIO_DMA_MINALIGN)members in adxl345, adxl355, adxl367, adxl380, bma220, bmi088 and sca3300, so the DMA buffers keep their own cacheline
- add the missing blank line after the mount matrix read in probe
- add the @orientation kernel-doc entry for msa311 and sca3300
- shorten the stk8ba50 test note to the behaviour observed on the device
- v1 lost its threading because the sending MTA rewrote Message-IDs while leaving References untouched; v2 is posted as a new series
Quoted 7 lines
Build tested with allmodconfig:
drivers/iio/accel, 71 objects, no warnings; checkpatch.pl is silent in default and in --strict mode. Only stk8ba50 was tested on hardware; the other 17 are compile tested.Signed-off-by He Xin <[email protected]>---
I haven't checked the placements in the data structs with pahole, but otherwise this LGTM.
For the series,
Signature · 2 lines
Kind regards, Joshua Crofts