dummy.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * dummy.c
  4. *
  5. * Copyright 2010 Wolfson Microelectronics PLC.
  6. *
  7. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  8. *
  9. * This is useful for systems with mixed controllable and
  10. * non-controllable regulators, as well as for allowing testing on
  11. * systems with no controllable regulators.
  12. */
  13. #include <linux/err.h>
  14. #include <linux/export.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/regulator/driver.h>
  17. #include <linux/regulator/machine.h>
  18. #include "dummy.h"
  19. struct regulator_dev *dummy_regulator_rdev;
  20. static const struct regulator_init_data dummy_initdata = {
  21. .constraints = {
  22. .always_on = 1,
  23. },
  24. };
  25. static const struct regulator_ops dummy_ops;
  26. static const struct regulator_desc dummy_desc = {
  27. .name = "regulator-dummy",
  28. .id = -1,
  29. .type = REGULATOR_VOLTAGE,
  30. .owner = THIS_MODULE,
  31. .ops = &dummy_ops,
  32. };
  33. static int dummy_regulator_probe(struct platform_device *pdev)
  34. {
  35. struct regulator_config config = { };
  36. int ret;
  37. config.dev = &pdev->dev;
  38. config.init_data = &dummy_initdata;
  39. dummy_regulator_rdev = devm_regulator_register(&pdev->dev, &dummy_desc,
  40. &config);
  41. if (IS_ERR(dummy_regulator_rdev)) {
  42. ret = PTR_ERR(dummy_regulator_rdev);
  43. pr_err("Failed to register regulator: %d\n", ret);
  44. return ret;
  45. }
  46. return 0;
  47. }
  48. static struct platform_driver dummy_regulator_driver = {
  49. .probe = dummy_regulator_probe,
  50. .driver = {
  51. .name = "reg-dummy",
  52. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  53. },
  54. };
  55. static struct platform_device *dummy_pdev;
  56. void __init regulator_dummy_init(void)
  57. {
  58. int ret;
  59. dummy_pdev = platform_device_alloc("reg-dummy", -1);
  60. if (!dummy_pdev) {
  61. pr_err("Failed to allocate dummy regulator device\n");
  62. return;
  63. }
  64. ret = platform_device_add(dummy_pdev);
  65. if (ret != 0) {
  66. pr_err("Failed to register dummy regulator device: %d\n", ret);
  67. platform_device_put(dummy_pdev);
  68. return;
  69. }
  70. ret = platform_driver_register(&dummy_regulator_driver);
  71. if (ret != 0) {
  72. pr_err("Failed to register dummy regulator driver: %d\n", ret);
  73. platform_device_unregister(dummy_pdev);
  74. }
  75. }