dummy.c 2.2 KB

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