4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
11 #include <sys/types.h>
14 #include <sys/ioctl.h>
16 #include <linux/input.h>
19 #include "common/input.h"
20 #include "plugin_lib.h"
25 static int analog_init_done;
27 static const char * const pandora_gpio_keys[KEY_MAX + 1] = {
28 [0 ... KEY_MAX] = NULL,
31 [KEY_RIGHT] = "Right",
34 [KEY_PAGEDOWN] = "(X)",
37 [KEY_RIGHTSHIFT]= "(L)",
38 [KEY_RIGHTCTRL] = "(R)",
39 [KEY_LEFTALT] = "Start",
40 [KEY_LEFTCTRL] = "Select",
41 [KEY_MENU] = "Pandora",
44 struct in_default_bind in_evdev_defbinds[] = {
45 { KEY_UP, IN_BINDTYPE_PLAYER12, DKEY_UP },
46 { KEY_DOWN, IN_BINDTYPE_PLAYER12, DKEY_DOWN },
47 { KEY_LEFT, IN_BINDTYPE_PLAYER12, DKEY_LEFT },
48 { KEY_RIGHT, IN_BINDTYPE_PLAYER12, DKEY_RIGHT },
49 { KEY_PAGEUP, IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE },
50 { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, DKEY_CROSS },
51 { KEY_END, IN_BINDTYPE_PLAYER12, DKEY_CIRCLE },
52 { KEY_HOME, IN_BINDTYPE_PLAYER12, DKEY_SQUARE },
53 { KEY_LEFTALT, IN_BINDTYPE_PLAYER12, DKEY_START },
54 { KEY_LEFTCTRL, IN_BINDTYPE_PLAYER12, DKEY_SELECT },
55 { KEY_RIGHTSHIFT,IN_BINDTYPE_PLAYER12, DKEY_L1 },
56 { KEY_RIGHTCTRL, IN_BINDTYPE_PLAYER12, DKEY_R1 },
57 { KEY_Q, IN_BINDTYPE_PLAYER12, DKEY_L2 },
58 { KEY_P, IN_BINDTYPE_PLAYER12, DKEY_R2 },
59 { KEY_SPACE, IN_BINDTYPE_EMU, SACTION_ENTER_MENU },
60 { KEY_1, IN_BINDTYPE_EMU, SACTION_SAVE_STATE },
61 { KEY_2, IN_BINDTYPE_EMU, SACTION_LOAD_STATE },
62 { KEY_3, IN_BINDTYPE_EMU, SACTION_PREV_SSLOT },
63 { KEY_4, IN_BINDTYPE_EMU, SACTION_NEXT_SSLOT },
64 { KEY_5, IN_BINDTYPE_EMU, SACTION_TOGGLE_FSKIP },
65 { KEY_6, IN_BINDTYPE_EMU, SACTION_SCREENSHOT },
69 static void analog_init(void)
73 fdnub[0] = fdnub[1] = -1;
75 for (i = nub = 0; nub < 2; i++)
77 long absbits[(ABS_MAX+1) / sizeof(long) / 8];
78 int ret, fd, support = 0;
81 snprintf(name, sizeof(name), "/dev/input/event%d", i);
82 fd = open(name, O_RDONLY|O_NONBLOCK);
85 continue; /* maybe we can access next one */
89 /* check supported events */
90 ret = ioctl(fd, EVIOCGBIT(0, sizeof(support)), &support);
92 printf("pandora: ioctl failed on %s\n", name);
96 if (!(support & (1 << EV_ABS)))
99 ret = ioctl(fd, EVIOCGNAME(sizeof(name)), name);
100 if (ret == -1 || strncmp(name, "nub", 3) != 0)
103 ret = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits);
106 if ((absbits[0] & ((1 << ABS_X)|(1 << ABS_Y))) != ((1 << ABS_X)|(1 << ABS_Y)))
109 printf("pandora: found analog #%d \"%s\"\n", nub, name);
118 printf("pandora: warning: not all nubs found: %d\n", nub);
120 analog_init_done = 1;
123 void in_update_analogs(void)
125 int *nubp[2] = { in_a1, in_a2 };
126 struct input_absinfo ainfo;
129 if (!analog_init_done)
132 for (i = 0; i < 2; i++) {
137 ret = ioctl(fd, EVIOCGABS(ABS_X), &ainfo);
142 v = ainfo.value / 2 + 127;
143 nubp[i][0] = v < 0 ? 0 : v;
145 ret = ioctl(fd, EVIOCGABS(ABS_Y), &ainfo);
150 v = ainfo.value / 2 + 127;
151 nubp[i][1] = v < 0 ? 0 : v;
153 //printf("%4d %4d %4d %4d\n", in_a1[0], in_a1[1], in_a2[0], in_a2[1]);
156 int plat_rescan_inputs(void)
159 in_set_config(in_name_to_id("evdev:gpio-keys"), IN_CFG_KEY_NAMES,
160 pandora_gpio_keys, sizeof(pandora_gpio_keys));
165 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";
167 int plat_cpu_clock_get(void)
171 f = fopen("/proc/pandora/cpu_mhz_max", "r");
173 fscanf(f, "%d", &ret);
179 int plat_cpu_clock_apply(int cpu_clock)
183 if (cpu_clock != 0 && cpu_clock != plat_cpu_clock_get()) {
184 snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",
185 pnd_script_base, cpu_clock);
191 int plat_get_bat_capacity(void)
195 f = fopen("/sys/class/power_supply/bq27500-0/capacity", "r");
197 fscanf(f, "%d", &ret);