mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] regulator: Factor out functions to work with regulator_internal
@ 2015-07-15  5:52 Sascha Hauer
  2015-07-15  5:52 ` [PATCH 2/2] regulator: Add support for regulator-boot-on device tree property Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2015-07-15  5:52 UTC (permalink / raw)
  To: Barebox List

Internally we only have a struct regulator_internal, so factor
out regulator_enable_internal and regulator_disable_internal
functions which can be called from regulator internal code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/regulator/core.c | 86 +++++++++++++++++++++++++-----------------------
 1 file changed, 45 insertions(+), 41 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a3c9e41..96bf846 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -43,6 +43,49 @@ struct regulator {
 	struct device_d *dev;
 };
 
+static int regulator_enable_internal(struct regulator_internal *ri)
+{
+	int ret;
+
+	if (ri->enable_count) {
+		ri->enable_count++;
+		return 0;
+	}
+
+	if (!ri->rdev->ops->enable)
+		return -ENOSYS;
+
+	ret = ri->rdev->ops->enable(ri->rdev);
+	if (ret)
+		return ret;
+
+	if (ri->enable_time_us)
+		udelay(ri->enable_time_us);
+
+	ri->enable_count++;
+
+	return 0;
+}
+
+static int regulator_disable_internal(struct regulator_internal *ri)
+{
+	int ret;
+
+	if (!ri->enable_count)
+		return -EINVAL;
+
+	if (!ri->rdev->ops->disable)
+		return -ENOSYS;
+
+	ret = ri->rdev->ops->disable(ri->rdev);
+	if (ret)
+		return ret;
+
+	ri->enable_count--;
+
+	return 0;
+}
+
 static struct regulator_internal * __regulator_register(struct regulator_dev *rd, const char *name)
 {
 	struct regulator_internal *ri;
@@ -239,32 +282,10 @@ struct regulator *regulator_get(struct device_d *dev, const char *supply)
  */
 int regulator_enable(struct regulator *r)
 {
-	struct regulator_internal *ri;
-	int ret;
-
 	if (!r)
 		return 0;
 
-	ri = r->ri;
-
-	if (ri->enable_count) {
-		ri->enable_count++;
-		return 0;
-	}
-
-	if (!ri->rdev->ops->enable)
-		return -ENOSYS;
-
-	ret = ri->rdev->ops->enable(ri->rdev);
-	if (ret)
-		return ret;
-
-	if (ri->enable_time_us)
-		udelay(ri->enable_time_us);
-
-	ri->enable_count++;
-
-	return 0;
+	return regulator_enable_internal(r->ri);
 }
 
 /*
@@ -278,27 +299,10 @@ int regulator_enable(struct regulator *r)
  */
 int regulator_disable(struct regulator *r)
 {
-	struct regulator_internal *ri;
-	int ret;
-
 	if (!r)
 		return 0;
 
-	ri = r->ri;
-
-	if (!ri->enable_count)
-		return -EINVAL;
-
-	if (!ri->rdev->ops->disable)
-		return -ENOSYS;
-
-	ret = ri->rdev->ops->disable(ri->rdev);
-	if (ret)
-		return ret;
-
-	ri->enable_count--;
-
-	return 0;
+	return regulator_disable_internal(r->ri);
 }
 
 static void regulator_print_one(struct regulator_internal *ri)
-- 
2.1.4


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] regulator: Add support for regulator-boot-on device tree property
  2015-07-15  5:52 [PATCH 1/2] regulator: Factor out functions to work with regulator_internal Sascha Hauer
@ 2015-07-15  5:52 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2015-07-15  5:52 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/regulator/core.c | 15 +++++++++++++++
 include/regulator.h      |  1 +
 2 files changed, 16 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 96bf846..73f5c6e 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -89,6 +89,7 @@ static int regulator_disable_internal(struct regulator_internal *ri)
 static struct regulator_internal * __regulator_register(struct regulator_dev *rd, const char *name)
 {
 	struct regulator_internal *ri;
+	int ret;
 
 	ri = xzalloc(sizeof(*ri));
 	ri->rdev = rd;
@@ -100,7 +101,19 @@ static struct regulator_internal * __regulator_register(struct regulator_dev *rd
 	if (name)
 		ri->name = xstrdup(name);
 
+	if (rd->boot_on) {
+		ret = regulator_enable_internal(ri);
+		if (ret && ret != -ENOSYS)
+			goto err;
+	}
+
 	return ri;
+err:
+	list_del(&ri->list);
+	free(ri->name);
+	free(ri);
+
+	return ERR_PTR(ret);
 }
 
 
@@ -117,6 +130,8 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
 	struct regulator_internal *ri;
 	const char *name;
 
+	rd->boot_on = of_property_read_bool(node, "regulator-boot-on");
+
 	name = of_get_property(node, "regulator-name", NULL);
 
 	ri = __regulator_register(rd, name);
diff --git a/include/regulator.h b/include/regulator.h
index a43d3df..367e13f 100644
--- a/include/regulator.h
+++ b/include/regulator.h
@@ -6,6 +6,7 @@ struct regulator;
 
 struct regulator_dev {
 	struct regulator_ops *ops;
+	int boot_on;
 };
 
 struct regulator_ops {
-- 
2.1.4


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-15  5:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-15  5:52 [PATCH 1/2] regulator: Factor out functions to work with regulator_internal Sascha Hauer
2015-07-15  5:52 ` [PATCH 2/2] regulator: Add support for regulator-boot-on device tree property Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox