From patchwork Wed Feb 11 08:16:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 44551 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f198.google.com (mail-we0-f198.google.com [74.125.82.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 595112151F for ; Wed, 11 Feb 2015 08:17:39 +0000 (UTC) Received: by mail-we0-f198.google.com with SMTP id u56sf1170743wes.1 for ; Wed, 11 Feb 2015 00:17:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=hYAvqkh4yWq2EKnk1yHdvEnyMg+MnGrI4cq8Dfu/YPY=; b=jk4Q/y1WaxxNoqKHMADZ2znW2rGYVPGMTAxE0qxJXiP/8xZBCu1L1p07aSWoSds1g8 Ym8zde8mowEW2V/s3dho0LO2TnEMYODZVXdSfSIBNvuGIPh0g4axSDq/hDJ0WIAMIMQS oSLK0cs8/NRMQalUny3Vg18mfXieNuU3FwwHdPzggNM7vC42JhLPEKYwDxWNcE1GFr5N 4YEo5vjDD8PVfPRDAYD/g/lTvZMy2v91f4snXaYt1XgcXJJMDBtDx8nHkuWMsugwqw4u DgUR0/+5czs6eXkYPtyqRGafaDyOc6PFeEXhZF7jge0BFOF5iy3aF2sj/D9idQ3kwuu+ UNOQ== X-Gm-Message-State: ALoCoQlF1vRmEmWe3Dug0iXlhTWKTlfGV9hvaiBzccizKX4gyCA2pJjtRu1J1YUsXru30FqKAGgd X-Received: by 10.112.168.104 with SMTP id zv8mr3242665lbb.10.1423642658637; Wed, 11 Feb 2015 00:17:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.137 with SMTP id y9ls33945laj.59.gmail; Wed, 11 Feb 2015 00:17:38 -0800 (PST) X-Received: by 10.112.77.137 with SMTP id s9mr21644888lbw.55.1423642658503; Wed, 11 Feb 2015 00:17:38 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id an6si13743768lbc.129.2015.02.11.00.17.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:17:38 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id b6so1683071lbj.12 for ; Wed, 11 Feb 2015 00:17:38 -0800 (PST) X-Received: by 10.152.6.101 with SMTP id z5mr26979430laz.19.1423642658401; Wed, 11 Feb 2015 00:17:38 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1102961lbj; Wed, 11 Feb 2015 00:17:37 -0800 (PST) X-Received: by 10.66.66.238 with SMTP id i14mr18039471pat.27.1423642639177; Wed, 11 Feb 2015 00:17:19 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pn5si73267pbb.72.2015.02.11.00.17.17; Wed, 11 Feb 2015 00:17:19 -0800 (PST) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752021AbbBKIRQ (ORCPT + 5 others); Wed, 11 Feb 2015 03:17:16 -0500 Received: from mail-pd0-f174.google.com ([209.85.192.174]:39170 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751927AbbBKIRP (ORCPT ); Wed, 11 Feb 2015 03:17:15 -0500 Received: by pdjy10 with SMTP id y10so2894701pdj.6 for ; Wed, 11 Feb 2015 00:17:14 -0800 (PST) X-Received: by 10.70.102.35 with SMTP id fl3mr44008385pdb.30.1423642634596; Wed, 11 Feb 2015 00:17:14 -0800 (PST) Received: from localhost ([210.177.145.249]) by mx.google.com with ESMTPSA id ms4sm49386pbc.92.2015.02.11.00.17.13 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 11 Feb 2015 00:17:14 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , rob.herring@linaro.org Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, arnd.bergmann@linaro.org, grant.likely@linaro.org, olof@lixom.net, nm@ti.com, Sudeep.Holla@arm.com, sboyd@codeaurora.org, devicetree@vger.kernel.org, santosh.shilimkar@oracle.com, mike.turquette@linaro.org, kesavan.abhilash@gmail.com, catalin.marinas@arm.com, ta.omasab@gmail.com, linux-arm-kernel@lists.infradead.org, thomas.petazzoni@free-electrons.com, l.stach@pengutronix.de, broonie@kernel.org, viswanath.puttagunta@linaro.org, Viresh Kumar Subject: [PATCH 6/7] opp: Add helpers for initializing CPU opps Date: Wed, 11 Feb 2015 16:16:29 +0800 Message-Id: <6bd4f6207604d97c0fd46ee39b0d296d5208ac68.1423642246.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.3.0.rc0.44.ga94655d In-Reply-To: References: In-Reply-To: References: Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This provides helpers to find which CPUs share OPPs and initialize OPPs for them. Signed-off-by: Viresh Kumar --- drivers/base/power/opp.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 17 +++++++ 2 files changed, 130 insertions(+) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 24a014b7a68a..751f56f323bf 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -11,6 +11,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -1321,6 +1322,44 @@ int of_init_opp_table(struct device *dev) } EXPORT_SYMBOL_GPL(of_init_opp_table); +int of_cpumask_init_opp_table(cpumask_var_t cpumask) +{ + struct device *cpu_dev; + int cpu, tcpu, ret = 0; + + if (cpumask_empty(cpumask)) + return -EINVAL; + + for_each_cpu(cpu, cpumask) { + cpu_dev = get_cpu_device(cpu); + if (!cpu_dev) { + pr_err("%s: failed to get cpu%d device\n", __func__, + cpu); + continue; + } + + ret = of_init_opp_table(cpu_dev); + if (ret) { + pr_err("%s: couldn't find opp table for cpu:%d, %d\n", + __func__, cpu, ret); + + /* Free all other OPPs */ + for_each_cpu(tcpu, cpumask) { + if (cpu == tcpu) + break; + + cpu_dev = get_cpu_device(tcpu); + if (cpu_dev) + of_free_opp_table(cpu_dev); + } + break; + } + } + + return ret; +} +EXPORT_SYMBOL_GPL(of_cpumask_init_opp_table); + /** * of_free_opp_table() - Free OPP table entries created from static DT entries * @dev: device pointer used to lookup device OPPs. @@ -1368,4 +1407,78 @@ void of_free_opp_table(struct device *dev) mutex_unlock(&dev_opp_list_lock); } EXPORT_SYMBOL_GPL(of_free_opp_table); + +void of_cpumask_free_opp_table(cpumask_var_t cpumask) +{ + struct device *cpu_dev; + int cpu; + + WARN_ON(cpumask_empty(cpumask)); + + for_each_cpu(cpu, cpumask) { + cpu_dev = get_cpu_device(cpu); + if (!cpu_dev) { + pr_err("%s: failed to get cpu%d device\n", __func__, + cpu); + continue; + } + + of_free_opp_table(cpu_dev); + } +} +EXPORT_SYMBOL_GPL(of_cpumask_free_opp_table); + +/* Works only for OPP v2 bindings */ +int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask) +{ + struct device_node *np, *tmp_np; + struct device *tcpu_dev; + int cpu, ret = 0; + + cpumask_set_cpu(cpu_dev->id, cpumask); + + /* Get OPP descriptor node */ + np = of_get_opp_desc_node(cpu_dev); + if (IS_ERR(np)) { + dev_info(cpu_dev, "%s: Couldn't find opp node: %ld\n", __func__, + PTR_ERR(np)); + return -EINVAL; + } + + /* OPPs are shared ? */ + if (!of_get_property(np, "shared-opp", NULL)) + goto put_cpu_node; + + for_each_possible_cpu(cpu) { + if (cpu == cpu_dev->id) + continue; + + tcpu_dev = get_cpu_device(cpu); + if (!tcpu_dev) { + pr_err("failed to get cpu%d device\n", cpu); + ret = -ENODEV; + goto put_cpu_node; + } + + /* Get OPP descriptor node */ + tmp_np = of_get_opp_desc_node(tcpu_dev); + if (IS_ERR(tmp_np)) { + dev_info(tcpu_dev, "%s: Couldn't find opp node: %ld\n", + __func__, PTR_ERR(np)); + ret = -EINVAL; + goto put_cpu_node; + } + + /* CPUs are sharing opp node */ + if (np == tmp_np) + cpumask_set_cpu(cpu, cpumask); + + of_node_put(tmp_np); + } + +put_cpu_node: + of_node_put(np); + return ret; +} +EXPORT_SYMBOL_GPL(of_get_cpus_sharing_opps); #endif diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 9949d07a93f9..41cbc7469b5a 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -115,6 +115,9 @@ static inline struct srcu_notifier_head *dev_pm_opp_get_notifier( #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) int of_init_opp_table(struct device *dev); void of_free_opp_table(struct device *dev); +int of_cpumask_init_opp_table(cpumask_var_t cpumask); +void of_cpumask_free_opp_table(cpumask_var_t cpumask); +int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask); struct device_node *of_get_opp_desc_node(struct device *dev); #else static inline int of_init_opp_table(struct device *dev) @@ -126,6 +129,20 @@ static inline void of_free_opp_table(struct device *dev) { } +static inline int of_cpumask_init_opp_table(cpumask_var_t cpumask) +{ + return -EINVAL; +} + +static inline void of_cpumask_free_opp_table(cpumask_var_t cpumask) +{ +} + +static inline int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask) +{ + return -EINVAL; +} + static inline struct device_node *of_get_opp_desc_node(struct device *dev) { return ERR_PTR(-EINVAL);