From patchwork Fri Sep 11 12:02:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 53462 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id 67557215BF for ; Fri, 11 Sep 2015 12:04:28 +0000 (UTC) Received: by ladx5 with SMTP id x5sf8673146lad.1 for ; Fri, 11 Sep 2015 05:04:27 -0700 (PDT) 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=aq5M+zUJB6fQqA69Yw/PBQSUZQZE6banHCHTaOtsyxs=; b=KhR5V8K4LlMhhC6244LMCBhupXqLeiut+/z+50JAH6M4AL82L+KWSk/6S95gfeRBKz pEbJ8cIFjrMHD7Qm6ew9g/qDnTtdt2CS2ZP6WBm4C/1RQ6crDzJChoUa/F3JrI1JrzB9 l0ES98I52ojiX/d1J1TuchdhYhY6tvbM0rf//b16G1cvrj5lqU0FQoQuzyvq2ywR2gDp 8II7LbxpY1BjqubVIIR33GiDTWhTmVzWLj05vBdE4dUoWnQIkT4dx/Kvhzhv95mkN2Xp 0RLvy4nC1t9TDn4eBUvvZvNVr5KsWy7wywsA9d7A1LQjGXng0/fflAuyPl4hf2gwFmGL muTg== X-Gm-Message-State: ALoCoQkiyxkRyO/XTkXXSZCk5Z7ZxLMkc79xikN76IvS5tFs5iUUxokl7UNLUCZNnTN3HVcXLRO7 X-Received: by 10.152.6.201 with SMTP id d9mr6272641laa.6.1441973067478; Fri, 11 Sep 2015 05:04:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.170 with SMTP id x10ls323967lal.61.gmail; Fri, 11 Sep 2015 05:04:27 -0700 (PDT) X-Received: by 10.112.180.137 with SMTP id do9mr42210744lbc.78.1441973067273; Fri, 11 Sep 2015 05:04:27 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id tg9si3918lbb.70.2015.09.11.05.04.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2015 05:04:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbbmp1 with SMTP id mp1so38387836lbb.1 for ; Fri, 11 Sep 2015 05:04:27 -0700 (PDT) X-Received: by 10.152.18.194 with SMTP id y2mr41678498lad.88.1441973067144; Fri, 11 Sep 2015 05:04:27 -0700 (PDT) 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.59.35 with SMTP id w3csp1546006lbq; Fri, 11 Sep 2015 05:04:26 -0700 (PDT) X-Received: by 10.50.50.198 with SMTP id e6mr3115519igo.13.1441973066019; Fri, 11 Sep 2015 05:04:26 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t11si163685ioi.49.2015.09.11.05.04.25; Fri, 11 Sep 2015 05:04:26 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753332AbbIKMEW (ORCPT + 28 others); Fri, 11 Sep 2015 08:04:22 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:33111 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752746AbbIKMES (ORCPT ); Fri, 11 Sep 2015 08:04:18 -0400 Received: by pacex6 with SMTP id ex6so73898032pac.0 for ; Fri, 11 Sep 2015 05:04:17 -0700 (PDT) X-Received: by 10.68.226.134 with SMTP id rs6mr95531621pbc.11.1441973057567; Fri, 11 Sep 2015 05:04:17 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id ll8sm13476pab.39.2015.09.11.05.04.16 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 11 Sep 2015 05:04:16 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , nm@ti.com, sboyd@codeaurora.org Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, rob.herring@linaro.org, lee.jones@linaro.org, Viresh Kumar , Bartlomiej Zolnierkiewicz , Dmitry Torokhov , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Pavel Machek Subject: [PATCH 14/16] PM / OPP: Add dev_pm_opp_set_regulator() to specify regulator Date: Fri, 11 Sep 2015 17:32:10 +0530 Message-Id: <1d8a3dabc6a0f46d1e94df0cbfec894c74e023a3.1441972771.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@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.173 as permitted sender) smtp.mailfrom=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: , The new OPP V2 bindings have a way to find supplies for a particular device. But the old V1 bindings doesn't have any API to do it today. This is required in order to move the complexity of switching OPPs (i.e. changing clock and voltages), into the OPP core, rather then keeping that in individual drivers. This patch adds another API, to be used only for V1 bindings, which first finds the regulator for the dev_opp and then disables all OPPs that aren't supported by the regulator. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 74 ++++++++++++++++++++++++++++++++++++++++++- include/linux/pm_opp.h | 6 ++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index a04dcacb8a07..4ee0911b97ea 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -970,6 +970,73 @@ static bool opp_supported_by_regulators(struct dev_pm_opp *opp, return true; } +/** + * dev_pm_opp_set_regulator() - Set regulator for the device OPP + * @dev: Device for which the regulator has to be set. + * @id: String used to find regulator. + * + * This is only required for the V1 bindings, as regulator is automatically + * found for the V2 bindings. OPP core finds a regulator with name -supply, + * and then get/put it automatically. The name of the debugfs files isn't + * changed however, to keep it simple. They are named as _*. + */ +int dev_pm_opp_set_regulator(struct device *dev, const char *id) +{ + struct device_opp *dev_opp; + struct dev_pm_opp *opp; + struct regulator *reg; + int ret = 0; + + rcu_read_lock(); + + dev_opp = _find_device_opp(dev); + if (IS_ERR(dev_opp)) { + ret = PTR_ERR(dev_opp); + dev_err(dev, "%s: no device opp found: %d\n", __func__, ret); + goto unlock; + } + + /* Do we already have a regulator attached to this dev_opp? */ + if (!IS_ERR_OR_NULL(*dev_opp->regulators)) { + dev_err(dev, "%s: can't add (%s), regulator already present\n", + __func__, id); + ret = -EINVAL; + goto unlock; + } + + reg = regulator_get_optional(dev, id); + + /* + * Few platforms may not have regulators for the device, and we need to + * save error number in that case as well. + */ + *dev_opp->regulators = reg; + + if (IS_ERR(reg)) { + ret = PTR_ERR(reg); + if (ret != -EPROBE_DEFER) + dev_err(dev, "%s: no regulator (%s) found: %d\n", + __func__, id, ret); + goto unlock; + } + + list_for_each_entry_rcu(opp, &dev_opp->opp_list, node) { + /* Disable OPPs, that aren't supported by the regulator */ + if (opp_supported_by_regulators(opp, dev_opp)) + continue; + + opp->available = false; + dev_warn(dev, "%s: disabled OPP (%lu), not supported by regulator (%s)\n", + __func__, opp->rate, id); + } + +unlock: + rcu_read_unlock(); + + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_set_regulator); + /* returns the number of entries used from microvolt */ static void opp_parse_single_supply(struct opp_supply *supply, bool triplet, u32 *microvolt, u32 *microamp) @@ -1493,9 +1560,14 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) if (IS_ERR(reg)) { ret = PTR_ERR(reg); if (ret != -EPROBE_DEFER) + dev_err(dev, "%s: deferring, no regulator (%s) found: %d\n", + __func__, *name, ret); + /* Regulator may not be compulsory for the device */ + if (!string_count) dev_err(dev, "%s: no regulator (%s) found: %d\n", __func__, *name, ret); - goto free_table; + else + goto free_table; } dev_opp->regulators[count] = reg; } diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index e36f347ff32b..e8aee03b974a 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -57,6 +57,7 @@ int dev_pm_opp_enable(struct device *dev, unsigned long freq); int dev_pm_opp_disable(struct device *dev, unsigned long freq); struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev); +int dev_pm_opp_set_regulator(struct device *dev, const char *id); #else static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) { @@ -141,6 +142,11 @@ static inline struct srcu_notifier_head *dev_pm_opp_get_notifier( { return ERR_PTR(-EINVAL); } + +static inline int dev_pm_opp_set_regulator(struct device *dev, const char *id) +{ + return -EINVAL; +} #endif /* CONFIG_PM_OPP */ #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)