Lines Matching +full:opp +full:- +full:suspend

1 // SPDX-License-Identifier: GPL-2.0 or MIT
16 * struct panthor_devfreq - Device frequency management
52 last = pdevfreq->time_last_update; in panthor_devfreq_update_utilization()
54 if (pdevfreq->last_busy_state) in panthor_devfreq_update_utilization()
55 pdevfreq->busy_time += ktime_sub(now, last); in panthor_devfreq_update_utilization()
57 pdevfreq->idle_time += ktime_sub(now, last); in panthor_devfreq_update_utilization()
59 pdevfreq->time_last_update = now; in panthor_devfreq_update_utilization()
65 struct dev_pm_opp *opp; in panthor_devfreq_target() local
67 opp = devfreq_recommended_opp(dev, freq, flags); in panthor_devfreq_target()
68 if (IS_ERR(opp)) in panthor_devfreq_target()
69 return PTR_ERR(opp); in panthor_devfreq_target()
70 dev_pm_opp_put(opp); in panthor_devfreq_target()
77 pdevfreq->busy_time = 0; in panthor_devfreq_reset()
78 pdevfreq->idle_time = 0; in panthor_devfreq_reset()
79 pdevfreq->time_last_update = ktime_get(); in panthor_devfreq_reset()
86 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_get_dev_status()
89 status->current_frequency = clk_get_rate(ptdev->clks.core); in panthor_devfreq_get_dev_status()
91 spin_lock_irqsave(&pdevfreq->lock, irqflags); in panthor_devfreq_get_dev_status()
95 status->total_time = ktime_to_ns(ktime_add(pdevfreq->busy_time, in panthor_devfreq_get_dev_status()
96 pdevfreq->idle_time)); in panthor_devfreq_get_dev_status()
98 status->busy_time = ktime_to_ns(pdevfreq->busy_time); in panthor_devfreq_get_dev_status()
102 spin_unlock_irqrestore(&pdevfreq->lock, irqflags); in panthor_devfreq_get_dev_status()
104 drm_dbg(&ptdev->base, "busy %lu total %lu %lu %% freq %lu MHz\n", in panthor_devfreq_get_dev_status()
105 status->busy_time, status->total_time, in panthor_devfreq_get_dev_status()
106 status->busy_time / (status->total_time / 100), in panthor_devfreq_get_dev_status()
107 status->current_frequency / 1000 / 1000); in panthor_devfreq_get_dev_status()
121 /* There's actually 2 regulators (mali and sram), but the OPP core only in panthor_devfreq_init()
129 struct device *dev = ptdev->base.dev; in panthor_devfreq_init()
131 struct dev_pm_opp *opp; in panthor_devfreq_init() local
135 pdevfreq = drmm_kzalloc(&ptdev->base, sizeof(*ptdev->devfreq), GFP_KERNEL); in panthor_devfreq_init()
137 return -ENOMEM; in panthor_devfreq_init()
139 ptdev->devfreq = pdevfreq; in panthor_devfreq_init()
143 if (ret != -EPROBE_DEFER) in panthor_devfreq_init()
144 DRM_DEV_ERROR(dev, "Couldn't set OPP regulators\n"); in panthor_devfreq_init()
153 spin_lock_init(&pdevfreq->lock); in panthor_devfreq_init()
157 cur_freq = clk_get_rate(ptdev->clks.core); in panthor_devfreq_init()
159 opp = devfreq_recommended_opp(dev, &cur_freq, 0); in panthor_devfreq_init()
160 if (IS_ERR(opp)) in panthor_devfreq_init()
161 return PTR_ERR(opp); in panthor_devfreq_init()
170 * supply, which is enabled when dev_pm_opp_set_opp(dev, opp) is called, in panthor_devfreq_init()
173 * If we really care about disabling regulators on suspend, we should: in panthor_devfreq_init()
174 * - use devm_regulator_get_optional() here in panthor_devfreq_init()
175 * - call dev_pm_opp_set_opp(dev, NULL) before leaving this function in panthor_devfreq_init()
176 * (this disables the regulator passed to the OPP layer) in panthor_devfreq_init()
177 * - call dev_pm_opp_set_opp(dev, NULL) and in panthor_devfreq_init()
178 * regulator_disable(ptdev->regulators.sram) in in panthor_devfreq_init()
180 * - call dev_pm_opp_set_opp(dev, default_opp) and in panthor_devfreq_init()
181 * regulator_enable(ptdev->regulators.sram) in in panthor_devfreq_init()
185 * consumption), or how much it slows down the suspend/resume steps, in panthor_devfreq_init()
189 if (ret && ret != -ENODEV) { in panthor_devfreq_init()
190 if (ret != -EPROBE_DEFER) in panthor_devfreq_init()
196 * Set the recommend OPP this will enable and configure the regulator in panthor_devfreq_init()
199 ret = dev_pm_opp_set_opp(dev, opp); in panthor_devfreq_init()
201 DRM_DEV_ERROR(dev, "Couldn't set recommended OPP\n"); in panthor_devfreq_init()
205 dev_pm_opp_put(opp); in panthor_devfreq_init()
211 pdevfreq->gov_data.upthreshold = 45; in panthor_devfreq_init()
212 pdevfreq->gov_data.downdifferential = 5; in panthor_devfreq_init()
214 pdevfreq->devfreq = devm_devfreq_add_device(dev, &panthor_devfreq_profile, in panthor_devfreq_init()
216 &pdevfreq->gov_data); in panthor_devfreq_init()
217 if (IS_ERR(pdevfreq->devfreq)) { in panthor_devfreq_init()
219 ret = PTR_ERR(pdevfreq->devfreq); in panthor_devfreq_init()
220 pdevfreq->devfreq = NULL; in panthor_devfreq_init()
224 cooling = devfreq_cooling_em_register(pdevfreq->devfreq, NULL); in panthor_devfreq_init()
233 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_resume()
235 if (!pdevfreq->devfreq) in panthor_devfreq_resume()
240 return devfreq_resume_device(pdevfreq->devfreq); in panthor_devfreq_resume()
245 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_suspend()
247 if (!pdevfreq->devfreq) in panthor_devfreq_suspend()
250 return devfreq_suspend_device(pdevfreq->devfreq); in panthor_devfreq_suspend()
255 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_record_busy()
258 if (!pdevfreq->devfreq) in panthor_devfreq_record_busy()
261 spin_lock_irqsave(&pdevfreq->lock, irqflags); in panthor_devfreq_record_busy()
264 pdevfreq->last_busy_state = true; in panthor_devfreq_record_busy()
266 spin_unlock_irqrestore(&pdevfreq->lock, irqflags); in panthor_devfreq_record_busy()
271 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_record_idle()
274 if (!pdevfreq->devfreq) in panthor_devfreq_record_idle()
277 spin_lock_irqsave(&pdevfreq->lock, irqflags); in panthor_devfreq_record_idle()
280 pdevfreq->last_busy_state = false; in panthor_devfreq_record_idle()
282 spin_unlock_irqrestore(&pdevfreq->lock, irqflags); in panthor_devfreq_record_idle()