restore some hw regs on exit to startup values
authornotaz <notasas@gmail.com>
Thu, 23 Jul 2009 19:10:33 +0000 (19:10 +0000)
committernotaz <notasas@gmail.com>
Thu, 23 Jul 2009 19:10:33 +0000 (19:10 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@709 be3aeb3a-fb24-0410-a615-afba39da0efa

platform/gp2x/plat.c
platform/gp2x/soc_mmsp2.c
platform/gp2x/soc_pollux.c

index c2dce2d..568d363 100644 (file)
@@ -181,7 +181,6 @@ void plat_finish(void)
                break;
        }
 
-       gp2x_video_changemode(16);
        sndout_oss_exit();
 }
 
index c136287..d6c40e5 100644 (file)
@@ -33,7 +33,12 @@ static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };
 
 static const int gp2x_screenaddrs[4] = { FRAMEBUFF_ADDR0, FRAMEBUFF_ADDR1, FRAMEBUFF_ADDR2, FRAMEBUFF_ADDR3 };
 static int gp2x_screenaddrs_use[4];
+
+static char gamma_was_changed = 0;
+static char cpuclk_was_changed = 0;
 static unsigned short gp2x_screenaddr_old[4];
+static unsigned short memtimex_old[2];
+static unsigned short reg0910;
 
 
 /* video stuff */
@@ -166,11 +171,11 @@ static void gp2x_set_cpuclk_(unsigned int mhz)
        for (i = 0; i < 10000; i++)
                if (!(gp2x_memregs[0x902>>1] & 1))
                        break;
+
+       cpuclk_was_changed = 1;
 }
 
 /* RAM timings */
-static unsigned short memtimex[2];
-
 #define TIMING_CHECK(t, adj, mask) \
        t += adj; \
        if (t & ~mask) \
@@ -214,8 +219,8 @@ static void set_ram_timings_(void)
 
 static void unset_ram_timings_(void)
 {
-       gp2x_memregs[0x3802>>1] = memtimex[0];
-       gp2x_memregs[0x3804>>1] = memtimex[1] | 0x8000;
+       gp2x_memregs[0x3802>>1] = memtimex_old[0];
+       gp2x_memregs[0x3804>>1] = memtimex_old[1] | 0x8000;
        printf("RAM timings reset to startup values.\n");
 }
 
@@ -344,6 +349,8 @@ static void set_lcd_gamma_(int g100, int A_SNs_curve)
                gp2x_memregs[0x295E>>1]= s;
                gp2x_memregs[0x295E>>1]= g;
        }
+
+       gamma_was_changed = 1;
 }
 
 
@@ -454,12 +461,13 @@ void mmsp2_init(void)
 
        memcpy(gp2x_screenaddrs_use, gp2x_screenaddrs, sizeof(gp2x_screenaddrs));
 
-       /* default LCD refresh */
+       /* save startup values: LCD refresh */
        get_reg_setting(lcd_rate_defaults);
 
-       /* RAM timings */
-       memtimex[0] = gp2x_memregs[0x3802>>1];
-       memtimex[1] = gp2x_memregs[0x3804>>1];
+       /* CPU and RAM timings */
+       reg0910 = gp2x_memregs[0x0910>>1];
+       memtimex_old[0] = gp2x_memregs[0x3802>>1];
+       memtimex_old[1] = gp2x_memregs[0x3804>>1];
 
        /* touchscreen */
        touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY);
@@ -503,13 +511,20 @@ void mmsp2_finish(void)
        pause940(1);
        sharedmem940_finish();
 
+       gp2x_video_RGB_setscaling_(0, 320, 240);
+       gp2x_video_changemode_ll_(16);
+
        gp2x_memregs[0x290E>>1] = gp2x_screenaddr_old[0];
        gp2x_memregs[0x2910>>1] = gp2x_screenaddr_old[1];
        gp2x_memregs[0x2912>>1] = gp2x_screenaddr_old[2];
        gp2x_memregs[0x2914>>1] = gp2x_screenaddr_old[3];
 
-       unset_ram_timings_();
        unset_lcd_custom_rate_();
+       if (gamma_was_changed)
+               set_lcd_gamma_(100, 0);
+       unset_ram_timings_();
+       if (cpuclk_was_changed)
+               gp2x_memregs[0x910>>1] = reg0910;
 
        munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE);
        munmap((void *)gp2x_memregs, 0x10000);
index fb7e66f..6bea317 100644 (file)
@@ -27,6 +27,10 @@ static unsigned int fb_paddr[fb_buf_count];
 static int fb_work_buf;
 static int fbdev = -1;
 
+static char cpuclk_was_changed = 0;
+static unsigned short memtimex_old[2];
+static unsigned int pllsetreg0;
+
 
 /* video stuff */
 static void pollux_video_flip(int buf_count)
@@ -110,6 +114,8 @@ static void gp2x_set_cpuclk_(unsigned int mhz)
        char buff[24];
        snprintf(buff, sizeof(buff), "cpuclk=%u", mhz);
        pollux_set(memregs, buff);
+
+       cpuclk_was_changed = 1;
 }
 
 /* misc */
@@ -124,8 +130,6 @@ static void pollux_set_fromenv(const char *env_var)
 }
 
 /* RAM timings */
-static unsigned short memtimex[2];
-
 static void set_ram_timings_(void)
 {
        pollux_set_fromenv("POLLUX_RAM_TIMINGS");
@@ -135,8 +139,8 @@ static void unset_ram_timings_(void)
 {
        int i;
 
-       memregs[0x14802>>1] = memtimex[0];
-       memregs[0x14804>>1] = memtimex[1] | 0x8000;
+       memregs[0x14802>>1] = memtimex_old[0];
+       memregs[0x14804>>1] = memtimex_old[1] | 0x8000;
 
        for (i = 0; i < 0x100000; i++)
                if (!(memregs[0x14804>>1] & 0x8000))
@@ -215,8 +219,9 @@ void pollux_init(void)
        fb_work_buf = 0;
        g_screen_ptr = gp2x_screens[0];
 
-       memtimex[0] = memregs[0x14802>>1];
-       memtimex[1] = memregs[0x14804>>1];
+       pllsetreg0 = memregl[0xf004];
+       memtimex_old[0] = memregs[0x14802>>1];
+       memtimex_old[1] = memregs[0x14804>>1];
 
        gp2x_video_flip = gp2x_video_flip_;
        gp2x_video_flip2 = gp2x_video_flip2_;
@@ -243,6 +248,13 @@ void pollux_finish(void)
 //     wiz_lcd_set_portrait(0);
        close(fbdev);
 
+       gp2x_video_changemode_ll_(16);
+       unset_ram_timings_();
+       if (cpuclk_was_changed) {
+               memregl[0xf004>>2] = pllsetreg0;
+               memregl[0xf07c>>2] |= 0x8000;
+       }
+
        munmap((void *)memregs, 0x20000);
        close(memdev);
 }