From patchwork Tue Jan 29 04:55:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 156914 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4225425jaa; Mon, 28 Jan 2019 20:57:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN4e8xisFxztGKmxIf6TTz04QUSgyIYS08URC8cV+BQxdKUhUr0O1Sd3K8rJZRxyhBFZEx74 X-Received: by 2002:a17:902:298a:: with SMTP id h10mr24747965plb.312.1548737829162; Mon, 28 Jan 2019 20:57:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548737829; cv=none; d=google.com; s=arc-20160816; b=0Uw6gl5X2iMMeHEYpFMH/HZp6UV3va4AS/9BrvRDg1x4sEWp2JgfqpzjraPAVqfW9e 8jRm4XL19EddRamieUjJOesktC9vL2KSXMu18KZyB28yBbZzc/Ki3xuBNN9gNdyOImGP WKUn5QSHQn13VuzG/LGx8YEDfwDA8IXQaMcDKkimFkzIkhEtzp4iEnLDabuovQCwyV2u i1XvjBN/MUF5F0HLJ5A7DZjYmH+yQpUUGb4IaAcJReLBVRQbC9lyDeQ4aGwT2dbce14+ Zu+gc06WuOzyf02mKyvl6NYMBTWDVs+ZjbWPdg65deRUIKq8jW9fnNlCrNkn9Y6QmY7J pmcg== 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=sZDXlqnH1fj24jYunxEgKg9iTnvnCWnhkKzCRQGaUNw=; b=Z15citnehgCDmx/t4caakMM6HKjow3HvIHbisknzDi4Ny69fc/A64dWYTyHH3YLbns adnUMri4fCa7Iyqsz5ubaXIZx8aPgyoMXQWmlaMa1MM1BHmHKVwWbI3czAFEYmw7yt6M Xbn6yybeQP7SKjkDR0nMkZEqkC8cQ6RzDfNsRg58BJFTp6qYQ8yuUykg67QxyOw+wcxH wlyWiIYJNTbNXiQKhI3ORdOGgpsIDYEvLVH9RvZDtJWsoTyIfnBEg4JDPWyUbKH6EXIU Rp7tEuH5KCr4JrwHUyBReyAlCBVudvdgaoj93+GHwK1kqr+/XcaQLJ9g6Hjg1N++FnWt jFpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="dugmhw/6"; 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 s66si26861696pgs.115.2019.01.28.20.57.08; Mon, 28 Jan 2019 20:57:09 -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="dugmhw/6"; 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 S1727402AbfA2E5F (ORCPT + 11 others); Mon, 28 Jan 2019 23:57:05 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:36904 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727227AbfA2E5F (ORCPT ); Mon, 28 Jan 2019 23:57:05 -0500 Received: by mail-wr1-f65.google.com with SMTP id s12so20502255wrt.4 for ; Mon, 28 Jan 2019 20:57: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=sZDXlqnH1fj24jYunxEgKg9iTnvnCWnhkKzCRQGaUNw=; b=dugmhw/6jrlx3hZh1S8+lDNGcaaJeEyKdpTAzYFvj8MdrXX4cbJ3LjAFvmxbXv8uZ8 g9U5qD6kTDf3N4N6p8Hcs7tc3njH1J/2iEOUb0orpv05Rh3NApFy5MlBQ4Ob/0CSEke6 l+D7RrxUcRxzO3v8QXFelqrncmWReP2gkECOI= 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=sZDXlqnH1fj24jYunxEgKg9iTnvnCWnhkKzCRQGaUNw=; b=aPMc+/xugF+Semx4bt6lbuYjF00C9X+yDAfmTOHGCn34T1OO3jpcewmtVLaPIzo20o IdmaRShrhbwTsOuhM2g92PdqUf+YU5F6hvN9h2oFqcOE+BHL35Aku7vGx0yCqdsAqaUM 2O5qXsgKVYD9q1eWH4D2iHHF/d7FSx4vWzUnhDE6pnKZ0O/voaRFdA3dcNzVrmMTVGOa yO4XFRLpcLkjjQI9e1BcPQJKm7lHmGuOdWjx6wc4MOirARslNAo9ikvf6MdBGsYmvT8H RMYw3IsR7nmcM7/q210+CDIsaLXfmT3qtOL8FQc1efee2TFJfy38SME3YYf2XPKbHhVk 76vA== X-Gm-Message-State: AJcUukcgthXW9tUsxVqnSzgWLvN7a43Wr4S6oR4wCZxM4BWjAWXx/6Hs gI+aFREx9Z60exBhAgiTb5k4TA== X-Received: by 2002:adf:db01:: with SMTP id s1mr23650280wri.214.1548737823567; Mon, 28 Jan 2019 20:57:03 -0800 (PST) Received: from localhost ([49.248.171.30]) by smtp.gmail.com with ESMTPSA id 127sm2512264wmm.45.2019.01.28.20.57.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 20:57:03 -0800 (PST) From: Amit Kucheria To: linux-kernel@vger.kernel.org Cc: "Rafael J. Wysocki" , Viresh Kumar , Sudeep Holla , linux-pm@vger.kernel.org Subject: [PATCH v5 2/9] cpufreq: Auto-register the driver as a thermal cooling device if asked Date: Tue, 29 Jan 2019 10:25:08 +0530 Message-Id: <6077cb33d7e078bb0e85776bad99fdb476f16d0c.1548737236.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 Acked-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 13 +++++++++++++ include/linux/cpufreq.h | 9 +++++++++ 2 files changed, 22 insertions(+) -- 2.17.1 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index e35a886e00bc..0f9b50d3ee91 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -1318,6 +1319,11 @@ static int cpufreq_online(unsigned int cpu) if (cpufreq_driver->ready) cpufreq_driver->ready(policy); +#if IS_ENABLED(CONFIG_CPU_THERMAL) + if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) + policy->cdev = of_cpufreq_cooling_register(policy); +#endif + pr_debug("initialization complete\n"); return 0; @@ -1405,6 +1411,13 @@ static int cpufreq_offline(unsigned int cpu) goto unlock; } +#if IS_ENABLED(CONFIG_CPU_THERMAL) + if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) { + cpufreq_cooling_unregister(policy->cdev); + policy->cdev = NULL; + } +#endif + if (cpufreq_driver->stop_cpu) cpufreq_driver->stop_cpu(policy); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index bd7fbd6a4478..6078eb07a7e4 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -151,6 +151,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 +389,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_IS_COOLING_DEV BIT(7) + int cpufreq_register_driver(struct cpufreq_driver *driver_data); int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);