devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <cy_huang@richtek.com>
To: <broonie@kernel.org>, <krzysztof.kozlowski+dt@linaro.org>,
	<conor+dt@kernel.org>
Cc: <robh+dt@kernel.org>, <lgirdwood@gmail.com>,
	<cy_huang@richtek.com>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] regulator: rt5739: Add DID check and compatible for rt5733
Date: Wed, 28 Jun 2023 16:47:17 +0800	[thread overview]
Message-ID: <1687942037-14652-3-git-send-email-cy_huang@richtek.com> (raw)
In-Reply-To: <1687942037-14652-1-git-send-email-cy_huang@richtek.com>

From: ChiYuan Huang <cy_huang@richtek.com>

Add compatible and use DID to check rt5733.

The only difference bwtween rt5733 and rt5739 is the output range and
voltage step. These two chips can be distinguished from the DIE id.

Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
---
 drivers/regulator/rt5739.c | 49 +++++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/drivers/regulator/rt5739.c b/drivers/regulator/rt5739.c
index 74fc5bf6d87e..c930ea27e51f 100644
--- a/drivers/regulator/rt5739.c
+++ b/drivers/regulator/rt5739.c
@@ -31,10 +31,17 @@
 #define RT5739_MODEVSEL1_MASK	BIT(1)
 #define RT5739_MODEVSEL0_MASK	BIT(0)
 #define RT5739_VID_MASK		GENMASK(7, 5)
+#define RT5739_DID_MASK		GENMASK(3, 0)
 #define RT5739_ACTD_MASK	BIT(7)
 #define RT5739_ENVSEL1_MASK	BIT(1)
 #define RT5739_ENVSEL0_MASK	BIT(0)
 
+#define RT5733_CHIPDIE_ID	0x1
+#define RT5733_VOLT_MINUV	270000
+#define RT5733_VOLT_MAXUV	1401250
+#define RT5733_VOLT_STPUV	6250
+#define RT5733_N_VOLTS		182
+
 #define RT5739_VOLT_MINUV	300000
 #define RT5739_VOLT_MAXUV	1300000
 #define RT5739_VOLT_STPUV	5000
@@ -92,9 +99,26 @@ static int rt5739_set_suspend_voltage(struct regulator_dev *rdev, int uV)
 {
 	const struct regulator_desc *desc = rdev->desc;
 	struct regmap *regmap = rdev_get_regmap(rdev);
-	unsigned int reg, vsel;
+	unsigned int did, reg, vsel;
+	int min_uV, max_uV, step_uV, ret;
+
+	ret = regmap_read(regmap, RT5739_REG_ID1, &did);
+	if (ret)
+		return ret;
+
+	did &= RT5739_DID_MASK;
+
+	if (did == RT5733_CHIPDIE_ID) {
+		min_uV = RT5733_VOLT_MINUV;
+		max_uV = RT5733_VOLT_MAXUV;
+		step_uV = RT5733_VOLT_STPUV;
+	} else {
+		min_uV = RT5739_VOLT_MINUV;
+		max_uV = RT5739_VOLT_MAXUV;
+		step_uV = RT5739_VOLT_STPUV;
+	}
 
-	if (uV < RT5739_VOLT_MINUV || uV > RT5739_VOLT_MAXUV)
+	if (uV < min_uV || uV > max_uV)
 		return -EINVAL;
 
 	if (desc->vsel_reg == RT5739_REG_NSEL0)
@@ -102,7 +126,7 @@ static int rt5739_set_suspend_voltage(struct regulator_dev *rdev, int uV)
 	else
 		reg = RT5739_REG_NSEL0;
 
-	vsel = (uV - RT5739_VOLT_MINUV) / RT5739_VOLT_STPUV;
+	vsel = (uV - min_uV) / step_uV;
 	return regmap_write(regmap, reg, vsel);
 }
 
@@ -189,15 +213,12 @@ static unsigned int rt5739_of_map_mode(unsigned int mode)
 }
 
 static void rt5739_init_regulator_desc(struct regulator_desc *desc,
-				       bool vsel_active_high)
+				       bool vsel_active_high, u8 did)
 {
 	/* Fixed */
 	desc->name = "rt5739-regulator";
 	desc->owner = THIS_MODULE;
 	desc->ops = &rt5739_regulator_ops;
-	desc->n_voltages = RT5739_N_VOLTS;
-	desc->min_uV = RT5739_VOLT_MINUV;
-	desc->uV_step = RT5739_VOLT_STPUV;
 	desc->vsel_mask = RT5739_VSEL_MASK;
 	desc->enable_reg = RT5739_REG_CNTL2;
 	desc->active_discharge_reg = RT5739_REG_CNTL1;
@@ -213,6 +234,17 @@ static void rt5739_init_regulator_desc(struct regulator_desc *desc,
 		desc->vsel_reg = RT5739_REG_NSEL0;
 		desc->enable_mask = RT5739_ENVSEL0_MASK;
 	}
+
+	/* Assigned by CHIPDIE ID */
+	if (did == RT5733_CHIPDIE_ID) {
+		desc->n_voltages = RT5733_N_VOLTS;
+		desc->min_uV = RT5733_VOLT_MINUV;
+		desc->uV_step = RT5733_VOLT_STPUV;
+	} else {
+		desc->n_voltages = RT5739_N_VOLTS;
+		desc->min_uV = RT5739_VOLT_MINUV;
+		desc->uV_step = RT5739_VOLT_STPUV;
+	}
 }
 
 static const struct regmap_config rt5739_regmap_config = {
@@ -258,7 +290,7 @@ static int rt5739_probe(struct i2c_client *i2c)
 
 	vsel_acth = device_property_read_bool(dev, "richtek,vsel-active-high");
 
-	rt5739_init_regulator_desc(desc, vsel_acth);
+	rt5739_init_regulator_desc(desc, vsel_acth, vid & RT5739_DID_MASK);
 
 	cfg.dev = dev;
 	cfg.of_node = dev_of_node(dev);
@@ -271,6 +303,7 @@ static int rt5739_probe(struct i2c_client *i2c)
 }
 
 static const struct of_device_id rt5739_device_table[] = {
+	{ .compatible = "richtek,rt5733" },
 	{ .compatible = "richtek,rt5739" },
 	{ /* sentinel */ }
 };
-- 
2.40.1


  parent reply	other threads:[~2023-06-28  8:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28  8:47 [PATCH 0/2] Add support for RT5733 cy_huang
2023-06-28  8:47 ` [PATCH 1/2] regulator: dt-bindings: rt5739: Add compatible for rt5733 cy_huang
2023-06-28  9:38   ` Rob Herring
2023-06-29  2:05     ` ChiYuan Huang
2023-06-28 15:41   ` Rob Herring
2023-06-28  8:47 ` cy_huang [this message]
2023-06-28 11:47   ` [PATCH 2/2] regulator: rt5739: Add DID check and " Mark Brown
2023-06-29  1:27     ` ChiYuan Huang
2023-07-12 14:29 ` [PATCH 0/2] Add support for RT5733 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=1687942037-14652-3-git-send-email-cy_huang@richtek.com \
    --to=cy_huang@richtek.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /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).