Lines Matching +full:device +full:- +full:sram

1 // SPDX-License-Identifier: GPL-2.0 or MIT
16 * struct panthor_devfreq - Device frequency management
19 /** @devfreq: devfreq device. */
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()
62 static int panthor_devfreq_target(struct device *dev, unsigned long *freq, in panthor_devfreq_target()
76 ptdev->current_frequency = *freq; in panthor_devfreq_target()
83 pdevfreq->busy_time = 0; in panthor_devfreq_reset()
84 pdevfreq->idle_time = 0; in panthor_devfreq_reset()
85 pdevfreq->time_last_update = ktime_get(); in panthor_devfreq_reset()
88 static int panthor_devfreq_get_dev_status(struct device *dev, in panthor_devfreq_get_dev_status()
92 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_get_dev_status()
95 status->current_frequency = clk_get_rate(ptdev->clks.core); in panthor_devfreq_get_dev_status()
97 spin_lock_irqsave(&pdevfreq->lock, irqflags); in panthor_devfreq_get_dev_status()
101 status->total_time = ktime_to_ns(ktime_add(pdevfreq->busy_time, in panthor_devfreq_get_dev_status()
102 pdevfreq->idle_time)); in panthor_devfreq_get_dev_status()
104 status->busy_time = ktime_to_ns(pdevfreq->busy_time); in panthor_devfreq_get_dev_status()
108 spin_unlock_irqrestore(&pdevfreq->lock, irqflags); in panthor_devfreq_get_dev_status()
110 drm_dbg(&ptdev->base, "busy %lu total %lu %lu %% freq %lu MHz\n", in panthor_devfreq_get_dev_status()
111 status->busy_time, status->total_time, in panthor_devfreq_get_dev_status()
112 status->busy_time / (status->total_time / 100), in panthor_devfreq_get_dev_status()
113 status->current_frequency / 1000 / 1000); in panthor_devfreq_get_dev_status()
127 /* There's actually 2 regulators (mali and sram), but the OPP core only in panthor_devfreq_init()
130 * We assume the sram regulator is coupled with the mali one and let in panthor_devfreq_init()
135 struct device *dev = ptdev->base.dev; in panthor_devfreq_init()
142 pdevfreq = drmm_kzalloc(&ptdev->base, sizeof(*ptdev->devfreq), GFP_KERNEL); in panthor_devfreq_init()
144 return -ENOMEM; in panthor_devfreq_init()
146 ptdev->devfreq = pdevfreq; in panthor_devfreq_init()
150 if (ret != -EPROBE_DEFER) in panthor_devfreq_init()
160 spin_lock_init(&pdevfreq->lock); in panthor_devfreq_init()
164 cur_freq = clk_get_rate(ptdev->clks.core); in panthor_devfreq_init()
169 * We use devm_regulator_get_enable_optional() and keep the sram supply in panthor_devfreq_init()
170 * enabled until the device is removed, just like we do for the mali in panthor_devfreq_init()
175 * - use devm_regulator_get_optional() here in panthor_devfreq_init()
176 * - call dev_pm_opp_set_opp(dev, NULL) before leaving this function in panthor_devfreq_init()
178 * - call dev_pm_opp_set_opp(dev, NULL) and in panthor_devfreq_init()
179 * regulator_disable(ptdev->regulators.sram) in in panthor_devfreq_init()
181 * - call dev_pm_opp_set_opp(dev, default_opp) and in panthor_devfreq_init()
182 * regulator_enable(ptdev->regulators.sram) in in panthor_devfreq_init()
187 * let's just keep regulators enabled for the device lifetime. in panthor_devfreq_init()
189 ret = devm_regulator_get_enable_optional(dev, "sram"); in panthor_devfreq_init()
190 if (ret && ret != -ENODEV) { in panthor_devfreq_init()
191 if (ret != -EPROBE_DEFER) in panthor_devfreq_init()
192 DRM_DEV_ERROR(dev, "Couldn't retrieve/enable sram supply\n"); in panthor_devfreq_init()
201 ptdev->current_frequency = cur_freq; in panthor_devfreq_init()
218 ptdev->fast_rate = freq; in panthor_devfreq_init()
226 pdevfreq->gov_data.upthreshold = 45; in panthor_devfreq_init()
227 pdevfreq->gov_data.downdifferential = 5; in panthor_devfreq_init()
229 pdevfreq->devfreq = devm_devfreq_add_device(dev, &panthor_devfreq_profile, in panthor_devfreq_init()
231 &pdevfreq->gov_data); in panthor_devfreq_init()
232 if (IS_ERR(pdevfreq->devfreq)) { in panthor_devfreq_init()
234 ret = PTR_ERR(pdevfreq->devfreq); in panthor_devfreq_init()
235 pdevfreq->devfreq = NULL; in panthor_devfreq_init()
239 cooling = devfreq_cooling_em_register(pdevfreq->devfreq, NULL); in panthor_devfreq_init()
241 DRM_DEV_INFO(dev, "Failed to register cooling device\n"); in panthor_devfreq_init()
248 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_resume()
250 if (!pdevfreq->devfreq) in panthor_devfreq_resume()
255 drm_WARN_ON(&ptdev->base, devfreq_resume_device(pdevfreq->devfreq)); in panthor_devfreq_resume()
260 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_suspend()
262 if (!pdevfreq->devfreq) in panthor_devfreq_suspend()
265 drm_WARN_ON(&ptdev->base, devfreq_suspend_device(pdevfreq->devfreq)); in panthor_devfreq_suspend()
270 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_record_busy()
273 if (!pdevfreq->devfreq) in panthor_devfreq_record_busy()
276 spin_lock_irqsave(&pdevfreq->lock, irqflags); in panthor_devfreq_record_busy()
279 pdevfreq->last_busy_state = true; in panthor_devfreq_record_busy()
281 spin_unlock_irqrestore(&pdevfreq->lock, irqflags); in panthor_devfreq_record_busy()
286 struct panthor_devfreq *pdevfreq = ptdev->devfreq; in panthor_devfreq_record_idle()
289 if (!pdevfreq->devfreq) in panthor_devfreq_record_idle()
292 spin_lock_irqsave(&pdevfreq->lock, irqflags); in panthor_devfreq_record_idle()
295 pdevfreq->last_busy_state = false; in panthor_devfreq_record_idle()
297 spin_unlock_irqrestore(&pdevfreq->lock, irqflags); in panthor_devfreq_record_idle()