add cd swap functionality
[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>
799b0b87 13#include <sys/ioctl.h>
69af03a2 14#include <unistd.h>
69af03a2 15#include <linux/omapfb.h>
16
69af03a2 17#include "common/menu.h"
18#include "linux/fbdev.h"
19#include "linux/oshide.h"
20#include "plugin_lib.h"
21#include "omap.h"
799b0b87 22#include "pandora.h"
69af03a2 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
96d9fde1 31static int omap_setup_layer_(int fd, int enabled, int x, int y, int w, int h, int first_call)
69af03a2 32{
33 struct omapfb_plane_info pi;
34 struct omapfb_mem_info mi;
35 int ret;
36
37 ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);
38 if (ret != 0) {
39 perror("QUERY_PLANE");
40 return -1;
41 }
42
43 ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);
44 if (ret != 0) {
45 perror("QUERY_MEM");
46 return -1;
47 }
48
49 /* must disable when changing stuff */
50 if (pi.enabled) {
51 pi.enabled = 0;
52 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
53 if (ret != 0)
54 perror("SETUP_PLANE");
55 }
56
96d9fde1 57 if (first_call) {
2cb46552 58 mi.size = 640*512*3*3;
96d9fde1 59 ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
60 if (ret != 0) {
61 perror("SETUP_MEM");
62 return -1;
63 }
69af03a2 64 }
65
66 pi.pos_x = x;
67 pi.pos_y = y;
68 pi.out_width = w;
69 pi.out_height = h;
70 pi.enabled = enabled;
71
72 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
73 if (ret != 0) {
74 perror("SETUP_PLANE");
75 return -1;
76 }
77
78 return 0;
79}
80
81int omap_enable_layer(int enabled)
82{
83 return omap_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled,
96d9fde1 84 g_layer_x, g_layer_y, g_layer_w, g_layer_h, 0);
69af03a2 85}
86
fba06457 87void plat_video_menu_enter(int is_rom_loaded)
88{
89 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
90 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 3);
91 if (g_menuscreen_ptr == NULL)
92 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
93}
94
69af03a2 95void plat_video_menu_begin(void)
96{
97}
98
99void plat_video_menu_end(void)
100{
101 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
102}
103
fba06457 104void plat_video_menu_leave(void)
105{
106 /* have to get rid of panning so that plugins that
107 * use fb0 and don't ever pan can work. */
108 vout_fbdev_clear(main_fb);
109 g_menuscreen_ptr = vout_fbdev_resize(main_fb,
110 g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 1);
111 if (g_menuscreen_ptr == NULL)
112 fprintf(stderr, "warning: vout_fbdev_resize failed\n");
113}
114
69af03a2 115void plat_init(void)
116{
117 const char *main_fb_name, *layer_fb_name;
118 void *temp_frame;
119 int fd, ret, w, h;
120
121 main_fb_name = getenv("FBDEV_MAIN");
122 if (main_fb_name == NULL)
123 main_fb_name = "/dev/fb0";
124
125 layer_fb_name = getenv("FBDEV_LAYER");
126 if (layer_fb_name == NULL)
127 layer_fb_name = "/dev/fb1";
128
129 // must set the layer up first to be able to use it
130 fd = open(layer_fb_name, O_RDWR);
131 if (fd == -1) {
132 fprintf(stderr, "%s: ", layer_fb_name);
133 perror("open");
134 exit(1);
135 }
136
bbd837c6 137 ret = omap_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h, 1);
69af03a2 138 close(fd);
139 if (ret != 0) {
140 fprintf(stderr, "failed to set up layer, exiting.\n");
141 exit(1);
142 }
143
144 oshide_init();
145
146 w = h = 0;
147 main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2);
148 if (main_fb == NULL) {
149 fprintf(stderr, "couldn't init fb: %s\n", main_fb_name);
150 exit(1);
151 }
152
153 g_menuscreen_w = w;
154 g_menuscreen_h = h;
155 g_menuscreen_ptr = vout_fbdev_flip(main_fb);
156
157 w = 640;
158 h = 512; // ??
159 layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3);
160 if (layer_fb == NULL) {
161 fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name);
162 goto fail0;
163 }
164
165 temp_frame = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
166 if (temp_frame == NULL) {
167 fprintf(stderr, "OOM\n");
168 goto fail1;
169 }
170 g_menubg_ptr = temp_frame;
69af03a2 171
799b0b87 172 pandora_init();
69af03a2 173 return;
174
175fail1:
176 vout_fbdev_finish(layer_fb);
177fail0:
178 vout_fbdev_finish(main_fb);
179 exit(1);
180
181}
182
bd6267e6 183void plat_finish(void)
184{
185 omap_enable_layer(0);
186 vout_fbdev_finish(layer_fb);
187 vout_fbdev_finish(main_fb);
188 oshide_finish();
189}
190