Commit 31aae2be authored by Mark Brown's avatar Mark Brown Committed by Liam Girdwood

regulator: Allow regulators to specify the time taken to ramp on enable

Regulators may sometimes take longer to enable than the control operation
used to do so, either because the regulator has ramp rate control used to
limit inrush current or because the control operation is very fast (GPIO
being the most common example of this).  In order to ensure that consumers
do not rely on the regulator before it is enabled provide an enable_time()
operation and have the core delay for that time before returning to the
caller.

This is implemented as a function since the ramp rate may be specified in
voltage per unit time and therefore the time depend on the configuration.
In future it would be desirable to allow the bulk operations to run the
delays for multiple enables in parallel but this is not currently supported.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 84b68263
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/suspend.h> #include <linux/suspend.h>
#include <linux/delay.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/regulator/driver.h> #include <linux/regulator/driver.h>
#include <linux/regulator/machine.h> #include <linux/regulator/machine.h>
...@@ -1084,6 +1085,13 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, ...@@ -1084,6 +1085,13 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
return NULL; return NULL;
} }
static int _regulator_get_enable_time(struct regulator_dev *rdev)
{
if (!rdev->desc->ops->enable_time)
return 0;
return rdev->desc->ops->enable_time(rdev);
}
/* Internal regulator request function */ /* Internal regulator request function */
static struct regulator *_regulator_get(struct device *dev, const char *id, static struct regulator *_regulator_get(struct device *dev, const char *id,
int exclusive) int exclusive)
...@@ -1251,7 +1259,7 @@ static int _regulator_can_change_status(struct regulator_dev *rdev) ...@@ -1251,7 +1259,7 @@ static int _regulator_can_change_status(struct regulator_dev *rdev)
/* locks held by regulator_enable() */ /* locks held by regulator_enable() */
static int _regulator_enable(struct regulator_dev *rdev) static int _regulator_enable(struct regulator_dev *rdev)
{ {
int ret; int ret, delay;
/* do we need to enable the supply regulator first */ /* do we need to enable the supply regulator first */
if (rdev->supply) { if (rdev->supply) {
...@@ -1275,13 +1283,34 @@ static int _regulator_enable(struct regulator_dev *rdev) ...@@ -1275,13 +1283,34 @@ static int _regulator_enable(struct regulator_dev *rdev)
if (!_regulator_can_change_status(rdev)) if (!_regulator_can_change_status(rdev))
return -EPERM; return -EPERM;
if (rdev->desc->ops->enable) { if (!rdev->desc->ops->enable)
ret = rdev->desc->ops->enable(rdev);
if (ret < 0)
return ret;
} else {
return -EINVAL; return -EINVAL;
/* Query before enabling in case configuration
* dependant. */
ret = _regulator_get_enable_time(rdev);
if (ret >= 0) {
delay = ret;
} else {
printk(KERN_WARNING
"%s: enable_time() failed for %s: %d\n",
__func__, rdev_get_name(rdev),
ret);
delay = 0;
} }
/* Allow the regulator to ramp; it would be useful
* to extend this for bulk operations so that the
* regulators can ramp together. */
ret = rdev->desc->ops->enable(rdev);
if (ret < 0)
return ret;
if (delay >= 1000)
mdelay(delay / 1000);
else if (delay)
udelay(delay);
} else if (ret < 0) { } else if (ret < 0) {
printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n",
__func__, rdev_get_name(rdev), ret); __func__, rdev_get_name(rdev), ret);
......
...@@ -58,6 +58,9 @@ enum regulator_status { ...@@ -58,6 +58,9 @@ enum regulator_status {
* @get_optimum_mode: Get the most efficient operating mode for the regulator * @get_optimum_mode: Get the most efficient operating mode for the regulator
* when running with the specified parameters. * when running with the specified parameters.
* *
* @enable_time: Time taken for the regulator voltage output voltage to
* stabalise after being enabled, in microseconds.
*
* @set_suspend_voltage: Set the voltage for the regulator when the system * @set_suspend_voltage: Set the voltage for the regulator when the system
* is suspended. * is suspended.
* @set_suspend_enable: Mark the regulator as enabled when the system is * @set_suspend_enable: Mark the regulator as enabled when the system is
...@@ -93,6 +96,9 @@ struct regulator_ops { ...@@ -93,6 +96,9 @@ struct regulator_ops {
int (*set_mode) (struct regulator_dev *, unsigned int mode); int (*set_mode) (struct regulator_dev *, unsigned int mode);
unsigned int (*get_mode) (struct regulator_dev *); unsigned int (*get_mode) (struct regulator_dev *);
/* Time taken to enable the regulator */
int (*enable_time) (struct regulator_dev *);
/* report regulator status ... most other accessors report /* report regulator status ... most other accessors report
* control inputs, this reports results of combining inputs * control inputs, this reports results of combining inputs
* from Linux (and other sources) with the actual load. * from Linux (and other sources) with the actual load.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment