From: He Xin via B4 Relay <devnull+hexin.hexin.host@kernel.org>
To: linux-iio@vger.kernel.org,
Michael Hennerich <Michael.Hennerich@analog.com>,
Puranjay Mohan <puranjay@kernel.org>,
Marcelo Schmitt <marcelo.schmitt@analog.com>,
Antoniu Miclaus <antoniu.miclaus@analog.com>,
Ramona Gradinariu <ramona.gradinariu@analog.com>,
Petre Rodan <petre.rodan@subdimension.ro>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux@analog.com, "He Xin" <hexin@hexin.host>
Subject: [PATCH v2 07/18] iio: accel: bma220_core: support mount matrix
Date: Mon, 30 Nov 2026 14:29:36 +0800 [thread overview]
Message-ID: <20261130-work-v2-7-9eccecc71702@hexin.host> (raw)
In-Reply-To: <20261130-work-v2-0-9eccecc71702@hexin.host>
From: He Xin <hexin@hexin.host>
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 <hexin@hexin.host>
---
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
WARNING: multiple messages have this Message-ID (diff)
From: He Xin <hexin@hexin.host>
To: linux-iio@vger.kernel.org,
Michael Hennerich <Michael.Hennerich@analog.com>,
Puranjay Mohan <puranjay@kernel.org>,
Marcelo Schmitt <marcelo.schmitt@analog.com>,
Antoniu Miclaus <antoniu.miclaus@analog.com>,
Ramona Gradinariu <ramona.gradinariu@analog.com>,
Petre Rodan <petre.rodan@subdimension.ro>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux@analog.com, "He Xin" <hexin@hexin.host>
Subject: [PATCH v2 07/18] iio: accel: bma220_core: support mount matrix
Date: Mon, 30 Nov 2026 14:29:36 +0800 [thread overview]
Message-ID: <20261130-work-v2-7-9eccecc71702@hexin.host> (raw)
In-Reply-To: <20261130-work-v2-0-9eccecc71702@hexin.host>
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 <hexin@hexin.host>
---
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
next prev parent reply other threads:[~2026-11-30 6:30 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 6:29 [PATCH v2 00/18] iio: accel: add mount matrix support to 18 accelerometer drivers He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 01/18] iio: accel: stk8ba50: support mount matrix He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-12-01 10:24 ` Andy Shevchenko
2026-12-02 2:18 ` 何鑫
2026-11-30 6:29 ` [PATCH v2 02/18] iio: accel: adxl345_core: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 03/18] iio: accel: adxl355_core: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 04/18] iio: accel: adxl367: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 05/18] iio: accel: adxl372: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 06/18] iio: accel: adxl380: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` He Xin via B4 Relay [this message]
2026-11-30 6:29 ` [PATCH v2 07/18] iio: accel: bma220_core: " He Xin
2026-11-30 6:29 ` [PATCH v2 08/18] iio: accel: bmi088-accel-core: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 09/18] iio: accel: da280: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 10/18] iio: accel: da311: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 11/18] iio: accel: dmard06: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 12/18] iio: accel: dmard09: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 13/18] iio: accel: dmard10: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 14/18] iio: accel: mma7455_core: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 15/18] iio: accel: msa311: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 16/18] iio: accel: mxc6255: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-12-01 10:29 ` Andy Shevchenko
2026-11-30 6:29 ` [PATCH v2 17/18] iio: accel: sca3300: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 6:29 ` [PATCH v2 18/18] iio: accel: stk8312: " He Xin via B4 Relay
2026-11-30 6:29 ` He Xin
2026-11-30 11:34 ` [PATCH v2 00/18] iio: accel: add mount matrix support to 18 accelerometer drivers Joshua Crofts
2026-12-01 10:27 ` Andy Shevchenko
2026-12-02 2:23 ` He Xin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130-work-v2-7-9eccecc71702@hexin.host \
--to=devnull+hexin.hexin.host@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=dlechner@baylibre.com \
--cc=hexin@hexin.host \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux@analog.com \
--cc=marcelo.schmitt@analog.com \
--cc=nuno.sa@analog.com \
--cc=petre.rodan@subdimension.ro \
--cc=puranjay@kernel.org \
--cc=ramona.gradinariu@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.