• Home
  • Raw
  • Download

Lines Matching +full:clock +full:- +full:frequency

34  * struct clock_cooling_device - data for cooling device with clock
38 * clock frequencies.
41 * @clk_rate_change_nb: reference to notifier block used to receive clock
43 * @freq_table: frequency table used to keep track of available frequencies.
44 * @clock_state: integer value representing the current state of clock
47 * frequency.
48 * @clk: struct clk reference used to enforce clock limits.
70 /* Below code defines functions to be used for clock as cooling device */
79 * clock_cooling_get_property - fetch a property of interest for a give cpu.
80 * @ccdev: clock cooling device reference
83 * @property: type of query (frequency, level, max level)
86 * 1. get maximum clock cooling states
87 * 2. translate frequency to cooling state
88 * 3. translate cooling state to frequency
95 * Return: 0 on success, -EINVAL when invalid parameters are passed.
105 int descend = -1; in clock_cooling_get_property()
106 struct cpufreq_frequency_table *pos, *table = ccdev->freq_table; in clock_cooling_get_property()
109 return -EINVAL; in clock_cooling_get_property()
112 return -EINVAL; in clock_cooling_get_property()
116 if (freq == pos->frequency) in clock_cooling_get_property()
119 /* get the frequency order */ in clock_cooling_get_property()
120 if (freq != CPUFREQ_ENTRY_INVALID && descend == -1) in clock_cooling_get_property()
121 descend = freq > pos->frequency; in clock_cooling_get_property()
123 freq = pos->frequency; in clock_cooling_get_property()
127 /* No valid cpu frequency entry */ in clock_cooling_get_property()
129 return -EINVAL; in clock_cooling_get_property()
132 max_level--; in clock_cooling_get_property()
141 level = descend ? input : (max_level - input); in clock_cooling_get_property()
146 if (freq == pos->frequency) in clock_cooling_get_property()
149 /* now we have a valid frequency entry */ in clock_cooling_get_property()
150 freq = pos->frequency; in clock_cooling_get_property()
153 /* get level by frequency */ in clock_cooling_get_property()
154 *output = descend ? i : (max_level - i); in clock_cooling_get_property()
158 /* get frequency by level */ in clock_cooling_get_property()
165 return -EINVAL; in clock_cooling_get_property()
169 * clock_cooling_get_level - return the cooling level of given clock cooling.
170 * @cdev: reference of a thermal cooling device of used as clock cooling device
171 * @freq: the frequency of interest
182 struct clock_cooling_device *ccdev = cdev->devdata; in clock_cooling_get_level()
194 * clock_cooling_get_frequency - get the absolute value of frequency from level.
195 * @ccdev: clock cooling device reference
198 * This function matches cooling level with frequency. Based on a cooling level
199 * of frequency, equals cooling state of cpu cooling device, it will return
200 * the corresponding frequency.
201 * e.g level=0 --> 1st MAX FREQ, level=1 ---> 2nd MAX FREQ, .... etc
203 * Return: 0 on error, the corresponding frequency otherwise.
220 * clock_cooling_apply - function to apply frequency clipping.
221 * @ccdev: clock_cooling_device pointer containing frequency clipping data.
224 * Function used to make sure the clock layer is aware of current thermal
225 * limits. The limits are applied by updating the clock rate in case it is
226 * higher than the corresponding frequency based on the requested cooling_state.
228 * Return: 0 on success, an error code otherwise (-EINVAL in case wrong
239 if (ccdev->clock_state == cooling_state) in clock_cooling_apply()
244 return -EINVAL; in clock_cooling_apply()
246 cur_freq = clk_get_rate(ccdev->clk); in clock_cooling_apply()
248 mutex_lock(&ccdev->lock); in clock_cooling_apply()
249 ccdev->clock_state = cooling_state; in clock_cooling_apply()
250 ccdev->clock_val = clip_freq; in clock_cooling_apply()
251 /* enforce clock level */ in clock_cooling_apply()
253 ret = clk_set_rate(ccdev->clk, clip_freq); in clock_cooling_apply()
254 mutex_unlock(&ccdev->lock); in clock_cooling_apply()
260 * clock_cooling_clock_notifier - notifier callback on clock rate changes.
262 * @event: value showing clock event for which this function invoked.
263 * @data: callback-specific data
265 * Callback to hijack the notification on clock transition.
266 * Every time there is a clock change, we intercept all pre change events
283 * layer is also hijacking clock pre notifications. in clock_cooling_clock_notifier()
285 if (ndata->new_rate > ccdev->clock_val) in clock_cooling_clock_notifier()
295 /* clock cooling device thermal callback functions are defined below */
298 * clock_cooling_get_max_state - callback function to get the max cooling state.
302 * Callback for the thermal cooling device to return the clock
310 struct clock_cooling_device *ccdev = cdev->devdata; in clock_cooling_get_max_state()
322 * clock_cooling_get_cur_state - function to get the current cooling state.
326 * Callback for the thermal cooling device to return the clock
334 struct clock_cooling_device *ccdev = cdev->devdata; in clock_cooling_get_cur_state()
336 *state = ccdev->clock_state; in clock_cooling_get_cur_state()
342 * clock_cooling_set_cur_state - function to set the current cooling state.
346 * Callback for the thermal cooling device to change the clock cooling
354 struct clock_cooling_device *clock_device = cdev->devdata; in clock_cooling_set_cur_state()
359 /* Bind clock callbacks to thermal cooling device ops */
367 * clock_cooling_register - function to create clock cooling device.
368 * @dev: struct device pointer to the device used as clock cooling device.
369 * @clock_name: string containing the clock used as cooling mechanism.
371 * This interface function registers the clock cooling device with the name
372 * "thermal-clock-%x". The cooling device is based on clock frequencies.
375 * the referred device. The ordered frequency table is used to control
376 * the clock cooling device cooling states and to limit clock transitions
392 return ERR_PTR(-ENOMEM); in clock_cooling_register()
394 mutex_init(&ccdev->lock); in clock_cooling_register()
395 ccdev->dev = dev; in clock_cooling_register()
396 ccdev->clk = devm_clk_get(dev, clock_name); in clock_cooling_register()
397 if (IS_ERR(ccdev->clk)) in clock_cooling_register()
398 return ERR_CAST(ccdev->clk); in clock_cooling_register()
403 ccdev->id = ret; in clock_cooling_register()
405 snprintf(dev_name, sizeof(dev_name), "thermal-clock-%d", ccdev->id); in clock_cooling_register()
410 ida_simple_remove(&clock_ida, ccdev->id); in clock_cooling_register()
411 return ERR_PTR(-EINVAL); in clock_cooling_register()
413 ccdev->cdev = cdev; in clock_cooling_register()
414 ccdev->clk_rate_change_nb.notifier_call = clock_cooling_clock_notifier; in clock_cooling_register()
417 ret = dev_pm_opp_init_cpufreq_table(dev, &ccdev->freq_table); in clock_cooling_register()
419 ida_simple_remove(&clock_ida, ccdev->id); in clock_cooling_register()
422 ccdev->clock_state = 0; in clock_cooling_register()
423 ccdev->clock_val = clock_cooling_get_frequency(ccdev, 0); in clock_cooling_register()
425 clk_notifier_register(ccdev->clk, &ccdev->clk_rate_change_nb); in clock_cooling_register()
432 * clock_cooling_unregister - function to remove clock cooling device.
435 * This interface function unregisters the "thermal-clock-%x" cooling device.
444 ccdev = cdev->devdata; in clock_cooling_unregister()
446 clk_notifier_unregister(ccdev->clk, &ccdev->clk_rate_change_nb); in clock_cooling_unregister()
447 dev_pm_opp_free_cpufreq_table(ccdev->dev, &ccdev->freq_table); in clock_cooling_unregister()
449 thermal_cooling_device_unregister(ccdev->cdev); in clock_cooling_unregister()
450 ida_simple_remove(&clock_ida, ccdev->id); in clock_cooling_unregister()