From 9a5a0dc9ff4086a295832709c609276512f54743 Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 4 Oct 2013 03:14:02 +0300 Subject: [PATCH] gp2x: pollux: bring back ram timings --- gp2x/pollux_set.c | 15 +++++++++++++++ gp2x/pollux_set.h | 2 ++ gp2x/soc_pollux.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/gp2x/pollux_set.c b/gp2x/pollux_set.c index 9781c82..0af6468 100644 --- a/gp2x/pollux_set.c +++ b/gp2x/pollux_set.c @@ -337,6 +337,21 @@ again: return 0; } +int pollux_set_fromenv(volatile unsigned short *memregs, + const char *env_var) +{ + const char *set_string; + int ret = -1; + + set_string = getenv(env_var); + if (set_string) + ret = pollux_set(memregs, set_string); + else + printf("env var %s not defined.\n", env_var); + + return ret; +} + #ifdef BINARY #include #include diff --git a/gp2x/pollux_set.h b/gp2x/pollux_set.h index 64bb220..42aa9ba 100644 --- a/gp2x/pollux_set.h +++ b/gp2x/pollux_set.h @@ -4,6 +4,8 @@ extern "C" #endif int pollux_set(volatile unsigned short *memregs, const char *str); +int pollux_set_fromenv(volatile unsigned short *memregs, + const char *env_var); #ifdef __cplusplus } diff --git a/gp2x/soc_pollux.c b/gp2x/soc_pollux.c index bbccede..5b0b3ff 100644 --- a/gp2x/soc_pollux.c +++ b/gp2x/soc_pollux.c @@ -29,10 +29,12 @@ #include "soc.h" #include "plat_gp2x.h" +#include "pollux_set.h" #include "../plat.h" static int battdev = -1, mixerdev = -1; static int cpu_clock_allowed; +static unsigned short saved_memtimex[2]; static unsigned int saved_video_regs[2][6]; static unsigned int timer_drift; // count per real second @@ -59,6 +61,26 @@ static int decode_pll(unsigned int reg) return v; } +/* RAM timings */ +static void set_ram_timings(void) +{ + pollux_set_fromenv(memregs, "POLLUX_RAM_TIMINGS"); +} + +static void unset_ram_timings(void) +{ + int i; + + memregs[0x14802>>1] = saved_memtimex[0]; + memregs[0x14804>>1] = saved_memtimex[1] | 0x8000; + + for (i = 0; i < 0x100000; i++) + if (!(memregs[0x14804>>1] & 0x8000)) + break; + + printf("RAM timings reset to startup values.\n"); +} + #define TIMER_BASE3 0x1980 #define TIMER_REG(x) memregl[(TIMER_BASE3 + x) >> 2] @@ -235,6 +257,11 @@ void pollux_init(void) } memregl = (volatile void *)memregs; + saved_memtimex[0] = memregs[0x14802>>1]; + saved_memtimex[1] = memregs[0x14804>>1]; + + set_ram_timings(); + // save video regs of both MLCs save_multiple_regs(saved_video_regs[0], 0x4058, ARRAY_SIZE(saved_video_regs[0])); save_multiple_regs(saved_video_regs[1], 0x4458, ARRAY_SIZE(saved_video_regs[1])); @@ -305,6 +332,8 @@ void pollux_finish(void) { timer_cleanup(); + unset_ram_timings(); + restore_multiple_regs(0x4058, saved_video_regs[0], ARRAY_SIZE(saved_video_regs[0])); restore_multiple_regs(0x4458, saved_video_regs[1], -- 2.39.5