2 * linux/drivers/video/sgivwfb.c -- SGI DBE frame buffer device
4 * Copyright (C) 1999 Silicon Graphics, Inc.
5 * Jeffrey Newquist, newquist@engr.sgi.som
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/errno.h>
16 #include <linux/string.h>
18 #include <linux/tty.h>
19 #include <linux/slab.h>
20 #include <linux/vmalloc.h>
21 #include <linux/delay.h>
22 #include <linux/interrupt.h>
23 #include <asm/uaccess.h>
25 #include <linux/init.h>
29 #include <video/fbcon.h>
30 #include <video/fbcon-cfb8.h>
31 #include <video/fbcon-cfb16.h>
32 #include <video/fbcon-cfb32.h>
34 #define INCLUDE_TIMING_TABLE_DATA
35 #define DBE_REG_BASE regs
39 struct fb_var_screeninfo var;
45 * RAM we reserve for the frame buffer. This defines the maximum screen
48 * The default can be overridden if the driver is compiled as a module
51 /* set by arch/i386/kernel/setup.c */
52 u_long sgivwfb_mem_phys;
53 u_long sgivwfb_mem_size;
55 static volatile char *fbmem;
57 static struct fb_info fb_info;
58 static struct { u_char red, green, blue, pad; } palette[256];
59 static char sgivwfb_name[16] = "SGI Vis WS FB";
64 /* console related variables */
65 static int currcon = 0;
66 static struct display disp;
69 #ifdef FBCON_HAS_CFB16
72 #ifdef FBCON_HAS_CFB32
77 static struct sgivwfb_par par_current = {
78 { /* var (screeninfo) */
80 640, 480, 640, 480, 0, 0, 8, 0,
81 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
82 0, 0, -1, -1, 0, 20000, 64, 64, 32, 32, 64, 2,
83 0, FB_VMODE_NONINTERLACED
86 0 /* par not activated */
90 * Interface used by the world
92 int sgivwfb_setup(char*);
94 static int sgivwfb_get_fix(struct fb_fix_screeninfo *fix, int con,
95 struct fb_info *info);
96 static int sgivwfb_get_var(struct fb_var_screeninfo *var, int con,
97 struct fb_info *info);
98 static int sgivwfb_set_var(struct fb_var_screeninfo *var, int con,
99 struct fb_info *info);
100 static int sgivwfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
101 struct fb_info *info);
102 static int sgivwfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
103 struct fb_info *info);
104 static int sgivwfb_mmap(struct fb_info *info, struct file *file,
105 struct vm_area_struct *vma);
107 static struct fb_ops sgivwfb_ops = {
109 fb_get_fix: sgivwfb_get_fix,
110 fb_get_var: sgivwfb_get_var,
111 fb_set_var: sgivwfb_set_var,
112 fb_get_cmap: sgivwfb_get_cmap,
113 fb_set_cmap: sgivwfb_set_cmap,
114 fb_mmap: sgivwfb_mmap,
118 * Interface to the low level console driver
120 int sgivwfb_init(void);
121 static int sgivwfbcon_switch(int con, struct fb_info *info);
122 static int sgivwfbcon_updatevar(int con, struct fb_info *info);
123 static void sgivwfbcon_blank(int blank, struct fb_info *info);
128 static u_long get_line_length(int xres_virtual, int bpp);
129 static unsigned long bytes_per_pixel(int bpp);
130 static void activate_par(struct sgivwfb_par *par);
131 static void sgivwfb_encode_fix(struct fb_fix_screeninfo *fix,
132 struct fb_var_screeninfo *var);
133 static int sgivwfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
134 u_int *transp, struct fb_info *info);
135 static int sgivwfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
136 u_int transp, struct fb_info *info);
137 static void do_install_cmap(int con, struct fb_info *info);
139 static unsigned long get_line_length(int xres_virtual, int bpp)
141 return(xres_virtual * bytes_per_pixel(bpp));
144 static unsigned long bytes_per_pixel(int bpp)
146 unsigned long length;
159 printk(KERN_INFO "sgivwfb: unsupported bpp=%d\n", bpp);
167 * Function: dbe_TurnOffDma
169 * Description: This should turn off the monitor and dbe. This is used
170 * when switching between the serial console and the graphics
174 static void dbe_TurnOffDma(void)
177 unsigned int readVal;
179 // Check to see if things are already turned off:
180 // 1) Check to see if dbe is not using the internal dotclock.
181 // 2) Check to see if the xy counter in dbe is already off.
183 DBE_GETREG(ctrlstat, readVal);
184 if (GET_DBE_FIELD(CTRLSTAT, PCLKSEL, readVal) < 2)
187 DBE_GETREG(vt_xy, readVal);
188 if (GET_DBE_FIELD(VT_XY, VT_FREEZE, readVal) == 1)
191 // Otherwise, turn off dbe
193 DBE_GETREG(ovr_control, readVal);
194 SET_DBE_FIELD(OVR_CONTROL, OVR_DMA_ENABLE, readVal, 0);
195 DBE_SETREG(ovr_control, readVal);
197 DBE_GETREG(frm_control, readVal);
198 SET_DBE_FIELD(FRM_CONTROL, FRM_DMA_ENABLE, readVal, 0);
199 DBE_SETREG(frm_control, readVal);
201 DBE_GETREG(did_control, readVal);
202 SET_DBE_FIELD(DID_CONTROL, DID_DMA_ENABLE, readVal, 0);
203 DBE_SETREG(did_control, readVal);
208 // This was necessary for GBE--we had to wait through two
209 // vertical retrace periods before the pixel DMA was
210 // turned off for sure. I've left this in for now, in
211 // case dbe needs it.
213 for (i = 0; i < 10000; i++)
215 DBE_GETREG(frm_inhwctrl, readVal);
216 if (GET_DBE_FIELD(FRM_INHWCTRL, FRM_DMA_ENABLE, readVal) == 0)
220 DBE_GETREG(ovr_inhwctrl, readVal);
221 if (GET_DBE_FIELD(OVR_INHWCTRL, OVR_DMA_ENABLE, readVal) == 0)
225 DBE_GETREG(did_inhwctrl, readVal);
226 if (GET_DBE_FIELD(DID_INHWCTRL, DID_DMA_ENABLE, readVal) == 0)
236 * Set the hardware according to 'par'.
238 static void activate_par(struct sgivwfb_par *par)
241 u32 readVal, outputVal;
242 int wholeTilesX, maxPixelsPerTileX;
243 int frmWrite1, frmWrite2, frmWrite3b;
244 dbe_timing_info_t *currentTiming; /* Current Video Timing */
245 int xpmax, ypmax; // Monitor resolution
246 int bytesPerPixel; // Bytes per pixel
248 currentTiming = &dbeVTimings[par->timing_num];
249 bytesPerPixel = bytes_per_pixel(par->var.bits_per_pixel);
250 xpmax = currentTiming->width;
251 ypmax = currentTiming->height;
253 /* dbe_InitGraphicsBase(); */
254 /* Turn on dotclock PLL */
255 DBE_SETREG(ctrlstat, 0x20000000);
259 /* dbe_CalculateScreenParams(); */
260 maxPixelsPerTileX = 512/bytesPerPixel;
261 wholeTilesX = xpmax/maxPixelsPerTileX;
262 if (wholeTilesX*maxPixelsPerTileX < xpmax)
265 printk(KERN_DEBUG "sgivwfb: pixPerTile=%d wholeTilesX=%d\n",
266 maxPixelsPerTileX, wholeTilesX);
268 /* dbe_InitGammaMap(); */
271 for (i = 0; i < 256; i++)
273 DBE_ISETREG(gmap, i, (i << 24) | (i << 16) | (i << 8));
277 DBE_GETREG(vt_xy, readVal);
278 if (GET_DBE_FIELD(VT_XY, VT_FREEZE, readVal) == 1)
280 DBE_SETREG(vt_xy, 0x00000000);
287 for (i = 0; i < 256; i++)
289 for (j = 0; j < 100; j++)
291 DBE_GETREG(cm_fifo, readVal);
292 if (readVal != 0x00000000)
298 // DBE_ISETREG(cmap, i, 0x00000000);
299 DBE_ISETREG(cmap, i, (i<<8)|(i<<16)|(i<<24));
302 /* dbe_InitFramebuffer(); */
304 SET_DBE_FIELD(FRM_SIZE_TILE, FRM_WIDTH_TILE, frmWrite1, wholeTilesX);
305 SET_DBE_FIELD(FRM_SIZE_TILE, FRM_RHS, frmWrite1, 0);
307 switch(bytesPerPixel)
310 SET_DBE_FIELD(FRM_SIZE_TILE, FRM_DEPTH, frmWrite1, DBE_FRM_DEPTH_8);
313 SET_DBE_FIELD(FRM_SIZE_TILE, FRM_DEPTH, frmWrite1, DBE_FRM_DEPTH_16);
316 SET_DBE_FIELD(FRM_SIZE_TILE, FRM_DEPTH, frmWrite1, DBE_FRM_DEPTH_32);
321 SET_DBE_FIELD(FRM_SIZE_PIXEL, FB_HEIGHT_PIX, frmWrite2, ypmax);
323 // Tell dbe about the framebuffer location and type
324 // XXX What format is the FRM_TILE_PTR?? 64K aligned address?
326 SET_DBE_FIELD(FRM_CONTROL, FRM_TILE_PTR, frmWrite3b, sgivwfb_mem_phys>>9);
327 SET_DBE_FIELD(FRM_CONTROL, FRM_DMA_ENABLE, frmWrite3b, 1);
328 SET_DBE_FIELD(FRM_CONTROL, FRM_LINEAR, frmWrite3b, 1);
330 /* Initialize DIDs */
333 switch(bytesPerPixel)
336 SET_DBE_FIELD(WID, TYP, outputVal, DBE_CMODE_I8);
339 SET_DBE_FIELD(WID, TYP, outputVal, DBE_CMODE_RGBA5);
342 SET_DBE_FIELD(WID, TYP, outputVal, DBE_CMODE_RGB8);
345 SET_DBE_FIELD(WID, BUF, outputVal, DBE_BMODE_BOTH);
347 for (i = 0; i < 32; i++)
349 DBE_ISETREG(mode_regs, i, outputVal);
352 /* dbe_InitTiming(); */
353 DBE_SETREG(vt_intr01, 0xffffffff);
354 DBE_SETREG(vt_intr23, 0xffffffff);
356 DBE_GETREG(dotclock, readVal);
357 DBE_SETREG(dotclock, readVal & 0xffff);
359 DBE_SETREG(vt_xymax, 0x00000000);
361 SET_DBE_FIELD(VT_VSYNC, VT_VSYNC_ON, outputVal, currentTiming->vsync_start);
362 SET_DBE_FIELD(VT_VSYNC, VT_VSYNC_OFF, outputVal, currentTiming->vsync_end);
363 DBE_SETREG(vt_vsync, outputVal);
365 SET_DBE_FIELD(VT_HSYNC, VT_HSYNC_ON, outputVal, currentTiming->hsync_start);
366 SET_DBE_FIELD(VT_HSYNC, VT_HSYNC_OFF, outputVal, currentTiming->hsync_end);
367 DBE_SETREG(vt_hsync, outputVal);
369 SET_DBE_FIELD(VT_VBLANK, VT_VBLANK_ON, outputVal, currentTiming->vblank_start);
370 SET_DBE_FIELD(VT_VBLANK, VT_VBLANK_OFF, outputVal, currentTiming->vblank_end);
371 DBE_SETREG(vt_vblank, outputVal);
373 SET_DBE_FIELD(VT_HBLANK, VT_HBLANK_ON, outputVal, currentTiming->hblank_start);
374 SET_DBE_FIELD(VT_HBLANK, VT_HBLANK_OFF, outputVal, currentTiming->hblank_end-3);
375 DBE_SETREG(vt_hblank, outputVal);
377 SET_DBE_FIELD(VT_VCMAP, VT_VCMAP_ON, outputVal, currentTiming->vblank_start);
378 SET_DBE_FIELD(VT_VCMAP, VT_VCMAP_OFF, outputVal, currentTiming->vblank_end);
379 DBE_SETREG(vt_vcmap, outputVal);
381 SET_DBE_FIELD(VT_HCMAP, VT_HCMAP_ON, outputVal, currentTiming->hblank_start);
382 SET_DBE_FIELD(VT_HCMAP, VT_HCMAP_OFF, outputVal, currentTiming->hblank_end-3);
383 DBE_SETREG(vt_hcmap, outputVal);
386 temp = currentTiming->vblank_start - currentTiming->vblank_end - 1;
390 SET_DBE_FIELD(DID_START_XY, DID_STARTY, outputVal, (u32)temp);
391 if (currentTiming->hblank_end >= 20)
392 SET_DBE_FIELD(DID_START_XY, DID_STARTX, outputVal,
393 currentTiming->hblank_end - 20);
395 SET_DBE_FIELD(DID_START_XY, DID_STARTX, outputVal,
396 currentTiming->htotal - (20 - currentTiming->hblank_end));
397 DBE_SETREG(did_start_xy, outputVal);
400 SET_DBE_FIELD(CRS_START_XY, CRS_STARTY, outputVal, (u32)(temp+1));
401 if (currentTiming->hblank_end >= DBE_CRS_MAGIC)
402 SET_DBE_FIELD(CRS_START_XY, CRS_STARTX, outputVal,
403 currentTiming->hblank_end - DBE_CRS_MAGIC);
405 SET_DBE_FIELD(CRS_START_XY, CRS_STARTX, outputVal,
406 currentTiming->htotal - (DBE_CRS_MAGIC - currentTiming->hblank_end));
407 DBE_SETREG(crs_start_xy, outputVal);
410 SET_DBE_FIELD(VC_START_XY, VC_STARTY, outputVal, (u32)temp);
411 SET_DBE_FIELD(VC_START_XY, VC_STARTX, outputVal,
412 currentTiming->hblank_end - 4);
413 DBE_SETREG(vc_start_xy, outputVal);
415 DBE_SETREG(frm_size_tile, frmWrite1);
416 DBE_SETREG(frm_size_pixel, frmWrite2);
419 SET_DBE_FIELD(DOTCLK, M, outputVal, currentTiming->pll_m-1);
420 SET_DBE_FIELD(DOTCLK, N, outputVal, currentTiming->pll_n-1);
421 SET_DBE_FIELD(DOTCLK, P, outputVal, currentTiming->pll_p);
422 SET_DBE_FIELD(DOTCLK, RUN, outputVal, 1);
423 DBE_SETREG(dotclock, outputVal);
427 DBE_SETREG(vt_vpixen, 0xffffff);
428 DBE_SETREG(vt_hpixen, 0xffffff);
431 SET_DBE_FIELD(VT_XYMAX, VT_MAXX, outputVal, currentTiming->htotal);
432 SET_DBE_FIELD(VT_XYMAX, VT_MAXY, outputVal, currentTiming->vtotal);
433 DBE_SETREG(vt_xymax, outputVal);
435 outputVal = frmWrite1;
436 SET_DBE_FIELD(FRM_SIZE_TILE, FRM_FIFO_RESET, outputVal, 1);
437 DBE_SETREG(frm_size_tile, outputVal);
438 DBE_SETREG(frm_size_tile, frmWrite1);
441 SET_DBE_FIELD(OVR_WIDTH_TILE, OVR_FIFO_RESET, outputVal, 1);
442 DBE_SETREG(ovr_width_tile, outputVal);
443 DBE_SETREG(ovr_width_tile, 0);
445 DBE_SETREG(frm_control, frmWrite3b);
446 DBE_SETREG(did_control, 0);
448 // Wait for dbe to take frame settings
449 for (i=0; i<100000; i++)
451 DBE_GETREG(frm_inhwctrl, readVal);
452 if (GET_DBE_FIELD(FRM_INHWCTRL, FRM_DMA_ENABLE, readVal) != 0)
459 printk(KERN_INFO "sgivwfb: timeout waiting for frame DMA enable.\n");
462 htmp = currentTiming->hblank_end - 19;
464 htmp += currentTiming->htotal; /* allow blank to wrap around */
465 SET_DBE_FIELD(VT_HPIXEN, VT_HPIXEN_ON, outputVal, htmp);
466 SET_DBE_FIELD(VT_HPIXEN, VT_HPIXEN_OFF, outputVal,
467 ((htmp + currentTiming->width - 2) % currentTiming->htotal));
468 DBE_SETREG(vt_hpixen, outputVal);
471 SET_DBE_FIELD(VT_VPIXEN, VT_VPIXEN_OFF, outputVal,
472 currentTiming->vblank_start);
473 SET_DBE_FIELD(VT_VPIXEN, VT_VPIXEN_ON, outputVal,
474 currentTiming->vblank_end);
475 DBE_SETREG(vt_vpixen, outputVal);
477 // Turn off mouse cursor
480 // XXX What's this section for??
481 DBE_GETREG(ctrlstat, readVal);
482 readVal &= 0x02000000;
486 DBE_SETREG(ctrlstat, 0x30000000);
490 static void sgivwfb_encode_fix(struct fb_fix_screeninfo *fix,
491 struct fb_var_screeninfo *var)
493 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
494 strcpy(fix->id, sgivwfb_name);
495 fix->smem_start = sgivwfb_mem_phys;
496 fix->smem_len = sgivwfb_mem_size;
497 fix->type = FB_TYPE_PACKED_PIXELS;
499 switch (var->bits_per_pixel) {
501 fix->visual = FB_VISUAL_PSEUDOCOLOR;
504 fix->visual = FB_VISUAL_TRUECOLOR;
507 fix->ywrapstep = ywrap;
509 fix->ypanstep = ypan;
510 fix->line_length = get_line_length(var->xres_virtual, var->bits_per_pixel);
511 fix->mmio_start = DBE_REG_PHYS;
512 fix->mmio_len = DBE_REG_SIZE;
516 * Read a single color register and split it into
517 * colors/transparent. Return != 0 for invalid regno.
519 static int sgivwfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
520 u_int *transp, struct fb_info *info)
525 *red = palette[regno].red << 8;
526 *green = palette[regno].green << 8;
527 *blue = palette[regno].blue << 8;
533 * Set a single color register. The values supplied are already
534 * rounded down to the hardware's capabilities (according to the
535 * entries in the var structure). Return != 0 for invalid regno.
538 static int sgivwfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
539 u_int transp, struct fb_info *info)
546 palette[regno].red = red;
547 palette[regno].green = green;
548 palette[regno].blue = blue;
550 /* wait for the color map FIFO to have a free entry */
551 while (cmap_fifo == 0)
552 cmap_fifo = regs->cm_fifo;
554 regs->cmap[regno] = (red << 24) | (green << 16) | (blue << 8);
555 cmap_fifo--; /* assume FIFO is filling up */
559 static void do_install_cmap(int con, struct fb_info *info)
563 if (fb_display[con].cmap.len)
564 fb_set_cmap(&fb_display[con].cmap, 1, sgivwfb_setcolreg, info);
566 fb_set_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel), 1,
567 sgivwfb_setcolreg, info);
570 /* ---------------------------------------------------- */
573 * Get the Fixed Part of the Display
575 static int sgivwfb_get_fix(struct fb_fix_screeninfo *fix, int con,
576 struct fb_info *info)
578 struct fb_var_screeninfo *var;
581 var = &par_current.var;
583 var = &fb_display[con].var;
584 sgivwfb_encode_fix(fix, var);
589 * Get the User Defined Part of the Display. If a real par get it form there
591 static int sgivwfb_get_var(struct fb_var_screeninfo *var, int con,
592 struct fb_info *info)
595 *var = par_current.var;
597 *var = fb_display[con].var;
602 * Set the User Defined Part of the Display. Again if par use it to get
605 static int sgivwfb_set_var(struct fb_var_screeninfo *var, int con,
606 struct fb_info *info)
608 int err, activate = var->activate;
609 int oldxres, oldyres, oldvxres, oldvyres, oldbpp;
615 struct dbe_timing_info *timing;
617 struct display *display;
620 display = &fb_display[con];
622 display = &disp; /* used during initialization */
625 * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
626 * as FB_VMODE_SMOOTH_XPAN is only used internally
629 if (var->vmode & FB_VMODE_CONUPDATE) {
630 var->vmode |= FB_VMODE_YWRAP;
631 var->xoffset = display->var.xoffset;
632 var->yoffset = display->var.yoffset;
635 /* XXX FIXME - forcing var's */
639 /* Limit bpp to 8, 16, and 32 */
640 if (var->bits_per_pixel <= 8)
641 var->bits_per_pixel = 8;
642 else if (var->bits_per_pixel <= 16)
643 var->bits_per_pixel = 16;
644 else if (var->bits_per_pixel <= 32)
645 var->bits_per_pixel = 32;
649 var->grayscale = 0; /* No grayscale for now */
651 /* determine valid resolution and timing */
652 for (min_mode=0; min_mode<DBE_VT_SIZE; min_mode++) {
653 if (dbeVTimings[min_mode].width >= var->xres &&
654 dbeVTimings[min_mode].height >= var->yres)
658 if (min_mode == DBE_VT_SIZE)
659 return -EINVAL; /* Resolution to high */
661 /* XXX FIXME - should try to pick best refresh rate */
662 /* for now, pick closest dot-clock within 3MHz*/
663 #error "Floating point not allowed in kernel"
664 req_dot = (int)((1.0e3/1.0e6) / (1.0e-12 * (float)var->pixclock));
665 printk(KERN_INFO "sgivwfb: requested pixclock=%d ps (%d KHz)\n", var->pixclock,
668 while (dbeVTimings[min_mode].width == dbeVTimings[test_mode].width) {
669 if (dbeVTimings[test_mode].cfreq+3000 > req_dot)
673 if (dbeVTimings[min_mode].width != dbeVTimings[test_mode].width)
675 min_mode = test_mode;
676 timing = &dbeVTimings[min_mode];
677 printk(KERN_INFO "sgivwfb: granted dot-clock=%d KHz\n", timing->cfreq);
679 /* Adjust virtual resolution, if necessary */
680 if (var->xres > var->xres_virtual || (!ywrap && !ypan))
681 var->xres_virtual = var->xres;
682 if (var->yres > var->yres_virtual || (!ywrap && !ypan))
683 var->yres_virtual = var->yres;
688 line_length = get_line_length(var->xres_virtual, var->bits_per_pixel);
689 if (line_length*var->yres_virtual > sgivwfb_mem_size)
690 return -ENOMEM; /* Virtual resolution to high */
692 switch (var->bits_per_pixel)
697 var->green.offset = 0;
698 var->green.length = 8;
699 var->blue.offset = 0;
700 var->blue.length = 8;
701 var->transp.offset = 0;
702 var->transp.length = 0;
704 case 16: /* RGBA 5551 */
705 var->red.offset = 11;
707 var->green.offset = 6;
708 var->green.length = 5;
709 var->blue.offset = 1;
710 var->blue.length = 5;
711 var->transp.offset = 0;
712 var->transp.length = 0;
714 case 32: /* RGB 8888 */
717 var->green.offset = 8;
718 var->green.length = 8;
719 var->blue.offset = 16;
720 var->blue.length = 8;
721 var->transp.offset = 24;
722 var->transp.length = 8;
725 var->red.msb_right = 0;
726 var->green.msb_right = 0;
727 var->blue.msb_right = 0;
728 var->transp.msb_right = 0;
730 /* set video timing information */
731 var->pixclock = (__u32)(1.0e+9/(float)timing->cfreq);
732 var->left_margin = timing->htotal - timing->hsync_end;
733 var->right_margin = timing->hsync_start - timing->width;
734 var->upper_margin = timing->vtotal - timing->vsync_end;
735 var->lower_margin = timing->vsync_start - timing->height;
736 var->hsync_len = timing->hsync_end - timing->hsync_start;
737 var->vsync_len = timing->vsync_end - timing->vsync_start;
739 if ((activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
740 oldxres = display->var.xres;
741 oldyres = display->var.yres;
742 oldvxres = display->var.xres_virtual;
743 oldvyres = display->var.yres_virtual;
744 oldbpp = display->var.bits_per_pixel;
746 par_current.var = *var;
747 par_current.timing_num = min_mode;
748 if (oldxres != var->xres || oldyres != var->yres ||
749 oldvxres != var->xres_virtual || oldvyres != var->yres_virtual ||
750 oldbpp != var->bits_per_pixel || !par_current.valid) {
751 struct fb_fix_screeninfo fix;
752 printk(KERN_INFO "sgivwfb: new video mode xres=%d yres=%d bpp=%d\n",
753 var->xres, var->yres, var->bits_per_pixel);
754 printk(KERN_INFO " vxres=%d vyres=%d\n",
755 var->xres_virtual, var->yres_virtual);
756 activate_par(&par_current);
757 sgivwfb_encode_fix(&fix, var);
758 display->screen_base = (char *)fbmem;
759 display->visual = fix.visual;
760 display->type = fix.type;
761 display->type_aux = fix.type_aux;
762 display->ypanstep = fix.ypanstep;
763 display->ywrapstep = fix.ywrapstep;
764 display->line_length = fix.line_length;
765 display->can_soft_blank = 1;
766 display->inverse = 0;
767 if (oldbpp != var->bits_per_pixel || !par_current.valid) {
768 if ((err = fb_alloc_cmap(&display->cmap, 0, 0)))
770 do_install_cmap(con, info);
772 switch (var->bits_per_pixel) {
773 #ifdef FBCON_HAS_CFB8
775 display->dispsw = &fbcon_cfb8;
778 #ifdef FBCON_HAS_CFB16
780 display->dispsw = &fbcon_cfb16;
781 display->dispsw_data = fbcon_cmap.cfb16;
784 #ifdef FBCON_HAS_CFB32
786 display->dispsw = &fbcon_cfb32;
787 display->dispsw_data = fbcon_cmap.cfb32;
791 display->dispsw = &fbcon_dummy;
794 par_current.valid = 1;
795 if (fb_info.changevar)
796 (*fb_info.changevar)(con);
805 static int sgivwfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
806 struct fb_info *info)
808 if (con == currcon) /* current console? */
809 return fb_get_cmap(cmap, kspc, sgivwfb_getcolreg, info);
810 else if (fb_display[con].cmap.len) /* non default colormap? */
811 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
813 fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
821 static int sgivwfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
822 struct fb_info *info)
826 if (!fb_display[con].cmap.len) { /* no colormap allocated? */
827 int size = fb_display[con].var.bits_per_pixel == 16 ? 32 : 256;
828 if ((err = fb_alloc_cmap(&fb_display[con].cmap, size, 0)))
831 if (con == currcon) /* current console? */
832 return fb_set_cmap(cmap, kspc, sgivwfb_setcolreg, info);
834 fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1);
838 static int sgivwfb_mmap(struct fb_info *info, struct file *file,
839 struct vm_area_struct *vma)
841 unsigned long size = vma->vm_end - vma->vm_start;
842 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
843 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
845 if (offset+size > sgivwfb_mem_size)
847 offset += sgivwfb_mem_phys;
848 pgprot_val(vma->vm_page_prot) = pgprot_val(vma->vm_page_prot) | _PAGE_PCD;
849 if (remap_page_range(vma->vm_start, offset, size, vma->vm_page_prot))
852 printk(KERN_DEBUG "sgivwfb: mmap framebuffer P(%lx)->V(%lx)\n", offset, vma->vm_start);
856 int __init sgivwfb_setup(char *options)
860 fb_info.fontname[0] = '\0';
862 if (!options || !*options)
865 while ((this_opt = strsep(&options, ",")) != NULL) {
866 if (!strncmp(this_opt, "font:", 5))
867 strcpy(fb_info.fontname, this_opt+5);
875 int __init sgivwfb_init(void)
877 printk(KERN_INFO "sgivwfb: framebuffer at 0x%lx, size %ldk\n",
878 sgivwfb_mem_phys, sgivwfb_mem_size/1024);
880 regs = (asregs*)ioremap_nocache(DBE_REG_PHYS, DBE_REG_SIZE);
882 printk(KERN_ERR "sgivwfb: couldn't ioremap registers\n");
883 goto fail_ioremap_regs;
887 mtrr_add((unsigned long)sgivwfb_mem_phys, sgivwfb_mem_size, MTRR_TYPE_WRCOMB, 1);
890 strcpy(fb_info.modename, sgivwfb_name);
891 fb_info.changevar = NULL;
893 fb_info.fbops = &sgivwfb_ops;
894 fb_info.disp = &disp;
895 fb_info.switch_con = &sgivwfbcon_switch;
896 fb_info.updatevar = &sgivwfbcon_updatevar;
897 fb_info.blank = &sgivwfbcon_blank;
898 fb_info.flags = FBINFO_FLAG_DEFAULT;
900 fbmem = ioremap_nocache((unsigned long)sgivwfb_mem_phys, sgivwfb_mem_size);
902 printk(KERN_ERR "sgivwfb: couldn't ioremap fbmem\n");
903 goto fail_ioremap_fbmem;
906 /* turn on default video mode */
907 sgivwfb_set_var(&par_current.var, -1, &fb_info);
909 if (register_framebuffer(&fb_info) < 0) {
910 printk(KERN_ERR "sgivwfb: couldn't register framebuffer\n");
911 goto fail_register_framebuffer;
914 printk(KERN_INFO "fb%d: Virtual frame buffer device, using %ldK of video memory\n",
915 GET_FB_IDX(fb_info.node), sgivwfb_mem_size>>10);
919 fail_register_framebuffer:
920 iounmap((char*)fbmem);
927 static int sgivwfbcon_switch(int con, struct fb_info *info)
929 /* Do we have to save the colormap? */
930 if (fb_display[currcon].cmap.len)
931 fb_get_cmap(&fb_display[currcon].cmap, 1, sgivwfb_getcolreg, info);
934 /* Install new colormap */
935 do_install_cmap(con, info);
940 * Update the `var' structure (called by fbcon.c)
942 static int sgivwfbcon_updatevar(int con, struct fb_info *info)
951 static void sgivwfbcon_blank(int blank, struct fb_info *info)
957 MODULE_LICENSE("GPL");
959 int init_module(void)
961 return sgivwfb_init();
964 void cleanup_module(void)
966 unregister_framebuffer(&fb_info);