From 2d36c20ef476742c68e2a3f575531b7c7a6f5f35 Mon Sep 17 00:00:00 2001 From: Osvaldo Banuelos Date: Thu, 7 Apr 2016 15:16:40 -0700 Subject: [PATCH] regulator: cprh-kbss-regulator: use APM hysteresis for voltage adjustments Adjust floor voltages based upon a configurable APM hysteresis voltage. This reduces the number of corners whose floor voltages must be raised to ensure stable operation with manual APM switching. In particular, for corners with ceiling voltage greater than or equal to the APM threshold voltage and floor voltage less than APM threshold voltage set an adjusted floor of max(floor, APM threshold - APM hysteresis). Change-Id: I65bebcfd8f4785bce9f65243987c05444aab14ee CRs-Fixed: 1001346 Signed-off-by: Osvaldo Banuelos --- .../bindings/regulator/cprh-kbss-regulator.txt | 10 ++++++---- drivers/regulator/cprh-kbss-regulator.c | 16 +++++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Documentation/devicetree/bindings/regulator/cprh-kbss-regulator.txt b/Documentation/devicetree/bindings/regulator/cprh-kbss-regulator.txt index e0f6ea2371b9..fc17085f5539 100644 --- a/Documentation/devicetree/bindings/regulator/cprh-kbss-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/cprh-kbss-regulator.txt @@ -50,10 +50,12 @@ KBSS specific properties: - qcom,apm-hysteresis-voltage Usage: optional Value type: - Definition: Specifies the voltage delta in microvolts between the APM - threshold voltage and the highest corner open-loop voltage - which may be used as the ceiling for the corner. If this - property is not specified, then a value of 0 is assumed. + Definition: Specifies the voltage in microvolts used to adjust floor + voltages with respect to the APM threshold voltage. This + voltage is used to reduce the number of corners whose floor + must be raised to ensure stable operation with manual APM + switching. If this property is not specified, then a value + of 0 is assumed. - qcom,voltage-base Usage: required diff --git a/drivers/regulator/cprh-kbss-regulator.c b/drivers/regulator/cprh-kbss-regulator.c index 2884d9fe591e..04a8206325c8 100644 --- a/drivers/regulator/cprh-kbss-regulator.c +++ b/drivers/regulator/cprh-kbss-regulator.c @@ -771,10 +771,11 @@ static int cprh_kbss_apm_threshold_as_corner(struct cpr3_regulator *vreg) * * The following algorithm is applied in the case that * floor < threshold <= ceiling: - * if open_loop >= threshold - adj, then floor = threshold + * if open_loop >= threshold, then floor = threshold - adj * else ceiling = threshold - step - * where adj = an adjustment factor to ensure sufficient voltage margin and - * step = VDD output step size + * where adj = APM hysteresis voltage established to minimize number + * of corners with artificially increased floor voltages + * and step = voltage in microvolts of a single step of the VDD supply * * The open-loop voltage is also bounded by the new floor or ceiling value as * needed. @@ -810,8 +811,9 @@ static int cprh_kbss_adjust_voltages_for_apm(struct cpr3_regulator *vreg) prev_ceiling = corner->ceiling_volt; prev_open_loop = corner->open_loop_volt; - if (corner->open_loop_volt >= threshold - adj) { - corner->floor_volt = threshold; + if (corner->open_loop_volt >= threshold) { + corner->floor_volt = max(corner->floor_volt, + threshold - adj); if (corner->open_loop_volt < corner->floor_volt) corner->open_loop_volt = corner->floor_volt; } else { @@ -1289,6 +1291,10 @@ static int cprh_kbss_init_controller(struct cpr3_controller *ctrl) if (rc) cpr3_debug(ctrl, "qcom,apm-threshold-voltage not specified\n"); + of_property_read_u32(ctrl->dev->of_node, "qcom,apm-hysteresis-voltage", + &ctrl->apm_adj_volt); + ctrl->apm_adj_volt = CPR3_ROUND(ctrl->apm_adj_volt, ctrl->step_volt); + ctrl->saw_use_unit_mV = of_property_read_bool(ctrl->dev->of_node, "qcom,cpr-saw-use-unit-mV");