From patchwork Thu Mar 4 12:50:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 393647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8508AC433DB for ; Thu, 4 Mar 2021 12:52:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55D8164F2C for ; Thu, 4 Mar 2021 12:52:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235357AbhCDMwC (ORCPT ); Thu, 4 Mar 2021 07:52:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233969AbhCDMvj (ORCPT ); Thu, 4 Mar 2021 07:51:39 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D1A3C06175F for ; Thu, 4 Mar 2021 04:50:59 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id d15so12286261wrv.5 for ; Thu, 04 Mar 2021 04:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=T4drX2OHz8WsU2B+DyV2cYvNY39nMQirtfdi2mTuSOg=; b=aT1zbGeyGacOaJcwjnuOmLSK6neJHxSZln7SpxKQYeYLkoMFu4fvwf2ZIQvJ8ZXsNL UyrBq4ll7SJEQgIJsoZ3gq05uAYhMnOjY2YM8EiSyhlPEpOz5In6kuKRsDTeMaFbiuyU aRlT+7rzGU0HqwpGo04vyPLaHPeLAbHBkApowFty6WvQ6p/IFUxKRevPINH2x7bCXPMM 58GD8mOxaTzQreXLjLiKGM3uREA5CgURdllKVkQxCPvTlt7OX0xe7rywzsTmogYKm6fG 2oPM9ZobJWjD6c2SAt2Onxh7NjxtOYeCyViyk2hlgJHkQ0MbzopK4irrvutohf941nTw lEEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=T4drX2OHz8WsU2B+DyV2cYvNY39nMQirtfdi2mTuSOg=; b=ene3CTYvTtsWdXpdQmNvJf6cyA9gegp8TQ+maxsz988ucyLyIhgyB4P+xzpbIFEWxK sckwWKqfKTFu7ze/Jqwn6zeP6E7Sl/yFGEDjXX9rlm43AxTwpqv241DD51R9JkHe05pz JjQeBVEQSP4aiOT9+mmXocTjFQX8iPmahMviaXYDnz9Jro86rHquLk8lL4/AvwZRv+Ug bBU1k3sGOxDw1A6NmHcCHnPmAZpgy0PzqkTlqT6y9QsjEwj/9qGoCnRrMAzRrl4I4+Ga tewbvmgmGWuM6NBs4Yy1ewBcM+Yi+3iDmLeXGQPsfpSonpppVIgV6p+ZM/Q/ITJzbuCU MBnQ== X-Gm-Message-State: AOAM532zW6cP0VElvV2COHnprk0rh0muLw1pIHhM34eMwtPB1nSyFhCp iraa2Jh8UYrdihhgYqnmg10S6A== X-Google-Smtp-Source: ABdhPJzGo4COvZK7kDu3+r40eNKlVccn5YfL70YriZdNoTBFiRhALzWFMjin8vjSY9WX/vCfmJQxIQ== X-Received: by 2002:a5d:620d:: with SMTP id y13mr3986716wru.88.1614862257577; Thu, 04 Mar 2021 04:50:57 -0800 (PST) Received: from localhost.localdomain (lns-bzn-59-82-252-144-192.adsl.proxad.net. [82.252.144.192]) by smtp.gmail.com with ESMTPSA id z2sm19688850wrm.0.2021.03.04.04.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 04:50:56 -0800 (PST) From: Daniel Lezcano To: cwchoi00@gmail.com, kyungmin.park@samsung.com, myungjoo.ham@samsung.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Chanwoo Choi , Qiang Yu , David Airlie , Daniel Vetter , Rob Clark , Sean Paul , Rob Herring , Tomeu Vizoso , Steven Price , Alyssa Rosenzweig , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS FOR LIMA), lima@lists.freedesktop.org (moderated list:DRM DRIVERS FOR LIMA), linux-arm-msm@vger.kernel.org (open list:DRM DRIVER FOR MSM ADRENO GPU), freedreno@lists.freedesktop.org (open list:DRM DRIVER FOR MSM ADRENO GPU) Subject: [PATCH] devfreq: Register devfreq as a cooling device Date: Thu, 4 Mar 2021 13:50:33 +0100 Message-Id: <20210304125034.28404-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Currently the default behavior is to manually having the devfreq backend to register themselves as a devfreq cooling device. There are no so many and actually it makes more sense to register the devfreq device when adding it. Consequently, every devfreq becomes a cooling device like cpufreq is. Having a devfreq being registered as a cooling device can not mitigate a thermal zone if it is not bound to this one. Thus, the current configurations are not impacted by this change. Signed-off-by: Daniel Lezcano --- drivers/devfreq/devfreq.c | 8 ++++++++ drivers/gpu/drm/lima/lima_devfreq.c | 13 ------------- drivers/gpu/drm/lima/lima_devfreq.h | 2 -- drivers/gpu/drm/msm/msm_gpu.c | 11 ----------- drivers/gpu/drm/msm/msm_gpu.h | 2 -- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 13 ------------- include/linux/devfreq.h | 3 +++ 7 files changed, 11 insertions(+), 41 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index b6d63f02d293..19149b31b000 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include #include "governor.h" @@ -935,6 +937,10 @@ struct devfreq *devfreq_add_device(struct device *dev, mutex_unlock(&devfreq_list_lock); + devfreq->cdev = devfreq_cooling_em_register(devfreq, NULL); + if (IS_ERR(devfreq->cdev)) + dev_info(dev, "Failed to register devfreq cooling device\n"); + return devfreq; err_init: @@ -960,6 +966,8 @@ int devfreq_remove_device(struct devfreq *devfreq) if (!devfreq) return -EINVAL; + thermal_cooling_device_unregister(devfreq->cdev); + if (devfreq->governor) { devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_STOP, NULL); diff --git a/drivers/gpu/drm/lima/lima_devfreq.c b/drivers/gpu/drm/lima/lima_devfreq.c index 5686ad4aaf7c..a696eff1642c 100644 --- a/drivers/gpu/drm/lima/lima_devfreq.c +++ b/drivers/gpu/drm/lima/lima_devfreq.c @@ -7,7 +7,6 @@ */ #include #include -#include #include #include #include @@ -90,11 +89,6 @@ void lima_devfreq_fini(struct lima_device *ldev) { struct lima_devfreq *devfreq = &ldev->devfreq; - if (devfreq->cooling) { - devfreq_cooling_unregister(devfreq->cooling); - devfreq->cooling = NULL; - } - if (devfreq->devfreq) { devm_devfreq_remove_device(ldev->dev, devfreq->devfreq); devfreq->devfreq = NULL; @@ -110,7 +104,6 @@ void lima_devfreq_fini(struct lima_device *ldev) int lima_devfreq_init(struct lima_device *ldev) { - struct thermal_cooling_device *cooling; struct device *dev = ldev->dev; struct opp_table *opp_table; struct devfreq *devfreq; @@ -173,12 +166,6 @@ int lima_devfreq_init(struct lima_device *ldev) ldevfreq->devfreq = devfreq; - cooling = of_devfreq_cooling_register(dev->of_node, devfreq); - if (IS_ERR(cooling)) - dev_info(dev, "Failed to register cooling device\n"); - else - ldevfreq->cooling = cooling; - return 0; err_fini: diff --git a/drivers/gpu/drm/lima/lima_devfreq.h b/drivers/gpu/drm/lima/lima_devfreq.h index 2d9b3008ce77..c43a2069e5d3 100644 --- a/drivers/gpu/drm/lima/lima_devfreq.h +++ b/drivers/gpu/drm/lima/lima_devfreq.h @@ -9,7 +9,6 @@ struct devfreq; struct opp_table; -struct thermal_cooling_device; struct lima_device; @@ -17,7 +16,6 @@ struct lima_devfreq { struct devfreq *devfreq; struct opp_table *clkname_opp_table; struct opp_table *regulators_opp_table; - struct thermal_cooling_device *cooling; ktime_t busy_time; ktime_t idle_time; diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index ab7c167b0623..d7f80ebfe9df 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -112,14 +111,6 @@ static void msm_devfreq_init(struct msm_gpu *gpu) } devfreq_suspend_device(gpu->devfreq.devfreq); - - gpu->cooling = of_devfreq_cooling_register(gpu->pdev->dev.of_node, - gpu->devfreq.devfreq); - if (IS_ERR(gpu->cooling)) { - DRM_DEV_ERROR(&gpu->pdev->dev, - "Couldn't register GPU cooling device\n"); - gpu->cooling = NULL; - } } static int enable_pwrrail(struct msm_gpu *gpu) @@ -1056,6 +1047,4 @@ void msm_gpu_cleanup(struct msm_gpu *gpu) if (gpu->worker) { kthread_destroy_worker(gpu->worker); } - - devfreq_cooling_unregister(gpu->cooling); } diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h index d7cd02cd2109..93419368bac8 100644 --- a/drivers/gpu/drm/msm/msm_gpu.h +++ b/drivers/gpu/drm/msm/msm_gpu.h @@ -155,8 +155,6 @@ struct msm_gpu { struct msm_gpu_state *crashstate; /* True if the hardware supports expanded apriv (a650 and newer) */ bool hw_apriv; - - struct thermal_cooling_device *cooling; }; static inline struct msm_gpu *dev_to_gpu(struct device *dev) diff --git a/drivers/gpu/drm/panfrost/panfrost_devfreq.c b/drivers/gpu/drm/panfrost/panfrost_devfreq.c index 56b3f5935703..2cb6300de1f1 100644 --- a/drivers/gpu/drm/panfrost/panfrost_devfreq.c +++ b/drivers/gpu/drm/panfrost/panfrost_devfreq.c @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -90,7 +89,6 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev) struct device *dev = &pfdev->pdev->dev; struct devfreq *devfreq; struct opp_table *opp_table; - struct thermal_cooling_device *cooling; struct panfrost_devfreq *pfdevfreq = &pfdev->pfdevfreq; opp_table = dev_pm_opp_set_regulators(dev, pfdev->comp->supply_names, @@ -139,12 +137,6 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev) } pfdevfreq->devfreq = devfreq; - cooling = devfreq_cooling_em_register(devfreq, NULL); - if (IS_ERR(cooling)) - DRM_DEV_INFO(dev, "Failed to register cooling device\n"); - else - pfdevfreq->cooling = cooling; - return 0; err_fini: @@ -156,11 +148,6 @@ void panfrost_devfreq_fini(struct panfrost_device *pfdev) { struct panfrost_devfreq *pfdevfreq = &pfdev->pfdevfreq; - if (pfdevfreq->cooling) { - devfreq_cooling_unregister(pfdevfreq->cooling); - pfdevfreq->cooling = NULL; - } - if (pfdevfreq->opp_of_table_added) { dev_pm_opp_of_remove_table(&pfdev->pdev->dev); pfdevfreq->opp_of_table_added = false; diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 26ea0850be9b..690bd4affe18 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -198,6 +198,9 @@ struct devfreq { struct srcu_notifier_head transition_notifier_list; + /* Pointer to the cooling device if used for thermal mitigation */ + struct thermal_cooling_device *cdev; + struct notifier_block nb_min; struct notifier_block nb_max; };