pm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/module.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/suspend.h>
  19. #include <asm/hardware/cache-l2x0.h>
  20. #include "pm.h"
  21. /*
  22. * suspend asm codes will access these to make DRAM become self-refresh and
  23. * system sleep
  24. */
  25. u32 sirfsoc_pwrc_base;
  26. void __iomem *sirfsoc_memc_base;
  27. static void sirfsoc_set_wakeup_source(void)
  28. {
  29. u32 pwr_trigger_en_reg;
  30. pwr_trigger_en_reg = sirfsoc_rtc_iobrg_readl(sirfsoc_pwrc_base +
  31. SIRFSOC_PWRC_TRIGGER_EN);
  32. #define X_ON_KEY_B (1 << 0)
  33. sirfsoc_rtc_iobrg_writel(pwr_trigger_en_reg | X_ON_KEY_B,
  34. sirfsoc_pwrc_base + SIRFSOC_PWRC_TRIGGER_EN);
  35. }
  36. static void sirfsoc_set_sleep_mode(u32 mode)
  37. {
  38. u32 sleep_mode = sirfsoc_rtc_iobrg_readl(sirfsoc_pwrc_base +
  39. SIRFSOC_PWRC_PDN_CTRL);
  40. sleep_mode &= ~(SIRFSOC_SLEEP_MODE_MASK << 1);
  41. sleep_mode |= mode << 1;
  42. sirfsoc_rtc_iobrg_writel(sleep_mode, sirfsoc_pwrc_base +
  43. SIRFSOC_PWRC_PDN_CTRL);
  44. }
  45. static int sirfsoc_pre_suspend_power_off(void)
  46. {
  47. u32 wakeup_entry = virt_to_phys(cpu_resume);
  48. sirfsoc_rtc_iobrg_writel(wakeup_entry, sirfsoc_pwrc_base +
  49. SIRFSOC_PWRC_SCRATCH_PAD1);
  50. sirfsoc_set_wakeup_source();
  51. sirfsoc_set_sleep_mode(SIRFSOC_DEEP_SLEEP_MODE);
  52. return 0;
  53. }
  54. static int sirfsoc_pm_enter(suspend_state_t state)
  55. {
  56. switch (state) {
  57. case PM_SUSPEND_MEM:
  58. sirfsoc_pre_suspend_power_off();
  59. outer_flush_all();
  60. outer_disable();
  61. /* go zzz */
  62. cpu_suspend(0, sirfsoc_finish_suspend);
  63. outer_resume();
  64. break;
  65. default:
  66. return -EINVAL;
  67. }
  68. return 0;
  69. }
  70. static const struct platform_suspend_ops sirfsoc_pm_ops = {
  71. .enter = sirfsoc_pm_enter,
  72. .valid = suspend_valid_only_mem,
  73. };
  74. static int __init sirfsoc_pm_init(void)
  75. {
  76. suspend_set_ops(&sirfsoc_pm_ops);
  77. return 0;
  78. }
  79. late_initcall(sirfsoc_pm_init);
  80. static const struct of_device_id pwrc_ids[] = {
  81. { .compatible = "sirf,prima2-pwrc" },
  82. {}
  83. };
  84. static int __init sirfsoc_of_pwrc_init(void)
  85. {
  86. struct device_node *np;
  87. np = of_find_matching_node(NULL, pwrc_ids);
  88. if (!np)
  89. panic("unable to find compatible pwrc node in dtb\n");
  90. /*
  91. * pwrc behind rtciobrg is not located in memory space
  92. * though the property is named reg. reg only means base
  93. * offset for pwrc. then of_iomap is not suitable here.
  94. */
  95. if (of_property_read_u32(np, "reg", &sirfsoc_pwrc_base))
  96. panic("unable to find base address of pwrc node in dtb\n");
  97. of_node_put(np);
  98. return 0;
  99. }
  100. postcore_initcall(sirfsoc_of_pwrc_init);
  101. static const struct of_device_id memc_ids[] = {
  102. { .compatible = "sirf,prima2-memc" },
  103. {}
  104. };
  105. static int __devinit sirfsoc_memc_probe(struct platform_device *op)
  106. {
  107. struct device_node *np = op->dev.of_node;
  108. sirfsoc_memc_base = of_iomap(np, 0);
  109. if (!sirfsoc_memc_base)
  110. panic("unable to map memc registers\n");
  111. return 0;
  112. }
  113. static struct platform_driver sirfsoc_memc_driver = {
  114. .probe = sirfsoc_memc_probe,
  115. .driver = {
  116. .name = "sirfsoc-memc",
  117. .owner = THIS_MODULE,
  118. .of_match_table = memc_ids,
  119. },
  120. };
  121. static int __init sirfsoc_memc_init(void)
  122. {
  123. return platform_driver_register(&sirfsoc_memc_driver);
  124. }
  125. postcore_initcall(sirfsoc_memc_init);