linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it
@ 2019-02-28 13:40 Axel Lin
  2019-02-28 13:40 ` [PATCH 01/11] regulator: Fix comment for csel_reg and csel_mask Axel Lin
                   ` (10 more replies)
  0 siblings, 11 replies; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

This serial adds regulator_set/get_current_limit_regmap helpers for regmap
users and convert drivers to use these helpers.

patch 1 is a comment fix for existing csel_reg/csel_mask fields.
patch 2 adds n_current_limits and *curr_table fields to
	struct regulator_desc and then adds
	regulator_set_current_limit_regmap() and
        regulator_get_current_limit_regmap()
patch 3-11 convert drivers to use regulator_set/get_current_limit_regmap
	helpers

I don't have h/w for these drivers, so please test it.

Axel Lin (11):
  regulator: Fix comment for csel_reg and csel_mask
  regulator: core: Add set/get_current_limit helpers for regmap users
  regulator: da9055: Convert to use
    regulator_set/get_current_limit_regmap
  regulator: da9210: Convert to use
    regulator_set/get_current_limit_regmap
  regulator: lp872x: Convert to use
    regulator_set/get_current_limit_regmap
  regulator: lp873x: Convert to use
    regulator_set/get_current_limit_regmap
  regulator: max77650: Convert to use
    regulator_set/get_current_limit_regmap
  regulator: pv88060: Convert to use
    regulator_set/get_current_limit_regmap
  regulator: pv88080: Convert to use
    regulator_set/get_current_limit_regmap
  regulator: pv88090: Convert to use
    regulator_set/get_current_limit_regmap
  regulator: wm831x-dcdc: Convert to use
    regulator_set/get_current_limit_regmap

 drivers/regulator/da9055-regulator.c   | 45 +++-----------
 drivers/regulator/da9210-regulator.c   | 53 +++-------------
 drivers/regulator/helpers.c            | 86 ++++++++++++++++++++++++++
 drivers/regulator/lp872x.c             | 70 +++------------------
 drivers/regulator/lp873x-regulator.c   | 45 ++------------
 drivers/regulator/max77650-regulator.c | 74 ++++++++--------------
 drivers/regulator/pv88060-regulator.c  | 51 +++------------
 drivers/regulator/pv88080-regulator.c  | 55 +++-------------
 drivers/regulator/pv88090-regulator.c  | 53 +++-------------
 drivers/regulator/wm831x-dcdc.c        | 42 ++-----------
 include/linux/regulator/driver.h       | 11 +++-
 11 files changed, 181 insertions(+), 404 deletions(-)

-- 
2.17.1


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

* [PATCH 01/11] regulator: Fix comment for csel_reg and csel_mask
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 13:40 ` [PATCH 02/11] regulator: core: Add set/get_current_limit helpers for regmap users Axel Lin
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

The csel_reg and csel_mask fields in struct regulator_desc needs to
be generic for drivers. Not just for TPS65218.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 include/linux/regulator/driver.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 05efe2b057c1..a0b9df5f60e0 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -284,8 +284,8 @@ enum regulator_type {
  * @vsel_range_mask: Mask for register bitfield used for range selector
  * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
  * @vsel_mask: Mask for register bitfield used for selector
- * @csel_reg: Register for TPS65218 LS3 current regulator
- * @csel_mask: Mask for TPS65218 LS3 current regulator
+ * @csel_reg: Register for current limit selector using regmap set_current_limit
+ * @csel_mask: Mask for register bitfield used for current limit selector
  * @apply_reg: Register for initiate voltage change on the output when
  *                using regulator_set_voltage_sel_regmap
  * @apply_bit: Register bitfield used for initiate voltage change on the
-- 
2.17.1


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

* [PATCH 02/11] regulator: core: Add set/get_current_limit helpers for regmap users
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
  2019-02-28 13:40 ` [PATCH 01/11] regulator: Fix comment for csel_reg and csel_mask Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 13:40 ` [PATCH 03/11] regulator: da9055: Convert to use regulator_set/get_current_limit_regmap Axel Lin
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

By setting curr_table, n_current_limits, csel_reg and csel_mask, the
regmap users can use regulator_set_current_limit_regmap and
regulator_get_current_limit_regmap for set/get_current_limit callbacks.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/helpers.c      | 86 ++++++++++++++++++++++++++++++++
 include/linux/regulator/driver.h |  7 +++
 2 files changed, 93 insertions(+)

diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index 68ac6017ef28..09b316559ef6 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -780,3 +780,89 @@ int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
 				  rdev->desc->active_discharge_mask, val);
 }
 EXPORT_SYMBOL_GPL(regulator_set_active_discharge_regmap);
+
+/**
+ * regulator_set_current_limit_regmap - set_current_limit for regmap users
+ *
+ * @rdev: regulator to operate on
+ * @min_uA: Lower bound for current limit
+ * @max_uA: Upper bound for current limit
+ *
+ * Regulators that use regmap for their register I/O can set curr_table,
+ * csel_reg and csel_mask fields in their descriptor and then use this
+ * as their set_current_limit operation, saving some code.
+ */
+int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
+				       int min_uA, int max_uA)
+{
+	unsigned int n_currents = rdev->desc->n_current_limits;
+	int i, sel = -1;
+
+	if (n_currents == 0)
+		return -EINVAL;
+
+	if (rdev->desc->curr_table) {
+		const unsigned int *curr_table = rdev->desc->curr_table;
+		bool ascend = curr_table[n_currents - 1] > curr_table[0];
+
+		/* search for closest to maximum */
+		if (ascend) {
+			for (i = n_currents - 1; i >= 0; i--) {
+				if (min_uA <= curr_table[i] &&
+				    curr_table[i] <= max_uA) {
+					sel = i;
+					break;
+				}
+			}
+		} else {
+			for (i = 0; i < n_currents; i++) {
+				if (min_uA <= curr_table[i] &&
+				    curr_table[i] <= max_uA) {
+					sel = i;
+					break;
+				}
+			}
+		}
+	}
+
+	if (sel < 0)
+		return -EINVAL;
+
+	sel <<= ffs(rdev->desc->csel_mask) - 1;
+
+	return regmap_update_bits(rdev->regmap, rdev->desc->csel_reg,
+				  rdev->desc->csel_mask, sel);
+}
+EXPORT_SYMBOL_GPL(regulator_set_current_limit_regmap);
+
+/**
+ * regulator_get_current_limit_regmap - get_current_limit for regmap users
+ *
+ * @rdev: regulator to operate on
+ *
+ * Regulators that use regmap for their register I/O can set the
+ * csel_reg and csel_mask fields in their descriptor and then use this
+ * as their get_current_limit operation, saving some code.
+ */
+int regulator_get_current_limit_regmap(struct regulator_dev *rdev)
+{
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(rdev->regmap, rdev->desc->csel_reg, &val);
+	if (ret != 0)
+		return ret;
+
+	val &= rdev->desc->csel_mask;
+	val >>= ffs(rdev->desc->csel_mask) - 1;
+
+	if (rdev->desc->curr_table) {
+		if (val >= rdev->desc->n_current_limits)
+			return -EINVAL;
+
+		return rdev->desc->curr_table[val];
+	}
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(regulator_get_current_limit_regmap);
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index a0b9df5f60e0..c3dff2272664 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -264,6 +264,7 @@ enum regulator_type {
  * @continuous_voltage_range: Indicates if the regulator can set any
  *                            voltage within constrains range.
  * @n_voltages: Number of selectors available for ops.list_voltage().
+ * @n_current_limits: Number of selectors available for current limits
  *
  * @min_uV: Voltage given by the lowest selector (if linear mapping)
  * @uV_step: Voltage increase with each selector (if linear mapping)
@@ -278,6 +279,7 @@ enum regulator_type {
  * @n_linear_ranges: Number of entries in the @linear_ranges (and in
  *		     linear_range_selectors if used) table(s).
  * @volt_table: Voltage mapping table (if table based mapping)
+ * @curr_table: Current limit mapping table (if table based mapping)
  *
  * @vsel_range_reg: Register for range selector when using pickable ranges
  *		    and regulator_regmap_X_voltage_X_pickable functions.
@@ -333,6 +335,7 @@ struct regulator_desc {
 	int id;
 	unsigned int continuous_voltage_range:1;
 	unsigned n_voltages;
+	unsigned int n_current_limits;
 	const struct regulator_ops *ops;
 	int irq;
 	enum regulator_type type;
@@ -351,6 +354,7 @@ struct regulator_desc {
 	int n_linear_ranges;
 
 	const unsigned int *volt_table;
+	const unsigned int *curr_table;
 
 	unsigned int vsel_range_reg;
 	unsigned int vsel_range_mask;
@@ -534,6 +538,9 @@ int regulator_set_pull_down_regmap(struct regulator_dev *rdev);
 
 int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
 					  bool enable);
+int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
+				       int min_uA, int max_uA);
+int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
 void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
 
 void regulator_lock(struct regulator_dev *rdev);
-- 
2.17.1


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

* [PATCH 03/11] regulator: da9055: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
  2019-02-28 13:40 ` [PATCH 01/11] regulator: Fix comment for csel_reg and csel_mask Axel Lin
  2019-02-28 13:40 ` [PATCH 02/11] regulator: core: Add set/get_current_limit helpers for regmap users Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 15:18   ` Steve Twiss
  2019-02-28 13:40 ` [PATCH 04/11] regulator: da9210: " Axel Lin
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/da9055-regulator.c | 45 ++++++----------------------
 1 file changed, 9 insertions(+), 36 deletions(-)

diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
index 417cafe2aba0..3c6fac793658 100644
--- a/drivers/regulator/da9055-regulator.c
+++ b/drivers/regulator/da9055-regulator.c
@@ -48,7 +48,9 @@
 #define DA9055_ID_LDO6		7
 
 /* DA9055 BUCK current limit */
-static const int da9055_current_limits[] = { 500000, 600000, 700000, 800000 };
+static const unsigned int da9055_current_limits[] = {
+	500000, 600000, 700000, 800000
+};
 
 struct da9055_conf_reg {
 	int reg;
@@ -169,39 +171,6 @@ static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
 				 val << volt.sl_shift);
 }
 
-static int da9055_buck_get_current_limit(struct regulator_dev *rdev)
-{
-	struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
-	struct da9055_regulator_info *info = regulator->info;
-	int ret;
-
-	ret = da9055_reg_read(regulator->da9055, DA9055_REG_BUCK_LIM);
-	if (ret < 0)
-		return ret;
-
-	ret &= info->mode.mask;
-	return da9055_current_limits[ret >> info->mode.shift];
-}
-
-static int da9055_buck_set_current_limit(struct regulator_dev *rdev, int min_uA,
-					 int max_uA)
-{
-	struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
-	struct da9055_regulator_info *info = regulator->info;
-	int i;
-
-	for (i = ARRAY_SIZE(da9055_current_limits) - 1; i >= 0; i--) {
-		if ((min_uA <= da9055_current_limits[i]) &&
-		    (da9055_current_limits[i] <= max_uA))
-			return da9055_reg_update(regulator->da9055,
-						 DA9055_REG_BUCK_LIM,
-						 info->mode.mask,
-						 i << info->mode.shift);
-	}
-
-	return -EINVAL;
-}
-
 static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
 {
 	struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
@@ -329,8 +298,8 @@ static const struct regulator_ops da9055_buck_ops = {
 	.get_mode = da9055_buck_get_mode,
 	.set_mode = da9055_buck_set_mode,
 
-	.get_current_limit = da9055_buck_get_current_limit,
-	.set_current_limit = da9055_buck_set_current_limit,
+	.get_current_limit = regulator_get_current_limit_regmap,
+	.set_current_limit = regulator_set_current_limit_regmap,
 
 	.get_voltage_sel = da9055_regulator_get_voltage_sel,
 	.set_voltage_sel = da9055_regulator_set_voltage_sel,
@@ -407,6 +376,10 @@ static const struct regulator_ops da9055_ldo_ops = {
 		.uV_step = (step) * 1000,\
 		.linear_min_sel = (voffset),\
 		.owner = THIS_MODULE,\
+		.curr_table = da9055_current_limits,\
+		.n_current_limits = ARRAY_SIZE(da9055_current_limits),\
+		.csel_reg = DA9055_REG_BUCK_LIM,\
+		.csel_mask = (mbits),\
 	},\
 	.conf = {\
 		.reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
-- 
2.17.1


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

* [PATCH 04/11] regulator: da9210: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
                   ` (2 preceding siblings ...)
  2019-02-28 13:40 ` [PATCH 03/11] regulator: da9055: Convert to use regulator_set/get_current_limit_regmap Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 14:01   ` Steve Twiss
  2019-02-28 13:40 ` [PATCH 05/11] regulator: lp872x: " Axel Lin
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/da9210-regulator.c | 53 ++++------------------------
 1 file changed, 7 insertions(+), 46 deletions(-)

diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c
index 84dba64ed11e..528303771723 100644
--- a/drivers/regulator/da9210-regulator.c
+++ b/drivers/regulator/da9210-regulator.c
@@ -41,10 +41,6 @@ static const struct regmap_config da9210_regmap_config = {
 	.val_bits = 8,
 };
 
-static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
-				    int max_uA);
-static int da9210_get_current_limit(struct regulator_dev *rdev);
-
 static const struct regulator_ops da9210_buck_ops = {
 	.enable = regulator_enable_regmap,
 	.disable = regulator_disable_regmap,
@@ -52,8 +48,8 @@ static const struct regulator_ops da9210_buck_ops = {
 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 	.list_voltage = regulator_list_voltage_linear,
-	.set_current_limit = da9210_set_current_limit,
-	.get_current_limit = da9210_get_current_limit,
+	.set_current_limit = regulator_set_current_limit_regmap,
+	.get_current_limit = regulator_get_current_limit_regmap,
 };
 
 /* Default limits measured in millivolts and milliamps */
@@ -62,7 +58,7 @@ static const struct regulator_ops da9210_buck_ops = {
 #define DA9210_STEP_MV		10
 
 /* Current limits for buck (uA) indices corresponds with register values */
-static const int da9210_buck_limits[] = {
+static const unsigned int da9210_buck_limits[] = {
 	1600000, 1800000, 2000000, 2200000, 2400000, 2600000, 2800000, 3000000,
 	3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 4600000
 };
@@ -80,47 +76,12 @@ static const struct regulator_desc da9210_reg = {
 	.enable_reg = DA9210_REG_BUCK_CONT,
 	.enable_mask = DA9210_BUCK_EN,
 	.owner = THIS_MODULE,
+	.curr_table = da9210_buck_limits,
+	.n_current_limits = ARRAY_SIZE(da9210_buck_limits),
+	.csel_reg = DA9210_REG_BUCK_ILIM,
+	.csel_mask = DA9210_BUCK_ILIM_MASK,
 };
 
-static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
-				    int max_uA)
-{
-	struct da9210 *chip = rdev_get_drvdata(rdev);
-	unsigned int sel;
-	int i;
-
-	/* search for closest to maximum */
-	for (i = ARRAY_SIZE(da9210_buck_limits)-1; i >= 0; i--) {
-		if (min_uA <= da9210_buck_limits[i] &&
-		    max_uA >= da9210_buck_limits[i]) {
-			sel = i;
-			sel = sel << DA9210_BUCK_ILIM_SHIFT;
-			return regmap_update_bits(chip->regmap,
-						  DA9210_REG_BUCK_ILIM,
-						  DA9210_BUCK_ILIM_MASK, sel);
-		}
-	}
-
-	return -EINVAL;
-}
-
-static int da9210_get_current_limit(struct regulator_dev *rdev)
-{
-	struct da9210 *chip = rdev_get_drvdata(rdev);
-	unsigned int data;
-	unsigned int sel;
-	int ret;
-
-	ret = regmap_read(chip->regmap, DA9210_REG_BUCK_ILIM, &data);
-	if (ret < 0)
-		return ret;
-
-	/* select one of 16 values: 0000 (1600mA) to 1111 (4600mA) */
-	sel = (data & DA9210_BUCK_ILIM_MASK) >> DA9210_BUCK_ILIM_SHIFT;
-
-	return da9210_buck_limits[sel];
-}
-
 static irqreturn_t da9210_irq_handler(int irq, void *data)
 {
 	struct da9210 *chip = data;
-- 
2.17.1


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

* [PATCH 05/11] regulator: lp872x: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
                   ` (3 preceding siblings ...)
  2019-02-28 13:40 ` [PATCH 04/11] regulator: da9210: " Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 13:40 ` [PATCH 06/11] regulator: lp873x: " Axel Lin
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/lp872x.c | 70 ++++++--------------------------------
 1 file changed, 10 insertions(+), 60 deletions(-)

diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c
index f8f875bad7dd..ca95257ce252 100644
--- a/drivers/regulator/lp872x.c
+++ b/drivers/regulator/lp872x.c
@@ -353,64 +353,6 @@ static int lp872x_buck_get_voltage_sel(struct regulator_dev *rdev)
 	return val & LP872X_VOUT_M;
 }
 
-static int lp8725_buck_set_current_limit(struct regulator_dev *rdev,
-					int min_uA, int max_uA)
-{
-	struct lp872x *lp = rdev_get_drvdata(rdev);
-	enum lp872x_regulator_id buck = rdev_get_id(rdev);
-	int i;
-	u8 addr;
-
-	switch (buck) {
-	case LP8725_ID_BUCK1:
-		addr = LP8725_BUCK1_VOUT2;
-		break;
-	case LP8725_ID_BUCK2:
-		addr = LP8725_BUCK2_VOUT2;
-		break;
-	default:
-		return -EINVAL;
-	}
-
-	for (i = ARRAY_SIZE(lp8725_buck_uA) - 1; i >= 0; i--) {
-		if (lp8725_buck_uA[i] >= min_uA &&
-			lp8725_buck_uA[i] <= max_uA)
-			return lp872x_update_bits(lp, addr,
-						  LP8725_BUCK_CL_M,
-						  i << LP8725_BUCK_CL_S);
-	}
-
-	return -EINVAL;
-}
-
-static int lp8725_buck_get_current_limit(struct regulator_dev *rdev)
-{
-	struct lp872x *lp = rdev_get_drvdata(rdev);
-	enum lp872x_regulator_id buck = rdev_get_id(rdev);
-	u8 addr, val;
-	int ret;
-
-	switch (buck) {
-	case LP8725_ID_BUCK1:
-		addr = LP8725_BUCK1_VOUT2;
-		break;
-	case LP8725_ID_BUCK2:
-		addr = LP8725_BUCK2_VOUT2;
-		break;
-	default:
-		return -EINVAL;
-	}
-
-	ret = lp872x_read_byte(lp, addr, &val);
-	if (ret)
-		return ret;
-
-	val = (val & LP8725_BUCK_CL_M) >> LP8725_BUCK_CL_S;
-
-	return (val < ARRAY_SIZE(lp8725_buck_uA)) ?
-			lp8725_buck_uA[val] : -EINVAL;
-}
-
 static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
 {
 	struct lp872x *lp = rdev_get_drvdata(rdev);
@@ -513,8 +455,8 @@ static const struct regulator_ops lp8725_buck_ops = {
 	.enable_time = lp872x_regulator_enable_time,
 	.set_mode = lp872x_buck_set_mode,
 	.get_mode = lp872x_buck_get_mode,
-	.set_current_limit = lp8725_buck_set_current_limit,
-	.get_current_limit = lp8725_buck_get_current_limit,
+	.set_current_limit = regulator_set_current_limit_regmap,
+	.get_current_limit = regulator_get_current_limit_regmap,
 };
 
 static const struct regulator_desc lp8720_regulator_desc[] = {
@@ -712,6 +654,10 @@ static const struct regulator_desc lp8725_regulator_desc[] = {
 		.owner = THIS_MODULE,
 		.enable_reg = LP872X_GENERAL_CFG,
 		.enable_mask = LP8725_BUCK1_EN_M,
+		.curr_table = lp8725_buck_uA,
+		.n_current_limits = ARRAY_SIZE(lp8725_buck_uA),
+		.csel_reg = LP8725_BUCK1_VOUT2,
+		.csel_mask = LP8725_BUCK_CL_M,
 	},
 	{
 		.name = "buck2",
@@ -724,6 +670,10 @@ static const struct regulator_desc lp8725_regulator_desc[] = {
 		.owner = THIS_MODULE,
 		.enable_reg = LP872X_GENERAL_CFG,
 		.enable_mask = LP8725_BUCK2_EN_M,
+		.curr_table = lp8725_buck_uA,
+		.n_current_limits = ARRAY_SIZE(lp8725_buck_uA),
+		.csel_reg = LP8725_BUCK2_VOUT2,
+		.csel_mask = LP8725_BUCK_CL_M,
 	},
 };
 
-- 
2.17.1


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

* [PATCH 06/11] regulator: lp873x: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
                   ` (4 preceding siblings ...)
  2019-02-28 13:40 ` [PATCH 05/11] regulator: lp872x: " Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 13:40 ` [PATCH 07/11] regulator: max77650: " Axel Lin
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/lp873x-regulator.c | 45 ++++------------------------
 1 file changed, 6 insertions(+), 39 deletions(-)

diff --git a/drivers/regulator/lp873x-regulator.c b/drivers/regulator/lp873x-regulator.c
index 70651fec8fd9..b55de293ca7a 100644
--- a/drivers/regulator/lp873x-regulator.c
+++ b/drivers/regulator/lp873x-regulator.c
@@ -39,6 +39,10 @@
 			.ramp_delay		= _delay,		\
 			.linear_ranges		= _lr,			\
 			.n_linear_ranges	= ARRAY_SIZE(_lr),	\
+			.curr_table	= lp873x_buck_uA,		\
+			.n_current_limits = ARRAY_SIZE(lp873x_buck_uA),	\
+			.csel_reg	= (_cr),			\
+			.csel_mask	= LP873X_BUCK0_CTRL_2_BUCK0_ILIM,\
 		},							\
 		.ctrl2_reg = _cr,					\
 	}
@@ -108,43 +112,6 @@ static int lp873x_buck_set_ramp_delay(struct regulator_dev *rdev,
 	return 0;
 }
 
-static int lp873x_buck_set_current_limit(struct regulator_dev *rdev,
-					 int min_uA, int max_uA)
-{
-	int id = rdev_get_id(rdev);
-	struct lp873x *lp873 = rdev_get_drvdata(rdev);
-	int i;
-
-	for (i = ARRAY_SIZE(lp873x_buck_uA) - 1; i >= 0; i--) {
-		if (lp873x_buck_uA[i] >= min_uA &&
-		    lp873x_buck_uA[i] <= max_uA)
-			return regmap_update_bits(lp873->regmap,
-						  regulators[id].ctrl2_reg,
-						  LP873X_BUCK0_CTRL_2_BUCK0_ILIM,
-						  i << __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM));
-	}
-
-	return -EINVAL;
-}
-
-static int lp873x_buck_get_current_limit(struct regulator_dev *rdev)
-{
-	int id = rdev_get_id(rdev);
-	struct lp873x *lp873 = rdev_get_drvdata(rdev);
-	int ret;
-	unsigned int val;
-
-	ret = regmap_read(lp873->regmap, regulators[id].ctrl2_reg, &val);
-	if (ret)
-		return ret;
-
-	val = (val & LP873X_BUCK0_CTRL_2_BUCK0_ILIM) >>
-	       __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM);
-
-	return (val < ARRAY_SIZE(lp873x_buck_uA)) ?
-			lp873x_buck_uA[val] : -EINVAL;
-}
-
 /* Operations permitted on BUCK0, BUCK1 */
 static const struct regulator_ops lp873x_buck01_ops = {
 	.is_enabled		= regulator_is_enabled_regmap,
@@ -156,8 +123,8 @@ static const struct regulator_ops lp873x_buck01_ops = {
 	.map_voltage		= regulator_map_voltage_linear_range,
 	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
 	.set_ramp_delay		= lp873x_buck_set_ramp_delay,
-	.set_current_limit	= lp873x_buck_set_current_limit,
-	.get_current_limit	= lp873x_buck_get_current_limit,
+	.set_current_limit	= regulator_set_current_limit_regmap,
+	.get_current_limit	= regulator_get_current_limit_regmap,
 };
 
 /* Operations permitted on LDO0 and LDO1 */
-- 
2.17.1


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

* [PATCH 07/11] regulator: max77650: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
                   ` (5 preceding siblings ...)
  2019-02-28 13:40 ` [PATCH 06/11] regulator: lp873x: " Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 14:11   ` Bartosz Golaszewski
  2019-02-28 13:40 ` [PATCH 08/11] regulator: pv88060: " Axel Lin
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/max77650-regulator.c | 74 +++++++++-----------------
 1 file changed, 25 insertions(+), 49 deletions(-)

diff --git a/drivers/regulator/max77650-regulator.c b/drivers/regulator/max77650-regulator.c
index a1af414db751..31ebf34b01ec 100644
--- a/drivers/regulator/max77650-regulator.c
+++ b/drivers/regulator/max77650-regulator.c
@@ -26,9 +26,6 @@
 #define MAX77650_REGULATOR_AD_ENABLED		BIT(3)
 
 #define MAX77650_REGULATOR_CURR_LIM_MASK	GENMASK(7, 6)
-#define MAX77650_REGULATOR_CURR_LIM_BITS(_reg) \
-		(((_reg) & MAX77650_REGULATOR_CURR_LIM_MASK) >> 6)
-#define MAX77650_REGULATOR_CURR_LIM_SHIFT(_val)	((_val) << 6)
 
 enum {
 	MAX77650_REGULATOR_ID_LDO = 0,
@@ -82,7 +79,7 @@ static const u32 max77651_sbb1_regulator_volt_table[] = {
 		_val = MAX77651_REGULATOR_SBB1_SEL_ENC(_val);		\
 	} while (0)
 
-static const int max77650_current_limit_table[] = {
+static const unsigned int max77650_current_limit_table[] = {
 	1000000, 866000, 707000, 500000,
 };
 
@@ -220,47 +217,6 @@ static int max77651_regulator_sbb1_set_voltage_sel(struct regulator_dev *rdev,
 	return 0;
 }
 
-static int max77650_regulator_get_current_limit(struct regulator_dev *rdev)
-{
-	struct max77650_regulator_desc *rdesc;
-	struct regmap *map;
-	int val, rv, limit;
-
-	rdesc = rdev_get_drvdata(rdev);
-	map = rdev_get_regmap(rdev);
-
-	rv = regmap_read(map, rdesc->regA, &val);
-	if (rv)
-		return rv;
-
-	limit = MAX77650_REGULATOR_CURR_LIM_BITS(val);
-
-	return max77650_current_limit_table[limit];
-}
-
-static int max77650_regulator_set_current_limit(struct regulator_dev *rdev,
-						int min_uA, int max_uA)
-{
-	struct max77650_regulator_desc *rdesc;
-	struct regmap *map;
-	int i, limit;
-
-	rdesc = rdev_get_drvdata(rdev);
-	map = rdev_get_regmap(rdev);
-
-	for (i = 0; i < ARRAY_SIZE(max77650_current_limit_table); i++) {
-		limit = max77650_current_limit_table[i];
-
-		if (limit >= min_uA && limit <= max_uA) {
-			return regmap_update_bits(map, rdesc->regA,
-					MAX77650_REGULATOR_CURR_LIM_MASK,
-					MAX77650_REGULATOR_CURR_LIM_SHIFT(i));
-		}
-	}
-
-	return -EINVAL;
-}
-
 static const struct regulator_ops max77650_regulator_LDO_ops = {
 	.is_enabled		= max77650_regulator_is_enabled,
 	.enable			= max77650_regulator_enable,
@@ -280,8 +236,8 @@ static const struct regulator_ops max77650_regulator_SBB_ops = {
 	.map_voltage		= regulator_map_voltage_linear,
 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
 	.set_voltage_sel	= max77650_regulator_set_voltage_sel,
-	.get_current_limit	= max77650_regulator_get_current_limit,
-	.set_current_limit	= max77650_regulator_set_current_limit,
+	.get_current_limit	= regulator_get_current_limit_regmap,
+	.set_current_limit	= regulator_set_current_limit_regmap,
 	.set_active_discharge	= regulator_set_active_discharge_regmap,
 };
 
@@ -293,8 +249,8 @@ static const struct regulator_ops max77651_SBB1_regulator_ops = {
 	.list_voltage		= regulator_list_voltage_table,
 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
 	.set_voltage_sel	= max77651_regulator_sbb1_set_voltage_sel,
-	.get_current_limit	= max77650_regulator_get_current_limit,
-	.set_current_limit	= max77650_regulator_set_current_limit,
+	.get_current_limit	= regulator_get_current_limit_regmap,
+	.set_current_limit	= regulator_set_current_limit_regmap,
 	.set_active_discharge	= regulator_set_active_discharge_regmap,
 };
 
@@ -343,6 +299,10 @@ static struct max77650_regulator_desc max77650_SBB0_desc = {
 		.enable_time		= 100,
 		.type			= REGULATOR_VOLTAGE,
 		.owner			= THIS_MODULE,
+		.csel_reg		= MAX77650_REG_CNFG_SBB0_A,
+		.csel_mask		= MAX77650_REGULATOR_CURR_LIM_MASK,
+		.curr_table		= max77650_current_limit_table,
+		.n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
 	},
 	.regA		= MAX77650_REG_CNFG_SBB0_A,
 	.regB		= MAX77650_REG_CNFG_SBB0_B,
@@ -368,6 +328,10 @@ static struct max77650_regulator_desc max77650_SBB1_desc = {
 		.enable_time		= 100,
 		.type			= REGULATOR_VOLTAGE,
 		.owner			= THIS_MODULE,
+		.csel_reg		= MAX77650_REG_CNFG_SBB1_A,
+		.csel_mask		= MAX77650_REGULATOR_CURR_LIM_MASK,
+		.curr_table		= max77650_current_limit_table,
+		.n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
 	},
 	.regA		= MAX77650_REG_CNFG_SBB1_A,
 	.regB		= MAX77650_REG_CNFG_SBB1_B,
@@ -392,6 +356,10 @@ static struct max77650_regulator_desc max77651_SBB1_desc = {
 		.enable_time		= 100,
 		.type			= REGULATOR_VOLTAGE,
 		.owner			= THIS_MODULE,
+		.csel_reg		= MAX77650_REG_CNFG_SBB1_A,
+		.csel_mask		= MAX77650_REGULATOR_CURR_LIM_MASK,
+		.curr_table		= max77650_current_limit_table,
+		.n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
 	},
 	.regA		= MAX77650_REG_CNFG_SBB1_A,
 	.regB		= MAX77650_REG_CNFG_SBB1_B,
@@ -417,6 +385,10 @@ static struct max77650_regulator_desc max77650_SBB2_desc = {
 		.enable_time		= 100,
 		.type			= REGULATOR_VOLTAGE,
 		.owner			= THIS_MODULE,
+		.csel_reg		= MAX77650_REG_CNFG_SBB2_A,
+		.csel_mask		= MAX77650_REGULATOR_CURR_LIM_MASK,
+		.curr_table		= max77650_current_limit_table,
+		.n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
 	},
 	.regA		= MAX77650_REG_CNFG_SBB2_A,
 	.regB		= MAX77650_REG_CNFG_SBB2_B,
@@ -442,6 +414,10 @@ static struct max77650_regulator_desc max77651_SBB2_desc = {
 		.enable_time		= 100,
 		.type			= REGULATOR_VOLTAGE,
 		.owner			= THIS_MODULE,
+		.csel_reg		= MAX77650_REG_CNFG_SBB2_A,
+		.csel_mask		= MAX77650_REGULATOR_CURR_LIM_MASK,
+		.curr_table		= max77650_current_limit_table,
+		.n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
 	},
 	.regA		= MAX77650_REG_CNFG_SBB2_A,
 	.regB		= MAX77650_REG_CNFG_SBB2_B,
-- 
2.17.1


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

* [PATCH 08/11] regulator: pv88060: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
                   ` (6 preceding siblings ...)
  2019-02-28 13:40 ` [PATCH 07/11] regulator: max77650: " Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 15:26   ` Steve Twiss
  2019-02-28 13:40 ` [PATCH 09/11] regulator: pv88080: " Axel Lin
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/pv88060-regulator.c | 51 ++++-----------------------
 1 file changed, 7 insertions(+), 44 deletions(-)

diff --git a/drivers/regulator/pv88060-regulator.c b/drivers/regulator/pv88060-regulator.c
index da6ed723e398..1600f9821891 100644
--- a/drivers/regulator/pv88060-regulator.c
+++ b/drivers/regulator/pv88060-regulator.c
@@ -53,10 +53,6 @@ enum {
 
 struct pv88060_regulator {
 	struct regulator_desc desc;
-	/* Current limiting */
-	unsigned	n_current_limits;
-	const int	*current_limits;
-	unsigned int limit_mask;
 	unsigned int conf;		/* buck configuration register */
 };
 
@@ -75,7 +71,7 @@ static const struct regmap_config pv88060_regmap_config = {
  * Entry indexes corresponds to register values.
  */
 
-static const int pv88060_buck1_limits[] = {
+static const unsigned int pv88060_buck1_limits[] = {
 	1496000, 2393000, 3291000, 4189000
 };
 
@@ -128,40 +124,6 @@ static int pv88060_buck_set_mode(struct regulator_dev *rdev,
 					PV88060_BUCK_MODE_MASK, val);
 }
 
-static int pv88060_set_current_limit(struct regulator_dev *rdev, int min,
-				    int max)
-{
-	struct pv88060_regulator *info = rdev_get_drvdata(rdev);
-	int i;
-
-	/* search for closest to maximum */
-	for (i = info->n_current_limits - 1; i >= 0; i--) {
-		if (min <= info->current_limits[i]
-			&& max >= info->current_limits[i]) {
-			return regmap_update_bits(rdev->regmap,
-				info->conf,
-				info->limit_mask,
-				i << PV88060_BUCK_ILIM_SHIFT);
-		}
-	}
-
-	return -EINVAL;
-}
-
-static int pv88060_get_current_limit(struct regulator_dev *rdev)
-{
-	struct pv88060_regulator *info = rdev_get_drvdata(rdev);
-	unsigned int data;
-	int ret;
-
-	ret = regmap_read(rdev->regmap, info->conf, &data);
-	if (ret < 0)
-		return ret;
-
-	data = (data & info->limit_mask) >> PV88060_BUCK_ILIM_SHIFT;
-	return info->current_limits[data];
-}
-
 static const struct regulator_ops pv88060_buck_ops = {
 	.get_mode = pv88060_buck_get_mode,
 	.set_mode = pv88060_buck_set_mode,
@@ -171,8 +133,8 @@ static const struct regulator_ops pv88060_buck_ops = {
 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 	.list_voltage = regulator_list_voltage_linear,
-	.set_current_limit = pv88060_set_current_limit,
-	.get_current_limit = pv88060_get_current_limit,
+	.set_current_limit = regulator_set_current_limit_regmap,
+	.get_current_limit = regulator_get_current_limit_regmap,
 };
 
 static const struct regulator_ops pv88060_ldo_ops = {
@@ -207,10 +169,11 @@ static const struct regulator_ops pv88060_sw_ops = {
 		.enable_mask = PV88060_BUCK_EN, \
 		.vsel_reg = PV88060_REG_##regl_name##_CONF0,\
 		.vsel_mask = PV88060_VBUCK_MASK,\
+		.curr_table = limits_array,\
+		.n_current_limits = ARRAY_SIZE(limits_array),\
+		.csel_reg = PV88060_REG_##regl_name##_CONF1,\
+		.csel_mask = PV88060_BUCK_ILIM_MASK,\
 	},\
-	.current_limits = limits_array,\
-	.n_current_limits = ARRAY_SIZE(limits_array),\
-	.limit_mask = PV88060_BUCK_ILIM_MASK, \
 	.conf = PV88060_REG_##regl_name##_CONF1,\
 }
 
-- 
2.17.1


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

* [PATCH 09/11] regulator: pv88080: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
                   ` (7 preceding siblings ...)
  2019-02-28 13:40 ` [PATCH 08/11] regulator: pv88060: " Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 15:41   ` Steve Twiss
  2019-02-28 13:40 ` [PATCH 10/11] regulator: pv88090: " Axel Lin
  2019-02-28 13:40 ` [PATCH 11/11] regulator: wm831x-dcdc: " Axel Lin
  10 siblings, 1 reply; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/pv88080-regulator.c | 55 ++++-----------------------
 1 file changed, 8 insertions(+), 47 deletions(-)

diff --git a/drivers/regulator/pv88080-regulator.c b/drivers/regulator/pv88080-regulator.c
index 6770e4de2097..bdddacdbeb99 100644
--- a/drivers/regulator/pv88080-regulator.c
+++ b/drivers/regulator/pv88080-regulator.c
@@ -45,12 +45,7 @@ enum pv88080_types {
 
 struct pv88080_regulator {
 	struct regulator_desc desc;
-	/* Current limiting */
-	unsigned int n_current_limits;
-	const int *current_limits;
-	unsigned int limit_mask;
 	unsigned int mode_reg;
-	unsigned int limit_reg;
 	unsigned int conf2;
 	unsigned int conf5;
 };
@@ -102,11 +97,11 @@ static const struct regmap_config pv88080_regmap_config = {
  * Entry indexes corresponds to register values.
  */
 
-static const int pv88080_buck1_limits[] = {
+static const unsigned int pv88080_buck1_limits[] = {
 	3230000, 5130000, 6960000, 8790000
 };
 
-static const int pv88080_buck23_limits[] = {
+static const unsigned int pv88080_buck23_limits[] = {
 	1496000, 2393000, 3291000, 4189000
 };
 
@@ -272,40 +267,6 @@ static int pv88080_buck_set_mode(struct regulator_dev *rdev,
 					PV88080_BUCK1_MODE_MASK, val);
 }
 
-static int pv88080_set_current_limit(struct regulator_dev *rdev, int min,
-				    int max)
-{
-	struct pv88080_regulator *info = rdev_get_drvdata(rdev);
-	int i;
-
-	/* search for closest to maximum */
-	for (i = info->n_current_limits - 1; i >= 0; i--) {
-		if (min <= info->current_limits[i]
-			&& max >= info->current_limits[i]) {
-				return regmap_update_bits(rdev->regmap,
-					info->limit_reg,
-					info->limit_mask,
-					i << PV88080_BUCK1_ILIM_SHIFT);
-		}
-	}
-
-	return -EINVAL;
-}
-
-static int pv88080_get_current_limit(struct regulator_dev *rdev)
-{
-	struct pv88080_regulator *info = rdev_get_drvdata(rdev);
-	unsigned int data;
-	int ret;
-
-	ret = regmap_read(rdev->regmap, info->limit_reg, &data);
-	if (ret < 0)
-		return ret;
-
-	data = (data & info->limit_mask) >> PV88080_BUCK1_ILIM_SHIFT;
-	return info->current_limits[data];
-}
-
 static const struct regulator_ops pv88080_buck_ops = {
 	.get_mode = pv88080_buck_get_mode,
 	.set_mode = pv88080_buck_set_mode,
@@ -315,8 +276,8 @@ static const struct regulator_ops pv88080_buck_ops = {
 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 	.list_voltage = regulator_list_voltage_linear,
-	.set_current_limit = pv88080_set_current_limit,
-	.get_current_limit = pv88080_get_current_limit,
+	.set_current_limit = regulator_set_current_limit_regmap,
+	.get_current_limit = regulator_get_current_limit_regmap,
 };
 
 static const struct regulator_ops pv88080_hvbuck_ops = {
@@ -341,9 +302,9 @@ static const struct regulator_ops pv88080_hvbuck_ops = {
 		.min_uV = min, \
 		.uV_step = step, \
 		.n_voltages = ((max) - (min))/(step) + 1, \
+		.curr_table = limits_array, \
+		.n_current_limits = ARRAY_SIZE(limits_array), \
 	},\
-	.current_limits = limits_array, \
-	.n_current_limits = ARRAY_SIZE(limits_array), \
 }
 
 #define PV88080_HVBUCK(chip, regl_name, min, step, max) \
@@ -521,9 +482,9 @@ static int pv88080_i2c_probe(struct i2c_client *i2c,
 		if (init_data)
 			config.init_data = &init_data[i];
 
-		pv88080_regulator_info[i].limit_reg
+		pv88080_regulator_info[i].desc.csel_reg
 			= regmap_config->buck_regmap[i].buck_limit_reg;
-		pv88080_regulator_info[i].limit_mask
+		pv88080_regulator_info[i].desc.csel_mask
 			= regmap_config->buck_regmap[i].buck_limit_mask;
 		pv88080_regulator_info[i].mode_reg
 			= regmap_config->buck_regmap[i].buck_mode_reg;
-- 
2.17.1


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

* [PATCH 10/11] regulator: pv88090: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
                   ` (8 preceding siblings ...)
  2019-02-28 13:40 ` [PATCH 09/11] regulator: pv88080: " Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-02-28 15:47   ` Steve Twiss
  2019-02-28 13:40 ` [PATCH 11/11] regulator: wm831x-dcdc: " Axel Lin
  10 siblings, 1 reply; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/pv88090-regulator.c | 53 ++++-----------------------
 1 file changed, 8 insertions(+), 45 deletions(-)

diff --git a/drivers/regulator/pv88090-regulator.c b/drivers/regulator/pv88090-regulator.c
index 2302b0df7630..6e97cc6df2ee 100644
--- a/drivers/regulator/pv88090-regulator.c
+++ b/drivers/regulator/pv88090-regulator.c
@@ -42,10 +42,6 @@ enum {
 
 struct pv88090_regulator {
 	struct regulator_desc desc;
-	/* Current limiting */
-	unsigned int n_current_limits;
-	const int	*current_limits;
-	unsigned int limit_mask;
 	unsigned int conf;
 	unsigned int conf2;
 };
@@ -71,14 +67,14 @@ static const struct regmap_config pv88090_regmap_config = {
  *  Entry indexes corresponds to register values.
  */
 
-static const int pv88090_buck1_limits[] = {
+static const unsigned int pv88090_buck1_limits[] = {
 	 220000,  440000,  660000,  880000, 1100000, 1320000, 1540000, 1760000,
 	1980000, 2200000, 2420000, 2640000, 2860000, 3080000, 3300000, 3520000,
 	3740000, 3960000, 4180000, 4400000, 4620000, 4840000, 5060000, 5280000,
 	5500000, 5720000, 5940000, 6160000, 6380000, 6600000, 6820000, 7040000
 };
 
-static const int pv88090_buck23_limits[] = {
+static const unsigned int pv88090_buck23_limits[] = {
 	1496000, 2393000, 3291000, 4189000
 };
 
@@ -150,40 +146,6 @@ static int pv88090_buck_set_mode(struct regulator_dev *rdev,
 					PV88090_BUCK1_MODE_MASK, val);
 }
 
-static int pv88090_set_current_limit(struct regulator_dev *rdev, int min,
-				    int max)
-{
-	struct pv88090_regulator *info = rdev_get_drvdata(rdev);
-	int i;
-
-	/* search for closest to maximum */
-	for (i = info->n_current_limits - 1; i >= 0; i--) {
-		if (min <= info->current_limits[i]
-			&& max >= info->current_limits[i]) {
-			return regmap_update_bits(rdev->regmap,
-				info->conf,
-				info->limit_mask,
-				i << PV88090_BUCK1_ILIM_SHIFT);
-		}
-	}
-
-	return -EINVAL;
-}
-
-static int pv88090_get_current_limit(struct regulator_dev *rdev)
-{
-	struct pv88090_regulator *info = rdev_get_drvdata(rdev);
-	unsigned int data;
-	int ret;
-
-	ret = regmap_read(rdev->regmap, info->conf, &data);
-	if (ret < 0)
-		return ret;
-
-	data = (data & info->limit_mask) >> PV88090_BUCK1_ILIM_SHIFT;
-	return info->current_limits[data];
-}
-
 static const struct regulator_ops pv88090_buck_ops = {
 	.get_mode = pv88090_buck_get_mode,
 	.set_mode = pv88090_buck_set_mode,
@@ -193,8 +155,8 @@ static const struct regulator_ops pv88090_buck_ops = {
 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 	.list_voltage = regulator_list_voltage_linear,
-	.set_current_limit = pv88090_set_current_limit,
-	.get_current_limit = pv88090_get_current_limit,
+	.set_current_limit = regulator_set_current_limit_regmap,
+	.get_current_limit = regulator_get_current_limit_regmap,
 };
 
 static const struct regulator_ops pv88090_ldo_ops = {
@@ -223,10 +185,11 @@ static const struct regulator_ops pv88090_ldo_ops = {
 		.enable_mask = PV88090_##regl_name##_EN, \
 		.vsel_reg = PV88090_REG_##regl_name##_CONF0, \
 		.vsel_mask = PV88090_V##regl_name##_MASK, \
+		.curr_table = limits_array, \
+		.n_current_limits = ARRAY_SIZE(limits_array), \
+		.csel_reg = PV88090_REG_##regl_name##_CONF1, \
+		.csel_mask = PV88090_##regl_name##_ILIM_MASK, \
 	},\
-	.current_limits = limits_array, \
-	.n_current_limits = ARRAY_SIZE(limits_array), \
-	.limit_mask = PV88090_##regl_name##_ILIM_MASK, \
 	.conf = PV88090_REG_##regl_name##_CONF1, \
 	.conf2 = PV88090_REG_##regl_name##_CONF2, \
 }
-- 
2.17.1


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

* [PATCH 11/11] regulator: wm831x-dcdc: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
                   ` (9 preceding siblings ...)
  2019-02-28 13:40 ` [PATCH 10/11] regulator: pv88090: " Axel Lin
@ 2019-02-28 13:40 ` Axel Lin
  2019-03-01  8:33   ` Charles Keepax
  10 siblings, 1 reply; 19+ messages in thread
From: Axel Lin @ 2019-02-28 13:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel, Axel Lin

Use regulator_set/get_current_limit_regmap helpers to save some code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/wm831x-dcdc.c | 42 +++++----------------------------
 1 file changed, 6 insertions(+), 36 deletions(-)

diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 828f262d6be0..12b422373580 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -308,48 +308,14 @@ static const unsigned int wm831x_dcdc_ilim[] = {
 	125000, 250000, 375000, 500000, 625000, 750000, 875000, 1000000
 };
 
-static int wm831x_buckv_set_current_limit(struct regulator_dev *rdev,
-					   int min_uA, int max_uA)
-{
-	struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
-	struct wm831x *wm831x = dcdc->wm831x;
-	u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2;
-	int i;
-
-	for (i = ARRAY_SIZE(wm831x_dcdc_ilim) - 1; i >= 0; i--) {
-		if ((min_uA <= wm831x_dcdc_ilim[i]) &&
-		    (wm831x_dcdc_ilim[i] <= max_uA))
-			return wm831x_set_bits(wm831x, reg,
-					       WM831X_DC1_HC_THR_MASK,
-						i << WM831X_DC1_HC_THR_SHIFT);
-	}
-
-	return -EINVAL;
-}
-
-static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
-{
-	struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
-	struct wm831x *wm831x = dcdc->wm831x;
-	u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2;
-	int val;
-
-	val = wm831x_reg_read(wm831x, reg);
-	if (val < 0)
-		return val;
-
-	val = (val & WM831X_DC1_HC_THR_MASK) >> WM831X_DC1_HC_THR_SHIFT;
-	return wm831x_dcdc_ilim[val];
-}
-
 static const struct regulator_ops wm831x_buckv_ops = {
 	.set_voltage_sel = wm831x_buckv_set_voltage_sel,
 	.get_voltage_sel = wm831x_buckv_get_voltage_sel,
 	.list_voltage = regulator_list_voltage_linear_range,
 	.map_voltage = regulator_map_voltage_linear_range,
 	.set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
-	.set_current_limit = wm831x_buckv_set_current_limit,
-	.get_current_limit = wm831x_buckv_get_current_limit,
+	.set_current_limit = regulator_set_current_limit_regmap,
+	.get_current_limit = regulator_get_current_limit_regmap,
 
 	.is_enabled = regulator_is_enabled_regmap,
 	.enable = regulator_enable_regmap,
@@ -475,6 +441,10 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
 	dcdc->desc.owner = THIS_MODULE;
 	dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
 	dcdc->desc.enable_mask = 1 << id;
+	dcdc->desc.csel_reg = dcdc->base + WM831X_DCDC_CONTROL_2;
+	dcdc->desc.csel_mask = WM831X_DC1_HC_THR_MASK;
+	dcdc->desc.n_current_limits = ARRAY_SIZE(wm831x_dcdc_ilim);
+	dcdc->desc.curr_table = wm831x_dcdc_ilim;
 
 	ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG);
 	if (ret < 0) {
-- 
2.17.1


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

* RE: [PATCH 04/11] regulator: da9210: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 ` [PATCH 04/11] regulator: da9210: " Axel Lin
@ 2019-02-28 14:01   ` Steve Twiss
  0 siblings, 0 replies; 19+ messages in thread
From: Steve Twiss @ 2019-02-28 14:01 UTC (permalink / raw)
  To: Axel Lin, Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Seong-Won Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel

On 28 February 2019 13:40, Axel Lin wrote:

> Subject: [PATCH 04/11] regulator: da9210: Convert to use
> regulator_set/get_current_limit_regmap

[...]

> @@ -52,8 +48,8 @@ static const struct regulator_ops da9210_buck_ops = {
>  	.set_voltage_sel = regulator_set_voltage_sel_regmap,
>  	.get_voltage_sel = regulator_get_voltage_sel_regmap,
>  	.list_voltage = regulator_list_voltage_linear,
> -	.set_current_limit = da9210_set_current_limit,
> -	.get_current_limit = da9210_get_current_limit,
> +	.set_current_limit = regulator_set_current_limit_regmap,
> +	.get_current_limit = regulator_get_current_limit_regmap,
>  };

Hi Axel, 
Thanks,

Acked-by: Steve Twiss <stwiss.opensource@diasemi.com>

Regards,
Steve


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

* Re: [PATCH 07/11] regulator: max77650: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 ` [PATCH 07/11] regulator: max77650: " Axel Lin
@ 2019-02-28 14:11   ` Bartosz Golaszewski
  0 siblings, 0 replies; 19+ messages in thread
From: Bartosz Golaszewski @ 2019-02-28 14:11 UTC (permalink / raw)
  To: Axel Lin
  Cc: Mark Brown, Support Opensource, patches, Ashish Jangam,
	Steve Twiss, Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Liam Girdwood, LKML

czw., 28 lut 2019 o 14:41 Axel Lin <axel.lin@ingics.com> napisał(a):
>
> Use regulator_set/get_current_limit_regmap helpers to save some code.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>  drivers/regulator/max77650-regulator.c | 74 +++++++++-----------------
>  1 file changed, 25 insertions(+), 49 deletions(-)
>
> diff --git a/drivers/regulator/max77650-regulator.c b/drivers/regulator/max77650-regulator.c
> index a1af414db751..31ebf34b01ec 100644
> --- a/drivers/regulator/max77650-regulator.c
> +++ b/drivers/regulator/max77650-regulator.c
> @@ -26,9 +26,6 @@
>  #define MAX77650_REGULATOR_AD_ENABLED          BIT(3)
>
>  #define MAX77650_REGULATOR_CURR_LIM_MASK       GENMASK(7, 6)
> -#define MAX77650_REGULATOR_CURR_LIM_BITS(_reg) \
> -               (((_reg) & MAX77650_REGULATOR_CURR_LIM_MASK) >> 6)
> -#define MAX77650_REGULATOR_CURR_LIM_SHIFT(_val)        ((_val) << 6)
>
>  enum {
>         MAX77650_REGULATOR_ID_LDO = 0,
> @@ -82,7 +79,7 @@ static const u32 max77651_sbb1_regulator_volt_table[] = {
>                 _val = MAX77651_REGULATOR_SBB1_SEL_ENC(_val);           \
>         } while (0)
>
> -static const int max77650_current_limit_table[] = {
> +static const unsigned int max77650_current_limit_table[] = {
>         1000000, 866000, 707000, 500000,
>  };
>
> @@ -220,47 +217,6 @@ static int max77651_regulator_sbb1_set_voltage_sel(struct regulator_dev *rdev,
>         return 0;
>  }
>
> -static int max77650_regulator_get_current_limit(struct regulator_dev *rdev)
> -{
> -       struct max77650_regulator_desc *rdesc;
> -       struct regmap *map;
> -       int val, rv, limit;
> -
> -       rdesc = rdev_get_drvdata(rdev);
> -       map = rdev_get_regmap(rdev);
> -
> -       rv = regmap_read(map, rdesc->regA, &val);
> -       if (rv)
> -               return rv;
> -
> -       limit = MAX77650_REGULATOR_CURR_LIM_BITS(val);
> -
> -       return max77650_current_limit_table[limit];
> -}
> -
> -static int max77650_regulator_set_current_limit(struct regulator_dev *rdev,
> -                                               int min_uA, int max_uA)
> -{
> -       struct max77650_regulator_desc *rdesc;
> -       struct regmap *map;
> -       int i, limit;
> -
> -       rdesc = rdev_get_drvdata(rdev);
> -       map = rdev_get_regmap(rdev);
> -
> -       for (i = 0; i < ARRAY_SIZE(max77650_current_limit_table); i++) {
> -               limit = max77650_current_limit_table[i];
> -
> -               if (limit >= min_uA && limit <= max_uA) {
> -                       return regmap_update_bits(map, rdesc->regA,
> -                                       MAX77650_REGULATOR_CURR_LIM_MASK,
> -                                       MAX77650_REGULATOR_CURR_LIM_SHIFT(i));
> -               }
> -       }
> -
> -       return -EINVAL;
> -}
> -
>  static const struct regulator_ops max77650_regulator_LDO_ops = {
>         .is_enabled             = max77650_regulator_is_enabled,
>         .enable                 = max77650_regulator_enable,
> @@ -280,8 +236,8 @@ static const struct regulator_ops max77650_regulator_SBB_ops = {
>         .map_voltage            = regulator_map_voltage_linear,
>         .get_voltage_sel        = regulator_get_voltage_sel_regmap,
>         .set_voltage_sel        = max77650_regulator_set_voltage_sel,
> -       .get_current_limit      = max77650_regulator_get_current_limit,
> -       .set_current_limit      = max77650_regulator_set_current_limit,
> +       .get_current_limit      = regulator_get_current_limit_regmap,
> +       .set_current_limit      = regulator_set_current_limit_regmap,
>         .set_active_discharge   = regulator_set_active_discharge_regmap,
>  };
>
> @@ -293,8 +249,8 @@ static const struct regulator_ops max77651_SBB1_regulator_ops = {
>         .list_voltage           = regulator_list_voltage_table,
>         .get_voltage_sel        = regulator_get_voltage_sel_regmap,
>         .set_voltage_sel        = max77651_regulator_sbb1_set_voltage_sel,
> -       .get_current_limit      = max77650_regulator_get_current_limit,
> -       .set_current_limit      = max77650_regulator_set_current_limit,
> +       .get_current_limit      = regulator_get_current_limit_regmap,
> +       .set_current_limit      = regulator_set_current_limit_regmap,
>         .set_active_discharge   = regulator_set_active_discharge_regmap,
>  };
>
> @@ -343,6 +299,10 @@ static struct max77650_regulator_desc max77650_SBB0_desc = {
>                 .enable_time            = 100,
>                 .type                   = REGULATOR_VOLTAGE,
>                 .owner                  = THIS_MODULE,
> +               .csel_reg               = MAX77650_REG_CNFG_SBB0_A,
> +               .csel_mask              = MAX77650_REGULATOR_CURR_LIM_MASK,
> +               .curr_table             = max77650_current_limit_table,
> +               .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
>         },
>         .regA           = MAX77650_REG_CNFG_SBB0_A,
>         .regB           = MAX77650_REG_CNFG_SBB0_B,
> @@ -368,6 +328,10 @@ static struct max77650_regulator_desc max77650_SBB1_desc = {
>                 .enable_time            = 100,
>                 .type                   = REGULATOR_VOLTAGE,
>                 .owner                  = THIS_MODULE,
> +               .csel_reg               = MAX77650_REG_CNFG_SBB1_A,
> +               .csel_mask              = MAX77650_REGULATOR_CURR_LIM_MASK,
> +               .curr_table             = max77650_current_limit_table,
> +               .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
>         },
>         .regA           = MAX77650_REG_CNFG_SBB1_A,
>         .regB           = MAX77650_REG_CNFG_SBB1_B,
> @@ -392,6 +356,10 @@ static struct max77650_regulator_desc max77651_SBB1_desc = {
>                 .enable_time            = 100,
>                 .type                   = REGULATOR_VOLTAGE,
>                 .owner                  = THIS_MODULE,
> +               .csel_reg               = MAX77650_REG_CNFG_SBB1_A,
> +               .csel_mask              = MAX77650_REGULATOR_CURR_LIM_MASK,
> +               .curr_table             = max77650_current_limit_table,
> +               .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
>         },
>         .regA           = MAX77650_REG_CNFG_SBB1_A,
>         .regB           = MAX77650_REG_CNFG_SBB1_B,
> @@ -417,6 +385,10 @@ static struct max77650_regulator_desc max77650_SBB2_desc = {
>                 .enable_time            = 100,
>                 .type                   = REGULATOR_VOLTAGE,
>                 .owner                  = THIS_MODULE,
> +               .csel_reg               = MAX77650_REG_CNFG_SBB2_A,
> +               .csel_mask              = MAX77650_REGULATOR_CURR_LIM_MASK,
> +               .curr_table             = max77650_current_limit_table,
> +               .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
>         },
>         .regA           = MAX77650_REG_CNFG_SBB2_A,
>         .regB           = MAX77650_REG_CNFG_SBB2_B,
> @@ -442,6 +414,10 @@ static struct max77650_regulator_desc max77651_SBB2_desc = {
>                 .enable_time            = 100,
>                 .type                   = REGULATOR_VOLTAGE,
>                 .owner                  = THIS_MODULE,
> +               .csel_reg               = MAX77650_REG_CNFG_SBB2_A,
> +               .csel_mask              = MAX77650_REGULATOR_CURR_LIM_MASK,
> +               .curr_table             = max77650_current_limit_table,
> +               .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
>         },
>         .regA           = MAX77650_REG_CNFG_SBB2_A,
>         .regB           = MAX77650_REG_CNFG_SBB2_B,
> --
> 2.17.1
>

Looks good.

Acked-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

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

* RE: [PATCH 03/11] regulator: da9055: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 ` [PATCH 03/11] regulator: da9055: Convert to use regulator_set/get_current_limit_regmap Axel Lin
@ 2019-02-28 15:18   ` Steve Twiss
  0 siblings, 0 replies; 19+ messages in thread
From: Steve Twiss @ 2019-02-28 15:18 UTC (permalink / raw)
  To: Axel Lin, Mark Brown
  Cc: Support Opensource, patches, Ashish Jangam, Steve Twiss,
	Paul Kocialkowski, Milo Kim, Keerthy, James Seong-Won Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel

On 28 February 2019 13:40, Axel Lin,

> Subject: [PATCH 03/11] regulator: da9055: Convert to use
> regulator_set/get_current_limit_regmap
> 
> Use regulator_set/get_current_limit_regmap helpers to save some code.

[...]

> @@ -329,8 +298,8 @@ static const struct regulator_ops da9055_buck_ops = {
>  	.get_mode = da9055_buck_get_mode,
>  	.set_mode = da9055_buck_set_mode,
> 
> -	.get_current_limit = da9055_buck_get_current_limit,
> -	.set_current_limit = da9055_buck_set_current_limit,
> +	.get_current_limit = regulator_get_current_limit_regmap,
> +	.set_current_limit = regulator_set_current_limit_regmap,
> 
>  	.get_voltage_sel = da9055_regulator_get_voltage_sel,
>  	.set_voltage_sel = da9055_regulator_set_voltage_sel,
> @@ -407,6 +376,10 @@ static const struct regulator_ops da9055_ldo_ops = {
>  		.uV_step = (step) * 1000,\
>  		.linear_min_sel = (voffset),\
>  		.owner = THIS_MODULE,\
> +		.curr_table = da9055_current_limits,\
> +		.n_current_limits = ARRAY_SIZE(da9055_current_limits),\
> +		.csel_reg = DA9055_REG_BUCK_LIM,\
> +		.csel_mask = (mbits),\

Hi Axel, 

Thanks.

Acked-by: Steve Twiss <stwiss.opensource@diasemi.com>

Regards,
Steve


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

* RE: [PATCH 08/11] regulator: pv88060: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 ` [PATCH 08/11] regulator: pv88060: " Axel Lin
@ 2019-02-28 15:26   ` Steve Twiss
  0 siblings, 0 replies; 19+ messages in thread
From: Steve Twiss @ 2019-02-28 15:26 UTC (permalink / raw)
  To: Axel Lin, Mark Brown
  Cc: James Seong-Won Ban, Support Opensource, patches, Ashish Jangam,
	Paul Kocialkowski, Milo Kim, Keerthy, Bartosz Golaszewski,
	Liam Girdwood, linux-kernel

On 28 February 2019 13:40, Axel Lin wrote:

> Subject: [PATCH 08/11] regulator: pv88060: Convert to use
> regulator_set/get_current_limit_regmap
> 
> Use regulator_set/get_current_limit_regmap helpers to save some code.

[...]

Hi Axel,

Looks good to me. Thanks again.

Acked-by: Steve Twiss <stwiss.opensource@diasemi.com>

Regards,
Steve

> @@ -171,8 +133,8 @@ static const struct regulator_ops pv88060_buck_ops = {
>  	.set_voltage_sel = regulator_set_voltage_sel_regmap,
>  	.get_voltage_sel = regulator_get_voltage_sel_regmap,
>  	.list_voltage = regulator_list_voltage_linear,
> -	.set_current_limit = pv88060_set_current_limit,
> -	.get_current_limit = pv88060_get_current_limit,
> +	.set_current_limit = regulator_set_current_limit_regmap,
> +	.get_current_limit = regulator_get_current_limit_regmap,
>  };
> 
>  static const struct regulator_ops pv88060_ldo_ops = {
> @@ -207,10 +169,11 @@ static const struct regulator_ops pv88060_sw_ops = {
>  		.enable_mask = PV88060_BUCK_EN, \
>  		.vsel_reg = PV88060_REG_##regl_name##_CONF0,\
>  		.vsel_mask = PV88060_VBUCK_MASK,\
> +		.curr_table = limits_array,\
> +		.n_current_limits = ARRAY_SIZE(limits_array),\
> +		.csel_reg = PV88060_REG_##regl_name##_CONF1,\
> +		.csel_mask = PV88060_BUCK_ILIM_MASK,\
>  	},\
> -	.current_limits = limits_array,\
> -	.n_current_limits = ARRAY_SIZE(limits_array),\
> -	.limit_mask = PV88060_BUCK_ILIM_MASK, \
>  	.conf = PV88060_REG_##regl_name##_CONF1,\
>  }
> 
> --
> 2.17.1


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

* RE: [PATCH 09/11] regulator: pv88080: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 ` [PATCH 09/11] regulator: pv88080: " Axel Lin
@ 2019-02-28 15:41   ` Steve Twiss
  0 siblings, 0 replies; 19+ messages in thread
From: Steve Twiss @ 2019-02-28 15:41 UTC (permalink / raw)
  To: Axel Lin, Mark Brown
  Cc: James Seong-Won Ban, Support Opensource, patches, Ashish Jangam,
	Paul Kocialkowski, Milo Kim, Keerthy, Bartosz Golaszewski,
	Liam Girdwood, linux-kernel

On 28 February 2019 13:40, Axel Lin wrote:

> Subject: [PATCH 09/11] regulator: pv88080: Convert to use
> regulator_set/get_current_limit_regmap
> 
> Use regulator_set/get_current_limit_regmap helpers to save some code.

[...]

Hi Axel,

Looks good to me. Thanks again.

Acked-by: Steve Twiss <stwiss.opensource@diasemi.com>

Regards,
Steve

[...]

> @@ -315,8 +276,8 @@ static const struct regulator_ops pv88080_buck_ops = {
>  	.set_voltage_sel = regulator_set_voltage_sel_regmap,
>  	.get_voltage_sel = regulator_get_voltage_sel_regmap,
>  	.list_voltage = regulator_list_voltage_linear,
> -	.set_current_limit = pv88080_set_current_limit,
> -	.get_current_limit = pv88080_get_current_limit,
> +	.set_current_limit = regulator_set_current_limit_regmap,
> +	.get_current_limit = regulator_get_current_limit_regmap,
>  };

[...]

> 
>  static const struct regulator_ops pv88080_hvbuck_ops = {
> @@ -341,9 +302,9 @@ static const struct regulator_ops pv88080_hvbuck_ops = {
>  		.min_uV = min, \
>  		.uV_step = step, \
>  		.n_voltages = ((max) - (min))/(step) + 1, \
> +		.curr_table = limits_array, \
> +		.n_current_limits = ARRAY_SIZE(limits_array), \
>  	},\
> -	.current_limits = limits_array, \
> -	.n_current_limits = ARRAY_SIZE(limits_array), \
>  }
> 
>  #define PV88080_HVBUCK(chip, regl_name, min, step, max) \
> @@ -521,9 +482,9 @@ static int pv88080_i2c_probe(struct i2c_client *i2c,
>  		if (init_data)
>  			config.init_data = &init_data[i];
> 
> -		pv88080_regulator_info[i].limit_reg
> +		pv88080_regulator_info[i].desc.csel_reg
>  			= regmap_config->buck_regmap[i].buck_limit_reg;
> -		pv88080_regulator_info[i].limit_mask
> +		pv88080_regulator_info[i].desc.csel_mask
>  			= regmap_config->buck_regmap[i].buck_limit_mask;
>  		pv88080_regulator_info[i].mode_reg
>  			= regmap_config->buck_regmap[i].buck_mode_reg;
> --
> 2.17.1


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

* RE: [PATCH 10/11] regulator: pv88090: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 ` [PATCH 10/11] regulator: pv88090: " Axel Lin
@ 2019-02-28 15:47   ` Steve Twiss
  0 siblings, 0 replies; 19+ messages in thread
From: Steve Twiss @ 2019-02-28 15:47 UTC (permalink / raw)
  To: Axel Lin, Mark Brown
  Cc: James Seong-Won Ban, Support Opensource, patches, Ashish Jangam,
	Paul Kocialkowski, Milo Kim, Keerthy, Bartosz Golaszewski,
	Liam Girdwood, linux-kernel

On 28 February 2019 13:40, Axel Lin wrote:

Hi Axel,

> Subject: [PATCH 10/11] regulator: pv88090: Convert to use
> regulator_set/get_current_limit_regmap
> 
> Use regulator_set/get_current_limit_regmap helpers to save some code.

[...]

> @@ -193,8 +155,8 @@ static const struct regulator_ops pv88090_buck_ops = {
>  	.set_voltage_sel = regulator_set_voltage_sel_regmap,
>  	.get_voltage_sel = regulator_get_voltage_sel_regmap,
>  	.list_voltage = regulator_list_voltage_linear,
> -	.set_current_limit = pv88090_set_current_limit,
> -	.get_current_limit = pv88090_get_current_limit,
> +	.set_current_limit = regulator_set_current_limit_regmap,
> +	.get_current_limit = regulator_get_current_limit_regmap,
>  };
> 
>  static const struct regulator_ops pv88090_ldo_ops = {
> @@ -223,10 +185,11 @@ static const struct regulator_ops pv88090_ldo_ops = {
>  		.enable_mask = PV88090_##regl_name##_EN, \
>  		.vsel_reg = PV88090_REG_##regl_name##_CONF0, \
>  		.vsel_mask = PV88090_V##regl_name##_MASK, \
> +		.curr_table = limits_array, \
> +		.n_current_limits = ARRAY_SIZE(limits_array), \
> +		.csel_reg = PV88090_REG_##regl_name##_CONF1, \
> +		.csel_mask = PV88090_##regl_name##_ILIM_MASK, \
>  	},\
> -	.current_limits = limits_array, \
> -	.n_current_limits = ARRAY_SIZE(limits_array), \
> -	.limit_mask = PV88090_##regl_name##_ILIM_MASK, \
>  	.conf = PV88090_REG_##regl_name##_CONF1, \
>  	.conf2 = PV88090_REG_##regl_name##_CONF2, \

Acked-by: Steve Twiss <stwiss.opensource@diasemi.com>;

Thanks,
Regards,
Steve



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

* Re: [PATCH 11/11] regulator: wm831x-dcdc: Convert to use regulator_set/get_current_limit_regmap
  2019-02-28 13:40 ` [PATCH 11/11] regulator: wm831x-dcdc: " Axel Lin
@ 2019-03-01  8:33   ` Charles Keepax
  0 siblings, 0 replies; 19+ messages in thread
From: Charles Keepax @ 2019-03-01  8:33 UTC (permalink / raw)
  To: Axel Lin
  Cc: Mark Brown, Support Opensource, patches, Ashish Jangam,
	Steve Twiss, Paul Kocialkowski, Milo Kim, Keerthy, James Ban,
	Bartosz Golaszewski, Liam Girdwood, linux-kernel

On Thu, Feb 28, 2019 at 09:40:22PM +0800, Axel Lin wrote:
> Use regulator_set/get_current_limit_regmap helpers to save some code.
> 
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---

Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Thanks,
Charles

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

end of thread, other threads:[~2019-03-01  8:36 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-28 13:40 [PATCH 00/11] regulator: Add set/get_current_limit helpers and use it Axel Lin
2019-02-28 13:40 ` [PATCH 01/11] regulator: Fix comment for csel_reg and csel_mask Axel Lin
2019-02-28 13:40 ` [PATCH 02/11] regulator: core: Add set/get_current_limit helpers for regmap users Axel Lin
2019-02-28 13:40 ` [PATCH 03/11] regulator: da9055: Convert to use regulator_set/get_current_limit_regmap Axel Lin
2019-02-28 15:18   ` Steve Twiss
2019-02-28 13:40 ` [PATCH 04/11] regulator: da9210: " Axel Lin
2019-02-28 14:01   ` Steve Twiss
2019-02-28 13:40 ` [PATCH 05/11] regulator: lp872x: " Axel Lin
2019-02-28 13:40 ` [PATCH 06/11] regulator: lp873x: " Axel Lin
2019-02-28 13:40 ` [PATCH 07/11] regulator: max77650: " Axel Lin
2019-02-28 14:11   ` Bartosz Golaszewski
2019-02-28 13:40 ` [PATCH 08/11] regulator: pv88060: " Axel Lin
2019-02-28 15:26   ` Steve Twiss
2019-02-28 13:40 ` [PATCH 09/11] regulator: pv88080: " Axel Lin
2019-02-28 15:41   ` Steve Twiss
2019-02-28 13:40 ` [PATCH 10/11] regulator: pv88090: " Axel Lin
2019-02-28 15:47   ` Steve Twiss
2019-02-28 13:40 ` [PATCH 11/11] regulator: wm831x-dcdc: " Axel Lin
2019-03-01  8:33   ` Charles Keepax

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