From: He Xin Date: Mon, 30 Nov 2026 14:29:33 +0800 Subject: [PATCH v2 04/18] iio: accel: adxl367: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-work-v2-4-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=1972; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=CgLC/SP5MMnNlmaYqKrJnqM8bsNSmK1N+Ve+0TE+Y4s=; b=KF6vcfONMJfxWl8ygN5HJ88vXxvYeGXjbWB7a9EUpMgrHaVT1kPXfJhkwSI0RGZsy60E5zEfb MzLBQTYoaA2BX3rsSEwt2JwIdIhhZzrXuE9ubWXWuhyRMk7rbwf4/X0 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/adxl367.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/iio/accel/adxl367.c b/drivers/iio/accel/adxl367.c index 026db73057..9a0eda5b01 100644 --- a/drivers/iio/accel/adxl367.c +++ b/drivers/iio/accel/adxl367.c @@ -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; -- 2.53.0