lkml.org 
[lkml]   [2023]   [Jul]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/2] hwmon: (isl28022) new driver for ISL28022 power monitor

> On 7/26/23 18:19, Guenter Roeck wrote:
> I strongly suspect that the conversions will result in overflows and that they are not always correct.
> I'll want to write unit test code before accepting the driver.
I changed the conversion for current to
*val = ((long)regval * 1250L * (long)data->gain) /
(long)data->shunt;

The term (1250 * gain) will be 10000 max, fits to 14 bit.
So no risk for 32bit overflow when multiply with 16bit value.

And changed the conversion for power to
*val = ((51200000L * ((long)data->gain)) /
(long)data->shunt) * (long)regval;

The first term (51200000 * gain / shunt) will be larger than 16bit when
(shunt/gain) is less than ~800. So min values for shunt are
- 6400 µOhm for 320 mV range
- 3200 µOhm for 160 mV range
- 1600 µOhm for 80 mV range
- 800 µOhm for 40 mV range
Can i set this conditionally in the .yaml file?

Regards Carsten
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2023-07-27 17:29    [W:0.044 / U:4.600 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site