From patchwork Thu Jul 25 10:41:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 169693 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp11464440ilk; Thu, 25 Jul 2019 03:42:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWGEyPpZjXK5WK+U2SMxTY4Ov82gWZ32s/XpeI20MBo9kkE28vlXcgUBsEdANE+Mh87xg4 X-Received: by 2002:a63:1d2:: with SMTP id 201mr51157866pgb.307.1564051324083; Thu, 25 Jul 2019 03:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564051324; cv=none; d=google.com; s=arc-20160816; b=TvWlIdhePUd9+QBfwTfgbQcyN/FWYGs43xROHzokN+y3gSk2C1Q1bSAx9ARw2hv5qg 3Dd2WpF/77mtp2ipBQfAnLh/p2DldFS3TSjjUBdcZJE2VrSmkiJ61c/iRjDn8KwGfV6x 7EvzNvW+DrYgv3iGX85p4sG8zU/iZ4iwNM+pr9yoqTNwaH2yomGPrRjMycjEJk4aXKNH vPBqtIXk36J+JjD09CKBJiZ3GGoeNjMXSrUvwjBtRHYU+6uK8JNmxpAuZvCBUaRzvSia xRHlloaxjgkBLUUfmlrlzWYF59133nJz1XNphRTDPC3U8O+ViAtxdxDAVm+du5hAfBu6 ZBiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OV03WyWjTcjS53n3WcFXDQeGooA4dZBwGcCk2JpHvuY=; b=Xje8y/ylV83QU2Vh/Wh1QWEjAcG0fMbIjjbqIWo1TcxGxLm5lCuBGjredwZ1+/Ko3v BMIAcY8T4bkLIPyELo4bndNj2t4qsLDPwA15ZDtEMe1Mvis/iPA5oCJ2LbwF+Pm1gvmm Is+bIxf9TD6TGhlFiLxh32LLmTrR+299eOeZ7XtuR+UMB5WnX3tckkfQ0Uq3a/eh2afo 0/cZLxZnx/0nDOP0edmvxQ1ZaGKiGplEorStheIswFOfoEzkKFB2ZIqmKQf3qBE4Uze/ UA7TTHFe+H2YKMIjLuoW1A1RW5dMLYtrs9cI5W56jAU49mWKzScAEimh2nWYRfhA4drk HM5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cD7WEF1d; 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 r185si15889653pgr.506.2019.07.25.03.42.03; Thu, 25 Jul 2019 03:42:04 -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 header.s=google header.b=cD7WEF1d; 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 S2388097AbfGYKmC (ORCPT + 29 others); Thu, 25 Jul 2019 06:42:02 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:37236 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387696AbfGYKl5 (ORCPT ); Thu, 25 Jul 2019 06:41:57 -0400 Received: by mail-lj1-f193.google.com with SMTP id z28so47600763ljn.4 for ; Thu, 25 Jul 2019 03:41:56 -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 :mime-version:content-transfer-encoding; bh=OV03WyWjTcjS53n3WcFXDQeGooA4dZBwGcCk2JpHvuY=; b=cD7WEF1d3w11OaswaTxy8+jt2pkiE/tHnii41Xg5HuGHyfS+QOx8FWWNiKSeRF8H5r jMyERhR7jsC2WM+VCEyOIYhHb86Trnpcu5JKHOLnAtN7BgqShaSnN8V2YzCqrBLPdqf9 iMrluiDf2YQtdR7gDDDuT417DPCGaX05oZNsT7MUvkOU/3xvwkHoN+oWnprXZJ83oGUe 4YA6RXLTTqkBzQAW4zg1x4n4bDzLdHT0DrfsVoQnQf/i0yTipf6KGyX/KD7AEZ9OKfyo kpc58nVx8ZxkOD6T6IsEc6n3vGgRAOk2xVCFw9hCMbJSzH3qE6GTvJFNA6wV01xCpeCF IgeQ== 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:mime-version:content-transfer-encoding; bh=OV03WyWjTcjS53n3WcFXDQeGooA4dZBwGcCk2JpHvuY=; b=ig6bXQgmVIcvV7vZrJ2UhrNXUOUCnFEY0V8V+DV2P+aWlL+Gx3mW5gU79wY6BLPekn 172rBail5wLxxVjQvspNkBIOPltHH5xGyAeIS+IAZ66fORFDgD0Ci8PpcU5apdzX7dgs b+Z93j6WrgZEfyT96pK92wenD8kOuAR/S6O8KWRYcwik6hULHJrcszFjNlPLERBbJiER aGya2p0T5KpEyDCtLhHdakT8wT7eWBWVQXG5L5nM505T7MKLiGSRe2w6E0ln9u1k0Pg4 tnmx5U7fYh3uHMj/DTlo0Wq0FDSk22D6tsRRjzfwrdkoS0gUAjy8G9UvmYW7RSpICKl9 Oswg== X-Gm-Message-State: APjAAAUUAeSzGcx72F5pfGZlI/lKYwSn3aqepCdRJ7541mcL3dAEDvV6 obX0yToqmRMj8CSW1DTWd7rjHw== X-Received: by 2002:a2e:87d0:: with SMTP id v16mr6292605ljj.24.1564051315743; Thu, 25 Jul 2019 03:41:55 -0700 (PDT) Received: from localhost.localdomain (ua-83-226-44-230.bbcust.telenor.se. [83.226.44.230]) by smtp.gmail.com with ESMTPSA id b6sm8268306lfa.54.2019.07.25.03.41.54 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 25 Jul 2019 03:41:55 -0700 (PDT) From: Niklas Cassel To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: linux-arm-msm@vger.kernel.org, jorge.ramirez-ortiz@linaro.org, bjorn.andersson@linaro.org, ulf.hansson@linaro.org, Niklas Cassel , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/14] opp: Add dev_pm_opp_find_level_exact() Date: Thu, 25 Jul 2019 12:41:29 +0200 Message-Id: <20190725104144.22924-2-niklas.cassel@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190725104144.22924-1-niklas.cassel@linaro.org> References: <20190725104144.22924-1-niklas.cassel@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When using performance states, there is usually not any opp-hz property specified, so the dev_pm_opp_find_freq_exact() function cannot be used. Since the performance states in the OPP table are unique, implement a dev_pm_opp_find_level_exact() in order to be able to fetch a specific OPP. Signed-off-by: Niklas Cassel --- drivers/opp/core.c | 48 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 8 +++++++ 2 files changed, 56 insertions(+) -- 2.21.0 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index cac3e4005045..3b7ffd0234e9 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -401,6 +401,54 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact); +/** + * dev_pm_opp_find_level_exact() - search for an exact level + * @dev: device for which we do this operation + * @level: level to search for + * + * 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 + * + * The callers are required to call dev_pm_opp_put() for the returned OPP after + * use. + */ +struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, + unsigned int level) +{ + struct opp_table *opp_table; + struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); + + 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); + } + + mutex_lock(&opp_table->lock); + + list_for_each_entry(temp_opp, &opp_table->opp_list, node) { + if (temp_opp->level == level) { + opp = temp_opp; + + /* Increment the reference count of OPP */ + dev_pm_opp_get(opp); + break; + } + } + + mutex_unlock(&opp_table->lock); + dev_pm_opp_put_opp_table(opp_table); + + return opp; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_exact); + static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table, unsigned long *freq) { diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 5bdceca5125d..b8197ab014f2 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -96,6 +96,8 @@ unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev); struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned long freq, bool available); +struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, + unsigned int level); struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, unsigned long *freq); @@ -200,6 +202,12 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, return ERR_PTR(-ENOTSUPP); } +static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, + unsigned int level) +{ + return ERR_PTR(-ENOTSUPP); +} + static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, unsigned long *freq) {