From: He Xin Date: Mon, 30 Nov 2026 14:29:45 +0800 Subject: [PATCH v2 16/18] iio: accel: mxc6255: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-work-v2-16-9eccecc71702@hexin.host> References: <20261130-work-v2-0-9eccecc71702@hexin.host> In-Reply-To: <20261130-work-v2-0-9eccecc71702@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=1796020192; l=1931; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=F4pdCYwRPfjocr90sJdrb8kATgJffPzUoUibcpyiiwI=; b=OdD4/JhH00wjkIbS6Japta/d3hs6f0veIcviaJroHybYzv0XtROEjtbykpA+hhG4GlNs/lBU9 9x7J2wnWgrPCA6U+bFWgs/rM9Nm8MesP1oZRcqn6aSoOB3mfVZv11Tc 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/mxc6255.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/iio/accel/mxc6255.c b/drivers/iio/accel/mxc6255.c index a9f41cf27a..7a53cdff50 100644 --- a/drivers/iio/accel/mxc6255.c +++ b/drivers/iio/accel/mxc6255.c @@ -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; -- 2.53.0