]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
hwmon: (ina238) Pre-calculate current, power, and energy LSB
authorGuenter Roeck <linux@roeck-us.net>
Fri, 29 Aug 2025 00:44:17 +0000 (17:44 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 7 Sep 2025 23:34:23 +0000 (16:34 -0700)
commit4a4fcd611295af96af51574b31f9e19e7505f965
treece6430dceae94e079033dbb12aa465597005fce6
parent40a5da1ec101476dd6abb9cfa181f1b50dc24ad0
hwmon: (ina238) Pre-calculate current, power, and energy LSB

Current, power, and energy LSB do not change during runtime, so we can
pre-calculate the respective values. The power LSB can be derived from
the current LSB using the equation in the datasheets. Similar, the
energy LSB can be derived from the power LSB.

Also add support for chips with built-in shunt resistor by providing
a chip specific configuration parameter for the current LSB. The
relationship of current -> power -> energy LSB values in those chips
is the same as in chips with external shunt resistor, so configuration
parameters for power and energy LSB are not needed.

Use ROUND_CLOSEST functions instead of divide operations to reduce
rounding errors.

Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz> # INA780
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/ina238.c