2008-06-27 23:24:34 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Rob Purchase
|
|
|
|
*
|
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.
|
2008-06-27 23:24:34 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "panic.h"
|
2010-11-15 21:13:58 +00:00
|
|
|
#include "system-target.h"
|
2009-10-04 16:08:33 +00:00
|
|
|
#ifdef IPOD_NANO2G
|
2009-10-12 08:54:51 +00:00
|
|
|
#include "storage.h"
|
2010-02-17 15:54:48 +00:00
|
|
|
#include "pmu-target.h"
|
2009-10-04 16:08:33 +00:00
|
|
|
#endif
|
2016-05-12 00:14:48 +00:00
|
|
|
#include "uart-target.h"
|
2008-06-27 23:24:34 +00:00
|
|
|
|
2010-12-30 20:23:46 +00:00
|
|
|
/* MIUSDPARA_BOOST taken from OF (see crt0.S). MIUSDPARA_UNBOOST is derived
|
|
|
|
* from MIUSDPARA_BOOST due to the fact that the minimum allowed DRAM timings
|
|
|
|
* are fix, but HCLK clock cycle time is doubled in unboosted state. */
|
|
|
|
#if defined(IPOD_NANO2G)
|
|
|
|
#define MIUSDPARA_BOOST 0x006A49A5
|
|
|
|
#define MIUSDPARA_UNBOOST 0x006124D1
|
|
|
|
#elif defined(MEIZU_M3)
|
|
|
|
#define MIUSDPARA_BOOST 0x006A491D
|
|
|
|
#define MIUSDPARA_UNBOOST 0x0061248D
|
|
|
|
#elif defined(MEIZU_M6SP)
|
|
|
|
#define MIUSDPARA_BOOST 0x006A4965
|
|
|
|
#define MIUSDPARA_UNBOOST 0x00612491
|
|
|
|
#endif
|
|
|
|
|
2008-06-27 23:24:34 +00:00
|
|
|
#define default_interrupt(name) \
|
|
|
|
extern __attribute__((weak,alias("UIRQ"))) void name (void)
|
|
|
|
|
|
|
|
void irq_handler(void) __attribute__((interrupt ("IRQ"), naked));
|
2009-10-23 23:58:54 +00:00
|
|
|
void fiq_handler(void) __attribute__((interrupt ("FIQ"), naked, \
|
|
|
|
weak, alias("fiq_dummy")));
|
2008-06-27 23:24:34 +00:00
|
|
|
|
|
|
|
default_interrupt(EXT0);
|
|
|
|
default_interrupt(EXT1);
|
|
|
|
default_interrupt(EXT2);
|
|
|
|
default_interrupt(EINT_VBUS);
|
|
|
|
default_interrupt(EINTG);
|
|
|
|
default_interrupt(INT_TIMERA);
|
|
|
|
default_interrupt(INT_WDT);
|
|
|
|
default_interrupt(INT_TIMERB);
|
|
|
|
default_interrupt(INT_TIMERC);
|
|
|
|
default_interrupt(INT_TIMERD);
|
|
|
|
default_interrupt(INT_DMA);
|
|
|
|
default_interrupt(INT_ALARM_RTC);
|
|
|
|
default_interrupt(INT_PRI_RTC);
|
|
|
|
default_interrupt(RESERVED1);
|
2016-05-12 00:14:48 +00:00
|
|
|
default_interrupt(INT_UART1);
|
2008-06-27 23:24:34 +00:00
|
|
|
default_interrupt(INT_USB_HOST);
|
|
|
|
default_interrupt(INT_USB_FUNC);
|
|
|
|
default_interrupt(INT_LCDC_0);
|
|
|
|
default_interrupt(INT_LCDC_1);
|
|
|
|
default_interrupt(INT_ECC);
|
|
|
|
default_interrupt(INT_CALM);
|
|
|
|
default_interrupt(INT_ATA);
|
|
|
|
default_interrupt(INT_UART0);
|
|
|
|
default_interrupt(INT_SPDIF_OUT);
|
|
|
|
default_interrupt(INT_SDCI);
|
|
|
|
default_interrupt(INT_LCD);
|
2010-12-12 12:40:37 +00:00
|
|
|
default_interrupt(INT_WHEEL);
|
2008-06-27 23:24:34 +00:00
|
|
|
default_interrupt(INT_IIC);
|
|
|
|
default_interrupt(RESERVED2);
|
|
|
|
default_interrupt(INT_MSTICK);
|
|
|
|
default_interrupt(INT_ADC_WAKEUP);
|
|
|
|
default_interrupt(INT_ADC);
|
2016-05-12 00:14:48 +00:00
|
|
|
#if CONFIG_CPU==S5L8701
|
|
|
|
default_interrupt(INT_UNK);
|
|
|
|
default_interrupt(INT_UART2);
|
2016-05-14 12:24:49 +00:00
|
|
|
default_interrupt(EINT_G0);
|
|
|
|
default_interrupt(EINT_G1);
|
|
|
|
default_interrupt(EINT_G2);
|
|
|
|
default_interrupt(EINT_G3);
|
2016-05-12 00:14:48 +00:00
|
|
|
#endif
|
2008-06-27 23:24:34 +00:00
|
|
|
|
|
|
|
|
2009-10-05 16:01:26 +00:00
|
|
|
void INT_TIMER(void)
|
|
|
|
{
|
|
|
|
if (TACON & 0x00038000) INT_TIMERA();
|
|
|
|
if (TBCON & 0x00038000) INT_TIMERB();
|
|
|
|
if (TCCON & 0x00038000) INT_TIMERC();
|
|
|
|
if (TDCON & 0x00038000) INT_TIMERD();
|
|
|
|
}
|
|
|
|
|
2008-06-27 23:24:34 +00:00
|
|
|
|
2009-09-17 08:05:19 +00:00
|
|
|
#if CONFIG_CPU==S5L8701
|
2009-10-02 16:53:26 +00:00
|
|
|
static void (* const irqvector[])(void) =
|
2016-05-14 12:24:49 +00:00
|
|
|
{ /* still 80% unverified and probably incorrect */
|
|
|
|
EXT0,EINT_G0,EINT_G1,EINT_G2,EINT_G3,INT_TIMER,INT_WDT,INT_UART2,
|
2016-05-12 00:14:48 +00:00
|
|
|
INT_UNK,INT_UNK,INT_DMA,INT_ALARM_RTC,INT_UART1,INT_UNK,INT_UNK,INT_USB_HOST,
|
|
|
|
INT_USB_FUNC,INT_LCDC_0,INT_LCDC_1,INT_CALM,INT_ATA,INT_UNK,INT_SPDIF_OUT,INT_ECC,
|
2010-12-12 12:40:37 +00:00
|
|
|
INT_SDCI,INT_LCD,INT_WHEEL,INT_IIC,RESERVED2,INT_MSTICK,INT_ADC_WAKEUP,INT_ADC
|
2009-10-02 16:53:26 +00:00
|
|
|
};
|
2009-09-17 08:05:19 +00:00
|
|
|
#else
|
2009-10-02 16:53:26 +00:00
|
|
|
static void (* const irqvector[])(void) =
|
|
|
|
{
|
|
|
|
EXT0,EXT1,EXT2,EINT_VBUS,EINTG,INT_TIMERA,INT_WDT,INT_TIMERB,
|
2016-05-12 00:14:48 +00:00
|
|
|
INT_TIMERC,INT_TIMERD,INT_DMA,INT_ALARM_RTC,INT_PRI_RTC,RESERVED1,INT_UART1,INT_USB_HOST,
|
2008-06-27 23:24:34 +00:00
|
|
|
INT_USB_FUNC,INT_LCDC_0,INT_LCDC_1,INT_ECC,INT_CALM,INT_ATA,INT_UART0,INT_SPDIF_OUT,
|
2010-12-12 12:40:37 +00:00
|
|
|
INT_SDCI,INT_LCD,INT_WHEEL,INT_IIC,RESERVED2,INT_MSTICK,INT_ADC_WAKEUP,INT_ADC
|
2008-06-27 23:24:34 +00:00
|
|
|
};
|
2009-10-02 16:53:26 +00:00
|
|
|
#endif
|
2008-06-27 23:24:34 +00:00
|
|
|
|
2009-09-17 08:05:19 +00:00
|
|
|
#if CONFIG_CPU==S5L8701
|
2009-10-02 16:53:26 +00:00
|
|
|
static const char * const irqname[] =
|
2016-05-14 12:24:49 +00:00
|
|
|
{ /* still 80% unverified and probably incorrect */
|
|
|
|
"EXT0","EINT_G0","EINT_G1","EINT_G2","EINT_G3","INT_TIMER","INT_WDT","INT_UART2",
|
2016-05-12 00:14:48 +00:00
|
|
|
"INT_UNK1","INT_UNK2","INT_DMA","INT_ALARM_RTC","INT_UART1","INT_UNK3","INT_UNK4","INT_USB_HOST",
|
|
|
|
"INT_USB_FUNC","INT_LCDC_0","INT_LCDC_1","INT_CALM","INT_ATA","INT_UNK5","INT_SPDIF_OUT","INT_ECC",
|
2010-12-12 12:40:37 +00:00
|
|
|
"INT_SDCI","INT_LCD","INT_WHEEL","INT_IIC","Reserved","INT_MSTICK","INT_ADC_WAKEUP","INT_ADC"
|
2009-10-02 16:53:26 +00:00
|
|
|
};
|
2009-09-17 08:05:19 +00:00
|
|
|
#else
|
2009-10-02 16:53:26 +00:00
|
|
|
static const char * const irqname[] =
|
|
|
|
{
|
|
|
|
"EXT0","EXT1","EXT2","EINT_VBUS","EINTG","INT_TIMERA","INT_WDT","INT_TIMERB",
|
2016-05-12 00:14:48 +00:00
|
|
|
"INT_TIMERC","INT_TIMERD","INT_DMA","INT_ALARM_RTC","INT_PRI_RTC","Reserved","INT_UART1","INT_USB_HOST",
|
2008-06-27 23:24:34 +00:00
|
|
|
"INT_USB_FUNC","INT_LCDC_0","INT_LCDC_1","INT_ECC","INT_CALM","INT_ATA","INT_UART0","INT_SPDIF_OUT",
|
2010-12-12 12:40:37 +00:00
|
|
|
"INT_SDCI","INT_LCD","INT_WHEEL","INT_IIC","Reserved","INT_MSTICK","INT_ADC_WAKEUP","INT_ADC"
|
2008-06-27 23:24:34 +00:00
|
|
|
};
|
2009-10-02 16:53:26 +00:00
|
|
|
#endif
|
2008-06-27 23:24:34 +00:00
|
|
|
|
|
|
|
static void UIRQ(void)
|
|
|
|
{
|
|
|
|
unsigned int offset = INTOFFSET;
|
|
|
|
panicf("Unhandled IRQ %02X: %s", offset, irqname[offset]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void irq_handler(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Based on: linux/arch/arm/kernel/entry-armv.S and system-meg-fx.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
asm volatile( "stmfd sp!, {r0-r7, ip, lr} \n" /* Store context */
|
|
|
|
"sub sp, sp, #8 \n"); /* Reserve stack */
|
|
|
|
|
2009-06-23 18:11:03 +00:00
|
|
|
int irq_no = INTOFFSET;
|
2008-06-27 23:24:34 +00:00
|
|
|
|
2009-06-23 18:11:03 +00:00
|
|
|
irqvector[irq_no]();
|
|
|
|
|
|
|
|
/* clear interrupt */
|
2009-07-25 00:54:31 +00:00
|
|
|
SRCPND = (1 << irq_no);
|
|
|
|
INTPND = INTPND;
|
2008-06-27 23:24:34 +00:00
|
|
|
|
|
|
|
asm volatile( "add sp, sp, #8 \n" /* Cleanup stack */
|
|
|
|
"ldmfd sp!, {r0-r7, ip, lr} \n" /* Restore context */
|
|
|
|
"subs pc, lr, #4 \n"); /* Return from IRQ */
|
|
|
|
}
|
|
|
|
|
2009-10-23 23:58:54 +00:00
|
|
|
void fiq_dummy(void)
|
|
|
|
{
|
|
|
|
asm volatile (
|
|
|
|
"subs pc, lr, #4 \r\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-27 23:24:34 +00:00
|
|
|
void system_init(void)
|
|
|
|
{
|
2010-05-30 21:43:14 +00:00
|
|
|
#ifdef IPOD_NANO2G
|
2010-02-17 15:54:48 +00:00
|
|
|
pmu_init();
|
2010-05-30 21:43:14 +00:00
|
|
|
#endif
|
2016-05-12 00:14:48 +00:00
|
|
|
#ifdef HAVE_SERIAL
|
|
|
|
uart_init();
|
|
|
|
#endif
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void system_reboot(void)
|
|
|
|
{
|
2009-10-05 12:29:08 +00:00
|
|
|
#ifdef IPOD_NANO2G
|
2009-10-12 08:54:51 +00:00
|
|
|
#ifdef HAVE_STORAGE_FLUSH
|
|
|
|
storage_flush();
|
|
|
|
#endif
|
2009-10-04 16:08:33 +00:00
|
|
|
|
|
|
|
/* Reset the SoC */
|
2009-10-05 12:29:08 +00:00
|
|
|
asm volatile("msr CPSR_c, #0xd3 \n"
|
|
|
|
"mov r5, #0x110000 \n"
|
|
|
|
"add r5, r5, #0xff \n"
|
|
|
|
"add r6, r5, #0xa00 \n"
|
|
|
|
"mov r10, #0x3c800000 \n"
|
|
|
|
"str r6, [r10] \n"
|
|
|
|
"mov r6, #0xff0 \n"
|
|
|
|
"str r6, [r10,#4] \n"
|
|
|
|
"str r5, [r10] \n");
|
2009-10-04 16:08:33 +00:00
|
|
|
|
|
|
|
/* Wait for reboot to kick in */
|
|
|
|
while(1);
|
|
|
|
#endif
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 12:05:53 +00:00
|
|
|
extern void post_mortem_stub(void);
|
|
|
|
|
2009-01-08 10:15:32 +00:00
|
|
|
void system_exception_wait(void)
|
|
|
|
{
|
2010-11-13 12:05:53 +00:00
|
|
|
post_mortem_stub();
|
2010-02-17 15:54:48 +00:00
|
|
|
while(1);
|
2009-01-08 10:15:32 +00:00
|
|
|
}
|
|
|
|
|
2008-06-27 23:24:34 +00:00
|
|
|
int system_memory_guard(int newmode)
|
|
|
|
{
|
|
|
|
(void)newmode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
|
|
|
|
void set_cpu_frequency(long frequency)
|
|
|
|
{
|
|
|
|
if (cpu_frequency == frequency)
|
|
|
|
return;
|
2010-02-17 15:54:48 +00:00
|
|
|
|
2008-06-27 23:24:34 +00:00
|
|
|
if (frequency == CPUFREQ_MAX)
|
|
|
|
{
|
2010-11-14 15:20:06 +00:00
|
|
|
/* Vcore = 1.000V */
|
|
|
|
pmu_write(0x1e, 0xf);
|
|
|
|
/* Allow for voltage to stabilize */
|
2010-11-15 21:13:58 +00:00
|
|
|
udelay(100);
|
2010-12-30 20:23:46 +00:00
|
|
|
/* Configure for 96 MHz HCLK */
|
|
|
|
MIUSDPARA = MIUSDPARA_BOOST;
|
2010-02-17 15:54:48 +00:00
|
|
|
/* FCLK_CPU = PLL0, HCLK = PLL0 / 2 */
|
|
|
|
CLKCON = (CLKCON & ~0xFF00FF00) | 0x20003100;
|
|
|
|
/* PCLK = HCLK / 2 */
|
|
|
|
CLKCON2 |= 0x200;
|
2010-11-14 15:20:06 +00:00
|
|
|
/* Switch to ASYNCHRONOUS mode => GCLK = FCLK_CPU */
|
2010-02-17 15:54:48 +00:00
|
|
|
asm volatile(
|
|
|
|
"mrc p15, 0, r0,c1,c0 \n\t"
|
|
|
|
"orr r0, r0, #0xc0000000 \n\t"
|
|
|
|
"mcr p15, 0, r0,c1,c0 \n\t"
|
|
|
|
::: "r0"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-14 15:20:06 +00:00
|
|
|
/* Switch to FASTBUS mode => GCLK = HCLK */
|
2010-02-17 15:54:48 +00:00
|
|
|
asm volatile(
|
|
|
|
"mrc p15, 0, r0,c1,c0 \n\t"
|
|
|
|
"bic r0, r0, #0xc0000000 \n\t"
|
|
|
|
"mcr p15, 0, r0,c1,c0 \n\t"
|
|
|
|
::: "r0"
|
|
|
|
);
|
|
|
|
/* PCLK = HCLK */
|
|
|
|
CLKCON2 &= ~0x200;
|
|
|
|
/* FCLK_CPU = OFF, HCLK = PLL0 / 4 */
|
|
|
|
CLKCON = (CLKCON & ~0xFF00FF00) | 0x80003300;
|
2010-12-30 20:23:46 +00:00
|
|
|
/* Configure for 48 MHz HCLK */
|
|
|
|
MIUSDPARA = MIUSDPARA_UNBOOST;
|
2010-11-14 15:20:06 +00:00
|
|
|
/* Vcore = 0.900V */
|
|
|
|
pmu_write(0x1e, 0xb);
|
2008-06-27 23:24:34 +00:00
|
|
|
}
|
2010-02-17 15:54:48 +00:00
|
|
|
|
2008-06-27 23:24:34 +00:00
|
|
|
cpu_frequency = frequency;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|