1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr
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 ****************************************************************************/
26 #include "ata-sd-target.h"
27 #include "button-target.h"
28 #include "usb-target.h"
32 extern void TIMER1(void);
33 extern void TIMER2(void);
34 extern void SERIAL0(void);
35 extern void ipod_mini_button_int(void); /* iPod Mini 1st gen only */
36 extern void ipod_4g_button_int(void); /* iPod 4th gen and higher only */
38 #if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
39 static struct corelock cpufreq_cl SHAREDBSS_ATTR
;
42 void __attribute__((interrupt("IRQ"))) irq_handler(void)
44 if(CURRENT_CORE
== CPU
)
46 if (CPU_INT_STAT
& TIMER1_MASK
) {
49 else if (CPU_INT_STAT
& TIMER2_MASK
) {
53 /* Rather high priority - place near front */
54 else if (CPU_INT_STAT
& USB_MASK
) {
58 #if defined(IPOD_MINI) /* Mini 1st gen only, mini 2nd gen uses iPod 4G code */
59 else if (CPU_HI_INT_STAT
& GPIO0_MASK
) {
60 if ((GPIOA_INT_STAT
& 0x3f) || (GPIOB_INT_STAT
& 0x30))
61 ipod_mini_button_int();
62 if (GPIOC_INT_STAT
& 0x02)
63 firewire_insert_int();
64 if (GPIOD_INT_STAT
& 0x08)
68 #elif CONFIG_KEYPAD == IPOD_4G_PAD /* except Mini 1st gen, handled above */
69 else if (CPU_HI_INT_STAT
& I2C_MASK
) {
72 #if defined(IPOD_COLOR) || defined(IPOD_MINI2G) || defined(IPOD_4G)
73 else if (CPU_HI_INT_STAT
& GPIO0_MASK
) {
74 if (GPIOC_INT_STAT
& 0x02)
75 firewire_insert_int();
76 if (GPIOD_INT_STAT
& 0x08)
79 #elif defined(IPOD_NANO) || defined(IPOD_VIDEO)
80 else if (CPU_HI_INT_STAT
& GPIO2_MASK
) {
81 if (GPIOL_INT_STAT
& 0x10)
85 /* end CONFIG_KEYPAD == IPOD_4G_PAD */
86 #elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
87 else if (CPU_HI_INT_STAT
& GPIO2_MASK
) {
88 if (GPIOL_INT_STAT
& 0x04)
91 /* end IRIVER_H10 || IRIVER_H10_5GB */
92 #elif defined(SANSA_E200)
93 else if (CPU_HI_INT_STAT
& GPIO0_MASK
) {
95 if (GPIOA_INT_STAT
& 0x80)
98 if (GPIOB_INT_STAT
& 0x10)
101 else if (CPU_HI_INT_STAT
& GPIO1_MASK
) {
102 if (GPIOF_INT_STAT
& 0xff)
104 if (GPIOH_INT_STAT
& 0xc0)
108 #elif defined(SANSA_C200)
109 else if (CPU_HI_INT_STAT
& GPIO1_MASK
) {
110 if (GPIOH_INT_STAT
& 0x02)
114 else if (CPU_HI_INT_STAT
& GPIO2_MASK
) {
115 if (GPIOL_INT_STAT
& 0x08)
120 #elif defined(MROBE_100)
121 else if (CPU_HI_INT_STAT
& GPIO0_MASK
) {
122 if (GPIOD_INT_STAT
& 0x02)
125 else if (CPU_HI_INT_STAT
& GPIO2_MASK
) {
126 if (GPIOL_INT_STAT
& 0x04)
130 #elif defined(PHILIPS_SA9200)
131 else if (CPU_HI_INT_STAT
& GPIO1_MASK
) {
132 if (GPIOF_INT_STAT
& 0x80)
135 /* end PHILIPS_SA9200 */
136 #elif defined(PHILIPS_HDD1630)
137 else if (CPU_HI_INT_STAT
& GPIO0_MASK
) {
138 if (GPIOA_INT_STAT
& 0x20)
141 else if (CPU_HI_INT_STAT
& GPIO1_MASK
) {
142 if (GPIOE_INT_STAT
& 0x04)
145 /* end PHILIPS_HDD1630 */
147 #ifdef IPOD_ACCESSORY_PROTOCOL
148 else if (CPU_HI_INT_STAT
& SER0_MASK
) {
153 if (COP_INT_STAT
& TIMER2_MASK
)
157 #endif /* BOOTLOADER */
159 /* TODO: The following function has been lifted straight from IPL, and
160 hence has a lot of numeric addresses used straight. I'd like to use
161 #defines for these, but don't know what most of them are for or even what
162 they should be named. Because of this I also have no way of knowing how
163 to extend the funtions to do alternate cache configurations. */
166 void ICODE_ATTR
cpucache_flush(void)
168 if (CACHE_CTL
& CACHE_CTL_ENABLE
)
170 CACHE_OPERATION
|= CACHE_OP_FLUSH
;
171 while ((CACHE_CTL
& CACHE_CTL_BUSY
) != 0);
176 void ICODE_ATTR
cpucache_invalidate(void)
178 if (CACHE_CTL
& CACHE_CTL_ENABLE
)
180 CACHE_OPERATION
|= CACHE_OP_FLUSH
| CACHE_OP_INVALIDATE
;
181 while ((CACHE_CTL
& CACHE_CTL_BUSY
) != 0);
186 static void init_cache(void)
188 /* Initialising the cache in the iPod bootloader prevents Rockbox from starting */
190 /* cache init mode */
191 CACHE_CTL
|= CACHE_CTL_INIT
;
193 /* what's this do? */
194 CACHE_PRIORITY
|= CURRENT_CORE
== CPU
? 0x10 : 0x20;
196 /* Cache if (addr & mask) >> 16 == (mask & match) >> 16:
197 * yes: 0x00000000 - 0x03ffffff
198 * no: 0x04000000 - 0x1fffffff
199 * yes: 0x20000000 - 0x23ffffff
200 * no: 0x24000000 - 0x3fffffff
202 CACHE_MASK
= 0x00001c00;
203 CACHE_OPERATION
= 0xfc0;
206 CACHE_CTL
|= CACHE_CTL_INIT
| CACHE_CTL_ENABLE
| CACHE_CTL_RUN
;
209 #endif /* !BOOTLOADER */
211 /* We need this for Sansas since we boost the cpu in their bootloader */
212 #if !defined(BOOTLOADER) || defined(SANSA_E200) || defined(SANSA_C200)
213 void scale_suspend_core(bool suspend
) ICODE_ATTR
;
214 void scale_suspend_core(bool suspend
)
216 unsigned int core
= CURRENT_CORE
;
217 IF_COP( unsigned int othercore
= 1 - core
; )
218 static int oldstatus IBSS_ATTR
;
222 oldstatus
= disable_interrupt_save(IRQ_FIQ_STATUS
);
223 IF_COP( PROC_CTL(othercore
) = 0x40000000; nop
; )
224 PROC_CTL(core
) = 0x48000003; nop
;
228 PROC_CTL(core
) = 0x4800001f; nop
;
229 IF_COP( PROC_CTL(othercore
) = 0x00000000; nop
; )
230 restore_interrupt(oldstatus
);
234 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
235 void set_cpu_frequency(long frequency
) ICODE_ATTR
;
236 void set_cpu_frequency(long frequency
)
238 static void pp_set_cpu_frequency(long frequency
)
241 #if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
242 corelock_lock(&cpufreq_cl
);
247 /* Note1: The PP5022 PLL must be run at >= 96MHz
248 * Bits 20..21 select the post divider (1/2/4/8).
249 * PP5026 is similar to PP5022 except it doesn't
250 * have this limitation (and the post divider?)
251 * Note2: CLOCK_SOURCE is set via 0=32kHz, 1=16MHz,
252 * 2=24MHz, 3=33MHz, 4=48MHz, 5=SLOW, 6=FAST, 7=PLL.
253 * SLOW = 24MHz / (DIV_SLOW + 1), DIV = Bits 16-19
254 * FAST = PLL / (DIV_FAST + 1), DIV = Bits 20-23 */
256 cpu_frequency
= CPUFREQ_SLEEP
;
257 PLL_CONTROL
|= 0x0c000000;
258 scale_suspend_core(true);
259 CLOCK_SOURCE
= 0x20000000; /* source #1, #2, #3, #4: 32kHz (#2 active) */
260 scale_suspend_core(false);
261 PLL_CONTROL
&= ~0x80000000; /* disable PLL */
262 DEV_INIT2
&= ~INIT_PLL
; /* disable PLL power */
266 cpu_frequency
= CPUFREQ_MAX
;
267 DEV_INIT2
|= INIT_PLL
; /* enable PLL power */
268 PLL_CONTROL
|= 0x88000000; /* enable PLL */
269 scale_suspend_core(true);
270 CLOCK_SOURCE
= 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
271 DEV_TIMING1
= 0x00000303;
272 scale_suspend_core(false);
273 #if defined(IPOD_MINI2G)
274 MLCD_SCLK_DIV
= 0x00000001; /* Mono LCD bridge serial clock divider */
275 #elif defined(IPOD_NANO)
276 IDE0_CFG
|= 0x10000000; /* set ">65MHz" bit */
278 #if CONFIG_CPU == PP5020
279 PLL_CONTROL
= 0x8a020a03; /* 80 MHz = 10/3 * 24MHz */
280 PLL_STATUS
= 0xd19b; /* unlock frequencies > 66MHz */
281 PLL_CONTROL
= 0x8a020a03; /* repeat setup */
282 udelay(500); /* wait for relock */
283 #elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
284 PLL_CONTROL
= 0x8a121403; /* 80 MHz = (20/3 * 24MHz) / 2 */
285 while (!(PLL_STATUS
& 0x80000000)); /* wait for relock */
287 scale_suspend_core(true);
288 DEV_TIMING1
= 0x00000808;
289 CLOCK_SOURCE
= 0x20007777; /* source #1, #2, #3, #4: PLL (#2 active) */
290 scale_suspend_core(false);
292 #if 0 /******** CPUFREQ_NORMAL = 24MHz without PLL ********/
294 cpu_frequency
= CPUFREQ_NORMAL
;
295 PLL_CONTROL
|= 0x08000000;
296 scale_suspend_core(true);
297 CLOCK_SOURCE
= 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
298 DEV_TIMING1
= 0x00000303;
299 #if defined(IPOD_MINI2G)
300 MLCD_SCLK_DIV
= 0x00000000; /* Mono LCD bridge serial clock divider */
301 #elif defined(IPOD_NANO)
302 IDE0_CFG
&= ~0x10000000; /* clear ">65MHz" bit */
304 scale_suspend_core(false);
305 PLL_CONTROL
&= ~0x80000000; /* disable PLL */
306 DEV_INIT2
&= ~INIT_PLL
; /* disable PLL power */
308 #else /******** CPUFREQ_NORMAL = 30MHz with PLL ********/
310 cpu_frequency
= CPUFREQ_NORMAL
;
311 DEV_INIT2
|= INIT_PLL
; /* enable PLL power */
312 PLL_CONTROL
|= 0x88000000; /* enable PLL */
313 scale_suspend_core(true);
314 CLOCK_SOURCE
= 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
315 DEV_TIMING1
= 0x00000303;
316 scale_suspend_core(false);
317 #if defined(IPOD_MINI2G)
318 MLCD_SCLK_DIV
= 0x00000000; /* Mono LCD bridge serial clock divider */
319 #elif defined(IPOD_NANO)
320 IDE0_CFG
&= ~0x10000000; /* clear ">65MHz" bit */
322 #if CONFIG_CPU == PP5020
323 PLL_CONTROL
= 0x8a020504; /* 30 MHz = 5/4 * 24MHz */
324 udelay(500); /* wait for relock */
325 #elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
326 PLL_CONTROL
= 0x8a220501; /* 30 MHz = (5/1 * 24MHz) / 4 */
327 while (!(PLL_STATUS
& 0x80000000)); /* wait for relock */
329 scale_suspend_core(true);
330 DEV_TIMING1
= 0x00000303;
331 CLOCK_SOURCE
= 0x20007777; /* source #1, #2, #3, #4: PLL (#2 active) */
332 scale_suspend_core(false);
334 #endif /******** CPUFREQ_NORMAL end ********/
336 cpu_frequency
= CPUFREQ_DEFAULT
;
337 PLL_CONTROL
|= 0x08000000;
338 scale_suspend_core(true);
339 CLOCK_SOURCE
= 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
340 DEV_TIMING1
= 0x00000303;
341 #if defined(IPOD_MINI2G)
342 MLCD_SCLK_DIV
= 0x00000000; /* Mono LCD bridge serial clock divider */
343 #elif defined(IPOD_NANO)
344 IDE0_CFG
&= ~0x10000000; /* clear ">65MHz" bit */
346 scale_suspend_core(false);
347 PLL_CONTROL
&= ~0x80000000; /* disable PLL */
348 DEV_INIT2
&= ~INIT_PLL
; /* disable PLL power */
352 #if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
353 corelock_unlock(&cpufreq_cl
);
356 #endif /* !BOOTLOADER || SANSA_E200 || SANSA_C200 */
358 void system_init(void)
361 if (CURRENT_CORE
== CPU
)
363 #if defined (IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(IPOD_COLOR)
364 /* set minimum startup configuration */
366 DEV_EN2
= 0x00002000;
367 CACHE_PRIORITY
= 0x0000003f;
368 GPO32_VAL
= 0x20000000;
369 DEV_INIT1
= 0xdc000000;
370 DEV_INIT2
= 0x40000000;
372 /* reset all allowed devices */
374 DEV_RS2
= 0xffffdfff;
376 DEV_RS2
= 0x00000000;
377 #elif defined (IPOD_VIDEO)
378 /* set minimum startup configuration */
380 DEV_EN2
= 0x00000000;
381 CACHE_PRIORITY
= 0x0000003f;
382 GPO32_VAL
= 0x00004000;
383 DEV_INIT1
= 0x00000000;
384 DEV_INIT2
= 0x40000000;
386 /* reset all allowed devices */
388 DEV_RS2
= 0xffffffff;
390 DEV_RS2
= 0x00000000;
391 #elif defined (IPOD_NANO)
392 /* set minimum startup configuration */
394 DEV_EN2
= 0x00002000;
395 CACHE_PRIORITY
= 0x0000003f;
396 GPO32_VAL
= 0x50000000;
397 DEV_INIT1
= 0xa8000000;
398 DEV_INIT2
= 0x40000000;
400 /* reset all allowed devices */
402 DEV_RS2
= 0xffffdfff;
404 DEV_RS2
= 0x00000000;
405 #elif defined(SANSA_C200) || defined (SANSA_E200)
406 /* set minimum startup configuration */
408 DEV_EN2
= 0x00000000;
409 CACHE_PRIORITY
= 0x0000003f;
410 GPO32_VAL
= 0x10000000;
411 DEV_INIT1
= 0x54000000;
412 DEV_INIT2
= 0x40000000;
414 /* reset all allowed devices */
416 DEV_RS2
= 0xffffffff;
418 DEV_RS2
= 0x00000000;
419 #elif defined(IPOD_4G)
420 /* set minimum startup configuration */
422 DEV_EN2
= 0x00000000;
423 CACHE_PRIORITY
= 0x0000003f;
424 GPO32_VAL
= 0x02000000;
425 DEV_INIT1
= 0x00000000;
426 DEV_INIT2
= 0x40000000;
428 /* reset all allowed devices */
430 DEV_RS2
= 0xffffffff;
432 DEV_RS2
= 0x00000000;
433 #elif defined (IPOD_MINI)
435 #elif defined (IPOD_MINI2G)
437 #elif defined (MROBE_100)
439 #elif defined (ELIO_TPJ1022)
443 #if !defined(SANSA_E200) && !defined(SANSA_C200) && !defined(PHILIPS_SA9200)
444 /* Remap the flash ROM on CPU, keep hidden from COP:
445 * 0x00000000-0x3fffffff = 0x20000000-0x23ffffff */
446 MMAP1_LOGICAL
= 0x20003c00;
447 MMAP1_PHYSICAL
= 0x00003084 |
448 MMAP_PHYS_READ_MASK
| MMAP_PHYS_WRITE_MASK
|
449 MMAP_PHYS_DATA_MASK
| MMAP_PHYS_CODE_MASK
;
452 /* disable all irqs */
455 HI_INT_FORCED_CLR
= -1;
474 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
476 corelock_init(&cpufreq_cl
);
480 pp_set_cpu_frequency(CPUFREQ_MAX
);
485 #else /* BOOTLOADER */
486 if (CURRENT_CORE
== CPU
)
488 #if defined(SANSA_C200) || defined (SANSA_E200)
489 pp_set_cpu_frequency(CPUFREQ_MAX
);
492 #endif /* BOOTLOADER */
495 void ICODE_ATTR
system_reboot(void)
497 disable_interrupt(IRQ_FIQ_STATUS
);
502 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200)
503 CACHE_CTL
&= ~CACHE_CTL_VECT_REMAP
;
505 /* Magic used by the c200 OF: 0x23066000
506 Magic used by the c200 BL: 0x23066b7b
507 In both cases, the OF executes these 2 commands from iram. */
508 STRAP_OPT_A
= 0x23066b7b;
511 DEV_RS
|= DEV_SYSTEM
;
513 /* wait until reboot kicks in */
517 void system_exception_wait(void)
519 /* FIXME: we just need the right buttons */
524 PROC_CTL(CURRENT_CORE
) = 0x40000000;
528 int system_memory_guard(int newmode
)