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/config.h>
58 #include <linux/module.h>
59 #include <linux/kernel.h>
60 #include <linux/errno.h>
61 #include <linux/string.h>
63 #include <linux/tty.h>
64 #include <linux/slab.h>
65 #include <linux/delay.h>
67 #include <linux/pci.h>
68 #include <linux/init.h>
70 #include <linux/toshiba.h>
71 extern int tosh_smm(SMMRegisters *regs);
76 #include <asm/pgtable.h>
77 #include <asm/system.h>
78 #include <asm/uaccess.h>
84 #include <video/vga.h>
85 #include <video/neomagic.h>
87 #define NEOFB_VERSION "0.4.2"
89 /* --------------------------------------------------------------------- */
95 static int nopciburst;
96 static char *mode_option __devinitdata = NULL;
100 MODULE_AUTHOR("(c) 2001-2002 Denis Oliver Kropp <dok@convergence.de>");
101 MODULE_LICENSE("GPL");
102 MODULE_DESCRIPTION("FBDev driver for NeoMagic PCI Chips");
103 module_param(internal, bool, 0);
104 MODULE_PARM_DESC(internal, "Enable output on internal LCD Display.");
105 module_param(external, bool, 0);
106 MODULE_PARM_DESC(external, "Enable output on external CRT.");
107 module_param(libretto, bool, 0);
108 MODULE_PARM_DESC(libretto, "Force Libretto 100/110 800x480 LCD.");
109 module_param(nostretch, bool, 0);
110 MODULE_PARM_DESC(nostretch,
111 "Disable stretching of modes smaller than LCD.");
112 module_param(nopciburst, bool, 0);
113 MODULE_PARM_DESC(nopciburst, "Disable PCI burst mode.");
114 module_param(mode_option, charp, 0);
115 MODULE_PARM_DESC(mode_option, "Preferred video mode ('640x480-8@60', etc)");
120 /* --------------------------------------------------------------------- */
122 static biosMode bios8[] = {
131 static biosMode bios16[] = {
140 static biosMode bios24[] = {
146 #ifdef NO_32BIT_SUPPORT_YET
147 /* FIXME: guessed values, wrong */
148 static biosMode bios32[] = {
155 static inline void write_le32(int regindex, u32 val, const struct neofb_par *par)
157 writel(val, par->neo2200 + par->cursorOff + regindex);
160 static int neoFindMode(int xres, int yres, int depth)
168 size = sizeof(bios8) / sizeof(biosMode);
172 size = sizeof(bios16) / sizeof(biosMode);
176 size = sizeof(bios24) / sizeof(biosMode);
179 #ifdef NO_32BIT_SUPPORT_YET
181 size = sizeof(bios32) / sizeof(biosMode);
189 for (i = 0; i < size; i++) {
190 if (xres <= mode[i].x_res) {
191 xres_s = mode[i].x_res;
192 for (; i < size; i++) {
193 if (mode[i].x_res != xres_s)
194 return mode[i - 1].mode;
195 if (yres <= mode[i].y_res)
200 return mode[size - 1].mode;
206 * Determine the closest clock frequency to the one requested.
208 #define REF_FREQ 0xe517 /* 14.31818 in 20.12 fixed point */
213 static void neoCalcVCLK(const struct fb_info *info,
214 struct neofb_par *par, long freq)
217 int n_best = 0, d_best = 0, f_best = 0;
218 long f_best_diff = (0x7ffff << 12); /* 20.12 */
219 long f_target = (freq << 12) / 1000; /* 20.12 */
221 for (f = 0; f <= MAX_F; f++)
222 for (n = 0; n <= MAX_N; n++)
223 for (d = 0; d <= MAX_D; d++) {
224 long f_out; /* 20.12 */
225 long f_diff; /* 20.12 */
228 ((((n + 1) << 12) / ((d +
232 f_diff = abs(f_out - f_target);
233 if (f_diff < f_best_diff) {
234 f_best_diff = f_diff;
241 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
242 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
243 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
244 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
245 /* NOT_DONE: We are trying the full range of the 2200 clock.
246 We should be able to try n up to 2047 */
247 par->VCLK3NumeratorLow = n_best;
248 par->VCLK3NumeratorHigh = (f_best << 7);
250 par->VCLK3NumeratorLow = n_best | (f_best << 7);
252 par->VCLK3Denominator = d_best;
255 printk("neoVCLK: f:%d NumLow=%d NumHi=%d Den=%d Df=%d\n",
257 par->VCLK3NumeratorLow,
258 par->VCLK3NumeratorHigh,
259 par->VCLK3Denominator, f_best_diff >> 12);
265 * Handle the initialization, etc. of a screen.
266 * Return FALSE on failure.
269 static int vgaHWInit(const struct fb_var_screeninfo *var,
270 const struct fb_info *info,
271 struct neofb_par *par, struct xtimings *timings)
273 par->MiscOutReg = 0x23;
275 if (!(timings->sync & FB_SYNC_HOR_HIGH_ACT))
276 par->MiscOutReg |= 0x40;
278 if (!(timings->sync & FB_SYNC_VERT_HIGH_ACT))
279 par->MiscOutReg |= 0x80;
284 par->Sequencer[0] = 0x00;
285 par->Sequencer[1] = 0x01;
286 par->Sequencer[2] = 0x0F;
287 par->Sequencer[3] = 0x00; /* Font select */
288 par->Sequencer[4] = 0x0E; /* Misc */
293 par->CRTC[0] = (timings->HTotal >> 3) - 5;
294 par->CRTC[1] = (timings->HDisplay >> 3) - 1;
295 par->CRTC[2] = (timings->HDisplay >> 3) - 1;
296 par->CRTC[3] = (((timings->HTotal >> 3) - 1) & 0x1F) | 0x80;
297 par->CRTC[4] = (timings->HSyncStart >> 3);
298 par->CRTC[5] = ((((timings->HTotal >> 3) - 1) & 0x20) << 2)
299 | (((timings->HSyncEnd >> 3)) & 0x1F);
300 par->CRTC[6] = (timings->VTotal - 2) & 0xFF;
301 par->CRTC[7] = (((timings->VTotal - 2) & 0x100) >> 8)
302 | (((timings->VDisplay - 1) & 0x100) >> 7)
303 | ((timings->VSyncStart & 0x100) >> 6)
304 | (((timings->VDisplay - 1) & 0x100) >> 5)
305 | 0x10 | (((timings->VTotal - 2) & 0x200) >> 4)
306 | (((timings->VDisplay - 1) & 0x200) >> 3)
307 | ((timings->VSyncStart & 0x200) >> 2);
309 par->CRTC[9] = (((timings->VDisplay - 1) & 0x200) >> 4) | 0x40;
311 if (timings->dblscan)
312 par->CRTC[9] |= 0x80;
314 par->CRTC[10] = 0x00;
315 par->CRTC[11] = 0x00;
316 par->CRTC[12] = 0x00;
317 par->CRTC[13] = 0x00;
318 par->CRTC[14] = 0x00;
319 par->CRTC[15] = 0x00;
320 par->CRTC[16] = timings->VSyncStart & 0xFF;
321 par->CRTC[17] = (timings->VSyncEnd & 0x0F) | 0x20;
322 par->CRTC[18] = (timings->VDisplay - 1) & 0xFF;
323 par->CRTC[19] = var->xres_virtual >> 4;
324 par->CRTC[20] = 0x00;
325 par->CRTC[21] = (timings->VDisplay - 1) & 0xFF;
326 par->CRTC[22] = (timings->VTotal - 1) & 0xFF;
327 par->CRTC[23] = 0xC3;
328 par->CRTC[24] = 0xFF;
331 * are these unnecessary?
332 * vgaHWHBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
333 * vgaHWVBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
337 * Graphics Display Controller
339 par->Graphics[0] = 0x00;
340 par->Graphics[1] = 0x00;
341 par->Graphics[2] = 0x00;
342 par->Graphics[3] = 0x00;
343 par->Graphics[4] = 0x00;
344 par->Graphics[5] = 0x40;
345 par->Graphics[6] = 0x05; /* only map 64k VGA memory !!!! */
346 par->Graphics[7] = 0x0F;
347 par->Graphics[8] = 0xFF;
350 par->Attribute[0] = 0x00; /* standard colormap translation */
351 par->Attribute[1] = 0x01;
352 par->Attribute[2] = 0x02;
353 par->Attribute[3] = 0x03;
354 par->Attribute[4] = 0x04;
355 par->Attribute[5] = 0x05;
356 par->Attribute[6] = 0x06;
357 par->Attribute[7] = 0x07;
358 par->Attribute[8] = 0x08;
359 par->Attribute[9] = 0x09;
360 par->Attribute[10] = 0x0A;
361 par->Attribute[11] = 0x0B;
362 par->Attribute[12] = 0x0C;
363 par->Attribute[13] = 0x0D;
364 par->Attribute[14] = 0x0E;
365 par->Attribute[15] = 0x0F;
366 par->Attribute[16] = 0x41;
367 par->Attribute[17] = 0xFF;
368 par->Attribute[18] = 0x0F;
369 par->Attribute[19] = 0x00;
370 par->Attribute[20] = 0x00;
374 static void vgaHWLock(struct vgastate *state)
376 /* Protect CRTC[0-7] */
377 vga_wcrt(state->vgabase, 0x11, vga_rcrt(state->vgabase, 0x11) | 0x80);
380 static void vgaHWUnlock(void)
382 /* Unprotect CRTC[0-7] */
383 vga_wcrt(NULL, 0x11, vga_rcrt(NULL, 0x11) & ~0x80);
386 static void neoLock(struct vgastate *state)
388 vga_wgfx(state->vgabase, 0x09, 0x00);
392 static void neoUnlock(void)
395 vga_wgfx(NULL, 0x09, 0x26);
399 * VGA Palette management
401 static int paletteEnabled = 0;
403 static inline void VGAenablePalette(void)
405 vga_r(NULL, VGA_IS1_RC);
406 vga_w(NULL, VGA_ATT_W, 0x00);
410 static inline void VGAdisablePalette(void)
412 vga_r(NULL, VGA_IS1_RC);
413 vga_w(NULL, VGA_ATT_W, 0x20);
417 static inline void VGAwATTR(u8 index, u8 value)
424 vga_r(NULL, VGA_IS1_RC);
425 vga_wattr(NULL, index, value);
428 static void vgaHWProtect(int on)
434 * Turn off screen and disable sequencer.
436 tmp = vga_rseq(NULL, 0x01);
437 vga_wseq(NULL, 0x00, 0x01); /* Synchronous Reset */
438 vga_wseq(NULL, 0x01, tmp | 0x20); /* disable the display */
443 * Reenable sequencer, then turn on screen.
445 tmp = vga_rseq(NULL, 0x01);
446 vga_wseq(NULL, 0x01, tmp & ~0x20); /* reenable display */
447 vga_wseq(NULL, 0x00, 0x03); /* clear synchronousreset */
453 static void vgaHWRestore(const struct fb_info *info,
454 const struct neofb_par *par)
458 vga_w(NULL, VGA_MIS_W, par->MiscOutReg);
460 for (i = 1; i < 5; i++)
461 vga_wseq(NULL, i, par->Sequencer[i]);
463 /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 or CRTC[17] */
464 vga_wcrt(NULL, 17, par->CRTC[17] & ~0x80);
466 for (i = 0; i < 25; i++)
467 vga_wcrt(NULL, i, par->CRTC[i]);
469 for (i = 0; i < 9; i++)
470 vga_wgfx(NULL, i, par->Graphics[i]);
474 for (i = 0; i < 21; i++)
475 VGAwATTR(i, par->Attribute[i]);
481 /* -------------------- Hardware specific routines ------------------------- */
484 * Hardware Acceleration for Neo2200+
486 static inline int neo2200_sync(struct fb_info *info)
488 struct neofb_par *par = info->par;
491 while (readl(&par->neo2200->bltStat) & 1)
496 static inline void neo2200_wait_fifo(struct fb_info *info,
497 int requested_fifo_space)
499 // ndev->neo.waitfifo_calls++;
500 // ndev->neo.waitfifo_sum += requested_fifo_space;
502 /* FIXME: does not work
503 if (neo_fifo_space < requested_fifo_space)
505 neo_fifo_waitcycles++;
509 neo_fifo_space = (neo2200->bltStat >> 8);
510 if (neo_fifo_space >= requested_fifo_space)
516 neo_fifo_cache_hits++;
519 neo_fifo_space -= requested_fifo_space;
525 static inline void neo2200_accel_init(struct fb_info *info,
526 struct fb_var_screeninfo *var)
528 struct neofb_par *par = info->par;
529 Neo2200 __iomem *neo2200 = par->neo2200;
534 switch (var->bits_per_pixel) {
536 bltMod = NEO_MODE1_DEPTH8;
537 pitch = var->xres_virtual;
541 bltMod = NEO_MODE1_DEPTH16;
542 pitch = var->xres_virtual * 2;
545 bltMod = NEO_MODE1_DEPTH24;
546 pitch = var->xres_virtual * 3;
550 "neofb: neo2200_accel_init: unexpected bits per pixel!\n");
554 writel(bltMod << 16, &neo2200->bltStat);
555 writel((pitch << 16) | pitch, &neo2200->pitch);
558 /* --------------------------------------------------------------------- */
561 neofb_open(struct fb_info *info, int user)
563 struct neofb_par *par = info->par;
564 int cnt = atomic_read(&par->ref_count);
567 memset(&par->state, 0, sizeof(struct vgastate));
568 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
569 save_vga(&par->state);
571 atomic_inc(&par->ref_count);
576 neofb_release(struct fb_info *info, int user)
578 struct neofb_par *par = info->par;
579 int cnt = atomic_read(&par->ref_count);
584 restore_vga(&par->state);
586 atomic_dec(&par->ref_count);
591 neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
593 struct neofb_par *par = info->par;
594 unsigned int pixclock = var->pixclock;
595 struct xtimings timings;
599 DBG("neofb_check_var");
602 pixclock = 10000; /* 10ns = 100MHz */
603 timings.pixclock = 1000000000 / pixclock;
604 if (timings.pixclock < 1)
605 timings.pixclock = 1;
607 if (timings.pixclock > par->maxClock)
610 timings.dblscan = var->vmode & FB_VMODE_DOUBLE;
611 timings.interlaced = var->vmode & FB_VMODE_INTERLACED;
612 timings.HDisplay = var->xres;
613 timings.HSyncStart = timings.HDisplay + var->right_margin;
614 timings.HSyncEnd = timings.HSyncStart + var->hsync_len;
615 timings.HTotal = timings.HSyncEnd + var->left_margin;
616 timings.VDisplay = var->yres;
617 timings.VSyncStart = timings.VDisplay + var->lower_margin;
618 timings.VSyncEnd = timings.VSyncStart + var->vsync_len;
619 timings.VTotal = timings.VSyncEnd + var->upper_margin;
620 timings.sync = var->sync;
622 /* Is the mode larger than the LCD panel? */
623 if (par->internal_display &&
624 ((var->xres > par->NeoPanelWidth) ||
625 (var->yres > par->NeoPanelHeight))) {
627 "Mode (%dx%d) larger than the LCD panel (%dx%d)\n",
628 var->xres, var->yres, par->NeoPanelWidth,
629 par->NeoPanelHeight);
633 /* Is the mode one of the acceptable sizes? */
634 if (!par->internal_display)
639 if (var->yres == 1024)
643 if (var->yres == 768)
647 if (var->yres == (par->libretto ? 480 : 600))
651 if (var->yres == 480)
659 "Mode (%dx%d) won't display properly on LCD\n",
660 var->xres, var->yres);
664 var->red.msb_right = 0;
665 var->green.msb_right = 0;
666 var->blue.msb_right = 0;
668 switch (var->bits_per_pixel) {
669 case 8: /* PSEUDOCOLOUR, 256 */
670 var->transp.offset = 0;
671 var->transp.length = 0;
674 var->green.offset = 0;
675 var->green.length = 8;
676 var->blue.offset = 0;
677 var->blue.length = 8;
680 case 16: /* DIRECTCOLOUR, 64k */
681 var->transp.offset = 0;
682 var->transp.length = 0;
683 var->red.offset = 11;
685 var->green.offset = 5;
686 var->green.length = 6;
687 var->blue.offset = 0;
688 var->blue.length = 5;
691 case 24: /* TRUECOLOUR, 16m */
692 var->transp.offset = 0;
693 var->transp.length = 0;
694 var->red.offset = 16;
696 var->green.offset = 8;
697 var->green.length = 8;
698 var->blue.offset = 0;
699 var->blue.length = 8;
702 #ifdef NO_32BIT_SUPPORT_YET
703 case 32: /* TRUECOLOUR, 16m */
704 var->transp.offset = 24;
705 var->transp.length = 8;
706 var->red.offset = 16;
708 var->green.offset = 8;
709 var->green.length = 8;
710 var->blue.offset = 0;
711 var->blue.length = 8;
715 printk(KERN_WARNING "neofb: no support for %dbpp\n",
716 var->bits_per_pixel);
720 vramlen = info->fix.smem_len;
721 if (vramlen > 4 * 1024 * 1024)
722 vramlen = 4 * 1024 * 1024;
724 if (var->yres_virtual < var->yres)
725 var->yres_virtual = var->yres;
726 if (var->xres_virtual < var->xres)
727 var->xres_virtual = var->xres;
729 memlen = var->xres_virtual * var->bits_per_pixel * var->yres_virtual >> 3;
731 if (memlen > vramlen) {
732 var->yres_virtual = vramlen * 8 / (var->xres_virtual *
733 var->bits_per_pixel);
734 memlen = var->xres_virtual * var->bits_per_pixel *
735 var->yres_virtual / 8;
738 /* we must round yres/xres down, we already rounded y/xres_virtual up
739 if it was possible. We should return -EINVAL, but I disagree */
740 if (var->yres_virtual < var->yres)
741 var->yres = var->yres_virtual;
742 if (var->xres_virtual < var->xres)
743 var->xres = var->xres_virtual;
744 if (var->xoffset + var->xres > var->xres_virtual)
745 var->xoffset = var->xres_virtual - var->xres;
746 if (var->yoffset + var->yres > var->yres_virtual)
747 var->yoffset = var->yres_virtual - var->yres;
753 if (var->bits_per_pixel >= 24 || !par->neo2200)
754 var->accel_flags &= ~FB_ACCELF_TEXT;
758 static int neofb_set_par(struct fb_info *info)
760 struct neofb_par *par = info->par;
761 struct xtimings timings;
765 int hoffset, voffset;
767 DBG("neofb_set_par");
771 vgaHWProtect(1); /* Blank the screen */
773 timings.dblscan = info->var.vmode & FB_VMODE_DOUBLE;
774 timings.interlaced = info->var.vmode & FB_VMODE_INTERLACED;
775 timings.HDisplay = info->var.xres;
776 timings.HSyncStart = timings.HDisplay + info->var.right_margin;
777 timings.HSyncEnd = timings.HSyncStart + info->var.hsync_len;
778 timings.HTotal = timings.HSyncEnd + info->var.left_margin;
779 timings.VDisplay = info->var.yres;
780 timings.VSyncStart = timings.VDisplay + info->var.lower_margin;
781 timings.VSyncEnd = timings.VSyncStart + info->var.vsync_len;
782 timings.VTotal = timings.VSyncEnd + info->var.upper_margin;
783 timings.sync = info->var.sync;
784 timings.pixclock = PICOS2KHZ(info->var.pixclock);
786 if (timings.pixclock < 1)
787 timings.pixclock = 1;
790 * This will allocate the datastructure and initialize all of the
791 * generic VGA registers.
794 if (vgaHWInit(&info->var, info, par, &timings))
798 * The default value assigned by vgaHW.c is 0x41, but this does
799 * not work for NeoMagic.
801 par->Attribute[16] = 0x01;
803 switch (info->var.bits_per_pixel) {
805 par->CRTC[0x13] = info->var.xres_virtual >> 3;
806 par->ExtCRTOffset = info->var.xres_virtual >> 11;
807 par->ExtColorModeSelect = 0x11;
810 par->CRTC[0x13] = info->var.xres_virtual >> 2;
811 par->ExtCRTOffset = info->var.xres_virtual >> 10;
812 par->ExtColorModeSelect = 0x13;
815 par->CRTC[0x13] = (info->var.xres_virtual * 3) >> 3;
816 par->ExtCRTOffset = (info->var.xres_virtual * 3) >> 11;
817 par->ExtColorModeSelect = 0x14;
819 #ifdef NO_32BIT_SUPPORT_YET
820 case 32: /* FIXME: guessed values */
821 par->CRTC[0x13] = info->var.xres_virtual >> 1;
822 par->ExtCRTOffset = info->var.xres_virtual >> 9;
823 par->ExtColorModeSelect = 0x15;
830 par->ExtCRTDispAddr = 0x10;
832 /* Vertical Extension */
833 par->VerticalExt = (((timings.VTotal - 2) & 0x400) >> 10)
834 | (((timings.VDisplay - 1) & 0x400) >> 9)
835 | (((timings.VSyncStart) & 0x400) >> 8)
836 | (((timings.VSyncStart) & 0x400) >> 7);
838 /* Fast write bursts on unless disabled. */
840 par->SysIfaceCntl1 = 0x30;
842 par->SysIfaceCntl1 = 0x00;
844 par->SysIfaceCntl2 = 0xc0; /* VESA Bios sets this to 0x80! */
846 /* Initialize: by default, we want display config register to be read */
847 par->PanelDispCntlRegRead = 1;
849 /* Enable any user specified display devices. */
850 par->PanelDispCntlReg1 = 0x00;
851 if (par->internal_display)
852 par->PanelDispCntlReg1 |= 0x02;
853 if (par->external_display)
854 par->PanelDispCntlReg1 |= 0x01;
856 /* If the user did not specify any display devices, then... */
857 if (par->PanelDispCntlReg1 == 0x00) {
858 /* Default to internal (i.e., LCD) only. */
859 par->PanelDispCntlReg1 = vga_rgfx(NULL, 0x20) & 0x03;
862 /* If we are using a fixed mode, then tell the chip we are. */
863 switch (info->var.xres) {
865 par->PanelDispCntlReg1 |= 0x60;
868 par->PanelDispCntlReg1 |= 0x40;
871 par->PanelDispCntlReg1 |= 0x20;
878 /* Setup shadow register locking. */
879 switch (par->PanelDispCntlReg1 & 0x03) {
880 case 0x01: /* External CRT only mode: */
881 par->GeneralLockReg = 0x00;
882 /* We need to program the VCLK for external display only mode. */
883 par->ProgramVCLK = 1;
885 case 0x02: /* Internal LCD only mode: */
886 case 0x03: /* Simultaneous internal/external (LCD/CRT) mode: */
887 par->GeneralLockReg = 0x01;
888 /* Don't program the VCLK when using the LCD. */
889 par->ProgramVCLK = 0;
894 * If the screen is to be stretched, turn on stretching for the
897 * OPTION_LCD_STRETCH means stretching should be turned off!
899 par->PanelDispCntlReg2 = 0x00;
900 par->PanelDispCntlReg3 = 0x00;
902 if (par->lcd_stretch && (par->PanelDispCntlReg1 == 0x02) && /* LCD only */
903 (info->var.xres != par->NeoPanelWidth)) {
904 switch (info->var.xres) {
905 case 320: /* Needs testing. KEM -- 24 May 98 */
906 case 400: /* Needs testing. KEM -- 24 May 98 */
911 par->PanelDispCntlReg2 |= 0xC6;
915 /* No stretching in these modes. */
921 * If the screen is to be centerd, turn on the centering for the
924 par->PanelVertCenterReg1 = 0x00;
925 par->PanelVertCenterReg2 = 0x00;
926 par->PanelVertCenterReg3 = 0x00;
927 par->PanelVertCenterReg4 = 0x00;
928 par->PanelVertCenterReg5 = 0x00;
929 par->PanelHorizCenterReg1 = 0x00;
930 par->PanelHorizCenterReg2 = 0x00;
931 par->PanelHorizCenterReg3 = 0x00;
932 par->PanelHorizCenterReg4 = 0x00;
933 par->PanelHorizCenterReg5 = 0x00;
936 if (par->PanelDispCntlReg1 & 0x02) {
937 if (info->var.xres == par->NeoPanelWidth) {
939 * No centering required when the requested display width
940 * equals the panel width.
943 par->PanelDispCntlReg2 |= 0x01;
944 par->PanelDispCntlReg3 |= 0x10;
946 /* Calculate the horizontal and vertical offsets. */
949 ((par->NeoPanelWidth -
950 info->var.xres) >> 4) - 1;
952 ((par->NeoPanelHeight -
953 info->var.yres) >> 1) - 2;
955 /* Stretched modes cannot be centered. */
960 switch (info->var.xres) {
961 case 320: /* Needs testing. KEM -- 24 May 98 */
962 par->PanelHorizCenterReg3 = hoffset;
963 par->PanelVertCenterReg2 = voffset;
965 case 400: /* Needs testing. KEM -- 24 May 98 */
966 par->PanelHorizCenterReg4 = hoffset;
967 par->PanelVertCenterReg1 = voffset;
970 par->PanelHorizCenterReg1 = hoffset;
971 par->PanelVertCenterReg3 = voffset;
974 par->PanelHorizCenterReg2 = hoffset;
975 par->PanelVertCenterReg4 = voffset;
978 par->PanelHorizCenterReg5 = hoffset;
979 par->PanelVertCenterReg5 = voffset;
983 /* No centering in these modes. */
990 neoFindMode(info->var.xres, info->var.yres,
991 info->var.bits_per_pixel);
994 * Calculate the VCLK that most closely matches the requested dot
997 neoCalcVCLK(info, par, timings.pixclock);
999 /* Since we program the clocks ourselves, always use VCLK3. */
1000 par->MiscOutReg |= 0x0C;
1002 /* alread unlocked above */
1003 /* BOGUS vga_wgfx(NULL, 0x09, 0x26); */
1005 /* don't know what this is, but it's 0 from bootup anyway */
1006 vga_wgfx(NULL, 0x15, 0x00);
1008 /* was set to 0x01 by my bios in text and vesa modes */
1009 vga_wgfx(NULL, 0x0A, par->GeneralLockReg);
1012 * The color mode needs to be set before calling vgaHWRestore
1013 * to ensure the DAC is initialized properly.
1015 * NOTE: Make sure we don't change bits make sure we don't change
1016 * any reserved bits.
1018 temp = vga_rgfx(NULL, 0x90);
1019 switch (info->fix.accel) {
1020 case FB_ACCEL_NEOMAGIC_NM2070:
1021 temp &= 0xF0; /* Save bits 7:4 */
1022 temp |= (par->ExtColorModeSelect & ~0xF0);
1024 case FB_ACCEL_NEOMAGIC_NM2090:
1025 case FB_ACCEL_NEOMAGIC_NM2093:
1026 case FB_ACCEL_NEOMAGIC_NM2097:
1027 case FB_ACCEL_NEOMAGIC_NM2160:
1028 case FB_ACCEL_NEOMAGIC_NM2200:
1029 case FB_ACCEL_NEOMAGIC_NM2230:
1030 case FB_ACCEL_NEOMAGIC_NM2360:
1031 case FB_ACCEL_NEOMAGIC_NM2380:
1032 temp &= 0x70; /* Save bits 6:4 */
1033 temp |= (par->ExtColorModeSelect & ~0x70);
1037 vga_wgfx(NULL, 0x90, temp);
1040 * In some rare cases a lockup might occur if we don't delay
1041 * here. (Reported by Miles Lane)
1046 * Disable horizontal and vertical graphics and text expansions so
1047 * that vgaHWRestore works properly.
1049 temp = vga_rgfx(NULL, 0x25);
1051 vga_wgfx(NULL, 0x25, temp);
1054 * Sleep for 200ms to make sure that the two operations above have
1055 * had time to take effect.
1060 * This function handles restoring the generic VGA registers. */
1061 vgaHWRestore(info, par);
1063 /* linear colormap for non palettized modes */
1064 switch (info->var.bits_per_pixel) {
1066 /* PseudoColor, 256 */
1067 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1070 /* TrueColor, 64k */
1071 info->fix.visual = FB_VISUAL_TRUECOLOR;
1073 for (i = 0; i < 64; i++) {
1076 outb(i << 1, 0x3c9);
1078 outb(i << 1, 0x3c9);
1082 #ifdef NO_32BIT_SUPPORT_YET
1085 /* TrueColor, 16m */
1086 info->fix.visual = FB_VISUAL_TRUECOLOR;
1088 for (i = 0; i < 256; i++) {
1098 vga_wgfx(NULL, 0x0E, par->ExtCRTDispAddr);
1099 vga_wgfx(NULL, 0x0F, par->ExtCRTOffset);
1100 temp = vga_rgfx(NULL, 0x10);
1101 temp &= 0x0F; /* Save bits 3:0 */
1102 temp |= (par->SysIfaceCntl1 & ~0x0F); /* VESA Bios sets bit 1! */
1103 vga_wgfx(NULL, 0x10, temp);
1105 vga_wgfx(NULL, 0x11, par->SysIfaceCntl2);
1106 vga_wgfx(NULL, 0x15, 0 /*par->SingleAddrPage */ );
1107 vga_wgfx(NULL, 0x16, 0 /*par->DualAddrPage */ );
1109 temp = vga_rgfx(NULL, 0x20);
1110 switch (info->fix.accel) {
1111 case FB_ACCEL_NEOMAGIC_NM2070:
1112 temp &= 0xFC; /* Save bits 7:2 */
1113 temp |= (par->PanelDispCntlReg1 & ~0xFC);
1115 case FB_ACCEL_NEOMAGIC_NM2090:
1116 case FB_ACCEL_NEOMAGIC_NM2093:
1117 case FB_ACCEL_NEOMAGIC_NM2097:
1118 case FB_ACCEL_NEOMAGIC_NM2160:
1119 temp &= 0xDC; /* Save bits 7:6,4:2 */
1120 temp |= (par->PanelDispCntlReg1 & ~0xDC);
1122 case FB_ACCEL_NEOMAGIC_NM2200:
1123 case FB_ACCEL_NEOMAGIC_NM2230:
1124 case FB_ACCEL_NEOMAGIC_NM2360:
1125 case FB_ACCEL_NEOMAGIC_NM2380:
1126 temp &= 0x98; /* Save bits 7,4:3 */
1127 temp |= (par->PanelDispCntlReg1 & ~0x98);
1130 vga_wgfx(NULL, 0x20, temp);
1132 temp = vga_rgfx(NULL, 0x25);
1133 temp &= 0x38; /* Save bits 5:3 */
1134 temp |= (par->PanelDispCntlReg2 & ~0x38);
1135 vga_wgfx(NULL, 0x25, temp);
1137 if (info->fix.accel != FB_ACCEL_NEOMAGIC_NM2070) {
1138 temp = vga_rgfx(NULL, 0x30);
1139 temp &= 0xEF; /* Save bits 7:5 and bits 3:0 */
1140 temp |= (par->PanelDispCntlReg3 & ~0xEF);
1141 vga_wgfx(NULL, 0x30, temp);
1144 vga_wgfx(NULL, 0x28, par->PanelVertCenterReg1);
1145 vga_wgfx(NULL, 0x29, par->PanelVertCenterReg2);
1146 vga_wgfx(NULL, 0x2a, par->PanelVertCenterReg3);
1148 if (info->fix.accel != FB_ACCEL_NEOMAGIC_NM2070) {
1149 vga_wgfx(NULL, 0x32, par->PanelVertCenterReg4);
1150 vga_wgfx(NULL, 0x33, par->PanelHorizCenterReg1);
1151 vga_wgfx(NULL, 0x34, par->PanelHorizCenterReg2);
1152 vga_wgfx(NULL, 0x35, par->PanelHorizCenterReg3);
1155 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2160)
1156 vga_wgfx(NULL, 0x36, par->PanelHorizCenterReg4);
1158 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
1159 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
1160 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
1161 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
1162 vga_wgfx(NULL, 0x36, par->PanelHorizCenterReg4);
1163 vga_wgfx(NULL, 0x37, par->PanelVertCenterReg5);
1164 vga_wgfx(NULL, 0x38, par->PanelHorizCenterReg5);
1169 /* Program VCLK3 if needed. */
1170 if (par->ProgramVCLK && ((vga_rgfx(NULL, 0x9B) != par->VCLK3NumeratorLow)
1171 || (vga_rgfx(NULL, 0x9F) != par->VCLK3Denominator)
1172 || (clock_hi && ((vga_rgfx(NULL, 0x8F) & ~0x0f)
1173 != (par->VCLK3NumeratorHigh &
1175 vga_wgfx(NULL, 0x9B, par->VCLK3NumeratorLow);
1177 temp = vga_rgfx(NULL, 0x8F);
1178 temp &= 0x0F; /* Save bits 3:0 */
1179 temp |= (par->VCLK3NumeratorHigh & ~0x0F);
1180 vga_wgfx(NULL, 0x8F, temp);
1182 vga_wgfx(NULL, 0x9F, par->VCLK3Denominator);
1186 vga_wcrt(NULL, 0x23, par->biosMode);
1188 vga_wgfx(NULL, 0x93, 0xc0); /* Gives 5x faster framebuffer writes !!! */
1190 /* Program vertical extension register */
1191 if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
1192 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
1193 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
1194 info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
1195 vga_wcrt(NULL, 0x70, par->VerticalExt);
1198 vgaHWProtect(0); /* Turn on screen */
1200 /* Calling this also locks offset registers required in update_start */
1201 neoLock(&par->state);
1203 info->fix.line_length =
1204 info->var.xres_virtual * (info->var.bits_per_pixel >> 3);
1206 switch (info->fix.accel) {
1207 case FB_ACCEL_NEOMAGIC_NM2200:
1208 case FB_ACCEL_NEOMAGIC_NM2230:
1209 case FB_ACCEL_NEOMAGIC_NM2360:
1210 case FB_ACCEL_NEOMAGIC_NM2380:
1211 neo2200_accel_init(info, &info->var);
1219 static void neofb_update_start(struct fb_info *info,
1220 struct fb_var_screeninfo *var)
1222 struct neofb_par *par = info->par;
1223 struct vgastate *state = &par->state;
1224 int oldExtCRTDispAddr;
1227 DBG("neofb_update_start");
1229 Base = (var->yoffset * var->xres_virtual + var->xoffset) >> 2;
1230 Base *= (var->bits_per_pixel + 7) / 8;
1235 * These are the generic starting address registers.
1237 vga_wcrt(state->vgabase, 0x0C, (Base & 0x00FF00) >> 8);
1238 vga_wcrt(state->vgabase, 0x0D, (Base & 0x00FF));
1241 * Make sure we don't clobber some other bits that might already
1242 * have been set. NOTE: NM2200 has a writable bit 3, but it shouldn't
1245 oldExtCRTDispAddr = vga_rgfx(NULL, 0x0E);
1246 vga_wgfx(state->vgabase, 0x0E, (((Base >> 16) & 0x0f) | (oldExtCRTDispAddr & 0xf0)));
1252 * Pan or Wrap the Display
1254 static int neofb_pan_display(struct fb_var_screeninfo *var,
1255 struct fb_info *info)
1259 y_bottom = var->yoffset;
1261 if (!(var->vmode & FB_VMODE_YWRAP))
1262 y_bottom += var->yres;
1264 if (var->xoffset > (var->xres_virtual - var->xres))
1266 if (y_bottom > info->var.yres_virtual)
1269 neofb_update_start(info, var);
1271 info->var.xoffset = var->xoffset;
1272 info->var.yoffset = var->yoffset;
1274 if (var->vmode & FB_VMODE_YWRAP)
1275 info->var.vmode |= FB_VMODE_YWRAP;
1277 info->var.vmode &= ~FB_VMODE_YWRAP;
1281 static int neofb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
1282 u_int transp, struct fb_info *fb)
1284 if (regno >= fb->cmap.len || regno > 255)
1287 switch (fb->var.bits_per_pixel) {
1291 outb(red >> 10, 0x3c9);
1292 outb(green >> 10, 0x3c9);
1293 outb(blue >> 10, 0x3c9);
1296 ((u32 *) fb->pseudo_palette)[regno] =
1297 ((red & 0xf800)) | ((green & 0xfc00) >> 5) |
1298 ((blue & 0xf800) >> 11);
1301 ((u32 *) fb->pseudo_palette)[regno] =
1302 ((red & 0xff00) << 8) | ((green & 0xff00)) |
1303 ((blue & 0xff00) >> 8);
1305 #ifdef NO_32BIT_SUPPORT_YET
1307 ((u32 *) fb->pseudo_palette)[regno] =
1308 ((transp & 0xff00) << 16) | ((red & 0xff00) << 8) |
1309 ((green & 0xff00)) | ((blue & 0xff00) >> 8);
1319 * (Un)Blank the display.
1321 static int neofb_blank(int blank_mode, struct fb_info *info)
1324 * Blank the screen if blank_mode != 0, else unblank.
1325 * Return 0 if blanking succeeded, != 0 if un-/blanking failed due to
1326 * e.g. a video mode which doesn't support it. Implements VESA suspend
1327 * and powerdown modes for monitors, and backlight control on LCDs.
1328 * blank_mode == 0: unblanked (backlight on)
1329 * blank_mode == 1: blank (backlight on)
1330 * blank_mode == 2: suspend vsync (backlight off)
1331 * blank_mode == 3: suspend hsync (backlight off)
1332 * blank_mode == 4: powerdown (backlight off)
1334 * wms...Enable VESA DPMS compatible powerdown mode
1335 * run "setterm -powersave powerdown" to take advantage
1337 struct neofb_par *par = info->par;
1338 int seqflags, lcdflags, dpmsflags, reg;
1342 * Reload the value stored in the register, if sensible. It might have
1343 * been changed via FN keystroke.
1345 if (par->PanelDispCntlRegRead) {
1347 par->PanelDispCntlReg1 = vga_rgfx(NULL, 0x20) & 0x03;
1348 neoLock(&par->state);
1350 par->PanelDispCntlRegRead = !blank_mode;
1352 switch (blank_mode) {
1353 case FB_BLANK_POWERDOWN: /* powerdown - both sync lines down */
1354 seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
1355 lcdflags = 0; /* LCD off */
1356 dpmsflags = NEO_GR01_SUPPRESS_HSYNC |
1357 NEO_GR01_SUPPRESS_VSYNC;
1358 #ifdef CONFIG_TOSHIBA
1359 /* Do we still need this ? */
1360 /* attempt to turn off backlight on toshiba; also turns off external */
1364 regs.eax = 0xff00; /* HCI_SET */
1365 regs.ebx = 0x0002; /* HCI_BACKLIGHT */
1366 regs.ecx = 0x0000; /* HCI_DISABLE */
1371 case FB_BLANK_HSYNC_SUSPEND: /* hsync off */
1372 seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
1373 lcdflags = 0; /* LCD off */
1374 dpmsflags = NEO_GR01_SUPPRESS_HSYNC;
1376 case FB_BLANK_VSYNC_SUSPEND: /* vsync off */
1377 seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
1378 lcdflags = 0; /* LCD off */
1379 dpmsflags = NEO_GR01_SUPPRESS_VSYNC;
1381 case FB_BLANK_NORMAL: /* just blank screen (backlight stays on) */
1382 seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
1383 lcdflags = par->PanelDispCntlReg1 & 0x02; /* LCD normal */
1384 dpmsflags = 0x00; /* no hsync/vsync suppression */
1386 case FB_BLANK_UNBLANK: /* unblank */
1387 seqflags = 0; /* Enable sequencer */
1388 lcdflags = par->PanelDispCntlReg1 & 0x02; /* LCD normal */
1389 dpmsflags = 0x00; /* no hsync/vsync suppression */
1390 #ifdef CONFIG_TOSHIBA
1391 /* Do we still need this ? */
1392 /* attempt to re-enable backlight/external on toshiba */
1396 regs.eax = 0xff00; /* HCI_SET */
1397 regs.ebx = 0x0002; /* HCI_BACKLIGHT */
1398 regs.ecx = 0x0001; /* HCI_ENABLE */
1403 default: /* Anything else we don't understand; return 1 to tell
1404 * fb_blank we didn't aactually do anything */
1409 reg = (vga_rseq(NULL, 0x01) & ~0x20) | seqflags;
1410 vga_wseq(NULL, 0x01, reg);
1411 reg = (vga_rgfx(NULL, 0x20) & ~0x02) | lcdflags;
1412 vga_wgfx(NULL, 0x20, reg);
1413 reg = (vga_rgfx(NULL, 0x01) & ~0xF0) | 0x80 | dpmsflags;
1414 vga_wgfx(NULL, 0x01, reg);
1415 neoLock(&par->state);
1420 neo2200_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
1422 struct neofb_par *par = info->par;
1425 dst = rect->dx + rect->dy * info->var.xres_virtual;
1426 rop = rect->rop ? 0x060000 : 0x0c0000;
1428 neo2200_wait_fifo(info, 4);
1430 /* set blt control */
1431 writel(NEO_BC3_FIFO_EN |
1432 NEO_BC0_SRC_IS_FG | NEO_BC3_SKIP_MAPPING |
1433 // NEO_BC3_DST_XY_ADDR |
1434 // NEO_BC3_SRC_XY_ADDR |
1435 rop, &par->neo2200->bltCntl);
1437 switch (info->var.bits_per_pixel) {
1439 writel(rect->color, &par->neo2200->fgColor);
1443 writel(((u32 *) (info->pseudo_palette))[rect->color],
1444 &par->neo2200->fgColor);
1448 writel(dst * ((info->var.bits_per_pixel + 7) >> 3),
1449 &par->neo2200->dstStart);
1450 writel((rect->height << 16) | (rect->width & 0xffff),
1451 &par->neo2200->xyExt);
1455 neo2200_copyarea(struct fb_info *info, const struct fb_copyarea *area)
1457 u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy;
1458 struct neofb_par *par = info->par;
1459 u_long src, dst, bltCntl;
1461 bltCntl = NEO_BC3_FIFO_EN | NEO_BC3_SKIP_MAPPING | 0x0C0000;
1463 if ((dy > sy) || ((dy == sy) && (dx > sx))) {
1464 /* Start with the lower right corner */
1465 sy += (area->height - 1);
1466 dy += (area->height - 1);
1467 sx += (area->width - 1);
1468 dx += (area->width - 1);
1470 bltCntl |= NEO_BC0_X_DEC | NEO_BC0_DST_Y_DEC | NEO_BC0_SRC_Y_DEC;
1473 src = sx * (info->var.bits_per_pixel >> 3) + sy*info->fix.line_length;
1474 dst = dx * (info->var.bits_per_pixel >> 3) + dy*info->fix.line_length;
1476 neo2200_wait_fifo(info, 4);
1478 /* set blt control */
1479 writel(bltCntl, &par->neo2200->bltCntl);
1481 writel(src, &par->neo2200->srcStart);
1482 writel(dst, &par->neo2200->dstStart);
1483 writel((area->height << 16) | (area->width & 0xffff),
1484 &par->neo2200->xyExt);
1488 neo2200_imageblit(struct fb_info *info, const struct fb_image *image)
1490 struct neofb_par *par = info->par;
1491 int s_pitch = (image->width * image->depth + 7) >> 3;
1492 int scan_align = info->pixmap.scan_align - 1;
1493 int buf_align = info->pixmap.buf_align - 1;
1494 int bltCntl_flags, d_pitch, data_len;
1496 // The data is padded for the hardware
1497 d_pitch = (s_pitch + scan_align) & ~scan_align;
1498 data_len = ((d_pitch * image->height) + buf_align) & ~buf_align;
1502 if (image->depth == 1) {
1503 if (info->var.bits_per_pixel == 24 && image->width < 16) {
1504 /* FIXME. There is a bug with accelerated color-expanded
1505 * transfers in 24 bit mode if the image being transferred
1506 * is less than 16 bits wide. This is due to insufficient
1507 * padding when writing the image. We need to adjust
1508 * struct fb_pixmap. Not yet done. */
1509 return cfb_imageblit(info, image);
1511 bltCntl_flags = NEO_BC0_SRC_MONO;
1512 } else if (image->depth == info->var.bits_per_pixel) {
1515 /* We don't currently support hardware acceleration if image
1516 * depth is different from display */
1517 return cfb_imageblit(info, image);
1520 switch (info->var.bits_per_pixel) {
1522 writel(image->fg_color, &par->neo2200->fgColor);
1523 writel(image->bg_color, &par->neo2200->bgColor);
1527 writel(((u32 *) (info->pseudo_palette))[image->fg_color],
1528 &par->neo2200->fgColor);
1529 writel(((u32 *) (info->pseudo_palette))[image->bg_color],
1530 &par->neo2200->bgColor);
1534 writel(NEO_BC0_SYS_TO_VID |
1535 NEO_BC3_SKIP_MAPPING | bltCntl_flags |
1536 // NEO_BC3_DST_XY_ADDR |
1537 0x0c0000, &par->neo2200->bltCntl);
1539 writel(0, &par->neo2200->srcStart);
1540 // par->neo2200->dstStart = (image->dy << 16) | (image->dx & 0xffff);
1541 writel(((image->dx & 0xffff) * (info->var.bits_per_pixel >> 3) +
1542 image->dy * info->fix.line_length), &par->neo2200->dstStart);
1543 writel((image->height << 16) | (image->width & 0xffff),
1544 &par->neo2200->xyExt);
1546 memcpy_toio(par->mmio_vbase + 0x100000, image->data, data_len);
1550 neofb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
1552 switch (info->fix.accel) {
1553 case FB_ACCEL_NEOMAGIC_NM2200:
1554 case FB_ACCEL_NEOMAGIC_NM2230:
1555 case FB_ACCEL_NEOMAGIC_NM2360:
1556 case FB_ACCEL_NEOMAGIC_NM2380:
1557 neo2200_fillrect(info, rect);
1560 cfb_fillrect(info, rect);
1566 neofb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
1568 switch (info->fix.accel) {
1569 case FB_ACCEL_NEOMAGIC_NM2200:
1570 case FB_ACCEL_NEOMAGIC_NM2230:
1571 case FB_ACCEL_NEOMAGIC_NM2360:
1572 case FB_ACCEL_NEOMAGIC_NM2380:
1573 neo2200_copyarea(info, area);
1576 cfb_copyarea(info, area);
1582 neofb_imageblit(struct fb_info *info, const struct fb_image *image)
1584 switch (info->fix.accel) {
1585 case FB_ACCEL_NEOMAGIC_NM2200:
1586 case FB_ACCEL_NEOMAGIC_NM2230:
1587 case FB_ACCEL_NEOMAGIC_NM2360:
1588 case FB_ACCEL_NEOMAGIC_NM2380:
1589 neo2200_imageblit(info, image);
1592 cfb_imageblit(info, image);
1598 neofb_sync(struct fb_info *info)
1600 switch (info->fix.accel) {
1601 case FB_ACCEL_NEOMAGIC_NM2200:
1602 case FB_ACCEL_NEOMAGIC_NM2230:
1603 case FB_ACCEL_NEOMAGIC_NM2360:
1604 case FB_ACCEL_NEOMAGIC_NM2380:
1615 neofb_draw_cursor(struct fb_info *info, u8 *dst, u8 *src, unsigned int width)
1617 //memset_io(info->sprite.addr, 0xff, 1);
1621 neofb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1623 struct neofb_par *par = (struct neofb_par *) info->par;
1626 write_le32(NEOREG_CURSCNTL, ~NEO_CURS_ENABLE, par);
1628 if (cursor->set & FB_CUR_SETPOS) {
1629 u32 x = cursor->image.dx;
1630 u32 y = cursor->image.dy;
1632 info->cursor.image.dx = x;
1633 info->cursor.image.dy = y;
1634 write_le32(NEOREG_CURSX, x, par);
1635 write_le32(NEOREG_CURSY, y, par);
1638 if (cursor->set & FB_CUR_SETSIZE) {
1639 info->cursor.image.height = cursor->image.height;
1640 info->cursor.image.width = cursor->image.width;
1643 if (cursor->set & FB_CUR_SETHOT)
1644 info->cursor.hot = cursor->hot;
1646 if (cursor->set & FB_CUR_SETCMAP) {
1647 if (cursor->image.depth == 1) {
1648 u32 fg = cursor->image.fg_color;
1649 u32 bg = cursor->image.bg_color;
1651 info->cursor.image.fg_color = fg;
1652 info->cursor.image.bg_color = bg;
1654 fg = ((fg & 0xff0000) >> 16) | ((fg & 0xff) << 16) | (fg & 0xff00);
1655 bg = ((bg & 0xff0000) >> 16) | ((bg & 0xff) << 16) | (bg & 0xff00);
1656 write_le32(NEOREG_CURSFGCOLOR, fg, par);
1657 write_le32(NEOREG_CURSBGCOLOR, bg, par);
1661 if (cursor->set & FB_CUR_SETSHAPE)
1662 fb_load_cursor_image(info);
1664 if (info->cursor.enable)
1665 write_le32(NEOREG_CURSCNTL, NEO_CURS_ENABLE, par);
1670 static struct fb_ops neofb_ops = {
1671 .owner = THIS_MODULE,
1672 .fb_open = neofb_open,
1673 .fb_release = neofb_release,
1674 .fb_check_var = neofb_check_var,
1675 .fb_set_par = neofb_set_par,
1676 .fb_setcolreg = neofb_setcolreg,
1677 .fb_pan_display = neofb_pan_display,
1678 .fb_blank = neofb_blank,
1679 .fb_sync = neofb_sync,
1680 .fb_fillrect = neofb_fillrect,
1681 .fb_copyarea = neofb_copyarea,
1682 .fb_imageblit = neofb_imageblit,
1685 /* --------------------------------------------------------------------- */
1687 static struct fb_videomode __devinitdata mode800x480 = {
1697 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
1698 .vmode = FB_VMODE_NONINTERLACED
1701 static int __devinit neo_map_mmio(struct fb_info *info,
1702 struct pci_dev *dev)
1704 struct neofb_par *par = info->par;
1706 DBG("neo_map_mmio");
1708 switch (info->fix.accel) {
1709 case FB_ACCEL_NEOMAGIC_NM2070:
1710 info->fix.mmio_start = pci_resource_start(dev, 0)+
1713 case FB_ACCEL_NEOMAGIC_NM2090:
1714 case FB_ACCEL_NEOMAGIC_NM2093:
1715 info->fix.mmio_start = pci_resource_start(dev, 0)+
1718 case FB_ACCEL_NEOMAGIC_NM2160:
1719 case FB_ACCEL_NEOMAGIC_NM2097:
1720 case FB_ACCEL_NEOMAGIC_NM2200:
1721 case FB_ACCEL_NEOMAGIC_NM2230:
1722 case FB_ACCEL_NEOMAGIC_NM2360:
1723 case FB_ACCEL_NEOMAGIC_NM2380:
1724 info->fix.mmio_start = pci_resource_start(dev, 1);
1727 info->fix.mmio_start = pci_resource_start(dev, 0);
1729 info->fix.mmio_len = MMIO_SIZE;
1731 if (!request_mem_region
1732 (info->fix.mmio_start, MMIO_SIZE, "memory mapped I/O")) {
1733 printk("neofb: memory mapped IO in use\n");
1737 par->mmio_vbase = ioremap(info->fix.mmio_start, MMIO_SIZE);
1738 if (!par->mmio_vbase) {
1739 printk("neofb: unable to map memory mapped IO\n");
1740 release_mem_region(info->fix.mmio_start,
1741 info->fix.mmio_len);
1744 printk(KERN_INFO "neofb: mapped io at %p\n",
1749 static void neo_unmap_mmio(struct fb_info *info)
1751 struct neofb_par *par = info->par;
1753 DBG("neo_unmap_mmio");
1755 iounmap(par->mmio_vbase);
1756 par->mmio_vbase = NULL;
1758 release_mem_region(info->fix.mmio_start,
1759 info->fix.mmio_len);
1762 static int __devinit neo_map_video(struct fb_info *info,
1763 struct pci_dev *dev, int video_len)
1765 //unsigned long addr;
1767 DBG("neo_map_video");
1769 info->fix.smem_start = pci_resource_start(dev, 0);
1770 info->fix.smem_len = video_len;
1772 if (!request_mem_region(info->fix.smem_start, info->fix.smem_len,
1774 printk("neofb: frame buffer in use\n");
1779 ioremap(info->fix.smem_start, info->fix.smem_len);
1780 if (!info->screen_base) {
1781 printk("neofb: unable to map screen memory\n");
1782 release_mem_region(info->fix.smem_start,
1783 info->fix.smem_len);
1786 printk(KERN_INFO "neofb: mapped framebuffer at %p\n",
1790 ((struct neofb_par *)(info->par))->mtrr =
1791 mtrr_add(info->fix.smem_start, pci_resource_len(dev, 0),
1792 MTRR_TYPE_WRCOMB, 1);
1795 /* Clear framebuffer, it's all white in memory after boot */
1796 memset_io(info->screen_base, 0, info->fix.smem_len);
1798 /* Allocate Cursor drawing pad.
1799 info->fix.smem_len -= PAGE_SIZE;
1800 addr = info->fix.smem_start + info->fix.smem_len;
1801 write_le32(NEOREG_CURSMEMPOS, ((0x000f & (addr >> 10)) << 8) |
1802 ((0x0ff0 & (addr >> 10)) >> 4), par);
1803 addr = (unsigned long) info->screen_base + info->fix.smem_len;
1804 info->sprite.addr = (u8 *) addr; */
1808 static void neo_unmap_video(struct fb_info *info)
1810 DBG("neo_unmap_video");
1814 struct neofb_par *par = info->par;
1816 mtrr_del(par->mtrr, info->fix.smem_start,
1817 info->fix.smem_len);
1820 iounmap(info->screen_base);
1821 info->screen_base = NULL;
1823 release_mem_region(info->fix.smem_start,
1824 info->fix.smem_len);
1827 static int __devinit neo_scan_monitor(struct fb_info *info)
1829 struct neofb_par *par = info->par;
1830 unsigned char type, display;
1833 // Eventually we will have i2c support.
1834 info->monspecs.modedb = kmalloc(sizeof(struct fb_videomode), GFP_KERNEL);
1835 if (!info->monspecs.modedb)
1837 info->monspecs.modedb_len = 1;
1839 /* Determine the panel type */
1840 vga_wgfx(NULL, 0x09, 0x26);
1841 type = vga_rgfx(NULL, 0x21);
1842 display = vga_rgfx(NULL, 0x20);
1843 if (!par->internal_display && !par->external_display) {
1844 par->internal_display = display & 2 || !(display & 3) ? 1 : 0;
1845 par->external_display = display & 1;
1846 printk (KERN_INFO "Autodetected %s display\n",
1847 par->internal_display && par->external_display ? "simultaneous" :
1848 par->internal_display ? "internal" : "external");
1851 /* Determine panel width -- used in NeoValidMode. */
1852 w = vga_rgfx(NULL, 0x20);
1853 vga_wgfx(NULL, 0x09, 0x00);
1854 switch ((w & 0x18) >> 3) {
1857 par->NeoPanelWidth = 640;
1858 par->NeoPanelHeight = 480;
1859 memcpy(info->monspecs.modedb, &vesa_modes[3], sizeof(struct fb_videomode));
1862 par->NeoPanelWidth = 800;
1863 if (par->libretto) {
1864 par->NeoPanelHeight = 480;
1865 memcpy(info->monspecs.modedb, &mode800x480, sizeof(struct fb_videomode));
1868 par->NeoPanelHeight = 600;
1869 memcpy(info->monspecs.modedb, &vesa_modes[8], sizeof(struct fb_videomode));
1874 par->NeoPanelWidth = 1024;
1875 par->NeoPanelHeight = 768;
1876 memcpy(info->monspecs.modedb, &vesa_modes[13], sizeof(struct fb_videomode));
1879 /* 1280x1024@60 panel support needs to be added */
1881 par->NeoPanelWidth = 1280;
1882 par->NeoPanelHeight = 1024;
1883 memcpy(info->monspecs.modedb, &vesa_modes[20], sizeof(struct fb_videomode));
1887 "neofb: Only 640x480, 800x600/480 and 1024x768 panels are currently supported\n");
1892 par->NeoPanelWidth = 640;
1893 par->NeoPanelHeight = 480;
1894 memcpy(info->monspecs.modedb, &vesa_modes[3], sizeof(struct fb_videomode));
1898 printk(KERN_INFO "Panel is a %dx%d %s %s display\n",
1900 par->NeoPanelHeight,
1901 (type & 0x02) ? "color" : "monochrome",
1902 (type & 0x10) ? "TFT" : "dual scan");
1906 static int __devinit neo_init_hw(struct fb_info *info)
1908 struct neofb_par *par = info->par;
1910 int maxClock = 65000;
1911 int CursorMem = 1024;
1912 int CursorOff = 0x100;
1913 int linearSize = 1024;
1914 int maxWidth = 1024;
1915 int maxHeight = 1024;
1922 printk(KERN_DEBUG "--- Neo extended register dump ---\n");
1923 for (int w = 0; w < 0x85; w++)
1924 printk(KERN_DEBUG "CR %p: %p\n", (void *) w,
1925 (void *) vga_rcrt(NULL, w);
1926 for (int w = 0; w < 0xC7; w++)
1927 printk(KERN_DEBUG "GR %p: %p\n", (void *) w,
1928 (void *) vga_rgfx(NULL, w));
1930 switch (info->fix.accel) {
1931 case FB_ACCEL_NEOMAGIC_NM2070:
1940 case FB_ACCEL_NEOMAGIC_NM2090:
1941 case FB_ACCEL_NEOMAGIC_NM2093:
1950 case FB_ACCEL_NEOMAGIC_NM2097:
1959 case FB_ACCEL_NEOMAGIC_NM2160:
1968 case FB_ACCEL_NEOMAGIC_NM2200:
1975 maxHeight = 1024; /* ???? */
1977 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
1979 case FB_ACCEL_NEOMAGIC_NM2230:
1986 maxHeight = 1024; /* ???? */
1988 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
1990 case FB_ACCEL_NEOMAGIC_NM2360:
1997 maxHeight = 1024; /* ???? */
1999 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
2001 case FB_ACCEL_NEOMAGIC_NM2380:
2008 maxHeight = 1024; /* ???? */
2010 par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
2014 info->sprite.size = CursorMem;
2015 info->sprite.scan_align = 1;
2016 info->sprite.buf_align = 1;
2017 info->sprite.flags = FB_PIXMAP_IO;
2018 info->sprite.outbuf = neofb_draw_cursor;
2020 par->maxClock = maxClock;
2021 par->cursorOff = CursorOff;
2022 return ((videoRam * 1024));
2026 static struct fb_info *__devinit neo_alloc_fb_info(struct pci_dev *dev, const struct
2029 struct fb_info *info;
2030 struct neofb_par *par;
2032 info = framebuffer_alloc(sizeof(struct neofb_par), &dev->dev);
2039 info->fix.accel = id->driver_data;
2041 par->pci_burst = !nopciburst;
2042 par->lcd_stretch = !nostretch;
2043 par->libretto = libretto;
2045 par->internal_display = internal;
2046 par->external_display = external;
2047 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
2049 switch (info->fix.accel) {
2050 case FB_ACCEL_NEOMAGIC_NM2070:
2051 sprintf(info->fix.id, "MagicGraph 128");
2053 case FB_ACCEL_NEOMAGIC_NM2090:
2054 sprintf(info->fix.id, "MagicGraph 128V");
2056 case FB_ACCEL_NEOMAGIC_NM2093:
2057 sprintf(info->fix.id, "MagicGraph 128ZV");
2059 case FB_ACCEL_NEOMAGIC_NM2097:
2060 sprintf(info->fix.id, "MagicGraph 128ZV+");
2062 case FB_ACCEL_NEOMAGIC_NM2160:
2063 sprintf(info->fix.id, "MagicGraph 128XD");
2065 case FB_ACCEL_NEOMAGIC_NM2200:
2066 sprintf(info->fix.id, "MagicGraph 256AV");
2067 info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
2068 FBINFO_HWACCEL_COPYAREA |
2069 FBINFO_HWACCEL_FILLRECT;
2071 case FB_ACCEL_NEOMAGIC_NM2230:
2072 sprintf(info->fix.id, "MagicGraph 256AV+");
2073 info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
2074 FBINFO_HWACCEL_COPYAREA |
2075 FBINFO_HWACCEL_FILLRECT;
2077 case FB_ACCEL_NEOMAGIC_NM2360:
2078 sprintf(info->fix.id, "MagicGraph 256ZX");
2079 info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
2080 FBINFO_HWACCEL_COPYAREA |
2081 FBINFO_HWACCEL_FILLRECT;
2083 case FB_ACCEL_NEOMAGIC_NM2380:
2084 sprintf(info->fix.id, "MagicGraph 256XL+");
2085 info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
2086 FBINFO_HWACCEL_COPYAREA |
2087 FBINFO_HWACCEL_FILLRECT;
2091 info->fix.type = FB_TYPE_PACKED_PIXELS;
2092 info->fix.type_aux = 0;
2093 info->fix.xpanstep = 0;
2094 info->fix.ypanstep = 4;
2095 info->fix.ywrapstep = 0;
2096 info->fix.accel = id->driver_data;
2098 info->fbops = &neofb_ops;
2099 info->pseudo_palette = par->palette;
2103 static void neo_free_fb_info(struct fb_info *info)
2107 * Free the colourmap
2109 fb_dealloc_cmap(&info->cmap);
2110 framebuffer_release(info);
2114 /* --------------------------------------------------------------------- */
2116 static int __devinit neofb_probe(struct pci_dev *dev,
2117 const struct pci_device_id *id)
2119 struct fb_info *info;
2120 u_int h_sync, v_sync;
2125 err = pci_enable_device(dev);
2130 info = neo_alloc_fb_info(dev, id);
2134 err = neo_map_mmio(info, dev);
2138 err = neo_scan_monitor(info);
2140 goto err_scan_monitor;
2142 video_len = neo_init_hw(info);
2143 if (video_len < 0) {
2148 err = neo_map_video(info, dev, video_len);
2152 if (!fb_find_mode(&info->var, info, mode_option, NULL, 0,
2153 info->monspecs.modedb, 16)) {
2154 printk(KERN_ERR "neofb: Unable to find usable video mode.\n");
2159 * Calculate the hsync and vsync frequencies. Note that
2160 * we split the 1e12 constant up so that we can preserve
2161 * the precision and fit the results into 32-bit registers.
2162 * (1953125000 * 512 = 1e12)
2164 h_sync = 1953125000 / info->var.pixclock;
2166 h_sync * 512 / (info->var.xres + info->var.left_margin +
2167 info->var.right_margin + info->var.hsync_len);
2169 h_sync / (info->var.yres + info->var.upper_margin +
2170 info->var.lower_margin + info->var.vsync_len);
2172 printk(KERN_INFO "neofb v" NEOFB_VERSION
2173 ": %dkB VRAM, using %dx%d, %d.%03dkHz, %dHz\n",
2174 info->fix.smem_len >> 10, info->var.xres,
2175 info->var.yres, h_sync / 1000, h_sync % 1000, v_sync);
2177 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
2180 err = register_framebuffer(info);
2184 printk(KERN_INFO "fb%d: %s frame buffer device\n",
2185 info->node, info->fix.id);
2190 pci_set_drvdata(dev, info);
2194 fb_dealloc_cmap(&info->cmap);
2196 neo_unmap_video(info);
2198 fb_destroy_modedb(info->monspecs.modedb);
2200 neo_unmap_mmio(info);
2202 neo_free_fb_info(info);
2206 static void __devexit neofb_remove(struct pci_dev *dev)
2208 struct fb_info *info = pci_get_drvdata(dev);
2210 DBG("neofb_remove");
2214 * If unregister_framebuffer fails, then
2215 * we will be leaving hooks that could cause
2216 * oopsen laying around.
2218 if (unregister_framebuffer(info))
2220 "neofb: danger danger! Oopsen imminent!\n");
2222 neo_unmap_video(info);
2223 fb_destroy_modedb(info->monspecs.modedb);
2224 neo_unmap_mmio(info);
2225 neo_free_fb_info(info);
2228 * Ensure that the driver data is no longer
2231 pci_set_drvdata(dev, NULL);
2235 static struct pci_device_id neofb_devices[] = {
2236 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2070,
2237 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2070},
2239 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2090,
2240 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2090},
2242 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2093,
2243 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2093},
2245 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2097,
2246 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2097},
2248 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2160,
2249 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2160},
2251 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2200,
2252 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2200},
2254 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2230,
2255 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2230},
2257 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2360,
2258 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2360},
2260 {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2380,
2261 PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2380},
2263 {0, 0, 0, 0, 0, 0, 0}
2266 MODULE_DEVICE_TABLE(pci, neofb_devices);
2268 static struct pci_driver neofb_driver = {
2270 .id_table = neofb_devices,
2271 .probe = neofb_probe,
2272 .remove = __devexit_p(neofb_remove)
2275 /* ************************* init in-kernel code ************************** */
2278 static int __init neofb_setup(char *options)
2284 if (!options || !*options)
2287 while ((this_opt = strsep(&options, ",")) != NULL) {
2291 if (!strncmp(this_opt, "internal", 8))
2293 else if (!strncmp(this_opt, "external", 8))
2295 else if (!strncmp(this_opt, "nostretch", 9))
2297 else if (!strncmp(this_opt, "nopciburst", 10))
2299 else if (!strncmp(this_opt, "libretto", 8))
2302 mode_option = this_opt;
2308 static int __init neofb_init(void)
2311 char *option = NULL;
2313 if (fb_get_options("neofb", &option))
2315 neofb_setup(option);
2317 return pci_register_driver(&neofb_driver);
2320 module_init(neofb_init);
2323 static void __exit neofb_exit(void)
2325 pci_unregister_driver(&neofb_driver);
2328 module_exit(neofb_exit);