From patchwork Mon Jan 28 06:41: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: 156696 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3089229jaa; Sun, 27 Jan 2019 22:44:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN7abuinpBErrUTRvqJGH02FABdSXClloiQ4n1Guos1OXWEb5UqJ4BQJAkBcQNa1qNC0JG7a X-Received: by 2002:a63:4e41:: with SMTP id o1mr19224250pgl.282.1548657875586; Sun, 27 Jan 2019 22:44:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548657875; cv=none; d=google.com; s=arc-20160816; b=vuOqmIKwcW+AdtZg3Sml7tyfDSDl8hSyXJ4hEb3M2e3ClleTwf+WC7ZW9s9kNWB0zX LXj1HbCRj75wEpHCVJ0y++IVIKlf9o6tsi5/urLoU3IjCeCNcWuiSNGPDx86IAbfwlHy yvQmWH6DnNX2uLb08CLO45M8GdtzY/+VOV1zRtBUIcyJqHGy4HujiPsGdAEJrSo+yFf5 XFLHeba/nJQoD5ZCKd5KGYedRGVGaNDdVrCC+1HMGxigXji9xYeOAPiX1rvg7kXAZqe4 TN9S6PQhJrvnQni7zt5tiA9v0eCmxN4gjtsp2+jBJnS/XM/OTnAmV7eZ/tj/RXphpDPQ e+cw== 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=AMCeOi6x/Wbey9b/NaGjqvsuxi1tHtv0yD2YjLVBzzg=; b=ffamXjSsYCX0OdjKpkhWibbHsdXKyGSLwr9/Qs0Oh4tXePP1iGDXAZ0OhRVtJt0gcB l8Tu4RJYifoYwnNAog1GbanHL0TKS483FczXJBh8MuAesLkztxCUW95wm1TvPegU9HWh Kp0Vu0Qeg4/xKDmC++F9RHECzE/6shtyx2aiUhWywSzZQ7qdYzCUiDLaMir0i+guOr7/ gQPfpoB+B5fPcBIowekn9WcYj0TsvKghh62PJ/XYEGYsMHoJtZzWaHP/U93qtOvNmcvW HW7wwrC8b4oYBY7cuibpWc42v14uPDM8Gdwga4AOpxSVTaPjouXztlOtshjATj3ux9oT +2AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WaHCrlaG; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 i69si33107796pgd.71.2019.01.27.22.44.35; Sun, 27 Jan 2019 22:44:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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=WaHCrlaG; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1726638AbfA1Goe (ORCPT + 15 others); Mon, 28 Jan 2019 01:44:34 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36043 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbfA1Goe (ORCPT ); Mon, 28 Jan 2019 01:44:34 -0500 Received: by mail-wm1-f65.google.com with SMTP id p6so12550373wmc.1 for ; Sun, 27 Jan 2019 22:44:33 -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=AMCeOi6x/Wbey9b/NaGjqvsuxi1tHtv0yD2YjLVBzzg=; b=WaHCrlaGNbIsQJL0PrjX/7IJwbxZdCo2c8Mn+7HRrFaoXNP38bwLNLaVldVR4W82KY jreY6JsHG3DN5l1yGSxfK+sur+J+dPFd6Amt15bQLyktwFianXBJq6qqMQRL/Trx7eei CgYnHmXSfl1pJut+G8OW/CqBrNXUv+88MVvu0= 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=AMCeOi6x/Wbey9b/NaGjqvsuxi1tHtv0yD2YjLVBzzg=; b=C+fKBHjxgbzHuZSfT8QHPdLEkZxJ5VxcNQy6wNfME6Ss8wMylPkiOoqRbpJ7vgLYms gT1v+BYvzQmI+PtfGYyRWb1SWFCOYNRx3CJtMnuzE8R2b3eGzI/8N00Stv886w7LzCZm 5DM6mcF1xND2bFIi7Z/1wYN1ab87KVIKNVDAy26YyS9cbX6aNbPoQ5ih6eLrUw6jyH+y PkGEo68JOWKem7fhJEGty5eEUhW+kp5q8i8s7RqBZhhXnclw0VlY9hyLXMkd6hF2h/dR Vkln6oySSqInhCpqLkvs/hRVlKfJQ2V2TKDYzNFgIsp4miwY0jAxVWZqfcaA+ANsofnK 96gA== X-Gm-Message-State: AJcUukfJdyoDVCDqVObUcyZX8IbZOawJfPg6tK/Ut16pG4X3IYU5nQZT A1KTUg2e+XU5qAA29pfiAJGkaA== X-Received: by 2002:a1c:8095:: with SMTP id b143mr15097321wmd.63.1548657872657; Sun, 27 Jan 2019 22:44:32 -0800 (PST) Received: from localhost ([49.248.191.44]) by smtp.gmail.com with ESMTPSA id h13sm95586448wrp.61.2019.01.27.22.44.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 Jan 2019 22:44:32 -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" , "Peter Zijlstra (Intel)" , Tao Wang , Sudeep Holla , linux-pm@vger.kernel.org Subject: [PATCH v4 2/9] cpufreq: Auto-register the driver as a thermal cooling device if asked Date: Mon, 28 Jan 2019 12:11:27 +0530 Message-Id: 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 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 | 9 +++++++++ include/linux/cpufreq.h | 9 +++++++++ 2 files changed, 18 insertions(+) -- 2.17.1 Reviewed-by: Daniel Lezcano diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index e35a886e00bc..29ed78b0b77b 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -1318,6 +1319,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) + policy->cdev = of_cpufreq_cooling_register(policy); + pr_debug("initialization complete\n"); return 0; @@ -1405,6 +1409,11 @@ static int cpufreq_offline(unsigned int cpu) goto unlock; } + if (cpufreq_driver->flags & CPUFREQ_AUTO_REGISTER_COOLING_DEV) { + cpufreq_cooling_unregister(policy->cdev); + policy->cdev = NULL; + } + if (cpufreq_driver->stop_cpu) cpufreq_driver->stop_cpu(policy); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index bd7fbd6a4478..55ca61a64fc2 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_AUTO_REGISTER_COOLING_DEV BIT(7) + int cpufreq_register_driver(struct cpufreq_driver *driver_data); int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);