[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250715-ina228-v1-2-3302fae4434b@pengutronix.de>
Date: Tue, 15 Jul 2025 22:49:01 +0200
From: Jonas Rebmann <jre@...gutronix.de>
To: Jean Delvare <jdelvare@...e.com>, Guenter Roeck <linux@...ck-us.net>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>
Cc: linux-hwmon@...r.kernel.org, linux-kernel@...r.kernel.org,
Krzysztof Kozlowski <krzk@...nel.org>, devicetree@...r.kernel.org,
kernel@...gutronix.de, Jonas Rebmann <jre@...gutronix.de>
Subject: [PATCH 2/4] hwmon: ina238: Add label support for voltage inputs
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@...gutronix.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
Powered by blists - more mailing lists