2008-10-12 16:46:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Rob Purchase
|
2008-10-28 11:24:29 +00:00
|
|
|
* Copyright © 2008 Rafaël Carré
|
2008-10-12 16:46:01 +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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2009-11-01 22:51:31 +00:00
|
|
|
#include "config.h"
|
2008-10-12 16:46:01 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "panic.h"
|
2012-01-08 01:43:16 +00:00
|
|
|
#include "ascodec.h"
|
2009-07-05 09:24:56 +00:00
|
|
|
#include "adc.h"
|
2008-11-25 13:38:32 +00:00
|
|
|
#include "dma-target.h"
|
2008-12-04 20:04:31 +00:00
|
|
|
#include "clock-target.h"
|
2009-01-21 20:51:43 +00:00
|
|
|
#include "fmradio_i2c.h"
|
2012-01-08 00:07:19 +00:00
|
|
|
#include "button.h"
|
2009-07-06 14:46:19 +00:00
|
|
|
#include "backlight-target.h"
|
2010-08-31 06:53:28 +00:00
|
|
|
#include "lcd.h"
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2012-01-08 01:43:16 +00:00
|
|
|
/* Charge Pump and Power management Settings */
|
|
|
|
#define AS314_CP_DCDC3_SETTING \
|
|
|
|
((0<<7) | /* CP_SW Auto-Switch Margin 0=200/300 1=150/255 */ \
|
|
|
|
(0<<6) | /* CP_on 0=Normal op 1=Chg Pump Always On */ \
|
|
|
|
(0<<5) | /* LREG_CPnot Always write 0 */ \
|
|
|
|
(0<<3) | /* DCDC3p BVDD setting 3.6/3.2/3.1/3.0 */ \
|
|
|
|
(1<<2) | /* LREG_off 1=Auto mode switching 0=Length Reg only*/\
|
|
|
|
(0<<0) ) /* CVDDp Core Voltage Setting 1.2/1.15/1.10/1.05*/
|
|
|
|
|
|
|
|
#define CVDD_1_20 0
|
|
|
|
#define CVDD_1_15 1
|
|
|
|
#define CVDD_1_10 2
|
|
|
|
#define CVDD_1_05 3
|
|
|
|
|
2008-10-12 16:46:01 +00:00
|
|
|
#define default_interrupt(name) \
|
|
|
|
extern __attribute__((weak,alias("UIRQ"))) void name (void)
|
|
|
|
|
2010-05-26 16:03:01 +00:00
|
|
|
static void UIRQ (void) __attribute__((interrupt ("IRQ")));
|
2012-01-08 22:29:25 +00:00
|
|
|
void irq_handler(void) __attribute__((naked, interrupt ("IRQ")));
|
2010-05-26 16:03:01 +00:00
|
|
|
void fiq_handler(void) __attribute__((interrupt ("FIQ")));
|
2008-10-12 16:46:01 +00:00
|
|
|
|
|
|
|
default_interrupt(INT_WATCHDOG);
|
|
|
|
default_interrupt(INT_TIMER1);
|
|
|
|
default_interrupt(INT_TIMER2);
|
2012-04-28 19:49:31 +00:00
|
|
|
default_interrupt(INT_USB_FUNC);
|
2008-10-12 16:46:01 +00:00
|
|
|
default_interrupt(INT_DMAC);
|
|
|
|
default_interrupt(INT_NAND);
|
|
|
|
default_interrupt(INT_IDE);
|
|
|
|
default_interrupt(INT_MCI0);
|
|
|
|
default_interrupt(INT_MCI1);
|
|
|
|
default_interrupt(INT_AUDIO);
|
|
|
|
default_interrupt(INT_SSP);
|
|
|
|
default_interrupt(INT_I2C_MS);
|
|
|
|
default_interrupt(INT_I2C_AUDIO);
|
|
|
|
default_interrupt(INT_I2SIN);
|
|
|
|
default_interrupt(INT_I2SOUT);
|
|
|
|
default_interrupt(INT_UART);
|
|
|
|
default_interrupt(INT_GPIOD);
|
|
|
|
default_interrupt(RESERVED1); /* Interrupt 17 : unused */
|
|
|
|
default_interrupt(INT_CGU);
|
|
|
|
default_interrupt(INT_MEMORY_STICK);
|
|
|
|
default_interrupt(INT_DBOP);
|
|
|
|
default_interrupt(RESERVED2); /* Interrupt 21 : unused */
|
|
|
|
default_interrupt(RESERVED3); /* Interrupt 22 : unused */
|
|
|
|
default_interrupt(RESERVED4); /* Interrupt 23 : unused */
|
|
|
|
default_interrupt(RESERVED5); /* Interrupt 24 : unused */
|
|
|
|
default_interrupt(RESERVED6); /* Interrupt 25 : unused */
|
|
|
|
default_interrupt(RESERVED7); /* Interrupt 26 : unused */
|
|
|
|
default_interrupt(RESERVED8); /* Interrupt 27 : unused */
|
|
|
|
default_interrupt(RESERVED9); /* Interrupt 28 : unused */
|
2010-04-27 10:11:52 +00:00
|
|
|
/* INT_GPIOA is declared in this file */
|
|
|
|
void INT_GPIOA(void);
|
2008-10-12 16:46:01 +00:00
|
|
|
default_interrupt(INT_GPIOB);
|
|
|
|
default_interrupt(INT_GPIOC);
|
|
|
|
|
|
|
|
static const char * const irqname[] =
|
|
|
|
{
|
|
|
|
"INT_WATCHDOG", "INT_TIMER1", "INT_TIMER2", "INT_USB", "INT_DMAC", "INT_NAND",
|
|
|
|
"INT_IDE", "INT_MCI0", "INT_MCI1", "INT_AUDIO", "INT_SSP", "INT_I2C_MS",
|
|
|
|
"INT_I2C_AUDIO", "INT_I2SIN", "INT_I2SOUT", "INT_UART", "INT_GPIOD", "RESERVED1",
|
|
|
|
"INT_CGU", "INT_MEMORY_STICK", "INT_DBOP", "RESERVED2", "RESERVED3", "RESERVED4",
|
|
|
|
"RESERVED5", "RESERVED6", "RESERVED7", "RESERVED8", "RESERVED9", "INT_GPIOA",
|
|
|
|
"INT_GPIOB", "INT_GPIOC"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void UIRQ(void)
|
|
|
|
{
|
2010-05-24 14:32:38 +00:00
|
|
|
bool masked = false;
|
2008-11-02 17:11:33 +00:00
|
|
|
int status = VIC_IRQ_STATUS;
|
2010-05-24 14:32:38 +00:00
|
|
|
if(status == 0)
|
|
|
|
{
|
|
|
|
status = VIC_RAW_INTR; /* masked interrupts */
|
|
|
|
masked = true;
|
|
|
|
}
|
2009-08-11 13:20:55 +00:00
|
|
|
|
|
|
|
if(status == 0)
|
|
|
|
panicf("Unhandled IRQ (source unknown!)");
|
|
|
|
|
2010-05-25 16:20:04 +00:00
|
|
|
unsigned irq_no = 31 - __builtin_clz(status);
|
2008-11-02 17:11:33 +00:00
|
|
|
|
2010-05-24 14:32:38 +00:00
|
|
|
panicf("Unhandled %smasked IRQ %02X: %s (status 0x%8X)",
|
2010-05-26 14:45:59 +00:00
|
|
|
masked ? "" : "un", irq_no, irqname[irq_no], status);
|
2008-10-12 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
2008-12-05 17:10:11 +00:00
|
|
|
/* Vectored interrupts (16 available) */
|
2011-07-02 02:49:09 +00:00
|
|
|
static const struct { int source; void (*isr) (void); } vec_int_srcs[] =
|
2008-12-05 17:10:11 +00:00
|
|
|
{
|
2010-05-19 12:11:54 +00:00
|
|
|
/* Highest priority at the top of the list */
|
2012-01-08 22:29:25 +00:00
|
|
|
#if defined(HAVE_HOTSWAP) || defined(HAVE_RDS_CAP) || \
|
|
|
|
(defined(SANSA_FUZEV2) && !INCREASED_SCROLLWHEEL_POLLING)
|
|
|
|
/* If GPIOA ISR is interrupted, things seem to go wonky ?? */
|
|
|
|
{ INT_SRC_GPIOA, INT_GPIOA },
|
|
|
|
#endif
|
2011-12-12 20:12:22 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
{ INT_SRC_I2SIN, INT_I2SIN }, /* For recording */
|
|
|
|
#endif
|
|
|
|
{ INT_SRC_DMAC, INT_DMAC }, /* Playback follows recording */
|
2008-12-05 17:10:11 +00:00
|
|
|
{ INT_SRC_NAND, INT_NAND },
|
2010-04-06 17:22:45 +00:00
|
|
|
#if (defined HAVE_MULTIDRIVE && CONFIG_CPU == AS3525)
|
2008-12-05 17:10:11 +00:00
|
|
|
{ INT_SRC_MCI0, INT_MCI0 },
|
2009-11-01 23:41:10 +00:00
|
|
|
#endif
|
2012-04-28 19:49:31 +00:00
|
|
|
{ INT_SRC_USB, INT_USB_FUNC, },
|
2010-05-19 12:11:54 +00:00
|
|
|
{ INT_SRC_TIMER1, INT_TIMER1 },
|
|
|
|
{ INT_SRC_TIMER2, INT_TIMER2 },
|
|
|
|
{ INT_SRC_I2C_AUDIO, INT_I2C_AUDIO },
|
|
|
|
{ INT_SRC_AUDIO, INT_AUDIO },
|
|
|
|
/* Lowest priority at the end of the list */
|
2008-12-05 17:10:11 +00:00
|
|
|
};
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2008-12-05 17:10:11 +00:00
|
|
|
static void setup_vic(void)
|
|
|
|
{
|
|
|
|
CGU_PERI |= CGU_VIC_CLOCK_ENABLE; /* enable VIC */
|
|
|
|
VIC_INT_EN_CLEAR = 0xffffffff; /* disable all interrupt lines */
|
|
|
|
VIC_INT_SELECT = 0; /* only IRQ, no FIQ */
|
2008-11-02 17:11:33 +00:00
|
|
|
|
2010-05-26 16:03:01 +00:00
|
|
|
*VIC_DEF_VECT_ADDR = UIRQ;
|
2008-10-25 19:13:11 +00:00
|
|
|
|
2012-01-08 22:29:25 +00:00
|
|
|
for(unsigned int i = 0; i < ARRAYLEN(vec_int_srcs); i++)
|
2008-12-05 17:10:11 +00:00
|
|
|
{
|
2010-05-26 16:03:01 +00:00
|
|
|
VIC_VECT_ADDRS[i] = vec_int_srcs[i].isr;
|
|
|
|
VIC_VECT_CNTLS[i] = (1<<5) | vec_int_srcs[i].source;
|
2008-12-05 17:10:11 +00:00
|
|
|
}
|
2012-01-08 22:29:25 +00:00
|
|
|
|
|
|
|
/* Reset priority hardware */
|
|
|
|
for(unsigned int i = 0; i < 32; i++)
|
|
|
|
*VIC_VECT_ADDR = 0;
|
2008-12-05 17:10:11 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 10:11:52 +00:00
|
|
|
void INT_GPIOA(void)
|
|
|
|
{
|
2010-05-19 14:30:34 +00:00
|
|
|
#ifdef HAVE_HOTSWAP
|
2010-04-27 10:11:52 +00:00
|
|
|
void sd_gpioa_isr(void);
|
|
|
|
sd_gpioa_isr();
|
|
|
|
#endif
|
2010-05-19 14:41:56 +00:00
|
|
|
#if defined(SANSA_FUZEV2) && !INCREASED_SCROLLWHEEL_POLLING
|
2010-04-27 10:11:52 +00:00
|
|
|
void button_gpioa_isr(void);
|
|
|
|
button_gpioa_isr();
|
|
|
|
#endif
|
2011-12-17 20:24:19 +00:00
|
|
|
#ifdef HAVE_RDS_CAP
|
|
|
|
void tuner_isr(void);
|
|
|
|
tuner_isr();
|
|
|
|
#endif
|
2010-04-27 10:11:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-05 17:10:11 +00:00
|
|
|
void irq_handler(void)
|
|
|
|
{
|
2012-01-08 22:29:25 +00:00
|
|
|
/* Worst-case IRQ stack usage with 10 vectors:
|
|
|
|
* 10*4*10 = 400 bytes (100 words)
|
|
|
|
*
|
|
|
|
* No SVC stack is used by pro/epi-logue code
|
|
|
|
*/
|
|
|
|
asm volatile (
|
|
|
|
"sub lr, lr, #4 \n" /* Create return address */
|
|
|
|
"stmfd sp!, { r0-r5, r12, lr } \n" /* Save what gets clobbered */
|
|
|
|
"ldr r0, =0xc6010030 \n" /* Obtain VIC address (before SPSR read!) */
|
|
|
|
"ldr r12, [r0] \n" /* Load Vector */
|
|
|
|
"mrs r1, spsr \n" /* Save SPSR_irq */
|
|
|
|
"stmfd sp!, { r0-r1 } \n" /* Must have something bet. mrs and msr */
|
|
|
|
"msr cpsr_c, #0x13 \n" /* Switch to SVC mode, enable IRQ */
|
|
|
|
"and r4, sp, #4 \n" /* Align SVC stack to 8 bytes, save */
|
|
|
|
"sub sp, sp, r4 \n"
|
|
|
|
"mov r5, lr \n" /* Save lr_SVC */
|
|
|
|
#if ARM_ARCH >= 5
|
|
|
|
"blx r12 \n" /* Call handler */
|
|
|
|
#else
|
|
|
|
"mov lr, pc \n"
|
|
|
|
"bx r12 \n"
|
|
|
|
#endif
|
|
|
|
"add sp, sp, r4 \n" /* Undo alignment fudge */
|
|
|
|
"mov lr, r5 \n" /* Restore lr_SVC */
|
|
|
|
"msr cpsr_c, #0x92 \n" /* Mask IRQ, return to IRQ mode */
|
|
|
|
"ldmfd sp!, { r0-r1 } \n" /* Pop VIC address, SPSR_irq */
|
|
|
|
"str r0, [r0] \n" /* Ack end of ISR to VIC */
|
|
|
|
"msr spsr_cxsf, r1 \n" /* Restore SPSR_irq */
|
|
|
|
"ldmfd sp!, { r0-r5, r12, pc }^ \n" /* Restore regs, and RFE */
|
|
|
|
);
|
2008-10-12 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fiq_handler(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-04-06 18:32:47 +00:00
|
|
|
#if defined(SANSA_C200V2)
|
2010-07-19 15:29:28 +00:00
|
|
|
int c200v2_variant;
|
2010-04-06 18:32:47 +00:00
|
|
|
|
|
|
|
static void check_model_variant(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int saved_dir = GPIOA_DIR;
|
|
|
|
|
|
|
|
/* Make A7 input */
|
|
|
|
GPIOA_DIR &= ~(1<<7);
|
|
|
|
/* wait a little to allow the pullup/pulldown resistor
|
|
|
|
* to charge the input capacitance */
|
|
|
|
for (i=0; i<1000; i++) asm volatile ("nop\n");
|
|
|
|
/* read the pullup/pulldown value on A7 to determine the variant */
|
2010-07-19 15:29:28 +00:00
|
|
|
c200v2_variant = !GPIOA_PIN(7);
|
2010-04-06 18:32:47 +00:00
|
|
|
GPIOA_DIR = saved_dir;
|
|
|
|
}
|
2011-10-29 17:08:05 +00:00
|
|
|
#elif defined(SANSA_FUZEV2) || defined(SANSA_CLIPPLUS) || defined(SANSA_CLIPZIP)
|
2010-07-22 13:47:09 +00:00
|
|
|
int amsv2_variant;
|
2010-07-19 15:29:28 +00:00
|
|
|
|
|
|
|
static void check_model_variant(void)
|
|
|
|
{
|
|
|
|
GPIOB_DIR &= ~(1<<5);
|
2010-07-22 13:47:09 +00:00
|
|
|
amsv2_variant = !!GPIOB_PIN(5);
|
2010-07-19 15:29:28 +00:00
|
|
|
}
|
2010-04-06 18:32:47 +00:00
|
|
|
#else
|
|
|
|
static inline void check_model_variant(void)
|
|
|
|
{
|
|
|
|
}
|
2010-07-19 15:29:28 +00:00
|
|
|
#endif /* model selection */
|
2010-04-06 18:32:47 +00:00
|
|
|
|
2008-10-12 16:46:01 +00:00
|
|
|
void system_init(void)
|
|
|
|
{
|
2010-02-05 12:40:25 +00:00
|
|
|
#if CONFIG_CPU == AS3525v2
|
2009-12-31 19:15:20 +00:00
|
|
|
CCU_SRC = 0x57D7BF0;
|
2010-02-05 12:40:25 +00:00
|
|
|
#else
|
2009-04-07 16:14:01 +00:00
|
|
|
CCU_SRC = 0x1fffff0
|
2010-02-17 23:27:35 +00:00
|
|
|
& ~CCU_SRC_IDE_EN; /* FIXME */
|
2010-02-23 06:59:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
unsigned int reset_loops = 640;
|
2009-04-07 16:14:01 +00:00
|
|
|
while(reset_loops--)
|
|
|
|
CCU_SRL = CCU_SRL_MAGIC_NUMBER;
|
|
|
|
CCU_SRC = CCU_SRL = 0;
|
2008-10-28 11:24:29 +00:00
|
|
|
|
2009-06-08 23:05:33 +00:00
|
|
|
CCU_SCON = 1; /* AHB master's priority configuration :
|
|
|
|
TIC (Test Interface Controller) > DMA > USB > IDE > ARM */
|
|
|
|
|
2010-04-01 03:55:49 +00:00
|
|
|
CGU_PROC = 0; /* fclk 24 MHz */
|
2010-04-01 08:21:21 +00:00
|
|
|
#if CONFIG_CPU == AS3525v2
|
|
|
|
/* pclk is always based on PLLA, since we don't know the current PLLA speed,
|
|
|
|
* avoid having pclk too fast and hope it's not too low */
|
|
|
|
CGU_PERI |= 0xf << 2; /* pclk lowest */
|
|
|
|
#else
|
2008-11-02 00:34:44 +00:00
|
|
|
CGU_PERI &= ~0x7f; /* pclk 24 MHz */
|
2010-04-01 08:21:21 +00:00
|
|
|
#endif
|
2008-11-02 00:34:44 +00:00
|
|
|
|
2011-12-10 11:28:00 +00:00
|
|
|
CGU_PERI &= ~CGU_ROM_ENABLE; /*disable built in boot rom clock*/
|
2011-11-08 02:07:26 +00:00
|
|
|
|
2010-04-01 04:37:17 +00:00
|
|
|
/* bits 31:30 should be set to 0 in arm926-ejs */
|
2010-04-01 02:39:25 +00:00
|
|
|
asm volatile(
|
|
|
|
"mrc p15, 0, r0, c1, c0 \n" /* control register */
|
|
|
|
"bic r0, r0, #3<<30 \n" /* clears bus bits : sets fastbus */
|
|
|
|
"mcr p15, 0, r0, c1, c0 \n"
|
|
|
|
: : : "r0" );
|
|
|
|
|
2010-05-18 16:23:11 +00:00
|
|
|
CGU_COUNTA = CGU_LOCK_CNT;
|
2008-12-04 20:04:31 +00:00
|
|
|
CGU_PLLA = AS3525_PLLA_SETTING;
|
2010-05-18 16:23:11 +00:00
|
|
|
CGU_PLLASUP = 0; /* enable PLLA */
|
|
|
|
while(!(CGU_INTCTRL & CGU_PLLA_LOCK)); /* wait until PLLA is locked */
|
|
|
|
|
|
|
|
#if AS3525_MCLK_SEL == AS3525_CLK_PLLB
|
|
|
|
CGU_COUNTB = CGU_LOCK_CNT;
|
2010-01-10 14:24:45 +00:00
|
|
|
CGU_PLLB = AS3525_PLLB_SETTING;
|
2010-05-18 16:23:11 +00:00
|
|
|
CGU_PLLBSUP = 0; /* enable PLLB */
|
|
|
|
while(!(CGU_INTCTRL & CGU_PLLB_LOCK)); /* wait until PLLB is locked */
|
2010-01-10 14:24:45 +00:00
|
|
|
#endif
|
2009-05-26 18:44:02 +00:00
|
|
|
|
|
|
|
/* Set FCLK frequency */
|
|
|
|
CGU_PROC = ((AS3525_FCLK_POSTDIV << 4) |
|
|
|
|
(AS3525_FCLK_PREDIV << 2) |
|
|
|
|
AS3525_FCLK_SEL);
|
2010-02-23 06:59:58 +00:00
|
|
|
|
2009-05-26 18:44:02 +00:00
|
|
|
/* Set PCLK frequency */
|
2010-02-23 06:59:58 +00:00
|
|
|
CGU_PERI = ((CGU_PERI & ~0x7F) | /* reset divider & clksel bits */
|
2009-05-26 18:44:02 +00:00
|
|
|
(AS3525_PCLK_DIV0 << 2) |
|
2010-04-05 04:48:43 +00:00
|
|
|
#if CONFIG_CPU == AS3525
|
2009-05-26 18:44:02 +00:00
|
|
|
(AS3525_PCLK_DIV1 << 6) |
|
2010-04-05 04:48:43 +00:00
|
|
|
#endif
|
2009-05-26 18:44:02 +00:00
|
|
|
AS3525_PCLK_SEL);
|
2008-11-02 00:34:44 +00:00
|
|
|
|
2010-09-05 15:34:34 +00:00
|
|
|
set_cpu_frequency(CPUFREQ_DEFAULT);
|
2010-06-23 07:06:06 +00:00
|
|
|
|
2008-12-04 20:04:31 +00:00
|
|
|
#if 0 /* the GPIO clock is already enabled by the dualboot function */
|
|
|
|
CGU_PERI |= CGU_GPIO_CLOCK_ENABLE;
|
|
|
|
#endif
|
2008-11-02 00:34:44 +00:00
|
|
|
|
2008-11-06 02:31:32 +00:00
|
|
|
/* enable timer interface for TIMER1 & TIMER2 */
|
|
|
|
CGU_PERI |= CGU_TIMERIF_CLOCK_ENABLE;
|
|
|
|
|
2008-12-05 17:10:11 +00:00
|
|
|
setup_vic();
|
2008-12-04 20:04:31 +00:00
|
|
|
|
|
|
|
dma_init();
|
|
|
|
|
2009-04-07 16:14:01 +00:00
|
|
|
ascodec_init();
|
2011-09-18 15:33:19 +00:00
|
|
|
|
2011-09-21 21:48:19 +00:00
|
|
|
/* Initialize power management settings */
|
|
|
|
#ifdef HAVE_AS3543
|
2011-09-18 15:33:19 +00:00
|
|
|
/* PLL: disable audio PLL, we use MCLK already */
|
|
|
|
ascodec_write_pmu(0x1A, 7, 0x02);
|
|
|
|
/* DCDC_Cntr: set switching speed of CVDD1/2 power supplies to 1 MHz */
|
|
|
|
ascodec_write_pmu(0x17, 7, 0x30);
|
|
|
|
/* Out_Cntr2: set drive strength of 24 MHz and 32 kHz clocks to 1 mA */
|
|
|
|
ascodec_write_pmu(0x1A, 2, 0xCC);
|
|
|
|
/* CHGVBUS2: set VBUS threshold to 3.18V and EOC threshold to 30% CC */
|
|
|
|
ascodec_write_pmu(0x19, 2, 0x41);
|
|
|
|
/* PVDD1: set PVDD1 power supply to 2.5 V */
|
|
|
|
ascodec_write_pmu(0x18, 1, 0x35);
|
|
|
|
/* AVDD17: set AVDD17 power supply to 2.5V */
|
|
|
|
ascodec_write_pmu(0x18, 7, 0x31);
|
2011-10-23 14:20:47 +00:00
|
|
|
#ifdef SANSA_CLIPZIP
|
|
|
|
/* CVDD2: set CVDD2 power supply to 2.8V */
|
|
|
|
ascodec_write_pmu(0x17, 2, 0xF4);
|
|
|
|
#endif
|
|
|
|
#else /* HAVE_AS3543 */
|
2011-09-21 21:48:19 +00:00
|
|
|
ascodec_write(AS3514_CVDD_DCDC3, AS314_CP_DCDC3_SETTING);
|
|
|
|
#endif /* HAVE_AS3543 */
|
2009-04-07 16:14:01 +00:00
|
|
|
|
2008-12-04 20:04:31 +00:00
|
|
|
#ifndef BOOTLOADER
|
2010-05-19 14:30:34 +00:00
|
|
|
/* setup isr for microsd monitoring and for fuzev2 scrollwheel irq */
|
|
|
|
#if defined(HAVE_HOTSWAP) || \
|
2010-05-19 14:41:56 +00:00
|
|
|
(defined(SANSA_FUZEV2) && !INCREASED_SCROLLWHEEL_POLLING)
|
2010-04-27 10:11:52 +00:00
|
|
|
VIC_INT_ENABLE = (INTERRUPT_GPIOA);
|
|
|
|
/* pin selection for irq happens in the drivers */
|
|
|
|
#endif
|
|
|
|
|
2010-02-22 02:42:58 +00:00
|
|
|
#if CONFIG_TUNER
|
2009-01-21 20:51:43 +00:00
|
|
|
fmradio_i2c_init();
|
|
|
|
#endif
|
2008-12-04 20:04:31 +00:00
|
|
|
#endif /* !BOOTLOADER */
|
2010-04-06 18:32:47 +00:00
|
|
|
check_model_variant();
|
2008-10-12 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void system_reboot(void)
|
|
|
|
{
|
2009-07-06 14:46:19 +00:00
|
|
|
_backlight_off();
|
2010-07-19 15:56:10 +00:00
|
|
|
|
|
|
|
disable_irq();
|
|
|
|
|
2011-12-10 11:28:00 +00:00
|
|
|
/* re-enable internal ROM */
|
|
|
|
CGU_PERI |= CGU_ROM_ENABLE;
|
|
|
|
|
2008-12-30 23:53:35 +00:00
|
|
|
/* use watchdog to reset */
|
|
|
|
CGU_PERI |= (CGU_WDOCNT_CLOCK_ENABLE | CGU_WDOIF_CLOCK_ENABLE);
|
|
|
|
WDT_LOAD = 1; /* set counter to 1 */
|
|
|
|
WDT_CONTROL = 3; /* enable watchdog counter & reset */
|
|
|
|
while(1);
|
2008-10-12 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
2009-01-08 10:15:32 +00:00
|
|
|
void system_exception_wait(void)
|
|
|
|
{
|
2010-06-18 13:45:24 +00:00
|
|
|
/* make sure lcd+backlight are on */
|
|
|
|
_backlight_panic_on();
|
2010-08-31 06:49:08 +00:00
|
|
|
/* make sure screen content is up to date */
|
|
|
|
lcd_update();
|
2009-11-03 07:42:42 +00:00
|
|
|
/* wait until button release (if a button is pressed) */
|
|
|
|
while(button_read_device());
|
|
|
|
/* then wait until next button press */
|
2009-04-07 16:14:01 +00:00
|
|
|
while(!button_read_device());
|
2009-01-08 10:15:32 +00:00
|
|
|
}
|
|
|
|
|
2008-10-12 16:46:01 +00:00
|
|
|
int system_memory_guard(int newmode)
|
|
|
|
{
|
|
|
|
(void)newmode;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-09 06:17:21 +00:00
|
|
|
|
2010-06-18 20:04:16 +00:00
|
|
|
/* usecs may be at most 2^32/248 (17 seconds) for 248MHz max cpu freq */
|
|
|
|
void udelay(unsigned usecs)
|
2010-06-18 19:14:08 +00:00
|
|
|
{
|
|
|
|
unsigned cycles_per_usec;
|
|
|
|
unsigned delay;
|
|
|
|
|
|
|
|
if (cpu_frequency == CPUFREQ_MAX) {
|
|
|
|
cycles_per_usec = (CPUFREQ_MAX + 999999) / 1000000;
|
|
|
|
} else {
|
|
|
|
cycles_per_usec = (CPUFREQ_NORMAL + 999999) / 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
delay = (usecs * cycles_per_usec + 3) / 4;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
"1: subs %0, %0, #1 \n" /* 1 cycle */
|
|
|
|
" bne 1b \n" /* 3 cycles */
|
|
|
|
: : "r"(delay)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-11-10 11:04:43 +00:00
|
|
|
#ifndef BOOTLOADER
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2010-04-06 17:22:57 +00:00
|
|
|
|
|
|
|
#if CONFIG_CPU == AS3525
|
2008-11-10 11:04:43 +00:00
|
|
|
void set_cpu_frequency(long frequency)
|
|
|
|
{
|
2009-05-26 18:44:02 +00:00
|
|
|
if(frequency == CPUFREQ_MAX)
|
|
|
|
{
|
2010-12-29 16:07:15 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_VOLTAGE
|
2009-06-30 17:56:21 +00:00
|
|
|
/* Increasing frequency so boost voltage before change */
|
|
|
|
ascodec_write(AS3514_CVDD_DCDC3, (AS314_CP_DCDC3_SETTING | CVDD_1_20));
|
2009-07-05 09:24:56 +00:00
|
|
|
|
2009-10-16 17:44:23 +00:00
|
|
|
/* Some players run a bit low so use 1.175 volts instead of 1.20 */
|
|
|
|
/* Wait for voltage to be at least 1.175v before making fclk > 200 MHz */
|
|
|
|
while(adc_read(ADC_CVDD) < 470); /* 470 * .0025 = 1.175V */
|
2010-01-12 23:56:59 +00:00
|
|
|
#endif /* HAVE_ADJUSTABLE_CPU_VOLTAGE */
|
2009-10-15 19:48:26 +00:00
|
|
|
|
2010-09-05 15:34:34 +00:00
|
|
|
CGU_PROC = ((AS3525_FCLK_POSTDIV << 4) |
|
|
|
|
(AS3525_FCLK_PREDIV << 2) |
|
|
|
|
AS3525_FCLK_SEL);
|
|
|
|
|
2009-05-26 18:44:02 +00:00
|
|
|
asm volatile(
|
|
|
|
"mrc p15, 0, r0, c1, c0 \n"
|
2010-11-18 16:37:56 +00:00
|
|
|
"orr r0, r0, #3<<30 \n" /* asynchronous bus clocking */
|
|
|
|
/* synchronous bus clocking had issues on some players */
|
2009-05-26 18:44:02 +00:00
|
|
|
"mcr p15, 0, r0, c1, c0 \n"
|
|
|
|
: : : "r0" );
|
|
|
|
|
|
|
|
cpu_frequency = CPUFREQ_MAX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"mrc p15, 0, r0, c1, c0 \n"
|
|
|
|
"bic r0, r0, #3<<30 \n" /* fastbus clocking */
|
|
|
|
"mcr p15, 0, r0, c1, c0 \n"
|
|
|
|
: : : "r0" );
|
2010-04-05 04:48:43 +00:00
|
|
|
|
2010-09-05 15:34:34 +00:00
|
|
|
/* FCLK is unused so put it to the lowest freq we can */
|
|
|
|
CGU_PROC = ((0xf << 4) | (0x3 << 2) | AS3525_CLK_MAIN);
|
2009-10-15 19:48:26 +00:00
|
|
|
|
2010-12-29 16:07:15 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_VOLTAGE
|
2009-06-30 17:56:21 +00:00
|
|
|
/* Decreasing frequency so reduce voltage after change */
|
|
|
|
ascodec_write(AS3514_CVDD_DCDC3, (AS314_CP_DCDC3_SETTING | CVDD_1_10));
|
2010-01-12 23:56:59 +00:00
|
|
|
#endif /* HAVE_ADJUSTABLE_CPU_VOLTAGE */
|
2009-10-15 19:48:26 +00:00
|
|
|
|
2009-05-26 18:44:02 +00:00
|
|
|
cpu_frequency = CPUFREQ_NORMAL;
|
|
|
|
}
|
2008-11-09 06:17:21 +00:00
|
|
|
}
|
2010-04-06 17:22:57 +00:00
|
|
|
#else /* as3525v2 */
|
2010-05-10 03:49:17 +00:00
|
|
|
/* FIXME : disabled for now, seems to cause buggy memory accesses
|
|
|
|
* Disabling MMU or putting the function in uncached memory seems to help? */
|
2010-04-06 17:22:57 +00:00
|
|
|
void set_cpu_frequency(long frequency)
|
|
|
|
{
|
2010-04-10 20:00:15 +00:00
|
|
|
int oldstatus = disable_irq_save();
|
2010-04-29 03:15:18 +00:00
|
|
|
|
|
|
|
/* We only have 2 settings */
|
|
|
|
cpu_frequency = (frequency == CPUFREQ_MAX) ? frequency : CPUFREQ_NORMAL;
|
2010-04-10 20:00:15 +00:00
|
|
|
|
2010-04-06 17:22:57 +00:00
|
|
|
if(frequency == CPUFREQ_MAX)
|
|
|
|
{
|
|
|
|
/* Change PCLK while FCLK is low, so it doesn't go too high */
|
2010-04-11 18:26:45 +00:00
|
|
|
CGU_PERI = (CGU_PERI & ~(0xF << 2)) | (AS3525_PCLK_DIV0 << 2);
|
2010-04-06 17:22:57 +00:00
|
|
|
|
|
|
|
CGU_PROC = ((AS3525_FCLK_POSTDIV << 4) |
|
|
|
|
(AS3525_FCLK_PREDIV << 2) |
|
|
|
|
AS3525_FCLK_SEL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CGU_PROC = ((AS3525_FCLK_POSTDIV_UNBOOSTED << 4) |
|
|
|
|
(AS3525_FCLK_PREDIV << 2) |
|
|
|
|
AS3525_FCLK_SEL);
|
|
|
|
|
|
|
|
/* Change PCLK after FCLK is low, so it doesn't go too high */
|
2010-04-11 18:26:45 +00:00
|
|
|
CGU_PERI = (CGU_PERI & ~(0xF << 2)) | (AS3525_PCLK_DIV0_UNBOOSTED << 2);
|
2010-04-10 20:00:15 +00:00
|
|
|
}
|
2010-04-06 17:22:57 +00:00
|
|
|
|
2010-04-10 20:00:15 +00:00
|
|
|
restore_irq(oldstatus);
|
2010-04-06 17:22:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-10 11:04:43 +00:00
|
|
|
#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
|
2009-05-26 18:44:02 +00:00
|
|
|
#endif /* !BOOTLOADER */
|