From patchwork Fri Jan 25 07:02:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 10780641 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B854746 for ; Fri, 25 Jan 2019 07:03:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57FCA2E95C for ; Fri, 25 Jan 2019 07:03:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B8642F843; Fri, 25 Jan 2019 07:03:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8C6A2E95C for ; Fri, 25 Jan 2019 07:03:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728030AbfAYHDG (ORCPT ); Fri, 25 Jan 2019 02:03:06 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:36974 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728012AbfAYHDF (ORCPT ); Fri, 25 Jan 2019 02:03:05 -0500 Received: by mail-ed1-f68.google.com with SMTP id h15so6560414edb.4 for ; Thu, 24 Jan 2019 23:03:04 -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:in-reply-to:references :in-reply-to:references; bh=y3EtZ9Zijh6g5b1BdvkqodqbkDXmOjJfZ/0yd7HhXeE=; b=N2cWSkuYkCEV0DFcML/0FcxMJLPso61+fkMzVT4Mqvd8kb07HlBv8CLzu9f9ruMTv5 rSVlVyo2UkXWTulTswVoSQNxgTbRyTapa+rDEU5RX/XV+04+5n7JQYPprzmadmUKbI2M 9fWlg7Z52z/ym4NaMQxg0kyDQFUH0twFyEWfY= 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:in-reply-to :references:in-reply-to:references; bh=y3EtZ9Zijh6g5b1BdvkqodqbkDXmOjJfZ/0yd7HhXeE=; b=mC19h8sr0tGHRTyEQcA3253yuWl9Z7i+EXPJsVMjWywugjaUkjoI/1I6/03iK2mfLz 3ZOdxyX3COTPYm4hib6iHolPN3Sy/QE79cbS6j0jho+8WPE2JRwMgqSugeGTYy2sOCv9 Gt7G/v1LSTmtqU4kN69OXwD0LIXWZPvKY/oJnCGc5PYtqBAx4KC2WYG9qez2pCKb36YS 0E6ng8/Nknf2fEzndI1btQ8XUBMG0T3W3JJT1FYPWrlN0Yv86+ttt4wA7TA0b5x1f0dU eAxHw8Oc2p1uagXKSDm40Lg7QZ+y11cW2cMk9to+zM+zKynZmuJGRAt8QW/MNpuQ+SXz +69Q== X-Gm-Message-State: AJcUukf3tiMdHfpfbLURn+oYlzHBMmt2YFVASS2mxztLuq+1NgHIkZ+h SDy2qjwe7NqowAuomDga6AwazeTsCbE= X-Google-Smtp-Source: ALg8bN4sKteL+WrlNuVtIG46p+TIOxBSxKJQbKpCRz2eFHDbSQ06sY6Y2/E0i1xj2bJHoxwN2sKdmw== X-Received: by 2002:a50:de88:: with SMTP id c8mr9572635edl.129.1548399783664; Thu, 24 Jan 2019 23:03:03 -0800 (PST) Received: from localhost ([49.248.181.51]) by smtp.gmail.com with ESMTPSA id h47sm11808656eda.8.2019.01.24.23.03.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Jan 2019 23:03:03 -0800 (PST) From: Amit Kucheria To: linux-kernel@vger.kernel.org Cc: linux-arm-msm@vger.kernel.org, viresh.kumar@linaro.org, edubezval@gmail.com, swboyd@chromium.org, dianders@chromium.org, mka@chromium.org, "Rafael J. Wysocki" , linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK) Subject: [PATCHv3 2/9] cpufreq: Auto-register the driver as a thermal cooling device if asked Date: Fri, 25 Jan 2019 12:32:22 +0530 Message-Id: <73e091e2d56d9fa6eb94feaed9fc2be30bf6da20.1548398851.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP All cpufreq drivers do similar things to register as a cooling device. Provide a cpufreq driver flag so drivers can just ask the cpufreq core to register the cooling device on their behalf. This allows us to get rid of duplicated code in the drivers. In order to allow this, we add a struct thermal_cooling_device pointer to struct cpufreq_policy so that drivers don't need to store it in a private data structure. Suggested-by: Stephen Boyd Suggested-by: Viresh Kumar Signed-off-by: Amit Kucheria Reviewed-by: Matthias Kaehlcke Tested-by: Matthias Kaehlcke --- drivers/cpufreq/cpufreq.c | 6 ++++++ include/linux/cpufreq.h | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index e35a886e00bc..cf1be057caf4 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1318,6 +1318,9 @@ static int cpufreq_online(unsigned int cpu) if (cpufreq_driver->ready) cpufreq_driver->ready(policy); + if (cpufreq_driver->flags & CPUFREQ_AUTO_REGISTER_COOLING_DEV) + register_cooling_device(policy); + pr_debug("initialization complete\n"); return 0; @@ -1405,6 +1408,9 @@ static int cpufreq_offline(unsigned int cpu) goto unlock; } + if (cpufreq_driver->flags & CPUFREQ_AUTO_REGISTER_COOLING_DEV) + unregister_cooling_device(policy); + if (cpufreq_driver->stop_cpu) cpufreq_driver->stop_cpu(policy); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index bd7fbd6a4478..c7eb59b8ce94 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -151,6 +152,9 @@ struct cpufreq_policy { /* For cpufreq driver's internal use */ void *driver_data; + + /* Pointer to the cooling device if used for thermal mitigation */ + struct thermal_cooling_device *cdev; }; /* Only for ACPI */ @@ -386,6 +390,12 @@ struct cpufreq_driver { */ #define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING BIT(6) +/* + * Set by drivers that want the core to automatically register the cpufreq + * driver as a thermal cooling device. + */ +#define CPUFREQ_AUTO_REGISTER_COOLING_DEV BIT(7) + int cpufreq_register_driver(struct cpufreq_driver *driver_data); int cpufreq_unregister_driver(struct cpufreq_driver *driver_data); @@ -415,6 +425,17 @@ cpufreq_verify_within_cpu_limits(struct cpufreq_policy *policy) policy->cpuinfo.max_freq); } +static inline void register_cooling_device(struct cpufreq_policy *policy) +{ + policy->cdev = of_cpufreq_cooling_register(policy); +} + +static inline void unregister_cooling_device(struct cpufreq_policy *policy) +{ + cpufreq_cooling_unregister(policy->cdev); + policy->cdev = NULL; +} + #ifdef CONFIG_CPU_FREQ void cpufreq_suspend(void); void cpufreq_resume(void);