mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 5/6] regulator: allow to use it with non DT device
Date: Tue, 13 Jan 2015 07:33:09 +0100	[thread overview]
Message-ID: <1421130790-1164-5-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1421130790-1164-1-git-send-email-plagnioj@jcrosoft.com>

this will use the device name as regulator name

with the same Algo as clkdev for lookup

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/regulator/Kconfig |  2 +-
 drivers/regulator/core.c  | 98 +++++++++++++++++++++++++++++++++++++++--------
 include/regulator.h       | 10 +++++
 3 files changed, 93 insertions(+), 17 deletions(-)

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 493b18a..4085b3f 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -1,5 +1,4 @@
 menuconfig REGULATOR
-	depends on OFDEVICE
 	bool "voltage regulator support"
 
 if REGULATOR
@@ -7,6 +6,7 @@ if REGULATOR
 config REGULATOR_FIXED
 	bool "fixed/gpio regulator"
 	depends on GENERIC_GPIO
+	depends on OFDEVICE
 	help
 	  This enables a simple fixed regulator. It is used for regulators
 	  which are not software controllable or controllable via gpio.
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 2808c27..a3c9e41 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -33,6 +33,7 @@ struct regulator_internal {
 	int min_uv;
 	int max_uv;
 	char *name;
+	const char *supply;
 	struct list_head consumer_list;
 };
 
@@ -42,6 +43,25 @@ struct regulator {
 	struct device_d *dev;
 };
 
+static struct regulator_internal * __regulator_register(struct regulator_dev *rd, const char *name)
+{
+	struct regulator_internal *ri;
+
+	ri = xzalloc(sizeof(*ri));
+	ri->rdev = rd;
+
+	INIT_LIST_HEAD(&ri->consumer_list);
+
+	list_add_tail(&ri->list, &regulator_list);
+
+	if (name)
+		ri->name = xstrdup(name);
+
+	return ri;
+}
+
+
+#ifdef CONFIG_OFDEVICE
 /*
  * of_regulator_register - register a regulator corresponding to a device_node
  * @rd:		the regulator device providing the ops
@@ -54,18 +74,10 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
 	struct regulator_internal *ri;
 	const char *name;
 
-	ri = xzalloc(sizeof(*ri));
-	ri->rdev = rd;
-	ri->node = node;
-
-	INIT_LIST_HEAD(&ri->consumer_list);
-
-	list_add_tail(&ri->list, &regulator_list);
-
 	name = of_get_property(node, "regulator-name", NULL);
 
-	if (name)
-		ri->name = xstrdup(name);
+	ri = __regulator_register(rd, name);
+	ri->node = node;
 
 	of_property_read_u32(node, "regulator-enable-ramp-delay",
 			&ri->enable_time_us);
@@ -127,6 +139,55 @@ out:
 
 	return ri;
 }
+#else
+static struct regulator_internal *of_regulator_get(struct device_d *dev, const char *supply)
+{
+	return NULL;
+}
+#endif
+
+int dev_regulator_register(struct regulator_dev *rd, const char * name, const char* supply)
+{
+	struct regulator_internal *ri;
+
+	ri = __regulator_register(rd, name);
+
+	ri->supply = supply;
+
+	return 0;
+}
+
+static struct regulator_internal *dev_regulator_get(struct device_d *dev, const char *supply)
+{
+	struct regulator_internal *ri;
+	struct regulator_internal *ret = NULL;
+	int match, best = 0;
+	const char *dev_id = dev ? dev_name(dev) : NULL;
+
+	list_for_each_entry(ri, &regulator_list, list) {
+		match = 0;
+		if (ri->name) {
+			if (!dev_id || strcmp(ri->name, dev_id))
+				continue;
+			match += 2;
+		}
+		if (ri->supply) {
+			if (!supply || strcmp(ri->supply, supply))
+				continue;
+			match += 1;
+		}
+
+		if (match > best) {
+			ret = ri;
+			if (match != 3)
+				best = match;
+			else
+				break;
+		}
+	}
+
+	return ret;
+}
 
 /*
  * regulator_get - get the supply for a device.
@@ -140,15 +201,20 @@ out:
  */
 struct regulator *regulator_get(struct device_d *dev, const char *supply)
 {
-	struct regulator_internal *ri;
+	struct regulator_internal *ri = NULL;
 	struct regulator *r;
 
-	if (!dev->device_node)
-		return NULL;
+	if (dev->device_node) {
+		ri = of_regulator_get(dev, supply);
+		if (IS_ERR(ri))
+			return ERR_CAST(ri);
+	}
 
-	ri = of_regulator_get(dev, supply);
-	if (IS_ERR(ri))
-		return ERR_CAST(ri);
+	if (!ri) {
+		ri = dev_regulator_get(dev, supply);
+		if (IS_ERR(ri))
+			return ERR_CAST(ri);
+	}
 
 	if (!ri)
 		return NULL;
diff --git a/include/regulator.h b/include/regulator.h
index 26a5e56..a43d3df 100644
--- a/include/regulator.h
+++ b/include/regulator.h
@@ -15,7 +15,17 @@ struct regulator_ops {
 	int (*is_enabled) (struct regulator_dev *);
 };
 
+#ifdef CONFIG_OFDEVICE
 int of_regulator_register(struct regulator_dev *rd, struct device_node *node);
+#else
+static inline int of_regulator_register(struct regulator_dev *rd,
+					struct device_node *node)
+{
+	return -ENOSYS;
+}
+#endif
+int dev_regulator_register(struct regulator_dev *rd, const char * name,
+			   const char* supply);
 
 void regulators_print(void);
 
-- 
2.1.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2015-01-13  6:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-13  6:31 [PATCH 0/6 v2] raspberry-pi: updates Jean-Christophe PLAGNIOL-VILLARD
2015-01-13  6:33 ` [PATCH 1/6] raspberry-pi: add board model detection Jean-Christophe PLAGNIOL-VILLARD
2015-01-13  6:33   ` [PATCH 2/6] raspberry-pi: add leds support Jean-Christophe PLAGNIOL-VILLARD
2015-01-18 22:08     ` Antony Pavlov
2015-01-19  7:51       ` Sascha Hauer
2015-01-19  7:58         ` Antony Pavlov
2015-01-19  7:59           ` Sascha Hauer
2015-01-19 12:16       ` Jean-Christophe PLAGNIOL-VILLARD
2015-01-13  6:33   ` [PATCH 3/6] amba: pl011: add support for regulator Jean-Christophe PLAGNIOL-VILLARD
2015-01-13  6:33   ` [PATCH 4/6] driver: add postcore_platform_driver Jean-Christophe PLAGNIOL-VILLARD
2015-01-13  6:33   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2015-01-13  6:33   ` [PATCH 6/6] regulator: add bcm2835 driver Jean-Christophe PLAGNIOL-VILLARD
2015-01-14  6:24 ` [PATCH 0/6 v2] raspberry-pi: updates Sascha Hauer
2015-01-18 22:20 ` Antony Pavlov
  -- strict thread matches above, loose matches on Subject: below --
2015-01-13  6:24 [PATCH 0/6] " Jean-Christophe PLAGNIOL-VILLARD
2015-01-13  6:26 ` [PATCH 1/6] raspberry-pi: add board model detection Jean-Christophe PLAGNIOL-VILLARD
2015-01-13  6:26   ` [PATCH 5/6] regulator: allow to use it with non DT device Jean-Christophe PLAGNIOL-VILLARD

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=1421130790-1164-5-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.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