X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fgp2x%2Fsoc_pollux.c;h=3b2ca2df26b6be1017e734fecee814dfabadd9d4;hb=45f2f245f51ef0c0d37df3c998595c132bfcaffa;hp=7b71324c6f2ca05177c924bb4788e64a3d8946d1;hpb=61753a672400a712390fb7a0cfb325c640bce479;p=picodrive.git diff --git a/platform/gp2x/soc_pollux.c b/platform/gp2x/soc_pollux.c index 7b71324..3b2ca2d 100644 --- a/platform/gp2x/soc_pollux.c +++ b/platform/gp2x/soc_pollux.c @@ -1,3 +1,11 @@ +/* + * + * 00000000-029fffff linux (42MB) + * 02a00000-02dfffff fb (4MB, 153600B really used) + * 02e00000-02ffffff sound dma (2MB) + * 03000000-03ffffff MPEGDEC (?, 16MB) + * + */ #include #include #include @@ -34,6 +42,17 @@ static unsigned int pllsetreg0; static int last_pal_setting = 0; +/* misc */ +static void pollux_set_fromenv(const char *env_var) +{ + const char *set_string; + set_string = getenv(env_var); + if (set_string) + pollux_set(memregs, set_string); + else + printf("env var %s not defined.\n", env_var); +} + /* video stuff */ static void pollux_video_flip(int buf_count) { @@ -62,6 +81,7 @@ static void gp2x_video_changemode_ll_(int bpp) int code = 0, bytes = 2; int rot_cmd[2] = { 0, 0 }; unsigned int r; + char buff[32]; int ret; if (bpp == prev_bpp) @@ -79,7 +99,8 @@ static void gp2x_video_changemode_ll_(int bpp) memregl[0x4000>>2] |= 1 << 3; /* the above ioctl resets LCD timings, so set them here */ - set_lcd_custom_rate(last_pal_setting); + snprintf(buff, sizeof(buff), "POLLUX_LCD_TIMINGS_%s", last_pal_setting ? "PAL" : "NTSC"); + pollux_set_fromenv(buff); switch (abs(bpp)) { @@ -141,17 +162,6 @@ static void gp2x_set_cpuclk_(unsigned int mhz) cpuclk_was_changed = 1; } -/* misc */ -static void pollux_set_fromenv(const char *env_var) -{ - const char *set_string; - set_string = getenv(env_var); - if (set_string) - pollux_set(memregs, set_string); - else - printf("env var %s not defined.\n", env_var); -} - /* RAM timings */ static void set_ram_timings_(void) { @@ -175,10 +185,7 @@ static void unset_ram_timings_(void) /* LCD refresh */ static void set_lcd_custom_rate_(int is_pal) { - char buff[32]; - - snprintf(buff, sizeof(buff), "POLLUX_LCD_TIMINGS_%s", is_pal ? "PAL" : "NTSC"); - pollux_set_fromenv(buff); + /* just remember PAL/NTSC. We always set timings in _changemode_ll() */ last_pal_setting = is_pal; } @@ -208,6 +215,32 @@ static int gp2x_read_battery_(void) } } +#define TIMER_BASE3 0x1980 +#define TIMER_REG(x) memregl[(TIMER_BASE3 + x) >> 2] + +unsigned int gp2x_get_ticks_us_(void) +{ + TIMER_REG(0x08) = 0x4b; /* run timer, latch value */ + return TIMER_REG(0); +} + +unsigned int gp2x_get_ticks_ms_(void) +{ + /* approximate /= 1000 */ + unsigned long long v64; + v64 = (unsigned long long)gp2x_get_ticks_us_() * 4294968; + return v64 >> 32; +} + +static void timer_cleanup(void) +{ + TIMER_REG(0x40) = 0x0c; /* be sure clocks are on */ + TIMER_REG(0x08) = 0x23; /* stop the timer, clear irq in case it's pending */ + TIMER_REG(0x00) = 0; /* clear counter */ + TIMER_REG(0x40) = 0; /* clocks off */ + TIMER_REG(0x44) = 0; /* dividers back to default */ +} + void pollux_init(void) { struct fb_fix_screeninfo fbfix; @@ -264,6 +297,14 @@ void pollux_init(void) if (battdev < 0) perror("Warning: could't open pollux_batt"); + /* setup timer */ + if (TIMER_REG(0x08) & 8) + timer_cleanup(); + + TIMER_REG(0x44) = 0x922; /* using PLL1, divider value 147 */ + TIMER_REG(0x40) = 0x0c; /* clocks on */ + TIMER_REG(0x08) = 0x6b; /* run timer, clear irq, latch value */ + pllsetreg0 = memregl[0xf004>>2]; memtimex_old[0] = memregs[0x14802>>1]; memtimex_old[1] = memregs[0x14804>>1]; @@ -284,6 +325,9 @@ void pollux_init(void) set_ram_timings = set_ram_timings_; unset_ram_timings = unset_ram_timings_; gp2x_read_battery = gp2x_read_battery_; + + gp2x_get_ticks_ms = gp2x_get_ticks_ms_; + gp2x_get_ticks_us = gp2x_get_ticks_us_; } void pollux_finish(void)