From patchwork Fri Jul 14 17:48:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Prakash, Prashanth" X-Patchwork-Id: 9841493 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1DE5A60393 for ; Fri, 14 Jul 2017 17:59:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B6842879C for ; Fri, 14 Jul 2017 17:59:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0060D287A1; Fri, 14 Jul 2017 17:59:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 978402879D for ; Fri, 14 Jul 2017 17:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751029AbdGNR7F (ORCPT ); Fri, 14 Jul 2017 13:59:05 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:38052 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750857AbdGNR7C (ORCPT ); Fri, 14 Jul 2017 13:59:02 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 48F816028D; Fri, 14 Jul 2017 17:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1500054549; bh=lY6efh4WR+FajyCoQoAGs3mpYLQiG0OtKU2hABPhfKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=izZt6tDNGNWDYqhGwulQdq4OGpQhBbNnoSdmjR164mDj/0mJKjtmmgD7QFJ1zuyC1 O/j+EFj2cfAjfUX3UpYU+c2/kkyP0WmLDAvnIW5Fcp+E7Qv9i6G8V8gjPhNGpBXwk2 +hEc0yRi99SIY4XxVPzi9phtZxJnySomx8UJpwr4= Received: from pprakash-lnx.qualcomm.com (unknown [129.46.15.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: pprakash@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 164886028D; Fri, 14 Jul 2017 17:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1500054548; bh=lY6efh4WR+FajyCoQoAGs3mpYLQiG0OtKU2hABPhfKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MthEBU7GX2axb36Bt7jJrtBNeykFPgm3UJmxcHd52xb60MLi4Gsd9LNOcnNMXm3bj KWUqvpxFtTtHDNVEFt+mbHi5NX5Cu9S8Hnr4cekUTltWmpC/e+CySdPQampsV7oR9I GoG9KhKSW3VHsn/wIPDN9tPomDy/bROVjeX+C3rI= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 164886028D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=pprakash@codeaurora.org From: Prashanth Prakash To: linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: rui.zhang@intel.com, edubezval@gmail.com, Prashanth Prakash Subject: [PATCH 1/2] thermal: add a sysfs entry for thermal zone description Date: Fri, 14 Jul 2017 11:48:54 -0600 Message-Id: <1500054535-975-2-git-send-email-pprakash@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1500054535-975-1-git-send-email-pprakash@codeaurora.org> References: <1500054535-975-1-git-send-email-pprakash@codeaurora.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a method to thermal_zone_device_ops to read the description of a thermal zone. Use the same method to expose the description to the userspace via a sysfs entry. Signed-off-by: Prashanth Prakash --- Documentation/thermal/sysfs-api.txt | 6 ++++++ drivers/thermal/thermal_sysfs.c | 19 +++++++++++++++++++ include/linux/thermal.h | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt index bb9a0a5..b6aa417 100644 --- a/Documentation/thermal/sysfs-api.txt +++ b/Documentation/thermal/sysfs-api.txt @@ -62,6 +62,7 @@ temperature) and throttle appropriate devices. will be fired. .set_emul_temp: set the emulation temperature which helps in debugging different threshold temperature points. + .get_desc: get a user friendly description for a thermal zone (optional) tzp: thermal zone platform parameters. passive_delay: number of milliseconds to wait between polls when performing passive cooling. @@ -280,6 +281,7 @@ Thermal zone device sys I/F, created once it's registered: |---integral_cutoff: Offset above which errors are accumulated |---slope: Slope constant applied as linear extrapolation |---offset: Offset constant applied as linear extrapolation + |---desc User friendly description/name Thermal cooling device sys I/F, created once it's registered: /sys/class/thermal/cooling_device[0-*]: @@ -329,6 +331,10 @@ temp Unit: millidegree Celsius RO, Required +desc + Provides a user friendly description/name for thermal zone + RO, Optional + mode One of the predefined values in [enabled, disabled]. This file gives information about the algorithm that is currently diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index a694de9..46d961d 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -34,6 +34,23 @@ } static ssize_t +desc_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct thermal_zone_device *tz = to_thermal_zone(dev); + int ret; + char desc_str[THERMAL_MAX_DESC_STR_LEN]; + + if (!tz->ops->get_desc) + return scnprintf(buf, PAGE_SIZE, "\n"); + + ret = tz->ops->get_desc(tz, desc_str, THERMAL_MAX_DESC_STR_LEN); + if (ret) + return ret; + + return scnprintf(buf, THERMAL_MAX_DESC_STR_LEN, "%s\n", desc_str); +} + +static ssize_t temp_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); @@ -397,6 +414,7 @@ * present on the sysfs interface. */ static DEVICE_ATTR(type, 0444, type_show, NULL); +static DEVICE_ATTR(desc, 0444, desc_show, NULL); static DEVICE_ATTR(temp, 0444, temp_show, NULL); static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store); static DEVICE_ATTR(available_policies, S_IRUGO, available_policies_show, NULL); @@ -411,6 +429,7 @@ static DEVICE_ATTR(sustainable_power, S_IWUSR | S_IRUGO, sustainable_power_show, static struct attribute *thermal_zone_dev_attrs[] = { &dev_attr_type.attr, &dev_attr_temp.attr, + &dev_attr_desc.attr, #if (IS_ENABLED(CONFIG_THERMAL_EMULATION)) &dev_attr_emul_temp.attr, #endif diff --git a/include/linux/thermal.h b/include/linux/thermal.h index dab11f9..bd8377a 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -47,6 +47,9 @@ /* use value, which < 0K, to indicate an invalid/uninitialized temperature */ #define THERMAL_TEMP_INVALID -274000 +/* Maximum length of thermal zone description string */ +#define THERMAL_MAX_DESC_STR_LEN 32 + /* Unit conversion macros */ #define DECI_KELVIN_TO_CELSIUS(t) ({ \ long _t = (t); \ @@ -127,6 +130,7 @@ struct thermal_zone_device_ops { enum thermal_trend *); int (*notify) (struct thermal_zone_device *, int, enum thermal_trip_type); + int (*get_desc) (struct thermal_zone_device *, char *, int); }; struct thermal_cooling_device_ops {