From: He Xin Date: Fri, 04 Dec 2026 19:13:02 +0800 Subject: [PATCH v3 11/18] iio: accel: dmard06: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-work-v3-11-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=2325; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=DAjyh2SeK0xOaVn7gNDN2fcGGpD4JaNhhIwdZzaPiOI=; b=NvAXggjTMhiBrXhLtjSCRTGR5/+PBdBVi2rGmzuc4Kv0aAJJa7EJHkETEI9aIlm0/Ct/uWXrO tEYiVxkUj+OCDl0zK1SrchuZjKpHqwvLhD+ZZQv8XTGYRFSBR286xpn 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/dmard06.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/iio/accel/dmard06.c b/drivers/iio/accel/dmard06.c index 82816fa443..b7b152cdc7 100644 --- a/drivers/iio/accel/dmard06.c +++ b/drivers/iio/accel/dmard06.c @@ -34,9 +34,19 @@ #define DMARD06_MODE_NORMAL 0x27 #define DMARD06_MODE_POWERDOWN 0x00 +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), + { } +}; + /* Device channels */ #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,13 @@ static int dmard06_probe(struct i2c_client *client) return -ENOMEM; dmard06 = iio_priv(indio_dev); + + if (!iio_read_acpi_mount_matrix(&client->dev, &dmard06->orientation, "ROTM")) { + 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); -- 2.53.0