From mboxrd@z Thu Jan 1 00:00:00 1970 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 BAC5FC4332D for ; Fri, 5 Mar 2021 17:04:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C81C650AD for ; Fri, 5 Mar 2021 17:04:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbhCEREH (ORCPT ); Fri, 5 Mar 2021 12:04:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231373AbhCERDx (ORCPT ); Fri, 5 Mar 2021 12:03:53 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 001F4C061574 for ; Fri, 5 Mar 2021 09:03:52 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id n11-20020a05600c4f8bb029010e5cf86347so1088780wmq.1 for ; Fri, 05 Mar 2021 09:03:52 -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=FRb7ItoNyUYyhXCHU4qOqv4pUK8UWPoqe/ZnMREqgVA=; b=EgUhOogowl99zpTzCzDFdUKufp8k9c2Gtw+KbklyRh9lG5Kpt5QaM9U79eUMWFyJKe OWSSPvd+BuEKkWrvoJO1Ivzf9Qe1vCZm08urwp9Zh0TGbbxSjjmo80dp5hrx4P/NWWnE 4NCqtnvVCUVsj80mq/qovHX9uVTKYdDxHUiJzm1rBr3vdLcSxoFpANUBJExljWclTCNU D8jyIdRzmUtn4FtjTC9wiWSqndGe2lDrn9vWi2ZWq4jv/jCuP+xaJuvMGyw/QEgqFgjC SUU67xpKbIHQ2v3685uL3a184kMuhCRtr6k3KxWWzA2EK3gfph8cMx/pUw6dxnA3YKzx 9p5A== 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=FRb7ItoNyUYyhXCHU4qOqv4pUK8UWPoqe/ZnMREqgVA=; b=qWU2Mtj36HqZiuO0L2LPdknoOknIrGmLtINUufdJFQv3QQ/zk0D3cczmArJCDMoAH7 AcH7OMBOUQyQ+D4Qe8E2H03pJWNotQ+3E0sSv3rZRjkNiAHP5uUDiBb2YAAe+QwpDmnC TBgzunacYXgNsqdVWATAPvd5A0N+WzFuZAdoeWWzs5RUOY9MqA+1c2Uz3UUje5JoKdSx hRbyQLJrJgrE/h5XckcgHhxq0DWdv+s7dUgUlwTdjBQrFRAEyxd8AT6X+Rz/xt4tXgxS PjULOBwUC2EAxs9Pc9cS2M45ZORxuKnGCOIEIn2Pv2/phmlci9xjIf1vrI2HrsLcuYCP ZXCg== X-Gm-Message-State: AOAM5334uGLWXweaFQMB9NH0u7z1SMpSbyblp9MEMffnnSjGYGdzFP/z scUKILG8mJQMk1nsYgLVWkrA8Q== X-Google-Smtp-Source: ABdhPJwgyaupgci5lBNHruz1mxgNewnWlNWe9DNU6BisY3tavo++IJzHF3YSaYwuf5gizHV6XPyQRQ== X-Received: by 2002:a1c:2ed4:: with SMTP id u203mr10046088wmu.45.1614963830695; Fri, 05 Mar 2021 09:03:50 -0800 (PST) Received: from localhost.localdomain (lns-bzn-59-82-252-141-80.adsl.proxad.net. [82.252.141.80]) by smtp.gmail.com with ESMTPSA id p17sm4760934wmq.47.2021.03.05.09.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 09:03:50 -0800 (PST) From: Daniel Lezcano To: cwchoi00@gmail.com Cc: lukasz.luba@arm.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, steven.price@arm.com, MyungJoo Ham , Kyungmin Park , Chanwoo Choi Subject: [PATCH v2 1/4] devfreq: Register devfreq as a cooling device on demand Date: Fri, 5 Mar 2021 18:03:34 +0100 Message-Id: <20210305170338.13647-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the default behavior is to manually having the devfreq backend to register themselves as a devfreq cooling device. Instead of adding the code in the drivers for the thermal cooling device registering, let's provide a flag in the devfreq's profile to tell the common devfreq code to register the newly created devfreq as a cooling device. Suggested-by: Chanwoo Choi Signed-off-by: Daniel Lezcano --- drivers/devfreq/devfreq.c | 11 +++++++++++ include/linux/devfreq.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index b6d63f02d293..5c0fdd3a48d2 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,13 @@ struct devfreq *devfreq_add_device(struct device *dev, mutex_unlock(&devfreq_list_lock); + if (devfreq->profile->is_cooling_device) { + 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 +969,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/include/linux/devfreq.h b/include/linux/devfreq.h index 26ea0850be9b..554e7904b0c5 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -98,11 +98,15 @@ struct devfreq_dev_status { * @freq_table: Optional list of frequencies to support statistics * and freq_table must be generated in ascending order. * @max_state: The size of freq_table. + * + * @is_cooling_device: A self-explanatory boolean giving the device a + * cooling effect property. */ struct devfreq_dev_profile { unsigned long initial_freq; unsigned int polling_ms; enum devfreq_timer timer; + bool is_cooling_device; int (*target)(struct device *dev, unsigned long *freq, u32 flags); int (*get_dev_status)(struct device *dev, @@ -198,6 +202,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; }; -- 2.17.1