X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Fsoc_pollux.c;h=7b71324c6f2ca05177c924bb4788e64a3d8946d1;hb=6dba776e17ea2cd7b3d8aa27f020dab66cb83ac8;hp=6bea3173e55f79728b234bf9a2d104aabf689371;hpb=71769e27e90704f464bc1844daa044a5b1b24fd4;p=libpicofe.git diff --git a/gp2x/soc_pollux.c b/gp2x/soc_pollux.c index 6bea317..7b71324 100644 --- a/gp2x/soc_pollux.c +++ b/gp2x/soc_pollux.c @@ -19,6 +19,7 @@ static volatile unsigned short *memregs; static volatile unsigned long *memregl; static int memdev = -1; +static int battdev = -1; extern void *gp2x_screens[4]; @@ -30,6 +31,7 @@ static int fbdev = -1; static char cpuclk_was_changed = 0; static unsigned short memtimex_old[2]; static unsigned int pllsetreg0; +static int last_pal_setting = 0; /* video stuff */ @@ -56,9 +58,30 @@ static void gp2x_video_flip2_(void) static void gp2x_video_changemode_ll_(int bpp) { + static int prev_bpp = 0; int code = 0, bytes = 2; + int rot_cmd[2] = { 0, 0 }; unsigned int r; - switch (bpp) + int ret; + + if (bpp == prev_bpp) + return; + prev_bpp = bpp; + + printf("changemode: %dbpp rot=%d\n", abs(bpp), bpp < 0); + + /* negative bpp means rotated mode */ + rot_cmd[0] = (bpp < 0) ? 6 : 5; + ret = ioctl(fbdev, _IOW('D', 90, int[2]), rot_cmd); + if (ret < 0) + perror("rot ioctl failed"); + memregl[0x4004>>2] = (bpp < 0) ? 0x013f00ef : 0x00ef013f; + memregl[0x4000>>2] |= 1 << 3; + + /* the above ioctl resets LCD timings, so set them here */ + set_lcd_custom_rate(last_pal_setting); + + switch (abs(bpp)) { case 8: code = 0x443a; @@ -72,12 +95,12 @@ static void gp2x_video_changemode_ll_(int bpp) break; default: - printf("unhandled bpp request: %d\n", bpp); + printf("unhandled bpp request: %d\n", abs(bpp)); return; } memregl[0x405c>>2] = bytes; - memregl[0x4060>>2] = bytes * 320; + memregl[0x4060>>2] = bytes * (bpp < 0 ? 240 : 320); r = memregl[0x4058>>2]; r = (r & 0xffff) | (code << 16) | 0x10; @@ -156,6 +179,7 @@ static void set_lcd_custom_rate_(int is_pal) snprintf(buff, sizeof(buff), "POLLUX_LCD_TIMINGS_%s", is_pal ? "PAL" : "NTSC"); pollux_set_fromenv(buff); + last_pal_setting = is_pal; } static void unset_lcd_custom_rate_(void) @@ -167,6 +191,23 @@ static void set_lcd_gamma_(int g100, int A_SNs_curve) /* hm, the LCD possibly can do it (but not POLLUX) */ } +static int gp2x_read_battery_(void) +{ + unsigned short magic_val = 0; + + if (battdev < 0) + return -1; + if (read(battdev, &magic_val, sizeof(magic_val)) != sizeof(magic_val)) + return -1; + switch (magic_val) { + default: + case 1: return 100; + case 2: return 66; + case 3: return 40; + case 4: return 0; + } +} + void pollux_init(void) { struct fb_fix_screeninfo fbfix; @@ -219,7 +260,11 @@ void pollux_init(void) fb_work_buf = 0; g_screen_ptr = gp2x_screens[0]; - pllsetreg0 = memregl[0xf004]; + battdev = open("/dev/pollux_batt", O_RDONLY); + if (battdev < 0) + perror("Warning: could't open pollux_batt"); + + pllsetreg0 = memregl[0xf004>>2]; memtimex_old[0] = memregs[0x14802>>1]; memtimex_old[1] = memregs[0x14804>>1]; @@ -238,6 +283,7 @@ void pollux_init(void) set_ram_timings = set_ram_timings_; unset_ram_timings = unset_ram_timings_; + gp2x_read_battery = gp2x_read_battery_; } void pollux_finish(void) @@ -245,7 +291,6 @@ void pollux_finish(void) /* switch to default fb mem, turn portrait off */ memregl[0x406C>>2] = fb_paddr[0]; memregl[0x4058>>2] |= 0x10; -// wiz_lcd_set_portrait(0); close(fbdev); gp2x_video_changemode_ll_(16); @@ -257,5 +302,7 @@ void pollux_finish(void) munmap((void *)memregs, 0x20000); close(memdev); + if (battdev >= 0) + close(battdev); }