regulator.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * arch/arm/mach-u300/regulator.c
  3. *
  4. * Copyright (C) 2009 ST-Ericsson AB
  5. * License terms: GNU General Public License (GPL) version 2
  6. * Handle board-bound regulators and board power not related
  7. * to any devices.
  8. * Author: Linus Walleij <linus.walleij@stericsson.com>
  9. */
  10. #include <linux/device.h>
  11. #include <linux/signal.h>
  12. #include <linux/err.h>
  13. #include <linux/of.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/regulator/machine.h>
  17. #include <linux/regulator/consumer.h>
  18. #include <linux/mfd/syscon.h>
  19. #include <linux/regmap.h>
  20. /* Power Management Control 16bit (R/W) */
  21. #define U300_SYSCON_PMCR (0x50)
  22. #define U300_SYSCON_PMCR_DCON_ENABLE (0x0002)
  23. #define U300_SYSCON_PMCR_PWR_MGNT_ENABLE (0x0001)
  24. /*
  25. * Regulators that power the board and chip and which are
  26. * not copuled to specific drivers are hogged in these
  27. * instances.
  28. */
  29. static struct regulator *main_power_15;
  30. /*
  31. * This function is used from pm.h to shut down the system by
  32. * resetting all regulators in turn and then disable regulator
  33. * LDO D (main power).
  34. */
  35. void u300_pm_poweroff(void)
  36. {
  37. sigset_t old, all;
  38. sigfillset(&all);
  39. if (!sigprocmask(SIG_BLOCK, &all, &old)) {
  40. /* Disable LDO D to shut down the system */
  41. if (main_power_15)
  42. regulator_disable(main_power_15);
  43. else
  44. pr_err("regulator not available to shut down system\n");
  45. (void) sigprocmask(SIG_SETMASK, &old, NULL);
  46. }
  47. return;
  48. }
  49. /*
  50. * Hog the regulators needed to power up the board.
  51. */
  52. static int __init __u300_init_boardpower(struct platform_device *pdev)
  53. {
  54. struct device_node *np = pdev->dev.of_node;
  55. struct device_node *syscon_np;
  56. struct regmap *regmap;
  57. int err;
  58. pr_info("U300: setting up board power\n");
  59. syscon_np = of_parse_phandle(np, "syscon", 0);
  60. if (!syscon_np) {
  61. pr_crit("U300: no syscon node\n");
  62. return -ENODEV;
  63. }
  64. regmap = syscon_node_to_regmap(syscon_np);
  65. if (IS_ERR(regmap)) {
  66. pr_crit("U300: could not locate syscon regmap\n");
  67. return PTR_ERR(regmap);
  68. }
  69. main_power_15 = regulator_get(&pdev->dev, "vana15");
  70. if (IS_ERR(main_power_15)) {
  71. pr_err("could not get vana15");
  72. return PTR_ERR(main_power_15);
  73. }
  74. err = regulator_enable(main_power_15);
  75. if (err) {
  76. pr_err("could not enable vana15\n");
  77. return err;
  78. }
  79. /*
  80. * On U300 a special system controller register pulls up the DC
  81. * until the vana15 (LDO D) regulator comes up. At this point, all
  82. * regulators are set and we do not need power control via
  83. * DC ON anymore. This function will likely be moved whenever
  84. * the rest of the U300 power management is implemented.
  85. */
  86. pr_info("U300: disable system controller pull-up\n");
  87. regmap_update_bits(regmap, U300_SYSCON_PMCR,
  88. U300_SYSCON_PMCR_DCON_ENABLE, 0);
  89. /* Register globally exported PM poweroff hook */
  90. pm_power_off = u300_pm_poweroff;
  91. return 0;
  92. }
  93. static int __init s365_board_probe(struct platform_device *pdev)
  94. {
  95. return __u300_init_boardpower(pdev);
  96. }
  97. static const struct of_device_id s365_board_match[] = {
  98. { .compatible = "stericsson,s365" },
  99. {},
  100. };
  101. static struct platform_driver s365_board_driver = {
  102. .driver = {
  103. .name = "s365-board",
  104. .of_match_table = s365_board_match,
  105. },
  106. };
  107. /*
  108. * So at module init time we hog the regulator!
  109. */
  110. static int __init u300_init_boardpower(void)
  111. {
  112. return platform_driver_probe(&s365_board_driver,
  113. s365_board_probe);
  114. }
  115. device_initcall(u300_init_boardpower);