Re: [PATCH 1/2] hwmon: (isl28022) new driver for ISL28022 power monitor

From: Carsten Spieß
Date: Thu Jul 27 2023 - 11:29:00 EST



> 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

Attachment: pgpfKvgFDJzll.pgp
Description: Digitale Signatur von OpenPGP