From patchwork Fri Dec 22 07:26:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 122634 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1910029qgn; Thu, 21 Dec 2017 23:31:49 -0800 (PST) X-Google-Smtp-Source: ACJfBosZrryaetsgs5USMOIi6nGire0hPOiCEreyI7qGq3y5QQt5Wej8SEoJDKWW7u+hVTiJquNH X-Received: by 10.99.154.66 with SMTP id e2mr12100839pgo.8.1513927908923; Thu, 21 Dec 2017 23:31:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513927908; cv=none; d=google.com; s=arc-20160816; b=YTlfN++2UuDf4kYrhEVggOwUoFnqhWu7HyTLWRge4zYdGgoCkQIgl1xYAm7RK+3J6b hbjQEs/abkPWrb4cE9hW1Tjn3a2+Ul7kp4sjRBJQDr3fhNLLLwcKH1GKUO/nOPHdfoQ5 BjIQHEsD1R38Mdfnx37Y9KrN6vg7M4y9I/P7zuuVkLhF5+dct/tn3guaoHQFY0eeB49M QlAzLam0+CkbPpfRXgcjp+qs58fvAWQTLqJxJV1Ncpy248naUWYOVFAI6LLc4jb4vzMQ u3qom5E8KgKoCLtwhus4iDyWRpfOkTFYXqLGS4wcRYHWtncu41JXoULCtrnl1H2CmPd3 SU9w== 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=8Sh8IoYgJFrnf4eFvxRVA0oiwAdth8iBB9cshhpvsYw=; b=jyAgbpOaDTJWIGPx95u2giVM+estqtARKGT81wOmP55ztEN9ibofxJ5Di6D6XkOH+N hUrFDdzntx8Wco1c8qb0kYwYtZv9hCOKsEULt1jkHH974vHLr/9oNetocbn5qRhGM57p 4VpM/HshN2lPzDD1cCCMva6CmSfYWw8G+67Lh3Rvp6xsEC0XnlUzu8Af3LejbTqfS7Hn jelHK8PzRiIwLIRIbikC3ioFlT6glxr19wj7MAh0Et9JSc4dJ7CxtLrWzqzc2NoFY1Ox fh4irjJWwKbsGoTNQQfdHAy4v6bhVhS6L91Y3O6C1s1hHiR8P7sLkh+ohBVWoDBb3Gkz CeRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jqjI1zUu; 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 l5si14888688pgs.496.2017.12.21.23.31.48; Thu, 21 Dec 2017 23:31:48 -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=jqjI1zUu; 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 S1756020AbdLVHbq (ORCPT + 28 others); Fri, 22 Dec 2017 02:31:46 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:41424 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752968AbdLVHaR (ORCPT ); Fri, 22 Dec 2017 02:30:17 -0500 Received: by mail-pl0-f65.google.com with SMTP id g2so12479016pli.8 for ; Thu, 21 Dec 2017 23:30:17 -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=8Sh8IoYgJFrnf4eFvxRVA0oiwAdth8iBB9cshhpvsYw=; b=jqjI1zUukTBKcS9WwUAh9pZ8Lt3Zsyl8RJ/Je3fi2/DKAVQtO+4DiyJPhg8FneARdR 4oIh4My9UAkACcIOXjlhhf211qnsY5dK8FdKzCatHGIXShnlwb3b68cP00L/KAyVvY7W yyJf6Z4XPXoq2syib3iNRfw3IgG+DDSOh1c3c= 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=8Sh8IoYgJFrnf4eFvxRVA0oiwAdth8iBB9cshhpvsYw=; b=TQdQwKzsceeJe/j/8DrQknPVRh2FuUic2ulRN6mgwTg7mVtGh+4kPrt/61euy9VsRQ LrMnBghxkabs/apwS7o4iiZ45u5KHk545lvQBqjbDML89o3tQDJxgoVNVXnbHcLdJQxd CsaStPqwtVySGt1R5d6Wgo3Z5wt1IwRPLrzZW9bniDgCzKFHhsFXIlFA0XU4SlFVSS45 +bQu6bEOKJkT2rJAh5erAwsUhZ+G19Snk+VjHxQJ8QmEOEIi9BOa2THTD/yxthv5NiJh T7dUH41PPy+P2D0aubzjJqT85T1MQ11WYDWQgcPlQ2joKcGiYaZOqGEczPuTTBOayhW4 8mEA== X-Gm-Message-State: AKGB3mKNDGouQZFymAMowyULoAudhwUSJcck8q9Mi8jTci6Cafs7x4w0 X9UgaXkpv8WcUWGeuF2tTglicQ== X-Received: by 10.159.197.67 with SMTP id d3mr13304056plo.409.1513927816644; Thu, 21 Dec 2017 23:30:16 -0800 (PST) Received: from localhost ([122.172.139.116]) by smtp.gmail.com with ESMTPSA id q69sm42942579pfa.161.2017.12.21.23.30.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Dec 2017 23:30:15 -0800 (PST) From: Viresh Kumar To: ulf.hansson@linaro.org, Kevin Hilman , Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , robh+dt@kernel.org, rnayak@codeaurora.org, sudeep.holla@arm.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] PM / OPP: Implement of_dev_pm_opp_find_required_opp() Date: Fri, 22 Dec 2017 12:56:26 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 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 A device's DT node or its OPP nodes can contain a phandle to other device's OPP node, in the "required-opp" property. This patch implements a routine to find that required OPP from the node that contains the "required-opp" property. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 4 +--- drivers/opp/of.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/opp/opp.h | 1 + include/linux/pm_opp.h | 6 ++++++ 4 files changed, 61 insertions(+), 3 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 92fa94a6dcc1..bfcad8983fd1 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) { @@ -892,7 +890,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 22c9bd191f62..2d1bb348ae73 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -665,3 +665,56 @@ 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-opp" property. + * + * Returns the OPP of the device 'dev', whose phandle is present in the "np" + * node. + * + * 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-opp", 0); + if (unlikely(!required_np)) { + dev_err(dev, "Unable to parse required-opp\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 4d00061648a3..b181032e6938 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); struct opp_table *_find_opp_table(struct device *dev); struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table); 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__ */