[PATCH] drm/xe/hwmon: Add label support

Karthik Poosa karthik.poosa at intel.com
Thu Feb 1 17:58:46 UTC 2024


Add label for power and energy attributes.

Signed-off-by: Karthik Poosa <karthik.poosa at intel.com>
---
 drivers/gpu/drm/xe/xe_hwmon.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
index 89c6f7f84b5a..9fd70bff3435 100644
--- a/drivers/gpu/drm/xe/xe_hwmon.c
+++ b/drivers/gpu/drm/xe/xe_hwmon.c
@@ -403,10 +403,10 @@ static const struct attribute_group *hwmon_groups[] = {
 };
 
 static const struct hwmon_channel_info * const hwmon_info[] = {
-	HWMON_CHANNEL_INFO(power, HWMON_P_MAX | HWMON_P_RATED_MAX | HWMON_P_CRIT),
+	HWMON_CHANNEL_INFO(power, HWMON_P_MAX | HWMON_P_RATED_MAX | HWMON_P_CRIT | HWMON_P_LABEL),
 	HWMON_CHANNEL_INFO(curr, HWMON_C_CRIT),
 	HWMON_CHANNEL_INFO(in, HWMON_I_INPUT),
-	HWMON_CHANNEL_INFO(energy, HWMON_E_INPUT),
+	HWMON_CHANNEL_INFO(energy, HWMON_E_INPUT | HWMON_E_LABEL),
 	NULL
 };
 
@@ -484,6 +484,8 @@ xe_hwmon_power_is_visible(struct xe_hwmon *hwmon, u32 attr, int chan)
 	case hwmon_power_crit:
 		return (xe_hwmon_pcode_read_i1(hwmon->gt, &uval) ||
 			!(uval & POWER_SETUP_I1_WATTS)) ? 0 : 0644;
+	case hwmon_power_label:
+		return 0444;
 	default:
 		return 0;
 	}
@@ -584,6 +586,8 @@ xe_hwmon_energy_is_visible(struct xe_hwmon *hwmon, u32 attr)
 	switch (attr) {
 	case hwmon_energy_input:
 		return xe_hwmon_get_reg(hwmon, REG_PKG_ENERGY_STATUS) ? 0444 : 0;
+	case hwmon_energy_label:
+		return 0444;
 	default:
 		return 0;
 	}
@@ -691,10 +695,26 @@ xe_hwmon_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
 	return ret;
 }
 
+static int xe_hwmon_read_label(struct device *dev,
+			       enum hwmon_sensor_types type,
+			       u32 attr, int channel, const char **str)
+{
+	switch (type) {
+	case hwmon_power:
+	case hwmon_energy:
+		*str = "card";
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+
 static const struct hwmon_ops hwmon_ops = {
 	.is_visible = xe_hwmon_is_visible,
 	.read = xe_hwmon_read,
 	.write = xe_hwmon_write,
+	.read_string = xe_hwmon_read_label,
 };
 
 static const struct hwmon_chip_info hwmon_chip_info = {
-- 
2.25.1



More information about the Intel-xe mailing list