pm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/da8xx.h>
  20. #include <mach/sram.h>
  21. #include <mach/pm.h>
  22. #include "clock.h"
  23. #define DEEPSLEEP_SLEEPCOUNT_MASK 0xFFFF
  24. static void (*davinci_sram_suspend) (struct davinci_pm_config *);
  25. static struct davinci_pm_config *pdata;
  26. static void davinci_sram_push(void *dest, void *src, unsigned int size)
  27. {
  28. memcpy(dest, src, size);
  29. flush_icache_range((unsigned long)dest, (unsigned long)(dest + size));
  30. }
  31. static void davinci_pm_suspend(void)
  32. {
  33. unsigned val;
  34. if (pdata->cpupll_reg_base != pdata->ddrpll_reg_base) {
  35. /* Switch CPU PLL to bypass mode */
  36. val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
  37. val &= ~(PLLCTL_PLLENSRC | PLLCTL_PLLEN);
  38. __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
  39. udelay(PLL_BYPASS_TIME);
  40. /* Powerdown CPU PLL */
  41. val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
  42. val |= PLLCTL_PLLPWRDN;
  43. __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
  44. }
  45. /* Configure sleep count in deep sleep register */
  46. val = __raw_readl(pdata->deepsleep_reg);
  47. val &= ~DEEPSLEEP_SLEEPCOUNT_MASK,
  48. val |= pdata->sleepcount;
  49. __raw_writel(val, pdata->deepsleep_reg);
  50. /* System goes to sleep in this call */
  51. davinci_sram_suspend(pdata);
  52. if (pdata->cpupll_reg_base != pdata->ddrpll_reg_base) {
  53. /* put CPU PLL in reset */
  54. val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
  55. val &= ~PLLCTL_PLLRST;
  56. __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
  57. /* put CPU PLL in power down */
  58. val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
  59. val &= ~PLLCTL_PLLPWRDN;
  60. __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
  61. /* wait for CPU PLL reset */
  62. udelay(PLL_RESET_TIME);
  63. /* bring CPU PLL out of reset */
  64. val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
  65. val |= PLLCTL_PLLRST;
  66. __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
  67. /* Wait for CPU PLL to lock */
  68. udelay(PLL_LOCK_TIME);
  69. /* Remove CPU PLL from bypass mode */
  70. val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
  71. val &= ~PLLCTL_PLLENSRC;
  72. val |= PLLCTL_PLLEN;
  73. __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
  74. }
  75. }
  76. static int davinci_pm_enter(suspend_state_t state)
  77. {
  78. int ret = 0;
  79. switch (state) {
  80. case PM_SUSPEND_STANDBY:
  81. case PM_SUSPEND_MEM:
  82. davinci_pm_suspend();
  83. break;
  84. default:
  85. ret = -EINVAL;
  86. }
  87. return ret;
  88. }
  89. static const struct platform_suspend_ops davinci_pm_ops = {
  90. .enter = davinci_pm_enter,
  91. .valid = suspend_valid_only_mem,
  92. };
  93. static int __init davinci_pm_probe(struct platform_device *pdev)
  94. {
  95. pdata = pdev->dev.platform_data;
  96. if (!pdata) {
  97. dev_err(&pdev->dev, "cannot get platform data\n");
  98. return -ENOENT;
  99. }
  100. davinci_sram_suspend = sram_alloc(davinci_cpu_suspend_sz, NULL);
  101. if (!davinci_sram_suspend) {
  102. dev_err(&pdev->dev, "cannot allocate SRAM memory\n");
  103. return -ENOMEM;
  104. }
  105. davinci_sram_push(davinci_sram_suspend, davinci_cpu_suspend,
  106. davinci_cpu_suspend_sz);
  107. suspend_set_ops(&davinci_pm_ops);
  108. return 0;
  109. }
  110. static int __exit davinci_pm_remove(struct platform_device *pdev)
  111. {
  112. sram_free(davinci_sram_suspend, davinci_cpu_suspend_sz);
  113. return 0;
  114. }
  115. static struct platform_driver davinci_pm_driver = {
  116. .driver = {
  117. .name = "pm-davinci",
  118. .owner = THIS_MODULE,
  119. },
  120. .remove = __exit_p(davinci_pm_remove),
  121. };
  122. static int __init davinci_pm_init(void)
  123. {
  124. return platform_driver_probe(&davinci_pm_driver, davinci_pm_probe);
  125. }
  126. late_initcall(davinci_pm_init);