From patchwork Mon Jan 21 15:40:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 156212 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6515642jaa; Mon, 21 Jan 2019 07:43:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN5EQ3nHcxiKqhltwHksYlfflg3M1nxLIWaXKsqajrho1LN5qMjNk31SWXGQsooqWXk0oWXg X-Received: by 2002:a62:cd1:: with SMTP id 78mr30132061pfm.219.1548085418901; Mon, 21 Jan 2019 07:43:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548085418; cv=none; d=google.com; s=arc-20160816; b=LM8/JnAcEtxJlEwU2y+MMwYPrRjPiAuLZ6GLaeYqr7u5mV8SImDBbtKDB8F1Hrbb2U Egr/lhBcVguekB6slfNKO2LufKABD/IsKOqVhuA0tc44IPXU4EUsZYh7iae4uroqPh1E VMnI5lxlLNgPeFaY0lQNNmp6kgxq9oSkPrkD7PWdC+1VOY0jCpMZT4jX4nYcvZxTHHaR bx6b2T2qYg/A7cRiAaGivmnhEDphzcjEircX0WsZped86RnTz2C5vqfqk620cwGR5qeB V2pNqv6pMhq+NY7OfCBCeQDsZrbHE2SvgMrUewb/AA9QwnXKz+g80pIb4CSzUQscBH1j HE2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=6nK5Z7skk0g3LC/CfG1f/AiMAh85ZzuJOt+3kzqjet0=; b=YUvG1fzw9rYTdkHoIvveAmMBCDrUcCqb5XVoAhm2i9Cemp3oUAADkrg9Dg7XdRccSz NlTispRq+phFLu/CO3CW2AcZlLXkQdkg7vGH2T6HzN2cWZMcsHNHmJW66lYCP4bF3ueu lHCjUltqHaOTMsaly7CQU9NggxRzMjKW4DK9njoUQxcEyjS+KoWHq7q0TWusTkKSU3zz KfIWGg62sIaGTb5HilsEn6Ma6511BduJwQVK36BIN7kk3aHZJXgNEfuqEAC+qhAzxPv+ HbCO+TnWnEjgzERXAkLA/lFJM5iKZ0pmV+dPB2VVcH5sxdSz3jDfeIZql7TloyWbxXOM skVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BCtyzqGC; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q24si11853704pgi.334.2019.01.21.07.43.38; Mon, 21 Jan 2019 07:43:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BCtyzqGC; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729220AbfAUPni (ORCPT + 11 others); Mon, 21 Jan 2019 10:43:38 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37559 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728822AbfAUPnh (ORCPT ); Mon, 21 Jan 2019 10:43:37 -0500 Received: by mail-wm1-f68.google.com with SMTP id g67so11214633wmd.2 for ; Mon, 21 Jan 2019 07:43:36 -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=6nK5Z7skk0g3LC/CfG1f/AiMAh85ZzuJOt+3kzqjet0=; b=BCtyzqGCEaRnpexFp/8u0S0xLLNlc/eLc1RE+1luRPpgO2HLYQY+VS2oWTHdcc0HQ3 4jh6sm6O35/GKcPGP0A+eYmGY1PVK7xR2w9iULuvIWlZgTcZNuJgD4TQoD9hELoHNXTV Ffh+LqclWWKwo+HtTeTnZv0GYrSmMHfCI4wGo= 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=6nK5Z7skk0g3LC/CfG1f/AiMAh85ZzuJOt+3kzqjet0=; b=YPiZwEWWzjVxsLgm1Zj1jxnPk1eDYfiKhIx+l+30E+cSnZr6BAtTMFccIGAgcQiyga JR9pB6sA/VHsPEI7y3Yi3e2FInp1X7raKsUuKGhloSNZpIQQpyDuR7RZd6RSBotZFwj/ S1/V+9izseiqRpmVfSOQD1lm6xNek3k59Qmhxn7ruPzPAbyAV3+P33hZsAxtUJ1XTKoy hPZ0QOrKUpQg8SS+r9f//3tr8WTXynp0/juaWhEwdkm6H9uy821chUqtUxqh7dqr7oGg 0bS3RHkPtz20dbigjOQbrSZo+4XQP4K3MJPb9gU6EUr0JW1lpkZqGXWnxEoNtMReGZCT XDSw== X-Gm-Message-State: AJcUukfjiJtf6HbCkzUwit9NUtJVd8E/yo7AqVb7Fi+oZZ1EU7fr4Vq4 rUw0D3ytUcopvMYH6yJPOPlAaw== X-Received: by 2002:a1c:7511:: with SMTP id o17mr24971901wmc.42.1548085415973; Mon, 21 Jan 2019 07:43:35 -0800 (PST) Received: from localhost ([49.248.61.1]) by smtp.gmail.com with ESMTPSA id n15sm76230608wrt.21.2019.01.21.07.43.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Jan 2019 07:43:35 -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" , Ingo Molnar , Sudeep Holla , Tao Wang , linux-pm@vger.kernel.org Subject: [PATCH v2 2/9] cpufreq: Auto-register the driver as a thermal cooling device if asked Date: Mon, 21 Jan 2019 21:10:27 +0530 Message-Id: <0036de796308b8919eac74a9a910f0d7b9c0cbf8.1548084260.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) -- 2.17.1 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..02fc9f210aee 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -151,6 +152,11 @@ struct cpufreq_policy { /* For cpufreq driver's internal use */ void *driver_data; + +#ifdef CONFIG_CPU_THERMAL + /* Pointer to the cooling device if used for thermal mitigation */ + struct thermal_cooling_device *cdev; +#endif }; /* Only for ACPI */ @@ -386,6 +392,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 +427,19 @@ cpufreq_verify_within_cpu_limits(struct cpufreq_policy *policy) policy->cpuinfo.max_freq); } +#ifdef CONFIG_CPU_THERMAL +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; +} +#else +static inline void register_cooling_device(struct cpufreq_policy *policy) {} +static inline void unregister_cooling_device(struct cpufreq_policy *policy) {} +#endif #ifdef CONFIG_CPU_FREQ void cpufreq_suspend(void); void cpufreq_resume(void);