| 1 | /* |
| 2 | * (C) notaz, 2011 |
| 3 | * |
| 4 | * This work is licensed under the terms of the GNU GPLv2 or later. |
| 5 | * See the COPYING file in the top-level directory. |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
| 11 | #include <sys/types.h> |
| 12 | #include <sys/stat.h> |
| 13 | #include <fcntl.h> |
| 14 | #include <sys/ioctl.h> |
| 15 | #include <unistd.h> |
| 16 | #include <linux/input.h> |
| 17 | #include <errno.h> |
| 18 | |
| 19 | #include "common/input.h" |
| 20 | #include "plugin_lib.h" |
| 21 | #include "plat.h" |
| 22 | #include "main.h" |
| 23 | |
| 24 | static const char * const pandora_gpio_keys[KEY_MAX + 1] = { |
| 25 | [0 ... KEY_MAX] = NULL, |
| 26 | [KEY_UP] = "Up", |
| 27 | [KEY_LEFT] = "Left", |
| 28 | [KEY_RIGHT] = "Right", |
| 29 | [KEY_DOWN] = "Down", |
| 30 | [KEY_HOME] = "(A)", |
| 31 | [KEY_PAGEDOWN] = "(X)", |
| 32 | [KEY_END] = "(B)", |
| 33 | [KEY_PAGEUP] = "(Y)", |
| 34 | [KEY_RIGHTSHIFT]= "(L)", |
| 35 | [KEY_RIGHTCTRL] = "(R)", |
| 36 | [KEY_LEFTALT] = "Start", |
| 37 | [KEY_LEFTCTRL] = "Select", |
| 38 | [KEY_MENU] = "Pandora", |
| 39 | }; |
| 40 | |
| 41 | struct in_default_bind in_evdev_defbinds[] = { |
| 42 | { KEY_UP, IN_BINDTYPE_PLAYER12, DKEY_UP }, |
| 43 | { KEY_DOWN, IN_BINDTYPE_PLAYER12, DKEY_DOWN }, |
| 44 | { KEY_LEFT, IN_BINDTYPE_PLAYER12, DKEY_LEFT }, |
| 45 | { KEY_RIGHT, IN_BINDTYPE_PLAYER12, DKEY_RIGHT }, |
| 46 | { KEY_PAGEUP, IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE }, |
| 47 | { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, DKEY_CROSS }, |
| 48 | { KEY_END, IN_BINDTYPE_PLAYER12, DKEY_CIRCLE }, |
| 49 | { KEY_HOME, IN_BINDTYPE_PLAYER12, DKEY_SQUARE }, |
| 50 | { KEY_LEFTALT, IN_BINDTYPE_PLAYER12, DKEY_START }, |
| 51 | { KEY_LEFTCTRL, IN_BINDTYPE_PLAYER12, DKEY_SELECT }, |
| 52 | { KEY_RIGHTSHIFT,IN_BINDTYPE_PLAYER12, DKEY_L1 }, |
| 53 | { KEY_RIGHTCTRL, IN_BINDTYPE_PLAYER12, DKEY_R1 }, |
| 54 | { KEY_Q, IN_BINDTYPE_PLAYER12, DKEY_L2 }, |
| 55 | { KEY_P, IN_BINDTYPE_PLAYER12, DKEY_R2 }, |
| 56 | { KEY_TAB, IN_BINDTYPE_EMU, SACTION_MINIMIZE }, |
| 57 | { KEY_SPACE, IN_BINDTYPE_EMU, SACTION_ENTER_MENU }, |
| 58 | { KEY_1, IN_BINDTYPE_EMU, SACTION_SAVE_STATE }, |
| 59 | { KEY_2, IN_BINDTYPE_EMU, SACTION_LOAD_STATE }, |
| 60 | { KEY_3, IN_BINDTYPE_EMU, SACTION_PREV_SSLOT }, |
| 61 | { KEY_4, IN_BINDTYPE_EMU, SACTION_NEXT_SSLOT }, |
| 62 | { KEY_5, IN_BINDTYPE_EMU, SACTION_TOGGLE_FSKIP }, |
| 63 | { KEY_6, IN_BINDTYPE_EMU, SACTION_SCREENSHOT }, |
| 64 | { 0, 0, 0 } |
| 65 | }; |
| 66 | |
| 67 | int plat_pandora_init(void) |
| 68 | { |
| 69 | in_probe(); |
| 70 | in_set_config(in_name_to_id("evdev:gpio-keys"), IN_CFG_KEY_NAMES, |
| 71 | pandora_gpio_keys, sizeof(pandora_gpio_keys)); |
| 72 | in_adev[0] = in_name_to_id("evdev:nub0"); |
| 73 | in_adev[1] = in_name_to_id("evdev:nub1"); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts"; |
| 79 | |
| 80 | int plat_cpu_clock_get(void) |
| 81 | { |
| 82 | FILE *f; |
| 83 | int ret = 0; |
| 84 | f = fopen("/proc/pandora/cpu_mhz_max", "r"); |
| 85 | if (f) { |
| 86 | fscanf(f, "%d", &ret); |
| 87 | fclose(f); |
| 88 | } |
| 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | int plat_cpu_clock_apply(int cpu_clock) |
| 93 | { |
| 94 | char buf[128]; |
| 95 | |
| 96 | if (cpu_clock != 0 && cpu_clock != plat_cpu_clock_get()) { |
| 97 | snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d", |
| 98 | pnd_script_base, cpu_clock); |
| 99 | system(buf); |
| 100 | } |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | int plat_get_bat_capacity(void) |
| 105 | { |
| 106 | FILE *f; |
| 107 | int ret = 0; |
| 108 | f = fopen("/sys/class/power_supply/bq27500-0/capacity", "r"); |
| 109 | if (f) { |
| 110 | fscanf(f, "%d", &ret); |
| 111 | fclose(f); |
| 112 | } |
| 113 | return ret; |
| 114 | } |