2 * mahatma - a simple kernel framework
3 * Copyright (c) 2008, 2009 Daniel Mack <daniel@caiaq.de>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "wikireader.h"
30 #define SUSPEND_SDRAM 1
32 void system_suspend(void)
34 register int card_state
= check_card_power();
41 // no more function calls after this point
42 // all code must be in-line
46 REG_CMU_PROTECT
= CMU_PROTECT_OFF
;
47 REG_CMU_OPT
|= WAKEUPWT
;
48 REG_CMU_PROTECT
= CMU_PROTECT_ON
;
50 // SDRAM to self-refresh mode (disables clock)
55 (0x7f << SELCO_SHIFT
) |
59 BUSY_WAIT_FOR(REG_SDRAMC_REF
& SELDO
);
61 // SDRAMC controller off
72 REG_CMU_PROTECT
= CMU_PROTECT_OFF
;
73 REG_CMU_GATEDCLK0
&= ~(
85 REG_CMU_PROTECT
= CMU_PROTECT_ON
;
87 // release the SDRAMC pin functions
93 // adjust baud rate for lower clock frequency
94 //REG_EFSIF0_BRTRDL = 12 & 0xff;
95 //REG_EFSIF0_BRTRDM = 12 >> 8;
97 SET_BRTRD(0, CALC_BAUD(MCLK
/ 4, DIV
, 57600));
98 SET_BRTRD(1, CALC_BAUD(MCLK
/ 4, DIV
, 38400));
100 // turn off un necessary clocks
101 REG_CMU_PROTECT
= CMU_PROTECT_OFF
;
102 REG_CMU_GATEDCLK0
&= ~(
145 CMU_CLK_SEL_OSC3_DIV_32
|
146 //CMU_CLK_SEL_OSC3_DIV_16 |
147 //CMU_CLK_SEL_OSC3_DIV_8 |
148 //CMU_CLK_SEL_OSC3_DIV_4 |
149 //CMU_CLK_SEL_OSC3_DIV_2 |
150 //CMU_CLK_SEL_OSC3_DIV_1 |
151 //CMU_CLK_SEL_LCDC_CLK |
203 REG_CMU_PROTECT
= CMU_PROTECT_ON
;
205 // end of suspend, wait for interrupt
206 asm volatile ("halt");
207 // interrupt is on hold until end of resume
211 SET_BRTRD(0, CALC_BAUD(MCLK
, DIV
, 57600));
212 SET_BRTRD(1, CALC_BAUD(MCLK
, DIV
, 38400));
214 REG_CMU_PROTECT
= CMU_PROTECT_OFF
;
217 //CMU_CLK_SEL_OSC3_DIV_32 |
218 //CMU_CLK_SEL_OSC3_DIV_16 |
219 //CMU_CLK_SEL_OSC3_DIV_8 |
220 //CMU_CLK_SEL_OSC3_DIV_4 |
221 //CMU_CLK_SEL_OSC3_DIV_2 |
222 //CMU_CLK_SEL_OSC3_DIV_1 |
223 //CMU_CLK_SEL_LCDC_CLK |
275 REG_CMU_PROTECT
= CMU_PROTECT_ON
;
278 register unsigned int i
= 0;
279 for (i
= 0; i
< 10000; i
++) {
280 asm volatile ("nop");
284 REG_CMU_PROTECT
= CMU_PROTECT_OFF
;
325 REG_CMU_PROTECT
= CMU_PROTECT_ON
;
329 /* re-enable the SDRAMC pin functions */
330 REG_P2_03_CFP
= 0x55;
331 REG_P2_47_CFP
= 0x55;
333 // enable RAM and self-refresh
347 (0x7f << SELCO_SHIFT
) |
348 (0x8c << AURCO_SHIFT
) |
353 // it is now possible to call other functions
354 // as SDRAM is operational again