From patchwork Mon Mar 20 09:32:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 95485 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp852614qgd; Mon, 20 Mar 2017 02:33:40 -0700 (PDT) X-Received: by 10.98.137.75 with SMTP id v72mr32143364pfd.190.1490002420683; Mon, 20 Mar 2017 02:33:40 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g21si16849481pgh.125.2017.03.20.02.33.39; Mon, 20 Mar 2017 02:33:40 -0700 (PDT) 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; 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 S1753794AbdCTJde (ORCPT + 23 others); Mon, 20 Mar 2017 05:33:34 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:34604 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752945AbdCTJcq (ORCPT ); Mon, 20 Mar 2017 05:32:46 -0400 Received: by mail-pg0-f41.google.com with SMTP id 21so41260787pgg.1 for ; Mon, 20 Mar 2017 02:32:45 -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=b1/unE8WWBT9vN1SczLDRGVUSz20jLQgbXzKmlFzS0w=; b=dOkEG3cE4fijKhDpeupsaF6BNucO/YJVcSQknalR1nJFdnprWonoySbFouEJ0UTIuA Jb9cMXWEz4GLM11/UgUpsi+FKaqjD02Dly8ODfogld9b8X38tJA/9pnknS7Y96atYi50 mELGvbXmRsDz1Mv3n59u2cfzJoWeYmmvIpvHg= 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=b1/unE8WWBT9vN1SczLDRGVUSz20jLQgbXzKmlFzS0w=; b=L6zuTvp6vPjTYYsRcyUoLLdcuoB8kI6PyaBNyx65BHBwpGVkYC7VAA8qAfppyWrJb+ TFSqJNFt2bClMKCetKYeB/NIE18ZOFtCxu7qQYl2Li9YPg0EjAzI/Dz1WIK4vnWg+JQ0 iXuAkA03U/KlnlVeNeDvDmjwJJCTDcYH04mpM+G8VN9/BosrfjK7BPvl2/cjwx8tvNFZ yObZSSds4uVDG/ZqDW7oh9k3nAuMCO/baOlVGNEJrQHfj3EV9WJ2KUohWT1V4ujijnuS ecm+Sttts5SxzjHuURliAdi6JrJfb4wKcxruWboklhI0hiD5pl3j5OUzLG2y6h4QKAvq YA9A== X-Gm-Message-State: AFeK/H1MkxdmeUT1tMYmBbZYDziryECiK13ETDFOKnSRmsSVgxtHI56dNzIBGHuRQ9xqdzRL X-Received: by 10.98.36.151 with SMTP id k23mr29401145pfk.53.1490002365385; Mon, 20 Mar 2017 02:32:45 -0700 (PDT) Received: from localhost ([122.171.239.200]) by smtp.gmail.com with ESMTPSA id p6sm32162192pgn.40.2017.03.20.02.32.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Mar 2017 02:32:44 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ulf.hansson@linaro.org, Kevin Hilman , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , robh+dt@kernel.org, lina.iyer@linaro.org, rnayak@codeaurora.org, Viresh Kumar Subject: [PATCH V4 6/9] PM / OPP: Add dev_pm_opp_find_dps() helper Date: Mon, 20 Mar 2017 15:02:18 +0530 Message-Id: <746e4e6f040cefb280569754cebd49db57d58d59.1490001099.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 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 This patch adds dev_pm_opp_find_dps() helper to get the OPP node for a domain-performance-state. This helper is only supported for tables representing power domains. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 66 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 8 ++++++ 2 files changed, 74 insertions(+) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index c435acb21a47..212f11d65790 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -503,6 +503,72 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); +/** + * dev_pm_opp_find_dps() - search for an exact domain-performance-state + * @dev: device for which we do this operation + * @dps: domain-performance-state + * @available: true/false - match for available opp + * + * Return: Searches for exact match in the opp table and returns pointer to the + * matching opp if found, else returns ERR_PTR in case of error and should + * be handled using IS_ERR. Error return values can be: + * EINVAL: for bad pointer + * ERANGE: no match found for search + * ENODEV: if device not found in list of registered devices + * + * Note: available is a modifier for the search. if available=true, then the + * match is for exact matching domain-performance-state and is available in the + * stored OPP table. if false, the match is for exact domain-performance-state + * which is not available. + * + * This provides a mechanism to enable an opp which is not available currently + * or the opposite as well. + * + * The callers are required to call dev_pm_opp_put() for the returned OPP after + * use. + */ +struct dev_pm_opp *dev_pm_opp_find_dps(struct device *dev, unsigned int dps, + bool available) +{ + struct opp_table *opp_table; + struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-EINVAL); + + opp_table = _find_opp_table(dev); + if (IS_ERR(opp_table)) { + int r = PTR_ERR(opp_table); + + dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r); + return ERR_PTR(r); + } + + /* This API is only supported for tables representing power domains */ + if (WARN_ON(!opp_table->is_domain)) + goto put_table; + + opp = ERR_PTR(-ERANGE); + + mutex_lock(&opp_table->lock); + + list_for_each_entry(temp_opp, &opp_table->opp_list, node) { + if (temp_opp->available == available && + temp_opp->domain_perf_state == dps) { + opp = temp_opp; + + /* Increment the reference count of OPP */ + dev_pm_opp_get(opp); + break; + } + } + + mutex_unlock(&opp_table->lock); + +put_table: + dev_pm_opp_put_opp_table(opp_table); + + return opp; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_find_dps); + static int _set_opp_voltage(struct device *dev, struct regulator *reg, struct dev_pm_opp_supply *supply) { diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index a6685b3dde26..11d3ff4de4b0 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -102,6 +102,8 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, unsigned long *freq); +struct dev_pm_opp *dev_pm_opp_find_dps(struct device *dev, unsigned int freq, + bool available); void dev_pm_opp_put(struct dev_pm_opp *opp); int dev_pm_opp_add(struct device *dev, unsigned long freq, @@ -194,6 +196,12 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, return ERR_PTR(-ENOTSUPP); } +static inline struct dev_pm_opp *dev_pm_opp_find_dps(struct device *dev, + unsigned int freq, bool available) +{ + return ERR_PTR(-ENOTSUPP); +} + static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,