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/module.h>
13 #include <linux/kernel.h>
15 #include <linux/errno.h>
16 #include <linux/delay.h>
18 #include <linux/init.h>
19 #include <linux/ioport.h>
20 #include <linux/platform_device.h>
25 #include <setup_arch.h>
27 #define INCLUDE_TIMING_TABLE_DATA
28 #define DBE_REG_BASE par->regs
29 #include <video/sgivw.h>
37 #define FLATPANEL_SGI_1600SW 5
40 * RAM we reserve for the frame buffer. This defines the maximum screen
43 * The default can be overridden if the driver is compiled as a module
49 static int flatpanel_id
= -1;
51 static struct fb_fix_screeninfo sgivwfb_fix __initdata
= {
52 .id
= "SGI Vis WS FB",
53 .type
= FB_TYPE_PACKED_PIXELS
,
54 .visual
= FB_VISUAL_PSEUDOCOLOR
,
55 .mmio_start
= DBE_REG_PHYS
,
56 .mmio_len
= DBE_REG_SIZE
,
57 .accel
= FB_ACCEL_NONE
,
61 static struct fb_var_screeninfo sgivwfb_var __initdata
= {
80 .vmode
= FB_VMODE_NONINTERLACED
83 static struct fb_var_screeninfo sgivwfb_var1600sw __initdata
= {
84 /* 1600x1024, 8 bpp */
102 .vmode
= FB_VMODE_NONINTERLACED
106 * Interface used by the world
108 int sgivwfb_init(void);
110 static int sgivwfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
);
111 static int sgivwfb_set_par(struct fb_info
*info
);
112 static int sgivwfb_setcolreg(u_int regno
, u_int red
, u_int green
,
113 u_int blue
, u_int transp
,
114 struct fb_info
*info
);
115 static int sgivwfb_mmap(struct fb_info
*info
,
116 struct vm_area_struct
*vma
);
118 static struct fb_ops sgivwfb_ops
= {
119 .owner
= THIS_MODULE
,
120 .fb_check_var
= sgivwfb_check_var
,
121 .fb_set_par
= sgivwfb_set_par
,
122 .fb_setcolreg
= sgivwfb_setcolreg
,
123 .fb_fillrect
= cfb_fillrect
,
124 .fb_copyarea
= cfb_copyarea
,
125 .fb_imageblit
= cfb_imageblit
,
126 .fb_mmap
= sgivwfb_mmap
,
132 static unsigned long bytes_per_pixel(int bpp
)
142 printk(KERN_INFO
"sgivwfb: unsupported bpp %d\n", bpp
);
147 static unsigned long get_line_length(int xres_virtual
, int bpp
)
149 return (xres_virtual
* bytes_per_pixel(bpp
));
153 * Function: dbe_TurnOffDma
155 * Description: This should turn off the monitor and dbe. This is used
156 * when switching between the serial console and the graphics
160 static void dbe_TurnOffDma(struct sgivw_par
*par
)
162 unsigned int readVal
;
165 // Check to see if things are already turned off:
166 // 1) Check to see if dbe is not using the internal dotclock.
167 // 2) Check to see if the xy counter in dbe is already off.
169 DBE_GETREG(ctrlstat
, readVal
);
170 if (GET_DBE_FIELD(CTRLSTAT
, PCLKSEL
, readVal
) < 2)
173 DBE_GETREG(vt_xy
, readVal
);
174 if (GET_DBE_FIELD(VT_XY
, VT_FREEZE
, readVal
) == 1)
177 // Otherwise, turn off dbe
179 DBE_GETREG(ovr_control
, readVal
);
180 SET_DBE_FIELD(OVR_CONTROL
, OVR_DMA_ENABLE
, readVal
, 0);
181 DBE_SETREG(ovr_control
, readVal
);
183 DBE_GETREG(frm_control
, readVal
);
184 SET_DBE_FIELD(FRM_CONTROL
, FRM_DMA_ENABLE
, readVal
, 0);
185 DBE_SETREG(frm_control
, readVal
);
187 DBE_GETREG(did_control
, readVal
);
188 SET_DBE_FIELD(DID_CONTROL
, DID_DMA_ENABLE
, readVal
, 0);
189 DBE_SETREG(did_control
, readVal
);
194 // This was necessary for GBE--we had to wait through two
195 // vertical retrace periods before the pixel DMA was
196 // turned off for sure. I've left this in for now, in
197 // case dbe needs it.
199 for (i
= 0; i
< 10000; i
++) {
200 DBE_GETREG(frm_inhwctrl
, readVal
);
201 if (GET_DBE_FIELD(FRM_INHWCTRL
, FRM_DMA_ENABLE
, readVal
) ==
205 DBE_GETREG(ovr_inhwctrl
, readVal
);
207 (OVR_INHWCTRL
, OVR_DMA_ENABLE
, readVal
) == 0)
210 DBE_GETREG(did_inhwctrl
, readVal
);
212 (DID_INHWCTRL
, DID_DMA_ENABLE
,
223 * Set the User Defined Part of the Display. Again if par use it to get
226 static int sgivwfb_check_var(struct fb_var_screeninfo
*var
,
227 struct fb_info
*info
)
229 struct sgivw_par
*par
= (struct sgivw_par
*)info
->par
;
230 struct dbe_timing_info
*timing
;
237 * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
238 * as FB_VMODE_SMOOTH_XPAN is only used internally
241 if (var
->vmode
& FB_VMODE_CONUPDATE
) {
242 var
->vmode
|= FB_VMODE_YWRAP
;
243 var
->xoffset
= info
->var
.xoffset
;
244 var
->yoffset
= info
->var
.yoffset
;
247 /* XXX FIXME - forcing var's */
251 /* Limit bpp to 8, 16, and 32 */
252 if (var
->bits_per_pixel
<= 8)
253 var
->bits_per_pixel
= 8;
254 else if (var
->bits_per_pixel
<= 16)
255 var
->bits_per_pixel
= 16;
256 else if (var
->bits_per_pixel
<= 32)
257 var
->bits_per_pixel
= 32;
261 var
->grayscale
= 0; /* No grayscale for now */
263 /* determine valid resolution and timing */
264 for (min_mode
= 0; min_mode
< DBE_VT_SIZE
; min_mode
++) {
265 if (dbeVTimings
[min_mode
].width
>= var
->xres
&&
266 dbeVTimings
[min_mode
].height
>= var
->yres
)
270 if (min_mode
== DBE_VT_SIZE
)
271 return -EINVAL
; /* Resolution to high */
273 /* XXX FIXME - should try to pick best refresh rate */
274 /* for now, pick closest dot-clock within 3MHz */
275 req_dot
= PICOS2KHZ(var
->pixclock
);
276 printk(KERN_INFO
"sgivwfb: requested pixclock=%d ps (%d KHz)\n",
277 var
->pixclock
, req_dot
);
278 test_mode
= min_mode
;
279 while (dbeVTimings
[min_mode
].width
== dbeVTimings
[test_mode
].width
) {
280 if (dbeVTimings
[test_mode
].cfreq
+ 3000 > req_dot
)
284 if (dbeVTimings
[min_mode
].width
!= dbeVTimings
[test_mode
].width
)
286 min_mode
= test_mode
;
287 timing
= &dbeVTimings
[min_mode
];
288 printk(KERN_INFO
"sgivwfb: granted dot-clock=%d KHz\n", timing
->cfreq
);
290 /* Adjust virtual resolution, if necessary */
291 if (var
->xres
> var
->xres_virtual
|| (!ywrap
&& !ypan
))
292 var
->xres_virtual
= var
->xres
;
293 if (var
->yres
> var
->yres_virtual
|| (!ywrap
&& !ypan
))
294 var
->yres_virtual
= var
->yres
;
299 line_length
= get_line_length(var
->xres_virtual
, var
->bits_per_pixel
);
300 if (line_length
* var
->yres_virtual
> sgivwfb_mem_size
)
301 return -ENOMEM
; /* Virtual resolution to high */
303 info
->fix
.line_length
= line_length
;
305 switch (var
->bits_per_pixel
) {
309 var
->green
.offset
= 0;
310 var
->green
.length
= 8;
311 var
->blue
.offset
= 0;
312 var
->blue
.length
= 8;
313 var
->transp
.offset
= 0;
314 var
->transp
.length
= 0;
316 case 16: /* RGBA 5551 */
317 var
->red
.offset
= 11;
319 var
->green
.offset
= 6;
320 var
->green
.length
= 5;
321 var
->blue
.offset
= 1;
322 var
->blue
.length
= 5;
323 var
->transp
.offset
= 0;
324 var
->transp
.length
= 0;
326 case 32: /* RGB 8888 */
329 var
->green
.offset
= 8;
330 var
->green
.length
= 8;
331 var
->blue
.offset
= 16;
332 var
->blue
.length
= 8;
333 var
->transp
.offset
= 24;
334 var
->transp
.length
= 8;
337 var
->red
.msb_right
= 0;
338 var
->green
.msb_right
= 0;
339 var
->blue
.msb_right
= 0;
340 var
->transp
.msb_right
= 0;
342 /* set video timing information */
343 var
->pixclock
= KHZ2PICOS(timing
->cfreq
);
344 var
->left_margin
= timing
->htotal
- timing
->hsync_end
;
345 var
->right_margin
= timing
->hsync_start
- timing
->width
;
346 var
->upper_margin
= timing
->vtotal
- timing
->vsync_end
;
347 var
->lower_margin
= timing
->vsync_start
- timing
->height
;
348 var
->hsync_len
= timing
->hsync_end
- timing
->hsync_start
;
349 var
->vsync_len
= timing
->vsync_end
- timing
->vsync_start
;
351 /* Ouch. This breaks the rules but timing_num is only important if you
352 * change a video mode */
353 par
->timing_num
= min_mode
;
355 printk(KERN_INFO
"sgivwfb: new video mode xres=%d yres=%d bpp=%d\n",
356 var
->xres
, var
->yres
, var
->bits_per_pixel
);
357 printk(KERN_INFO
" vxres=%d vyres=%d\n", var
->xres_virtual
,
363 * Setup flatpanel related registers.
365 static void sgivwfb_setup_flatpanel(struct sgivw_par
*par
, struct dbe_timing_info
*currentTiming
)
367 int fp_wid
, fp_hgt
, fp_vbs
, fp_vbe
;
370 SET_DBE_FIELD(VT_FLAGS
, HDRV_INVERT
, outputVal
,
371 (currentTiming
->flags
& FB_SYNC_HOR_HIGH_ACT
) ? 0 : 1);
372 SET_DBE_FIELD(VT_FLAGS
, VDRV_INVERT
, outputVal
,
373 (currentTiming
->flags
& FB_SYNC_VERT_HIGH_ACT
) ? 0 : 1);
374 DBE_SETREG(vt_flags
, outputVal
);
376 /* Turn on the flat panel */
377 switch (flatpanel_id
) {
378 case FLATPANEL_SGI_1600SW
:
383 currentTiming
->pll_m
= 4;
384 currentTiming
->pll_n
= 1;
385 currentTiming
->pll_p
= 0;
388 fp_wid
= fp_hgt
= fp_vbs
= fp_vbe
= 0xfff;
392 SET_DBE_FIELD(FP_DE
, FP_DE_ON
, outputVal
, fp_vbs
);
393 SET_DBE_FIELD(FP_DE
, FP_DE_OFF
, outputVal
, fp_vbe
);
394 DBE_SETREG(fp_de
, outputVal
);
396 SET_DBE_FIELD(FP_HDRV
, FP_HDRV_OFF
, outputVal
, fp_wid
);
397 DBE_SETREG(fp_hdrv
, outputVal
);
399 SET_DBE_FIELD(FP_VDRV
, FP_VDRV_ON
, outputVal
, 1);
400 SET_DBE_FIELD(FP_VDRV
, FP_VDRV_OFF
, outputVal
, fp_hgt
+ 1);
401 DBE_SETREG(fp_vdrv
, outputVal
);
405 * Set the hardware according to 'par'.
407 static int sgivwfb_set_par(struct fb_info
*info
)
409 struct sgivw_par
*par
= info
->par
;
410 int i
, j
, htmp
, temp
;
411 u32 readVal
, outputVal
;
412 int wholeTilesX
, maxPixelsPerTileX
;
413 int frmWrite1
, frmWrite2
, frmWrite3b
;
414 struct dbe_timing_info
*currentTiming
; /* Current Video Timing */
415 int xpmax
, ypmax
; // Monitor resolution
416 int bytesPerPixel
; // Bytes per pixel
418 currentTiming
= &dbeVTimings
[par
->timing_num
];
419 bytesPerPixel
= bytes_per_pixel(info
->var
.bits_per_pixel
);
420 xpmax
= currentTiming
->width
;
421 ypmax
= currentTiming
->height
;
423 /* dbe_InitGraphicsBase(); */
424 /* Turn on dotclock PLL */
425 DBE_SETREG(ctrlstat
, 0x20000000);
429 /* dbe_CalculateScreenParams(); */
430 maxPixelsPerTileX
= 512 / bytesPerPixel
;
431 wholeTilesX
= xpmax
/ maxPixelsPerTileX
;
432 if (wholeTilesX
* maxPixelsPerTileX
< xpmax
)
435 printk(KERN_DEBUG
"sgivwfb: pixPerTile=%d wholeTilesX=%d\n",
436 maxPixelsPerTileX
, wholeTilesX
);
438 /* dbe_InitGammaMap(); */
441 for (i
= 0; i
< 256; i
++) {
442 DBE_ISETREG(gmap
, i
, (i
<< 24) | (i
<< 16) | (i
<< 8));
446 DBE_GETREG(vt_xy
, readVal
);
447 if (GET_DBE_FIELD(VT_XY
, VT_FREEZE
, readVal
) == 1) {
448 DBE_SETREG(vt_xy
, 0x00000000);
454 for (i
= 0; i
< 256; i
++) {
455 for (j
= 0; j
< 100; j
++) {
456 DBE_GETREG(cm_fifo
, readVal
);
457 if (readVal
!= 0x00000000)
463 // DBE_ISETREG(cmap, i, 0x00000000);
464 DBE_ISETREG(cmap
, i
, (i
<< 8) | (i
<< 16) | (i
<< 24));
467 /* dbe_InitFramebuffer(); */
469 SET_DBE_FIELD(FRM_SIZE_TILE
, FRM_WIDTH_TILE
, frmWrite1
,
471 SET_DBE_FIELD(FRM_SIZE_TILE
, FRM_RHS
, frmWrite1
, 0);
473 switch (bytesPerPixel
) {
475 SET_DBE_FIELD(FRM_SIZE_TILE
, FRM_DEPTH
, frmWrite1
,
479 SET_DBE_FIELD(FRM_SIZE_TILE
, FRM_DEPTH
, frmWrite1
,
483 SET_DBE_FIELD(FRM_SIZE_TILE
, FRM_DEPTH
, frmWrite1
,
489 SET_DBE_FIELD(FRM_SIZE_PIXEL
, FB_HEIGHT_PIX
, frmWrite2
, ypmax
);
491 // Tell dbe about the framebuffer location and type
492 // XXX What format is the FRM_TILE_PTR?? 64K aligned address?
494 SET_DBE_FIELD(FRM_CONTROL
, FRM_TILE_PTR
, frmWrite3b
,
495 sgivwfb_mem_phys
>> 9);
496 SET_DBE_FIELD(FRM_CONTROL
, FRM_DMA_ENABLE
, frmWrite3b
, 1);
497 SET_DBE_FIELD(FRM_CONTROL
, FRM_LINEAR
, frmWrite3b
, 1);
499 /* Initialize DIDs */
502 switch (bytesPerPixel
) {
504 SET_DBE_FIELD(WID
, TYP
, outputVal
, DBE_CMODE_I8
);
507 SET_DBE_FIELD(WID
, TYP
, outputVal
, DBE_CMODE_RGBA5
);
510 SET_DBE_FIELD(WID
, TYP
, outputVal
, DBE_CMODE_RGB8
);
513 SET_DBE_FIELD(WID
, BUF
, outputVal
, DBE_BMODE_BOTH
);
515 for (i
= 0; i
< 32; i
++) {
516 DBE_ISETREG(mode_regs
, i
, outputVal
);
519 /* dbe_InitTiming(); */
520 DBE_SETREG(vt_intr01
, 0xffffffff);
521 DBE_SETREG(vt_intr23
, 0xffffffff);
523 DBE_GETREG(dotclock
, readVal
);
524 DBE_SETREG(dotclock
, readVal
& 0xffff);
526 DBE_SETREG(vt_xymax
, 0x00000000);
528 SET_DBE_FIELD(VT_VSYNC
, VT_VSYNC_ON
, outputVal
,
529 currentTiming
->vsync_start
);
530 SET_DBE_FIELD(VT_VSYNC
, VT_VSYNC_OFF
, outputVal
,
531 currentTiming
->vsync_end
);
532 DBE_SETREG(vt_vsync
, outputVal
);
534 SET_DBE_FIELD(VT_HSYNC
, VT_HSYNC_ON
, outputVal
,
535 currentTiming
->hsync_start
);
536 SET_DBE_FIELD(VT_HSYNC
, VT_HSYNC_OFF
, outputVal
,
537 currentTiming
->hsync_end
);
538 DBE_SETREG(vt_hsync
, outputVal
);
540 SET_DBE_FIELD(VT_VBLANK
, VT_VBLANK_ON
, outputVal
,
541 currentTiming
->vblank_start
);
542 SET_DBE_FIELD(VT_VBLANK
, VT_VBLANK_OFF
, outputVal
,
543 currentTiming
->vblank_end
);
544 DBE_SETREG(vt_vblank
, outputVal
);
546 SET_DBE_FIELD(VT_HBLANK
, VT_HBLANK_ON
, outputVal
,
547 currentTiming
->hblank_start
);
548 SET_DBE_FIELD(VT_HBLANK
, VT_HBLANK_OFF
, outputVal
,
549 currentTiming
->hblank_end
- 3);
550 DBE_SETREG(vt_hblank
, outputVal
);
552 SET_DBE_FIELD(VT_VCMAP
, VT_VCMAP_ON
, outputVal
,
553 currentTiming
->vblank_start
);
554 SET_DBE_FIELD(VT_VCMAP
, VT_VCMAP_OFF
, outputVal
,
555 currentTiming
->vblank_end
);
556 DBE_SETREG(vt_vcmap
, outputVal
);
558 SET_DBE_FIELD(VT_HCMAP
, VT_HCMAP_ON
, outputVal
,
559 currentTiming
->hblank_start
);
560 SET_DBE_FIELD(VT_HCMAP
, VT_HCMAP_OFF
, outputVal
,
561 currentTiming
->hblank_end
- 3);
562 DBE_SETREG(vt_hcmap
, outputVal
);
564 if (flatpanel_id
!= -1)
565 sgivwfb_setup_flatpanel(par
, currentTiming
);
568 temp
= currentTiming
->vblank_start
- currentTiming
->vblank_end
- 1;
572 SET_DBE_FIELD(DID_START_XY
, DID_STARTY
, outputVal
, (u32
) temp
);
573 if (currentTiming
->hblank_end
>= 20)
574 SET_DBE_FIELD(DID_START_XY
, DID_STARTX
, outputVal
,
575 currentTiming
->hblank_end
- 20);
577 SET_DBE_FIELD(DID_START_XY
, DID_STARTX
, outputVal
,
578 currentTiming
->htotal
- (20 -
581 DBE_SETREG(did_start_xy
, outputVal
);
584 SET_DBE_FIELD(CRS_START_XY
, CRS_STARTY
, outputVal
,
586 if (currentTiming
->hblank_end
>= DBE_CRS_MAGIC
)
587 SET_DBE_FIELD(CRS_START_XY
, CRS_STARTX
, outputVal
,
588 currentTiming
->hblank_end
- DBE_CRS_MAGIC
);
590 SET_DBE_FIELD(CRS_START_XY
, CRS_STARTX
, outputVal
,
591 currentTiming
->htotal
- (DBE_CRS_MAGIC
-
594 DBE_SETREG(crs_start_xy
, outputVal
);
597 SET_DBE_FIELD(VC_START_XY
, VC_STARTY
, outputVal
, (u32
) temp
);
598 SET_DBE_FIELD(VC_START_XY
, VC_STARTX
, outputVal
,
599 currentTiming
->hblank_end
- 4);
600 DBE_SETREG(vc_start_xy
, outputVal
);
602 DBE_SETREG(frm_size_tile
, frmWrite1
);
603 DBE_SETREG(frm_size_pixel
, frmWrite2
);
606 SET_DBE_FIELD(DOTCLK
, M
, outputVal
, currentTiming
->pll_m
- 1);
607 SET_DBE_FIELD(DOTCLK
, N
, outputVal
, currentTiming
->pll_n
- 1);
608 SET_DBE_FIELD(DOTCLK
, P
, outputVal
, currentTiming
->pll_p
);
609 SET_DBE_FIELD(DOTCLK
, RUN
, outputVal
, 1);
610 DBE_SETREG(dotclock
, outputVal
);
614 DBE_SETREG(vt_vpixen
, 0xffffff);
615 DBE_SETREG(vt_hpixen
, 0xffffff);
618 SET_DBE_FIELD(VT_XYMAX
, VT_MAXX
, outputVal
, currentTiming
->htotal
);
619 SET_DBE_FIELD(VT_XYMAX
, VT_MAXY
, outputVal
, currentTiming
->vtotal
);
620 DBE_SETREG(vt_xymax
, outputVal
);
622 outputVal
= frmWrite1
;
623 SET_DBE_FIELD(FRM_SIZE_TILE
, FRM_FIFO_RESET
, outputVal
, 1);
624 DBE_SETREG(frm_size_tile
, outputVal
);
625 DBE_SETREG(frm_size_tile
, frmWrite1
);
628 SET_DBE_FIELD(OVR_WIDTH_TILE
, OVR_FIFO_RESET
, outputVal
, 1);
629 DBE_SETREG(ovr_width_tile
, outputVal
);
630 DBE_SETREG(ovr_width_tile
, 0);
632 DBE_SETREG(frm_control
, frmWrite3b
);
633 DBE_SETREG(did_control
, 0);
635 // Wait for dbe to take frame settings
636 for (i
= 0; i
< 100000; i
++) {
637 DBE_GETREG(frm_inhwctrl
, readVal
);
638 if (GET_DBE_FIELD(FRM_INHWCTRL
, FRM_DMA_ENABLE
, readVal
) !=
647 "sgivwfb: timeout waiting for frame DMA enable.\n");
650 htmp
= currentTiming
->hblank_end
- 19;
652 htmp
+= currentTiming
->htotal
; /* allow blank to wrap around */
653 SET_DBE_FIELD(VT_HPIXEN
, VT_HPIXEN_ON
, outputVal
, htmp
);
654 SET_DBE_FIELD(VT_HPIXEN
, VT_HPIXEN_OFF
, outputVal
,
655 ((htmp
+ currentTiming
->width
-
656 2) % currentTiming
->htotal
));
657 DBE_SETREG(vt_hpixen
, outputVal
);
660 SET_DBE_FIELD(VT_VPIXEN
, VT_VPIXEN_OFF
, outputVal
,
661 currentTiming
->vblank_start
);
662 SET_DBE_FIELD(VT_VPIXEN
, VT_VPIXEN_ON
, outputVal
,
663 currentTiming
->vblank_end
);
664 DBE_SETREG(vt_vpixen
, outputVal
);
666 // Turn off mouse cursor
667 par
->regs
->crs_ctl
= 0;
669 // XXX What's this section for??
670 DBE_GETREG(ctrlstat
, readVal
);
671 readVal
&= 0x02000000;
674 DBE_SETREG(ctrlstat
, 0x30000000);
680 * Set a single color register. The values supplied are already
681 * rounded down to the hardware's capabilities (according to the
682 * entries in the var structure). Return != 0 for invalid regno.
685 static int sgivwfb_setcolreg(u_int regno
, u_int red
, u_int green
,
686 u_int blue
, u_int transp
,
687 struct fb_info
*info
)
689 struct sgivw_par
*par
= (struct sgivw_par
*) info
->par
;
697 /* wait for the color map FIFO to have a free entry */
698 while (par
->cmap_fifo
== 0)
699 par
->cmap_fifo
= par
->regs
->cm_fifo
;
701 par
->regs
->cmap
[regno
] = (red
<< 24) | (green
<< 16) | (blue
<< 8);
702 par
->cmap_fifo
--; /* assume FIFO is filling up */
706 static int sgivwfb_mmap(struct fb_info
*info
,
707 struct vm_area_struct
*vma
)
709 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
710 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
712 if (vma
->vm_pgoff
> (~0UL >> PAGE_SHIFT
))
714 if (offset
+ size
> sgivwfb_mem_size
)
716 offset
+= sgivwfb_mem_phys
;
717 pgprot_val(vma
->vm_page_prot
) =
718 pgprot_val(vma
->vm_page_prot
) | _PAGE_PCD
;
719 vma
->vm_flags
|= VM_IO
;
720 if (remap_pfn_range(vma
, vma
->vm_start
, offset
>> PAGE_SHIFT
,
721 size
, vma
->vm_page_prot
))
723 printk(KERN_DEBUG
"sgivwfb: mmap framebuffer P(%lx)->V(%lx)\n",
724 offset
, vma
->vm_start
);
728 int __init
sgivwfb_setup(char *options
)
732 if (!options
|| !*options
)
735 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
736 if (!strncmp(this_opt
, "monitor:", 8)) {
737 if (!strncmp(this_opt
+ 8, "crt", 3))
739 else if (!strncmp(this_opt
+ 8, "1600sw", 6))
740 flatpanel_id
= FLATPANEL_SGI_1600SW
;
749 static int __init
sgivwfb_probe(struct platform_device
*dev
)
751 struct sgivw_par
*par
;
752 struct fb_info
*info
;
755 info
= framebuffer_alloc(sizeof(struct sgivw_par
) + sizeof(u32
) * 16, &dev
->dev
);
760 if (!request_mem_region(DBE_REG_PHYS
, DBE_REG_SIZE
, "sgivwfb")) {
761 printk(KERN_ERR
"sgivwfb: couldn't reserve mmio region\n");
762 framebuffer_release(info
);
766 par
->regs
= (struct asregs
*) ioremap_nocache(DBE_REG_PHYS
, DBE_REG_SIZE
);
768 printk(KERN_ERR
"sgivwfb: couldn't ioremap registers\n");
769 goto fail_ioremap_regs
;
772 mtrr_add(sgivwfb_mem_phys
, sgivwfb_mem_size
, MTRR_TYPE_WRCOMB
, 1);
774 sgivwfb_fix
.smem_start
= sgivwfb_mem_phys
;
775 sgivwfb_fix
.smem_len
= sgivwfb_mem_size
;
776 sgivwfb_fix
.ywrapstep
= ywrap
;
777 sgivwfb_fix
.ypanstep
= ypan
;
779 info
->fix
= sgivwfb_fix
;
781 switch (flatpanel_id
) {
782 case FLATPANEL_SGI_1600SW
:
783 info
->var
= sgivwfb_var1600sw
;
784 monitor
= "SGI 1600SW flatpanel";
787 info
->var
= sgivwfb_var
;
791 printk(KERN_INFO
"sgivwfb: %s monitor selected\n", monitor
);
793 info
->fbops
= &sgivwfb_ops
;
794 info
->pseudo_palette
= (void *) (par
+ 1);
795 info
->flags
= FBINFO_DEFAULT
;
797 info
->screen_base
= ioremap_nocache((unsigned long) sgivwfb_mem_phys
, sgivwfb_mem_size
);
798 if (!info
->screen_base
) {
799 printk(KERN_ERR
"sgivwfb: couldn't ioremap screen_base\n");
800 goto fail_ioremap_fbmem
;
803 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0)
806 if (register_framebuffer(info
) < 0) {
807 printk(KERN_ERR
"sgivwfb: couldn't register framebuffer\n");
808 goto fail_register_framebuffer
;
811 platform_set_drvdata(dev
, info
);
813 printk(KERN_INFO
"fb%d: SGI DBE frame buffer device, using %ldK of video memory at %#lx\n",
814 info
->node
, sgivwfb_mem_size
>> 10, sgivwfb_mem_phys
);
817 fail_register_framebuffer
:
818 fb_dealloc_cmap(&info
->cmap
);
820 iounmap((char *) info
->screen_base
);
824 release_mem_region(DBE_REG_PHYS
, DBE_REG_SIZE
);
825 framebuffer_release(info
);
829 static int sgivwfb_remove(struct platform_device
*dev
)
831 struct fb_info
*info
= platform_get_drvdata(dev
);
834 struct sgivw_par
*par
= info
->par
;
836 unregister_framebuffer(info
);
839 iounmap(info
->screen_base
);
840 release_mem_region(DBE_REG_PHYS
, DBE_REG_SIZE
);
845 static struct platform_driver sgivwfb_driver
= {
846 .probe
= sgivwfb_probe
,
847 .remove
= sgivwfb_remove
,
853 static struct platform_device
*sgivwfb_device
;
855 int __init
sgivwfb_init(void)
862 if (fb_get_options("sgivwfb", &option
))
864 sgivwfb_setup(option
);
866 ret
= platform_driver_register(&sgivwfb_driver
);
868 sgivwfb_device
= platform_device_alloc("sgivwfb", 0);
869 if (sgivwfb_device
) {
870 ret
= platform_device_add(sgivwfb_device
);
874 platform_driver_unregister(&sgivwfb_driver
);
875 platform_device_put(sgivwfb_device
);
881 module_init(sgivwfb_init
);
884 MODULE_LICENSE("GPL");
886 static void __exit
sgivwfb_exit(void)
888 platform_device_unregister(sgivwfb_device
);
889 platform_driver_unregister(&sgivwfb_driver
);
892 module_exit(sgivwfb_exit
);