2007-04-22 12:03:17 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Alan Korr
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "system.h"
|
|
|
|
#include "thread.h"
|
2007-07-26 10:46:17 +00:00
|
|
|
#include "i2s.h"
|
2007-09-28 09:00:04 +00:00
|
|
|
#include "i2c-pp.h"
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-04-22 12:27:54 +00:00
|
|
|
#if NUM_CORES > 1
|
|
|
|
struct mutex boostctrl_mtx NOCACHEBSS_ATTR;
|
|
|
|
#endif
|
|
|
|
|
2007-04-22 12:03:17 +00:00
|
|
|
#ifndef BOOTLOADER
|
|
|
|
extern void TIMER1(void);
|
|
|
|
extern void TIMER2(void);
|
2007-07-31 09:33:45 +00:00
|
|
|
extern void ipod_mini_button_int(void); /* iPod Mini 1st gen only */
|
|
|
|
extern void ipod_4g_button_int(void); /* iPod 4th gen and higher only */
|
|
|
|
#ifdef SANSA_E200
|
|
|
|
extern void button_int(void);
|
|
|
|
extern void clickwheel_int(void);
|
|
|
|
extern void microsd_int(void);
|
|
|
|
#endif
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-08-27 16:04:32 +00:00
|
|
|
#ifdef HAVE_USBSTACK
|
|
|
|
#include "usbstack/core.h"
|
|
|
|
#endif
|
|
|
|
|
2007-04-22 12:03:17 +00:00
|
|
|
void irq(void)
|
|
|
|
{
|
|
|
|
if(CURRENT_CORE == CPU)
|
|
|
|
{
|
2007-08-27 16:04:32 +00:00
|
|
|
if (CPU_INT_STAT & TIMER1_MASK) {
|
2007-04-22 12:03:17 +00:00
|
|
|
TIMER1();
|
2007-08-27 16:04:32 +00:00
|
|
|
#ifdef HAVE_USBSTACK
|
|
|
|
usb_stack_irq();
|
|
|
|
#endif
|
|
|
|
} else if (CPU_INT_STAT & TIMER2_MASK)
|
2007-04-22 12:03:17 +00:00
|
|
|
TIMER2();
|
2007-07-31 09:33:45 +00:00
|
|
|
#if defined(IPOD_MINI) /* Mini 1st gen only, mini 2nd gen uses iPod 4G code */
|
2007-04-22 12:03:17 +00:00
|
|
|
else if (CPU_HI_INT_STAT & GPIO_MASK)
|
|
|
|
ipod_mini_button_int();
|
2007-07-31 09:33:45 +00:00
|
|
|
#elif CONFIG_KEYPAD == IPOD_4G_PAD /* except Mini 1st gen, handled above */
|
|
|
|
else if (CPU_HI_INT_STAT & I2C_MASK)
|
|
|
|
ipod_4g_button_int();
|
|
|
|
#elif defined(SANSA_E200)
|
2007-06-30 02:08:27 +00:00
|
|
|
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
|
|
|
|
if (GPIOA_INT_STAT & 0x80)
|
|
|
|
microsd_int();
|
|
|
|
}
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO1_MASK) {
|
2007-05-11 08:09:49 +00:00
|
|
|
if (GPIOF_INT_STAT & 0xff)
|
|
|
|
button_int();
|
|
|
|
if (GPIOH_INT_STAT & 0xc0)
|
|
|
|
clickwheel_int();
|
|
|
|
}
|
2007-06-03 14:31:42 +00:00
|
|
|
#endif
|
2007-04-22 12:03:17 +00:00
|
|
|
} else {
|
2007-09-28 10:20:02 +00:00
|
|
|
if (COP_INT_STAT & TIMER2_MASK)
|
2007-04-22 12:03:17 +00:00
|
|
|
TIMER2();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* BOOTLOADER */
|
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
/* TODO: The following function has been lifted straight from IPL, and
|
|
|
|
hence has a lot of numeric addresses used straight. I'd like to use
|
2007-04-22 12:03:17 +00:00
|
|
|
#defines for these, but don't know what most of them are for or even what
|
|
|
|
they should be named. Because of this I also have no way of knowing how
|
2007-07-26 15:07:16 +00:00
|
|
|
to extend the funtions to do alternate cache configurations. */
|
2007-04-22 12:03:17 +00:00
|
|
|
|
|
|
|
#ifndef BOOTLOADER
|
2007-09-28 10:20:02 +00:00
|
|
|
void flush_icache(void) ICODE_ATTR;
|
|
|
|
void flush_icache(void)
|
|
|
|
{
|
|
|
|
if (CACHE_CTL & CACHE_ENABLE)
|
|
|
|
{
|
|
|
|
outl(inl(0xf000f044) | 0x2, 0xf000f044);
|
|
|
|
while ((CACHE_CTL & 0x8000) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void invalidate_icache(void) ICODE_ATTR;
|
|
|
|
void invalidate_icache(void)
|
|
|
|
{
|
|
|
|
if (CACHE_CTL & CACHE_ENABLE)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
outl(inl(0xf000f044) | 0x6, 0xf000f044);
|
|
|
|
while ((CACHE_CTL & 0x8000) != 0);
|
|
|
|
for (i = 0x10000000; i < 0x10002000; i += 16)
|
|
|
|
inb(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_cache(void)
|
2007-04-22 12:03:17 +00:00
|
|
|
{
|
|
|
|
/* Initialising the cache in the iPod bootloader prevents Rockbox from starting */
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* cache init mode? */
|
2007-09-28 10:20:02 +00:00
|
|
|
CACHE_CTL |= CACHE_INIT;
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
/* what's this do? */
|
|
|
|
outl(inl(0x60006044) | (CURRENT_CORE == CPU ? 0x10 : 0x20),
|
|
|
|
0x60006044);
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
outl(0xc00, 0xf000f040);
|
|
|
|
outl(0xfc0, 0xf000f044);
|
2007-04-22 12:03:17 +00:00
|
|
|
|
|
|
|
/* enable cache */
|
2007-09-28 10:20:02 +00:00
|
|
|
CACHE_CTL |= CACHE_INIT | CACHE_ENABLE | CACHE_RUN;
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
/* fill cache from physical address - do we have a better candidate for
|
|
|
|
an 8KB unchanging memory range? */
|
2007-04-22 12:03:17 +00:00
|
|
|
for (i = 0x10000000; i < 0x10002000; i += 16)
|
|
|
|
inb(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
void set_cpu_frequency(long frequency)
|
2007-07-26 15:07:16 +00:00
|
|
|
#else
|
|
|
|
static void pp_set_cpu_frequency(long frequency)
|
|
|
|
#endif
|
2007-04-22 12:03:17 +00:00
|
|
|
{
|
2007-07-26 15:07:16 +00:00
|
|
|
unsigned long clcd_clock_src;
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
|
2007-04-22 12:03:17 +00:00
|
|
|
/* Using mutex or spinlock isn't safe here. */
|
|
|
|
while (test_and_set(&boostctrl_mtx.locked, 1)) ;
|
2007-07-26 15:07:16 +00:00
|
|
|
#endif
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-09-06 03:28:58 +00:00
|
|
|
#if defined(SANSA_E200) || defined(SANSA_C200)
|
2007-07-26 10:46:17 +00:00
|
|
|
i2s_scale_attn_level(CPUFREQ_DEFAULT);
|
|
|
|
#endif
|
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
cpu_frequency = frequency;
|
|
|
|
clcd_clock_src = CLCD_CLOCK_SRC; /* save selected color LCD clock source */
|
2007-07-02 05:16:40 +00:00
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
switch (frequency)
|
|
|
|
{
|
2007-07-31 21:13:35 +00:00
|
|
|
/* Note: The PP5022 PLL must be run at >= 96MHz
|
|
|
|
* Bits 20..21 select the post divider (1/2/4/8).
|
|
|
|
* PP5026 is similar to PP5022 except it doesn't
|
|
|
|
* have this limitation (and the post divider?) */
|
2007-07-26 15:07:16 +00:00
|
|
|
case CPUFREQ_MAX:
|
2007-07-31 20:48:49 +00:00
|
|
|
CLOCK_SOURCE = 0x10007772; /* source #1: 24MHz, #2, #3, #4: PLL */
|
|
|
|
CLCD_CLOCK_SRC &= ~0xc0000000; /* select 24MHz as color LCD clock source */
|
|
|
|
DEV_TIMING1 = 0x00000808;
|
2007-07-31 21:13:35 +00:00
|
|
|
#if CONFIG_CPU == PP5020
|
2007-07-31 20:48:49 +00:00
|
|
|
PLL_CONTROL = 0x8a020a03; /* 10/3 * 24MHz */
|
|
|
|
PLL_STATUS = 0xd19b; /* unlock frequencies > 66MHz */
|
|
|
|
PLL_CONTROL = 0x8a020a03; /* repeat setup */
|
|
|
|
udelay(500); /* wait for relock */
|
2007-07-26 15:07:16 +00:00
|
|
|
#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
|
2007-07-31 20:48:49 +00:00
|
|
|
PLL_CONTROL = 0x8a121403; /* (20/3 * 24MHz) / 2 */
|
2007-07-26 15:07:16 +00:00
|
|
|
udelay(250);
|
|
|
|
while (!(PLL_STATUS & 0x80000000)); /* wait for relock */
|
2007-07-31 21:13:35 +00:00
|
|
|
#endif
|
2007-07-26 15:07:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CPUFREQ_NORMAL:
|
2007-07-31 20:48:49 +00:00
|
|
|
CLOCK_SOURCE = 0x10007772; /* source #1: 24MHz, #2, #3, #4: PLL */
|
|
|
|
CLCD_CLOCK_SRC &= ~0xc0000000; /* select 24MHz as color LCD clock source */
|
|
|
|
DEV_TIMING1 = 0x00000303;
|
2007-07-31 21:13:35 +00:00
|
|
|
#if CONFIG_CPU == PP5020
|
|
|
|
PLL_CONTROL = 0x8a020504; /* 5/4 * 24MHz */
|
|
|
|
udelay(500); /* wait for relock */
|
|
|
|
#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
|
2007-07-31 20:48:49 +00:00
|
|
|
PLL_CONTROL = 0x8a220501; /* (5/1 * 24MHz) / 4 */
|
2007-07-26 15:07:16 +00:00
|
|
|
udelay(250);
|
|
|
|
while (!(PLL_STATUS & 0x80000000)); /* wait for relock */
|
2007-07-31 21:13:35 +00:00
|
|
|
#endif
|
2007-07-26 15:07:16 +00:00
|
|
|
break;
|
|
|
|
|
2007-07-31 20:48:49 +00:00
|
|
|
case CPUFREQ_SLEEP:
|
|
|
|
CLOCK_SOURCE = 0x10002202; /* source #2: 32kHz, #1, #3, #4: 24MHz */
|
|
|
|
CLCD_CLOCK_SRC &= ~0xc0000000; /* select 24MHz as color LCD clock source */
|
|
|
|
PLL_CONTROL &= ~0x80000000; /* disable PLL */
|
|
|
|
udelay(10000); /* let 32kHz source stabilize? */
|
|
|
|
break;
|
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
default:
|
2007-07-31 20:48:49 +00:00
|
|
|
CLOCK_SOURCE = 0x10002222; /* source #1, #2, #3, #4: 24MHz */
|
|
|
|
CLCD_CLOCK_SRC &= ~0xc0000000; /* select 24MHz as color LCD clock source */
|
|
|
|
DEV_TIMING1 = 0x00000303;
|
2007-07-26 15:07:16 +00:00
|
|
|
PLL_CONTROL &= ~0x80000000; /* disable PLL */
|
|
|
|
cpu_frequency = CPUFREQ_DEFAULT;
|
|
|
|
break;
|
|
|
|
}
|
2007-08-01 12:51:06 +00:00
|
|
|
CLOCK_SOURCE = (CLOCK_SOURCE & ~0xf0000000) | 0x20000000; /* select source #2 */
|
2007-07-26 05:06:11 +00:00
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
CLCD_CLOCK_SRC; /* dummy read (to sync the write pipeline??) */
|
|
|
|
CLCD_CLOCK_SRC = clcd_clock_src; /* restore saved value */
|
2007-07-26 05:06:11 +00:00
|
|
|
|
2007-09-06 03:28:58 +00:00
|
|
|
#if defined(SANSA_E200) || defined(SANSA_C200)
|
2007-07-26 10:46:17 +00:00
|
|
|
i2s_scale_attn_level(frequency);
|
|
|
|
#endif
|
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
|
2007-04-22 12:03:17 +00:00
|
|
|
boostctrl_mtx.locked = 0;
|
|
|
|
#endif
|
2007-07-26 15:07:16 +00:00
|
|
|
}
|
|
|
|
#endif /* !BOOTLOADER */
|
2007-04-22 12:03:17 +00:00
|
|
|
|
|
|
|
void system_init(void)
|
|
|
|
{
|
|
|
|
#ifndef BOOTLOADER
|
|
|
|
if (CURRENT_CORE == CPU)
|
|
|
|
{
|
2007-09-20 02:46:11 +00:00
|
|
|
#if defined(SANSA_E200) || defined(SANSA_C200)
|
2007-05-17 10:14:17 +00:00
|
|
|
/* Reset all devices */
|
2007-09-20 02:46:11 +00:00
|
|
|
outl(inl(0x60006008) | 0x20, 0x60006008);
|
2007-05-17 10:14:17 +00:00
|
|
|
DEV_RS = 0x3bfffef8;
|
|
|
|
outl(0xffffffff, 0x60006008);
|
|
|
|
DEV_RS = 0;
|
|
|
|
outl(0x00000000, 0x60006008);
|
2007-09-28 10:20:02 +00:00
|
|
|
#elif defined (IRIVER_H10)
|
|
|
|
DEV_RS = 0x3ffffef8;
|
|
|
|
outl(0xffffffff, 0x60006008);
|
|
|
|
outl(inl(0x70000024) | 0xc0, 0x70000024);
|
|
|
|
DEV_RS = 0;
|
|
|
|
outl(0x00000000, 0x60006008);
|
2007-05-17 10:14:17 +00:00
|
|
|
#endif
|
2007-04-22 12:03:17 +00:00
|
|
|
/* Remap the flash ROM from 0x00000000 to 0x20000000. */
|
|
|
|
MMAP3_LOGICAL = 0x20000000 | 0x3a00;
|
|
|
|
MMAP3_PHYSICAL = 0x00000000 | 0x3f84;
|
|
|
|
|
|
|
|
/* disable all irqs */
|
|
|
|
COP_HI_INT_CLR = -1;
|
|
|
|
CPU_HI_INT_CLR = -1;
|
|
|
|
HI_INT_FORCED_CLR = -1;
|
|
|
|
|
|
|
|
COP_INT_CLR = -1;
|
|
|
|
CPU_INT_CLR = -1;
|
|
|
|
INT_FORCED_CLR = -1;
|
2007-05-11 08:09:49 +00:00
|
|
|
|
|
|
|
GPIOA_INT_EN = 0;
|
|
|
|
GPIOB_INT_EN = 0;
|
|
|
|
GPIOC_INT_EN = 0;
|
|
|
|
GPIOD_INT_EN = 0;
|
|
|
|
GPIOE_INT_EN = 0;
|
|
|
|
GPIOF_INT_EN = 0;
|
|
|
|
GPIOG_INT_EN = 0;
|
|
|
|
GPIOH_INT_EN = 0;
|
|
|
|
GPIOI_INT_EN = 0;
|
|
|
|
GPIOJ_INT_EN = 0;
|
|
|
|
GPIOK_INT_EN = 0;
|
|
|
|
GPIOL_INT_EN = 0;
|
|
|
|
|
2007-09-06 03:28:58 +00:00
|
|
|
#if defined(SANSA_E200) || defined(SANSA_C200)
|
2007-06-01 01:05:57 +00:00
|
|
|
/* outl(0x00000000, 0x6000b000); */
|
|
|
|
outl(inl(0x6000a000) | 0x80000000, 0x6000a000); /* Init DMA controller? */
|
2007-07-26 15:07:16 +00:00
|
|
|
#endif
|
2007-06-01 01:05:57 +00:00
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
DEV_INIT |= 1 << 30; /* enable PLL power */
|
2007-06-01 01:05:57 +00:00
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
#if NUM_CORES > 1
|
2007-04-22 12:03:17 +00:00
|
|
|
spinlock_init(&boostctrl_mtx);
|
|
|
|
#endif
|
2007-07-26 15:07:16 +00:00
|
|
|
#else
|
|
|
|
pp_set_cpu_frequency(CPUFREQ_MAX);
|
2007-04-22 12:03:17 +00:00
|
|
|
#endif
|
2007-07-26 15:07:16 +00:00
|
|
|
}
|
2007-06-01 01:05:57 +00:00
|
|
|
|
2007-09-28 10:20:02 +00:00
|
|
|
init_cache();
|
2007-06-01 01:05:57 +00:00
|
|
|
#endif /* BOOTLOADER */
|
2007-04-22 12:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void system_reboot(void)
|
|
|
|
{
|
|
|
|
/* Reboot */
|
2007-09-27 02:50:50 +00:00
|
|
|
#ifdef SANSA_C200
|
|
|
|
CACHE_CTL &= ~0x10;
|
|
|
|
|
2007-09-28 07:56:20 +00:00
|
|
|
pp_i2c_send( 0x46, 0x23, 0x0); /* backlight off */
|
|
|
|
|
|
|
|
/* Magic used by the c200 OF: 0x23066000
|
|
|
|
Magic used by the c200 BL: 0x23066b7b
|
2007-09-27 02:50:50 +00:00
|
|
|
In both cases, the OF executes these 2 commands from iram. */
|
2007-09-28 07:56:20 +00:00
|
|
|
outl(0x23066b7b, 0x70000008);
|
2007-09-27 02:50:50 +00:00
|
|
|
DEV_RS = DEV_SYSTEM;
|
|
|
|
#else
|
2007-04-22 12:03:17 +00:00
|
|
|
DEV_RS |= DEV_SYSTEM;
|
2007-09-27 02:50:50 +00:00
|
|
|
#endif
|
2007-04-22 12:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int system_memory_guard(int newmode)
|
|
|
|
{
|
|
|
|
(void)newmode;
|
|
|
|
return 0;
|
|
|
|
}
|