| 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: dev->parent, NULL); |
| 43 | if (!config.regmap) |
| 44 | return dev_err_probe(dev, err: -ENOENT, fmt: "Failed to get regmap\n" ); |
| 45 | |
| 46 | config.dev = dev; |
| 47 | config.of_node = of_get_child_by_name(node: dev->parent->of_node, name: "regulator-vbus" ); |
| 48 | if (!config.of_node) |
| 49 | return dev_err_probe(dev, err: -ENODEV, fmt: "regulator node not found\n" ); |
| 50 | |
| 51 | rdev = devm_regulator_register(dev, regulator_desc: &rzg2l_usb_vbus_rdesc, config: &config); |
| 52 | of_node_put(node: config.of_node); |
| 53 | if (IS_ERR(ptr: rdev)) |
| 54 | return dev_err_probe(dev, err: PTR_ERR(ptr: rdev), |
| 55 | fmt: "not able to register vbus regulator\n" ); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static struct platform_driver rzg2l_usb_vbus_regulator_driver = { |
| 61 | .probe = rzg2l_usb_vbus_regulator_probe, |
| 62 | .driver = { |
| 63 | .name = "rzg2l-usb-vbus-regulator" , |
| 64 | .probe_type = PROBE_PREFER_ASYNCHRONOUS, |
| 65 | }, |
| 66 | }; |
| 67 | module_platform_driver(rzg2l_usb_vbus_regulator_driver); |
| 68 | |
| 69 | MODULE_AUTHOR("Biju Das <biju.das.jz@bp.renesas.com>" ); |
| 70 | MODULE_DESCRIPTION("Renesas RZ/G2L USB Vbus Regulator Driver" ); |
| 71 | MODULE_LICENSE("GPL" ); |
| 72 | |