aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Le Goater <clg@fr.ibm.com>2015-04-08 13:19:48 -0400
committerGuenter Roeck <linux@roeck-us.net>2015-04-08 13:34:20 -0400
commit14681637ab3013d3577cc59633159f425733532e (patch)
tree6d6fd26df55390d612c7a2697d31576b3c0811a2
parent9e4f74b11925d033dcbe429f1fb6202cab03ad8f (diff)
hwmon: (ibmpowernv) add support for the new device tree
The new OPAL device tree for sensors has a different layout and uses new property names, for the type and for the handler used to capture the sensor data. This patch modifies the ibmpowernv driver to support such a tree in a way preserving compatibility with older OPAL firmwares. This is achieved by changing the error path of the routine parsing an OPAL node name. The node is simply considered being from the new device tree layout and fallback values are used. 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.c50
1 files changed, 40 insertions, 10 deletions
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
index ebf335c71990..b6bc463886c0 100644
--- a/drivers/hwmon/ibmpowernv.c
+++ b/drivers/hwmon/ibmpowernv.c
@@ -50,6 +50,8 @@ enum sensors {
50 MAX_SENSOR_TYPE, 50 MAX_SENSOR_TYPE,
51}; 51};
52 52
53#define INVALID_INDEX (-1U)
54
53static struct sensor_group { 55static struct sensor_group {
54 const char *name; 56 const char *name;
55 const char *compatible; 57 const char *compatible;
@@ -176,11 +178,26 @@ static const char *parse_opal_node_name(const char *node_name,
176static int get_sensor_type(struct device_node *np) 178static int get_sensor_type(struct device_node *np)
177{ 179{
178 enum sensors type; 180 enum sensors type;
181 const char *str;
179 182
180 for (type = 0; type < MAX_SENSOR_TYPE; type++) { 183 for (type = 0; type < MAX_SENSOR_TYPE; type++) {
181 if (of_device_is_compatible(np, sensor_groups[type].compatible)) 184 if (of_device_is_compatible(np, sensor_groups[type].compatible))
182 return type; 185 return type;
183 } 186 }
187
188 /*
189 * Let's check if we have a newer device tree
190 */
191 if (!of_device_is_compatible(np, "ibm,opal-sensor"))
192 return MAX_SENSOR_TYPE;
193
194 if (of_property_read_string(np, "sensor-type", &str))
195 return MAX_SENSOR_TYPE;
196
197 for (type = 0; type < MAX_SENSOR_TYPE; type++)
198 if (!strcmp(str, sensor_groups[type].name))
199 return type;
200
184 return MAX_SENSOR_TYPE; 201 return MAX_SENSOR_TYPE;
185} 202}
186 203
@@ -189,11 +206,15 @@ static u32 get_sensor_hwmon_index(struct sensor_data *sdata,
189{ 206{
190 int i; 207 int i;
191 208
192 for (i = 0; i < count; i++) 209 /*
193 if (sdata_table[i].opal_index == sdata->opal_index && 210 * We don't use the OPAL index on newer device trees
194 sdata_table[i].type == sdata->type) 211 */
195 return sdata_table[i].hwmon_index; 212 if (sdata->opal_index != INVALID_INDEX) {
196 213 for (i = 0; i < count; i++)
214 if (sdata_table[i].opal_index == sdata->opal_index &&
215 sdata_table[i].type == sdata->type)
216 return sdata_table[i].hwmon_index;
217 }
197 return ++sensor_groups[sdata->type].hwmon_index; 218 return ++sensor_groups[sdata->type].hwmon_index;
198} 219}
199 220
@@ -283,7 +304,12 @@ static int create_device_attrs(struct platform_device *pdev)
283 if (type == MAX_SENSOR_TYPE) 304 if (type == MAX_SENSOR_TYPE)
284 continue; 305 continue;
285 306
286 if (of_property_read_u32(np, "sensor-id", &sensor_id)) { 307 /*
308 * Newer device trees use a "sensor-data" property
309 * name for input.
310 */
311 if (of_property_read_u32(np, "sensor-id", &sensor_id) &&
312 of_property_read_u32(np, "sensor-data", &sensor_id)) {
287 dev_info(&pdev->dev, 313 dev_info(&pdev->dev,
288 "'sensor-id' missing in the node '%s'\n", 314 "'sensor-id' missing in the node '%s'\n",
289 np->name); 315 np->name);
@@ -293,12 +319,16 @@ static int create_device_attrs(struct platform_device *pdev)
293 sdata[count].id = sensor_id; 319 sdata[count].id = sensor_id;
294 sdata[count].type = type; 320 sdata[count].type = type;
295 321
322 /*
323 * If we can not parse the node name, it means we are
324 * running on a newer device tree. We can just forget
325 * about the OPAL index and use a defaut value for the
326 * hwmon attribute name
327 */
296 attr_name = parse_opal_node_name(np->name, type, &opal_index); 328 attr_name = parse_opal_node_name(np->name, type, &opal_index);
297 if (IS_ERR(attr_name)) { 329 if (IS_ERR(attr_name)) {
298 dev_err(&pdev->dev, "Sensor device node name '%s' is invalid\n", 330 attr_name = "input";
299 np->name); 331 opal_index = INVALID_INDEX;
300 err = PTR_ERR(attr_name);
301 goto exit_put_node;
302 } 332 }
303 333
304 sdata[count].opal_index = opal_index; 334 sdata[count].opal_index = opal_index;