From: He Xin Date: Fri, 04 Dec 2026 19:13:09 +0800 Subject: [PATCH v3 18/18] iio: accel: stk8312: support mount matrix MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-work-v3-18-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=2263; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=lh+DjJF4X5ke7PvGQJFsFBxV81nx8ei1NbqdFe9gJ3g=; b=Id3HH74GWOLy69m7Jy4hdWVz7YXwB6+HE6Tq/9SKUhTtym3XiOuF/IBb9PprF/Pe5F5dKsq5X 9rwYww2Eg7KAv6/1i07C8RhT2dY3svkUykGLqiKvZHkOri1ha3ZzjHF 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/stk8312.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c index 50840c3440..f44198b53b 100644 --- a/drivers/iio/accel/stk8312.c +++ b/drivers/iio/accel/stk8312.c @@ -78,8 +78,18 @@ static const struct { {12, 500000}, {6, 250000}, {3, 125000} }; +static const struct iio_mount_matrix * +stk8312_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info stk8312_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, stk8312_get_mount_matrix), + { } +}; + #define STK8312_ACCEL_CHANNEL(index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = stk8312_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ @@ -115,8 +125,18 @@ struct stk8312_data { s8 chans[3]; aligned_s64 timestamp; } scan; + struct iio_mount_matrix orientation; }; +static const struct iio_mount_matrix * +stk8312_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct stk8312_data *data = iio_priv(indio_dev); + + return &data->orientation; +} + static IIO_CONST_ATTR(in_accel_scale_available, STK8312_SCALE_AVAIL); static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("3.125 6.25 12.5 25 50 100 200 400"); @@ -516,6 +536,13 @@ static int stk8312_probe(struct i2c_client *client) return -ENOMEM; data = iio_priv(indio_dev); + + if (!iio_read_acpi_mount_matrix(&client->dev, &data->orientation, "ROTM")) { + 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