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=1796020205; b=I+9LzDYhRH1+7Hx5UvxyE8w8hKbHID0Db/MrrWpYU8VLAjKxa0Gu/VT9Oo99eZNJ4rav Hxv8pkqSHq5Nkfga7rL0EMBjhj+yOM2C196EstoT2lGX7ILgDAzks0Y98LZL/A1O67zgk 5l/q8JRiMhb4vpf3EnA4TX69QT5Kjsh4zFwxQgb9CnnDL3MJ3pg9G3mlLTVy3aNnN3dFB /SFQQX4Ut1SVvtzxCiiM5YSuvbjhEhLy9Vc0IYiWQERQrUDcwjP3Kytwn/hds7FUseHEO Yj0fx9kSIjK2HSs4I9OB3Gk1/6grvNsNTQEd6g9PCsnnm5bcM2IyaU7r2STKDhEaedA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020205; 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=5Swjb8j28Hee4q+ujywBi3CSQlRsYgj7EB1fuHVf5e4=; b=jQiYkMnFbUGmcJA3fji+YR/wwHAVeZGVtg0lxJaz8t5wXNZJqn6dhgb9wuWjcRclMmIv VhtIbz45eo6X/pZTHY5fUdRnoESFBkAnETj4aXDiIq29G1wl9cuBiezSIFLnisDoIYIir 5X4yXpyp8QPKs2USiOYwgx3gScMyZftGdv57yBl4ppw1TSmPpIqO5ITHOnpH84nj/yP8v RS4Pyt2dYKoIhzBfDP8xgFTh68R1pzPFdYQfV+0tWmRRU6BmqhyFVZVQqMfNnGL8NfNIG XDyn6XlY3SZixmSHbCNJ6LGP7bJnU1NXa0yApsEhGG3hBDmXjhCVgXvq8RO+oU/GmdA== 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=NZDlbv6l; 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 EBB39606A33A for ; Mon, 30 Nov 2026 06:30:04 +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=NZDlbv6l 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=1796020204; b=qun5/s12fZk/vfHtTwk7kaOlhlrkjg7cCBmUBbZHiDuXrN46tQ97STbs5Dym2CH+kG7r 3gdBNHA0UN6HLLm0l2NPtG2/EBuh3sIJ2EH96NUl8mMyrKfSYhCj4DQAh0UjfbcA14jXm Ggx7me3JyuRu6XsabZMdOya9q+5AsqCRYqXnqQfuAU/0WxV6gDDmIgrWIbmiH+tT2EdLT dLqw6fob/+AAZ0/Z2WbRiPyYtQUKxqCZ4tmwAvcTUuE9L2SstBW3nThdR5EEawphqrjHM uqF2zsX0kVbL+SyHxfdhKsne/lQbDPBZ+bvpcJTVzhSW88Dfvm84ywkjs9A+bCmsySQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796020204; 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=5Swjb8j28Hee4q+ujywBi3CSQlRsYgj7EB1fuHVf5e4=; b=rPCBZGgcYdW0qyF9qxnzFOrbdoGkmTeeOKOqqPXivUu3Pe0pFaPVLpRLcBk2LyzAACUJ YWDWLf9IkYhP/zvsDqznN7BwOGMRZifZRL4pfI17DZP6bMCONp93YkEZPTaxIH2ECQHIK FmSy+J9GG58NfiBlEbmWW+3m4kX6Xoz7Qrg//Q+wVTlcVmiR04a6HDCcYrKJB5T4ms6MV P6IwZDL0ecqOKzTAgBjmxrZKEokrPqglq9DoMQgkulO+7ZQlzVfZ6+x5Fgsn3PMlRlL2p dhvROuFeekRcNuQlBPKG+euFKRbVrA6aiLHVEzV6k4hucr4BPz5Mq5cqc3HEDUZAl+A== 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 662C31F0089A; Mon, 30 Nov 2026 06:29:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796020204; bh=5Swjb8j28Hee4q+ujywBi3CSQlRsYgj7EB1fuHVf5e4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=NZDlbv6lOZzKu5BG0CYquTmtod4L9n7A+mZMBduCNFPbVjjOA1uqrVwEYZL4z0rOZ FoOd+jDk3ikpXZ7X8s6uvL4Wc1nPy+/2Yuf2FRNIP3qarna2ci+baO2JDYDelORzk4 0ep8Tnmu1A3A84INp1Nt8gUeUArutXTm3dlyF4erR7uwc+RX3IEOznlW2jBwapMMAH t+mfqji7qtWK/mxUvLSzsD/DZO3qI755r2NtmNt4zwbcpvyhy917C+7VYYTvsgMtYg D0px7f3f8lkwfhMgQqRWOIYMXCQEtugUP/g0US3eJ3BIyTV0/VR4tvDg15q/yucSE/ KRIey1W+O8Ebg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id E2A5E4E6EE; Mon, 30 Nov 2026 06:29:54 +0000 (UTC) From: He Xin via B4 Relay Date: Mon, 30 Nov 2026 14:29:30 +0800 Subject: [PATCH v2 01/18] iio: accel: stk8ba50: 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-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 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. 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