Re: ina226 as IIO device instead of HWMON

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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










[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux