summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/mpio/hd200/system-hd200.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/mpio/hd200/system-hd200.c')
-rw-r--r--firmware/target/coldfire/mpio/hd200/system-hd200.c125
1 files changed, 125 insertions, 0 deletions
diff --git a/firmware/target/coldfire/mpio/hd200/system-hd200.c b/firmware/target/coldfire/mpio/hd200/system-hd200.c
new file mode 100644
index 0000000000..06628c0835
--- /dev/null
+++ b/firmware/target/coldfire/mpio/hd200/system-hd200.c
@@ -0,0 +1,125 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
9 *
10 * Copyright (C) 2010 Marcin Bukat
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22#include "cpu.h"
23#include "kernel.h"
24#include "system.h"
25#include "power.h"
26#include "timer.h"
27
28/* Settings for all possible clock frequencies (with properly working timers)
29 *
30 * xxx_REFRESH_TIMER below
31 * system.h, CPUFREQ_xxx_MULT |
32 * | |
33 * V V
34 * PLLCR & Rftim. IDECONFIG1/IDECONFIG2
35 * CPUCLK/Hz MULT ~0x70c00000 16MB CSCR0 CSCR1 CS2Pre CS2Post CS2Wait
36 * -------------------------------------------------------------------------
37 * 11289600 1 0x00000200 4 0x0180 0x0180 1 1 0
38 * 22579200 2 0x05028049 10 0x0180 0x0180 1 1 0
39 * 33868800 3 0x03024049 15 0x0180 0x0180 1 1 0
40 * 45158400 4 0x05028045 21 0x0180 0x0180 1 1 0
41 * 56448000 5 0x02028049 26 0x0580 0x0580 2 1 0
42 * 67737600 6 0x03024045 32 0x0580 0x0980 2 1 0
43 * 79027200 7 0x0302a045 37 0x0580 0x0d80 2 1 0
44 * 90316800 8 0x03030045 43 0x0980 0x0d80 2 1 0
45 * 101606400 9 0x01024049 48 0x0980 0x1180 2 1 0
46 * 112896000 10 0x01028049 54 0x0980 0x1580 3 1 0
47 * 124185600 11 0x0102c049 59 0x0980 0x1180 3 1 1
48 */
49
50#define MAX_REFRESH_TIMER 59
51#define NORMAL_REFRESH_TIMER 21
52#define DEFAULT_REFRESH_TIMER 4
53
54#ifdef HAVE_ADJUSTABLE_CPU_FREQ
55void set_cpu_frequency (long) __attribute__ ((section (".icode")));
56void set_cpu_frequency(long frequency)
57#else
58void cf_set_cpu_frequency (long) __attribute__ ((section (".icode")));
59void cf_set_cpu_frequency(long frequency)
60#endif
61{
62 switch(frequency)
63 {
64 case CPUFREQ_MAX:
65 DCR = (0x8200 | DEFAULT_REFRESH_TIMER);
66 /* Refresh timer for bypass frequency */
67 PLLCR &= ~1; /* Bypass mode */
68 timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false);
69 PLLCR = 0x0102c049 | (PLLCR & 0x70C00000);
70 CSCR0 = 0x00001180; /* Flash: 4 wait states */
71 CSCR3 = 0x00001180; /* LCD: 4 wait states */
72 while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked.
73 This may take up to 10ms! */
74 timers_adjust_prescale(CPUFREQ_MAX_MULT, true);
75 DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */
76 cpu_frequency = CPUFREQ_MAX;
77 IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(3<<10);
78 /* BUFEN2 enable on /CS2 | CS2Post 1 clock| CS2Pre 3 clocks*/
79 IDECONFIG2 = (1<<18)|(1<<16)|(1<<8)|(1<<0); /* TA /CS2 enable + CS2wait */
80
81 and_l(~(0x07<<16), &ADCONFIG);
82 or_l(((1<<7)|(1<<2)|(1<<0))<<16, &ADCONFIG); /* adclk = busclk/32 */
83
84 break;
85
86 case CPUFREQ_NORMAL:
87 DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER;
88 /* Refresh timer for bypass frequency */
89 PLLCR &= ~1; /* Bypass mode */
90 timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false);
91 PLLCR = 0x05028045 | (PLLCR & 0x70C00000);
92 CSCR0 = 0x00000580; /* Flash: 1 wait state */
93 CSCR3 = 0x00000980; /* LCD: 0 wait states */
94 while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked.
95 This may take up to 10ms! */
96 timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true);
97 DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */
98 cpu_frequency = CPUFREQ_NORMAL;
99 IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10);
100 IDECONFIG2 = (1<<18)|(1<<16);
101
102 and_l(~(0x07<<16), &ADCONFIG);
103 or_l(((1<<7)|(1<<1)|(1<<0))<<16, &ADCONFIG); /* adclk = busclk/8 */
104
105 break;
106 default:
107 DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER;
108 /* Refresh timer for bypass frequency */
109 PLLCR &= ~1; /* Bypass mode */
110 timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true);
111 /* Power down PLL, but keep CLSEL and CRSEL */
112 PLLCR = 0x00000200 | (PLLCR & 0x70C00000);
113 CSCR0 = 0x00000180; /* Flash: 0 wait states */
114 CSCR3 = 0x00000980; /* LCD: 0 wait states */
115 DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */
116 cpu_frequency = CPUFREQ_DEFAULT;
117 IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10);
118 IDECONFIG2 = (1<<18)|(1<<16);
119
120 and_l(~(0x07<<16), &ADCONFIG);
121 or_l(((1<<7)|(1<<0))<<16, &ADCONFIG); /* adclk = busclk/2 */
122
123 break;
124 }
125}