2 * (C) GraÅžvydas "notaz" Ignotas, 2009,2013
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.
11 * <random_info=mem_map>
12 * 00000000-029fffff linux (42MB)
13 * 02a00000-02dfffff fb (4MB, 153600B really used)
14 * 02e00000-02ffffff sound dma (2MB)
15 * 03000000-03ffffff MPEGDEC (?, 16MB)
22 #include <sys/types.h>
25 #include <sys/ioctl.h>
30 #include "../libpicofe/gp2x/soc.h"
31 #include "../libpicofe/gp2x/plat_gp2x.h"
32 #include "../libpicofe/gp2x/pollux_set.h"
33 #include "../common/emu.h"
34 #include "../common/arm_utils.h"
37 #define FB_BUF_COUNT 4
38 #define FB_MEM_SIZE (320*240*2 * FB_BUF_COUNT)
40 static unsigned int fb_paddr[FB_BUF_COUNT];
41 static int fb_work_buf;
42 static int fbdev = -1;
46 static void pollux_video_flip(int buf_count)
48 memregl[0x406C>>2] = memregl[0x446C>>2] = fb_paddr[fb_work_buf];
49 memregl[0x4058>>2] |= 0x10;
50 memregl[0x4458>>2] |= 0x10;
53 if (fb_work_buf >= buf_count)
55 g_screen_ptr = gp2x_screens[fb_work_buf];
58 static void gp2x_video_flip_(void)
60 pollux_video_flip(FB_BUF_COUNT);
63 /* doulblebuffered flip */
64 static void gp2x_video_flip2_(void)
69 static void gp2x_video_changemode_ll_(int bpp, int is_pal)
71 static int prev_bpp = 0;
72 int code = 0, bytes = 2;
73 int rot_cmd[2] = { 0, 0 };
82 printf("changemode: %dbpp rot=%d\n", abs(bpp), bpp < 0);
84 /* negative bpp means rotated mode */
85 rot_cmd[0] = (bpp < 0) ? 6 : 5;
86 ret = ioctl(fbdev, _IOW('D', 90, int[2]), rot_cmd);
88 perror("rot ioctl failed");
89 memregl[0x4004>>2] = (bpp < 0) ? 0x013f00ef : 0x00ef013f;
90 memregl[0x4000>>2] |= 1 << 3;
92 /* the above ioctl resets LCD timings, so set them here */
93 snprintf(buff, sizeof(buff), "POLLUX_LCD_TIMINGS_%s",
94 is_pal ? "PAL" : "NTSC");
95 pollux_set_fromenv(memregs, buff);
111 printf("unhandled bpp request: %d\n", abs(bpp));
115 // program both MLCs so that TV-out works
116 memregl[0x405c>>2] = memregl[0x445c>>2] = bytes;
117 memregl[0x4060>>2] = memregl[0x4460>>2] =
118 bytes * (bpp < 0 ? 240 : 320);
120 r = memregl[0x4058>>2];
121 r = (r & 0xffff) | (code << 16) | 0x10;
122 memregl[0x4058>>2] = r;
124 r = memregl[0x4458>>2];
125 r = (r & 0xffff) | (code << 16) | 0x10;
126 memregl[0x4458>>2] = r;
129 static void gp2x_video_setpalette_(int *pal, int len)
131 /* pollux palette is 16bpp only.. */
133 for (i = 0; i < len; i++)
136 c = ((c >> 8) & 0xf800) | ((c >> 5) & 0x07c0) | ((c >> 3) & 0x001f);
137 memregl[0x4070>>2] = (i << 24) | c;
141 static void gp2x_video_RGB_setscaling_(int ln_offs, int W, int H)
143 /* maybe a job for 3d hardware? */
146 static void gp2x_video_wait_vsync_(void)
148 while (!(memregl[0x308c>>2] & (1 << 10)))
150 memregl[0x308c>>2] |= 1 << 10;
153 void vid_pollux_init(void)
155 struct fb_fix_screeninfo fbfix;
158 fbdev = open("/dev/fb0", O_RDWR);
160 perror("can't open fbdev");
164 ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix);
166 perror("ioctl(fbdev) failed");
170 printf("framebuffer: \"%s\" @ %08lx\n", fbfix.id, fbfix.smem_start);
171 fb_paddr[0] = fbfix.smem_start;
173 gp2x_screens[0] = mmap(0, FB_MEM_SIZE, PROT_READ|PROT_WRITE,
174 MAP_SHARED, memdev, fb_paddr[0]);
175 if (gp2x_screens[0] == MAP_FAILED)
177 perror("mmap(gp2x_screens) failed");
180 memset(gp2x_screens[0], 0, FB_MEM_SIZE);
182 printf(" %p -> %08x\n", gp2x_screens[0], fb_paddr[0]);
183 for (i = 1; i < FB_BUF_COUNT; i++)
185 fb_paddr[i] = fb_paddr[i-1] + 320*240*2;
186 gp2x_screens[i] = (char *)gp2x_screens[i-1] + 320*240*2;
187 printf(" %p -> %08x\n", gp2x_screens[i], fb_paddr[i]);
190 g_screen_ptr = gp2x_screens[0];
192 gp2x_video_flip = gp2x_video_flip_;
193 gp2x_video_flip2 = gp2x_video_flip2_;
194 gp2x_video_changemode_ll = gp2x_video_changemode_ll_;
195 gp2x_video_setpalette = gp2x_video_setpalette_;
196 gp2x_video_RGB_setscaling = gp2x_video_RGB_setscaling_;
197 gp2x_video_wait_vsync = gp2x_video_wait_vsync_;
200 void vid_pollux_finish(void)
202 memset(gp2x_screens[0], 0, FB_MEM_SIZE);
203 munmap(gp2x_screens[0], FB_MEM_SIZE);