2 * (C) GraÅžvydas "notaz" Ignotas, 2011,2012
4 * This work is licensed under the terms of any of these licenses
6 * - GNU GPL, version 2 or later.
7 * - GNU LGPL, version 2.1 or later.
9 * See the COPYING file in the top-level directory.
15 #include <sys/types.h>
17 #include <linux/input.h>
23 static const char * const pandora_gpio_keys[KEY_MAX + 1] = {
24 [0 ... KEY_MAX] = NULL,
27 [KEY_RIGHT] = "Right",
30 [KEY_PAGEDOWN] = "(X)",
33 [KEY_RIGHTSHIFT]= "(L)",
34 [KEY_RIGHTCTRL] = "(R)",
35 [KEY_LEFTALT] = "Start",
36 [KEY_LEFTCTRL] = "Select",
37 [KEY_MENU] = "Pandora",
40 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";
42 static void scan_for_filters(void)
46 const char **mfilters;
50 dir = opendir("/etc/pandora/conf/dss_fir");
52 perror("filter opendir");
65 if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
74 mfilters = calloc(count + 1, sizeof(mfilters[0]));
79 for (i = 0; (ent = readdir(dir)); ) {
82 if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
85 len = strlen(ent->d_name);
87 // skip pre-HF5 extra files
88 if (len >= 3 && strcmp(ent->d_name + len - 3, "_v3") == 0)
90 if (len >= 3 && strcmp(ent->d_name + len - 3, "_v5") == 0)
93 // have to cut "_up_h" for pre-HF5
94 if (len > 5 && strcmp(ent->d_name + len - 5, "_up_h") == 0)
97 if (len > sizeof(buff) - 1)
100 strncpy(buff, ent->d_name, len);
102 mfilters[i] = strdup(buff);
103 if (mfilters[i] != NULL)
108 plat_target.hwfilters = mfilters;
111 static int do_system(const char *cmd)
122 static int read_int_from_file(const char *fname)
127 f = fopen(fname, "r");
129 fscanf(f, "%d", &ret);
135 static int lcdrate_set(int is_pal)
137 static int old_pal = -1;
140 if (is_pal == old_pal)
144 snprintf(buf, sizeof(buf), "%s/op_lcdrate.sh %d",
145 pnd_script_base, is_pal ? 50 : 60);
146 return do_system(buf);
149 static int hwfilter_set(int which)
151 static int old_filter = -1;
155 if (plat_target.hwfilters == NULL)
158 if (which == old_filter)
161 for (i = 0; i <= which; i++)
162 if (plat_target.hwfilters[i] == NULL)
167 snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s",
168 pnd_script_base, plat_target.hwfilters[which]);
169 return do_system(buf);
172 static int cpu_clock_get(void)
174 return read_int_from_file("/proc/pandora/cpu_mhz_max");
177 static int cpu_clock_set(int cpu_clock)
184 if (cpu_clock == cpu_clock_get())
187 snprintf(buf, sizeof(buf),
188 "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",
189 pnd_script_base, cpu_clock);
190 return do_system(buf);
193 static int bat_capacity_get(void)
195 return read_int_from_file("/sys/class/power_supply/bq27500-0/capacity");
198 static int gamma_set(int val, int black_level)
202 snprintf(buf, sizeof(buf), "%s/op_gamma.sh -b %d %.2f",
203 pnd_script_base, black_level, (float)val / 100.0f);
204 return do_system(buf);
207 struct plat_target plat_target = {
216 int plat_target_init(void)
223 /* to be called after in_probe */
224 void plat_target_setup_input(void)
228 gpiokeys_id = in_name_to_id("evdev:gpio-keys");
229 in_set_config(gpiokeys_id, IN_CFG_KEY_NAMES,
230 pandora_gpio_keys, sizeof(pandora_gpio_keys));
231 in_set_config(gpiokeys_id, IN_CFG_DEFAULT_DEV, NULL, 0);
234 void plat_target_finish(void)