linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@ingics.com>
To: Mark Brown <broonie@kernel.org>
Cc: Support Opensource <support.opensource@diasemi.com>,
	patches@opensource.cirrus.com,
	Ashish Jangam <ashish.jangam@kpitcummins.com>,
	Steve Twiss <stwiss.opensource@diasemi.com>,
	Paul Kocialkowski <contact@paulk.fr>, Milo Kim <milo.kim@ti.com>,
	Keerthy <j-keerthy@ti.com>,
	James Ban <James.Ban.opensource@diasemi.com>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org, Axel Lin <axel.lin@ingics.com>
Subject: [PATCH 05/11] regulator: lp872x: Convert to use regulator_set/get_current_limit_regmap
Date: Thu, 28 Feb 2019 21:40:16 +0800	[thread overview]
Message-ID: <20190228134022.32625-6-axel.lin@ingics.com> (raw)
In-Reply-To: <20190228134022.32625-1-axel.lin@ingics.com>

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


  parent reply	other threads:[~2019-02-28 13:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Axel Lin [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190228134022.32625-6-axel.lin@ingics.com \
    --to=axel.lin@ingics.com \
    --cc=James.Ban.opensource@diasemi.com \
    --cc=ashish.jangam@kpitcummins.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=contact@paulk.fr \
    --cc=j-keerthy@ti.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=milo.kim@ti.com \
    --cc=patches@opensource.cirrus.com \
    --cc=stwiss.opensource@diasemi.com \
    --cc=support.opensource@diasemi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).