pm.c 3.8 KB

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