From patchwork Thu Jan 9 10:37:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Ni X-Patchwork-Id: 3458261 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 7D75CC02DC for ; Thu, 9 Jan 2014 10:37:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 53B002016C for ; Thu, 9 Jan 2014 10:37:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 27CE32016A for ; Thu, 9 Jan 2014 10:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751040AbaAIKht (ORCPT ); Thu, 9 Jan 2014 05:37:49 -0500 Received: from hqemgate16.nvidia.com ([216.228.121.65]:9756 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751291AbaAIKht (ORCPT ); Thu, 9 Jan 2014 05:37:49 -0500 Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Thu, 09 Jan 2014 02:38:07 -0800 Received: from hqemhub03.nvidia.com ([172.20.12.94]) by hqnvupgp08.nvidia.com (PGP Universal service); Thu, 09 Jan 2014 02:37:51 -0800 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Thu, 09 Jan 2014 02:37:51 -0800 Received: from HQMAIL106.nvidia.com (172.18.146.12) by hqemhub03.nvidia.com (172.20.150.15) with Microsoft SMTP Server (TLS) id 8.3.327.1; Thu, 9 Jan 2014 02:37:48 -0800 Received: from HQMAIL106.nvidia.com (172.18.146.12) by HQMAIL106.nvidia.com (172.18.146.12) with Microsoft SMTP Server (TLS) id 15.0.712.24; Thu, 9 Jan 2014 02:37:48 -0800 Received: from hkemhub02.nvidia.com (10.18.67.13) by HQMAIL106.nvidia.com (172.18.146.12) with Microsoft SMTP Server (TLS) id 15.0.712.24 via Frontend Transport; Thu, 9 Jan 2014 02:37:47 -0800 Received: from niwei-MCP7A.nvidia.com (10.18.67.6) by hkemhub02.nvidia.com (10.18.67.13) with Microsoft SMTP Server id 8.3.327.1; Thu, 9 Jan 2014 18:37:45 +0800 From: Wei Ni To: , , , CC: , , , , Wei Ni Subject: [PATCH v2 1/2] thermal: introduce thermal_zone_get_zone_by_node helper function Date: Thu, 9 Jan 2014 18:37:58 +0800 Message-ID: <1389263879-10483-2-git-send-email-wni@nvidia.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1389263879-10483-1-git-send-email-wni@nvidia.com> References: <1389263879-10483-1-git-send-email-wni@nvidia.com> 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=-6.9 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 The thermal framework start to support device tree, this patch adds a helper function to get a reference of a thermal zone, based on the zone's device node. It will add a device_node *np member in the struct thermal_zone_device, and initialize it when create a thermal zone. This funciton perform a zone device node lookup and return a reference to a thermal zone device that matches the device node requested. In case the zone is not found or if the required parameters are invalid, it will return the corresponding error code (ERR_PTR). Change-Id: I4d65f849e84425dddd387f70886a9c7c4c2002f2 Signed-off-by: Wei Ni --- drivers/thermal/of-thermal.c | 2 ++ drivers/thermal/thermal_core.c | 33 +++++++++++++++++++++++++++++++++ include/linux/thermal.h | 3 +++ 3 files changed, 38 insertions(+) diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 04b1be7..53f2d3a 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -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; diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 338a88b..eeddb94 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1672,6 +1672,39 @@ exit: } EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name); +/** +* thermal_zone_get_zone_by_node() - search for a zone and returns its ref +* @node: device node of the thermal zone +* +* 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 device node, an ERR_PTR otherwise (-EINVAL for invalid +* paramenters, -ENODEV for not found). +*/ +struct thermal_zone_device * +thermal_zone_get_zone_by_node(struct device_node *node) +{ + struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-ENODEV); + bool found = false; + + if (!node) + return ERR_PTR(-EINVAL); + + mutex_lock(&thermal_list_lock); + list_for_each_entry(pos, &thermal_tz_list, node) + if (node == pos->np) { + ref = pos; + found = true; + break; + } + mutex_unlock(&thermal_list_lock); + + return ref; +} +EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_node); + #ifdef CONFIG_NET static const struct genl_multicast_group thermal_event_mcgrps[] = { { .name = THERMAL_GENL_MCAST_GROUP_NAME, }, diff --git a/include/linux/thermal.h b/include/linux/thermal.h index f7e11c7..288d272 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; @@ -286,6 +287,8 @@ 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);