tridentfb: remove misplaced enable_mmio()
[deliverable/linux.git] / drivers / video / tridentfb.c
CommitLineData
1da177e4
LT
1/*
2 * Frame buffer driver for Trident Blade and Image series
3 *
245a2c2c 4 * Copyright 2001, 2002 - Jani Monoses <jani@iv.ro>
1da177e4
LT
5 *
6 *
7 * CREDITS:(in order of appearance)
245a2c2c
KH
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,
13 * code, suggestions
1da177e4 14 * TODO:
245a2c2c
KH
15 * timing value tweaking so it looks good on every monitor in every mode
16 * TGUI acceleration
1da177e4
LT
17 */
18
1da177e4
LT
19#include <linux/module.h>
20#include <linux/fb.h>
21#include <linux/init.h>
22#include <linux/pci.h>
23
24#include <linux/delay.h>
25#include <video/trident.h>
26
27#define VERSION "0.7.8-NEWAPI"
28
29struct tridentfb_par {
245a2c2c
KH
30 int vclk; /* in MHz */
31 void __iomem *io_virt; /* iospace virtual memory address */
1da177e4
LT
32};
33
245a2c2c 34static unsigned char eng_oper; /* engine operation... */
1da177e4
LT
35static struct fb_ops tridentfb_ops;
36
37static struct tridentfb_par default_par;
38
39/* FIXME:kmalloc these 3 instead */
40static struct fb_info fb_info;
41static u32 pseudo_pal[16];
42
1da177e4
LT
43static struct fb_var_screeninfo default_var;
44
45static struct fb_fix_screeninfo tridentfb_fix = {
245a2c2c 46 .id = "Trident",
1da177e4
LT
47 .type = FB_TYPE_PACKED_PIXELS,
48 .ypanstep = 1,
49 .visual = FB_VISUAL_PSEUDOCOLOR,
50 .accel = FB_ACCEL_NONE,
51};
52
53static int chip_id;
54
55static int defaultaccel;
56static int displaytype;
57
1da177e4
LT
58/* defaults which are normally overriden by user values */
59
60/* video mode */
07f41e45 61static char *mode_option __devinitdata = "640x480";
1da177e4
LT
62static int bpp = 8;
63
64static int noaccel;
65
66static int center;
67static int stretch;
68
69static int fp;
70static int crt;
71
72static int memsize;
73static int memdiff;
74static int nativex;
75
07f41e45
KH
76module_param(mode_option, charp, 0);
77MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
9e3f0ca8
KH
78module_param_named(mode, mode_option, charp, 0);
79MODULE_PARM_DESC(mode, "Initial video mode e.g. '648x480-8@60' (deprecated)");
1da177e4
LT
80module_param(bpp, int, 0);
81module_param(center, int, 0);
82module_param(stretch, int, 0);
83module_param(noaccel, int, 0);
84module_param(memsize, int, 0);
85module_param(memdiff, int, 0);
86module_param(nativex, int, 0);
87module_param(fp, int, 0);
88module_param(crt, int, 0);
89
1da177e4
LT
90static int chip3D;
91static int chipcyber;
92
93static int is3Dchip(int id)
94{
245a2c2c
KH
95 return ((id == BLADE3D) || (id == CYBERBLADEE4) ||
96 (id == CYBERBLADEi7) || (id == CYBERBLADEi7D) ||
97 (id == CYBER9397) || (id == CYBER9397DVD) ||
98 (id == CYBER9520) || (id == CYBER9525DVD) ||
99 (id == IMAGE975) || (id == IMAGE985) ||
100 (id == CYBERBLADEi1) || (id == CYBERBLADEi1D) ||
101 (id == CYBERBLADEAi1) || (id == CYBERBLADEAi1D) ||
102 (id == CYBERBLADEXPm8) || (id == CYBERBLADEXPm16) ||
103 (id == CYBERBLADEXPAi1));
1da177e4
LT
104}
105
106static int iscyber(int id)
107{
108 switch (id) {
245a2c2c
KH
109 case CYBER9388:
110 case CYBER9382:
111 case CYBER9385:
112 case CYBER9397:
113 case CYBER9397DVD:
114 case CYBER9520:
115 case CYBER9525DVD:
116 case CYBERBLADEE4:
117 case CYBERBLADEi7D:
118 case CYBERBLADEi1:
119 case CYBERBLADEi1D:
120 case CYBERBLADEAi1:
121 case CYBERBLADEAi1D:
122 case CYBERBLADEXPAi1:
123 return 1;
1da177e4 124
245a2c2c
KH
125 case CYBER9320:
126 case TGUI9660:
127 case IMAGE975:
128 case IMAGE985:
129 case BLADE3D:
130 case CYBERBLADEi7: /* VIA MPV4 integrated version */
131
132 default:
133 /* case CYBERBLDAEXPm8: Strange */
134 /* case CYBERBLDAEXPm16: Strange */
135 return 0;
1da177e4
LT
136 }
137}
138
245a2c2c 139#define CRT 0x3D0 /* CRTC registers offset for color display */
1da177e4
LT
140
141#ifndef TRIDENT_MMIO
142 #define TRIDENT_MMIO 1
143#endif
144
145#if TRIDENT_MMIO
245a2c2c 146 #define t_outb(val, reg) writeb(val,((struct tridentfb_par *)(fb_info.par))->io_virt + reg)
1da177e4
LT
147 #define t_inb(reg) readb(((struct tridentfb_par*)(fb_info.par))->io_virt + reg)
148#else
245a2c2c 149 #define t_outb(val, reg) outb(val, reg)
1da177e4
LT
150 #define t_inb(reg) inb(reg)
151#endif
152
153
154static struct accel_switch {
245a2c2c
KH
155 void (*init_accel) (int, int);
156 void (*wait_engine) (void);
157 void (*fill_rect) (u32, u32, u32, u32, u32, u32);
158 void (*copy_rect) (u32, u32, u32, u32, u32, u32);
1da177e4
LT
159} *acc;
160
245a2c2c 161#define writemmr(r, v) writel(v, ((struct tridentfb_par *)fb_info.par)->io_virt + r)
1da177e4
LT
162#define readmmr(r) readl(((struct tridentfb_par *)fb_info.par)->io_virt + r)
163
1da177e4
LT
164/*
165 * Blade specific acceleration.
166 */
167
245a2c2c 168#define point(x, y) ((y) << 16 | (x))
1da177e4
LT
169#define STA 0x2120
170#define CMD 0x2144
171#define ROP 0x2148
172#define CLR 0x2160
173#define SR1 0x2100
174#define SR2 0x2104
175#define DR1 0x2108
176#define DR2 0x210C
177
178#define ROP_S 0xCC
179
245a2c2c 180static void blade_init_accel(int pitch, int bpp)
1da177e4 181{
245a2c2c
KH
182 int v1 = (pitch >> 3) << 20;
183 int tmp = 0, v2;
1da177e4 184 switch (bpp) {
245a2c2c
KH
185 case 8:
186 tmp = 0;
187 break;
188 case 15:
189 tmp = 5;
190 break;
191 case 16:
192 tmp = 1;
193 break;
194 case 24:
195 case 32:
196 tmp = 2;
197 break;
1da177e4 198 }
245a2c2c
KH
199 v2 = v1 | (tmp << 29);
200 writemmr(0x21C0, v2);
201 writemmr(0x21C4, v2);
202 writemmr(0x21B8, v2);
203 writemmr(0x21BC, v2);
204 writemmr(0x21D0, v1);
205 writemmr(0x21D4, v1);
206 writemmr(0x21C8, v1);
207 writemmr(0x21CC, v1);
208 writemmr(0x216C, 0);
1da177e4
LT
209}
210
211static void blade_wait_engine(void)
212{
245a2c2c 213 while (readmmr(STA) & 0xFA800000) ;
1da177e4
LT
214}
215
245a2c2c 216static void blade_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
1da177e4 217{
245a2c2c
KH
218 writemmr(CLR, c);
219 writemmr(ROP, rop ? 0x66 : ROP_S);
220 writemmr(CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2);
1da177e4 221
245a2c2c
KH
222 writemmr(DR1, point(x, y));
223 writemmr(DR2, point(x + w - 1, y + h - 1));
1da177e4
LT
224}
225
245a2c2c 226static void blade_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
1da177e4 227{
245a2c2c 228 u32 s1, s2, d1, d2;
1da177e4 229 int direction = 2;
245a2c2c
KH
230 s1 = point(x1, y1);
231 s2 = point(x1 + w - 1, y1 + h - 1);
232 d1 = point(x2, y2);
233 d2 = point(x2 + w - 1, y2 + h - 1);
1da177e4
LT
234
235 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
245a2c2c 236 direction = 0;
1da177e4 237
245a2c2c
KH
238 writemmr(ROP, ROP_S);
239 writemmr(CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction);
1da177e4 240
245a2c2c
KH
241 writemmr(SR1, direction ? s2 : s1);
242 writemmr(SR2, direction ? s1 : s2);
243 writemmr(DR1, direction ? d2 : d1);
244 writemmr(DR2, direction ? d1 : d2);
1da177e4
LT
245}
246
247static struct accel_switch accel_blade = {
248 blade_init_accel,
249 blade_wait_engine,
250 blade_fill_rect,
251 blade_copy_rect,
252};
253
1da177e4
LT
254/*
255 * BladeXP specific acceleration functions
256 */
257
258#define ROP_P 0xF0
245a2c2c 259#define masked_point(x, y) ((y & 0xffff)<<16|(x & 0xffff))
1da177e4 260
245a2c2c 261static void xp_init_accel(int pitch, int bpp)
1da177e4 262{
245a2c2c 263 int tmp = 0, v1;
1da177e4
LT
264 unsigned char x = 0;
265
266 switch (bpp) {
245a2c2c
KH
267 case 8:
268 x = 0;
269 break;
270 case 16:
271 x = 1;
272 break;
273 case 24:
274 x = 3;
275 break;
276 case 32:
277 x = 2;
278 break;
1da177e4
LT
279 }
280
281 switch (pitch << (bpp >> 3)) {
245a2c2c
KH
282 case 8192:
283 case 512:
284 x |= 0x00;
285 break;
286 case 1024:
287 x |= 0x04;
288 break;
289 case 2048:
290 x |= 0x08;
291 break;
292 case 4096:
293 x |= 0x0C;
294 break;
1da177e4
LT
295 }
296
245a2c2c 297 t_outb(x, 0x2125);
1da177e4
LT
298
299 eng_oper = x | 0x40;
300
301 switch (bpp) {
245a2c2c
KH
302 case 8:
303 tmp = 18;
304 break;
305 case 15:
306 case 16:
307 tmp = 19;
308 break;
309 case 24:
310 case 32:
311 tmp = 20;
312 break;
1da177e4
LT
313 }
314
315 v1 = pitch << tmp;
316
245a2c2c
KH
317 writemmr(0x2154, v1);
318 writemmr(0x2150, v1);
319 t_outb(3, 0x2126);
1da177e4
LT
320}
321
322static void xp_wait_engine(void)
323{
324 int busy;
325 int count, timeout;
326
327 count = 0;
328 timeout = 0;
329 for (;;) {
330 busy = t_inb(STA) & 0x80;
331 if (busy != 0x80)
332 return;
333 count++;
334 if (count == 10000000) {
335 /* Timeout */
336 count = 9990000;
337 timeout++;
338 if (timeout == 8) {
339 /* Reset engine */
340 t_outb(0x00, 0x2120);
341 return;
342 }
343 }
344 }
345}
346
245a2c2c 347static void xp_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
1da177e4 348{
245a2c2c
KH
349 writemmr(0x2127, ROP_P);
350 writemmr(0x2158, c);
351 writemmr(0x2128, 0x4000);
352 writemmr(0x2140, masked_point(h, w));
353 writemmr(0x2138, masked_point(y, x));
354 t_outb(0x01, 0x2124);
355 t_outb(eng_oper, 0x2125);
1da177e4
LT
356}
357
245a2c2c 358static void xp_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
1da177e4
LT
359{
360 int direction;
245a2c2c 361 u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
1da177e4
LT
362
363 direction = 0x0004;
245a2c2c 364
1da177e4
LT
365 if ((x1 < x2) && (y1 == y2)) {
366 direction |= 0x0200;
367 x1_tmp = x1 + w - 1;
368 x2_tmp = x2 + w - 1;
369 } else {
370 x1_tmp = x1;
371 x2_tmp = x2;
372 }
245a2c2c 373
1da177e4
LT
374 if (y1 < y2) {
375 direction |= 0x0100;
376 y1_tmp = y1 + h - 1;
377 y2_tmp = y2 + h - 1;
245a2c2c 378 } else {
1da177e4
LT
379 y1_tmp = y1;
380 y2_tmp = y2;
381 }
382
245a2c2c
KH
383 writemmr(0x2128, direction);
384 t_outb(ROP_S, 0x2127);
385 writemmr(0x213C, masked_point(y1_tmp, x1_tmp));
386 writemmr(0x2138, masked_point(y2_tmp, x2_tmp));
387 writemmr(0x2140, masked_point(h, w));
388 t_outb(0x01, 0x2124);
1da177e4
LT
389}
390
391static struct accel_switch accel_xp = {
245a2c2c 392 xp_init_accel,
1da177e4
LT
393 xp_wait_engine,
394 xp_fill_rect,
395 xp_copy_rect,
396};
397
1da177e4
LT
398/*
399 * Image specific acceleration functions
400 */
245a2c2c 401static void image_init_accel(int pitch, int bpp)
1da177e4
LT
402{
403 int tmp = 0;
245a2c2c
KH
404 switch (bpp) {
405 case 8:
406 tmp = 0;
407 break;
408 case 15:
409 tmp = 5;
410 break;
411 case 16:
412 tmp = 1;
413 break;
414 case 24:
415 case 32:
416 tmp = 2;
417 break;
1da177e4
LT
418 }
419 writemmr(0x2120, 0xF0000000);
245a2c2c 420 writemmr(0x2120, 0x40000000 | tmp);
1da177e4
LT
421 writemmr(0x2120, 0x80000000);
422 writemmr(0x2144, 0x00000000);
423 writemmr(0x2148, 0x00000000);
424 writemmr(0x2150, 0x00000000);
425 writemmr(0x2154, 0x00000000);
245a2c2c 426 writemmr(0x2120, 0x60000000 | (pitch << 16) | pitch);
1da177e4
LT
427 writemmr(0x216C, 0x00000000);
428 writemmr(0x2170, 0x00000000);
429 writemmr(0x217C, 0x00000000);
430 writemmr(0x2120, 0x10000000);
431 writemmr(0x2130, (2047 << 16) | 2047);
432}
433
434static void image_wait_engine(void)
435{
245a2c2c 436 while (readmmr(0x2164) & 0xF0000000) ;
1da177e4
LT
437}
438
245a2c2c 439static void image_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
1da177e4 440{
245a2c2c
KH
441 writemmr(0x2120, 0x80000000);
442 writemmr(0x2120, 0x90000000 | ROP_S);
1da177e4 443
245a2c2c 444 writemmr(0x2144, c);
1da177e4 445
245a2c2c
KH
446 writemmr(DR1, point(x, y));
447 writemmr(DR2, point(x + w - 1, y + h - 1));
1da177e4 448
245a2c2c 449 writemmr(0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9);
1da177e4
LT
450}
451
245a2c2c 452static void image_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
1da177e4 453{
245a2c2c 454 u32 s1, s2, d1, d2;
1da177e4 455 int direction = 2;
245a2c2c
KH
456 s1 = point(x1, y1);
457 s2 = point(x1 + w - 1, y1 + h - 1);
458 d1 = point(x2, y2);
459 d2 = point(x2 + w - 1, y2 + h - 1);
1da177e4 460
245a2c2c
KH
461 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
462 direction = 0;
463
464 writemmr(0x2120, 0x80000000);
465 writemmr(0x2120, 0x90000000 | ROP_S);
466
467 writemmr(SR1, direction ? s2 : s1);
468 writemmr(SR2, direction ? s1 : s2);
469 writemmr(DR1, direction ? d2 : d1);
470 writemmr(DR2, direction ? d1 : d2);
471 writemmr(0x2124, 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction);
472}
1da177e4
LT
473
474static struct accel_switch accel_image = {
475 image_init_accel,
476 image_wait_engine,
477 image_fill_rect,
478 image_copy_rect,
479};
480
481/*
482 * Accel functions called by the upper layers
483 */
484#ifdef CONFIG_FB_TRIDENT_ACCEL
245a2c2c
KH
485static void tridentfb_fillrect(struct fb_info *info,
486 const struct fb_fillrect *fr)
1da177e4
LT
487{
488 int bpp = info->var.bits_per_pixel;
8dad46cf 489 int col = 0;
245a2c2c 490
1da177e4 491 switch (bpp) {
245a2c2c
KH
492 default:
493 case 8:
494 col |= fr->color;
495 col |= col << 8;
496 col |= col << 16;
497 break;
498 case 16:
499 col = ((u32 *)(info->pseudo_palette))[fr->color];
500 break;
501 case 32:
502 col = ((u32 *)(info->pseudo_palette))[fr->color];
503 break;
504 }
505
1da177e4
LT
506 acc->fill_rect(fr->dx, fr->dy, fr->width, fr->height, col, fr->rop);
507 acc->wait_engine();
508}
245a2c2c
KH
509static void tridentfb_copyarea(struct fb_info *info,
510 const struct fb_copyarea *ca)
1da177e4 511{
245a2c2c 512 acc->copy_rect(ca->sx, ca->sy, ca->dx, ca->dy, ca->width, ca->height);
1da177e4
LT
513 acc->wait_engine();
514}
515#else /* !CONFIG_FB_TRIDENT_ACCEL */
516#define tridentfb_fillrect cfb_fillrect
517#define tridentfb_copyarea cfb_copyarea
518#endif /* CONFIG_FB_TRIDENT_ACCEL */
519
520
521/*
522 * Hardware access functions
523 */
524
525static inline unsigned char read3X4(int reg)
526{
245a2c2c 527 struct tridentfb_par *par = (struct tridentfb_par *)fb_info.par;
1da177e4 528 writeb(reg, par->io_virt + CRT + 4);
245a2c2c 529 return readb(par->io_virt + CRT + 5);
1da177e4
LT
530}
531
532static inline void write3X4(int reg, unsigned char val)
533{
245a2c2c 534 struct tridentfb_par *par = (struct tridentfb_par *)fb_info.par;
1da177e4
LT
535 writeb(reg, par->io_virt + CRT + 4);
536 writeb(val, par->io_virt + CRT + 5);
537}
538
539static inline unsigned char read3C4(int reg)
540{
541 t_outb(reg, 0x3C4);
542 return t_inb(0x3C5);
543}
544
545static inline void write3C4(int reg, unsigned char val)
546{
547 t_outb(reg, 0x3C4);
548 t_outb(val, 0x3C5);
549}
550
551static inline unsigned char read3CE(int reg)
552{
553 t_outb(reg, 0x3CE);
554 return t_inb(0x3CF);
555}
556
557static inline void writeAttr(int reg, unsigned char val)
558{
245a2c2c 559 readb(((struct tridentfb_par *)fb_info.par)->io_virt + CRT + 0x0A); /* flip-flop to index */
1da177e4
LT
560 t_outb(reg, 0x3C0);
561 t_outb(val, 0x3C0);
562}
563
564static inline void write3CE(int reg, unsigned char val)
565{
566 t_outb(reg, 0x3CE);
567 t_outb(val, 0x3CF);
568}
569
e8ed857c 570static void enable_mmio(void)
1da177e4
LT
571{
572 /* Goto New Mode */
573 outb(0x0B, 0x3C4);
574 inb(0x3C5);
575
576 /* Unprotect registers */
577 outb(NewMode1, 0x3C4);
578 outb(0x80, 0x3C5);
245a2c2c 579
1da177e4 580 /* Enable MMIO */
245a2c2c 581 outb(PCIReg, 0x3D4);
1da177e4 582 outb(inb(0x3D5) | 0x01, 0x3D5);
e8ed857c
KH
583}
584
585static void disable_mmio(void)
586{
e8ed857c
KH
587 /* Goto New Mode */
588 t_outb(0x0B, 0x3C4);
589 t_inb(0x3C5);
590
591 /* Unprotect registers */
592 t_outb(NewMode1, 0x3C4);
e8ed857c
KH
593 t_outb(0x80, 0x3C5);
594
595 /* Disable MMIO */
596 t_outb(PCIReg, 0x3D4);
597 t_outb(t_inb(0x3D5) & ~0x01, 0x3D5);
1da177e4
LT
598}
599
1da177e4
LT
600#define crtc_unlock() write3X4(CRTVSyncEnd, read3X4(CRTVSyncEnd) & 0x7F)
601
602/* Return flat panel's maximum x resolution */
474ab45a 603static int __devinit get_nativex(void)
1da177e4 604{
245a2c2c 605 int x, y, tmp;
1da177e4
LT
606
607 if (nativex)
608 return nativex;
609
245a2c2c 610 tmp = (read3CE(VertStretch) >> 4) & 3;
1da177e4
LT
611
612 switch (tmp) {
245a2c2c
KH
613 case 0:
614 x = 1280; y = 1024;
615 break;
616 case 2:
617 x = 1024; y = 768;
618 break;
619 case 3:
620 x = 800; y = 600;
621 break;
622 case 4:
623 x = 1400; y = 1050;
624 break;
625 case 1:
626 default:
627 x = 640; y = 480;
628 break;
1da177e4
LT
629 }
630
631 output("%dx%d flat panel found\n", x, y);
632 return x;
633}
634
635/* Set pitch */
636static void set_lwidth(int width)
637{
638 write3X4(Offset, width & 0xFF);
245a2c2c
KH
639 write3X4(AddColReg,
640 (read3X4(AddColReg) & 0xCF) | ((width & 0x300) >> 4));
1da177e4
LT
641}
642
643/* For resolutions smaller than FP resolution stretch */
644static void screen_stretch(void)
645{
245a2c2c
KH
646 if (chip_id != CYBERBLADEXPAi1)
647 write3CE(BiosReg, 0);
648 else
649 write3CE(BiosReg, 8);
650 write3CE(VertStretch, (read3CE(VertStretch) & 0x7C) | 1);
651 write3CE(HorStretch, (read3CE(HorStretch) & 0x7C) | 1);
1da177e4
LT
652}
653
654/* For resolutions smaller than FP resolution center */
655static void screen_center(void)
656{
245a2c2c
KH
657 write3CE(VertStretch, (read3CE(VertStretch) & 0x7C) | 0x80);
658 write3CE(HorStretch, (read3CE(HorStretch) & 0x7C) | 0x80);
1da177e4
LT
659}
660
661/* Address of first shown pixel in display memory */
662static void set_screen_start(int base)
663{
664 write3X4(StartAddrLow, base & 0xFF);
665 write3X4(StartAddrHigh, (base & 0xFF00) >> 8);
245a2c2c
KH
666 write3X4(CRTCModuleTest,
667 (read3X4(CRTCModuleTest) & 0xDF) | ((base & 0x10000) >> 11));
668 write3X4(CRTHiOrd,
669 (read3X4(CRTHiOrd) & 0xF8) | ((base & 0xE0000) >> 17));
1da177e4
LT
670}
671
672/* Use 20.12 fixed-point for NTSC value and frequency calculation */
245a2c2c 673#define calc_freq(n, m, k) ( ((unsigned long)0xE517 * (n + 8) / ((m + 2) * (1 << k))) >> 12 )
1da177e4
LT
674
675/* Set dotclock frequency */
676static void set_vclk(int freq)
677{
245a2c2c
KH
678 int m, n, k;
679 int f, fi, d, di;
680 unsigned char lo = 0, hi = 0;
1da177e4
LT
681
682 d = 20;
245a2c2c
KH
683 for (k = 2; k >= 0; k--)
684 for (m = 0; m < 63; m++)
685 for (n = 0; n < 128; n++) {
686 fi = calc_freq(n, m, k);
687 if ((di = abs(fi - freq)) < d) {
688 d = di;
689 f = fi;
690 lo = n;
691 hi = (k << 6) | m;
692 }
693 }
1da177e4 694 if (chip3D) {
245a2c2c
KH
695 write3C4(ClockHigh, hi);
696 write3C4(ClockLow, lo);
1da177e4 697 } else {
245a2c2c
KH
698 outb(lo, 0x43C8);
699 outb(hi, 0x43C9);
1da177e4 700 }
245a2c2c 701 debug("VCLK = %X %X\n", hi, lo);
1da177e4
LT
702}
703
704/* Set number of lines for flat panels*/
705static void set_number_of_lines(int lines)
706{
707 int tmp = read3CE(CyberEnhance) & 0x8F;
708 if (lines > 1024)
709 tmp |= 0x50;
710 else if (lines > 768)
711 tmp |= 0x30;
712 else if (lines > 600)
713 tmp |= 0x20;
714 else if (lines > 480)
715 tmp |= 0x10;
716 write3CE(CyberEnhance, tmp);
717}
718
719/*
720 * If we see that FP is active we assume we have one.
721 * Otherwise we have a CRT display.User can override.
722 */
474ab45a 723static unsigned int __devinit get_displaytype(void)
1da177e4
LT
724{
725 if (fp)
726 return DISPLAY_FP;
727 if (crt || !chipcyber)
728 return DISPLAY_CRT;
245a2c2c 729 return (read3CE(FPConfig) & 0x10) ? DISPLAY_FP : DISPLAY_CRT;
1da177e4
LT
730}
731
732/* Try detecting the video memory size */
474ab45a 733static unsigned int __devinit get_memsize(void)
1da177e4
LT
734{
735 unsigned char tmp, tmp2;
736 unsigned int k;
737
738 /* If memory size provided by user */
739 if (memsize)
740 k = memsize * Kb;
741 else
245a2c2c
KH
742 switch (chip_id) {
743 case CYBER9525DVD:
744 k = 2560 * Kb;
745 break;
1da177e4
LT
746 default:
747 tmp = read3X4(SPR) & 0x0F;
748 switch (tmp) {
749
245a2c2c 750 case 0x01:
b614ce8b 751 k = 512 * Kb;
245a2c2c
KH
752 break;
753 case 0x02:
754 k = 6 * Mb; /* XP */
755 break;
756 case 0x03:
757 k = 1 * Mb;
758 break;
759 case 0x04:
760 k = 8 * Mb;
761 break;
762 case 0x06:
763 k = 10 * Mb; /* XP */
764 break;
765 case 0x07:
766 k = 2 * Mb;
767 break;
768 case 0x08:
769 k = 12 * Mb; /* XP */
770 break;
771 case 0x0A:
772 k = 14 * Mb; /* XP */
773 break;
774 case 0x0C:
775 k = 16 * Mb; /* XP */
776 break;
777 case 0x0E: /* XP */
778
779 tmp2 = read3C4(0xC1);
780 switch (tmp2) {
781 case 0x00:
782 k = 20 * Mb;
783 break;
784 case 0x01:
785 k = 24 * Mb;
786 break;
787 case 0x10:
788 k = 28 * Mb;
789 break;
790 case 0x11:
791 k = 32 * Mb;
792 break;
793 default:
794 k = 1 * Mb;
795 break;
796 }
797 break;
798
799 case 0x0F:
800 k = 4 * Mb;
801 break;
802 default:
803 k = 1 * Mb;
1da177e4 804 break;
1da177e4 805 }
245a2c2c 806 }
1da177e4
LT
807
808 k -= memdiff * Kb;
245a2c2c 809 output("framebuffer size = %d Kb\n", k / Kb);
1da177e4
LT
810 return k;
811}
812
813/* See if we can handle the video mode described in var */
245a2c2c
KH
814static int tridentfb_check_var(struct fb_var_screeninfo *var,
815 struct fb_info *info)
1da177e4
LT
816{
817 int bpp = var->bits_per_pixel;
818 debug("enter\n");
819
820 /* check color depth */
245a2c2c 821 if (bpp == 24)
1da177e4 822 bpp = var->bits_per_pixel = 32;
245a2c2c 823 /* check whether resolution fits on panel and in memory */
1da177e4
LT
824 if (flatpanel && nativex && var->xres > nativex)
825 return -EINVAL;
245a2c2c 826 if (var->xres * var->yres_virtual * bpp / 8 > info->fix.smem_len)
1da177e4
LT
827 return -EINVAL;
828
829 switch (bpp) {
245a2c2c
KH
830 case 8:
831 var->red.offset = 0;
832 var->green.offset = 0;
833 var->blue.offset = 0;
834 var->red.length = 6;
835 var->green.length = 6;
836 var->blue.length = 6;
837 break;
838 case 16:
839 var->red.offset = 11;
840 var->green.offset = 5;
841 var->blue.offset = 0;
842 var->red.length = 5;
843 var->green.length = 6;
844 var->blue.length = 5;
845 break;
846 case 32:
847 var->red.offset = 16;
848 var->green.offset = 8;
849 var->blue.offset = 0;
850 var->red.length = 8;
851 var->green.length = 8;
852 var->blue.length = 8;
853 break;
854 default:
855 return -EINVAL;
1da177e4
LT
856 }
857 debug("exit\n");
858
859 return 0;
860
861}
245a2c2c 862
1da177e4
LT
863/* Pan the display */
864static int tridentfb_pan_display(struct fb_var_screeninfo *var,
245a2c2c 865 struct fb_info *info)
1da177e4
LT
866{
867 unsigned int offset;
868
869 debug("enter\n");
870 offset = (var->xoffset + (var->yoffset * var->xres))
245a2c2c 871 * var->bits_per_pixel / 32;
1da177e4
LT
872 info->var.xoffset = var->xoffset;
873 info->var.yoffset = var->yoffset;
874 set_screen_start(offset);
875 debug("exit\n");
876 return 0;
877}
878
245a2c2c
KH
879#define shadowmode_on() write3CE(CyberControl, read3CE(CyberControl) | 0x81)
880#define shadowmode_off() write3CE(CyberControl, read3CE(CyberControl) & 0x7E)
1da177e4
LT
881
882/* Set the hardware to the requested video mode */
883static int tridentfb_set_par(struct fb_info *info)
884{
245a2c2c
KH
885 struct tridentfb_par *par = (struct tridentfb_par *)(info->par);
886 u32 htotal, hdispend, hsyncstart, hsyncend, hblankstart, hblankend;
887 u32 vtotal, vdispend, vsyncstart, vsyncend, vblankstart, vblankend;
888 struct fb_var_screeninfo *var = &info->var;
1da177e4
LT
889 int bpp = var->bits_per_pixel;
890 unsigned char tmp;
891 debug("enter\n");
245a2c2c
KH
892 hdispend = var->xres / 8 - 1;
893 hsyncstart = (var->xres + var->right_margin) / 8;
894 hsyncend = var->hsync_len / 8;
895 htotal =
896 (var->xres + var->left_margin + var->right_margin +
897 var->hsync_len) / 8 - 10;
1da177e4
LT
898 hblankstart = hdispend + 1;
899 hblankend = htotal + 5;
900
1da177e4
LT
901 vdispend = var->yres - 1;
902 vsyncstart = var->yres + var->lower_margin;
903 vsyncend = var->vsync_len;
245a2c2c 904 vtotal = var->upper_margin + vsyncstart + vsyncend - 2;
1da177e4
LT
905 vblankstart = var->yres;
906 vblankend = vtotal + 2;
907
1da177e4 908 crtc_unlock();
245a2c2c 909 write3CE(CyberControl, 8);
1da177e4
LT
910
911 if (flatpanel && var->xres < nativex) {
912 /*
913 * on flat panels with native size larger
914 * than requested resolution decide whether
915 * we stretch or center
916 */
245a2c2c 917 t_outb(0xEB, 0x3C2);
1da177e4
LT
918
919 shadowmode_on();
920
245a2c2c 921 if (center)
1da177e4
LT
922 screen_center();
923 else if (stretch)
924 screen_stretch();
925
926 } else {
245a2c2c
KH
927 t_outb(0x2B, 0x3C2);
928 write3CE(CyberControl, 8);
1da177e4
LT
929 }
930
931 /* vertical timing values */
932 write3X4(CRTVTotal, vtotal & 0xFF);
933 write3X4(CRTVDispEnd, vdispend & 0xFF);
934 write3X4(CRTVSyncStart, vsyncstart & 0xFF);
935 write3X4(CRTVSyncEnd, (vsyncend & 0x0F));
936 write3X4(CRTVBlankStart, vblankstart & 0xFF);
245a2c2c 937 write3X4(CRTVBlankEnd, 0 /* p->vblankend & 0xFF */ );
1da177e4
LT
938
939 /* horizontal timing values */
940 write3X4(CRTHTotal, htotal & 0xFF);
941 write3X4(CRTHDispEnd, hdispend & 0xFF);
942 write3X4(CRTHSyncStart, hsyncstart & 0xFF);
245a2c2c 943 write3X4(CRTHSyncEnd, (hsyncend & 0x1F) | ((hblankend & 0x20) << 2));
1da177e4 944 write3X4(CRTHBlankStart, hblankstart & 0xFF);
245a2c2c 945 write3X4(CRTHBlankEnd, 0 /* (p->hblankend & 0x1F) */ );
1da177e4
LT
946
947 /* higher bits of vertical timing values */
948 tmp = 0x10;
949 if (vtotal & 0x100) tmp |= 0x01;
950 if (vdispend & 0x100) tmp |= 0x02;
951 if (vsyncstart & 0x100) tmp |= 0x04;
952 if (vblankstart & 0x100) tmp |= 0x08;
953
954 if (vtotal & 0x200) tmp |= 0x20;
955 if (vdispend & 0x200) tmp |= 0x40;
956 if (vsyncstart & 0x200) tmp |= 0x80;
957 write3X4(CRTOverflow, tmp);
958
245a2c2c 959 tmp = read3X4(CRTHiOrd) | 0x08; /* line compare bit 10 */
1da177e4
LT
960 if (vtotal & 0x400) tmp |= 0x80;
961 if (vblankstart & 0x400) tmp |= 0x40;
962 if (vsyncstart & 0x400) tmp |= 0x20;
963 if (vdispend & 0x400) tmp |= 0x10;
964 write3X4(CRTHiOrd, tmp);
965
966 tmp = 0;
967 if (htotal & 0x800) tmp |= 0x800 >> 11;
968 if (hblankstart & 0x800) tmp |= 0x800 >> 7;
969 write3X4(HorizOverflow, tmp);
245a2c2c 970
1da177e4
LT
971 tmp = 0x40;
972 if (vblankstart & 0x200) tmp |= 0x20;
245a2c2c 973//FIXME if (info->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; /* double scan for 200 line modes */
1da177e4
LT
974 write3X4(CRTMaxScanLine, tmp);
975
245a2c2c
KH
976 write3X4(CRTLineCompare, 0xFF);
977 write3X4(CRTPRowScan, 0);
978 write3X4(CRTModeControl, 0xC3);
1da177e4 979
245a2c2c 980 write3X4(LinearAddReg, 0x20); /* enable linear addressing */
1da177e4 981
245a2c2c
KH
982 tmp = (info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80;
983 write3X4(CRTCModuleTest, tmp); /* enable access extended memory */
1da177e4 984
245a2c2c 985 write3X4(GraphEngReg, 0x80); /* enable GE for text acceleration */
1da177e4 986
245a2c2c
KH
987#ifdef CONFIG_FB_TRIDENT_ACCEL
988 acc->init_accel(info->var.xres, bpp);
8dad46cf 989#endif
245a2c2c 990
1da177e4 991 switch (bpp) {
245a2c2c
KH
992 case 8:
993 tmp = 0x00;
994 break;
995 case 16:
996 tmp = 0x05;
997 break;
998 case 24:
999 tmp = 0x29;
1000 break;
1001 case 32:
1002 tmp = 0x09;
1003 break;
1da177e4
LT
1004 }
1005
1006 write3X4(PixelBusReg, tmp);
1007
1008 tmp = 0x10;
1009 if (chipcyber)
245a2c2c
KH
1010 tmp |= 0x20;
1011 write3X4(DRAMControl, tmp); /* both IO, linear enable */
1da177e4
LT
1012
1013 write3X4(InterfaceSel, read3X4(InterfaceSel) | 0x40);
245a2c2c
KH
1014 write3X4(Performance, 0x92);
1015 write3X4(PCIReg, 0x07); /* MMIO & PCI read and write burst enable */
1da177e4
LT
1016
1017 /* convert from picoseconds to MHz */
245a2c2c 1018 par->vclk = 1000000 / info->var.pixclock;
1da177e4 1019 if (bpp == 32)
245a2c2c 1020 par->vclk *= 2;
1da177e4
LT
1021 set_vclk(par->vclk);
1022
245a2c2c
KH
1023 write3C4(0, 3);
1024 write3C4(1, 1); /* set char clock 8 dots wide */
1025 write3C4(2, 0x0F); /* enable 4 maps because needed in chain4 mode */
1026 write3C4(3, 0);
1027 write3C4(4, 0x0E); /* memory mode enable bitmaps ?? */
1da177e4 1028
245a2c2c
KH
1029 write3CE(MiscExtFunc, (bpp == 32) ? 0x1A : 0x12); /* divide clock by 2 if 32bpp */
1030 /* chain4 mode display and CPU path */
1031 write3CE(0x5, 0x40); /* no CGA compat, allow 256 col */
1032 write3CE(0x6, 0x05); /* graphics mode */
1033 write3CE(0x7, 0x0F); /* planes? */
1da177e4
LT
1034
1035 if (chip_id == CYBERBLADEXPAi1) {
1036 /* This fixes snow-effect in 32 bpp */
245a2c2c 1037 write3X4(CRTHSyncStart, 0x84);
1da177e4
LT
1038 }
1039
245a2c2c
KH
1040 writeAttr(0x10, 0x41); /* graphics mode and support 256 color modes */
1041 writeAttr(0x12, 0x0F); /* planes */
1042 writeAttr(0x13, 0); /* horizontal pel panning */
1da177e4 1043
245a2c2c
KH
1044 /* colors */
1045 for (tmp = 0; tmp < 0x10; tmp++)
1046 writeAttr(tmp, tmp);
1047 readb(par->io_virt + CRT + 0x0A); /* flip-flop to index */
1048 t_outb(0x20, 0x3C0); /* enable attr */
1da177e4
LT
1049
1050 switch (bpp) {
245a2c2c
KH
1051 case 8:
1052 tmp = 0;
1053 break;
1054 case 15:
1055 tmp = 0x10;
1056 break;
1057 case 16:
1058 tmp = 0x30;
1059 break;
1060 case 24:
1061 case 32:
1062 tmp = 0xD0;
1063 break;
1da177e4
LT
1064 }
1065
1066 t_inb(0x3C8);
1067 t_inb(0x3C6);
1068 t_inb(0x3C6);
1069 t_inb(0x3C6);
1070 t_inb(0x3C6);
245a2c2c 1071 t_outb(tmp, 0x3C6);
1da177e4
LT
1072 t_inb(0x3C8);
1073
1074 if (flatpanel)
1075 set_number_of_lines(info->var.yres);
245a2c2c 1076 set_lwidth(info->var.xres * bpp / (4 * 16));
1da177e4 1077 info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
245a2c2c
KH
1078 info->fix.line_length = info->var.xres * (bpp >> 3);
1079 info->cmap.len = (bpp == 8) ? 256 : 16;
1da177e4
LT
1080 debug("exit\n");
1081 return 0;
1082}
1083
1084/* Set one color register */
1085static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green,
245a2c2c
KH
1086 unsigned blue, unsigned transp,
1087 struct fb_info *info)
1da177e4
LT
1088{
1089 int bpp = info->var.bits_per_pixel;
1090
1091 if (regno >= info->cmap.len)
1092 return 1;
1093
973d9ab2 1094 if (bpp == 8) {
245a2c2c
KH
1095 t_outb(0xFF, 0x3C6);
1096 t_outb(regno, 0x3C8);
1da177e4 1097
245a2c2c
KH
1098 t_outb(red >> 10, 0x3C9);
1099 t_outb(green >> 10, 0x3C9);
1100 t_outb(blue >> 10, 0x3C9);
1da177e4 1101
973d9ab2
AD
1102 } else if (regno < 16) {
1103 if (bpp == 16) { /* RGB 565 */
1104 u32 col;
1105
1106 col = (red & 0xF800) | ((green & 0xFC00) >> 5) |
1107 ((blue & 0xF800) >> 11);
1108 col |= col << 16;
1109 ((u32 *)(info->pseudo_palette))[regno] = col;
1110 } else if (bpp == 32) /* ARGB 8888 */
1111 ((u32*)info->pseudo_palette)[regno] =
245a2c2c
KH
1112 ((transp & 0xFF00) << 16) |
1113 ((red & 0xFF00) << 8) |
973d9ab2 1114 ((green & 0xFF00)) |
245a2c2c 1115 ((blue & 0xFF00) >> 8);
973d9ab2 1116 }
1da177e4 1117
245a2c2c 1118/* debug("exit\n"); */
1da177e4
LT
1119 return 0;
1120}
1121
1122/* Try blanking the screen.For flat panels it does nothing */
1123static int tridentfb_blank(int blank_mode, struct fb_info *info)
1124{
245a2c2c 1125 unsigned char PMCont, DPMSCont;
1da177e4
LT
1126
1127 debug("enter\n");
1128 if (flatpanel)
1129 return 0;
245a2c2c 1130 t_outb(0x04, 0x83C8); /* Read DPMS Control */
1da177e4
LT
1131 PMCont = t_inb(0x83C6) & 0xFC;
1132 DPMSCont = read3CE(PowerStatus) & 0xFC;
245a2c2c 1133 switch (blank_mode) {
1da177e4
LT
1134 case FB_BLANK_UNBLANK:
1135 /* Screen: On, HSync: On, VSync: On */
1136 case FB_BLANK_NORMAL:
1137 /* Screen: Off, HSync: On, VSync: On */
1138 PMCont |= 0x03;
1139 DPMSCont |= 0x00;
1140 break;
1141 case FB_BLANK_HSYNC_SUSPEND:
1142 /* Screen: Off, HSync: Off, VSync: On */
1143 PMCont |= 0x02;
1144 DPMSCont |= 0x01;
1145 break;
1146 case FB_BLANK_VSYNC_SUSPEND:
1147 /* Screen: Off, HSync: On, VSync: Off */
1148 PMCont |= 0x02;
1149 DPMSCont |= 0x02;
1150 break;
1151 case FB_BLANK_POWERDOWN:
1152 /* Screen: Off, HSync: Off, VSync: Off */
1153 PMCont |= 0x00;
1154 DPMSCont |= 0x03;
1155 break;
245a2c2c 1156 }
1da177e4 1157
245a2c2c
KH
1158 write3CE(PowerStatus, DPMSCont);
1159 t_outb(4, 0x83C8);
1160 t_outb(PMCont, 0x83C6);
1da177e4
LT
1161
1162 debug("exit\n");
1163
1164 /* let fbcon do a softblank for us */
1165 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
1166}
1167
245a2c2c
KH
1168static struct fb_ops tridentfb_ops = {
1169 .owner = THIS_MODULE,
1170 .fb_setcolreg = tridentfb_setcolreg,
1171 .fb_pan_display = tridentfb_pan_display,
1172 .fb_blank = tridentfb_blank,
1173 .fb_check_var = tridentfb_check_var,
1174 .fb_set_par = tridentfb_set_par,
1175 .fb_fillrect = tridentfb_fillrect,
1176 .fb_copyarea = tridentfb_copyarea,
1177 .fb_imageblit = cfb_imageblit,
1178};
1179
1180static int __devinit trident_pci_probe(struct pci_dev * dev,
1181 const struct pci_device_id * id)
1da177e4
LT
1182{
1183 int err;
1184 unsigned char revision;
1185
1186 err = pci_enable_device(dev);
1187 if (err)
1188 return err;
1189
1190 chip_id = id->device;
1191
245a2c2c 1192 if (chip_id == CYBERBLADEi1)
9fa68eae
KP
1193 output("*** Please do use cyblafb, Cyberblade/i1 support "
1194 "will soon be removed from tridentfb!\n");
1195
1196
1da177e4 1197 /* If PCI id is 0x9660 then further detect chip type */
245a2c2c 1198
1da177e4 1199 if (chip_id == TGUI9660) {
245a2c2c
KH
1200 outb(RevisionID, 0x3C4);
1201 revision = inb(0x3C5);
1202
1da177e4 1203 switch (revision) {
245a2c2c
KH
1204 case 0x22:
1205 case 0x23:
1206 chip_id = CYBER9397;
1207 break;
1208 case 0x2A:
1209 chip_id = CYBER9397DVD;
1210 break;
1211 case 0x30:
1212 case 0x33:
1213 case 0x34:
1214 case 0x35:
1215 case 0x38:
1216 case 0x3A:
1217 case 0xB3:
1218 chip_id = CYBER9385;
1219 break;
1220 case 0x40 ... 0x43:
1221 chip_id = CYBER9382;
1222 break;
1223 case 0x4A:
1224 chip_id = CYBER9388;
1225 break;
1226 default:
1227 break;
1da177e4
LT
1228 }
1229 }
1230
1231 chip3D = is3Dchip(chip_id);
1232 chipcyber = iscyber(chip_id);
1233
1234 if (is_xp(chip_id)) {
1235 acc = &accel_xp;
245a2c2c 1236 } else if (is_blade(chip_id)) {
1da177e4
LT
1237 acc = &accel_blade;
1238 } else {
1239 acc = &accel_image;
1240 }
1241
1242 /* acceleration is on by default for 3D chips */
1243 defaultaccel = chip3D && !noaccel;
1244
1245 fb_info.par = &default_par;
1246
1247 /* setup MMIO region */
245a2c2c
KH
1248 tridentfb_fix.mmio_start = pci_resource_start(dev, 1);
1249 tridentfb_fix.mmio_len = chip3D ? 0x20000 : 0x10000;
1da177e4
LT
1250
1251 if (!request_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len, "tridentfb")) {
1252 debug("request_region failed!\n");
1253 return -1;
1254 }
1255
1256 default_par.io_virt = ioremap_nocache(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
1257
1258 if (!default_par.io_virt) {
1da177e4 1259 debug("ioremap failed\n");
e8ed857c
KH
1260 err = -1;
1261 goto out_unmap1;
1da177e4
LT
1262 }
1263
1264 enable_mmio();
245a2c2c 1265
1da177e4 1266 /* setup framebuffer memory */
245a2c2c 1267 tridentfb_fix.smem_start = pci_resource_start(dev, 0);
1da177e4 1268 tridentfb_fix.smem_len = get_memsize();
245a2c2c 1269
1da177e4
LT
1270 if (!request_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len, "tridentfb")) {
1271 debug("request_mem_region failed!\n");
e8ed857c 1272 disable_mmio();
a02f6402 1273 err = -1;
e8ed857c 1274 goto out_unmap1;
1da177e4
LT
1275 }
1276
1277 fb_info.screen_base = ioremap_nocache(tridentfb_fix.smem_start,
245a2c2c 1278 tridentfb_fix.smem_len);
1da177e4
LT
1279
1280 if (!fb_info.screen_base) {
1da177e4 1281 debug("ioremap failed\n");
a02f6402 1282 err = -1;
e8ed857c 1283 goto out_unmap2;
1da177e4
LT
1284 }
1285
1286 output("%s board found\n", pci_name(dev));
1da177e4
LT
1287 displaytype = get_displaytype();
1288
245a2c2c 1289 if (flatpanel)
1da177e4
LT
1290 nativex = get_nativex();
1291
1292 fb_info.fix = tridentfb_fix;
1293 fb_info.fbops = &tridentfb_ops;
1294
1295
1296 fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1297#ifdef CONFIG_FB_TRIDENT_ACCEL
1298 fb_info.flags |= FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT;
1299#endif
1300 fb_info.pseudo_palette = pseudo_pal;
1301
07f41e45
KH
1302 if (!fb_find_mode(&default_var, &fb_info,
1303 mode_option, NULL, 0, NULL, bpp)) {
a02f6402 1304 err = -EINVAL;
e8ed857c 1305 goto out_unmap2;
a02f6402 1306 }
e8ed857c
KH
1307 err = fb_alloc_cmap(&fb_info.cmap, 256, 0);
1308 if (err < 0)
1309 goto out_unmap2;
1310
1da177e4
LT
1311 if (defaultaccel && acc)
1312 default_var.accel_flags |= FB_ACCELF_TEXT;
1313 else
1314 default_var.accel_flags &= ~FB_ACCELF_TEXT;
1315 default_var.activate |= FB_ACTIVATE_NOW;
1316 fb_info.var = default_var;
1317 fb_info.device = &dev->dev;
1318 if (register_framebuffer(&fb_info) < 0) {
1319 printk(KERN_ERR "tridentfb: could not register Trident framebuffer\n");
e8ed857c 1320 fb_dealloc_cmap(&fb_info.cmap);
a02f6402 1321 err = -EINVAL;
e8ed857c 1322 goto out_unmap2;
1da177e4
LT
1323 }
1324 output("fb%d: %s frame buffer device %dx%d-%dbpp\n",
245a2c2c
KH
1325 fb_info.node, fb_info.fix.id, default_var.xres,
1326 default_var.yres, default_var.bits_per_pixel);
1da177e4 1327 return 0;
a02f6402 1328
e8ed857c 1329out_unmap2:
a02f6402
AL
1330 if (fb_info.screen_base)
1331 iounmap(fb_info.screen_base);
e8ed857c
KH
1332 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
1333 disable_mmio();
1334out_unmap1:
1335 if (default_par.io_virt)
1336 iounmap(default_par.io_virt);
1337 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
a02f6402 1338 return err;
1da177e4
LT
1339}
1340
245a2c2c 1341static void __devexit trident_pci_remove(struct pci_dev *dev)
1da177e4
LT
1342{
1343 struct tridentfb_par *par = (struct tridentfb_par*)fb_info.par;
1344 unregister_framebuffer(&fb_info);
1345 iounmap(par->io_virt);
1346 iounmap(fb_info.screen_base);
1347 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
e8ed857c 1348 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
1da177e4
LT
1349}
1350
1351/* List of boards that we are trying to support */
1352static struct pci_device_id trident_devices[] = {
245a2c2c
KH
1353 {PCI_VENDOR_ID_TRIDENT, BLADE3D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1354 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1355 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1356 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1357 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1358 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1359 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1360 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEE4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1361 {PCI_VENDOR_ID_TRIDENT, TGUI9660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1362 {PCI_VENDOR_ID_TRIDENT, IMAGE975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1363 {PCI_VENDOR_ID_TRIDENT, IMAGE985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1364 {PCI_VENDOR_ID_TRIDENT, CYBER9320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1365 {PCI_VENDOR_ID_TRIDENT, CYBER9388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1366 {PCI_VENDOR_ID_TRIDENT, CYBER9520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1367 {PCI_VENDOR_ID_TRIDENT, CYBER9525DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1368 {PCI_VENDOR_ID_TRIDENT, CYBER9397, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1369 {PCI_VENDOR_ID_TRIDENT, CYBER9397DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1370 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1371 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1372 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1da177e4 1373 {0,}
245a2c2c
KH
1374};
1375
1376MODULE_DEVICE_TABLE(pci, trident_devices);
1da177e4
LT
1377
1378static struct pci_driver tridentfb_pci_driver = {
245a2c2c
KH
1379 .name = "tridentfb",
1380 .id_table = trident_devices,
1381 .probe = trident_pci_probe,
1382 .remove = __devexit_p(trident_pci_remove)
1da177e4
LT
1383};
1384
1385/*
1386 * Parse user specified options (`video=trident:')
1387 * example:
245a2c2c 1388 * video=trident:800x600,bpp=16,noaccel
1da177e4
LT
1389 */
1390#ifndef MODULE
07f41e45 1391static int __init tridentfb_setup(char *options)
1da177e4 1392{
245a2c2c 1393 char *opt;
1da177e4
LT
1394 if (!options || !*options)
1395 return 0;
245a2c2c
KH
1396 while ((opt = strsep(&options, ",")) != NULL) {
1397 if (!*opt)
1398 continue;
1399 if (!strncmp(opt, "noaccel", 7))
1da177e4 1400 noaccel = 1;
245a2c2c 1401 else if (!strncmp(opt, "fp", 2))
1da177e4 1402 displaytype = DISPLAY_FP;
245a2c2c 1403 else if (!strncmp(opt, "crt", 3))
1da177e4 1404 displaytype = DISPLAY_CRT;
245a2c2c
KH
1405 else if (!strncmp(opt, "bpp=", 4))
1406 bpp = simple_strtoul(opt + 4, NULL, 0);
1407 else if (!strncmp(opt, "center", 6))
1da177e4 1408 center = 1;
245a2c2c 1409 else if (!strncmp(opt, "stretch", 7))
1da177e4 1410 stretch = 1;
245a2c2c
KH
1411 else if (!strncmp(opt, "memsize=", 8))
1412 memsize = simple_strtoul(opt + 8, NULL, 0);
1413 else if (!strncmp(opt, "memdiff=", 8))
1414 memdiff = simple_strtoul(opt + 8, NULL, 0);
1415 else if (!strncmp(opt, "nativex=", 8))
1416 nativex = simple_strtoul(opt + 8, NULL, 0);
1da177e4 1417 else
07f41e45 1418 mode_option = opt;
1da177e4
LT
1419 }
1420 return 0;
1421}
1422#endif
1423
1424static int __init tridentfb_init(void)
1425{
1426#ifndef MODULE
1427 char *option = NULL;
1428
1429 if (fb_get_options("tridentfb", &option))
1430 return -ENODEV;
1431 tridentfb_setup(option);
1432#endif
1433 output("Trident framebuffer %s initializing\n", VERSION);
1434 return pci_register_driver(&tridentfb_pci_driver);
1435}
1436
1437static void __exit tridentfb_exit(void)
1438{
1439 pci_unregister_driver(&tridentfb_pci_driver);
1440}
1441
1da177e4
LT
1442module_init(tridentfb_init);
1443module_exit(tridentfb_exit);
1444
1445MODULE_AUTHOR("Jani Monoses <jani@iv.ro>");
1446MODULE_DESCRIPTION("Framebuffer driver for Trident cards");
1447MODULE_LICENSE("GPL");
1448
This page took 0.426275 seconds and 5 git commands to generate.