2 * Frame buffer driver for Trident TGUI, Blade and Image series
4 * Copyright 2001, 2002 - Jani Monoses <jani@iv.ro>
7 * CREDITS:(in order of appearance)
8 * skeletonfb.c by Geert Uytterhoeven and other fb code in drivers/video
9 * Special thanks ;) to Mattia Crivellini <tia@mclink.it>
10 * much inspired by the XFree86 4.x Trident driver sources
11 * by Alan Hourihane the FreeVGA project
12 * Francesco Salvestrini <salvestrini@users.sf.net> XP support,
15 * timing value tweaking so it looks good on every monitor in every mode
18 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <video/vga.h>
25 #include <video/trident.h>
27 #define VERSION "0.7.9-NEWAPI"
29 struct tridentfb_par {
30 void __iomem *io_virt; /* iospace virtual memory address */
34 void (*init_accel) (struct tridentfb_par *, int, int);
35 void (*wait_engine) (struct tridentfb_par *);
37 (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
39 (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
42 static unsigned char eng_oper; /* engine operation... */
43 static struct fb_ops tridentfb_ops;
45 static struct fb_fix_screeninfo tridentfb_fix = {
47 .type = FB_TYPE_PACKED_PIXELS,
49 .visual = FB_VISUAL_PSEUDOCOLOR,
50 .accel = FB_ACCEL_NONE,
53 /* defaults which are normally overriden by user values */
56 static char *mode_option __devinitdata = "640x480";
57 static int bpp __devinitdata = 8;
59 static int noaccel __devinitdata;
64 static int fp __devinitdata;
65 static int crt __devinitdata;
67 static int memsize __devinitdata;
68 static int memdiff __devinitdata;
71 module_param(mode_option, charp, 0);
72 MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
73 module_param_named(mode, mode_option, charp, 0);
74 MODULE_PARM_DESC(mode, "Initial video mode e.g. '648x480-8@60' (deprecated)");
75 module_param(bpp, int, 0);
76 module_param(center, int, 0);
77 module_param(stretch, int, 0);
78 module_param(noaccel, int, 0);
79 module_param(memsize, int, 0);
80 module_param(memdiff, int, 0);
81 module_param(nativex, int, 0);
82 module_param(fp, int, 0);
83 MODULE_PARM_DESC(fp, "Define if flatpanel is connected");
84 module_param(crt, int, 0);
85 MODULE_PARM_DESC(crt, "Define if CRT is connected");
87 static int is_oldclock(int id)
89 return (id == TGUI9440) ||
94 static int is_oldprotect(int id)
96 return (id == TGUI9440) ||
98 (id == PROVIDIA9685) ||
104 static int is_blade(int id)
106 return (id == BLADE3D) ||
107 (id == CYBERBLADEE4) ||
108 (id == CYBERBLADEi7) ||
109 (id == CYBERBLADEi7D) ||
110 (id == CYBERBLADEi1) ||
111 (id == CYBERBLADEi1D) ||
112 (id == CYBERBLADEAi1) ||
113 (id == CYBERBLADEAi1D);
116 static int is_xp(int id)
118 return (id == CYBERBLADEXPAi1) ||
119 (id == CYBERBLADEXPm8) ||
120 (id == CYBERBLADEXPm16);
123 static int is3Dchip(int id)
125 return ((id == BLADE3D) || (id == CYBERBLADEE4) ||
126 (id == CYBERBLADEi7) || (id == CYBERBLADEi7D) ||
127 (id == CYBER9397) || (id == CYBER9397DVD) ||
128 (id == CYBER9520) || (id == CYBER9525DVD) ||
129 (id == IMAGE975) || (id == IMAGE985) ||
130 (id == CYBERBLADEi1) || (id == CYBERBLADEi1D) ||
131 (id == CYBERBLADEAi1) || (id == CYBERBLADEAi1D) ||
132 (id == CYBERBLADEXPm8) || (id == CYBERBLADEXPm16) ||
133 (id == CYBERBLADEXPAi1));
136 static int iscyber(int id)
152 case CYBERBLADEXPAi1:
161 case CYBERBLADEi7: /* VIA MPV4 integrated version */
164 /* case CYBERBLDAEXPm8: Strange */
165 /* case CYBERBLDAEXPm16: Strange */
170 static inline void t_outb(struct tridentfb_par *p, u8 val, u16 reg)
172 fb_writeb(val, p->io_virt + reg);
175 static inline u8 t_inb(struct tridentfb_par *p, u16 reg)
177 return fb_readb(p->io_virt + reg);
180 static inline void writemmr(struct tridentfb_par *par, u16 r, u32 v)
182 fb_writel(v, par->io_virt + r);
185 static inline u32 readmmr(struct tridentfb_par *par, u16 r)
187 return fb_readl(par->io_virt + r);
191 * Blade specific acceleration.
194 #define point(x, y) ((y) << 16 | (x))
196 static void blade_init_accel(struct tridentfb_par *par, int pitch, int bpp)
198 int v1 = (pitch >> 3) << 20;
199 int tmp = bpp == 24 ? 2 : (bpp >> 4);
200 int v2 = v1 | (tmp << 29);
202 writemmr(par, 0x21C0, v2);
203 writemmr(par, 0x21C4, v2);
204 writemmr(par, 0x21B8, v2);
205 writemmr(par, 0x21BC, v2);
206 writemmr(par, 0x21D0, v1);
207 writemmr(par, 0x21D4, v1);
208 writemmr(par, 0x21C8, v1);
209 writemmr(par, 0x21CC, v1);
210 writemmr(par, 0x216C, 0);
213 static void blade_wait_engine(struct tridentfb_par *par)
215 while (readmmr(par, STATUS) & 0xFA800000)
219 static void blade_fill_rect(struct tridentfb_par *par,
220 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
222 writemmr(par, COLOR, c);
223 writemmr(par, ROP, rop ? ROP_X : ROP_S);
224 writemmr(par, CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2);
226 writemmr(par, DST1, point(x, y));
227 writemmr(par, DST2, point(x + w - 1, y + h - 1));
230 static void blade_copy_rect(struct tridentfb_par *par,
231 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
234 u32 s1 = point(x1, y1);
235 u32 s2 = point(x1 + w - 1, y1 + h - 1);
236 u32 d1 = point(x2, y2);
237 u32 d2 = point(x2 + w - 1, y2 + h - 1);
239 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
242 writemmr(par, ROP, ROP_S);
243 writemmr(par, CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction);
245 writemmr(par, SRC1, direction ? s2 : s1);
246 writemmr(par, SRC2, direction ? s1 : s2);
247 writemmr(par, DST1, direction ? d2 : d1);
248 writemmr(par, DST2, direction ? d1 : d2);
252 * BladeXP specific acceleration functions
255 static void xp_init_accel(struct tridentfb_par *par, int pitch, int bpp)
257 unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
258 int v1 = pitch << (bpp == 24 ? 20 : (18 + x));
260 switch (pitch << (bpp >> 3)) {
276 t_outb(par, x, 0x2125);
280 writemmr(par, 0x2154, v1);
281 writemmr(par, 0x2150, v1);
282 t_outb(par, 3, 0x2126);
285 static void xp_wait_engine(struct tridentfb_par *par)
291 while (t_inb(par, STATUS) & 0x80) {
293 if (count == 10000000) {
299 t_outb(par, 0x00, STATUS);
307 static void xp_fill_rect(struct tridentfb_par *par,
308 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
310 writemmr(par, 0x2127, ROP_P);
311 writemmr(par, 0x2158, c);
312 writemmr(par, DRAWFL, 0x4000);
313 writemmr(par, OLDDIM, point(h, w));
314 writemmr(par, OLDDST, point(y, x));
315 t_outb(par, 0x01, OLDCMD);
316 t_outb(par, eng_oper, 0x2125);
319 static void xp_copy_rect(struct tridentfb_par *par,
320 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
323 u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
327 if ((x1 < x2) && (y1 == y2)) {
345 writemmr(par, DRAWFL, direction);
346 t_outb(par, ROP_S, 0x2127);
347 writemmr(par, OLDSRC, point(y1_tmp, x1_tmp));
348 writemmr(par, OLDDST, point(y2_tmp, x2_tmp));
349 writemmr(par, OLDDIM, point(h, w));
350 t_outb(par, 0x01, OLDCMD);
354 * Image specific acceleration functions
356 static void image_init_accel(struct tridentfb_par *par, int pitch, int bpp)
358 int tmp = bpp == 24 ? 2: (bpp >> 4);
360 writemmr(par, 0x2120, 0xF0000000);
361 writemmr(par, 0x2120, 0x40000000 | tmp);
362 writemmr(par, 0x2120, 0x80000000);
363 writemmr(par, 0x2144, 0x00000000);
364 writemmr(par, 0x2148, 0x00000000);
365 writemmr(par, 0x2150, 0x00000000);
366 writemmr(par, 0x2154, 0x00000000);
367 writemmr(par, 0x2120, 0x60000000 | (pitch << 16) | pitch);
368 writemmr(par, 0x216C, 0x00000000);
369 writemmr(par, 0x2170, 0x00000000);
370 writemmr(par, 0x217C, 0x00000000);
371 writemmr(par, 0x2120, 0x10000000);
372 writemmr(par, 0x2130, (2047 << 16) | 2047);
375 static void image_wait_engine(struct tridentfb_par *par)
377 while (readmmr(par, 0x2164) & 0xF0000000)
381 static void image_fill_rect(struct tridentfb_par *par,
382 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
384 writemmr(par, 0x2120, 0x80000000);
385 writemmr(par, 0x2120, 0x90000000 | ROP_S);
387 writemmr(par, 0x2144, c);
389 writemmr(par, DST1, point(x, y));
390 writemmr(par, DST2, point(x + w - 1, y + h - 1));
392 writemmr(par, 0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9);
395 static void image_copy_rect(struct tridentfb_par *par,
396 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
399 u32 s1 = point(x1, y1);
400 u32 s2 = point(x1 + w - 1, y1 + h - 1);
401 u32 d1 = point(x2, y2);
402 u32 d2 = point(x2 + w - 1, y2 + h - 1);
404 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
407 writemmr(par, 0x2120, 0x80000000);
408 writemmr(par, 0x2120, 0x90000000 | ROP_S);
410 writemmr(par, SRC1, direction ? s2 : s1);
411 writemmr(par, SRC2, direction ? s1 : s2);
412 writemmr(par, DST1, direction ? d2 : d1);
413 writemmr(par, DST2, direction ? d1 : d2);
414 writemmr(par, 0x2124,
415 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction);
419 * TGUI 9440/96XX acceleration
422 static void tgui_init_accel(struct tridentfb_par *par, int pitch, int bpp)
424 unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
426 /* disable clipping */
427 writemmr(par, 0x2148, 0);
428 writemmr(par, 0x214C, point(4095, 2047));
430 switch ((pitch * bpp) / 8) {
446 fb_writew(x, par->io_virt + 0x2122);
449 static void tgui_fill_rect(struct tridentfb_par *par,
450 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
452 t_outb(par, ROP_P, 0x2127);
453 writemmr(par, OLDCLR, c);
454 writemmr(par, DRAWFL, 0x4020);
455 writemmr(par, OLDDIM, point(w - 1, h - 1));
456 writemmr(par, OLDDST, point(x, y));
457 t_outb(par, 1, OLDCMD);
460 static void tgui_copy_rect(struct tridentfb_par *par,
461 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
464 u16 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
466 if ((x1 < x2) && (y1 == y2)) {
484 writemmr(par, DRAWFL, 0x4 | flags);
485 t_outb(par, ROP_S, 0x2127);
486 writemmr(par, OLDSRC, point(x1_tmp, y1_tmp));
487 writemmr(par, OLDDST, point(x2_tmp, y2_tmp));
488 writemmr(par, OLDDIM, point(w - 1, h - 1));
489 t_outb(par, 1, OLDCMD);
493 * Accel functions called by the upper layers
495 #ifdef CONFIG_FB_TRIDENT_ACCEL
496 static void tridentfb_fillrect(struct fb_info *info,
497 const struct fb_fillrect *fr)
499 struct tridentfb_par *par = info->par;
502 if (info->flags & FBINFO_HWACCEL_DISABLED) {
503 cfb_fillrect(info, fr);
506 if (info->var.bits_per_pixel == 8) {
511 col = ((u32 *)(info->pseudo_palette))[fr->color];
513 par->wait_engine(par);
514 par->fill_rect(par, fr->dx, fr->dy, fr->width,
515 fr->height, col, fr->rop);
518 static void tridentfb_copyarea(struct fb_info *info,
519 const struct fb_copyarea *ca)
521 struct tridentfb_par *par = info->par;
523 if (info->flags & FBINFO_HWACCEL_DISABLED) {
524 cfb_copyarea(info, ca);
527 par->wait_engine(par);
528 par->copy_rect(par, ca->sx, ca->sy, ca->dx, ca->dy,
529 ca->width, ca->height);
532 static int tridentfb_sync(struct fb_info *info)
534 struct tridentfb_par *par = info->par;
536 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
537 par->wait_engine(par);
541 #define tridentfb_fillrect cfb_fillrect
542 #define tridentfb_copyarea cfb_copyarea
543 #endif /* CONFIG_FB_TRIDENT_ACCEL */
546 * Hardware access functions
549 static inline unsigned char read3X4(struct tridentfb_par *par, int reg)
551 return vga_mm_rcrt(par->io_virt, reg);
554 static inline void write3X4(struct tridentfb_par *par, int reg,
557 vga_mm_wcrt(par->io_virt, reg, val);
560 static inline unsigned char read3CE(struct tridentfb_par *par,
563 return vga_mm_rgfx(par->io_virt, reg);
566 static inline void writeAttr(struct tridentfb_par *par, int reg,
569 fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
570 vga_mm_wattr(par->io_virt, reg, val);
573 static inline void write3CE(struct tridentfb_par *par, int reg,
576 vga_mm_wgfx(par->io_virt, reg, val);
579 static void enable_mmio(void)
584 /* Unprotect registers */
585 vga_io_wseq(NewMode1, 0x80);
589 outb(inb(0x3D5) | 0x01, 0x3D5);
592 static void disable_mmio(struct tridentfb_par *par)
595 vga_mm_rseq(par->io_virt, 0x0B);
597 /* Unprotect registers */
598 vga_mm_wseq(par->io_virt, NewMode1, 0x80);
601 t_outb(par, PCIReg, 0x3D4);
602 t_outb(par, t_inb(par, 0x3D5) & ~0x01, 0x3D5);
605 static void crtc_unlock(struct tridentfb_par *par)
607 write3X4(par, VGA_CRTC_V_SYNC_END,
608 read3X4(par, VGA_CRTC_V_SYNC_END) & 0x7F);
611 /* Return flat panel's maximum x resolution */
612 static int __devinit get_nativex(struct tridentfb_par *par)
619 tmp = (read3CE(par, VertStretch) >> 4) & 3;
640 output("%dx%d flat panel found\n", x, y);
645 static void set_lwidth(struct tridentfb_par *par, int width)
647 write3X4(par, VGA_CRTC_OFFSET, width & 0xFF);
648 write3X4(par, AddColReg,
649 (read3X4(par, AddColReg) & 0xCF) | ((width & 0x300) >> 4));
652 /* For resolutions smaller than FP resolution stretch */
653 static void screen_stretch(struct tridentfb_par *par)
655 if (par->chip_id != CYBERBLADEXPAi1)
656 write3CE(par, BiosReg, 0);
658 write3CE(par, BiosReg, 8);
659 write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 1);
660 write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 1);
663 /* For resolutions smaller than FP resolution center */
664 static void screen_center(struct tridentfb_par *par)
666 write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 0x80);
667 write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 0x80);
670 /* Address of first shown pixel in display memory */
671 static void set_screen_start(struct tridentfb_par *par, int base)
674 write3X4(par, VGA_CRTC_START_LO, base & 0xFF);
675 write3X4(par, VGA_CRTC_START_HI, (base & 0xFF00) >> 8);
676 tmp = read3X4(par, CRTCModuleTest) & 0xDF;
677 write3X4(par, CRTCModuleTest, tmp | ((base & 0x10000) >> 11));
678 tmp = read3X4(par, CRTHiOrd) & 0xF8;
679 write3X4(par, CRTHiOrd, tmp | ((base & 0xE0000) >> 17));
682 /* Set dotclock frequency */
683 static void set_vclk(struct tridentfb_par *par, unsigned long freq)
686 unsigned long fi, d, di;
687 unsigned char best_m = 0, best_n = 0, best_k = 0;
688 unsigned char hi, lo;
691 for (k = 1; k >= 0; k--)
692 for (m = 0; m < 32; m++) {
694 for (n = (n < 0 ? 0 : n); n < 122; n++) {
695 fi = ((14318l * (n + 8)) / (m + 2)) >> k;
708 if (is_oldclock(par->chip_id)) {
709 lo = best_n | (best_m << 7);
710 hi = (best_m >> 1) | (best_k << 4);
713 hi = best_m | (best_k << 6);
716 if (is3Dchip(par->chip_id)) {
717 vga_mm_wseq(par->io_virt, ClockHigh, hi);
718 vga_mm_wseq(par->io_virt, ClockLow, lo);
720 t_outb(par, lo, 0x43C8);
721 t_outb(par, hi, 0x43C9);
723 debug("VCLK = %X %X\n", hi, lo);
726 /* Set number of lines for flat panels*/
727 static void set_number_of_lines(struct tridentfb_par *par, int lines)
729 int tmp = read3CE(par, CyberEnhance) & 0x8F;
732 else if (lines > 768)
734 else if (lines > 600)
736 else if (lines > 480)
738 write3CE(par, CyberEnhance, tmp);
742 * If we see that FP is active we assume we have one.
743 * Otherwise we have a CRT display. User can override.
745 static int __devinit is_flatpanel(struct tridentfb_par *par)
749 if (crt || !iscyber(par->chip_id))
751 return (read3CE(par, FPConfig) & 0x10) ? 1 : 0;
754 /* Try detecting the video memory size */
755 static unsigned int __devinit get_memsize(struct tridentfb_par *par)
757 unsigned char tmp, tmp2;
760 /* If memory size provided by user */
764 switch (par->chip_id) {
769 tmp = read3X4(par, SPR) & 0x0F;
785 k = 10 * Mb; /* XP */
791 k = 12 * Mb; /* XP */
794 k = 14 * Mb; /* XP */
797 k = 16 * Mb; /* XP */
801 tmp2 = vga_mm_rseq(par->io_virt, 0xC1);
831 output("framebuffer size = %d Kb\n", k / Kb);
835 /* See if we can handle the video mode described in var */
836 static int tridentfb_check_var(struct fb_var_screeninfo *var,
837 struct fb_info *info)
839 struct tridentfb_par *par = info->par;
840 int bpp = var->bits_per_pixel;
842 int ramdac = 230000; /* 230MHz for most 3D chips */
845 /* check color depth */
847 bpp = var->bits_per_pixel = 32;
848 if (bpp != 8 && bpp != 16 && bpp != 32)
850 if (par->chip_id == TGUI9440 && bpp == 32)
852 /* check whether resolution fits on panel and in memory */
853 if (par->flatpanel && nativex && var->xres > nativex)
855 /* various resolution checks */
856 var->xres = (var->xres + 7) & ~0x7;
857 if (var->xres > var->xres_virtual)
858 var->xres_virtual = var->xres;
859 if (var->yres > var->yres_virtual)
860 var->yres_virtual = var->yres;
861 if (var->xres_virtual > 4095 || var->yres > 2048)
863 /* prevent from position overflow for acceleration */
864 if (var->yres_virtual > 0xffff)
866 line_length = var->xres_virtual * bpp / 8;
868 if (!is3Dchip(par->chip_id) &&
869 !(info->flags & FBINFO_HWACCEL_DISABLED)) {
870 /* acceleration requires line length to be power of 2 */
871 if (line_length <= 512)
872 var->xres_virtual = 512 * 8 / bpp;
873 else if (line_length <= 1024)
874 var->xres_virtual = 1024 * 8 / bpp;
875 else if (line_length <= 2048)
876 var->xres_virtual = 2048 * 8 / bpp;
877 else if (line_length <= 4096)
878 var->xres_virtual = 4096 * 8 / bpp;
879 else if (line_length <= 8192)
880 var->xres_virtual = 8192 * 8 / bpp;
884 line_length = var->xres_virtual * bpp / 8;
887 if (var->yres > var->yres_virtual)
888 var->yres_virtual = var->yres;
889 if (line_length * var->yres_virtual > info->fix.smem_len)
895 var->green.offset = 0;
896 var->blue.offset = 0;
898 var->green.length = 6;
899 var->blue.length = 6;
902 var->red.offset = 11;
903 var->green.offset = 5;
904 var->blue.offset = 0;
906 var->green.length = 6;
907 var->blue.length = 5;
910 var->red.offset = 16;
911 var->green.offset = 8;
912 var->blue.offset = 0;
914 var->green.length = 8;
915 var->blue.length = 8;
921 if (is_xp(par->chip_id))
924 switch (par->chip_id) {
926 ramdac = (bpp >= 16) ? 45000 : 90000;
940 /* The clock is doubled for 32 bpp */
944 if (PICOS2KHZ(var->pixclock) > ramdac)
953 /* Pan the display */
954 static int tridentfb_pan_display(struct fb_var_screeninfo *var,
955 struct fb_info *info)
957 struct tridentfb_par *par = info->par;
961 offset = (var->xoffset + (var->yoffset * var->xres_virtual))
962 * var->bits_per_pixel / 32;
963 info->var.xoffset = var->xoffset;
964 info->var.yoffset = var->yoffset;
965 set_screen_start(par, offset);
970 static void shadowmode_on(struct tridentfb_par *par)
972 write3CE(par, CyberControl, read3CE(par, CyberControl) | 0x81);
975 static void shadowmode_off(struct tridentfb_par *par)
977 write3CE(par, CyberControl, read3CE(par, CyberControl) & 0x7E);
980 /* Set the hardware to the requested video mode */
981 static int tridentfb_set_par(struct fb_info *info)
983 struct tridentfb_par *par = (struct tridentfb_par *)(info->par);
984 u32 htotal, hdispend, hsyncstart, hsyncend, hblankstart, hblankend;
985 u32 vtotal, vdispend, vsyncstart, vsyncend, vblankstart, vblankend;
986 struct fb_var_screeninfo *var = &info->var;
987 int bpp = var->bits_per_pixel;
992 hdispend = var->xres / 8 - 1;
993 hsyncstart = (var->xres + var->right_margin) / 8;
994 hsyncend = (var->xres + var->right_margin + var->hsync_len) / 8;
995 htotal = (var->xres + var->left_margin + var->right_margin +
996 var->hsync_len) / 8 - 5;
997 hblankstart = hdispend + 1;
998 hblankend = htotal + 3;
1000 vdispend = var->yres - 1;
1001 vsyncstart = var->yres + var->lower_margin;
1002 vsyncend = vsyncstart + var->vsync_len;
1003 vtotal = var->upper_margin + vsyncend - 2;
1004 vblankstart = vdispend + 1;
1007 if (info->var.vmode & FB_VMODE_INTERLACED) {
1017 write3CE(par, CyberControl, 8);
1019 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
1021 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
1024 if (par->flatpanel && var->xres < nativex) {
1026 * on flat panels with native size larger
1027 * than requested resolution decide whether
1028 * we stretch or center
1030 t_outb(par, tmp | 0xC0, VGA_MIS_W);
1037 screen_stretch(par);
1040 t_outb(par, tmp, VGA_MIS_W);
1041 write3CE(par, CyberControl, 8);
1044 /* vertical timing values */
1045 write3X4(par, VGA_CRTC_V_TOTAL, vtotal & 0xFF);
1046 write3X4(par, VGA_CRTC_V_DISP_END, vdispend & 0xFF);
1047 write3X4(par, VGA_CRTC_V_SYNC_START, vsyncstart & 0xFF);
1048 write3X4(par, VGA_CRTC_V_SYNC_END, (vsyncend & 0x0F));
1049 write3X4(par, VGA_CRTC_V_BLANK_START, vblankstart & 0xFF);
1050 write3X4(par, VGA_CRTC_V_BLANK_END, vblankend & 0xFF);
1052 /* horizontal timing values */
1053 write3X4(par, VGA_CRTC_H_TOTAL, htotal & 0xFF);
1054 write3X4(par, VGA_CRTC_H_DISP, hdispend & 0xFF);
1055 write3X4(par, VGA_CRTC_H_SYNC_START, hsyncstart & 0xFF);
1056 write3X4(par, VGA_CRTC_H_SYNC_END,
1057 (hsyncend & 0x1F) | ((hblankend & 0x20) << 2));
1058 write3X4(par, VGA_CRTC_H_BLANK_START, hblankstart & 0xFF);
1059 write3X4(par, VGA_CRTC_H_BLANK_END, hblankend & 0x1F);
1061 /* higher bits of vertical timing values */
1063 if (vtotal & 0x100) tmp |= 0x01;
1064 if (vdispend & 0x100) tmp |= 0x02;
1065 if (vsyncstart & 0x100) tmp |= 0x04;
1066 if (vblankstart & 0x100) tmp |= 0x08;
1068 if (vtotal & 0x200) tmp |= 0x20;
1069 if (vdispend & 0x200) tmp |= 0x40;
1070 if (vsyncstart & 0x200) tmp |= 0x80;
1071 write3X4(par, VGA_CRTC_OVERFLOW, tmp);
1073 tmp = read3X4(par, CRTHiOrd) & 0x07;
1074 tmp |= 0x08; /* line compare bit 10 */
1075 if (vtotal & 0x400) tmp |= 0x80;
1076 if (vblankstart & 0x400) tmp |= 0x40;
1077 if (vsyncstart & 0x400) tmp |= 0x20;
1078 if (vdispend & 0x400) tmp |= 0x10;
1079 write3X4(par, CRTHiOrd, tmp);
1081 tmp = (htotal >> 8) & 0x01;
1082 tmp |= (hdispend >> 7) & 0x02;
1083 tmp |= (hsyncstart >> 5) & 0x08;
1084 tmp |= (hblankstart >> 4) & 0x10;
1085 write3X4(par, HorizOverflow, tmp);
1088 if (vblankstart & 0x200) tmp |= 0x20;
1089 //FIXME if (info->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; /* double scan for 200 line modes */
1090 write3X4(par, VGA_CRTC_MAX_SCAN, tmp);
1092 write3X4(par, VGA_CRTC_LINE_COMPARE, 0xFF);
1093 write3X4(par, VGA_CRTC_PRESET_ROW, 0);
1094 write3X4(par, VGA_CRTC_MODE, 0xC3);
1096 write3X4(par, LinearAddReg, 0x20); /* enable linear addressing */
1098 tmp = (info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80;
1099 /* enable access extended memory */
1100 write3X4(par, CRTCModuleTest, tmp);
1101 tmp = read3CE(par, MiscIntContReg) & ~0x4;
1102 if (info->var.vmode & FB_VMODE_INTERLACED)
1104 write3CE(par, MiscIntContReg, tmp);
1106 /* enable GE for text acceleration */
1107 write3X4(par, GraphEngReg, 0x80);
1124 write3X4(par, PixelBusReg, tmp);
1126 tmp = read3X4(par, DRAMControl);
1127 if (!is_oldprotect(par->chip_id))
1129 if (iscyber(par->chip_id))
1131 write3X4(par, DRAMControl, tmp); /* both IO, linear enable */
1133 write3X4(par, InterfaceSel, read3X4(par, InterfaceSel) | 0x40);
1134 if (!is_xp(par->chip_id))
1135 write3X4(par, Performance, read3X4(par, Performance) | 0x10);
1136 /* MMIO & PCI read and write burst enable */
1137 if (par->chip_id != TGUI9440)
1138 write3X4(par, PCIReg, read3X4(par, PCIReg) | 0x06);
1140 vga_mm_wseq(par->io_virt, 0, 3);
1141 vga_mm_wseq(par->io_virt, 1, 1); /* set char clock 8 dots wide */
1142 /* enable 4 maps because needed in chain4 mode */
1143 vga_mm_wseq(par->io_virt, 2, 0x0F);
1144 vga_mm_wseq(par->io_virt, 3, 0);
1145 vga_mm_wseq(par->io_virt, 4, 0x0E); /* memory mode enable bitmaps ?? */
1147 /* convert from picoseconds to kHz */
1148 vclk = PICOS2KHZ(info->var.pixclock);
1150 /* divide clock by 2 if 32bpp chain4 mode display and CPU path */
1151 tmp = read3CE(par, MiscExtFunc) & 0xF0;
1152 if (bpp == 32 || (par->chip_id == TGUI9440 && bpp == 16)) {
1156 set_vclk(par, vclk);
1157 write3CE(par, MiscExtFunc, tmp | 0x12);
1158 write3CE(par, 0x5, 0x40); /* no CGA compat, allow 256 col */
1159 write3CE(par, 0x6, 0x05); /* graphics mode */
1160 write3CE(par, 0x7, 0x0F); /* planes? */
1162 if (par->chip_id == CYBERBLADEXPAi1) {
1163 /* This fixes snow-effect in 32 bpp */
1164 write3X4(par, VGA_CRTC_H_SYNC_START, 0x84);
1167 /* graphics mode and support 256 color modes */
1168 writeAttr(par, 0x10, 0x41);
1169 writeAttr(par, 0x12, 0x0F); /* planes */
1170 writeAttr(par, 0x13, 0); /* horizontal pel panning */
1173 for (tmp = 0; tmp < 0x10; tmp++)
1174 writeAttr(par, tmp, tmp);
1175 fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
1176 t_outb(par, 0x20, VGA_ATT_W); /* enable attr */
1191 t_inb(par, VGA_PEL_IW);
1192 t_inb(par, VGA_PEL_MSK);
1193 t_inb(par, VGA_PEL_MSK);
1194 t_inb(par, VGA_PEL_MSK);
1195 t_inb(par, VGA_PEL_MSK);
1196 t_outb(par, tmp, VGA_PEL_MSK);
1197 t_inb(par, VGA_PEL_IW);
1200 set_number_of_lines(par, info->var.yres);
1201 info->fix.line_length = info->var.xres_virtual * bpp / 8;
1202 set_lwidth(par, info->fix.line_length / 8);
1204 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
1205 par->init_accel(par, info->var.xres_virtual, bpp);
1207 info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
1208 info->cmap.len = (bpp == 8) ? 256 : 16;
1213 /* Set one color register */
1214 static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1215 unsigned blue, unsigned transp,
1216 struct fb_info *info)
1218 int bpp = info->var.bits_per_pixel;
1219 struct tridentfb_par *par = info->par;
1221 if (regno >= info->cmap.len)
1225 t_outb(par, 0xFF, VGA_PEL_MSK);
1226 t_outb(par, regno, VGA_PEL_IW);
1228 t_outb(par, red >> 10, VGA_PEL_D);
1229 t_outb(par, green >> 10, VGA_PEL_D);
1230 t_outb(par, blue >> 10, VGA_PEL_D);
1232 } else if (regno < 16) {
1233 if (bpp == 16) { /* RGB 565 */
1236 col = (red & 0xF800) | ((green & 0xFC00) >> 5) |
1237 ((blue & 0xF800) >> 11);
1239 ((u32 *)(info->pseudo_palette))[regno] = col;
1240 } else if (bpp == 32) /* ARGB 8888 */
1241 ((u32*)info->pseudo_palette)[regno] =
1242 ((transp & 0xFF00) << 16) |
1243 ((red & 0xFF00) << 8) |
1244 ((green & 0xFF00)) |
1245 ((blue & 0xFF00) >> 8);
1248 /* debug("exit\n"); */
1252 /* Try blanking the screen.For flat panels it does nothing */
1253 static int tridentfb_blank(int blank_mode, struct fb_info *info)
1255 unsigned char PMCont, DPMSCont;
1256 struct tridentfb_par *par = info->par;
1261 t_outb(par, 0x04, 0x83C8); /* Read DPMS Control */
1262 PMCont = t_inb(par, 0x83C6) & 0xFC;
1263 DPMSCont = read3CE(par, PowerStatus) & 0xFC;
1264 switch (blank_mode) {
1265 case FB_BLANK_UNBLANK:
1266 /* Screen: On, HSync: On, VSync: On */
1267 case FB_BLANK_NORMAL:
1268 /* Screen: Off, HSync: On, VSync: On */
1272 case FB_BLANK_HSYNC_SUSPEND:
1273 /* Screen: Off, HSync: Off, VSync: On */
1277 case FB_BLANK_VSYNC_SUSPEND:
1278 /* Screen: Off, HSync: On, VSync: Off */
1282 case FB_BLANK_POWERDOWN:
1283 /* Screen: Off, HSync: Off, VSync: Off */
1289 write3CE(par, PowerStatus, DPMSCont);
1290 t_outb(par, 4, 0x83C8);
1291 t_outb(par, PMCont, 0x83C6);
1295 /* let fbcon do a softblank for us */
1296 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
1299 static struct fb_ops tridentfb_ops = {
1300 .owner = THIS_MODULE,
1301 .fb_setcolreg = tridentfb_setcolreg,
1302 .fb_pan_display = tridentfb_pan_display,
1303 .fb_blank = tridentfb_blank,
1304 .fb_check_var = tridentfb_check_var,
1305 .fb_set_par = tridentfb_set_par,
1306 .fb_fillrect = tridentfb_fillrect,
1307 .fb_copyarea = tridentfb_copyarea,
1308 .fb_imageblit = cfb_imageblit,
1309 #ifdef CONFIG_FB_TRIDENT_ACCEL
1310 .fb_sync = tridentfb_sync,
1314 static int __devinit trident_pci_probe(struct pci_dev *dev,
1315 const struct pci_device_id *id)
1318 unsigned char revision;
1319 struct fb_info *info;
1320 struct tridentfb_par *default_par;
1324 err = pci_enable_device(dev);
1328 info = framebuffer_alloc(sizeof(struct tridentfb_par), &dev->dev);
1331 default_par = info->par;
1333 chip_id = id->device;
1335 if (chip_id == CYBERBLADEi1)
1336 output("*** Please do use cyblafb, Cyberblade/i1 support "
1337 "will soon be removed from tridentfb!\n");
1339 #ifndef CONFIG_FB_TRIDENT_ACCEL
1343 /* If PCI id is 0x9660 then further detect chip type */
1345 if (chip_id == TGUI9660) {
1346 revision = vga_io_rseq(RevisionID);
1350 chip_id = PROVIDIA9685;
1354 chip_id = CYBER9397;
1357 chip_id = CYBER9397DVD;
1366 chip_id = CYBER9385;
1369 chip_id = CYBER9382;
1372 chip_id = CYBER9388;
1379 chip3D = is3Dchip(chip_id);
1381 if (is_xp(chip_id)) {
1382 default_par->init_accel = xp_init_accel;
1383 default_par->wait_engine = xp_wait_engine;
1384 default_par->fill_rect = xp_fill_rect;
1385 default_par->copy_rect = xp_copy_rect;
1386 tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADEXP;
1387 } else if (is_blade(chip_id)) {
1388 default_par->init_accel = blade_init_accel;
1389 default_par->wait_engine = blade_wait_engine;
1390 default_par->fill_rect = blade_fill_rect;
1391 default_par->copy_rect = blade_copy_rect;
1392 tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADE3D;
1393 } else if (chip3D) { /* 3DImage family left */
1394 default_par->init_accel = image_init_accel;
1395 default_par->wait_engine = image_wait_engine;
1396 default_par->fill_rect = image_fill_rect;
1397 default_par->copy_rect = image_copy_rect;
1398 tridentfb_fix.accel = FB_ACCEL_TRIDENT_3DIMAGE;
1399 } else { /* TGUI 9440/96XX family */
1400 default_par->init_accel = tgui_init_accel;
1401 default_par->wait_engine = xp_wait_engine;
1402 default_par->fill_rect = tgui_fill_rect;
1403 default_par->copy_rect = tgui_copy_rect;
1404 tridentfb_fix.accel = FB_ACCEL_TRIDENT_TGUI;
1407 default_par->chip_id = chip_id;
1409 /* setup MMIO region */
1410 tridentfb_fix.mmio_start = pci_resource_start(dev, 1);
1411 tridentfb_fix.mmio_len = chip3D ? 0x20000 : 0x10000;
1413 if (!request_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len, "tridentfb")) {
1414 debug("request_region failed!\n");
1415 framebuffer_release(info);
1419 default_par->io_virt = ioremap_nocache(tridentfb_fix.mmio_start,
1420 tridentfb_fix.mmio_len);
1422 if (!default_par->io_virt) {
1423 debug("ioremap failed\n");
1430 /* setup framebuffer memory */
1431 tridentfb_fix.smem_start = pci_resource_start(dev, 0);
1432 tridentfb_fix.smem_len = get_memsize(default_par);
1434 if (!request_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len, "tridentfb")) {
1435 debug("request_mem_region failed!\n");
1436 disable_mmio(info->par);
1441 info->screen_base = ioremap_nocache(tridentfb_fix.smem_start,
1442 tridentfb_fix.smem_len);
1444 if (!info->screen_base) {
1445 debug("ioremap failed\n");
1450 output("%s board found\n", pci_name(dev));
1451 default_par->flatpanel = is_flatpanel(default_par);
1453 if (default_par->flatpanel)
1454 nativex = get_nativex(default_par);
1456 info->fix = tridentfb_fix;
1457 info->fbops = &tridentfb_ops;
1458 info->pseudo_palette = default_par->pseudo_pal;
1460 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1461 if (!noaccel && default_par->init_accel) {
1462 info->flags &= ~FBINFO_HWACCEL_DISABLED;
1463 info->flags |= FBINFO_HWACCEL_COPYAREA;
1464 info->flags |= FBINFO_HWACCEL_FILLRECT;
1466 info->flags |= FBINFO_HWACCEL_DISABLED;
1468 if (!fb_find_mode(&info->var, info,
1469 mode_option, NULL, 0, NULL, bpp)) {
1473 err = fb_alloc_cmap(&info->cmap, 256, 0);
1477 info->var.activate |= FB_ACTIVATE_NOW;
1478 info->device = &dev->dev;
1479 if (register_framebuffer(info) < 0) {
1480 printk(KERN_ERR "tridentfb: could not register Trident framebuffer\n");
1481 fb_dealloc_cmap(&info->cmap);
1485 output("fb%d: %s frame buffer device %dx%d-%dbpp\n",
1486 info->node, info->fix.id, info->var.xres,
1487 info->var.yres, info->var.bits_per_pixel);
1489 pci_set_drvdata(dev, info);
1493 if (info->screen_base)
1494 iounmap(info->screen_base);
1495 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
1496 disable_mmio(info->par);
1498 if (default_par->io_virt)
1499 iounmap(default_par->io_virt);
1500 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
1501 framebuffer_release(info);
1505 static void __devexit trident_pci_remove(struct pci_dev *dev)
1507 struct fb_info *info = pci_get_drvdata(dev);
1508 struct tridentfb_par *par = info->par;
1510 unregister_framebuffer(info);
1511 iounmap(par->io_virt);
1512 iounmap(info->screen_base);
1513 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
1514 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
1515 pci_set_drvdata(dev, NULL);
1516 framebuffer_release(info);
1519 /* List of boards that we are trying to support */
1520 static struct pci_device_id trident_devices[] = {
1521 {PCI_VENDOR_ID_TRIDENT, BLADE3D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1522 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1523 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1524 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1525 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1526 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1527 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1528 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEE4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1529 {PCI_VENDOR_ID_TRIDENT, TGUI9440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1530 {PCI_VENDOR_ID_TRIDENT, TGUI9660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1531 {PCI_VENDOR_ID_TRIDENT, IMAGE975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1532 {PCI_VENDOR_ID_TRIDENT, IMAGE985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1533 {PCI_VENDOR_ID_TRIDENT, CYBER9320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1534 {PCI_VENDOR_ID_TRIDENT, CYBER9388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1535 {PCI_VENDOR_ID_TRIDENT, CYBER9520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1536 {PCI_VENDOR_ID_TRIDENT, CYBER9525DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1537 {PCI_VENDOR_ID_TRIDENT, CYBER9397, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1538 {PCI_VENDOR_ID_TRIDENT, CYBER9397DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1539 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1540 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1541 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1545 MODULE_DEVICE_TABLE(pci, trident_devices);
1547 static struct pci_driver tridentfb_pci_driver = {
1548 .name = "tridentfb",
1549 .id_table = trident_devices,
1550 .probe = trident_pci_probe,
1551 .remove = __devexit_p(trident_pci_remove)
1555 * Parse user specified options (`video=trident:')
1557 * video=trident:800x600,bpp=16,noaccel
1560 static int __init tridentfb_setup(char *options)
1563 if (!options || !*options)
1565 while ((opt = strsep(&options, ",")) != NULL) {
1568 if (!strncmp(opt, "noaccel", 7))
1570 else if (!strncmp(opt, "fp", 2))
1572 else if (!strncmp(opt, "crt", 3))
1574 else if (!strncmp(opt, "bpp=", 4))
1575 bpp = simple_strtoul(opt + 4, NULL, 0);
1576 else if (!strncmp(opt, "center", 6))
1578 else if (!strncmp(opt, "stretch", 7))
1580 else if (!strncmp(opt, "memsize=", 8))
1581 memsize = simple_strtoul(opt + 8, NULL, 0);
1582 else if (!strncmp(opt, "memdiff=", 8))
1583 memdiff = simple_strtoul(opt + 8, NULL, 0);
1584 else if (!strncmp(opt, "nativex=", 8))
1585 nativex = simple_strtoul(opt + 8, NULL, 0);
1593 static int __init tridentfb_init(void)
1596 char *option = NULL;
1598 if (fb_get_options("tridentfb", &option))
1600 tridentfb_setup(option);
1602 output("Trident framebuffer %s initializing\n", VERSION);
1603 return pci_register_driver(&tridentfb_pci_driver);
1606 static void __exit tridentfb_exit(void)
1608 pci_unregister_driver(&tridentfb_pci_driver);
1611 module_init(tridentfb_init);
1612 module_exit(tridentfb_exit);
1614 MODULE_AUTHOR("Jani Monoses <jani@iv.ro>");
1615 MODULE_DESCRIPTION("Framebuffer driver for Trident cards");
1616 MODULE_LICENSE("GPL");