From: Javi Merino <javi.merino@arm.com>
To: edubezval@gmail.com, rui.zhang@intel.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
punit.agrawal@arm.com, broonie@kernel.org, tixy@linaro.org,
Javi Merino <javi.merino@arm.com>
Subject: [PATCH v2 2/7] thermal: extend the cooling device API to include power information
Date: Thu, 26 Feb 2015 19:00:28 +0000 [thread overview]
Message-ID: <1424977233-15965-3-git-send-email-javi.merino@arm.com> (raw)
In-Reply-To: <1424977233-15965-1-git-send-email-javi.merino@arm.com>
Add three optional callbacks to the cooling device interface to allow
them to express power. In addition to the callbacks, add helpers to
identify cooling devices that implement the power cooling device API.
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Eduardo Valentin <edubezval@gmail.com>
Signed-off-by: Javi Merino <javi.merino@arm.com>
---
drivers/thermal/thermal_core.c | 52 ++++++++++++++++++++++++++++++++++++++++++
include/linux/thermal.h | 18 +++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 3bbda8979049..82f1cca9c8ce 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -873,6 +873,58 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,
static DEVICE_ATTR(emul_temp, S_IWUSR, NULL, emul_temp_store);
#endif/*CONFIG_THERMAL_EMULATION*/
+/**
+ * power_actor_get_max_power() - get the maximum power that a cdev can consume
+ * @cdev: pointer to &thermal_cooling_device
+ * @tz: a valid thermal zone device pointer
+ * @max_power: pointer in which to store the maximum power
+ *
+ * Calculate the maximum power consumption in milliwats that the
+ * cooling device can currently consume and store it in @max_power.
+ *
+ * Return: 0 on success, -EINVAL if @cdev doesn't support the
+ * power_actor API or -E* on other error.
+ */
+int power_actor_get_max_power(struct thermal_cooling_device *cdev,
+ struct thermal_zone_device *tz, u32 *max_power)
+{
+ if (!cdev_is_power_actor(cdev))
+ return -EINVAL;
+
+ return cdev->ops->state2power(cdev, tz, 0, max_power);
+}
+
+/**
+ * power_actor_set_power() - limit the maximum power that a cooling device can consume
+ * @cdev: pointer to &thermal_cooling_device
+ * @instance: thermal instance to update
+ * @power: the power in milliwatts
+ *
+ * Set the cooling device to consume at most @power milliwatts.
+ *
+ * Return: 0 on success, -EINVAL if the cooling device does not
+ * implement the power actor API or -E* for other failures.
+ */
+int power_actor_set_power(struct thermal_cooling_device *cdev,
+ struct thermal_instance *instance, u32 power)
+{
+ unsigned long state;
+ int ret;
+
+ if (!cdev_is_power_actor(cdev))
+ return -EINVAL;
+
+ ret = cdev->ops->power2state(cdev, instance->tz, power, &state);
+ if (ret)
+ return ret;
+
+ instance->target = state;
+ cdev->updated = false;
+ thermal_cdev_update(cdev);
+
+ return 0;
+}
+
static DEVICE_ATTR(type, 0444, type_show, NULL);
static DEVICE_ATTR(temp, 0444, temp_show, NULL);
static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 358c17990711..d69b1806f430 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -63,6 +63,7 @@
struct thermal_zone_device;
struct thermal_cooling_device;
+struct thermal_instance;
enum thermal_device_mode {
THERMAL_DEVICE_DISABLED = 0,
@@ -116,6 +117,12 @@ struct thermal_cooling_device_ops {
int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
+ int (*get_requested_power)(struct thermal_cooling_device *,
+ struct thermal_zone_device *, u32 *);
+ int (*state2power)(struct thermal_cooling_device *,
+ struct thermal_zone_device *, unsigned long, u32 *);
+ int (*power2state)(struct thermal_cooling_device *,
+ struct thermal_zone_device *, u32, unsigned long *);
};
struct thermal_cooling_device {
@@ -329,6 +336,17 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
}
#endif
+
+static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
+{
+ return cdev->ops->get_requested_power && cdev->ops->state2power &&
+ cdev->ops->power2state;
+}
+
+int power_actor_get_max_power(struct thermal_cooling_device *,
+ struct thermal_zone_device *tz, u32 *max_power);
+int power_actor_set_power(struct thermal_cooling_device *,
+ struct thermal_instance *, u32);
struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
void *, struct thermal_zone_device_ops *,
const struct thermal_zone_params *, int, int);
--
1.9.1
next prev parent reply other threads:[~2015-02-26 19:00 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-26 19:00 [PATCH v2 0/7] The power allocator thermal governor Javi Merino
2015-02-26 19:00 ` [PATCH v2 1/7] thermal: let governors have private data for each thermal zone Javi Merino
2015-02-26 19:00 ` Javi Merino [this message]
2015-02-26 19:00 ` [PATCH v2 3/7] thermal: cpu_cooling: implement the power cooling device API Javi Merino
2015-02-26 19:00 ` [PATCH v2 4/7] thermal: introduce the Power Allocator governor Javi Merino
2015-02-26 20:36 ` Eduardo Valentin
2015-02-27 16:12 ` Javi Merino
2015-02-26 19:00 ` [PATCH v2 5/7] thermal: add trace events to the power allocator governor Javi Merino
2015-02-26 19:38 ` Steven Rostedt
2015-02-26 19:46 ` Eduardo Valentin
2015-02-26 22:52 ` Steven Rostedt
2015-02-26 21:18 ` Eduardo Valentin
2015-02-27 0:09 ` Steven Rostedt
2015-02-26 19:00 ` [PATCH v2 6/7] of: thermal: Introduce sustainable power for a thermal zone Javi Merino
2015-02-26 19:00 ` [PATCH v2 7/7] thermal: export thermal_zone_parameters to sysfs Javi Merino
2015-02-26 21:30 ` Eduardo Valentin
2015-02-26 22:04 ` Eduardo Valentin
2015-02-27 17:19 ` Javi Merino
2015-02-26 22:10 ` Eduardo Valentin
2015-03-02 14:17 ` Javi Merino
2015-02-26 22:16 ` [PATCH v2 0/7] The power allocator thermal governor Eduardo Valentin
2015-03-02 16:28 ` Javi Merino
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=1424977233-15965-3-git-send-email-javi.merino@arm.com \
--to=javi.merino@arm.com \
--cc=broonie@kernel.org \
--cc=edubezval@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=punit.agrawal@arm.com \
--cc=rui.zhang@intel.com \
--cc=tixy@linaro.org \
/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