From: He Xin Date: Mon, 30 Nov 2026 14:29:30 +0800 Subject: [PATCH v2 01/18] iio: accel: stk8ba50: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-work-v2-1-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=2065; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=A+jJhIDgm1iZ2qG8qDX5Ho/zv30+nWI7vP+dpuGG+3w=; b=2MIS7p+uRUBrWI/SFgIAAG49ukcmwRC5ZnvYJo2qG5aQpdQKbnQxFNouRam0pQHX+IoRRv5hi /PPMZWF998OAA5UuRlv4XoSJ/TFl4lVyFniEUc+/x4wJAT0bPNFP6GA 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. Tested on a tablet whose sensor is mounted rotated 180 degrees about X: without the patch in_accel_mount_matrix is absent, so iio-sensor-proxy has to fall back to a udev/hwdb override; with it the matrix from _DSD is reported and the orientation comes out correct. Signed-off-by: He Xin --- drivers/iio/accel/stk8ba50.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c index 6c1e286c0a..f510013570 100644 --- a/drivers/iio/accel/stk8ba50.c +++ b/drivers/iio/accel/stk8ba50.c @@ -102,10 +102,26 @@ struct stk8ba50_data { s16 chans[3]; aligned_s64 timetamp; } scan; + struct iio_mount_matrix orientation; +}; + +static const struct iio_mount_matrix * +stk8ba50_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct stk8ba50_data *data = iio_priv(indio_dev); + + return &data->orientation; +} + +static const struct iio_chan_spec_ext_info stk8ba50_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, stk8ba50_get_mount_matrix), + { } }; #define STK8BA50_ACCEL_CHANNEL(index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = stk8ba50_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ @@ -395,6 +411,11 @@ static int stk8ba50_probe(struct i2c_client *client) return -ENOMEM; data = iio_priv(indio_dev); + + ret = iio_read_mount_matrix(&client->dev, &data->orientation); + if (ret) + return ret; + data->client = client; i2c_set_clientdata(client, indio_dev); mutex_init(&data->lock); -- 2.53.0