OMAP: Add new function to check wether there is irq pending
[linux-ginger.git] / arch / sh / boards / mach-hp6xx / pm.c
blobd936c1af7620263244d6471fb4890432a0b54184
1 /*
2 * hp6x0 Power Management Routines
4 * Copyright (c) 2006 Andriy Skulysh <askulsyh@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License.
8 */
9 #include <linux/init.h>
10 #include <linux/suspend.h>
11 #include <linux/errno.h>
12 #include <linux/time.h>
13 #include <linux/delay.h>
14 #include <linux/gfp.h>
15 #include <asm/io.h>
16 #include <asm/hd64461.h>
17 #include <mach/hp6xx.h>
18 #include <cpu/dac.h>
19 #include <asm/freq.h>
20 #include <asm/watchdog.h>
22 #define INTR_OFFSET 0x600
24 #define STBCR 0xffffff82
25 #define STBCR2 0xffffff88
27 #define STBCR_STBY 0x80
28 #define STBCR_MSTP2 0x04
30 #define MCR 0xffffff68
31 #define RTCNT 0xffffff70
33 #define MCR_RMODE 2
34 #define MCR_RFSH 4
36 extern u8 wakeup_start;
37 extern u8 wakeup_end;
39 static void pm_enter(void)
41 u8 stbcr, csr;
42 u16 frqcr, mcr;
43 u32 vbr_new, vbr_old;
45 set_bl_bit();
47 /* set wdt */
48 csr = sh_wdt_read_csr();
49 csr &= ~WTCSR_TME;
50 csr |= WTCSR_CKS_4096;
51 sh_wdt_write_csr(csr);
52 csr = sh_wdt_read_csr();
53 sh_wdt_write_cnt(0);
55 /* disable PLL1 */
56 frqcr = ctrl_inw(FRQCR);
57 frqcr &= ~(FRQCR_PLLEN | FRQCR_PSTBY);
58 ctrl_outw(frqcr, FRQCR);
60 /* enable standby */
61 stbcr = ctrl_inb(STBCR);
62 ctrl_outb(stbcr | STBCR_STBY | STBCR_MSTP2, STBCR);
64 /* set self-refresh */
65 mcr = ctrl_inw(MCR);
66 ctrl_outw(mcr & ~MCR_RFSH, MCR);
68 /* set interrupt handler */
69 asm volatile("stc vbr, %0" : "=r" (vbr_old));
70 vbr_new = get_zeroed_page(GFP_ATOMIC);
71 udelay(50);
72 memcpy((void*)(vbr_new + INTR_OFFSET),
73 &wakeup_start, &wakeup_end - &wakeup_start);
74 asm volatile("ldc %0, vbr" : : "r" (vbr_new));
76 ctrl_outw(0, RTCNT);
77 ctrl_outw(mcr | MCR_RFSH | MCR_RMODE, MCR);
79 cpu_sleep();
81 asm volatile("ldc %0, vbr" : : "r" (vbr_old));
83 free_page(vbr_new);
85 /* enable PLL1 */
86 frqcr = ctrl_inw(FRQCR);
87 frqcr |= FRQCR_PSTBY;
88 ctrl_outw(frqcr, FRQCR);
89 udelay(50);
90 frqcr |= FRQCR_PLLEN;
91 ctrl_outw(frqcr, FRQCR);
93 ctrl_outb(stbcr, STBCR);
95 clear_bl_bit();
98 static int hp6x0_pm_enter(suspend_state_t state)
100 u8 stbcr, stbcr2;
101 #ifdef CONFIG_HD64461_ENABLER
102 u8 scr;
103 u16 hd64461_stbcr;
104 #endif
106 #ifdef CONFIG_HD64461_ENABLER
107 outb(0, HD64461_PCC1CSCIER);
109 scr = inb(HD64461_PCC1SCR);
110 scr |= HD64461_PCCSCR_VCC1;
111 outb(scr, HD64461_PCC1SCR);
113 hd64461_stbcr = inw(HD64461_STBCR);
114 hd64461_stbcr |= HD64461_STBCR_SPC1ST;
115 outw(hd64461_stbcr, HD64461_STBCR);
116 #endif
118 ctrl_outb(0x1f, DACR);
120 stbcr = ctrl_inb(STBCR);
121 ctrl_outb(0x01, STBCR);
123 stbcr2 = ctrl_inb(STBCR2);
124 ctrl_outb(0x7f , STBCR2);
126 outw(0xf07f, HD64461_SCPUCR);
128 pm_enter();
130 outw(0, HD64461_SCPUCR);
131 ctrl_outb(stbcr, STBCR);
132 ctrl_outb(stbcr2, STBCR2);
134 #ifdef CONFIG_HD64461_ENABLER
135 hd64461_stbcr = inw(HD64461_STBCR);
136 hd64461_stbcr &= ~HD64461_STBCR_SPC1ST;
137 outw(hd64461_stbcr, HD64461_STBCR);
139 outb(0x4c, HD64461_PCC1CSCIER);
140 outb(0x00, HD64461_PCC1CSCR);
141 #endif
143 return 0;
146 static struct platform_suspend_ops hp6x0_pm_ops = {
147 .enter = hp6x0_pm_enter,
148 .valid = suspend_valid_only_mem,
151 static int __init hp6x0_pm_init(void)
153 suspend_set_ops(&hp6x0_pm_ops);
154 return 0;
157 late_initcall(hp6x0_pm_init);