From patchwork Wed Apr 1 10:15:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 457210 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1FD261400A0 for ; Wed, 1 Apr 2015 21:19:21 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 05E1D1A11C0 for ; Wed, 1 Apr 2015 21:19:21 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 313801A08D7 for ; Wed, 1 Apr 2015 21:15:57 +1100 (AEDT) Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 1 Apr 2015 11:15:53 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 1 Apr 2015 11:15:51 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 869091B08067; Wed, 1 Apr 2015 11:16:19 +0100 (BST) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t31AFoCa50528478; Wed, 1 Apr 2015 10:15:50 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t31AFl3n029127; Wed, 1 Apr 2015 04:15:50 -0600 Received: from hermes.kaod.org (sig-9-79-3-227.uk.ibm.com [9.79.3.227]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t31AFAaH028454; Wed, 1 Apr 2015 04:15:42 -0600 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: lm-sensors@lm-sensors.org Date: Wed, 1 Apr 2015 12:15:04 +0200 Message-Id: <1427883306-32528-3-git-send-email-clg@fr.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1426787085-9004-1-git-send-email-clg@fr.ibm.com> References: <1426787085-9004-1-git-send-email-clg@fr.ibm.com> MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15040110-0041-0000-0000-000003EC7A90 Cc: Jean Delvare , skiboot@lists.ozlabs.org, linuxppc-dev@lists.ozlabs.org, Guenter Roeck Subject: [Skiboot] [PATCH 2/4] hwmon: (ibmpowernv) add support for the new device tree X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" 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 --- drivers/hwmon/ibmpowernv.c | 47 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c index c9aa4d837c6f..f38aa27343f2 100644 --- a/drivers/hwmon/ibmpowernv.c +++ b/drivers/hwmon/ibmpowernv.c @@ -176,11 +176,26 @@ static const char *parse_opal_node_name(const char *node_name, static int get_sensor_type(struct device_node *np) { enum sensors type; + const char *str; for (type = 0; type < MAX_SENSOR_TYPE; type++) { if (of_device_is_compatible(np, sensor_groups[type].compatible)) return type; } + + /* + * Let's check if we have a newer device tree + */ + if (!of_device_is_compatible(np, "ibm,opal-sensor")) + return MAX_SENSOR_TYPE; + + if (of_property_read_string(np, "sensor-type", &str)) + return MAX_SENSOR_TYPE; + + for (type = 0; type < MAX_SENSOR_TYPE; type++) + if (!strcmp(str, sensor_groups[type].name)) + return type; + return MAX_SENSOR_TYPE; } @@ -189,11 +204,16 @@ static u32 get_sensor_hwmon_index(struct sensor_data *sdata, { int i; - for (i = 0; i < count; i++) - if (sdata_table[i].opal_index == sdata->opal_index && - sdata_table[i].type == sdata->type) - return sdata_table[i].hwmon_index; + /* + * We don't use the OPAL index on newer device trees + */ + if (sdata->opal_index != -1) { + for (i = 0; i < count; i++) + if (sdata_table[i].opal_index == sdata->opal_index && + sdata_table[i].type == sdata->type) + return sdata_table[i].hwmon_index; + } return ++sensor_groups[sdata->type].hwmon_index; } @@ -282,7 +302,12 @@ static int create_device_attrs(struct platform_device *pdev) if (type == MAX_SENSOR_TYPE) continue; - if (of_property_read_u32(np, "sensor-id", &sensor_id)) { + /* + * Newer device trees use a "sensor-data" property + * name for input. + */ + if (of_property_read_u32(np, "sensor-id", &sensor_id) && + of_property_read_u32(np, "sensor-data", &sensor_id)) { dev_info(&pdev->dev, "'sensor-id' missing in the node '%s'\n", np->name); @@ -292,12 +317,16 @@ static int create_device_attrs(struct platform_device *pdev) sdata[count].id = sensor_id; sdata[count].type = type; + /* + * If we can not parse the node name, it means we are + * running on a newer device tree. We can just forget + * about the OPAL index and use a defaut value for the + * hwmon attribute name + */ attr_name = parse_opal_node_name(np->name, type, &opal_index); if (IS_ERR(attr_name)) { - dev_err(&pdev->dev, "Sensor device node name '%s' is invalid\n", - np->name); - err = PTR_ERR(attr_name); - goto exit_put_node; + attr_name = "input"; + opal_index = -1; } sdata[count].opal_index = opal_index;