From: He Xin Date: Mon, 30 Nov 2026 14:29:44 +0800 Subject: [PATCH v2 15/18] iio: accel: msa311: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-work-v2-15-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=2442; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=fHbGzkXhyUDGaVIc1eLNh6psGrSyYmyhdwVjl55ZX5E=; b=3kwx4BbrsKLaI32DqbMkp1qPbCZGmGMccXxT9dvvEnwe+wsQAHKsytGjDj7D8hNZcD/b8DCGG qX0FZUjUc3FCzgBjxSMggVKDc4RGldjg5XUuDBj0gX7WdRw7tKz5iIN 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/msa311.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/iio/accel/msa311.c b/drivers/iio/accel/msa311.c index caf9b1b639..ccbdcaf524 100644 --- a/drivers/iio/accel/msa311.c +++ b/drivers/iio/accel/msa311.c @@ -351,6 +351,7 @@ static const struct regmap_config msa311_regmap_config = { * @chip_name: Chip name in the format "msa311-%02x" % partid * @new_data_trig: Optional NEW_DATA interrupt driven trigger used * to notify external consumers a new sample is ready + * @orientation: mount matrix describing the sensor mounting orientation */ struct msa311_priv { struct regmap *regs; @@ -361,6 +362,7 @@ struct msa311_priv { char *chip_name; struct iio_trigger *new_data_trig; + struct iio_mount_matrix orientation; }; enum msa311_si { @@ -370,8 +372,23 @@ enum msa311_si { MSA311_SI_TIMESTAMP, }; +static const struct iio_mount_matrix * +msa311_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct msa311_priv *msa311 = iio_priv(indio_dev); + + return &msa311->orientation; +} + +static const struct iio_chan_spec_ext_info msa311_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, msa311_get_mount_matrix), + { } +}; + #define MSA311_ACCEL_CHANNEL(axis) { \ .type = IIO_ACCEL, \ + .ext_info = msa311_ext_info, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ @@ -1149,6 +1166,11 @@ static int msa311_probe(struct i2c_client *i2c) return -ENOMEM; msa311 = iio_priv(indio_dev); + + err = iio_read_mount_matrix(dev, &msa311->orientation); + if (err) + return err; + msa311->dev = dev; i2c_set_clientdata(i2c, indio_dev); -- 2.53.0