Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp140049imu; Thu, 24 Jan 2019 23:03:45 -0800 (PST) X-Google-Smtp-Source: ALg8bN7rRzfduWwY5ng4bdq9re2Sp/JkD2ZHPYCPMJt9y9N0CwWvQsz7JurQCqVTuEGRQpvcxxpV X-Received: by 2002:a17:902:a58a:: with SMTP id az10mr9968748plb.10.1548399825032; Thu, 24 Jan 2019 23:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548399825; cv=none; d=google.com; s=arc-20160816; b=rrB5MnyhyPVVrJGa2qsngjFbPGiYubq/FRIUfV7F5a1iz1TnLfOOEwq1TuYa4ATTMV 7Iw93u4z2wGPLQCstFe5KeY+utredel+HZXvSZJ08QGzgscxO5KP3JPbFizR2dF7kjo/ JkZ43R419t3dnn8t/aADg+P5j1pRtG9drruSfM2bBNpuRBiuGpN1ZUSBVqLEc/xrEOE4 3aPwJoKc8EQ8pA4tXIhB73BqyzqKP3vppB4nnysHQT5cdrg2u3zslkBp1Q/wzrBag5sk 7V92CcAuhDFkJHAJQq916Z0+m+gwJ34UbwI3Nb62JoGTgH6EPURHnWoIBeDMl1APcMFA zMCA== 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=y3EtZ9Zijh6g5b1BdvkqodqbkDXmOjJfZ/0yd7HhXeE=; b=wjcnEumHUHyPo8Iv+3GRBDCUNjcOfqz7OaC0y6C2Eup4gr+1lY4QFEzM3RK5WS7mW/ v5v3JobILsEa8+DXZB+DlffLTUR+19DPwZ4hdMqZCToFpbIRMB9DtTjBJK7Hnsvama8Z e4kRt07yzMgo+XmnFLxLnCfKhVj8bQt9ifvxX454R+SiZ3cD6HxtCLcg62vRkNRGrJMP E3yv7dRnERI2v7DZau9oJaVFGCMnXwwEwksZxfu0LOs+yR+Jo54hbl59ieHx4gX3iE5W jndLWmpoGXah9bBYK8ZnXoDO4Y0gXfir+Xlu1lFq3PC9rq8khG+yvTdHVF/VDx6W9xk8 h3nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N2cWSkuY; 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 j91si25392613pld.395.2019.01.24.23.03.22; Thu, 24 Jan 2019 23:03:44 -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=N2cWSkuY; 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 S1728067AbfAYHDG (ORCPT + 99 others); Fri, 25 Jan 2019 02:03:06 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:45624 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728017AbfAYHDG (ORCPT ); Fri, 25 Jan 2019 02:03:06 -0500 Received: by mail-ed1-f67.google.com with SMTP id d39so6533565edb.12 for ; Thu, 24 Jan 2019 23:03: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=y3EtZ9Zijh6g5b1BdvkqodqbkDXmOjJfZ/0yd7HhXeE=; b=N2cWSkuYkCEV0DFcML/0FcxMJLPso61+fkMzVT4Mqvd8kb07HlBv8CLzu9f9ruMTv5 rSVlVyo2UkXWTulTswVoSQNxgTbRyTapa+rDEU5RX/XV+04+5n7JQYPprzmadmUKbI2M 9fWlg7Z52z/ym4NaMQxg0kyDQFUH0twFyEWfY= 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=y3EtZ9Zijh6g5b1BdvkqodqbkDXmOjJfZ/0yd7HhXeE=; b=TyigXdZv9Om6jMcToLC3LJt22scDiyidCxFjc+rH+jIPI54z8fg8lzEJKhgRc00ACi Hg6KneycELwvodAhqhugKif+p1FiHAU3icTOqWQC7dphnF2XZMO/w2qwMaIna22LEyRR 9jApJxvl4CrUxPBL/tQpKf8GpbzdLSVDg/na71yqRhj1Hc8h1AaKOctNUl22Uxwmeqa9 VQN2VESskc9XAyl0XR0HQvD/OMJocgNo6E9BuMBq5n81fHREl8UxNRfdFmDnJyg3iarU ux1EvB5CuqJ2gMZn6MFjHHduBnHmReMvyVYMowNO4xIkU16Qwszl4U+V2AsY6jYFAqml OVqA== X-Gm-Message-State: AJcUukeMaBekOKAiu49QXY9gshhtq67BgvCEctzIBRLf/D+mrVeHPvAA osnBqlssDfgwAt3rUgtvhPl7y91vEGU= X-Received: by 2002:a50:de88:: with SMTP id c8mr9572635edl.129.1548399783664; Thu, 24 Jan 2019 23:03:03 -0800 (PST) Received: from localhost ([49.248.181.51]) by smtp.gmail.com with ESMTPSA id h47sm11808656eda.8.2019.01.24.23.03.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Jan 2019 23:03:03 -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" , linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK) Subject: [PATCHv3 2/9] cpufreq: Auto-register the driver as a thermal cooling device if asked Date: Fri, 25 Jan 2019 12:32:22 +0530 Message-Id: <73e091e2d56d9fa6eb94feaed9fc2be30bf6da20.1548398851.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 | 21 +++++++++++++++++++++ 2 files changed, 27 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..c7eb59b8ce94 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -151,6 +152,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 +390,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 +425,17 @@ cpufreq_verify_within_cpu_limits(struct cpufreq_policy *policy) policy->cpuinfo.max_freq); } +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; +} + #ifdef CONFIG_CPU_FREQ void cpufreq_suspend(void); void cpufreq_resume(void); -- 2.17.1