From: Zhang Rui <rui.zhang@intel.com>
To: "Rafael J. Wysocki" <rjw@sisk.pl>,
Matthew Garrett <mjg@redhat.com>, Len Brown <lenb@kernel.org>,
R Durgadoss <durgadoss.r@intel.com>,
Eduardo Valentin <eduardo.valentin@ti.com>,
Amit Kachhap <amit.kachhap@linaro.org>, Wei Ni <wni@nvidia.com>,
Zhang Rui <rui.zhang@intel.com>
Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org
Subject: [PATCH RESEND 02/16] Thermal: Add Hysteresis attributes
Date: Wed, 25 Jul 2012 10:10:59 +0800 [thread overview]
Message-ID: <1343182273-32096-3-git-send-email-rui.zhang@intel.com> (raw)
In-Reply-To: <1343182273-32096-1-git-send-email-rui.zhang@intel.com>
From: Durgadoss R <dugardoss.r@intel.com>
The Linux Thermal Framework does not support hysteresis
attributes. Most thermal sensors, today, have a
hysteresis value associated with trip points.
This patch adds hysteresis attributes on a per-trip-point
basis, to the Thermal Framework. These attributes are
optionally writable.
Signed-off-by: Durgadoss R <durgadoss.r@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
Documentation/thermal/sysfs-api.txt | 6 +++
drivers/thermal/thermal_sys.c | 88 +++++++++++++++++++++++++++++++++--
include/linux/thermal.h | 5 ++
3 files changed, 94 insertions(+), 5 deletions(-)
diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt
index 4c10593..2ba4c9b 100644
--- a/Documentation/thermal/sysfs-api.txt
+++ b/Documentation/thermal/sysfs-api.txt
@@ -121,6 +121,7 @@ if hwmon is compiled in or built as a module.
|---mode: Working mode of the thermal zone
|---trip_point_[0-*]_temp: Trip point temperature
|---trip_point_[0-*]_type: Trip point type
+ |---trip_point_[0-*]_hyst: Hysteresis value for this trip point
Thermal cooling device sys I/F, created once it's registered:
/sys/class/thermal/cooling_device[0-*]:
@@ -190,6 +191,11 @@ trip_point_[0-*]_type
thermal zone.
RO, Optional
+trip_point_[0-*]_hyst
+ The hysteresis value for a trip point, represented as an integer
+ Unit: Celsius
+ RW, Optional
+
cdev[0-*]
Sysfs link to the thermal cooling device node where the sys I/F
for cooling device throttling control represents.
diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 5feb335..2d7a9fe 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -240,6 +240,52 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
}
static ssize_t
+trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct thermal_zone_device *tz = to_thermal_zone(dev);
+ int trip, ret;
+ unsigned long temperature;
+
+ if (!tz->ops->set_trip_hyst)
+ return -EPERM;
+
+ if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
+ return -EINVAL;
+
+ if (kstrtoul(buf, 10, &temperature))
+ return -EINVAL;
+
+ /*
+ * We are not doing any check on the 'temperature' value
+ * here. The driver implementing 'set_trip_hyst' has to
+ * take care of this.
+ */
+ ret = tz->ops->set_trip_hyst(tz, trip, temperature);
+
+ return ret ? ret : count;
+}
+
+static ssize_t
+trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct thermal_zone_device *tz = to_thermal_zone(dev);
+ int trip, ret;
+ unsigned long temperature;
+
+ if (!tz->ops->get_trip_hyst)
+ return -EPERM;
+
+ if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
+ return -EINVAL;
+
+ ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
+
+ return ret ? ret : sprintf(buf, "%ld\n", temperature);
+}
+
+static ssize_t
passive_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
@@ -1091,21 +1137,29 @@ EXPORT_SYMBOL(thermal_zone_device_update);
static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
{
int indx;
+ int size = sizeof(struct thermal_attr) * tz->trips;
- tz->trip_type_attrs =
- kzalloc(sizeof(struct thermal_attr) * tz->trips, GFP_KERNEL);
+ tz->trip_type_attrs = kzalloc(size, GFP_KERNEL);
if (!tz->trip_type_attrs)
return -ENOMEM;
- tz->trip_temp_attrs =
- kzalloc(sizeof(struct thermal_attr) * tz->trips, GFP_KERNEL);
+ tz->trip_temp_attrs = kzalloc(size, GFP_KERNEL);
if (!tz->trip_temp_attrs) {
kfree(tz->trip_type_attrs);
return -ENOMEM;
}
- for (indx = 0; indx < tz->trips; indx++) {
+ if (tz->ops->get_trip_hyst) {
+ tz->trip_hyst_attrs = kzalloc(size, GFP_KERNEL);
+ if (!tz->trip_hyst_attrs) {
+ kfree(tz->trip_type_attrs);
+ kfree(tz->trip_temp_attrs);
+ return -ENOMEM;
+ }
+ }
+
+ for (indx = 0; indx < tz->trips; indx++) {
/* create trip type attribute */
snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
"trip_point_%d_type", indx);
@@ -1136,6 +1190,26 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
device_create_file(&tz->device,
&tz->trip_temp_attrs[indx].attr);
+
+ /* create Optional trip hyst attribute */
+ if (!tz->ops->get_trip_hyst)
+ continue;
+ snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH,
+ "trip_point_%d_hyst", indx);
+
+ sysfs_attr_init(&tz->trip_hyst_attrs[indx].attr.attr);
+ tz->trip_hyst_attrs[indx].attr.attr.name =
+ tz->trip_hyst_attrs[indx].name;
+ tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO;
+ tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show;
+ if (tz->ops->set_trip_hyst) {
+ tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR;
+ tz->trip_hyst_attrs[indx].attr.store =
+ trip_point_hyst_store;
+ }
+
+ device_create_file(&tz->device,
+ &tz->trip_hyst_attrs[indx].attr);
}
return 0;
}
@@ -1149,9 +1223,13 @@ static void remove_trip_attrs(struct thermal_zone_device *tz)
&tz->trip_type_attrs[indx].attr);
device_remove_file(&tz->device,
&tz->trip_temp_attrs[indx].attr);
+ if (tz->ops->get_trip_hyst)
+ device_remove_file(&tz->device,
+ &tz->trip_hyst_attrs[indx].attr);
}
kfree(tz->trip_type_attrs);
kfree(tz->trip_temp_attrs);
+ kfree(tz->trip_hyst_attrs);
}
/**
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 6eaf914..cfc8d90 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -60,6 +60,10 @@ struct thermal_zone_device_ops {
unsigned long *);
int (*set_trip_temp) (struct thermal_zone_device *, int,
unsigned long);
+ int (*get_trip_hyst) (struct thermal_zone_device *, int,
+ unsigned long *);
+ int (*set_trip_hyst) (struct thermal_zone_device *, int,
+ unsigned long);
int (*get_crit_temp) (struct thermal_zone_device *, unsigned long *);
int (*notify) (struct thermal_zone_device *, int,
enum thermal_trip_type);
@@ -98,6 +102,7 @@ struct thermal_zone_device {
struct device device;
struct thermal_attr *trip_temp_attrs;
struct thermal_attr *trip_type_attrs;
+ struct thermal_attr *trip_hyst_attrs;
void *devdata;
int trips;
int tc1;
--
1.7.9.5
next prev parent reply other threads:[~2012-07-25 2:11 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 2:10 [PATCH RESEND 00/16] Thermal: generic thermal layer enhancement Zhang Rui
2012-07-25 2:10 ` [PATCH RESEND 01/16] Thermal: Make Thermal trip points writeable Zhang Rui
2012-07-25 3:18 ` Len Brown
2012-07-25 2:10 ` Zhang Rui [this message]
2012-07-25 3:19 ` [PATCH RESEND 02/16] Thermal: Add Hysteresis attributes Len Brown
2012-07-25 2:11 ` [PATCH RESEND 03/16] Thermal: Documentation update Zhang Rui
2012-07-25 2:11 ` [PATCH RESEND 04/16] Thermal: Introduce multiple cooling states support Zhang Rui
2012-07-25 20:06 ` Rafael J. Wysocki
2012-07-26 2:33 ` Zhang Rui
2012-07-25 2:11 ` [PATCH RESEND 05/16] Thermal: Introduce cooling states range support Zhang Rui
2012-07-25 20:08 ` Rafael J. Wysocki
2012-08-08 12:07 ` Valentin, Eduardo
2012-07-25 2:11 ` [PATCH RESEND 06/16] Thermal: set upper and lower limits Zhang Rui
2012-07-25 20:14 ` Rafael J. Wysocki
2012-08-08 12:50 ` Valentin, Eduardo
2012-07-25 2:11 ` [PATCH RESEND 07/16] Thermal: Introduce .get_trend() callback Zhang Rui
2012-07-25 20:19 ` Rafael J. Wysocki
2012-07-26 2:21 ` Zhang Rui
2012-07-25 2:11 ` [PATCH RESEND 08/16] Thermal: Remove tc1/tc2 in generic thermal layer Zhang Rui
2012-07-25 20:24 ` Rafael J. Wysocki
2012-07-26 2:23 ` Zhang Rui
2012-07-25 2:11 ` [PATCH RESEND 09/16] Thermal: Introduce thermal_zone_trip_update() Zhang Rui
2012-07-25 20:31 ` Rafael J. Wysocki
2012-07-26 2:25 ` Zhang Rui
2012-07-25 2:11 ` [PATCH RESEND 10/16] Thermal: rename structure thermal_cooling_device_instance to thermal_instance Zhang Rui
2012-07-25 20:32 ` Rafael J. Wysocki
2012-07-25 2:11 ` [PATCH RESEND 11/16] Thermal: Rename thermal_zone_device.cooling_devices Zhang Rui
2012-07-25 20:33 ` Rafael J. Wysocki
2012-07-25 2:11 ` [PATCH RESEND 12/16] Thermal: Rename thermal_instance.node to thermal_instance.tz_node Zhang Rui
2012-07-25 20:34 ` Rafael J. Wysocki
2012-07-25 2:11 ` [PATCH RESEND 13/16] Thermal: List thermal_instance in thermal_cooling_device Zhang Rui
2012-07-25 20:35 ` Rafael J. Wysocki
2012-07-25 2:11 ` [PATCH RESEND 14/16] Thermal: Introduce simple arbitrator for setting device cooling state Zhang Rui
2012-07-25 20:38 ` Rafael J. Wysocki
2012-07-25 2:11 ` [PATCH RESEND 15/16] Thermal: Unify the code for both active and passive cooling Zhang Rui
2012-07-25 20:41 ` Rafael J. Wysocki
2012-08-09 8:26 ` Valentin, Eduardo
2012-08-09 8:32 ` Zhang Rui
2012-07-25 2:11 ` [PATCH RESEND 16/16] Thermal: Introduce locking for cdev.thermal_instances list Zhang Rui
2012-07-25 18:54 ` Rafael J. Wysocki
2012-07-26 2:32 ` Zhang Rui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343182273-32096-3-git-send-email-rui.zhang@intel.com \
--to=rui.zhang@intel.com \
--cc=amit.kachhap@linaro.org \
--cc=durgadoss.r@intel.com \
--cc=eduardo.valentin@ti.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mjg@redhat.com \
--cc=rjw@sisk.pl \
--cc=wni@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).