diff options
author | Cédric Le Goater <clg@fr.ibm.com> | 2015-04-08 19:19:49 +0200 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2015-04-08 10:34:20 -0700 |
commit | 2bcd3787b946b725a37763c0877da0996f5ec064 (patch) | |
tree | ec81d8281653d5e7822644a887f7de3452aed237 /drivers/hwmon | |
parent | 14681637ab3013d3577cc59633159f425733532e (diff) | |
download | op-kernel-dev-2bcd3787b946b725a37763c0877da0996f5ec064.zip op-kernel-dev-2bcd3787b946b725a37763c0877da0996f5ec064.tar.gz |
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>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/ibmpowernv.c | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c index b6bc463..1180ce6 100644 --- a/drivers/hwmon/ibmpowernv.c +++ b/drivers/hwmon/ibmpowernv.c @@ -32,6 +32,7 @@ #include <linux/err.h> #define MAX_ATTR_LEN 32 +#define MAX_LABEL_LEN 64 /* Sensor suffix name from DT */ #define DT_FAULT_ATTR_SUFFIX "faulted" @@ -70,6 +71,7 @@ struct sensor_data { u32 hwmon_index; u32 opal_index; enum sensors type; + char label[MAX_LABEL_LEN]; char name[MAX_ATTR_LEN]; struct device_attribute dev_attr; }; @@ -101,8 +103,25 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr, return sprintf(buf, "%u\n", x); } -static int get_sensor_index_attr(const char *name, u32 *index, - char *attr) +static ssize_t show_label(struct device *dev, struct device_attribute *devattr, + char *buf) +{ + struct sensor_data *sdata = container_of(devattr, struct sensor_data, + dev_attr); + + return sprintf(buf, "%s\n", sdata->label); +} + +static void __init make_sensor_label(struct device_node *np, + struct sensor_data *sdata, + const char *label) +{ + size_t n; + + n = snprintf(sdata->label, sizeof(sdata->label), "%s", label); +} + +static int get_sensor_index_attr(const char *name, u32 *index, char *attr) { char *hash_pos = strchr(name, '#'); char buf[8] = { 0 }; @@ -227,11 +246,21 @@ static int populate_attr_groups(struct platform_device *pdev) opal = of_find_node_by_path("/ibm,opal/sensors"); for_each_child_of_node(opal, np) { + const char *label; + if (np->name == NULL) continue; type = get_sensor_type(np); - if (type != MAX_SENSOR_TYPE) + if (type == MAX_SENSOR_TYPE) + continue; + + sensor_groups[type].attr_count++; + + /* + * add a new attribute for labels + */ + if (!of_property_read_string(np, "label", &label)) sensor_groups[type].attr_count++; } @@ -296,6 +325,7 @@ static int create_device_attrs(struct platform_device *pdev) for_each_child_of_node(opal, np) { const char *attr_name; u32 opal_index; + const char *label; if (np->name == NULL) continue; @@ -339,6 +369,25 @@ static int create_device_attrs(struct platform_device *pdev) pgroups[type]->attrs[sensor_groups[type].attr_count++] = &sdata[count++].dev_attr.attr; + + if (!of_property_read_string(np, "label", &label)) { + /* + * For the label attribute, we can reuse the + * "properties" of the previous "input" + * attribute. They are related to the same + * sensor. + */ + sdata[count].type = type; + sdata[count].opal_index = sdata[count - 1].opal_index; + sdata[count].hwmon_index = sdata[count - 1].hwmon_index; + + make_sensor_label(np, &sdata[count], label); + + create_hwmon_attr(&sdata[count], "label", show_label); + + pgroups[type]->attrs[sensor_groups[type].attr_count++] = + &sdata[count++].dev_attr.attr; + } } exit_put_node: |