linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] regulator: tps65218: Fix LS3 and add LS2
@ 2019-02-20  8:15 Christian Hohnstaedt
  2019-02-20  8:15 ` [PATCH 1/3] regulator: tps65218.c: fix LS3 issues Christian Hohnstaedt
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Christian Hohnstaedt @ 2019-02-20  8:15 UTC (permalink / raw)
  To: J Keerthy
  Cc: Liam Girdwood, Mark Brown, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

The patch-series fixes issues in the LS3 configuration
and adds support for the LS2 regulator in the tps65218

Christian Hohnstaedt (3):
  regulator: tps65218.c: fix LS3 issues
  dt-bindings: regulator: Add LS2 load switch
  regulator: tps65218: Add support for LS2

 .../devicetree/bindings/regulator/tps65218.txt     |  9 +++++++--
 drivers/regulator/tps65218-regulator.c             | 23 +++++++++++++++-------
 2 files changed, 23 insertions(+), 9 deletions(-)

-- 
2.7.4


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

* [PATCH 1/3] regulator: tps65218.c: fix LS3 issues
  2019-02-20  8:15 [PATCH 0/3] regulator: tps65218: Fix LS3 and add LS2 Christian Hohnstaedt
@ 2019-02-20  8:15 ` Christian Hohnstaedt
  2019-02-20 16:40   ` Mark Brown
  2019-02-20  8:15 ` [PATCH 2/3] dt-bindings: regulator: Add LS2 load switch Christian Hohnstaedt
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Christian Hohnstaedt @ 2019-02-20  8:15 UTC (permalink / raw)
  To: J Keerthy
  Cc: Liam Girdwood, Mark Brown, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

- Fix list of valid LS3 currents from mA to µA
- Fix selection of min/max microAmps of LS3.
  Selecting one of the configured values as max value now really
  selects it instead of the next lower one

Signed-off-by: Christian Hohnstaedt <Christian.Hohnstaedt@wago.com>
---
 drivers/regulator/tps65218-regulator.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/tps65218-regulator.c b/drivers/regulator/tps65218-regulator.c
index 6209bee..5dd559e 100644
--- a/drivers/regulator/tps65218-regulator.c
+++ b/drivers/regulator/tps65218-regulator.c
@@ -188,7 +188,8 @@ static struct regulator_ops tps65218_ldo1_dcdc34_ops = {
 	.set_suspend_disable	= tps65218_pmic_set_suspend_disable,
 };
 
-static const int ls3_currents[] = { 100, 200, 500, 1000 };
+static const int ls3_currents[] = { 100000, 200000, 500000, 1000000 };
+
 
 static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,
 					       int lim_uA)
@@ -214,7 +215,7 @@ static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
 	unsigned int num_currents = ARRAY_SIZE(ls3_currents);
 	struct tps65218 *tps = rdev_get_drvdata(dev);
 
-	while (index < num_currents && ls3_currents[index] < max_uA)
+	while (index < num_currents && ls3_currents[index] <= max_uA)
 		index++;
 
 	index--;
-- 
2.7.4


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

* [PATCH 2/3] dt-bindings: regulator: Add LS2 load switch
  2019-02-20  8:15 [PATCH 0/3] regulator: tps65218: Fix LS3 and add LS2 Christian Hohnstaedt
  2019-02-20  8:15 ` [PATCH 1/3] regulator: tps65218.c: fix LS3 issues Christian Hohnstaedt
@ 2019-02-20  8:15 ` Christian Hohnstaedt
  2019-02-20  8:15 ` [PATCH 3/3] regulator: tps65218: Add support for LS2 Christian Hohnstaedt
  2019-02-25  6:41 ` [PATCH v2 0/2] regulator: tps65218: support LS2 Christian Hohnstaedt
  3 siblings, 0 replies; 12+ messages in thread
From: Christian Hohnstaedt @ 2019-02-20  8:15 UTC (permalink / raw)
  To: J Keerthy
  Cc: Liam Girdwood, Mark Brown, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

and change units of LS3 example from microvolt to microamp

Signed-off-by: Christian Hohnstaedt <Christian.Hohnstaedt@wago.com>
---
 Documentation/devicetree/bindings/regulator/tps65218.txt | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/regulator/tps65218.txt b/Documentation/devicetree/bindings/regulator/tps65218.txt
index 02f0e9b..54aded3 100644
--- a/Documentation/devicetree/bindings/regulator/tps65218.txt
+++ b/Documentation/devicetree/bindings/regulator/tps65218.txt
@@ -71,8 +71,13 @@ tps65218: tps65218@24 {
 		regulator-always-on;
 	};
 
+	ls2: regulator-ls2 {
+		regulator-min-microamp = <100000>;
+		regulator-max-microamp = <1000000>;
+	};
+
 	ls3: regulator-ls3 {
-		regulator-min-microvolt = <100000>;
-		regulator-max-microvolt = <1000000>;
+		regulator-min-microamp = <100000>;
+		regulator-max-microamp = <1000000>;
 	};
 };
-- 
2.7.4


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

* [PATCH 3/3] regulator: tps65218: Add support for LS2
  2019-02-20  8:15 [PATCH 0/3] regulator: tps65218: Fix LS3 and add LS2 Christian Hohnstaedt
  2019-02-20  8:15 ` [PATCH 1/3] regulator: tps65218.c: fix LS3 issues Christian Hohnstaedt
  2019-02-20  8:15 ` [PATCH 2/3] dt-bindings: regulator: Add LS2 load switch Christian Hohnstaedt
@ 2019-02-20  8:15 ` Christian Hohnstaedt
  2019-02-20 16:48   ` Mark Brown
  2019-02-25  6:41 ` [PATCH v2 0/2] regulator: tps65218: support LS2 Christian Hohnstaedt
  3 siblings, 1 reply; 12+ messages in thread
From: Christian Hohnstaedt @ 2019-02-20  8:15 UTC (permalink / raw)
  To: J Keerthy
  Cc: Liam Girdwood, Mark Brown, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

Re-use the "tps65218_pmic_*_current_limit()" functions of LS3
and calculate the different required bit-shift by counting the
trailing 0s in "struct regulator_desc.csel_mask"

Signed-off-by: Christian Hohnstaedt <Christian.Hohnstaedt@wago.com>
---
 drivers/regulator/tps65218-regulator.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/tps65218-regulator.c b/drivers/regulator/tps65218-regulator.c
index 5dd559e..95708d3 100644
--- a/drivers/regulator/tps65218-regulator.c
+++ b/drivers/regulator/tps65218-regulator.c
@@ -205,7 +205,8 @@ static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,
 		return -EINVAL;
 
 	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
-				 index << 2, TPS65218_PROTECT_L1);
+				 index << __builtin_ctz(dev->desc->csel_mask),
+				 TPS65218_PROTECT_L1);
 }
 
 static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
@@ -224,7 +225,8 @@ static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
 		return -EINVAL;
 
 	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
-				 index << 2, TPS65218_PROTECT_L1);
+				 index << __builtin_ctz(dev->desc->csel_mask),
+				 TPS65218_PROTECT_L1);
 }
 
 static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)
@@ -237,12 +239,13 @@ static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)
 	if (retval < 0)
 		return retval;
 
-	index = (index & dev->desc->csel_mask) >> 2;
+	index = (index & dev->desc->csel_mask) >>
+					 __builtin_ctz(dev->desc->csel_mask);
 
 	return ls3_currents[index];
 }
 
-static struct regulator_ops tps65218_ls3_ops = {
+static struct regulator_ops tps65218_ls23_ops = {
 	.is_enabled		= regulator_is_enabled_regmap,
 	.enable			= tps65218_pmic_enable,
 	.disable		= tps65218_pmic_disable,
@@ -304,8 +307,13 @@ static const struct regulator_desc regulators[] = {
 			   TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges,
 			   2, 0, 0, TPS65218_REG_SEQ6,
 			   TPS65218_SEQ6_LDO1_SEQ_MASK),
+	TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
+			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
+			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,
+			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,
+			   NULL, 0, 0, 0, 0, 0),
 	TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3,
-			   REGULATOR_CURRENT, tps65218_ls3_ops, 0, 0, 0,
+			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
 			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN,
 			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK,
 			   NULL, 0, 0, 0, 0, 0),
-- 
2.7.4


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

* Re: [PATCH 1/3] regulator: tps65218.c: fix LS3 issues
  2019-02-20  8:15 ` [PATCH 1/3] regulator: tps65218.c: fix LS3 issues Christian Hohnstaedt
@ 2019-02-20 16:40   ` Mark Brown
  0 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2019-02-20 16:40 UTC (permalink / raw)
  To: Christian Hohnstaedt
  Cc: J Keerthy, Liam Girdwood, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

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

On Wed, Feb 20, 2019 at 09:15:50AM +0100, Christian Hohnstaedt wrote:

> - Fix list of valid LS3 currents from mA to µA
> - Fix selection of min/max microAmps of LS3.
>   Selecting one of the configured values as max value now really
>   selects it instead of the next lower one

This is two separate changes so should have been two separate patches,
that way things are easier to review since it's clear what change does
what and if there's a problem with one change the other doesn't need to
get held up.

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

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

* Re: [PATCH 3/3] regulator: tps65218: Add support for LS2
  2019-02-20  8:15 ` [PATCH 3/3] regulator: tps65218: Add support for LS2 Christian Hohnstaedt
@ 2019-02-20 16:48   ` Mark Brown
  2019-02-22  8:38     ` [PATCH v2] " Christian Hohnstaedt
  0 siblings, 1 reply; 12+ messages in thread
From: Mark Brown @ 2019-02-20 16:48 UTC (permalink / raw)
  To: Christian Hohnstaedt
  Cc: J Keerthy, Liam Girdwood, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

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

On Wed, Feb 20, 2019 at 09:15:52AM +0100, Christian Hohnstaedt wrote:

> +	TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
> +			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
> +			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,
> +			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,
> +			   NULL, 0, 0, 0, 0, 0),

This doesn't build:

drivers/regulator/tps65218-regulator.c:309:45: error: ‘TPS65218_LS_2’ undeclared here (not in a function); did you mean ‘TPS65218_LS_3’?
  TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
                                             ^~~~~~~~~~~~~
drivers/regulator/tps65218-regulator.c:36:11: note: in definition of macro ‘TPS65218_REGULATOR’
   .id   = _id,   \
           ^~~


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

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

* [PATCH v2] regulator: tps65218: Add support for LS2
  2019-02-20 16:48   ` Mark Brown
@ 2019-02-22  8:38     ` Christian Hohnstaedt
  2019-02-22 12:19       ` Mark Brown
  0 siblings, 1 reply; 12+ messages in thread
From: Christian Hohnstaedt @ 2019-02-22  8:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: J Keerthy, Liam Girdwood, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

Re-use the "tps65218_pmic_*_current_limit()" functions of LS3
and calculate the different required bit-shift by counting the
trailing 0s in "struct regulator_desc.csel_mask"

Signed-off-by: Christian Hohnstaedt <Christian.Hohnstaedt@wago.com>
---

Somehow the header changes got lost in the first patch, Sorry.

 drivers/regulator/tps65218-regulator.c | 18 +++++++++++++-----
 include/linux/mfd/tps65218.h           |  3 ++-
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/tps65218-regulator.c b/drivers/regulator/tps65218-regulator.c
index 5dd559e..95708d3 100644
--- a/drivers/regulator/tps65218-regulator.c
+++ b/drivers/regulator/tps65218-regulator.c
@@ -205,7 +205,8 @@ static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,
 		return -EINVAL;
 
 	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
-				 index << 2, TPS65218_PROTECT_L1);
+				 index << __builtin_ctz(dev->desc->csel_mask),
+				 TPS65218_PROTECT_L1);
 }
 
 static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
@@ -224,7 +225,8 @@ static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
 		return -EINVAL;
 
 	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
-				 index << 2, TPS65218_PROTECT_L1);
+				 index << __builtin_ctz(dev->desc->csel_mask),
+				 TPS65218_PROTECT_L1);
 }
 
 static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)
@@ -237,12 +239,13 @@ static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)
 	if (retval < 0)
 		return retval;
 
-	index = (index & dev->desc->csel_mask) >> 2;
+	index = (index & dev->desc->csel_mask) >>
+					 __builtin_ctz(dev->desc->csel_mask);
 
 	return ls3_currents[index];
 }
 
-static struct regulator_ops tps65218_ls3_ops = {
+static struct regulator_ops tps65218_ls23_ops = {
 	.is_enabled		= regulator_is_enabled_regmap,
 	.enable			= tps65218_pmic_enable,
 	.disable		= tps65218_pmic_disable,
@@ -304,8 +307,13 @@ static const struct regulator_desc regulators[] = {
 			   TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges,
 			   2, 0, 0, TPS65218_REG_SEQ6,
 			   TPS65218_SEQ6_LDO1_SEQ_MASK),
+	TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
+			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
+			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,
+			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,
+			   NULL, 0, 0, 0, 0, 0),
 	TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3,
-			   REGULATOR_CURRENT, tps65218_ls3_ops, 0, 0, 0,
+			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
 			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN,
 			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK,
 			   NULL, 0, 0, 0, 0, 0),
diff --git a/include/linux/mfd/tps65218.h b/include/linux/mfd/tps65218.h
index 3cbe103..b0470c3 100644
--- a/include/linux/mfd/tps65218.h
+++ b/include/linux/mfd/tps65218.h
@@ -212,6 +212,7 @@ enum tps65218_regulator_id {
 	/* LDOs */
 	TPS65218_LDO_1,
 	/* LS's */
+	TPS65218_LS_2,
 	TPS65218_LS_3,
 };
 
@@ -222,7 +223,7 @@ enum tps65218_regulator_id {
 /* Number of LDO voltage regulators available */
 #define TPS65218_NUM_LDO		1
 /* Number of total LS current regulators available */
-#define TPS65218_NUM_LS			1
+#define TPS65218_NUM_LS			2
 /* Number of total regulators available */
 #define TPS65218_NUM_REGULATOR		(TPS65218_NUM_DCDC + TPS65218_NUM_LDO \
 					 + TPS65218_NUM_LS)
-- 
2.7.4


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

* Re: [PATCH v2] regulator: tps65218: Add support for LS2
  2019-02-22  8:38     ` [PATCH v2] " Christian Hohnstaedt
@ 2019-02-22 12:19       ` Mark Brown
  0 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2019-02-22 12:19 UTC (permalink / raw)
  To: Christian Hohnstaedt
  Cc: J Keerthy, Liam Girdwood, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

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

On Fri, Feb 22, 2019 at 09:38:54AM +0100, Christian Hohnstaedt wrote:
> Re-use the "tps65218_pmic_*_current_limit()" functions of LS3
> and calculate the different required bit-shift by counting the
> trailing 0s in "struct regulator_desc.csel_mask"

Can you please also resend the DT bindings change?

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

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

* [PATCH v2 0/2] regulator: tps65218: support LS2
  2019-02-20  8:15 [PATCH 0/3] regulator: tps65218: Fix LS3 and add LS2 Christian Hohnstaedt
                   ` (2 preceding siblings ...)
  2019-02-20  8:15 ` [PATCH 3/3] regulator: tps65218: Add support for LS2 Christian Hohnstaedt
@ 2019-02-25  6:41 ` Christian Hohnstaedt
  2019-02-25  6:41   ` [PATCH v2 1/2] dt-bindings: regulator: add LS2 load switch documentation Christian Hohnstaedt
  2019-02-25  6:41   ` [PATCH v2 2/2] regulator: tps65218: add support for LS2 Christian Hohnstaedt
  3 siblings, 2 replies; 12+ messages in thread
From: Christian Hohnstaedt @ 2019-02-25  6:41 UTC (permalink / raw)
  To: Mark Brown
  Cc: J Keerthy, Liam Girdwood, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

Add support for the LS2 regulator in the tps65218 device


Christian Hohnstaedt (2):
  dt-bindings: regulator: Add LS2 load switch documentation
  regulator: tps65218: Add support for LS2

 .../devicetree/bindings/regulator/tps65218.txt         |  4 ++--
 drivers/regulator/tps65218-regulator.c                 | 18 +++++++++++++-----
 include/linux/mfd/tps65218.h                           |  3 ++-
 3 files changed, 17 insertions(+), 8 deletions(-)

-- 
2.7.4


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

* [PATCH v2 1/2] dt-bindings: regulator: add LS2 load switch documentation
  2019-02-25  6:41 ` [PATCH v2 0/2] regulator: tps65218: support LS2 Christian Hohnstaedt
@ 2019-02-25  6:41   ` Christian Hohnstaedt
  2019-02-27 23:44     ` Rob Herring
  2019-02-25  6:41   ` [PATCH v2 2/2] regulator: tps65218: add support for LS2 Christian Hohnstaedt
  1 sibling, 1 reply; 12+ messages in thread
From: Christian Hohnstaedt @ 2019-02-25  6:41 UTC (permalink / raw)
  To: Mark Brown
  Cc: J Keerthy, Liam Girdwood, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

Document device-tree settings of the load-switch LS2
in the tps65218 device.

Signed-off-by: Christian Hohnstaedt <Christian.Hohnstaedt@wago.com>
---
 Documentation/devicetree/bindings/regulator/tps65218.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/regulator/tps65218.txt b/Documentation/devicetree/bindings/regulator/tps65218.txt
index 02f0e9b..b28e9bd 100644
--- a/Documentation/devicetree/bindings/regulator/tps65218.txt
+++ b/Documentation/devicetree/bindings/regulator/tps65218.txt
@@ -71,6 +71,11 @@ tps65218: tps65218@24 {
 		regulator-always-on;
 	};
 
+	ls2: regulator-ls2 {
+		regulator-min-microamp = <100000>;
+		regulator-max-microamp = <1000000>;
+	};
+
 	ls3: regulator-ls3 {
 		regulator-min-microvolt = <100000>;
 		regulator-max-microvolt = <1000000>;
-- 
2.7.4


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

* [PATCH v2 2/2] regulator: tps65218: add support for LS2
  2019-02-25  6:41 ` [PATCH v2 0/2] regulator: tps65218: support LS2 Christian Hohnstaedt
  2019-02-25  6:41   ` [PATCH v2 1/2] dt-bindings: regulator: add LS2 load switch documentation Christian Hohnstaedt
@ 2019-02-25  6:41   ` Christian Hohnstaedt
  1 sibling, 0 replies; 12+ messages in thread
From: Christian Hohnstaedt @ 2019-02-25  6:41 UTC (permalink / raw)
  To: Mark Brown
  Cc: J Keerthy, Liam Girdwood, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

Re-use the "tps65218_pmic_*_current_limit()" functions of LS3
and calculate the different required bit-shift by counting the
trailing 0s in "struct regulator_desc.csel_mask"

Signed-off-by: Christian Hohnstaedt <Christian.Hohnstaedt@wago.com>
---
 drivers/regulator/tps65218-regulator.c | 18 +++++++++++++-----
 include/linux/mfd/tps65218.h           |  3 ++-
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/tps65218-regulator.c b/drivers/regulator/tps65218-regulator.c
index 5dd559e..95708d3 100644
--- a/drivers/regulator/tps65218-regulator.c
+++ b/drivers/regulator/tps65218-regulator.c
@@ -205,7 +205,8 @@ static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,
 		return -EINVAL;
 
 	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
-				 index << 2, TPS65218_PROTECT_L1);
+				 index << __builtin_ctz(dev->desc->csel_mask),
+				 TPS65218_PROTECT_L1);
 }
 
 static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
@@ -224,7 +225,8 @@ static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
 		return -EINVAL;
 
 	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
-				 index << 2, TPS65218_PROTECT_L1);
+				 index << __builtin_ctz(dev->desc->csel_mask),
+				 TPS65218_PROTECT_L1);
 }
 
 static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)
@@ -237,12 +239,13 @@ static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)
 	if (retval < 0)
 		return retval;
 
-	index = (index & dev->desc->csel_mask) >> 2;
+	index = (index & dev->desc->csel_mask) >>
+					 __builtin_ctz(dev->desc->csel_mask);
 
 	return ls3_currents[index];
 }
 
-static struct regulator_ops tps65218_ls3_ops = {
+static struct regulator_ops tps65218_ls23_ops = {
 	.is_enabled		= regulator_is_enabled_regmap,
 	.enable			= tps65218_pmic_enable,
 	.disable		= tps65218_pmic_disable,
@@ -304,8 +307,13 @@ static const struct regulator_desc regulators[] = {
 			   TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges,
 			   2, 0, 0, TPS65218_REG_SEQ6,
 			   TPS65218_SEQ6_LDO1_SEQ_MASK),
+	TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
+			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
+			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,
+			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,
+			   NULL, 0, 0, 0, 0, 0),
 	TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3,
-			   REGULATOR_CURRENT, tps65218_ls3_ops, 0, 0, 0,
+			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
 			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN,
 			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK,
 			   NULL, 0, 0, 0, 0, 0),
diff --git a/include/linux/mfd/tps65218.h b/include/linux/mfd/tps65218.h
index 3cbe103..b0470c3 100644
--- a/include/linux/mfd/tps65218.h
+++ b/include/linux/mfd/tps65218.h
@@ -212,6 +212,7 @@ enum tps65218_regulator_id {
 	/* LDOs */
 	TPS65218_LDO_1,
 	/* LS's */
+	TPS65218_LS_2,
 	TPS65218_LS_3,
 };
 
@@ -222,7 +223,7 @@ enum tps65218_regulator_id {
 /* Number of LDO voltage regulators available */
 #define TPS65218_NUM_LDO		1
 /* Number of total LS current regulators available */
-#define TPS65218_NUM_LS			1
+#define TPS65218_NUM_LS			2
 /* Number of total regulators available */
 #define TPS65218_NUM_REGULATOR		(TPS65218_NUM_DCDC + TPS65218_NUM_LDO \
 					 + TPS65218_NUM_LS)
-- 
2.7.4


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

* Re: [PATCH v2 1/2] dt-bindings: regulator: add LS2 load switch documentation
  2019-02-25  6:41   ` [PATCH v2 1/2] dt-bindings: regulator: add LS2 load switch documentation Christian Hohnstaedt
@ 2019-02-27 23:44     ` Rob Herring
  0 siblings, 0 replies; 12+ messages in thread
From: Rob Herring @ 2019-02-27 23:44 UTC (permalink / raw)
  To: Christian Hohnstaedt
  Cc: Mark Brown, J Keerthy, Liam Girdwood, Rob Herring, Mark Rutland,
	Tony Lindgren, devicetree, linux-omap, linux-kernel

On Mon, 25 Feb 2019 07:41:05 +0100, Christian Hohnstaedt wrote:
> Document device-tree settings of the load-switch LS2
> in the tps65218 device.
> 
> Signed-off-by: Christian Hohnstaedt <Christian.Hohnstaedt@wago.com>
> ---
>  Documentation/devicetree/bindings/regulator/tps65218.txt | 5 +++++
>  1 file changed, 5 insertions(+)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

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

end of thread, other threads:[~2019-02-27 23:44 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-20  8:15 [PATCH 0/3] regulator: tps65218: Fix LS3 and add LS2 Christian Hohnstaedt
2019-02-20  8:15 ` [PATCH 1/3] regulator: tps65218.c: fix LS3 issues Christian Hohnstaedt
2019-02-20 16:40   ` Mark Brown
2019-02-20  8:15 ` [PATCH 2/3] dt-bindings: regulator: Add LS2 load switch Christian Hohnstaedt
2019-02-20  8:15 ` [PATCH 3/3] regulator: tps65218: Add support for LS2 Christian Hohnstaedt
2019-02-20 16:48   ` Mark Brown
2019-02-22  8:38     ` [PATCH v2] " Christian Hohnstaedt
2019-02-22 12:19       ` Mark Brown
2019-02-25  6:41 ` [PATCH v2 0/2] regulator: tps65218: support LS2 Christian Hohnstaedt
2019-02-25  6:41   ` [PATCH v2 1/2] dt-bindings: regulator: add LS2 load switch documentation Christian Hohnstaedt
2019-02-27 23:44     ` Rob Herring
2019-02-25  6:41   ` [PATCH v2 2/2] regulator: tps65218: add support for LS2 Christian Hohnstaedt

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