pm.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * DaVinci Power Management Routines
  3. *
  4. * Copyright (C) 2009 Texas Instruments, Inc. http://www.ti.com/
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/pm.h>
  11. #include <linux/suspend.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/clk.h>
  15. #include <linux/spinlock.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/delay.h>
  18. #include <asm/io.h>
  19. #include <mach/common.h>
  20. #include <mach/da8xx.h>
  21. #include <mach/mux.h>
  22. #include <mach/pm.h>
  23. #include "clock.h"
  24. #include "psc.h"
  25. #include "sram.h"
  26. #define DA850_PLL1_BASE 0x01e1a000
  27. #define DEEPSLEEP_SLEEPCOUNT_MASK 0xFFFF
  28. #define DEEPSLEEP_SLEEPCOUNT 128
  29. static void (*davinci_sram_suspend) (struct davinci_pm_config *);
  30. static struct davinci_pm_config pm_config = {
  31. .sleepcount = DEEPSLEEP_SLEEPCOUNT,
  32. .ddrpsc_num = DA8XX_LPSC1_EMIF3C,
  33. };
  34. static void davinci_sram_push(void *dest, void *src, unsigned int size)
  35. {
  36. memcpy(dest, src, size);
  37. flush_icache_range((unsigned long)dest, (unsigned long)(dest + size));
  38. }
  39. static void davinci_pm_suspend(void)
  40. {
  41. unsigned val;
  42. if (pm_config.cpupll_reg_base != pm_config.ddrpll_reg_base) {
  43. /* Switch CPU PLL to bypass mode */
  44. val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
  45. val &= ~(PLLCTL_PLLENSRC | PLLCTL_PLLEN);
  46. __raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
  47. udelay(PLL_BYPASS_TIME);
  48. /* Powerdown CPU PLL */
  49. val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
  50. val |= PLLCTL_PLLPWRDN;
  51. __raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
  52. }
  53. /* Configure sleep count in deep sleep register */
  54. val = __raw_readl(pm_config.deepsleep_reg);
  55. val &= ~DEEPSLEEP_SLEEPCOUNT_MASK,
  56. val |= pm_config.sleepcount;
  57. __raw_writel(val, pm_config.deepsleep_reg);
  58. /* System goes to sleep in this call */
  59. davinci_sram_suspend(&pm_config);
  60. if (pm_config.cpupll_reg_base != pm_config.ddrpll_reg_base) {
  61. /* put CPU PLL in reset */
  62. val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
  63. val &= ~PLLCTL_PLLRST;
  64. __raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
  65. /* put CPU PLL in power down */
  66. val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
  67. val &= ~PLLCTL_PLLPWRDN;
  68. __raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
  69. /* wait for CPU PLL reset */
  70. udelay(PLL_RESET_TIME);
  71. /* bring CPU PLL out of reset */
  72. val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
  73. val |= PLLCTL_PLLRST;
  74. __raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
  75. /* Wait for CPU PLL to lock */
  76. udelay(PLL_LOCK_TIME);
  77. /* Remove CPU PLL from bypass mode */
  78. val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
  79. val &= ~PLLCTL_PLLENSRC;
  80. val |= PLLCTL_PLLEN;
  81. __raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
  82. }
  83. }
  84. static int davinci_pm_enter(suspend_state_t state)
  85. {
  86. int ret = 0;
  87. switch (state) {
  88. case PM_SUSPEND_STANDBY:
  89. case PM_SUSPEND_MEM:
  90. davinci_pm_suspend();
  91. break;
  92. default:
  93. ret = -EINVAL;
  94. }
  95. return ret;
  96. }
  97. static const struct platform_suspend_ops davinci_pm_ops = {
  98. .enter = davinci_pm_enter,
  99. .valid = suspend_valid_only_mem,
  100. };
  101. int __init davinci_pm_init(void)
  102. {
  103. int ret;
  104. ret = davinci_cfg_reg(DA850_RTC_ALARM);
  105. if (ret)
  106. return ret;
  107. pm_config.ddr2_ctlr_base = da8xx_get_mem_ctlr();
  108. pm_config.deepsleep_reg = DA8XX_SYSCFG1_VIRT(DA8XX_DEEPSLEEP_REG);
  109. pm_config.cpupll_reg_base = ioremap(DA8XX_PLL0_BASE, SZ_4K);
  110. if (!pm_config.cpupll_reg_base)
  111. return -ENOMEM;
  112. pm_config.ddrpll_reg_base = ioremap(DA850_PLL1_BASE, SZ_4K);
  113. if (!pm_config.ddrpll_reg_base) {
  114. ret = -ENOMEM;
  115. goto no_ddrpll_mem;
  116. }
  117. pm_config.ddrpsc_reg_base = ioremap(DA8XX_PSC1_BASE, SZ_4K);
  118. if (!pm_config.ddrpsc_reg_base) {
  119. ret = -ENOMEM;
  120. goto no_ddrpsc_mem;
  121. }
  122. davinci_sram_suspend = sram_alloc(davinci_cpu_suspend_sz, NULL);
  123. if (!davinci_sram_suspend) {
  124. pr_err("PM: cannot allocate SRAM memory\n");
  125. ret = -ENOMEM;
  126. goto no_sram_mem;
  127. }
  128. davinci_sram_push(davinci_sram_suspend, davinci_cpu_suspend,
  129. davinci_cpu_suspend_sz);
  130. suspend_set_ops(&davinci_pm_ops);
  131. return 0;
  132. no_sram_mem:
  133. iounmap(pm_config.ddrpsc_reg_base);
  134. no_ddrpsc_mem:
  135. iounmap(pm_config.ddrpll_reg_base);
  136. no_ddrpll_mem:
  137. iounmap(pm_config.cpupll_reg_base);
  138. return ret;
  139. }