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>

authored by Lukasz Luba and committed by Zhang Rui e34cab4c 39da7c50

+28 -17
+28 -17
drivers/thermal/devfreq_cooling.c
··· 164 return THERMAL_CSTATE_INVALID; 165 } 166 167 - /** 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 { 180 - struct devfreq *df = dfc->devfreq; 181 struct device *dev = df->dev.parent; 182 unsigned long voltage; 183 struct dev_pm_opp *opp; 184 - 185 - if (!dfc->power_ops->get_static_power) 186 - return 0; 187 188 opp = dev_pm_opp_find_freq_exact(dev, freq, true); 189 if (PTR_ERR(opp) == -ERANGE) ··· 187 dev_err_ratelimited(dev, 188 "Failed to get voltage for frequency %lu\n", 189 freq); 190 - return 0; 191 } 192 193 return dfc->power_ops->get_static_power(df, voltage); 194 }
··· 164 return THERMAL_CSTATE_INVALID; 165 } 166 167 + static unsigned long get_voltage(struct devfreq *df, unsigned long freq) 168 { 169 struct device *dev = df->dev.parent; 170 unsigned long voltage; 171 struct dev_pm_opp *opp; 172 173 opp = dev_pm_opp_find_freq_exact(dev, freq, true); 174 if (PTR_ERR(opp) == -ERANGE) ··· 202 dev_err_ratelimited(dev, 203 "Failed to get voltage for frequency %lu\n", 204 freq); 205 } 206 + 207 + return voltage; 208 + } 209 + 210 + /** 211 + * get_static_power() - calculate the static power 212 + * @dfc: Pointer to devfreq cooling device 213 + * @freq: Frequency in Hz 214 + * 215 + * Calculate the static power in milliwatts using the supplied 216 + * get_static_power(). The current voltage is calculated using the 217 + * OPP library. If no get_static_power() was supplied, assume the 218 + * static power is negligible. 219 + */ 220 + static unsigned long 221 + get_static_power(struct devfreq_cooling_device *dfc, unsigned long freq) 222 + { 223 + struct devfreq *df = dfc->devfreq; 224 + unsigned long voltage; 225 + 226 + if (!dfc->power_ops->get_static_power) 227 + return 0; 228 + 229 + voltage = get_voltage(df, freq); 230 + 231 + if (voltage == 0) 232 + return 0; 233 234 return dfc->power_ops->get_static_power(df, voltage); 235 }