The INA family of power monitors estimate power consumption based on
two voltage measurements: across a shunt resistor and across the bus.
Conveniently label them "Shunt Voltage" and "Bus Voltage".
Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
drivers/hwmon/ina238.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c
index d603d4990c928984350c1f414431219b1489a546..44f7ce3c1d7b5a91f67d12c1d29e1e560024a04c 100644
--- a/drivers/hwmon/ina238.c
+++ b/drivers/hwmon/ina238.c
@@ -507,6 +507,27 @@ static ssize_t energy1_input_show(struct device *dev,
return sysfs_emit(buf, "%llu\n", energy);
}
+static int ina238_read_string(struct device *dev, enum hwmon_sensor_types type,
+ u32 attr, int channel, const char **str)
+{
+ switch (type) {
+ case hwmon_in:
+ switch (channel) {
+ case 0:
+ *str = "Shunt Voltage";
+ return 0;
+ case 1:
+ *str = "Bus Voltage";
+ return 0;
+ default:
+ break;
+ }
+ default:
+ break;
+ }
+ return -EOPNOTSUPP;
+}
+
static int ina238_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
@@ -565,6 +586,7 @@ static umode_t ina238_is_visible(const void *drvdata,
case hwmon_in_input:
case hwmon_in_max_alarm:
case hwmon_in_min_alarm:
+ case hwmon_in_label:
return 0444;
case hwmon_in_max:
case hwmon_in_min:
@@ -615,9 +637,9 @@ static umode_t ina238_is_visible(const void *drvdata,
static const struct hwmon_channel_info * const ina238_info[] = {
HWMON_CHANNEL_INFO(in,
/* 0: shunt voltage */
- INA238_HWMON_IN_CONFIG,
+ INA238_HWMON_IN_CONFIG | HWMON_I_LABEL,
/* 1: bus voltage */
- INA238_HWMON_IN_CONFIG),
+ INA238_HWMON_IN_CONFIG | HWMON_I_LABEL),
HWMON_CHANNEL_INFO(curr,
/* 0: current through shunt */
HWMON_C_INPUT),
@@ -633,6 +655,7 @@ static const struct hwmon_channel_info * const ina238_info[] = {
static const struct hwmon_ops ina238_hwmon_ops = {
.is_visible = ina238_is_visible,
+ .read_string = ina238_read_string,
.read = ina238_read,
.write = ina238_write,
};
--
2.39.5
On 7/15/25 13:49, Jonas Rebmann wrote: > The INA family of power monitors estimate power consumption based on > two voltage measurements: across a shunt resistor and across the bus. > > Conveniently label them "Shunt Voltage" and "Bus Voltage". > Labels are supposed to show the sensor's association with the system, not the chip labeling. So this is a no-go. And, yes, apparently I have been too complacent with people (mis-)using the label attributes. That doesn't make it better, so don't use it as argument to support this one. Guenter
Hi Guenter, Thanks for the review! On 16/07/2025 17.04, Guenter Roeck wrote: > On 7/15/25 13:49, Jonas Rebmann wrote: >> The INA family of power monitors estimate power consumption based on >> two voltage measurements: across a shunt resistor and across the bus. >> >> Conveniently label them "Shunt Voltage" and "Bus Voltage". >> > > Labels are supposed to show the sensor's association with the system, not > the chip labeling. So this is a no-go. And, yes, apparently I have been too > complacent with people (mis-)using the label attributes. That doesn't make > it better, so don't use it as argument to support this one. As this chip measures power based on two voltage measurements, the measured voltage inputs must always be associated with the system in that way, that in1 measures the voltage on a bus and in0 over a shunt resistor on that bus. Otherwise the Power/Energy/Charge-Measurements will be incorrect. Do you have a suggestion on how to use the labels correctly or should I just drop the patch for v2? Regards, Jonas -- Pengutronix e.K. | Jonas Rebmann | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
On Thu, Jul 17, 2025 at 09:30:33AM +0200, Jonas Rebmann wrote: > Hi Guenter, > > Thanks for the review! > > On 16/07/2025 17.04, Guenter Roeck wrote: > > On 7/15/25 13:49, Jonas Rebmann wrote: > > > The INA family of power monitors estimate power consumption based on > > > two voltage measurements: across a shunt resistor and across the bus. > > > > > > Conveniently label them "Shunt Voltage" and "Bus Voltage". > > > > > > > Labels are supposed to show the sensor's association with the system, not > > the chip labeling. So this is a no-go. And, yes, apparently I have been too > > complacent with people (mis-)using the label attributes. That doesn't make > > it better, so don't use it as argument to support this one. > > As this chip measures power based on two voltage measurements, the > measured voltage inputs must always be associated with the system in > that way, that in1 measures the voltage on a bus and in0 over a shunt > resistor on that bus. > > Otherwise the Power/Energy/Charge-Measurements will be incorrect. > > Do you have a suggestion on how to use the labels correctly or should I > just drop the patch for v2? > Please drop it. Guenter > Regards, > Jonas > > > -- > Pengutronix e.K. | Jonas Rebmann | > Steuerwalder Str. 21 | http://www.pengutronix.de/ | > 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 | >
© 2016 - 2025 Red Hat, Inc.