From 7ceadd9993ea84078e9d74d79215419e06496f90 Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 23 Aug 2013 02:58:06 +0300 Subject: [PATCH] GP2X updates video stuff moved out as it's project specific.. --- gp2x/in_gp2x.c | 24 +-- gp2x/plat.c | 110 ++++++++++ gp2x/plat_gp2x.h | 12 -- gp2x/soc.c | 33 +-- gp2x/soc.h | 27 +-- gp2x/soc_dummy.c | 106 ---------- gp2x/soc_mmsp2.c | 294 +++++++++------------------ gp2x/soc_pollux.c | 486 +++++++-------------------------------------- input.c | 3 +- linux/sndout_oss.c | 5 + menu.h | 5 +- plat.h | 6 +- 12 files changed, 309 insertions(+), 802 deletions(-) create mode 100644 gp2x/plat.c delete mode 100644 gp2x/soc_dummy.c diff --git a/gp2x/in_gp2x.c b/gp2x/in_gp2x.c index 4599a3e..99cd46a 100644 --- a/gp2x/in_gp2x.c +++ b/gp2x/in_gp2x.c @@ -18,6 +18,8 @@ #include #include "../input.h" +#include "soc.h" +#include "plat_gp2x.h" #include "in_gp2x.h" #define IN_GP2X_PREFIX "gp2x:" @@ -47,15 +49,14 @@ static const char *in_gp2x_keys[IN_GP2X_NBUTTONS] = { static int in_gp2x_get_mmsp2_bits(void) { - extern volatile unsigned short *gp2x_memregs; int value; - value = gp2x_memregs[0x1198>>1] & 0xff; // GPIO M + value = memregs[0x1198>>1] & 0xff; // GPIO M if (value == 0xFD) value = 0xFA; if (value == 0xF7) value = 0xEB; if (value == 0xDF) value = 0xAF; if (value == 0x7F) value = 0xBE; - value |= gp2x_memregs[0x1184>>1] & 0xFF00; // GPIO C - value |= gp2x_memregs[0x1186>>1] << 16; // GPIO D + value |= memregs[0x1184>>1] & 0xFF00; // GPIO C + value |= memregs[0x1186>>1] << 16; // GPIO D value = ~value & 0x08c0ff55; return value; @@ -87,17 +88,6 @@ static int in_gp2x_get_wiz_bits(void) return value; } -#ifdef FAKE_IN_GP2X -volatile unsigned short *gp2x_memregs; -int gp2x_dev_id = -1; - -static int in_gp2x_get_fake_bits(void) -{ - extern int current_keys; - return current_keys; -} -#endif - static void in_gp2x_probe(void) { switch (gp2x_dev_id) @@ -115,10 +105,6 @@ static void in_gp2x_probe(void) break; // we'll use evdev for Caanoo default: -#ifdef FAKE_IN_GP2X - in_gp2x_get_bits = in_gp2x_get_fake_bits; - break; -#endif return; } diff --git a/gp2x/plat.c b/gp2x/plat.c new file mode 100644 index 0000000..e80b0fb --- /dev/null +++ b/gp2x/plat.c @@ -0,0 +1,110 @@ +/* + * (C) notaz, 2013 + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "../plat.h" +#include "../input.h" +#include "plat_gp2x.h" +#include "soc.h" + +int default_cpu_clock; +int gp2x_dev_id; + +static const char * const caanoo_keys[KEY_MAX + 1] = { + [0 ... KEY_MAX] = NULL, + [KEY_UP] = "Up", + [KEY_LEFT] = "Left", + [KEY_RIGHT] = "Right", + [KEY_DOWN] = "Down", + [BTN_TRIGGER] = "A", + [BTN_THUMB] = "X", + [BTN_THUMB2] = "B", + [BTN_TOP] = "Y", + [BTN_TOP2] = "L", + [BTN_PINKIE] = "R", + [BTN_BASE] = "Home", + [BTN_BASE2] = "Lock", + [BTN_BASE3] = "I", + [BTN_BASE4] = "II", + [BTN_BASE5] = "Push", +}; + +/* to be filled by mmsp2/pollux _init */ +struct plat_target plat_target; + +int plat_target_init(void) +{ + gp2x_soc_t soc; + FILE *f; + + soc = soc_detect(); + switch (soc) + { + case SOCID_MMSP2: + mmsp2_init(); + default_cpu_clock = 200; + gp2x_dev_id = GP2X_DEV_GP2X; + break; + case SOCID_POLLUX: + pollux_init(); + default_cpu_clock = 533; + f = fopen("/dev/accel", "rb"); + if (f) { + printf("detected Caanoo\n"); + gp2x_dev_id = GP2X_DEV_CAANOO; + fclose(f); + } + else { + printf("detected Wiz\n"); + gp2x_dev_id = GP2X_DEV_WIZ; + } + break; + default: + printf("could not recognize SoC.\n"); + break; + } + + return 0; +} + +/* to be called after in_probe */ +void plat_target_setup_input(void) +{ + if (gp2x_dev_id == GP2X_DEV_CAANOO) + in_set_config(in_name_to_id("evdev:pollux-analog"), + IN_CFG_KEY_NAMES, + caanoo_keys, sizeof(caanoo_keys)); +} + +void plat_target_finish(void) +{ + gp2x_soc_t soc; + + soc = soc_detect(); + switch (soc) + { + case SOCID_MMSP2: + mmsp2_finish(); + break; + case SOCID_POLLUX: + pollux_finish(); + break; + default: + break; + } +} diff --git a/gp2x/plat_gp2x.h b/gp2x/plat_gp2x.h index c77e061..f3fecdb 100644 --- a/gp2x/plat_gp2x.h +++ b/gp2x/plat_gp2x.h @@ -3,15 +3,6 @@ extern int default_cpu_clock; -/* video */ -void gp2x_video_changemode(int bpp); -void gp2x_memcpy_all_buffers(void *data, int offset, int len); -void gp2x_memset_all_buffers(int offset, int byte, int len); -void gp2x_make_fb_bufferable(int yes); - -/* input */ -int gp2x_touchpad_read(int *x, int *y); - /* misc */ enum { GP2X_DEV_GP2X = 1, @@ -19,11 +10,8 @@ enum { GP2X_DEV_CAANOO, }; extern int gp2x_dev_id; -extern int gp2x_current_bpp; unsigned int plat_get_ticks_ms_good(void); unsigned int plat_get_ticks_us_good(void); -void gp2x_menu_init(void); - #endif diff --git a/gp2x/soc.c b/gp2x/soc.c index 3d4ad04..0d1b8a3 100644 --- a/gp2x/soc.c +++ b/gp2x/soc.c @@ -19,27 +19,13 @@ #include "soc.h" -void (*gp2x_video_flip)(void); -void (*gp2x_video_flip2)(void); -void (*gp2x_video_changemode_ll)(int bpp); -void (*gp2x_video_setpalette)(int *pal, int len); -void (*gp2x_video_RGB_setscaling)(int ln_offs, int W, int H); -void (*gp2x_video_wait_vsync)(void); - -void (*gp2x_set_cpuclk)(unsigned int mhz); - -void (*set_lcd_custom_rate)(int is_pal); -void (*unset_lcd_custom_rate)(void); -void (*set_lcd_gamma)(int g100, int A_SNs_curve); - -void (*set_ram_timings)(void); -void (*unset_ram_timings)(void); -int (*gp2x_read_battery)(void); +volatile unsigned short *memregs; +volatile unsigned int *memregl; +int memdev = -1; unsigned int (*gp2x_get_ticks_ms)(void); unsigned int (*gp2x_get_ticks_us)(void); - gp2x_soc_t soc_detect(void) { volatile unsigned short *memregs; @@ -47,26 +33,27 @@ gp2x_soc_t soc_detect(void) static gp2x_soc_t ret = -2; int pollux_chipname[0x30/4 + 1]; char *pollux_chipname_c = (char *)pollux_chipname; - int memdev; + int memdev_tmp; int i; if ((int)ret != -2) /* already detected */ return ret; - memdev = open("/dev/mem", O_RDONLY); - if (memdev == -1) + memdev_tmp = open("/dev/mem", O_RDONLY); + if (memdev_tmp == -1) { perror("open(/dev/mem)"); ret = -1; return -1; } - memregs = mmap(0, 0x20000, PROT_READ, MAP_SHARED, memdev, 0xc0000000); + memregs = mmap(0, 0x20000, PROT_READ, MAP_SHARED, + memdev_tmp, 0xc0000000); if (memregs == MAP_FAILED) { perror("mmap(memregs)"); - close(memdev); + close(memdev_tmp); ret = -1; return -1; } @@ -106,7 +93,7 @@ gp2x_soc_t soc_detect(void) not_pollux_like: out: munmap((void *)memregs, 0x20000); - close(memdev); + close(memdev_tmp); return ret; } diff --git a/gp2x/soc.h b/gp2x/soc.h index 9686148..4a8d455 100644 --- a/gp2x/soc.h +++ b/gp2x/soc.h @@ -1,3 +1,8 @@ + +extern volatile unsigned short *memregs; +extern volatile unsigned int *memregl; +extern int memdev; + typedef enum { SOCID_MMSP2 = 1, SOCID_POLLUX, @@ -11,28 +16,6 @@ void mmsp2_finish(void); void pollux_init(void); void pollux_finish(void); -void dummy_init(void); -void dummy_finish(void); - -/* SoC specific functions */ -extern void (*gp2x_video_flip)(void); -extern void (*gp2x_video_flip2)(void); -/* negative bpp means rotated mode (for Wiz) */ -extern void (*gp2x_video_changemode_ll)(int bpp); -extern void (*gp2x_video_setpalette)(int *pal, int len); -extern void (*gp2x_video_RGB_setscaling)(int ln_offs, int W, int H); -extern void (*gp2x_video_wait_vsync)(void); - -extern void (*gp2x_set_cpuclk)(unsigned int mhz); - -extern void (*set_lcd_custom_rate)(int is_pal); -extern void (*unset_lcd_custom_rate)(void); -extern void (*set_lcd_gamma)(int g100, int A_SNs_curve); - -extern void (*set_ram_timings)(void); -extern void (*unset_ram_timings)(void); -extern int (*gp2x_read_battery)(void); - /* gettimeofday is not suitable for Wiz, at least fw 1.1 or lower */ extern unsigned int (*gp2x_get_ticks_ms)(void); extern unsigned int (*gp2x_get_ticks_us)(void); diff --git a/gp2x/soc_dummy.c b/gp2x/soc_dummy.c deleted file mode 100644 index 21aef2a..0000000 --- a/gp2x/soc_dummy.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * (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. - */ - -/* dummy code for qemu testing, etc */ -#include - -#include "soc.h" -#include "../emu.h" - -extern void *gp2x_screens[4]; - -extern unsigned int plat_get_ticks_ms_good(void); -extern unsigned int plat_get_ticks_us_good(void); - -/* video stuff */ -static void gp2x_video_flip_(void) -{ -} - -/* doulblebuffered flip */ -static void gp2x_video_flip2_(void) -{ -} - -static void gp2x_video_changemode_ll_(int bpp) -{ -} - -static void gp2x_video_setpalette_(int *pal, int len) -{ -} - -static void gp2x_video_RGB_setscaling_(int ln_offs, int W, int H) -{ -} - -static void gp2x_video_wait_vsync_(void) -{ -} - -/* RAM timings */ -static void set_ram_timings_(void) -{ -} - -static void unset_ram_timings_(void) -{ -} - -/* LCD refresh */ -static void set_lcd_custom_rate_(int is_pal) -{ -} - -static void unset_lcd_custom_rate_(void) -{ -} - -static void set_lcd_gamma_(int g100, int A_SNs_curve) -{ -} - -static int gp2x_read_battery_(void) -{ - return 0; -} - -void dummy_init(void) -{ - int i; - g_screen_ptr = malloc(320 * 240 * 2); - for (i = 0; i < array_size(gp2x_screens); i++) - gp2x_screens[i] = g_screen_ptr; - - gp2x_video_flip = gp2x_video_flip_; - gp2x_video_flip2 = gp2x_video_flip2_; - gp2x_video_changemode_ll = gp2x_video_changemode_ll_; - gp2x_video_setpalette = gp2x_video_setpalette_; - gp2x_video_RGB_setscaling = gp2x_video_RGB_setscaling_; - gp2x_video_wait_vsync = gp2x_video_wait_vsync_; - - set_lcd_custom_rate = set_lcd_custom_rate_; - unset_lcd_custom_rate = unset_lcd_custom_rate_; - set_lcd_gamma = set_lcd_gamma_; - - set_ram_timings = set_ram_timings_; - unset_ram_timings = unset_ram_timings_; - gp2x_read_battery = gp2x_read_battery_; - - gp2x_get_ticks_ms = plat_get_ticks_ms_good; - gp2x_get_ticks_us = plat_get_ticks_us_good; -} - -void dummy_finish(void) -{ - free(gp2x_screens[0]); -} - diff --git a/gp2x/soc_mmsp2.c b/gp2x/soc_mmsp2.c index ee933d4..beea7bf 100644 --- a/gp2x/soc_mmsp2.c +++ b/gp2x/soc_mmsp2.c @@ -17,141 +17,36 @@ #include #include #include +#include #include +#include #include "soc.h" #include "soc_mmsp2.h" #include "plat_gp2x.h" -#include "../emu.h" #include "../plat.h" -#include "../arm_utils.h" -#include "940ctl.h" -volatile unsigned short *gp2x_memregs; -volatile unsigned long *gp2x_memregl; -extern void *gp2x_screens[4]; -static int screensel = 0; - -int memdev = -1; /* used by code940 */ +static int mixerdev = -1; static int touchdev = -1; static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 }; -#define FRAMEBUFF_SIZE 0x30000 -#define FRAMEBUFF_WHOLESIZE (FRAMEBUFF_SIZE*4) // 320*240*2 + some more -#define FRAMEBUFF_ADDR0 (0x4000000 - FRAMEBUFF_WHOLESIZE) -#define FRAMEBUFF_ADDR1 (FRAMEBUFF_ADDR0 + FRAMEBUFF_SIZE) -#define FRAMEBUFF_ADDR2 (FRAMEBUFF_ADDR1 + FRAMEBUFF_SIZE) -#define FRAMEBUFF_ADDR3 (FRAMEBUFF_ADDR2 + FRAMEBUFF_SIZE) - -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 */ -static void gp2x_video_flip_(void) -{ - unsigned short lsw = (unsigned short) gp2x_screenaddrs_use[screensel&3]; - unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&3] >> 16); - - gp2x_memregs[0x2910>>1] = msw; - gp2x_memregs[0x2914>>1] = msw; - gp2x_memregs[0x290E>>1] = lsw; - gp2x_memregs[0x2912>>1] = lsw; - - // jump to other buffer: - g_screen_ptr = gp2x_screens[++screensel&3]; -} - -/* doulblebuffered flip */ -static void gp2x_video_flip2_(void) -{ - unsigned short msw = (unsigned short)(gp2x_screenaddrs_use[screensel&1] >> 16); - - gp2x_memregs[0x2910>>1] = msw; - gp2x_memregs[0x2914>>1] = msw; - gp2x_memregs[0x290E>>1] = 0; - gp2x_memregs[0x2912>>1] = 0; - - // jump to other buffer: - g_screen_ptr = gp2x_screens[++screensel&1]; -} - -static void gp2x_video_changemode_ll_(int bpp) -{ - gp2x_memregs[0x28DA>>1] = (((bpp+1)/8)<<9)|0xAB; /*8/15/16/24bpp...*/ - gp2x_memregs[0x290C>>1] = 320*((bpp+1)/8); /*line width in bytes*/ -} - -static void gp2x_video_setpalette_(int *pal, int len) -{ - unsigned short *g = (unsigned short *)pal; - volatile unsigned short *memreg = &gp2x_memregs[0x295A>>1]; - - gp2x_memregs[0x2958>>1] = 0; - - len *= 2; - while (len--) - *memreg = *g++; -} - -static void gp2x_video_RGB_setscaling_(int ln_offs, int W, int H) -{ - float escalaw, escalah; - int bpp = (gp2x_memregs[0x28DA>>1]>>9)&0x3; - unsigned short scalw; - - // set offset - gp2x_screenaddrs_use[0] = gp2x_screenaddrs[0] + ln_offs * 320 * bpp; - gp2x_screenaddrs_use[1] = gp2x_screenaddrs[1] + ln_offs * 320 * bpp; - gp2x_screenaddrs_use[2] = gp2x_screenaddrs[2] + ln_offs * 320 * bpp; - gp2x_screenaddrs_use[3] = gp2x_screenaddrs[3] + ln_offs * 320 * bpp; - - escalaw = 1024.0; // RGB Horiz LCD - escalah = 320.0; // RGB Vert LCD - - if (gp2x_memregs[0x2800>>1]&0x100) //TV-Out - { - escalaw=489.0; // RGB Horiz TV (PAL, NTSC) - if (gp2x_memregs[0x2818>>1] == 287) //PAL - escalah=274.0; // RGB Vert TV PAL - else if (gp2x_memregs[0x2818>>1] == 239) //NTSC - escalah=331.0; // RGB Vert TV NTSC - } - - // scale horizontal - scalw = (unsigned short)((float)escalaw *(W/320.0)); - /* if there is no horizontal scaling, vertical doesn't work. - * Here is a nasty wrokaround... */ - if (H != 240 && W == 320) scalw--; - gp2x_memregs[0x2906>>1]=scalw; - // scale vertical - gp2x_memregl[0x2908>>2]=(unsigned long)((float)escalah *bpp *(H/240.0)); -} - -static void gp2x_video_wait_vsync_(void) -{ - unsigned short v = gp2x_memregs[0x1182>>1]; - while (!((v ^ gp2x_memregs[0x1182>>1]) & 0x10)) - spend_cycles(1024); -} - /* 940 */ void pause940(int yes) { if (yes) - gp2x_memregs[0x0904>>1] &= 0xFFFE; + memregs[0x0904>>1] &= 0xFFFE; else - gp2x_memregs[0x0904>>1] |= 1; + memregs[0x0904>>1] |= 1; } void reset940(int yes, int bank) { - gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (bank & 0x03); + memregs[0x3B48>>1] = ((yes&1) << 7) | (bank & 0x03); } /* @@ -164,7 +59,15 @@ void reset940(int yes, int bank) #define SYS_CLK_FREQ 7372800 -static void gp2x_set_cpuclk_(unsigned int mhz) +static int cpu_current_mhz = 200; + +static int mmsp2_clock_get(void) +{ + // TODO: read the actual value? + return cpu_current_mhz; +} + +static int mmsp2_clock_set(int mhz) { unsigned int mdiv, pdiv, sdiv = 0; unsigned int v; @@ -174,16 +77,18 @@ static void gp2x_set_cpuclk_(unsigned int mhz) mdiv = (mhz * pdiv * 1000000) / SYS_CLK_FREQ; if (mdiv & ~0xff) { fprintf(stderr, "invalid cpuclk MHz: %u\n", mhz); - return; + return -1; } v = ((mdiv-8)<<8) | ((pdiv-2)<<2) | sdiv; - gp2x_memregs[0x910>>1] = v; + memregs[0x910>>1] = v; for (i = 0; i < 10000; i++) - if (!(gp2x_memregs[0x902>>1] & 1)) + if (!(memregs[0x902>>1] & 1)) break; cpuclk_was_changed = 1; + cpu_current_mhz = mhz; + return 0; } /* RAM timings */ @@ -192,6 +97,14 @@ static void gp2x_set_cpuclk_(unsigned int mhz) if (t & ~mask) \ goto bad +static __attribute__((noinline)) void spend_cycles(int c) +{ + asm volatile( + "0: subs %0, %0, #1 ;" + "bgt 0b" + : "=r" (c) : "0" (c) : "cc"); +} + static void set_ram_timing_vals(int tCAS, int tRC, int tRAS, int tWR, int tMRD, int tRFC, int tRP, int tRCD) { int i; @@ -207,13 +120,13 @@ static void set_ram_timing_vals(int tCAS, int tRC, int tRAS, int tWR, int tMRD, /* get spend_cycles() into cache */ spend_cycles(1); - gp2x_memregs[0x3802>>1] = ((tMRD & 0xF) << 12) | ((tRFC & 0xF) << 8) | ((tRP & 0xF) << 4) | (tRCD & 0xF); - gp2x_memregs[0x3804>>1] = 0x8000 | ((tCAS & 1) << 12) | ((tRC & 0xF) << 8) | ((tRAS & 0xF) << 4) | (tWR & 0xF); + memregs[0x3802>>1] = ((tMRD & 0xF) << 12) | ((tRFC & 0xF) << 8) | ((tRP & 0xF) << 4) | (tRCD & 0xF); + memregs[0x3804>>1] = 0x8000 | ((tCAS & 1) << 12) | ((tRC & 0xF) << 8) | ((tRAS & 0xF) << 4) | (tWR & 0xF); /* be sure we don't access the mem while it's being reprogrammed */ spend_cycles(128*1024); for (i = 0; i < 8*1024; i++) - if (!(gp2x_memregs[0x3804>>1] & 0x8000)) + if (!(memregs[0x3804>>1] & 0x8000)) break; printf("RAM timings set.\n"); @@ -230,8 +143,8 @@ static void set_ram_timings_(void) static void unset_ram_timings_(void) { - gp2x_memregs[0x3802>>1] = memtimex_old[0]; - gp2x_memregs[0x3804>>1] = memtimex_old[1] | 0x8000; + memregs[0x3802>>1] = memtimex_old[0]; + memregs[0x3804>>1] = memtimex_old[1] | 0x8000; printf("RAM timings reset to startup values.\n"); } @@ -284,7 +197,7 @@ static void get_reg_setting(reg_setting *set) { for (; set->reg; set++) { - unsigned short val = gp2x_memregs[set->reg >> 1]; + unsigned short val = memregs[set->reg >> 1]; val &= set->valmask; set->val = val; } @@ -294,23 +207,24 @@ static void set_reg_setting(const reg_setting *set) { for (; set->reg; set++) { - unsigned short val = gp2x_memregs[set->reg >> 1]; + unsigned short val = memregs[set->reg >> 1]; val &= ~set->valmask; val |= set->val; - gp2x_memregs[set->reg >> 1] = val; + memregs[set->reg >> 1] = val; } } -static void set_lcd_custom_rate_(int is_pal) +static int mmsp2_lcdrate_set(int is_pal) { - if (gp2x_memregs[0x2800>>1] & 0x100) // tv-out - return; + if (memregs[0x2800>>1] & 0x100) // tv-out + return 0; printf("setting custom LCD refresh (%d Hz)... ", is_pal ? 100 : 120); fflush(stdout); set_reg_setting(is_pal ? lcd_rate_100 : lcd_rate_120); printf("done.\n"); + return 0; } static void unset_lcd_custom_rate_(void) @@ -321,14 +235,17 @@ static void unset_lcd_custom_rate_(void) static void set_lcd_gamma_(int g100, int A_SNs_curve) { - float gamma = (float) g100 / 100; + float gamma = (float) g100 / 100.0f; int i; gamma = 1 / gamma; + if (g100 == 100) + A_SNs_curve = 0; + /* enable gamma */ - gp2x_memregs[0x2880>>1] &= ~(1<<12); + memregs[0x2880>>1] &= ~(1<<12); - gp2x_memregs[0x295C>>1] = 0; + memregs[0x295C>>1] = 0; for (i = 0; i < 256; i++) { unsigned char g; @@ -351,22 +268,23 @@ static void set_lcd_gamma_(int g100, int A_SNs_curve) } else { - blah = i; + blah = (double)i; } g = (unsigned char)(255.0 * pow(blah/255.0, gamma)); //printf("%d : %d\n", i, g); s = (g<<8) | g; - gp2x_memregs[0x295E>>1]= s; - gp2x_memregs[0x295E>>1]= g; + memregs[0x295E>>1]= s; + memregs[0x295E>>1]= g; } gamma_was_changed = 1; } -static int gp2x_read_battery_(void) +static int mmsp2_gamma_set(int val, int black_level) { - return -1; /* TODO? */ + set_lcd_gamma_(val, 1); + return 0; } /* these are not quite MMSP2 related, @@ -429,11 +347,33 @@ static void proc_set(const char *path, const char *val) fclose(f); } +static int step_volume(int *volume, int diff) +{ + int ret, val; + + if (mixerdev < 0) + return -1; + + *volume += diff; + if (*volume >= 100) + *volume = 100; + else if (*volume < 0) + *volume = 0; + + val = *volume; + val |= val << 8; + + ret = ioctl(mixerdev, SOUND_MIXER_WRITE_PCM, &val); + if (ret == -1) { + perror("WRITE_PCM"); + return ret; + } + + return 0; +} void mmsp2_init(void) { - int i; - memdev = open("/dev/mem", O_RDWR); if (memdev == -1) { @@ -441,48 +381,23 @@ void mmsp2_init(void) exit(1); } - gp2x_memregs = mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000); - if (gp2x_memregs == MAP_FAILED) + memregs = mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000); + if (memregs == MAP_FAILED) { perror("mmap(memregs)"); exit(1); } - gp2x_memregl = (unsigned long *) gp2x_memregs; + memregl = (volatile unsigned int *) memregs; - gp2x_memregs[0x2880>>1] &= ~0x383; // disable cursor, subpict, osd, video layers - - gp2x_screens[0] = mmap(0, FRAMEBUFF_WHOLESIZE, PROT_WRITE, MAP_SHARED, - memdev, gp2x_screenaddrs[0]); - if (gp2x_screens[0] == MAP_FAILED) - { - perror("mmap(g_screen_ptr)"); - exit(1); - } - printf("framebuffers:\n"); - printf(" %08x -> %p\n", gp2x_screenaddrs[0], gp2x_screens[0]); - for (i = 1; i < 4; i++) - { - gp2x_screens[i] = (char *) gp2x_screens[i - 1] + FRAMEBUFF_SIZE; - printf(" %08x -> %p\n", gp2x_screenaddrs[i], gp2x_screens[i]); - } - - g_screen_ptr = gp2x_screens[0]; - screensel = 0; - - gp2x_screenaddr_old[0] = gp2x_memregs[0x290E>>1]; - gp2x_screenaddr_old[1] = gp2x_memregs[0x2910>>1]; - gp2x_screenaddr_old[2] = gp2x_memregs[0x2912>>1]; - gp2x_screenaddr_old[3] = gp2x_memregs[0x2914>>1]; - - memcpy(gp2x_screenaddrs_use, gp2x_screenaddrs, sizeof(gp2x_screenaddrs)); + memregs[0x2880>>1] &= ~0x383; // disable cursor, subpict, osd, video layers /* save startup values: LCD refresh */ get_reg_setting(lcd_rate_defaults); /* CPU and RAM timings */ - reg0910 = gp2x_memregs[0x0910>>1]; - memtimex_old[0] = gp2x_memregs[0x3802>>1]; - memtimex_old[1] = gp2x_memregs[0x3804>>1]; + reg0910 = memregs[0x0910>>1]; + memtimex_old[0] = memregs[0x3802>>1]; + memtimex_old[1] = memregs[0x3804>>1]; /* touchscreen */ touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY); @@ -500,25 +415,17 @@ void mmsp2_init(void) proc_set("/proc/sys/vm/max-readahead", "0\n"); proc_set("/proc/sys/vm/min-readahead", "0\n"); - /* code940 portion */ - sharedmem940_init(); - - gp2x_video_flip = gp2x_video_flip_; - gp2x_video_flip2 = gp2x_video_flip2_; - gp2x_video_changemode_ll = gp2x_video_changemode_ll_; - gp2x_video_setpalette = gp2x_video_setpalette_; - gp2x_video_RGB_setscaling = gp2x_video_RGB_setscaling_; - gp2x_video_wait_vsync = gp2x_video_wait_vsync_; + mixerdev = open("/dev/mixer", O_RDWR); + if (mixerdev == -1) + perror("open(/dev/mixer)"); - gp2x_set_cpuclk = gp2x_set_cpuclk_; + set_ram_timings_(); - set_lcd_custom_rate = set_lcd_custom_rate_; - unset_lcd_custom_rate = unset_lcd_custom_rate_; - set_lcd_gamma = set_lcd_gamma_; - - set_ram_timings = set_ram_timings_; - unset_ram_timings = unset_ram_timings_; - gp2x_read_battery = gp2x_read_battery_; + plat_target.cpu_clock_get = mmsp2_clock_get; + plat_target.cpu_clock_set = mmsp2_clock_set; + plat_target.lcdrate_set = mmsp2_lcdrate_set; + plat_target.gamma_set = mmsp2_gamma_set; + plat_target.step_volume = step_volume; gp2x_get_ticks_ms = plat_get_ticks_ms_good; gp2x_get_ticks_us = plat_get_ticks_us_good; @@ -528,27 +435,18 @@ void mmsp2_finish(void) { reset940(1, 3); 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_lcd_custom_rate_(); if (gamma_was_changed) set_lcd_gamma_(100, 0); unset_ram_timings_(); if (cpuclk_was_changed) - gp2x_memregs[0x910>>1] = reg0910; + memregs[0x910>>1] = reg0910; - munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE); - munmap((void *)gp2x_memregs, 0x10000); + munmap((void *)memregs, 0x10000); close(memdev); if (touchdev >= 0) close(touchdev); + if (mixerdev >= 0) + close(mixerdev); } - diff --git a/gp2x/soc_pollux.c b/gp2x/soc_pollux.c index a773ae1..e59a561 100644 --- a/gp2x/soc_pollux.c +++ b/gp2x/soc_pollux.c @@ -19,237 +19,88 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include #include "soc.h" #include "plat_gp2x.h" #include "../plat.h" -volatile unsigned short *memregs; -volatile unsigned int *memregl; -int memdev = -1; -int gp2x_dev_id; - static int battdev = -1, mixerdev = -1; static int cpu_clock_allowed; static unsigned int saved_video_regs[2][6]; +static unsigned int timer_drift; // count per real second #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #endif -// TODO FIXME: merge -#if 0 -extern void *gp2x_screens[4]; - -#define fb_buf_count 4 -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_old; -static unsigned int timer_drift; // count per real second -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) -{ - memregl[0x406C>>2] = fb_paddr[fb_work_buf]; - memregl[0x4058>>2] |= 0x10; - fb_work_buf++; - if (fb_work_buf >= buf_count) - fb_work_buf = 0; - g_screen_ptr = gp2x_screens[fb_work_buf]; -} - -static void gp2x_video_flip_(void) -{ - pollux_video_flip(fb_buf_count); -} - -/* doulblebuffered flip */ -static void gp2x_video_flip2_(void) -{ - pollux_video_flip(2); -} - -static void gp2x_video_changemode_ll_(int bpp) +/* note: both PLLs are programmed the same way, + * the databook incorrectly states that PLL1 differs */ +static int decode_pll(unsigned int reg) { - static int prev_bpp = 0; - int code = 0, bytes = 2; - int rot_cmd[2] = { 0, 0 }; - unsigned int r; - char buff[32]; - 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 */ - snprintf(buff, sizeof(buff), "POLLUX_LCD_TIMINGS_%s", last_pal_setting ? "PAL" : "NTSC"); - pollux_set_fromenv(buff); - - switch (abs(bpp)) - { - case 8: - code = 0x443a; - bytes = 1; - break; - - case 15: - case 16: - code = 0x4432; - bytes = 2; - break; - - default: - printf("unhandled bpp request: %d\n", abs(bpp)); - return; - } + long long v; + int p, m, s; - memregl[0x405c>>2] = bytes; - memregl[0x4060>>2] = bytes * (bpp < 0 ? 240 : 320); + p = (reg >> 18) & 0x3f; + m = (reg >> 8) & 0x3ff; + s = reg & 0xff; - r = memregl[0x4058>>2]; - r = (r & 0xffff) | (code << 16) | 0x10; - memregl[0x4058>>2] = r; -} + if (p == 0) + p = 1; -static void gp2x_video_setpalette_(int *pal, int len) -{ - /* pollux palette is 16bpp only.. */ - int i; - for (i = 0; i < len; i++) - { - int c = pal[i]; - c = ((c >> 8) & 0xf800) | ((c >> 5) & 0x07c0) | ((c >> 3) & 0x001f); - memregl[0x4070>>2] = (i << 24) | c; - } + v = 27000000; // master clock + v = v * m / (p << s); + return v; } -static void gp2x_video_RGB_setscaling_(int ln_offs, int W, int H) -{ - /* maybe a job for 3d hardware? */ -} +#define TIMER_BASE3 0x1980 +#define TIMER_REG(x) memregl[(TIMER_BASE3 + x) >> 2] -static void gp2x_video_wait_vsync_(void) +static unsigned int gp2x_get_ticks_us_(void) { - while (!(memregl[0x308c>>2] & (1 << 10))) - spend_cycles(128); - memregl[0x308c>>2] |= 1 << 10; + TIMER_REG(0x08) = 0x4b; /* run timer, latch value */ + return TIMER_REG(0); } -/* CPU clock */ -static void gp2x_set_cpuclk_(unsigned int mhz) +static unsigned int gp2x_get_ticks_ms_(void) { - char buff[24]; - snprintf(buff, sizeof(buff), "cpuclk=%u", mhz); - pollux_set(memregs, buff); - - cpuclk_was_changed = 1; + /* approximate /= 1000 */ + unsigned long long v64; + v64 = (unsigned long long)gp2x_get_ticks_us_() * 4294968; + return v64 >> 32; } -/* RAM timings */ -static void set_ram_timings_(void) +static void timer_cleanup(void) { - pollux_set_fromenv("POLLUX_RAM_TIMINGS"); + 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 */ } -static void unset_ram_timings_(void) +static void save_multiple_regs(unsigned int *dest, int base, int count) { + const volatile unsigned int *regs = memregl + base / 4; int i; - memregs[0x14802>>1] = memtimex_old[0]; - memregs[0x14804>>1] = memtimex_old[1] | 0x8000; - - for (i = 0; i < 0x100000; i++) - if (!(memregs[0x14804>>1] & 0x8000)) - break; - - printf("RAM timings reset to startup values.\n"); -} - -/* LCD refresh */ -static void set_lcd_custom_rate_(int is_pal) -{ - /* just remember PAL/NTSC. We always set timings in _changemode_ll() */ - last_pal_setting = is_pal; -} - -static void unset_lcd_custom_rate_(void) -{ -} - -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; - } + for (i = 0; i < count; i++) + dest[i] = regs[i]; } -#define TIMER_BASE3 0x1980 -#define TIMER_REG(x) memregl[(TIMER_BASE3 + x) >> 2] - -static unsigned int gp2x_get_ticks_us_(void) +static void restore_multiple_regs(int base, const unsigned int *src, int count) { - TIMER_REG(0x08) = 0x4b; /* run timer, latch value */ - return TIMER_REG(0); -} + volatile unsigned int *regs = memregl + base / 4; + int i; -static 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; + for (i = 0; i < count; i++) + regs[i] = src[i]; } int pollux_get_real_snd_rate(int req_rate) @@ -284,192 +135,6 @@ int pollux_get_real_snd_rate(int req_rate) return rate; } -void pollux_init(void) -{ - struct fb_fix_screeninfo fbfix; - int i, ret, rate, timer_div; - - memdev = open("/dev/mem", O_RDWR); - if (memdev == -1) { - perror("open(/dev/mem) failed"); - exit(1); - } - - memregs = mmap(0, 0x20000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000); - if (memregs == MAP_FAILED) { - perror("mmap(memregs) failed"); - exit(1); - } - memregl = (volatile void *)memregs; - - fbdev = open("/dev/fb0", O_RDWR); - if (fbdev < 0) { - perror("can't open fbdev"); - exit(1); - } - - ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix); - if (ret == -1) { - perror("ioctl(fbdev) failed"); - exit(1); - } - - printf("framebuffer: \"%s\" @ %08lx\n", fbfix.id, fbfix.smem_start); - fb_paddr[0] = fbfix.smem_start; - - gp2x_screens[0] = mmap(0, 320*240*2*fb_buf_count, PROT_READ|PROT_WRITE, - MAP_SHARED, memdev, fb_paddr[0]); - if (gp2x_screens[0] == MAP_FAILED) - { - perror("mmap(gp2x_screens) failed"); - exit(1); - } - memset(gp2x_screens[0], 0, 320*240*2*fb_buf_count); - - printf(" %p -> %08x\n", gp2x_screens[0], fb_paddr[0]); - for (i = 1; i < fb_buf_count; i++) - { - fb_paddr[i] = fb_paddr[i-1] + 320*240*2; - gp2x_screens[i] = (char *)gp2x_screens[i-1] + 320*240*2; - printf(" %p -> %08x\n", gp2x_screens[i], fb_paddr[i]); - } - fb_work_buf = 0; - g_screen_ptr = gp2x_screens[0]; - - battdev = open("/dev/pollux_batt", O_RDONLY); - if (battdev < 0) - perror("Warning: could't open pollux_batt"); - - /* find what PLL1 runs at, for the timer */ - rate = decode_pll(memregl[0xf008>>2]); - printf("PLL1 @ %dHz\n", rate); - - /* setup timer */ - 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) = ((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 */ - - gp2x_get_ticks_ms = gp2x_get_ticks_ms_; - gp2x_get_ticks_us = gp2x_get_ticks_us_; - } - else { - fprintf(stderr, "warning: could not make use of timer\n"); - - // those functions are actually not good at all on Wiz kernel - gp2x_get_ticks_ms = plat_get_ticks_ms_good; - gp2x_get_ticks_us = plat_get_ticks_us_good; - } - - pllsetreg0_old = memregl[0xf004>>2]; - memtimex_old[0] = memregs[0x14802>>1]; - memtimex_old[1] = memregs[0x14804>>1]; - - gp2x_video_flip = gp2x_video_flip_; - gp2x_video_flip2 = gp2x_video_flip2_; - gp2x_video_changemode_ll = gp2x_video_changemode_ll_; - gp2x_video_setpalette = gp2x_video_setpalette_; - gp2x_video_RGB_setscaling = gp2x_video_RGB_setscaling_; - gp2x_video_wait_vsync = gp2x_video_wait_vsync_; - - /* some firmwares have sys clk on PLL0, we can't adjust CPU clock - * by reprogramming the PLL0 then, as it overclocks system bus */ - if ((memregl[0xf000>>2] & 0x03000030) == 0x01000000) - gp2x_set_cpuclk = gp2x_set_cpuclk_; - else { - fprintf(stderr, "unexpected PLL config (%08x), overclocking disabled\n", - memregl[0xf000>>2]); - gp2x_set_cpuclk = NULL; - } - - set_lcd_custom_rate = set_lcd_custom_rate_; - unset_lcd_custom_rate = unset_lcd_custom_rate_; - set_lcd_gamma = set_lcd_gamma_; - - set_ram_timings = set_ram_timings_; - unset_ram_timings = unset_ram_timings_; - gp2x_read_battery = gp2x_read_battery_; -} - -void pollux_finish(void) -{ - /* switch to default fb mem, turn portrait off */ - memregl[0x406C>>2] = fb_paddr[0]; - memregl[0x4058>>2] |= 0x10; - close(fbdev); - - gp2x_video_changemode_ll_(16); - unset_ram_timings_(); - if (cpuclk_was_changed) { - memregl[0xf004>>2] = pllsetreg0_old; - memregl[0xf07c>>2] |= 0x8000; - } - timer_cleanup(); - - munmap((void *)memregs, 0x20000); - close(memdev); - if (battdev >= 0) - close(battdev); -} -#endif - -/* note: both PLLs are programmed the same way, - * the databook incorrectly states that PLL1 differs */ -static int decode_pll(unsigned int reg) -{ - long long v; - int p, m, s; - - p = (reg >> 18) & 0x3f; - m = (reg >> 8) & 0x3ff; - s = reg & 0xff; - - if (p == 0) - p = 1; - - v = 27000000; // master clock - v = v * m / (p << s); - return v; -} - -#define TIMER_BASE3 0x1980 -#define TIMER_REG(x) memregl[(TIMER_BASE3 + x) >> 2] - -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 */ -} - -static void save_multiple_regs(unsigned int *dest, int base, int count) -{ - const volatile unsigned int *regs = memregl + base / 4; - int i; - - for (i = 0; i < count; i++) - dest[i] = regs[i]; -} - -static void restore_multiple_regs(int base, const unsigned int *src, int count) -{ - volatile unsigned int *regs = memregl + base / 4; - int i; - - for (i = 0; i < count; i++) - regs[i] = src[i]; -} - /* newer API */ static int pollux_cpu_clock_get(void) { @@ -527,44 +192,34 @@ static int pollux_bat_capacity_get(void) } } -static int step_volume(int is_up) +static int step_volume(int *volume, int diff) { - static int volume = 50; int ret, val; if (mixerdev < 0) return -1; - if (is_up) { - volume += 5; - if (volume > 255) volume = 255; - } - else { - volume -= 5; - if (volume < 0) volume = 0; - } - val = volume; + *volume += diff; + if (*volume > 255) + *volume = 255; + else if (*volume < 0) + *volume = 0; + + val = *volume; val |= val << 8; ret = ioctl(mixerdev, SOUND_MIXER_WRITE_PCM, &val); - if (ret == -1) + if (ret == -1) { perror("WRITE_PCM"); + return ret; + } - return ret; + return 0; } -struct plat_target plat_target = { - pollux_cpu_clock_get, - pollux_cpu_clock_set, - pollux_bat_capacity_get, - - .step_volume = step_volume, -}; - -int plat_target_init(void) +void pollux_init(void) { int rate, timer_div, timer_div2; - FILE *f; memdev = open("/dev/mem", O_RDWR); if (memdev == -1) { @@ -611,45 +266,42 @@ int plat_target_init(void) fprintf(stderr, "warning: timer in use, overriding!\n"); timer_cleanup(); } - if (timer_rate != 1000000) - fprintf(stderr, "warning: timer drift %d us\n", timer_rate - 1000000); + timer_drift = timer_rate - 1000000; + if (timer_drift != 0) + fprintf(stderr, "warning: timer drift %d us\n", + timer_drift); timer_div2 = (timer_div2 + 3) & 3; TIMER_REG(0x44) = ((timer_div - 1) << 4) | 2; /* using PLL1 */ TIMER_REG(0x40) = 0x0c; /* clocks on */ TIMER_REG(0x08) = 0x68 | timer_div2; /* run timer, clear irq, latch value */ } - else + else { fprintf(stderr, "warning: could not make use of timer\n"); + // those functions are actually not good at all on Wiz kernel + gp2x_get_ticks_ms = plat_get_ticks_ms_good; + gp2x_get_ticks_us = plat_get_ticks_us_good; + } + battdev = open("/dev/pollux_batt", O_RDONLY); if (battdev < 0) perror("Warning: could't open pollux_batt"); - f = fopen("/dev/accel", "rb"); - if (f) { - printf("detected Caanoo\n"); - gp2x_dev_id = GP2X_DEV_CAANOO; - fclose(f); - } - else { - printf("detected Wiz\n"); - gp2x_dev_id = GP2X_DEV_WIZ; - } - mixerdev = open("/dev/mixer", O_RDWR); if (mixerdev == -1) perror("open(/dev/mixer)"); - return 0; -} + plat_target.cpu_clock_get = pollux_cpu_clock_get; + plat_target.cpu_clock_set = pollux_cpu_clock_set; + plat_target.bat_capacity_get = pollux_bat_capacity_get; + plat_target.step_volume = step_volume; -/* to be called after in_probe */ -void plat_target_setup_input(void) -{ + gp2x_get_ticks_ms = gp2x_get_ticks_ms_; + gp2x_get_ticks_us = gp2x_get_ticks_us_; } -void plat_target_finish(void) +void pollux_finish(void) { timer_cleanup(); diff --git a/input.c b/input.c index 12654e4..362f3ce 100644 --- a/input.c +++ b/input.c @@ -60,7 +60,8 @@ static int *in_alloc_binds(int drv_id, int key_count) defbinds = DRV(drv_id).defbinds; if (defbinds != NULL) { for (i = 0; ; i++) { - if (defbinds[i].bit == 0 && defbinds[i].code == 0) + if (defbinds[i].bit == 0 && defbinds[i].btype == 0 + && defbinds[i].bit == 0) break; binds[IN_BIND_OFFS(defbinds[i].code, defbinds[i].btype)] = 1 << defbinds[i].bit; diff --git a/linux/sndout_oss.c b/linux/sndout_oss.c index c0b775a..a8fbe3f 100644 --- a/linux/sndout_oss.c +++ b/linux/sndout_oss.c @@ -41,6 +41,11 @@ int sndout_oss_init(void) void sndout_oss_stop(void) { +#ifdef __GP2X__ + /* restarting audio on GP2X causes trouble */ + return; +#endif + if (sounddev < 0) return; diff --git a/menu.h b/menu.h index 21da7f3..531db6d 100644 --- a/menu.h +++ b/menu.h @@ -88,8 +88,11 @@ typedef struct #define mee_onoff_cust(name, id, var, mask, name_func) \ { name, MB_OPT_CUSTONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, name_func, NULL, NULL } +#define mee_range_cust_h(name, id, var, min, max, name_func, help) \ + { name, MB_OPT_CUSTRANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, name_func, NULL, help } + #define mee_range_cust(name, id, var, min, max, name_func) \ - { name, MB_OPT_CUSTRANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, name_func, NULL, NULL } + mee_range_cust_h(name, id, var, min, max, name_func, NULL) #define mee_enum_h(name, id, var, names_list, help) \ { name, MB_OPT_ENUM, id, &(var), 0, 0, 0, 1, 1, 1, NULL, NULL, names_list, help } diff --git a/plat.h b/plat.h index 54436cd..78dedf3 100644 --- a/plat.h +++ b/plat.h @@ -15,7 +15,7 @@ struct plat_target { int (*hwfilter_set)(int which); int (*lcdrate_set)(int is_pal); int (*gamma_set)(int val, int black_level); - int (*step_volume)(int is_up); + int (*step_volume)(int *volume, int diff); const char **vout_methods; int vout_method; int vout_fullscreen; @@ -76,10 +76,10 @@ static __inline int plat_target_gamma_set(int val, int black_level) } /* step sound volume up or down */ -static __inline int plat_target_step_volume(int is_up) +static __inline int plat_target_step_volume(int *volume, int diff) { if (plat_target.step_volume) - return plat_target.step_volume(is_up); + return plat_target.step_volume(volume, diff); return -1; } -- 2.39.5