Skip to content

Commit

Permalink
drm/panfrost: Register devfreq cooling device
Browse files Browse the repository at this point in the history
When we have devfreq, also try to register a basic cooling device in
case GPU workloads manage to hit thermal throttling thresholds.

Signed-off-by: Robin Murphy <[email protected]>
Reviewed-by: Steven Price <[email protected]>
Signed-off-by: Rob Herring <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/21f228099321f460d62e0ab7c77b2d2213dd4da8.1574974319.git.robin.murphy@arm.com
  • Loading branch information
rmurphy-arm authored and robherring committed Dec 6, 2019
1 parent 1ca3fd9 commit bc1152b
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions drivers/gpu/drm/panfrost/panfrost_devfreq.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright 2019 Collabora ltd. */
#include <linux/devfreq.h>
#include <linux/devfreq_cooling.h>
#include <linux/platform_device.h>
#include <linux/pm_opp.h>
#include <linux/clk.h>
Expand Down Expand Up @@ -81,8 +82,11 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)
int ret;
struct dev_pm_opp *opp;
unsigned long cur_freq;
struct device *dev = &pfdev->pdev->dev;
struct devfreq *devfreq;
struct thermal_cooling_device *cooling;

ret = dev_pm_opp_of_add_table(&pfdev->pdev->dev);
ret = dev_pm_opp_of_add_table(dev);
if (ret == -ENODEV) /* Optional, continue without devfreq */
return 0;
else if (ret)
Expand All @@ -92,29 +96,35 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)

cur_freq = clk_get_rate(pfdev->clock);

opp = devfreq_recommended_opp(&pfdev->pdev->dev, &cur_freq, 0);
opp = devfreq_recommended_opp(dev, &cur_freq, 0);
if (IS_ERR(opp))
return PTR_ERR(opp);

panfrost_devfreq_profile.initial_freq = cur_freq;
dev_pm_opp_put(opp);

pfdev->devfreq.devfreq = devm_devfreq_add_device(&pfdev->pdev->dev,
&panfrost_devfreq_profile, DEVFREQ_GOV_SIMPLE_ONDEMAND,
NULL);
if (IS_ERR(pfdev->devfreq.devfreq)) {
DRM_DEV_ERROR(&pfdev->pdev->dev, "Couldn't initialize GPU devfreq\n");
ret = PTR_ERR(pfdev->devfreq.devfreq);
pfdev->devfreq.devfreq = NULL;
dev_pm_opp_of_remove_table(&pfdev->pdev->dev);
return ret;
devfreq = devm_devfreq_add_device(dev, &panfrost_devfreq_profile,
DEVFREQ_GOV_SIMPLE_ONDEMAND, NULL);
if (IS_ERR(devfreq)) {
DRM_DEV_ERROR(dev, "Couldn't initialize GPU devfreq\n");
dev_pm_opp_of_remove_table(dev);
return PTR_ERR(devfreq);
}
pfdev->devfreq.devfreq = devfreq;

cooling = of_devfreq_cooling_register(dev->of_node, devfreq);
if (IS_ERR(cooling))
DRM_DEV_INFO(dev, "Failed to register cooling device\n");
else
pfdev->devfreq.cooling = cooling;

return 0;
}

void panfrost_devfreq_fini(struct panfrost_device *pfdev)
{
if (pfdev->devfreq.cooling)
devfreq_cooling_unregister(pfdev->devfreq.cooling);
dev_pm_opp_of_remove_table(&pfdev->pdev->dev);
}

Expand Down

0 comments on commit bc1152b

Please sign in to comment.