From patchwork Wed Jan 8 09:06:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Ni X-Patchwork-Id: 3452941 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E2509C02DC for ; Wed, 8 Jan 2014 09:06:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B31A2010C for ; Wed, 8 Jan 2014 09:06:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B4B820103 for ; Wed, 8 Jan 2014 09:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754886AbaAHJG0 (ORCPT ); Wed, 8 Jan 2014 04:06:26 -0500 Received: from hqemgate14.nvidia.com ([216.228.121.143]:3367 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755428AbaAHJGW (ORCPT ); Wed, 8 Jan 2014 04:06:22 -0500 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com id ; Wed, 08 Jan 2014 01:06:23 -0800 Received: from hqemhub03.nvidia.com ([172.20.12.94]) by hqnvupgp07.nvidia.com (PGP Universal service); Wed, 08 Jan 2014 01:06:46 -0800 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Wed, 08 Jan 2014 01:06:46 -0800 Received: from HQMAIL101.nvidia.com (172.20.187.10) by hqemhub03.nvidia.com (172.20.150.15) with Microsoft SMTP Server (TLS) id 8.3.327.1; Wed, 8 Jan 2014 01:06:21 -0800 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.712.24; Wed, 8 Jan 2014 01:06:21 -0800 Received: from hkemhub01.nvidia.com (10.18.67.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.712.24 via Frontend Transport; Wed, 8 Jan 2014 01:06:21 -0800 Received: from niwei-MCP7A.nvidia.com (10.18.67.6) by hkemhub01.nvidia.com (10.18.67.12) with Microsoft SMTP Server id 8.3.327.1; Wed, 8 Jan 2014 17:06:17 +0800 From: Wei Ni To: , , CC: , , , , Wei Ni Subject: [PATCH] thermal: use device node to get thermal zone Date: Wed, 8 Jan 2014 17:06:51 +0800 Message-ID: <1389172011-32107-1-git-send-email-wni@nvidia.com> X-Mailer: git-send-email 1.7.9.5 X-NVConfidentiality: public MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If use name to get the thermal zone, sometimes it can't get the unique thermal zone, because the thermal fw support same name for different thermal zone. So we can change to use device node to get thermal zone. Signed-off-by: Wei Ni --- drivers/thermal/of-thermal.c | 6 ++++-- drivers/thermal/thermal_core.c | 37 ++++++++++++++++--------------------- include/linux/thermal.h | 4 +++- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 04b1be7..97c12cf 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -330,7 +330,7 @@ thermal_zone_of_add_sensor(struct device_node *zone, struct thermal_zone_device *tzd; struct __thermal_zone *tz; - tzd = thermal_zone_get_zone_by_name(zone->name); + tzd = thermal_zone_get_zone_by_node(zone); if (IS_ERR(tzd)) return ERR_PTR(-EPROBE_DEFER); @@ -804,6 +804,8 @@ int __init of_parse_thermal_zones(void) of_thermal_free_zone(tz); /* attempting to build remaining zones still */ } + + zone->np = child; } return 0; @@ -837,7 +839,7 @@ void of_thermal_destroy_zones(void) for_each_child_of_node(np, child) { struct thermal_zone_device *zone; - zone = thermal_zone_get_zone_by_name(child->name); + zone = thermal_zone_get_zone_by_node(child); if (IS_ERR(zone)) continue; diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 338a88b..89e0637 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1635,42 +1635,37 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) EXPORT_SYMBOL_GPL(thermal_zone_device_unregister); /** - * thermal_zone_get_zone_by_name() - search for a zone and returns its ref - * @name: thermal zone name to fetch the temperature + * thermal_zone_get_zone_by_node() - search for a zone and returns its ref + * @node: device node of the thermal zone * - * When only one zone is found with the passed name, returns a reference to it. + * When thermal zone is found with the passed device node, returns a reference + * to it. * * Return: On success returns a reference to an unique thermal zone with - * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid - * paramenters, -ENODEV for not found and -EEXIST for multiple matches). + * matching device node, an ERR_PTR otherwise (-EINVAL for invalid + * paramenters, -ENODEV for not found). */ -struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name) +struct thermal_zone_device * +thermal_zone_get_zone_by_node(struct device_node *node) { - struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL); - unsigned int found = 0; + struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-ENODEV); + bool found = false; - if (!name) - goto exit; + if (!node) + return ERR_PTR(-EINVAL); mutex_lock(&thermal_list_lock); list_for_each_entry(pos, &thermal_tz_list, node) - if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) { - found++; + if (node == pos->np) { ref = pos; + found = true; + break; } mutex_unlock(&thermal_list_lock); - /* nothing has been found, thus an error code for it */ - if (found == 0) - ref = ERR_PTR(-ENODEV); - else if (found > 1) - /* Success only when an unique zone is found */ - ref = ERR_PTR(-EEXIST); - -exit: return ref; } -EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name); +EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_node); #ifdef CONFIG_NET static const struct genl_multicast_group thermal_event_mcgrps[] = { diff --git a/include/linux/thermal.h b/include/linux/thermal.h index f7e11c7..a94de8c 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -162,6 +162,7 @@ struct thermal_zone_device { int id; char type[THERMAL_NAME_LENGTH]; struct device device; + struct device_node *np; struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; @@ -285,7 +286,8 @@ struct thermal_cooling_device * thermal_of_cooling_device_register(struct device_node *np, char *, void *, const struct thermal_cooling_device_ops *); void thermal_cooling_device_unregister(struct thermal_cooling_device *); -struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name); +struct thermal_zone_device * +thermal_zone_get_zone_by_node(struct device_node *node); int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp); int get_tz_trend(struct thermal_zone_device *, int);