regulator.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/regulator/consumer.h>
  14. /* Those are just for writing in syscon */
  15. #include <linux/io.h>
  16. #include <mach/hardware.h>
  17. #include <mach/syscon.h>
  18. /*
  19. * Regulators that power the board and chip and which are
  20. * not copuled to specific drivers are hogged in these
  21. * instances.
  22. */
  23. static struct regulator *main_power_15;
  24. /*
  25. * This function is used from pm.h to shut down the system by
  26. * resetting all regulators in turn and then disable regulator
  27. * LDO D (main power).
  28. */
  29. void u300_pm_poweroff(void)
  30. {
  31. sigset_t old, all;
  32. sigfillset(&all);
  33. if (!sigprocmask(SIG_BLOCK, &all, &old)) {
  34. /* Disable LDO D to shut down the system */
  35. if (main_power_15)
  36. regulator_disable(main_power_15);
  37. else
  38. pr_err("regulator not available to shut down system\n");
  39. (void) sigprocmask(SIG_SETMASK, &old, NULL);
  40. }
  41. return;
  42. }
  43. /*
  44. * Hog the regulators needed to power up the board.
  45. */
  46. static int __init u300_init_boardpower(void)
  47. {
  48. int err;
  49. u32 val;
  50. pr_info("U300: setting up board power\n");
  51. main_power_15 = regulator_get(NULL, "vana15");
  52. if (IS_ERR(main_power_15)) {
  53. pr_err("could not get vana15");
  54. return PTR_ERR(main_power_15);
  55. }
  56. err = regulator_enable(main_power_15);
  57. if (err) {
  58. pr_err("could not enable vana15\n");
  59. return err;
  60. }
  61. /*
  62. * On U300 a special system controller register pulls up the DC
  63. * until the vana15 (LDO D) regulator comes up. At this point, all
  64. * regulators are set and we do not need power control via
  65. * DC ON anymore. This function will likely be moved whenever
  66. * the rest of the U300 power management is implemented.
  67. */
  68. pr_info("U300: disable system controller pull-up\n");
  69. val = readw(U300_SYSCON_VBASE + U300_SYSCON_PMCR);
  70. val &= ~U300_SYSCON_PMCR_DCON_ENABLE;
  71. writew(val, U300_SYSCON_VBASE + U300_SYSCON_PMCR);
  72. /* Register globally exported PM poweroff hook */
  73. pm_power_off = u300_pm_poweroff;
  74. return 0;
  75. }
  76. /*
  77. * So at module init time we hog the regulator!
  78. */
  79. module_init(u300_init_boardpower);