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_MEM:
  89. davinci_pm_suspend();
  90. break;
  91. default:
  92. ret = -EINVAL;
  93. }
  94. return ret;
  95. }
  96. static const struct platform_suspend_ops davinci_pm_ops = {
  97. .enter = davinci_pm_enter,
  98. .valid = suspend_valid_only_mem,
  99. };
  100. int __init davinci_pm_init(void)
  101. {
  102. int ret;
  103. ret = davinci_cfg_reg(DA850_RTC_ALARM);
  104. if (ret)
  105. return ret;
  106. pm_config.ddr2_ctlr_base = da8xx_get_mem_ctlr();
  107. pm_config.deepsleep_reg = DA8XX_SYSCFG1_VIRT(DA8XX_DEEPSLEEP_REG);
  108. pm_config.cpupll_reg_base = ioremap(DA8XX_PLL0_BASE, SZ_4K);
  109. if (!pm_config.cpupll_reg_base)
  110. return -ENOMEM;
  111. pm_config.ddrpll_reg_base = ioremap(DA850_PLL1_BASE, SZ_4K);
  112. if (!pm_config.ddrpll_reg_base) {
  113. ret = -ENOMEM;
  114. goto no_ddrpll_mem;
  115. }
  116. pm_config.ddrpsc_reg_base = ioremap(DA8XX_PSC1_BASE, SZ_4K);
  117. if (!pm_config.ddrpsc_reg_base) {
  118. ret = -ENOMEM;
  119. goto no_ddrpsc_mem;
  120. }
  121. davinci_sram_suspend = sram_alloc(davinci_cpu_suspend_sz, NULL);
  122. if (!davinci_sram_suspend) {
  123. pr_err("PM: cannot allocate SRAM memory\n");
  124. ret = -ENOMEM;
  125. goto no_sram_mem;
  126. }
  127. davinci_sram_push(davinci_sram_suspend, davinci_cpu_suspend,
  128. davinci_cpu_suspend_sz);
  129. suspend_set_ops(&davinci_pm_ops);
  130. return 0;
  131. no_sram_mem:
  132. iounmap(pm_config.ddrpsc_reg_base);
  133. no_ddrpsc_mem:
  134. iounmap(pm_config.ddrpll_reg_base);
  135. no_ddrpll_mem:
  136. iounmap(pm_config.cpupll_reg_base);
  137. return ret;
  138. }