Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* ina226 as IIO device instead of HWMON
@ 2019-08-09 10:37 Michal Simek
  2019-08-09 13:02 ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Simek @ 2019-08-09 10:37 UTC (permalink / raw)
  To: linux-iio, mtitinger, Kevin Hilman, Lars-Peter Clausen,
	Guenter Roeck, narmstrong

Hi,

we are dealing with one issue with ina226 on xilinx platform when hwmon
driver is used. We have board for battery monitoring with shunt resistor
setup to 10 Ohm which is out of config value in hwmon driver. I have
temporary code to workaround this but I have also found that ina226 is
supported via iio framework. I have seen that Baylibre was trying to add
generic iio support to sigrok.
http://wiki.baylibre.com/doku.php?id=acme:oldstart

I expect you wanted to use sigrok also for ina226.

Anyway my question is if there is any standard tool which is capable to
calculate and show information from iio ina226 chip which is can be used
instead of lm-sensors and hwmon driver.

I would expect that iio-hwmon could be also used but didn't try that yet
with ina226 chip.

Thanks,
Michal

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ina226 as IIO device instead of HWMON
  2019-08-09 10:37 ina226 as IIO device instead of HWMON Michal Simek
@ 2019-08-09 13:02 ` Guenter Roeck
  2019-08-09 13:42   ` Michal Simek
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2019-08-09 13:02 UTC (permalink / raw)
  To: Michal Simek, linux-iio, mtitinger, Kevin Hilman,
	Lars-Peter Clausen, narmstrong

Hi Michal,

On 8/9/19 3:37 AM, Michal Simek wrote:
> Hi,
> 
> we are dealing with one issue with ina226 on xilinx platform when hwmon
> driver is used. We have board for battery monitoring with shunt resistor
> setup to 10 Ohm which is out of config value in hwmon driver. I have

Took me a while to understand that you mean 10 Ohm, not mOhm.
Well, yes, that is a bit large. I'd be open to accept a patch fixing that,
though I don't immediately know how to update the devicetree property (and,
unless I am missing something, the iio driver has the same problem).

> temporary code to workaround this but I have also found that ina226 is
> supported via iio framework. I have seen that Baylibre was trying to add
> generic iio support to sigrok.
> http://wiki.baylibre.com/doku.php?id=acme:oldstart
> 
> I expect you wanted to use sigrok also for ina226.
> 
> Anyway my question is if there is any standard tool which is capable to
> calculate and show information from iio ina226 chip which is can be used
> instead of lm-sensors and hwmon driver.
> 
> I would expect that iio-hwmon could be also used but didn't try that yet
> with ina226 chip.
> 

I don't immediately see why iio-hwmon couldn't be used. Also, if you don't
use the ina226 as hardware monitoring device, iio would be a more appropriate
solution anyway.

FWIW, we should actually remove the in22xx hwmon driver at some point and
ask users to use the iio driver combined with the iio-hwmon bridge instead
(after making sure that the iio driver combined with the iio-hwmon bridge
provides the same functionality).

Guenter

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ina226 as IIO device instead of HWMON
  2019-08-09 13:02 ` Guenter Roeck
@ 2019-08-09 13:42   ` Michal Simek
  2019-08-09 14:54     ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Simek @ 2019-08-09 13:42 UTC (permalink / raw)
  To: Guenter Roeck, Michal Simek, linux-iio, mtitinger, Kevin Hilman,
	Lars-Peter Clausen, narmstrong

On 09. 08. 19 15:02, Guenter Roeck wrote:
> Hi Michal,
> 
> On 8/9/19 3:37 AM, Michal Simek wrote:
>> Hi,
>>
>> we are dealing with one issue with ina226 on xilinx platform when hwmon
>> driver is used. We have board for battery monitoring with shunt resistor
>> setup to 10 Ohm which is out of config value in hwmon driver. I have
> 
> Took me a while to understand that you mean 10 Ohm, not mOhm.

yes.

> Well, yes, that is a bit large. I'd be open to accept a patch fixing that,
> though I don't immediately know how to update the devicetree property (and,
> unless I am missing something, the iio driver has the same problem).

There is shunt-resistor property in uOhm that's why 10 Ohm is like this
shunt-resistor = <10000000>;

> 
>> temporary code to workaround this but I have also found that ina226 is
>> supported via iio framework. I have seen that Baylibre was trying to add
>> generic iio support to sigrok.
>> http://wiki.baylibre.com/doku.php?id=acme:oldstart
>>
>> I expect you wanted to use sigrok also for ina226.
>>
>> Anyway my question is if there is any standard tool which is capable to
>> calculate and show information from iio ina226 chip which is can be used
>> instead of lm-sensors and hwmon driver.
>>
>> I would expect that iio-hwmon could be also used but didn't try that yet
>> with ina226 chip.
>>
> 
> I don't immediately see why iio-hwmon couldn't be used. Also, if you don't
> use the ina226 as hardware monitoring device, iio would be a more
> appropriate
> solution anyway.

I have tried this and found that IIO_POWER is not exported via iio-hwmon
driver.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
/tree/drivers/hwmon/iio_hwmon.c?h=next-20190809#n104

It is easy to add because ina226 iio export power via channel 2

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/iio/adc/ina2xx-adc.c?h=next-20190809#n690

Also dt description is easy to add. + iio-channels = <1>; to ina226 dt node.
       iio-hwmon {
               compatible = "iio-hwmon";
               io-channels = <&ps_pmbus 1>, <&ps_pmbus 2>, <&ps_pmbus 3>;
       };

> 
> FWIW, we should actually remove the in22xx hwmon driver at some point and
> ask users to use the iio driver combined with the iio-hwmon bridge instead
> (after making sure that the iio driver combined with the iio-hwmon bridge
> provides the same functionality).

The functionality is likely the same but I would expect that with this
new driver we should get something more. Especially that sigrok
connection looks interesting.
In our system we have SoC which have a lot of ina226 which monitors the
second SoC and would be nice to get precise information or graphs out of
it via standard user space tools or directly to web page.

Thanks,
Michal


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ina226 as IIO device instead of HWMON
  2019-08-09 13:42   ` Michal Simek
@ 2019-08-09 14:54     ` Guenter Roeck
  2019-08-12 11:28       ` Michal Simek
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2019-08-09 14:54 UTC (permalink / raw)
  To: Michal Simek
  Cc: linux-iio, mtitinger, Kevin Hilman, Lars-Peter Clausen, narmstrong

On Fri, Aug 09, 2019 at 03:42:00PM +0200, Michal Simek wrote:
> On 09. 08. 19 15:02, Guenter Roeck wrote:
> > Hi Michal,
> > 
> > On 8/9/19 3:37 AM, Michal Simek wrote:
> >> Hi,
> >>
> >> we are dealing with one issue with ina226 on xilinx platform when hwmon
> >> driver is used. We have board for battery monitoring with shunt resistor
> >> setup to 10 Ohm which is out of config value in hwmon driver. I have
> > 
> > Took me a while to understand that you mean 10 Ohm, not mOhm.
> 
> yes.
> 
> > Well, yes, that is a bit large. I'd be open to accept a patch fixing that,
> > though I don't immediately know how to update the devicetree property (and,
> > unless I am missing something, the iio driver has the same problem).
> 
> There is shunt-resistor property in uOhm that's why 10 Ohm is like this
> shunt-resistor = <10000000>;
> 

Yes, I know, but that applies to both hwmon and iio.  What am I missing ?
Is there some overflow condition in the hwmon driver ? If yes, that should
be easy to fix.

> > 
> >> temporary code to workaround this but I have also found that ina226 is
> >> supported via iio framework. I have seen that Baylibre was trying to add
> >> generic iio support to sigrok.
> >> http://wiki.baylibre.com/doku.php?id=acme:oldstart
> >>
> >> I expect you wanted to use sigrok also for ina226.
> >>
> >> Anyway my question is if there is any standard tool which is capable to
> >> calculate and show information from iio ina226 chip which is can be used
> >> instead of lm-sensors and hwmon driver.
> >>
> >> I would expect that iio-hwmon could be also used but didn't try that yet
> >> with ina226 chip.
> >>
> > 
> > I don't immediately see why iio-hwmon couldn't be used. Also, if you don't
> > use the ina226 as hardware monitoring device, iio would be a more
> > appropriate
> > solution anyway.
> 
> I have tried this and found that IIO_POWER is not exported via iio-hwmon
> driver.

Probably IIO_POWER didn't exist when the iio-hwmon bridge was written.
Patches welcome.

> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
> /tree/drivers/hwmon/iio_hwmon.c?h=next-20190809#n104
> 
> It is easy to add because ina226 iio export power via channel 2
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/iio/adc/ina2xx-adc.c?h=next-20190809#n690
> 
> Also dt description is easy to add. + iio-channels = <1>; to ina226 dt node.
>        iio-hwmon {
>                compatible = "iio-hwmon";
>                io-channels = <&ps_pmbus 1>, <&ps_pmbus 2>, <&ps_pmbus 3>;
>        };
> 
> > 
> > FWIW, we should actually remove the in22xx hwmon driver at some point and
> > ask users to use the iio driver combined with the iio-hwmon bridge instead
> > (after making sure that the iio driver combined with the iio-hwmon bridge
> > provides the same functionality).
> 
> The functionality is likely the same but I would expect that with this
> new driver we should get something more. Especially that sigrok
> connection looks interesting.

Sorry, which new driver, and what is "something more" ?

Thanks,
Guenter

> In our system we have SoC which have a lot of ina226 which monitors the
> second SoC and would be nice to get precise information or graphs out of
> it via standard user space tools or directly to web page.
> 
> Thanks,
> Michal
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ina226 as IIO device instead of HWMON
  2019-08-09 14:54     ` Guenter Roeck
@ 2019-08-12 11:28       ` Michal Simek
  0 siblings, 0 replies; 5+ messages in thread
From: Michal Simek @ 2019-08-12 11:28 UTC (permalink / raw)
  To: Guenter Roeck, Michal Simek
  Cc: linux-iio, mtitinger, Kevin Hilman, Lars-Peter Clausen, narmstrong

On 09. 08. 19 16:54, Guenter Roeck wrote:
> On Fri, Aug 09, 2019 at 03:42:00PM +0200, Michal Simek wrote:
>> On 09. 08. 19 15:02, Guenter Roeck wrote:
>>> Hi Michal,
>>>
>>> On 8/9/19 3:37 AM, Michal Simek wrote:
>>>> Hi,
>>>>
>>>> we are dealing with one issue with ina226 on xilinx platform when hwmon
>>>> driver is used. We have board for battery monitoring with shunt resistor
>>>> setup to 10 Ohm which is out of config value in hwmon driver. I have
>>>
>>> Took me a while to understand that you mean 10 Ohm, not mOhm.
>>
>> yes.
>>
>>> Well, yes, that is a bit large. I'd be open to accept a patch fixing that,
>>> though I don't immediately know how to update the devicetree property (and,
>>> unless I am missing something, the iio driver has the same problem).
>>
>> There is shunt-resistor property in uOhm that's why 10 Ohm is like this
>> shunt-resistor = <10000000>;
>>
> 
> Yes, I know, but that applies to both hwmon and iio.  What am I missing ?
> Is there some overflow condition in the hwmon driver ? If yes, that should
> be easy to fix.

For hwmon driver the issue is with ina2xx_set_shunt()
where passed val is 10000000 (10 Ohm)


unsigned int dividend = DIV_ROUND_CLOSEST(1000000000,

				data->config->shunt_div);
/* 1000 000 000 / 400 = 2 500 000; */
        if (val <= 0 || val > dividend)
                return -EINVAL;

And on this condition you see that 10 000 000 is bigger then  2 500 000.

> 
>>>
>>>> temporary code to workaround this but I have also found that ina226 is
>>>> supported via iio framework. I have seen that Baylibre was trying to add
>>>> generic iio support to sigrok.
>>>> http://wiki.baylibre.com/doku.php?id=acme:oldstart
>>>>
>>>> I expect you wanted to use sigrok also for ina226.
>>>>
>>>> Anyway my question is if there is any standard tool which is capable to
>>>> calculate and show information from iio ina226 chip which is can be used
>>>> instead of lm-sensors and hwmon driver.
>>>>
>>>> I would expect that iio-hwmon could be also used but didn't try that yet
>>>> with ina226 chip.
>>>>
>>>
>>> I don't immediately see why iio-hwmon couldn't be used. Also, if you don't
>>> use the ina226 as hardware monitoring device, iio would be a more
>>> appropriate
>>> solution anyway.
>>
>> I have tried this and found that IIO_POWER is not exported via iio-hwmon
>> driver.
> 
> Probably IIO_POWER didn't exist when the iio-hwmon bridge was written.
> Patches welcome.

ok.

> 
>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
>> /tree/drivers/hwmon/iio_hwmon.c?h=next-20190809#n104
>>
>> It is easy to add because ina226 iio export power via channel 2
>>
>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/iio/adc/ina2xx-adc.c?h=next-20190809#n690
>>
>> Also dt description is easy to add. + iio-channels = <1>; to ina226 dt node.
>>        iio-hwmon {
>>                compatible = "iio-hwmon";
>>                io-channels = <&ps_pmbus 1>, <&ps_pmbus 2>, <&ps_pmbus 3>;
>>        };
>>
>>>
>>> FWIW, we should actually remove the in22xx hwmon driver at some point and
>>> ask users to use the iio driver combined with the iio-hwmon bridge instead
>>> (after making sure that the iio driver combined with the iio-hwmon bridge
>>> provides the same functionality).
>>
>> The functionality is likely the same but I would expect that with this
>> new driver we should get something more. Especially that sigrok
>> connection looks interesting.
> 
> Sorry, which new driver, and what is "something more" ?

Based on what I have read IIO (new) driver is capable to run kernel
thread and in buffer mode is capturing data from the device which then
you can read back. That's why I would expect that there are user space
tools which are ready to use and capable to simply enable buffer mode
and capture that data for you.

Anyway I am able to see ina226 via iio_info.
	iio:device1: ina226 (buffer capable)
		9 channels found:
			voltage0:  (input, index: 0, format: le:U16/16>>0)
			3 channel-specific attributes found:
				attr  0: integration_time value: 0.001100
				attr  1: raw value: 2611
				attr  2: scale value: 0.002500000
			voltage1:  (input, index: 1, format: le:U16/16>>0)
			3 channel-specific attributes found:
				attr  0: integration_time value: 0.001100
				attr  1: raw value: 678
				attr  2: scale value: 1.250000000
			power2:  (input, index: 2, format: le:U16/16>>0)
			2 channel-specific attributes found:
				attr  0: raw value: 88
				attr  1: scale value: 0.006250000
			current3:  (input, index: 3, format: le:U16/16>>0)
			2 channel-specific attributes found:
				attr  0: raw value: 2611
				attr  1: scale value: 0.000250000
			timestamp:  (input, index: 4, format: le:S64/64>>0)
			allow:  (input)
			1 channel-specific attributes found:
				attr  0: async_readout value: 0
			oversampling:  (input)
			1 channel-specific attributes found:
				attr  0: ratio value: 4
			sampling:  (input)
			1 channel-specific attributes found:
				attr  0: frequency value: 114
			shunt:  (input)
			1 channel-specific attributes found:
				attr  0: resistor value: 10.000000000
		2 device-specific attributes found:
				attr  0: current_timestamp_clock value: realtime

				attr  1: integration_time_available value: 0.000140 0.000204
0.000332 0.000588 0.001100 0.002116 0.004156 0.008244
		2 buffer-specific attributes found:
				attr  0: data_available value: 0
				attr  1: watermark value: 1
		1 debug attributes found:
				debug attr  0: direct_reg_access value: 0x4327


but running iio_readdev ina226 locally is just returning error

root@zynqmp-debian:~# iio_readdev ina226
WARNING: High-speed mode not enabled
Unable to refill buffer: Connection timed out

But when I run iiod on target and
iio_readdev -n 192.168.0.208 ina226 | od -x
on host I am getting data.

It would be interesting to know if anybody really test ina2xx IIO driver
regularly.

It looks like sigrok support has never been finished too.
https://sourceforge.net/p/sigrok/mailman/message/35148318/#

Lars: Have you ever tried it?  I am using zcu102 for experiments and you
should have it around too.

Thanks,
Michal








^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-09 10:37 ina226 as IIO device instead of HWMON Michal Simek
2019-08-09 13:02 ` Guenter Roeck
2019-08-09 13:42   ` Michal Simek
2019-08-09 14:54     ` Guenter Roeck
2019-08-12 11:28       ` Michal Simek

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox