pm.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * loongson-specific suspend support
  3. *
  4. * Copyright (C) 2009 Lemote Inc.
  5. * Author: Wu Zhangjin <wuzhangjin@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include <linux/suspend.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/pm.h>
  15. #include <asm/i8259.h>
  16. #include <asm/mipsregs.h>
  17. #include <loongson.h>
  18. static unsigned int __maybe_unused cached_master_mask; /* i8259A */
  19. static unsigned int __maybe_unused cached_slave_mask;
  20. static unsigned int __maybe_unused cached_bonito_irq_mask; /* bonito */
  21. void arch_suspend_disable_irqs(void)
  22. {
  23. /* disable all mips events */
  24. local_irq_disable();
  25. #ifdef CONFIG_I8259
  26. /* disable all events of i8259A */
  27. cached_slave_mask = inb(PIC_SLAVE_IMR);
  28. cached_master_mask = inb(PIC_MASTER_IMR);
  29. outb(0xff, PIC_SLAVE_IMR);
  30. inb(PIC_SLAVE_IMR);
  31. outb(0xff, PIC_MASTER_IMR);
  32. inb(PIC_MASTER_IMR);
  33. #endif
  34. /* disable all events of bonito */
  35. cached_bonito_irq_mask = LOONGSON_INTEN;
  36. LOONGSON_INTENCLR = 0xffff;
  37. (void)LOONGSON_INTENCLR;
  38. }
  39. void arch_suspend_enable_irqs(void)
  40. {
  41. /* enable all mips events */
  42. local_irq_enable();
  43. #ifdef CONFIG_I8259
  44. /* only enable the cached events of i8259A */
  45. outb(cached_slave_mask, PIC_SLAVE_IMR);
  46. outb(cached_master_mask, PIC_MASTER_IMR);
  47. #endif
  48. /* enable all cached events of bonito */
  49. LOONGSON_INTENSET = cached_bonito_irq_mask;
  50. (void)LOONGSON_INTENSET;
  51. }
  52. /*
  53. * Setup the board-specific events for waking up loongson from wait mode
  54. */
  55. void __weak setup_wakeup_events(void)
  56. {
  57. }
  58. /*
  59. * Check wakeup events
  60. */
  61. int __weak wakeup_loongson(void)
  62. {
  63. return 1;
  64. }
  65. /*
  66. * If the events are really what we want to wakeup the CPU, wake it up
  67. * otherwise put the CPU asleep again.
  68. */
  69. static void wait_for_wakeup_events(void)
  70. {
  71. while (!wakeup_loongson())
  72. LOONGSON_CHIPCFG(0) &= ~0x7;
  73. }
  74. /*
  75. * Stop all perf counters
  76. *
  77. * $24 is the control register of Loongson perf counter
  78. */
  79. static inline void stop_perf_counters(void)
  80. {
  81. __write_64bit_c0_register($24, 0, 0);
  82. }
  83. static void loongson_suspend_enter(void)
  84. {
  85. static unsigned int cached_cpu_freq;
  86. /* setup wakeup events via enabling the IRQs */
  87. setup_wakeup_events();
  88. stop_perf_counters();
  89. cached_cpu_freq = LOONGSON_CHIPCFG(0);
  90. /* Put CPU into wait mode */
  91. LOONGSON_CHIPCFG(0) &= ~0x7;
  92. /* wait for the given events to wakeup cpu from wait mode */
  93. wait_for_wakeup_events();
  94. LOONGSON_CHIPCFG(0) = cached_cpu_freq;
  95. mmiowb();
  96. }
  97. void __weak mach_suspend(void)
  98. {
  99. }
  100. void __weak mach_resume(void)
  101. {
  102. }
  103. static int loongson_pm_enter(suspend_state_t state)
  104. {
  105. mach_suspend();
  106. /* processor specific suspend */
  107. loongson_suspend_enter();
  108. mach_resume();
  109. return 0;
  110. }
  111. static int loongson_pm_valid_state(suspend_state_t state)
  112. {
  113. switch (state) {
  114. case PM_SUSPEND_ON:
  115. case PM_SUSPEND_STANDBY:
  116. case PM_SUSPEND_MEM:
  117. return 1;
  118. default:
  119. return 0;
  120. }
  121. }
  122. static const struct platform_suspend_ops loongson_pm_ops = {
  123. .valid = loongson_pm_valid_state,
  124. .enter = loongson_pm_enter,
  125. };
  126. static int __init loongson_pm_init(void)
  127. {
  128. suspend_set_ops(&loongson_pm_ops);
  129. return 0;
  130. }
  131. arch_initcall(loongson_pm_init);