Skip to contentSkip to conversation

regulator: Provide optional dummy regulator for consumers

PATCH New Mark Brown 3 participants 6 messages Feb 11, 2010 – Feb 13, 2010 Voltage and current regulator framework

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 regulator: Provide optional dummy regulator for consumers

In order to ease transitions with drivers are boards start using regulators provide an option to cause all regulator_get() calls to succeed, with a dummy always on regulator being supplied where one has not been configured. A warning is printed whenever the dummy regulator is used to aid system development.

This regulator does not implement any regulator operations but will allow simple consumers which only do enable() and disable() calls to run. It is kept separate from the fixed voltage regulator to avoid Kconfig confusion on the part of users when it is extended to allow boards to explicitly use the dummy regulator to simplify cases where the majority of supplies are from fixed regulators without software control.

This option is currently only effective for systems which do not specify full constriants. If required an override could also be provided to allow these systems to use the dummy regulator, though it is likely that unconfigured supplies on such systems will lead to error due to regulators being powered down more aggressively when not in use.

---
 drivers/regulator/Kconfig  |   11 +++++++
 drivers/regulator/Makefile |    1 +
 drivers/regulator/core.c   |   27 ++++++++++++++++-
 drivers/regulator/dummy.c  |   71 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/regulator/dummy.h  |   31 +++++++++++++++++++
 5 files changed, 140 insertions(+), 1 deletions(-)
 create mode 100644 drivers/regulator/dummy.c
 create mode 100644 drivers/regulator/dummy.h
drivers/regulator/Kconfig +11 -0
index 3c07169..834b484 100644
@@ -27,6 +27,17 @@ config REGULATOR_DEBUG
 	help
 	  Say yes here to enable debugging support.
 
+config REGULATOR_DUMMY
+	bool "Provide a dummy regulator if regulator lookups fail"
+	help
+	  If this option is enabled then when a regulator lookup fails
+	  and the board has not specified that it has provided full
+	  constraints then the regulator core will provide an always
+	  enabled dummy regulator will be provided, allowing consumer
+	  drivers to continue.
+
+	  A warning will be generated when this substitution is done.
+
 config REGULATOR_FIXED_VOLTAGE
 	tristate "Fixed voltage regulator support"
 	help
drivers/regulator/Makefile +1 -0
index 7c59bcb..e845b66 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
 obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
 
 obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
+obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o
 obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o
drivers/regulator/core.c +26 -1
index 75a26f7..c7bbe30 100644
@@ -24,6 +24,8 @@
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 
+#include "dummy.h"
+
 #define REGULATOR_VERSION "0.5"
 
 static DEFINE_MUTEX(regulator_list_mutex);
@@ -1123,6 +1125,22 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
 			goto found;
 		}
 	}
+
+#ifdef CONFIG_REGULATOR_DUMMY
+	if (!devname)
+		devname = "deviceless";
+
+	/* If the board didn't flag that it was fully constrained then
+	 * substitute in a dummy regulator so consumers can continue.
+	 */
+	if (!has_full_constraints) {
+		pr_warning("%s supply %s not found, using dummy regulator\n",
+			   devname, id);
+		rdev = dummy_regulator_rdev;
+		goto found;
+	}
+#endif
+
 	mutex_unlock(&regulator_list_mutex);
 	return regulator;
 
@@ -2483,8 +2501,15 @@ EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
 
 static int __init regulator_init(void)
 {
+	int ret;
+
 	printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
-	return class_register(&regulator_class);
+
+	ret = class_register(&regulator_class);
+
+	regulator_dummy_init();
+
+	return ret;
 }
 
 /* init early to allow our consumers to complete system booting */
drivers/regulator/dummy.c new file +71 -0

71 lines not on this page · raw message

drivers/regulator/dummy.h new file +31 -0
new file mode 100644
index 0000000..3921c0e
@@ -0,0 +1,31 @@
+/*
+ * dummy.h
+ *
+ * Copyright 2010 Wolfson Microelectronics PLC.
+ *
+ * Author: Mark Brown <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This is useful for systems with mixed controllable and
+ * non-controllable regulators, as well as for allowing testing on
+ * systems with no controllable regulators.
+ */
+
+#ifndef _DUMMY_H
+#define _DUMMY_H
+
+struct regulator_dev;
+
+extern struct regulator_dev *dummy_regulator_rdev;
+
+#ifdef CONFIG_REGULATOR_DUMMY
+void __init regulator_dummy_init(void);
+#else
+static inline void regulator_dummy_init(void) { }
+#endif
+
+#endif
Signature · 1 line
1.6.6.1
author
#1 lore raw

PATCH 1/1 regulator: Provide optional dummy regulator for consumers

In order to ease transitions with drivers are boards start using regulators provide an option to cause all regulator_get() calls to succeed, with a dummy always on regulator being supplied where one has not been configured. A warning is printed whenever the dummy regulator is used to aid system development.

This regulator does not implement any regulator operations but will allow simple consumers which only do enable() and disable() calls to run. It is kept separate from the fixed voltage regulator to avoid Kconfig confusion on the part of users when it is extended to allow boards to explicitly use the dummy regulator to simplify cases where the majority of supplies are from fixed regulators without software control.

This option is currently only effective for systems which do not specify full constriants. If required an override could also be provided to allow these systems to use the dummy regulator, though it is likely that unconfigured supplies on such systems will lead to error due to regulators being powered down more aggressively when not in use.

---

And if we remember that git doesn't overwrite the patch file before sending...

 drivers/regulator/Kconfig  |   11 +++++++
 drivers/regulator/Makefile |    1 +
 drivers/regulator/core.c   |   27 +++++++++++++++++-
 drivers/regulator/dummy.c  |   66 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/regulator/dummy.h  |   31 ++++++++++++++++++++
 5 files changed, 135 insertions(+), 1 deletions(-)
 create mode 100644 drivers/regulator/dummy.c
 create mode 100644 drivers/regulator/dummy.h
drivers/regulator/Kconfig +11 -0
index 3c07169..834b484 100644
@@ -27,6 +27,17 @@ config REGULATOR_DEBUG
 	help
 	  Say yes here to enable debugging support.
 
+config REGULATOR_DUMMY
+	bool "Provide a dummy regulator if regulator lookups fail"
+	help
+	  If this option is enabled then when a regulator lookup fails
+	  and the board has not specified that it has provided full
+	  constraints then the regulator core will provide an always
+	  enabled dummy regulator will be provided, allowing consumer
+	  drivers to continue.
+
+	  A warning will be generated when this substitution is done.
+
 config REGULATOR_FIXED_VOLTAGE
 	tristate "Fixed voltage regulator support"
 	help
drivers/regulator/Makefile +1 -0
index 7c59bcb..e845b66 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
 obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
 
 obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
+obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o
 obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o
drivers/regulator/core.c +26 -1
index 75a26f7..c7bbe30 100644
@@ -24,6 +24,8 @@
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 
+#include "dummy.h"
+
 #define REGULATOR_VERSION "0.5"
 
 static DEFINE_MUTEX(regulator_list_mutex);
@@ -1123,6 +1125,22 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
 			goto found;
 		}
 	}
+
+#ifdef CONFIG_REGULATOR_DUMMY
+	if (!devname)
+		devname = "deviceless";
+
+	/* If the board didn't flag that it was fully constrained then
+	 * substitute in a dummy regulator so consumers can continue.
+	 */
+	if (!has_full_constraints) {
+		pr_warning("%s supply %s not found, using dummy regulator\n",
+			   devname, id);
+		rdev = dummy_regulator_rdev;
+		goto found;
+	}
+#endif
+
 	mutex_unlock(&regulator_list_mutex);
 	return regulator;
 
@@ -2483,8 +2501,15 @@ EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
 
 static int __init regulator_init(void)
 {
+	int ret;
+
 	printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
-	return class_register(&regulator_class);
+
+	ret = class_register(&regulator_class);
+
+	regulator_dummy_init();
+
+	return ret;
 }
 
 /* init early to allow our consumers to complete system booting */
drivers/regulator/dummy.c new file +66 -0

66 lines not on this page · raw message

drivers/regulator/dummy.h new file +31 -0
new file mode 100644
index 0000000..3921c0e
@@ -0,0 +1,31 @@
+/*
+ * dummy.h
+ *
+ * Copyright 2010 Wolfson Microelectronics PLC.
+ *
+ * Author: Mark Brown <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This is useful for systems with mixed controllable and
+ * non-controllable regulators, as well as for allowing testing on
+ * systems with no controllable regulators.
+ */
+
+#ifndef _DUMMY_H
+#define _DUMMY_H
+
+struct regulator_dev;
+
+extern struct regulator_dev *dummy_regulator_rdev;
+
+#ifdef CONFIG_REGULATOR_DUMMY
+void __init regulator_dummy_init(void);
+#else
+static inline void regulator_dummy_init(void) { }
+#endif
+
+#endif
Signature · 1 line
1.6.6.1
#2 lore raw
Quoted 13 lines · Mark Brown

In order to ease transitions with drivers are boards start using regulators provide an option to cause all regulator_get() calls to succeed, with a dummy always on regulator being supplied where one has not been configured. A warning is printed whenever the dummy regulator is used to aid system development.

This regulator does not implement any regulator operations but will allow simple consumers which only do enable() and disable() calls to run. It is kept separate from the fixed voltage regulator to avoid Kconfig confusion on the part of users when it is extended to allow boards to explicitly use the dummy regulator to simplify cases where the majority of supplies are from fixed regulators without software control.

Quoted 9 lines

This option is currently only effective for systems which do not specify full constriants. If required an override could also be provided to allow these systems to use the dummy regulator, though it is likely that unconfigured supplies on such systems will lead to error due to regulators being powered down more aggressively when not in use.

---

Applied.

Thanks

Liam

Signature · 3 lines
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk
#3 lore raw
In reply to Mark Brown
Quoted 13 lines · Mark Brown

In order to ease transitions with drivers are boards start using regulators provide an option to cause all regulator_get() calls to succeed, with a dummy always on regulator being supplied where one has not been configured. A warning is printed whenever the dummy regulator is used to aid system development.

This regulator does not implement any regulator operations but will allow simple consumers which only do enable() and disable() calls to run. It is kept separate from the fixed voltage regulator to avoid Kconfig confusion on the part of users when it is extended to allow boards to explicitly use the dummy regulator to simplify cases where the majority of supplies are from fixed regulators without software control.

Quoted 9 lines

This option is currently only effective for systems which do not specify full constriants. If required an override could also be provided to allow these systems to use the dummy regulator, though it is likely that unconfigured supplies on such systems will lead to error due to regulators being powered down more aggressively when not in use.

---

hm, tried intentionally nuking regulator setup on my board to test dummy and drivers started failing on regulator_enable() with -1 (EPERM?). Looks like dummy doesn't have constraints defined, so not much use of this if _enable() is failing anyway.

BTW, drivers/mmc/host/omap_hsmmc.c has quite a lot of logic related to vcc_aux being available or not (vcc_aux is typically used to power some MMC pins and is unused on devices with SD cards, like pandora). I wonder if it may cause some functionality change there.

author
#4 lore raw
Quoted 21 lines · Grazvydas Ignotas
Quoted 19 lines · Mark Brown

In order to ease transitions with drivers are boards start using regulators provide an option to cause all regulator_get() calls to succeed, with a dummy always on regulator being supplied where one has not been configured. A warning is printed whenever the dummy regulator is used to aid system development.

This regulator does not implement any regulator operations but will allow simple consumers which only do enable() and disable() calls to run. It is kept separate from the fixed voltage regulator to avoid Kconfig confusion on the part of users when it is extended to allow boards to explicitly use the dummy regulator to simplify cases where the majority of supplies are from fixed regulators without software control.

This option is currently only effective for systems which do not specify full constriants. If required an override could also be provided to allow these systems to use the dummy regulator, though it is likely that unconfigured supplies on such systems will lead to error due to regulators being powered down more aggressively when not in use.

Quoted 8 lines
Quoted 3 lines

---

hm, tried intentionally nuking regulator setup on my board to test dummy and drivers started failing on regulator_enable() with -1 (EPERM?). Looks like dummy doesn't have constraints defined, so not much use of this if _enable() is failing anyway.

Hrmpf. That was working for me - are you running the latest regulator code? There was a bug where it was requiring CHANGE_STATUS even if the regulator is always on, which isn't sensible since there is no possibility of actually changing the status. It should now only be checking for permission to change status if it would actually do so. There was also a patch yesterday to make regulators that don't define an is_enabled() report as enabled.

Quoted 4 lines

BTW, drivers/mmc/host/omap_hsmmc.c has quite a lot of logic related to vcc_aux being available or not (vcc_aux is typically used to power some MMC pins and is unused on devices with SD cards, like pandora). I wonder if it may cause some functionality change there.

Yeah, quite possibly. This sort of stuff is one of the reasons it's much nicer to specify full constraints where possible; it allows drivers that can have missing supplies to handle that.

#5 lore raw
Quoted 35 lines · Mark Brown
Quoted 24 lines · Grazvydas Ignotas
Quoted 22 lines · Mark Brown

In order to ease transitions with drivers are boards start using regulators
provide an option to cause all regulator_get() calls to succeed, with a dummy always on regulator being supplied where one has not been configured.
A warning is printed whenever the dummy regulator is used to aid system development.

This regulator does not implement any regulator operations but will allow simple consumers which only do enable() and disable() calls to run. It is kept separate from the fixed voltage regulator to avoid Kconfig confusion on the part of users when it is extended to allow boards to explicitly use the dummy regulator to simplify cases where the majority of supplies are from fixed regulators without software control.

This option is currently only effective for systems which do not specify full constriants. If required an override could also be provided to allow these systems to use the dummy regulator, though it is likely that unconfigured supplies on such systems will lead to error due to regulators being powered down more aggressively when not in use.

Quoted 8 lines
Quoted 3 lines

---

hm, tried intentionally nuking regulator setup on my board to test dummy and drivers started failing on regulator_enable() with -1 (EPERM?). Looks like dummy doesn't have constraints defined, so not much use of this if _enable() is failing anyway.

Quoted 6 lines

Hrmpf. That was working for me - are you running the latest regulator code? There was a bug where it was requiring CHANGE_STATUS even if the regulator is always on, which isn't sensible since there is no possibility of actually changing the status. It should now only be checking for permission to change status if it would actually do so. There was also a patch yesterday to make regulators that don't define an is_enabled() report as enabled.

Oh, it appears I was missing those patches (they were not in last linux-lest yet), now everything works as expected, thanks.

Quoted 9 lines
Quoted 5 lines

BTW, drivers/mmc/host/omap_hsmmc.c has quite a lot of logic related to vcc_aux being available or not (vcc_aux is typically used to power some MMC pins and is unused on devices with SD cards, like pandora). I wonder if it may cause some functionality change there.

Yeah, quite possibly. This sort of stuff is one of the reasons it's much nicer to specify full constraints where possible; it allows drivers that can have missing supplies to handle that.