From: He Xin Date: Fri, 04 Dec 2026 19:13:05 +0800 Subject: [PATCH v3 14/18] iio: accel: mma7455_core: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-work-v3-14-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=2061; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=gaYVllos/rOW/Fyn7TDI2UGBxB0UExuTIY0C8wfyH6g=; b=+LOvv+Nf60EEMpHNJmmFQutve/PUFJP4GviCY77CjhhgDKGlfscegVIn+V5ebX+hAGq+x67V/ PdaLQ6Rruo1AUnmkAkZQkkjr/csuaUHTJH1mgfBeCjaDc+gB+SPXuaT 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/mma7455_core.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/iio/accel/mma7455_core.c b/drivers/iio/accel/mma7455_core.c index a2b5bdf14d..57c1b500bf 100644 --- a/drivers/iio/accel/mma7455_core.c +++ b/drivers/iio/accel/mma7455_core.c @@ -61,6 +61,7 @@ struct mma7455_data { __le16 channels[3]; aligned_s64 ts; } scan; + struct iio_mount_matrix orientation; }; static int mma7455_drdy(struct mma7455_data *mma7455) @@ -209,8 +210,23 @@ static const struct iio_info mma7455_info = { .write_raw = mma7455_write_raw, }; +static const struct iio_mount_matrix * +mma7455_core_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct mma7455_data *mma7455 = iio_priv(indio_dev); + + return &mma7455->orientation; +} + +static const struct iio_chan_spec_ext_info mma7455_core_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, mma7455_core_get_mount_matrix), + { } +}; + #define MMA7455_CHANNEL(axis, idx) { \ .type = IIO_ACCEL, \ + .ext_info = mma7455_core_ext_info,\ .modified = 1, \ .address = MMA7455_REG_##axis##OUTL,\ .channel2 = IIO_MOD_##axis, \ @@ -267,6 +283,13 @@ int mma7455_core_probe(struct device *dev, struct regmap *regmap, dev_set_drvdata(dev, indio_dev); mma7455 = iio_priv(indio_dev); + + if (!iio_read_acpi_mount_matrix(dev, &mma7455->orientation, "ROTM")) { + ret = iio_read_mount_matrix(dev, &mma7455->orientation); + if (ret) + return ret; + } + mma7455->regmap = regmap; indio_dev->info = &mma7455_info; -- 2.53.0