Re: [PATCH] hwmon: applesmc: Add temperature sensor labels to sysfs interface

Previous thread: [PATCH] DMA ENGINE: Do not reset 'private' of channel by Jassi Brar on Tuesday, May 4, 2010 - 2:22 am. (2 messages)

Next thread: PATCH: Fix up memrar to the new RAR API by Alan Cox on Tuesday, May 4, 2010 - 2:52 am. (2 messages)
From: Henrik Rydberg
Date: Tuesday, May 4, 2010 - 2:55 am

From: Alex Murray <murray.alex@gmail.com>

The Apple SMC uses a systematic labeling scheme for the hardware
temperature sensors. This scheme is currently hidden from
userland. Since the sensor set, and consequently the numbering,
differs between models, an extensive database of configurations is
required for an application such as fan control. This patch adds the
SMC labels to the hwmon sysfs interface, allowing applications to use
the sensors more intelligibly.

Signed-off-by: Alex Murray <murray.alex@gmail.com>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
---
 drivers/hwmon/applesmc.c |  145 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 144 insertions(+), 1 deletions(-)

diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index 36a0d62..8be86ef 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -657,6 +657,17 @@ out:
 		return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right);
 }
 
+/* Displays sensor key as label */
+static ssize_t applesmc_show_sensor_label(struct device *dev,
+			struct device_attribute *devattr, char *sysfsbuf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	const char *key =
+		temperature_sensors_sets[applesmc_temperature_set][attr->index];
+
+	return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", key);
+}
+
 /* Displays degree Celsius * 1000 */
 static ssize_t applesmc_show_temperature(struct device *dev,
 			struct device_attribute *devattr, char *sysfsbuf)
@@ -1124,6 +1135,86 @@ static const struct attribute_group fan_attribute_groups[] = {
 /*
  * Temperature sensors sysfs entries.
  */
+static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO,
+					applesmc_show_sensor_label, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO,
+					applesmc_show_sensor_label, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO,
+					applesmc_show_sensor_label, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO,
+					applesmc_show_sensor_label, NULL, ...
From: Jean Delvare
Date: Tuesday, May 4, 2010 - 3:06 am

Hi Henrik,





Other than that, the patch looks good.

-- 
Jean Delvare
--

From: Henrik Rydberg
Date: Tuesday, May 4, 2010 - 4:15 am

Jean Delvare wrote:

Shoot, my bad review. Will send a new patch. While at it, the same function
seems to leak fan attribute groups. Want me to correct such issues (in another
patch)?

Henrik

--

From: Jean Delvare
Date: Tuesday, May 4, 2010 - 4:32 am

Yes please. As a bugfix, that would even be a candidate for 2.6.34. I
have another patch (for asc7621) pending already.

-- 
Jean Delvare
--

Previous thread: [PATCH] DMA ENGINE: Do not reset 'private' of channel by Jassi Brar on Tuesday, May 4, 2010 - 2:22 am. (2 messages)

Next thread: PATCH: Fix up memrar to the new RAR API by Alan Cox on Tuesday, May 4, 2010 - 2:52 am. (2 messages)