From patchwork Wed Nov 4 17:37:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javi Merino X-Patchwork-Id: 7552471 X-Patchwork-Delegate: eduardo.valentin@ti.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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 282D7BEEA4 for ; Wed, 4 Nov 2015 17:39:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 69F8A20765 for ; Wed, 4 Nov 2015 17:39:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D56082076F for ; Wed, 4 Nov 2015 17:39:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030721AbbKDRiq (ORCPT ); Wed, 4 Nov 2015 12:38:46 -0500 Received: from foss.arm.com ([217.140.101.70]:33262 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030715AbbKDRio (ORCPT ); Wed, 4 Nov 2015 12:38:44 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0AB854A; Wed, 4 Nov 2015 09:38:34 -0800 (PST) Received: from e104805-lin.cambridge.arm.com (e104805-lin.cambridge.arm.com [10.1.205.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 03E9C3F21A; Wed, 4 Nov 2015 09:38:42 -0800 (PST) From: Javi Merino To: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rui.zang@intel.com, edubezval@gmail.com, Javi Merino , Zhang Rui Subject: [PATCH v2 3/3] thermal: show the sub thermal zones in sysfs Date: Wed, 4 Nov 2015 17:37:42 +0000 Message-Id: <1446658662-19582-4-git-send-email-javi.merino@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446658662-19582-1-git-send-email-javi.merino@arm.com> References: <1446658662-19582-1-git-send-email-javi.merino@arm.com> 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, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 When a thermal zone is created that has sub thermal zones via devicetree or via thermal_zone_add_subtz() expose that relationship in sysfs. Cc: Zhang Rui Cc: Eduardo Valentin Signed-off-by: Javi Merino --- Documentation/thermal/sysfs-api.txt | 5 +++++ drivers/thermal/thermal_core.c | 22 ++++++++++++++++++++++ include/linux/thermal.h | 3 +++ 3 files changed, 30 insertions(+) diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt index 5650b7eaaf7e..53972973792a 100644 --- a/Documentation/thermal/sysfs-api.txt +++ b/Documentation/thermal/sysfs-api.txt @@ -220,6 +220,7 @@ Thermal zone device sys I/F, created once it's registered: |---trip_point_[0-*]_type: Trip point type |---trip_point_[0-*]_hyst: Hysteresis value for this trip point |---emul_temp: Emulated temperature set node + |---subtz[0-*] Slave thermal zones of this thermal zone |---sustainable_power: Sustainable dissipatable power |---k_po: Proportional term during temperature overshoot |---k_pu: Proportional term during temperature undershoot @@ -355,6 +356,10 @@ emul_temp because userland can easily disable the thermal policy by simply flooding this sysfs node with low temperature values. +subtz[0-*] + sysfs link to the slave thermal zone device. + RO, Optional + sustainable_power An estimate of the sustained power that can be dissipated by the thermal zone. Used by the power allocator governor. For diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index a2ab482337f3..af72b704af36 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -62,6 +62,8 @@ static DEFINE_MUTEX(thermal_governor_lock); static struct thermal_governor *def_governor; struct thermal_zone_link { + int id; + char name[THERMAL_NAME_LENGTH]; struct thermal_zone_device *slave; struct list_head node; }; @@ -2076,6 +2078,23 @@ int thermal_zone_add_subtz(struct thermal_zone_device *tz, link->slave = subtz; list_add_tail(&link->node, &tz->slave_tzs); + ret = get_idr(&tz->link_idr, NULL, &link->id); + if (ret) { + /* + * Even if we couldn't create the symlink in sysfs, + * we've linked the thermal zones, so return success + */ + ret = 0; + goto unlock; + } + + snprintf(link->name, ARRAY_SIZE(link->name), "subtz%d", link->id); + ret = sysfs_create_link(&tz->device.kobj, &subtz->device.kobj, + link->name); + if (ret) + pr_warn("Failed to create symlink to sub thermal zone: %d\n", + ret); + ret = 0; unlock: @@ -2107,6 +2126,9 @@ int thermal_zone_del_subtz(struct thermal_zone_device *tz, list_for_each_entry(link, &tz->slave_tzs, node) { if (link->slave == subtz) { + sysfs_remove_link(&tz->device.kobj, link->name); + release_idr(&tz->link_idr, NULL, link->id); + list_del(&link->node); kfree(link); diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 01de95d16679..e1fcac52a7a5 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -174,6 +174,8 @@ struct thermal_attr { * @thermal_instances: list of &struct thermal_instance of this thermal zone * @idr: &struct idr to generate unique id for this zone's cooling * devices + * @link_idr: &struct idr to generate unique ids for this zone's links to + * other thermal zones * @lock: lock to protect thermal_instances list * @node: node in thermal_tz_list (in thermal_core.c) * @poll_queue: delayed work for polling @@ -202,6 +204,7 @@ struct thermal_zone_device { void *governor_data; struct list_head thermal_instances; struct idr idr; + struct idr link_idr; struct mutex lock; struct list_head node; struct delayed_work poll_queue;