linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: ina238: Report energy in microjoules
@ 2025-07-15 13:02 Jonas Rebmann
  2025-07-15 17:37 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Jonas Rebmann @ 2025-07-15 13:02 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, Jonathan Corbet
  Cc: linux-hwmon, linux-doc, linux-kernel, Wenliang Yan, kernel,
	Jonas Rebmann

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: 6daaf15a1173 ("hwmon: (ina238) Add support for SQ52206")
Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
This is a fix for a bug introduced into ina238.c recently (6daaf15a1173
("hwmon: (ina238) Add support for SQ52206")) and merged into
v6.16-rc1.

Jean, Guenter, can you include this for 6.16, please?
---
 Documentation/hwmon/ina238.rst | 2 +-
 drivers/hwmon/ina238.c         | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Documentation/hwmon/ina238.rst b/Documentation/hwmon/ina238.rst
index d1b93cf8627f352612f17953c62efc5ef5596fe5..9a24da4786a43f7493b364b005b2ae9992c3b10d 100644
--- a/Documentation/hwmon/ina238.rst
+++ b/Documentation/hwmon/ina238.rst
@@ -65,7 +65,7 @@ Additional sysfs entries for sq52206
 ------------------------------------
 
 ======================= =======================================================
-energy1_input		Energy measurement (mJ)
+energy1_input		Energy measurement (uJ)
 
 power1_input_highest	Peak Power (uW)
 ======================= =======================================================
diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c
index a4a41742786bd19e1c5dab34c7d71973527161a1..9a5fd16a4ec2a6d5a6cd5e8070d0442e1ef0135a 100644
--- a/drivers/hwmon/ina238.c
+++ b/drivers/hwmon/ina238.c
@@ -97,7 +97,7 @@
  *  Power (mW) = 0.2 * register value * 20000 / rshunt / 4 * gain
  *  (Specific for SQ52206)
  *  Power (mW) = 0.24 * register value * 20000 / rshunt / 4 * gain
- *  Energy (mJ) = 16 * 0.24 * register value * 20000 / rshunt / 4 * gain
+ *  Energy (uJ) = 16 * 0.24 * register value * 20000 / rshunt / 4 * gain * 1000
  */
 #define INA238_CALIBRATION_VALUE	16384
 #define INA238_FIXED_SHUNT		20000
@@ -500,9 +500,9 @@ static ssize_t energy1_input_show(struct device *dev,
 	if (ret)
 		return ret;
 
-	/* result in mJ */
-	energy = div_u64(regval * INA238_FIXED_SHUNT *	data->gain * 16 *
-				data->config->power_calculate_factor, 4 * 100 * data->rshunt);
+	/* result in uJ */
+	energy = div_u64(regval * INA238_FIXED_SHUNT *	data->gain * 16 * 10 *
+				data->config->power_calculate_factor, 4 * data->rshunt);
 
 	return sysfs_emit(buf, "%llu\n", energy);
 }

---
base-commit: 155a3c003e555a7300d156a5252c004c392ec6b0
change-id: 20250715-hwmon-ina238-microjoules-3d8edaa5ded0

Best regards,
-- 
Jonas Rebmann <jre@pengutronix.de>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwmon: ina238: Report energy in microjoules
  2025-07-15 13:02 [PATCH] hwmon: ina238: Report energy in microjoules Jonas Rebmann
@ 2025-07-15 17:37 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2025-07-15 17:37 UTC (permalink / raw)
  To: Jonas Rebmann
  Cc: Jean Delvare, Jonathan Corbet, linux-hwmon, linux-doc,
	linux-kernel, Wenliang Yan, kernel

On Tue, Jul 15, 2025 at 03:02:41PM +0200, Jonas Rebmann wrote:
> 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: 6daaf15a1173 ("hwmon: (ina238) Add support for SQ52206")
> Signed-off-by: Jonas Rebmann <jre@pengutronix.de>

Applied.

Guenter
> ---
> This is a fix for a bug introduced into ina238.c recently (6daaf15a1173
> ("hwmon: (ina238) Add support for SQ52206")) and merged into
> v6.16-rc1.
> 
> Jean, Guenter, can you include this for 6.16, please?
> ---
>  Documentation/hwmon/ina238.rst | 2 +-
>  drivers/hwmon/ina238.c         | 8 ++++----
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> 
> ---
> base-commit: 155a3c003e555a7300d156a5252c004c392ec6b0
> change-id: 20250715-hwmon-ina238-microjoules-3d8edaa5ded0
> 
> Best regards,
> 
> diff --git a/Documentation/hwmon/ina238.rst b/Documentation/hwmon/ina238.rst
> index d1b93cf8627f352612f17953c62efc5ef5596fe5..9a24da4786a43f7493b364b005b2ae9992c3b10d 100644
> --- a/Documentation/hwmon/ina238.rst
> +++ b/Documentation/hwmon/ina238.rst
> @@ -65,7 +65,7 @@ Additional sysfs entries for sq52206
>  ------------------------------------
>  
>  ======================= =======================================================
> -energy1_input		Energy measurement (mJ)
> +energy1_input		Energy measurement (uJ)
>  
>  power1_input_highest	Peak Power (uW)
>  ======================= =======================================================
> diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c
> index a4a41742786bd19e1c5dab34c7d71973527161a1..9a5fd16a4ec2a6d5a6cd5e8070d0442e1ef0135a 100644
> --- a/drivers/hwmon/ina238.c
> +++ b/drivers/hwmon/ina238.c
> @@ -97,7 +97,7 @@
>   *  Power (mW) = 0.2 * register value * 20000 / rshunt / 4 * gain
>   *  (Specific for SQ52206)
>   *  Power (mW) = 0.24 * register value * 20000 / rshunt / 4 * gain
> - *  Energy (mJ) = 16 * 0.24 * register value * 20000 / rshunt / 4 * gain
> + *  Energy (uJ) = 16 * 0.24 * register value * 20000 / rshunt / 4 * gain * 1000
>   */
>  #define INA238_CALIBRATION_VALUE	16384
>  #define INA238_FIXED_SHUNT		20000
> @@ -500,9 +500,9 @@ static ssize_t energy1_input_show(struct device *dev,
>  	if (ret)
>  		return ret;
>  
> -	/* result in mJ */
> -	energy = div_u64(regval * INA238_FIXED_SHUNT *	data->gain * 16 *
> -				data->config->power_calculate_factor, 4 * 100 * data->rshunt);
> +	/* result in uJ */
> +	energy = div_u64(regval * INA238_FIXED_SHUNT *	data->gain * 16 * 10 *
> +				data->config->power_calculate_factor, 4 * data->rshunt);
>  
>  	return sysfs_emit(buf, "%llu\n", energy);
>  }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-15 17:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-15 13:02 [PATCH] hwmon: ina238: Report energy in microjoules Jonas Rebmann
2025-07-15 17:37 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).