regulator.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /* Those are just for writing in syscon */
  19. #include <linux/of_address.h>
  20. #include <linux/io.h>
  21. /* Power Management Control 16bit (R/W) */
  22. #define U300_SYSCON_PMCR (0x50)
  23. #define U300_SYSCON_PMCR_DCON_ENABLE (0x0002)
  24. #define U300_SYSCON_PMCR_PWR_MGNT_ENABLE (0x0001)
  25. /*
  26. * Regulators that power the board and chip and which are
  27. * not copuled to specific drivers are hogged in these
  28. * instances.
  29. */
  30. static struct regulator *main_power_15;
  31. /*
  32. * This function is used from pm.h to shut down the system by
  33. * resetting all regulators in turn and then disable regulator
  34. * LDO D (main power).
  35. */
  36. void u300_pm_poweroff(void)
  37. {
  38. sigset_t old, all;
  39. sigfillset(&all);
  40. if (!sigprocmask(SIG_BLOCK, &all, &old)) {
  41. /* Disable LDO D to shut down the system */
  42. if (main_power_15)
  43. regulator_disable(main_power_15);
  44. else
  45. pr_err("regulator not available to shut down system\n");
  46. (void) sigprocmask(SIG_SETMASK, &old, NULL);
  47. }
  48. return;
  49. }
  50. /*
  51. * Hog the regulators needed to power up the board.
  52. */
  53. static int __init __u300_init_boardpower(struct platform_device *pdev)
  54. {
  55. struct device_node *np = pdev->dev.of_node;
  56. struct device_node *syscon_np;
  57. static void __iomem *syscon_base;
  58. int err;
  59. u32 val;
  60. pr_info("U300: setting up board power\n");
  61. syscon_np = of_parse_phandle(np, "syscon", 0);
  62. if (!syscon_np) {
  63. pr_crit("U300: no syscon node\n");
  64. return -ENODEV;
  65. }
  66. syscon_base = of_iomap(syscon_np, 0);
  67. if (!syscon_base) {
  68. pr_crit("U300: could not remap syscon\n");
  69. return -ENODEV;
  70. }
  71. main_power_15 = regulator_get(&pdev->dev, "vana15");
  72. if (IS_ERR(main_power_15)) {
  73. pr_err("could not get vana15");
  74. return PTR_ERR(main_power_15);
  75. }
  76. err = regulator_enable(main_power_15);
  77. if (err) {
  78. pr_err("could not enable vana15\n");
  79. return err;
  80. }
  81. /*
  82. * On U300 a special system controller register pulls up the DC
  83. * until the vana15 (LDO D) regulator comes up. At this point, all
  84. * regulators are set and we do not need power control via
  85. * DC ON anymore. This function will likely be moved whenever
  86. * the rest of the U300 power management is implemented.
  87. */
  88. pr_info("U300: disable system controller pull-up\n");
  89. val = readw(syscon_base + U300_SYSCON_PMCR);
  90. val &= ~U300_SYSCON_PMCR_DCON_ENABLE;
  91. writew(val, syscon_base + U300_SYSCON_PMCR);
  92. /* Register globally exported PM poweroff hook */
  93. pm_power_off = u300_pm_poweroff;
  94. return 0;
  95. }
  96. static int __init s365_board_probe(struct platform_device *pdev)
  97. {
  98. return __u300_init_boardpower(pdev);
  99. }
  100. static const struct of_device_id s365_board_match[] = {
  101. { .compatible = "stericsson,s365" },
  102. {},
  103. };
  104. static struct platform_driver s365_board_driver = {
  105. .driver = {
  106. .name = "s365-board",
  107. .owner = THIS_MODULE,
  108. .of_match_table = s365_board_match,
  109. },
  110. };
  111. /*
  112. * So at module init time we hog the regulator!
  113. */
  114. static int __init u300_init_boardpower(void)
  115. {
  116. return platform_driver_probe(&s365_board_driver,
  117. s365_board_probe);
  118. }
  119. device_initcall(u300_init_boardpower);