iio: Allow to read mount matrix from ACPI
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 21 Feb 2019 17:02:46 +0000 (18:02 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 4 Apr 2019 19:19:46 +0000 (20:19 +0100)
Currently mount matrix is allowed in Device Tree, though there is
no technical issue to extend it to support ACPI.

Convert the function to use device_property_read_string_array() and
thus allow to read mount matrix from ACPI if available.

Example of use in _DSD method:

  Name (_DSD, Package ()
  {
     ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
     Package ()
     {
        Package () { "mount-matrix", Package() {
                "1", "0",     "0",
                "0", "0.866", "0.5",
                "0", "-0.5",  "0.866",
        } },
     }
  })

At the same time drop the "of" prefix from its name and
convert current users.

No functional change intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/kxsd9.c
drivers/iio/gyro/mpu3050-core.c
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
drivers/iio/industrialio-core.c
drivers/iio/magnetometer/ak8974.c
drivers/iio/magnetometer/ak8975.c
include/linux/iio/iio.h

index 0c0df4fce420694437f0ba14e10b61f0ed5a28e1..70c60db6224783c9fddaa21fb2eda0f39eedb78c 100644 (file)
@@ -420,9 +420,7 @@ int kxsd9_common_probe(struct device *dev,
        indio_dev->available_scan_masks = kxsd9_scan_masks;
 
        /* Read the mounting matrix, if present */
-       ret = of_iio_read_mount_matrix(dev,
-                                      "mount-matrix",
-                                      &st->orientation);
+       ret = iio_read_mount_matrix(dev, "mount-matrix", &st->orientation);
        if (ret)
                return ret;
 
index 77fac81a3adce2245fe0bf499b60a382c08af98b..8200e48f561b049b8c5c13e2a6c1c40627777505 100644 (file)
@@ -1149,8 +1149,7 @@ int mpu3050_common_probe(struct device *dev,
        mpu3050->divisor = 99;
 
        /* Read the mounting matrix, if present */
-       ret = of_iio_read_mount_matrix(dev, "mount-matrix",
-                                      &mpu3050->orientation);
+       ret = iio_read_mount_matrix(dev, "mount-matrix", &mpu3050->orientation);
        if (ret)
                return ret;
 
index 650de0fefb7bdac2eef66c16e810951036eab6f1..0692198043341e13faaf3c944489e7ed7b7f4db7 100644 (file)
@@ -1021,8 +1021,8 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 
        pdata = dev_get_platdata(dev);
        if (!pdata) {
-               result = of_iio_read_mount_matrix(dev, "mount-matrix",
-                                                 &st->orientation);
+               result = iio_read_mount_matrix(dev, "mount-matrix",
+                                              &st->orientation);
                if (result) {
                        dev_err(dev, "Failed to retrieve mounting matrix %d\n",
                                result);
index 4700fd5d8c90a6ebaee08659b4bb17ca9db105a4..f2ebca65f964c78d477812fe70683ba1b16caa62 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/device.h>
 #include <linux/fs.h>
 #include <linux/poll.h>
+#include <linux/property.h>
 #include <linux/sched.h>
 #include <linux/wait.h>
 #include <linux/cdev.h>
@@ -530,8 +531,8 @@ ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv,
 EXPORT_SYMBOL_GPL(iio_show_mount_matrix);
 
 /**
- * of_iio_read_mount_matrix() - retrieve iio device mounting matrix from
- *                              device-tree "mount-matrix" property
+ * iio_read_mount_matrix() - retrieve iio device mounting matrix from
+ *                           device "mount-matrix" property
  * @dev:       device the mounting matrix property is assigned to
  * @propname:  device specific mounting matrix property name
  * @matrix:    where to store retrieved matrix
@@ -541,40 +542,29 @@ EXPORT_SYMBOL_GPL(iio_show_mount_matrix);
  *
  * Return: 0 if success, or a negative error code on failure.
  */
-#ifdef CONFIG_OF
-int of_iio_read_mount_matrix(const struct device *dev,
-                            const char *propname,
-                            struct iio_mount_matrix *matrix)
+int iio_read_mount_matrix(struct device *dev, const char *propname,
+                         struct iio_mount_matrix *matrix)
 {
-       if (dev->of_node) {
-               int err = of_property_read_string_array(dev->of_node,
-                               propname, matrix->rotation,
-                               ARRAY_SIZE(iio_mount_idmatrix.rotation));
+       size_t len = ARRAY_SIZE(iio_mount_idmatrix.rotation);
+       int err;
 
-               if (err == ARRAY_SIZE(iio_mount_idmatrix.rotation))
-                       return 0;
+       err = device_property_read_string_array(dev, propname,
+                                               matrix->rotation, len);
+       if (err == len)
+               return 0;
 
-               if (err >= 0)
-                       /* Invalid number of matrix entries. */
-                       return -EINVAL;
+       if (err >= 0)
+               /* Invalid number of matrix entries. */
+               return -EINVAL;
 
-               if (err != -EINVAL)
-                       /* Invalid matrix declaration format. */
-                       return err;
-       }
+       if (err != -EINVAL)
+               /* Invalid matrix declaration format. */
+               return err;
 
        /* Matrix was not declared at all: fallback to identity. */
        return iio_setup_mount_idmatrix(dev, matrix);
 }
-#else
-int of_iio_read_mount_matrix(const struct device *dev,
-                            const char *propname,
-                            struct iio_mount_matrix *matrix)
-{
-       return iio_setup_mount_idmatrix(dev, matrix);
-}
-#endif
-EXPORT_SYMBOL(of_iio_read_mount_matrix);
+EXPORT_SYMBOL(iio_read_mount_matrix);
 
 static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type,
                                  int size, const int *vals)
index 93be1f4c0f276f831b7136f2e90a3df53b40f901..f4d0a6c0fde70a02758e2fb445248184858a6dae 100644 (file)
@@ -733,9 +733,8 @@ static int ak8974_probe(struct i2c_client *i2c,
        ak8974->i2c = i2c;
        mutex_init(&ak8974->lock);
 
-       ret = of_iio_read_mount_matrix(&i2c->dev,
-                                      "mount-matrix",
-                                      &ak8974->orientation);
+       ret = iio_read_mount_matrix(&i2c->dev, "mount-matrix",
+                                   &ak8974->orientation);
        if (ret)
                return ret;
 
index d430b80808ef782dfc777ab6021c068fb93b294d..db7214ac514cd94f5752f908f95e80c635e97bf0 100644 (file)
@@ -911,9 +911,8 @@ static int ak8975_probe(struct i2c_client *client,
        data->eoc_irq = 0;
 
        if (!pdata) {
-               err = of_iio_read_mount_matrix(&client->dev,
-                                              "mount-matrix",
-                                              &data->orientation);
+               err = iio_read_mount_matrix(&client->dev, "mount-matrix",
+                                           &data->orientation);
                if (err)
                        return err;
        } else
index a74cb177dc6f9cf9bcab0ed6547760b1e01b6e70..bb10c1bee3012d28f0af2d252288737fcffcd03b 100644 (file)
@@ -130,8 +130,8 @@ struct iio_mount_matrix {
 
 ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv,
                              const struct iio_chan_spec *chan, char *buf);
-int of_iio_read_mount_matrix(const struct device *dev, const char *propname,
-                            struct iio_mount_matrix *matrix);
+int iio_read_mount_matrix(struct device *dev, const char *propname,
+                         struct iio_mount_matrix *matrix);
 
 typedef const struct iio_mount_matrix *
        (iio_get_mount_matrix_t)(const struct iio_dev *indio_dev,