mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adam Ward <adam.ward@diasemi.com>
To: Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Vincent Whitchurch <vincent.whitchurch@axis.com>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>
Subject: [PATCH 8/9] regulator: da9121: add mode support
Date: Fri, 20 Nov 2020 12:14:58 +0000	[thread overview]
Message-ID: <9903ab966b77d8947405e5d4defd162d407cebcf.1605868780.git.Adam.Ward.opensource@diasemi.com> (raw)
In-Reply-To: <cover.1605868780.git.Adam.Ward.opensource@diasemi.com>

Adds get/set for mode, and mapping from REGULATOR_MODE_* to select
PFM/PWM/Auto operation.

Signed-off-by: Adam Ward <Adam.Ward.opensource@diasemi.com>
---
 drivers/regulator/da9121-regulator.c | 74 ++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/drivers/regulator/da9121-regulator.c b/drivers/regulator/da9121-regulator.c
index 5d11c22..3addbd2 100644
--- a/drivers/regulator/da9121-regulator.c
+++ b/drivers/regulator/da9121-regulator.c
@@ -230,6 +230,72 @@ static int da9121_set_current_limit(struct regulator_dev *rdev,
 	return ret;
 }
 
+static unsigned int da9121_map_mode(unsigned int mode)
+{
+	switch (mode) {
+	case DA9121_BUCK_MODE_FORCE_PWM:
+		return REGULATOR_MODE_FAST;
+	case DA9121_BUCK_MODE_FORCE_PWM_SHEDDING:
+		return REGULATOR_MODE_NORMAL;
+	case DA9121_BUCK_MODE_AUTO:
+		return REGULATOR_MODE_IDLE;
+	case DA9121_BUCK_MODE_FORCE_PFM:
+		return REGULATOR_MODE_STANDBY;
+	default:
+		return -EINVAL;
+	}
+}
+
+static int da9121_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
+{
+	struct da9121 *chip = rdev_get_drvdata(rdev);
+	unsigned int val;
+	unsigned int reg;
+	unsigned int msk;
+
+	switch (mode) {
+	case REGULATOR_MODE_FAST:
+		val = DA9121_BUCK_MODE_FORCE_PWM;
+		break;
+	case REGULATOR_MODE_NORMAL:
+		val = DA9121_BUCK_MODE_FORCE_PWM_SHEDDING;
+		break;
+	case REGULATOR_MODE_IDLE:
+		val = DA9121_BUCK_MODE_AUTO;
+		break;
+	case REGULATOR_MODE_STANDBY:
+		val = DA9121_BUCK_MODE_FORCE_PFM;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (!da9121_rdev_to_buck_reg_mask(rdev, true, &reg, &msk))
+		return -EINVAL;
+
+	return regmap_update_bits(chip->regmap, reg, msk, val);
+}
+
+static unsigned int da9121_buck_get_mode(struct regulator_dev *rdev)
+{
+	struct da9121 *chip = rdev_get_drvdata(rdev);
+	unsigned int reg;
+	unsigned int msk;
+	unsigned int val;
+	int ret = 0;
+
+	if (!da9121_rdev_to_buck_reg_mask(rdev, true, &reg, &msk))
+		return -EINVAL;
+
+	ret = regmap_read(chip->regmap, reg, &val);
+	if (ret < 0) {
+		dev_err(chip->dev, "Cannot read BUCK register: %d\n", ret);
+		return -EINVAL;
+	}
+
+	return da9121_map_mode(val & msk);
+}
+
 static const struct regulator_ops da9121_buck_ops = {
 	.enable = regulator_enable_regmap,
 	.disable = regulator_disable_regmap,
@@ -239,6 +305,8 @@ static int da9121_set_current_limit(struct regulator_dev *rdev,
 	.list_voltage = regulator_list_voltage_linear,
 	.get_current_limit = da9121_get_current_limit,
 	.set_current_limit = da9121_set_current_limit,
+	.set_mode = da9121_buck_set_mode,
+	.get_mode = da9121_buck_get_mode,
 };
 
 static struct of_regulator_match da9121_matches[] = {
@@ -258,6 +326,7 @@ static int da9121_set_current_limit(struct regulator_dev *rdev,
 	.name = "da9121",
 	.of_match = "buck1",
 	.owner = THIS_MODULE,
+	.of_map_mode = da9121_map_mode,
 	.regulators_node = of_match_ptr("regulators"),
 	.ops = &da9121_buck_ops,
 	.type = REGULATOR_VOLTAGE,
@@ -281,6 +350,7 @@ static int da9121_set_current_limit(struct regulator_dev *rdev,
 		.name = "DA9220/DA9132 BUCK1",
 		.of_match = "buck1",
 		.owner = THIS_MODULE,
+		.of_map_mode = da9121_map_mode,
 		.regulators_node = of_match_ptr("regulators"),
 		.ops = &da9121_buck_ops,
 		.type = REGULATOR_VOLTAGE,
@@ -298,6 +368,7 @@ static int da9121_set_current_limit(struct regulator_dev *rdev,
 		.name = "DA9220/DA9132 BUCK2",
 		.of_match = "buck2",
 		.owner = THIS_MODULE,
+		.of_map_mode = da9121_map_mode,
 		.regulators_node = of_match_ptr("regulators"),
 		.ops = &da9121_buck_ops,
 		.type = REGULATOR_VOLTAGE,
@@ -318,6 +389,7 @@ static int da9121_set_current_limit(struct regulator_dev *rdev,
 		.name = "DA9122/DA9131 BUCK1",
 		.of_match = "buck1",
 		.owner = THIS_MODULE,
+		.of_map_mode = da9121_map_mode,
 		.regulators_node = of_match_ptr("regulators"),
 		.ops = &da9121_buck_ops,
 		.type = REGULATOR_VOLTAGE,
@@ -335,6 +407,7 @@ static int da9121_set_current_limit(struct regulator_dev *rdev,
 		.name = "DA9122/DA9131 BUCK2",
 		.of_match = "buck2",
 		.owner = THIS_MODULE,
+		.of_map_mode = da9121_map_mode,
 		.regulators_node = of_match_ptr("regulators"),
 		.ops = &da9121_buck_ops,
 		.type = REGULATOR_VOLTAGE,
@@ -354,6 +427,7 @@ static int da9121_set_current_limit(struct regulator_dev *rdev,
 	.name = "DA9217 BUCK1",
 	.of_match = "buck1",
 	.owner = THIS_MODULE,
+	.of_map_mode = da9121_map_mode,
 	.regulators_node = of_match_ptr("regulators"),
 	.ops = &da9121_buck_ops,
 	.type = REGULATOR_VOLTAGE,
-- 
1.9.1


  parent reply	other threads:[~2020-11-20 12:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20 12:14 [PATCH 0/9] regulator: da9121: extend support to variants, add features Adam Ward
2020-11-20 12:14 ` [PATCH 1/9] regulator: Update DA9121 dt-bindings Adam Ward
2020-11-20 13:47   ` Vincent Whitchurch
2020-11-25  9:21     ` Vincent Whitchurch
2020-11-27 13:01       ` Adam Ward
2020-11-27 14:59         ` Mark Brown
2020-11-20 12:14 ` [PATCH 2/9] regulator: da9121: Add header file Adam Ward
2020-11-20 12:14 ` [PATCH 3/9] regulator: da9121: Add device variants Adam Ward
2020-11-20 12:14 ` [PATCH 4/9] regulator: da9121: Add device variant details and respective regmaps Adam Ward
2020-11-20 12:45   ` Mark Brown
2020-11-20 12:14 ` [PATCH 5/9] regulator: da9121: Add support for device variants via devicetree Adam Ward
2020-11-20 12:51   ` Mark Brown
2020-11-20 12:14 ` [PATCH 6/9] regulator: da9121: Update registration to support multiple buck variants Adam Ward
2020-11-20 13:06   ` Mark Brown
2020-11-20 12:14 ` [PATCH 7/9] regulator: da9121: add current support Adam Ward
2020-11-20 13:17   ` Mark Brown
2020-11-20 12:14 ` Adam Ward [this message]
2020-11-20 12:14 ` [PATCH 9/9] regulator: da9121: add interrupt support Adam Ward
2020-11-20 13:45   ` Mark Brown

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=9903ab966b77d8947405e5d4defd162d407cebcf.1605868780.git.Adam.Ward.opensource@diasemi.com \
    --to=adam.ward@diasemi.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=vincent.whitchurch@axis.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

all inboxes | Powered by JetHome®