blob: 479b2e79ad68ea569882bf7ce7df7645d648a02d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -07002 * Frame buffer driver for Trident TGUI, Blade and Image series
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 */
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/module.h>
19#include <linux/fb.h>
20#include <linux/init.h>
21#include <linux/pci.h>
22
23#include <linux/delay.h>
Krzysztof Helt10172ed2008-07-23 21:30:54 -070024#include <video/vga.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <video/trident.h>
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027struct tridentfb_par {
Krzysztof Helt245a2c22007-10-16 01:28:42 -070028 void __iomem *io_virt; /* iospace virtual memory address */
Krzysztof Heltea8ee552008-07-23 21:30:51 -070029 u32 pseudo_pal[16];
Krzysztof Helt122e8ad2008-07-23 21:30:52 -070030 int chip_id;
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070031 int flatpanel;
Krzysztof Heltd9cad042008-07-23 21:30:54 -070032 void (*init_accel) (struct tridentfb_par *, int, int);
33 void (*wait_engine) (struct tridentfb_par *);
34 void (*fill_rect)
35 (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
36 void (*copy_rect)
37 (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
Krzysztof Helt0292be42008-07-23 21:31:08 -070038 void (*image_blit)
39 (struct tridentfb_par *par, const char*,
40 u32, u32, u32, u32, u32, u32);
Krzysztof Helt5cf13842008-07-23 21:31:05 -070041 unsigned char eng_oper; /* engine operation... */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042};
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static struct fb_fix_screeninfo tridentfb_fix = {
Krzysztof Helt245a2c22007-10-16 01:28:42 -070045 .id = "Trident",
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 .type = FB_TYPE_PACKED_PIXELS,
47 .ypanstep = 1,
48 .visual = FB_VISUAL_PSEUDOCOLOR,
49 .accel = FB_ACCEL_NONE,
50};
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/* defaults which are normally overriden by user values */
53
54/* video mode */
Krzysztof Helt5cf13842008-07-23 21:31:05 -070055static char *mode_option __devinitdata = "640x480-8@60";
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070056static int bpp __devinitdata = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070058static int noaccel __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60static int center;
61static int stretch;
62
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070063static int fp __devinitdata;
64static int crt __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070066static int memsize __devinitdata;
67static int memdiff __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068static int nativex;
69
Krzysztof Helt07f41e42008-04-28 02:15:06 -070070module_param(mode_option, charp, 0);
71MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
Krzysztof Helt9e3f0ca2008-04-28 02:15:10 -070072module_param_named(mode, mode_option, charp, 0);
73MODULE_PARM_DESC(mode, "Initial video mode e.g. '648x480-8@60' (deprecated)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074module_param(bpp, int, 0);
75module_param(center, int, 0);
76module_param(stretch, int, 0);
77module_param(noaccel, int, 0);
78module_param(memsize, int, 0);
79module_param(memdiff, int, 0);
80module_param(nativex, int, 0);
81module_param(fp, int, 0);
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070082MODULE_PARM_DESC(fp, "Define if flatpanel is connected");
Linus Torvalds1da177e2005-04-16 15:20:36 -070083module_param(crt, int, 0);
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070084MODULE_PARM_DESC(crt, "Define if CRT is connected");
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Krzysztof Helt5cf13842008-07-23 21:31:05 -070086static inline int is_oldclock(int id)
Krzysztof Helt6bdf1032008-07-23 21:30:56 -070087{
Krzysztof Helta0d92252008-07-23 21:30:58 -070088 return (id == TGUI9440) ||
89 (id == TGUI9660) ||
Krzysztof Helt0e73a472008-07-23 21:30:58 -070090 (id == CYBER9320);
91}
92
Krzysztof Helt5cf13842008-07-23 21:31:05 -070093static inline int is_oldprotect(int id)
Krzysztof Helt0e73a472008-07-23 21:30:58 -070094{
Krzysztof Helt5cf13842008-07-23 21:31:05 -070095 return is_oldclock(id) ||
Krzysztof Helt0e73a472008-07-23 21:30:58 -070096 (id == PROVIDIA9685) ||
Krzysztof Helt0e73a472008-07-23 21:30:58 -070097 (id == CYBER9382) ||
98 (id == CYBER9385);
Krzysztof Helt6bdf1032008-07-23 21:30:56 -070099}
100
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700101static inline int is_blade(int id)
Krzysztof Helte0759a52008-07-23 21:30:53 -0700102{
103 return (id == BLADE3D) ||
104 (id == CYBERBLADEE4) ||
105 (id == CYBERBLADEi7) ||
106 (id == CYBERBLADEi7D) ||
107 (id == CYBERBLADEi1) ||
108 (id == CYBERBLADEi1D) ||
109 (id == CYBERBLADEAi1) ||
110 (id == CYBERBLADEAi1D);
111}
112
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700113static inline int is_xp(int id)
Krzysztof Helte0759a52008-07-23 21:30:53 -0700114{
115 return (id == CYBERBLADEXPAi1) ||
116 (id == CYBERBLADEXPm8) ||
117 (id == CYBERBLADEXPm16);
118}
119
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700120static inline int is3Dchip(int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700122 return is_blade(id) || is_xp(id) ||
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700123 (id == CYBER9397) || (id == CYBER9397DVD) ||
124 (id == CYBER9520) || (id == CYBER9525DVD) ||
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700125 (id == IMAGE975) || (id == IMAGE985);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700128static inline int iscyber(int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 switch (id) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700131 case CYBER9388:
132 case CYBER9382:
133 case CYBER9385:
134 case CYBER9397:
135 case CYBER9397DVD:
136 case CYBER9520:
137 case CYBER9525DVD:
138 case CYBERBLADEE4:
139 case CYBERBLADEi7D:
140 case CYBERBLADEi1:
141 case CYBERBLADEi1D:
142 case CYBERBLADEAi1:
143 case CYBERBLADEAi1D:
144 case CYBERBLADEXPAi1:
145 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700147 case CYBER9320:
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700148 case CYBERBLADEi7: /* VIA MPV4 integrated version */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700149 default:
150 /* case CYBERBLDAEXPm8: Strange */
151 /* case CYBERBLDAEXPm16: Strange */
152 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154}
155
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700156static inline void t_outb(struct tridentfb_par *p, u8 val, u16 reg)
157{
158 fb_writeb(val, p->io_virt + reg);
159}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700161static inline u8 t_inb(struct tridentfb_par *p, u16 reg)
162{
163 return fb_readb(p->io_virt + reg);
164}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700166static inline void writemmr(struct tridentfb_par *par, u16 r, u32 v)
167{
168 fb_writel(v, par->io_virt + r);
169}
170
171static inline u32 readmmr(struct tridentfb_par *par, u16 r)
172{
173 return fb_readl(par->io_virt + r);
174}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/*
177 * Blade specific acceleration.
178 */
179
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700180#define point(x, y) ((y) << 16 | (x))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700182static void blade_init_accel(struct tridentfb_par *par, int pitch, int bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700184 int v1 = (pitch >> 3) << 20;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700185 int tmp = bpp == 24 ? 2 : (bpp >> 4);
186 int v2 = v1 | (tmp << 29);
187
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700188 writemmr(par, 0x21C0, v2);
189 writemmr(par, 0x21C4, v2);
190 writemmr(par, 0x21B8, v2);
191 writemmr(par, 0x21BC, v2);
192 writemmr(par, 0x21D0, v1);
193 writemmr(par, 0x21D4, v1);
194 writemmr(par, 0x21C8, v1);
195 writemmr(par, 0x21CC, v1);
196 writemmr(par, 0x216C, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700199static void blade_wait_engine(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700201 while (readmmr(par, STATUS) & 0xFA800000)
202 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203}
204
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700205static void blade_fill_rect(struct tridentfb_par *par,
206 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700208 writemmr(par, COLOR, c);
209 writemmr(par, ROP, rop ? ROP_X : ROP_S);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700210 writemmr(par, CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700212 writemmr(par, DST1, point(x, y));
213 writemmr(par, DST2, point(x + w - 1, y + h - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
Krzysztof Helt0292be42008-07-23 21:31:08 -0700216static void blade_image_blit(struct tridentfb_par *par, const char *data,
217 u32 x, u32 y, u32 w, u32 h, u32 c, u32 b)
218{
219 unsigned size = ((w + 31) >> 5) * h;
220
221 writemmr(par, COLOR, c);
222 writemmr(par, BGCOLOR, b);
223 writemmr(par, CMD, 0xa0000000 | 3 << 19);
224
225 writemmr(par, DST1, point(x, y));
226 writemmr(par, DST2, point(x + w - 1, y + h - 1));
227
228 memcpy(par->io_virt + 0x10000, data, 4 * size);
229}
230
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700231static void blade_copy_rect(struct tridentfb_par *par,
232 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 int direction = 2;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700235 u32 s1 = point(x1, y1);
236 u32 s2 = point(x1 + w - 1, y1 + h - 1);
237 u32 d1 = point(x2, y2);
238 u32 d2 = point(x2 + w - 1, y2 + h - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700241 direction = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700243 writemmr(par, ROP, ROP_S);
244 writemmr(par, CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700246 writemmr(par, SRC1, direction ? s2 : s1);
247 writemmr(par, SRC2, direction ? s1 : s2);
248 writemmr(par, DST1, direction ? d2 : d1);
249 writemmr(par, DST2, direction ? d1 : d2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252/*
253 * BladeXP specific acceleration functions
254 */
255
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700256static void xp_init_accel(struct tridentfb_par *par, int pitch, int bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700258 unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
259 int v1 = pitch << (bpp == 24 ? 20 : (18 + x));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 switch (pitch << (bpp >> 3)) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700262 case 8192:
263 case 512:
264 x |= 0x00;
265 break;
266 case 1024:
267 x |= 0x04;
268 break;
269 case 2048:
270 x |= 0x08;
271 break;
272 case 4096:
273 x |= 0x0C;
274 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700277 t_outb(par, x, 0x2125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700279 par->eng_oper = x | 0x40;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700281 writemmr(par, 0x2154, v1);
282 writemmr(par, 0x2150, v1);
283 t_outb(par, 3, 0x2126);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
285
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700286static void xp_wait_engine(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700288 int count = 0;
289 int timeout = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700291 while (t_inb(par, STATUS) & 0x80) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 count++;
293 if (count == 10000000) {
294 /* Timeout */
295 count = 9990000;
296 timeout++;
297 if (timeout == 8) {
298 /* Reset engine */
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700299 t_outb(par, 0x00, STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return;
301 }
302 }
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700303 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
305}
306
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700307static void xp_fill_rect(struct tridentfb_par *par,
308 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700310 writemmr(par, 0x2127, ROP_P);
311 writemmr(par, 0x2158, c);
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700312 writemmr(par, DRAWFL, 0x4000);
313 writemmr(par, OLDDIM, point(h, w));
314 writemmr(par, OLDDST, point(y, x));
315 t_outb(par, 0x01, OLDCMD);
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700316 t_outb(par, par->eng_oper, 0x2125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700319static void xp_copy_rect(struct tridentfb_par *par,
320 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700322 u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700323 int direction = 0x0004;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if ((x1 < x2) && (y1 == y2)) {
326 direction |= 0x0200;
327 x1_tmp = x1 + w - 1;
328 x2_tmp = x2 + w - 1;
329 } else {
330 x1_tmp = x1;
331 x2_tmp = x2;
332 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 if (y1 < y2) {
335 direction |= 0x0100;
336 y1_tmp = y1 + h - 1;
337 y2_tmp = y2 + h - 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700338 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 y1_tmp = y1;
340 y2_tmp = y2;
341 }
342
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700343 writemmr(par, DRAWFL, direction);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700344 t_outb(par, ROP_S, 0x2127);
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700345 writemmr(par, OLDSRC, point(y1_tmp, x1_tmp));
346 writemmr(par, OLDDST, point(y2_tmp, x2_tmp));
347 writemmr(par, OLDDIM, point(h, w));
348 t_outb(par, 0x01, OLDCMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351/*
352 * Image specific acceleration functions
353 */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700354static void image_init_accel(struct tridentfb_par *par, int pitch, int bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700356 int tmp = bpp == 24 ? 2: (bpp >> 4);
357
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700358 writemmr(par, 0x2120, 0xF0000000);
359 writemmr(par, 0x2120, 0x40000000 | tmp);
360 writemmr(par, 0x2120, 0x80000000);
361 writemmr(par, 0x2144, 0x00000000);
362 writemmr(par, 0x2148, 0x00000000);
363 writemmr(par, 0x2150, 0x00000000);
364 writemmr(par, 0x2154, 0x00000000);
365 writemmr(par, 0x2120, 0x60000000 | (pitch << 16) | pitch);
366 writemmr(par, 0x216C, 0x00000000);
367 writemmr(par, 0x2170, 0x00000000);
368 writemmr(par, 0x217C, 0x00000000);
369 writemmr(par, 0x2120, 0x10000000);
370 writemmr(par, 0x2130, (2047 << 16) | 2047);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371}
372
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700373static void image_wait_engine(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700375 while (readmmr(par, 0x2164) & 0xF0000000)
376 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377}
378
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700379static void image_fill_rect(struct tridentfb_par *par,
380 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700382 writemmr(par, 0x2120, 0x80000000);
383 writemmr(par, 0x2120, 0x90000000 | ROP_S);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700385 writemmr(par, 0x2144, c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700387 writemmr(par, DST1, point(x, y));
388 writemmr(par, DST2, point(x + w - 1, y + h - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700390 writemmr(par, 0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700393static void image_copy_rect(struct tridentfb_par *par,
394 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Krzysztof Helt2c86a0c2008-07-23 21:31:03 -0700396 int direction = 0x4;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700397 u32 s1 = point(x1, y1);
398 u32 s2 = point(x1 + w - 1, y1 + h - 1);
399 u32 d1 = point(x2, y2);
400 u32 d2 = point(x2 + w - 1, y2 + h - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700402 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
403 direction = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700405 writemmr(par, 0x2120, 0x80000000);
406 writemmr(par, 0x2120, 0x90000000 | ROP_S);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700408 writemmr(par, SRC1, direction ? s2 : s1);
409 writemmr(par, SRC2, direction ? s1 : s2);
410 writemmr(par, DST1, direction ? d2 : d1);
411 writemmr(par, DST2, direction ? d1 : d2);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700412 writemmr(par, 0x2124,
413 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414}
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416/*
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700417 * TGUI 9440/96XX acceleration
418 */
419
420static void tgui_init_accel(struct tridentfb_par *par, int pitch, int bpp)
421{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700422 unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700423
424 /* disable clipping */
425 writemmr(par, 0x2148, 0);
426 writemmr(par, 0x214C, point(4095, 2047));
427
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700428 switch ((pitch * bpp) / 8) {
429 case 8192:
430 case 512:
431 x |= 0x00;
432 break;
433 case 1024:
434 x |= 0x04;
435 break;
436 case 2048:
437 x |= 0x08;
438 break;
439 case 4096:
440 x |= 0x0C;
441 break;
442 }
443
444 fb_writew(x, par->io_virt + 0x2122);
445}
446
447static void tgui_fill_rect(struct tridentfb_par *par,
448 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
449{
450 t_outb(par, ROP_P, 0x2127);
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700451 writemmr(par, OLDCLR, c);
452 writemmr(par, DRAWFL, 0x4020);
453 writemmr(par, OLDDIM, point(w - 1, h - 1));
454 writemmr(par, OLDDST, point(x, y));
455 t_outb(par, 1, OLDCMD);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700456}
457
458static void tgui_copy_rect(struct tridentfb_par *par,
459 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
460{
461 int flags = 0;
462 u16 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
463
464 if ((x1 < x2) && (y1 == y2)) {
465 flags |= 0x0200;
466 x1_tmp = x1 + w - 1;
467 x2_tmp = x2 + w - 1;
468 } else {
469 x1_tmp = x1;
470 x2_tmp = x2;
471 }
472
473 if (y1 < y2) {
474 flags |= 0x0100;
475 y1_tmp = y1 + h - 1;
476 y2_tmp = y2 + h - 1;
477 } else {
478 y1_tmp = y1;
479 y2_tmp = y2;
480 }
481
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700482 writemmr(par, DRAWFL, 0x4 | flags);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700483 t_outb(par, ROP_S, 0x2127);
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700484 writemmr(par, OLDSRC, point(x1_tmp, y1_tmp));
485 writemmr(par, OLDDST, point(x2_tmp, y2_tmp));
486 writemmr(par, OLDDIM, point(w - 1, h - 1));
487 t_outb(par, 1, OLDCMD);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700488}
489
490/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 * Accel functions called by the upper layers
492 */
493#ifdef CONFIG_FB_TRIDENT_ACCEL
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700494static void tridentfb_fillrect(struct fb_info *info,
495 const struct fb_fillrect *fr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700497 struct tridentfb_par *par = info->par;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700498 int col;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700499
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -0700500 if (info->flags & FBINFO_HWACCEL_DISABLED) {
501 cfb_fillrect(info, fr);
502 return;
503 }
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700504 if (info->var.bits_per_pixel == 8) {
505 col = fr->color;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700506 col |= col << 8;
507 col |= col << 16;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700508 } else
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700509 col = ((u32 *)(info->pseudo_palette))[fr->color];
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700510
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700511 par->wait_engine(par);
Krzysztof Heltd9cad042008-07-23 21:30:54 -0700512 par->fill_rect(par, fr->dx, fr->dy, fr->width,
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700513 fr->height, col, fr->rop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700515
Krzysztof Helt0292be42008-07-23 21:31:08 -0700516static void tridentfb_imageblit(struct fb_info *info,
517 const struct fb_image *img)
518{
519 struct tridentfb_par *par = info->par;
520 int col, bgcol;
521
522 if ((info->flags & FBINFO_HWACCEL_DISABLED) || img->depth != 1) {
523 cfb_imageblit(info, img);
524 return;
525 }
526 if (info->var.bits_per_pixel == 8) {
527 col = img->fg_color;
528 col |= col << 8;
529 col |= col << 16;
530 bgcol = img->bg_color;
531 bgcol |= bgcol << 8;
532 bgcol |= bgcol << 16;
533 } else {
534 col = ((u32 *)(info->pseudo_palette))[img->fg_color];
535 bgcol = ((u32 *)(info->pseudo_palette))[img->bg_color];
536 }
537
538 par->wait_engine(par);
539 if (par->image_blit)
540 par->image_blit(par, img->data, img->dx, img->dy,
541 img->width, img->height, col, bgcol);
542 else
543 cfb_imageblit(info, img);
544}
545
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700546static void tridentfb_copyarea(struct fb_info *info,
547 const struct fb_copyarea *ca)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700549 struct tridentfb_par *par = info->par;
550
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -0700551 if (info->flags & FBINFO_HWACCEL_DISABLED) {
552 cfb_copyarea(info, ca);
553 return;
554 }
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700555 par->wait_engine(par);
Krzysztof Heltd9cad042008-07-23 21:30:54 -0700556 par->copy_rect(par, ca->sx, ca->sy, ca->dx, ca->dy,
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700557 ca->width, ca->height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700559
560static int tridentfb_sync(struct fb_info *info)
561{
562 struct tridentfb_par *par = info->par;
563
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -0700564 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
565 par->wait_engine(par);
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700566 return 0;
567}
568#else
569#define tridentfb_fillrect cfb_fillrect
570#define tridentfb_copyarea cfb_copyarea
Krzysztof Helt0292be42008-07-23 21:31:08 -0700571#define tridentfb_imageblit cfb_imageblit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#endif /* CONFIG_FB_TRIDENT_ACCEL */
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574/*
575 * Hardware access functions
576 */
577
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700578static inline unsigned char read3X4(struct tridentfb_par *par, int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700580 return vga_mm_rcrt(par->io_virt, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
582
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700583static inline void write3X4(struct tridentfb_par *par, int reg,
584 unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700586 vga_mm_wcrt(par->io_virt, reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
588
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700589static inline unsigned char read3CE(struct tridentfb_par *par,
590 unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700592 return vga_mm_rgfx(par->io_virt, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
594
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700595static inline void writeAttr(struct tridentfb_par *par, int reg,
596 unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700598 fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
599 vga_mm_wattr(par->io_virt, reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700602static inline void write3CE(struct tridentfb_par *par, int reg,
603 unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700605 vga_mm_wgfx(par->io_virt, reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606}
607
Krzysztof Helt13b0de42008-07-23 21:31:06 -0700608static void enable_mmio(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
610 /* Goto New Mode */
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700611 vga_io_rseq(0x0B);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 /* Unprotect registers */
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700614 vga_io_wseq(NewMode1, 0x80);
Krzysztof Helt13b0de42008-07-23 21:31:06 -0700615 if (!is_oldprotect(par->chip_id))
616 vga_io_wseq(Protection, 0x92);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 /* Enable MMIO */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700619 outb(PCIReg, 0x3D4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 outb(inb(0x3D5) | 0x01, 0x3D5);
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800621}
622
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700623static void disable_mmio(struct tridentfb_par *par)
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800624{
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800625 /* Goto New Mode */
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700626 vga_mm_rseq(par->io_virt, 0x0B);
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800627
628 /* Unprotect registers */
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700629 vga_mm_wseq(par->io_virt, NewMode1, 0x80);
Krzysztof Helt13b0de42008-07-23 21:31:06 -0700630 if (!is_oldprotect(par->chip_id))
631 vga_mm_wseq(par->io_virt, Protection, 0x92);
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800632
633 /* Disable MMIO */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700634 t_outb(par, PCIReg, 0x3D4);
635 t_outb(par, t_inb(par, 0x3D5) & ~0x01, 0x3D5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636}
637
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700638static inline void crtc_unlock(struct tridentfb_par *par)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700639{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700640 write3X4(par, VGA_CRTC_V_SYNC_END,
641 read3X4(par, VGA_CRTC_V_SYNC_END) & 0x7F);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700642}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644/* Return flat panel's maximum x resolution */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700645static int __devinit get_nativex(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700647 int x, y, tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 if (nativex)
650 return nativex;
651
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700652 tmp = (read3CE(par, VertStretch) >> 4) & 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654 switch (tmp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700655 case 0:
656 x = 1280; y = 1024;
657 break;
658 case 2:
659 x = 1024; y = 768;
660 break;
661 case 3:
662 x = 800; y = 600;
663 break;
664 case 4:
665 x = 1400; y = 1050;
666 break;
667 case 1:
668 default:
669 x = 640; y = 480;
670 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672
673 output("%dx%d flat panel found\n", x, y);
674 return x;
675}
676
677/* Set pitch */
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700678static inline void set_lwidth(struct tridentfb_par *par, int width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700680 write3X4(par, VGA_CRTC_OFFSET, width & 0xFF);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700681 write3X4(par, AddColReg,
682 (read3X4(par, AddColReg) & 0xCF) | ((width & 0x300) >> 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
685/* For resolutions smaller than FP resolution stretch */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700686static void screen_stretch(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
Krzysztof Helt122e8ad2008-07-23 21:30:52 -0700688 if (par->chip_id != CYBERBLADEXPAi1)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700689 write3CE(par, BiosReg, 0);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700690 else
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700691 write3CE(par, BiosReg, 8);
692 write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 1);
693 write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
695
696/* For resolutions smaller than FP resolution center */
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700697static inline void screen_center(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700699 write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 0x80);
700 write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}
702
703/* Address of first shown pixel in display memory */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700704static void set_screen_start(struct tridentfb_par *par, int base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700706 u8 tmp;
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700707 write3X4(par, VGA_CRTC_START_LO, base & 0xFF);
708 write3X4(par, VGA_CRTC_START_HI, (base & 0xFF00) >> 8);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700709 tmp = read3X4(par, CRTCModuleTest) & 0xDF;
710 write3X4(par, CRTCModuleTest, tmp | ((base & 0x10000) >> 11));
711 tmp = read3X4(par, CRTHiOrd) & 0xF8;
712 write3X4(par, CRTHiOrd, tmp | ((base & 0xE0000) >> 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715/* Set dotclock frequency */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700716static void set_vclk(struct tridentfb_par *par, unsigned long freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700718 int m, n, k;
Krzysztof Helt6bdf1032008-07-23 21:30:56 -0700719 unsigned long fi, d, di;
720 unsigned char best_m = 0, best_n = 0, best_k = 0;
721 unsigned char hi, lo;
Krzysztof Helt6280fd42008-07-23 21:31:08 -0700722 unsigned char shift = !is_oldclock(par->chip_id) ? 2 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Krzysztof Helt3f275ea2008-05-12 14:02:11 -0700724 d = 20000;
Krzysztof Helt6280fd42008-07-23 21:31:08 -0700725 for (k = shift; k >= 0; k--)
726 for (m = 1; m < 32; m++) {
727 n = ((m + 2) << shift) - 8;
Krzysztof Helt34dec242008-07-23 21:31:04 -0700728 for (n = (n < 0 ? 0 : n); n < 122; n++) {
Krzysztof Helt3f275ea2008-05-12 14:02:11 -0700729 fi = ((14318l * (n + 8)) / (m + 2)) >> k;
Krzysztof Helt34dec242008-07-23 21:31:04 -0700730 di = abs(fi - freq);
Krzysztof Helt6280fd42008-07-23 21:31:08 -0700731 if (di < d || (di == d && k == best_k)) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700732 d = di;
Krzysztof Helt6bdf1032008-07-23 21:30:56 -0700733 best_n = n;
734 best_m = m;
735 best_k = k;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700736 }
Krzysztof Helt3f275ea2008-05-12 14:02:11 -0700737 if (fi > freq)
738 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700739 }
Krzysztof Helt34dec242008-07-23 21:31:04 -0700740 }
Krzysztof Helt6bdf1032008-07-23 21:30:56 -0700741
742 if (is_oldclock(par->chip_id)) {
743 lo = best_n | (best_m << 7);
744 hi = (best_m >> 1) | (best_k << 4);
745 } else {
746 lo = best_n;
747 hi = best_m | (best_k << 6);
748 }
749
Krzysztof Helt122e8ad2008-07-23 21:30:52 -0700750 if (is3Dchip(par->chip_id)) {
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700751 vga_mm_wseq(par->io_virt, ClockHigh, hi);
752 vga_mm_wseq(par->io_virt, ClockLow, lo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 } else {
Krzysztof Heltc1724fe2008-07-23 21:30:56 -0700754 t_outb(par, lo, 0x43C8);
755 t_outb(par, hi, 0x43C9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700757 debug("VCLK = %X %X\n", hi, lo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758}
759
760/* Set number of lines for flat panels*/
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700761static void set_number_of_lines(struct tridentfb_par *par, int lines)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700763 int tmp = read3CE(par, CyberEnhance) & 0x8F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 if (lines > 1024)
765 tmp |= 0x50;
766 else if (lines > 768)
767 tmp |= 0x30;
768 else if (lines > 600)
769 tmp |= 0x20;
770 else if (lines > 480)
771 tmp |= 0x10;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700772 write3CE(par, CyberEnhance, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773}
774
775/*
776 * If we see that FP is active we assume we have one.
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700777 * Otherwise we have a CRT display. User can override.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 */
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700779static int __devinit is_flatpanel(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
781 if (fp)
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700782 return 1;
Krzysztof Helt122e8ad2008-07-23 21:30:52 -0700783 if (crt || !iscyber(par->chip_id))
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700784 return 0;
785 return (read3CE(par, FPConfig) & 0x10) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786}
787
788/* Try detecting the video memory size */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700789static unsigned int __devinit get_memsize(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
791 unsigned char tmp, tmp2;
792 unsigned int k;
793
794 /* If memory size provided by user */
795 if (memsize)
796 k = memsize * Kb;
797 else
Krzysztof Helt122e8ad2008-07-23 21:30:52 -0700798 switch (par->chip_id) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700799 case CYBER9525DVD:
800 k = 2560 * Kb;
801 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 default:
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700803 tmp = read3X4(par, SPR) & 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 switch (tmp) {
805
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700806 case 0x01:
Krzysztof Heltb614ce82008-03-10 11:43:37 -0700807 k = 512 * Kb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700809 case 0x02:
810 k = 6 * Mb; /* XP */
811 break;
812 case 0x03:
813 k = 1 * Mb;
814 break;
815 case 0x04:
816 k = 8 * Mb;
817 break;
818 case 0x06:
819 k = 10 * Mb; /* XP */
820 break;
821 case 0x07:
822 k = 2 * Mb;
823 break;
824 case 0x08:
825 k = 12 * Mb; /* XP */
826 break;
827 case 0x0A:
828 k = 14 * Mb; /* XP */
829 break;
830 case 0x0C:
831 k = 16 * Mb; /* XP */
832 break;
833 case 0x0E: /* XP */
834
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700835 tmp2 = vga_mm_rseq(par->io_virt, 0xC1);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700836 switch (tmp2) {
837 case 0x00:
838 k = 20 * Mb;
839 break;
840 case 0x01:
841 k = 24 * Mb;
842 break;
843 case 0x10:
844 k = 28 * Mb;
845 break;
846 case 0x11:
847 k = 32 * Mb;
848 break;
849 default:
850 k = 1 * Mb;
851 break;
852 }
853 break;
854
855 case 0x0F:
856 k = 4 * Mb;
857 break;
858 default:
859 k = 1 * Mb;
860 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
864 k -= memdiff * Kb;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700865 output("framebuffer size = %d Kb\n", k / Kb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 return k;
867}
868
869/* See if we can handle the video mode described in var */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700870static int tridentfb_check_var(struct fb_var_screeninfo *var,
871 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700873 struct tridentfb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 int bpp = var->bits_per_pixel;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700875 int line_length;
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700876 int ramdac = 230000; /* 230MHz for most 3D chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 debug("enter\n");
878
879 /* check color depth */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700880 if (bpp == 24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 bpp = var->bits_per_pixel = 32;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700882 if (bpp != 8 && bpp != 16 && bpp != 32)
883 return -EINVAL;
Krzysztof Helt54f019e2008-07-23 21:31:01 -0700884 if (par->chip_id == TGUI9440 && bpp == 32)
885 return -EINVAL;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700886 /* check whether resolution fits on panel and in memory */
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700887 if (par->flatpanel && nativex && var->xres > nativex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 return -EINVAL;
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700889 /* various resolution checks */
890 var->xres = (var->xres + 7) & ~0x7;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700891 if (var->xres > var->xres_virtual)
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700892 var->xres_virtual = var->xres;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700893 if (var->yres > var->yres_virtual)
894 var->yres_virtual = var->yres;
895 if (var->xres_virtual > 4095 || var->yres > 2048)
896 return -EINVAL;
897 /* prevent from position overflow for acceleration */
898 if (var->yres_virtual > 0xffff)
899 return -EINVAL;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700900 line_length = var->xres_virtual * bpp / 8;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -0700901
902 if (!is3Dchip(par->chip_id) &&
903 !(info->flags & FBINFO_HWACCEL_DISABLED)) {
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700904 /* acceleration requires line length to be power of 2 */
905 if (line_length <= 512)
906 var->xres_virtual = 512 * 8 / bpp;
907 else if (line_length <= 1024)
908 var->xres_virtual = 1024 * 8 / bpp;
909 else if (line_length <= 2048)
910 var->xres_virtual = 2048 * 8 / bpp;
911 else if (line_length <= 4096)
912 var->xres_virtual = 4096 * 8 / bpp;
913 else if (line_length <= 8192)
914 var->xres_virtual = 8192 * 8 / bpp;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700915 else
916 return -EINVAL;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700917
918 line_length = var->xres_virtual * bpp / 8;
919 }
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -0700920
Krzysztof Heltf330c4b2008-07-23 21:31:07 -0700921 /* datasheet specifies how to set panning only up to 4 MB */
922 if (line_length * (var->yres_virtual - var->yres) > (4 << 20))
923 var->yres_virtual = ((4 << 20) / line_length) + var->yres;
924
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700925 if (line_length * var->yres_virtual > info->fix.smem_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 return -EINVAL;
927
928 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700929 case 8:
930 var->red.offset = 0;
Krzysztof Helta4af1792008-07-23 21:31:06 -0700931 var->red.length = 8;
932 var->green = var->red;
933 var->blue = var->red;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700934 break;
935 case 16:
936 var->red.offset = 11;
937 var->green.offset = 5;
938 var->blue.offset = 0;
939 var->red.length = 5;
940 var->green.length = 6;
941 var->blue.length = 5;
942 break;
943 case 32:
944 var->red.offset = 16;
945 var->green.offset = 8;
946 var->blue.offset = 0;
947 var->red.length = 8;
948 var->green.length = 8;
949 var->blue.length = 8;
950 break;
951 default:
952 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 }
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700954
955 if (is_xp(par->chip_id))
956 ramdac = 350000;
957
958 switch (par->chip_id) {
959 case TGUI9440:
Krzysztof Helt54f019e2008-07-23 21:31:01 -0700960 ramdac = (bpp >= 16) ? 45000 : 90000;
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700961 break;
962 case CYBER9320:
963 case TGUI9660:
964 ramdac = 135000;
965 break;
966 case PROVIDIA9685:
967 case CYBER9388:
968 case CYBER9382:
969 case CYBER9385:
970 ramdac = 170000;
971 break;
972 }
973
974 /* The clock is doubled for 32 bpp */
975 if (bpp == 32)
976 ramdac /= 2;
977
978 if (PICOS2KHZ(var->pixclock) > ramdac)
979 return -EINVAL;
980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 debug("exit\n");
982
983 return 0;
984
985}
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987/* Pan the display */
988static int tridentfb_pan_display(struct fb_var_screeninfo *var,
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700989 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700991 struct tridentfb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 unsigned int offset;
993
994 debug("enter\n");
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700995 offset = (var->xoffset + (var->yoffset * var->xres_virtual))
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700996 * var->bits_per_pixel / 32;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700997 set_screen_start(par, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 debug("exit\n");
999 return 0;
1000}
1001
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001002static inline void shadowmode_on(struct tridentfb_par *par)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001003{
1004 write3CE(par, CyberControl, read3CE(par, CyberControl) | 0x81);
1005}
1006
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001007static inline void shadowmode_off(struct tridentfb_par *par)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001008{
1009 write3CE(par, CyberControl, read3CE(par, CyberControl) & 0x7E);
1010}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
1012/* Set the hardware to the requested video mode */
1013static int tridentfb_set_par(struct fb_info *info)
1014{
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001015 struct tridentfb_par *par = info->par;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001016 u32 htotal, hdispend, hsyncstart, hsyncend, hblankstart, hblankend;
1017 u32 vtotal, vdispend, vsyncstart, vsyncend, vblankstart, vblankend;
1018 struct fb_var_screeninfo *var = &info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 int bpp = var->bits_per_pixel;
1020 unsigned char tmp;
Krzysztof Helt3f275ea2008-05-12 14:02:11 -07001021 unsigned long vclk;
1022
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 debug("enter\n");
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001024 hdispend = var->xres / 8 - 1;
Krzysztof Helt34dec242008-07-23 21:31:04 -07001025 hsyncstart = (var->xres + var->right_margin) / 8;
1026 hsyncend = (var->xres + var->right_margin + var->hsync_len) / 8;
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001027 htotal = (var->xres + var->left_margin + var->right_margin +
1028 var->hsync_len) / 8 - 5;
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001029 hblankstart = hdispend + 1;
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001030 hblankend = htotal + 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 vdispend = var->yres - 1;
1033 vsyncstart = var->yres + var->lower_margin;
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001034 vsyncend = vsyncstart + var->vsync_len;
1035 vtotal = var->upper_margin + vsyncend - 2;
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001036 vblankstart = vdispend + 1;
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001037 vblankend = vtotal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Krzysztof Helt34dec242008-07-23 21:31:04 -07001039 if (info->var.vmode & FB_VMODE_INTERLACED) {
1040 vtotal /= 2;
1041 vdispend /= 2;
1042 vsyncstart /= 2;
1043 vsyncend /= 2;
1044 vblankstart /= 2;
1045 vblankend /= 2;
1046 }
1047
Krzysztof Helt13b0de42008-07-23 21:31:06 -07001048 enable_mmio(par);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001049 crtc_unlock(par);
1050 write3CE(par, CyberControl, 8);
Krzysztof Helt34dec242008-07-23 21:31:04 -07001051 tmp = 0xEB;
1052 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
1053 tmp &= ~0x40;
1054 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
1055 tmp &= ~0x80;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001057 if (par->flatpanel && var->xres < nativex) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 /*
1059 * on flat panels with native size larger
1060 * than requested resolution decide whether
1061 * we stretch or center
1062 */
Krzysztof Helt34dec242008-07-23 21:31:04 -07001063 t_outb(par, tmp | 0xC0, VGA_MIS_W);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001065 shadowmode_on(par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001067 if (center)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001068 screen_center(par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 else if (stretch)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001070 screen_stretch(par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 } else {
Krzysztof Helt34dec242008-07-23 21:31:04 -07001073 t_outb(par, tmp, VGA_MIS_W);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001074 write3CE(par, CyberControl, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
1076
1077 /* vertical timing values */
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001078 write3X4(par, VGA_CRTC_V_TOTAL, vtotal & 0xFF);
1079 write3X4(par, VGA_CRTC_V_DISP_END, vdispend & 0xFF);
1080 write3X4(par, VGA_CRTC_V_SYNC_START, vsyncstart & 0xFF);
1081 write3X4(par, VGA_CRTC_V_SYNC_END, (vsyncend & 0x0F));
1082 write3X4(par, VGA_CRTC_V_BLANK_START, vblankstart & 0xFF);
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001083 write3X4(par, VGA_CRTC_V_BLANK_END, vblankend & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
1085 /* horizontal timing values */
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001086 write3X4(par, VGA_CRTC_H_TOTAL, htotal & 0xFF);
1087 write3X4(par, VGA_CRTC_H_DISP, hdispend & 0xFF);
1088 write3X4(par, VGA_CRTC_H_SYNC_START, hsyncstart & 0xFF);
1089 write3X4(par, VGA_CRTC_H_SYNC_END,
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001090 (hsyncend & 0x1F) | ((hblankend & 0x20) << 2));
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001091 write3X4(par, VGA_CRTC_H_BLANK_START, hblankstart & 0xFF);
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001092 write3X4(par, VGA_CRTC_H_BLANK_END, hblankend & 0x1F);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 /* higher bits of vertical timing values */
1095 tmp = 0x10;
1096 if (vtotal & 0x100) tmp |= 0x01;
1097 if (vdispend & 0x100) tmp |= 0x02;
1098 if (vsyncstart & 0x100) tmp |= 0x04;
1099 if (vblankstart & 0x100) tmp |= 0x08;
1100
1101 if (vtotal & 0x200) tmp |= 0x20;
1102 if (vdispend & 0x200) tmp |= 0x40;
1103 if (vsyncstart & 0x200) tmp |= 0x80;
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001104 write3X4(par, VGA_CRTC_OVERFLOW, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001106 tmp = read3X4(par, CRTHiOrd) & 0x07;
1107 tmp |= 0x08; /* line compare bit 10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 if (vtotal & 0x400) tmp |= 0x80;
1109 if (vblankstart & 0x400) tmp |= 0x40;
1110 if (vsyncstart & 0x400) tmp |= 0x20;
1111 if (vdispend & 0x400) tmp |= 0x10;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001112 write3X4(par, CRTHiOrd, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001114 tmp = (htotal >> 8) & 0x01;
1115 tmp |= (hdispend >> 7) & 0x02;
1116 tmp |= (hsyncstart >> 5) & 0x08;
1117 tmp |= (hblankstart >> 4) & 0x10;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001118 write3X4(par, HorizOverflow, tmp);
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 tmp = 0x40;
1121 if (vblankstart & 0x200) tmp |= 0x20;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001122//FIXME if (info->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; /* double scan for 200 line modes */
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001123 write3X4(par, VGA_CRTC_MAX_SCAN, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001125 write3X4(par, VGA_CRTC_LINE_COMPARE, 0xFF);
1126 write3X4(par, VGA_CRTC_PRESET_ROW, 0);
1127 write3X4(par, VGA_CRTC_MODE, 0xC3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001129 write3X4(par, LinearAddReg, 0x20); /* enable linear addressing */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001131 tmp = (info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001132 /* enable access extended memory */
1133 write3X4(par, CRTCModuleTest, tmp);
Krzysztof Helt34dec242008-07-23 21:31:04 -07001134 tmp = read3CE(par, MiscIntContReg) & ~0x4;
1135 if (info->var.vmode & FB_VMODE_INTERLACED)
1136 tmp |= 0x4;
1137 write3CE(par, MiscIntContReg, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001139 /* enable GE for text acceleration */
1140 write3X4(par, GraphEngReg, 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001143 case 8:
1144 tmp = 0x00;
1145 break;
1146 case 16:
1147 tmp = 0x05;
1148 break;
1149 case 24:
1150 tmp = 0x29;
1151 break;
1152 case 32:
1153 tmp = 0x09;
1154 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 }
1156
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001157 write3X4(par, PixelBusReg, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001159 tmp = read3X4(par, DRAMControl);
1160 if (!is_oldprotect(par->chip_id))
1161 tmp |= 0x10;
Krzysztof Helt122e8ad2008-07-23 21:30:52 -07001162 if (iscyber(par->chip_id))
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001163 tmp |= 0x20;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001164 write3X4(par, DRAMControl, tmp); /* both IO, linear enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001166 write3X4(par, InterfaceSel, read3X4(par, InterfaceSel) | 0x40);
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001167 if (!is_xp(par->chip_id))
1168 write3X4(par, Performance, read3X4(par, Performance) | 0x10);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001169 /* MMIO & PCI read and write burst enable */
Krzysztof Helt13b0de42008-07-23 21:31:06 -07001170 if (par->chip_id != TGUI9440 && par->chip_id != IMAGE975)
Krzysztof Helta0d92252008-07-23 21:30:58 -07001171 write3X4(par, PCIReg, read3X4(par, PCIReg) | 0x06);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001173 vga_mm_wseq(par->io_virt, 0, 3);
1174 vga_mm_wseq(par->io_virt, 1, 1); /* set char clock 8 dots wide */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001175 /* enable 4 maps because needed in chain4 mode */
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001176 vga_mm_wseq(par->io_virt, 2, 0x0F);
1177 vga_mm_wseq(par->io_virt, 3, 0);
1178 vga_mm_wseq(par->io_virt, 4, 0x0E); /* memory mode enable bitmaps ?? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Krzysztof Helt54f019e2008-07-23 21:31:01 -07001180 /* convert from picoseconds to kHz */
1181 vclk = PICOS2KHZ(info->var.pixclock);
1182
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001183 /* divide clock by 2 if 32bpp chain4 mode display and CPU path */
Krzysztof Helt65e93e02008-07-23 21:31:00 -07001184 tmp = read3CE(par, MiscExtFunc) & 0xF0;
Krzysztof Helt54f019e2008-07-23 21:31:01 -07001185 if (bpp == 32 || (par->chip_id == TGUI9440 && bpp == 16)) {
Krzysztof Helt65e93e02008-07-23 21:31:00 -07001186 tmp |= 8;
Krzysztof Helt54f019e2008-07-23 21:31:01 -07001187 vclk *= 2;
1188 }
1189 set_vclk(par, vclk);
Krzysztof Helt65e93e02008-07-23 21:31:00 -07001190 write3CE(par, MiscExtFunc, tmp | 0x12);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001191 write3CE(par, 0x5, 0x40); /* no CGA compat, allow 256 col */
1192 write3CE(par, 0x6, 0x05); /* graphics mode */
1193 write3CE(par, 0x7, 0x0F); /* planes? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001195 /* graphics mode and support 256 color modes */
1196 writeAttr(par, 0x10, 0x41);
1197 writeAttr(par, 0x12, 0x0F); /* planes */
1198 writeAttr(par, 0x13, 0); /* horizontal pel panning */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001200 /* colors */
1201 for (tmp = 0; tmp < 0x10; tmp++)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001202 writeAttr(par, tmp, tmp);
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001203 fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
1204 t_outb(par, 0x20, VGA_ATT_W); /* enable attr */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
1206 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001207 case 8:
1208 tmp = 0;
1209 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001210 case 16:
1211 tmp = 0x30;
1212 break;
1213 case 24:
1214 case 32:
1215 tmp = 0xD0;
1216 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 }
1218
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001219 t_inb(par, VGA_PEL_IW);
1220 t_inb(par, VGA_PEL_MSK);
1221 t_inb(par, VGA_PEL_MSK);
1222 t_inb(par, VGA_PEL_MSK);
1223 t_inb(par, VGA_PEL_MSK);
1224 t_outb(par, tmp, VGA_PEL_MSK);
1225 t_inb(par, VGA_PEL_IW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001227 if (par->flatpanel)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001228 set_number_of_lines(par, info->var.yres);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -07001229 info->fix.line_length = info->var.xres_virtual * bpp / 8;
1230 set_lwidth(par, info->fix.line_length / 8);
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001231
1232 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
1233 par->init_accel(par, info->var.xres_virtual, bpp);
Krzysztof Helt2c86a0c2008-07-23 21:31:03 -07001234
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001236 info->cmap.len = (bpp == 8) ? 256 : 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 debug("exit\n");
1238 return 0;
1239}
1240
1241/* Set one color register */
1242static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green,
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001243 unsigned blue, unsigned transp,
1244 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
1246 int bpp = info->var.bits_per_pixel;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001247 struct tridentfb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 if (regno >= info->cmap.len)
1250 return 1;
1251
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001252 if (bpp == 8) {
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001253 t_outb(par, 0xFF, VGA_PEL_MSK);
1254 t_outb(par, regno, VGA_PEL_IW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001256 t_outb(par, red >> 10, VGA_PEL_D);
1257 t_outb(par, green >> 10, VGA_PEL_D);
1258 t_outb(par, blue >> 10, VGA_PEL_D);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001260 } else if (regno < 16) {
1261 if (bpp == 16) { /* RGB 565 */
1262 u32 col;
Antonino A. Daplas8dad46c2005-08-01 23:46:44 +08001263
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001264 col = (red & 0xF800) | ((green & 0xFC00) >> 5) |
1265 ((blue & 0xF800) >> 11);
1266 col |= col << 16;
1267 ((u32 *)(info->pseudo_palette))[regno] = col;
1268 } else if (bpp == 32) /* ARGB 8888 */
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001269 ((u32 *)info->pseudo_palette)[regno] =
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001270 ((transp & 0xFF00) << 16) |
1271 ((red & 0xFF00) << 8) |
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001272 ((green & 0xFF00)) |
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001273 ((blue & 0xFF00) >> 8);
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 return 0;
1277}
1278
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001279/* Try blanking the screen. For flat panels it does nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280static int tridentfb_blank(int blank_mode, struct fb_info *info)
1281{
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001282 unsigned char PMCont, DPMSCont;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001283 struct tridentfb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
1285 debug("enter\n");
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001286 if (par->flatpanel)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 return 0;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001288 t_outb(par, 0x04, 0x83C8); /* Read DPMS Control */
1289 PMCont = t_inb(par, 0x83C6) & 0xFC;
1290 DPMSCont = read3CE(par, PowerStatus) & 0xFC;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001291 switch (blank_mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 case FB_BLANK_UNBLANK:
1293 /* Screen: On, HSync: On, VSync: On */
1294 case FB_BLANK_NORMAL:
1295 /* Screen: Off, HSync: On, VSync: On */
1296 PMCont |= 0x03;
1297 DPMSCont |= 0x00;
1298 break;
1299 case FB_BLANK_HSYNC_SUSPEND:
1300 /* Screen: Off, HSync: Off, VSync: On */
1301 PMCont |= 0x02;
1302 DPMSCont |= 0x01;
1303 break;
1304 case FB_BLANK_VSYNC_SUSPEND:
1305 /* Screen: Off, HSync: On, VSync: Off */
1306 PMCont |= 0x02;
1307 DPMSCont |= 0x02;
1308 break;
1309 case FB_BLANK_POWERDOWN:
1310 /* Screen: Off, HSync: Off, VSync: Off */
1311 PMCont |= 0x00;
1312 DPMSCont |= 0x03;
1313 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001316 write3CE(par, PowerStatus, DPMSCont);
1317 t_outb(par, 4, 0x83C8);
1318 t_outb(par, PMCont, 0x83C6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320 debug("exit\n");
1321
1322 /* let fbcon do a softblank for us */
1323 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
1324}
1325
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001326static struct fb_ops tridentfb_ops = {
1327 .owner = THIS_MODULE,
1328 .fb_setcolreg = tridentfb_setcolreg,
1329 .fb_pan_display = tridentfb_pan_display,
1330 .fb_blank = tridentfb_blank,
1331 .fb_check_var = tridentfb_check_var,
1332 .fb_set_par = tridentfb_set_par,
1333 .fb_fillrect = tridentfb_fillrect,
1334 .fb_copyarea = tridentfb_copyarea,
Krzysztof Helt0292be42008-07-23 21:31:08 -07001335 .fb_imageblit = tridentfb_imageblit,
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -07001336#ifdef CONFIG_FB_TRIDENT_ACCEL
1337 .fb_sync = tridentfb_sync,
Krzysztof Heltbcac2d52008-07-23 21:31:01 -07001338#endif
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001339};
1340
Krzysztof Helte09ed092008-07-23 21:30:51 -07001341static int __devinit trident_pci_probe(struct pci_dev *dev,
1342 const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343{
1344 int err;
1345 unsigned char revision;
Krzysztof Helte09ed092008-07-23 21:30:51 -07001346 struct fb_info *info;
1347 struct tridentfb_par *default_par;
Krzysztof Helt122e8ad2008-07-23 21:30:52 -07001348 int chip3D;
1349 int chip_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
1351 err = pci_enable_device(dev);
1352 if (err)
1353 return err;
1354
Krzysztof Helte09ed092008-07-23 21:30:51 -07001355 info = framebuffer_alloc(sizeof(struct tridentfb_par), &dev->dev);
1356 if (!info)
1357 return -ENOMEM;
1358 default_par = info->par;
1359
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 chip_id = id->device;
1361
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001362#ifndef CONFIG_FB_TRIDENT_ACCEL
1363 noaccel = 1;
1364#endif
Knut Petersen9fa68ea2005-09-09 13:04:56 -07001365
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 /* If PCI id is 0x9660 then further detect chip type */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001367
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 if (chip_id == TGUI9660) {
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001369 revision = vga_io_rseq(RevisionID);
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001370
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 switch (revision) {
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001372 case 0x21:
1373 chip_id = PROVIDIA9685;
1374 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001375 case 0x22:
1376 case 0x23:
1377 chip_id = CYBER9397;
1378 break;
1379 case 0x2A:
1380 chip_id = CYBER9397DVD;
1381 break;
1382 case 0x30:
1383 case 0x33:
1384 case 0x34:
1385 case 0x35:
1386 case 0x38:
1387 case 0x3A:
1388 case 0xB3:
1389 chip_id = CYBER9385;
1390 break;
1391 case 0x40 ... 0x43:
1392 chip_id = CYBER9382;
1393 break;
1394 case 0x4A:
1395 chip_id = CYBER9388;
1396 break;
1397 default:
1398 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 }
1400 }
1401
1402 chip3D = is3Dchip(chip_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
1404 if (is_xp(chip_id)) {
Krzysztof Heltd9cad042008-07-23 21:30:54 -07001405 default_par->init_accel = xp_init_accel;
1406 default_par->wait_engine = xp_wait_engine;
1407 default_par->fill_rect = xp_fill_rect;
1408 default_par->copy_rect = xp_copy_rect;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001409 tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADEXP;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001410 } else if (is_blade(chip_id)) {
Krzysztof Heltd9cad042008-07-23 21:30:54 -07001411 default_par->init_accel = blade_init_accel;
1412 default_par->wait_engine = blade_wait_engine;
1413 default_par->fill_rect = blade_fill_rect;
1414 default_par->copy_rect = blade_copy_rect;
Krzysztof Helt0292be42008-07-23 21:31:08 -07001415 default_par->image_blit = blade_image_blit;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001416 tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADE3D;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -07001417 } else if (chip3D) { /* 3DImage family left */
Krzysztof Heltd9cad042008-07-23 21:30:54 -07001418 default_par->init_accel = image_init_accel;
1419 default_par->wait_engine = image_wait_engine;
1420 default_par->fill_rect = image_fill_rect;
1421 default_par->copy_rect = image_copy_rect;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001422 tridentfb_fix.accel = FB_ACCEL_TRIDENT_3DIMAGE;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -07001423 } else { /* TGUI 9440/96XX family */
1424 default_par->init_accel = tgui_init_accel;
1425 default_par->wait_engine = xp_wait_engine;
1426 default_par->fill_rect = tgui_fill_rect;
1427 default_par->copy_rect = tgui_copy_rect;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001428 tridentfb_fix.accel = FB_ACCEL_TRIDENT_TGUI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
1430
Krzysztof Helt122e8ad2008-07-23 21:30:52 -07001431 default_par->chip_id = chip_id;
1432
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 /* setup MMIO region */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001434 tridentfb_fix.mmio_start = pci_resource_start(dev, 1);
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001435 tridentfb_fix.mmio_len = pci_resource_len(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001437 if (!request_mem_region(tridentfb_fix.mmio_start,
1438 tridentfb_fix.mmio_len, "tridentfb")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 debug("request_region failed!\n");
Krzysztof Helt3876ae82008-07-23 21:30:57 -07001440 framebuffer_release(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 return -1;
1442 }
1443
Krzysztof Helte09ed092008-07-23 21:30:51 -07001444 default_par->io_virt = ioremap_nocache(tridentfb_fix.mmio_start,
1445 tridentfb_fix.mmio_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Krzysztof Helte09ed092008-07-23 21:30:51 -07001447 if (!default_par->io_virt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 debug("ioremap failed\n");
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001449 err = -1;
1450 goto out_unmap1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 }
1452
Krzysztof Helt13b0de42008-07-23 21:31:06 -07001453 enable_mmio(default_par);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -07001454
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 /* setup framebuffer memory */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001456 tridentfb_fix.smem_start = pci_resource_start(dev, 0);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001457 tridentfb_fix.smem_len = get_memsize(default_par);
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001458
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001459 if (!request_mem_region(tridentfb_fix.smem_start,
1460 tridentfb_fix.smem_len, "tridentfb")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 debug("request_mem_region failed!\n");
Krzysztof Helte09ed092008-07-23 21:30:51 -07001462 disable_mmio(info->par);
Amol Lada02f6402006-12-08 02:40:03 -08001463 err = -1;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001464 goto out_unmap1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 }
1466
Krzysztof Helte09ed092008-07-23 21:30:51 -07001467 info->screen_base = ioremap_nocache(tridentfb_fix.smem_start,
1468 tridentfb_fix.smem_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Krzysztof Helte09ed092008-07-23 21:30:51 -07001470 if (!info->screen_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 debug("ioremap failed\n");
Amol Lada02f6402006-12-08 02:40:03 -08001472 err = -1;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001473 goto out_unmap2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 }
1475
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001476 default_par->flatpanel = is_flatpanel(default_par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001478 if (default_par->flatpanel)
Krzysztof Helte09ed092008-07-23 21:30:51 -07001479 nativex = get_nativex(default_par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Krzysztof Helte09ed092008-07-23 21:30:51 -07001481 info->fix = tridentfb_fix;
1482 info->fbops = &tridentfb_ops;
Krzysztof Heltaa0aa8a2008-07-23 21:30:59 -07001483 info->pseudo_palette = default_par->pseudo_pal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Krzysztof Helte09ed092008-07-23 21:30:51 -07001485 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001486 if (!noaccel && default_par->init_accel) {
1487 info->flags &= ~FBINFO_HWACCEL_DISABLED;
1488 info->flags |= FBINFO_HWACCEL_COPYAREA;
1489 info->flags |= FBINFO_HWACCEL_FILLRECT;
1490 } else
1491 info->flags |= FBINFO_HWACCEL_DISABLED;
1492
Krzysztof Helt0292be42008-07-23 21:31:08 -07001493 info->pixmap.addr = kmalloc(4096, GFP_KERNEL);
1494 if (!info->pixmap.addr) {
1495 err = -ENOMEM;
1496 goto out_unmap2;
1497 }
1498
1499 info->pixmap.size = 4096;
1500 info->pixmap.buf_align = 4;
1501 info->pixmap.scan_align = 1;
1502 info->pixmap.access_align = 32;
1503 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1504
1505 if (default_par->image_blit) {
1506 info->flags |= FBINFO_HWACCEL_IMAGEBLIT;
1507 info->pixmap.scan_align = 4;
1508 }
1509
1510 if (noaccel) {
1511 printk(KERN_DEBUG "disabling acceleration\n");
1512 info->flags |= FBINFO_HWACCEL_DISABLED;
1513 info->pixmap.scan_align = 1;
1514 }
1515
Krzysztof Heltea8ee552008-07-23 21:30:51 -07001516 if (!fb_find_mode(&info->var, info,
Krzysztof Helt07f41e42008-04-28 02:15:06 -07001517 mode_option, NULL, 0, NULL, bpp)) {
Amol Lada02f6402006-12-08 02:40:03 -08001518 err = -EINVAL;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001519 goto out_unmap2;
Amol Lada02f6402006-12-08 02:40:03 -08001520 }
Krzysztof Helte09ed092008-07-23 21:30:51 -07001521 err = fb_alloc_cmap(&info->cmap, 256, 0);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001522 if (err < 0)
1523 goto out_unmap2;
1524
Krzysztof Heltea8ee552008-07-23 21:30:51 -07001525 info->var.activate |= FB_ACTIVATE_NOW;
Krzysztof Helte09ed092008-07-23 21:30:51 -07001526 info->device = &dev->dev;
1527 if (register_framebuffer(info) < 0) {
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001528 printk(KERN_ERR "tridentfb: could not register framebuffer\n");
Krzysztof Helte09ed092008-07-23 21:30:51 -07001529 fb_dealloc_cmap(&info->cmap);
Amol Lada02f6402006-12-08 02:40:03 -08001530 err = -EINVAL;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001531 goto out_unmap2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 }
1533 output("fb%d: %s frame buffer device %dx%d-%dbpp\n",
Krzysztof Heltea8ee552008-07-23 21:30:51 -07001534 info->node, info->fix.id, info->var.xres,
1535 info->var.yres, info->var.bits_per_pixel);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001536
1537 pci_set_drvdata(dev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 return 0;
Amol Lada02f6402006-12-08 02:40:03 -08001539
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001540out_unmap2:
Krzysztof Helt0292be42008-07-23 21:31:08 -07001541 kfree(info->pixmap.addr);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001542 if (info->screen_base)
1543 iounmap(info->screen_base);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001544 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001545 disable_mmio(info->par);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001546out_unmap1:
Krzysztof Helte09ed092008-07-23 21:30:51 -07001547 if (default_par->io_virt)
1548 iounmap(default_par->io_virt);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001549 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001550 framebuffer_release(info);
Amol Lada02f6402006-12-08 02:40:03 -08001551 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001554static void __devexit trident_pci_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Krzysztof Helte09ed092008-07-23 21:30:51 -07001556 struct fb_info *info = pci_get_drvdata(dev);
1557 struct tridentfb_par *par = info->par;
1558
1559 unregister_framebuffer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 iounmap(par->io_virt);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001561 iounmap(info->screen_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001563 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001564 pci_set_drvdata(dev, NULL);
Krzysztof Helt0292be42008-07-23 21:31:08 -07001565 kfree(info->pixmap.addr);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001566 framebuffer_release(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567}
1568
1569/* List of boards that we are trying to support */
1570static struct pci_device_id trident_devices[] = {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001571 {PCI_VENDOR_ID_TRIDENT, BLADE3D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1572 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1573 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1574 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1575 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1576 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1577 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1578 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEE4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Krzysztof Helta0d92252008-07-23 21:30:58 -07001579 {PCI_VENDOR_ID_TRIDENT, TGUI9440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001580 {PCI_VENDOR_ID_TRIDENT, TGUI9660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1581 {PCI_VENDOR_ID_TRIDENT, IMAGE975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1582 {PCI_VENDOR_ID_TRIDENT, IMAGE985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1583 {PCI_VENDOR_ID_TRIDENT, CYBER9320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1584 {PCI_VENDOR_ID_TRIDENT, CYBER9388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1585 {PCI_VENDOR_ID_TRIDENT, CYBER9520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1586 {PCI_VENDOR_ID_TRIDENT, CYBER9525DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1587 {PCI_VENDOR_ID_TRIDENT, CYBER9397, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1588 {PCI_VENDOR_ID_TRIDENT, CYBER9397DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1589 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1590 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1591 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 {0,}
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001593};
1594
1595MODULE_DEVICE_TABLE(pci, trident_devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
1597static struct pci_driver tridentfb_pci_driver = {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001598 .name = "tridentfb",
1599 .id_table = trident_devices,
1600 .probe = trident_pci_probe,
1601 .remove = __devexit_p(trident_pci_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602};
1603
1604/*
1605 * Parse user specified options (`video=trident:')
1606 * example:
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001607 * video=trident:800x600,bpp=16,noaccel
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 */
1609#ifndef MODULE
Krzysztof Helt07f41e42008-04-28 02:15:06 -07001610static int __init tridentfb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611{
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001612 char *opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 if (!options || !*options)
1614 return 0;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001615 while ((opt = strsep(&options, ",")) != NULL) {
1616 if (!*opt)
1617 continue;
1618 if (!strncmp(opt, "noaccel", 7))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 noaccel = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001620 else if (!strncmp(opt, "fp", 2))
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001621 fp = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001622 else if (!strncmp(opt, "crt", 3))
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001623 fp = 0;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001624 else if (!strncmp(opt, "bpp=", 4))
1625 bpp = simple_strtoul(opt + 4, NULL, 0);
1626 else if (!strncmp(opt, "center", 6))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 center = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001628 else if (!strncmp(opt, "stretch", 7))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 stretch = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001630 else if (!strncmp(opt, "memsize=", 8))
1631 memsize = simple_strtoul(opt + 8, NULL, 0);
1632 else if (!strncmp(opt, "memdiff=", 8))
1633 memdiff = simple_strtoul(opt + 8, NULL, 0);
1634 else if (!strncmp(opt, "nativex=", 8))
1635 nativex = simple_strtoul(opt + 8, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 else
Krzysztof Helt07f41e42008-04-28 02:15:06 -07001637 mode_option = opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 }
1639 return 0;
1640}
1641#endif
1642
1643static int __init tridentfb_init(void)
1644{
1645#ifndef MODULE
1646 char *option = NULL;
1647
1648 if (fb_get_options("tridentfb", &option))
1649 return -ENODEV;
1650 tridentfb_setup(option);
1651#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 return pci_register_driver(&tridentfb_pci_driver);
1653}
1654
1655static void __exit tridentfb_exit(void)
1656{
1657 pci_unregister_driver(&tridentfb_pci_driver);
1658}
1659
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660module_init(tridentfb_init);
1661module_exit(tridentfb_exit);
1662
1663MODULE_AUTHOR("Jani Monoses <jani@iv.ro>");
1664MODULE_DESCRIPTION("Framebuffer driver for Trident cards");
1665MODULE_LICENSE("GPL");
1666