From: Thara Gopinath <thara.gopinath@linaro.org>
To: edubezval@gmail.com, rui.zhang@intel.com, ulf.hansson@linaro.org,
daniel.lezcano@linaro.org, bjorn.andersson@linaro.org,
agross@kernel.org
Cc: amit.kucheria@verdurent.com, mark.rutland@arm.com,
rjw@rjwysocki.net, linux-pm@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v3 4/7] thermal: Add generic power domain warming device driver.
Date: Wed, 16 Oct 2019 15:37:18 -0400 [thread overview]
Message-ID: <1571254641-13626-5-git-send-email-thara.gopinath@linaro.org> (raw)
In-Reply-To: <1571254641-13626-1-git-send-email-thara.gopinath@linaro.org>
Resources modeled as power domains in linux kenrel
can be used to warm the SoC(eg. mx power domain on sdm845).
To support this feature, introduce a generic power domain
warming device driver that can be plugged into the thermal framework
(The thermal framework itself requires further modifiction to
support a warming device in place of a cooling device.
Those extensions are not introduced in this patch series).
Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
---
drivers/thermal/Kconfig | 10 +++
drivers/thermal/Makefile | 2 +
drivers/thermal/pwr_domain_warming.c | 136 +++++++++++++++++++++++++++++++++++
include/linux/pwr_domain_warming.h | 31 ++++++++
4 files changed, 179 insertions(+)
create mode 100644 drivers/thermal/pwr_domain_warming.c
create mode 100644 include/linux/pwr_domain_warming.h
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 001a21a..0c5c93e 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -187,6 +187,16 @@ config DEVFREQ_THERMAL
If you want this support, you should say Y here.
+config PWR_DOMAIN_WARMING_THERMAL
+ bool "Power Domain based warming device"
+ depends on PM_GENERIC_DOMAINS_OF
+ help
+ This implements the generic power domain based warming
+ mechanism through increasing the performance state of
+ a power domain.
+
+ If you want this support, you should say Y here.
+
config THERMAL_EMULATION
bool "Thermal emulation mode support"
help
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 74a37c7..382c64a 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -27,6 +27,8 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL) += clock_cooling.o
# devfreq cooling
thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
+thermal_sys-$(CONFIG_PWR_DOMAIN_WARMING_THERMAL) += pwr_domain_warming.o
+
# platform thermal drivers
obj-y += broadcom/
obj-$(CONFIG_THERMAL_MMIO) += thermal_mmio.o
diff --git a/drivers/thermal/pwr_domain_warming.c b/drivers/thermal/pwr_domain_warming.c
new file mode 100644
index 0000000..60fae3e
--- /dev/null
+++ b/drivers/thermal/pwr_domain_warming.c
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019, Linaro Ltd
+ */
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/pm_runtime.h>
+#include <linux/slab.h>
+#include <linux/pwr_domain_warming.h>
+
+struct pd_warming_device {
+ struct thermal_cooling_device *cdev;
+ struct generic_pm_domain *gpd;
+ struct device *dev;
+ int max_state;
+ int cur_state;
+ bool runtime_resumed;
+};
+
+static int pd_wdev_get_max_state(struct thermal_cooling_device *cdev,
+ unsigned long *state)
+{
+ struct pd_warming_device *pd_wdev = cdev->devdata;
+
+ *state = pd_wdev->max_state;
+ return 0;
+}
+
+static int pd_wdev_get_cur_state(struct thermal_cooling_device *cdev,
+ unsigned long *state)
+{
+ struct pd_warming_device *pd_wdev = cdev->devdata;
+
+ *state = dev_pm_genpd_get_performance_state(pd_wdev->dev);
+
+ return 0;
+}
+
+static int pd_wdev_set_cur_state(struct thermal_cooling_device *cdev,
+ unsigned long state)
+{
+ struct pd_warming_device *pd_wdev = cdev->devdata;
+ struct device *dev = pd_wdev->dev;
+ int ret;
+
+ ret = dev_pm_genpd_set_performance_state(dev, state);
+
+ if (ret)
+ return ret;
+
+ if (state && !pd_wdev->runtime_resumed) {
+ ret = pm_runtime_get_sync(dev);
+ pd_wdev->runtime_resumed = true;
+ } else if (!state && pd_wdev->runtime_resumed) {
+ ret = pm_runtime_put(dev);
+ pd_wdev->runtime_resumed = false;
+ }
+
+ return ret;
+}
+
+static int pd_wdev_late_init(struct thermal_cooling_device *cdev)
+{
+ struct pd_warming_device *pd_wdev = cdev->devdata;
+ struct device *dev = &cdev->device;
+ int state_count, ret;
+
+ ret = pm_genpd_add_device(pd_wdev->gpd, dev);
+
+ if (ret)
+ return ret;
+
+ state_count = dev_pm_genpd_performance_state_count(dev);
+ if (state_count < 0)
+ return state_count;
+
+ pm_runtime_enable(dev);
+
+ pd_wdev->dev = dev;
+ pd_wdev->max_state = state_count - 1;
+
+ return 0;
+}
+
+static struct thermal_cooling_device_ops pd_warming_device_ops = {
+ .late_init = pd_wdev_late_init,
+ .get_max_state = pd_wdev_get_max_state,
+ .get_cur_state = pd_wdev_get_cur_state,
+ .set_cur_state = pd_wdev_set_cur_state,
+};
+
+struct thermal_cooling_device *
+pwr_domain_warming_register(struct device_node *node,
+ struct generic_pm_domain *gpd)
+{
+ struct pd_warming_device *pd_wdev;
+
+ pd_wdev = kzalloc(sizeof(*pd_wdev), GFP_KERNEL);
+ if (!pd_wdev)
+ return ERR_PTR(-ENOMEM);
+
+ pd_wdev->runtime_resumed = false;
+ pd_wdev->gpd = gpd;
+
+ pd_wdev->cdev = thermal_of_cooling_device_register
+ (node, gpd->name, pd_wdev,
+ &pd_warming_device_ops);
+ if (IS_ERR(pd_wdev->cdev)) {
+ pr_err("unable to register %s cooling device\n", gpd->name);
+ if (pd_wdev->dev)
+ pm_runtime_disable(pd_wdev->dev);
+ }
+
+ return pd_wdev->cdev;
+}
+EXPORT_SYMBOL_GPL(pwr_domain_warming_register);
+
+void pwr_domain_warming_unregister(struct thermal_cooling_device *cdev)
+{
+ struct pd_warming_device *pd_wdev = cdev->devdata;
+ struct device *dev = pd_wdev->dev;
+
+ if (pd_wdev->runtime_resumed) {
+ dev_pm_genpd_set_performance_state(dev, 0);
+ pm_runtime_put(dev);
+ pd_wdev->runtime_resumed = false;
+ }
+ pm_runtime_disable(pd_wdev->dev);
+ thermal_cooling_device_unregister(cdev);
+ kfree(pd_wdev);
+}
+EXPORT_SYMBOL_GPL(pwr_domain_warming_unregister);
diff --git a/include/linux/pwr_domain_warming.h b/include/linux/pwr_domain_warming.h
new file mode 100644
index 0000000..ed9942b
--- /dev/null
+++ b/include/linux/pwr_domain_warming.h
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019, Linaro Ltd.
+ */
+#ifndef __PWR_DOMAIN_WARMING_H__
+#define __PWR_DOMAIN_WARMING_H__
+
+#include <linux/pm_domain.h>
+#include <linux/thermal.h>
+
+#ifdef CONFIG_PWR_DOMAIN_WARMING_THERMAL
+struct thermal_cooling_device *
+pwr_domain_warming_register(struct device_node *node,
+ struct generic_pm_domain *gpd);
+
+void pwr_domain_warming_unregister(struct thermal_cooling_device *cdev);
+
+#else
+static inline struct thermal_cooling_device *
+pwr_domain_warming_register(struct device_node *node,
+ struct generic_pm_domain *gpd)
+{
+ return ERR_PTR(-ENOSYS);
+}
+
+static inline void
+pwr_domain_warming_unregister(struct thermal_cooling_device *cdev)
+{
+}
+#endif /* CONFIG_PWR_DOMAIN_WARMING_THERMAL */
+#endif /* __PWR_DOMAIN_WARMING_H__ */
--
2.1.4
next prev parent reply other threads:[~2019-10-16 19:38 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-16 19:37 [PATCH v3 0/7]Introduce Power domain based warming device driver Thara Gopinath
2019-10-16 19:37 ` [PATCH v3 1/7] PM/Domains: Add support for retrieving genpd performance states information Thara Gopinath
2019-10-17 8:49 ` Ulf Hansson
2019-10-17 16:11 ` Thara Gopinath
2019-10-16 19:37 ` [PATCH v3 2/7] soc: qcom: rpmhpd: Introduce function to retrieve power domain performance state count Thara Gopinath
2019-10-16 19:37 ` [PATCH v3 3/7] thermal: core: Add late init hook to cooling device ops Thara Gopinath
2019-12-03 17:04 ` Amit Kucheria
2019-12-03 17:09 ` Thara Gopinath
2019-12-03 17:11 ` Amit Kucheria
2019-10-16 19:37 ` Thara Gopinath [this message]
2019-10-17 8:47 ` [PATCH v3 4/7] thermal: Add generic power domain warming device driver Ulf Hansson
2019-10-17 15:46 ` Thara Gopinath
2019-10-16 19:37 ` [PATCH v3 5/7] soc: qcom: Extend RPMh power controller driver to register warming devices Thara Gopinath
2019-10-16 19:37 ` [PATCH v3 6/7] dt-bindings: soc: qcom: Extend RPMh power controller binding to describe thermal warming device Thara Gopinath
2019-10-17 9:04 ` Ulf Hansson
2019-10-17 15:28 ` Thara Gopinath
2019-10-17 15:43 ` Ulf Hansson
2019-10-17 16:10 ` Thara Gopinath
2019-10-29 1:36 ` Rob Herring
2019-10-29 10:06 ` Ulf Hansson
2019-10-29 20:16 ` Rob Herring
2019-10-30 9:27 ` Ulf Hansson
2019-10-30 14:27 ` Thara Gopinath
2019-10-16 19:37 ` [PATCH v3 7/7] arm64: dts: qcom: Add mx power domain as " Thara Gopinath
2019-10-29 1:31 ` Rob Herring
2019-10-30 14:23 ` Thara Gopinath
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=1571254641-13626-5-git-send-email-thara.gopinath@linaro.org \
--to=thara.gopinath@linaro.org \
--cc=agross@kernel.org \
--cc=amit.kucheria@verdurent.com \
--cc=bjorn.andersson@linaro.org \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=edubezval@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=rjw@rjwysocki.net \
--cc=rui.zhang@intel.com \
--cc=ulf.hansson@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;
as well as URLs for NNTP newsgroup(s).