Skip to contentSkip to conversation

PM: Devfreq: Add frequency get function in profile

PATCH MyungJoo Ham 2 participants 2 messages Jun 13, 2012

lore
Share & tools
lore
#0 lore raw
Quoted 5 lines

when devfreq set one frequency, the final frequency may not the same as the requested frequency. Add get function in profile to let devfreq driver return the final frequency.

That is why in update_freq() function that you've modified uses:

err = devfreq->profile->target(devfreq->dev.parent, &freq, flags);

not

err = devfreq->profile->target(devfreq->dev.parent, freq, flags);

The target function will return the configured frequency right there. Calling "__devfreq_get()" at the same location wouldn't help as long as the "target()" callback is implemented correctly.

Cheers!
MyungJoo

Quoted 57 lines
---
 drivers/devfreq/devfreq.c |   12 +++++++++++-
 include/linux/devfreq.h   |    2 ++
 2 files changed, 13 insertions(+), 1 deletions(-)
drivers/devfreq/devfreq.c +11 -1
index 2144200..50a4fc0 100644
@@ -72,6 +72,16 @@ static struct devfreq *find_device_devfreq(struct device *dev)
 	return ERR_PTR(-ENODEV);
 }
 
+static unsigned long __devfreq_get(struct device *dev)
+{
+	struct devfreq *devfreq = to_devfreq(dev);
+	unsigned long ret_freq = devfreq->previous_freq;
+	if (!devfreq->profile->get)
+		return ret_freq;
+	ret_freq = devfreq->profile->get(devfreq->dev.parent);
+	return ret_freq;
+}
+
 /**
  * update_devfreq() - Reevaluate the device and configure frequency.
  * @devfreq:	the devfreq instance.
@@ -116,7 +126,7 @@ int update_devfreq(struct devfreq *devfreq)
 	if (err)
 		return err;
 
-	devfreq->previous_freq = freq;
+	devfreq->previous_freq = __devfreq_get(&devfreq->dev);
 	return err;
 }
 
include/linux/devfreq.h +2 -0
index e5e4036..f789314 100644
@@ -65,6 +65,7 @@ struct devfreq_frequency_table {
  * @initial_freq	The operating frequency when devfreq_add_device() is
  *			called.
  * @polling_ms		The polling interval in ms. 0 disables polling.
+ * @get			Get the devices's actual frequency
  * @target		The device should set its operating frequency at
  *			freq or lowest-upper-than-freq value. If freq is
  *			higher than any operable frequency, set maximum.
@@ -84,6 +85,7 @@ struct devfreq_dev_profile {
 	unsigned long initial_freq;
 	unsigned int polling_ms;
 
+	unsigned long	(*get)(struct device *dev);
 	int (*target)(struct device *dev, unsigned long *freq, u32 flags);
 	int (*get_dev_status)(struct device *dev,
 			      struct devfreq_dev_status *stat);
Signature · 1 line
1.7.0.4
#1 lore raw

Ok, I got it. So this patch has no too much use.

Thanks
Xiaoguang

-----Original Message-----
From: MyungJoo Ham [mailto:[email protected]]
Sent: 2012年6月13日 12:58
To: Xiaoguang Chen; [email protected]
Cc: 박경민; [email protected]
Subject: Re: [PATCH 2/2] PM: Devfreq: Add frequency get function in profile

Quoted 5 lines

when devfreq set one frequency, the final frequency may not the same as the requested frequency. Add get function in profile to let devfreq driver return the final frequency.

That is why in update_freq() function that you've modified uses:

err = devfreq->profile->target(devfreq->dev.parent, &freq, flags);

not

err = devfreq->profile->target(devfreq->dev.parent, freq, flags);

The target function will return the configured frequency right there.
Calling "__devfreq_get()" at the same location wouldn't help as long as the "target()" callback is implemented correctly.

Cheers!
MyungJoo

Quoted 56 lines
---
 drivers/devfreq/devfreq.c |   12 +++++++++++-
 include/linux/devfreq.h   |    2 ++
 2 files changed, 13 insertions(+), 1 deletions(-)
drivers/devfreq/devfreq.c +10 -1
index 2144200..50a4fc0 100644
@@ -72,6 +72,16 @@ static struct devfreq *find_device_devfreq(struct device *dev)
 	return ERR_PTR(-ENODEV);
 }
 
+static unsigned long __devfreq_get(struct device *dev) {
+	struct devfreq *devfreq = to_devfreq(dev);
+	unsigned long ret_freq = devfreq->previous_freq;
+	if (!devfreq->profile->get)
+		return ret_freq;
+	ret_freq = devfreq->profile->get(devfreq->dev.parent);
+	return ret_freq;
+}
+
 /**
  * update_devfreq() - Reevaluate the device and configure frequency.
  * @devfreq:	the devfreq instance.
@@ -116,7 +126,7 @@ int update_devfreq(struct devfreq *devfreq)
 	if (err)
 		return err;
 
-	devfreq->previous_freq = freq;
+	devfreq->previous_freq = __devfreq_get(&devfreq->dev);
 	return err;
 }
 
include/linux/devfreq.h index renamed from include/linux/devfreq.h +0 -0

e5e4036..f789314 100644

include/linux/devfreq.h +2 -1
@@ -65,6 +65,7 @@ struct devfreq_frequency_table {
  * @initial_freq	The operating frequency when devfreq_add_device() is
  *			called.
  * @polling_ms		The polling interval in ms. 0 disables polling.
+ * @get			Get the devices's actual frequency
  * @target		The device should set its operating frequency at
  *			freq or lowest-upper-than-freq value. If freq is
  *			higher than any operable frequency, set maximum.
@@ -84,6 +85,7 @@ struct devfreq_dev_profile {
 	unsigned long initial_freq;
 	unsigned int polling_ms;
 
+	unsigned long	(*get)(struct device *dev);
 	int (*target)(struct device *dev, unsigned long *freq, u32 flags);
 	int (*get_dev_status)(struct device *dev,
 			      struct devfreq_dev_status *stat);
--

1.7.0.4