fbdev: resize: do single ioctl in nonerror path
[pcsx_rearmed.git] / frontend / plat_omap.c
CommitLineData
69af03a2 1/*
2 * (C) notaz, 2010
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 <sys/types.h>
11#include <sys/stat.h>
12#include <fcntl.h>
13#include <unistd.h>
14#include <linux/input.h>
15#include <linux/omapfb.h>
16
17#include "common/input.h"
18#include "common/menu.h"
19#include "linux/fbdev.h"
20#include "linux/oshide.h"
21#include "plugin_lib.h"
22#include "omap.h"
23
24
25static struct vout_fbdev *main_fb;
26int g_layer_x = 80, g_layer_y = 0;
27int g_layer_w = 640, g_layer_h = 480;
28
29struct vout_fbdev *layer_fb;
30
31static const char * const pandora_gpio_keys[KEY_MAX + 1] = {
32 [0 ... KEY_MAX] = NULL,
33 [KEY_UP] = "Up",
34 [KEY_LEFT] = "Left",
35 [KEY_RIGHT] = "Right",
36 [KEY_DOWN] = "Down",
37 [KEY_HOME] = "A",
38 [KEY_PAGEDOWN] = "X",
39 [KEY_END] = "B",
40 [KEY_PAGEUP] = "Y",
41 [KEY_RIGHTSHIFT]= "L",
42 [KEY_RIGHTCTRL] = "R",
43 [KEY_LEFTALT] = "Start",
44 [KEY_LEFTCTRL] = "Select",
45 [KEY_MENU] = "Pandora",
46};
47
48struct in_default_bind in_evdev_defbinds[] = {
49 { KEY_UP, IN_BINDTYPE_PLAYER12, DKEY_UP },
50 { KEY_DOWN, IN_BINDTYPE_PLAYER12, DKEY_DOWN },
51 { KEY_LEFT, IN_BINDTYPE_PLAYER12, DKEY_LEFT },
52 { KEY_RIGHT, IN_BINDTYPE_PLAYER12, DKEY_RIGHT },
53 { KEY_SPACE, IN_BINDTYPE_EMU, PEVB_MENU },
54 { KEY_PAGEUP, IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE },
55 { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, DKEY_CROSS },
56 { KEY_END, IN_BINDTYPE_PLAYER12, DKEY_CIRCLE },
57 { KEY_HOME, IN_BINDTYPE_PLAYER12, DKEY_SQUARE },
58 { KEY_LEFTALT, IN_BINDTYPE_PLAYER12, DKEY_START },
59 { KEY_LEFTCTRL, IN_BINDTYPE_PLAYER12, DKEY_SELECT },
60 { KEY_RIGHTSHIFT,IN_BINDTYPE_PLAYER12, DKEY_L1 },
61 { KEY_RIGHTCTRL, IN_BINDTYPE_PLAYER12, DKEY_R1 },
62 { KEY_Q, IN_BINDTYPE_PLAYER12, DKEY_L2 },
63 { KEY_P, IN_BINDTYPE_PLAYER12, DKEY_R2 },
64 { 0, 0, 0 }
65};
66
96d9fde1 67static int omap_setup_layer_(int fd, int enabled, int x, int y, int w, int h, int first_call)
69af03a2 68{
69 struct omapfb_plane_info pi;
70 struct omapfb_mem_info mi;
71 int ret;
72
73 ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);
74 if (ret != 0) {
75 perror("QUERY_PLANE");
76 return -1;
77 }
78
79 ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);
80 if (ret != 0) {
81 perror("QUERY_MEM");
82 return -1;
83 }
84
85 /* must disable when changing stuff */
86 if (pi.enabled) {
87 pi.enabled = 0;
88 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
89 if (ret != 0)
90 perror("SETUP_PLANE");
91 }
92
96d9fde1 93 if (first_call) {
2cb46552 94 mi.size = 640*512*3*3;
96d9fde1 95 ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
96 if (ret != 0) {
97 perror("SETUP_MEM");
98 return -1;
99 }
69af03a2 100 }
101
102 pi.pos_x = x;
103 pi.pos_y = y;
104 pi.out_width = w;
105 pi.out_height = h;
106 pi.enabled = enabled;
107
108 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
109 if (ret != 0) {
110 perror("SETUP_PLANE");
111 return -1;
112 }
113
114 return 0;
115}
116
117int omap_enable_layer(int enabled)
118{
119 return omap_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled,
96d9fde1 120 g_layer_x, g_layer_y, g_layer_w, g_layer_h, 0);
69af03a2 121}
122
69af03a2 123void plat_video_menu_begin(void)
124{
125}
126
127void plat_video_menu_end(void)
128{
129 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
130}
131
132void plat_init(void)
133{
134 const char *main_fb_name, *layer_fb_name;
135 void *temp_frame;
136 int fd, ret, w, h;
137
138 main_fb_name = getenv("FBDEV_MAIN");
139 if (main_fb_name == NULL)
140 main_fb_name = "/dev/fb0";
141
142 layer_fb_name = getenv("FBDEV_LAYER");
143 if (layer_fb_name == NULL)
144 layer_fb_name = "/dev/fb1";
145
146 // must set the layer up first to be able to use it
147 fd = open(layer_fb_name, O_RDWR);
148 if (fd == -1) {
149 fprintf(stderr, "%s: ", layer_fb_name);
150 perror("open");
151 exit(1);
152 }
153
bbd837c6 154 ret = omap_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h, 1);
69af03a2 155 close(fd);
156 if (ret != 0) {
157 fprintf(stderr, "failed to set up layer, exiting.\n");
158 exit(1);
159 }
160
161 oshide_init();
162
163 w = h = 0;
164 main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2);
165 if (main_fb == NULL) {
166 fprintf(stderr, "couldn't init fb: %s\n", main_fb_name);
167 exit(1);
168 }
169
170 g_menuscreen_w = w;
171 g_menuscreen_h = h;
172 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
173
174 w = 640;
175 h = 512; // ??
176 layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3);
177 if (layer_fb == NULL) {
178 fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name);
179 goto fail0;
180 }
181
182 temp_frame = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
183 if (temp_frame == NULL) {
184 fprintf(stderr, "OOM\n");
185 goto fail1;
186 }
187 g_menubg_ptr = temp_frame;
69af03a2 188
189 in_set_config(in_name_to_id("evdev:gpio-keys"), IN_CFG_KEY_NAMES,
190 pandora_gpio_keys, sizeof(pandora_gpio_keys));
191 return;
192
193fail1:
194 vout_fbdev_finish(layer_fb);
195fail0:
196 vout_fbdev_finish(main_fb);
197 exit(1);
198
199}
200
bd6267e6 201void plat_finish(void)
202{
203 omap_enable_layer(0);
204 vout_fbdev_finish(layer_fb);
205 vout_fbdev_finish(main_fb);
206 oshide_finish();
207}
208