iio: Allow to read mount matrix from ACPI
Subsystems (4)
PATCH 1/1 iio: Allow to read mount matrix from ACPI
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.
At the same time drop the "of" prefix from its name and convert current users.
No functional change intended.
--- drivers/iio/accel/kxsd9.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +- drivers/iio/industrialio-core.c | 46 +++++++++------------- drivers/iio/magnetometer/ak8974.c | 2 +- drivers/iio/magnetometer/ak8975.c | 2 +- include/linux/iio/iio.h | 4 +- 7 files changed, 25 insertions(+), 35 deletions(-)
drivers/iio/accel/kxsd9.c +1 -1
@@ -420,7 +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, + ret =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (ret)
drivers/iio/gyro/mpu3050-core.c +1 -1
@@ -1149,7 +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" , + ret =iio_read_mount_matrix (dev,"mount-matrix" , &mpu3050->orientation);if (ret)return ret;
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +1 -1
@@ -990,7 +990,7 @@ 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" , + result =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (result) { dev_err(dev, "Failed to retrieve mounting matrix %d\n",
drivers/iio/industrialio-core.c +18 -28
72 lines not on this page · raw message
drivers/iio/magnetometer/ak8974.c +1 -1
@@ -733,7 +733,7 @@ static int ak8974_probe(struct i2c_client *i2c, ak8974->i2c = i2c;mutex_init (&ak8974->lock); - ret =of_iio_read_mount_matrix (&i2c->dev, + ret =iio_read_mount_matrix (&i2c->dev,"mount-matrix" , &ak8974->orientation);if (ret)
drivers/iio/magnetometer/ak8975.c +1 -1
@@ -911,7 +911,7 @@ static int ak8975_probe(struct i2c_client *client, data->eoc_irq =0 ;if (!pdata) { - err =of_iio_read_mount_matrix (&client->dev, + err =iio_read_mount_matrix (&client->dev,"mount-matrix" , &data->orientation);if (err)
include/linux/iio/iio.h +2 -2
@@ -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,
Signature · 1 line
2.20.1
Jonathan Cameron
maintainerQuoted 6 lines · On Wed, 20 Feb 2019 18:20:52 +0300 Andy Shevchenko…
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.
Quoted 6 lines
At the same time drop the "of" prefix from its name and convert current users.
No functional change intended.
Signed-off-by Andy Shevchenko <[email protected]>
Hi Andy,
I sort of agree that there is no obvious reason to limit it to DT. One corner that is unfortunate is that we have ACPI DSDT with _OFT providing the same thing. Neither is 'standard' as such.
Also, could we have an example of what the DSDT would look like to provide this for a device? I'm too lazy to figure it out for myself given you probably already know off the top of your head ;)
Thanks,
Jonathan
Quoted 169 lines
--- drivers/iio/accel/kxsd9.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +- drivers/iio/industrialio-core.c | 46 +++++++++------------- drivers/iio/magnetometer/ak8974.c | 2 +- drivers/iio/magnetometer/ak8975.c | 2 +- include/linux/iio/iio.h | 4 +- 7 files changed, 25 insertions(+), 35 deletions(-)drivers/iio/accel/kxsd9.c +1
-1@@ -420,7 +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, + ret =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (ret)drivers/iio/gyro/mpu3050-core.c +1
-1@@ -1149,7 +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" , + ret =iio_read_mount_matrix (dev,"mount-matrix" , &mpu3050->orientation);if (ret)return ret;drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +1
-1@@ -990,7 +990,7 @@ 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" , + result =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (result) { dev_err(dev, "Failed to retrieve mounting matrix %d\n",drivers/iio/industrialio-core.c +18
-28@@ -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> @@ -525,8 +526,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 @@ -536,40 +537,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)drivers/iio/magnetometer/ak8974.c +1
-1@@ -733,7 +733,7 @@ static int ak8974_probe(struct i2c_client *i2c, ak8974->i2c = i2c;mutex_init (&ak8974->lock); - ret =of_iio_read_mount_matrix (&i2c->dev, + ret =iio_read_mount_matrix (&i2c->dev,"mount-matrix" , &ak8974->orientation);if (ret)drivers/iio/magnetometer/ak8975.c +1
-1@@ -911,7 +911,7 @@ static int ak8975_probe(struct i2c_client *client, data->eoc_irq =0 ;if (!pdata) { - err =of_iio_read_mount_matrix (&client->dev, + err =iio_read_mount_matrix (&client->dev,"mount-matrix" , &data->orientation);if (err)include/linux/iio/iio.h +2
-2@@ -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,
Hi Andy,
Quoted 10 lines
Am 20.02.2019 um 16:20 schrieb Andy Shevchenko <[email protected]>:
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.At the same time drop the "of" prefix from its name and convert current users.
Maybe we can drop the "of" prefix after my earlier patches have been accepted?
So that you patch does not break compile of my patch series.
Quoted 171 lines
No functional change intended.
Signed-off-by Andy Shevchenko <[email protected]>---
drivers/iio/accel/kxsd9.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +- drivers/iio/industrialio-core.c | 46 +++++++++------------- drivers/iio/magnetometer/ak8974.c | 2 +- drivers/iio/magnetometer/ak8975.c | 2 +- include/linux/iio/iio.h | 4 +- 7 files changed, 25 insertions(+), 35 deletions(-)drivers/iio/accel/kxsd9.c +1
-1@@ -420,7 +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, + ret =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (ret)drivers/iio/gyro/mpu3050-core.c +1
-1@@ -1149,7 +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" , + ret =iio_read_mount_matrix (dev,"mount-matrix" , &mpu3050->orientation);if (ret)return ret;drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +1
-1@@ -990,7 +990,7 @@ 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" , + result =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (result) { dev_err(dev, "Failed to retrieve mounting matrix %d\n",drivers/iio/industrialio-core.c +18
-28@@ -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> @@ -525,8 +526,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 @@ -536,40 +537,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)drivers/iio/magnetometer/ak8974.c +1
-1@@ -733,7 +733,7 @@ static int ak8974_probe(struct i2c_client *i2c, ak8974->i2c = i2c;mutex_init (&ak8974->lock); - ret =of_iio_read_mount_matrix (&i2c->dev, + ret =iio_read_mount_matrix (&i2c->dev,"mount-matrix" , &ak8974->orientation);if (ret)drivers/iio/magnetometer/ak8975.c +1
-1@@ -911,7 +911,7 @@ static int ak8975_probe(struct i2c_client *client, data->eoc_irq =0 ;if (!pdata) { - err =of_iio_read_mount_matrix (&client->dev, + err =iio_read_mount_matrix (&client->dev,"mount-matrix" , &data->orientation);if (err)include/linux/iio/iio.h +2
-2@@ -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);
Quoted 5 lines
typedef const struct
iio_mount_matrix*
(iio_get_mount_matrix_t)(const structiio_dev*indio_dev,Signature · 1 line
2.20.1
BR and thanks,
Nikolaus
Quoted 10 lines · H. Nikolaus Schaller
Hi Andy,
Quoted 8 lines
Am 20.02.2019 um 16:20 schrieb Andy Shevchenko <[email protected]>:
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.
Quoted 6 lines
Quoted 2 lines
At the same time drop the "of" prefix from its name and convert current users.
Maybe we can drop the "of" prefix after my earlier patches have been accepted?
So that you patch does not break compile of my patch series.
Whatever Jonathan considers the best for the users and developers!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Wed, 20 Feb 2019 18:20:52 +0300 Andy Shevchenko…
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.At the same time drop the "of" prefix from its name and convert current users.
No functional change intended.
Quoted 7 lines
Quoted 1 line
Signed-off-by Andy Shevchenko <[email protected]>Hi Andy,
I sort of agree that there is no obvious reason to limit it to DT. One corner that is unfortunate is that we have ACPI DSDT with
_OFTproviding the same thing. Neither is 'standard' as such.
He-h, that _OFT should be parsed on per device basis. I'm tired of firmware writers that are (abusing / not using in a clever way) ACPI features.
Quoted 3 lines
Also, could we have an example of what the DSDT would look like to provide this for a device? I'm too lazy to figure it out for myself given you probably already know off the top of your head ;)
Sure.
Since it's an array of strings it would be as simple as
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"
} }
}
})Should I send a version with extended commit message?
P.S. This is basically the example of any property that can be provided
via ACPI. Just add / replace name and value(s).
Quoted 175 lines
Thanks,
Jonathan
Quoted 169 lines
--- drivers/iio/accel/kxsd9.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +- drivers/iio/industrialio-core.c | 46 +++++++++------------- drivers/iio/magnetometer/ak8974.c | 2 +- drivers/iio/magnetometer/ak8975.c | 2 +- include/linux/iio/iio.h | 4 +- 7 files changed, 25 insertions(+), 35 deletions(-)drivers/iio/accel/kxsd9.c +1
-1@@ -420,7 +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, + ret =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (ret)drivers/iio/gyro/mpu3050-core.c +1
-1@@ -1149,7 +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" , + ret =iio_read_mount_matrix (dev,"mount-matrix" , &mpu3050->orientation);if (ret)return ret;drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +1
-1@@ -990,7 +990,7 @@ 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" , + result =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (result) { dev_err(dev, "Failed to retrieve mounting matrix %d\n",drivers/iio/industrialio-core.c +18
-28@@ -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> @@ -525,8 +526,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 @@ -536,40 +537,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)drivers/iio/magnetometer/ak8974.c +1
-1@@ -733,7 +733,7 @@ static int ak8974_probe(struct i2c_client *i2c, ak8974->i2c = i2c;mutex_init (&ak8974->lock); - ret =of_iio_read_mount_matrix (&i2c->dev, + ret =iio_read_mount_matrix (&i2c->dev,"mount-matrix" , &ak8974->orientation);if (ret)drivers/iio/magnetometer/ak8975.c +1
-1@@ -911,7 +911,7 @@ static int ak8975_probe(struct i2c_client *client, data->eoc_irq =0 ;if (!pdata) { - err =of_iio_read_mount_matrix (&client->dev, + err =iio_read_mount_matrix (&client->dev,"mount-matrix" , &data->orientation);if (err)include/linux/iio/iio.h +2
-2@@ -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,
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 17 lines · On Wed, 20 Feb 2019 18:41:40 +0200 Andy Shevchenko…
Quoted 16 lines · Jonathan Cameron
Quoted 12 lines · On Wed, 20 Feb 2019 18:20:52 +0300 Andy Shevchenko…
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.At the same time drop the "of" prefix from its name and convert current users.
No functional change intended.
Signed-off-by Andy Shevchenko <[email protected]>
Quoted 8 lines
Quoted 5 lines
Hi Andy,
I sort of agree that there is no obvious reason to limit it to DT. One corner that is unfortunate is that we have ACPI DSDT with
_OFTproviding the same thing. Neither is 'standard' as such.He-h, that
_OFTshould be parsed on per device basis. I'm tired of firmware writers that are (abusing / not using in a clever way) ACPI features.
Agreed, it would be nice if they didn't make stuff up when ever they felt like it. Particularly tedious when the day job regularly involves asking our firmware team to do it right rather than paper over it. Guess there are advantages to working for a big company who do all the parts ;)
Quoted 23 lines
Quoted 4 lines
Also, could we have an example of what the DSDT would look like to provide this for a device? I'm too lazy to figure it out for myself given you probably already know off the top of your head ;)
Sure.
Since it's an array of strings it would be as simple as
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" } } } })
Quoted 4 lines
Should I send a version with extended commit message?
P.S. This is basically the example of any property that can be provided
via ACPI. Just add / replace name and value(s).
That would be great. I hadn't realised there was a catch all UUID for this. Why on earth is that in a random separate document rather than the ACPI specification itself *sigh*.
Jonathan
Quoted 177 lines
Quoted 176 lines
Thanks,
Jonathan
Quoted 169 lines
--- drivers/iio/accel/kxsd9.c | 2 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 2 +- drivers/iio/industrialio-core.c | 46 +++++++++------------- drivers/iio/magnetometer/ak8974.c | 2 +- drivers/iio/magnetometer/ak8975.c | 2 +- include/linux/iio/iio.h | 4 +- 7 files changed, 25 insertions(+), 35 deletions(-)drivers/iio/accel/kxsd9.c +1
-1@@ -420,7 +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, + ret =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (ret)drivers/iio/gyro/mpu3050-core.c +1
-1@@ -1149,7 +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" , + ret =iio_read_mount_matrix (dev,"mount-matrix" , &mpu3050->orientation);if (ret)return ret;drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +1
-1@@ -990,7 +990,7 @@ 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" , + result =iio_read_mount_matrix (dev,"mount-matrix" , &st->orientation);if (result) { dev_err(dev, "Failed to retrieve mounting matrix %d\n",drivers/iio/industrialio-core.c +18
-28@@ -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> @@ -525,8 +526,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 @@ -536,40 +537,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)drivers/iio/magnetometer/ak8974.c +1
-1@@ -733,7 +733,7 @@ static int ak8974_probe(struct i2c_client *i2c, ak8974->i2c = i2c;mutex_init (&ak8974->lock); - ret =of_iio_read_mount_matrix (&i2c->dev, + ret =iio_read_mount_matrix (&i2c->dev,"mount-matrix" , &ak8974->orientation);if (ret)drivers/iio/magnetometer/ak8975.c +1
-1@@ -911,7 +911,7 @@ static int ak8975_probe(struct i2c_client *client, data->eoc_irq =0 ;if (!pdata) { - err =of_iio_read_mount_matrix (&client->dev, + err =iio_read_mount_matrix (&client->dev,"mount-matrix" , &data->orientation);if (err)include/linux/iio/iio.h +2
-2@@ -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,
Jonathan Cameron
maintainerQuoted 14 lines · On Wed, 20 Feb 2019 18:19:12 +0200 Andy Shevchenko…
Quoted 13 lines · H. Nikolaus Schaller
Hi Andy,
Quoted 10 lines
Am 20.02.2019 um 16:20 schrieb Andy Shevchenko <[email protected]>:
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.At the same time drop the "of" prefix from its name and convert current users.
Quoted 7 lines
Quoted 3 lines
Maybe we can drop the "of" prefix after my earlier patches have been accepted?
So that you patch does not break compile of my patch series.
Whatever Jonathan considers the best for the users and developers!
Either way is easy to fix up. We are only talking a rename of a single function. Keep them separate and I'm sort it out.
Jonathan