From 688fe99a439f7c9dfcc52fbf7cb347f140a2dc8b Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Tue, 5 Oct 2010 19:18:32 -0700 Subject: regulator: Add option for machine drivers to enable the dummy regulator Allow machine drivers to explicitly enable the use of the dummy regulator, enabling simpler support for systems with only a few specific supplies visible to software. It is strongly recommended that this is not used on systems with substantial software control over their PMICs, for maximum functionality constrints should be as fully specified as possible. Signed-off-by: Mark Brown Signed-off-by: Liam Girdwood --- drivers/regulator/core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'drivers/regulator/core.c') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index cc8b337b9119..4fa08c85f3ce 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -33,6 +33,7 @@ static DEFINE_MUTEX(regulator_list_mutex); static LIST_HEAD(regulator_list); static LIST_HEAD(regulator_map_list); static int has_full_constraints; +static bool board_wants_dummy_regulator; /* * struct regulator_map @@ -1108,6 +1109,11 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, } } + if (board_wants_dummy_regulator) { + rdev = dummy_regulator_rdev; + goto found; + } + #ifdef CONFIG_REGULATOR_DUMMY if (!devname) devname = "deviceless"; @@ -2462,6 +2468,22 @@ void regulator_has_full_constraints(void) } EXPORT_SYMBOL_GPL(regulator_has_full_constraints); +/** + * regulator_use_dummy_regulator - Provide a dummy regulator when none is found + * + * Calling this function will cause the regulator API to provide a + * dummy regulator to consumers if no physical regulator is found, + * allowing most consumers to proceed as though a regulator were + * configured. This allows systems such as those with software + * controllable regulators for the CPU core only to be brought up more + * readily. + */ +void regulator_use_dummy_regulator(void) +{ + board_wants_dummy_regulator = true; +} +EXPORT_SYMBOL_GPL(regulator_use_dummy_regulator); + /** * rdev_get_drvdata - get rdev regulator driver data * @rdev: regulator -- cgit v1.2.3-59-g8ed1b From 8cbf811dfd027bde8504e541d0009c5722b98be5 Mon Sep 17 00:00:00 2001 From: Jeffrey Carlyle Date: Fri, 8 Oct 2010 14:49:19 -0500 Subject: regulator: avoid deadlock when disabling regulator with supply I have a regulator A that sets regulator B as its supply. When I call set_supply to add B as the supply for A, regulator A gets added to the supply_list for regulator B. When I call regulator_disable(A), I end up with a call chain like this: regulator_disable(A) > mutex_lock(A) > _regulator_disable(A) >> _regulator_disable(B) >>> _notifier_call_chain(B) >>>> mutex_lock(A) Which results in dead lock since we are trying to acquire the mutex lock for regulator A which we already hold. This patch addresses this issue by moving the call to disable regulator B outside of the lock aquired inside the initial call to regulator_disable. This change also addresses the issue of not acquiring the mutex for regulator B before calling _regulator_disable(B). Signed-off-by: Jeffrey Carlyle Acked-by: Mark Brown Signed-off-by: Liam Girdwood --- drivers/regulator/core.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'drivers/regulator/core.c') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 4fa08c85f3ce..f1d10c974cd4 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -64,7 +64,8 @@ struct regulator { }; static int _regulator_is_enabled(struct regulator_dev *rdev); -static int _regulator_disable(struct regulator_dev *rdev); +static int _regulator_disable(struct regulator_dev *rdev, + struct regulator_dev **supply_rdev_ptr); static int _regulator_get_voltage(struct regulator_dev *rdev); static int _regulator_get_current_limit(struct regulator_dev *rdev); static unsigned int _regulator_get_mode(struct regulator_dev *rdev); @@ -1354,7 +1355,8 @@ int regulator_enable(struct regulator *regulator) EXPORT_SYMBOL_GPL(regulator_enable); /* locks held by regulator_disable() */ -static int _regulator_disable(struct regulator_dev *rdev) +static int _regulator_disable(struct regulator_dev *rdev, + struct regulator_dev **supply_rdev_ptr) { int ret = 0; @@ -1382,8 +1384,7 @@ static int _regulator_disable(struct regulator_dev *rdev) } /* decrease our supplies ref count and disable if required */ - if (rdev->supply) - _regulator_disable(rdev->supply); + *supply_rdev_ptr = rdev->supply; rdev->use_count = 0; } else if (rdev->use_count > 1) { @@ -1413,17 +1414,29 @@ static int _regulator_disable(struct regulator_dev *rdev) int regulator_disable(struct regulator *regulator) { struct regulator_dev *rdev = regulator->rdev; + struct regulator_dev *supply_rdev = NULL; int ret = 0; mutex_lock(&rdev->mutex); - ret = _regulator_disable(rdev); + ret = _regulator_disable(rdev, &supply_rdev); mutex_unlock(&rdev->mutex); + + /* decrease our supplies ref count and disable if required */ + while (supply_rdev != NULL) { + rdev = supply_rdev; + + mutex_lock(&rdev->mutex); + _regulator_disable(rdev, &supply_rdev); + mutex_unlock(&rdev->mutex); + } + return ret; } EXPORT_SYMBOL_GPL(regulator_disable); /* locks held by regulator_force_disable() */ -static int _regulator_force_disable(struct regulator_dev *rdev) +static int _regulator_force_disable(struct regulator_dev *rdev, + struct regulator_dev **supply_rdev_ptr) { int ret = 0; @@ -1442,8 +1455,7 @@ static int _regulator_force_disable(struct regulator_dev *rdev) } /* decrease our supplies ref count and disable if required */ - if (rdev->supply) - _regulator_disable(rdev->supply); + *supply_rdev_ptr = rdev->supply; rdev->use_count = 0; return ret; @@ -1460,12 +1472,17 @@ static int _regulator_force_disable(struct regulator_dev *rdev) */ int regulator_force_disable(struct regulator *regulator) { + struct regulator_dev *supply_rdev = NULL; int ret; mutex_lock(®ulator->rdev->mutex); regulator->uA_load = 0; - ret = _regulator_force_disable(regulator->rdev); + ret = _regulator_force_disable(regulator->rdev, &supply_rdev); mutex_unlock(®ulator->rdev->mutex); + + if (supply_rdev) + regulator_disable(get_device_regulator(rdev_get_dev(supply_rdev))); + return ret; } EXPORT_SYMBOL_GPL(regulator_force_disable); -- cgit v1.2.3-59-g8ed1b