Skip to content

Commit 3e8e93c

Browse files
jonrebmgroeck
authored andcommitted
hwmon: (ina238) Report energy in microjoules
The hwmon sysfs interface specifies that energy values should be reported in microjoules. This is also what tools such as lmsensors expect, reporting wrong values otherwise. Adjust the driver to scale the output accordingly and adjust ina238 driver documentation. Fixes: 6daaf15 ("hwmon: (ina238) Add support for SQ52206") Signed-off-by: Jonas Rebmann <[email protected]> Link: https://lore.kernel.org/r/20250715-hwmon-ina238-microjoules-v1-1-9df678568a41@pengutronix.de Signed-off-by: Guenter Roeck <[email protected]>
1 parent 495a4f0 commit 3e8e93c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Documentation/hwmon/ina238.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Additional sysfs entries for sq52206
6565
------------------------------------
6666

6767
======================= =======================================================
68-
energy1_input Energy measurement (mJ)
68+
energy1_input Energy measurement (uJ)
6969

7070
power1_input_highest Peak Power (uW)
7171
======================= =======================================================

drivers/hwmon/ina238.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
* Power (mW) = 0.2 * register value * 20000 / rshunt / 4 * gain
9898
* (Specific for SQ52206)
9999
* Power (mW) = 0.24 * register value * 20000 / rshunt / 4 * gain
100-
* Energy (mJ) = 16 * 0.24 * register value * 20000 / rshunt / 4 * gain
100+
* Energy (uJ) = 16 * 0.24 * register value * 20000 / rshunt / 4 * gain * 1000
101101
*/
102102
#define INA238_CALIBRATION_VALUE 16384
103103
#define INA238_FIXED_SHUNT 20000
@@ -500,9 +500,9 @@ static ssize_t energy1_input_show(struct device *dev,
500500
if (ret)
501501
return ret;
502502

503-
/* result in mJ */
504-
energy = div_u64(regval * INA238_FIXED_SHUNT * data->gain * 16 *
505-
data->config->power_calculate_factor, 4 * 100 * data->rshunt);
503+
/* result in uJ */
504+
energy = div_u64(regval * INA238_FIXED_SHUNT * data->gain * 16 * 10 *
505+
data->config->power_calculate_factor, 4 * data->rshunt);
506506

507507
return sysfs_emit(buf, "%llu\n", energy);
508508
}

0 commit comments

Comments
 (0)