Skip to contentSkip to conversation

regulator: rt6160: Add DT binding document for Richtek RT6160

PATCH Superseded cy_huang 2 participants 7 messages May 26, 2021 – Jun 2, 2021

Subsystems (2)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

cy_huang

author
#0 lore raw

PATCH v4 1/2 regulator: rt6160: Add DT binding document for Richtek RT6160

From: ChiYuan Huang <[email protected]>

Add DT binding document for Richtek RT6160 voltage regulator.

---
since v4
- Add Reviewed-by.

since v3
- Move all regulator related properties to the upper node.

since v2
- Move buckboost node from patternProperties to Properties.

---
 .../regulator/richtek,rt6160-regulator.yaml        | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/richtek,rt6160-regulator.yaml
Documentation/devicetree/bindings/regulator/richtek,rt6160-regulator.yaml new file +61 -0
new file mode 100644
index 00000000..0534b0d
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/richtek,rt6160-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Richtek RT6160 BuckBoost converter
+
+maintainers:
+  - ChiYuan Huang <[email protected]>
+
+description: |
+  The RT6160 is a high-efficiency buck-boost converter that can provide
+  up to 3A output current from 2025mV to 5200mV. And it support the wide
+  input voltage range from 2200mV to 5500mV.
+
+  Datasheet is available at
+  https://www.richtek.com/assets/product_file/RT6160A/DS6160A-00.pdf
+
+allOf:
+  - $ref: regulator.yaml#
+
+properties:
+  compatible:
+    enum:
+      - richtek,rt6160
+
+  reg:
+    maxItems: 1
+
+  enable-gpios:
+    description: A connection of the 'enable' gpio line.
+    maxItems: 1
+
+  richtek,vsel-active-low:
+    description: |
+      Used to indicate the 'vsel' pin active level. if not specified, use
+      high active level as the default.
+    type: boolean
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      rt6160@75 {
+        compatible = "richtek,rt6160";
+        reg = <0x75>;
+        enable-gpios = <&gpio26 2 0>;
+        regulator-name = "rt6160-buckboost";
+        regulator-min-microvolt = <2025000>;
+        regulator-max-microvolt = <5200000>;
+      };
+    };
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v4 2/2 regulator: rt6160: Add support for Richtek RT6160

From: ChiYuan Huang <[email protected]>

Add support for Richtek RT6160 voltage regulator. It can provide up to 3A output current within the adjustable voltage from 2025mV to 5200mV. It integrate a buckboost converter to support wide input voltage range from 2200mV to 5500mV.

---
since v4
- Add of_node into regulator_config to fix regulator_get by device tree node parsing.

since v3
- Use more header file like as of_regulator.h and property.h.
- Change the parsing string from 'richtek,vsel_active_low' to 'richtek,vsel-active-low'.
- Use of_get_regulator_init_data to get the regulator init_data.

since v2
- Fix W=1 warning for of_device_id.

---
 drivers/regulator/Kconfig            |  11 ++
 drivers/regulator/Makefile           |   1 +
 drivers/regulator/rt6160-regulator.c | 270 +++++++++++++++++++++++++++++++++++
 3 files changed, 282 insertions(+)
 create mode 100644 drivers/regulator/rt6160-regulator.c
drivers/regulator/Kconfig +11 -0
index 9d84d92..4fe7ddc 100644
@@ -1030,6 +1030,17 @@ config REGULATOR_RT5033
 	  RT5033 PMIC. The device supports multiple regulators like
 	  current source, LDO and Buck.
 
+config REGULATOR_RT6160
+	tristate "Richtek RT6160 BuckBoost voltage regulator"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  This adds support for voltage regulator in Richtek RT6160.
+	  This device automatically change voltage output mode from
+	  Buck or Boost. The mode transistion depend on the input source voltage.
+	  The wide output range is from 2025mV to 5200mV and can be used on most
+	  common application scenario.
+
 config REGULATOR_RTMV20
 	tristate "RTMV20 Laser Diode Regulator"
 	depends on I2C
drivers/regulator/Makefile +1 -0
index 580b015..5b2c93e 100644
@@ -124,6 +124,7 @@ obj-$(CONFIG_REGULATOR_ROHM)	+= rohm-regulator.o
 obj-$(CONFIG_REGULATOR_RT4801)	+= rt4801-regulator.o
 obj-$(CONFIG_REGULATOR_RT4831)	+= rt4831-regulator.o
 obj-$(CONFIG_REGULATOR_RT5033)	+= rt5033-regulator.o
+obj-$(CONFIG_REGULATOR_RT6160)	+= rt6160-regulator.o
 obj-$(CONFIG_REGULATOR_RTMV20)	+= rtmv20-regulator.o
 obj-$(CONFIG_REGULATOR_S2MPA01) += s2mpa01.o
 obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
drivers/regulator/rt6160-regulator.c new file +270 -0

270 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH v4 2/2] regulator: rt6160: Add support for Richtek RT6160

On Wed, May 26, 2021 at 01:47:48PM +0800, cy_huang wrote:

This looks mostly good, a few small issues below:

Quoted 6 lines
drivers/regulator/rt6160-regulator.c new file +6 -0
+static int rt6160_set_suspend_voltage(struct regulator_dev *rdev, int uV)
+{
+	struct rt6160_priv *priv = rdev_get_drvdata(rdev);
+	struct regmap *regmap = rdev_get_regmap(rdev);
+	unsigned int reg = RT6160_REG_VSELH;
+	int vsel;

drivers/regulator/rt6160-regulator.c line 97

Quoted 10 lines
drivers/regulator/rt6160-regulator.c new file +10 -0
+
+	vsel = regulator_map_voltage_linear(rdev, uV, uV);
+	if (vsel < 0)
+		return vsel;
+
+	if (priv->vsel_active_low)
+		reg = RT6160_REG_VSELL;
+
+	return regmap_update_bits(regmap, reg, RT6160_VSEL_MASK, vsel);
+}

This seems to just be updating the normal voltage configuration regulator, the suspend mode operations are there for devices that have a hardware suspend mode that's entered as part of the very low level system suspend process.

drivers/regulator/rt6160-regulator.c line 107

Quoted 9 lines
drivers/regulator/rt6160-regulator.c new file +9 -0
+static int rt6160_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
+{
+	struct regmap *regmap = rdev_get_regmap(rdev);
+	unsigned int ramp_value = RT6160_RAMPRATE_1VMS;
+
+	switch (ramp_delay) {
+	case 1 ... 1000:
+		ramp_value = RT6160_RAMPRATE_1VMS;
+		break;

This looks like it could be converted to regulator_set_ramp_delay_regmap()

drivers/regulator/rt6160-regulator.c line 168

Quoted 7 lines
drivers/regulator/rt6160-regulator.c new file +7 -0
+static unsigned int rt6160_of_map_mode(unsigned int mode)
+{
+	if (mode == RT6160_MODE_FPWM)
+		return REGULATOR_MODE_FAST;
+	else if (mode == RT6160_MODE_AUTO)
+		return REGULATOR_MODE_NORMAL;
+

This would be more idiomatically written as a switch statement.

drivers/regulator/rt6160-regulator.c line 208

Quoted 5 lines
drivers/regulator/rt6160-regulator.c new file +5 -0
+	enable_gpio = devm_gpiod_get_optional(&i2c->dev, "enable", GPIOD_OUT_HIGH);
+	if (IS_ERR(enable_gpio)) {
+		dev_err(&i2c->dev, "Failed to get 'enable' gpio\n");
+		return PTR_ERR(enable_gpio);
+	}

There's no other references to enable_gpio?

drivers/regulator/rt6160-regulator.c line 214

Quoted 5 lines
drivers/regulator/rt6160-regulator.c new file +5 -0
+	regmap = devm_regmap_init_i2c(i2c, &rt6160_regmap_config);
+	if (IS_ERR(regmap)) {
+		dev_err(&i2c->dev, "Failed to init regmap\n");
+		return PTR_ERR(regmap);
+	}

It's better to print the error code to help anyone who runs into issues figure out what's wrong.

#3 lore raw

Re: [PATCH v4 2/2] regulator: rt6160: Add support for Richtek RT6160

HI:

Mark Brown <[email protected]> 於 2021年5月26日 週三 下午6:50寫道:

Quoted 18 lines · cy_huang

This looks mostly good, a few small issues below:

Quoted 13 lines
drivers/regulator/rt6160-regulator.c new file +13 -0
+static int rt6160_set_suspend_voltage(struct regulator_dev *rdev, int uV)
+{
+     struct rt6160_priv *priv = rdev_get_drvdata(rdev);
+     struct regmap *regmap = rdev_get_regmap(rdev);
+     unsigned int reg = RT6160_REG_VSELH;
+     int vsel;
+
+     vsel = regulator_map_voltage_linear(rdev, uV, uV);
+     if (vsel < 0)
+             return vsel;
+
+     if (priv->vsel_active_low)
+             reg = RT6160_REG_VSELL;
Quoted 9 lines

drivers/regulator/rt6160-regulator.c line 97

Quoted 3 lines
drivers/regulator/rt6160-regulator.c new file +3 -0
+
+     return regmap_update_bits(regmap, reg, RT6160_VSEL_MASK, vsel);
+}

This seems to just be updating the normal voltage configuration regulator, the suspend mode operations are there for devices that have a hardware suspend mode that's entered as part of the very low level system suspend process.

There's a independent 'vsel' pin. It depend on user's HW design. And that's why there's a 'richtek,vsel_active_low' property. Its normal application is to use vsel high active level, and it means the opposite level can be used for the suspend voltage

And there're also two voltage registers for vsel level high and low.

Quoted 12 lines

drivers/regulator/rt6160-regulator.c line 107

Quoted 9 lines
drivers/regulator/rt6160-regulator.c new file +9 -0
+static int rt6160_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
+{
+     struct regmap *regmap = rdev_get_regmap(rdev);
+     unsigned int ramp_value = RT6160_RAMPRATE_1VMS;
+
+     switch (ramp_delay) {
+     case 1 ... 1000:
+             ramp_value = RT6160_RAMPRATE_1VMS;
+             break;

This looks like it could be converted to regulator_set_ramp_delay_regmap()

I didn't notice there's the regulator_set_ramp_delay_regmap API that can be used in kernel 5.13.
Ack in next.

Quoted 10 lines

drivers/regulator/rt6160-regulator.c line 168

Quoted 7 lines
drivers/regulator/rt6160-regulator.c new file +7 -0
+static unsigned int rt6160_of_map_mode(unsigned int mode)
+{
+     if (mode == RT6160_MODE_FPWM)
+             return REGULATOR_MODE_FAST;
+     else if (mode == RT6160_MODE_AUTO)
+             return REGULATOR_MODE_NORMAL;
+

This would be more idiomatically written as a switch statement.

Ack in next. Change the if-else to switch case. Thx.

Quoted 8 lines

drivers/regulator/rt6160-regulator.c line 208

Quoted 5 lines
drivers/regulator/rt6160-regulator.c new file +5 -0
+     enable_gpio = devm_gpiod_get_optional(&i2c->dev, "enable", GPIOD_OUT_HIGH);
+     if (IS_ERR(enable_gpio)) {
+             dev_err(&i2c->dev, "Failed to get 'enable' gpio\n");
+             return PTR_ERR(enable_gpio);
+     }

There's no other references to enable_gpio?

The IC is designed for low IQ.
So from the driver probe, I only need to keep 'enable' pin high. Or if user specify the 'enable' gpio, it will block i2c communication, register also be reset,
and add more delay time on enable/disable.
That's why there's no other references to 'enable' gpio.

Quoted 8 lines

drivers/regulator/rt6160-regulator.c line 214

Quoted 5 lines
drivers/regulator/rt6160-regulator.c new file +5 -0
+     regmap = devm_regmap_init_i2c(i2c, &rt6160_regmap_config);
+     if (IS_ERR(regmap)) {
+             dev_err(&i2c->dev, "Failed to init regmap\n");
+             return PTR_ERR(regmap);
+     }

It's better to print the error code to help anyone who runs into issues figure out what's wrong.

Sure, change it to dev_err(&i2c->dev, "Failed to init regmap (%d)\n", PTR_ERR(regmap));
Ack in next, thx.

#4 lore raw

Re: [PATCH v4 2/2] regulator: rt6160: Add support for Richtek RT6160

HI, Mark:

ChiYuan Huang <[email protected]> 於 2021年5月26日 週三 下午11:04寫道:

Quoted 49 lines

HI:

Mark Brown <[email protected]> 於 2021年5月26日 週三 下午6:50寫道:

Quoted 18 lines · cy_huang

This looks mostly good, a few small issues below:

Quoted 13 lines
drivers/regulator/rt6160-regulator.c new file +13 -0
+static int rt6160_set_suspend_voltage(struct regulator_dev *rdev, int uV)
+{
+     struct rt6160_priv *priv = rdev_get_drvdata(rdev);
+     struct regmap *regmap = rdev_get_regmap(rdev);
+     unsigned int reg = RT6160_REG_VSELH;
+     int vsel;
+
+     vsel = regulator_map_voltage_linear(rdev, uV, uV);
+     if (vsel < 0)
+             return vsel;
+
+     if (priv->vsel_active_low)
+             reg = RT6160_REG_VSELL;
Quoted 9 lines

drivers/regulator/rt6160-regulator.c line 97

Quoted 3 lines
drivers/regulator/rt6160-regulator.c new file +3 -0
+
+     return regmap_update_bits(regmap, reg, RT6160_VSEL_MASK, vsel);
+}

This seems to just be updating the normal voltage configuration regulator, the suspend mode operations are there for devices that have a hardware suspend mode that's entered as part of the very low level system suspend process.

There's a independent 'vsel' pin. It depend on user's HW design. And that's why there's a 'richtek,vsel_active_low' property. Its normal application is to use vsel high active level, and it means the opposite level can be used for the suspend voltage

And there're also two voltage registers for vsel level high and low.

Quoted 12 lines

drivers/regulator/rt6160-regulator.c line 107

Quoted 9 lines
drivers/regulator/rt6160-regulator.c new file +9 -0
+static int rt6160_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
+{
+     struct regmap *regmap = rdev_get_regmap(rdev);
+     unsigned int ramp_value = RT6160_RAMPRATE_1VMS;
+
+     switch (ramp_delay) {
+     case 1 ... 1000:
+             ramp_value = RT6160_RAMPRATE_1VMS;
+             break;

This looks like it could be converted to regulator_set_ramp_delay_regmap()

Quoted 3 lines

I didn't notice there's the regulator_set_ramp_delay_regmap API that can be used in kernel 5.13.u
Ack in next.

I review the regulator_set_ramp_delay_regmap API.
If seems I need to fill in the ramp_delay_table by the descend order. But this chip ramp delay table is designed the ascending value reg bit field [0 1 2 3] by
the ascending order [1000 2500 5000 10000] uV/uS
Even if I tried to filler in descending order, I also need a inverted operation.

And I found the regulator_set_ramp_delay_regmap API has some logic error. From the include/linux/regulator/driver.h, the set_ramp_delay function says to set the less or equal one ramp delay value.
But your logic will get the larger or equal one from the descending ramp delay table.

Could you help to check about this?

Quoted 36 lines
Quoted 10 lines

drivers/regulator/rt6160-regulator.c line 168

Quoted 7 lines
drivers/regulator/rt6160-regulator.c new file +7 -0
+static unsigned int rt6160_of_map_mode(unsigned int mode)
+{
+     if (mode == RT6160_MODE_FPWM)
+             return REGULATOR_MODE_FAST;
+     else if (mode == RT6160_MODE_AUTO)
+             return REGULATOR_MODE_NORMAL;
+

This would be more idiomatically written as a switch statement.

Ack in next. Change the if-else to switch case. Thx.

Quoted 8 lines

drivers/regulator/rt6160-regulator.c line 208

Quoted 5 lines
drivers/regulator/rt6160-regulator.c new file +5 -0
+     enable_gpio = devm_gpiod_get_optional(&i2c->dev, "enable", GPIOD_OUT_HIGH);
+     if (IS_ERR(enable_gpio)) {
+             dev_err(&i2c->dev, "Failed to get 'enable' gpio\n");
+             return PTR_ERR(enable_gpio);
+     }

There's no other references to enable_gpio?

The IC is designed for low IQ.
So from the driver probe, I only need to keep 'enable' pin high. Or if user specify the 'enable' gpio, it will block i2c communication, register also be reset,
and add more delay time on enable/disable.
That's why there's no other references to 'enable' gpio.

Quoted 8 lines

drivers/regulator/rt6160-regulator.c line 214

Quoted 5 lines
drivers/regulator/rt6160-regulator.c new file +5 -0
+     regmap = devm_regmap_init_i2c(i2c, &rt6160_regmap_config);
+     if (IS_ERR(regmap)) {
+             dev_err(&i2c->dev, "Failed to init regmap\n");
+             return PTR_ERR(regmap);
+     }

It's better to print the error code to help anyone who runs into issues figure out what's wrong.

Sure, change it to dev_err(&i2c->dev, "Failed to init regmap (%d)\n", PTR_ERR(regmap));
Ack in next, thx.

maintainer
#5 lore raw

Re: [PATCH v4 2/2] regulator: rt6160: Add support for Richtek RT6160

Quoted 6 lines · ChiYuan Huang

I review the regulator_set_ramp_delay_regmap API.
If seems I need to fill in the ramp_delay_table by the descend order. But this chip ramp delay table is designed the ascending value reg bit field [0 1 2 3] by
the ascending order [1000 2500 5000 10000] uV/uS
Even if I tried to filler in descending order, I also need a inverted operation.

I see... that really should be supportable, and I'd have expected find_closest_bigger() to DTRT here, it's not obvious it's expecting ordering.

Quoted 5 lines

And I found the regulator_set_ramp_delay_regmap API has some logic error. From the include/linux/regulator/driver.h, the set_ramp_delay function says to set the less or equal one ramp delay value.
But your logic will get the larger or equal one from the descending ramp delay table.

The code is correct here, the documentation should be fixed - with a delay like this we should be erring on the side of delaying too long to be safe.

#6 lore raw

Re: [PATCH v4 2/2] regulator: rt6160: Add support for Richtek RT6160

HI, Mark:

Mark Brown <[email protected]> 於 2021年6月1日 週二 下午11:52寫道:

Quoted 20 lines · ChiYuan Huang
Quoted 7 lines

I review the regulator_set_ramp_delay_regmap API.
If seems I need to fill in the ramp_delay_table by the descend order. But this chip ramp delay table is designed the ascending value reg bit field [0 1 2 3] by
the ascending order [1000 2500 5000 10000] uV/uS
Even if I tried to filler in descending order, I also need a inverted operation.

I see... that really should be supportable, and I'd have expected find_closest_bigger() to DTRT here, it's not obvious it's expecting ordering.

Quoted 5 lines

And I found the regulator_set_ramp_delay_regmap API has some logic error. From the include/linux/regulator/driver.h, the set_ramp_delay function says to set the less or equal one ramp delay value.
But your logic will get the larger or equal one from the descending ramp delay table.

Quoted 3 lines

The code is correct here, the documentation should be fixed - with a delay like this we should be erring on the side of delaying too long to be safe.

If so, I will upload v7 patch series to meet this selection logic. Thanks.