From patchwork Mon Apr 9 11:43:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 133029 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp168256ljb; Mon, 9 Apr 2018 04:44:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx49OFIxRosBUGh71AQQ2AoVwt84E6rlA7z4s3ce4gJ39va4rd2hdp4ypLgXrBbb82VTekGbL X-Received: by 10.101.76.207 with SMTP id n15mr25371059pgt.313.1523274267095; Mon, 09 Apr 2018 04:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523274267; cv=none; d=google.com; s=arc-20160816; b=RmasGHseUFKvzMIFRX5RahVjm7OTVDd7iqtMT9qx3aFi5C2iWWTJxHnnXU37Bs4dLh BjMO3+RnlhBm0h5R/d0Fr7nO/abTvBMlF8QjDOiKkkXuSS3qceZ5I/5qu6jPykgQwZz3 MfoF1JsvMkzbyyp8Mk0gv+YLkhPFpGVQRlDNTjjooxeUgdz0w4tFYI1/9kCV1Qv/IpFy F3pO8Ig0KoitnqmD5qD2drJDLFMlzywia8GU6PuE+bdYtgp6XNCjSBsIbHdw2CGwbgBH vjzXZhVi2vQ0oLLAAvxaCpUeF+AxlKpRmO8CvTzN/lHYStbzT/q26eBpBn3RWN04hDgD wTNw== 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 :arc-authentication-results; bh=Dyz16f/J6MR66QggqKEx5zGMjJYj7H8uGvs95bHqvQg=; b=MwQykeLXBMiSUhncQJf56rfozdXS8afGyJwvkl+V5DhTjneBxPLPJ/C+TRDnADeTer 5RpbHQsyvwVxlvTOaeebm70kKY2yabeyXzqMMo5I31EggIS0L8OC+rkGE7jNIXN31Q42 skqchEYlpM3yKS98iQJHEvldlwKcQggNsuiaFZxisdyUNlF+gqFAic5YuTyxBbxysK6a HMKi9/T43zRgAt6umxYXNr7Qg1mdgcitYLIMUbctzroQID2p4FC9T2yGOv+jY+tyHjX1 wiBg4KE6VP1JZ4H+DYO57WBxdoMwiIFeFD62i+bdJNaX7VvhlzYpbb3XpKqbRjv0WGrB /ogQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FtuLRDJ0; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 j188si105815pgc.584.2018.04.09.04.44.26; Mon, 09 Apr 2018 04:44:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=FtuLRDJ0; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1751738AbeDILo0 (ORCPT + 11 others); Mon, 9 Apr 2018 07:44:26 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35028 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751581AbeDILoZ (ORCPT ); Mon, 9 Apr 2018 07:44:25 -0400 Received: by mail-pf0-f196.google.com with SMTP id u86so5661316pfd.2 for ; Mon, 09 Apr 2018 04:44:25 -0700 (PDT) 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=Dyz16f/J6MR66QggqKEx5zGMjJYj7H8uGvs95bHqvQg=; b=FtuLRDJ0Mf/B1F9Nh6ATOJLo3sehbbtzbogVzrVydk1g8eGyE2QNHkoS0CwFBKpuVy mNP5hBUFjMEOoo/efE2n09KJV9L3VYLuZyhJejDeZD22c1BFwAJPq1a6UZbskm5YmmVS cHIze0nfGs2drENunramYofcma3tUlPlaemBg= 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=Dyz16f/J6MR66QggqKEx5zGMjJYj7H8uGvs95bHqvQg=; b=Oya/lS7VIp+MNKrNZXOVoJD645ykkOlf3qx+rt1z6phm8YPx5AEPHBY22ph6Lvuw4u hAv0tAYKiCLnf7z4NqPpPTXVGZqXoPZINkD7C5LeRifnmfw6Vg1SkxhWUng2oq/5DhfW zDMjZBohU9YkSEeZpuSndtLi9bP2lT5ISaMfscxC1IIKOv7rtXMuM7nuV/zksH3fBbye 0EK5y9mx4O/Ia02SK9TJCVODWjbdQ3dR9D2P1tiVC41Z3M2lTlLguXPl+sY2mKwRt+8J pY4tW7Yt/UG0tKt+2FU5CyDeI8eu5r6To2EOL55IP9X57esJvRbchJ/I4kpSKuREDi/V m3Yg== X-Gm-Message-State: AElRT7FIlVJPgWCLH99S5UcwbXRhaKJq+h8qzh7Ue0vv/jWFgSpDYZj4 6g4+QaEcV7vgsIR9qkPWrcMm/g== X-Received: by 10.99.136.194 with SMTP id l185mr25303738pgd.419.1523274265028; Mon, 09 Apr 2018 04:44:25 -0700 (PDT) Received: from localhost ([122.171.228.188]) by smtp.gmail.com with ESMTPSA id u6sm451590pgo.1.2018.04.09.04.44.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Apr 2018 04:44:24 -0700 (PDT) From: Viresh Kumar To: Ulf Hansson , Stephen Boyd , Viresh Kumar , Nishanth Menon , "Rafael J. Wysocki" Cc: Viresh Kumar , Rajendra Nayak , Vincent Guittot , linux-pm@vger.kernel.org Subject: [PATCH V2 05/11] PM / OPP: Implement of_dev_pm_opp_find_required_opp() Date: Mon, 9 Apr 2018 17:13:45 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org A device's DT node or its OPP nodes can contain a phandle to other device's OPP node, in the "required-opps" property. This patch implements a routine to find that required OPP from the node that contains the "required-opps" property. Signed-off-by: Viresh Kumar Reviewed-by: Ulf Hansson --- drivers/opp/core.c | 4 +--- drivers/opp/of.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/opp/opp.h | 1 + include/linux/pm_opp.h | 6 ++++++ 4 files changed, 62 insertions(+), 3 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index a0f72c732718..416f54ba7a26 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -33,8 +33,6 @@ LIST_HEAD(opp_tables); /* Lock to allow exclusive modification to the device and opp lists */ DEFINE_MUTEX(opp_table_lock); -static void dev_pm_opp_get(struct dev_pm_opp *opp); - static struct opp_device *_find_opp_dev(const struct device *dev, struct opp_table *opp_table) { @@ -901,7 +899,7 @@ static void _opp_kref_release(struct kref *kref) dev_pm_opp_put_opp_table(opp_table); } -static void dev_pm_opp_get(struct dev_pm_opp *opp) +void dev_pm_opp_get(struct dev_pm_opp *opp) { kref_get(&opp->kref); } diff --git a/drivers/opp/of.c b/drivers/opp/of.c index cba669cd00c5..6380ec3d695b 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -673,3 +673,57 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, return ret; } EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus); + +/** + * of_dev_pm_opp_find_required_opp() - Search for required OPP. + * @dev: The device whose OPP node is referenced by the 'np' DT node. + * @np: Node that contains the "required-opps" property. + * + * Returns the OPP of the device 'dev', whose phandle is present in the "np" + * node. Although the "required-opps" property supports having multiple + * phandles, this helper routine only parses the very first phandle in the list. + * + * Return: Matching opp, else returns ERR_PTR in case of error and should be + * handled using IS_ERR. + * + * The callers are required to call dev_pm_opp_put() for the returned OPP after + * use. + */ +struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, + struct device_node *np) +{ + struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ENODEV); + struct device_node *required_np; + struct opp_table *opp_table; + + opp_table = _find_opp_table(dev); + if (IS_ERR(opp_table)) + return ERR_CAST(opp_table); + + required_np = of_parse_phandle(np, "required-opps", 0); + if (unlikely(!required_np)) { + dev_err(dev, "Unable to parse required-opps\n"); + goto put_opp_table; + } + + mutex_lock(&opp_table->lock); + + list_for_each_entry(temp_opp, &opp_table->opp_list, node) { + if (temp_opp->available && temp_opp->np == required_np) { + opp = temp_opp; + + /* Increment the reference count of OPP */ + dev_pm_opp_get(opp); + break; + } + } + + mutex_unlock(&opp_table->lock); + + of_node_put(required_np); +put_opp_table: + dev_pm_opp_put_opp_table(opp_table); + + return opp; +} +EXPORT_SYMBOL_GPL(of_dev_pm_opp_find_required_opp); diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 381a4fb15d5c..f9eccf9811ae 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -187,6 +187,7 @@ struct opp_table { }; /* Routines internal to opp core */ +void dev_pm_opp_get(struct dev_pm_opp *opp); void _get_opp_table_kref(struct opp_table *opp_table); int _get_opp_count(struct opp_table *opp_table); struct opp_table *_find_opp_table(struct device *dev); diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index f042fdeaaa3c..70686f434c13 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -309,6 +309,7 @@ int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask); void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask); int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev); +struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np); #else static inline int dev_pm_opp_of_add_table(struct device *dev) { @@ -342,6 +343,11 @@ static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device { return NULL; } + +static inline struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np) +{ + return NULL; +} #endif #endif /* __LINUX_OPP_H__ */