]> Pileus Git - ~andy/linux/commitdiff
regulator: Add ramp_delay configuration to constraints
authorYadwinder Singh Brar <yadi.brar01@gmail.com>
Mon, 11 Jun 2012 12:11:08 +0000 (17:41 +0530)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Sun, 17 Jun 2012 20:08:52 +0000 (21:08 +0100)
For some hardwares ramp_delay for BUCKs is a configurable parameter which can
be configured through DT or board file.This patch adds ramp_delay to regulator
constraints and allow user to configure it for regulators which supports this
feature, through DT or board file. It will provide two ways of setting the
ramp_delay for a regulator:
First, by setting it as constraints in board file(for configurable
regulators) and set_machine_constraints() will take care of setting it on
hardware by calling(the provided) .set_ramp_delay() operation(callback).
Second, by setting it as data in regulator_desc(as fixed/default
ramp_delay rate) for a regulator in driver.

regulator_set_voltage_time_sel() will give preference to
constraints->ramp_delay while reading ramp_delay rate for regulator. Similarly
users should also take care accordingly while refering ramp_delay rate(in case
of implementing their private .set_voltage_time_sel() callbacks for different
regulators).

[Rewrote subject for 80 columns -- broonie]

Signed-off-by: Yadwinder Singh Brar <yadi.brar@samsung.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Documentation/devicetree/bindings/regulator/regulator.txt
drivers/regulator/core.c
drivers/regulator/of_regulator.c
include/linux/regulator/driver.h
include/linux/regulator/machine.h

index 5b7a408acdaa2ddd09aacab5d8ab402f52f00389..d0a7b1296a361017cba250ea9b9aeeeed87ec02a 100644 (file)
@@ -10,6 +10,7 @@ Optional properties:
 - regulator-always-on: boolean, regulator should never be disabled
 - regulator-boot-on: bootloader/firmware enabled regulator
 - <name>-supply: phandle to the parent supply/regulator node
+- regulator-ramp-delay: ramp delay for regulator(in mV/uS)
 
 Example:
 
index 6ffca9b32388a4a5f092188b1fe700b750e76373..b615ae6606db7881193ddf25d20eff73a348f556 100644 (file)
@@ -967,6 +967,14 @@ static int set_machine_constraints(struct regulator_dev *rdev,
                }
        }
 
+       if (rdev->constraints->ramp_delay && ops->set_ramp_delay) {
+               ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay);
+               if (ret < 0) {
+                       rdev_err(rdev, "failed to set ramp_delay\n");
+                       goto out;
+               }
+       }
+
        print_constraints(rdev);
        return 0;
 out:
@@ -2296,10 +2304,17 @@ int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
                                   unsigned int old_selector,
                                   unsigned int new_selector)
 {
-       if (rdev->desc->ramp_delay && rdev->desc->uV_step)
-               return DIV_ROUND_UP(rdev->desc->uV_step *
-                       abs(new_selector - old_selector),
-                       rdev->desc->ramp_delay * 1000);
+       if (rdev->desc->uV_step) {
+               if (rdev->constraints->ramp_delay)
+                       return DIV_ROUND_UP(rdev->desc->uV_step *
+                               abs(new_selector - old_selector),
+                               rdev->constraints->ramp_delay * 1000);
+               if (rdev->desc->ramp_delay)
+                       return DIV_ROUND_UP(rdev->desc->uV_step *
+                               abs(new_selector - old_selector),
+                               rdev->desc->ramp_delay * 1000);
+               rdev_warn(rdev, "ramp_delay not set\n");
+       }
        return 0;
 }
 
index 56593b75168a28e830946201778cd1937f08a724..e2a7310790667a26aeca3437bb229b2e3805606a 100644 (file)
@@ -20,7 +20,7 @@ static void of_get_regulation_constraints(struct device_node *np,
                                        struct regulator_init_data **init_data)
 {
        const __be32 *min_uV, *max_uV, *uV_offset;
-       const __be32 *min_uA, *max_uA;
+       const __be32 *min_uA, *max_uA, *ramp_delay;
        struct regulation_constraints *constraints = &(*init_data)->constraints;
 
        constraints->name = of_get_property(np, "regulator-name", NULL);
@@ -60,6 +60,10 @@ static void of_get_regulation_constraints(struct device_node *np,
                constraints->always_on = true;
        else /* status change should be possible if not always on. */
                constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS;
+
+       ramp_delay = of_get_property(np, "regulator-ramp-delay", NULL);
+       if (ramp_delay)
+               constraints->min_uV = be32_to_cpu(*ramp_delay);
 }
 
 /**
index ae5c2537923762b0c084aa0ee7f6ebd7b316487b..ddc155d262da1eedb8a0ec7fa44844cc64d2b302 100644 (file)
@@ -67,6 +67,8 @@ enum regulator_status {
  *
  * @enable_time: Time taken for the regulator voltage output voltage to
  *               stabilise after being enabled, in microseconds.
+ * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
+ *             select ramp delay equal to or less than(closest) ramp_delay.
  * @set_voltage_time_sel: Time taken for the regulator voltage output voltage
  *               to stabilise after being set to a new value, in microseconds.
  *               The function provides the from and to voltage selector, the
@@ -113,6 +115,7 @@ struct regulator_ops {
 
        /* Time taken to enable or set voltage on the regulator */
        int (*enable_time) (struct regulator_dev *);
+       int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
        int (*set_voltage_time_sel) (struct regulator_dev *,
                                     unsigned int old_selector,
                                     unsigned int new_selector);
index b02108446be756cc1c216271e21ac3cbf7a132d8..5f37ad3cc1725229b841c1e8532ca4144360ada4 100644 (file)
@@ -92,6 +92,7 @@ struct regulator_state {
  *                 mode.
  * @initial_state: Suspend state to set by default.
  * @initial_mode: Mode to set at startup.
+ * @ramp_delay: Time to settle down after voltage change (unit: mV/us)
  */
 struct regulation_constraints {
 
@@ -125,6 +126,8 @@ struct regulation_constraints {
        /* mode to set on startup */
        unsigned int initial_mode;
 
+       unsigned int ramp_delay;
+
        /* constraint flags */
        unsigned always_on:1;   /* regulator never off when system is on */
        unsigned boot_on:1;     /* bootloader/firmware enabled regulator */