iio: accel: adxl345_core: support mount matrix
Subsystems (7)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/18 iio: accel: adxl345_core: 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.
--- drivers/iio/accel/adxl345_core.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/adxl345_core.c +20 -0
@@ -204,6 +204,7 @@ struct adxl345_state {u32 tap_window_us;__le16 fifo_buf[ADXL345_DIRS *ADXL345_FIFO_SIZE +1 ]__aligned(IIO_DMA_MINALIGN) ; +struct iio_mount_matrix orientation; };static const struct iio_event_spec adxl345_events[] = {
@@ -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,10 @@ 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
Jonathan Cameron
maintainerQuoted 9 lines · On Fri, 27 Nov 2026 11:07:53 +0800 He Xin <[email protected]> wrote:
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.Signed-off-by He Xin <[email protected]>
Something messed around with your message IDs so the thread is broken. It seems to have added a prefix to them. Try to find out what did that for v2 or just use the b4 webgateway (look for docs for b4 on kernel.org).
drivers/iio/accel/adxl345_core.c struct adxl345_state { · line 207
Quoted 13 lines
--- drivers/iio/accel/adxl345_core.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)drivers/iio/accel/adxl345_core.c +1
-0@@ -204,6 +204,7 @@ struct adxl345_state {u32 tap_window_us;__le16 fifo_buf[ADXL345_DIRS *ADXL345_FIFO_SIZE +1 ]__aligned(IIO_DMA_MINALIGN) ; +struct iio_mount_matrix orientation;
Look at the line above and make sure you understand why that IIO_DMA_MINALIGN is there.
Technically this isn't actually a bug because the data is const after boot, but none the less we should have nothing else in that cacheline because it makes things harder to reason about.
Quoted 9 lines
drivers/iio/accel/adxl345_core.c +0
-0};#define ADXL345_CHANNEL (index, reg, axis) { \drivers/iio/accel/adxl345_core.c +1
-0.type = IIO_ACCEL, \ + .ext_info = adxl345_core_ext_info, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ .address = (reg), \
drivers/iio/accel/adxl345_core.c int adxl345_core_probe(struct device *dev, struct regmap *regmap, · line 1924
Quoted 7 lines
drivers/iio/accel/adxl345_core.c +4
-0@@ -1902,6 +1918,10 @@ 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;
Next part is unrelated so a blank line here.
Quoted 3 lines
drivers/iio/accel/adxl345_core.c +0
-0st->regmap = regmap; st->info =device_get_match_data (dev);if (!st->info)
PATCH 2/18 iio: accel: adxl355_core: support mount matrix
In reply to a message not in the archiveThe 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/adxl355_core.c +20 -0
@@ -235,6 +235,7 @@ struct adxl355_data {aligned_s64 ts; } buffer; }__aligned(IIO_DMA_MINALIGN) ; +struct iio_mount_matrix orientation; }; static int adxl355_set_op_mode(struct adxl355_data *data,
@@ -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,10 @@ 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 3/18 iio: accel: adxl367: support mount matrix
In reply to a message not in the archiveThe 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/adxl367.c +20 -0
@@ -181,6 +181,7 @@ struct adxl367_state {u8 act_threshold_buf[2 ];u8 inact_time_buf[2 ];u8 status_buf[3 ]; +struct iio_mount_matrix orientation; };static const unsigned int adxl367_threshold_h_reg_tbl[] = {
@@ -1328,8 +1329,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, \
@@ -1439,6 +1455,10 @@ 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 4/18 iio: accel: adxl372: support mount matrix
In reply to a message not in the archiveThe 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/iio/accel/adxl372.c +24 -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,10 @@ 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 5/18 iio: accel: adxl380: support mount matrix
In reply to a message not in the archiveThe 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
@@ -224,6 +224,7 @@ struct adxl380_state {int hpf_tbl[7 ][2 ];__be16 fifo_buf[ADXL380_FIFO_SAMPLES ]__aligned(IIO_DMA_MINALIGN) ; +struct iio_mount_matrix orientation; };bool adxl380_readable_noinc_reg (struct device *dev,unsigned int reg)
@@ -1769,8 +1770,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, \
@@ -1962,6 +1978,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 6/18 iio: accel: bma220_core: support mount matrix
In reply to a message not in the archiveThe 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/iio/accel/bma220_core.c +24 -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, \
@@ -135,8 +145,18 @@ struct bma220_data {/* Ensure timestamp is naturally aligned. */ aligned_s64 timestamp; } scan__aligned(IIO_DMA_MINALIGN) ; +struct iio_mount_matrix orientation; }; +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,10 @@ 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 7/18 iio: accel: bmi088-accel-core: support mount matrix
In reply to a message not in the archiveThe 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/bmi088-accel-core.c +20 -0
@@ -126,6 +126,7 @@ struct bmi088_accel_data {struct regmap *regmap;const struct bmi088_accel_chip_info *chip_info;u8 buffer[2 ]__aligned(IIO_DMA_MINALIGN) ;/* shared DMA safe buffer */ +struct iio_mount_matrix orientation; };static const struct regmap_range bmi088_volatile_ranges[] = {
@@ -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,10 @@ 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 8/18 iio: accel: da280: support mount matrix
In reply to a message not in the archiveThe 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/iio/accel/da280.c +24 -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,10 @@ 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 9/18 iio: accel: da311: support mount matrix
In reply to a message not in the archiveThe 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/iio/accel/da311.c +24 -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,10 @@ 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 10/18 iio: accel: dmard06: support mount matrix
In reply to a message not in the archiveThe 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/iio/accel/dmard06.c +24 -0
@@ -35,8 +35,18 @@#define DMARD06_MODE_POWERDOWN 0x00/* Device channels */ +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), + { } +}; +#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,10 @@ 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 11/18 iio: accel: dmard09: support mount matrix
In reply to a message not in the archiveThe 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/dmard09.c +20 -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,10 @@ 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 12/18 iio: accel: dmard10: support mount matrix
In reply to a message not in the archiveThe 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/iio/accel/dmard10.c +24 -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,10 @@ 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 13/18 iio: accel: mma7455_core: support mount matrix
In reply to a message not in the archiveThe 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/mma7455_core.c +20 -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,10 @@ 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 14/18 iio: accel: msa311: support mount matrix
In reply to a message not in the archiveThe 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/msa311.c +20 -0
@@ -361,6 +361,7 @@ struct msa311_priv {char *chip_name;struct iio_trigger *new_data_trig; +struct iio_mount_matrix orientation; };enum msa311_si {
@@ -370,8 +371,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 +1165,10 @@ 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 15/18 iio: accel: mxc6255: support mount matrix
In reply to a message not in the archiveThe 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/mxc6255.c +20 -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,10 @@ 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 16/18 iio: accel: sca3300: support mount matrix
In reply to a message not in the archiveThe 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/iio/accel/sca3300.c +24 -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, \
@@ -191,8 +201,18 @@ struct sca3300_data {const struct sca3300_chip_info *chip;u8 txbuf[4 ]__aligned(IIO_DMA_MINALIGN) ;u8 rxbuf[4 ]; +struct iio_mount_matrix orientation; }; +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 +639,10 @@ 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 17/18 iio: accel: stk8312: support mount matrix
In reply to a message not in the archiveThe 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/iio/accel/stk8312.c +24 -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,10 @@ 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
PATCH 18/18 iio: accel: stk8ba50: support mount matrix
In reply to a message not in the archiveThe 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 Phytium D3000M tablet (ACPI HID STK8BA50) where the sensor is mounted rotated 180 degrees about the X axis: 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iio/accel/stk8ba50.c +20 -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,10 @@ 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
Jonathan Cameron
maintainerRe: [PATCH 18/18] iio: accel: stk8ba50: support mount matrix
Quoted 9 lines · On Fri, 27 Nov 2026 11:08:10 +0800 He Xin <[email protected]> wrote:
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 Phytium D3000M tablet (ACPI HID STK8BA50) where the
That isn't a valid ACPI HID. Sure it is out in the wild, but just for the record Phytium should be doing better on this!
Quoted 4 lines
sensor is mounted rotated 180 degrees about the X axis: without the patch
in_accel_mount_matrixis absent, so iio-sensor-proxy has to fall back to a udev/hwdb override; with it the matrix from_DSDis reported and the orientation comes out correct.
Put the one you actually care about first in the series.
I'm not against adding this to all of them, but I would expect the distro folk to decide to backport this one but not the others.
Quoted 2 lines
Signed-off-by He Xin <[email protected]>
Just one minor thing below.
Quoted 7 lines
#define
STK8BA50_ACCEL_CHANNEL(index, reg, axis){ \drivers/iio/accel/stk8ba50.c +1
-0.type = IIO_ACCEL, \ + .ext_info = stk8ba50_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \
drivers/iio/accel/stk8ba50.c static int stk8ba50_probe(struct i2c_client *client) · line 417
Quoted 7 lines
drivers/iio/accel/stk8ba50.c +4
-0@@ -395,6 +411,10 @@ 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;
Blank line.
Quoted 3 lines
drivers/iio/accel/stk8ba50.c +0
-0data->client = client;i2c_set_clientdata (client, indio_dev);mutex_init (&data->lock);