Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/panthor: call into devfreq for current frequency

As it stands, panthor keeps a cached current frequency value for when it
wants to retrieve it. This doesn't work well for when things might
switch frequency without panthor's knowledge.

Instead, implement the get_cur_freq operation, and expose it through a
helper function to the rest of panthor.

Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Karunika Choo <karunika.choo@arm.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Link: https://patch.msgid.link/20251017-mt8196-gpufreq-v8-3-98fc1cc566a1@collabora.com
Signed-off-by: Liviu Dudau <liviu.dudau@arm.com>

authored by

Nicolas Frattaroli and committed by
Liviu Dudau
3dd4844b 12c069e0

+31 -8
+26 -4
drivers/gpu/drm/panthor/panthor_devfreq.c
··· 63 63 static int panthor_devfreq_target(struct device *dev, unsigned long *freq, 64 64 u32 flags) 65 65 { 66 - struct panthor_device *ptdev = dev_get_drvdata(dev); 67 66 struct dev_pm_opp *opp; 68 67 int err; 69 68 ··· 72 73 dev_pm_opp_put(opp); 73 74 74 75 err = dev_pm_opp_set_rate(dev, *freq); 75 - if (!err) 76 - ptdev->current_frequency = *freq; 77 76 78 77 return err; 79 78 } ··· 113 116 return 0; 114 117 } 115 118 119 + static int panthor_devfreq_get_cur_freq(struct device *dev, unsigned long *freq) 120 + { 121 + struct panthor_device *ptdev = dev_get_drvdata(dev); 122 + 123 + *freq = clk_get_rate(ptdev->clks.core); 124 + 125 + return 0; 126 + } 127 + 116 128 static struct devfreq_dev_profile panthor_devfreq_profile = { 117 129 .timer = DEVFREQ_TIMER_DELAYED, 118 130 .polling_ms = 50, /* ~3 frames */ 119 131 .target = panthor_devfreq_target, 120 132 .get_dev_status = panthor_devfreq_get_dev_status, 133 + .get_cur_freq = panthor_devfreq_get_cur_freq, 121 134 }; 122 135 123 136 int panthor_devfreq_init(struct panthor_device *ptdev) ··· 205 198 return PTR_ERR(opp); 206 199 207 200 panthor_devfreq_profile.initial_freq = cur_freq; 208 - ptdev->current_frequency = cur_freq; 209 201 210 202 /* 211 203 * Set the recommend OPP this will enable and configure the regulator ··· 301 295 pdevfreq->last_busy_state = false; 302 296 303 297 spin_unlock_irqrestore(&pdevfreq->lock, irqflags); 298 + } 299 + 300 + unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev) 301 + { 302 + struct panthor_devfreq *pdevfreq = ptdev->devfreq; 303 + unsigned long freq = 0; 304 + int ret; 305 + 306 + if (!pdevfreq->devfreq) 307 + return 0; 308 + 309 + ret = pdevfreq->devfreq->profile->get_cur_freq(ptdev->base.dev, &freq); 310 + if (ret) 311 + return 0; 312 + 313 + return freq; 304 314 }
+2
drivers/gpu/drm/panthor/panthor_devfreq.h
··· 18 18 void panthor_devfreq_record_busy(struct panthor_device *ptdev); 19 19 void panthor_devfreq_record_idle(struct panthor_device *ptdev); 20 20 21 + unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev); 22 + 21 23 #endif /* __PANTHOR_DEVFREQ_H__ */
-3
drivers/gpu/drm/panthor/panthor_device.h
··· 214 214 /** @profile_mask: User-set profiling flags for job accounting. */ 215 215 u32 profile_mask; 216 216 217 - /** @current_frequency: Device clock frequency at present. Set by DVFS*/ 218 - unsigned long current_frequency; 219 - 220 217 /** @fast_rate: Maximum device clock frequency. Set by DVFS */ 221 218 unsigned long fast_rate; 222 219
+3 -1
drivers/gpu/drm/panthor/panthor_drv.c
··· 26 26 #include <drm/gpu_scheduler.h> 27 27 #include <drm/panthor_drm.h> 28 28 29 + #include "panthor_devfreq.h" 29 30 #include "panthor_device.h" 30 31 #include "panthor_fw.h" 31 32 #include "panthor_gem.h" ··· 1521 1520 drm_printf(p, "drm-cycles-panthor:\t%llu\n", pfile->stats.cycles); 1522 1521 1523 1522 drm_printf(p, "drm-maxfreq-panthor:\t%lu Hz\n", ptdev->fast_rate); 1524 - drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", ptdev->current_frequency); 1523 + drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", 1524 + panthor_devfreq_get_freq(ptdev)); 1525 1525 } 1526 1526 1527 1527 static void panthor_show_internal_memory_stats(struct drm_printer *p, struct drm_file *file)