2 * Lemote loongson2f family machines' specific suspend support
4 * Copyright (C) 2009 Lemote Inc.
5 * Author: Wu Zhangjin <wuzj@lemote.com>
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.
13 #include <linux/suspend.h>
14 #include <linux/interrupt.h>
16 #include <linux/i8042.h>
17 #include <linux/module.h>
19 #include <asm/i8259.h>
20 #include <asm/mipsregs.h>
21 #include <asm/bootinfo.h>
25 #include "ec_kb3310b.h"
27 #define I8042_KBD_IRQ 1
28 #define I8042_CTR_KBDINT 0x01
29 #define I8042_CTR_KBDDIS 0x10
31 static unsigned char i8042_ctr
;
33 static int i8042_enable_kbd_port(void)
35 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_RCTR
)) {
36 pr_err("i8042.c: Can't read CTR while enabling i8042 kbd port."
41 i8042_ctr
&= ~I8042_CTR_KBDDIS
;
42 i8042_ctr
|= I8042_CTR_KBDINT
;
44 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_WCTR
)) {
45 i8042_ctr
&= ~I8042_CTR_KBDINT
;
46 i8042_ctr
|= I8042_CTR_KBDDIS
;
47 pr_err("i8042.c: Failed to enable KBD port.\n");
55 void setup_wakeup_events(void)
59 switch (mips_machtype
) {
60 case MACH_LEMOTE_ML2F7
:
61 case MACH_LEMOTE_YL2F89
:
62 /* open the keyboard irq in i8259A */
63 outb((0xff & ~(1 << I8042_KBD_IRQ
)), PIC_MASTER_IMR
);
64 irq_mask
= inb(PIC_MASTER_IMR
);
66 /* enable keyboard port */
67 i8042_enable_kbd_port();
69 /* Wakeup CPU via SCI lid open event */
70 outb(irq_mask
& ~(1 << PIC_CASCADE_IR
), PIC_MASTER_IMR
);
72 outb(0xff & ~(1 << (SCI_IRQ_NUM
- 8)), PIC_SLAVE_IMR
);
82 static struct delayed_work lid_task
;
83 static int initialized
;
84 /* yeeloong_report_lid_status will be implemented in yeeloong_laptop.c */
85 sci_handler yeeloong_report_lid_status
;
86 EXPORT_SYMBOL(yeeloong_report_lid_status
);
87 static void yeeloong_lid_update_task(struct work_struct
*work
)
89 if (yeeloong_report_lid_status
)
90 yeeloong_report_lid_status(BIT_LID_DETECT_ON
);
93 int wakeup_loongson(void)
97 /* query the interrupt number */
98 irq
= mach_i8259_irq();
102 printk(KERN_INFO
"%s: irq = %d\n", __func__
, irq
);
104 if (irq
== I8042_KBD_IRQ
)
106 else if (irq
== SCI_IRQ_NUM
) {
108 /* query the event number */
109 ret
= ec_query_seq(CMD_GET_EVENT_NUM
);
112 sci_event
= ec_get_event_num();
115 if (sci_event
== EVENT_LID
) {
117 /* check the LID status */
118 lid_status
= ec_read(REG_LID_DETECT
);
119 /* wakeup cpu when people open the LID */
120 if (lid_status
== BIT_LID_DETECT_ON
) {
121 /* If we call it directly here, the WARNING
122 * will be sent out by getnstimeofday
123 * via "WARN_ON(timekeeping_suspended);"
124 * because we can not schedule in suspend mode.
126 if (initialized
== 0) {
127 INIT_DELAYED_WORK(&lid_task
,
128 yeeloong_lid_update_task
);
131 schedule_delayed_work(&lid_task
, 1);