2008-05-08 16:47:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by James Espinoza
|
|
|
|
*
|
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-05-08 16:47:24 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
2010-08-12 13:38:25 +00:00
|
|
|
#include "gcc_extensions.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "panic.h"
|
2008-02-08 02:20:05 +00:00
|
|
|
#include "avic-imx31.h"
|
2008-04-12 16:56:45 +00:00
|
|
|
#include "gpio-imx31.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "mmu-imx31.h"
|
|
|
|
#include "system-target.h"
|
2012-01-07 22:43:53 +00:00
|
|
|
#include "powermgmt.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "serial-imx31.h"
|
|
|
|
#include "debug.h"
|
2009-03-22 02:13:27 +00:00
|
|
|
#include "ccm-imx31.h"
|
2008-05-10 18:32:34 +00:00
|
|
|
#include "mc13783.h"
|
2010-04-07 03:43:48 +00:00
|
|
|
#include "dvfs_dptc-imx31.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2009-02-08 22:32:41 +00:00
|
|
|
static unsigned long product_rev;
|
|
|
|
static unsigned long system_rev;
|
|
|
|
|
|
|
|
/** IC revision info routines **/
|
|
|
|
unsigned int iim_system_rev(void)
|
|
|
|
{
|
|
|
|
return system_rev & IIM_SREV_SREV;
|
|
|
|
}
|
|
|
|
|
2009-08-06 09:44:09 +00:00
|
|
|
unsigned int iim_prod_rev(void)
|
2009-02-08 22:32:41 +00:00
|
|
|
{
|
|
|
|
return product_rev;
|
|
|
|
}
|
|
|
|
|
2010-06-11 14:39:35 +00:00
|
|
|
static void INIT_ATTR iim_init(void)
|
2009-02-08 22:32:41 +00:00
|
|
|
{
|
|
|
|
/* Initialize the IC revision info (required by SDMA) */
|
2009-03-22 01:50:48 +00:00
|
|
|
ccm_module_clock_gating(CG_IIM, CGM_ON_RUN_WAIT);
|
2009-02-08 22:32:41 +00:00
|
|
|
product_rev = IIM_PREV;
|
|
|
|
system_rev = IIM_SREV;
|
|
|
|
}
|
|
|
|
|
2009-01-23 01:23:25 +00:00
|
|
|
/** Watchdog timer routines **/
|
|
|
|
|
2008-12-21 18:10:36 +00:00
|
|
|
/* Initialize the watchdog timer */
|
|
|
|
void watchdog_init(unsigned int half_seconds)
|
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
uint16_t wcr = ((half_seconds << WDOG_WCR_WT_POS) & WDOG_WCR_WT) |
|
2008-12-21 18:10:36 +00:00
|
|
|
WDOG_WCR_WOE | /* WDOG output enabled */
|
|
|
|
WDOG_WCR_WDA | /* WDOG assertion - no effect */
|
|
|
|
WDOG_WCR_SRS | /* System reset - no effect */
|
|
|
|
WDOG_WCR_WRE; /* Generate a WDOG signal */
|
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
ccm_module_clock_gating(CG_WDOG, CGM_ON_RUN_WAIT);
|
2008-12-21 18:10:36 +00:00
|
|
|
|
|
|
|
WDOG_WCR = wcr;
|
|
|
|
WDOG_WSR = 0x5555;
|
|
|
|
WDOG_WCR = wcr | WDOG_WCR_WDE; /* Enable timer - hardware does
|
|
|
|
not allow a disable now */
|
|
|
|
WDOG_WSR = 0xaaaa;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Service the watchdog timer */
|
|
|
|
void watchdog_service(void)
|
|
|
|
{
|
|
|
|
WDOG_WSR = 0x5555;
|
|
|
|
WDOG_WSR = 0xaaaa;
|
|
|
|
}
|
|
|
|
|
2013-05-11 23:59:01 +00:00
|
|
|
|
|
|
|
/** uevent APIs **/
|
|
|
|
|
|
|
|
static void (*ucallback)(void) = NULL; /* uevent callback */
|
|
|
|
|
|
|
|
static void cancel_uevent(void)
|
|
|
|
{
|
|
|
|
GPTSR = GPTSR_OF1;
|
|
|
|
GPTIR &= ~GPTIR_OF1IE;
|
|
|
|
ucallback = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __attribute__((interrupt("IRQ"))) GPT_HANDLER(void)
|
|
|
|
{
|
|
|
|
uevent_cb_type cb = ucallback;
|
|
|
|
cancel_uevent();
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
|
|
|
void uevent(unsigned long usecs, uevent_cb_type callback)
|
|
|
|
{
|
|
|
|
if (!callback || ucallback)
|
|
|
|
return; /* Is busy */
|
|
|
|
|
|
|
|
unsigned long status = disable_interrupt_save(IRQ_FIQ_STATUS);
|
|
|
|
|
|
|
|
ucallback = callback;
|
|
|
|
|
|
|
|
for (int i = 0; i < 1; i++)
|
|
|
|
{
|
|
|
|
unsigned long utime = GPTCNT;
|
|
|
|
unsigned long time = utime + usecs + 1;
|
|
|
|
|
|
|
|
GPTOCR1 = time;
|
|
|
|
GPTSR = GPTSR_OF1;
|
|
|
|
GPTIR |= GPTIR_OF1IE;
|
|
|
|
|
|
|
|
if (TIME_BEFORE(GPTCNT, time))
|
|
|
|
break; /* Didn't miss it */
|
|
|
|
}
|
|
|
|
|
|
|
|
restore_interrupt(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uevent_cancel(void)
|
|
|
|
{
|
|
|
|
unsigned long status = disable_interrupt_save(IRQ_FIQ_STATUS);
|
|
|
|
|
|
|
|
if (ucallback)
|
|
|
|
cancel_uevent();
|
|
|
|
|
|
|
|
restore_interrupt(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** GPT timer routines - basis for udelay/uevent **/
|
2009-01-23 01:23:25 +00:00
|
|
|
|
|
|
|
/* Start the general-purpose timer (1MHz) */
|
|
|
|
void gpt_start(void)
|
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
ccm_module_clock_gating(CG_GPT, CGM_ON_RUN_WAIT);
|
|
|
|
unsigned int ipg_mhz = ccm_get_ipg_clk() / 1000000;
|
2009-01-23 01:23:25 +00:00
|
|
|
|
|
|
|
GPTCR &= ~GPTCR_EN; /* Disable counter */
|
|
|
|
GPTCR |= GPTCR_SWR; /* Reset module */
|
|
|
|
while (GPTCR & GPTCR_SWR);
|
|
|
|
/* No output
|
|
|
|
* No capture
|
2011-01-22 09:23:31 +00:00
|
|
|
* Enable in wait and run mode
|
2009-01-23 01:23:25 +00:00
|
|
|
* Freerun mode (count to 0xFFFFFFFF and roll-over to 0x00000000)
|
|
|
|
*/
|
2011-01-22 09:23:31 +00:00
|
|
|
GPTCR = GPTCR_FRR | GPTCR_WAITEN | GPTCR_CLKSRC_IPG_CLK;
|
2009-01-23 01:23:25 +00:00
|
|
|
GPTPR = ipg_mhz - 1;
|
2013-05-11 23:59:01 +00:00
|
|
|
GPTSR = GPTSR_OF1;
|
2009-01-23 01:23:25 +00:00
|
|
|
GPTCR |= GPTCR_EN;
|
2013-05-11 23:59:01 +00:00
|
|
|
|
|
|
|
avic_enable_int(INT_GPT, INT_TYPE_IRQ, INT_PRIO_GPT, GPT_HANDLER);
|
2009-01-23 01:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop the general-purpose timer */
|
|
|
|
void gpt_stop(void)
|
|
|
|
{
|
2013-05-11 23:59:01 +00:00
|
|
|
unsigned long status = disable_interrupt_save(IRQ_FIQ_STATUS);
|
|
|
|
avic_disable_int(INT_GPT);
|
|
|
|
cancel_uevent();
|
2009-01-23 01:23:25 +00:00
|
|
|
GPTCR &= ~GPTCR_EN;
|
2013-05-11 23:59:01 +00:00
|
|
|
restore_interrupt(status);
|
2009-01-23 01:23:25 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
int system_memory_guard(int newmode)
|
|
|
|
{
|
|
|
|
(void)newmode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
void system_halt(void)
|
|
|
|
{
|
|
|
|
disable_interrupt(IRQ_FIQ_STATUS);
|
|
|
|
avic_set_ni_level(AVIC_NIL_DISABLE);
|
|
|
|
while (1)
|
|
|
|
core_idle();
|
|
|
|
}
|
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
void system_reboot(void)
|
|
|
|
{
|
2009-01-08 10:15:32 +00:00
|
|
|
/* Multi-context so no SPI available (WDT?) */
|
2010-04-23 15:32:50 +00:00
|
|
|
system_halt();
|
2009-01-08 10:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void system_exception_wait(void)
|
|
|
|
{
|
|
|
|
/* Called in many contexts so button reading may be a chore */
|
2010-04-23 15:32:50 +00:00
|
|
|
system_halt();
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 14:39:35 +00:00
|
|
|
void INIT_ATTR system_init(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2011-01-08 20:42:51 +00:00
|
|
|
static const enum IMX31_CG_LIST disable_clocks[] INITDATA_ATTR =
|
2008-05-08 16:27:23 +00:00
|
|
|
{
|
|
|
|
/* CGR0 */
|
|
|
|
CG_SD_MMC1,
|
|
|
|
CG_SD_MMC2,
|
|
|
|
CG_IIM,
|
2009-01-03 07:29:26 +00:00
|
|
|
CG_SDMA,
|
2008-05-08 16:27:23 +00:00
|
|
|
CG_CSPI3,
|
|
|
|
CG_RNG,
|
|
|
|
CG_UART1,
|
|
|
|
CG_UART2,
|
|
|
|
CG_SSI1,
|
|
|
|
CG_I2C1,
|
|
|
|
CG_I2C2,
|
|
|
|
CG_I2C3,
|
|
|
|
|
|
|
|
/* CGR1 */
|
|
|
|
CG_HANTRO,
|
|
|
|
CG_MEMSTICK1,
|
|
|
|
CG_MEMSTICK2,
|
|
|
|
CG_CSI,
|
2009-01-03 07:29:26 +00:00
|
|
|
CG_RTC,
|
2008-05-08 16:27:23 +00:00
|
|
|
CG_WDOG,
|
2009-01-03 07:29:26 +00:00
|
|
|
CG_PWM,
|
2008-05-08 16:27:23 +00:00
|
|
|
CG_SIM,
|
|
|
|
CG_ECT,
|
|
|
|
CG_USBOTG,
|
|
|
|
CG_KPP,
|
|
|
|
CG_UART3,
|
|
|
|
CG_UART4,
|
|
|
|
CG_UART5,
|
|
|
|
CG_1_WIRE,
|
|
|
|
|
|
|
|
/* CGR2 */
|
|
|
|
CG_SSI2,
|
|
|
|
CG_CSPI1,
|
|
|
|
CG_CSPI2,
|
|
|
|
CG_GACC,
|
|
|
|
CG_RTIC,
|
|
|
|
CG_FIR
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
/* Initialize frequency with current */
|
|
|
|
cpu_frequency = ccm_get_mcu_clk();
|
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
/* MCR WFI enables wait mode (CCM_CCMR_LPM_WAIT_MODE = 0) */
|
2010-06-30 02:02:46 +00:00
|
|
|
bitclr32(&CCM_CCMR, CCM_CCMR_LPM);
|
2008-05-08 16:27:23 +00:00
|
|
|
|
2009-02-08 22:32:41 +00:00
|
|
|
iim_init();
|
|
|
|
|
2010-06-30 02:02:46 +00:00
|
|
|
bitset32(&SDHC1_CLOCK_CONTROL, STOP_CLK);
|
|
|
|
bitset32(&SDHC2_CLOCK_CONTROL, STOP_CLK);
|
|
|
|
bitset32(&RNGA_CONTROL, RNGA_CONTROL_SLEEP);
|
|
|
|
bitclr32(&UCR1_1, EUARTUCR1_UARTEN);
|
|
|
|
bitclr32(&UCR1_2, EUARTUCR1_UARTEN);
|
|
|
|
bitclr32(&UCR1_3, EUARTUCR1_UARTEN);
|
|
|
|
bitclr32(&UCR1_4, EUARTUCR1_UARTEN);
|
|
|
|
bitclr32(&UCR1_5, EUARTUCR1_UARTEN);
|
2008-05-08 16:27:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAYLEN(disable_clocks); i++)
|
2009-03-22 01:50:48 +00:00
|
|
|
ccm_module_clock_gating(disable_clocks[i], CGM_OFF);
|
2008-05-08 16:27:23 +00:00
|
|
|
|
2008-02-05 04:43:19 +00:00
|
|
|
avic_init();
|
2009-01-23 01:23:25 +00:00
|
|
|
gpt_start();
|
2008-04-12 16:56:45 +00:00
|
|
|
gpio_init();
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 02:20:05 +00:00
|
|
|
void system_prepare_fw_start(void)
|
|
|
|
{
|
2011-01-23 20:21:35 +00:00
|
|
|
dvfs_stop();
|
|
|
|
dptc_stop();
|
2008-05-10 18:00:11 +00:00
|
|
|
mc13783_close();
|
2008-02-08 02:20:05 +00:00
|
|
|
tick_stop();
|
2010-04-23 15:32:50 +00:00
|
|
|
disable_interrupt(IRQ_FIQ_STATUS);
|
|
|
|
avic_set_ni_level(AVIC_NIL_DISABLE);
|
2008-02-08 02:20:05 +00:00
|
|
|
}
|
2010-04-23 15:32:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef BOOTLOADER
|
|
|
|
void rolo_restart_firmware(const unsigned char *source, unsigned char *dest,
|
2010-08-12 13:38:25 +00:00
|
|
|
int length) NORETURN_ATTR;
|
2010-04-23 15:32:50 +00:00
|
|
|
|
2010-08-12 13:38:25 +00:00
|
|
|
void NORETURN_ATTR
|
2010-04-23 15:32:50 +00:00
|
|
|
rolo_restart(const unsigned char *source, unsigned char *dest, int length)
|
|
|
|
{
|
|
|
|
/* Some housekeeping tasks must be performed for a safe changeover */
|
|
|
|
charging_algorithm_close();
|
|
|
|
system_prepare_fw_start();
|
|
|
|
|
|
|
|
/* Copying routine where new image is run */
|
|
|
|
rolo_restart_firmware(source, dest, length);
|
|
|
|
}
|
|
|
|
#endif /* BOOTLOADER */
|
|
|
|
|
2008-02-08 02:20:05 +00:00
|
|
|
|
2010-09-07 14:30:30 +00:00
|
|
|
void dumpregs(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2010-01-03 10:19:43 +00:00
|
|
|
asm volatile ("mov %0,r0\n\t"
|
|
|
|
"mov %1,r1\n\t"
|
|
|
|
"mov %2,r2\n\t"
|
|
|
|
"mov %3,r3":
|
|
|
|
"=r"(regs.r0),"=r"(regs.r1),
|
|
|
|
"=r"(regs.r2),"=r"(regs.r3):);
|
2007-09-21 15:51:53 +00:00
|
|
|
|
|
|
|
asm volatile ("mov %0,r4\n\t"
|
2010-01-03 10:19:43 +00:00
|
|
|
"mov %1,r5\n\t"
|
|
|
|
"mov %2,r6\n\t"
|
|
|
|
"mov %3,r7":
|
|
|
|
"=r"(regs.r4),"=r"(regs.r5),
|
|
|
|
"=r"(regs.r6),"=r"(regs.r7):);
|
2007-09-21 15:51:53 +00:00
|
|
|
|
|
|
|
asm volatile ("mov %0,r8\n\t"
|
2010-01-03 10:19:43 +00:00
|
|
|
"mov %1,r9\n\t"
|
|
|
|
"mov %2,r10\n\t"
|
|
|
|
"mov %3,r12":
|
|
|
|
"=r"(regs.r8),"=r"(regs.r9),
|
|
|
|
"=r"(regs.r10),"=r"(regs.r11):);
|
2013-05-11 23:59:01 +00:00
|
|
|
|
2010-01-03 10:19:43 +00:00
|
|
|
asm volatile ("mov %0,r12\n\t"
|
|
|
|
"mov %1,sp\n\t"
|
|
|
|
"mov %2,lr\n\t"
|
|
|
|
"mov %3,pc\n"
|
|
|
|
"sub %3,%3,#8":
|
|
|
|
"=r"(regs.r12),"=r"(regs.sp),
|
|
|
|
"=r"(regs.lr),"=r"(regs.pc):);
|
2007-09-21 15:51:53 +00:00
|
|
|
#ifdef HAVE_SERIAL
|
|
|
|
dprintf("Register Dump :\n");
|
2010-01-03 10:19:43 +00:00
|
|
|
dprintf("R0=0x%x\tR1=0x%x\tR2=0x%x\tR3=0x%x\n",regs.r0,regs.r1,regs.r2,regs.r3);
|
2007-09-21 15:51:53 +00:00
|
|
|
dprintf("R4=0x%x\tR5=0x%x\tR6=0x%x\tR7=0x%x\n",regs.r4,regs.r5,regs.r6,regs.r7);
|
2010-01-03 10:19:43 +00:00
|
|
|
dprintf("R8=0x%x\tR9=0x%x\tR10=0x%x\tR11=0x%x\n",regs.r8,regs.r9,regs.r10,regs.r11);
|
|
|
|
dprintf("R12=0x%x\tSP=0x%x\tLR=0x%x\tPC=0x%x\n",regs.r12,regs.sp,regs.lr,regs.pc);
|
|
|
|
//dprintf("CPSR=0x%x\t\n",regs.cpsr);
|
2007-09-21 15:51:53 +00:00
|
|
|
#endif
|
2010-01-03 10:19:43 +00:00
|
|
|
DEBUGF("Register Dump :\n");
|
|
|
|
DEBUGF("R0=0x%x\tR1=0x%x\tR2=0x%x\tR3=0x%x\n",regs.r0,regs.r1,regs.r2,regs.r3);
|
2007-09-21 15:51:53 +00:00
|
|
|
DEBUGF("R4=0x%x\tR5=0x%x\tR6=0x%x\tR7=0x%x\n",regs.r4,regs.r5,regs.r6,regs.r7);
|
2010-01-03 10:19:43 +00:00
|
|
|
DEBUGF("R8=0x%x\tR9=0x%x\tR10=0x%x\tR11=0x%x\n",regs.r8,regs.r9,regs.r10,regs.r11);
|
|
|
|
DEBUGF("R12=0x%x\tSP=0x%x\tLR=0x%x\tPC=0x%x\n",regs.r12,regs.sp,regs.lr,regs.pc);
|
|
|
|
//DEBUGF("CPSR=0x%x\t\n",regs.cpsr);
|
2013-05-11 23:59:01 +00:00
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
|
|
|
|
void set_cpu_frequency(long frequency)
|
|
|
|
{
|
|
|
|
(void)freqency;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|