From patchwork Tue Sep 27 10:12:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajendra Nayak X-Patchwork-Id: 4366 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 C1D1223EFA for ; Tue, 27 Sep 2011 10:13:33 +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 B55F5A182DB for ; Tue, 27 Sep 2011 10:13:33 +0000 (UTC) Received: by mail-fx0-f52.google.com with SMTP id 23so9690167fxe.11 for ; Tue, 27 Sep 2011 03:13:33 -0700 (PDT) Received: by 10.223.45.140 with SMTP id e12mr5260445faf.27.1317118413627; Tue, 27 Sep 2011 03:13:33 -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 f10cs67264laf; Tue, 27 Sep 2011 03:13:32 -0700 (PDT) Received: by 10.101.134.21 with SMTP id l21mr3410157ann.167.1317118410465; Tue, 27 Sep 2011 03:13:30 -0700 (PDT) Received: from bear.ext.ti.com (bear.ext.ti.com. [192.94.94.41]) by mx.google.com with ESMTPS id b13si12698419anl.14.2011.09.27.03.13.29 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Sep 2011 03:13:30 -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 p8RADQK6015495 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 27 Sep 2011 05:13:28 -0500 Received: from dbde71.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id p8RADP1J024623; Tue, 27 Sep 2011 15:43:25 +0530 (IST) Received: from dbdp31.itg.ti.com (172.24.170.98) by DBDE71.ent.ti.com (172.24.170.149) with Microsoft SMTP Server id 8.3.106.1; Tue, 27 Sep 2011 15:43:25 +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 p8RAD81P019725; Tue, 27 Sep 2011 15:43:25 +0530 (IST) From: Rajendra Nayak To: , CC: , , , , , , , Rajendra Nayak Subject: [PATCH 8/9] regulator: helper to extract regulator node based on supply name Date: Tue, 27 Sep 2011 15:42:51 +0530 Message-ID: <1317118372-17052-9-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 Device nodes in DT can associate themselves with one or more regulators by providing a list of phandles (to regulator nodes) and corresponding supply names. For Example: devicenode: node@0x0 { ... ... vmmc-supply = <®ulator1>; vpll-supply = <®ulator1>; }; The driver would then do a regulator_get(dev, "vmmc"); to get regulator1 and do a regulator_get(dev, "vpll"); to get regulator2. of_get_regulator() extracts the regulator node for a given device, based on the supply name. Signed-off-by: Rajendra Nayak --- drivers/regulator/of_regulator.c | 39 ++++++++++++++++++++++++++++++++ include/linux/regulator/of_regulator.h | 7 +++++ 2 files changed, 46 insertions(+), 0 deletions(-) diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 7fa63ff..49dd105 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -14,6 +14,45 @@ #include #include + +/** + * of_get_regulator - get a regulator device node based on supply name + * @dev: Device pointer for the consumer (of regulator) device + * @supply: regulator supply name + * + * Extract the regulator device node corresponding to the supply name. + * retruns the device node corresponding to the regulator if found, else + * returns NULL. + */ +struct device_node *of_get_regulator(struct device *dev, const char *supply) +{ + struct device_node *regnode = NULL; + u32 reghandle; + char prop_name[32]; /* 32 is max size of property name */ + const void *prop; + int sz; + + if (!dev) + return NULL; + + dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); + + snprintf(prop_name, 32, "%s-supply", supply); + + prop = of_get_property(dev->of_node, prop_name, &sz); + if (!prop || sz < 4) + return NULL; + + reghandle = be32_to_cpup(prop); + regnode = of_find_node_by_phandle(reghandle); + if (!regnode) { + pr_warn("%s: %s property in node %s references invalid phandle", + __func__, prop_name, dev->of_node->full_name); + return NULL; + } + return regnode; +} + static void of_get_regulation_constraints(struct device_node *np, struct regulator_init_data **init_data) { diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h index 3f63be9..edaba1a 100644 --- a/include/linux/regulator/of_regulator.h +++ b/include/linux/regulator/of_regulator.h @@ -9,12 +9,19 @@ #if defined(CONFIG_OF_REGULATOR) extern struct regulator_init_data *of_get_regulator_init_data(struct device *dev); +extern struct device_node *of_get_regulator(struct device *dev, + const char *supply); #else static inline struct regulator_init_data *of_get_regulator_init_data(struct device_node *np) { return NULL; } +static inline struct device_node *of_get_regulator(struct device *dev, + const char *id) +{ + return NULL; +} #endif /* CONFIG_OF_REGULATOR */ #endif /* __LINUX_OF_REG_H */