renesas-usb-vbus-regulator.c 1.9 KB

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