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