aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Le Goater <clg@fr.ibm.com>2015-04-08 13:19:49 -0400
committerGuenter Roeck <linux@roeck-us.net>2015-04-08 13:34:20 -0400
commit2bcd3787b946b725a37763c0877da0996f5ec064 (patch)
treeec81d8281653d5e7822644a887f7de3452aed237
parent14681637ab3013d3577cc59633159f425733532e (diff)
hwmon: (ibmpowernv) add a label attribute
Currently, sensors are only identified by their type and index. The new OPAL device tree can expose extra properties to identify some sensors by their name or location. This patch adds the creation of a new hwmon *_label attribute when such properties are detected. Signed-off-by: Cédric Le Goater <clg@fr.ibm.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/ibmpowernv.c55
1 files changed, 52 insertions, 3 deletions
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
index b6bc463886c0..1180ce631377 100644
--- a/drivers/hwmon/ibmpowernv.c
+++ b/drivers/hwmon/ibmpowernv.c
@@ -32,6 +32,7 @@
32#include <linux/err.h> 32#include <linux/err.h>
33 33
34#define MAX_ATTR_LEN 32 34#define MAX_ATTR_LEN 32
35#define MAX_LABEL_LEN 64
35 36
36/* Sensor suffix name from DT */ 37/* Sensor suffix name from DT */
37#define DT_FAULT_ATTR_SUFFIX "faulted" 38#define DT_FAULT_ATTR_SUFFIX "faulted"
@@ -70,6 +71,7 @@ struct sensor_data {
70 u32 hwmon_index; 71 u32 hwmon_index;
71 u32 opal_index; 72 u32 opal_index;
72 enum sensors type; 73 enum sensors type;
74 char label[MAX_LABEL_LEN];
73 char name[MAX_ATTR_LEN]; 75 char name[MAX_ATTR_LEN];
74 struct device_attribute dev_attr; 76 struct device_attribute dev_attr;
75}; 77};
@@ -101,8 +103,25 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr,
101 return sprintf(buf, "%u\n", x); 103 return sprintf(buf, "%u\n", x);
102} 104}
103 105
104static int get_sensor_index_attr(const char *name, u32 *index, 106static ssize_t show_label(struct device *dev, struct device_attribute *devattr,
105 char *attr) 107 char *buf)
108{
109 struct sensor_data *sdata = container_of(devattr, struct sensor_data,
110 dev_attr);
111
112 return sprintf(buf, "%s\n", sdata->label);
113}
114
115static void __init make_sensor_label(struct device_node *np,
116 struct sensor_data *sdata,
117 const char *label)
118{
119 size_t n;
120
121 n = snprintf(sdata->label, sizeof(sdata->label), "%s", label);
122}
123
124static int get_sensor_index_attr(const char *name, u32 *index, char *attr)
106{ 125{
107 char *hash_pos = strchr(name, '#'); 126 char *hash_pos = strchr(name, '#');
108 char buf[8] = { 0 }; 127 char buf[8] = { 0 };
@@ -227,11 +246,21 @@ static int populate_attr_groups(struct platform_device *pdev)
227 246
228 opal = of_find_node_by_path("/ibm,opal/sensors"); 247 opal = of_find_node_by_path("/ibm,opal/sensors");
229 for_each_child_of_node(opal, np) { 248 for_each_child_of_node(opal, np) {
249 const char *label;
250
230 if (np->name == NULL) 251 if (np->name == NULL)
231 continue; 252 continue;
232 253
233 type = get_sensor_type(np); 254 type = get_sensor_type(np);
234 if (type != MAX_SENSOR_TYPE) 255 if (type == MAX_SENSOR_TYPE)
256 continue;
257
258 sensor_groups[type].attr_count++;
259
260 /*
261 * add a new attribute for labels
262 */
263 if (!of_property_read_string(np, "label", &label))
235 sensor_groups[type].attr_count++; 264 sensor_groups[type].attr_count++;
236 } 265 }
237 266
@@ -296,6 +325,7 @@ static int create_device_attrs(struct platform_device *pdev)
296 for_each_child_of_node(opal, np) { 325 for_each_child_of_node(opal, np) {
297 const char *attr_name; 326 const char *attr_name;
298 u32 opal_index; 327 u32 opal_index;
328 const char *label;
299 329
300 if (np->name == NULL) 330 if (np->name == NULL)
301 continue; 331 continue;
@@ -339,6 +369,25 @@ static int create_device_attrs(struct platform_device *pdev)
339 369
340 pgroups[type]->attrs[sensor_groups[type].attr_count++] = 370 pgroups[type]->attrs[sensor_groups[type].attr_count++] =
341 &sdata[count++].dev_attr.attr; 371 &sdata[count++].dev_attr.attr;
372
373 if (!of_property_read_string(np, "label", &label)) {
374 /*
375 * For the label attribute, we can reuse the
376 * "properties" of the previous "input"
377 * attribute. They are related to the same
378 * sensor.
379 */
380 sdata[count].type = type;
381 sdata[count].opal_index = sdata[count - 1].opal_index;
382 sdata[count].hwmon_index = sdata[count - 1].hwmon_index;
383
384 make_sensor_label(np, &sdata[count], label);
385
386 create_hwmon_attr(&sdata[count], "label", show_label);
387
388 pgroups[type]->attrs[sensor_groups[type].attr_count++] =
389 &sdata[count++].dev_attr.attr;
390 }
342 } 391 }
343 392
344exit_put_node: 393exit_put_node: