diff mbox series

[2/4] regulator: da9062: add of_map_mode support for bucks

Message ID 1573121050-4728-3-git-send-email-chf.fritz@googlemail.com (mailing list archive)
State New, archived
Headers show
Series regulator da9062: support setting buck modes | expand

Commit Message

Christoph Fritz Nov. 7, 2019, 10:04 a.m. UTC
This patch adds of_map_mode support for bucks to set regulator modes
from within regulator framework.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
Signed-off-by: Christian Hemp <c.hemp@phytec.de>
Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
---
 drivers/regulator/da9062-regulator.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Adam Thomson Nov. 8, 2019, 10:42 a.m. UTC | #1
On 07 November 2019 10:04, Christoph Fritz wrote:

> This patch adds of_map_mode support for bucks to set regulator modes
> from within regulator framework.

This looks fine to me, other than a couple of little points below.

> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> Signed-off-by: Christian Hemp <c.hemp@phytec.de>
> Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
> ---
>  drivers/regulator/da9062-regulator.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/regulator/da9062-regulator.c b/drivers/regulator/da9062-
> regulator.c
> index 1a95982..f5f2ead 100644
> --- a/drivers/regulator/da9062-regulator.c
> +++ b/drivers/regulator/da9062-regulator.c
> @@ -98,6 +98,20 @@ static const unsigned int da9062_buck_b_limits[] = {
>  	2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
>  };
> 
> +static unsigned int da906x_map_buck_mode(unsigned int mode)

This can just be called da9062 as this function is only used in this file.

> +{
> +	switch (mode) {
> +	case DA906X_BUCK_MODE_SLEEP:

Obvioulsy these names will want updating as per my comments on patch 01 in the
series.

> +		return REGULATOR_MODE_STANDBY;
> +	case DA906X_BUCK_MODE_SYNC:
> +		return REGULATOR_MODE_FAST;
> +	case DA906X_BUCK_MODE_AUTO:
> +		return REGULATOR_MODE_NORMAL;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
>  static int da9062_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
>  {
>  	struct da9062_regulator *regl = rdev_get_drvdata(rdev);
> @@ -363,6 +377,7 @@ static const struct da9062_regulator_info
> local_da9061_regulator_info[] = {
>  		.desc.vsel_reg = DA9062AA_VBUCK1_A,
>  		.desc.vsel_mask = DA9062AA_VBUCK1_A_MASK,
>  		.desc.linear_min_sel = 0,
> +		.desc.of_map_mode = da906x_map_buck_mode,
>  		.sleep = REG_FIELD(DA9062AA_VBUCK1_A,
>  			__builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
>  			sizeof(unsigned int) * 8 -
> @@ -399,6 +414,7 @@ static const struct da9062_regulator_info
> local_da9061_regulator_info[] = {
>  		.desc.vsel_reg = DA9062AA_VBUCK3_A,
>  		.desc.vsel_mask = DA9062AA_VBUCK3_A_MASK,
>  		.desc.linear_min_sel = 0,
> +		.desc.of_map_mode = da906x_map_buck_mode,
>  		.sleep = REG_FIELD(DA9062AA_VBUCK3_A,
>  			__builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
>  			sizeof(unsigned int) * 8 -
> @@ -435,6 +451,7 @@ static const struct da9062_regulator_info
> local_da9061_regulator_info[] = {
>  		.desc.vsel_reg = DA9062AA_VBUCK4_A,
>  		.desc.vsel_mask = DA9062AA_VBUCK4_A_MASK,
>  		.desc.linear_min_sel = 0,
> +		.desc.of_map_mode = da906x_map_buck_mode,
>  		.sleep = REG_FIELD(DA9062AA_VBUCK4_A,
>  			__builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
>  			sizeof(unsigned int) * 8 -
> @@ -607,6 +624,7 @@ static const struct da9062_regulator_info
> local_da9062_regulator_info[] = {
>  		.desc.vsel_reg = DA9062AA_VBUCK1_A,
>  		.desc.vsel_mask = DA9062AA_VBUCK1_A_MASK,
>  		.desc.linear_min_sel = 0,
> +		.desc.of_map_mode = da906x_map_buck_mode,
>  		.sleep = REG_FIELD(DA9062AA_VBUCK1_A,
>  			__builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
>  			sizeof(unsigned int) * 8 -
> @@ -643,6 +661,7 @@ static const struct da9062_regulator_info
> local_da9062_regulator_info[] = {
>  		.desc.vsel_reg = DA9062AA_VBUCK2_A,
>  		.desc.vsel_mask = DA9062AA_VBUCK2_A_MASK,
>  		.desc.linear_min_sel = 0,
> +		.desc.of_map_mode = da906x_map_buck_mode,
>  		.sleep = REG_FIELD(DA9062AA_VBUCK2_A,
>  			__builtin_ffs((int)DA9062AA_BUCK2_SL_A_MASK) - 1,
>  			sizeof(unsigned int) * 8 -
> @@ -679,6 +698,7 @@ static const struct da9062_regulator_info
> local_da9062_regulator_info[] = {
>  		.desc.vsel_reg = DA9062AA_VBUCK3_A,
>  		.desc.vsel_mask = DA9062AA_VBUCK3_A_MASK,
>  		.desc.linear_min_sel = 0,
> +		.desc.of_map_mode = da906x_map_buck_mode,
>  		.sleep = REG_FIELD(DA9062AA_VBUCK3_A,
>  			__builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
>  			sizeof(unsigned int) * 8 -
> @@ -715,6 +735,7 @@ static const struct da9062_regulator_info
> local_da9062_regulator_info[] = {
>  		.desc.vsel_reg = DA9062AA_VBUCK4_A,
>  		.desc.vsel_mask = DA9062AA_VBUCK4_A_MASK,
>  		.desc.linear_min_sel = 0,
> +		.desc.of_map_mode = da906x_map_buck_mode,
>  		.sleep = REG_FIELD(DA9062AA_VBUCK4_A,
>  			__builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
>  			sizeof(unsigned int) * 8 -
> --
> 2.1.4
diff mbox series

Patch

diff --git a/drivers/regulator/da9062-regulator.c b/drivers/regulator/da9062-regulator.c
index 1a95982..f5f2ead 100644
--- a/drivers/regulator/da9062-regulator.c
+++ b/drivers/regulator/da9062-regulator.c
@@ -98,6 +98,20 @@  static const unsigned int da9062_buck_b_limits[] = {
 	2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
 };
 
+static unsigned int da906x_map_buck_mode(unsigned int mode)
+{
+	switch (mode) {
+	case DA906X_BUCK_MODE_SLEEP:
+		return REGULATOR_MODE_STANDBY;
+	case DA906X_BUCK_MODE_SYNC:
+		return REGULATOR_MODE_FAST;
+	case DA906X_BUCK_MODE_AUTO:
+		return REGULATOR_MODE_NORMAL;
+	default:
+		return -EINVAL;
+	}
+}
+
 static int da9062_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
 {
 	struct da9062_regulator *regl = rdev_get_drvdata(rdev);
@@ -363,6 +377,7 @@  static const struct da9062_regulator_info local_da9061_regulator_info[] = {
 		.desc.vsel_reg = DA9062AA_VBUCK1_A,
 		.desc.vsel_mask = DA9062AA_VBUCK1_A_MASK,
 		.desc.linear_min_sel = 0,
+		.desc.of_map_mode = da906x_map_buck_mode,
 		.sleep = REG_FIELD(DA9062AA_VBUCK1_A,
 			__builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
 			sizeof(unsigned int) * 8 -
@@ -399,6 +414,7 @@  static const struct da9062_regulator_info local_da9061_regulator_info[] = {
 		.desc.vsel_reg = DA9062AA_VBUCK3_A,
 		.desc.vsel_mask = DA9062AA_VBUCK3_A_MASK,
 		.desc.linear_min_sel = 0,
+		.desc.of_map_mode = da906x_map_buck_mode,
 		.sleep = REG_FIELD(DA9062AA_VBUCK3_A,
 			__builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
 			sizeof(unsigned int) * 8 -
@@ -435,6 +451,7 @@  static const struct da9062_regulator_info local_da9061_regulator_info[] = {
 		.desc.vsel_reg = DA9062AA_VBUCK4_A,
 		.desc.vsel_mask = DA9062AA_VBUCK4_A_MASK,
 		.desc.linear_min_sel = 0,
+		.desc.of_map_mode = da906x_map_buck_mode,
 		.sleep = REG_FIELD(DA9062AA_VBUCK4_A,
 			__builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
 			sizeof(unsigned int) * 8 -
@@ -607,6 +624,7 @@  static const struct da9062_regulator_info local_da9062_regulator_info[] = {
 		.desc.vsel_reg = DA9062AA_VBUCK1_A,
 		.desc.vsel_mask = DA9062AA_VBUCK1_A_MASK,
 		.desc.linear_min_sel = 0,
+		.desc.of_map_mode = da906x_map_buck_mode,
 		.sleep = REG_FIELD(DA9062AA_VBUCK1_A,
 			__builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
 			sizeof(unsigned int) * 8 -
@@ -643,6 +661,7 @@  static const struct da9062_regulator_info local_da9062_regulator_info[] = {
 		.desc.vsel_reg = DA9062AA_VBUCK2_A,
 		.desc.vsel_mask = DA9062AA_VBUCK2_A_MASK,
 		.desc.linear_min_sel = 0,
+		.desc.of_map_mode = da906x_map_buck_mode,
 		.sleep = REG_FIELD(DA9062AA_VBUCK2_A,
 			__builtin_ffs((int)DA9062AA_BUCK2_SL_A_MASK) - 1,
 			sizeof(unsigned int) * 8 -
@@ -679,6 +698,7 @@  static const struct da9062_regulator_info local_da9062_regulator_info[] = {
 		.desc.vsel_reg = DA9062AA_VBUCK3_A,
 		.desc.vsel_mask = DA9062AA_VBUCK3_A_MASK,
 		.desc.linear_min_sel = 0,
+		.desc.of_map_mode = da906x_map_buck_mode,
 		.sleep = REG_FIELD(DA9062AA_VBUCK3_A,
 			__builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
 			sizeof(unsigned int) * 8 -
@@ -715,6 +735,7 @@  static const struct da9062_regulator_info local_da9062_regulator_info[] = {
 		.desc.vsel_reg = DA9062AA_VBUCK4_A,
 		.desc.vsel_mask = DA9062AA_VBUCK4_A_MASK,
 		.desc.linear_min_sel = 0,
+		.desc.of_map_mode = da906x_map_buck_mode,
 		.sleep = REG_FIELD(DA9062AA_VBUCK4_A,
 			__builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
 			sizeof(unsigned int) * 8 -