From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796020226; b=i2gyLddG4BLGjRgNZSeMKVu/C2qUlnQfzBItGIdilFqo9vquaXjTp8VHvarb14nKLBjF US2wUCBcrRQsJgbdJMI3vxJhKLyMUlTcwh4YlhXWUMnLxJk8ytAr/2uXOQfNwUnSWjTue XKtiVxn04Now0wMD+tW0nCmWRQH5IB6jFyqP1/CCIh1Oo4HDrBZIdy9qhdShoR1lWmc5k MRJ/LUKLK9OXPin/nlx71IBTQ8DmHHu0AD4sFQ2XJQW8jmxQusD8qiw9eNOU9QQDhoK43 DGNeS93t+t7O/vwn4PQrP25s4CuHbBWxkP9b2VhJzy5gf6uXPBi7sG/6yD2T1DRCq/w== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020226; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=JDL2DuAgS3kNWB381oEJw+Kctwy9Vj3uOMmZ6mJmyY4=; b=2XwAsjfy20qyKkAbVZxW0L0xrzDcB1KNZpPJCmEpolPPaRD09nODrmDveWC53eD12YKK Zs91+EQmupbPTqLVhq75/gH9Puk1y1VblZX6CnNWI0s0tnihq35UNWxQf4+cENmL+pQuL /b87Ko/rYcsPiqcF/PmPn97ectRPqXWUcBM3zntzRXH5jk/CFrslukFD2pYvuJygah9/X Wmfe5cK/iCbB5oX1gQ/sYFs7gTBzhhQgIU8OEXTgMS5I7BmxTtmDfp09NdDIaSVZQvhCv k283owjCr4OEiwXl/wKGcYo4rRH+Ror4yhk0m9q0NZq1lzu2YuVjlG5c/0Hdk8zVP7g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aD9WD+59; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 023FA606A329 for ; Mon, 30 Nov 2026 06:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aD9WD+59 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796020225; b=a1RO0+Vu3uvHwCthwU/07ooVkWaTEnWULGGDYpaySw4vqfSIx0FKEw54I7oaYCE4jkgX veH7E4fY2iMCLgJkQdsrEcYazHj5UFSM5rgeRt+7LVAbwZ8pw6Ph/I+zsZohfvI5PDptH UWkl0OcN56tYtiSXa4ocgPKnHeDVXQ9Zr+s4mliwTQusn+ZpwXRRjB9XWZJSS+0PkL+jN CiJt500ymZufAUfpV7sGFVT/T+2u5VwLUez92sQ/1luSFkOKsmcVw3Z6Sm9oonoxGOAjD 5eEzRygAwEqbulCBKOfL2hUJ7pz4hfEeTOttJ89QlIa0z7ROWRJ0NVLapElerHHfjsQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796020225; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=JDL2DuAgS3kNWB381oEJw+Kctwy9Vj3uOMmZ6mJmyY4=; b=r/8RIkkEwSmGc7gJAhIWhSYkmjT4qlXbnZfjca3vQdXsLe9++C7dqzAjpndXr1tf28wo IGYUMh3C26+b2c4HKCDm5c6cq4Zupt+vddo2GsMPXJSUDMZ1UNX4ThUC016mvTZwPiAR4 3xqIO23PS+M7CJy0lzGc8l1/5dQtn22tnj8xj4p7ZaMme5zhxbIlyv9hFk4SfUIYFBLnV zUj6NWp6qaErZdCgIAq8aSQ4CtVVGWEaGrtynskZXl5ctCnXbRHI5ttbaraeZ12qD8vvF 0Y2O+hqmFaVdpfHSAoVvbvx0Yyy/g9Ua2bIi9VIK36qf0l1KryNIt3x37sLhqfhPWVg== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 0CEF61F00A02; Mon, 30 Nov 2026 06:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796020225; bh=JDL2DuAgS3kNWB381oEJw+Kctwy9Vj3uOMmZ6mJmyY4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=aD9WD+59cJ6nFuh4ddYDbomYqKf5pL+MufxZCQFjDaDB3a4P41DOKRCiGo2PmlKki 8icUVJT/LomTrhgx/WZ9iqc3X1usvus+/SzwNfjmVS7xdFgpqhqvoYmW++oQ/93Kak mW5eLoCPwW68CpTy4XKh9MtgWrWSErjUsoYBXfJM99pmcQIpkqscGS/SZ3dUKwzEkp n61gQ/8WSWLrjBqkC75bNijMwJMFf+MtCfSWKTigdui+n26s3/XQa0wdg914uTROjM ytese+hLfsJK8gQHhsjT6MEp5E/TK2mpLQdPxIA+4F5dAI0B3eW/jiMGQbB+n5bJ8f +NOyZtSwG2GiA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 8B5FF4E732; Mon, 30 Nov 2026 06:29:57 +0000 (UTC) From: He Xin via B4 Relay Date: Mon, 30 Nov 2026 14:29:47 +0800 Subject: [PATCH v2 18/18] iio: accel: stk8312: support mount matrix X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261130-work-v2-18-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=2173; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=Dkn0GV+qRcrW9Gc3CEbEEz6+PO+q/adMmLY7e+DCZ9g=; b=YwWj/KTau1PJXxMyzWInlrm9wRxwaQA40mlZBhRKbfBHnj26jyMMHKLfLQLUCnPj36wtBwLXT goF4F64NdvUCqexajdomY7lmhSH41q4HsgSLy15CCQdpr4zAPlz51w2 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 X-Original-From: He Xin Reply-To: hexin@hexin.host Content-Transfer-Encoding: 7bit From: He Xin 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 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c index 50840c3440..146cfc8c9f 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,11 @@ static int stk8312_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