diff mbox series

[2/4] iio: adc: ina2xx: Setup better name then simple ina2xx

Message ID e1a9d7c5f94a4942a97a242e530a3bfdda8bbc74.1566310292.git.michal.simek@xilinx.com (mailing list archive)
State New, archived
Headers show
Series iio: adc: ina2xx: Improve device identification | expand

Commit Message

Michal Simek Aug. 20, 2019, 2:11 p.m. UTC
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 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)

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

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(-)

Comments

Phil Reid Aug. 21, 2019, 2:10 a.m. UTC | #1
On 20/08/2019 22:11, Michal Simek wrote:
> 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 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)

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.


> 
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
> 
> 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(-)
> 
> diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
> index 37058d9c2054..7c7c63677bf4 100644
> --- a/drivers/iio/adc/ina2xx-adc.c
> +++ b/drivers/iio/adc/ina2xx-adc.c
> @@ -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);
>
Michal Simek Aug. 21, 2019, 8:36 a.m. UTC | #2
On 21. 08. 19 4:10, Phil Reid wrote:
> On 20/08/2019 22:11, Michal Simek wrote:
>> 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 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)
> 
> 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
diff mbox series

Patch

diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index 37058d9c2054..7c7c63677bf4 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -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);