Skip to content

Commit 84fbd61

Browse files
bijudasbroonie
authored andcommitted
regulator: Add Renesas RZ/G2L USB VBUS regulator driver
As per the RZ/G2L HW manual, VBUSEN can be controlled by the VBOUT bit of the VBUS Control Register. This register is mapped in the reset framework. The reset driver expose this register as regmap and instantiates this driver. The consumer will use the regulator API to control the VBOUT bit as the control need to be done in the atomic context. Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> Link: https://patch.msgid.link/20240616105402.45211-5-biju.das.jz@bp.renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1cb7d29 commit 84fbd61

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

drivers/regulator/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,15 @@ config REGULATOR_UNIPHIER
16341634
help
16351635
Support for regulators implemented on Socionext UniPhier SoCs.
16361636

1637+
config REGULATOR_RZG2L_VBCTRL
1638+
tristate "Renesas RZ/G2L USB VBUS regulator driver"
1639+
depends on ARCH_RZG2L || COMPILE_TEST
1640+
depends on OF
1641+
select REGMAP_MMIO
1642+
default ARCH_RZG2L
1643+
help
1644+
Support for VBUS regulators implemented on Renesas RZ/G2L SoCs.
1645+
16371646
config REGULATOR_VCTRL
16381647
tristate "Voltage controlled regulators"
16391648
depends on OF

drivers/regulator/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o
189189
obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o
190190
obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
191191
obj-$(CONFIG_REGULATOR_UNIPHIER) += uniphier-regulator.o
192+
obj-$(CONFIG_REGULATOR_RZG2L_VBCTRL) += renesas-usb-vbus-regulator.o
192193
obj-$(CONFIG_REGULATOR_VCTRL) += vctrl-regulator.o
193194
obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress-regulator.o
194195
obj-$(CONFIG_REGULATOR_VQMMC_IPQ4019) += vqmmc-ipq4019-regulator.o
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// Renesas USB VBUS output regulator driver
4+
//
5+
// Copyright (C) 2024 Renesas Electronics Corporation
6+
//
7+
8+
#include <linux/module.h>
9+
#include <linux/err.h>
10+
#include <linux/kernel.h>
11+
#include <linux/of.h>
12+
#include <linux/platform_device.h>
13+
#include <linux/regmap.h>
14+
#include <linux/regulator/driver.h>
15+
#include <linux/regulator/of_regulator.h>
16+
17+
static const struct regulator_ops rzg2l_usb_vbus_reg_ops = {
18+
.enable = regulator_enable_regmap,
19+
.disable = regulator_disable_regmap,
20+
.is_enabled = regulator_is_enabled_regmap,
21+
};
22+
23+
static const struct regulator_desc rzg2l_usb_vbus_rdesc = {
24+
.name = "vbus",
25+
.of_match = of_match_ptr("regulator-vbus"),
26+
.ops = &rzg2l_usb_vbus_reg_ops,
27+
.type = REGULATOR_VOLTAGE,
28+
.owner = THIS_MODULE,
29+
.enable_reg = 0,
30+
.enable_mask = BIT(0),
31+
.enable_is_inverted = true,
32+
.fixed_uV = 5000000,
33+
.n_voltages = 1,
34+
};
35+
36+
static int rzg2l_usb_vbus_regulator_probe(struct platform_device *pdev)
37+
{
38+
struct regulator_config config = { };
39+
struct device *dev = &pdev->dev;
40+
struct regulator_dev *rdev;
41+
42+
config.regmap = dev_get_regmap(dev->parent, NULL);
43+
if (!config.regmap)
44+
return dev_err_probe(dev, -ENOENT, "Failed to get regmap\n");
45+
46+
config.dev = dev;
47+
config.of_node = of_get_child_by_name(dev->parent->of_node, "regulator-vbus");
48+
if (!config.of_node)
49+
return dev_err_probe(dev, -ENODEV, "regulator node not found\n");
50+
51+
rdev = devm_regulator_register(dev, &rzg2l_usb_vbus_rdesc, &config);
52+
if (IS_ERR(rdev)) {
53+
of_node_put(config.of_node);
54+
return dev_err_probe(dev, PTR_ERR(rdev),
55+
"not able to register vbus regulator\n");
56+
}
57+
58+
of_node_put(config.of_node);
59+
60+
return 0;
61+
}
62+
63+
static struct platform_driver rzg2l_usb_vbus_regulator_driver = {
64+
.probe = rzg2l_usb_vbus_regulator_probe,
65+
.driver = {
66+
.name = "rzg2l-usb-vbus-regulator",
67+
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
68+
},
69+
};
70+
module_platform_driver(rzg2l_usb_vbus_regulator_driver);
71+
72+
MODULE_AUTHOR("Biju Das <biju.das.jz@bp.renesas.com>");
73+
MODULE_DESCRIPTION("Renesas RZ/G2L USB Vbus Regulator Driver");
74+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)