diff options
Diffstat (limited to 'firmware/target/coldfire/iriver/system-iriver.c')
-rw-r--r-- | firmware/target/coldfire/iriver/system-iriver.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iriver/system-iriver.c b/firmware/target/coldfire/iriver/system-iriver.c new file mode 100644 index 0000000000..5f404fb8cf --- /dev/null +++ b/firmware/target/coldfire/iriver/system-iriver.c | |||
@@ -0,0 +1,133 @@ | |||
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 | #include "pcf50606.h" | ||
26 | |||
27 | #if MEM < 32 | ||
28 | #define MAX_REFRESH_TIMER 59 | ||
29 | #define NORMAL_REFRESH_TIMER 21 | ||
30 | #define DEFAULT_REFRESH_TIMER 4 | ||
31 | #else | ||
32 | #define MAX_REFRESH_TIMER 29 | ||
33 | #define NORMAL_REFRESH_TIMER 10 | ||
34 | #define DEFAULT_REFRESH_TIMER 1 | ||
35 | #endif | ||
36 | |||
37 | #ifdef IRIVER_H300_SERIES | ||
38 | #define RECALC_DELAYS(f) \ | ||
39 | pcf50606_i2c_recalc_delay(f) | ||
40 | #else | ||
41 | #define RECALC_DELAYS(f) | ||
42 | #endif | ||
43 | |||
44 | #ifdef HAVE_SERIAL | ||
45 | #define BAUD_RATE 57600 | ||
46 | #define BAUDRATE_DIV_DEFAULT (CPUFREQ_DEFAULT/(BAUD_RATE*32*2)) | ||
47 | #define BAUDRATE_DIV_NORMAL (CPUFREQ_NORMAL/(BAUD_RATE*32*2)) | ||
48 | #define BAUDRATE_DIV_MAX (CPUFREQ_MAX/(BAUD_RATE*32*2)) | ||
49 | #endif | ||
50 | |||
51 | void set_cpu_frequency (long) __attribute__ ((section (".icode"))); | ||
52 | void set_cpu_frequency(long frequency) | ||
53 | { | ||
54 | switch(frequency) | ||
55 | { | ||
56 | case CPUFREQ_MAX: | ||
57 | DCR = (0x8200 | DEFAULT_REFRESH_TIMER); | ||
58 | /* Refresh timer for bypass frequency */ | ||
59 | PLLCR &= ~1; /* Bypass mode */ | ||
60 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); | ||
61 | RECALC_DELAYS(CPUFREQ_MAX); | ||
62 | PLLCR = 0x11c56005; | ||
63 | CSCR0 = 0x00001180; /* Flash: 4 wait states */ | ||
64 | CSCR1 = 0x00000980; /* LCD: 2 wait states */ | ||
65 | #if CONFIG_USBOTG == USBOTG_ISP1362 | ||
66 | CSCR3 = 0x00002180; /* USBOTG: 8 wait states */ | ||
67 | #endif | ||
68 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. | ||
69 | This may take up to 10ms! */ | ||
70 | timers_adjust_prescale(CPUFREQ_MAX_MULT, true); | ||
71 | DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */ | ||
72 | cpu_frequency = CPUFREQ_MAX; | ||
73 | IDECONFIG1 = 0x10100000 | (1 << 13) | (2 << 10); | ||
74 | /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */ | ||
75 | IDECONFIG2 = 0x40000 | (2 << 8); /* TA enable + CS2wait */ | ||
76 | |||
77 | #ifdef HAVE_SERIAL | ||
78 | UBG10 = BAUDRATE_DIV_MAX >> 8; | ||
79 | UBG20 = BAUDRATE_DIV_MAX & 0xff; | ||
80 | #endif | ||
81 | break; | ||
82 | |||
83 | case CPUFREQ_NORMAL: | ||
84 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; | ||
85 | /* Refresh timer for bypass frequency */ | ||
86 | PLLCR &= ~1; /* Bypass mode */ | ||
87 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); | ||
88 | RECALC_DELAYS(CPUFREQ_NORMAL); | ||
89 | PLLCR = 0x13c5e005; | ||
90 | CSCR0 = 0x00000580; /* Flash: 1 wait state */ | ||
91 | CSCR1 = 0x00000180; /* LCD: 0 wait states */ | ||
92 | #if CONFIG_USBOTG == USBOTG_ISP1362 | ||
93 | CSCR3 = 0x00000580; /* USBOTG: 1 wait state */ | ||
94 | #endif | ||
95 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. | ||
96 | This may take up to 10ms! */ | ||
97 | timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true); | ||
98 | DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */ | ||
99 | cpu_frequency = CPUFREQ_NORMAL; | ||
100 | IDECONFIG1 = 0x10100000 | (0 << 13) | (1 << 10); | ||
101 | /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */ | ||
102 | IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ | ||
103 | |||
104 | #ifdef HAVE_SERIAL | ||
105 | UBG10 = BAUDRATE_DIV_NORMAL >> 8; | ||
106 | UBG20 = BAUDRATE_DIV_NORMAL & 0xff; | ||
107 | #endif | ||
108 | break; | ||
109 | default: | ||
110 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; | ||
111 | /* Refresh timer for bypass frequency */ | ||
112 | PLLCR &= ~1; /* Bypass mode */ | ||
113 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true); | ||
114 | RECALC_DELAYS(CPUFREQ_DEFAULT); | ||
115 | PLLCR = 0x10c00200; /* Power down PLL, but keep CLSEL and CRSEL */ | ||
116 | CSCR0 = 0x00000180; /* Flash: 0 wait states */ | ||
117 | CSCR1 = 0x00000180; /* LCD: 0 wait states */ | ||
118 | #if CONFIG_USBOTG == USBOTG_ISP1362 | ||
119 | CSCR3 = 0x00000180; /* USBOTG: 0 wait states */ | ||
120 | #endif | ||
121 | DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */ | ||
122 | cpu_frequency = CPUFREQ_DEFAULT; | ||
123 | IDECONFIG1 = 0x10100000 | (0 << 13) | (1 << 10); | ||
124 | /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */ | ||
125 | IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ | ||
126 | |||
127 | #ifdef HAVE_SERIAL | ||
128 | UBG10 = BAUDRATE_DIV_DEFAULT >> 8; | ||
129 | UBG20 = BAUDRATE_DIV_DEFAULT & 0xff; | ||
130 | #endif | ||
131 | break; | ||
132 | } | ||
133 | } | ||