pm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * power management entry for CSR SiRFprimaII
  3. *
  4. * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/suspend.h>
  10. #include <linux/slab.h>
  11. #include <linux/export.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include <linux/of_device.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/io.h>
  17. #include <linux/rtc/sirfsoc_rtciobrg.h>
  18. #include <asm/outercache.h>
  19. #include <asm/suspend.h>
  20. #include <asm/hardware/cache-l2x0.h>
  21. #include "pm.h"
  22. /*
  23. * suspend asm codes will access these to make DRAM become self-refresh and
  24. * system sleep
  25. */
  26. u32 sirfsoc_pwrc_base;
  27. void __iomem *sirfsoc_memc_base;
  28. static void sirfsoc_set_wakeup_source(void)
  29. {
  30. u32 pwr_trigger_en_reg;
  31. pwr_trigger_en_reg = sirfsoc_rtc_iobrg_readl(sirfsoc_pwrc_base +
  32. SIRFSOC_PWRC_TRIGGER_EN);
  33. #define X_ON_KEY_B (1 << 0)
  34. #define RTC_ALARM0_B (1 << 2)
  35. #define RTC_ALARM1_B (1 << 3)
  36. sirfsoc_rtc_iobrg_writel(pwr_trigger_en_reg | X_ON_KEY_B |
  37. RTC_ALARM0_B | RTC_ALARM1_B,
  38. sirfsoc_pwrc_base + SIRFSOC_PWRC_TRIGGER_EN);
  39. }
  40. static void sirfsoc_set_sleep_mode(u32 mode)
  41. {
  42. u32 sleep_mode = sirfsoc_rtc_iobrg_readl(sirfsoc_pwrc_base +
  43. SIRFSOC_PWRC_PDN_CTRL);
  44. sleep_mode &= ~(SIRFSOC_SLEEP_MODE_MASK << 1);
  45. sleep_mode |= mode << 1;
  46. sirfsoc_rtc_iobrg_writel(sleep_mode, sirfsoc_pwrc_base +
  47. SIRFSOC_PWRC_PDN_CTRL);
  48. }
  49. static int sirfsoc_pre_suspend_power_off(void)
  50. {
  51. u32 wakeup_entry = __pa_symbol(cpu_resume);
  52. sirfsoc_rtc_iobrg_writel(wakeup_entry, sirfsoc_pwrc_base +
  53. SIRFSOC_PWRC_SCRATCH_PAD1);
  54. sirfsoc_set_wakeup_source();
  55. sirfsoc_set_sleep_mode(SIRFSOC_DEEP_SLEEP_MODE);
  56. return 0;
  57. }
  58. static int sirfsoc_pm_enter(suspend_state_t state)
  59. {
  60. switch (state) {
  61. case PM_SUSPEND_MEM:
  62. sirfsoc_pre_suspend_power_off();
  63. outer_disable();
  64. /* go zzz */
  65. cpu_suspend(0, sirfsoc_finish_suspend);
  66. outer_resume();
  67. break;
  68. default:
  69. return -EINVAL;
  70. }
  71. return 0;
  72. }
  73. static const struct platform_suspend_ops sirfsoc_pm_ops = {
  74. .enter = sirfsoc_pm_enter,
  75. .valid = suspend_valid_only_mem,
  76. };
  77. static const struct of_device_id pwrc_ids[] = {
  78. { .compatible = "sirf,prima2-pwrc" },
  79. {}
  80. };
  81. static int __init sirfsoc_of_pwrc_init(void)
  82. {
  83. struct device_node *np;
  84. np = of_find_matching_node(NULL, pwrc_ids);
  85. if (!np) {
  86. pr_err("unable to find compatible sirf pwrc node in dtb\n");
  87. return -ENOENT;
  88. }
  89. /*
  90. * pwrc behind rtciobrg is not located in memory space
  91. * though the property is named reg. reg only means base
  92. * offset for pwrc. then of_iomap is not suitable here.
  93. */
  94. if (of_property_read_u32(np, "reg", &sirfsoc_pwrc_base))
  95. panic("unable to find base address of pwrc node in dtb\n");
  96. of_node_put(np);
  97. return 0;
  98. }
  99. static const struct of_device_id memc_ids[] = {
  100. { .compatible = "sirf,prima2-memc" },
  101. {}
  102. };
  103. static int sirfsoc_memc_probe(struct platform_device *op)
  104. {
  105. struct device_node *np = op->dev.of_node;
  106. sirfsoc_memc_base = of_iomap(np, 0);
  107. if (!sirfsoc_memc_base)
  108. panic("unable to map memc registers\n");
  109. return 0;
  110. }
  111. static struct platform_driver sirfsoc_memc_driver = {
  112. .probe = sirfsoc_memc_probe,
  113. .driver = {
  114. .name = "sirfsoc-memc",
  115. .of_match_table = memc_ids,
  116. },
  117. };
  118. static int __init sirfsoc_memc_init(void)
  119. {
  120. return platform_driver_register(&sirfsoc_memc_driver);
  121. }
  122. int __init sirfsoc_pm_init(void)
  123. {
  124. sirfsoc_of_pwrc_init();
  125. sirfsoc_memc_init();
  126. suspend_set_ops(&sirfsoc_pm_ops);
  127. return 0;
  128. }