| 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 | struct plat_target plat_target; |
| 49 | |
| 50 | int plat_target_init(void) |
| 51 | { |
| 52 | gp2x_soc_t soc; |
| 53 | FILE *f; |
| 54 | |
| 55 | soc = soc_detect(); |
| 56 | switch (soc) |
| 57 | { |
| 58 | case SOCID_MMSP2: |
| 59 | mmsp2_init(); |
| 60 | default_cpu_clock = 200; |
| 61 | gp2x_dev_id = GP2X_DEV_GP2X; |
| 62 | break; |
| 63 | case SOCID_POLLUX: |
| 64 | pollux_init(); |
| 65 | default_cpu_clock = 533; |
| 66 | f = fopen("/dev/accel", "rb"); |
| 67 | if (f) { |
| 68 | printf("detected Caanoo\n"); |
| 69 | gp2x_dev_id = GP2X_DEV_CAANOO; |
| 70 | fclose(f); |
| 71 | } |
| 72 | else { |
| 73 | printf("detected Wiz\n"); |
| 74 | gp2x_dev_id = GP2X_DEV_WIZ; |
| 75 | } |
| 76 | break; |
| 77 | default: |
| 78 | printf("could not recognize SoC.\n"); |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | /* to be called after in_probe */ |
| 86 | void plat_target_setup_input(void) |
| 87 | { |
| 88 | if (gp2x_dev_id == GP2X_DEV_CAANOO) |
| 89 | in_set_config(in_name_to_id("evdev:pollux-analog"), |
| 90 | IN_CFG_KEY_NAMES, |
| 91 | caanoo_keys, sizeof(caanoo_keys)); |
| 92 | } |
| 93 | |
| 94 | void plat_target_finish(void) |
| 95 | { |
| 96 | gp2x_soc_t soc; |
| 97 | |
| 98 | soc = soc_detect(); |
| 99 | switch (soc) |
| 100 | { |
| 101 | case SOCID_MMSP2: |
| 102 | mmsp2_finish(); |
| 103 | break; |
| 104 | case SOCID_POLLUX: |
| 105 | pollux_finish(); |
| 106 | break; |
| 107 | default: |
| 108 | break; |
| 109 | } |
| 110 | } |