From patchwork Fri Sep 11 12:02:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 53456 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by patches.linaro.org (Postfix) with ESMTPS id 212E0215BF for ; Fri, 11 Sep 2015 12:03:44 +0000 (UTC) Received: by lamp12 with SMTP id p12sf24570433lam.2 for ; Fri, 11 Sep 2015 05:03:42 -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=hdtzUVxuECBtQPj528QUjS5guAxBC5JGQ0uaQkY6+E0=; b=lXnpCfaiTwMr2i/uVboCZuqikoavRqLTHFyjQ37kOcj5dZjO39KUd62PDCxtpeRLdw VVcOfhaDXbLaD+APPJ9k1LrxDtT/PGcWkwfVuP9af5uU99tSkOhlI3d/JSVoS7J+/YGR KR/f/8NarEaYnV6olNvuNAYyuhzpiapelV/l3nenSDzFOvtDAzkONcCmuftkZO1IWiAj N+XDQHzsw07bVJ/Ogh7fha1ny/oV+2G2inki7HZtuuEiekvUo+aM1NxJN/EFp8J0F5Gc ZJeoRQzbfBPcTz3qa98Qr9DIWM2++0P68t2OybuZmC0Hj8ZEnpeUXk2U16N55Y14+M3p he4w== X-Gm-Message-State: ALoCoQk0Wja0lzOUv3DYxObV1p9l6WT2CB4wbRDR3zKxUkBuM/XMLdRpM0zsdiHaCPQObNLailaK X-Received: by 10.194.57.200 with SMTP id k8mr1540981wjq.2.1441973022748; Fri, 11 Sep 2015 05:03:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.198 with SMTP id le6ls303698lab.56.gmail; Fri, 11 Sep 2015 05:03:42 -0700 (PDT) X-Received: by 10.152.26.135 with SMTP id l7mr25443295lag.59.1441973022578; Fri, 11 Sep 2015 05:03:42 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id sc1si35854lbb.8.2015.09.11.05.03.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2015 05:03:42 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by lahg1 with SMTP id g1so16311830lah.1 for ; Fri, 11 Sep 2015 05:03:42 -0700 (PDT) X-Received: by 10.152.203.134 with SMTP id kq6mr41915920lac.106.1441973022462; Fri, 11 Sep 2015 05:03:42 -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 w3csp1545484lbq; Fri, 11 Sep 2015 05:03:41 -0700 (PDT) X-Received: by 10.202.83.19 with SMTP id h19mr35506741oib.119.1441973021248; Fri, 11 Sep 2015 05:03:41 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si26461obf.12.2015.09.11.05.03.40; Fri, 11 Sep 2015 05:03:41 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753131AbbIKMDg (ORCPT + 12 others); Fri, 11 Sep 2015 08:03:36 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:33526 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753096AbbIKMDe (ORCPT ); Fri, 11 Sep 2015 08:03:34 -0400 Received: by pacex6 with SMTP id ex6so73883239pac.0 for ; Fri, 11 Sep 2015 05:03:34 -0700 (PDT) X-Received: by 10.68.241.103 with SMTP id wh7mr94822055pbc.88.1441973014133; Fri, 11 Sep 2015 05:03:34 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id ey17sm29316pac.26.2015.09.11.05.03.32 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 11 Sep 2015 05:03:33 -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 08/16] PM / OPP: get/put regulators from OPP core Date: Fri, 11 Sep 2015 17:32:04 +0530 Message-Id: X-Mailer: git-send-email 2.4.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@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.215.42 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: , When the 'supply_names' property is present, the OPP core can request regulators for them. All the regulators from the 'supply_names' property must be present, in order to move forward. If an error occurs, undo all allocations and return the appropriate error. This also helps in returning error on -EPROBE_DEFER case, where the driver must try again at a later point of time. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 30 +++++++++++++++++++++++++++--- drivers/base/power/opp/opp.h | 3 +++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index d6e945ec6467..42ea5a332ddc 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -509,8 +509,10 @@ static struct device_opp *_add_device_opp(struct device *dev, int supply_count) if (!IS_ERR(dev_opp)) return dev_opp; - /* Allocate size for supply-names with dev_opp */ - size = sizeof(*dev_opp) + supply_count * sizeof(*dev_opp->supply_names); + /* Allocate memory for supply-names & regulators with dev_opp */ + size = sizeof(*dev_opp); + size += supply_count * sizeof(*dev_opp->supply_names); + size += supply_count * sizeof(*dev_opp->regulators); /* * Allocate a new device OPP table. In the infrequent case where a new @@ -521,7 +523,8 @@ static struct device_opp *_add_device_opp(struct device *dev, int supply_count) return NULL; dev_opp->supply_count = supply_count; - dev_opp->supply_names = (const char **)(dev_opp + 1); + dev_opp->regulators = (struct regulator **)(dev_opp + 1); + dev_opp->supply_names = (const char **)(dev_opp->regulators + supply_count); INIT_LIST_HEAD(&dev_opp->dev_list); @@ -566,10 +569,15 @@ static void _kfree_device_rcu(struct rcu_head *head) static void _remove_device_opp(struct device_opp *dev_opp) { struct device_list_opp *list_dev; + int count; if (!list_empty(&dev_opp->opp_list)) return; + /* Release regulators */ + for (count = dev_opp->supply_count - 1; count >= 0; count--) + regulator_put(dev_opp->regulators[count]); + list_dev = list_first_entry(&dev_opp->dev_list, struct device_list_opp, node); @@ -1293,6 +1301,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) const char **name; int ret = 0, count, supply_count, string_count; bool triplets; + struct regulator *reg; dev_opp = _managed_opp(opp_np); if (dev_opp) { @@ -1334,6 +1343,21 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) } } + /* Get supply regulators */ + name = dev_opp->supply_names; + for (count = 0; count < supply_count; count++, name++) { + /* Parse regulators */ + reg = regulator_get_optional(dev, *name); + if (IS_ERR(reg)) { + ret = PTR_ERR(reg); + if (ret != -EPROBE_DEFER) + dev_err(dev, "%s: no regulator (%s) found: %d\n", + __func__, *name, ret); + goto free_table; + } + dev_opp->regulators[count] = reg; + } + /* We have opp-list node now, iterate over it and add OPPs */ count = 0; for_each_available_child_of_node(opp_np, np) { diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index 16575268f6ce..830c4b654a51 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -135,6 +136,7 @@ struct device_list_opp { * @opp_list: list of opps * @np: struct device_node pointer for opp's DT node. * @supply_count: Number of power-supplies + * @regulators: Array of regulators * @supply_names: Array of strings containing names of the power-supplies * @shared_opp: OPP is shared between multiple devices. * @dentry: debugfs dentry pointer of the real device directory (not links). @@ -160,6 +162,7 @@ struct device_opp { unsigned long clock_latency_ns_max; unsigned int supply_count; + struct regulator **regulators; const char **supply_names; bool shared_opp;