From: He Xin Date: Mon, 30 Nov 2026 14:29:34 +0800 Subject: [PATCH v2 05/18] iio: accel: adxl372: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-work-v2-5-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=2154; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=2c4diHzSSPx/fOsrHHu4L4XkAKJhTweh3NO+5t+VRVc=; b=Qhcdxe1/h8LgkF4BnTTT9jhgYkjLtJqxPdZvoEE9QUyj1UF7lNYFo0kGkplHvW5aN5XANadRN 6VVzcCdgOurCWQ8jfzaXD2+P7nza20tRvf8fSIhmoQS52Ja9XGQFFIE 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/adxl372.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c index e375d068a3..b5a9c395b0 100644 --- a/drivers/iio/accel/adxl372.c +++ b/drivers/iio/accel/adxl372.c @@ -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; -- 2.53.0