Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6368463imu; Mon, 21 Jan 2019 07:45:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN6Sxy5JvEK9UDVDT1OfzX9vGEsLstlvsKx9mdSKVG1LygXaxJ/d9gpWVa/EPLVSD08a1NsS X-Received: by 2002:a62:33c1:: with SMTP id z184mr29992530pfz.104.1548085519303; Mon, 21 Jan 2019 07:45:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548085519; cv=none; d=google.com; s=arc-20160816; b=elJAwt2bKTBa3++VZTU1wjCTysecOup3SJlh4E4Hw2VKPkoBHbJSWOTvh+FUrb7TMz 2xz0iWxMLB/a77/PCiU8G8RsY7JN+pXVeht/tIjhgeb39PQWST6penpLpKzM3NKmMEP4 v6ThtJCpvaqLqN5q2A1aqt/dxe7xwX+rY6MJMCNV8HVwpeT3dSfPgMRCFHTrXkvVIQ/7 oYj1ehIgzFhuVbNEYgvkJGZXKiSkfeUpXs20FS1Ra3t7TE8vuOO0yqxowc5C4an7P1GK YwyeE2HXDZRGqNKVAzHsnP1Nrtc/MONkqDsocw6ar826hS1ZQirBiejLtiPFHgroiJWn wwjg== 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=Q88Q+wLf9sY6OOMrWxK9s1sTQy/GIB6+9MdVYeXgTrwZUKB3JjaCNuLcFVGT25+C/2 o06jwXCk6c6/68I0pkpOg2Yv0aOaaha7EENd0HJGYA4Ykt/r7y52n3/NEe1Y0EMchmAd /rbSuYcy7xm6Hgff4IW+ZxodtM0CFpMYjkNQZG1gRpttJ0aD/i6Vrygw790O6FarvCWu TvB4ulRgzFu7NcVIEV+Fu34MToP8EmpCk6JQYXaOEZ6UCv/br7ppvvf5VxWpJEye4wMl AKUYqCfskkyd1Su8EYqyiuYdjsy//Zejet2BIsvlAoiNhl1VyXtxBJRckYUaZkE/RJVY U0Dg== 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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 d4si12396584pfa.150.2019.01.21.07.45.03; Mon, 21 Jan 2019 07:45:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1730157AbfAUPnj (ORCPT + 99 others); Mon, 21 Jan 2019 10:43:39 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:40150 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729195AbfAUPni (ORCPT ); Mon, 21 Jan 2019 10:43:38 -0500 Received: by mail-wm1-f68.google.com with SMTP id f188so11190256wmf.5 for ; Mon, 21 Jan 2019 07:43:37 -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=m+sw8jOVVhUiNfgHoEH2vlrThxiYM5XkZHiMYjIdLnOmSa6dEDqLPUBqYSH3XNvbcD 8NQT0Evn4HPLadXih0ffK+TMrB8CeEVhV9j5M4SVLedfRvIJUvSepQeAJcxhw4FqLN9C UPr4awC/CwTouYsIlw0x9lYrwjVTXbg5WBM6U5fT0cEww/t3nMk6KAkGcgSECs1ABkqh 7PpgdDYdiXW+DcOnPnyGTz0YaVenZAaivGpnp2i2j7xxpllXdcIImlXVBdvWL9+gUGrg AsncKixmEyDFE0qtN+4dEHsOkF+R7/srl6liUknP2eUkeA+8cHXMV51c33Ipc+PRLpoc fNjA== X-Gm-Message-State: AJcUukc92KbJvoy3OMQD3gLUAkp7Ckvlxg4kSvo6q0Y6+ZKzOrIBRZW+ zzZNdQ7DPEA7DZlwyDV32mEULC9WRtU= 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(+) 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); -- 2.17.1