2e06e414c3b1e3f1a87a2bf1bd335edffeb5c22c
[libpicofe.git] / gp2x / plat.c
1 /*
2  * (C) notaz, 2013
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
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/types.h>
16 #include <dirent.h>
17 #include <linux/input.h>
18 #include <errno.h>
19
20 #include "../plat.h"
21 #include "../input.h"
22 #include "plat_gp2x.h"
23 #include "soc.h"
24
25 int default_cpu_clock;
26 int gp2x_dev_id;
27
28 static const char * const caanoo_keys[KEY_MAX + 1] = {
29         [0 ... KEY_MAX] = NULL,
30         [KEY_UP]        = "Up",
31         [KEY_LEFT]      = "Left",
32         [KEY_RIGHT]     = "Right",
33         [KEY_DOWN]      = "Down",
34         [BTN_TRIGGER]   = "A",
35         [BTN_THUMB]     = "X",
36         [BTN_THUMB2]    = "B",
37         [BTN_TOP]       = "Y",
38         [BTN_TOP2]      = "L",
39         [BTN_PINKIE]    = "R",
40         [BTN_BASE]      = "Home",
41         [BTN_BASE2]     = "Lock",
42         [BTN_BASE3]     = "I",
43         [BTN_BASE4]     = "II",
44         [BTN_BASE5]     = "Push",
45 };
46
47 /* to be filled by mmsp2/pollux _init */
48 static int sound_rates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 53000, -1 };
49 struct plat_target plat_target = { .sound_rates = sound_rates };
50
51 int plat_target_init(void)
52 {
53         gp2x_soc_t soc;
54         FILE *f;
55
56         soc = soc_detect();
57         switch (soc)
58         {
59         case SOCID_MMSP2:
60                 mmsp2_init();
61                 default_cpu_clock = 200;
62                 gp2x_dev_id = GP2X_DEV_GP2X;
63                 break;
64         case SOCID_POLLUX:
65                 pollux_init();
66                 default_cpu_clock = 533;
67                 f = fopen("/dev/accel", "rb");
68                 if (f) {
69                         printf("detected Caanoo\n");
70                         gp2x_dev_id = GP2X_DEV_CAANOO;
71                         fclose(f);
72                 }
73                 else {
74                         printf("detected Wiz\n");
75                         gp2x_dev_id = GP2X_DEV_WIZ;
76                 }
77                 break;
78         default:
79                 printf("could not recognize SoC.\n");
80                 break;
81         }
82
83         return 0;
84 }
85
86 /* to be called after in_probe */
87 void plat_target_setup_input(void)
88 {
89         if (gp2x_dev_id == GP2X_DEV_CAANOO)
90                 in_set_config(in_name_to_id("evdev:pollux-analog"),
91                         IN_CFG_KEY_NAMES,
92                         caanoo_keys, sizeof(caanoo_keys));
93 }
94
95 void plat_target_finish(void)
96 {
97         gp2x_soc_t soc;
98
99         soc = soc_detect();
100         switch (soc)
101         {
102         case SOCID_MMSP2:
103                 mmsp2_finish();
104                 break;
105         case SOCID_POLLUX:
106                 pollux_finish();
107                 break;
108         default:
109                 break;
110         }
111 }