linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] regulator: palma: add ramp delay support through regulator constraints
@ 2013-04-18 13:02 Laxman Dewangan
       [not found] ` <1366290168-3921-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  2013-04-18 17:24 ` Mark Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Laxman Dewangan @ 2013-04-18 13:02 UTC (permalink / raw)
  To: broonie-DgEjT+Ai2ygdnm+yROfE0A
  Cc: sameo-VuQAYsv1563Yd54FQh9/CA, gg-kDsPt+C1G03kYMGBc/C6ZA,
	ian-kDsPt+C1G03kYMGBc/C6ZA, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Laxman Dewangan

Currently Palma regulator driver support the ramp delay
through rail specific platform data.

As regulator framework support the configuration of ramp
delay through regulator constraint, using the framework
method and removing the platform specific data approach.

Signed-off-by: Laxman Dewangan <ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 drivers/regulator/palmas-regulator.c |   93 ++++++++++++++++++++++++++++------
 include/linux/mfd/palmas.h           |   14 +-----
 2 files changed, 79 insertions(+), 28 deletions(-)

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index d6efaf1..f5612c3 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -188,6 +188,8 @@ static const struct regs_info palmas_regs_info[] = {
 	},
 };
 
+static unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500};
+
 #define SMPS_CTRL_MODE_OFF		0x00
 #define SMPS_CTRL_MODE_ON		0x01
 #define SMPS_CTRL_MODE_ECO		0x02
@@ -398,6 +400,56 @@ static int palmas_map_voltage_smps(struct regulator_dev *rdev,
 	return ret;
 }
 
+static int palma_smps_set_voltage_smps_time_sel(struct regulator_dev *rdev,
+	unsigned int old_selector, unsigned int new_selector)
+{
+	struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
+	int id = rdev_get_id(rdev);
+	int old_uv, new_uv;
+	unsigned int ramp_delay = pmic->ramp_delay[id];
+
+	if (!ramp_delay)
+		return 0;
+
+	old_uv = palmas_list_voltage_smps(rdev, old_selector);
+	if (old_uv < 0)
+		return old_uv;
+
+	new_uv = palmas_list_voltage_smps(rdev, new_selector);
+	if (new_uv < 0)
+		return new_uv;
+
+	return DIV_ROUND_UP(abs(old_uv - new_uv), ramp_delay);
+}
+
+static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev,
+		 int ramp_delay)
+{
+	struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
+	int id = rdev_get_id(rdev);
+	unsigned int reg = 0;
+	unsigned int addr = palmas_regs_info[id].tstep_addr;
+	int ret;
+
+	if (ramp_delay <= 0)
+		reg = 0;
+	else if (ramp_delay < 2500)
+		reg = 3;
+	else if (ramp_delay < 5000)
+		reg = 2;
+	else
+		reg = 1;
+
+	ret = palmas_smps_write(pmic->palmas, addr, reg);
+	if (ret < 0) {
+		dev_err(pmic->palmas->dev, "TSTEP write failed: %d\n", ret);
+		return ret;
+	}
+
+	pmic->ramp_delay[id] = palmas_smps_ramp_delay[reg];
+	return ret;
+}
+
 static struct regulator_ops palmas_ops_smps = {
 	.is_enabled		= palmas_is_enabled_smps,
 	.enable			= palmas_enable_smps,
@@ -408,6 +460,8 @@ static struct regulator_ops palmas_ops_smps = {
 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
 	.list_voltage		= palmas_list_voltage_smps,
 	.map_voltage		= palmas_map_voltage_smps,
+	.set_voltage_time_sel	= palma_smps_set_voltage_smps_time_sel,
+	.set_ramp_delay		= palmas_smps_set_ramp_delay,
 };
 
 static struct regulator_ops palmas_ops_smps10 = {
@@ -496,16 +550,6 @@ static int palmas_smps_init(struct palmas *palmas, int id,
 	if (ret)
 		return ret;
 
-	if (palmas_regs_info[id].tstep_addr && reg_init->tstep) {
-		addr = palmas_regs_info[id].tstep_addr;
-
-		reg = reg_init->tstep & PALMAS_SMPS12_TSTEP_TSTEP_MASK;
-
-		ret = palmas_smps_write(palmas, addr, reg);
-		if (ret)
-			return ret;
-	}
-
 	if (palmas_regs_info[id].vsel_addr && reg_init->vsel) {
 		addr = palmas_regs_info[id].vsel_addr;
 
@@ -687,11 +731,6 @@ static void palmas_dt_to_pdata(struct device *dev,
 		if (!ret)
 			pdata->reg_init[idx]->mode_sleep = prop;
 
-		ret = of_property_read_u32(palmas_matches[idx].of_node,
-				"ti,tstep", &prop);
-		if (!ret)
-			pdata->reg_init[idx]->tstep = prop;
-
 		ret = of_property_read_bool(palmas_matches[idx].of_node,
 					    "ti,smps-range");
 		if (ret)
@@ -753,6 +792,7 @@ static int palmas_regulators_probe(struct platform_device *pdev)
 	config.driver_data = pmic;
 
 	for (id = 0; id < PALMAS_REG_LDO1; id++) {
+		bool ramp_delay_support = false;
 
 		/*
 		 * Miss out regulators which are not available due
@@ -763,19 +803,42 @@ static int palmas_regulators_probe(struct platform_device *pdev)
 		case PALMAS_REG_SMPS3:
 			if (pmic->smps123)
 				continue;
+			if (id == PALMAS_REG_SMPS12)
+				ramp_delay_support = true;
 			break;
 		case PALMAS_REG_SMPS123:
 			if (!pmic->smps123)
 				continue;
+			ramp_delay_support = true;
 			break;
 		case PALMAS_REG_SMPS45:
 		case PALMAS_REG_SMPS7:
 			if (pmic->smps457)
 				continue;
+			if (id == PALMAS_REG_SMPS45)
+				ramp_delay_support = true;
 			break;
 		case PALMAS_REG_SMPS457:
 			if (!pmic->smps457)
 				continue;
+			ramp_delay_support = true;
+			break;
+		}
+
+		if ((id == PALMAS_REG_SMPS6) && (id == PALMAS_REG_SMPS8))
+			ramp_delay_support = true;
+
+		if (ramp_delay_support) {
+			addr = palmas_regs_info[id].tstep_addr;
+			ret = palmas_smps_read(pmic->palmas, addr, &reg);
+			if (ret < 0) {
+				dev_err(&pdev->dev,
+					"reading TSTEP reg failed: %d\n", ret);
+				goto err_unregister_regulator;
+			}
+			pmic->desc[id].ramp_delay =
+					palmas_smps_ramp_delay[reg & 0x3];
+			pmic->ramp_delay[id] = pmic->desc[id].ramp_delay;
 		}
 
 		/* Initialise sleep/init values from platform data */
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index 12d8a62..91ef60c 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -119,19 +119,6 @@ struct palmas_reg_init {
 	 */
 	int mode_sleep;
 
-	/* tstep is the timestep loaded to the TSTEP register
-	 *
-	 * For SMPS
-	 *
-	 * 0: Jump (no slope control)
-	 * 1: 10mV/us
-	 * 2: 5mV/us
-	 * 3: 2.5mV/us
-	 *
-	 * For LDO unused
-	 */
-	int tstep;
-
 	/* voltage_sel is the bitfield loaded onto the SMPSX_VOLTAGE
 	 * register. Set this is the default voltage set in OTP needs
 	 * to be overridden.
@@ -350,6 +337,7 @@ struct palmas_pmic {
 	int smps457;
 
 	int range[PALMAS_REG_SMPS10];
+	unsigned int ramp_delay[PALMAS_REG_SMPS10];
 };
 
 struct palmas_resource {
-- 
1.7.1.1

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

* [PATCH 2/2] regulator: palmas: preserve modes of rails during enable/disable
       [not found] ` <1366290168-3921-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2013-04-18 13:02   ` Laxman Dewangan
       [not found]     ` <1366290168-3921-2-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  2013-04-18 13:13   ` [PATCH 1/2] regulator: palma: add ramp delay support through regulator constraints Graeme Gregory
  1 sibling, 1 reply; 5+ messages in thread
From: Laxman Dewangan @ 2013-04-18 13:02 UTC (permalink / raw)
  To: broonie-DgEjT+Ai2ygdnm+yROfE0A
  Cc: sameo-VuQAYsv1563Yd54FQh9/CA, gg-kDsPt+C1G03kYMGBc/C6ZA,
	ian-kDsPt+C1G03kYMGBc/C6ZA, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Laxman Dewangan

The Palma device like TPS65913 have the mode mask which is also
used for enable/disable the rails. The mode bits are defined as
	00: OFF
	01: AUTO
	10: ECO
	11: Forced PWM

and modes are set accordingly as
	REGULATOR_MODE_NORMAL: AUTO
	REGULATOR_MODE_IDLE: ECO
	REGULATOR_MODE_FAST: PWM

Two issue observed:
1. If client calls following sequence:
	regulator_enable(),
	regulator_set_mode(FAST),
	regulator_disable()

	and again the regulator_enable() then the mode is reset
	to NORMAL inplace of keeping the mode as FAST.

	Fixing this by storing the current mode configured by client
	and restoring modes when enable() is called after disable().

2. In following sequence, the regulator get enabled:
	regulator_disable()
	regulator_set_mode(FAST),

	Fixing this by updating new mode in register only if it is
	enabled.

Signed-off-by: Laxman Dewangan <ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 drivers/regulator/palmas-regulator.c |   30 +++++++++++++++++++++++-------
 include/linux/mfd/palmas.h           |    1 +
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index f5612c3..2948d21 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -275,7 +275,10 @@ static int palmas_enable_smps(struct regulator_dev *dev)
 	palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
 
 	reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
-	reg |= SMPS_CTRL_MODE_ON;
+	if (pmic->current_reg_mode[id])
+		reg |= pmic->current_reg_mode[id];
+	else
+		reg |= SMPS_CTRL_MODE_ON;
 
 	palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
 
@@ -297,16 +300,19 @@ static int palmas_disable_smps(struct regulator_dev *dev)
 	return 0;
 }
 
-
 static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
 {
 	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
 	int id = rdev_get_id(dev);
 	unsigned int reg;
+	bool rail_enable = true;
 
 	palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
 	reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
 
+	if (reg == SMPS_CTRL_MODE_OFF)
+		rail_enable = false;
+
 	switch (mode) {
 	case REGULATOR_MODE_NORMAL:
 		reg |= SMPS_CTRL_MODE_ON;
@@ -320,8 +326,11 @@ static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
 	default:
 		return -EINVAL;
 	}
-	palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
 
+	pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
+	if (rail_enable)
+		palmas_smps_write(pmic->palmas,
+			palmas_regs_info[id].ctrl_addr, reg);
 	return 0;
 }
 
@@ -331,9 +340,7 @@ static unsigned int palmas_get_mode_smps(struct regulator_dev *dev)
 	int id = rdev_get_id(dev);
 	unsigned int reg;
 
-	palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
-	reg &= PALMAS_SMPS12_CTRL_STATUS_MASK;
-	reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT;
+	reg = pmic->current_reg_mode[id] & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
 
 	switch (reg) {
 	case SMPS_CTRL_MODE_ON:
@@ -872,7 +879,8 @@ static int palmas_regulators_probe(struct platform_device *pdev)
 			/*
 			 * Read and store the RANGE bit for later use
 			 * This must be done before regulator is probed,
-			 * otherwise we error in probe with unsupportable ranges.
+			 * otherwise we error in probe with unsupportable
+			 * ranges. Read the current smps mode for later use.
 			 */
 			addr = palmas_regs_info[id].vsel_addr;
 
@@ -889,6 +897,14 @@ static int palmas_regulators_probe(struct platform_device *pdev)
 						palmas_regs_info[id].vsel_addr);
 			pmic->desc[id].vsel_mask =
 					PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
+
+			/* Read the smps mode for later use. */
+			addr = palmas_regs_info[id].ctrl_addr;
+			ret = palmas_smps_read(pmic->palmas, addr, &reg);
+			if (ret)
+				goto err_unregister_regulator;
+			pmic->current_reg_mode[id] = reg &
+					PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
 		}
 
 		pmic->desc[id].type = REGULATOR_VOLTAGE;
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index 91ef60c..8f21daf 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -338,6 +338,7 @@ struct palmas_pmic {
 
 	int range[PALMAS_REG_SMPS10];
 	unsigned int ramp_delay[PALMAS_REG_SMPS10];
+	unsigned int current_reg_mode[PALMAS_REG_SMPS10];
 };
 
 struct palmas_resource {
-- 
1.7.1.1

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

* Re: [PATCH 1/2] regulator: palma: add ramp delay support through regulator constraints
       [not found] ` <1366290168-3921-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  2013-04-18 13:02   ` [PATCH 2/2] regulator: palmas: preserve modes of rails during enable/disable Laxman Dewangan
@ 2013-04-18 13:13   ` Graeme Gregory
  1 sibling, 0 replies; 5+ messages in thread
From: Graeme Gregory @ 2013-04-18 13:13 UTC (permalink / raw)
  To: Laxman Dewangan
  Cc: broonie-DgEjT+Ai2ygdnm+yROfE0A, sameo-VuQAYsv1563Yd54FQh9/CA,
	ian-kDsPt+C1G03kYMGBc/C6ZA, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA

This looks good to me.

Acked-by: Graeme Gregory <gg-kDsPt+C1G03kYMGBc/C6ZA@public.gmane.org>

On 18/04/13 14:02, Laxman Dewangan wrote:
> Currently Palma regulator driver support the ramp delay
> through rail specific platform data.
>
> As regulator framework support the configuration of ramp
> delay through regulator constraint, using the framework
> method and removing the platform specific data approach.
>
> Signed-off-by: Laxman Dewangan <ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---
>  drivers/regulator/palmas-regulator.c |   93 ++++++++++++++++++++++++++++------
>  include/linux/mfd/palmas.h           |   14 +-----
>  2 files changed, 79 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
> index d6efaf1..f5612c3 100644
> --- a/drivers/regulator/palmas-regulator.c
> +++ b/drivers/regulator/palmas-regulator.c
> @@ -188,6 +188,8 @@ static const struct regs_info palmas_regs_info[] = {
>  	},
>  };
>  
> +static unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500};
> +
>  #define SMPS_CTRL_MODE_OFF		0x00
>  #define SMPS_CTRL_MODE_ON		0x01
>  #define SMPS_CTRL_MODE_ECO		0x02
> @@ -398,6 +400,56 @@ static int palmas_map_voltage_smps(struct regulator_dev *rdev,
>  	return ret;
>  }
>  
> +static int palma_smps_set_voltage_smps_time_sel(struct regulator_dev *rdev,
> +	unsigned int old_selector, unsigned int new_selector)
> +{
> +	struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
> +	int id = rdev_get_id(rdev);
> +	int old_uv, new_uv;
> +	unsigned int ramp_delay = pmic->ramp_delay[id];
> +
> +	if (!ramp_delay)
> +		return 0;
> +
> +	old_uv = palmas_list_voltage_smps(rdev, old_selector);
> +	if (old_uv < 0)
> +		return old_uv;
> +
> +	new_uv = palmas_list_voltage_smps(rdev, new_selector);
> +	if (new_uv < 0)
> +		return new_uv;
> +
> +	return DIV_ROUND_UP(abs(old_uv - new_uv), ramp_delay);
> +}
> +
> +static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev,
> +		 int ramp_delay)
> +{
> +	struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
> +	int id = rdev_get_id(rdev);
> +	unsigned int reg = 0;
> +	unsigned int addr = palmas_regs_info[id].tstep_addr;
> +	int ret;
> +
> +	if (ramp_delay <= 0)
> +		reg = 0;
> +	else if (ramp_delay < 2500)
> +		reg = 3;
> +	else if (ramp_delay < 5000)
> +		reg = 2;
> +	else
> +		reg = 1;
> +
> +	ret = palmas_smps_write(pmic->palmas, addr, reg);
> +	if (ret < 0) {
> +		dev_err(pmic->palmas->dev, "TSTEP write failed: %d\n", ret);
> +		return ret;
> +	}
> +
> +	pmic->ramp_delay[id] = palmas_smps_ramp_delay[reg];
> +	return ret;
> +}
> +
>  static struct regulator_ops palmas_ops_smps = {
>  	.is_enabled		= palmas_is_enabled_smps,
>  	.enable			= palmas_enable_smps,
> @@ -408,6 +460,8 @@ static struct regulator_ops palmas_ops_smps = {
>  	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
>  	.list_voltage		= palmas_list_voltage_smps,
>  	.map_voltage		= palmas_map_voltage_smps,
> +	.set_voltage_time_sel	= palma_smps_set_voltage_smps_time_sel,
> +	.set_ramp_delay		= palmas_smps_set_ramp_delay,
>  };
>  
>  static struct regulator_ops palmas_ops_smps10 = {
> @@ -496,16 +550,6 @@ static int palmas_smps_init(struct palmas *palmas, int id,
>  	if (ret)
>  		return ret;
>  
> -	if (palmas_regs_info[id].tstep_addr && reg_init->tstep) {
> -		addr = palmas_regs_info[id].tstep_addr;
> -
> -		reg = reg_init->tstep & PALMAS_SMPS12_TSTEP_TSTEP_MASK;
> -
> -		ret = palmas_smps_write(palmas, addr, reg);
> -		if (ret)
> -			return ret;
> -	}
> -
>  	if (palmas_regs_info[id].vsel_addr && reg_init->vsel) {
>  		addr = palmas_regs_info[id].vsel_addr;
>  
> @@ -687,11 +731,6 @@ static void palmas_dt_to_pdata(struct device *dev,
>  		if (!ret)
>  			pdata->reg_init[idx]->mode_sleep = prop;
>  
> -		ret = of_property_read_u32(palmas_matches[idx].of_node,
> -				"ti,tstep", &prop);
> -		if (!ret)
> -			pdata->reg_init[idx]->tstep = prop;
> -
>  		ret = of_property_read_bool(palmas_matches[idx].of_node,
>  					    "ti,smps-range");
>  		if (ret)
> @@ -753,6 +792,7 @@ static int palmas_regulators_probe(struct platnetform_device *pdev)
>  	config.driver_data = pmic;
>  
>  	for (id = 0; id < PALMAS_REG_LDO1; id++) {
> +		bool ramp_delay_support = false;
>  
>  		/*
>  		 * Miss out regulators which are not available due
> @@ -763,19 +803,42 @@ static int palmas_regulators_probe(struct platform_device *pdev)
>  		case PALMAS_REG_SMPS3:
>  			if (pmic->smps123)
>  				continue;net
> +			if (id == PALMAS_REG_SMPS12)
> +				ramp_delay_support = true;
>  			break;
>  		case PALMAS_REG_SMPS123:
>  			if (!pmic->smps123)
>  				continue;
> +			ramp_delay_support = true;
>  			break;
>  		case PALMAS_REG_SMPS45:
>  		case PALMAS_REG_SMPS7:
>  			if (pmic->smps457)
>  				continue;
> +			if (id == PALMAS_REG_SMPS45)
> +				ramp_delay_support = true;
>  			break;
>  		case PALMAS_REG_SMPS457:
>  			if (!pmic->smps457)
>  				continue;
> +			ramp_delay_support = true;
> +			break;
> +		}
> +
> +		if ((id == PALMAS_REG_SMPS6) && (id == PALMAS_REG_SMPS8))
> +			ramp_delay_support = true;
> +
> +		if (ramp_delay_support) {
> +			addr = palmas_regs_info[id].tstep_addr;
> +			ret = palmas_smps_read(pmic->palmas, addr, &reg);
> +			if (ret < 0) {
> +				dev_err(&pdev->dev,
> +					"reading TSTEP reg failed: %d\n", ret);
> +				goto err_unregister_regulator;
> +			}
> +			pmic->desc[id].ramp_delay =
> +					palmas_smps_ramp_delay[reg & 0x3];
> +			pmic->ramp_delay[id] = pmic->desc[id].ramp_delay;
>  		}
>  
>  		/* Initialise sleep/init values from platform data */
> diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
> index 12d8a62..91ef60c 100644
> --- a/include/linux/mfd/palmas.h
> +++ b/include/linux/mfd/palmas.h
> @@ -119,19 +119,6 @@ struct palmas_reg_init {
>  	 */
>  	int mode_sleep;
>  
> -	/* tstep is the timestep loaded to the TSTEP register
> -	 *
> -	 * For SMPS
> -	 *
> -	 * 0: Jump (no slope control)
> -	 * 1: 10mV/us
> -	 * 2: 5mV/us
> -	 * 3: 2.5mV/us
> -	 *
> -	 * For LDO unused
> -	 */
> -	int tstep;
> -
>  	/* voltage_sel is the bitfield loaded onto the SMPSX_VOLTAGE
>  	 * register. Set this is the default voltage set in OTP needs
>  	 * to be overridden.
> @@ -350,6 +337,7 @@ struct palmas_pmic {
>  	int smps457;
>  
>  	int range[PALMAS_REG_SMPS10];
> +	unsigned int ramp_delay[PALMAS_REG_SMPS10];
>  };
>  
>  struct palmas_resource {

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

* Re: [PATCH 2/2] regulator: palmas: preserve modes of rails during enable/disable
       [not found]     ` <1366290168-3921-2-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2013-04-18 13:13       ` Graeme Gregory
  0 siblings, 0 replies; 5+ messages in thread
From: Graeme Gregory @ 2013-04-18 13:13 UTC (permalink / raw)
  To: Laxman Dewangan
  Cc: broonie-DgEjT+Ai2ygdnm+yROfE0A, sameo-VuQAYsv1563Yd54FQh9/CA,
	ian-kDsPt+C1G03kYMGBc/C6ZA, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA

This looks good to me.

Acked-by: Graeme Gregory <gg-kDsPt+C1G03kYMGBc/C6ZA@public.gmane.org>

On 18/04/13 14:02, Laxman Dewangan wrote:
> The Palma device like TPS65913 have the mode mask which is also
> used for enable/disable the rails. The mode bits are defined as
> 	00: OFF
> 	01: AUTO
> 	10: ECO
> 	11: Forced PWM
>
> and modes are set accordingly as
> 	REGULATOR_MODE_NORMAL: AUTO
> 	REGULATOR_MODE_IDLE: ECO
> 	REGULATOR_MODE_FAST: PWM
>
> Two issue observed:
> 1. If client calls following sequence:
> 	regulator_enable(),
> 	regulator_set_mode(FAST),
> 	regulator_disable()
>
> 	and again the regulator_enable() then the mode is reset
> 	to NORMAL inplace of keeping the mode as FAST.
>
> 	Fixing this by storing the current mode configured by client
> 	and restoring modes when enable() is called after disable().
>
> 2. In following sequence, the regulator get enabled:
> 	regulator_disable()
> 	regulator_set_mode(FAST),
>
> 	Fixing this by updating new mode in register only if it is
> 	enabled.
>
> Signed-off-by: Laxman Dewangan <ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---
>  drivers/regulator/palmas-regulator.c |   30 +++++++++++++++++++++++-------
>  include/linux/mfd/palmas.h           |    1 +
>  2 files changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
> index f5612c3..2948d21 100644
> --- a/drivers/regulator/palmas-regulator.c
> +++ b/drivers/regulator/palmas-regulator.c
> @@ -275,7 +275,10 @@ static int palmas_enable_smps(struct regulator_dev *dev)
>  	palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
>  
>  	reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
> -	reg |= SMPS_CTRL_MODE_ON;
> +	if (pmic->current_reg_mode[id])
> +		reg |= pmic->current_reg_mode[id];
> +	else
> +		reg |= SMPS_CTRL_MODE_ON;
>  
>  	palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
>  
> @@ -297,16 +300,19 @@ static int palmas_disable_smps(struct regulator_dev *dev)
>  	return 0;
>  }
>  
> -
>  static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
>  {
>  	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
>  	int id = rdev_get_id(dev);
>  	unsigned int reg;
> +	bool rail_enable = true;
>  
>  	palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
>  	reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
>  
> +	if (reg == SMPS_CTRL_MODE_OFF)
> +		rail_enable = false;
> +
>  	switch (mode) {
>  	case REGULATOR_MODE_NORMAL:
>  		reg |= SMPS_CTRL_MODE_ON;
> @@ -320,8 +326,11 @@ static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
>  	default:
>  		return -EINVAL;
>  	}
> -	palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
>  
> +	pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
> +	if (rail_enable)
> +		palmas_smps_write(pmic->palmas,
> +			palmas_regs_info[id].ctrl_addr, reg);
>  	return 0;
>  }
>  
> @@ -331,9 +340,7 @@ static unsigned int palmas_get_mode_smps(struct regulator_dev *dev)
>  	int id = rdev_get_id(dev);
>  	unsigned int reg;
>  
> -	palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
> -	reg &= PALMAS_SMPS12_CTRL_STATUS_MASK;
> -	reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT;
> +	reg = pmic->current_reg_mode[id] & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
>  
>  	switch (reg) {
>  	casThis looks good to me.
>
>
>
> Acked-by: Graeme Gregory <gg-kDsPt+C1G03kYMGBc/C6ZA@public.gmane.org>e SMPS_CTRL_MODE_ON:
> @@ -872,7 +879,8 @@ static int palmas_regulators_probe(struct platform_device *pdev)
>  			/*
>  			 * Read and store the RANGE bit for later use
>  			 * This must be done before regulator is probed,
> -			 * otherwise we error in probe with unsupportable ranges.
> +			 * otherwise we error in probe with unsupportable
> +			 * ranges. Read the current smps mode for later use.
>  			 */
>  			addr = palmas_regs_info[id].vsel_addr;
>  
> @@ -889,6 +897,14 @@ static int palmas_regulators_probe(struct platform_device *pdev)
>  						palmas_regs_info[id].vsel_addr);
>  			pmic->desc[id].vsel_mask =
>  					PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
> +This looks good to me.
>
>
>
> Acked-by: Graeme Gregory <gg-kDsPt+C1G03kYMGBc/C6ZA@public.gmane.org>
> +			/* Read the smps mode for later use. */
> +			addr = palmas_regs_info[id].ctrl_addr;
> +			ret = palmas_smps_read(pmic->palmas, addr, &reg);
> +			if (ret)
> +				goto err_unregister_regulator;
> +			pmic->current_reg_mode[id] = reg &
> +					PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
>  		}
>  
>  		pmic->desc[id].type = REGULATOR_VOLTAGE;
> diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
> index 91ef60c..8f21daf 100644
> --- a/include/linux/mfd/palmas.h
> +++ b/include/linux/mfd/palmas.h
> @@ -338,6 +338,7 @@ struct palmas_pmic {
>  
>  	int range[PALMAS_REG_SMPS10];
>  	unsigned int ramp_delay[PALMAS_REG_SMPS10];
> +	unsigned int current_reg_mode[PALMAS_REG_SMPS10];
>  };
>  
>  struct palmas_resource {

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

* Re: [PATCH 1/2] regulator: palma: add ramp delay support through regulator constraints
  2013-04-18 13:02 [PATCH 1/2] regulator: palma: add ramp delay support through regulator constraints Laxman Dewangan
       [not found] ` <1366290168-3921-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2013-04-18 17:24 ` Mark Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Brown @ 2013-04-18 17:24 UTC (permalink / raw)
  To: Laxman Dewangan; +Cc: sameo, gg, ian, linux-kernel, linux-tegra

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

On Thu, Apr 18, 2013 at 06:32:47PM +0530, Laxman Dewangan wrote:
> Currently Palma regulator driver support the ramp delay
> through rail specific platform data.
> 
> As regulator framework support the configuration of ramp
> delay through regulator constraint, using the framework
> method and removing the platform specific data approach.

Applied both, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2013-04-18 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-18 13:02 [PATCH 1/2] regulator: palma: add ramp delay support through regulator constraints Laxman Dewangan
     [not found] ` <1366290168-3921-1-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-04-18 13:02   ` [PATCH 2/2] regulator: palmas: preserve modes of rails during enable/disable Laxman Dewangan
     [not found]     ` <1366290168-3921-2-git-send-email-ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-04-18 13:13       ` Graeme Gregory
2013-04-18 13:13   ` [PATCH 1/2] regulator: palma: add ramp delay support through regulator constraints Graeme Gregory
2013-04-18 17:24 ` Mark Brown

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).