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=1796020215; b=dNP/Kx9MtJpddj0gfSBCr6EqSXIJLhE6e+9sbOhwvjEIBX31DznPAY4pRBdO5nPG+hjM 7212eEmC4+Q+KDcuQsUEV8r8xHE/wado3PaW+SbP/2bdjSpcfBCFKSN3ER+9qP8MHc1in 6ERp1k738eFw4/ty27ywyKTVuMAA/p4LlFwfpe3fDAyeGYTSg5hjZbMKUsfqvXX6ZPhAj Q56SNaOAStntWUXwDr2SGlsqxyjuMaftBnqvkCB7Sd9J3vozcAa2FEf0B6kgW1rUnL+4q ZuqTkz+bwp2voEi10OBMGZQJjqpTddBuYfNn05SUxq2wPcHsPUE9wdpNcndgP55OvAg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020215; 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=0gYfpqHpOzzOh2PdxJRiviSrokU3pUdtODuBrxdzDho=; b=J+FvefPmSNA4E5Ac22szUoVSGAvK9Tb5DVlBkYJibKhl+tCRU+T+5EihUh4oNA3pDOKh 06NuOD8kpwu38o1uMmxKoeDq2O7itVvn4C7NJpRLhazDtdlWUav30rae+OoPNrvG2C3rF 2Ovp1TZF+nx69uaGGU+voRiKeyI52nhmxnRr3Wu/ToVmVWAYsLzU2/JsEKonnouL2fm3x qbd+CgMLbI7oqO2U6e5XKVtncpFWBu/NyoZK0pxVzmb5pghV5vJ4TvEa5pED0uho8NUPl k4DzA2RauC7BH4v1AHw9SRdGTp9YAjkJBMqhleXvOFxj6KbEd5tR91VmpXfC63S811Q== 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=ePu4ZPaZ; 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 7FE57606A688 for ; Mon, 30 Nov 2026 06:30:15 +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=ePu4ZPaZ 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=1796020215; b=CtZzSsFdRRRhkG7VMhKBK4fcukrYLE678T8yJNW4A4JqCK2Dg7cK1HO1j6vIBZWYSnPW MVWq8uj+aVnlyTSZ1fZy6e+1rPyOP/Go94qTdDrUTmWFn54Asjci+EyUyOGudWi1YrsiI mKhZO5AR796gOvl4kKR+wsZdzOwXjXsgIonYE20RRyt5lu7ccIdOeUmVPwMacsfVYW2XZ ibBRE5HgWChekeDzFWuQOrUEZ6+9A73HsafayCif9P46lEdr1HEigHnfrDmayZNhozchC gpntq87vS1Y4fOBArIxVIekOkpoS0331TqGJ/0HbfpPbA8HnhuZa7rnYlhkx4DWvNnA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796020215; 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=0gYfpqHpOzzOh2PdxJRiviSrokU3pUdtODuBrxdzDho=; b=GJiv1HGi8U/uXra9kfWu3Jbi+QZGBdescwzeFCFFLR9j2bYMOPIymvSu/Vr7jzh4y3j8 w98eoCZo0Ulm8fGvKZSISErCj0d2TpVor6umVWKnp2ew3/vBK4AwZqaB9+WtPcQJNDmDk 7PnzlHmQtpncHYfDkmBahvREIHG8QUXKUqkoSuWbOx/rLiAJmGOSpIXE+dBJF8itrB9J4 K3KNqvXF7NzkfPPX3GbEFys8ttIgSvVnCaV2i885Wf2df2Eizps1s0YREa5f2t4FGGh0Y lfvE9LpBpFbve4fJFXbpjlOal8JoUNVwilmGup5rzN1AV7iWG64ipoRE01omKbmqgIw== 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 9C8511F00929; Mon, 30 Nov 2026 06:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796020215; bh=0gYfpqHpOzzOh2PdxJRiviSrokU3pUdtODuBrxdzDho=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=ePu4ZPaZUtnUH57SVYu5x8vJr9qCioGPz+YjZy9WmOarg0riADkjFvyvWS4m4IXYB hI7jKXPlKfmN0PufFBjFboLJLtGSrNkr+qsZ0whas1RoU7FYAFf1OoER0rMGZS0CUk Efa7t0T1IqI/vFqcLGrzx63jl63meYS037fPW2c8ltTIpJbqB0qMEqTt7yaR1HLqHT tJORz6DVZuXSEYB0/gzQYHBdXSuKwn2hi+uvJTDV7rg3WfamtDwyoP+F8hpOWd2iEh EYoISm2GRJ7CSoSBYyNTrKgE/fgCksx9Z4lJ+zsim8XMXIu/1J0x3SUG2ScKND/wnW 0vOAgpKK67k1g== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id CE07C4E706; Mon, 30 Nov 2026 06:29:55 +0000 (UTC) From: He Xin via B4 Relay Date: Mon, 30 Nov 2026 14:29:36 +0800 Subject: [PATCH v2 07/18] iio: accel: bma220_core: 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-7-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=2376; i=hexin@hexin.host; s=20261130; h=from:subject:message-id; bh=j3Y4YdLj/16/g/zZKc1J0EKKYP4bk33H8O7bTudMoOU=; b=pszvgEssdQyTVaMObGZ3oxVA4RyI2HBdDqO65XJaR+71B1JlSNrzb7pe3ameTuCphkFHR9fiX GwBKKkNPW9vCzZH6S+ySg30jmjA3CR3I3bQxcdSga79aggcu3aqJyeK 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/bma220_core.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c index b83abfdd84..c718098cad 100644 --- a/drivers/iio/accel/bma220_core.c +++ b/drivers/iio/accel/bma220_core.c @@ -94,8 +94,18 @@ #define BMA220_COF_64Hz 0x4 #define BMA220_COF_32Hz 0x5 +static const struct iio_mount_matrix * +bma220_core_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan); + +static const struct iio_chan_spec_ext_info bma220_core_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, bma220_core_get_mount_matrix), + { } +}; + #define BMA220_ACCEL_CHANNEL(index, reg, axis) { \ .type = IIO_ACCEL, \ + .ext_info = bma220_core_ext_info, \ .address = reg, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ @@ -130,6 +140,7 @@ struct bma220_data { u8 lpf_3dB_freq_idx; u8 range_idx; struct iio_trigger *trig; + struct iio_mount_matrix orientation; struct { s8 chans[3]; /* Ensure timestamp is naturally aligned. */ @@ -137,6 +148,15 @@ struct bma220_data { } scan __aligned(IIO_DMA_MINALIGN); }; +static const struct iio_mount_matrix * +bma220_core_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct bma220_data *data = iio_priv(indio_dev); + + return &data->orientation; +} + static const struct iio_chan_spec bma220_channels[] = { BMA220_ACCEL_CHANNEL(0, BMA220_REG_ACCEL_X, X), BMA220_ACCEL_CHANNEL(1, BMA220_REG_ACCEL_Y, Y), @@ -508,6 +528,11 @@ int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq) return -ENOMEM; data = iio_priv(indio_dev); + + ret = iio_read_mount_matrix(dev, &data->orientation); + if (ret) + return ret; + data->regmap = regmap; ret = bma220_init(dev, data); -- 2.53.0