Lines Matching +full:switching +full:- +full:freq

1 // SPDX-License-Identifier: GPL-2.0-only
19 static int msm_devfreq_target(struct device *dev, unsigned long *freq, in msm_devfreq_target() argument
23 struct msm_gpu_devfreq *df = &gpu->devfreq; in msm_devfreq_target()
27 * Note that devfreq_recommended_opp() can modify the freq in msm_devfreq_target()
30 opp = devfreq_recommended_opp(dev, freq, flags); in msm_devfreq_target()
38 * the new target freq (to use when we return to active) in msm_devfreq_target()
40 if (df->idle_freq) { in msm_devfreq_target()
41 df->idle_freq = *freq; in msm_devfreq_target()
46 if (gpu->funcs->gpu_set_freq) { in msm_devfreq_target()
47 mutex_lock(&df->lock); in msm_devfreq_target()
48 gpu->funcs->gpu_set_freq(gpu, opp, df->suspended); in msm_devfreq_target()
49 mutex_unlock(&df->lock); in msm_devfreq_target()
51 dev_pm_opp_set_rate(dev, *freq); in msm_devfreq_target()
61 struct msm_gpu_devfreq *df = &gpu->devfreq; in get_freq()
64 * If the GPU is idle, use the shadow/saved freq to avoid in get_freq()
65 * confusing devfreq (which is unaware that we are switching in get_freq()
66 * to lowest freq until the device is active again) in get_freq()
68 if (df->idle_freq) in get_freq()
69 return df->idle_freq; in get_freq()
71 if (gpu->funcs->gpu_get_freq) in get_freq()
72 return gpu->funcs->gpu_get_freq(gpu); in get_freq()
74 return clk_get_rate(gpu->core_clk); in get_freq()
81 struct msm_gpu_devfreq *df = &gpu->devfreq; in msm_devfreq_get_dev_status()
86 mutex_lock(&df->lock); in msm_devfreq_get_dev_status()
88 status->current_frequency = get_freq(gpu); in msm_devfreq_get_dev_status()
90 status->total_time = ktime_us_delta(time, df->time); in msm_devfreq_get_dev_status()
91 df->time = time; in msm_devfreq_get_dev_status()
93 if (df->suspended) { in msm_devfreq_get_dev_status()
94 mutex_unlock(&df->lock); in msm_devfreq_get_dev_status()
95 status->busy_time = 0; in msm_devfreq_get_dev_status()
99 busy_cycles = gpu->funcs->gpu_busy(gpu, &sample_rate); in msm_devfreq_get_dev_status()
100 busy_time = busy_cycles - df->busy_cycles; in msm_devfreq_get_dev_status()
101 df->busy_cycles = busy_cycles; in msm_devfreq_get_dev_status()
103 mutex_unlock(&df->lock); in msm_devfreq_get_dev_status()
110 status->busy_time = busy_time; in msm_devfreq_get_dev_status()
115 static int msm_devfreq_get_cur_freq(struct device *dev, unsigned long *freq) in msm_devfreq_get_cur_freq() argument
117 *freq = get_freq(dev_to_gpu(dev)); in msm_devfreq_get_cur_freq()
135 struct msm_gpu_devfreq *df = &gpu->devfreq; in has_devfreq()
136 return !!df->devfreq; in has_devfreq()
141 struct msm_gpu_devfreq *df = &gpu->devfreq; in msm_devfreq_init()
142 struct msm_drm_private *priv = gpu->dev->dev_private; in msm_devfreq_init()
145 if (!gpu->funcs->gpu_busy) in msm_devfreq_init()
150 * want to throttle up at 50% load for the double-buffer case, in msm_devfreq_init()
154 priv->gpu_devfreq_config.upthreshold = 50; in msm_devfreq_init()
155 priv->gpu_devfreq_config.downdifferential = 10; in msm_devfreq_init()
157 mutex_init(&df->lock); in msm_devfreq_init()
159 dev_pm_qos_add_request(&gpu->pdev->dev, &df->boost_freq, in msm_devfreq_init()
162 msm_devfreq_profile.initial_freq = gpu->fast_rate; in msm_devfreq_init()
167 * After a deferred probe, these may have be left to non-zero values, in msm_devfreq_init()
173 df->devfreq = devm_devfreq_add_device(&gpu->pdev->dev, in msm_devfreq_init()
175 &priv->gpu_devfreq_config); in msm_devfreq_init()
177 if (IS_ERR(df->devfreq)) { in msm_devfreq_init()
178 DRM_DEV_ERROR(&gpu->pdev->dev, "Couldn't initialize GPU devfreq\n"); in msm_devfreq_init()
179 dev_pm_qos_remove_request(&df->boost_freq); in msm_devfreq_init()
180 df->devfreq = NULL; in msm_devfreq_init()
184 devfreq_suspend_device(df->devfreq); in msm_devfreq_init()
186 gpu->cooling = of_devfreq_cooling_register(gpu->pdev->dev.of_node, df->devfreq); in msm_devfreq_init()
187 if (IS_ERR(gpu->cooling)) { in msm_devfreq_init()
188 DRM_DEV_ERROR(&gpu->pdev->dev, in msm_devfreq_init()
190 gpu->cooling = NULL; in msm_devfreq_init()
193 msm_hrtimer_work_init(&df->boost_work, gpu->worker, msm_devfreq_boost_work, in msm_devfreq_init()
195 msm_hrtimer_work_init(&df->idle_work, gpu->worker, msm_devfreq_idle_work, in msm_devfreq_init()
201 hrtimer_cancel(&df->idle_work.timer); in cancel_idle_work()
202 kthread_cancel_work_sync(&df->idle_work.work); in cancel_idle_work()
207 hrtimer_cancel(&df->boost_work.timer); in cancel_boost_work()
208 kthread_cancel_work_sync(&df->boost_work.work); in cancel_boost_work()
213 struct msm_gpu_devfreq *df = &gpu->devfreq; in msm_devfreq_cleanup()
218 devfreq_cooling_unregister(gpu->cooling); in msm_devfreq_cleanup()
219 dev_pm_qos_remove_request(&df->boost_freq); in msm_devfreq_cleanup()
224 struct msm_gpu_devfreq *df = &gpu->devfreq; in msm_devfreq_resume()
230 mutex_lock(&df->lock); in msm_devfreq_resume()
231 df->busy_cycles = gpu->funcs->gpu_busy(gpu, &sample_rate); in msm_devfreq_resume()
232 df->time = ktime_get(); in msm_devfreq_resume()
233 df->suspended = false; in msm_devfreq_resume()
234 mutex_unlock(&df->lock); in msm_devfreq_resume()
236 devfreq_resume_device(df->devfreq); in msm_devfreq_resume()
241 struct msm_gpu_devfreq *df = &gpu->devfreq; in msm_devfreq_suspend()
246 mutex_lock(&df->lock); in msm_devfreq_suspend()
247 df->suspended = true; in msm_devfreq_suspend()
248 mutex_unlock(&df->lock); in msm_devfreq_suspend()
250 devfreq_suspend_device(df->devfreq); in msm_devfreq_suspend()
261 dev_pm_qos_update_request(&df->boost_freq, 0); in msm_devfreq_boost_work()
266 struct msm_gpu_devfreq *df = &gpu->devfreq; in msm_devfreq_boost()
267 uint64_t freq; in msm_devfreq_boost() local
272 freq = get_freq(gpu); in msm_devfreq_boost()
273 freq *= factor; in msm_devfreq_boost()
279 do_div(freq, HZ_PER_KHZ); in msm_devfreq_boost()
281 dev_pm_qos_update_request(&df->boost_freq, freq); in msm_devfreq_boost()
283 msm_hrtimer_queue_work(&df->boost_work, in msm_devfreq_boost()
290 struct msm_gpu_devfreq *df = &gpu->devfreq; in msm_devfreq_active()
306 mutex_lock(&df->devfreq->lock); in msm_devfreq_active()
308 target_freq = df->idle_freq; in msm_devfreq_active()
310 idle_time = ktime_to_ms(ktime_sub(ktime_get(), df->idle_time)); in msm_devfreq_active()
312 df->idle_freq = 0; in msm_devfreq_active()
316 * chance to run, in which case the df->idle_freq would have in msm_devfreq_active()
317 * still been zero. In this case, no need to change freq. in msm_devfreq_active()
320 msm_devfreq_target(&gpu->pdev->dev, &target_freq, 0); in msm_devfreq_active()
322 mutex_unlock(&df->devfreq->lock); in msm_devfreq_active()
327 * the governor to ramp up the freq.. so give some boost in msm_devfreq_active()
340 struct msm_drm_private *priv = gpu->dev->dev_private; in msm_devfreq_idle_work()
347 mutex_lock(&df->devfreq->lock); in msm_devfreq_idle_work()
351 if (priv->gpu_clamp_to_idle) in msm_devfreq_idle_work()
352 msm_devfreq_target(&gpu->pdev->dev, &target_freq, 0); in msm_devfreq_idle_work()
354 df->idle_time = ktime_get(); in msm_devfreq_idle_work()
355 df->idle_freq = idle_freq; in msm_devfreq_idle_work()
357 mutex_unlock(&df->devfreq->lock); in msm_devfreq_idle_work()
362 struct msm_gpu_devfreq *df = &gpu->devfreq; in msm_devfreq_idle()
367 msm_hrtimer_queue_work(&df->idle_work, ms_to_ktime(1), in msm_devfreq_idle()