iio: magnetometer: hmc5843: add mount matrix support
authorH. Nikolaus Schaller <hns@goldelico.com>
Thu, 21 Feb 2019 17:02:53 +0000 (18:02 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 4 Apr 2019 19:19:48 +0000 (20:19 +0100)
This patch allows to read a mount-matrix device tree
property and report to user-space or in-kernel iio
clients.

Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/magnetometer/hmc5843.h
drivers/iio/magnetometer/hmc5843_core.c

index a75224cf99df24b50c8f823332b35f171fb0d280..e3e22d2508d36f378b761fdf2bdba8b6033126a3 100644 (file)
@@ -43,6 +43,7 @@ struct hmc5843_data {
        struct mutex lock;
        struct regmap *regmap;
        const struct hmc5843_chip_info *variant;
+       struct iio_mount_matrix orientation;
        __be16 buffer[8];
 };
 
index ada142fb7aa35926a331840d785ce496a4a3feae..05629ec56d8095ca803d0e268cb97aaaea9985df 100644 (file)
@@ -237,6 +237,15 @@ int hmc5843_set_measurement_configuration(struct iio_dev *indio_dev,
        return hmc5843_set_meas_conf(data, meas_conf);
 }
 
+static const struct iio_mount_matrix *
+hmc5843_get_mount_matrix(const struct iio_dev *indio_dev,
+                         const struct iio_chan_spec *chan)
+{
+       struct hmc5843_data *data = iio_priv(indio_dev);
+
+       return &data->orientation;
+}
+
 static const struct iio_enum hmc5843_meas_conf_enum = {
        .items = hmc5843_meas_conf_modes,
        .num_items = ARRAY_SIZE(hmc5843_meas_conf_modes),
@@ -247,7 +256,8 @@ static const struct iio_enum hmc5843_meas_conf_enum = {
 static const struct iio_chan_spec_ext_info hmc5843_ext_info[] = {
        IIO_ENUM("meas_conf", true, &hmc5843_meas_conf_enum),
        IIO_ENUM_AVAILABLE("meas_conf", &hmc5843_meas_conf_enum),
-       { },
+       IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, hmc5843_get_mount_matrix),
+       { }
 };
 
 static const struct iio_enum hmc5983_meas_conf_enum = {
@@ -260,7 +270,8 @@ static const struct iio_enum hmc5983_meas_conf_enum = {
 static const struct iio_chan_spec_ext_info hmc5983_ext_info[] = {
        IIO_ENUM("meas_conf", true, &hmc5983_meas_conf_enum),
        IIO_ENUM_AVAILABLE("meas_conf", &hmc5983_meas_conf_enum),
-       { },
+       IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, hmc5843_get_mount_matrix),
+       { }
 };
 
 static
@@ -635,6 +646,11 @@ int hmc5843_common_probe(struct device *dev, struct regmap *regmap,
        data->variant = &hmc5843_chip_info_tbl[id];
        mutex_init(&data->lock);
 
+       ret = iio_read_mount_matrix(dev, "mount-matrix",
+                               &data->orientation);
+       if (ret)
+               return ret;
+
        indio_dev->dev.parent = dev;
        indio_dev->name = name;
        indio_dev->info = &hmc5843_info;