distinguish VR SVP from 32X version
[picodrive.git] / platform / gp2x / soc.c
CommitLineData
42171343 1#include <stdio.h>
2#include <string.h>
3#include <sys/types.h>
4#include <sys/stat.h>
5#include <fcntl.h>
6#include <sys/mman.h>
7#include <unistd.h>
8
9#include "soc.h"
ee2a3bdf 10
11void (*gp2x_video_flip)(void);
12void (*gp2x_video_flip2)(void);
13void (*gp2x_video_changemode_ll)(int bpp);
14void (*gp2x_video_setpalette)(int *pal, int len);
15void (*gp2x_video_RGB_setscaling)(int ln_offs, int W, int H);
16void (*gp2x_video_wait_vsync)(void);
17
18void (*gp2x_set_cpuclk)(unsigned int mhz);
19
20void (*set_lcd_custom_rate)(int is_pal);
21void (*unset_lcd_custom_rate)(void);
22void (*set_lcd_gamma)(int g100, int A_SNs_curve);
23
24void (*set_ram_timings)(void);
25void (*unset_ram_timings)(void);
61753a67 26int (*gp2x_read_battery)(void);
ee2a3bdf 27
b24e0f6c 28unsigned int (*gp2x_get_ticks_ms)(void);
29unsigned int (*gp2x_get_ticks_us)(void);
30
42171343 31
42171343 32gp2x_soc_t soc_detect(void)
33{
34 volatile unsigned short *memregs;
35 volatile unsigned int *memregl;
274f95a9 36 static gp2x_soc_t ret = -2;
42171343 37 int pollux_chipname[0x30/4 + 1];
38 char *pollux_chipname_c = (char *)pollux_chipname;
42171343 39 int memdev;
40 int i;
41
f4750ee0 42 if ((int)ret != -2)
0d9bf4fc 43 /* already detected */
44 return ret;
45
42171343 46 memdev = open("/dev/mem", O_RDONLY);
47 if (memdev == -1)
48 {
49 perror("open(/dev/mem)");
274f95a9 50 ret = -1;
42171343 51 return -1;
52 }
53
54 memregs = mmap(0, 0x20000, PROT_READ, MAP_SHARED, memdev, 0xc0000000);
55 if (memregs == MAP_FAILED)
56 {
57 perror("mmap(memregs)");
58 close(memdev);
274f95a9 59 ret = -1;
42171343 60 return -1;
61 }
62 memregl = (volatile void *)memregs;
63
64 if (memregs[0x1836>>1] == 0x2330)
65 {
66 printf("looks like this is MMSP2\n");
67 ret = SOCID_MMSP2;
68 goto out;
69 }
70
71 /* perform word reads. Byte reads might also work,
72 * but we don't want to play with that. */
73 for (i = 0; i < 0x30; i += 4)
74 {
75 pollux_chipname[i >> 2] = memregl[(0x1f810 + i) >> 2];
76 }
77 pollux_chipname_c[0x30] = 0;
78
79 for (i = 0; i < 0x30; i++)
80 {
81 unsigned char c = pollux_chipname_c[i];
82 if (c < 0x20 || c > 0x7f)
83 goto not_pollux_like;
84 }
85
86 printf("found pollux-like id: \"%s\"\n", pollux_chipname_c);
87
88 if (strncmp(pollux_chipname_c, "MAGICEYES-LEAPFROG-LF1000", 25) ||
89 strncmp(pollux_chipname_c, "MAGICEYES-POLLUX", 16))
90 {
91 ret = SOCID_POLLUX;
92 goto out;
93 }
94
95not_pollux_like:
96out:
97 munmap((void *)memregs, 0x20000);
98 close(memdev);
42171343 99 return ret;
100}
101