regulator: core: factor out delay function from _regulator_do_enable
[deliverable/linux.git] / drivers / regulator / core.c
index a3c3785901f55b72c52db9ad4a2db3c4313dfaf2..dc0e9813b62dec4e5e160afa1840bb2b298807b9 100644 (file)
@@ -839,7 +839,7 @@ static void print_constraints(struct regulator_dev *rdev)
 static int machine_constraints_voltage(struct regulator_dev *rdev,
        struct regulation_constraints *constraints)
 {
-       struct regulator_ops *ops = rdev->desc->ops;
+       const struct regulator_ops *ops = rdev->desc->ops;
        int ret;
 
        /* do we need to apply the constraint voltage */
@@ -938,7 +938,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
 static int machine_constraints_current(struct regulator_dev *rdev,
        struct regulation_constraints *constraints)
 {
-       struct regulator_ops *ops = rdev->desc->ops;
+       const struct regulator_ops *ops = rdev->desc->ops;
        int ret;
 
        if (!constraints->min_uA && !constraints->max_uA)
@@ -982,7 +982,7 @@ static int set_machine_constraints(struct regulator_dev *rdev,
        const struct regulation_constraints *constraints)
 {
        int ret = 0;
-       struct regulator_ops *ops = rdev->desc->ops;
+       const struct regulator_ops *ops = rdev->desc->ops;
 
        if (constraints)
                rdev->constraints = kmemdup(constraints, sizeof(*constraints),
@@ -1759,6 +1759,45 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
        return 0;
 }
 
+/**
+ * _regulator_enable_delay - a delay helper function
+ * @delay: time to delay in microseconds
+ *
+ * Delay for the requested amount of time as per the guidelines in:
+ *
+ *     Documentation/timers/timers-howto.txt
+ *
+ * The assumption here is that regulators will never be enabled in
+ * atomic context and therefore sleeping functions can be used.
+ */
+static void _regulator_enable_delay(unsigned int delay)
+{
+       unsigned int ms = delay / 1000;
+       unsigned int us = delay % 1000;
+
+       if (ms > 0) {
+               /*
+                * For small enough values, handle super-millisecond
+                * delays in the usleep_range() call below.
+                */
+               if (ms < 20)
+                       us += ms * 1000;
+               else
+                       msleep(ms);
+       }
+
+       /*
+        * Give the scheduler some room to coalesce with any other
+        * wakeup sources. For delays shorter than 10 us, don't even
+        * bother setting up high-resolution timers and just busy-
+        * loop.
+        */
+       if (us >= 10)
+               usleep_range(us, us + 100);
+       else
+               udelay(us);
+}
+
 static int _regulator_do_enable(struct regulator_dev *rdev)
 {
        int ret, delay;
@@ -1792,40 +1831,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
         * together.  */
        trace_regulator_enable_delay(rdev_get_name(rdev));
 
-       /*
-        * Delay for the requested amount of time as per the guidelines in:
-        *
-        *     Documentation/timers/timers-howto.txt
-        *
-        * The assumption here is that regulators will never be enabled in
-        * atomic context and therefore sleeping functions can be used.
-        */
-       if (delay) {
-               unsigned int ms = delay / 1000;
-               unsigned int us = delay % 1000;
-
-               if (ms > 0) {
-                       /*
-                        * For small enough values, handle super-millisecond
-                        * delays in the usleep_range() call below.
-                        */
-                       if (ms < 20)
-                               us += ms * 1000;
-                       else
-                               msleep(ms);
-               }
-
-               /*
-                * Give the scheduler some room to coalesce with any other
-                * wakeup sources. For delays shorter than 10 us, don't even
-                * bother setting up high-resolution timers and just busy-
-                * loop.
-                */
-               if (us >= 10)
-                       usleep_range(us, us + 100);
-               else
-                       udelay(us);
-       }
+       _regulator_enable_delay(delay);
 
        trace_regulator_enable_complete(rdev_get_name(rdev));
 
@@ -2208,9 +2214,9 @@ EXPORT_SYMBOL_GPL(regulator_count_voltages);
  */
 int regulator_list_voltage(struct regulator *regulator, unsigned selector)
 {
-       struct regulator_dev    *rdev = regulator->rdev;
-       struct regulator_ops    *ops = rdev->desc->ops;
-       int                     ret;
+       struct regulator_dev *rdev = regulator->rdev;
+       const struct regulator_ops *ops = rdev->desc->ops;
+       int ret;
 
        if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector)
                return rdev->desc->fixed_uV;
@@ -2572,8 +2578,8 @@ EXPORT_SYMBOL_GPL(regulator_set_voltage);
 int regulator_set_voltage_time(struct regulator *regulator,
                               int old_uV, int new_uV)
 {
-       struct regulator_dev    *rdev = regulator->rdev;
-       struct regulator_ops    *ops = rdev->desc->ops;
+       struct regulator_dev *rdev = regulator->rdev;
+       const struct regulator_ops *ops = rdev->desc->ops;
        int old_sel = -1;
        int new_sel = -1;
        int voltage;
@@ -3336,9 +3342,9 @@ EXPORT_SYMBOL_GPL(regulator_mode_to_status);
  */
 static int add_regulator_attributes(struct regulator_dev *rdev)
 {
-       struct device           *dev = &rdev->dev;
-       struct regulator_ops    *ops = rdev->desc->ops;
-       int                     status = 0;
+       struct device *dev = &rdev->dev;
+       const struct regulator_ops *ops = rdev->desc->ops;
+       int status = 0;
 
        /* some attributes need specific methods to be displayed */
        if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) ||
@@ -3905,7 +3911,7 @@ core_initcall(regulator_init);
 static int __init regulator_init_complete(void)
 {
        struct regulator_dev *rdev;
-       struct regulator_ops *ops;
+       const struct regulator_ops *ops;
        struct regulation_constraints *c;
        int enabled, ret;
 
This page took 0.02581 seconds and 5 git commands to generate.