[PATCH v2 3/3] iio: magnetometer: mmc5633: Add mount matrix support
From: Gerard Marull-Paretas
Date: Sun Nov 22 2026 - 14:08:59 EST
Read the mount matrix from the firmware and expose it, so that user
space can account for how the sensor is oriented on the board.
Signed-off-by: Gerard Marull-Paretas <gerard@xxxxxxxxxxx>
---
drivers/iio/magnetometer/mmc5633.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/iio/magnetometer/mmc5633.c b/drivers/iio/magnetometer/mmc5633.c
index 79015c7984de..f9ecb3737cf6 100644
--- a/drivers/iio/magnetometer/mmc5633.c
+++ b/drivers/iio/magnetometer/mmc5633.c
@@ -83,6 +83,7 @@ struct mmc5633_data {
struct regmap *regmap;
struct i3c_device *i3cdev;
struct mutex mutex; /* protect to finish one whole measurement */
+ struct iio_mount_matrix orientation;
};
static int mmc5633_samp_freq[][2] = {
@@ -92,6 +93,20 @@ static int mmc5633_samp_freq[][2] = {
{ 6, 600000 },
};
+static const struct iio_mount_matrix *
+mmc5633_get_mount_matrix(const struct iio_dev *indio_dev,
+ const struct iio_chan_spec *chan)
+{
+ struct mmc5633_data *data = iio_priv(indio_dev);
+
+ return &data->orientation;
+}
+
+static const struct iio_chan_spec_ext_info mmc5633_ext_info[] = {
+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, mmc5633_get_mount_matrix),
+ { }
+};
+
#define MMC5633_CHANNEL(_axis) { \
.type = IIO_MAGN, \
.modified = 1, \
@@ -100,6 +115,7 @@ static int mmc5633_samp_freq[][2] = {
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
BIT(IIO_CHAN_INFO_SCALE), \
+ .ext_info = mmc5633_ext_info, \
}
static const struct iio_chan_spec mmc5633_channels[] = {
@@ -480,6 +496,10 @@ static int mmc5633_common_probe(struct regmap *regmap, char *name,
fsleep(MMC5633_POWER_ON_US);
+ ret = iio_read_mount_matrix(dev, &data->orientation);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to read mount matrix\n");
+
indio_dev->info = &mmc5633_info;
indio_dev->name = name;
indio_dev->channels = mmc5633_channels;
--
2.45.2