xref: /linux/drivers/regulator/renesas-usb-vbus-regulator.c (revision d30c1683aaecb93d2ab95685dc4300a33d3cea7a)
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/of.h>
11 #include <linux/platform_device.h>
12 #include <linux/regmap.h>
13 #include <linux/regulator/driver.h>
14 
15 static const struct regulator_ops rzg2l_usb_vbus_reg_ops = {
16 	.enable     = regulator_enable_regmap,
17 	.disable    = regulator_disable_regmap,
18 	.is_enabled = regulator_is_enabled_regmap,
19 };
20 
21 static const struct regulator_desc rzg2l_usb_vbus_rdesc = {
22 	.name = "vbus",
23 	.of_match = of_match_ptr("regulator-vbus"),
24 	.ops = &rzg2l_usb_vbus_reg_ops,
25 	.type = REGULATOR_VOLTAGE,
26 	.owner = THIS_MODULE,
27 	.enable_reg  = 0,
28 	.enable_mask = BIT(0),
29 	.enable_is_inverted = true,
30 	.fixed_uV	= 5000000,
31 	.n_voltages	= 1,
32 };
33 
34 static int rzg2l_usb_vbus_regulator_probe(struct platform_device *pdev)
35 {
36 	struct regulator_config config = { };
37 	struct device *dev = &pdev->dev;
38 	struct regulator_dev *rdev;
39 
40 	config.regmap = dev_get_regmap(dev->parent, NULL);
41 	if (!config.regmap)
42 		return dev_err_probe(dev, -ENOENT, "Failed to get regmap\n");
43 
44 	config.dev = dev;
45 	config.of_node = of_get_child_by_name(dev->parent->of_node, "regulator-vbus");
46 	if (!config.of_node)
47 		return dev_err_probe(dev, -ENODEV, "regulator node not found\n");
48 
49 	rdev = devm_regulator_register(dev, &rzg2l_usb_vbus_rdesc, &config);
50 	of_node_put(config.of_node);
51 	if (IS_ERR(rdev))
52 		return dev_err_probe(dev, PTR_ERR(rdev),
53 				     "not able to register vbus regulator\n");
54 
55 	return 0;
56 }
57 
58 static struct platform_driver rzg2l_usb_vbus_regulator_driver = {
59 	.probe = rzg2l_usb_vbus_regulator_probe,
60 	.driver	= {
61 		.name = "rzg2l-usb-vbus-regulator",
62 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
63 	},
64 };
65 module_platform_driver(rzg2l_usb_vbus_regulator_driver);
66 
67 MODULE_AUTHOR("Biju Das <biju.das.jz@bp.renesas.com>");
68 MODULE_DESCRIPTION("Renesas RZ/G2L USB Vbus Regulator Driver");
69 MODULE_LICENSE("GPL");
70