Skip to contentSkip to conversation

regulator: rt5133: Add RT5133 PMIC regulator Support

PATCH Superseded [email protected] 3 participants 3 messages Jul 17, 2025

Subsystems (2)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: rt5133: Add RT5133 PMIC regulator Support

From: Jeff Chang <[email protected]>

RT5133 is an intefrated chip. It includes 8 LDOs and 3 GPOs that can be used to drive output high/low purpose. The dependency of the GPO block is internally LDO1 Voltage. If LDO1 voltage output disabled, GPO cannot be used to drive output high. It need to pay more attention on the usage.

---
 .../bindings/regulator/richtek,rt5133.yaml    | 164 +++++
 drivers/regulator/Kconfig                     |  13 +
 drivers/regulator/Makefile                    |   1 +
 drivers/regulator/rt5133-regulator.c          | 636 ++++++++++++++++++
 4 files changed, 814 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/richtek,rt5133.yaml
 create mode 100644 drivers/regulator/rt5133-regulator.c
Documentation/devicetree/bindings/regulator/richtek,rt5133.yaml new file +164 -0
new file mode 100644
index 000000000000..e8091f2bedb3
@@ -0,0 +1,164 @@
+# SPDX-License-Identifier: GPL-6.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/richtek,rt5133.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Richtek RT5133 PMIC Regulator
+
+maintainers:
+  - ShihChia Chang <[email protected]>
+
+description: |
+  RT5133 is an intefrated chip. It includes 8 LDOs and 3 GPOs that can be
+  used to drive output high/low purpose. The dependency of the GPO block
+  is internally LDO1 Voltage. If LDO1 voltage output disabled, GPO cannot
+  be used to drive output high. It need to pay more attention on the usage.
+
+allOf:
+  - $ref: regulator.yaml#
+
+properties:
+  compatible:
+    enum:
+      - richtek,rt5133
+
+  reg:
+    maxItems: 1
+
+  enable-gpios:
+    description: A connection of the 'enable' gpio line.
+    maxItems: 1
+
+  wakeup-source: true
+
+  interrupts:
+    maxItems: 1
+
+  gpio-controller: true
+
+  "#gpio-cells":
+    const: 2
+
+  regulators:
+    type: object
+
+  oc-shutdown-all:
+    type: object
+    description: |
+      Anyone of LDO OC state
+        0: LDO OC only shut down itself
+        1: LDO OC shut down all channels
+
+  pgb-shutdown-all:
+    type: object
+    description: |
+      Anyone of PGB OC state
+        0: LDO PGB only shut down itself
+        1: LDO PGB shut down all channels
+
+  soft-start-time-sel:
+    type: object
+    description: |
+      soft-start time of LDO
+        0: 1ms
+        1: 2ms
+        2: 4ms
+        3: 8ms
+
+  rt5133-ldo1-supply:
+    description: |
+      Only for LDO7 LDO8, pvin7 and pvin8 reference design are RT5133 LDO1.
+      If not connect to LDO1 vout, this property for pvin7 and pvin8 is necessary.
+    
+
+required:
+  - compatible
+  - reg
+  - interrupts-extended
+  - wakeup-source
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      rt5133: rt5133@18 {
+        status = "ok";
+        compatible = "richtek,rt5133";
+        reg = <0x18>;
+        wakeup-source;
+        interrupts-extended = <&pio 187 0x0>;
+        enable-gpios = <&pio 186 0x0>;
+        gpio-controller;
+        #gpio-cells = <2>;
+        regulators {
+          BASE {
+            regulator-name = "rt5133,base";
+            oc-shutdown-all = <0>;
+            pgb-shutdown-all = <0>;
+          };
+          rt5133_ldo1: LDO1 {
+            regulator-name = "rt5133-ldo1";
+            regulator-min-microvolt = <1800000>;
+            regulator-max-microvolt = <3199998>;
+            regulator-active-discharge;
+            soft-start-time-sel = <1>;
+          };
+          rt5133_ldo2: LDO2 {
+            regulator-name = "rt5133-ldo2";
+            regulator-min-microvolt = <1800000>;
+            regulator-max-microvolt = <3200000>;
+            regulator-active-discharge;
+            soft-start-time-sel = <1>;
+          };
+          rt5133_ldo3: LDO3 {
+            regulator-name = "rt5133-ldo3";
+            regulator-min-microvolt = <1700000>;
+            regulator-max-microvolt = <3000000>;
+            regulator-active-discharge;
+            soft-start-time-sel = <1>;
+          };
+          rt5133_ldo4: LDO4 {
+            regulator-name = "rt5133-ldo4";
+            regulator-min-microvolt = <1700000>;
+            regulator-max-microvolt = <3000000>;
+            regulator-active-discharge;
+            soft-start-time-sel = <1>;
+          };
+          rt5133_ldo5: LDO5 {
+            regulator-name = "rt5133-ldo5";
+            regulator-min-microvolt = <1700000>;
+            regulator-max-microvolt = <3000000>;
+            regulator-active-discharge;
+            soft-start-time-sel = <1>;
+          };
+          rt5133_ldo6: LDO6 {
+            regulator-name = "rt5133-ldo6";
+            regulator-min-microvolt = <1700000>;
+            regulator-max-microvolt = <3000000>;
+            regulator-active-discharge;
+            soft-start-time-sel = <1>;
+          };
+          rt5133_ldo7: LDO7 {
+            regulator-name = "rt5133-ldo7";
+            regulator-min-microvolt = <900000>;
+            regulator-max-microvolt = <1200000>;
+            regulator-active-discharge;
+            soft-start-time-sel = <1>;
+            rt5133-ldo1-supply = <&rt5133_ldo1>;
+          };
+          rt5133_ldo8: LDO8 {
+            regulator-name = "rt5133-ldo8";
+            regulator-min-microvolt = <855000>;
+            regulator-max-microvolt = <1200000>;
+            regulator-active-discharge;
+            soft-start-time-sel = <1>;
+            rt5133-ldo1-supply = <&rt5133_ldo1>;
+          };
+        };
+      };
+    };
drivers/regulator/Kconfig +13 -0
index 6d8988387da4..d5a0e422772d 100644
@@ -1229,6 +1229,19 @@ config REGULATOR_RT5120
 	  600mV to 1395mV, per step 6.250mV. The others are all fixed voltage
 	  by external hardware circuit.
 
+config REGULATOR_RT5133
+	tristate "Richtek RT5133 PMIC Regulators"
+	depends on I2C && GPIOLIB
+	select REGMAP
+	select CRC8
+	select OF_GPIO
+	help
+	  RT5133 is an intefrated chip. It includes 8 LDOs and 3 GPOs that
+	  can be used to drive output high/low purpose. The dependency of the
+	  GPO block is internally LDO-1 Voltage. If LDO1 voltage output disabled,
+	  GPO cannot be used to drive output high. It need to pay more attention
+	  on the usage.
+
 config REGULATOR_RT5190A
 	tristate "Richtek RT5190A PMIC"
 	depends on I2C
drivers/regulator/Makefile +1 -0
index c0bc7a0f4e67..709384ae0a0c 100644
@@ -145,6 +145,7 @@ obj-$(CONFIG_REGULATOR_RT4803)	+= rt4803.o
 obj-$(CONFIG_REGULATOR_RT4831)	+= rt4831-regulator.o
 obj-$(CONFIG_REGULATOR_RT5033)	+= rt5033-regulator.o
 obj-$(CONFIG_REGULATOR_RT5120)	+= rt5120-regulator.o
+obj-$(CONFIG_REGULATOR_RT5133)	+= rt5133-regulator.o
 obj-$(CONFIG_REGULATOR_RT5190A) += rt5190a-regulator.o
 obj-$(CONFIG_REGULATOR_RT5739)	+= rt5739.o
 obj-$(CONFIG_REGULATOR_RT5759)	+= rt5759-regulator.o
drivers/regulator/rt5133-regulator.c new file +636 -0

636 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 3 lines · On Thu, Jul 17, 2025 at 04:16:01PM +0800, [email protected] wrote:

From: Jeff Chang <[email protected]>

RT5133 is an intefrated chip. It includes 8 LDOs and 3 GPOs that

Integrated?

Quoted 7 lines
---
 .../bindings/regulator/richtek,rt5133.yaml    | 164 +++++
 drivers/regulator/Kconfig                     |  13 +
 drivers/regulator/Makefile                    |   1 +
 drivers/regulator/rt5133-regulator.c          | 636 ++++++++++++++++++
 4 files changed, 814 insertions(+)

The DT bindings should be sent as a separate patch copied to the DT maintainers, this should be a small series.

Documentation/devicetree/bindings/regulator/richtek,rt5133.yaml line 67

Quoted 8 lines
Documentation/devicetree/bindings/regulator/richtek,rt5133.yaml new file +8 -0
+  soft-start-time-sel:
+    type: object
+    description: |
+      soft-start time of LDO
+        0: 1ms
+        1: 2ms
+        2: 4ms
+        3: 8ms

Implement the set_soft_start() operation and use standard bindings for this.

Documentation/devicetree/bindings/regulator/richtek,rt5133.yaml line 72

Quoted 4 lines
Documentation/devicetree/bindings/regulator/richtek,rt5133.yaml new file +4 -0
+  rt5133-ldo1-supply:
+    description: |
+      Only for LDO7 LDO8, pvin7 and pvin8 reference design are RT5133 LDO1.
+      If not connect to LDO1 vout, this property for pvin7 and pvin8 is necessary.

You should probably just define all the supplies for all the regulators, then if some of them are supplied from other regulators on the device that can be represented naturally.

drivers/regulator/rt5133-regulator.c line 6

Quoted 8 lines

+++ b/drivers/regulator/rt5133-regulator.c

drivers/regulator/rt5133-regulator.c new file +6 -0
@@ -0,0 +1,636 @@
+// SPDX-License-Identifier: GPL-4.0
+/*
+ * Copyright (C) 2025 Richtek Technology Corp.
+ *
+ * Author: ChiYuan Huang <[email protected]>
+ */

What's with the GPL-4.0 license? The kernel is GPL 2.0 plus extras, and AFAIK there is no GPL-4.0.

Please also make the entire comment a C++ one so things look more intentional.

drivers/regulator/rt5133-regulator.c line 26

Quoted 7 lines
drivers/regulator/rt5133-regulator.c new file +7 -0
+static bool dbg_log_en;
+module_param(dbg_log_en, bool, 0644);
+#define rt_dbg(dev, fmt, ...)	\
+	do { \
+		if (dbg_log_en) \
+			dev_info(dev, "%s " fmt, __func__, ##__VA_ARGS__); \
+	} while (0)

Just use the standard dev_dbg().

drivers/regulator/rt5133-regulator.c line 27

Quoted 1 line
drivers/regulator/rt5133-regulator.c new file +1 -0
+#define RT5133_DRV_VERSION		"1.0.2_MTK"

We normally don't version drivers, the versions don't get updated by people doing normal kernel work.

Quoted 9 lines
drivers/regulator/rt5133-regulator.c new file +9 -0
+static irqreturn_t rt5133_intr_handler(int irq_number, void *data)
+{
+	struct rt5133_priv *priv = data;
+	u32 intr_evts = 0, handle_evts;
+	int i, ret;
+
+	ret = regmap_bulk_read(priv->regmap, RT5133_REG_BASE_EVT, &intr_evts,
+			       RT5133_INTR_BYTE_NR);
+	if (ret)

drivers/regulator/rt5133-regulator.c line 353

Quoted 10 lines
drivers/regulator/rt5133-regulator.c new file +10 -0
+		goto out_intr_handler;
+
+	handle_evts = intr_evts & RT5133_BASE_EVT_MASK;
+	/*
+	 * VREF_EVT is a special case, if base off
+	 * this event will also be trigger. Skip it
+	 */
+	if (handle_evts & ~RT5133_VREF_EVT_MASK)
+		dev_info(priv->dev, "base event occurred [0x%02x]\n",
+			 handle_evts);

This logging might get noisy. Also if there are no events the handler should return IRQ_NONE so genirq can handle things if they go wrong (same for the read error above).

drivers/regulator/rt5133-regulator.c line 501

Quoted 5 lines
drivers/regulator/rt5133-regulator.c new file +5 -0
+static const struct regmap_config rt5133_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = RT5133_REG_LDO8_CTRL4,
+};

May as well enable a cache for the non-volatile registers?

drivers/regulator/rt5133-regulator.c line 548

Quoted 7 lines
drivers/regulator/rt5133-regulator.c new file +7 -0
+static int rt5133_probe(struct i2c_client *i2c)
+{
+	struct rt5133_priv *priv;
+	struct regulator_config config = {0};
+	int i, ret;
+
+	dev_info(&i2c->dev, "%s start(%s)\n", __func__, RT5133_DRV_VERSION);

Remove all these dev_info() logs during normal operation, logging the chip revision if you read one would make sense but just "I'm here" logs aren't so useful.

drivers/regulator/rt5133-regulator.c line 601

Quoted 7 lines
drivers/regulator/rt5133-regulator.c new file +7 -0
+	priv->gc.label = dev_name(&i2c->dev);
+	priv->gc.parent = &i2c->dev;
+	priv->gc.base = -1;
+	priv->gc.ngpio = RT5133_GPIO_NR;
+	priv->gc.set = rt5133_gpio_set;
+	priv->gc.get = rt5133_gpio_get;
+	priv->gc.direction_output = rt5133_gpio_direction_output;

These should be _cansleep operations given that the device is controlled via I2C.

#2 lore raw
In reply to [email protected]
Quoted 11 lines · On 17/07/2025 10:16, [email protected] wrote:

From: Jeff Chang <[email protected]>

RT5133 is an intefrated chip. It includes 8 LDOs and 3 GPOs that can be used to drive output high/low purpose. The dependency of the GPO block is internally LDO1 Voltage. If LDO1 voltage output disabled, GPO cannot be used to drive output high. It need to pay more attention on the usage.

---
 .../bindings/regulator/richtek,rt5133.yaml    | 164 +++++

Please run scripts/checkpatch.pl on the patches and fix reported warnings. After that, run also 'scripts/checkpatch.pl --strict' on the patches and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.

<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.

You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.

Please kindly resend and include all necessary To/Cc entries. </form letter>

...

drivers/regulator/rt5133-regulator.c line 627

Quoted 11 lines
drivers/regulator/rt5133-regulator.c new file +11 -0
+
+static const struct of_device_id __maybe_unused rt5133_ofid_tbls[] = {
+	{ .compatible = "richtek,rt5133", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, rt5133_ofid_tbls);
+
+static struct i2c_driver rt5133_driver = {
+	.driver = {
+		.name = "rt5133",
+		.owner = THIS_MODULE,

That's old template (like 12 yo one) you are using.

Maybe below will be helpful to find more of such artifacts:

Please run standard kernel tools for static analysis, like coccinelle, smatch and sparse, and fix reported warnings. Also please check for warnings when building with W=1. Most of these commands (checks or W=1 build) can build specific targets, like some directory, to narrow the scope to only your code. The code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.

Best regards,
Krzysztof