Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3140926imu; Sun, 27 Jan 2019 22:45:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN7MishMWtAZ/rEw6RJ8WDaWjN3E5Ltm2iwmRR7dPY0MOuckyTcxK5Ocb1NK1Hp8mdGCBe0L X-Received: by 2002:a62:26c7:: with SMTP id m190mr21140832pfm.79.1548657903935; Sun, 27 Jan 2019 22:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548657903; cv=none; d=google.com; s=arc-20160816; b=v6vOl8bFTubMNMOkPjNaeVRhokzMy2olal2JY4SkzvH9c5AiJxlsnFCEdzlINifKDO Rmumj1OSIZm7WhlVb07QYcOKvr2HzAXDPqKkZprDpu44B4MYe1GyDBVANTdsDdp9GwJE 33CeIV7kiRyOujdd1utcq4l4VE3sfxXVwcNXe3jj2vcspB4df8zfCthvnY62wIOeBSWO sOuSq5zGoj3QMHw7u508gKr1QmEBTyC7DgHHLxT4eT7tNhMqeE5eZ6kuwJRscYGRkKrU Mgxv1xpZXVyYaIhrbj4Kw4ExQkjF0PkHwjf1VcHhJD9uYuL4RYIl9lJYEt8QJ1T1SE9p jI/A== 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=aBbmUab7gzHSTHM6z53drLo5/DX9wvVxfQOXrKoaV1ghCk7hbFNiBV3wUvyxIhyDv7 nVidlHW1nOiNn85iHS9oa9Bc0ijg1MNqSxtNdgfpaD6nh4+ub49MmQP1/2dQaKr0UW/J CVia8exN3hm2V/UE//AFzj4tJxG0ZkGgzzXKyDBiZ9SWwhocRaM0+/VqdHBcVnFctwDL 8lNZmrWqJ6xojk55TQPFMb5ovRv3UDtJ24OhJRe5WAU1Dt9hrPmrvMMNLYXSZH0rjmAs AWhmiQ3WNuG2kZkLZFXPbZtwxwXimLaz8off2ug/nSQ7Nadoa/DLMkUS5Lwa77Pg8L9g OYgw== 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-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 92si32834508pld.84.2019.01.27.22.44.48; Sun, 27 Jan 2019 22:45:03 -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=WaHCrlaG; 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 S1726778AbfA1Gog (ORCPT + 99 others); Mon, 28 Jan 2019 01:44:36 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53488 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726630AbfA1Gog (ORCPT ); Mon, 28 Jan 2019 01:44:36 -0500 Received: by mail-wm1-f67.google.com with SMTP id d15so12680607wmb.3 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=pmUsVdGDacjURQWSL0mVxN/Wo07l+HZYtm3MAy4mg/qhi9dZfNCWZhALLisX2Qhis6 h/3Ah9CeTN3EhDlswiddh2EHcr4N16BwQ8g08SauA8tAJcXeKxIqWyNfoLWCFpZzAlFj 9jadS6S8k7gmO987iIl1E9cOJ35cgopJHc+DGsKCrSistAS0LZmu7hCrzOSY+nXARZZl 93avYdBOowfgEp6V3eDndKvYTWvH7KVm4vkjXz3ICDtPBBO+TvYj9WtLOT13FAUOnesM Ajs+KNjGIPBcyKzNMW3qW2mDcgivBsGippYpVuFHU3DOg3ie6EpxzlDSfFyFzYMnK2oa 4MJQ== X-Gm-Message-State: AJcUukdXMCdhrGvrNl9zt0KbpNuHDVtF8yFFyNAsZRUiYr6nFib/XGID FTwHqUNdt1eXghLIe+6w0MzlQF5+1AU= 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-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 | 9 +++++++++ include/linux/cpufreq.h | 9 +++++++++ 2 files changed, 18 insertions(+) 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); -- 2.17.1