2007-04-22 12:03:17 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Alan Korr
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-04-22 12:03:17 +00:00
|
|
|
*
|
|
|
|
* 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-10-25 09:03:47 +00:00
|
|
|
#include "as3514.h"
|
2009-07-01 10:07:22 +00:00
|
|
|
#ifdef HAVE_HOTSWAP
|
|
|
|
#include "sd-pp-target.h"
|
|
|
|
#endif
|
2008-06-29 11:03:12 +00:00
|
|
|
#include "button-target.h"
|
2007-11-22 20:51:00 +00:00
|
|
|
#include "usb_drv.h"
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2011-01-15 08:19:30 +00:00
|
|
|
#if !defined(BOOTLOADER) || defined(HAVE_BOOTLOADER_USB_MODE)
|
2007-04-22 12:03:17 +00:00
|
|
|
extern void TIMER1(void);
|
|
|
|
extern void TIMER2(void);
|
2008-12-25 01:46:16 +00:00
|
|
|
extern void SERIAL0(void);
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2009-02-03 12:16:45 +00:00
|
|
|
#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
|
|
|
|
static struct corelock cpufreq_cl SHAREDBSS_ATTR;
|
|
|
|
#endif
|
|
|
|
|
2010-08-29 13:20:16 +00:00
|
|
|
#if defined(IPOD_VIDEO) && !defined(BOOTLOADER)
|
|
|
|
unsigned char probed_ramsize;
|
|
|
|
#endif
|
|
|
|
|
2009-01-20 16:11:59 +00:00
|
|
|
void __attribute__((interrupt("IRQ"))) irq_handler(void)
|
2007-04-22 12:03:17 +00:00
|
|
|
{
|
|
|
|
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();
|
2009-01-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
else if (CPU_INT_STAT & TIMER2_MASK) {
|
2007-04-22 12:03:17 +00:00
|
|
|
TIMER2();
|
2009-01-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
#ifdef HAVE_USBSTACK
|
|
|
|
/* Rather high priority - place near front */
|
|
|
|
else if (CPU_INT_STAT & USB_MASK) {
|
|
|
|
usb_drv_int();
|
|
|
|
}
|
|
|
|
#endif
|
2007-07-31 09:33:45 +00:00
|
|
|
#if defined(IPOD_MINI) /* Mini 1st gen only, mini 2nd gen uses iPod 4G code */
|
2009-01-22 22:05:04 +00:00
|
|
|
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
|
|
|
|
if ((GPIOA_INT_STAT & 0x3f) || (GPIOB_INT_STAT & 0x30))
|
|
|
|
ipod_mini_button_int();
|
|
|
|
if (GPIOC_INT_STAT & 0x02)
|
|
|
|
firewire_insert_int();
|
|
|
|
if (GPIOD_INT_STAT & 0x08)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
|
|
|
/* end IPOD_MINI */
|
2007-07-31 09:33:45 +00:00
|
|
|
#elif CONFIG_KEYPAD == IPOD_4G_PAD /* except Mini 1st gen, handled above */
|
2009-01-22 22:05:04 +00:00
|
|
|
else if (CPU_HI_INT_STAT & I2C_MASK) {
|
2007-07-31 09:33:45 +00:00
|
|
|
ipod_4g_button_int();
|
2009-01-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
#if defined(IPOD_COLOR) || defined(IPOD_MINI2G) || defined(IPOD_4G)
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
|
|
|
|
if (GPIOC_INT_STAT & 0x02)
|
|
|
|
firewire_insert_int();
|
|
|
|
if (GPIOD_INT_STAT & 0x08)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
|
|
|
#elif defined(IPOD_NANO) || defined(IPOD_VIDEO)
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO2_MASK) {
|
|
|
|
if (GPIOL_INT_STAT & 0x10)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* end CONFIG_KEYPAD == IPOD_4G_PAD */
|
|
|
|
#elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO2_MASK) {
|
|
|
|
if (GPIOL_INT_STAT & 0x04)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
|
|
|
/* end IRIVER_H10 || IRIVER_H10_5GB */
|
2007-07-31 09:33:45 +00:00
|
|
|
#elif defined(SANSA_E200)
|
2007-06-30 02:08:27 +00:00
|
|
|
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
|
2009-01-22 22:05:04 +00:00
|
|
|
#ifdef HAVE_HOTSWAP
|
2007-06-30 02:08:27 +00:00
|
|
|
if (GPIOA_INT_STAT & 0x80)
|
|
|
|
microsd_int();
|
2008-05-13 02:50:31 +00:00
|
|
|
#endif
|
2009-01-22 22:05:04 +00:00
|
|
|
if (GPIOB_INT_STAT & 0x10)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
2007-06-30 02:08:27 +00:00
|
|
|
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();
|
|
|
|
}
|
2009-01-22 22:05:04 +00:00
|
|
|
/* end SANSA_E200 */
|
|
|
|
#elif defined(SANSA_C200)
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO1_MASK) {
|
|
|
|
if (GPIOH_INT_STAT & 0x02)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
|
|
|
#ifdef HAVE_HOTSWAP
|
2007-11-04 13:22:17 +00:00
|
|
|
else if (CPU_HI_INT_STAT & GPIO2_MASK) {
|
|
|
|
if (GPIOL_INT_STAT & 0x08)
|
|
|
|
microsd_int();
|
|
|
|
}
|
2009-01-22 22:05:04 +00:00
|
|
|
#endif
|
|
|
|
/* end SANSA_C200 */
|
2008-02-24 04:12:16 +00:00
|
|
|
#elif defined(MROBE_100)
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
|
2009-01-22 22:05:04 +00:00
|
|
|
if (GPIOD_INT_STAT & 0x02)
|
2008-02-24 04:12:16 +00:00
|
|
|
button_int();
|
2009-07-26 14:26:14 +00:00
|
|
|
if (GPIOD_INT_STAT & 0x80)
|
|
|
|
headphones_int();
|
|
|
|
|
2009-01-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO2_MASK) {
|
|
|
|
if (GPIOL_INT_STAT & 0x04)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
|
|
|
/* end MROBE_100 */
|
|
|
|
#elif defined(PHILIPS_SA9200)
|
2009-06-19 03:41:52 +00:00
|
|
|
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
|
|
|
|
if (GPIOD_INT_STAT & 0x02)
|
|
|
|
button_int();
|
2011-01-17 12:24:41 +00:00
|
|
|
if (GPIOB_INT_STAT & 0x40)
|
2009-01-22 22:05:04 +00:00
|
|
|
usb_insert_int();
|
|
|
|
}
|
|
|
|
/* end PHILIPS_SA9200 */
|
2009-12-25 04:05:01 +00:00
|
|
|
#elif defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
|
2008-12-19 03:31:26 +00:00
|
|
|
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
|
|
|
|
if (GPIOA_INT_STAT & 0x20)
|
|
|
|
button_int();
|
2009-01-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO1_MASK) {
|
|
|
|
if (GPIOE_INT_STAT & 0x04)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
2009-12-25 04:05:01 +00:00
|
|
|
/* end PHILIPS_HDD1630 || PHILIPS_HDD6330 */
|
2009-05-25 21:10:45 +00:00
|
|
|
#elif defined(SAMSUNG_YH820) || defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
|
|
|
|
if (GPIOD_INT_STAT & 0x10)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
|
|
|
/* end SAMSUNG_YHxxx */
|
2010-01-18 19:05:20 +00:00
|
|
|
#elif defined(PBELL_VIBE500)
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO0_MASK) {
|
|
|
|
if (GPIOA_INT_STAT & 0x20)
|
|
|
|
button_int();
|
|
|
|
}
|
|
|
|
else if (CPU_HI_INT_STAT & GPIO2_MASK) {
|
|
|
|
if (GPIOL_INT_STAT & 0x04)
|
|
|
|
usb_insert_int();
|
|
|
|
}
|
|
|
|
/* end PBELL_VIBE500 */
|
2007-11-22 20:51:00 +00:00
|
|
|
#endif
|
2008-12-25 01:46:16 +00:00
|
|
|
#ifdef IPOD_ACCESSORY_PROTOCOL
|
2009-01-22 22:05:04 +00:00
|
|
|
else if (CPU_HI_INT_STAT & SER0_MASK) {
|
|
|
|
SERIAL0();
|
2007-11-22 20:51:00 +00:00
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
}
|
2011-01-15 08:19:30 +00:00
|
|
|
#endif /* BOOTLOADER || HAVE_BOOTLOADER_USB_MODE */
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2011-01-15 08:19:30 +00:00
|
|
|
#if !defined(BOOTLOADER) || defined(HAVE_BOOTLOADER_USB_MODE)
|
|
|
|
static void disable_all_interrupts(void)
|
|
|
|
{
|
|
|
|
COP_HI_INT_DIS = -1;
|
|
|
|
CPU_HI_INT_DIS = -1;
|
|
|
|
HI_INT_FORCED_CLR = -1;
|
|
|
|
|
|
|
|
COP_INT_DIS = -1;
|
|
|
|
CPU_INT_DIS = -1;
|
|
|
|
INT_FORCED_CLR = -1;
|
|
|
|
|
|
|
|
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-04-22 12:03:17 +00:00
|
|
|
|
2011-12-17 07:27:24 +00:00
|
|
|
void ICODE_ATTR commit_dcache(void)
|
2007-09-28 10:20:02 +00:00
|
|
|
{
|
2007-09-30 10:53:31 +00:00
|
|
|
if (CACHE_CTL & CACHE_CTL_ENABLE)
|
2007-09-28 10:20:02 +00:00
|
|
|
{
|
2007-09-30 10:53:31 +00:00
|
|
|
CACHE_OPERATION |= CACHE_OP_FLUSH;
|
|
|
|
while ((CACHE_CTL & CACHE_CTL_BUSY) != 0);
|
2009-02-19 20:40:03 +00:00
|
|
|
nop; nop; nop; nop;
|
2007-09-28 10:20:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-17 07:27:24 +00:00
|
|
|
void ICODE_ATTR commit_discard_idcache(void)
|
2007-09-28 10:20:02 +00:00
|
|
|
{
|
2007-09-30 10:53:31 +00:00
|
|
|
if (CACHE_CTL & CACHE_CTL_ENABLE)
|
2007-09-28 10:20:02 +00:00
|
|
|
{
|
2007-09-30 10:53:31 +00:00
|
|
|
CACHE_OPERATION |= CACHE_OP_FLUSH | CACHE_OP_INVALIDATE;
|
|
|
|
while ((CACHE_CTL & CACHE_CTL_BUSY) != 0);
|
2007-10-04 04:53:01 +00:00
|
|
|
nop; nop; nop; nop;
|
2007-09-28 10:20:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-17 07:27:24 +00:00
|
|
|
|
|
|
|
void commit_discard_dcache(void) __attribute__((alias("commit_discard_idcache")));
|
2007-09-28 10:20:02 +00:00
|
|
|
|
|
|
|
static void init_cache(void)
|
2007-04-22 12:03:17 +00:00
|
|
|
{
|
2011-01-15 08:19:30 +00:00
|
|
|
/* Initialising the cache in the iPod bootloader may prevent Rockbox from starting
|
|
|
|
* depending on the model */
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-10-04 04:53:01 +00:00
|
|
|
/* cache init mode */
|
2011-01-15 08:19:30 +00:00
|
|
|
CACHE_CTL &= ~(CACHE_CTL_ENABLE | CACHE_CTL_RUN);
|
2007-09-30 10:53:31 +00:00
|
|
|
CACHE_CTL |= CACHE_CTL_INIT;
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2011-01-15 08:19:30 +00:00
|
|
|
#ifndef BOOTLOADER
|
2007-09-28 10:20:02 +00:00
|
|
|
/* what's this do? */
|
2007-09-30 10:53:31 +00:00
|
|
|
CACHE_PRIORITY |= CURRENT_CORE == CPU ? 0x10 : 0x20;
|
2011-01-15 08:19:30 +00:00
|
|
|
#endif
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-10-04 04:53:01 +00:00
|
|
|
/* Cache if (addr & mask) >> 16 == (mask & match) >> 16:
|
|
|
|
* yes: 0x00000000 - 0x03ffffff
|
|
|
|
* no: 0x04000000 - 0x1fffffff
|
|
|
|
* yes: 0x20000000 - 0x23ffffff
|
|
|
|
* no: 0x24000000 - 0x3fffffff
|
|
|
|
*/
|
|
|
|
CACHE_MASK = 0x00001c00;
|
2007-09-30 10:53:31 +00:00
|
|
|
CACHE_OPERATION = 0xfc0;
|
2007-04-22 12:03:17 +00:00
|
|
|
|
|
|
|
/* enable cache */
|
2007-09-30 10:53:31 +00:00
|
|
|
CACHE_CTL |= CACHE_CTL_INIT | CACHE_CTL_ENABLE | CACHE_CTL_RUN;
|
2007-10-04 04:53:01 +00:00
|
|
|
nop; nop; nop; nop;
|
2007-04-22 12:03:17 +00:00
|
|
|
}
|
2011-01-17 06:50:27 +00:00
|
|
|
#endif /* BOOTLOADER || HAVE_BOOTLOADER_USB_MODE */
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2008-04-19 16:48:01 +00:00
|
|
|
/* We need this for Sansas since we boost the cpu in their bootloader */
|
2011-01-17 06:50:27 +00:00
|
|
|
#if !defined(BOOTLOADER) || (defined(SANSA_E200) || defined(SANSA_C200) || \
|
|
|
|
defined(PHILIPS_SA9200))
|
2007-10-16 01:25:17 +00:00
|
|
|
void scale_suspend_core(bool suspend) ICODE_ATTR;
|
|
|
|
void scale_suspend_core(bool suspend)
|
|
|
|
{
|
|
|
|
unsigned int core = CURRENT_CORE;
|
2008-03-21 17:20:57 +00:00
|
|
|
IF_COP( unsigned int othercore = 1 - core; )
|
2007-10-16 01:25:17 +00:00
|
|
|
static int oldstatus IBSS_ATTR;
|
|
|
|
|
|
|
|
if (suspend)
|
|
|
|
{
|
2008-03-31 06:00:23 +00:00
|
|
|
oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS);
|
2008-03-21 17:20:57 +00:00
|
|
|
IF_COP( PROC_CTL(othercore) = 0x40000000; nop; )
|
2007-10-16 01:25:17 +00:00
|
|
|
PROC_CTL(core) = 0x48000003; nop;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PROC_CTL(core) = 0x4800001f; nop;
|
2008-03-21 17:20:57 +00:00
|
|
|
IF_COP( PROC_CTL(othercore) = 0x00000000; nop; )
|
2008-03-31 06:00:23 +00:00
|
|
|
restore_interrupt(oldstatus);
|
2007-10-16 01:25:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-19 16:30:17 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2007-10-16 01:25:17 +00:00
|
|
|
void set_cpu_frequency(long frequency) ICODE_ATTR;
|
2007-04-22 12:03:17 +00:00
|
|
|
void set_cpu_frequency(long frequency)
|
2007-07-26 15:07:16 +00:00
|
|
|
#else
|
|
|
|
static void pp_set_cpu_frequency(long frequency)
|
|
|
|
#endif
|
2008-02-10 05:39:20 +00:00
|
|
|
{
|
2007-07-26 15:07:16 +00:00
|
|
|
#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
|
2009-02-03 12:16:45 +00:00
|
|
|
corelock_lock(&cpufreq_cl);
|
2007-07-26 15:07:16 +00:00
|
|
|
#endif
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
switch (frequency)
|
|
|
|
{
|
2008-02-10 05:39:20 +00:00
|
|
|
/* Note1: The PP5022 PLL must be run at >= 96MHz
|
2007-07-31 21:13:35 +00:00
|
|
|
* Bits 20..21 select the post divider (1/2/4/8).
|
|
|
|
* PP5026 is similar to PP5022 except it doesn't
|
2008-02-10 05:39:20 +00:00
|
|
|
* have this limitation (and the post divider?)
|
|
|
|
* Note2: CLOCK_SOURCE is set via 0=32kHz, 1=16MHz,
|
|
|
|
* 2=24MHz, 3=33MHz, 4=48MHz, 5=SLOW, 6=FAST, 7=PLL.
|
|
|
|
* SLOW = 24MHz / (DIV_SLOW + 1), DIV = Bits 16-19
|
|
|
|
* FAST = PLL / (DIV_FAST + 1), DIV = Bits 20-23 */
|
|
|
|
case CPUFREQ_SLEEP:
|
|
|
|
cpu_frequency = CPUFREQ_SLEEP;
|
|
|
|
PLL_CONTROL |= 0x0c000000;
|
|
|
|
scale_suspend_core(true);
|
|
|
|
CLOCK_SOURCE = 0x20000000; /* source #1, #2, #3, #4: 32kHz (#2 active) */
|
|
|
|
scale_suspend_core(false);
|
|
|
|
PLL_CONTROL &= ~0x80000000; /* disable PLL */
|
|
|
|
DEV_INIT2 &= ~INIT_PLL; /* disable PLL power */
|
|
|
|
break;
|
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
case CPUFREQ_MAX:
|
2008-02-10 05:39:20 +00:00
|
|
|
cpu_frequency = CPUFREQ_MAX;
|
|
|
|
DEV_INIT2 |= INIT_PLL; /* enable PLL power */
|
|
|
|
PLL_CONTROL |= 0x88000000; /* enable PLL */
|
|
|
|
scale_suspend_core(true);
|
|
|
|
CLOCK_SOURCE = 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
|
|
|
|
DEV_TIMING1 = 0x00000303;
|
|
|
|
scale_suspend_core(false);
|
|
|
|
#if defined(IPOD_MINI2G)
|
2007-11-08 06:52:48 +00:00
|
|
|
MLCD_SCLK_DIV = 0x00000001; /* Mono LCD bridge serial clock divider */
|
2008-02-10 05:39:20 +00:00
|
|
|
#elif defined(IPOD_NANO)
|
|
|
|
IDE0_CFG |= 0x10000000; /* set ">65MHz" bit */
|
2007-11-08 06:52:48 +00:00
|
|
|
#endif
|
2007-07-31 21:13:35 +00:00
|
|
|
#if CONFIG_CPU == PP5020
|
2008-02-10 05:39:20 +00:00
|
|
|
PLL_CONTROL = 0x8a020a03; /* 80 MHz = 10/3 * 24MHz */
|
|
|
|
PLL_STATUS = 0xd19b; /* unlock frequencies > 66MHz */
|
|
|
|
PLL_CONTROL = 0x8a020a03; /* repeat setup */
|
2007-07-31 20:48:49 +00:00
|
|
|
udelay(500); /* wait for relock */
|
2007-07-26 15:07:16 +00:00
|
|
|
#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
|
2008-02-10 05:39:20 +00:00
|
|
|
PLL_CONTROL = 0x8a121403; /* 80 MHz = (20/3 * 24MHz) / 2 */
|
2007-07-26 15:07:16 +00:00
|
|
|
while (!(PLL_STATUS & 0x80000000)); /* wait for relock */
|
2007-07-31 21:13:35 +00:00
|
|
|
#endif
|
2007-10-16 01:25:17 +00:00
|
|
|
scale_suspend_core(true);
|
2008-02-10 05:39:20 +00:00
|
|
|
DEV_TIMING1 = 0x00000808;
|
|
|
|
CLOCK_SOURCE = 0x20007777; /* source #1, #2, #3, #4: PLL (#2 active) */
|
|
|
|
scale_suspend_core(false);
|
2007-07-26 15:07:16 +00:00
|
|
|
break;
|
2008-02-10 05:39:20 +00:00
|
|
|
#if 0 /******** CPUFREQ_NORMAL = 24MHz without PLL ********/
|
2007-07-26 15:07:16 +00:00
|
|
|
case CPUFREQ_NORMAL:
|
2008-02-10 05:39:20 +00:00
|
|
|
cpu_frequency = CPUFREQ_NORMAL;
|
|
|
|
PLL_CONTROL |= 0x08000000;
|
|
|
|
scale_suspend_core(true);
|
|
|
|
CLOCK_SOURCE = 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
|
|
|
|
DEV_TIMING1 = 0x00000303;
|
|
|
|
#if defined(IPOD_MINI2G)
|
|
|
|
MLCD_SCLK_DIV = 0x00000000; /* Mono LCD bridge serial clock divider */
|
|
|
|
#elif defined(IPOD_NANO)
|
|
|
|
IDE0_CFG &= ~0x10000000; /* clear ">65MHz" bit */
|
2007-11-20 01:46:18 +00:00
|
|
|
#endif
|
2008-02-10 05:39:20 +00:00
|
|
|
scale_suspend_core(false);
|
|
|
|
PLL_CONTROL &= ~0x80000000; /* disable PLL */
|
|
|
|
DEV_INIT2 &= ~INIT_PLL; /* disable PLL power */
|
|
|
|
break;
|
|
|
|
#else /******** CPUFREQ_NORMAL = 30MHz with PLL ********/
|
|
|
|
case CPUFREQ_NORMAL:
|
|
|
|
cpu_frequency = CPUFREQ_NORMAL;
|
|
|
|
DEV_INIT2 |= INIT_PLL; /* enable PLL power */
|
|
|
|
PLL_CONTROL |= 0x88000000; /* enable PLL */
|
|
|
|
scale_suspend_core(true);
|
|
|
|
CLOCK_SOURCE = 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
|
|
|
|
DEV_TIMING1 = 0x00000303;
|
|
|
|
scale_suspend_core(false);
|
|
|
|
#if defined(IPOD_MINI2G)
|
|
|
|
MLCD_SCLK_DIV = 0x00000000; /* Mono LCD bridge serial clock divider */
|
|
|
|
#elif defined(IPOD_NANO)
|
|
|
|
IDE0_CFG &= ~0x10000000; /* clear ">65MHz" bit */
|
2007-11-08 06:52:48 +00:00
|
|
|
#endif
|
2007-07-31 21:13:35 +00:00
|
|
|
#if CONFIG_CPU == PP5020
|
2008-02-10 05:39:20 +00:00
|
|
|
PLL_CONTROL = 0x8a020504; /* 30 MHz = 5/4 * 24MHz */
|
2007-07-31 21:13:35 +00:00
|
|
|
udelay(500); /* wait for relock */
|
|
|
|
#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
|
2008-02-10 05:39:20 +00:00
|
|
|
PLL_CONTROL = 0x8a220501; /* 30 MHz = (5/1 * 24MHz) / 4 */
|
2007-07-26 15:07:16 +00:00
|
|
|
while (!(PLL_STATUS & 0x80000000)); /* wait for relock */
|
2007-07-31 21:13:35 +00:00
|
|
|
#endif
|
2007-10-16 01:25:17 +00:00
|
|
|
scale_suspend_core(true);
|
2008-03-19 13:10:02 +00:00
|
|
|
DEV_TIMING1 = 0x00000303;
|
2008-02-10 05:39:20 +00:00
|
|
|
CLOCK_SOURCE = 0x20007777; /* source #1, #2, #3, #4: PLL (#2 active) */
|
2007-10-16 01:25:17 +00:00
|
|
|
scale_suspend_core(false);
|
2007-07-31 20:48:49 +00:00
|
|
|
break;
|
2008-02-10 05:39:20 +00:00
|
|
|
#endif /******** CPUFREQ_NORMAL end ********/
|
2007-07-26 15:07:16 +00:00
|
|
|
default:
|
2008-02-10 05:39:20 +00:00
|
|
|
cpu_frequency = CPUFREQ_DEFAULT;
|
|
|
|
PLL_CONTROL |= 0x08000000;
|
|
|
|
scale_suspend_core(true);
|
|
|
|
CLOCK_SOURCE = 0x20002222; /* source #1, #2, #3, #4: 24MHz (#2 active) */
|
|
|
|
DEV_TIMING1 = 0x00000303;
|
|
|
|
#if defined(IPOD_MINI2G)
|
|
|
|
MLCD_SCLK_DIV = 0x00000000; /* Mono LCD bridge serial clock divider */
|
|
|
|
#elif defined(IPOD_NANO)
|
|
|
|
IDE0_CFG &= ~0x10000000; /* clear ">65MHz" bit */
|
2007-11-08 06:52:48 +00:00
|
|
|
#endif
|
2008-02-10 05:39:20 +00:00
|
|
|
scale_suspend_core(false);
|
|
|
|
PLL_CONTROL &= ~0x80000000; /* disable PLL */
|
|
|
|
DEV_INIT2 &= ~INIT_PLL; /* disable PLL power */
|
2007-07-26 15:07:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-10 05:39:20 +00:00
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
|
2009-02-03 12:16:45 +00:00
|
|
|
corelock_unlock(&cpufreq_cl);
|
2007-04-22 12:03:17 +00:00
|
|
|
#endif
|
2007-07-26 15:07:16 +00:00
|
|
|
}
|
2011-01-17 06:50:27 +00:00
|
|
|
#endif /* !BOOTLOADER || (SANSA_E200 || SANSA_C200 || PHILIPS_SA9200) */
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2011-01-17 06:50:27 +00:00
|
|
|
#ifndef BOOTLOADER
|
2007-04-22 12:03:17 +00:00
|
|
|
void system_init(void)
|
|
|
|
{
|
|
|
|
if (CURRENT_CORE == CPU)
|
|
|
|
{
|
2008-02-10 05:39:20 +00:00
|
|
|
#if defined (IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(IPOD_COLOR)
|
|
|
|
/* set minimum startup configuration */
|
|
|
|
DEV_EN = 0xc2000124;
|
|
|
|
DEV_EN2 = 0x00002000;
|
|
|
|
CACHE_PRIORITY = 0x0000003f;
|
|
|
|
GPO32_VAL = 0x20000000;
|
|
|
|
DEV_INIT1 = 0xdc000000;
|
|
|
|
DEV_INIT2 = 0x40000000;
|
|
|
|
|
|
|
|
/* reset all allowed devices */
|
2009-02-21 09:43:21 +00:00
|
|
|
DEV_RS = 0x3dfffef8;
|
2008-02-10 05:39:20 +00:00
|
|
|
DEV_RS2 = 0xffffdfff;
|
|
|
|
DEV_RS = 0x00000000;
|
|
|
|
DEV_RS2 = 0x00000000;
|
|
|
|
#elif defined (IPOD_VIDEO)
|
|
|
|
/* set minimum startup configuration */
|
|
|
|
DEV_EN = 0xc2000124;
|
|
|
|
DEV_EN2 = 0x00000000;
|
|
|
|
CACHE_PRIORITY = 0x0000003f;
|
2009-04-12 14:54:12 +00:00
|
|
|
GPO32_VAL &= 0x00004000;
|
2008-02-10 05:39:20 +00:00
|
|
|
DEV_INIT1 = 0x00000000;
|
|
|
|
DEV_INIT2 = 0x40000000;
|
|
|
|
|
|
|
|
/* reset all allowed devices */
|
2009-01-18 12:35:03 +00:00
|
|
|
DEV_RS = 0x3dfffef8;
|
2008-02-10 05:39:20 +00:00
|
|
|
DEV_RS2 = 0xffffffff;
|
|
|
|
DEV_RS = 0x00000000;
|
|
|
|
DEV_RS2 = 0x00000000;
|
|
|
|
#elif defined (IPOD_NANO)
|
|
|
|
/* set minimum startup configuration */
|
|
|
|
DEV_EN = 0xc2000124;
|
|
|
|
DEV_EN2 = 0x00002000;
|
|
|
|
CACHE_PRIORITY = 0x0000003f;
|
|
|
|
GPO32_VAL = 0x50000000;
|
|
|
|
DEV_INIT1 = 0xa8000000;
|
|
|
|
DEV_INIT2 = 0x40000000;
|
|
|
|
|
|
|
|
/* reset all allowed devices */
|
|
|
|
DEV_RS = 0x3ffffef8;
|
|
|
|
DEV_RS2 = 0xffffdfff;
|
|
|
|
DEV_RS = 0x00000000;
|
|
|
|
DEV_RS2 = 0x00000000;
|
|
|
|
#elif defined(SANSA_C200) || defined (SANSA_E200)
|
|
|
|
/* set minimum startup configuration */
|
|
|
|
DEV_EN = 0xc4000124;
|
|
|
|
DEV_EN2 = 0x00000000;
|
|
|
|
CACHE_PRIORITY = 0x0000003f;
|
|
|
|
GPO32_VAL = 0x10000000;
|
|
|
|
DEV_INIT1 = 0x54000000;
|
|
|
|
DEV_INIT2 = 0x40000000;
|
|
|
|
|
|
|
|
/* reset all allowed devices */
|
|
|
|
DEV_RS = 0x3bfffef8;
|
|
|
|
DEV_RS2 = 0xffffffff;
|
2009-06-19 03:41:52 +00:00
|
|
|
DEV_RS = 0x00000000;
|
|
|
|
DEV_RS2 = 0x00000000;
|
|
|
|
#elif defined(PHILIPS_SA9200)
|
|
|
|
/* reset all allowed devices */
|
|
|
|
DEV_RS = 0x3ffffef8;
|
|
|
|
DEV_RS2 = 0xffffffff;
|
2008-02-10 05:39:20 +00:00
|
|
|
DEV_RS = 0x00000000;
|
|
|
|
DEV_RS2 = 0x00000000;
|
|
|
|
#elif defined(IPOD_4G)
|
|
|
|
/* set minimum startup configuration */
|
|
|
|
DEV_EN = 0xc2020124;
|
|
|
|
DEV_EN2 = 0x00000000;
|
|
|
|
CACHE_PRIORITY = 0x0000003f;
|
|
|
|
GPO32_VAL = 0x02000000;
|
|
|
|
DEV_INIT1 = 0x00000000;
|
|
|
|
DEV_INIT2 = 0x40000000;
|
|
|
|
|
|
|
|
/* reset all allowed devices */
|
2009-01-18 12:35:03 +00:00
|
|
|
DEV_RS = 0x3dfdfef8;
|
2008-02-10 05:39:20 +00:00
|
|
|
DEV_RS2 = 0xffffffff;
|
|
|
|
DEV_RS = 0x00000000;
|
|
|
|
DEV_RS2 = 0x00000000;
|
|
|
|
#elif defined (IPOD_MINI)
|
|
|
|
/* to be done */
|
|
|
|
#elif defined (IPOD_MINI2G)
|
2008-03-08 23:50:55 +00:00
|
|
|
/* to be done */
|
2008-02-10 05:39:20 +00:00
|
|
|
#elif defined (MROBE_100)
|
|
|
|
/* to be done */
|
2009-12-07 16:12:49 +00:00
|
|
|
#elif defined (TATUNG_TPJ1022)
|
2008-02-10 05:39:20 +00:00
|
|
|
/* to be done */
|
2010-01-18 19:05:20 +00:00
|
|
|
#elif defined(PBELL_VIBE500)
|
2010-03-09 19:09:17 +00:00
|
|
|
/* reset all allowed devices */
|
|
|
|
DEV_RS = 0x3ffffef8;
|
|
|
|
DEV_RS2 = 0xffffffff;
|
|
|
|
DEV_RS = 0x00000000;
|
|
|
|
DEV_RS2 = 0x00000000;
|
2007-05-17 10:14:17 +00:00
|
|
|
#endif
|
2007-10-04 04:53:01 +00:00
|
|
|
|
2008-05-21 03:55:17 +00:00
|
|
|
#if !defined(SANSA_E200) && !defined(SANSA_C200) && !defined(PHILIPS_SA9200)
|
2007-10-04 04:53:01 +00:00
|
|
|
/* Remap the flash ROM on CPU, keep hidden from COP:
|
|
|
|
* 0x00000000-0x3fffffff = 0x20000000-0x23ffffff */
|
|
|
|
MMAP1_LOGICAL = 0x20003c00;
|
|
|
|
MMAP1_PHYSICAL = 0x00003084 |
|
|
|
|
MMAP_PHYS_READ_MASK | MMAP_PHYS_WRITE_MASK |
|
|
|
|
MMAP_PHYS_DATA_MASK | MMAP_PHYS_CODE_MASK;
|
|
|
|
#endif
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2011-01-15 08:19:30 +00:00
|
|
|
disable_all_interrupts();
|
2007-05-11 08:09:49 +00:00
|
|
|
|
2007-07-26 15:07:16 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
#if NUM_CORES > 1
|
2009-02-03 12:16:45 +00:00
|
|
|
corelock_init(&cpufreq_cl);
|
2007-10-16 01:25:17 +00:00
|
|
|
cpu_boost_init();
|
2007-04-22 12:03:17 +00:00
|
|
|
#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
|
2010-08-29 13:20:16 +00:00
|
|
|
|
|
|
|
#if defined(IPOD_VIDEO)
|
|
|
|
/* crt0-pp.S wrote the ram size to the last byte of the first 32MB
|
|
|
|
ram bank. See the comment there for how we determine it. */
|
|
|
|
volatile unsigned char *end32 = (volatile unsigned char *)0x01ffffff;
|
|
|
|
probed_ramsize = *end32;
|
|
|
|
#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();
|
2011-01-17 06:50:27 +00:00
|
|
|
}
|
2011-01-15 08:19:30 +00:00
|
|
|
|
2011-01-17 06:50:27 +00:00
|
|
|
#else /* BOOTLOADER */
|
2011-01-15 08:19:30 +00:00
|
|
|
|
2011-01-17 06:50:27 +00:00
|
|
|
void system_init(void)
|
|
|
|
{
|
|
|
|
/* Only the CPU gets here in the bootloader */
|
2011-01-15 08:19:30 +00:00
|
|
|
#ifdef HAVE_BOOTLOADER_USB_MODE
|
|
|
|
disable_all_interrupts();
|
|
|
|
init_cache();
|
|
|
|
/* Use the local vector map */
|
|
|
|
CACHE_CTL |= CACHE_CTL_VECT_REMAP;
|
|
|
|
#endif /* HAVE_BOOTLOADER_USB_MODE */
|
|
|
|
|
2009-03-14 02:47:14 +00:00
|
|
|
#if defined(SANSA_C200) || defined(SANSA_E200) || defined(PHILIPS_SA9200)
|
2011-01-17 06:50:27 +00:00
|
|
|
pp_set_cpu_frequency(CPUFREQ_MAX);
|
2008-04-19 16:30:17 +00:00
|
|
|
#endif
|
2011-01-17 06:50:27 +00:00
|
|
|
/* Else the frequency should get changed upon USB connect -
|
2011-01-15 08:19:30 +00:00
|
|
|
* decide per-target */
|
2011-01-17 06:50:27 +00:00
|
|
|
}
|
2011-01-15 08:19:30 +00:00
|
|
|
|
2011-01-17 06:50:27 +00:00
|
|
|
#ifdef HAVE_BOOTLOADER_USB_MODE
|
|
|
|
void system_prepare_fw_start(void)
|
|
|
|
{
|
|
|
|
disable_interrupt(IRQ_FIQ_STATUS);
|
|
|
|
tick_stop();
|
|
|
|
disable_all_interrupts();
|
|
|
|
/* Some OF's disable this themselves, others do not and will hang. */
|
|
|
|
CACHE_CTL &= ~CACHE_CTL_VECT_REMAP;
|
2007-04-22 12:03:17 +00:00
|
|
|
}
|
2011-01-17 06:50:27 +00:00
|
|
|
#endif /* HAVE_BOOTLOADER_USB_MODE */
|
|
|
|
#endif /* !BOOTLOADER */
|
2007-04-22 12:03:17 +00:00
|
|
|
|
2009-01-22 22:05:04 +00:00
|
|
|
void ICODE_ATTR system_reboot(void)
|
2007-04-22 12:03:17 +00:00
|
|
|
{
|
2009-01-22 22:05:04 +00:00
|
|
|
disable_interrupt(IRQ_FIQ_STATUS);
|
|
|
|
CPU_INT_DIS = -1;
|
|
|
|
COP_INT_DIS = -1;
|
|
|
|
|
2007-04-22 12:03:17 +00:00
|
|
|
/* Reboot */
|
2008-05-21 03:55:17 +00:00
|
|
|
#if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200)
|
2007-09-30 10:53:31 +00:00
|
|
|
CACHE_CTL &= ~CACHE_CTL_VECT_REMAP;
|
2007-09-27 02:50:50 +00:00
|
|
|
|
2007-09-28 07:56:20 +00:00
|
|
|
/* 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-30 11:14:03 +00:00
|
|
|
STRAP_OPT_A = 0x23066b7b;
|
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
|
2008-03-04 13:52:07 +00:00
|
|
|
/* wait until reboot kicks in */
|
|
|
|
while (1);
|
2007-04-22 12:03:17 +00:00
|
|
|
}
|
|
|
|
|
2009-01-08 10:15:32 +00:00
|
|
|
void system_exception_wait(void)
|
|
|
|
{
|
|
|
|
/* FIXME: we just need the right buttons */
|
|
|
|
CPU_INT_DIS = -1;
|
|
|
|
COP_INT_DIS = -1;
|
|
|
|
|
|
|
|
/* Halt */
|
|
|
|
PROC_CTL(CURRENT_CORE) = 0x40000000;
|
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
|
2007-04-22 12:03:17 +00:00
|
|
|
int system_memory_guard(int newmode)
|
|
|
|
{
|
|
|
|
(void)newmode;
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-15 08:19:30 +00:00
|
|
|
|