From: He Xin Date: Mon, 30 Nov 2026 14:29:37 +0800 Subject: [PATCH v2 08/18] iio: accel: bmi088-accel-core: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-work-v2-8-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=2076; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=kxditqW3lM71nggfQdJzlrVB5Jkhe5wtB5xj0hUvreA=; b=EFp48swp5hZLgBiMrcReAUqw7sSoEPlpTpwzchiTwzlCCZVbMcKQxVA71xOEf70jSDh16ifA+ UjlzGiGdMJ9ADbx1WWVbbG8tLMBntAhYvuAcbbGgxaggBfdRH7YHzJj 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/bmi088-accel-core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/iio/accel/bmi088-accel-core.c b/drivers/iio/accel/bmi088-accel-core.c index c7da90af0d..dea150b33c 100644 --- a/drivers/iio/accel/bmi088-accel-core.c +++ b/drivers/iio/accel/bmi088-accel-core.c @@ -125,6 +125,7 @@ struct bmi088_accel_chip_info { struct bmi088_accel_data { struct regmap *regmap; const struct bmi088_accel_chip_info *chip_info; + struct iio_mount_matrix orientation; u8 buffer[2] __aligned(IIO_DMA_MINALIGN); /* shared DMA safe buffer */ }; @@ -433,8 +434,23 @@ static int bmi088_accel_write_raw(struct iio_dev *indio_dev, } } +static const struct iio_mount_matrix * +bmi088_accel_core_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct bmi088_accel_data *data = iio_priv(indio_dev); + + return &data->orientation; +} + +static const struct iio_chan_spec_ext_info bmi088_accel_core_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, bmi088_accel_core_get_mount_matrix), + { } +}; + #define BMI088_ACCEL_CHANNEL(_axis) { \ .type = IIO_ACCEL, \ + .ext_info = bmi088_accel_core_ext_info,\ .modified = 1, \ .channel2 = IIO_MOD_##_axis, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ @@ -555,6 +571,11 @@ int bmi088_accel_core_probe(struct device *dev, struct regmap *regmap, return -ENOMEM; data = iio_priv(indio_dev); + + ret = iio_read_mount_matrix(dev, &data->orientation); + if (ret) + return ret; + dev_set_drvdata(dev, indio_dev); data->regmap = regmap; -- 2.53.0