diff options
author | Lukasz Luba <lukasz.luba@arm.com> | 2017-05-04 07:34:31 -0400 |
---|---|---|
committer | Zhang Rui <rui.zhang@intel.com> | 2017-05-05 03:54:45 -0400 |
commit | e34cab4cd1f98b4daed5bc98fe727e63f8dbf4e4 (patch) | |
tree | 0150fecad849ea961220d7002dedae0bbc672cb4 | |
parent | 39da7c509acff13fc8cb12ec1bb20337c988ed36 (diff) |
thermal: devfreq_cooling: refactor code and add get_voltage function
Move the code which gets the voltage for a given frequency.
This code will be resused in few places.
Acked-by: Javi Merino <javi.merino@kernel.org>
Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
-rw-r--r-- | drivers/thermal/devfreq_cooling.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 4bf4ad58cffd..af9d32837a3a 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c | |||
@@ -164,27 +164,12 @@ freq_get_state(struct devfreq_cooling_device *dfc, unsigned long freq) | |||
164 | return THERMAL_CSTATE_INVALID; | 164 | return THERMAL_CSTATE_INVALID; |
165 | } | 165 | } |
166 | 166 | ||
167 | /** | 167 | static unsigned long get_voltage(struct devfreq *df, unsigned long freq) |
168 | * get_static_power() - calculate the static power | ||
169 | * @dfc: Pointer to devfreq cooling device | ||
170 | * @freq: Frequency in Hz | ||
171 | * | ||
172 | * Calculate the static power in milliwatts using the supplied | ||
173 | * get_static_power(). The current voltage is calculated using the | ||
174 | * OPP library. If no get_static_power() was supplied, assume the | ||
175 | * static power is negligible. | ||
176 | */ | ||
177 | static unsigned long | ||
178 | get_static_power(struct devfreq_cooling_device *dfc, unsigned long freq) | ||
179 | { | 168 | { |
180 | struct devfreq *df = dfc->devfreq; | ||
181 | struct device *dev = df->dev.parent; | 169 | struct device *dev = df->dev.parent; |
182 | unsigned long voltage; | 170 | unsigned long voltage; |
183 | struct dev_pm_opp *opp; | 171 | struct dev_pm_opp *opp; |
184 | 172 | ||
185 | if (!dfc->power_ops->get_static_power) | ||
186 | return 0; | ||
187 | |||
188 | opp = dev_pm_opp_find_freq_exact(dev, freq, true); | 173 | opp = dev_pm_opp_find_freq_exact(dev, freq, true); |
189 | if (PTR_ERR(opp) == -ERANGE) | 174 | if (PTR_ERR(opp) == -ERANGE) |
190 | opp = dev_pm_opp_find_freq_exact(dev, freq, false); | 175 | opp = dev_pm_opp_find_freq_exact(dev, freq, false); |
@@ -202,9 +187,35 @@ get_static_power(struct devfreq_cooling_device *dfc, unsigned long freq) | |||
202 | dev_err_ratelimited(dev, | 187 | dev_err_ratelimited(dev, |
203 | "Failed to get voltage for frequency %lu\n", | 188 | "Failed to get voltage for frequency %lu\n", |
204 | freq); | 189 | freq); |
205 | return 0; | ||
206 | } | 190 | } |
207 | 191 | ||
192 | return voltage; | ||
193 | } | ||
194 | |||
195 | /** | ||
196 | * get_static_power() - calculate the static power | ||
197 | * @dfc: Pointer to devfreq cooling device | ||
198 | * @freq: Frequency in Hz | ||
199 | * | ||
200 | * Calculate the static power in milliwatts using the supplied | ||
201 | * get_static_power(). The current voltage is calculated using the | ||
202 | * OPP library. If no get_static_power() was supplied, assume the | ||
203 | * static power is negligible. | ||
204 | */ | ||
205 | static unsigned long | ||
206 | get_static_power(struct devfreq_cooling_device *dfc, unsigned long freq) | ||
207 | { | ||
208 | struct devfreq *df = dfc->devfreq; | ||
209 | unsigned long voltage; | ||
210 | |||
211 | if (!dfc->power_ops->get_static_power) | ||
212 | return 0; | ||
213 | |||
214 | voltage = get_voltage(df, freq); | ||
215 | |||
216 | if (voltage == 0) | ||
217 | return 0; | ||
218 | |||
208 | return dfc->power_ops->get_static_power(df, voltage); | 219 | return dfc->power_ops->get_static_power(df, voltage); |
209 | } | 220 | } |
210 | 221 | ||