dummy.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * dummy.c
  3. *
  4. * Copyright 2010 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  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. static struct regulator_ops dummy_ops;
  26. static struct regulator_desc dummy_desc = {
  27. .name = "dummy",
  28. .id = -1,
  29. .type = REGULATOR_VOLTAGE,
  30. .owner = THIS_MODULE,
  31. .ops = &dummy_ops,
  32. };
  33. static int __devinit dummy_regulator_probe(struct platform_device *pdev)
  34. {
  35. int ret;
  36. dummy_regulator_rdev = regulator_register(&dummy_desc, NULL,
  37. &dummy_initdata, NULL, NULL);
  38. if (IS_ERR(dummy_regulator_rdev)) {
  39. ret = PTR_ERR(dummy_regulator_rdev);
  40. pr_err("Failed to register regulator: %d\n", ret);
  41. return ret;
  42. }
  43. return 0;
  44. }
  45. static struct platform_driver dummy_regulator_driver = {
  46. .probe = dummy_regulator_probe,
  47. .driver = {
  48. .name = "reg-dummy",
  49. .owner = THIS_MODULE,
  50. },
  51. };
  52. static struct platform_device *dummy_pdev;
  53. void __init regulator_dummy_init(void)
  54. {
  55. int ret;
  56. dummy_pdev = platform_device_alloc("reg-dummy", -1);
  57. if (!dummy_pdev) {
  58. pr_err("Failed to allocate dummy regulator device\n");
  59. return;
  60. }
  61. ret = platform_device_add(dummy_pdev);
  62. if (ret != 0) {
  63. pr_err("Failed to register dummy regulator device: %d\n", ret);
  64. platform_device_put(dummy_pdev);
  65. return;
  66. }
  67. ret = platform_driver_register(&dummy_regulator_driver);
  68. if (ret != 0) {
  69. pr_err("Failed to register dummy regulator driver: %d\n", ret);
  70. platform_device_unregister(dummy_pdev);
  71. }
  72. }