[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230727172842.3fe20026.mail@carsten-spiess.de>
Date: Thu, 27 Jul 2023 17:28:42 +0200
From: Carsten Spieß <mail@...sten-spiess.de>
To: Guenter Roeck <linux@...ck-us.net>
Cc: Jean Delvare <jdelvare@...e.com>, Jonathan Corbet <corbet@....net>,
Geert Uytterhoeven <geert+renesas@...der.be>,
Magnus Damm <magnus.damm@...il.com>,
linux-hwmon@...r.kernel.org, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-renesas-soc@...r.kernel.org
Subject: Re: [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
Content of type "application/pgp-signature" skipped
Powered by blists - more mailing lists