X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=gp2x%2Fsoc_pollux.c;h=39f89553ec7f8ce6f8e7995bb7196cf0e12ca3da;hb=2d3fa8770e527558e3532e8cdf07db11102fa712;hp=9dae49037ab2581c3cece6e9b1627d22f7eda461;hpb=902972d1c7f353aebb17a5ab587b2526e1a45d60;p=libpicofe.git
diff --git a/gp2x/soc_pollux.c b/gp2x/soc_pollux.c
index 9dae490..39f8955 100644
--- a/gp2x/soc_pollux.c
+++ b/gp2x/soc_pollux.c
@@ -1,4 +1,13 @@
/*
+ * (C) Gražvydas "notaz" Ignotas, 2009-2010
+ *
+ * This work is licensed under the terms of any of these licenses
+ * (at your option):
+ * - GNU GPL, version 2 or later.
+ * - GNU LGPL, version 2.1 or later.
+ * - MAME license.
+ * See the COPYING file in the top-level directory.
+ *
*
* 00000000-029fffff linux (42MB)
* 02a00000-02dfffff fb (4MB, 153600B really used)
@@ -6,6 +15,7 @@
* 03000000-03ffffff MPEGDEC (?, 16MB)
*
*/
+
#include
#include
#include
@@ -20,9 +30,9 @@
#include "soc.h"
#include "plat_gp2x.h"
-#include "../common/emu.h"
-#include "../common/plat.h"
-#include "../common/arm_utils.h"
+#include "../emu.h"
+#include "../plat.h"
+#include "../arm_utils.h"
#include "pollux_set.h"
static volatile unsigned short *memregs;
@@ -39,7 +49,8 @@ static int fbdev = -1;
static char cpuclk_was_changed = 0;
static unsigned short memtimex_old[2];
-static unsigned int pllsetreg0;
+static unsigned int pllsetreg0_old;
+static unsigned int timer_drift; // count per real second
static int last_pal_setting = 0;
@@ -148,7 +159,7 @@ static void gp2x_video_RGB_setscaling_(int ln_offs, int W, int H)
static void gp2x_video_wait_vsync_(void)
{
- while (!(memregl[0x308c>>2] & (1 << 10)));
+ while (!(memregl[0x308c>>2] & (1 << 10)))
spend_cycles(128);
memregl[0x308c>>2] |= 1 << 10;
}
@@ -219,13 +230,13 @@ 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)
+static 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)
+static unsigned int gp2x_get_ticks_ms_(void)
{
/* approximate /= 1000 */
unsigned long long v64;
@@ -261,10 +272,42 @@ static int decode_pll(unsigned int reg)
return v;
}
+int pollux_get_real_snd_rate(int req_rate)
+{
+ int clk0_src, clk1_src, rate, div;
+
+ clk0_src = (memregl[0xdbc4>>2] >> 1) & 7;
+ clk1_src = (memregl[0xdbc8>>2] >> 1) & 7;
+ if (clk0_src > 1 || clk1_src != 7) {
+ fprintf(stderr, "get_real_snd_rate: bad clk sources: %d %d\n", clk0_src, clk1_src);
+ return req_rate;
+ }
+
+ rate = decode_pll(clk0_src ? memregl[0xf008>>2] : memregl[0xf004>>2]);
+
+ // apply divisors
+ div = ((memregl[0xdbc4>>2] >> 4) & 0x1f) + 1;
+ rate /= div;
+ div = ((memregl[0xdbc8>>2] >> 4) & 0x1f) + 1;
+ rate /= div;
+ rate /= 64;
+
+ //printf("rate %d\n", rate);
+ rate -= rate * timer_drift / 1000000;
+ printf("adjusted rate: %d\n", rate);
+
+ if (rate < 8000-1000 || rate > 44100+1000) {
+ fprintf(stderr, "get_real_snd_rate: got bad rate: %d\n", rate);
+ return req_rate;
+ }
+
+ return rate;
+}
+
void pollux_init(void)
{
struct fb_fix_screeninfo fbfix;
- int i, ret, rate;
+ int i, ret, rate, timer_div;
memdev = open("/dev/mem", O_RDWR);
if (memdev == -1) {
@@ -320,16 +363,18 @@ void pollux_init(void)
/* find what PLL1 runs at, for the timer */
rate = decode_pll(memregl[0xf008>>2]);
printf("PLL1 @ %dHz\n", rate);
- rate /= 1000000;
/* setup timer */
- if (1 <= rate && rate <= 256) {
+ timer_div = (rate + 500000) / 1000000;
+ if (1 <= timer_div && timer_div <= 256) {
+ timer_drift = (rate - (timer_div * 1000000)) / timer_div;
+
if (TIMER_REG(0x08) & 8) {
fprintf(stderr, "warning: timer in use, overriding!\n");
timer_cleanup();
}
- TIMER_REG(0x44) = ((rate - 1) << 4) | 2; /* using PLL1, divide by it's rate */
+ TIMER_REG(0x44) = ((timer_div - 1) << 4) | 2; /* using PLL1, divide by it's rate */
TIMER_REG(0x40) = 0x0c; /* clocks on */
TIMER_REG(0x08) = 0x6b; /* run timer, clear irq, latch value */
@@ -344,7 +389,7 @@ void pollux_init(void)
gp2x_get_ticks_us = plat_get_ticks_us_good;
}
- pllsetreg0 = memregl[0xf004>>2];
+ pllsetreg0_old = memregl[0xf004>>2];
memtimex_old[0] = memregs[0x14802>>1];
memtimex_old[1] = memregs[0x14804>>1];
@@ -384,7 +429,7 @@ void pollux_finish(void)
gp2x_video_changemode_ll_(16);
unset_ram_timings_();
if (cpuclk_was_changed) {
- memregl[0xf004>>2] = pllsetreg0;
+ memregl[0xf004>>2] = pllsetreg0_old;
memregl[0xf07c>>2] |= 0x8000;
}
timer_cleanup();