]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/panthor: call into devfreq for current frequency
authorNicolas Frattaroli <nicolas.frattaroli@collabora.com>
Fri, 17 Oct 2025 15:31:10 +0000 (17:31 +0200)
committerLiviu Dudau <liviu.dudau@arm.com>
Mon, 3 Nov 2025 15:27:25 +0000 (15:27 +0000)
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>
drivers/gpu/drm/panthor/panthor_devfreq.c
drivers/gpu/drm/panthor/panthor_devfreq.h
drivers/gpu/drm/panthor/panthor_device.h
drivers/gpu/drm/panthor/panthor_drv.c

index 7d1425a843826351c35ac042646cdd19a9adfbec..d4a92f9b84ae9ad6b5ae88b73cab5b1ac669c437 100644 (file)
@@ -63,7 +63,6 @@ static void panthor_devfreq_update_utilization(struct panthor_devfreq *pdevfreq)
 static int panthor_devfreq_target(struct device *dev, unsigned long *freq,
                                  u32 flags)
 {
-       struct panthor_device *ptdev = dev_get_drvdata(dev);
        struct dev_pm_opp *opp;
        int err;
 
@@ -73,8 +72,6 @@ static int panthor_devfreq_target(struct device *dev, unsigned long *freq,
        dev_pm_opp_put(opp);
 
        err = dev_pm_opp_set_rate(dev, *freq);
-       if (!err)
-               ptdev->current_frequency = *freq;
 
        return err;
 }
@@ -116,11 +113,21 @@ static int panthor_devfreq_get_dev_status(struct device *dev,
        return 0;
 }
 
+static int panthor_devfreq_get_cur_freq(struct device *dev, unsigned long *freq)
+{
+       struct panthor_device *ptdev = dev_get_drvdata(dev);
+
+       *freq = clk_get_rate(ptdev->clks.core);
+
+       return 0;
+}
+
 static struct devfreq_dev_profile panthor_devfreq_profile = {
        .timer = DEVFREQ_TIMER_DELAYED,
        .polling_ms = 50, /* ~3 frames */
        .target = panthor_devfreq_target,
        .get_dev_status = panthor_devfreq_get_dev_status,
+       .get_cur_freq = panthor_devfreq_get_cur_freq,
 };
 
 int panthor_devfreq_init(struct panthor_device *ptdev)
@@ -198,7 +205,6 @@ int panthor_devfreq_init(struct panthor_device *ptdev)
                return PTR_ERR(opp);
 
        panthor_devfreq_profile.initial_freq = cur_freq;
-       ptdev->current_frequency = cur_freq;
 
        /*
         * Set the recommend OPP this will enable and configure the regulator
@@ -296,3 +302,19 @@ void panthor_devfreq_record_idle(struct panthor_device *ptdev)
 
        spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
 }
+
+unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev)
+{
+       struct panthor_devfreq *pdevfreq = ptdev->devfreq;
+       unsigned long freq = 0;
+       int ret;
+
+       if (!pdevfreq->devfreq)
+               return 0;
+
+       ret = pdevfreq->devfreq->profile->get_cur_freq(ptdev->base.dev, &freq);
+       if (ret)
+               return 0;
+
+       return freq;
+}
index b7631de695f7d79456478c87e8af5dc47673cd1d..f8e29e02f66cb3281ed4bb4c75cda9bd4df82b92 100644 (file)
@@ -18,4 +18,6 @@ void panthor_devfreq_suspend(struct panthor_device *ptdev);
 void panthor_devfreq_record_busy(struct panthor_device *ptdev);
 void panthor_devfreq_record_idle(struct panthor_device *ptdev);
 
+unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev);
+
 #endif /* __PANTHOR_DEVFREQ_H__ */
index 9f0649ecfc4fc697a21a8b2fc4dd89c8ecf298df..f32c1868bf6d782d99df9dbd0babcea049c917e0 100644 (file)
@@ -214,9 +214,6 @@ struct panthor_device {
        /** @profile_mask: User-set profiling flags for job accounting. */
        u32 profile_mask;
 
-       /** @current_frequency: Device clock frequency at present. Set by DVFS*/
-       unsigned long current_frequency;
-
        /** @fast_rate: Maximum device clock frequency. Set by DVFS */
        unsigned long fast_rate;
 
index a1cd31c2ca092a276dc7a379d7bd9139546b51f5..d1d4c50da5bf6ab73a3602ea99380d0d0e951163 100644 (file)
@@ -26,6 +26,7 @@
 #include <drm/gpu_scheduler.h>
 #include <drm/panthor_drm.h>
 
+#include "panthor_devfreq.h"
 #include "panthor_device.h"
 #include "panthor_fw.h"
 #include "panthor_gem.h"
@@ -1520,7 +1521,8 @@ static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev,
                drm_printf(p, "drm-cycles-panthor:\t%llu\n", pfile->stats.cycles);
 
        drm_printf(p, "drm-maxfreq-panthor:\t%lu Hz\n", ptdev->fast_rate);
-       drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", ptdev->current_frequency);
+       drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n",
+                  panthor_devfreq_get_freq(ptdev));
 }
 
 static void panthor_show_internal_memory_stats(struct drm_printer *p, struct drm_file *file)