summary refs log tree commit diff
path: root/drivers/hwmon/ibmpowernv.c
diff options
context:
space:
mode:
authorCédric Le Goater <clg@fr.ibm.com>2015-04-08 19:19:50 +0200
committerGuenter Roeck <linux@roeck-us.net>2015-04-08 10:34:20 -0700
commit3df2f59f0aae2f5380a9d8037c91dcab75c4478d (patch)
tree8e49b6332b95a8fa5847185ff39e855fc2b25382 /drivers/hwmon/ibmpowernv.c
parent2bcd3787b946b725a37763c0877da0996f5ec064 (diff)
downloadlinux-3df2f59f0aae2f5380a9d8037c91dcab75c4478d.tar.gz
hwmon: (ibmpowernv) pretty print labels
The new OPAL device tree adds a few properties which can be used to add
extra information on the sensor label.

In the case of a cpu core sensor, the firmware exposes the physical
identifier of the core in the "ibm,pir" property. The driver
translates this identifier in a linux cpu number and prints out a
range corresponding to the hardware threads of the core (as they
share the same sensor).

The numbering gives a hint on the localization of the core in the
system (which socket, which chip).

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/ibmpowernv.c')
-rw-r--r--drivers/hwmon/ibmpowernv.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
index 1180ce631377..7108daf056b0 100644
--- a/drivers/hwmon/ibmpowernv.c
+++ b/drivers/hwmon/ibmpowernv.c
@@ -30,6 +30,7 @@
 #include <linux/platform_device.h>
 #include <asm/opal.h>
 #include <linux/err.h>
+#include <asm/cputhreads.h>
 
 #define MAX_ATTR_LEN	32
 #define MAX_LABEL_LEN	64
@@ -112,13 +113,53 @@ static ssize_t show_label(struct device *dev, struct device_attribute *devattr,
 	return sprintf(buf, "%s\n", sdata->label);
 }
 
+static int __init get_logical_cpu(int hwcpu)
+{
+	int cpu;
+
+	for_each_possible_cpu(cpu)
+		if (get_hard_smp_processor_id(cpu) == hwcpu)
+			return cpu;
+
+	return -ENOENT;
+}
+
 static void __init make_sensor_label(struct device_node *np,
 				     struct sensor_data *sdata,
 				     const char *label)
 {
+	u32 id;
 	size_t n;
 
 	n = snprintf(sdata->label, sizeof(sdata->label), "%s", label);
+
+	/*
+	 * Core temp pretty print
+	 */
+	if (!of_property_read_u32(np, "ibm,pir", &id)) {
+		int cpuid = get_logical_cpu(id);
+
+		if (cpuid >= 0)
+			/*
+			 * The digital thermal sensors are associated
+			 * with a core. Let's print out the range of
+			 * cpu ids corresponding to the hardware
+			 * threads of the core.
+			 */
+			n += snprintf(sdata->label + n,
+				      sizeof(sdata->label) - n, " %d-%d",
+				      cpuid, cpuid + threads_per_core - 1);
+		else
+			n += snprintf(sdata->label + n,
+				      sizeof(sdata->label) - n, " phy%d", id);
+	}
+
+	/*
+	 * Membuffer pretty print
+	 */
+	if (!of_property_read_u32(np, "ibm,chip-id", &id))
+		n += snprintf(sdata->label + n, sizeof(sdata->label) - n,
+			      " %d", id & 0xffff);
 }
 
 static int get_sensor_index_attr(const char *name, u32 *index, char *attr)