linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator: qcom_spmi: Add slewing delays for all SMPS types
@ 2016-03-29 22:58 Stephen Boyd
  2016-03-29 23:09 ` Mark Brown
  2016-03-30 14:36 ` Georgi Djakov
  0 siblings, 2 replies; 4+ messages in thread
From: Stephen Boyd @ 2016-03-29 22:58 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-arm, linux-kernel, linux-arm-msm, Georgi Djakov, David Collins

Only the FT SMPS type regulators have slewing supported in the
driver, but all types of SMPS regulators need the same support.
The only difference is that some SMPS regulators don't have a
step size and the step delay is typically 20, not 8. Luckily, the
step size reads as 0 for the non-FT types, so we can always read
that, but we need to detect which type of regulator we're using
to figure out what step delay to use. Make these minor
adjustments to the slew rate calculations and add support for the
delay function to the appropriate regulator ops.

Reported-by: Georgi Djakov <georgi.djakov@linaro.org>
Cc: David Collins <collinsd@codeaurora.org>
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
---
 drivers/regulator/qcom_spmi-regulator.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c
index 88a5dc88badc..c2a63f9e1c10 100644
--- a/drivers/regulator/qcom_spmi-regulator.c
+++ b/drivers/regulator/qcom_spmi-regulator.c
@@ -246,6 +246,7 @@ enum spmi_common_control_register_index {
 
 /* Minimum voltage stepper delay for each step. */
 #define SPMI_FTSMPS_STEP_DELAY		8
+#define SPMI_DEFAULT_STEP_DELAY		20
 
 /*
  * The ratio SPMI_FTSMPS_STEP_MARGIN_NUM/SPMI_FTSMPS_STEP_MARGIN_DEN is used to
@@ -1008,6 +1009,7 @@ static struct regulator_ops spmi_smps_ops = {
 	.disable		= spmi_regulator_common_disable,
 	.is_enabled		= spmi_regulator_common_is_enabled,
 	.set_voltage		= spmi_regulator_common_set_voltage,
+	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
 	.get_voltage		= spmi_regulator_common_get_voltage,
 	.list_voltage		= spmi_regulator_common_list_voltage,
 	.set_mode		= spmi_regulator_common_set_mode,
@@ -1081,6 +1083,7 @@ static struct regulator_ops spmi_ult_lo_smps_ops = {
 	.disable		= spmi_regulator_common_disable,
 	.is_enabled		= spmi_regulator_common_is_enabled,
 	.set_voltage		= spmi_regulator_ult_lo_smps_set_voltage,
+	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
 	.get_voltage		= spmi_regulator_ult_lo_smps_get_voltage,
 	.list_voltage		= spmi_regulator_common_list_voltage,
 	.set_mode		= spmi_regulator_common_set_mode,
@@ -1094,6 +1097,7 @@ static struct regulator_ops spmi_ult_ho_smps_ops = {
 	.disable		= spmi_regulator_common_disable,
 	.is_enabled		= spmi_regulator_common_is_enabled,
 	.set_voltage		= spmi_regulator_single_range_set_voltage,
+	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
 	.get_voltage		= spmi_regulator_single_range_get_voltage,
 	.list_voltage		= spmi_regulator_common_list_voltage,
 	.set_mode		= spmi_regulator_common_set_mode,
@@ -1245,11 +1249,11 @@ found:
 	return 0;
 }
 
-static int spmi_regulator_ftsmps_init_slew_rate(struct spmi_regulator *vreg)
+static int spmi_regulator_init_slew_rate(struct spmi_regulator *vreg)
 {
 	int ret;
 	u8 reg = 0;
-	int step, delay, slew_rate;
+	int step, delay, slew_rate, step_delay;
 	const struct spmi_voltage_range *range;
 
 	ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, &reg, 1);
@@ -1262,6 +1266,15 @@ static int spmi_regulator_ftsmps_init_slew_rate(struct spmi_regulator *vreg)
 	if (!range)
 		return -EINVAL;
 
+	switch (vreg->logical_type) {
+	case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS:
+		step_delay = SPMI_FTSMPS_STEP_DELAY;
+		break;
+	default:
+		step_delay = SPMI_DEFAULT_STEP_DELAY;
+		break;
+	}
+
 	step = reg & SPMI_FTSMPS_STEP_CTRL_STEP_MASK;
 	step >>= SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT;
 
@@ -1270,7 +1283,7 @@ static int spmi_regulator_ftsmps_init_slew_rate(struct spmi_regulator *vreg)
 
 	/* slew_rate has units of uV/us */
 	slew_rate = SPMI_FTSMPS_CLOCK_RATE * range->step_uV * (1 << step);
-	slew_rate /= 1000 * (SPMI_FTSMPS_STEP_DELAY << delay);
+	slew_rate /= 1000 * (step_delay << delay);
 	slew_rate *= SPMI_FTSMPS_STEP_MARGIN_NUM;
 	slew_rate /= SPMI_FTSMPS_STEP_MARGIN_DEN;
 
@@ -1411,8 +1424,11 @@ static int spmi_regulator_of_parse(struct device_node *node,
 		return ret;
 	}
 
-	if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS) {
-		ret = spmi_regulator_ftsmps_init_slew_rate(vreg);
+	if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS ||
+	    vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS ||
+	    vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS ||
+	    vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_SMPS) {
+		ret = spmi_regulator_init_slew_rate(vreg);
 		if (ret)
 			return ret;
 	}
-- 
2.8.0.rc4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] regulator: qcom_spmi: Add slewing delays for all SMPS types
  2016-03-29 22:58 [PATCH] regulator: qcom_spmi: Add slewing delays for all SMPS types Stephen Boyd
@ 2016-03-29 23:09 ` Mark Brown
  2016-03-30 14:36 ` Georgi Djakov
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2016-03-29 23:09 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: linux-arm, linux-kernel, linux-arm-msm, Georgi Djakov, David Collins

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

On Tue, Mar 29, 2016 at 03:58:40PM -0700, Stephen Boyd wrote:

> -	if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS) {
> -		ret = spmi_regulator_ftsmps_init_slew_rate(vreg);
> +	if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS ||
> +	    vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS ||
> +	    vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS ||
> +	    vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_SMPS) {
> +		ret = spmi_regulator_init_slew_rate(vreg);

This should be a switch statement.  Otherwise this looks fine.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] regulator: qcom_spmi: Add slewing delays for all SMPS types
  2016-03-29 22:58 [PATCH] regulator: qcom_spmi: Add slewing delays for all SMPS types Stephen Boyd
  2016-03-29 23:09 ` Mark Brown
@ 2016-03-30 14:36 ` Georgi Djakov
  2016-03-30 18:09   ` Stephen Boyd
  1 sibling, 1 reply; 4+ messages in thread
From: Georgi Djakov @ 2016-03-30 14:36 UTC (permalink / raw)
  To: Stephen Boyd, Mark Brown
  Cc: linux-arm, linux-kernel, linux-arm-msm, David Collins

On 03/30/2016 01:58 AM, Stephen Boyd wrote:
> Only the FT SMPS type regulators have slewing supported in the
> driver, but all types of SMPS regulators need the same support.
> The only difference is that some SMPS regulators don't have a
> step size and the step delay is typically 20, not 8. Luckily, the
> step size reads as 0 for the non-FT types, so we can always read
> that, but we need to detect which type of regulator we're using
> to figure out what step delay to use. Make these minor
> adjustments to the slew rate calculations and add support for the
> delay function to the appropriate regulator ops.
> 
> Reported-by: Georgi Djakov <georgi.djakov@linaro.org>
> Cc: David Collins <collinsd@codeaurora.org>
> Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>

Thanks for the patch! I have verified it by applying this one
on top: https://lkml.org/lkml/2016/3/30/381

Tested-by: Georgi Djakov <georgi.djakov@linaro.org>

BR,
Georgi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] regulator: qcom_spmi: Add slewing delays for all SMPS types
  2016-03-30 14:36 ` Georgi Djakov
@ 2016-03-30 18:09   ` Stephen Boyd
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2016-03-30 18:09 UTC (permalink / raw)
  To: Georgi Djakov, Mark Brown
  Cc: linux-arm, linux-kernel, linux-arm-msm, David Collins

Quoting Georgi Djakov (2016-03-30 07:36:11)
> On 03/30/2016 01:58 AM, Stephen Boyd wrote:
> > Only the FT SMPS type regulators have slewing supported in the
> > driver, but all types of SMPS regulators need the same support.
> > The only difference is that some SMPS regulators don't have a
> > step size and the step delay is typically 20, not 8. Luckily, the
> > step size reads as 0 for the non-FT types, so we can always read
> > that, but we need to detect which type of regulator we're using
> > to figure out what step delay to use. Make these minor
> > adjustments to the slew rate calculations and add support for the
> > delay function to the appropriate regulator ops.
> > 
> > Reported-by: Georgi Djakov <georgi.djakov@linaro.org>
> > Cc: David Collins <collinsd@codeaurora.org>
> > Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
> 
> Thanks for the patch! I have verified it by applying this one
> on top: https://lkml.org/lkml/2016/3/30/381
> 
> Tested-by: Georgi Djakov <georgi.djakov@linaro.org>
> 

Thanks for testing. I'll pick up the rest on the other thread.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-30 18:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-29 22:58 [PATCH] regulator: qcom_spmi: Add slewing delays for all SMPS types Stephen Boyd
2016-03-29 23:09 ` Mark Brown
2016-03-30 14:36 ` Georgi Djakov
2016-03-30 18:09   ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).