From: He Xin Date: Fri, 04 Dec 2026 19:13:03 +0800 Subject: [PATCH v3 12/18] iio: accel: dmard09: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-work-v3-12-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=1885; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=hyTgnrgN0GaS1t5xkMjXL3Xg/oMziHUNA/rJ5bYpZT0=; b=ejxP7q2+neuKtxl4tv9SXE3+B66wG9wuT61yBtfdwkB6av46QT/TaUQYvBRM1kiT33SrQvydw aR4pNMdbaInAV83er2YT9JBHJTc3SrQ+kPDrA7RdWNcyo+jTpJ6XAWx 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/dmard09.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/iio/accel/dmard09.c b/drivers/iio/accel/dmard09.c index 6f0497ab61..8c308836f0 100644 --- a/drivers/iio/accel/dmard09.c +++ b/drivers/iio/accel/dmard09.c @@ -30,10 +30,26 @@ struct dmard09_data { struct i2c_client *client; + struct iio_mount_matrix orientation; +}; + +static const struct iio_mount_matrix * +dmard09_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct dmard09_data *data = iio_priv(indio_dev); + + return &data->orientation; +} + +static const struct iio_chan_spec_ext_info dmard09_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, dmard09_get_mount_matrix), + { } }; #define DMARD09_CHANNEL(_axis, offset) { \ .type = IIO_ACCEL, \ + .ext_info = dmard09_ext_info, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ .modified = 1, \ @@ -106,6 +122,13 @@ static int dmard09_probe(struct i2c_client *client) return -ENOMEM; data = iio_priv(indio_dev); + + if (!iio_read_acpi_mount_matrix(&client->dev, &data->orientation, "ROTM")) { + ret = iio_read_mount_matrix(&client->dev, &data->orientation); + if (ret) + return ret; + } + data->client = client; ret = i2c_smbus_read_byte_data(data->client, DMARD09_REG_CHIPID); -- 2.53.0