dummy.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 struct regulator_init_data dummy_initdata = {
  21. .constraints = {
  22. .always_on = 1,
  23. },
  24. };
  25. static 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 = regulator_register(&dummy_desc, &config);
  40. if (IS_ERR(dummy_regulator_rdev)) {
  41. ret = PTR_ERR(dummy_regulator_rdev);
  42. pr_err("Failed to register regulator: %d\n", ret);
  43. return ret;
  44. }
  45. return 0;
  46. }
  47. static struct platform_driver dummy_regulator_driver = {
  48. .probe = dummy_regulator_probe,
  49. .driver = {
  50. .name = "reg-dummy",
  51. },
  52. };
  53. static struct platform_device *dummy_pdev;
  54. void __init regulator_dummy_init(void)
  55. {
  56. int ret;
  57. dummy_pdev = platform_device_alloc("reg-dummy", -1);
  58. if (!dummy_pdev) {
  59. pr_err("Failed to allocate dummy regulator device\n");
  60. return;
  61. }
  62. ret = platform_device_add(dummy_pdev);
  63. if (ret != 0) {
  64. pr_err("Failed to register dummy regulator device: %d\n", ret);
  65. platform_device_put(dummy_pdev);
  66. return;
  67. }
  68. ret = platform_driver_register(&dummy_regulator_driver);
  69. if (ret != 0) {
  70. pr_err("Failed to register dummy regulator driver: %d\n", ret);
  71. platform_device_unregister(dummy_pdev);
  72. }
  73. }