diff options
Diffstat (limited to 'firmware/target/coldfire/iaudio/m3/system-m3.c')
-rw-r--r-- | firmware/target/coldfire/iaudio/m3/system-m3.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iaudio/m3/system-m3.c b/firmware/target/coldfire/iaudio/m3/system-m3.c new file mode 100644 index 0000000000..bf15caa8e0 --- /dev/null +++ b/firmware/target/coldfire/iaudio/m3/system-m3.c | |||
@@ -0,0 +1,112 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include "kernel.h" | ||
22 | #include "system.h" | ||
23 | #include "power.h" | ||
24 | #include "timer.h" | ||
25 | |||
26 | /* Settings for all possible clock frequencies (with properly working timers) | ||
27 | * NOTE: Some 5249 chips don't like having PLLDIV set to 0. We must avoid that! | ||
28 | * | ||
29 | * xxx_REFRESH_TIMER below | ||
30 | * system.h, CPUFREQ_xxx_MULT | | ||
31 | * | | | ||
32 | * V V | ||
33 | * PLLCR & Rftim. IDECONFIG1/IDECONFIG2 | ||
34 | * CPUCLK/Hz MULT ~0x70400000 16MB CSCR0 CS2Pre CS2Post CS2Wait | ||
35 | * ----------------------------------------------------------------- | ||
36 | * 11289600 1 0x00800200 4 0x0180 1 1 0 | ||
37 | * 22579200 2 0x0589e025 10 0x0180 1 1 0 | ||
38 | * 33868800 3 0x0388e025 15 0x0180 1 1 0 | ||
39 | * 45158400 4 0x0589e021 21 0x0580 1 1 0 | ||
40 | * 56448000 5 0x0289e025 26 0x0580 2 1 0 | ||
41 | * 67737600 6 0x0388e021 32 0x0980 2 1 0 | ||
42 | * 79027200 7 0x038a6021 37 0x0980 2 1 0 | ||
43 | * 90316800 8 0x038be021 43 0x0d80 2 1 0 | ||
44 | * 101606400 9 0x01892025 48 0x0d80 2 1 0 | ||
45 | * 112896000 10 0x0189e025 54 0x1180 3 1 0 | ||
46 | * 124185600 11 0x018ae025 59 0x1180 3 1 1 | ||
47 | */ | ||
48 | |||
49 | #define MAX_REFRESH_TIMER 59 | ||
50 | #define NORMAL_REFRESH_TIMER 21 | ||
51 | #define DEFAULT_REFRESH_TIMER 4 | ||
52 | |||
53 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
54 | void set_cpu_frequency (long) __attribute__ ((section (".icode"))); | ||
55 | void set_cpu_frequency(long frequency) | ||
56 | #else | ||
57 | void cf_set_cpu_frequency (long) __attribute__ ((section (".icode"))); | ||
58 | void cf_set_cpu_frequency(long frequency) | ||
59 | #endif | ||
60 | { | ||
61 | switch(frequency) | ||
62 | { | ||
63 | case CPUFREQ_MAX: | ||
64 | DCR = (0x8200 | DEFAULT_REFRESH_TIMER); | ||
65 | /* Refresh timer for bypass frequency */ | ||
66 | PLLCR &= ~1; /* Bypass mode */ | ||
67 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); | ||
68 | PLLCR = 0x018ae025 | (PLLCR & 0x70400000); | ||
69 | CSCR0 = 0x00001180; /* Flash: 4 wait states */ | ||
70 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. | ||
71 | This may take up to 10ms! */ | ||
72 | timers_adjust_prescale(CPUFREQ_MAX_MULT, true); | ||
73 | DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */ | ||
74 | cpu_frequency = CPUFREQ_MAX; | ||
75 | IDECONFIG1 = 0x100000 | (1 << 13) | (3 << 10); | ||
76 | /* SBUFEN2 enable | CS2Post | CS2Pre */ | ||
77 | IDECONFIG2 = 0x40000 | (1 << 8); /* TA enable + CS2wait */ | ||
78 | break; | ||
79 | |||
80 | case CPUFREQ_NORMAL: | ||
81 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; | ||
82 | /* Refresh timer for bypass frequency */ | ||
83 | PLLCR &= ~1; /* Bypass mode */ | ||
84 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); | ||
85 | PLLCR = 0x0589e021 | (PLLCR & 0x70400000); | ||
86 | CSCR0 = 0x00000580; /* Flash: 1 wait state */ | ||
87 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. | ||
88 | This may take up to 10ms! */ | ||
89 | timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true); | ||
90 | DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */ | ||
91 | cpu_frequency = CPUFREQ_NORMAL; | ||
92 | IDECONFIG1 = 0x100000 | (1 << 13) | (1 << 10); | ||
93 | /* BUFEN2 enable | CS2Post | CS2Pre */ | ||
94 | IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ | ||
95 | break; | ||
96 | |||
97 | default: | ||
98 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; | ||
99 | /* Refresh timer for bypass frequency */ | ||
100 | PLLCR &= ~1; /* Bypass mode */ | ||
101 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true); | ||
102 | /* Power down PLL, but keep CRSEL and CLSEL */ | ||
103 | PLLCR = 0x00800200 | (PLLCR & 0x70400000); | ||
104 | CSCR0 = 0x00000180; /* Flash: 0 wait states */ | ||
105 | DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */ | ||
106 | cpu_frequency = CPUFREQ_DEFAULT; | ||
107 | IDECONFIG1 = 0x100000 | (1 << 13) | (1 << 10); | ||
108 | /* BUFEN2 enable | CS2Post | CS2Pre */ | ||
109 | IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ | ||
110 | break; | ||
111 | } | ||
112 | } | ||