diff mbox

[1/4] PM / devfreq: Add function to set max/min frequency

Message ID 1435928310-15938-2-git-send-email-javi.merino@arm.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Javi Merino July 3, 2015, 12:58 p.m. UTC
From: Ørjan Eide <orjan.eide@arm.com>

Factor out the logic to set minimum and maximum frequency for the device
so that it can be used by other parts of the kernel.

Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Ørjan Eide <orjan.eide@arm.com>
---
 drivers/devfreq/devfreq.c | 72 +++++++++++++++++++++++++++++++----------------
 include/linux/devfreq.h   | 13 +++++++++
 2 files changed, 61 insertions(+), 24 deletions(-)

Comments

MyungJoo Ham July 4, 2015, 2:44 a.m. UTC | #1
On Fri, Jul 3, 2015 at 9:58 PM, Javi Merino <javi.merino@arm.com> wrote:
> From: Ørjan Eide <orjan.eide@arm.com>
>
> Factor out the logic to set minimum and maximum frequency for the device
> so that it can be used by other parts of the kernel.
>
> Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
> Cc: Kyungmin Park <kyungmin.park@samsung.com>
> Signed-off-by: Ørjan Eide <orjan.eide@arm.com>

Dear Javi,



Is there reasons to name the function "devfreq_qos_set_[min|max]"? not
"devfreq_set_[min|max]"? The functions may be used by non-PM-qos
components as well (e.g., thermal).


And I like the idea of using devfreq devices as cooling devices. :)


Cheers,
MyungJoo.


ps. I will be on a trip starting hours later for 8 days and then in a
military training for 3 days. Please expect that my responses during
the next 11-12 days will be very slow.
Javi Merino July 6, 2015, 8:47 a.m. UTC | #2
On Sat, Jul 04, 2015 at 03:44:08AM +0100, MyungJoo Ham wrote:
> On Fri, Jul 3, 2015 at 9:58 PM, Javi Merino <javi.merino@arm.com> wrote:
> > From: Ørjan Eide <orjan.eide@arm.com>
> >
> > Factor out the logic to set minimum and maximum frequency for the device
> > so that it can be used by other parts of the kernel.
> >
> > Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
> > Cc: Kyungmin Park <kyungmin.park@samsung.com>
> > Signed-off-by: Ørjan Eide <orjan.eide@arm.com>
> 
> Dear Javi,
> 
> Is there reasons to name the function "devfreq_qos_set_[min|max]"? not
> "devfreq_set_[min|max]"? The functions may be used by non-PM-qos
> components as well (e.g., thermal).

No, there are no reasons for those names.  I'll rename them to
devfreq_set_[min|max]

> And I like the idea of using devfreq devices as cooling devices. :)

Yes, we would like to be able to use them as passive cooling devices,
like what we do with cpufreq for the cpus. 

> ps. I will be on a trip starting hours later for 8 days and then in a
> military training for 3 days. Please expect that my responses during
> the next 11-12 days will be very slow.

No worries.  Thanks,
Javi
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index ca1b362d77e2..6390d5db6816 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -768,6 +768,48 @@  err_out:
 }
 EXPORT_SYMBOL(devfreq_remove_governor);
 
+int devfreq_qos_set_max(struct devfreq *df, unsigned long value)
+{
+	unsigned long min;
+	int ret = 0;
+
+	mutex_lock(&df->lock);
+	min = df->min_freq;
+	if (value && min && value < min) {
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	df->max_freq = value;
+	update_devfreq(df);
+unlock:
+	mutex_unlock(&df->lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(devfreq_qos_set_max);
+
+int devfreq_qos_set_min(struct devfreq *df, unsigned long value)
+{
+	unsigned long max;
+	int ret = 0;
+
+	mutex_lock(&df->lock);
+	max = df->max_freq;
+	if (value && max && value > max) {
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	df->min_freq = value;
+	update_devfreq(df);
+unlock:
+	mutex_unlock(&df->lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(devfreq_qos_set_min);
+
 static ssize_t governor_show(struct device *dev,
 			     struct device_attribute *attr, char *buf)
 {
@@ -899,24 +941,15 @@  static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr,
 	struct devfreq *df = to_devfreq(dev);
 	unsigned long value;
 	int ret;
-	unsigned long max;
 
 	ret = sscanf(buf, "%lu", &value);
 	if (ret != 1)
 		return -EINVAL;
 
-	mutex_lock(&df->lock);
-	max = df->max_freq;
-	if (value && max && value > max) {
-		ret = -EINVAL;
-		goto unlock;
-	}
+	ret = devfreq_qos_set_min(df, value);
+	if (!ret)
+		ret = count;
 
-	df->min_freq = value;
-	update_devfreq(df);
-	ret = count;
-unlock:
-	mutex_unlock(&df->lock);
 	return ret;
 }
 
@@ -932,24 +965,15 @@  static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr,
 	struct devfreq *df = to_devfreq(dev);
 	unsigned long value;
 	int ret;
-	unsigned long min;
 
 	ret = sscanf(buf, "%lu", &value);
 	if (ret != 1)
 		return -EINVAL;
 
-	mutex_lock(&df->lock);
-	min = df->min_freq;
-	if (value && min && value < min) {
-		ret = -EINVAL;
-		goto unlock;
-	}
+	ret = devfreq_qos_set_max(df, value);
+	if (!ret)
+		ret = count;
 
-	df->max_freq = value;
-	update_devfreq(df);
-	ret = count;
-unlock:
-	mutex_unlock(&df->lock);
 	return ret;
 }
 static DEVICE_ATTR_RW(min_freq);
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index ce447f0f1bad..ffbe1f62ec2c 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -204,6 +204,9 @@  extern int devm_devfreq_register_opp_notifier(struct device *dev,
 extern void devm_devfreq_unregister_opp_notifier(struct device *dev,
 						struct devfreq *devfreq);
 
+int devfreq_qos_set_min(struct devfreq *df, unsigned long value);
+int devfreq_qos_set_max(struct devfreq *df, unsigned long value);
+
 #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
 /**
  * struct devfreq_simple_ondemand_data - void *data fed to struct devfreq
@@ -289,6 +292,16 @@  static inline void devm_devfreq_unregister_opp_notifier(struct device *dev,
 							struct devfreq *devfreq)
 {
 }
+
+static inline int devfreq_qos_set_min(struct devfreq *df, unsigned long value)
+{
+	return -EINVAL;
+}
+
+static inline int devfreq_qos_set_max(struct devfreq *df, unsigned long value)
+{
+	return -EINVAL;
+}
 #endif /* CONFIG_PM_DEVFREQ */
 
 #endif /* __LINUX_DEVFREQ_H__ */