diff mbox

Regulator support for smsc911x

Message ID 20120203074408.GD1990@pengutronix.de
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Sascha Hauer Feb. 3, 2012, 7:44 a.m. UTC
On Fri, Feb 03, 2012 at 01:17:23AM -0200, Fabio Estevam wrote:
> On Thu, Feb 2, 2012 at 11:02 PM, Fabio Estevam <festevam@gmail.com> wrote:
> > Robert,
> >
> > Since commit c7e963f6 (net/smsc911x: Add regulator support) I am no
> > longer able to use smsc911x driver due to the lack of regulators for
> > smsc on mx31_3ds board.
> >
> > Do you a board example that uses such regulator, so that I can look
> > for a reference?
> 
> Ok, I fixed it by enabling CONFIG_REGULATOR_DUMMY on
> imx_v6_v7_defconfig, but I am wondering if the patch below would be a
> more appropriate fix:
> 
> --- a/drivers/net/ethernet/smsc/Kconfig
> +++ b/drivers/net/ethernet/smsc/Kconfig
> @@ -102,6 +102,8 @@ config SMSC911X
>         select NET_CORE
>         select MII
>         select PHYLIB
> +       select REGULATOR
> +       select REGULATOR_DUMMY
>         ---help---
>           Say Y here if you want support for SMSC LAN911x and LAN921x families
>           of ethernet controllers.
> 
> Please advise if I should fix it in Kconfig or defconfig, so that I
> can submit a patch.

The problem with the dummy regulator is that it can hide real problems.
If you enable it every device will get a regulator when it requests one.
If for some reason for example the initialization order of your devices
changes and a device gets probed before the corresponding (real)
regulator is registered, then this device will continue with the dummy
regulator and probably won't work.

We could a) live with this problem and default enable the dummy
regulator. We could also b) apply (a fixed version of) the following
patch which simplifies registration of a dummy regulator. Still it's a
bit annoying to have to fix all users once someone adds regulator
support for a driver.

Sascha

8<------------------------------------------------

regulator: allow boards to bind to the dummy regulator

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/regulator/core.c          |   19 +++++++++++++++++++
 include/linux/regulator/machine.h |    8 ++++++++
 2 files changed, 27 insertions(+), 0 deletions(-)

Comments

Mark Brown Feb. 3, 2012, 11:11 a.m. UTC | #1
On Fri, Feb 03, 2012 at 08:44:08AM +0100, Sascha Hauer wrote:
> On Fri, Feb 03, 2012 at 01:17:23AM -0200, Fabio Estevam wrote:

> > Please advise if I should fix it in Kconfig or defconfig, so that I
> > can submit a patch.

> If you enable it every device will get a regulator when it requests one.
> If for some reason for example the initialization order of your devices
> changes and a device gets probed before the corresponding (real)
> regulator is registered, then this device will continue with the dummy
> regulator and probably won't work.

Hrm, yeah - the dummy regulator support will be totally broken by the
stuff Grant is working on for fixing the general issues with probe
ordering.

> We could a) live with this problem and default enable the dummy
> regulator. We could also b) apply (a fixed version of) the following
> patch which simplifies registration of a dummy regulator. Still it's a

There's also options c) set up the regulators for the board and d) don't
enable the regulator API if the board doesn't use regulators.

> bit annoying to have to fix all users once someone adds regulator
> support for a driver.

Yeah, it's a shame.  I really can't see anything else useful we can do
though.
diff mbox

Patch

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index d8e6a42..a7a38ba 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1046,6 +1046,25 @@  static void unset_regulator_supplies(struct regulator_dev *rdev)
 	}
 }
 
+int regulator_add_dummy_supply(struct regulator_consumer_supply *supply,
+		int num_supplies)
+{
+	int i, ret;
+
+	for (i = 0; i < num_supplies; i++) {
+		ret = set_consumer_device_supply(dummy_regulator_rdev, NULL,
+				supply[i].dev_name, supply[i].supply);
+		if (ret)
+			goto err_out;
+	}
+
+	return 0;
+err_out:
+	/* FIXME: unset device supply */
+	return ret;
+}
+EXPORT_SYMBOL_GPL(regulator_add_dummy_supply);
+
 #define REG_STR_SIZE	64
 
 static struct regulator *create_regulator(struct regulator_dev *rdev,
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index ce3127a..89089cd 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -192,6 +192,8 @@  int regulator_suspend_finish(void);
 #ifdef CONFIG_REGULATOR
 void regulator_has_full_constraints(void);
 void regulator_use_dummy_regulator(void);
+int regulator_add_dummy_supply(struct regulator_consumer_supply *supply,
+		int num_supplies);
 #else
 static inline void regulator_has_full_constraints(void)
 {
@@ -200,6 +202,12 @@  static inline void regulator_has_full_constraints(void)
 static inline void regulator_use_dummy_regulator(void)
 {
 }
+
+static inline int regulator_add_dummy_supply(struct regulator_consumer_supply *supply,
+		int num_supplies)
+{
+	return 0;
+}
 #endif
 
 #endif