pm.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * loongson-specific suspend support
  4. *
  5. * Copyright (C) 2009 Lemote Inc.
  6. * Author: Wu Zhangjin <[email protected]>
  7. */
  8. #include <linux/suspend.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/pm.h>
  11. #include <asm/i8259.h>
  12. #include <asm/mipsregs.h>
  13. #include <loongson.h>
  14. static unsigned int __maybe_unused cached_master_mask; /* i8259A */
  15. static unsigned int __maybe_unused cached_slave_mask;
  16. static unsigned int __maybe_unused cached_bonito_irq_mask; /* bonito */
  17. void arch_suspend_disable_irqs(void)
  18. {
  19. /* disable all mips events */
  20. local_irq_disable();
  21. #ifdef CONFIG_I8259
  22. /* disable all events of i8259A */
  23. cached_slave_mask = inb(PIC_SLAVE_IMR);
  24. cached_master_mask = inb(PIC_MASTER_IMR);
  25. outb(0xff, PIC_SLAVE_IMR);
  26. inb(PIC_SLAVE_IMR);
  27. outb(0xff, PIC_MASTER_IMR);
  28. inb(PIC_MASTER_IMR);
  29. #endif
  30. /* disable all events of bonito */
  31. cached_bonito_irq_mask = LOONGSON_INTEN;
  32. LOONGSON_INTENCLR = 0xffff;
  33. (void)LOONGSON_INTENCLR;
  34. }
  35. void arch_suspend_enable_irqs(void)
  36. {
  37. /* enable all mips events */
  38. local_irq_enable();
  39. #ifdef CONFIG_I8259
  40. /* only enable the cached events of i8259A */
  41. outb(cached_slave_mask, PIC_SLAVE_IMR);
  42. outb(cached_master_mask, PIC_MASTER_IMR);
  43. #endif
  44. /* enable all cached events of bonito */
  45. LOONGSON_INTENSET = cached_bonito_irq_mask;
  46. (void)LOONGSON_INTENSET;
  47. }
  48. /*
  49. * Setup the board-specific events for waking up loongson from wait mode
  50. */
  51. void __weak setup_wakeup_events(void)
  52. {
  53. }
  54. void __weak mach_suspend(void)
  55. {
  56. }
  57. void __weak mach_resume(void)
  58. {
  59. }
  60. static int loongson_pm_enter(suspend_state_t state)
  61. {
  62. mach_suspend();
  63. mach_resume();
  64. return 0;
  65. }
  66. static int loongson_pm_valid_state(suspend_state_t state)
  67. {
  68. switch (state) {
  69. case PM_SUSPEND_ON:
  70. case PM_SUSPEND_STANDBY:
  71. case PM_SUSPEND_MEM:
  72. return 1;
  73. default:
  74. return 0;
  75. }
  76. }
  77. static const struct platform_suspend_ops loongson_pm_ops = {
  78. .valid = loongson_pm_valid_state,
  79. .enter = loongson_pm_enter,
  80. };
  81. static int __init loongson_pm_init(void)
  82. {
  83. suspend_set_ops(&loongson_pm_ops);
  84. return 0;
  85. }
  86. arch_initcall(loongson_pm_init);