From: Rajendra Nayak <rnayak-l0cyMroinI0@public.gmane.org>
To: broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org,
grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org
Cc: patches-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
lrg-l0cyMroinI0@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: [PATCH v2 5/5] regulator: map consumer regulator based on device tree
Date: Mon, 10 Oct 2011 21:49:38 +0530 [thread overview]
Message-ID: <1318263578-7407-6-git-send-email-rnayak@ti.com> (raw)
In-Reply-To: <1318263578-7407-1-git-send-email-rnayak-l0cyMroinI0@public.gmane.org>
Device nodes in DT can associate themselves with one or more
regulators/supply 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.
Use it to 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.
Also, since the regulator dt nodes can use the same binding to
associate with a parent regulator/supply, allow the drivers to
specify a supply_name, which can then be used to lookup dt
to find the parent phandle.
Signed-off-by: Rajendra Nayak <rnayak-l0cyMroinI0@public.gmane.org>
---
drivers/regulator/core.c | 91 +++++++++++++++++++++++++++++++------
include/linux/regulator/driver.h | 2 +
2 files changed, 78 insertions(+), 15 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index d8e6a42..9a5ebbe 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -25,9 +25,11 @@
#include <linux/mutex.h>
#include <linux/suspend.h>
#include <linux/delay.h>
+#include <linux/of.h>
#include <linux/regulator/consumer.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
#define CREATE_TRACE_POINTS
#include <trace/events/regulator.h>
@@ -131,6 +133,33 @@ static struct regulator *get_device_regulator(struct device *dev)
return NULL;
}
+/**
+ * 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;
+ char prop_name[32]; /* 32 is max size of property name */
+
+ dev_dbg(dev, "Looking up %s-supply from device tree\n", supply);
+
+ snprintf(prop_name, 32, "%s-supply", supply);
+ regnode = of_parse_phandle(dev->of_node, prop_name, 0);
+
+ 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;
+}
+
/* Platform voltage constraint check */
static int regulator_check_voltage(struct regulator_dev *rdev,
int *min_uV, int *max_uV)
@@ -1155,6 +1184,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 +1197,23 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
mutex_lock(®ulator_list_mutex);
+ /*
+ * Lookup happens in 3 ways
+ * 1. If a dev and dev->of_node exist, look for a
+ * regulator mapping in dt node.
+ * 2. Check if a match can be found in regulator_map_list
+ * if regulator info is still passed in non-dt way
+ * 3. if !dev, then just look for a matching regulator name.
+ * Useful for dt builds using regulator_get() without specifying
+ * a device.
+ */
+ if (dev && dev->of_node) {
+ node = of_get_regulator(dev, id);
+ if (node)
+ list_for_each_entry(rdev, ®ulator_list, list)
+ if (node == rdev->dev.parent->of_node)
+ goto found;
+ }
list_for_each_entry(map, ®ulator_map_list, list) {
/* If the mapping has a device set up it must match */
if (map->dev_name &&
@@ -1178,6 +1225,10 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
goto found;
}
}
+ if (!dev)
+ list_for_each_entry(rdev, ®ulator_list, list)
+ if (strcmp(rdev_get_name(rdev), id))
+ goto found;
if (board_wants_dummy_regulator) {
rdev = dummy_regulator_rdev;
@@ -2579,6 +2630,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
static atomic_t regulator_no = ATOMIC_INIT(0);
struct regulator_dev *rdev;
int ret, i;
+ const char *supply;
if (regulator_desc == NULL)
return ERR_PTR(-EINVAL);
@@ -2653,25 +2705,34 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
if (ret < 0)
goto scrub;
- if (init_data->supply_regulator) {
- struct regulator_dev *r;
- int found = 0;
+ if (init_data->supply_regulator)
+ supply = init_data->supply_regulator;
+ else if (regulator_desc->supply_name);
+ supply = regulator_desc->supply_name;
- list_for_each_entry(r, ®ulator_list, list) {
- if (strcmp(rdev_get_name(r),
- init_data->supply_regulator) == 0) {
- found = 1;
- break;
- }
+ if (supply) {
+ struct regulator_dev *r;
+ struct device_node *node;
+
+ /* first do a dt based lookup */
+ if (dev) {
+ node = of_get_regulator(dev, supply);
+ if (node)
+ list_for_each_entry(r, ®ulator_list, list)
+ if (node == r->dev.parent->of_node)
+ goto found;
}
- if (!found) {
- dev_err(dev, "Failed to find supply %s\n",
- init_data->supply_regulator);
- ret = -ENODEV;
- goto scrub;
- }
+ /* next try doing it non-dt way */
+ list_for_each_entry(r, ®ulator_list, list)
+ if (strcmp(rdev_get_name(r), supply) == 0)
+ goto found;
+ dev_err(dev, "Failed to find supply %s\n", supply);
+ ret = -ENODEV;
+ goto scrub;
+
+found:
ret = set_supply(rdev, r);
if (ret < 0)
goto scrub;
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 1a80bc7..65ca5ff 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -153,6 +153,7 @@ enum regulator_type {
* this type.
*
* @name: Identifying name for the regulator.
+ * @supply_name: Identifying the regulator supply
* @id: Numerical identifier for the regulator.
* @n_voltages: Number of selectors available for ops.list_voltage().
* @ops: Regulator operations table.
@@ -162,6 +163,7 @@ enum regulator_type {
*/
struct regulator_desc {
const char *name;
+ const char *supply_name;
int id;
unsigned n_voltages;
struct regulator_ops *ops;
--
1.7.1
next prev parent reply other threads:[~2011-10-10 16:19 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-10 16:19 [PATCH v2 0/5] Device tree support for regulators Rajendra Nayak
2011-10-10 16:19 ` [PATCH v2 2/5] dt: add empty dt helpers for non-dt build Rajendra Nayak
2011-10-13 18:32 ` Grant Likely
[not found] ` <1318263578-7407-1-git-send-email-rnayak-l0cyMroinI0@public.gmane.org>
2011-10-10 16:19 ` [PATCH v2 1/5] regulator: twl: Remove hardcoded board constraints from driver Rajendra Nayak
2011-10-10 16:25 ` Mark Brown
2011-10-10 16:34 ` Rajendra Nayak
2011-10-10 16:19 ` [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data Rajendra Nayak
2011-10-10 17:22 ` Mark Brown
2011-10-11 5:59 ` Rajendra Nayak
2011-10-13 18:38 ` Grant Likely
2011-10-13 22:12 ` Mark Brown
2011-10-13 18:40 ` Grant Likely
2011-10-16 14:55 ` Shawn Guo
2011-10-17 4:17 ` Rajendra Nayak
2011-10-18 11:58 ` Shawn Guo
[not found] ` <20111018115836.GC30703-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-10-18 16:00 ` Mark Brown
2011-10-19 5:33 ` Shawn Guo
[not found] ` <20111019053354.GB31162-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-10-19 14:47 ` Mark Brown
2011-10-19 15:04 ` Shawn Guo
2011-10-19 15:10 ` Mark Brown
2011-10-20 3:42 ` Rajendra Nayak
[not found] ` <4E9F9892.9070007-l0cyMroinI0@public.gmane.org>
2011-10-20 9:41 ` Mark Brown
[not found] ` <20111020094140.GK18713-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2011-10-20 12:10 ` Rajendra Nayak
2011-10-20 16:27 ` Tony Lindgren
[not found] ` <20111020162743.GB31337-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2011-10-20 16:40 ` Mark Brown
2011-10-20 17:05 ` Tony Lindgren
2011-10-20 17:22 ` Tony Lindgren
2011-10-20 19:57 ` Mark Brown
2011-10-20 20:10 ` Tony Lindgren
2011-10-20 21:42 ` Mark Brown
2011-10-20 22:09 ` Tony Lindgren
2011-10-24 9:07 ` Grant Likely
2011-10-20 19:56 ` Mark Brown
2011-10-18 13:20 ` Shawn Guo
2011-10-19 11:35 ` Rajendra Nayak
2011-10-19 14:42 ` Shawn Guo
2011-10-19 14:50 ` Mark Brown
[not found] ` <20111019144215.GA32007-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-10-20 5:18 ` Rajendra Nayak
2011-10-20 6:14 ` Shawn Guo
2011-10-20 12:09 ` Rajendra Nayak
2011-10-21 8:23 ` Shawn Guo
2011-10-21 8:41 ` Rajendra Nayak
2011-10-21 11:58 ` Shawn Guo
2011-10-24 6:02 ` Rajendra Nayak
2011-10-24 7:34 ` Mark Brown
2011-10-24 8:17 ` Grant Likely
2011-10-24 8:53 ` Rajendra Nayak
2011-10-24 9:19 ` Mark Brown
2011-10-24 10:05 ` Rajendra Nayak
2011-10-24 9:23 ` Shawn Guo
2011-10-24 9:02 ` Shawn Guo
2011-10-24 8:56 ` Rajendra Nayak
2011-10-24 9:11 ` Shawn Guo
2011-10-24 9:13 ` Rajendra Nayak
2011-10-24 13:47 ` Shawn Guo
2011-10-25 6:00 ` Rajendra Nayak
2011-10-25 6:26 ` Rajendra Nayak
2011-10-25 6:52 ` Shawn Guo
[not found] ` <20111025065216.GD2119-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-10-25 6:56 ` Rajendra Nayak
2011-10-25 7:20 ` Shawn Guo
2011-10-25 7:13 ` Rajendra Nayak
2011-10-25 7:42 ` Shawn Guo
2011-10-24 11:35 ` Grant Likely
2011-10-24 9:24 ` Grant Likely
2011-10-24 9:39 ` Mark Brown
2011-10-24 13:04 ` Shawn Guo
2011-10-24 13:06 ` Mark Brown
2011-10-24 13:40 ` Shawn Guo
2011-10-24 13:49 ` Mark Brown
2011-10-24 14:47 ` Shawn Guo
[not found] ` <20111024144716.GG1755-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-10-25 7:11 ` Mark Brown
2011-10-24 13:59 ` Grant Likely
2011-10-24 14:51 ` Shawn Guo
2011-10-24 14:56 ` Grant Likely
2011-10-24 15:51 ` Shawn Guo
2011-10-24 22:21 ` Grant Likely
2011-10-25 6:10 ` Rajendra Nayak
2011-10-25 7:08 ` Shawn Guo
2011-10-25 7:01 ` Rajendra Nayak
2011-10-25 7:28 ` Shawn Guo
2011-10-10 16:19 ` [PATCH v2 4/5] regulator: adapt fixed regulator driver to dt Rajendra Nayak
2011-10-13 18:43 ` Grant Likely
2011-10-10 16:19 ` Rajendra Nayak [this message]
2011-10-10 17:35 ` [PATCH v2 5/5] regulator: map consumer regulator based on device tree Mark Brown
2011-10-11 5:49 ` Rajendra Nayak
2011-10-11 7:08 ` Nayak, Rajendra
[not found] ` <CACYZBRFmLEY_f1UwJa5U9uj8+NVA-WfUVkiuW1yKrpwnrA_00A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-10-13 16:52 ` Mark Brown
2011-10-13 18:46 ` Grant Likely
2011-10-18 13:33 ` Shawn Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1318263578-7407-6-git-send-email-rnayak@ti.com \
--to=rnayak-l0cymroini0@public.gmane.org \
--cc=broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lrg-l0cyMroinI0@public.gmane.org \
--cc=patches-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).