From: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
To: linux-samsung-soc@vger.kernel.org
Cc: linux-pm@vger.kernel.org, m.reichl@fivetechno.de,
myungjoo.ham@gmail.com, cw00.choi@samsung.com,
Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
Subject: [RFC 1/4] PM / devfreq: Add DevFreq subsystem suspend/resume
Date: Wed, 23 Nov 2016 14:51:24 +0100 [thread overview]
Message-ID: <1479909087-22659-2-git-send-email-tjakobi@math.uni-bielefeld.de> (raw)
In-Reply-To: <1479909087-22659-1-git-send-email-tjakobi@math.uni-bielefeld.de>
This suspend/resume operations works analogous to the
cpufreq_{suspend,resume}() calls in the CPUFreq subsystem.
Signed-off-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
---
drivers/devfreq/devfreq.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/devfreq.h | 10 +++++++
2 files changed, 85 insertions(+)
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index bf3ea76..2f1aa83 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -785,6 +785,81 @@ int devfreq_resume_device(struct devfreq *devfreq)
EXPORT_SYMBOL(devfreq_resume_device);
/**
+ * devfreq_suspend() - Suspend DevFreq governors
+ *
+ * Called during system wide Suspend/Hibernate cycles for suspending governors
+ * in the same fashion as cpufreq_suspend().
+ */
+void devfreq_suspend(void)
+{
+ struct devfreq *devfreq;
+ unsigned long freq;
+ int ret;
+
+ mutex_lock(&devfreq_list_lock);
+
+ list_for_each_entry(devfreq, &devfreq_list, node) {
+ if (!devfreq->suspend_freq)
+ continue;
+
+ ret = devfreq_suspend_device(devfreq);
+ if (ret < 0) {
+ dev_warn(&devfreq->dev, "%s: governor suspend failed\n", __func__);
+ continue;
+ }
+
+ devfreq->resume_freq = 0;
+ if (devfreq->profile->get_cur_freq) {
+ ret = devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq);
+ if (ret >= 0)
+ devfreq->resume_freq = freq;
+ }
+
+ freq = devfreq->suspend_freq;
+ ret = devfreq->profile->target(devfreq->dev.parent, &freq, 0);
+
+ if (ret < 0)
+ dev_warn(&devfreq->dev, "%s: setting suspend frequency failed\n", __func__);
+ }
+
+ mutex_unlock(&devfreq_list_lock);
+}
+
+/**
+ * devfreq_resume() - Resume DevFreq governors
+ *
+ * Called during system wide Suspend/Hibernate cycle for resuming governors that
+ * are suspended with devfreq_suspend().
+ */
+void devfreq_resume(void)
+{
+ struct devfreq *devfreq;
+ unsigned long freq;
+ int ret;
+
+ mutex_lock(&devfreq_list_lock);
+
+ list_for_each_entry(devfreq, &devfreq_list, node) {
+ if (!devfreq->suspend_freq)
+ continue;
+
+ freq = devfreq->resume_freq;
+ ret = devfreq->profile->target(devfreq->dev.parent, &freq, 0);
+
+ if (ret < 0) {
+ dev_warn(&devfreq->dev, "%s: setting resume frequency failed\n", __func__);
+ continue;
+ }
+
+ ret = devfreq_resume_device(devfreq);
+ if (ret < 0)
+ dev_warn(&devfreq->dev, "%s: governor resume failed\n", __func__);
+ }
+
+ mutex_unlock(&devfreq_list_lock);
+}
+
+/**
* devfreq_add_governor() - Add devfreq governor
* @governor: the devfreq governor to be added
*/
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index 2de4e2e..555d024 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -171,6 +171,9 @@ struct devfreq {
struct notifier_block nb;
struct delayed_work work;
+ unsigned long suspend_freq; /* freq during devfreq suspend */
+ unsigned long resume_freq; /* freq restored after suspend cycle */
+
unsigned long previous_freq;
struct devfreq_dev_status last_status;
@@ -211,6 +214,10 @@ extern void devm_devfreq_remove_device(struct device *dev,
extern int devfreq_suspend_device(struct devfreq *devfreq);
extern int devfreq_resume_device(struct devfreq *devfreq);
+/* Suspend/resume the entire Devfreq subsystem. */
+void devfreq_suspend(void);
+void devfreq_resume(void);
+
/* Helper functions for devfreq user device driver with OPP. */
extern struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
unsigned long *freq, u32 flags);
@@ -410,6 +417,9 @@ static inline int devfreq_update_stats(struct devfreq *df)
{
return -EINVAL;
}
+
+static inline void devfreq_suspend(void) {}
+static inline void devfreq_resume(void) {}
#endif /* CONFIG_PM_DEVFREQ */
#endif /* __LINUX_DEVFREQ_H__ */
--
2.7.3
next prev parent reply other threads:[~2016-11-23 13:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-23 13:51 [RFC 0/4] PM / devfreq: draft for OPP suspend impl Tobias Jakobi
2016-11-23 13:51 ` Tobias Jakobi [this message]
2016-11-24 1:34 ` [RFC 1/4] PM / devfreq: Add DevFreq subsystem suspend/resume Chanwoo Choi
2016-11-24 8:20 ` Chanwoo Choi
2016-11-24 14:20 ` Tobias Jakobi
2016-11-23 13:51 ` [RFC 2/4] PM / devfreq: suspend subsystem on system suspend/hibernate Tobias Jakobi
2016-11-24 1:35 ` Chanwoo Choi
2016-11-23 13:51 ` [RFC 3/4] PM / devfreq: exynos-bus: add support for suspend OPP Tobias Jakobi
2016-11-24 1:38 ` Chanwoo Choi
2016-11-24 14:22 ` Tobias Jakobi
2016-11-23 13:51 ` [RFC 4/4] ARM: dts: exynos4x12: add suspend OPP for DMC and leftbus Tobias Jakobi
2016-11-24 1:41 ` Chanwoo Choi
2016-11-24 14:27 ` Tobias Jakobi
2016-11-24 23:44 ` Chanwoo Choi
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=1479909087-22659-2-git-send-email-tjakobi@math.uni-bielefeld.de \
--to=tjakobi@math.uni-bielefeld.de \
--cc=cw00.choi@samsung.com \
--cc=linux-pm@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=m.reichl@fivetechno.de \
--cc=myungjoo.ham@gmail.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).