blob: 919ce75db9e2ce1a0bcf6ce71d498eace0233c38 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Frame buffer driver for Trident Blade and Image series
3 *
Krzysztof Helt245a2c22007-10-16 01:28:42 -07004 * Copyright 2001, 2002 - Jani Monoses <jani@iv.ro>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 *
7 * CREDITS:(in order of appearance)
Krzysztof Helt245a2c22007-10-16 01:28:42 -07008 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * TODO:
Krzysztof Helt245a2c22007-10-16 01:28:42 -070015 * timing value tweaking so it looks good on every monitor in every mode
16 * TGUI acceleration
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#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 {
Krzysztof Helt245a2c22007-10-16 01:28:42 -070030 int vclk; /* in MHz */
31 void __iomem *io_virt; /* iospace virtual memory address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032};
33
Krzysztof Helt245a2c22007-10-16 01:28:42 -070034static unsigned char eng_oper; /* engine operation... */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static struct fb_var_screeninfo default_var;
44
45static struct fb_fix_screeninfo tridentfb_fix = {
Krzysztof Helt245a2c22007-10-16 01:28:42 -070046 .id = "Trident",
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .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
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/* defaults which are normally overriden by user values */
59
60/* video mode */
Krzysztof Helt245a2c22007-10-16 01:28:42 -070061static char *mode = "640x480";
Linus Torvalds1da177e2005-04-16 15:20:36 -070062static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070076module_param(mode, charp, 0);
77module_param(bpp, int, 0);
78module_param(center, int, 0);
79module_param(stretch, int, 0);
80module_param(noaccel, int, 0);
81module_param(memsize, int, 0);
82module_param(memdiff, int, 0);
83module_param(nativex, int, 0);
84module_param(fp, int, 0);
85module_param(crt, int, 0);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static int chip3D;
88static int chipcyber;
89
90static int is3Dchip(int id)
91{
Krzysztof Helt245a2c22007-10-16 01:28:42 -070092 return ((id == BLADE3D) || (id == CYBERBLADEE4) ||
93 (id == CYBERBLADEi7) || (id == CYBERBLADEi7D) ||
94 (id == CYBER9397) || (id == CYBER9397DVD) ||
95 (id == CYBER9520) || (id == CYBER9525DVD) ||
96 (id == IMAGE975) || (id == IMAGE985) ||
97 (id == CYBERBLADEi1) || (id == CYBERBLADEi1D) ||
98 (id == CYBERBLADEAi1) || (id == CYBERBLADEAi1D) ||
99 (id == CYBERBLADEXPm8) || (id == CYBERBLADEXPm16) ||
100 (id == CYBERBLADEXPAi1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
103static int iscyber(int id)
104{
105 switch (id) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700106 case CYBER9388:
107 case CYBER9382:
108 case CYBER9385:
109 case CYBER9397:
110 case CYBER9397DVD:
111 case CYBER9520:
112 case CYBER9525DVD:
113 case CYBERBLADEE4:
114 case CYBERBLADEi7D:
115 case CYBERBLADEi1:
116 case CYBERBLADEi1D:
117 case CYBERBLADEAi1:
118 case CYBERBLADEAi1D:
119 case CYBERBLADEXPAi1:
120 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700122 case CYBER9320:
123 case TGUI9660:
124 case IMAGE975:
125 case IMAGE985:
126 case BLADE3D:
127 case CYBERBLADEi7: /* VIA MPV4 integrated version */
128
129 default:
130 /* case CYBERBLDAEXPm8: Strange */
131 /* case CYBERBLDAEXPm16: Strange */
132 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134}
135
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700136#define CRT 0x3D0 /* CRTC registers offset for color display */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138#ifndef TRIDENT_MMIO
139 #define TRIDENT_MMIO 1
140#endif
141
142#if TRIDENT_MMIO
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700143 #define t_outb(val, reg) writeb(val,((struct tridentfb_par *)(fb_info.par))->io_virt + reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 #define t_inb(reg) readb(((struct tridentfb_par*)(fb_info.par))->io_virt + reg)
145#else
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700146 #define t_outb(val, reg) outb(val, reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 #define t_inb(reg) inb(reg)
148#endif
149
150
151static struct accel_switch {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700152 void (*init_accel) (int, int);
153 void (*wait_engine) (void);
154 void (*fill_rect) (u32, u32, u32, u32, u32, u32);
155 void (*copy_rect) (u32, u32, u32, u32, u32, u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156} *acc;
157
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700158#define writemmr(r, v) writel(v, ((struct tridentfb_par *)fb_info.par)->io_virt + r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#define readmmr(r) readl(((struct tridentfb_par *)fb_info.par)->io_virt + r)
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161/*
162 * Blade specific acceleration.
163 */
164
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700165#define point(x, y) ((y) << 16 | (x))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#define STA 0x2120
167#define CMD 0x2144
168#define ROP 0x2148
169#define CLR 0x2160
170#define SR1 0x2100
171#define SR2 0x2104
172#define DR1 0x2108
173#define DR2 0x210C
174
175#define ROP_S 0xCC
176
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700177static void blade_init_accel(int pitch, int bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700179 int v1 = (pitch >> 3) << 20;
180 int tmp = 0, v2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700182 case 8:
183 tmp = 0;
184 break;
185 case 15:
186 tmp = 5;
187 break;
188 case 16:
189 tmp = 1;
190 break;
191 case 24:
192 case 32:
193 tmp = 2;
194 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700196 v2 = v1 | (tmp << 29);
197 writemmr(0x21C0, v2);
198 writemmr(0x21C4, v2);
199 writemmr(0x21B8, v2);
200 writemmr(0x21BC, v2);
201 writemmr(0x21D0, v1);
202 writemmr(0x21D4, v1);
203 writemmr(0x21C8, v1);
204 writemmr(0x21CC, v1);
205 writemmr(0x216C, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207
208static void blade_wait_engine(void)
209{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700210 while (readmmr(STA) & 0xFA800000) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}
212
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700213static void blade_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700215 writemmr(CLR, c);
216 writemmr(ROP, rop ? 0x66 : ROP_S);
217 writemmr(CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700219 writemmr(DR1, point(x, y));
220 writemmr(DR2, point(x + w - 1, y + h - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
222
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700223static void blade_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700225 u32 s1, s2, d1, d2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 int direction = 2;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700227 s1 = point(x1, y1);
228 s2 = point(x1 + w - 1, y1 + h - 1);
229 d1 = point(x2, y2);
230 d2 = point(x2 + w - 1, y2 + h - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700233 direction = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700235 writemmr(ROP, ROP_S);
236 writemmr(CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700238 writemmr(SR1, direction ? s2 : s1);
239 writemmr(SR2, direction ? s1 : s2);
240 writemmr(DR1, direction ? d2 : d1);
241 writemmr(DR2, direction ? d1 : d2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
243
244static struct accel_switch accel_blade = {
245 blade_init_accel,
246 blade_wait_engine,
247 blade_fill_rect,
248 blade_copy_rect,
249};
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251/*
252 * BladeXP specific acceleration functions
253 */
254
255#define ROP_P 0xF0
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700256#define masked_point(x, y) ((y & 0xffff)<<16|(x & 0xffff))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700258static void xp_init_accel(int pitch, int bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700260 int tmp = 0, v1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 unsigned char x = 0;
262
263 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700264 case 8:
265 x = 0;
266 break;
267 case 16:
268 x = 1;
269 break;
270 case 24:
271 x = 3;
272 break;
273 case 32:
274 x = 2;
275 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
277
278 switch (pitch << (bpp >> 3)) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700279 case 8192:
280 case 512:
281 x |= 0x00;
282 break;
283 case 1024:
284 x |= 0x04;
285 break;
286 case 2048:
287 x |= 0x08;
288 break;
289 case 4096:
290 x |= 0x0C;
291 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
293
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700294 t_outb(x, 0x2125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 eng_oper = x | 0x40;
297
298 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700299 case 8:
300 tmp = 18;
301 break;
302 case 15:
303 case 16:
304 tmp = 19;
305 break;
306 case 24:
307 case 32:
308 tmp = 20;
309 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
312 v1 = pitch << tmp;
313
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700314 writemmr(0x2154, v1);
315 writemmr(0x2150, v1);
316 t_outb(3, 0x2126);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
319static void xp_wait_engine(void)
320{
321 int busy;
322 int count, timeout;
323
324 count = 0;
325 timeout = 0;
326 for (;;) {
327 busy = t_inb(STA) & 0x80;
328 if (busy != 0x80)
329 return;
330 count++;
331 if (count == 10000000) {
332 /* Timeout */
333 count = 9990000;
334 timeout++;
335 if (timeout == 8) {
336 /* Reset engine */
337 t_outb(0x00, 0x2120);
338 return;
339 }
340 }
341 }
342}
343
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700344static void xp_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700346 writemmr(0x2127, ROP_P);
347 writemmr(0x2158, c);
348 writemmr(0x2128, 0x4000);
349 writemmr(0x2140, masked_point(h, w));
350 writemmr(0x2138, masked_point(y, x));
351 t_outb(0x01, 0x2124);
352 t_outb(eng_oper, 0x2125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700355static void xp_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 int direction;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700358 u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 direction = 0x0004;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 if ((x1 < x2) && (y1 == y2)) {
363 direction |= 0x0200;
364 x1_tmp = x1 + w - 1;
365 x2_tmp = x2 + w - 1;
366 } else {
367 x1_tmp = x1;
368 x2_tmp = x2;
369 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 if (y1 < y2) {
372 direction |= 0x0100;
373 y1_tmp = y1 + h - 1;
374 y2_tmp = y2 + h - 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700375 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 y1_tmp = y1;
377 y2_tmp = y2;
378 }
379
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700380 writemmr(0x2128, direction);
381 t_outb(ROP_S, 0x2127);
382 writemmr(0x213C, masked_point(y1_tmp, x1_tmp));
383 writemmr(0x2138, masked_point(y2_tmp, x2_tmp));
384 writemmr(0x2140, masked_point(h, w));
385 t_outb(0x01, 0x2124);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
387
388static struct accel_switch accel_xp = {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700389 xp_init_accel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 xp_wait_engine,
391 xp_fill_rect,
392 xp_copy_rect,
393};
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395/*
396 * Image specific acceleration functions
397 */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700398static void image_init_accel(int pitch, int bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
400 int tmp = 0;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700401 switch (bpp) {
402 case 8:
403 tmp = 0;
404 break;
405 case 15:
406 tmp = 5;
407 break;
408 case 16:
409 tmp = 1;
410 break;
411 case 24:
412 case 32:
413 tmp = 2;
414 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416 writemmr(0x2120, 0xF0000000);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700417 writemmr(0x2120, 0x40000000 | tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 writemmr(0x2120, 0x80000000);
419 writemmr(0x2144, 0x00000000);
420 writemmr(0x2148, 0x00000000);
421 writemmr(0x2150, 0x00000000);
422 writemmr(0x2154, 0x00000000);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700423 writemmr(0x2120, 0x60000000 | (pitch << 16) | pitch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 writemmr(0x216C, 0x00000000);
425 writemmr(0x2170, 0x00000000);
426 writemmr(0x217C, 0x00000000);
427 writemmr(0x2120, 0x10000000);
428 writemmr(0x2130, (2047 << 16) | 2047);
429}
430
431static void image_wait_engine(void)
432{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700433 while (readmmr(0x2164) & 0xF0000000) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434}
435
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700436static void image_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700438 writemmr(0x2120, 0x80000000);
439 writemmr(0x2120, 0x90000000 | ROP_S);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700441 writemmr(0x2144, c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700443 writemmr(DR1, point(x, y));
444 writemmr(DR2, point(x + w - 1, y + h - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700446 writemmr(0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447}
448
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700449static void image_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700451 u32 s1, s2, d1, d2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 int direction = 2;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700453 s1 = point(x1, y1);
454 s2 = point(x1 + w - 1, y1 + h - 1);
455 d1 = point(x2, y2);
456 d2 = point(x2 + w - 1, y2 + h - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700458 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
459 direction = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700461 writemmr(0x2120, 0x80000000);
462 writemmr(0x2120, 0x90000000 | ROP_S);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700464 writemmr(SR1, direction ? s2 : s1);
465 writemmr(SR2, direction ? s1 : s2);
466 writemmr(DR1, direction ? d2 : d1);
467 writemmr(DR2, direction ? d1 : d2);
468 writemmr(0x2124, 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471static struct accel_switch accel_image = {
472 image_init_accel,
473 image_wait_engine,
474 image_fill_rect,
475 image_copy_rect,
476};
477
478/*
479 * Accel functions called by the upper layers
480 */
481#ifdef CONFIG_FB_TRIDENT_ACCEL
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700482static void tridentfb_fillrect(struct fb_info *info,
483 const struct fb_fillrect *fr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
485 int bpp = info->var.bits_per_pixel;
Antonino A. Daplas8dad46c2005-08-01 23:46:44 +0800486 int col = 0;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700489 default:
490 case 8:
491 col |= fr->color;
492 col |= col << 8;
493 col |= col << 16;
494 break;
495 case 16:
496 col = ((u32 *)(info->pseudo_palette))[fr->color];
497 break;
498 case 32:
499 col = ((u32 *)(info->pseudo_palette))[fr->color];
500 break;
501 }
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 acc->fill_rect(fr->dx, fr->dy, fr->width, fr->height, col, fr->rop);
504 acc->wait_engine();
505}
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700506static void tridentfb_copyarea(struct fb_info *info,
507 const struct fb_copyarea *ca)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700509 acc->copy_rect(ca->sx, ca->sy, ca->dx, ca->dy, ca->width, ca->height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 acc->wait_engine();
511}
512#else /* !CONFIG_FB_TRIDENT_ACCEL */
513#define tridentfb_fillrect cfb_fillrect
514#define tridentfb_copyarea cfb_copyarea
515#endif /* CONFIG_FB_TRIDENT_ACCEL */
516
517
518/*
519 * Hardware access functions
520 */
521
522static inline unsigned char read3X4(int reg)
523{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700524 struct tridentfb_par *par = (struct tridentfb_par *)fb_info.par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 writeb(reg, par->io_virt + CRT + 4);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700526 return readb(par->io_virt + CRT + 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527}
528
529static inline void write3X4(int reg, unsigned char val)
530{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700531 struct tridentfb_par *par = (struct tridentfb_par *)fb_info.par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 writeb(reg, par->io_virt + CRT + 4);
533 writeb(val, par->io_virt + CRT + 5);
534}
535
536static inline unsigned char read3C4(int reg)
537{
538 t_outb(reg, 0x3C4);
539 return t_inb(0x3C5);
540}
541
542static inline void write3C4(int reg, unsigned char val)
543{
544 t_outb(reg, 0x3C4);
545 t_outb(val, 0x3C5);
546}
547
548static inline unsigned char read3CE(int reg)
549{
550 t_outb(reg, 0x3CE);
551 return t_inb(0x3CF);
552}
553
554static inline void writeAttr(int reg, unsigned char val)
555{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700556 readb(((struct tridentfb_par *)fb_info.par)->io_virt + CRT + 0x0A); /* flip-flop to index */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 t_outb(reg, 0x3C0);
558 t_outb(val, 0x3C0);
559}
560
561static inline void write3CE(int reg, unsigned char val)
562{
563 t_outb(reg, 0x3CE);
564 t_outb(val, 0x3CF);
565}
566
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800567static void enable_mmio(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800569 unsigned char tmp;
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 /* Goto New Mode */
572 outb(0x0B, 0x3C4);
573 inb(0x3C5);
574
575 /* Unprotect registers */
576 outb(NewMode1, 0x3C4);
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800577 tmp = inb(0x3C5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 outb(0x80, 0x3C5);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 /* Enable MMIO */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700581 outb(PCIReg, 0x3D4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 outb(inb(0x3D5) | 0x01, 0x3D5);
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800583
584 t_outb(NewMode1, 0x3C4);
585 t_outb(tmp, 0x3C5);
586}
587
588static void disable_mmio(void)
589{
590 unsigned char tmp;
591
592 /* Goto New Mode */
593 t_outb(0x0B, 0x3C4);
594 t_inb(0x3C5);
595
596 /* Unprotect registers */
597 t_outb(NewMode1, 0x3C4);
598 tmp = t_inb(0x3C5);
599 t_outb(0x80, 0x3C5);
600
601 /* Disable MMIO */
602 t_outb(PCIReg, 0x3D4);
603 t_outb(t_inb(0x3D5) & ~0x01, 0x3D5);
604
605 outb(NewMode1, 0x3C4);
606 outb(tmp, 0x3C5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define crtc_unlock() write3X4(CRTVSyncEnd, read3X4(CRTVSyncEnd) & 0x7F)
610
611/* Return flat panel's maximum x resolution */
Randy Dunlap474ab452006-06-25 05:48:38 -0700612static int __devinit get_nativex(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700614 int x, y, tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 if (nativex)
617 return nativex;
618
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700619 tmp = (read3CE(VertStretch) >> 4) & 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621 switch (tmp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700622 case 0:
623 x = 1280; y = 1024;
624 break;
625 case 2:
626 x = 1024; y = 768;
627 break;
628 case 3:
629 x = 800; y = 600;
630 break;
631 case 4:
632 x = 1400; y = 1050;
633 break;
634 case 1:
635 default:
636 x = 640; y = 480;
637 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
639
640 output("%dx%d flat panel found\n", x, y);
641 return x;
642}
643
644/* Set pitch */
645static void set_lwidth(int width)
646{
647 write3X4(Offset, width & 0xFF);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700648 write3X4(AddColReg,
649 (read3X4(AddColReg) & 0xCF) | ((width & 0x300) >> 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
652/* For resolutions smaller than FP resolution stretch */
653static void screen_stretch(void)
654{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700655 if (chip_id != CYBERBLADEXPAi1)
656 write3CE(BiosReg, 0);
657 else
658 write3CE(BiosReg, 8);
659 write3CE(VertStretch, (read3CE(VertStretch) & 0x7C) | 1);
660 write3CE(HorStretch, (read3CE(HorStretch) & 0x7C) | 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662
663/* For resolutions smaller than FP resolution center */
664static void screen_center(void)
665{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700666 write3CE(VertStretch, (read3CE(VertStretch) & 0x7C) | 0x80);
667 write3CE(HorStretch, (read3CE(HorStretch) & 0x7C) | 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
670/* Address of first shown pixel in display memory */
671static void set_screen_start(int base)
672{
673 write3X4(StartAddrLow, base & 0xFF);
674 write3X4(StartAddrHigh, (base & 0xFF00) >> 8);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700675 write3X4(CRTCModuleTest,
676 (read3X4(CRTCModuleTest) & 0xDF) | ((base & 0x10000) >> 11));
677 write3X4(CRTHiOrd,
678 (read3X4(CRTHiOrd) & 0xF8) | ((base & 0xE0000) >> 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
680
681/* Use 20.12 fixed-point for NTSC value and frequency calculation */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700682#define calc_freq(n, m, k) ( ((unsigned long)0xE517 * (n + 8) / ((m + 2) * (1 << k))) >> 12 )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
684/* Set dotclock frequency */
685static void set_vclk(int freq)
686{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700687 int m, n, k;
688 int f, fi, d, di;
689 unsigned char lo = 0, hi = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 d = 20;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700692 for (k = 2; k >= 0; k--)
693 for (m = 0; m < 63; m++)
694 for (n = 0; n < 128; n++) {
695 fi = calc_freq(n, m, k);
696 if ((di = abs(fi - freq)) < d) {
697 d = di;
698 f = fi;
699 lo = n;
700 hi = (k << 6) | m;
701 }
702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 if (chip3D) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700704 write3C4(ClockHigh, hi);
705 write3C4(ClockLow, lo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 } else {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700707 outb(lo, 0x43C8);
708 outb(hi, 0x43C9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700710 debug("VCLK = %X %X\n", hi, lo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
712
713/* Set number of lines for flat panels*/
714static void set_number_of_lines(int lines)
715{
716 int tmp = read3CE(CyberEnhance) & 0x8F;
717 if (lines > 1024)
718 tmp |= 0x50;
719 else if (lines > 768)
720 tmp |= 0x30;
721 else if (lines > 600)
722 tmp |= 0x20;
723 else if (lines > 480)
724 tmp |= 0x10;
725 write3CE(CyberEnhance, tmp);
726}
727
728/*
729 * If we see that FP is active we assume we have one.
730 * Otherwise we have a CRT display.User can override.
731 */
Randy Dunlap474ab452006-06-25 05:48:38 -0700732static unsigned int __devinit get_displaytype(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
734 if (fp)
735 return DISPLAY_FP;
736 if (crt || !chipcyber)
737 return DISPLAY_CRT;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700738 return (read3CE(FPConfig) & 0x10) ? DISPLAY_FP : DISPLAY_CRT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
740
741/* Try detecting the video memory size */
Randy Dunlap474ab452006-06-25 05:48:38 -0700742static unsigned int __devinit get_memsize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
744 unsigned char tmp, tmp2;
745 unsigned int k;
746
747 /* If memory size provided by user */
748 if (memsize)
749 k = memsize * Kb;
750 else
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700751 switch (chip_id) {
752 case CYBER9525DVD:
753 k = 2560 * Kb;
754 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 default:
756 tmp = read3X4(SPR) & 0x0F;
757 switch (tmp) {
758
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700759 case 0x01:
760 k = 512;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700762 case 0x02:
763 k = 6 * Mb; /* XP */
764 break;
765 case 0x03:
766 k = 1 * Mb;
767 break;
768 case 0x04:
769 k = 8 * Mb;
770 break;
771 case 0x06:
772 k = 10 * Mb; /* XP */
773 break;
774 case 0x07:
775 k = 2 * Mb;
776 break;
777 case 0x08:
778 k = 12 * Mb; /* XP */
779 break;
780 case 0x0A:
781 k = 14 * Mb; /* XP */
782 break;
783 case 0x0C:
784 k = 16 * Mb; /* XP */
785 break;
786 case 0x0E: /* XP */
787
788 tmp2 = read3C4(0xC1);
789 switch (tmp2) {
790 case 0x00:
791 k = 20 * Mb;
792 break;
793 case 0x01:
794 k = 24 * Mb;
795 break;
796 case 0x10:
797 k = 28 * Mb;
798 break;
799 case 0x11:
800 k = 32 * Mb;
801 break;
802 default:
803 k = 1 * Mb;
804 break;
805 }
806 break;
807
808 case 0x0F:
809 k = 4 * Mb;
810 break;
811 default:
812 k = 1 * Mb;
813 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 k -= memdiff * Kb;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700818 output("framebuffer size = %d Kb\n", k / Kb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 return k;
820}
821
822/* See if we can handle the video mode described in var */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700823static int tridentfb_check_var(struct fb_var_screeninfo *var,
824 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
826 int bpp = var->bits_per_pixel;
827 debug("enter\n");
828
829 /* check color depth */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700830 if (bpp == 24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 bpp = var->bits_per_pixel = 32;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700832 /* check whether resolution fits on panel and in memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 if (flatpanel && nativex && var->xres > nativex)
834 return -EINVAL;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700835 if (var->xres * var->yres_virtual * bpp / 8 > info->fix.smem_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 return -EINVAL;
837
838 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700839 case 8:
840 var->red.offset = 0;
841 var->green.offset = 0;
842 var->blue.offset = 0;
843 var->red.length = 6;
844 var->green.length = 6;
845 var->blue.length = 6;
846 break;
847 case 16:
848 var->red.offset = 11;
849 var->green.offset = 5;
850 var->blue.offset = 0;
851 var->red.length = 5;
852 var->green.length = 6;
853 var->blue.length = 5;
854 break;
855 case 32:
856 var->red.offset = 16;
857 var->green.offset = 8;
858 var->blue.offset = 0;
859 var->red.length = 8;
860 var->green.length = 8;
861 var->blue.length = 8;
862 break;
863 default:
864 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 }
866 debug("exit\n");
867
868 return 0;
869
870}
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872/* Pan the display */
873static int tridentfb_pan_display(struct fb_var_screeninfo *var,
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700874 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
876 unsigned int offset;
877
878 debug("enter\n");
879 offset = (var->xoffset + (var->yoffset * var->xres))
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700880 * var->bits_per_pixel / 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 info->var.xoffset = var->xoffset;
882 info->var.yoffset = var->yoffset;
883 set_screen_start(offset);
884 debug("exit\n");
885 return 0;
886}
887
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700888#define shadowmode_on() write3CE(CyberControl, read3CE(CyberControl) | 0x81)
889#define shadowmode_off() write3CE(CyberControl, read3CE(CyberControl) & 0x7E)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891/* Set the hardware to the requested video mode */
892static int tridentfb_set_par(struct fb_info *info)
893{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700894 struct tridentfb_par *par = (struct tridentfb_par *)(info->par);
895 u32 htotal, hdispend, hsyncstart, hsyncend, hblankstart, hblankend;
896 u32 vtotal, vdispend, vsyncstart, vsyncend, vblankstart, vblankend;
897 struct fb_var_screeninfo *var = &info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 int bpp = var->bits_per_pixel;
899 unsigned char tmp;
900 debug("enter\n");
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700901 hdispend = var->xres / 8 - 1;
902 hsyncstart = (var->xres + var->right_margin) / 8;
903 hsyncend = var->hsync_len / 8;
904 htotal =
905 (var->xres + var->left_margin + var->right_margin +
906 var->hsync_len) / 8 - 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 hblankstart = hdispend + 1;
908 hblankend = htotal + 5;
909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 vdispend = var->yres - 1;
911 vsyncstart = var->yres + var->lower_margin;
912 vsyncend = var->vsync_len;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700913 vtotal = var->upper_margin + vsyncstart + vsyncend - 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 vblankstart = var->yres;
915 vblankend = vtotal + 2;
916
917 enable_mmio();
918 crtc_unlock();
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700919 write3CE(CyberControl, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 if (flatpanel && var->xres < nativex) {
922 /*
923 * on flat panels with native size larger
924 * than requested resolution decide whether
925 * we stretch or center
926 */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700927 t_outb(0xEB, 0x3C2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 shadowmode_on();
930
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700931 if (center)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 screen_center();
933 else if (stretch)
934 screen_stretch();
935
936 } else {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700937 t_outb(0x2B, 0x3C2);
938 write3CE(CyberControl, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 }
940
941 /* vertical timing values */
942 write3X4(CRTVTotal, vtotal & 0xFF);
943 write3X4(CRTVDispEnd, vdispend & 0xFF);
944 write3X4(CRTVSyncStart, vsyncstart & 0xFF);
945 write3X4(CRTVSyncEnd, (vsyncend & 0x0F));
946 write3X4(CRTVBlankStart, vblankstart & 0xFF);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700947 write3X4(CRTVBlankEnd, 0 /* p->vblankend & 0xFF */ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949 /* horizontal timing values */
950 write3X4(CRTHTotal, htotal & 0xFF);
951 write3X4(CRTHDispEnd, hdispend & 0xFF);
952 write3X4(CRTHSyncStart, hsyncstart & 0xFF);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700953 write3X4(CRTHSyncEnd, (hsyncend & 0x1F) | ((hblankend & 0x20) << 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 write3X4(CRTHBlankStart, hblankstart & 0xFF);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700955 write3X4(CRTHBlankEnd, 0 /* (p->hblankend & 0x1F) */ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 /* higher bits of vertical timing values */
958 tmp = 0x10;
959 if (vtotal & 0x100) tmp |= 0x01;
960 if (vdispend & 0x100) tmp |= 0x02;
961 if (vsyncstart & 0x100) tmp |= 0x04;
962 if (vblankstart & 0x100) tmp |= 0x08;
963
964 if (vtotal & 0x200) tmp |= 0x20;
965 if (vdispend & 0x200) tmp |= 0x40;
966 if (vsyncstart & 0x200) tmp |= 0x80;
967 write3X4(CRTOverflow, tmp);
968
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700969 tmp = read3X4(CRTHiOrd) | 0x08; /* line compare bit 10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 if (vtotal & 0x400) tmp |= 0x80;
971 if (vblankstart & 0x400) tmp |= 0x40;
972 if (vsyncstart & 0x400) tmp |= 0x20;
973 if (vdispend & 0x400) tmp |= 0x10;
974 write3X4(CRTHiOrd, tmp);
975
976 tmp = 0;
977 if (htotal & 0x800) tmp |= 0x800 >> 11;
978 if (hblankstart & 0x800) tmp |= 0x800 >> 7;
979 write3X4(HorizOverflow, tmp);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 tmp = 0x40;
982 if (vblankstart & 0x200) tmp |= 0x20;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700983//FIXME if (info->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; /* double scan for 200 line modes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 write3X4(CRTMaxScanLine, tmp);
985
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700986 write3X4(CRTLineCompare, 0xFF);
987 write3X4(CRTPRowScan, 0);
988 write3X4(CRTModeControl, 0xC3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700990 write3X4(LinearAddReg, 0x20); /* enable linear addressing */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700992 tmp = (info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80;
993 write3X4(CRTCModuleTest, tmp); /* enable access extended memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700995 write3X4(GraphEngReg, 0x80); /* enable GE for text acceleration */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700997#ifdef CONFIG_FB_TRIDENT_ACCEL
998 acc->init_accel(info->var.xres, bpp);
Antonino A. Daplas8dad46c2005-08-01 23:46:44 +0800999#endif
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001002 case 8:
1003 tmp = 0x00;
1004 break;
1005 case 16:
1006 tmp = 0x05;
1007 break;
1008 case 24:
1009 tmp = 0x29;
1010 break;
1011 case 32:
1012 tmp = 0x09;
1013 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015
1016 write3X4(PixelBusReg, tmp);
1017
1018 tmp = 0x10;
1019 if (chipcyber)
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001020 tmp |= 0x20;
1021 write3X4(DRAMControl, tmp); /* both IO, linear enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
1023 write3X4(InterfaceSel, read3X4(InterfaceSel) | 0x40);
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001024 write3X4(Performance, 0x92);
1025 write3X4(PCIReg, 0x07); /* MMIO & PCI read and write burst enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
1027 /* convert from picoseconds to MHz */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001028 par->vclk = 1000000 / info->var.pixclock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if (bpp == 32)
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001030 par->vclk *= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 set_vclk(par->vclk);
1032
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001033 write3C4(0, 3);
1034 write3C4(1, 1); /* set char clock 8 dots wide */
1035 write3C4(2, 0x0F); /* enable 4 maps because needed in chain4 mode */
1036 write3C4(3, 0);
1037 write3C4(4, 0x0E); /* memory mode enable bitmaps ?? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001039 write3CE(MiscExtFunc, (bpp == 32) ? 0x1A : 0x12); /* divide clock by 2 if 32bpp */
1040 /* chain4 mode display and CPU path */
1041 write3CE(0x5, 0x40); /* no CGA compat, allow 256 col */
1042 write3CE(0x6, 0x05); /* graphics mode */
1043 write3CE(0x7, 0x0F); /* planes? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 if (chip_id == CYBERBLADEXPAi1) {
1046 /* This fixes snow-effect in 32 bpp */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001047 write3X4(CRTHSyncStart, 0x84);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 }
1049
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001050 writeAttr(0x10, 0x41); /* graphics mode and support 256 color modes */
1051 writeAttr(0x12, 0x0F); /* planes */
1052 writeAttr(0x13, 0); /* horizontal pel panning */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001054 /* colors */
1055 for (tmp = 0; tmp < 0x10; tmp++)
1056 writeAttr(tmp, tmp);
1057 readb(par->io_virt + CRT + 0x0A); /* flip-flop to index */
1058 t_outb(0x20, 0x3C0); /* enable attr */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001061 case 8:
1062 tmp = 0;
1063 break;
1064 case 15:
1065 tmp = 0x10;
1066 break;
1067 case 16:
1068 tmp = 0x30;
1069 break;
1070 case 24:
1071 case 32:
1072 tmp = 0xD0;
1073 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 }
1075
1076 t_inb(0x3C8);
1077 t_inb(0x3C6);
1078 t_inb(0x3C6);
1079 t_inb(0x3C6);
1080 t_inb(0x3C6);
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001081 t_outb(tmp, 0x3C6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 t_inb(0x3C8);
1083
1084 if (flatpanel)
1085 set_number_of_lines(info->var.yres);
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001086 set_lwidth(info->var.xres * bpp / (4 * 16));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001088 info->fix.line_length = info->var.xres * (bpp >> 3);
1089 info->cmap.len = (bpp == 8) ? 256 : 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 debug("exit\n");
1091 return 0;
1092}
1093
1094/* Set one color register */
1095static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green,
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001096 unsigned blue, unsigned transp,
1097 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
1099 int bpp = info->var.bits_per_pixel;
1100
1101 if (regno >= info->cmap.len)
1102 return 1;
1103
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001104 if (bpp == 8) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001105 t_outb(0xFF, 0x3C6);
1106 t_outb(regno, 0x3C8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001108 t_outb(red >> 10, 0x3C9);
1109 t_outb(green >> 10, 0x3C9);
1110 t_outb(blue >> 10, 0x3C9);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001112 } else if (regno < 16) {
1113 if (bpp == 16) { /* RGB 565 */
1114 u32 col;
Antonino A. Daplas8dad46c2005-08-01 23:46:44 +08001115
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001116 col = (red & 0xF800) | ((green & 0xFC00) >> 5) |
1117 ((blue & 0xF800) >> 11);
1118 col |= col << 16;
1119 ((u32 *)(info->pseudo_palette))[regno] = col;
1120 } else if (bpp == 32) /* ARGB 8888 */
1121 ((u32*)info->pseudo_palette)[regno] =
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001122 ((transp & 0xFF00) << 16) |
1123 ((red & 0xFF00) << 8) |
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001124 ((green & 0xFF00)) |
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001125 ((blue & 0xFF00) >> 8);
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001128/* debug("exit\n"); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 return 0;
1130}
1131
1132/* Try blanking the screen.For flat panels it does nothing */
1133static int tridentfb_blank(int blank_mode, struct fb_info *info)
1134{
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001135 unsigned char PMCont, DPMSCont;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137 debug("enter\n");
1138 if (flatpanel)
1139 return 0;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001140 t_outb(0x04, 0x83C8); /* Read DPMS Control */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 PMCont = t_inb(0x83C6) & 0xFC;
1142 DPMSCont = read3CE(PowerStatus) & 0xFC;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001143 switch (blank_mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 case FB_BLANK_UNBLANK:
1145 /* Screen: On, HSync: On, VSync: On */
1146 case FB_BLANK_NORMAL:
1147 /* Screen: Off, HSync: On, VSync: On */
1148 PMCont |= 0x03;
1149 DPMSCont |= 0x00;
1150 break;
1151 case FB_BLANK_HSYNC_SUSPEND:
1152 /* Screen: Off, HSync: Off, VSync: On */
1153 PMCont |= 0x02;
1154 DPMSCont |= 0x01;
1155 break;
1156 case FB_BLANK_VSYNC_SUSPEND:
1157 /* Screen: Off, HSync: On, VSync: Off */
1158 PMCont |= 0x02;
1159 DPMSCont |= 0x02;
1160 break;
1161 case FB_BLANK_POWERDOWN:
1162 /* Screen: Off, HSync: Off, VSync: Off */
1163 PMCont |= 0x00;
1164 DPMSCont |= 0x03;
1165 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001168 write3CE(PowerStatus, DPMSCont);
1169 t_outb(4, 0x83C8);
1170 t_outb(PMCont, 0x83C6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 debug("exit\n");
1173
1174 /* let fbcon do a softblank for us */
1175 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
1176}
1177
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001178static struct fb_ops tridentfb_ops = {
1179 .owner = THIS_MODULE,
1180 .fb_setcolreg = tridentfb_setcolreg,
1181 .fb_pan_display = tridentfb_pan_display,
1182 .fb_blank = tridentfb_blank,
1183 .fb_check_var = tridentfb_check_var,
1184 .fb_set_par = tridentfb_set_par,
1185 .fb_fillrect = tridentfb_fillrect,
1186 .fb_copyarea = tridentfb_copyarea,
1187 .fb_imageblit = cfb_imageblit,
1188};
1189
1190static int __devinit trident_pci_probe(struct pci_dev * dev,
1191 const struct pci_device_id * id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
1193 int err;
1194 unsigned char revision;
1195
1196 err = pci_enable_device(dev);
1197 if (err)
1198 return err;
1199
1200 chip_id = id->device;
1201
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001202 if (chip_id == CYBERBLADEi1)
Knut Petersen9fa68ea2005-09-09 13:04:56 -07001203 output("*** Please do use cyblafb, Cyberblade/i1 support "
1204 "will soon be removed from tridentfb!\n");
1205
1206
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 /* If PCI id is 0x9660 then further detect chip type */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001208
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 if (chip_id == TGUI9660) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001210 outb(RevisionID, 0x3C4);
1211 revision = inb(0x3C5);
1212
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 switch (revision) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001214 case 0x22:
1215 case 0x23:
1216 chip_id = CYBER9397;
1217 break;
1218 case 0x2A:
1219 chip_id = CYBER9397DVD;
1220 break;
1221 case 0x30:
1222 case 0x33:
1223 case 0x34:
1224 case 0x35:
1225 case 0x38:
1226 case 0x3A:
1227 case 0xB3:
1228 chip_id = CYBER9385;
1229 break;
1230 case 0x40 ... 0x43:
1231 chip_id = CYBER9382;
1232 break;
1233 case 0x4A:
1234 chip_id = CYBER9388;
1235 break;
1236 default:
1237 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 }
1239 }
1240
1241 chip3D = is3Dchip(chip_id);
1242 chipcyber = iscyber(chip_id);
1243
1244 if (is_xp(chip_id)) {
1245 acc = &accel_xp;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001246 } else if (is_blade(chip_id)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 acc = &accel_blade;
1248 } else {
1249 acc = &accel_image;
1250 }
1251
1252 /* acceleration is on by default for 3D chips */
1253 defaultaccel = chip3D && !noaccel;
1254
1255 fb_info.par = &default_par;
1256
1257 /* setup MMIO region */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001258 tridentfb_fix.mmio_start = pci_resource_start(dev, 1);
1259 tridentfb_fix.mmio_len = chip3D ? 0x20000 : 0x10000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 if (!request_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len, "tridentfb")) {
1262 debug("request_region failed!\n");
1263 return -1;
1264 }
1265
1266 default_par.io_virt = ioremap_nocache(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
1267
1268 if (!default_par.io_virt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 debug("ioremap failed\n");
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001270 err = -1;
1271 goto out_unmap1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 }
1273
1274 enable_mmio();
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 /* setup framebuffer memory */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001277 tridentfb_fix.smem_start = pci_resource_start(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 tridentfb_fix.smem_len = get_memsize();
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001279
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 if (!request_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len, "tridentfb")) {
1281 debug("request_mem_region failed!\n");
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001282 disable_mmio();
Amol Lada02f6402006-12-08 02:40:03 -08001283 err = -1;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001284 goto out_unmap1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 }
1286
1287 fb_info.screen_base = ioremap_nocache(tridentfb_fix.smem_start,
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001288 tridentfb_fix.smem_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
1290 if (!fb_info.screen_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 debug("ioremap failed\n");
Amol Lada02f6402006-12-08 02:40:03 -08001292 err = -1;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001293 goto out_unmap2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 }
1295
1296 output("%s board found\n", pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 displaytype = get_displaytype();
1298
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001299 if (flatpanel)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 nativex = get_nativex();
1301
1302 fb_info.fix = tridentfb_fix;
1303 fb_info.fbops = &tridentfb_ops;
1304
1305
1306 fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1307#ifdef CONFIG_FB_TRIDENT_ACCEL
1308 fb_info.flags |= FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT;
1309#endif
1310 fb_info.pseudo_palette = pseudo_pal;
1311
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001312 if (!fb_find_mode(&default_var, &fb_info, mode, NULL, 0, NULL, bpp)) {
Amol Lada02f6402006-12-08 02:40:03 -08001313 err = -EINVAL;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001314 goto out_unmap2;
Amol Lada02f6402006-12-08 02:40:03 -08001315 }
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001316 err = fb_alloc_cmap(&fb_info.cmap, 256, 0);
1317 if (err < 0)
1318 goto out_unmap2;
1319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 if (defaultaccel && acc)
1321 default_var.accel_flags |= FB_ACCELF_TEXT;
1322 else
1323 default_var.accel_flags &= ~FB_ACCELF_TEXT;
1324 default_var.activate |= FB_ACTIVATE_NOW;
1325 fb_info.var = default_var;
1326 fb_info.device = &dev->dev;
1327 if (register_framebuffer(&fb_info) < 0) {
1328 printk(KERN_ERR "tridentfb: could not register Trident framebuffer\n");
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001329 fb_dealloc_cmap(&fb_info.cmap);
Amol Lada02f6402006-12-08 02:40:03 -08001330 err = -EINVAL;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001331 goto out_unmap2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333 output("fb%d: %s frame buffer device %dx%d-%dbpp\n",
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001334 fb_info.node, fb_info.fix.id, default_var.xres,
1335 default_var.yres, default_var.bits_per_pixel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 return 0;
Amol Lada02f6402006-12-08 02:40:03 -08001337
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001338out_unmap2:
Amol Lada02f6402006-12-08 02:40:03 -08001339 if (fb_info.screen_base)
1340 iounmap(fb_info.screen_base);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001341 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
1342 disable_mmio();
1343out_unmap1:
1344 if (default_par.io_virt)
1345 iounmap(default_par.io_virt);
1346 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
Amol Lada02f6402006-12-08 02:40:03 -08001347 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348}
1349
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001350static void __devexit trident_pci_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351{
1352 struct tridentfb_par *par = (struct tridentfb_par*)fb_info.par;
1353 unregister_framebuffer(&fb_info);
1354 iounmap(par->io_virt);
1355 iounmap(fb_info.screen_base);
1356 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001357 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358}
1359
1360/* List of boards that we are trying to support */
1361static struct pci_device_id trident_devices[] = {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001362 {PCI_VENDOR_ID_TRIDENT, BLADE3D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1363 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1364 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1365 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1366 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1367 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1368 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1369 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEE4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1370 {PCI_VENDOR_ID_TRIDENT, TGUI9660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1371 {PCI_VENDOR_ID_TRIDENT, IMAGE975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1372 {PCI_VENDOR_ID_TRIDENT, IMAGE985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1373 {PCI_VENDOR_ID_TRIDENT, CYBER9320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1374 {PCI_VENDOR_ID_TRIDENT, CYBER9388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1375 {PCI_VENDOR_ID_TRIDENT, CYBER9520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1376 {PCI_VENDOR_ID_TRIDENT, CYBER9525DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1377 {PCI_VENDOR_ID_TRIDENT, CYBER9397, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1378 {PCI_VENDOR_ID_TRIDENT, CYBER9397DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1379 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1380 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1381 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 {0,}
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001383};
1384
1385MODULE_DEVICE_TABLE(pci, trident_devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387static struct pci_driver tridentfb_pci_driver = {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001388 .name = "tridentfb",
1389 .id_table = trident_devices,
1390 .probe = trident_pci_probe,
1391 .remove = __devexit_p(trident_pci_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392};
1393
1394/*
1395 * Parse user specified options (`video=trident:')
1396 * example:
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001397 * video=trident:800x600,bpp=16,noaccel
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 */
1399#ifndef MODULE
1400static int tridentfb_setup(char *options)
1401{
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001402 char *opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 if (!options || !*options)
1404 return 0;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001405 while ((opt = strsep(&options, ",")) != NULL) {
1406 if (!*opt)
1407 continue;
1408 if (!strncmp(opt, "noaccel", 7))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 noaccel = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001410 else if (!strncmp(opt, "fp", 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 displaytype = DISPLAY_FP;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001412 else if (!strncmp(opt, "crt", 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 displaytype = DISPLAY_CRT;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001414 else if (!strncmp(opt, "bpp=", 4))
1415 bpp = simple_strtoul(opt + 4, NULL, 0);
1416 else if (!strncmp(opt, "center", 6))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 center = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001418 else if (!strncmp(opt, "stretch", 7))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 stretch = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001420 else if (!strncmp(opt, "memsize=", 8))
1421 memsize = simple_strtoul(opt + 8, NULL, 0);
1422 else if (!strncmp(opt, "memdiff=", 8))
1423 memdiff = simple_strtoul(opt + 8, NULL, 0);
1424 else if (!strncmp(opt, "nativex=", 8))
1425 nativex = simple_strtoul(opt + 8, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 else
1427 mode = opt;
1428 }
1429 return 0;
1430}
1431#endif
1432
1433static int __init tridentfb_init(void)
1434{
1435#ifndef MODULE
1436 char *option = NULL;
1437
1438 if (fb_get_options("tridentfb", &option))
1439 return -ENODEV;
1440 tridentfb_setup(option);
1441#endif
1442 output("Trident framebuffer %s initializing\n", VERSION);
1443 return pci_register_driver(&tridentfb_pci_driver);
1444}
1445
1446static void __exit tridentfb_exit(void)
1447{
1448 pci_unregister_driver(&tridentfb_pci_driver);
1449}
1450
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451module_init(tridentfb_init);
1452module_exit(tridentfb_exit);
1453
1454MODULE_AUTHOR("Jani Monoses <jani@iv.ro>");
1455MODULE_DESCRIPTION("Framebuffer driver for Trident cards");
1456MODULE_LICENSE("GPL");
1457