All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amit Kucheria <amit.kucheria@linaro.org>
To: linux-kernel@vger.kernel.org
Cc: linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org,
	viresh.kumar@linaro.org, edubezval@gmail.com,
	andy.gross@linaro.org, tdas@codeaurora.org, swboyd@chromium.org,
	dianders@chromium.org, mka@chromium.org,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	"open list:CPU FREQUENCY DRIVERS" <linux-pm@vger.kernel.org>
Subject: [PATCH v2 4/9] cpufreq: Add a flag to auto-register a cooling device
Date: Mon, 14 Jan 2019 15:51:06 +0530	[thread overview]
Message-ID: <e195496f42375259f1b202eae39d20a56725f4a7.1547458732.git.amit.kucheria@linaro.org> (raw)
In-Reply-To: <cover.1547458732.git.amit.kucheria@linaro.org>
In-Reply-To: <cover.1547458732.git.amit.kucheria@linaro.org>

All cpufreq drivers do similar things to register as a cooling device.
Provide a cpufreq driver flag so drivers can just ask the cpufreq core
to register the cooling device on their behalf. This allows us to get
rid of duplicated code in the drivers.

Suggested-by: Stephen Boyd <swboyd@chromium.org>
Suggested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
---
 drivers/cpufreq/cpufreq.c | 13 +++++++++++++
 include/linux/cpufreq.h   |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 6f23ebb395f1..7faebfc61e60 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -30,6 +30,7 @@
 #include <linux/syscore_ops.h>
 #include <linux/tick.h>
 #include <trace/events/power.h>
+#include <linux/cpu_cooling.h>
 
 static LIST_HEAD(cpufreq_policy_list);
 
@@ -1318,6 +1319,12 @@ static int cpufreq_online(unsigned int cpu)
 	if (cpufreq_driver->ready)
 		cpufreq_driver->ready(policy);
 
+	if (cpufreq_driver->flags & CPUFREQ_AUTO_REGISTER_COOLING_DEV) {
+		struct thermal_cooling_device **cdev = &policy->cooldev;
+
+		*cdev = of_cpufreq_cooling_register(policy);
+	}
+
 	pr_debug("initialization complete\n");
 
 	return 0;
@@ -1411,6 +1418,12 @@ static int cpufreq_offline(unsigned int cpu)
 	if (has_target())
 		cpufreq_exit_governor(policy);
 
+	if (cpufreq_driver->flags & CPUFREQ_AUTO_REGISTER_COOLING_DEV) {
+		struct thermal_cooling_device **cdev = &policy->cooldev;
+
+		cpufreq_cooling_unregister(*cdev);
+	}
+
 	/*
 	 * Perform the ->exit() even during light-weight tear-down,
 	 * since this is a core component, and is essential for the
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 9fbc1d996967..0c51d5ce7350 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -388,6 +388,12 @@ struct cpufreq_driver {
  */
 #define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING (1 << 6)
 
+/*
+ * Set by drivers that want the core to automatically register the cpufreq
+ * driver as a thermal cooling device
+ */
+#define CPUFREQ_AUTO_REGISTER_COOLING_DEV (1 << 7)
+
 int cpufreq_register_driver(struct cpufreq_driver *driver_data);
 int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
 
-- 
2.17.1

WARNING: multiple messages have this Message-ID (diff)
From: Amit Kucheria <amit.kucheria@linaro.org>
To: linux-kernel@vger.kernel.org
Cc: linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org,
	viresh.kumar@linaro.org, edubezval@gmail.com,
	andy.gross@linaro.org, tdas@codeaurora.org, swboyd@chromium.org,
	dianders@chromium.org, mka@chromium.org,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	linux-pm@vger.kernel.org (open list:CPU FREQUENCY DRIVERS)
Subject: [PATCH v2 4/9] cpufreq: Add a flag to auto-register a cooling device
Date: Mon, 14 Jan 2019 15:51:06 +0530	[thread overview]
Message-ID: <e195496f42375259f1b202eae39d20a56725f4a7.1547458732.git.amit.kucheria@linaro.org> (raw)
In-Reply-To: <cover.1547458732.git.amit.kucheria@linaro.org>
In-Reply-To: <cover.1547458732.git.amit.kucheria@linaro.org>

All cpufreq drivers do similar things to register as a cooling device.
Provide a cpufreq driver flag so drivers can just ask the cpufreq core
to register the cooling device on their behalf. This allows us to get
rid of duplicated code in the drivers.

Suggested-by: Stephen Boyd <swboyd@chromium.org>
Suggested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
---
 drivers/cpufreq/cpufreq.c | 13 +++++++++++++
 include/linux/cpufreq.h   |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 6f23ebb395f1..7faebfc61e60 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -30,6 +30,7 @@
 #include <linux/syscore_ops.h>
 #include <linux/tick.h>
 #include <trace/events/power.h>
+#include <linux/cpu_cooling.h>
 
 static LIST_HEAD(cpufreq_policy_list);
 
@@ -1318,6 +1319,12 @@ static int cpufreq_online(unsigned int cpu)
 	if (cpufreq_driver->ready)
 		cpufreq_driver->ready(policy);
 
+	if (cpufreq_driver->flags & CPUFREQ_AUTO_REGISTER_COOLING_DEV) {
+		struct thermal_cooling_device **cdev = &policy->cooldev;
+
+		*cdev = of_cpufreq_cooling_register(policy);
+	}
+
 	pr_debug("initialization complete\n");
 
 	return 0;
@@ -1411,6 +1418,12 @@ static int cpufreq_offline(unsigned int cpu)
 	if (has_target())
 		cpufreq_exit_governor(policy);
 
+	if (cpufreq_driver->flags & CPUFREQ_AUTO_REGISTER_COOLING_DEV) {
+		struct thermal_cooling_device **cdev = &policy->cooldev;
+
+		cpufreq_cooling_unregister(*cdev);
+	}
+
 	/*
 	 * Perform the ->exit() even during light-weight tear-down,
 	 * since this is a core component, and is essential for the
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 9fbc1d996967..0c51d5ce7350 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -388,6 +388,12 @@ struct cpufreq_driver {
  */
 #define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING (1 << 6)
 
+/*
+ * Set by drivers that want the core to automatically register the cpufreq
+ * driver as a thermal cooling device
+ */
+#define CPUFREQ_AUTO_REGISTER_COOLING_DEV (1 << 7)
+
 int cpufreq_register_driver(struct cpufreq_driver *driver_data);
 int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
 
-- 
2.17.1


  parent reply	other threads:[~2019-01-14 10:21 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-14 10:21 [PATCH v2 0/9] Thermal throttling for SDM845 Amit Kucheria
2019-01-14 10:21 ` Amit Kucheria
2019-01-14 10:21 ` [PATCH v2 1/9] [ALREADY QUEUED] cpufreq: qcom-hw: Move to device_initcall Amit Kucheria
2019-01-14 10:21   ` Amit Kucheria
2019-01-17  6:03   ` Viresh Kumar
2019-01-14 10:21 ` [PATCH v2 2/9] drivers: thermal: of-thermal: Print name of device node with error Amit Kucheria
2019-01-14 10:21   ` Amit Kucheria
2019-01-14 23:54   ` Stephen Boyd
2019-01-21  9:39     ` Amit Kucheria
2019-01-14 10:21 ` [PATCH v2 3/9] drivers: cpufreq: Add thermal_cooling_device pointer to struct cpufreq_policy Amit Kucheria
2019-01-14 10:21   ` Amit Kucheria
2019-01-14 23:54   ` Stephen Boyd
2019-01-14 10:21 ` Amit Kucheria [this message]
2019-01-14 10:21   ` [PATCH v2 4/9] cpufreq: Add a flag to auto-register a cooling device Amit Kucheria
2019-01-14 23:57   ` Stephen Boyd
2019-01-21 14:23     ` Amit Kucheria
2019-01-14 10:21 ` [PATCH v2 5/9] cpufreq: Replace open-coded << with BIT() Amit Kucheria
2019-01-14 10:21   ` Amit Kucheria
2019-01-14 10:21 ` [PATCH v2 6/9] cpufreq: qcom-hw: Register as a cpufreq cooling device Amit Kucheria
2019-01-14 10:21   ` Amit Kucheria
2019-01-14 23:58   ` Stephen Boyd
2019-01-14 10:21 ` [PATCH v2 7/9] arm64: dts: sdm845: Increase alert trip point to 95 degrees Amit Kucheria
2019-01-14 10:21   ` Amit Kucheria
2019-01-14 10:21 ` [PATCH v2 8/9] arm64: dts: sdm845: wireup the thermal trip points to cpufreq Amit Kucheria
2019-01-14 10:21   ` Amit Kucheria
2019-01-14 22:01   ` Matthias Kaehlcke
2019-01-14 22:01     ` Matthias Kaehlcke
2019-01-21 18:10     ` Amit Kucheria
2019-01-21 18:10       ` Amit Kucheria
2019-01-22 18:18       ` Matthias Kaehlcke
2019-01-22 18:18         ` Matthias Kaehlcke
2019-01-14 10:21 ` [PATCH v2 9/9] thermal: cpu_cooling: Clarify error message Amit Kucheria
2019-01-14 10:21   ` Amit Kucheria
2019-01-17  5:57   ` Viresh Kumar
2019-01-17 10:34     ` Rafael J. Wysocki
2019-01-21  9:43       ` Amit Kucheria
2019-01-14 10:27 ` [PATCH v2 0/9] Thermal throttling for SDM845 Rafael J. Wysocki
2019-01-14 10:27   ` Rafael J. Wysocki
2019-01-14 10:34   ` Amit Kucheria
2019-01-14 10:34     ` Amit Kucheria
2019-01-14 16:52     ` Amit Kucheria
2019-01-14 16:52       ` Amit Kucheria

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=e195496f42375259f1b202eae39d20a56725f4a7.1547458732.git.amit.kucheria@linaro.org \
    --to=amit.kucheria@linaro.org \
    --cc=andy.gross@linaro.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=dianders@chromium.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=mka@chromium.org \
    --cc=rjw@rjwysocki.net \
    --cc=swboyd@chromium.org \
    --cc=tdas@codeaurora.org \
    --cc=viresh.kumar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.