pm.c 3.8 KB

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