1 /* drivers/video/pvr2fb.c
3 * Frame buffer and fbcon support for the NEC PowerVR2 found within the Sega
6 * Copyright (c) 2001 M. R. Brown <mrbrown@0xd6.org>
7 * Copyright (c) 2001 Paul Mundt <lethal@chaoticdreams.org>
9 * This file is part of the LinuxDC project (linuxdc.sourceforge.net).
14 * This driver is mostly based on the excellent amifb and vfb sources. It uses
15 * an odd scheme for converting hardware values to/from framebuffer values, here are
16 * some hacked-up formulas:
18 * The Dreamcast has screen offsets from each side of it's four borders and the start
19 * offsets of the display window. I used these values to calculate 'pseudo' values
20 * (think of them as placeholders) for the fb video mode, so that when it came time
21 * to convert these values back into their hardware values, I could just add mode-
22 * specific offsets to get the correct mode settings:
24 * left_margin = diwstart_h - borderstart_h;
25 * right_margin = borderstop_h - (diwstart_h + xres);
26 * upper_margin = diwstart_v - borderstart_v;
27 * lower_margin = borderstop_v - (diwstart_h + yres);
29 * hsync_len = borderstart_h + (hsync_total - borderstop_h);
30 * vsync_len = borderstart_v + (vsync_total - borderstop_v);
32 * Then, when it's time to convert back to hardware settings, the only constants
33 * are the borderstart_* offsets, all other values are derived from the fb video
37 * borderstart_h = 116;
40 * borderstop_h = borderstart_h + hsync_total - hsync_len;
42 * diwstart_v = borderstart_v - upper_margin;
44 * However, in the current implementation, the borderstart values haven't had
45 * the benefit of being fully researched, so some modes may be broken.
48 #include <linux/module.h>
49 #include <linux/kernel.h>
50 #include <linux/errno.h>
51 #include <linux/string.h>
53 #include <linux/tty.h>
54 #include <linux/slab.h>
55 #include <linux/delay.h>
56 #include <linux/config.h>
57 #include <linux/interrupt.h>
59 #include <linux/init.h>
60 #include <linux/console.h>
62 #ifdef CONFIG_SH_DREAMCAST
64 #include <asm/machvec.h>
65 #include <asm/dc_sysasic.h>
72 #include <video/fbcon.h>
73 #include <video/fbcon-cfb16.h>
74 #include <video/fbcon-cfb24.h>
75 #include <video/fbcon-cfb32.h>
77 #ifdef CONFIG_FB_PVR2_DEBUG
78 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
80 # define DPRINTK(fmt, args...)
83 /* 2D video registers */
84 #define DISP_BASE 0xa05f8000
86 #define DISP_BRDRCOLR (DISP_BASE + 0x40)
87 #define DISP_DIWMODE (DISP_BASE + 0x44)
88 #define DISP_DIWADDRL (DISP_BASE + 0x50)
89 #define DISP_DIWADDRS (DISP_BASE + 0x54)
90 #define DISP_DIWSIZE (DISP_BASE + 0x5c)
91 #define DISP_SYNCCONF (DISP_BASE + 0xd0)
92 #define DISP_BRDRHORZ (DISP_BASE + 0xd4)
93 #define DISP_SYNCSIZE (DISP_BASE + 0xd8)
94 #define DISP_BRDRVERT (DISP_BASE + 0xdc)
95 #define DISP_DIWCONF (DISP_BASE + 0xe8)
96 #define DISP_DIWHSTRT (DISP_BASE + 0xec)
97 #define DISP_DIWVSTRT (DISP_BASE + 0xf0)
99 /* Pixel clocks, one for TV output, doubled for VGA output */
101 #define VGA_CLK 37119
103 /* This is for 60Hz - the VTOTAL is doubled for interlaced modes */
104 #define PAL_HTOTAL 863
105 #define PAL_VTOTAL 312
106 #define NTSC_HTOTAL 857
107 #define NTSC_VTOTAL 262
109 enum { CT_VGA, CT_NONE, CT_RGB, CT_COMPOSITE };
111 enum { VO_PAL, VO_NTSC, VO_VGA };
113 struct pvr2_params { u_short val; char *name; };
114 static struct pvr2_params cables[] __initdata = {
115 { CT_VGA, "VGA" }, { CT_RGB, "RGB" }, { CT_COMPOSITE, "COMPOSITE" },
118 static struct pvr2_params outputs[] __initdata = {
119 { VO_PAL, "PAL" }, { VO_NTSC, "NTSC" }, { VO_VGA, "VGA" },
123 * This describes the current video mode
126 static struct pvr2fb_par {
137 u_short hsync_total; /* Clocks/line */
138 u_short vsync_total; /* Lines/field */
139 u_short borderstart_h;
140 u_short borderstop_h;
141 u_short borderstart_v;
142 u_short borderstop_v;
143 u_short diwstart_h; /* Horizontal offset of the display field */
144 u_short diwstart_v; /* Vertical offset of the display field, for
145 interlaced modes, this is the long field */
146 u_long disp_start; /* Address of image within VRAM */
148 u_long next_line; /* Modulo for next line */
150 u_char is_interlaced; /* Is the display interlaced? */
151 u_char is_doublescan; /* Are scanlines output twice? (doublescan) */
152 u_char is_lowres; /* Is horizontal pixel-doubling enabled? */
154 u_long bordercolor; /* RGB888 format border color */
160 static int currcon = 0;
162 static struct display disp;
163 static struct fb_info fb_info;
164 static int pvr2fb_inverse = 0;
166 static struct { u_short red, green, blue, alpha; } palette[256];
168 #ifdef FBCON_HAS_CFB16
171 #ifdef FBCON_HAS_CFB24
174 #ifdef FBCON_HAS_CFB32
179 static char pvr2fb_name[16] = "NEC PowerVR2";
181 #define VIDEOMEMSIZE (8*1024*1024)
182 static u_long videomemory = 0xa5000000, videomemorysize = VIDEOMEMSIZE;
183 static int cable_type = -1;
184 static int video_output = -1;
187 static int enable_mtrr = 1;
188 static int mtrr_handle;
192 * We do all updating, blanking, etc. during the vertical retrace period
195 static u_short do_vmode_full = 0; /* Change the video mode */
196 static u_short do_vmode_pan = 0; /* Update the video mode */
197 static short do_blank = 0; /* (Un)Blank the screen */
199 static u_short is_blanked = 0; /* Is the screen blanked? */
201 /* Interface used by the world */
203 int pvr2fb_setup(char*);
205 static int pvr2fb_get_fix(struct fb_fix_screeninfo *fix, int con,
206 struct fb_info *info);
207 static int pvr2fb_get_var(struct fb_var_screeninfo *var, int con,
208 struct fb_info *info);
209 static int pvr2fb_set_var(struct fb_var_screeninfo *var, int con,
210 struct fb_info *info);
211 static int pvr2fb_pan_display(struct fb_var_screeninfo *var, int con,
212 struct fb_info *info);
213 static int pvr2fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
214 struct fb_info *info);
215 static int pvr2fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
216 struct fb_info *info);
219 * Interface to the low level console driver
222 static int pvr2fbcon_switch(int con, struct fb_info *info);
223 static int pvr2fbcon_updatevar(int con, struct fb_info *info);
224 static void pvr2fbcon_blank(int blank, struct fb_info *info);
227 * Internal/hardware-specific routines
230 static void do_install_cmap(int con, struct fb_info *info);
231 static u_long get_line_length(int xres_virtual, int bpp);
232 static void set_color_bitfields(struct fb_var_screeninfo *var);
233 static int pvr2_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
234 u_int *transp, struct fb_info *info);
235 static int pvr2_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
236 u_int transp, struct fb_info *info);
238 static int pvr2_encode_fix(struct fb_fix_screeninfo *fix,
239 struct pvr2fb_par *par);
240 static int pvr2_decode_var(struct fb_var_screeninfo *var,
241 struct pvr2fb_par *par);
242 static int pvr2_encode_var(struct fb_var_screeninfo *var,
243 struct pvr2fb_par *par);
244 static void pvr2_get_par(struct pvr2fb_par *par);
245 static void pvr2_set_var(struct fb_var_screeninfo *var);
246 static void pvr2_pan_var(struct fb_var_screeninfo *var);
247 static int pvr2_update_par(void);
248 static void pvr2_update_display(void);
249 static void pvr2_init_display(void);
250 static void pvr2_do_blank(void);
251 static void pvr2fb_interrupt(int irq, void *dev_id, struct pt_regs *fp);
252 static int pvr2_init_cable(void);
253 static int pvr2_get_param(const struct pvr2_params *p, const char *s,
256 static struct fb_ops pvr2fb_ops = {
258 fb_get_fix: pvr2fb_get_fix,
259 fb_get_var: pvr2fb_get_var,
260 fb_set_var: pvr2fb_set_var,
261 fb_get_cmap: pvr2fb_get_cmap,
262 fb_set_cmap: pvr2fb_set_cmap,
263 fb_pan_display: pvr2fb_pan_display,
266 static struct fb_videomode pvr2_modedb[] __initdata = {
269 * Broadcast video modes (PAL and NTSC). I'm unfamiliar with
270 * PAL-M and PAL-N, but from what I've read both modes parallel PAL and
271 * NTSC, so it shouldn't be a problem (I hope).
275 /* 640x480 @ 60Hz interlaced (NTSC) */
276 "ntsc_640x480i", 60, 640, 480, TV_CLK, 38, 33, 0, 18, 146, 26,
277 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED | FB_VMODE_YWRAP
281 /* 640x240 @ 60Hz (NTSC) */
282 /* XXX: Broken! Don't use... */
283 "ntsc_640x240", 60, 640, 240, TV_CLK, 38, 33, 0, 0, 146, 22,
284 FB_SYNC_BROADCAST, FB_VMODE_YWRAP
288 /* 640x480 @ 60hz (VGA) */
289 "vga_640x480", 60, 640, 480, VGA_CLK, 38, 33, 0, 18, 146, 26,
295 #define NUM_TOTAL_MODES ARRAY_SIZE(pvr2_modedb)
297 #define DEFMODE_NTSC 0
298 #define DEFMODE_PAL 0
299 #define DEFMODE_VGA 2
301 static int defmode = DEFMODE_NTSC;
302 static char *mode_option __initdata = NULL;
304 /* Get the fixed part of the display */
306 static int pvr2fb_get_fix(struct fb_fix_screeninfo *fix, int con,
307 struct fb_info *info)
309 struct pvr2fb_par par;
316 if ((err = pvr2_decode_var(&fb_display[con].var, &par)))
319 return pvr2_encode_fix(fix, &par);
322 /* Get the user-defined part of the display */
324 static int pvr2fb_get_var(struct fb_var_screeninfo *var, int con,
325 struct fb_info *info)
330 struct pvr2fb_par par;
333 err = pvr2_encode_var(var, &par);
335 *var = fb_display[con].var;
340 /* Set the user-defined part of the display */
342 static int pvr2fb_set_var(struct fb_var_screeninfo *var, int con,
343 struct fb_info *info)
345 int err, activate = var->activate;
346 int oldxres, oldyres, oldvxres, oldvyres, oldbpp;
347 struct pvr2fb_par par;
349 struct display *display;
351 display = &fb_display[con];
353 display = &disp; /* used during initialization */
356 * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
357 * as FB_VMODE_SMOOTH_XPAN is only used internally
360 if (var->vmode & FB_VMODE_CONUPDATE) {
361 var->vmode |= FB_VMODE_YWRAP;
362 var->xoffset = display->var.xoffset;
363 var->yoffset = display->var.yoffset;
365 if ((err = pvr2_decode_var(var, &par)))
367 pvr2_encode_var(var, &par);
369 /* Do memory check and bitfield set here?? */
371 if ((activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
372 oldxres = display->var.xres;
373 oldyres = display->var.yres;
374 oldvxres = display->var.xres_virtual;
375 oldvyres = display->var.yres_virtual;
376 oldbpp = display->var.bits_per_pixel;
378 if (oldxres != var->xres || oldyres != var->yres ||
379 oldvxres != var->xres_virtual || oldvyres != var->yres_virtual ||
380 oldbpp != var->bits_per_pixel) {
381 struct fb_fix_screeninfo fix;
383 pvr2_encode_fix(&fix, &par);
384 display->screen_base = (char *)fix.smem_start;
385 display->scrollmode = SCROLL_YREDRAW;
386 display->visual = fix.visual;
387 display->type = fix.type;
388 display->type_aux = fix.type_aux;
389 display->ypanstep = fix.ypanstep;
390 display->ywrapstep = fix.ywrapstep;
391 display->line_length = fix.line_length;
392 display->can_soft_blank = 1;
393 display->inverse = pvr2fb_inverse;
394 switch (var->bits_per_pixel) {
395 #ifdef FBCON_HAS_CFB16
397 display->dispsw = &fbcon_cfb16;
398 display->dispsw_data = fbcon_cmap.cfb16;
401 #ifdef FBCON_HAS_CFB24
403 display->dispsw = &fbcon_cfb24;
404 display->dispsw_data = fbcon_cmap.cfb24;
407 #ifdef FBCON_HAS_CFB32
409 display->dispsw = &fbcon_cfb32;
410 display->dispsw_data = fbcon_cmap.cfb32;
414 display->dispsw = &fbcon_dummy;
417 if (fb_info.changevar)
418 (*fb_info.changevar)(con);
420 if (oldbpp != var->bits_per_pixel) {
421 if ((err = fb_alloc_cmap(&display->cmap, 0, 0)))
423 do_install_cmap(con, info);
426 pvr2_set_var(&display->var);
433 * Pan or wrap the display.
434 * This call looks only at xoffset, yoffset and the FB_VMODE_YRAP flag
437 static int pvr2fb_pan_display(struct fb_var_screeninfo *var, int con,
438 struct fb_info *info)
440 if (var->vmode & FB_VMODE_YWRAP) {
441 if (var->yoffset<0 || var->yoffset >=
442 fb_display[con].var.yres_virtual || var->xoffset)
445 if (var->xoffset+fb_display[con].var.xres >
446 fb_display[con].var.xres_virtual ||
447 var->yoffset+fb_display[con].var.yres >
448 fb_display[con].var.yres_virtual)
453 fb_display[con].var.xoffset = var->xoffset;
454 fb_display[con].var.yoffset = var->yoffset;
455 if (var->vmode & FB_VMODE_YWRAP)
456 fb_display[con].var.vmode |= FB_VMODE_YWRAP;
458 fb_display[con].var.vmode &= ~FB_VMODE_YWRAP;
463 /* Get the colormap */
465 static int pvr2fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
466 struct fb_info *info)
468 if (con == currcon) /* current console? */
469 return fb_get_cmap(cmap, kspc, pvr2_getcolreg, info);
470 else if (fb_display[con].cmap.len) /* non default colormap? */
471 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
473 fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
478 /* Set the colormap */
480 static int pvr2fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
481 struct fb_info *info)
485 if (!fb_display[con].cmap.len) { /* no colormap allocated? */
486 if ((err = fb_alloc_cmap(&fb_display[con].cmap,
487 1<<fb_display[con].var.bits_per_pixel,
491 if (con == currcon) /* current console? */
492 return fb_set_cmap(cmap, kspc, pvr2_setcolreg, info);
494 fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1);
499 static int pvr2fbcon_switch(int con, struct fb_info *info)
501 /* Do we have to save the colormap? */
502 if (fb_display[currcon].cmap.len)
503 fb_get_cmap(&fb_display[currcon].cmap, 1, pvr2_getcolreg, info);
506 pvr2_set_var(&fb_display[con].var);
507 /* Install new colormap */
508 do_install_cmap(con, info);
512 static int pvr2fbcon_updatevar(int con, struct fb_info *info)
514 pvr2_pan_var(&fb_display[con].var);
518 static void pvr2fbcon_blank(int blank, struct fb_info *info)
520 do_blank = blank ? blank : -1;
523 /* Setup the colormap */
525 static void do_install_cmap(int con, struct fb_info *info)
529 if (fb_display[con].cmap.len)
530 fb_set_cmap(&fb_display[con].cmap, 1, pvr2_setcolreg, info);
532 fb_set_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
533 1, pvr2_setcolreg, info);
536 static inline u_long get_line_length(int xres_virtual, int bpp)
538 return (u_long)((((xres_virtual*bpp)+31)&~31) >> 3);
541 static void set_color_bitfields(struct fb_var_screeninfo *var)
543 switch (var->bits_per_pixel) {
544 case 16: /* RGB 565 */
545 var->red.offset = 11; var->red.length = 5;
546 var->green.offset = 5; var->green.length = 6;
547 var->blue.offset = 0; var->blue.length = 5;
548 var->transp.offset = 0; var->transp.length = 0;
550 case 24: /* RGB 888 */
551 var->red.offset = 16; var->red.length = 8;
552 var->green.offset = 8; var->green.length = 8;
553 var->blue.offset = 0; var->blue.length = 8;
554 var->transp.offset = 0; var->transp.length = 0;
556 case 32: /* ARGB 8888 */
557 var->red.offset = 16; var->red.length = 8;
558 var->green.offset = 8; var->green.length = 8;
559 var->blue.offset = 0; var->blue.length = 8;
560 var->transp.offset = 24; var->transp.length = 8;
565 static int pvr2_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
566 u_int *transp, struct fb_info *info)
571 *red = palette[regno].red;
572 *green = palette[regno].green;
573 *blue = palette[regno].blue;
578 static int pvr2_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
579 u_int transp, struct fb_info *info)
584 palette[regno].red = red;
585 palette[regno].green = green;
586 palette[regno].blue = blue;
590 #ifdef FBCON_HAS_CFB16
591 case 16: /* RGB 565 */
592 fbcon_cmap.cfb16[regno] = (red & 0xf800) |
593 ((green & 0xfc00) >> 5) |
594 ((blue & 0xf800) >> 11);
597 #ifdef FBCON_HAS_CFB24
598 case 24: /* RGB 888 */
599 red >>= 8; green >>= 8; blue >>= 8;
600 fbcon_cmap.cfb24[regno] = (red << 16) | (green << 8) | blue;
603 #ifdef FBCON_HAS_CFB32
604 case 32: /* ARGB 8888 */
605 red >>= 8; green >>= 8; blue >>= 8;
606 fbcon_cmap.cfb32[regno] = (red << 16) | (green << 8) | blue;
610 DPRINTK("Invalid bit depth %d?!?\n", currbpp);
619 static int pvr2_encode_fix(struct fb_fix_screeninfo *fix,
620 struct pvr2fb_par *par)
622 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
623 strcpy(fix->id, pvr2fb_name);
624 fix->smem_start = videomemory;
625 fix->smem_len = videomemorysize;
626 fix->type = FB_TYPE_PACKED_PIXELS;
628 fix->visual = FB_VISUAL_TRUECOLOR;
630 if (par->vmode & FB_VMODE_YWRAP) {
632 fix->xpanstep = fix->ypanstep = 0;
638 fix->line_length = par->next_line;
644 * Create a hardware video mode using the framebuffer values. If a value needs
645 * to be clipped or constrained it's done here. This routine needs a bit more
646 * work to make sure we're doing the right tests at the right time.
648 static int pvr2_decode_var(struct fb_var_screeninfo *var,
649 struct pvr2fb_par *par)
654 if (var->pixclock != TV_CLK && var->pixclock != VGA_CLK) {
655 DPRINTK("Invalid pixclock value %d\n", var->pixclock);
658 par->pixclock = var->pixclock;
660 if ((par->xres = var->xres) < 320)
662 if ((par->yres = var->yres) < 240)
664 if ((par->vxres = var->xres_virtual) < par->xres)
665 par->vxres = par->xres;
666 if ((par->vyres = var->yres_virtual) < par->yres)
667 par->vyres = par->yres;
669 if ((par->bpp = var->bits_per_pixel) <= 16)
671 else if ((par->bpp = var->bits_per_pixel) <= 24)
673 else if ((par->bpp = var->bits_per_pixel) <= 32)
679 * XXX: It's possible that a user could use a VGA box, change the cable
680 * type in hardware (i.e. switch from VGA<->composite), then change modes
681 * (i.e. switching to another VT). If that happens we should automagically
682 * change the output format to cope, but currently I don't have a VGA box
683 * to make sure this works properly.
685 cable_type = pvr2_init_cable();
686 if (cable_type == CT_VGA && video_output != VO_VGA)
687 video_output = VO_VGA;
689 par->vmode = var->vmode & FB_VMODE_MASK;
690 if (par->vmode & FB_VMODE_INTERLACED && video_output != VO_VGA)
691 par->is_interlaced = 1;
693 * XXX: Need to be more creative with this (i.e. allow doublecan for
696 par->is_doublescan = (par->yres < 480 && video_output == VO_VGA);
698 par->hsync_total = var->left_margin + var->xres + var->right_margin +
700 par->vsync_total = var->upper_margin + var->yres + var->lower_margin +
703 if (var->sync & FB_SYNC_BROADCAST) {
704 vtotal = par->vsync_total;
705 if (par->is_interlaced)
707 if (vtotal > (PAL_VTOTAL + NTSC_VTOTAL)/2) {
708 /* PAL video output */
709 /* XXX: Should be using a range here ... ? */
710 if (par->hsync_total != PAL_HTOTAL) {
711 DPRINTK("invalid hsync total for PAL\n");
714 /* XXX: Check for start values here... */
715 /* XXX: Check hardware for PAL-compatibility */
716 par->borderstart_h = 116;
717 par->borderstart_v = 44;
719 /* NTSC video output */
720 if (par->hsync_total != NTSC_HTOTAL) {
721 DPRINTK("invalid hsync total for NTSC\n");
724 par->borderstart_h = 126;
725 par->borderstart_v = 18;
729 /* XXX: What else needs to be checked? */
731 * XXX: We have a little freedom in VGA modes, what ranges should
732 * be here (i.e. hsync/vsync totals, etc.)?
734 par->borderstart_h = 126;
735 par->borderstart_v = 40;
738 /* Calculate the remainding offsets */
739 par->borderstop_h = par->borderstart_h + par->hsync_total -
741 par->borderstop_v = par->borderstart_v + par->vsync_total -
743 par->diwstart_h = par->borderstart_h + var->left_margin;
744 par->diwstart_v = par->borderstart_v + var->upper_margin;
745 if (!par->is_interlaced)
746 par->borderstop_v /= 2;
751 /* XXX: Needs testing. */
752 if (!((par->vmode ^ var->vmode) & FB_VMODE_YWRAP)) {
753 par->xoffset = var->xoffset;
754 par->yoffset = var->yoffset;
755 if (par->vmode & FB_VMODE_YWRAP) {
756 if (par->xoffset || par->yoffset < 0 || par->yoffset >=
758 par->xoffset = par->yoffset = 0;
760 if (par->xoffset < 0 || par->xoffset > par->vxres-par->xres ||
761 par->yoffset < 0 || par->yoffset > par->vyres-par->yres)
762 par->xoffset = par->yoffset = 0;
765 par->xoffset = par->yoffset = 0;
767 /* Check memory sizes */
768 line_length = get_line_length(var->xres_virtual, var->bits_per_pixel);
769 if (line_length * var->yres_virtual > videomemorysize)
771 par->disp_start = videomemory + (get_line_length(par->vxres, par->bpp) *
772 par->yoffset) * get_line_length(par->xoffset, par->bpp);
773 par->next_line = line_length;
778 static int pvr2_encode_var(struct fb_var_screeninfo *var,
779 struct pvr2fb_par *par)
781 memset(var, 0, sizeof(struct fb_var_screeninfo));
783 var->xres = par->xres;
784 var->yres = par->yres;
785 var->xres_virtual = par->vxres;
786 var->yres_virtual = par->vyres;
787 var->xoffset = par->xoffset;
788 var->yoffset = par->yoffset;
790 var->bits_per_pixel = par->bpp;
791 set_color_bitfields(var);
793 var->activate = FB_ACTIVATE_NOW;
797 var->pixclock = par->pixclock;
799 if (par->is_doublescan)
800 var->vmode = FB_VMODE_DOUBLE;
802 if (par->is_interlaced)
803 var->vmode |= FB_VMODE_INTERLACED;
805 var->vmode |= FB_VMODE_NONINTERLACED;
807 var->right_margin = par->borderstop_h - (par->diwstart_h + par->xres);
808 var->left_margin = par->diwstart_h - par->borderstart_h;
809 var->hsync_len = par->borderstart_h + (par->hsync_total - par->borderstop_h);
810 var->upper_margin = par->diwstart_v - par->borderstart_v;
811 var->lower_margin = par->borderstop_v - (par->diwstart_v + par->yres);
812 var->vsync_len = par->borderstart_v + (par->vsync_total - par->borderstop_v);
813 if (video_output != VO_VGA)
814 var->sync = FB_SYNC_BROADCAST;
816 if (par->vmode & FB_VMODE_YWRAP)
817 var->vmode |= FB_VMODE_YWRAP;
822 static void pvr2_get_par(struct pvr2fb_par *par)
827 /* Setup the new videomode in hardware */
829 static void pvr2_set_var(struct fb_var_screeninfo *var)
833 pvr2_decode_var(var, ¤tpar);
839 * Pan or wrap the display
840 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag in `var'.
842 static void pvr2_pan_var(struct fb_var_screeninfo *var)
844 struct pvr2fb_par *par = ¤tpar;
846 par->xoffset = var->xoffset;
847 par->yoffset = var->yoffset;
848 if (var->vmode & FB_VMODE_YWRAP)
849 par->vmode |= FB_VMODE_YWRAP;
851 par->vmode &= ~FB_VMODE_YWRAP;
858 static int pvr2_update_par(void)
860 struct pvr2fb_par *par = ¤tpar;
863 move = get_line_length(par->xoffset, par->bpp);
865 par->disp_start += (par->next_line * par->yoffset) + move;
867 par->disp_start += move;
872 static void pvr2_update_display(void)
874 struct pvr2fb_par *par = ¤tpar;
876 /* Update the start address of the display image */
877 ctrl_outl(par->disp_start, DISP_DIWADDRL);
878 ctrl_outl(par->disp_start +
879 get_line_length(par->xoffset + par->xres, par->bpp),
884 * Initialize the video mode. Currently, the 16bpp and 24bpp modes aren't
885 * very stable. It's probably due to the fact that a lot of the 2D video
886 * registers are still undocumented.
889 static void pvr2_init_display(void)
891 struct pvr2fb_par *par = ¤tpar;
892 u_short diw_height, diw_width, diw_modulo = 1;
893 u_short bytesperpixel = par->bpp / 8;
895 /* hsync and vsync totals */
896 ctrl_outl((par->vsync_total << 16) | par->hsync_total, DISP_SYNCSIZE);
898 /* column height, modulo, row width */
899 /* since we're "panning" within vram, we need to offset things based
900 * on the offset from the virtual x start to our real gfx. */
901 if (video_output != VO_VGA && par->is_interlaced)
902 diw_modulo += par->next_line / 4;
903 diw_height = (par->is_interlaced ? par->yres / 2 : par->yres);
904 diw_width = get_line_length(par->xres, par->bpp) / 4;
905 ctrl_outl((diw_modulo << 20) | (--diw_height << 10) | --diw_width,
908 /* display address, long and short fields */
909 ctrl_outl(par->disp_start, DISP_DIWADDRL);
910 ctrl_outl(par->disp_start +
911 get_line_length(par->xoffset + par->xres, par->bpp),
914 /* border horizontal, border vertical, border color */
915 ctrl_outl((par->borderstart_h << 16) | par->borderstop_h, DISP_BRDRHORZ);
916 ctrl_outl((par->borderstart_v << 16) | par->borderstop_v, DISP_BRDRVERT);
917 ctrl_outl(0, DISP_BRDRCOLR);
919 /* display window start position */
920 ctrl_outl(par->diwstart_h, DISP_DIWHSTRT);
921 ctrl_outl((par->diwstart_v << 16) | par->diwstart_v, DISP_DIWVSTRT);
924 ctrl_outl((0x16 << 16) | par->is_lowres, DISP_DIWCONF);
926 /* clock doubler (for VGA), scan doubler, display enable */
927 ctrl_outl(((video_output == VO_VGA) << 23) |
928 (par->is_doublescan << 1) | 1, DISP_DIWMODE);
931 ctrl_outl(ctrl_inl(DISP_DIWMODE) | (--bytesperpixel << 2), DISP_DIWMODE);
933 /* video enable, color sync, interlace,
934 * hsync and vsync polarity (currently unused) */
935 ctrl_outl(0x100 | ((par->is_interlaced /*|4*/) << 4), DISP_SYNCCONF);
939 /* Simulate blanking by making the border cover the entire screen */
941 #define BLANK_BIT (1<<3)
943 static void pvr2_do_blank(void)
947 diwconf = ctrl_inl(DISP_DIWCONF);
949 ctrl_outl(diwconf | BLANK_BIT, DISP_DIWCONF);
951 ctrl_outl(diwconf & ~BLANK_BIT, DISP_DIWCONF);
953 is_blanked = do_blank > 0 ? do_blank : 0;
956 static void pvr2fb_interrupt(int irq, void *dev_id, struct pt_regs *fp)
958 if (do_vmode_pan || do_vmode_full)
959 pvr2_update_display();
978 * Determine the cable type and initialize the cable output format. Don't do
979 * anything if the cable type has been overidden (via "cable:XX").
982 #define PCTRA 0xff80002c
983 #define PDTRA 0xff800030
984 #define VOUTC 0xa0702c00
986 static int pvr2_init_cable(void)
988 if (cable_type < 0) {
989 ctrl_outl((ctrl_inl(PCTRA) & 0xfff0ffff) | 0x000a0000,
991 cable_type = (ctrl_inw(PDTRA) >> 8) & 3;
994 /* Now select the output format (either composite or other) */
995 /* XXX: Save the previous val first, as this reg is also AICA
997 if (cable_type == CT_COMPOSITE)
998 ctrl_outl(3 << 8, VOUTC);
1000 ctrl_outl(0, VOUTC);
1005 int __init pvr2fb_init(void)
1007 struct fb_var_screeninfo var;
1010 if (!MACH_DREAMCAST)
1013 /* Make a guess at the monitor based on the attached cable */
1014 if (pvr2_init_cable() == CT_VGA) {
1015 fb_info.monspecs.hfmin = 30000;
1016 fb_info.monspecs.hfmax = 70000;
1017 fb_info.monspecs.vfmin = 60;
1018 fb_info.monspecs.vfmax = 60;
1020 else { /* Not VGA, using a TV (taken from acornfb) */
1021 fb_info.monspecs.hfmin = 15469;
1022 fb_info.monspecs.hfmax = 15781;
1023 fb_info.monspecs.vfmin = 49;
1024 fb_info.monspecs.vfmax = 51;
1027 /* XXX: This needs to pull default video output via BIOS or other means */
1028 if (video_output < 0) {
1029 if (cable_type == CT_VGA)
1030 video_output = VO_VGA;
1032 video_output = VO_NTSC;
1035 strcpy(fb_info.modename, pvr2fb_name);
1036 fb_info.changevar = NULL;
1038 fb_info.fbops = &pvr2fb_ops;
1039 fb_info.disp = &disp;
1040 fb_info.switch_con = &pvr2fbcon_switch;
1041 fb_info.updatevar = &pvr2fbcon_updatevar;
1042 fb_info.blank = &pvr2fbcon_blank;
1043 fb_info.flags = FBINFO_FLAG_DEFAULT;
1044 memset(&var, 0, sizeof(var));
1046 if (video_output == VO_VGA)
1047 defmode = DEFMODE_VGA;
1049 if (!fb_find_mode(&var, &fb_info, mode_option, pvr2_modedb,
1050 NUM_TOTAL_MODES, &pvr2_modedb[defmode], 16)) {
1054 if (request_irq(HW_EVENT_VSYNC, pvr2fb_interrupt, 0,
1055 "pvr2 VBL handler", ¤tpar)) {
1056 DPRINTK("couldn't register VBL int\n");
1062 mtrr_handle = mtrr_add(videomemory, videomemorysize, MTRR_TYPE_WRCOMB, 1);
1063 printk("pvr2fb: MTRR turned on\n");
1067 pvr2fb_set_var(&var, -1, &fb_info);
1069 if (register_framebuffer(&fb_info) < 0)
1072 modememused = get_line_length(var.xres_virtual, var.bits_per_pixel);
1073 modememused *= var.yres_virtual;
1074 printk("fb%d: %s frame buffer device, using %ldk/%ldk of video memory\n",
1075 GET_FB_IDX(fb_info.node), fb_info.modename, modememused>>10,
1076 videomemorysize>>10);
1077 printk("fb%d: Mode %dx%d-%d pitch = %ld cable: %s video output: %s\n",
1078 GET_FB_IDX(fb_info.node), var.xres, var.yres, var.bits_per_pixel,
1079 get_line_length(var.xres, var.bits_per_pixel),
1080 (char *)pvr2_get_param(cables, NULL, cable_type, 3),
1081 (char *)pvr2_get_param(outputs, NULL, video_output, 3));
1086 static void __exit pvr2fb_exit(void)
1090 mtrr_del(mtrr_handle, videomemory, videomemorysize);
1091 printk("pvr2fb: MTRR turned off\n");
1094 unregister_framebuffer(&fb_info);
1097 static int __init pvr2_get_param(const struct pvr2_params *p, const char *s,
1102 for (i = 0 ; i < size ; i++ ) {
1104 if (!strnicmp(p[i].name, s, strlen(s)))
1107 if (p[i].val == val)
1108 return (int)p[i].name;
1115 * Parse command arguments. Supported arguments are:
1116 * inverse Use inverse color maps
1117 * nomtrr Disable MTRR usage
1118 * font:<fontname> Specify console font
1119 * cable:composite|rgb|vga Override the video cable type
1120 * output:NTSC|PAL|VGA Override the video output format
1122 * <xres>x<yres>[-<bpp>][@<refresh>] or,
1123 * <name>[-<bpp>][@<refresh>] Startup using this video mode
1127 int __init pvr2fb_setup(char *options)
1131 char output_arg[80];
1133 fb_info.fontname[0] = '\0';
1135 if (!options || !*options)
1138 while ((this_opt = strsep(&options, ","))) {
1141 if (!strcmp(this_opt, "inverse")) {
1144 } else if (!strncmp(this_opt, "font:", 5))
1145 strcpy(fb_info.fontname, this_opt + 5);
1146 else if (!strncmp(this_opt, "cable:", 6))
1147 strcpy(cable_arg, this_opt + 6);
1148 else if (!strncmp(this_opt, "output:", 7))
1149 strcpy(output_arg, this_opt + 7);
1151 else if (!strncmp(this_opt, "nomtrr", 6))
1155 mode_option = this_opt;
1159 cable_type = pvr2_get_param(cables, cable_arg, 0, 3);
1162 video_output = pvr2_get_param(outputs, output_arg, 0, 3);
1169 MODULE_LICENSE("GPL");
1170 module_init(pvr2fb_init);
1172 module_exit(pvr2fb_exit);