linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: lukasz.luba@arm.com
To: linux-kernel@vger.kernel.org, rui.zhang@intel.com,
	daniel.lezcano@linaro.org, linux-pm@vger.kernel.org,
	linux-doc@vger.kernel.org
Cc: amit.kucheria@verdurent.com, corbet@lwn.net, lukasz.luba@arm.com,
	dietmar.eggemann@arm.com
Subject: [PATCH  3/3] thermal: Add sysfs binding for cooling device and thermal zone
Date: Mon, 16 Dec 2019 14:06:22 +0000	[thread overview]
Message-ID: <20191216140622.25467-4-lukasz.luba@arm.com> (raw)
In-Reply-To: <20191216140622.25467-1-lukasz.luba@arm.com>

From: Lukasz Luba <lukasz.luba@arm.com>

Make it possible to bind from userspace a cooling device to an existing
thermal zone. It adds more flexibility in addition to static device tree
definitions. There is also a code for changing trip point connected to
cooling device instance in the thermal zone.

In order to bind a device to a zone, first the proper thermal zone name
must be checked from file:
cat /sys/class/thermal/thermal_zoneX/type
Then that name must be set into cooling device 'bind_tz' file:
echo 'gpu-thermal' > /sys/class/thermal/cooling_deviceY/bind_tz
Next a proper trip point must be chosen for this cooling device:
echo 2 > /sys/class/thermal/thermal_zoneX/cdev_Z_trip_point

To unbind, first set -1 to connected trip point:
echo -1 > /sys/class/thermal/thermal_zoneX/cdev_Z_trip_point
Then unbind the thermal zone from the cooling device:
echo 'gpu-thermal' > /sys/class/thermal/cooling_deviceY/unbind_tz

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/thermal/thermal_sysfs.c | 57 +++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index 80c8bae6dd1c..473449b41d55 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -722,15 +722,72 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
 	return result ? result : count;
 }
 
+static ssize_t
+bind_tz_store(struct device *dev, struct device_attribute *attr,
+		const char *buf, size_t count)
+{
+	struct thermal_cooling_device *cdev = to_cooling_device(dev);
+	struct thermal_zone_device *tz;
+	char *orig, *name;
+	int res = 0;
+
+	orig = kstrndup(buf, count, GFP_KERNEL);
+	if (!orig)
+		return -ENOMEM;
+
+	name = strstrip(orig);
+
+	tz = thermal_zone_get_zone_by_name(name);
+	if (IS_ERR_OR_NULL(tz))
+		return -EINVAL;
+
+	res = thermal_zone_bind_cooling_device(tz, THERMAL_TRIPS_NONE, cdev,
+					       THERMAL_NO_LIMIT,
+					       THERMAL_NO_LIMIT,
+					       THERMAL_WEIGHT_DEFAULT);
+
+	kfree(orig);
+	return res ? res : count;
+}
+
+static ssize_t
+unbind_tz_store(struct device *dev, struct device_attribute *attr,
+		const char *buf, size_t count)
+{
+	struct thermal_cooling_device *cdev = to_cooling_device(dev);
+	struct thermal_zone_device *tz;
+	char *name, *orig;
+	int res = 0;
+
+	orig = kstrndup(buf, count, GFP_KERNEL);
+	if (!orig)
+		return -ENOMEM;
+
+	name = strstrip(orig);
+
+	tz = thermal_zone_get_zone_by_name(name);
+	if (IS_ERR_OR_NULL(tz))
+		return -EINVAL;
+
+	res = thermal_zone_unbind_cooling_device(tz, THERMAL_TRIPS_NONE, cdev);
+
+	kfree(orig);
+	return res ? res : count;
+}
+
 static struct device_attribute
 dev_attr_cdev_type = __ATTR(type, 0444, cdev_type_show, NULL);
 static DEVICE_ATTR_RO(max_state);
 static DEVICE_ATTR_RW(cur_state);
+static DEVICE_ATTR_WO(bind_tz);
+static DEVICE_ATTR_WO(unbind_tz);
 
 static struct attribute *cooling_device_attrs[] = {
 	&dev_attr_cdev_type.attr,
 	&dev_attr_max_state.attr,
 	&dev_attr_cur_state.attr,
+	&dev_attr_bind_tz.attr,
+	&dev_attr_unbind_tz.attr,
 	NULL,
 };
 
-- 
2.17.1


  parent reply	other threads:[~2019-12-16 14:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-16 14:06 [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings lukasz.luba
2019-12-16 14:06 ` [PATCH 1/3] docs: thermal: Add bind, unbind information together with trip point lukasz.luba
2019-12-16 14:06 ` [PATCH 2/3] thermal: Make cooling device trip point writable from sysfs lukasz.luba
2019-12-16 14:06 ` lukasz.luba [this message]
2020-03-13 13:33 ` [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings Daniel Lezcano
2020-03-13 15:28   ` Lukasz Luba

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=20191216140622.25467-4-lukasz.luba@arm.com \
    --to=lukasz.luba@arm.com \
    --cc=amit.kucheria@verdurent.com \
    --cc=corbet@lwn.net \
    --cc=daniel.lezcano@linaro.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.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).