pm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Lemote loongson2f family machines' 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 <linux/i8042.h>
  12. #include <linux/export.h>
  13. #include <asm/i8259.h>
  14. #include <asm/mipsregs.h>
  15. #include <asm/bootinfo.h>
  16. #include <loongson.h>
  17. #include <cs5536/cs5536_mfgpt.h>
  18. #include "ec_kb3310b.h"
  19. #define I8042_KBD_IRQ 1
  20. #define I8042_CTR_KBDINT 0x01
  21. #define I8042_CTR_KBDDIS 0x10
  22. static unsigned char i8042_ctr;
  23. static int i8042_enable_kbd_port(void)
  24. {
  25. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_RCTR)) {
  26. pr_err("i8042.c: Can't read CTR while enabling i8042 kbd port."
  27. "\n");
  28. return -EIO;
  29. }
  30. i8042_ctr &= ~I8042_CTR_KBDDIS;
  31. i8042_ctr |= I8042_CTR_KBDINT;
  32. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
  33. i8042_ctr &= ~I8042_CTR_KBDINT;
  34. i8042_ctr |= I8042_CTR_KBDDIS;
  35. pr_err("i8042.c: Failed to enable KBD port.\n");
  36. return -EIO;
  37. }
  38. return 0;
  39. }
  40. void setup_wakeup_events(void)
  41. {
  42. int irq_mask;
  43. switch (mips_machtype) {
  44. case MACH_LEMOTE_ML2F7:
  45. case MACH_LEMOTE_YL2F89:
  46. /* open the keyboard irq in i8259A */
  47. outb((0xff & ~(1 << I8042_KBD_IRQ)), PIC_MASTER_IMR);
  48. irq_mask = inb(PIC_MASTER_IMR);
  49. /* enable keyboard port */
  50. i8042_enable_kbd_port();
  51. /* Wakeup CPU via SCI lid open event */
  52. outb(irq_mask & ~(1 << PIC_CASCADE_IR), PIC_MASTER_IMR);
  53. inb(PIC_MASTER_IMR);
  54. outb(0xff & ~(1 << (SCI_IRQ_NUM - 8)), PIC_SLAVE_IMR);
  55. inb(PIC_SLAVE_IMR);
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61. static struct delayed_work lid_task;
  62. static int initialized;
  63. /* yeeloong_report_lid_status will be implemented in yeeloong_laptop.c */
  64. sci_handler yeeloong_report_lid_status;
  65. EXPORT_SYMBOL(yeeloong_report_lid_status);
  66. static void yeeloong_lid_update_task(struct work_struct *work)
  67. {
  68. if (yeeloong_report_lid_status)
  69. yeeloong_report_lid_status(BIT_LID_DETECT_ON);
  70. }
  71. int wakeup_loongson(void)
  72. {
  73. int irq;
  74. /* query the interrupt number */
  75. irq = mach_i8259_irq();
  76. if (irq < 0)
  77. return 0;
  78. printk(KERN_INFO "%s: irq = %d\n", __func__, irq);
  79. if (irq == I8042_KBD_IRQ)
  80. return 1;
  81. else if (irq == SCI_IRQ_NUM) {
  82. int ret, sci_event;
  83. /* query the event number */
  84. ret = ec_query_seq(CMD_GET_EVENT_NUM);
  85. if (ret < 0)
  86. return 0;
  87. sci_event = ec_get_event_num();
  88. if (sci_event < 0)
  89. return 0;
  90. if (sci_event == EVENT_LID) {
  91. int lid_status;
  92. /* check the LID status */
  93. lid_status = ec_read(REG_LID_DETECT);
  94. /* wakeup cpu when people open the LID */
  95. if (lid_status == BIT_LID_DETECT_ON) {
  96. /* If we call it directly here, the WARNING
  97. * will be sent out by getnstimeofday
  98. * via "WARN_ON(timekeeping_suspended);"
  99. * because we can not schedule in suspend mode.
  100. */
  101. if (initialized == 0) {
  102. INIT_DELAYED_WORK(&lid_task,
  103. yeeloong_lid_update_task);
  104. initialized = 1;
  105. }
  106. schedule_delayed_work(&lid_task, 1);
  107. return 1;
  108. }
  109. }
  110. }
  111. return 0;
  112. }
  113. void __weak mach_suspend(void)
  114. {
  115. disable_mfgpt0_counter();
  116. }
  117. void __weak mach_resume(void)
  118. {
  119. enable_mfgpt0_counter();
  120. }