iio: adc: ina2xx: Improve device identification
Subsystems (3)
cover iio: adc: ina2xx: Improve device identification
Hi,
the purpose of this series is to improve ina226 identification. On systems like Xilinx ZynqMP zcu102 (check dt in the tree) you can find out almost 20 ina226 chips and it is impossible to find out based on simple ina226 which chip is repsonsible for what.
The series is adding two ways how to improve device identification. Please let me know what you think I am happy to do changes in it.
Thanks,
Michal
Michal Simek (4):
iio: adc: ina2xx: Define *device_node only once
iio: adc: ina2xx: Setup better name then simple ina2xx
dt-bindings: Add optional label property for ina2xx
iio: adc: ina2xx: Use label proper for device identification
.../devicetree/bindings/hwmon/ina2xx.txt | 2 ++ drivers/iio/adc/ina2xx-adc.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/4 iio: adc: ina2xx: Define *device_node only once
There is no reason to c&p full client->dev.of_node link when simple variable can keep it.
---
drivers/iio/adc/ina2xx-adc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iio/adc/ina2xx-adc.c +4 -3
@@ -951,6 +951,7 @@ static int ina2xx_probe(struct i2c_client *client,struct ina2xx_chip_info *chip;struct iio_dev *indio_dev;struct iio_buffer *buffer; +struct device_node *np = client->dev.of_node;unsigned int val;enum ina2xx_ids type;int ret;
@@ -970,7 +971,7 @@ static int ina2xx_probe(struct i2c_client *client,return PTR_ERR (chip->regmap); } -if (client->dev.of_node) +if (np) type = (enum ina2xx_ids )of_device_get_match_data (&client->dev);else type = id->driver_data;
@@ -978,7 +979,7 @@ static int ina2xx_probe(struct i2c_client *client,mutex_init (&chip->state_lock); -if (of_property_read_u32 (client->dev.of_node, +if (of_property_read_u32 (np,"shunt-resistor" , &val) <0 ) {struct ina2xx_platform_data *pdata =dev_get_platdata (&client->dev);
@@ -1016,7 +1017,7 @@ static int ina2xx_probe(struct i2c_client *client, indio_dev->modes =INDIO_DIRECT_MODE |INDIO_BUFFER_SOFTWARE ; indio_dev->dev.parent = &client->dev; - indio_dev->dev.of_node = client->dev.of_node; + indio_dev->dev.of_node = np;if (id->driver_data == ina226) { indio_dev->channels = ina226_channels; indio_dev->num_channels =ARRAY_SIZE (ina226_channels);
Signature · 1 line
2.17.1
Re: [PATCH 1/4] iio: adc: ina2xx: Define *device_node only once
Quoted 2 lines · Michal Simek
There is no reason to c&p full
client->dev.of_nodelink when simple variable can keep it.
One comment
Quoted 29 lines
Signed-off-by Michal Simek <[email protected]>---
drivers/iio/adc/ina2xx-adc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/iio/adc/ina2xx-adc.c +2
-1@@ -951,6 +951,7 @@ static int ina2xx_probe(struct i2c_client *client,struct ina2xx_chip_info *chip;struct iio_dev *indio_dev;struct iio_buffer *buffer; +struct device_node *np = client->dev.of_node;unsigned int val;enum ina2xx_ids type;int ret;@@ -970,7 +971,7 @@ static int ina2xx_probe(struct i2c_client *client,return PTR_ERR (chip->regmap); } -if (client->dev.of_node) +if (np) type = (enum ina2xx_ids )of_device_get_match_data (&client->dev);else type = id->driver_data;
drivers/iio/adc/ina2xx-adc.c static int ina2xx_probe(struct i2c_client *client, · line 983
Quoted 6 lines
drivers/iio/adc/ina2xx-adc.c +1
-1@@ -978,7 +979,7 @@ static int ina2xx_probe(struct i2c_client *client,mutex_init (&chip->state_lock); -if (of_property_read_u32 (client->dev.of_node, +if (of_property_read_u32 (np,"shunt-resistor" , &val) <0 ) {
This will fit on one line <80 now.
Quoted 12 lines
drivers/iio/adc/ina2xx-adc.c +1
-1struct ina2xx_platform_data *pdata =dev_get_platdata (&client->dev);@@ -1016,7 +1017,7 @@ static int ina2xx_probe(struct i2c_client *client, indio_dev->modes =INDIO_DIRECT_MODE |INDIO_BUFFER_SOFTWARE ; indio_dev->dev.parent = &client->dev; - indio_dev->dev.of_node = client->dev.of_node; + indio_dev->dev.of_node = np;if (id->driver_data == ina226) { indio_dev->channels = ina226_channels; indio_dev->num_channels =ARRAY_SIZE (ina226_channels);
Signature · 11 lines
Regards Phil Reid ElectroMagnetic Imaging Technology Pty Ltd Development of Geophysical Instrumentation & Software www.electromag.com.au 3 The Avenue, Midland WA 6056, AUSTRALIA Ph: +61 8 9250 8100 Fax: +61 8 9250 7100 Email: [email protected]
PATCH 2/4 iio: adc: ina2xx: Setup better name then simple ina2xx
In reply to Michal SimekOn systems with multiple ina2xx chips it is impossible to find out which iio device is which one based on probe order. That's why it is necessary to setup better name based on possition.
The patch is reusing dev_name which is setup by core with client->name.
name char array was setup to 128 byte length to correspond the same name length by HID device.
Before this patch:
iio:device9: ina226 (buffer capable)
After:
iio:device9: ina226-3-004a (buffer capable)
---
Also id->name can be used as prefix. On ina226 output is the same.
Also I am happy to change that space for name will be dynamicky allocated to save a space if needed.
--- drivers/iio/adc/ina2xx-adc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/iio/adc/ina2xx-adc.c +7 -1
@@ -146,6 +146,7 @@ struct ina2xx_chip_info {int range_vbus;/* Bus voltage maximum in V */ int pga_gain_vshunt;/* Shunt voltage PGA gain */ bool allow_async_readout; +char name[128 ]; };static const struct ina2xx_config ina2xx_config[] = {
@@ -1027,7 +1028,12 @@ static int ina2xx_probe(struct i2c_client *client, indio_dev->num_channels =ARRAY_SIZE (ina219_channels); indio_dev->info = &ina219_info; } - indio_dev->name = id->name; + +/* Compose chip name to unified i2c format */ +snprintf (chip->name,sizeof (chip->name),"%s-%s" , + client->name,dev_name (&client->dev)); + + indio_dev->name = chip->name; indio_dev->setup_ops = &ina2xx_setup_ops; buffer =devm_iio_kfifo_allocate (&indio_dev->dev);
Signature · 1 line
2.17.1
Re: [PATCH 2/4] iio: adc: ina2xx: Setup better name then simple ina2xx
Quoted 5 lines · Michal Simek
On systems with multiple ina2xx chips it is impossible to find out which iio device is which one based on probe order. That's why it is necessary to setup better name based on possition.
The patch is reusingdev_namewhich is setup by core withclient->name.
Quoted 7 lines
name char array was setup to 128 byte length to correspond the same name length by HID device.
Before this patch:
iio:device9: ina226 (buffer capable)
After:
iio:device9: ina226-3-004a (buffer capable)
Could this break existing user space code that's just looking for just ina226. I2c bus numbers aren't all that great at id'ing devices either. It's better than nothing but depending on what cards we have plugged into our system the same device gets a different bus number.
Quoted 39 lines
Signed-off-by Michal Simek <[email protected]>---
Also
id->namecan be used as prefix. On ina226 output is the same.Also I am happy to change that space for name will be dynamicky allocated to save a space if needed.
--- drivers/iio/adc/ina2xx-adc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/iio/adc/ina2xx-adc.c +7
-1@@ -146,6 +146,7 @@ struct ina2xx_chip_info {int range_vbus;/* Bus voltage maximum in V */ int pga_gain_vshunt;/* Shunt voltage PGA gain */ bool allow_async_readout; +char name[128 ]; };static const struct ina2xx_config ina2xx_config[] = {@@ -1027,7 +1028,12 @@ static int ina2xx_probe(struct i2c_client *client, indio_dev->num_channels =ARRAY_SIZE (ina219_channels); indio_dev->info = &ina219_info; } - indio_dev->name = id->name; + +/* Compose chip name to unified i2c format */ +snprintf (chip->name,sizeof (chip->name),"%s-%s" , + client->name,dev_name (&client->dev)); + + indio_dev->name = chip->name; indio_dev->setup_ops = &ina2xx_setup_ops; buffer =devm_iio_kfifo_allocate (&indio_dev->dev);
Signature · 2 lines
Regards Phil Reid
Re: [PATCH 2/4] iio: adc: ina2xx: Setup better name then simple ina2xx
Quoted 15 lines · Phil Reid
Quoted 6 lines · Michal Simek
On systems with multiple ina2xx chips it is impossible to find out which iio device is which one based on probe order. That's why it is necessary to
setup better name based on possition.
The patch is reusingdev_namewhich is setup by core withclient->name.Quoted 7 lines
name char array was setup to 128 byte length to correspond the same name length by HID device.
Before this patch:
iio:device9: ina226 (buffer capable)
After:
iio:device9: ina226-3-004a (buffer capable)
Quoted 7 lines
Could this break existing user space code that's just looking for just ina226.
I2c bus numbers aren't all that great at id'ing devices either. It's better than
nothing but depending on what cards we have plugged into our system the same device gets
a different bus number.
Fair point. Let's wait what dt guys say about label property. I can simply drop this patch and use just this.
indio_dev->name = of_get_property(np, "label", NULL) ? : id->name;
Thanks,
Michal
PATCH 3/4 dt-bindings: Add optional label property for ina2xx
In reply to Michal SimekUsing optional "label" property is adding an option to user to use better name for device identification.
---
Documentation/devicetree/bindings/hwmon/ina2xx.txt | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/hwmon/ina2xx.txt +2 -0
@@ -14,6 +14,8 @@ Optional properties: - shunt-resistor Shunt resistor value in micro-Ohm +- label + Symbolic name for a power monitor Example:
Signature · 1 line
2.17.1
Re: [PATCH 3/4] dt-bindings: Add optional label property for ina2xx
Quoted 9 lines · Michal Simek
Using optional "label" property is adding an option to user to use better name for device identification.
Signed-off-by Michal Simek <[email protected]>---
Documentation/devicetree/bindings/hwmon/ina2xx.txt | 2 ++ 1 file changed, 2 insertions(+)
PATCH 4/4 iio: adc: ina2xx: Use label proper for device identification
In reply to Michal SimekAdd support for using label property for easier device identification via iio framework.
---
drivers/iio/adc/ina2xx-adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ina2xx-adc.c +1 -1
@@ -1033,7 +1033,7 @@ static int ina2xx_probe(struct i2c_client *client,snprintf (chip->name,sizeof (chip->name),"%s-%s" , client->name,dev_name (&client->dev)); - indio_dev->name = chip->name; + indio_dev->name =of_get_property (np,"label" ,NULL ) ? : chip->name; indio_dev->setup_ops = &ina2xx_setup_ops; buffer =devm_iio_kfifo_allocate (&indio_dev->dev);
Signature · 1 line
2.17.1
Re: [PATCH 4/4] iio: adc: ina2xx: Use label proper for device identification
Quoted 15 lines · Michal Simek
Add support for using label property for easier device identification via iio framework.
Signed-off-by Michal Simek <[email protected]>---
drivers/iio/adc/ina2xx-adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/ina2xx-adc.c +0
-0
drivers/iio/adc/ina2xx-adc.c static int ina2xx_probe(struct i2c_client *client, · line 1039
Quoted 8 lines
drivers/iio/adc/ina2xx-adc.c +1
-1@@ -1033,7 +1033,7 @@ static int ina2xx_probe(struct i2c_client *client,snprintf (chip->name,sizeof (chip->name),"%s-%s" , client->name,dev_name (&client->dev)); - indio_dev->name = chip->name; + indio_dev->name =of_get_property (np,"label" ,NULL ) ? : chip->name; indio_dev->setup_ops = &ina2xx_setup_ops; buffer =devm_iio_kfifo_allocate (&indio_dev->dev);
I like this personally. It'd be nice if it was a core function so it could be an opt in to any iio device.
Don't know how well received that'd be thou.
Signature · 2 lines
Regards Phil Reid
Re: [PATCH 4/4] iio: adc: ina2xx: Use label proper for device identification
Quoted 25 lines · Phil Reid
Quoted 14 lines · Michal Simek
Add support for using label property for easier device identification via iio framework.
Signed-off-by Michal Simek <[email protected]>---
drivers/iio/adc/ina2xx-adc.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/ina2xx-adc.c +0
-0drivers/iio/adc/ina2xx-adc.c static int ina2xx_probe(struct i2c_client *client, · line 1039
Quoted 7 lines
drivers/iio/adc/ina2xx-adc.c +1
-0@@ -1033,7 +1033,7 @@ static int ina2xx_probe(struct i2c_client *client, snprintf(chip->name, sizeof(chip->name), "%s-%s", client->name, dev_name(&client->dev)); - indio_dev->name = chip->name; + indio_dev->name = of_get_property(np, "label", NULL) ? : chip->name; indio_dev->setup_ops = &ina2xx_setup_ops; buffer = devm_iio_kfifo_allocate(&indio_dev->dev);I like this personally. It'd be nice if it was a core function so it could be an opt in to any iio device.
Quoted 2 lines
Don't know how well received that'd be thou.
Something like this?
(quoted diff) +0 -0
b/drivers/iio/industrialio-core.c
index 524a686077ca..d21b495d36a1 100644
drivers/iio/industrialio-core.c +0 -0
@@ -1647,6 +1647,9 @@ int __iio_device_register(struct iio_dev
*indio_dev, struct module *this_mod)
if (!indio_dev->dev.of_node && indio_dev->dev.parent)
indio_dev->dev.of_node = indio_dev->dev.parent->of_node;+ indio_dev->name = of_get_property(indio_dev->dev.of_node,
"label", NULL) ? :
+ indio_dev->name;
+
ret = iio_check_unique_scan_index(indio_dev);
if (ret < 0)
return ret;M
Jonathan Cameron
maintainerRe: [PATCH 4/4] iio: adc: ina2xx: Use label proper for device identification
Quoted 26 lines · On Wed, 21 Aug 2019 11:12:00 +0200 Michal Simek <[email protected]> wrote:
Quoted 25 lines · Phil Reid
Quoted 14 lines · Michal Simek
Add support for using label property for easier device identification via iio framework.
Signed-off-by Michal Simek <[email protected]>---
drivers/iio/adc/ina2xx-adc.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/ina2xx-adc.c +0
-0drivers/iio/adc/ina2xx-adc.c static int ina2xx_probe(struct i2c_client *client, · line 1039
Quoted 7 lines
drivers/iio/adc/ina2xx-adc.c +1
-0@@ -1033,7 +1033,7 @@ static int ina2xx_probe(struct i2c_client *client, snprintf(chip->name, sizeof(chip->name), "%s-%s", client->name, dev_name(&client->dev)); - indio_dev->name = chip->name; + indio_dev->name = of_get_property(np, "label", NULL) ? : chip->name; indio_dev->setup_ops = &ina2xx_setup_ops; buffer = devm_iio_kfifo_allocate(&indio_dev->dev);I like this personally. It'd be nice if it was a core function so it could be an opt in to any iio device.
Quoted 2 lines
Quoted 2 lines
Don't know how well received that'd be thou.
I'm not particularly keen on changing the semantics of existing ABI, but how about adding new ABI to provide this?
/sys/bus/iio/devices/iio\:device0/label for example?
I haven't thought about it in depth yet though. If you spin a patch with that and the DT docs we'll be more likely to get a view from DT maintainers if this is acceptable use of label.
Thanks
Jonathan
Quoted 23 lines
Something like this?
drivers/iio/industrialio-core.c +1
-0@@ -1647,6 +1647,9 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)if (!indio_dev->dev.of_node && indio_dev->dev.parent) indio_dev->dev.of_node = indio_dev->dev.parent->of_node; + indio_dev->name = of_get_property(indio_dev->dev.of_node,"label", NULL) ? :
drivers/iio/industrialio-core.c +2
-0+ indio_dev->name; + ret =iio_check_unique_scan_index (indio_dev);if (ret <0 )return ret;M
Re: [PATCH 4/4] iio: adc: ina2xx: Use label proper for device identification
Quoted 31 lines · Jonathan Cameron
Quoted 26 lines · On Wed, 21 Aug 2019 11:12:00 +0200 Michal Simek <[email protected]> wrote:
Quoted 25 lines · Phil Reid
Quoted 14 lines · Michal Simek
Add support for using label property for easier device identification via iio framework.
Signed-off-by Michal Simek <[email protected]>---
drivers/iio/adc/ina2xx-adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/ina2xx-adc.c +0
-0drivers/iio/adc/ina2xx-adc.c static int ina2xx_probe(struct i2c_client *client, · line 1039
Quoted 7 lines
drivers/iio/adc/ina2xx-adc.c +1
-0@@ -1033,7 +1033,7 @@ static int ina2xx_probe(struct i2c_client *client, snprintf(chip->name, sizeof(chip->name), "%s-%s", client->name, dev_name(&client->dev)); - indio_dev->name = chip->name; + indio_dev->name = of_get_property(np, "label", NULL) ? : chip->name; indio_dev->setup_ops = &ina2xx_setup_ops; buffer = devm_iio_kfifo_allocate(&indio_dev->dev);I like this personally. It'd be nice if it was a core function so it could be an opt in to any iio device.
Quoted 2 lines
Quoted 2 lines
Don't know how well received that'd be thou.
Quoted 9 lines
I'm not particularly keen on changing the semantics of existing ABI, but how about adding new ABI to provide this?
/sys/bus/iio/devices/iio\:device0/label for example?
I haven't thought about it in depth yet though. If you spin a patch with that and the DT docs we'll be more likely to get a view from DT maintainers if this is acceptable use of label.
I've sent "iio: core: Add optional symbolic label to device attributes" for further discussion.
Quoted 30 lines
Thanks
Jonathan
Quoted 23 lines
Something like this?
drivers/iio/industrialio-core.c +1
-0@@ -1647,6 +1647,9 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)if (!indio_dev->dev.of_node && indio_dev->dev.parent) indio_dev->dev.of_node = indio_dev->dev.parent->of_node; + indio_dev->name = of_get_property(indio_dev->dev.of_node,"label", NULL) ? :
drivers/iio/industrialio-core.c +2
-0+ indio_dev->name; + ret =iio_check_unique_scan_index (indio_dev);if (ret <0 )return ret;M
Signature · 11 lines
Regards Phil Reid ElectroMagnetic Imaging Technology Pty Ltd Development of Geophysical Instrumentation & Software www.electromag.com.au 3 The Avenue, Midland WA 6056, AUSTRALIA Ph: +61 8 9250 8100 Fax: +61 8 9250 7100 Email: [email protected]
Re: [PATCH 4/4] iio: adc: ina2xx: Use label proper for device identification
Quoted 41 lines · Phil Reid
Quoted 40 lines · Jonathan Cameron
Quoted 30 lines · On Wed, 21 Aug 2019 11:12:00 +0200 Michal Simek <[email protected]> wrote:
Quoted 29 lines · Phil Reid
Quoted 23 lines · Michal Simek
Add support for using label property for easier device identification via
iio framework.Signed-off-by Michal Simek <[email protected]>---
drivers/iio/adc/ina2xx-adc.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/ina2xx-adc.c +1
-0@@ -1033,7 +1033,7 @@ static int ina2xx_probe(struct i2c_client *client, snprintf(chip->name, sizeof(chip->name), "%s-%s", client->name, dev_name(&client->dev)); - indio_dev->name = chip->name; + indio_dev->name = of_get_property(np, "label", NULL) ? : chip->name; indio_dev->setup_ops = &ina2xx_setup_ops;Quoted 2 lines
buffer =
devm_iio_kfifo_allocate(&indio_dev->dev);I like this personally. It'd be nice if it was a core function so it could be an opt in to any iio device.
Quoted 2 lines
Quoted 2 lines
Don't know how well received that'd be thou.
I'm not particularly keen on changing the semantics of existing ABI, but how about adding new ABI to provide this?
/sys/bus/iio/devices/iio\:device0/label for example?
Quoted 7 lines
Quoted 4 lines
I haven't thought about it in depth yet though. If you spin a patch with that and the DT docs we'll be more likely to get a view from DT maintainers if this is acceptable use of label.
I've sent "iio: core: Add optional symbolic label to device attributes" for further discussion.
Series looks good. I expect that there will be also update in libiio if this is accepted.
Thanks,
Michal