From: He Xin Date: Fri, 04 Dec 2026 19:13:08 +0800 Subject: [PATCH v3 17/18] iio: accel: sca3300: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-work-v3-17-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=2468; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=QXL/baRy899oym5X7RLZ7E3120ry8lQ8UwdACRWIkgc=; b=h56Bz202FVDesPQdor2DsdTYoUOBu6kz1KceM66VKZtkAAsfzfVtSJ87MucZSFw06IVYY79m9 j4gplADM3+rCL8TakySwXJJYXeEUjDRxLK9EXKSeR5aLWlO6VA2nVO1 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/sca3300.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c index 67582cc341..a5eeded322 100644 --- a/drivers/iio/accel/sca3300.c +++ b/drivers/iio/accel/sca3300.c @@ -56,8 +56,18 @@ enum sca3300_scan_indexes { SCA3300_SCAN_MAX }; +static const struct iio_mount_matrix * +sca3300_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info sca3300_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, sca3300_get_mount_matrix), + { } +}; + #define SCA3300_ACCEL_CHANNEL(index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = sca3300_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ @@ -184,15 +194,26 @@ struct sca3300_chip_info { * @chip: Sensor chip specific information * @txbuf: Transmit buffer * @rxbuf: Receive buffer + * @orientation: mount matrix describing the sensor mounting orientation */ struct sca3300_data { struct spi_device *spi; struct mutex lock; const struct sca3300_chip_info *chip; + struct iio_mount_matrix orientation; u8 txbuf[4] __aligned(IIO_DMA_MINALIGN); u8 rxbuf[4]; }; +static const struct iio_mount_matrix * +sca3300_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct sca3300_data *sca_data = iio_priv(indio_dev); + + return &sca_data->orientation; +} + static const struct sca3300_chip_info sca3300_chip_tbl[] = { { .name = "sca3300", @@ -619,6 +640,13 @@ static int sca3300_probe(struct spi_device *spi) return -ENOMEM; sca_data = iio_priv(indio_dev); + + if (!iio_read_acpi_mount_matrix(&spi->dev, &sca_data->orientation, "ROTM")) { + ret = iio_read_mount_matrix(&spi->dev, &sca_data->orientation); + if (ret) + return ret; + } + mutex_init(&sca_data->lock); sca_data->spi = spi; -- 2.53.0