[PATCH 06/11] regulator: renesas-usb-vbus-regulator: Introduce helper for regulator registration

From: Biju

Date: Fri Jun 12 2026 - 10:32:04 EST


From: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>

Extract the regulator node lookup and registration logic from
rzg2l_usb_vbus_regulator_probe() into a new helper function
rzg2l_usb_vbus_regulator_register(), which takes the parent device node,
regulator name, descriptor, and config as parameters.

This refactoring avoids code duplication in a follow-up patch that adds
support for the RZ/G3L SoC, which requires registering a second VBUS
regulator for its additional OTG port.

Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
---
.../regulator/renesas-usb-vbus-regulator.c | 32 ++++++++++++-------
1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/regulator/renesas-usb-vbus-regulator.c b/drivers/regulator/renesas-usb-vbus-regulator.c
index 9ba791bd72ec..511631a788c2 100644
--- a/drivers/regulator/renesas-usb-vbus-regulator.c
+++ b/drivers/regulator/renesas-usb-vbus-regulator.c
@@ -31,28 +31,38 @@ static const struct regulator_desc rzg2l_usb_vbus_rdesc = {
.n_voltages = 1,
};

+static int rzg2l_usb_vbus_regulator_register(struct device_node *np,
+ const char *name,
+ const struct regulator_desc *desc,
+ struct regulator_config *config)
+{
+ struct regulator_dev *rdev;
+
+ config->of_node = of_get_child_by_name(np, name);
+ if (!config->of_node)
+ return dev_err_probe(config->dev, -ENODEV, "regulator node %s not found\n", name);
+
+ rdev = devm_regulator_register(config->dev, desc, config);
+ of_node_put(config->of_node);
+ if (IS_ERR(rdev))
+ return dev_err_probe(config->dev, PTR_ERR(rdev), "not able to register %s\n", name);
+
+ return 0;
+}
+
static int rzg2l_usb_vbus_regulator_probe(struct platform_device *pdev)
{
struct regulator_config config = { };
struct device *dev = &pdev->dev;
- struct regulator_dev *rdev;

config.regmap = dev_get_regmap(dev->parent, NULL);
if (!config.regmap)
return dev_err_probe(dev, -ENOENT, "Failed to get regmap\n");

config.dev = dev;
- config.of_node = of_get_child_by_name(dev->parent->of_node, "regulator-vbus");
- if (!config.of_node)
- return dev_err_probe(dev, -ENODEV, "regulator node not found\n");

- rdev = devm_regulator_register(dev, &rzg2l_usb_vbus_rdesc, &config);
- of_node_put(config.of_node);
- if (IS_ERR(rdev))
- return dev_err_probe(dev, PTR_ERR(rdev),
- "not able to register vbus regulator\n");
-
- return 0;
+ return rzg2l_usb_vbus_regulator_register(dev->parent->of_node, "regulator-vbus",
+ &rzg2l_usb_vbus_rdesc, &config);
}

static struct platform_driver rzg2l_usb_vbus_regulator_driver = {
--
2.43.0