2 * linux/drivers/video/neofb.c -- NeoMagic Framebuffer Driver
4 * Copyright (c) 2001-2002 Denis Oliver Kropp <dok@directfb.org>
7 * Card specific code is based on XFree86's neomagic driver.
8 * Framebuffer framework code is based on code of cyber2000fb.
10 * This file is subject to the terms and conditions of the GNU General
11 * Public License. See the file COPYING in the main directory of this
12 * archive for more details.
16 * - Cosmetic changes (dok)
19 * - Toshiba Libretto support, allow modes larger than LCD size if
20 * LCD is disabled, keep BIOS settings if internal/external display
21 * haven't been enabled explicitly
22 * (Thomas J. Moore <dark@mama.indstate.edu>)
25 * - Porting over to new fbdev api. (jsimmons)
28 * - got rid of all floating point (dok)
31 * - added module license (dok)
34 * - hardware accelerated clear and move for 2200 and above (dok)
35 * - maximum allowed dotclock is handled now (dok)
38 * - correct panning after X usage (dok)
39 * - added module and kernel parameters (dok)
40 * - no stretching if external display is enabled (dok)
43 * - initial version (dok)
47 * - ioctl for internal/external switching
49 * - 32bit depth support, maybe impossible
50 * - disable pan-on-sync, need specs
53 * - white margin on bootup like with tdfxfb (colormap problem?)
57 #include <linux/module.h>
58 #include <linux/kernel.h>
59 #include <linux/errno.h>
60 #include <linux/string.h>
62 #include <linux/slab.h>
63 #include <linux/delay.h>
65 #include <linux/pci.h>
66 #include <linux/init.h>
68 #include <linux/toshiba.h>
73 #include <asm/pgtable.h>
74 #include <asm/system.h>
75 #include <asm/uaccess.h>
81 #include <video/vga.h>
82 #include <video/neomagic.h>
84 #define NEOFB_VERSION "0.4.2"
86 /* --------------------------------------------------------------------- */
92 static int nopciburst;
93 static char *mode_option __devinitdata = NULL;
97 MODULE_AUTHOR("(c) 2001-2002 Denis Oliver Kropp <dok@convergence.de>");
98 MODULE_LICENSE("GPL");
99 MODULE_DESCRIPTION("FBDev driver for NeoMagic PCI Chips");
100 module_param(internal, bool, 0);
101 MODULE_PARM_DESC(internal, "Enable output on internal LCD Display.");
102 module_param(external, bool, 0);
103 MODULE_PARM_DESC(external, "Enable output on external CRT.");
104 module_param(libretto, bool, 0);
105 MODULE_PARM_DESC(libretto, "Force Libretto 100/110 800x480 LCD.");
106 module_param(nostretch, bool, 0);
107 MODULE_PARM_DESC(nostretch,
108 "Disable stretching of modes smaller than LCD.");
109 module_param(nopciburst, bool, 0);
110 MODULE_PARM_DESC(nopciburst, "Disable PCI burst mode.");
111 module_param(mode_option, charp, 0);
112 MODULE_PARM_DESC(mode_option, "Preferred video mode ('640x480-8@60', etc)");
117 /* --------------------------------------------------------------------- */
119 static biosMode bios8[] = {
128 static biosMode bios16[] = {
137 static biosMode bios24[] = {
143 #ifdef NO_32BIT_SUPPORT_YET
144 /* FIXME: guessed values, wrong */
145 static biosMode bios32[] = {
152 static inline void write_le32(int regindex, u32 val, const struct neofb_par *par)
154 writel(val, par->neo2200 + par->cursorOff + regindex);
157 static int neoFindMode(int xres, int yres, int depth)
165 size = ARRAY_SIZE(bios8);
169 size = ARRAY_SIZE(bios16);
173 size = ARRAY_SIZE(bios24);
176 #ifdef NO_32BIT_SUPPORT_YET
178 size = ARRAY_SIZE(bios32);
186 for (i = 0; i < size; i++) {
187 if (xres <= mode[i].x_res) {
188 xres_s = mode[i].x_res;
189 for (; i < size; i++) {
190 if (mode[i].x_res != xres_s)
191 return mode[i - 1].mode;
192 if (yres <= mode[i].y_res)
197 return mode[size - 1].mode;
203 * Determine the closest clock frequency to the one requested.
205 #define REF_FREQ 0xe517 /* 14.31818 in 20.12 fixed point */
210 static void neoCalcVCLK(const struct fb_info *info,
211 struct neofb_par *par, long freq)
214 int n_best = 0, d_best = 0, f_best = 0;
215 long f_best_diff = (0x7ffff << 12); /* 20.12 */
216 long f_target = (freq << 12) / 1000; /* 20.12 */
218 for (f = 0; f <= MAX_F; f++)
219 for (n = 0; n <= MAX_N; n++)
220 for (d = 0; d <= MAX_D; d++) {
221 long f_out; /* 20.12 */
222 long f_diff; /* 20.12 */
225 ((((n + 1) << 12) / ((d +
229 f_diff = abs(f_out - f_target);
230 if (f_diff < f_best_diff) {
231 f_best_diff = f_diff;
238 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
239 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
240 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
241 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
242 /* NOT_DONE: We are trying the full range of the 2200 clock.
243 We should be able to try n up to 2047 */
244 par->VCLK3NumeratorLow = n_best;
245 par->VCLK3NumeratorHigh = (f_best << 7);
247 par->VCLK3NumeratorLow = n_best | (f_best << 7);
249 par->VCLK3Denominator = d_best;
252 printk("neoVCLK: f:%d NumLow=%d NumHi=%d Den=%d Df=%d\n",
254 par->VCLK3NumeratorLow,
255 par->VCLK3NumeratorHigh,
256 par->VCLK3Denominator, f_best_diff >> 12);
262 * Handle the initialization, etc. of a screen.
263 * Return FALSE on failure.
266 static int vgaHWInit(const struct fb_var_screeninfo *var,
267 const struct fb_info *info,
268 struct neofb_par *par, struct xtimings *timings)
270 par->MiscOutReg = 0x23;
272 if (!(timings->sync & FB_SYNC_HOR_HIGH_ACT))
273 par->MiscOutReg |= 0x40;
275 if (!(timings->sync & FB_SYNC_VERT_HIGH_ACT))
276 par->MiscOutReg |= 0x80;
281 par->Sequencer[0] = 0x00;
282 par->Sequencer[1] = 0x01;
283 par->Sequencer[2] = 0x0F;
284 par->Sequencer[3] = 0x00; /* Font select */
285 par->Sequencer[4] = 0x0E; /* Misc */
290 par->CRTC[0] = (timings->HTotal >> 3) - 5;
291 par->CRTC[1] = (timings->HDisplay >> 3) - 1;
292 par->CRTC[2] = (timings->HDisplay >> 3) - 1;
293 par->CRTC[3] = (((timings->HTotal >> 3) - 1) & 0x1F) | 0x80;
294 par->CRTC[4] = (timings->HSyncStart >> 3);
295 par->CRTC[5] = ((((timings->HTotal >> 3) - 1) & 0x20) << 2)
296 | (((timings->HSyncEnd >> 3)) & 0x1F);
297 par->CRTC[6] = (timings->VTotal - 2) & 0xFF;
298 par->CRTC[7] = (((timings->VTotal - 2) & 0x100) >> 8)
299 | (((timings->VDisplay - 1) & 0x100) >> 7)
300 | ((timings->VSyncStart & 0x100) >> 6)
301 | (((timings->VDisplay - 1) & 0x100) >> 5)
302 | 0x10 | (((timings->VTotal - 2) & 0x200) >> 4)
303 | (((timings->VDisplay - 1) & 0x200) >> 3)
304 | ((timings->VSyncStart & 0x200) >> 2);
306 par->CRTC[9] = (((timings->VDisplay - 1) & 0x200) >> 4) | 0x40;
308 if (timings->dblscan)
309 par->CRTC[9] |= 0x80;
311 par->CRTC[10] = 0x00;
312 par->CRTC[11] = 0x00;
313 par->CRTC[12] = 0x00;
314 par->CRTC[13] = 0x00;
315 par->CRTC[14] = 0x00;
316 par->CRTC[15] = 0x00;
317 par->CRTC[16] = timings->VSyncStart & 0xFF;
318 par->CRTC[17] = (timings->VSyncEnd & 0x0F) | 0x20;
319 par->CRTC[18] = (timings->VDisplay - 1) & 0xFF;
320 par->CRTC[19] = var->xres_virtual >> 4;
321 par->CRTC[20] = 0x00;
322 par->CRTC[21] = (timings->VDisplay - 1) & 0xFF;
323 par->CRTC[22] = (timings->VTotal - 1) & 0xFF;
324 par->CRTC[23] = 0xC3;
325 par->CRTC[24] = 0xFF;
328 * are these unnecessary?
329 * vgaHWHBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
330 * vgaHWVBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
334 * Graphics Display Controller
336 par->Graphics[0] = 0x00;
337 par->Graphics[1] = 0x00;
338 par->Graphics[2] = 0x00;
339 par->Graphics[3] = 0x00;
340 par->Graphics[4] = 0x00;
341 par->Graphics[5] = 0x40;
342 par->Graphics[6] = 0x05; /* only map 64k VGA memory !!!! */
343 par->Graphics[7] = 0x0F;
344 par->Graphics[8] = 0xFF;
347 par->Attribute[0] = 0x00; /* standard colormap translation */
348 par->Attribute[1] = 0x01;
349 par->Attribute[2] = 0x02;
350 par->Attribute[3] = 0x03;
351 par->Attribute[4] = 0x04;
352 par->Attribute[5] = 0x05;
353 par->Attribute[6] = 0x06;
354 par->Attribute[7] = 0x07;
355 par->Attribute[8] = 0x08;
356 par->Attribute[9] = 0x09;
357 par->Attribute[10] = 0x0A;
358 par->Attribute[11] = 0x0B;
359 par->Attribute[12] = 0x0C;
360 par->Attribute[13] = 0x0D;
361 par->Attribute[14] = 0x0E;
362 par->Attribute[15] = 0x0F;
363 par->Attribute[16] = 0x41;
364 par->Attribute[17] = 0xFF;
365 par->Attribute[18] = 0x0F;
366 par->Attribute[19] = 0x00;
367 par->Attribute[20] = 0x00;
371 static void vgaHWLock(struct vgastate *state)
373 /* Protect CRTC[0-7] */
374 vga_wcrt(state->vgabase, 0x11, vga_rcrt(state->vgabase, 0x11) | 0x80);
377 static void vgaHWUnlock(void)
379 /* Unprotect CRTC[0-7] */
380 vga_wcrt(NULL, 0x11, vga_rcrt(NULL, 0x11) & ~0x80);
383 static void neoLock(struct vgastate *state)
385 vga_wgfx(state->vgabase, 0x09, 0x00);
389 static void neoUnlock(void)
392 vga_wgfx(NULL, 0x09, 0x26);
396 * VGA Palette management
398 static int paletteEnabled = 0;
400 static inline void VGAenablePalette(void)
402 vga_r(NULL, VGA_IS1_RC);
403 vga_w(NULL, VGA_ATT_W, 0x00);
407 static inline void VGAdisablePalette(void)
409 vga_r(NULL, VGA_IS1_RC);
410 vga_w(NULL, VGA_ATT_W, 0x20);
414 static inline void VGAwATTR(u8 index, u8 value)
421 vga_r(NULL, VGA_IS1_RC);
422 vga_wattr(NULL, index, value);
425 static void vgaHWProtect(int on)
431 * Turn off screen and disable sequencer.
433 tmp = vga_rseq(NULL, 0x01);
434 vga_wseq(NULL, 0x00, 0x01); /* Synchronous Reset */
435 vga_wseq(NULL, 0x01, tmp | 0x20); /* disable the display */
440 * Reenable sequencer, then turn on screen.
442 tmp = vga_rseq(NULL, 0x01);
443 vga_wseq(NULL, 0x01, tmp & ~0x20); /* reenable display */
444 vga_wseq(NULL, 0x00, 0x03); /* clear synchronousreset */
450 static void vgaHWRestore(const struct fb_info *info,
451 const struct neofb_par *par)
455 vga_w(NULL, VGA_MIS_W, par->MiscOutReg);
457 for (i = 1; i < 5; i++)
458 vga_wseq(NULL, i, par->Sequencer[i]);
460 /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 or CRTC[17] */
461 vga_wcrt(NULL, 17, par->CRTC[17] & ~0x80);
463 for (i = 0; i < 25; i++)
464 vga_wcrt(NULL, i, par->CRTC[i]);
466 for (i = 0; i < 9; i++)
467 vga_wgfx(NULL, i, par->Graphics[i]);
471 for (i = 0; i < 21; i++)
472 VGAwATTR(i, par->Attribute[i]);
478 /* -------------------- Hardware specific routines ------------------------- */
481 * Hardware Acceleration for Neo2200+
483 static inline int neo2200_sync(struct fb_info *info)
485 struct neofb_par *par = info->par;
487 while (readl(&par->neo2200->bltStat) & 1);
491 static inline void neo2200_wait_fifo(struct fb_info *info,
492 int requested_fifo_space)
494 // ndev->neo.waitfifo_calls++;
495 // ndev->neo.waitfifo_sum += requested_fifo_space;
497 /* FIXME: does not work
498 if (neo_fifo_space < requested_fifo_space)
500 neo_fifo_waitcycles++;
504 neo_fifo_space = (neo2200->bltStat >> 8);
505 if (neo_fifo_space >= requested_fifo_space)
511 neo_fifo_cache_hits++;
514 neo_fifo_space -= requested_fifo_space;
520 static inline void neo2200_accel_init(struct fb_info *info,
521 struct fb_var_screeninfo *var)
523 struct neofb_par *par = info->par;
524 Neo2200 __iomem *neo2200 = par->neo2200;
529 switch (var->bits_per_pixel) {
531 bltMod = NEO_MODE1_DEPTH8;
532 pitch = var->xres_virtual;
536 bltMod = NEO_MODE1_DEPTH16;
537 pitch = var->xres_virtual * 2;
540 bltMod = NEO_MODE1_DEPTH24;
541 pitch = var->xres_virtual * 3;
545 "neofb: neo2200_accel_init: unexpected bits per pixel!\n");
549 writel(bltMod << 16, &neo2200->bltStat);
550 writel((pitch << 16) | pitch, &neo2200->pitch);
553 /* --------------------------------------------------------------------- */
556 neofb_open(struct fb_info *info, int user)
558 struct neofb_par *par = info->par;
560 mutex_lock(&par->open_lock);
561 if (!par->ref_count) {
562 memset(&par->state, 0, sizeof(struct vgastate));
563 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
564 save_vga(&par->state);
567 mutex_unlock(&par->open_lock);
573 neofb_release(struct fb_info *info, int user)
575 struct neofb_par *par = info->par;
577 mutex_lock(&par->open_lock);
578 if (!par->ref_count) {
579 mutex_unlock(&par->open_lock);
582 if (par->ref_count == 1) {
583 restore_vga(&par->state);
586 mutex_unlock(&par->open_lock);
592 neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
594 struct neofb_par *par = info->par;
595 unsigned int pixclock = var->pixclock;
596 struct xtimings timings;
600 DBG("neofb_check_var");
603 pixclock = 10000; /* 10ns = 100MHz */
604 timings.pixclock = 1000000000 / pixclock;
605 if (timings.pixclock < 1)
606 timings.pixclock = 1;
608 if (timings.pixclock > par->maxClock)
611 timings.dblscan = var->vmode & FB_VMODE_DOUBLE;
612 timings.interlaced = var->vmode & FB_VMODE_INTERLACED;
613 timings.HDisplay = var->xres;
614 timings.HSyncStart = timings.HDisplay + var->right_margin;
615 timings.HSyncEnd = timings.HSyncStart + var->hsync_len;
616 timings.HTotal = timings.HSyncEnd + var->left_margin;
617 timings.VDisplay = var->yres;
618 timings.VSyncStart = timings.VDisplay + var->lower_margin;
619 timings.VSyncEnd = timings.VSyncStart + var->vsync_len;
620 timings.VTotal = timings.VSyncEnd + var->upper_margin;
621 timings.sync = var->sync;
623 /* Is the mode larger than the LCD panel? */
624 if (par->internal_display &&
625 ((var->xres > par->NeoPanelWidth) ||
626 (var->yres > par->NeoPanelHeight))) {
628 "Mode (%dx%d) larger than the LCD panel (%dx%d)\n",
629 var->xres, var->yres, par->NeoPanelWidth,
630 par->NeoPanelHeight);
634 /* Is the mode one of the acceptable sizes? */
635 if (!par->internal_display)
640 if (var->yres == 1024)
644 if (var->yres == 768)
648 if (var->yres == (par->libretto ? 480 : 600))
652 if (var->yres == 480)
660 "Mode (%dx%d) won't display properly on LCD\n",
661 var->xres, var->yres);
665 var->red.msb_right = 0;
666 var->green.msb_right = 0;
667 var->blue.msb_right = 0;
669 switch (var->bits_per_pixel) {
670 case 8: /* PSEUDOCOLOUR, 256 */
671 var->transp.offset = 0;
672 var->transp.length = 0;
675 var->green.offset = 0;
676 var->green.length = 8;
677 var->blue.offset = 0;
678 var->blue.length = 8;
681 case 16: /* DIRECTCOLOUR, 64k */
682 var->transp.offset = 0;
683 var->transp.length = 0;
684 var->red.offset = 11;
686 var->green.offset = 5;
687 var->green.length = 6;
688 var->blue.offset = 0;
689 var->blue.length = 5;
692 case 24: /* TRUECOLOUR, 16m */
693 var->transp.offset = 0;
694 var->transp.length = 0;
695 var->red.offset = 16;
697 var->green.offset = 8;
698 var->green.length = 8;
699 var->blue.offset = 0;
700 var->blue.length = 8;
703 #ifdef NO_32BIT_SUPPORT_YET
704 case 32: /* TRUECOLOUR, 16m */
705 var->transp.offset = 24;
706 var->transp.length = 8;
707 var->red.offset = 16;
709 var->green.offset = 8;
710 var->green.length = 8;
711 var->blue.offset = 0;
712 var->blue.length = 8;
716 printk(KERN_WARNING "neofb: no support for %dbpp\n",
717 var->bits_per_pixel);
721 vramlen = info->fix.smem_len;
722 if (vramlen > 4 * 1024 * 1024)
723 vramlen = 4 * 1024 * 1024;
725 if (var->yres_virtual < var->yres)
726 var->yres_virtual = var->yres;
727 if (var->xres_virtual < var->xres)
728 var->xres_virtual = var->xres;
730 memlen = var->xres_virtual * var->bits_per_pixel * var->yres_virtual >> 3;
732 if (memlen > vramlen) {
733 var->yres_virtual = vramlen * 8 / (var->xres_virtual *
734 var->bits_per_pixel);
735 memlen = var->xres_virtual * var->bits_per_pixel *
736 var->yres_virtual / 8;
739 /* we must round yres/xres down, we already rounded y/xres_virtual up
740 if it was possible. We should return -EINVAL, but I disagree */
741 if (var->yres_virtual < var->yres)
742 var->yres = var->yres_virtual;
743 if (var->xres_virtual < var->xres)
744 var->xres = var->xres_virtual;
745 if (var->xoffset + var->xres > var->xres_virtual)
746 var->xoffset = var->xres_virtual - var->xres;
747 if (var->yoffset + var->yres > var->yres_virtual)
748 var->yoffset = var->yres_virtual - var->yres;
754 if (var->bits_per_pixel >= 24 || !par->neo2200)
755 var->accel_flags &= ~FB_ACCELF_TEXT;
759 static int neofb_set_par(struct fb_info *info)
761 struct neofb_par *par = info->par;
762 struct xtimings timings;
766 int hoffset, voffset;
768 DBG("neofb_set_par");
772 vgaHWProtect(1); /* Blank the screen */
774 timings.dblscan = info->var.vmode & FB_VMODE_DOUBLE;
775 timings.interlaced = info->var.vmode & FB_VMODE_INTERLACED;
776 timings.HDisplay = info->var.xres;
777 timings.HSyncStart = timings.HDisplay + info->var.right_margin;
778 timings.HSyncEnd = timings.HSyncStart + info->var.hsync_len;
779 timings.HTotal = timings.HSyncEnd + info->var.left_margin;
780 timings.VDisplay = info->var.yres;
781 timings.VSyncStart = timings.VDisplay + info->var.lower_margin;
782 timings.VSyncEnd = timings.VSyncStart + info->var.vsync_len;
783 timings.VTotal = timings.VSyncEnd + info->var.upper_margin;
784 timings.sync = info->var.sync;
785 timings.pixclock = PICOS2KHZ(info->var.pixclock);
787 if (timings.pixclock < 1)
788 timings.pixclock = 1;
791 * This will allocate the datastructure and initialize all of the
792 * generic VGA registers.
795 if (vgaHWInit(&info->var, info, par, &timings))
799 * The default value assigned by vgaHW.c is 0x41, but this does
800 * not work for NeoMagic.
802 par->Attribute[16] = 0x01;
804 switch (info->var.bits_per_pixel) {
806 par->CRTC[0x13] = info->var.xres_virtual >> 3;
807 par->ExtCRTOffset = info->var.xres_virtual >> 11;
808 par->ExtColorModeSelect = 0x11;
811 par->CRTC[0x13] = info->var.xres_virtual >> 2;
812 par->ExtCRTOffset = info->var.xres_virtual >> 10;
813 par->ExtColorModeSelect = 0x13;
816 par->CRTC[0x13] = (info->var.xres_virtual * 3) >> 3;
817 par->ExtCRTOffset = (info->var.xres_virtual * 3) >> 11;
818 par->ExtColorModeSelect = 0x14;
820 #ifdef NO_32BIT_SUPPORT_YET
821 case 32: /* FIXME: guessed values */
822 par->CRTC[0x13] = info->var.xres_virtual >> 1;
823 par->ExtCRTOffset = info->var.xres_virtual >> 9;
824 par->ExtColorModeSelect = 0x15;
831 par->ExtCRTDispAddr = 0x10;
833 /* Vertical Extension */
834 par->VerticalExt = (((timings.VTotal - 2) & 0x400) >> 10)
835 | (((timings.VDisplay - 1) & 0x400) >> 9)
836 | (((timings.VSyncStart) & 0x400) >> 8)
837 | (((timings.VSyncStart) & 0x400) >> 7);
839 /* Fast write bursts on unless disabled. */
841 par->SysIfaceCntl1 = 0x30;
843 par->SysIfaceCntl1 = 0x00;
845 par->SysIfaceCntl2 = 0xc0; /* VESA Bios sets this to 0x80! */
847 /* Initialize: by default, we want display config register to be read */
848 par->PanelDispCntlRegRead = 1;
850 /* Enable any user specified display devices. */
851 par->PanelDispCntlReg1 = 0x00;
852 if (par->internal_display)
853 par->PanelDispCntlReg1 |= 0x02;
854 if (par->external_display)
855 par->PanelDispCntlReg1 |= 0x01;
857 /* If the user did not specify any display devices, then... */
858 if (par->PanelDispCntlReg1 == 0x00) {
859 /* Default to internal (i.e., LCD) only. */
860 par->PanelDispCntlReg1 = vga_rgfx(NULL, 0x20) & 0x03;
863 /* If we are using a fixed mode, then tell the chip we are. */
864 switch (info->var.xres) {
866 par->PanelDispCntlReg1 |= 0x60;
869 par->PanelDispCntlReg1 |= 0x40;
872 par->PanelDispCntlReg1 |= 0x20;
879 /* Setup shadow register locking. */
880 switch (par->PanelDispCntlReg1 & 0x03) {
881 case 0x01: /* External CRT only mode: */
882 par->GeneralLockReg = 0x00;
883 /* We need to program the VCLK for external display only mode. */
884 par->ProgramVCLK = 1;
886 case 0x02: /* Internal LCD only mode: */
887 case 0x03: /* Simultaneous internal/external (LCD/CRT) mode: */
888 par->GeneralLockReg = 0x01;
889 /* Don't program the VCLK when using the LCD. */
890 par->ProgramVCLK = 0;
895 * If the screen is to be stretched, turn on stretching for the
898 * OPTION_LCD_STRETCH means stretching should be turned off!
900 par->PanelDispCntlReg2 = 0x00;
901 par->PanelDispCntlReg3 = 0x00;
903 if (par->lcd_stretch && (par->PanelDispCntlReg1 == 0x02) && /* LCD only */
904 (info->var.xres != par->NeoPanelWidth)) {
905 switch (info->var.xres) {
906 case 320: /* Needs testing. KEM -- 24 May 98 */
907 case 400: /* Needs testing. KEM -- 24 May 98 */
912 par->PanelDispCntlReg2 |= 0xC6;
916 /* No stretching in these modes. */
922 * If the screen is to be centerd, turn on the centering for the
925 par->PanelVertCenterReg1 = 0x00;
926 par->PanelVertCenterReg2 = 0x00;
927 par->PanelVertCenterReg3 = 0x00;
928 par->PanelVertCenterReg4 = 0x00;
929 par->PanelVertCenterReg5 = 0x00;
930 par->PanelHorizCenterReg1 = 0x00;
931 par->PanelHorizCenterReg2 = 0x00;
932 par->PanelHorizCenterReg3 = 0x00;
933 par->PanelHorizCenterReg4 = 0x00;
934 par->PanelHorizCenterReg5 = 0x00;
937 if (par->PanelDispCntlReg1 & 0x02) {
938 if (info->var.xres == par->NeoPanelWidth) {
940 * No centering required when the requested display width
941 * equals the panel width.
944 par->PanelDispCntlReg2 |= 0x01;
945 par->PanelDispCntlReg3 |= 0x10;
947 /* Calculate the horizontal and vertical offsets. */
950 ((par->NeoPanelWidth -
951 info->var.xres) >> 4) - 1;
953 ((par->NeoPanelHeight -
954 info->var.yres) >> 1) - 2;
956 /* Stretched modes cannot be centered. */
961 switch (info->var.xres) {
962 case 320: /* Needs testing. KEM -- 24 May 98 */
963 par->PanelHorizCenterReg3 = hoffset;
964 par->PanelVertCenterReg2 = voffset;
966 case 400: /* Needs testing. KEM -- 24 May 98 */
967 par->PanelHorizCenterReg4 = hoffset;
968 par->PanelVertCenterReg1 = voffset;
971 par->PanelHorizCenterReg1 = hoffset;
972 par->PanelVertCenterReg3 = voffset;
975 par->PanelHorizCenterReg2 = hoffset;
976 par->PanelVertCenterReg4 = voffset;
979 par->PanelHorizCenterReg5 = hoffset;
980 par->PanelVertCenterReg5 = voffset;
984 /* No centering in these modes. */
991 neoFindMode(info->var.xres, info->var.yres,
992 info->var.bits_per_pixel);
995 * Calculate the VCLK that most closely matches the requested dot
998 neoCalcVCLK(info, par, timings.pixclock);
1000 /* Since we program the clocks ourselves, always use VCLK3. */
1001 par->MiscOutReg |= 0x0C;
1003 /* alread unlocked above */
1004 /* BOGUS vga_wgfx(NULL, 0x09, 0x26); */
1006 /* don't know what this is, but it's 0 from bootup anyway */
1007 vga_wgfx(NULL, 0x15, 0x00);
1009 /* was set to 0x01 by my bios in text and vesa modes */
1010 vga_wgfx(NULL, 0x0A, par->GeneralLockReg);
1013 * The color mode needs to be set before calling vgaHWRestore
1014 * to ensure the DAC is initialized properly.
1016 * NOTE: Make sure we don't change bits make sure we don't change
1017 * any reserved bits.
1019 temp = vga_rgfx(NULL, 0x90);
1020 switch (info->fix.accel) {
1021 case FB_ACCEL_NEOMAGIC_NM2070:
1022 temp &= 0xF0; /* Save bits 7:4 */
1023 temp |= (par->ExtColorModeSelect & ~0xF0);
1025 case FB_ACCEL_NEOMAGIC_NM2090:
1026 case FB_ACCEL_NEOMAGIC_NM2093:
1027 case FB_ACCEL_NEOMAGIC_NM2097:
1028 case FB_ACCEL_NEOMAGIC_NM2160:
1029 case FB_ACCEL_NEOMAGIC_NM2200:
1030 case FB_ACCEL_NEOMAGIC_NM2230:
1031 case FB_ACCEL_NEOMAGIC_NM2360:
1032 case FB_ACCEL_NEOMAGIC_NM2380:
1033 temp &= 0x70; /* Save bits 6:4 */
1034 temp |= (par->ExtColorModeSelect & ~0x70);
1038 vga_wgfx(NULL, 0x90, temp);
1041 * In some rare cases a lockup might occur if we don't delay
1042 * here. (Reported by Miles Lane)
1047 * Disable horizontal and vertical graphics and text expansions so
1048 * that vgaHWRestore works properly.
1050 temp = vga_rgfx(NULL, 0x25);
1052 vga_wgfx(NULL, 0x25, temp);
1055 * Sleep for 200ms to make sure that the two operations above have
1056 * had time to take effect.
1061 * This function handles restoring the generic VGA registers. */
1062 vgaHWRestore(info, par);
1064 /* linear colormap for non palettized modes */
1065 switch (info->var.bits_per_pixel) {
1067 /* PseudoColor, 256 */
1068 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1071 /* TrueColor, 64k */
1072 info->fix.visual = FB_VISUAL_TRUECOLOR;
1074 for (i = 0; i < 64; i++) {
1077 outb(i << 1, 0x3c9);
1079 outb(i << 1, 0x3c9);
1083 #ifdef NO_32BIT_SUPPORT_YET
1086 /* TrueColor, 16m */
1087 info->fix.visual = FB_VISUAL_TRUECOLOR;
1089 for (i = 0; i < 256; i++) {
1099 vga_wgfx(NULL, 0x0E, par->ExtCRTDispAddr);
1100 vga_wgfx(NULL, 0x0F, par->ExtCRTOffset);
1101 temp = vga_rgfx(NULL, 0x10);
1102 temp &= 0x0F; /* Save bits 3:0 */
1103 temp |= (par->SysIfaceCntl1 & ~0x0F); /* VESA Bios sets bit 1! */
1104 vga_wgfx(NULL, 0x10, temp);
1106 vga_wgfx(NULL, 0x11, par->SysIfaceCntl2);
1107 vga_wgfx(NULL, 0x15, 0 /*par->SingleAddrPage */ );
1108 vga_wgfx(NULL, 0x16, 0 /*par->DualAddrPage */ );
1110 temp = vga_rgfx(NULL, 0x20);
1111 switch (info->fix.accel) {
1112 case FB_ACCEL_NEOMAGIC_NM2070:
1113 temp &= 0xFC; /* Save bits 7:2 */
1114 temp |= (par->PanelDispCntlReg1 & ~0xFC);
1116 case FB_ACCEL_NEOMAGIC_NM2090:
1117 case FB_ACCEL_NEOMAGIC_NM2093:
1118 case FB_ACCEL_NEOMAGIC_NM2097:
1119 case FB_ACCEL_NEOMAGIC_NM2160:
1120 temp &= 0xDC; /* Save bits 7:6,4:2 */
1121 temp |= (par->PanelDispCntlReg1 & ~0xDC);
1123 case FB_ACCEL_NEOMAGIC_NM2200:
1124 case FB_ACCEL_NEOMAGIC_NM2230:
1125 case FB_ACCEL_NEOMAGIC_NM2360:
1126 case FB_ACCEL_NEOMAGIC_NM2380:
1127 temp &= 0x98; /* Save bits 7,4:3 */
1128 temp |= (par->PanelDispCntlReg1 & ~0x98);
1131 vga_wgfx(NULL, 0x20, temp);
1133 temp = vga_rgfx(NULL, 0x25);
1134 temp &= 0x38; /* Save bits 5:3 */
1135 temp |= (par->PanelDispCntlReg2 & ~0x38);
1136 vga_wgfx(NULL, 0x25, temp);
1138 if (info->fix.accel != FB_ACCEL_NEOMAGIC_NM2070) {
1139 temp = vga_rgfx(NULL, 0x30);
1140 temp &= 0xEF; /* Save bits 7:5 and bits 3:0 */
1141 temp |= (par->PanelDispCntlReg3 & ~0xEF);
1142 vga_wgfx(NULL, 0x30, temp);
1145 vga_wgfx(NULL, 0x28, par->PanelVertCenterReg1);
1146 vga_wgfx(NULL, 0x29, par->PanelVertCenterReg2);
1147 vga_wgfx(NULL, 0x2a, par->PanelVertCenterReg3);
1149 if (info->fix.accel != FB_ACCEL_NEOMAGIC_NM2070) {
1150 vga_wgfx(NULL, 0x32, par->PanelVertCenterReg4);
1151 vga_wgfx(NULL, 0x33, par->PanelHorizCenterReg1);
1152 vga_wgfx(NULL, 0x34, par->PanelHorizCenterReg2);
1153 vga_wgfx(NULL, 0x35, par->PanelHorizCenterReg3);
1156 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2160)
1157 vga_wgfx(NULL, 0x36, par->PanelHorizCenterReg4);
1159 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
1160 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
1161 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
1162 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
1163 vga_wgfx(NULL, 0x36, par->PanelHorizCenterReg4);
1164 vga_wgfx(NULL, 0x37, par->PanelVertCenterReg5);
1165 vga_wgfx(NULL, 0x38, par->PanelHorizCenterReg5);
1170 /* Program VCLK3 if needed. */
1171 if (par->ProgramVCLK && ((vga_rgfx(NULL, 0x9B) != par->VCLK3NumeratorLow)
1172 || (vga_rgfx(NULL, 0x9F) != par->VCLK3Denominator)
1173 || (clock_hi && ((vga_rgfx(NULL, 0x8F) & ~0x0f)
1174 != (par->VCLK3NumeratorHigh &
1176 vga_wgfx(NULL, 0x9B, par->VCLK3NumeratorLow);
1178 temp = vga_rgfx(NULL, 0x8F);
1179 temp &= 0x0F; /* Save bits 3:0 */
1180 temp |= (par->VCLK3NumeratorHigh & ~0x0F);
1181 vga_wgfx(NULL, 0x8F, temp);
1183 vga_wgfx(NULL, 0x9F, par->VCLK3Denominator);
1187 vga_wcrt(NULL, 0x23, par->biosMode);
1189 vga_wgfx(NULL, 0x93, 0xc0); /* Gives 5x faster framebuffer writes !!! */
1191 /* Program vertical extension register */
1192 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
1193 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
1194 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
1195 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
1196 vga_wcrt(NULL, 0x70, par->VerticalExt);
1199 vgaHWProtect(0); /* Turn on screen */
1201 /* Calling this also locks offset registers required in update_start */
1202 neoLock(&par->state);
1204 info->fix.line_length =
1205 info->var.xres_virtual * (info->var.bits_per_pixel >> 3);
1207 switch (info->fix.accel) {
1208 case FB_ACCEL_NEOMAGIC_NM2200:
1209 case FB_ACCEL_NEOMAGIC_NM2230:
1210 case FB_ACCEL_NEOMAGIC_NM2360:
1211 case FB_ACCEL_NEOMAGIC_NM2380:
1212 neo2200_accel_init(info, &info->var);
1220 static void neofb_update_start(struct fb_info *info,
1221 struct fb_var_screeninfo *var)
1223 struct neofb_par *par = info->par;
1224 struct vgastate *state = &par->state;
1225 int oldExtCRTDispAddr;
1228 DBG("neofb_update_start");
1230 Base = (var->yoffset * var->xres_virtual + var->xoffset) >> 2;
1231 Base *= (var->bits_per_pixel + 7) / 8;
1236 * These are the generic starting address registers.
1238 vga_wcrt(state->vgabase, 0x0C, (Base & 0x00FF00) >> 8);
1239 vga_wcrt(state->vgabase, 0x0D, (Base & 0x00FF));
1242 * Make sure we don't clobber some other bits that might already
1243 * have been set. NOTE: NM2200 has a writable bit 3, but it shouldn't
1246 oldExtCRTDispAddr = vga_rgfx(NULL, 0x0E);
1247 vga_wgfx(state->vgabase, 0x0E, (((Base >> 16) & 0x0f) | (oldExtCRTDispAddr & 0xf0)));
1253 * Pan or Wrap the Display
1255 static int neofb_pan_display(struct fb_var_screeninfo *var,
1256 struct fb_info *info)
1260 y_bottom = var->yoffset;
1262 if (!(var->vmode & FB_VMODE_YWRAP))
1263 y_bottom += var->yres;
1265 if (var->xoffset > (var->xres_virtual - var->xres))
1267 if (y_bottom > info->var.yres_virtual)
1270 neofb_update_start(info, var);
1272 info->var.xoffset = var->xoffset;
1273 info->var.yoffset = var->yoffset;
1275 if (var->vmode & FB_VMODE_YWRAP)
1276 info->var.vmode |= FB_VMODE_YWRAP;
1278 info->var.vmode &= ~FB_VMODE_YWRAP;
1282 static int neofb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
1283 u_int transp, struct fb_info *fb)
1285 if (regno >= fb->cmap.len || regno > 255)
1288 switch (fb->var.bits_per_pixel) {
1292 outb(red >> 10, 0x3c9);
1293 outb(green >> 10, 0x3c9);
1294 outb(blue >> 10, 0x3c9);
1297 ((u32 *) fb->pseudo_palette)[regno] =
1298 ((red & 0xf800)) | ((green & 0xfc00) >> 5) |
1299 ((blue & 0xf800) >> 11);
1302 ((u32 *) fb->pseudo_palette)[regno] =
1303 ((red & 0xff00) << 8) | ((green & 0xff00)) |
1304 ((blue & 0xff00) >> 8);
1306 #ifdef NO_32BIT_SUPPORT_YET
1308 ((u32 *) fb->pseudo_palette)[regno] =
1309 ((transp & 0xff00) << 16) | ((red & 0xff00) << 8) |
1310 ((green & 0xff00)) | ((blue & 0xff00) >> 8);
1320 * (Un)Blank the display.
1322 static int neofb_blank(int blank_mode, struct fb_info *info)
1325 * Blank the screen if blank_mode != 0, else unblank.
1326 * Return 0 if blanking succeeded, != 0 if un-/blanking failed due to
1327 * e.g. a video mode which doesn't support it. Implements VESA suspend
1328 * and powerdown modes for monitors, and backlight control on LCDs.
1329 * blank_mode == 0: unblanked (backlight on)
1330 * blank_mode == 1: blank (backlight on)
1331 * blank_mode == 2: suspend vsync (backlight off)
1332 * blank_mode == 3: suspend hsync (backlight off)
1333 * blank_mode == 4: powerdown (backlight off)
1335 * wms...Enable VESA DPMS compatible powerdown mode
1336 * run "setterm -powersave powerdown" to take advantage
1338 struct neofb_par *par = info->par;
1339 int seqflags, lcdflags, dpmsflags, reg, tmpdisp;
1342 * Read back the register bits related to display configuration. They might
1343 * have been changed underneath the driver via Fn key stroke.
1346 tmpdisp = vga_rgfx(NULL, 0x20) & 0x03;
1347 neoLock(&par->state);
1349 /* In case we blank the screen, we want to store the possibly new
1350 * configuration in the driver. During un-blank, we re-apply this setting,
1351 * since the LCD bit will be cleared in order to switch off the backlight.
1353 if (par->PanelDispCntlRegRead) {
1354 par->PanelDispCntlReg1 = tmpdisp;
1356 par->PanelDispCntlRegRead = !blank_mode;
1358 switch (blank_mode) {
1359 case FB_BLANK_POWERDOWN: /* powerdown - both sync lines down */
1360 seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
1361 lcdflags = 0; /* LCD off */
1362 dpmsflags = NEO_GR01_SUPPRESS_HSYNC |
1363 NEO_GR01_SUPPRESS_VSYNC;
1364 #ifdef CONFIG_TOSHIBA
1365 /* Do we still need this ? */
1366 /* attempt to turn off backlight on toshiba; also turns off external */
1370 regs.eax = 0xff00; /* HCI_SET */
1371 regs.ebx = 0x0002; /* HCI_BACKLIGHT */
1372 regs.ecx = 0x0000; /* HCI_DISABLE */
1377 case FB_BLANK_HSYNC_SUSPEND: /* hsync off */
1378 seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
1379 lcdflags = 0; /* LCD off */
1380 dpmsflags = NEO_GR01_SUPPRESS_HSYNC;
1382 case FB_BLANK_VSYNC_SUSPEND: /* vsync off */
1383 seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
1384 lcdflags = 0; /* LCD off */
1385 dpmsflags = NEO_GR01_SUPPRESS_VSYNC;
1387 case FB_BLANK_NORMAL: /* just blank screen (backlight stays on) */
1388 seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
1390 * During a blank operation with the LID shut, we might store "LCD off"
1391 * by mistake. Due to timing issues, the BIOS may switch the lights
1392 * back on, and we turn it back off once we "unblank".
1394 * So here is an attempt to implement ">=" - if we are in the process
1395 * of unblanking, and the LCD bit is unset in the driver but set in the
1396 * register, we must keep it.
1398 lcdflags = ((par->PanelDispCntlReg1 | tmpdisp) & 0x02); /* LCD normal */
1399 dpmsflags = 0x00; /* no hsync/vsync suppression */
1401 case FB_BLANK_UNBLANK: /* unblank */
1402 seqflags = 0; /* Enable sequencer */
1403 lcdflags = ((par->PanelDispCntlReg1 | tmpdisp) & 0x02); /* LCD normal */
1404 dpmsflags = 0x00; /* no hsync/vsync suppression */
1405 #ifdef CONFIG_TOSHIBA
1406 /* Do we still need this ? */
1407 /* attempt to re-enable backlight/external on toshiba */
1411 regs.eax = 0xff00; /* HCI_SET */
1412 regs.ebx = 0x0002; /* HCI_BACKLIGHT */
1413 regs.ecx = 0x0001; /* HCI_ENABLE */
1418 default: /* Anything else we don't understand; return 1 to tell
1419 * fb_blank we didn't aactually do anything */
1424 reg = (vga_rseq(NULL, 0x01) & ~0x20) | seqflags;
1425 vga_wseq(NULL, 0x01, reg);
1426 reg = (vga_rgfx(NULL, 0x20) & ~0x02) | lcdflags;
1427 vga_wgfx(NULL, 0x20, reg);
1428 reg = (vga_rgfx(NULL, 0x01) & ~0xF0) | 0x80 | dpmsflags;
1429 vga_wgfx(NULL, 0x01, reg);
1430 neoLock(&par->state);
1435 neo2200_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
1437 struct neofb_par *par = info->par;
1440 dst = rect->dx + rect->dy * info->var.xres_virtual;
1441 rop = rect->rop ? 0x060000 : 0x0c0000;
1443 neo2200_wait_fifo(info, 4);
1445 /* set blt control */
1446 writel(NEO_BC3_FIFO_EN |
1447 NEO_BC0_SRC_IS_FG | NEO_BC3_SKIP_MAPPING |
1448 // NEO_BC3_DST_XY_ADDR |
1449 // NEO_BC3_SRC_XY_ADDR |
1450 rop, &par->neo2200->bltCntl);
1452 switch (info->var.bits_per_pixel) {
1454 writel(rect->color, &par->neo2200->fgColor);
1458 writel(((u32 *) (info->pseudo_palette))[rect->color],
1459 &par->neo2200->fgColor);
1463 writel(dst * ((info->var.bits_per_pixel + 7) >> 3),
1464 &par->neo2200->dstStart);
1465 writel((rect->height << 16) | (rect->width & 0xffff),
1466 &par->neo2200->xyExt);
1470 neo2200_copyarea(struct fb_info *info, const struct fb_copyarea *area)
1472 u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy;
1473 struct neofb_par *par = info->par;
1474 u_long src, dst, bltCntl;
1476 bltCntl = NEO_BC3_FIFO_EN | NEO_BC3_SKIP_MAPPING | 0x0C0000;
1478 if ((dy > sy) || ((dy == sy) && (dx > sx))) {
1479 /* Start with the lower right corner */
1480 sy += (area->height - 1);
1481 dy += (area->height - 1);
1482 sx += (area->width - 1);
1483 dx += (area->width - 1);
1485 bltCntl |= NEO_BC0_X_DEC | NEO_BC0_DST_Y_DEC | NEO_BC0_SRC_Y_DEC;
1488 src = sx * (info->var.bits_per_pixel >> 3) + sy*info->fix.line_length;
1489 dst = dx * (info->var.bits_per_pixel >> 3) + dy*info->fix.line_length;
1491 neo2200_wait_fifo(info, 4);
1493 /* set blt control */
1494 writel(bltCntl, &par->neo2200->bltCntl);
1496 writel(src, &par->neo2200->srcStart);
1497 writel(dst, &par->neo2200->dstStart);
1498 writel((area->height << 16) | (area->width & 0xffff),
1499 &par->neo2200->xyExt);
1503 neo2200_imageblit(struct fb_info *info, const struct fb_image *image)
1505 struct neofb_par *par = info->par;
1506 int s_pitch = (image->width * image->depth + 7) >> 3;
1507 int scan_align = info->pixmap.scan_align - 1;
1508 int buf_align = info->pixmap.buf_align - 1;
1509 int bltCntl_flags, d_pitch, data_len;
1511 // The data is padded for the hardware
1512 d_pitch = (s_pitch + scan_align) & ~scan_align;
1513 data_len = ((d_pitch * image->height) + buf_align) & ~buf_align;
1517 if (image->depth == 1) {
1518 if (info->var.bits_per_pixel == 24 && image->width < 16) {
1519 /* FIXME. There is a bug with accelerated color-expanded
1520 * transfers in 24 bit mode if the image being transferred
1521 * is less than 16 bits wide. This is due to insufficient
1522 * padding when writing the image. We need to adjust
1523 * struct fb_pixmap. Not yet done. */
1524 return cfb_imageblit(info, image);
1526 bltCntl_flags = NEO_BC0_SRC_MONO;
1527 } else if (image->depth == info->var.bits_per_pixel) {
1530 /* We don't currently support hardware acceleration if image
1531 * depth is different from display */
1532 return cfb_imageblit(info, image);
1535 switch (info->var.bits_per_pixel) {
1537 writel(image->fg_color, &par->neo2200->fgColor);
1538 writel(image->bg_color, &par->neo2200->bgColor);
1542 writel(((u32 *) (info->pseudo_palette))[image->fg_color],
1543 &par->neo2200->fgColor);
1544 writel(((u32 *) (info->pseudo_palette))[image->bg_color],
1545 &par->neo2200->bgColor);
1549 writel(NEO_BC0_SYS_TO_VID |
1550 NEO_BC3_SKIP_MAPPING | bltCntl_flags |
1551 // NEO_BC3_DST_XY_ADDR |
1552 0x0c0000, &par->neo2200->bltCntl);
1554 writel(0, &par->neo2200->srcStart);
1555 // par->neo2200->dstStart = (image->dy << 16) | (image->dx & 0xffff);
1556 writel(((image->dx & 0xffff) * (info->var.bits_per_pixel >> 3) +
1557 image->dy * info->fix.line_length), &par->neo2200->dstStart);
1558 writel((image->height << 16) | (image->width & 0xffff),
1559 &par->neo2200->xyExt);
1561 memcpy_toio(par->mmio_vbase + 0x100000, image->data, data_len);
1565 neofb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
1567 switch (info->fix.accel) {
1568 case FB_ACCEL_NEOMAGIC_NM2200:
1569 case FB_ACCEL_NEOMAGIC_NM2230:
1570 case FB_ACCEL_NEOMAGIC_NM2360:
1571 case FB_ACCEL_NEOMAGIC_NM2380:
1572 neo2200_fillrect(info, rect);
1575 cfb_fillrect(info, rect);
1581 neofb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
1583 switch (info->fix.accel) {
1584 case FB_ACCEL_NEOMAGIC_NM2200:
1585 case FB_ACCEL_NEOMAGIC_NM2230:
1586 case FB_ACCEL_NEOMAGIC_NM2360:
1587 case FB_ACCEL_NEOMAGIC_NM2380:
1588 neo2200_copyarea(info, area);
1591 cfb_copyarea(info, area);
1597 neofb_imageblit(struct fb_info *info, const struct fb_image *image)
1599 switch (info->fix.accel) {
1600 case FB_ACCEL_NEOMAGIC_NM2200:
1601 case FB_ACCEL_NEOMAGIC_NM2230:
1602 case FB_ACCEL_NEOMAGIC_NM2360:
1603 case FB_ACCEL_NEOMAGIC_NM2380:
1604 neo2200_imageblit(info, image);
1607 cfb_imageblit(info, image);
1613 neofb_sync(struct fb_info *info)
1615 switch (info->fix.accel) {
1616 case FB_ACCEL_NEOMAGIC_NM2200:
1617 case FB_ACCEL_NEOMAGIC_NM2230:
1618 case FB_ACCEL_NEOMAGIC_NM2360:
1619 case FB_ACCEL_NEOMAGIC_NM2380:
1630 neofb_draw_cursor(struct fb_info *info, u8 *dst, u8 *src, unsigned int width)
1632 //memset_io(info->sprite.addr, 0xff, 1);
1636 neofb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1638 struct neofb_par *par = (struct neofb_par *) info->par;
1641 write_le32(NEOREG_CURSCNTL, ~NEO_CURS_ENABLE, par);
1643 if (cursor->set & FB_CUR_SETPOS) {
1644 u32 x = cursor->image.dx;
1645 u32 y = cursor->image.dy;
1647 info->cursor.image.dx = x;
1648 info->cursor.image.dy = y;
1649 write_le32(NEOREG_CURSX, x, par);
1650 write_le32(NEOREG_CURSY, y, par);
1653 if (cursor->set & FB_CUR_SETSIZE) {
1654 info->cursor.image.height = cursor->image.height;
1655 info->cursor.image.width = cursor->image.width;
1658 if (cursor->set & FB_CUR_SETHOT)
1659 info->cursor.hot = cursor->hot;
1661 if (cursor->set & FB_CUR_SETCMAP) {
1662 if (cursor->image.depth == 1) {
1663 u32 fg = cursor->image.fg_color;
1664 u32 bg = cursor->image.bg_color;
1666 info->cursor.image.fg_color = fg;
1667 info->cursor.image.bg_color = bg;
1669 fg = ((fg & 0xff0000) >> 16) | ((fg & 0xff) << 16) | (fg & 0xff00);
1670 bg = ((bg & 0xff0000) >> 16) | ((bg & 0xff) << 16) | (bg & 0xff00);
1671 write_le32(NEOREG_CURSFGCOLOR, fg, par);
1672 write_le32(NEOREG_CURSBGCOLOR, bg, par);
1676 if (cursor->set & FB_CUR_SETSHAPE)
1677 fb_load_cursor_image(info);
1679 if (info->cursor.enable)
1680 write_le32(NEOREG_CURSCNTL, NEO_CURS_ENABLE, par);
1685 static struct fb_ops neofb_ops = {
1686 .owner = THIS_MODULE,
1687 .fb_open = neofb_open,
1688 .fb_release = neofb_release,
1689 .fb_check_var = neofb_check_var,
1690 .fb_set_par = neofb_set_par,
1691 .fb_setcolreg = neofb_setcolreg,
1692 .fb_pan_display = neofb_pan_display,
1693 .fb_blank = neofb_blank,
1694 .fb_sync = neofb_sync,
1695 .fb_fillrect = neofb_fillrect,
1696 .fb_copyarea = neofb_copyarea,
1697 .fb_imageblit = neofb_imageblit,
1700 /* --------------------------------------------------------------------- */
1702 static struct fb_videomode __devinitdata mode800x480 = {
1712 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
1713 .vmode = FB_VMODE_NONINTERLACED
1716 static int __devinit neo_map_mmio(struct fb_info *info,
1717 struct pci_dev *dev)
1719 struct neofb_par *par = info->par;
1721 DBG("neo_map_mmio");
1723 switch (info->fix.accel) {
1724 case FB_ACCEL_NEOMAGIC_NM2070:
1725 info->fix.mmio_start = pci_resource_start(dev, 0)+
1728 case FB_ACCEL_NEOMAGIC_NM2090:
1729 case FB_ACCEL_NEOMAGIC_NM2093:
1730 info->fix.mmio_start = pci_resource_start(dev, 0)+
1733 case FB_ACCEL_NEOMAGIC_NM2160:
1734 case FB_ACCEL_NEOMAGIC_NM2097:
1735 case FB_ACCEL_NEOMAGIC_NM2200:
1736 case FB_ACCEL_NEOMAGIC_NM2230:
1737 case FB_ACCEL_NEOMAGIC_NM2360:
1738 case FB_ACCEL_NEOMAGIC_NM2380:
1739 info->fix.mmio_start = pci_resource_start(dev, 1);
1742 info->fix.mmio_start = pci_resource_start(dev, 0);
1744 info->fix.mmio_len = MMIO_SIZE;
1746 if (!request_mem_region
1747 (info->fix.mmio_start, MMIO_SIZE, "memory mapped I/O")) {
1748 printk("neofb: memory mapped IO in use\n");
1752 par->mmio_vbase = ioremap(info->fix.mmio_start, MMIO_SIZE);
1753 if (!par->mmio_vbase) {
1754 printk("neofb: unable to map memory mapped IO\n");
1755 release_mem_region(info->fix.mmio_start,
1756 info->fix.mmio_len);
1759 printk(KERN_INFO "neofb: mapped io at %p\n",
1764 static void neo_unmap_mmio(struct fb_info *info)
1766 struct neofb_par *par = info->par;
1768 DBG("neo_unmap_mmio");
1770 iounmap(par->mmio_vbase);
1771 par->mmio_vbase = NULL;
1773 release_mem_region(info->fix.mmio_start,
1774 info->fix.mmio_len);
1777 static int __devinit neo_map_video(struct fb_info *info,
1778 struct pci_dev *dev, int video_len)
1780 //unsigned long addr;
1782 DBG("neo_map_video");
1784 info->fix.smem_start = pci_resource_start(dev, 0);
1785 info->fix.smem_len = video_len;
1787 if (!request_mem_region(info->fix.smem_start, info->fix.smem_len,
1789 printk("neofb: frame buffer in use\n");
1794 ioremap(info->fix.smem_start, info->fix.smem_len);
1795 if (!info->screen_base) {
1796 printk("neofb: unable to map screen memory\n");
1797 release_mem_region(info->fix.smem_start,
1798 info->fix.smem_len);
1801 printk(KERN_INFO "neofb: mapped framebuffer at %p\n",
1805 ((struct neofb_par *)(info->par))->mtrr =
1806 mtrr_add(info->fix.smem_start, pci_resource_len(dev, 0),
1807 MTRR_TYPE_WRCOMB, 1);
1810 /* Clear framebuffer, it's all white in memory after boot */
1811 memset_io(info->screen_base, 0, info->fix.smem_len);
1813 /* Allocate Cursor drawing pad.
1814 info->fix.smem_len -= PAGE_SIZE;
1815 addr = info->fix.smem_start + info->fix.smem_len;
1816 write_le32(NEOREG_CURSMEMPOS, ((0x000f & (addr >> 10)) << 8) |
1817 ((0x0ff0 & (addr >> 10)) >> 4), par);
1818 addr = (unsigned long) info->screen_base + info->fix.smem_len;
1819 info->sprite.addr = (u8 *) addr; */
1823 static void neo_unmap_video(struct fb_info *info)
1825 DBG("neo_unmap_video");
1829 struct neofb_par *par = info->par;
1831 mtrr_del(par->mtrr, info->fix.smem_start,
1832 info->fix.smem_len);
1835 iounmap(info->screen_base);
1836 info->screen_base = NULL;
1838 release_mem_region(info->fix.smem_start,
1839 info->fix.smem_len);
1842 static int __devinit neo_scan_monitor(struct fb_info *info)
1844 struct neofb_par *par = info->par;
1845 unsigned char type, display;
1848 // Eventually we will have i2c support.
1849 info->monspecs.modedb = kmalloc(sizeof(struct fb_videomode), GFP_KERNEL);
1850 if (!info->monspecs.modedb)
1852 info->monspecs.modedb_len = 1;
1854 /* Determine the panel type */
1855 vga_wgfx(NULL, 0x09, 0x26);
1856 type = vga_rgfx(NULL, 0x21);
1857 display = vga_rgfx(NULL, 0x20);
1858 if (!par->internal_display && !par->external_display) {
1859 par->internal_display = display & 2 || !(display & 3) ? 1 : 0;
1860 par->external_display = display & 1;
1861 printk (KERN_INFO "Autodetected %s display\n",
1862 par->internal_display && par->external_display ? "simultaneous" :
1863 par->internal_display ? "internal" : "external");
1866 /* Determine panel width -- used in NeoValidMode. */
1867 w = vga_rgfx(NULL, 0x20);
1868 vga_wgfx(NULL, 0x09, 0x00);
1869 switch ((w & 0x18) >> 3) {
1872 par->NeoPanelWidth = 640;
1873 par->NeoPanelHeight = 480;
1874 memcpy(info->monspecs.modedb, &vesa_modes[3], sizeof(struct fb_videomode));
1877 par->NeoPanelWidth = 800;
1878 if (par->libretto) {
1879 par->NeoPanelHeight = 480;
1880 memcpy(info->monspecs.modedb, &mode800x480, sizeof(struct fb_videomode));
1883 par->NeoPanelHeight = 600;
1884 memcpy(info->monspecs.modedb, &vesa_modes[8], sizeof(struct fb_videomode));
1889 par->NeoPanelWidth = 1024;
1890 par->NeoPanelHeight = 768;
1891 memcpy(info->monspecs.modedb, &vesa_modes[13], sizeof(struct fb_videomode));
1894 /* 1280x1024@60 panel support needs to be added */
1896 par->NeoPanelWidth = 1280;
1897 par->NeoPanelHeight = 1024;
1898 memcpy(info->monspecs.modedb, &vesa_modes[20], sizeof(struct fb_videomode));
1902 "neofb: Only 640x480, 800x600/480 and 1024x768 panels are currently supported\n");
1907 par->NeoPanelWidth = 640;
1908 par->NeoPanelHeight = 480;
1909 memcpy(info->monspecs.modedb, &vesa_modes[3], sizeof(struct fb_videomode));
1913 printk(KERN_INFO "Panel is a %dx%d %s %s display\n",
1915 par->NeoPanelHeight,
1916 (type & 0x02) ? "color" : "monochrome",
1917 (type & 0x10) ? "TFT" : "dual scan");
1921 static int __devinit neo_init_hw(struct fb_info *info)
1923 struct neofb_par *par = info->par;
1925 int maxClock = 65000;
1926 int CursorMem = 1024;
1927 int CursorOff = 0x100;
1928 int linearSize = 1024;
1929 int maxWidth = 1024;
1930 int maxHeight = 1024;
1937 printk(KERN_DEBUG "--- Neo extended register dump ---\n");
1938 for (int w = 0; w < 0x85; w++)
1939 printk(KERN_DEBUG "CR %p: %p\n", (void *) w,
1940 (void *) vga_rcrt(NULL, w));
1941 for (int w = 0; w < 0xC7; w++)
1942 printk(KERN_DEBUG "GR %p: %p\n", (void *) w,
1943 (void *) vga_rgfx(NULL, w));
1945 switch (info->fix.accel) {
1946 case FB_ACCEL_NEOMAGIC_NM2070:
1955 case FB_ACCEL_NEOMAGIC_NM2090:
1956 case FB_ACCEL_NEOMAGIC_NM2093:
1965 case FB_ACCEL_NEOMAGIC_NM2097:
1974 case FB_ACCEL_NEOMAGIC_NM2160:
1983 case FB_ACCEL_NEOMAGIC_NM2200:
1990 maxHeight = 1024; /* ???? */
1992 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
1994 case FB_ACCEL_NEOMAGIC_NM2230:
2001 maxHeight = 1024; /* ???? */
2003 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
2005 case FB_ACCEL_NEOMAGIC_NM2360:
2012 maxHeight = 1024; /* ???? */
2014 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
2016 case FB_ACCEL_NEOMAGIC_NM2380:
2023 maxHeight = 1024; /* ???? */
2025 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
2029 info->sprite.size = CursorMem;
2030 info->sprite.scan_align = 1;
2031 info->sprite.buf_align = 1;
2032 info->sprite.flags = FB_PIXMAP_IO;
2033 info->sprite.outbuf = neofb_draw_cursor;
2035 par->maxClock = maxClock;
2036 par->cursorOff = CursorOff;
2037 return ((videoRam * 1024));
2041 static struct fb_info *__devinit neo_alloc_fb_info(struct pci_dev *dev, const struct
2044 struct fb_info *info;
2045 struct neofb_par *par;
2047 info = framebuffer_alloc(sizeof(struct neofb_par), &dev->dev);
2054 info->fix.accel = id->driver_data;
2056 mutex_init(&par->open_lock);
2057 par->pci_burst = !nopciburst;
2058 par->lcd_stretch = !nostretch;
2059 par->libretto = libretto;
2061 par->internal_display = internal;
2062 par->external_display = external;
2063 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
2065 switch (info->fix.accel) {
2066 case FB_ACCEL_NEOMAGIC_NM2070:
2067 sprintf(info->fix.id, "MagicGraph 128");
2069 case FB_ACCEL_NEOMAGIC_NM2090:
2070 sprintf(info->fix.id, "MagicGraph 128V");
2072 case FB_ACCEL_NEOMAGIC_NM2093:
2073 sprintf(info->fix.id, "MagicGraph 128ZV");
2075 case FB_ACCEL_NEOMAGIC_NM2097:
2076 sprintf(info->fix.id, "MagicGraph 128ZV+");
2078 case FB_ACCEL_NEOMAGIC_NM2160:
2079 sprintf(info->fix.id, "MagicGraph 128XD");
2081 case FB_ACCEL_NEOMAGIC_NM2200:
2082 sprintf(info->fix.id, "MagicGraph 256AV");
2083 info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
2084 FBINFO_HWACCEL_COPYAREA |
2085 FBINFO_HWACCEL_FILLRECT;
2087 case FB_ACCEL_NEOMAGIC_NM2230:
2088 sprintf(info->fix.id, "MagicGraph 256AV+");
2089 info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
2090 FBINFO_HWACCEL_COPYAREA |
2091 FBINFO_HWACCEL_FILLRECT;
2093 case FB_ACCEL_NEOMAGIC_NM2360:
2094 sprintf(info->fix.id, "MagicGraph 256ZX");
2095 info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
2096 FBINFO_HWACCEL_COPYAREA |
2097 FBINFO_HWACCEL_FILLRECT;
2099 case FB_ACCEL_NEOMAGIC_NM2380:
2100 sprintf(info->fix.id, "MagicGraph 256XL+");
2101 info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
2102 FBINFO_HWACCEL_COPYAREA |
2103 FBINFO_HWACCEL_FILLRECT;
2107 info->fix.type = FB_TYPE_PACKED_PIXELS;
2108 info->fix.type_aux = 0;
2109 info->fix.xpanstep = 0;
2110 info->fix.ypanstep = 4;
2111 info->fix.ywrapstep = 0;
2112 info->fix.accel = id->driver_data;
2114 info->fbops = &neofb_ops;
2115 info->pseudo_palette = par->palette;
2119 static void neo_free_fb_info(struct fb_info *info)
2123 * Free the colourmap
2125 fb_dealloc_cmap(&info->cmap);
2126 framebuffer_release(info);
2130 /* --------------------------------------------------------------------- */
2132 static int __devinit neofb_probe(struct pci_dev *dev,
2133 const struct pci_device_id *id)
2135 struct fb_info *info;
2136 u_int h_sync, v_sync;
2141 err = pci_enable_device(dev);
2146 info = neo_alloc_fb_info(dev, id);
2150 err = neo_map_mmio(info, dev);
2154 err = neo_scan_monitor(info);
2156 goto err_scan_monitor;
2158 video_len = neo_init_hw(info);
2159 if (video_len < 0) {
2164 err = neo_map_video(info, dev, video_len);
2168 if (!fb_find_mode(&info->var, info, mode_option, NULL, 0,
2169 info->monspecs.modedb, 16)) {
2170 printk(KERN_ERR "neofb: Unable to find usable video mode.\n");
2175 * Calculate the hsync and vsync frequencies. Note that
2176 * we split the 1e12 constant up so that we can preserve
2177 * the precision and fit the results into 32-bit registers.
2178 * (1953125000 * 512 = 1e12)
2180 h_sync = 1953125000 / info->var.pixclock;
2182 h_sync * 512 / (info->var.xres + info->var.left_margin +
2183 info->var.right_margin + info->var.hsync_len);
2185 h_sync / (info->var.yres + info->var.upper_margin +
2186 info->var.lower_margin + info->var.vsync_len);
2188 printk(KERN_INFO "neofb v" NEOFB_VERSION
2189 ": %dkB VRAM, using %dx%d, %d.%03dkHz, %dHz\n",
2190 info->fix.smem_len >> 10, info->var.xres,
2191 info->var.yres, h_sync / 1000, h_sync % 1000, v_sync);
2193 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
2196 err = register_framebuffer(info);
2200 printk(KERN_INFO "fb%d: %s frame buffer device\n",
2201 info->node, info->fix.id);
2206 pci_set_drvdata(dev, info);
2210 fb_dealloc_cmap(&info->cmap);
2212 neo_unmap_video(info);
2214 fb_destroy_modedb(info->monspecs.modedb);
2216 neo_unmap_mmio(info);
2218 neo_free_fb_info(info);
2222 static void __devexit neofb_remove(struct pci_dev *dev)
2224 struct fb_info *info = pci_get_drvdata(dev);
2226 DBG("neofb_remove");
2230 * If unregister_framebuffer fails, then
2231 * we will be leaving hooks that could cause
2232 * oopsen laying around.
2234 if (unregister_framebuffer(info))
2236 "neofb: danger danger! Oopsen imminent!\n");
2238 neo_unmap_video(info);
2239 fb_destroy_modedb(info->monspecs.modedb);
2240 neo_unmap_mmio(info);
2241 neo_free_fb_info(info);
2244 * Ensure that the driver data is no longer
2247 pci_set_drvdata(dev, NULL);
2251 static struct pci_device_id neofb_devices[] = {
2252 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2070,
2253 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2070},
2255 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2090,
2256 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2090},
2258 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2093,
2259 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2093},
2261 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2097,
2262 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2097},
2264 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2160,
2265 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2160},
2267 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2200,
2268 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2200},
2270 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2230,
2271 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2230},
2273 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2360,
2274 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2360},
2276 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2380,
2277 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2380},
2279 {0, 0, 0, 0, 0, 0, 0}
2282 MODULE_DEVICE_TABLE(pci, neofb_devices);
2284 static struct pci_driver neofb_driver = {
2286 .id_table = neofb_devices,
2287 .probe = neofb_probe,
2288 .remove = __devexit_p(neofb_remove)
2291 /* ************************* init in-kernel code ************************** */
2294 static int __init neofb_setup(char *options)
2300 if (!options || !*options)
2303 while ((this_opt = strsep(&options, ",")) != NULL) {
2307 if (!strncmp(this_opt, "internal", 8))
2309 else if (!strncmp(this_opt, "external", 8))
2311 else if (!strncmp(this_opt, "nostretch", 9))
2313 else if (!strncmp(this_opt, "nopciburst", 10))
2315 else if (!strncmp(this_opt, "libretto", 8))
2318 mode_option = this_opt;
2324 static int __init neofb_init(void)
2327 char *option = NULL;
2329 if (fb_get_options("neofb", &option))
2331 neofb_setup(option);
2333 return pci_register_driver(&neofb_driver);
2336 module_init(neofb_init);
2339 static void __exit neofb_exit(void)
2341 pci_unregister_driver(&neofb_driver);
2344 module_exit(neofb_exit);