diff mbox

[2/3,RFC] devfreq: Add suspend and resume apis

Message ID 1345227645-20703-3-git-send-email-rajagopal.venkat@linaro.org
State New
Headers show

Commit Message

rajagopal.venkat@linaro.org Aug. 17, 2012, 6:20 p.m. UTC
This patch adds suspend and resume apis needed
for devices which can idle. Suspend/resume apis
are called from driver to suspend/resume devfreq
load monitoring of that device.

Signed-off-by: Rajagopal Venkat <rajagopal.venkat@linaro.org>
---
 drivers/devfreq/devfreq.c                 | 30 ++++++++++++++++++++++++++++++
 drivers/devfreq/governor_simpleondemand.c | 15 +++++++++++++++
 include/linux/devfreq.h                   | 16 ++++++++++++++++
 3 files changed, 61 insertions(+)
diff mbox

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 5aa23a8..375b5aa1 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -233,6 +233,36 @@  int devfreq_remove_device(struct devfreq *devfreq)
 }
 EXPORT_SYMBOL(devfreq_remove_device);
 
+/**
+ * devfreq_suspend_device() - Suspend devfreq of a device.
+ * @devfreq	the devfreq instance to be suspended
+ */
+int devfreq_suspend_device(struct devfreq *devfreq)
+{
+	if (!devfreq)
+		return -EINVAL;
+
+	devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_SUSPEND);
+
+	return 0;
+}
+EXPORT_SYMBOL(devfreq_suspend_device);
+
+/**
+ * devfreq_resume_device() - Resume devfreq of a device.
+ * @devfreq	the devfreq instance to be resumed
+ */
+int devfreq_resume_device(struct devfreq *devfreq)
+{
+	if (!devfreq)
+		return -EINVAL;
+
+	devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_RESUME);
+
+	return 0;
+}
+EXPORT_SYMBOL(devfreq_resume_device);
+
 static ssize_t show_governor(struct device *dev,
 			     struct device_attribute *attr, char *buf)
 {
diff --git a/drivers/devfreq/governor_simpleondemand.c b/drivers/devfreq/governor_simpleondemand.c
index 7c70c30..95e4db9 100644
--- a/drivers/devfreq/governor_simpleondemand.c
+++ b/drivers/devfreq/governor_simpleondemand.c
@@ -221,6 +221,21 @@  static int devfreq_simple_ondemand_func(struct devfreq *df,
 		ondemand_exit(df);
 		break;
 
+	case DEVFREQ_GOV_SUSPEND:
+		if (delayed_work_pending(&data->work)) {
+			data->stop_queuing = true;
+			cancel_delayed_work_sync(&data->work);
+		}
+		break;
+
+	case DEVFREQ_GOV_RESUME:
+		if (!delayed_work_pending(&data->work)) {
+			data->stop_queuing = false;
+			queue_delayed_work(devfreq_wq, &data->work,
+				msecs_to_jiffies(df->profile->polling_ms));
+		}
+		break;
+
 	case DEVFREQ_GOV_LIMITS:
 		if (delayed_work_pending(&data->work)) {
 			mutex_lock(&df->lock);
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index 600cc2e..7c6517f 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -56,6 +56,8 @@  struct devfreq_dev_status {
 #define DEVFREQ_GOV_START			0x1
 #define DEVFREQ_GOV_STOP			0x2
 #define DEVFREQ_GOV_LIMITS			0x3
+#define DEVFREQ_GOV_SUSPEND			0x4
+#define DEVFREQ_GOV_RESUME			0x5
 
 /**
  * struct devfreq_dev_profile - Devfreq's user device profile
@@ -155,6 +157,10 @@  extern struct devfreq *devfreq_add_device(struct device *dev,
 				  void *data);
 extern int devfreq_remove_device(struct devfreq *devfreq);
 
+extern int devfreq_suspend_device(struct devfreq *devfreq);
+
+extern int devfreq_resume_device(struct devfreq *devfreq);
+
 /* Helper functions for devfreq user device driver with OPP. */
 extern struct opp *devfreq_recommended_opp(struct device *dev,
 					   unsigned long *freq, u32 flags);
@@ -207,6 +213,16 @@  static int devfreq_remove_device(struct devfreq *devfreq)
 	return 0;
 }
 
+static int devfreq_suspend_device(struct devfreq *devfreq)
+{
+	return 0;
+}
+
+extern int devfreq_resume_device(struct devfreq *devfreq)
+{
+	return 0;
+}
+
 static struct opp *devfreq_recommended_opp(struct device *dev,
 					   unsigned long *freq, u32 flags)
 {