f89d8471 |
1 | /* |
2 | * (C) GraÅžvydas "notaz" Ignotas, 2009-2010 |
3 | * |
4 | * This work is licensed under the terms of any of these licenses |
5 | * (at your option): |
6 | * - GNU GPL, version 2 or later. |
7 | * - GNU LGPL, version 2.1 or later. |
8 | * - MAME license. |
9 | * See the COPYING file in the top-level directory. |
10 | */ |
11 | |
d572cbad |
12 | #include <stdio.h> |
13 | #include <string.h> |
14 | #include <sys/types.h> |
15 | #include <sys/stat.h> |
16 | #include <fcntl.h> |
17 | #include <sys/mman.h> |
18 | #include <unistd.h> |
19 | |
20 | #include "soc.h" |
fa8d1331 |
21 | |
7ceadd99 |
22 | volatile unsigned short *memregs; |
23 | volatile unsigned int *memregl; |
24 | int memdev = -1; |
fa8d1331 |
25 | |
b5bfb864 |
26 | unsigned int (*gp2x_get_ticks_ms)(void); |
27 | unsigned int (*gp2x_get_ticks_us)(void); |
28 | |
d572cbad |
29 | gp2x_soc_t soc_detect(void) |
30 | { |
31 | volatile unsigned short *memregs; |
32 | volatile unsigned int *memregl; |
1eb704b6 |
33 | static gp2x_soc_t ret = -2; |
d572cbad |
34 | int pollux_chipname[0x30/4 + 1]; |
35 | char *pollux_chipname_c = (char *)pollux_chipname; |
7ceadd99 |
36 | int memdev_tmp; |
d572cbad |
37 | int i; |
38 | |
b6072c17 |
39 | if ((int)ret != -2) |
fa5e045b |
40 | /* already detected */ |
41 | return ret; |
42 | |
7ceadd99 |
43 | memdev_tmp = open("/dev/mem", O_RDONLY); |
44 | if (memdev_tmp == -1) |
d572cbad |
45 | { |
46 | perror("open(/dev/mem)"); |
1eb704b6 |
47 | ret = -1; |
d572cbad |
48 | return -1; |
49 | } |
50 | |
7ceadd99 |
51 | memregs = mmap(0, 0x20000, PROT_READ, MAP_SHARED, |
52 | memdev_tmp, 0xc0000000); |
d572cbad |
53 | if (memregs == MAP_FAILED) |
54 | { |
55 | perror("mmap(memregs)"); |
7ceadd99 |
56 | close(memdev_tmp); |
1eb704b6 |
57 | ret = -1; |
d572cbad |
58 | return -1; |
59 | } |
60 | memregl = (volatile void *)memregs; |
61 | |
62 | if (memregs[0x1836>>1] == 0x2330) |
63 | { |
64 | printf("looks like this is MMSP2\n"); |
65 | ret = SOCID_MMSP2; |
66 | goto out; |
67 | } |
68 | |
69 | /* perform word reads. Byte reads might also work, |
70 | * but we don't want to play with that. */ |
71 | for (i = 0; i < 0x30; i += 4) |
72 | { |
73 | pollux_chipname[i >> 2] = memregl[(0x1f810 + i) >> 2]; |
74 | } |
75 | pollux_chipname_c[0x30] = 0; |
76 | |
77 | for (i = 0; i < 0x30; i++) |
78 | { |
79 | unsigned char c = pollux_chipname_c[i]; |
80 | if (c < 0x20 || c > 0x7f) |
81 | goto not_pollux_like; |
82 | } |
83 | |
84 | printf("found pollux-like id: \"%s\"\n", pollux_chipname_c); |
85 | |
86 | if (strncmp(pollux_chipname_c, "MAGICEYES-LEAPFROG-LF1000", 25) || |
87 | strncmp(pollux_chipname_c, "MAGICEYES-POLLUX", 16)) |
88 | { |
89 | ret = SOCID_POLLUX; |
90 | goto out; |
91 | } |
92 | |
93 | not_pollux_like: |
94 | out: |
95 | munmap((void *)memregs, 0x20000); |
7ceadd99 |
96 | close(memdev_tmp); |
d572cbad |
97 | return ret; |
98 | } |
99 | |