From: He Xin Date: Fri, 04 Dec 2026 19:12:58 +0800 Subject: [PATCH v3 07/18] iio: accel: bma220_core: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-work-v3-7-c7b74b9bc63f@hexin.host> References: <20261204-work-v3-0-c7b74b9bc63f@hexin.host> In-Reply-To: <20261204-work-v3-0-c7b74b9bc63f@hexin.host> To: linux-iio@vger.kernel.org, Michael Hennerich , Puranjay Mohan , Marcelo Schmitt , Antoniu Miclaus , Ramona Gradinariu , Petre Rodan Cc: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , linux@analog.com, He Xin X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796382823; l=2457; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=wXD+lqAiXP0uQOnmMAR8pw27jGmFLzzV8eJnHDFV4cQ=; b=5nNqMgvc+9cLRjD9zNWedn2OgBWOxpxI2tiJQhrSLwkVS/cVg6K0xn07zUlF2XsKkTSO1bHjy qnj743eMQDUAZZTH8HdqrM/W5wtsL9xk6WRYwAOLa1SVOTfiLn92CTJ X-Developer-Key: i=hexin@hexin.host; a=ed25519; pk=XShmjlZrsbSLtSY1GT4Ptl+4KQ/QVjE9VGdvbN87rFk= X-Endpoint-Received: by B4 Relay for hexin@hexin.host/20261130 with auth_id=1691 List-Id: B4 Relay Submissions 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 --- drivers/iio/accel/bma220_core.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c index b83abfdd84..150d8db2c4 100644 --- a/drivers/iio/accel/bma220_core.c +++ b/drivers/iio/accel/bma220_core.c @@ -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,13 @@ int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq) return -ENOMEM; data = iio_priv(indio_dev); + + if (!iio_read_acpi_mount_matrix(dev, &data->orientation, "ROTM")) { + ret = iio_read_mount_matrix(dev, &data->orientation); + if (ret) + return ret; + } + data->regmap = regmap; ret = bma220_init(dev, data); -- 2.53.0