From patchwork Tue Sep 27 10:12:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajendra Nayak X-Patchwork-Id: 4368 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3A57C23F6F for ; Tue, 27 Sep 2011 10:13:35 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 2F4CCA182DB for ; Tue, 27 Sep 2011 10:13:35 +0000 (UTC) Received: by mail-fx0-f52.google.com with SMTP id 23so9690167fxe.11 for ; Tue, 27 Sep 2011 03:13:35 -0700 (PDT) Received: by 10.223.57.17 with SMTP id a17mr7300888fah.65.1317118415100; Tue, 27 Sep 2011 03:13:35 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.3.234 with SMTP id f10cs67266laf; Tue, 27 Sep 2011 03:13:34 -0700 (PDT) Received: by 10.101.192.18 with SMTP id u18mr6817062anp.34.1317118411191; Tue, 27 Sep 2011 03:13:31 -0700 (PDT) Received: from bear.ext.ti.com (bear.ext.ti.com. [192.94.94.41]) by mx.google.com with ESMTPS id x3si8789734ani.195.2011.09.27.03.13.30 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Sep 2011 03:13:31 -0700 (PDT) Received-SPF: pass (google.com: domain of rnayak@ti.com designates 192.94.94.41 as permitted sender) client-ip=192.94.94.41; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rnayak@ti.com designates 192.94.94.41 as permitted sender) smtp.mail=rnayak@ti.com Received: from dbdp20.itg.ti.com ([172.24.170.38]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id p8RADREY015503 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 27 Sep 2011 05:13:29 -0500 Received: from dbde70.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id p8RADQIT024629; Tue, 27 Sep 2011 15:43:26 +0530 (IST) Received: from dbdp31.itg.ti.com (172.24.170.98) by DBDE70.ent.ti.com (172.24.170.148) with Microsoft SMTP Server id 8.3.106.1; Tue, 27 Sep 2011 15:43:26 +0530 Received: from ula0131687.apr.dhcp.ti.com (ula0131687-172024137082.apr.dhcp.ti.com [172.24.137.82]) by dbdp31.itg.ti.com (8.13.8/8.13.8) with ESMTP id p8RAD81Q019725; Tue, 27 Sep 2011 15:43:26 +0530 (IST) From: Rajendra Nayak To: , CC: , , , , , , , Rajendra Nayak Subject: [PATCH 9/9] regulator: map consumer regulator based on device tree Date: Tue, 27 Sep 2011 15:42:52 +0530 Message-ID: <1317118372-17052-10-git-send-email-rnayak@ti.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1317118372-17052-1-git-send-email-rnayak@ti.com> References: <1317118372-17052-1-git-send-email-rnayak@ti.com> MIME-Version: 1.0 Look up the regulator for a given consumer from device tree, during a regulator_get(). If not found fallback and lookup through the regulator_map_list instead. Devices can associate with one or more regulators by providing a list of phandles and supply names. For Example: devicenode: node@0x0 { ... ... vmmc-supply = <®ulator1>; vpll-supply = <®ulator2>; }; When a device driver calls a regulator_get, specifying the supply name, the phandle and eventually the regulator node is extracted from the device node. Signed-off-by: Rajendra Nayak --- drivers/regulator/core.c | 14 ++++++++++++++ include/linux/regulator/driver.h | 3 +++ 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d8e6a42..47b851c 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -25,9 +25,11 @@ #include #include #include +#include #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -1155,6 +1157,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, struct regulator_map *map; struct regulator *regulator = ERR_PTR(-ENODEV); const char *devname = NULL; + struct device_node *node; int ret; if (id == NULL) { @@ -1167,6 +1170,15 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, mutex_lock(®ulator_list_mutex); + if (dev->of_node) { + node = of_get_regulator(dev, id); + if (!node) + goto retry; /* fallback and chk regulator_map_list */ + list_for_each_entry(rdev, ®ulator_list, list) + if (node == rdev->node) + goto found; + } +retry: list_for_each_entry(map, ®ulator_map_list, list) { /* If the mapping has a device set up it must match */ if (map->dev_name && @@ -2619,6 +2631,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, rdev->reg_data = driver_data; rdev->owner = regulator_desc->owner; rdev->desc = regulator_desc; + if (dev && dev->of_node) + rdev->node = dev->of_node; INIT_LIST_HEAD(&rdev->consumer_list); INIT_LIST_HEAD(&rdev->list); BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 1a80bc7..4aebbf5 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -196,6 +196,9 @@ struct regulator_dev { struct mutex mutex; /* consumer lock */ struct module *owner; struct device dev; +#ifdef CONFIG_OF + struct device_node *node; +#endif struct regulation_constraints *constraints; struct regulator *supply; /* for tree */