diff --git a/apps/plugins/plugin.lds b/apps/plugins/plugin.lds index 9a65fd5..7d26edc 100644 --- a/apps/plugins/plugin.lds +++ b/apps/plugins/plugin.lds @@ -1,4 +1,5 @@ #include "config.h" +#include "cpu.h" /* These output formats should be in the config-files */ @@ -48,9 +49,9 @@ OUTPUT_FORMAT(elf32-littlemips) #elif CONFIG_CPU==AS3525 #if MEMORYSIZE <= 2 -#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGIN_BUFFER_SIZE - STUBOFFSET +#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGIN_BUFFER_SIZE - STUBOFFSET - TTB_SIZE #else -#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGIN_BUFFER_SIZE - STUBOFFSET - CODEC_SIZE +#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGIN_BUFFER_SIZE - STUBOFFSET - CODEC_SIZE - TTB_SIZE #endif #endif diff --git a/firmware/SOURCES b/firmware/SOURCES index 8610c1c..3a793cc 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -362,6 +362,7 @@ target/arm/as3525/usb-as3525.c target/arm/as3525/dma-pl081.c target/arm/as3525/ascodec-as3525.c #ifndef BOOTLOADER +target/arm/mmu-arm.S drivers/generic_i2c.c target/arm/adc-as3514.c target/arm/as3525/audio-as3525.c diff --git a/firmware/export/as3525.h b/firmware/export/as3525.h index 388df2a..5d589d0 100644 --- a/firmware/export/as3525.h +++ b/firmware/export/as3525.h @@ -475,4 +475,7 @@ interface */ #define I2SOUT_CLEAR (*(volatile unsigned char*)(I2SOUT_BASE+0x10)) #define I2SOUT_DATA (volatile unsigned long*)(I2SOUT_BASE+0x14) +#define TTB_SIZE 0x4000 +#define TTB_BASE_ADDR (0x30000000 + (MEMORYSIZE*0x100000) - TTB_SIZE) + #endif /*__AS3525_H__*/ diff --git a/firmware/target/arm/as3525/app.lds b/firmware/target/arm/as3525/app.lds index 7f37cc5..f1f7f62 100644 --- a/firmware/target/arm/as3525/app.lds +++ b/firmware/target/arm/as3525/app.lds @@ -1,4 +1,5 @@ #include "config.h" +#include "cpu.h" ENTRY(start) @@ -23,11 +24,11 @@ STARTUP(target/arm/crt0.o) #include "cpu.h" #ifdef LOWMEM -#define DRAMSIZE (MEMORYSIZE * 0x100000) - STUBOFFSET - PLUGINSIZE +#define DRAMSIZE (MEMORYSIZE * 0x100000) - STUBOFFSET - PLUGINSIZE - TTB_SIZE #define CODECORIG (IRAMORIG + 0x50000 - CODEC_SIZE) #define IRAMSIZE (0x50000 - CODEC_SIZE) #else -#define DRAMSIZE (MEMORYSIZE * 0x100000) - STUBOFFSET - PLUGINSIZE - CODECSIZE +#define DRAMSIZE (MEMORYSIZE * 0x100000) - STUBOFFSET - PLUGINSIZE - CODECSIZE - TTB_SIZE #define CODECORIG (ENDAUDIOADDR) #define IRAMSIZE (0x20000) #endif diff --git a/firmware/target/arm/as3525/ata_sd_as3525.c b/firmware/target/arm/as3525/ata_sd_as3525.c index 7e5bc12..f3463c2 100644 --- a/firmware/target/arm/as3525/ata_sd_as3525.c +++ b/firmware/target/arm/as3525/ata_sd_as3525.c @@ -646,7 +646,7 @@ static int sd_select_bank(signed char bank) } #define UNALIGNED_NUM_SECTORS 10 -static int32_t aligned_buffer[UNALIGNED_NUM_SECTORS* (SECTOR_SIZE / 4)]; +static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SECTOR_SIZE] __attribute__((aligned(32))); static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf, const bool write) @@ -656,7 +656,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, #endif int ret = 0; int bank; - bool unaligned_transfer = (int)buf & 3; + bool unaligned_transfer = true/*(int)buf & 3*/; /* skip SanDisk OF */ if (drive == INTERNAL_AS3525) @@ -710,6 +710,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, while(count) { + unsigned char *uncached_buf = aligned_buffer + 0x10000000; /* 128 * 512 = 2^16, and doesn't fit in the 16 bits of DATA_LENGTH * register, so we have to transfer maximum 127 sectors at a time. */ unsigned int transfer = (count >= 128) ? 127 : count; /* sectors */ @@ -729,7 +730,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, if(transfer > UNALIGNED_NUM_SECTORS) transfer = UNALIGNED_NUM_SECTORS; if(write) - memcpy(aligned_buffer, buf, transfer * SECTOR_SIZE); + memcpy(uncached_buf, buf, transfer * SECTOR_SIZE); } else dma_buf = buf; @@ -761,7 +762,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, if(!retry) { if(unaligned_transfer && !write) - memcpy(buf, aligned_buffer, transfer * SECTOR_SIZE); + memcpy(buf, uncached_buf, transfer * SECTOR_SIZE); buf += transfer * SECTOR_SIZE; start += transfer; count -= transfer; diff --git a/firmware/target/arm/as3525/clock-target.h b/firmware/target/arm/as3525/clock-target.h index a227f46..0c97170 100644 --- a/firmware/target/arm/as3525/clock-target.h +++ b/firmware/target/arm/as3525/clock-target.h @@ -33,19 +33,19 @@ #define CPUFREQ_MAX 248000000 -#define CPUFREQ_DEFAULT 24800000 +#define CPUFREQ_DEFAULT 124000000 -#define CPUFREQ_NORMAL 31000000 +#define CPUFREQ_NORMAL 124000000 /* peripherals */ -#define AS3525_PCLK_FREQ 65000000 +#define AS3525_PCLK_FREQ 62000000 -#define AS3525_IDE_FREQ 90000000 +#define AS3525_IDE_FREQ 66000000 #define AS3525_SD_IDENT_FREQ 400000 /* must be between 100 & 400 kHz */ -#define AS3525_I2C_FREQ 400000 +#define AS3525_I2C_FREQ 1600000 /* LCD controller : varies on the models */ #if defined(SANSA_CLIP) diff --git a/firmware/target/arm/as3525/pcm-as3525.c b/firmware/target/arm/as3525/pcm-as3525.c index 5074941..6024633 100644 --- a/firmware/target/arm/as3525/pcm-as3525.c +++ b/firmware/target/arm/as3525/pcm-as3525.c @@ -28,6 +28,7 @@ #include "panic.h" #include "as3514.h" #include "audiohw.h" +#include "mmu-arm.h" #define MAX_TRANSFER (4*((1<<11)-1)) /* maximum data we can transfer via DMA * i.e. 32 bits at once (size of I2SO_DATA) @@ -69,6 +70,7 @@ static void play_start_pcm(void) CGU_PERI |= CGU_I2SOUT_APB_CLOCK_ENABLE; CGU_AUDIO |= (1<<11); + clean_dcache_range((void*)addr, size); /* force write back */ dma_enable_channel(1, (void*)addr, (void*)I2SOUT_DATA, DMA_PERI_I2SOUT, DMAC_FLOWCTRL_DMAC_MEM_TO_PERI, true, false, size >> 2, DMA_S1, dma_callback); diff --git a/firmware/target/arm/as3525/system-as3525.c b/firmware/target/arm/as3525/system-as3525.c index a5f34d9..f9f3fd5 100644 --- a/firmware/target/arm/as3525/system-as3525.c +++ b/firmware/target/arm/as3525/system-as3525.c @@ -28,6 +28,9 @@ #include "clock-target.h" #include "fmradio_i2c.h" #include "button-target.h" +#ifndef BOOTLOADER +#include "mmu-arm.h" +#endif #define default_interrupt(name) \ extern __attribute__((weak,alias("UIRQ"))) void name (void) @@ -226,37 +229,40 @@ void system_init(void) CCU_SRL = CCU_SRL_MAGIC_NUMBER; CCU_SRC = CCU_SRL = 0; - CGU_PROC = 0; /* fclk 24 MHz */ - CGU_PERI &= ~0x7f; /* pclk 24 MHz */ - asm volatile( "mrc p15, 0, r0, c1, c0 \n" - "orr r0, r0, #0xC0000000 \n" /* asynchronous clocking */ + "bic r0, r0, #0xC0000000 \n" /* fastbus clocking */ "mcr p15, 0, r0, c1, c0 \n" : : : "r0" ); + CGU_PROC = 0; /* fclk 24 MHz */ + CGU_PERI &= ~0x7f; /* pclk 24 MHz */ + + CGU_COUNTA = 0xff; CGU_PLLA = AS3525_PLLA_SETTING; while(!(CGU_INTCTRL & (1<<0))); /* wait until PLLA is locked */ CGU_PROC = (AS3525_CPU_PREDIV << 2) | 1; + set_cpu_frequency(CPUFREQ_DEFAULT); CGU_PERI |= ((CLK_DIV(AS3525_PLLA_FREQ, AS3525_PCLK_FREQ) - 1) << 2) | 1; /* clk_in = PLLA */ - - /* FIXME: dcache will not be active, since the mmu is not running - * See arm922t datasheet */ asm volatile( - "mov r0, #0 \n" - "mcr p15, 0, r0, c7, c7 \n" /* invalidate icache & dcache */ - "mrc p15, 0, r0, c1, c0 \n" /* control register */ - "orr r0, r0, #0x1000 \n" /* enable icache */ - "orr r0, r0, #4 \n" /* enable dcache */ - "mcr p15, 0, r0, c1, c0 \n" + "mrc p15, 0, r0, c1, c0 \n" + "orr r0, r0, #0xC0000000 \n" /* asynchronous clocking */ + "mcr p15, 0, r0, c1, c0 \n" : : : "r0" ); #ifdef BOOTLOADER sdram_init(); +#else + ttb_init(); + map_section(0, 0, 0x1000, CACHE_NONE); + map_section(0, 0, 1, CACHE_ALL); /* IRAM */ + map_section(0x30000000, 0x30000000, MEMORYSIZE, CACHE_ALL); /* sdram */ + map_section(0x30000000, 0x40000000, MEMORYSIZE, CACHE_NONE); /* sdram */ + enable_mmu(); #endif /* BOOTLOADER */ #if 0 /* the GPIO clock is already enabled by the dualboot function */