1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by James Espinoza
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #include "avic-imx31.h"
26 #include "gpio-imx31.h"
27 #include "mmu-imx31.h"
28 #include "system-target.h"
30 #include "serial-imx31.h"
32 #include "clkctl-imx31.h"
35 /** Watchdog timer routines **/
37 /* Initialize the watchdog timer */
38 void watchdog_init(unsigned int half_seconds
)
40 uint16_t wcr
= WDOG_WCR_WTw(half_seconds
) | /* Timeout */
41 WDOG_WCR_WOE
| /* WDOG output enabled */
42 WDOG_WCR_WDA
| /* WDOG assertion - no effect */
43 WDOG_WCR_SRS
| /* System reset - no effect */
44 WDOG_WCR_WRE
; /* Generate a WDOG signal */
46 imx31_clkctl_module_clock_gating(CG_WDOG
, CGM_ON_RUN_WAIT
);
50 WDOG_WCR
= wcr
| WDOG_WCR_WDE
; /* Enable timer - hardware does
51 not allow a disable now */
55 /* Service the watchdog timer */
56 void watchdog_service(void)
62 /** GPT timer routines - basis for udelay **/
64 /* Start the general-purpose timer (1MHz) */
67 imx31_clkctl_module_clock_gating(CG_GPT
, CGM_ON_RUN_WAIT
);
68 unsigned int ipg_mhz
= imx31_clkctl_get_ipg_clk() / 1000000;
70 GPTCR
&= ~GPTCR_EN
; /* Disable counter */
71 GPTCR
|= GPTCR_SWR
; /* Reset module */
72 while (GPTCR
& GPTCR_SWR
);
75 * Enable in run mode only (doesn't tick while in WFI)
76 * Freerun mode (count to 0xFFFFFFFF and roll-over to 0x00000000)
78 GPTCR
= GPTCR_FRR
| GPTCR_CLKSRC_IPG_CLK
;
83 /* Stop the general-purpose timer */
89 int system_memory_guard(int newmode
)
95 void system_reboot(void)
97 /* Multi-context so no SPI available (WDT?) */
101 void system_exception_wait(void)
103 /* Called in many contexts so button reading may be a chore */
104 avic_disable_int(ALL
);
109 void system_init(void)
111 static const int disable_clocks
[] =
155 /* MCR WFI enables wait mode */
156 CLKCTL_CCMR
&= ~(3 << 14);
158 imx31_regset32(&SDHC1_CLOCK_CONTROL
, STOP_CLK
);
159 imx31_regset32(&SDHC2_CLOCK_CONTROL
, STOP_CLK
);
160 imx31_regset32(&RNGA_CONTROL
, RNGA_CONTROL_SLEEP
);
161 imx31_regclr32(&UCR1_1
, EUARTUCR1_UARTEN
);
162 imx31_regclr32(&UCR1_2
, EUARTUCR1_UARTEN
);
163 imx31_regclr32(&UCR1_3
, EUARTUCR1_UARTEN
);
164 imx31_regclr32(&UCR1_4
, EUARTUCR1_UARTEN
);
165 imx31_regclr32(&UCR1_5
, EUARTUCR1_UARTEN
);
167 for (i
= 0; i
< ARRAYLEN(disable_clocks
); i
++)
168 imx31_clkctl_module_clock_gating(disable_clocks
[i
], CGM_OFF
);
175 void __attribute__((naked
)) imx31_regmod32(volatile uint32_t *reg_p
,
179 asm volatile("and r1, r1, r2 \n"
188 (void)reg_p
; (void)value
; (void)mask
;
191 void __attribute__((naked
)) imx31_regset32(volatile uint32_t *reg_p
,
194 asm volatile("mrs r3, cpsr \n"
201 (void)reg_p
; (void)mask
;
204 void __attribute__((naked
)) imx31_regclr32(volatile uint32_t *reg_p
,
207 asm volatile("mrs r3, cpsr \n"
214 (void)reg_p
; (void)mask
;
218 void system_prepare_fw_start(void)
220 disable_interrupt(IRQ_FIQ_STATUS
);
221 avic_disable_int(ALL
);
227 inline void dumpregs(void)
229 asm volatile ("mov %0,r0\n\t"
233 "=r"(regs
.r0
),"=r"(regs
.r1
),
234 "=r"(regs
.r2
),"=r"(regs
.r3
):);
236 asm volatile ("mov %0,r4\n\t"
240 "=r"(regs
.r4
),"=r"(regs
.r5
),
241 "=r"(regs
.r6
),"=r"(regs
.r7
):);
243 asm volatile ("mov %0,r8\n\t"
247 "=r"(regs
.r8
),"=r"(regs
.r9
),
248 "=r"(regs
.r10
),"=r"(regs
.r11
):);
250 asm volatile ("mov %0,r12\n\t"
255 "=r"(regs
.r12
),"=r"(regs
.sp
),
256 "=r"(regs
.lr
),"=r"(regs
.pc
):);
258 dprintf("Register Dump :\n");
259 dprintf("R0=0x%x\tR1=0x%x\tR2=0x%x\tR3=0x%x\n",regs
.r0
,regs
.r1
,regs
.r2
,regs
.r3
);
260 dprintf("R4=0x%x\tR5=0x%x\tR6=0x%x\tR7=0x%x\n",regs
.r4
,regs
.r5
,regs
.r6
,regs
.r7
);
261 dprintf("R8=0x%x\tR9=0x%x\tR10=0x%x\tR11=0x%x\n",regs
.r8
,regs
.r9
,regs
.r10
,regs
.r11
);
262 dprintf("R12=0x%x\tSP=0x%x\tLR=0x%x\tPC=0x%x\n",regs
.r12
,regs
.sp
,regs
.lr
,regs
.pc
);
263 //dprintf("CPSR=0x%x\t\n",regs.cpsr);
265 DEBUGF("Register Dump :\n");
266 DEBUGF("R0=0x%x\tR1=0x%x\tR2=0x%x\tR3=0x%x\n",regs
.r0
,regs
.r1
,regs
.r2
,regs
.r3
);
267 DEBUGF("R4=0x%x\tR5=0x%x\tR6=0x%x\tR7=0x%x\n",regs
.r4
,regs
.r5
,regs
.r6
,regs
.r7
);
268 DEBUGF("R8=0x%x\tR9=0x%x\tR10=0x%x\tR11=0x%x\n",regs
.r8
,regs
.r9
,regs
.r10
,regs
.r11
);
269 DEBUGF("R12=0x%x\tSP=0x%x\tLR=0x%x\tPC=0x%x\n",regs
.r12
,regs
.sp
,regs
.lr
,regs
.pc
);
270 //DEBUGF("CPSR=0x%x\t\n",regs.cpsr);
274 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
276 void set_cpu_frequency(long frequency
)