blob: c6c77562839d9663cef133f9b23e0d1607a5d2c8 [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>
Krzysztof Heltddb53d42009-03-31 15:25:40 -07005 * Copyright 2009 Krzysztof Helt <krzysztof.h1@wp.pl>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include <linux/delay.h>
Krzysztof Helt10172ed2008-07-23 21:30:54 -070025#include <video/vga.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <video/trident.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028struct tridentfb_par {
Krzysztof Helt245a2c22007-10-16 01:28:42 -070029 void __iomem *io_virt; /* iospace virtual memory address */
Krzysztof Heltea8ee552008-07-23 21:30:51 -070030 u32 pseudo_pal[16];
Krzysztof Helt122e8ad2008-07-23 21:30:52 -070031 int chip_id;
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070032 int flatpanel;
Krzysztof Heltd9cad042008-07-23 21:30:54 -070033 void (*init_accel) (struct tridentfb_par *, int, int);
34 void (*wait_engine) (struct tridentfb_par *);
35 void (*fill_rect)
36 (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
37 void (*copy_rect)
38 (struct tridentfb_par *par, u32, u32, u32, u32, u32, u32);
Krzysztof Helt0292be42008-07-23 21:31:08 -070039 void (*image_blit)
40 (struct tridentfb_par *par, const char*,
41 u32, u32, u32, u32, u32, u32);
Krzysztof Helt5cf13842008-07-23 21:31:05 -070042 unsigned char eng_oper; /* engine operation... */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/* defaults which are normally overriden by user values */
54
55/* video mode */
Krzysztof Helt5cf13842008-07-23 21:31:05 -070056static char *mode_option __devinitdata = "640x480-8@60";
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070057static int bpp __devinitdata = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070059static int noaccel __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61static int center;
62static int stretch;
63
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070064static int fp __devinitdata;
65static int crt __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070067static int memsize __devinitdata;
68static int memdiff __devinitdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int nativex;
70
Krzysztof Helt07f41e42008-04-28 02:15:06 -070071module_param(mode_option, charp, 0);
72MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
Krzysztof Helt9e3f0ca2008-04-28 02:15:10 -070073module_param_named(mode, mode_option, charp, 0);
74MODULE_PARM_DESC(mode, "Initial video mode e.g. '648x480-8@60' (deprecated)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070075module_param(bpp, int, 0);
76module_param(center, int, 0);
77module_param(stretch, int, 0);
78module_param(noaccel, int, 0);
79module_param(memsize, int, 0);
80module_param(memdiff, int, 0);
81module_param(nativex, int, 0);
82module_param(fp, int, 0);
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070083MODULE_PARM_DESC(fp, "Define if flatpanel is connected");
Linus Torvalds1da177e2005-04-16 15:20:36 -070084module_param(crt, int, 0);
Krzysztof Helt6eed8e12008-07-23 21:30:53 -070085MODULE_PARM_DESC(crt, "Define if CRT is connected");
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Krzysztof Helt5cf13842008-07-23 21:31:05 -070087static inline int is_oldclock(int id)
Krzysztof Helt6bdf1032008-07-23 21:30:56 -070088{
Krzysztof Helta0d92252008-07-23 21:30:58 -070089 return (id == TGUI9440) ||
90 (id == TGUI9660) ||
Krzysztof Helt0e73a472008-07-23 21:30:58 -070091 (id == CYBER9320);
92}
93
Krzysztof Helt5cf13842008-07-23 21:31:05 -070094static inline int is_oldprotect(int id)
Krzysztof Helt0e73a472008-07-23 21:30:58 -070095{
Krzysztof Helt5cf13842008-07-23 21:31:05 -070096 return is_oldclock(id) ||
Krzysztof Helt0e73a472008-07-23 21:30:58 -070097 (id == PROVIDIA9685) ||
Krzysztof Helt0e73a472008-07-23 21:30:58 -070098 (id == CYBER9382) ||
99 (id == CYBER9385);
Krzysztof Helt6bdf1032008-07-23 21:30:56 -0700100}
101
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700102static inline int is_blade(int id)
Krzysztof Helte0759a52008-07-23 21:30:53 -0700103{
104 return (id == BLADE3D) ||
105 (id == CYBERBLADEE4) ||
106 (id == CYBERBLADEi7) ||
107 (id == CYBERBLADEi7D) ||
108 (id == CYBERBLADEi1) ||
109 (id == CYBERBLADEi1D) ||
110 (id == CYBERBLADEAi1) ||
111 (id == CYBERBLADEAi1D);
112}
113
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700114static inline int is_xp(int id)
Krzysztof Helte0759a52008-07-23 21:30:53 -0700115{
116 return (id == CYBERBLADEXPAi1) ||
117 (id == CYBERBLADEXPm8) ||
118 (id == CYBERBLADEXPm16);
119}
120
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700121static inline int is3Dchip(int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700123 return is_blade(id) || is_xp(id) ||
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700124 (id == CYBER9397) || (id == CYBER9397DVD) ||
125 (id == CYBER9520) || (id == CYBER9525DVD) ||
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700126 (id == IMAGE975) || (id == IMAGE985);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700129static inline int iscyber(int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
131 switch (id) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700132 case CYBER9388:
133 case CYBER9382:
134 case CYBER9385:
135 case CYBER9397:
136 case CYBER9397DVD:
137 case CYBER9520:
138 case CYBER9525DVD:
139 case CYBERBLADEE4:
140 case CYBERBLADEi7D:
141 case CYBERBLADEi1:
142 case CYBERBLADEi1D:
143 case CYBERBLADEAi1:
144 case CYBERBLADEAi1D:
145 case CYBERBLADEXPAi1:
146 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700148 case CYBER9320:
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700149 case CYBERBLADEi7: /* VIA MPV4 integrated version */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700150 default:
151 /* case CYBERBLDAEXPm8: Strange */
152 /* case CYBERBLDAEXPm16: Strange */
153 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155}
156
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700157static inline void t_outb(struct tridentfb_par *p, u8 val, u16 reg)
158{
159 fb_writeb(val, p->io_virt + reg);
160}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700162static inline u8 t_inb(struct tridentfb_par *p, u16 reg)
163{
164 return fb_readb(p->io_virt + reg);
165}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700167static inline void writemmr(struct tridentfb_par *par, u16 r, u32 v)
168{
169 fb_writel(v, par->io_virt + r);
170}
171
172static inline u32 readmmr(struct tridentfb_par *par, u16 r)
173{
174 return fb_readl(par->io_virt + r);
175}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/*
178 * Blade specific acceleration.
179 */
180
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700181#define point(x, y) ((y) << 16 | (x))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700183static void blade_init_accel(struct tridentfb_par *par, int pitch, int bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700185 int v1 = (pitch >> 3) << 20;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700186 int tmp = bpp == 24 ? 2 : (bpp >> 4);
187 int v2 = v1 | (tmp << 29);
188
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700189 writemmr(par, 0x21C0, v2);
190 writemmr(par, 0x21C4, v2);
191 writemmr(par, 0x21B8, v2);
192 writemmr(par, 0x21BC, v2);
193 writemmr(par, 0x21D0, v1);
194 writemmr(par, 0x21D4, v1);
195 writemmr(par, 0x21C8, v1);
196 writemmr(par, 0x21CC, v1);
197 writemmr(par, 0x216C, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700200static void blade_wait_engine(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700202 while (readmmr(par, STATUS) & 0xFA800000)
203 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700206static void blade_fill_rect(struct tridentfb_par *par,
207 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700209 writemmr(par, COLOR, c);
210 writemmr(par, ROP, rop ? ROP_X : ROP_S);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700211 writemmr(par, CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700213 writemmr(par, DST1, point(x, y));
214 writemmr(par, DST2, point(x + w - 1, y + h - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
Krzysztof Helt0292be42008-07-23 21:31:08 -0700217static void blade_image_blit(struct tridentfb_par *par, const char *data,
218 u32 x, u32 y, u32 w, u32 h, u32 c, u32 b)
219{
220 unsigned size = ((w + 31) >> 5) * h;
221
222 writemmr(par, COLOR, c);
223 writemmr(par, BGCOLOR, b);
224 writemmr(par, CMD, 0xa0000000 | 3 << 19);
225
226 writemmr(par, DST1, point(x, y));
227 writemmr(par, DST2, point(x + w - 1, y + h - 1));
228
229 memcpy(par->io_virt + 0x10000, data, 4 * size);
230}
231
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700232static void blade_copy_rect(struct tridentfb_par *par,
233 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 int direction = 2;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700236 u32 s1 = point(x1, y1);
237 u32 s2 = point(x1 + w - 1, y1 + h - 1);
238 u32 d1 = point(x2, y2);
239 u32 d2 = point(x2 + w - 1, y2 + h - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700242 direction = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700244 writemmr(par, ROP, ROP_S);
245 writemmr(par, CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700247 writemmr(par, SRC1, direction ? s2 : s1);
248 writemmr(par, SRC2, direction ? s1 : s2);
249 writemmr(par, DST1, direction ? d2 : d1);
250 writemmr(par, DST2, direction ? d1 : d2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253/*
254 * BladeXP specific acceleration functions
255 */
256
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700257static void xp_init_accel(struct tridentfb_par *par, int pitch, int bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700259 unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
260 int v1 = pitch << (bpp == 24 ? 20 : (18 + x));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 switch (pitch << (bpp >> 3)) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700263 case 8192:
264 case 512:
265 x |= 0x00;
266 break;
267 case 1024:
268 x |= 0x04;
269 break;
270 case 2048:
271 x |= 0x08;
272 break;
273 case 4096:
274 x |= 0x0C;
275 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
277
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700278 t_outb(par, x, 0x2125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700280 par->eng_oper = x | 0x40;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700282 writemmr(par, 0x2154, v1);
283 writemmr(par, 0x2150, v1);
284 t_outb(par, 3, 0x2126);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700287static void xp_wait_engine(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700289 int count = 0;
290 int timeout = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700292 while (t_inb(par, STATUS) & 0x80) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 count++;
294 if (count == 10000000) {
295 /* Timeout */
296 count = 9990000;
297 timeout++;
298 if (timeout == 8) {
299 /* Reset engine */
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700300 t_outb(par, 0x00, STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 return;
302 }
303 }
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700304 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306}
307
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700308static void xp_fill_rect(struct tridentfb_par *par,
309 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700311 writemmr(par, 0x2127, ROP_P);
312 writemmr(par, 0x2158, c);
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700313 writemmr(par, DRAWFL, 0x4000);
314 writemmr(par, OLDDIM, point(h, w));
315 writemmr(par, OLDDST, point(y, x));
316 t_outb(par, 0x01, OLDCMD);
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700317 t_outb(par, par->eng_oper, 0x2125);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318}
319
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700320static void xp_copy_rect(struct tridentfb_par *par,
321 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700323 u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700324 int direction = 0x0004;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 if ((x1 < x2) && (y1 == y2)) {
327 direction |= 0x0200;
328 x1_tmp = x1 + w - 1;
329 x2_tmp = x2 + w - 1;
330 } else {
331 x1_tmp = x1;
332 x2_tmp = x2;
333 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (y1 < y2) {
336 direction |= 0x0100;
337 y1_tmp = y1 + h - 1;
338 y2_tmp = y2 + h - 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700339 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 y1_tmp = y1;
341 y2_tmp = y2;
342 }
343
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700344 writemmr(par, DRAWFL, direction);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700345 t_outb(par, ROP_S, 0x2127);
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700346 writemmr(par, OLDSRC, point(y1_tmp, x1_tmp));
347 writemmr(par, OLDDST, point(y2_tmp, x2_tmp));
348 writemmr(par, OLDDIM, point(h, w));
349 t_outb(par, 0x01, OLDCMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352/*
353 * Image specific acceleration functions
354 */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700355static void image_init_accel(struct tridentfb_par *par, int pitch, int bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700357 int tmp = bpp == 24 ? 2: (bpp >> 4);
358
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700359 writemmr(par, 0x2120, 0xF0000000);
360 writemmr(par, 0x2120, 0x40000000 | tmp);
361 writemmr(par, 0x2120, 0x80000000);
362 writemmr(par, 0x2144, 0x00000000);
363 writemmr(par, 0x2148, 0x00000000);
364 writemmr(par, 0x2150, 0x00000000);
365 writemmr(par, 0x2154, 0x00000000);
366 writemmr(par, 0x2120, 0x60000000 | (pitch << 16) | pitch);
367 writemmr(par, 0x216C, 0x00000000);
368 writemmr(par, 0x2170, 0x00000000);
369 writemmr(par, 0x217C, 0x00000000);
370 writemmr(par, 0x2120, 0x10000000);
371 writemmr(par, 0x2130, (2047 << 16) | 2047);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700374static void image_wait_engine(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700376 while (readmmr(par, 0x2164) & 0xF0000000)
377 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700380static void image_fill_rect(struct tridentfb_par *par,
381 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700383 writemmr(par, 0x2120, 0x80000000);
384 writemmr(par, 0x2120, 0x90000000 | ROP_S);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700386 writemmr(par, 0x2144, c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700388 writemmr(par, DST1, point(x, y));
389 writemmr(par, DST2, point(x + w - 1, y + h - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700391 writemmr(par, 0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392}
393
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700394static void image_copy_rect(struct tridentfb_par *par,
395 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Krzysztof Helt2c86a0c2008-07-23 21:31:03 -0700397 int direction = 0x4;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700398 u32 s1 = point(x1, y1);
399 u32 s2 = point(x1 + w - 1, y1 + h - 1);
400 u32 d1 = point(x2, y2);
401 u32 d2 = point(x2 + w - 1, y2 + h - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700403 if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))
404 direction = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700406 writemmr(par, 0x2120, 0x80000000);
407 writemmr(par, 0x2120, 0x90000000 | ROP_S);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700409 writemmr(par, SRC1, direction ? s2 : s1);
410 writemmr(par, SRC2, direction ? s1 : s2);
411 writemmr(par, DST1, direction ? d2 : d1);
412 writemmr(par, DST2, direction ? d1 : d2);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700413 writemmr(par, 0x2124,
414 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417/*
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700418 * TGUI 9440/96XX acceleration
419 */
420
421static void tgui_init_accel(struct tridentfb_par *par, int pitch, int bpp)
422{
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700423 unsigned char x = bpp == 24 ? 3 : (bpp >> 4);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700424
425 /* disable clipping */
426 writemmr(par, 0x2148, 0);
427 writemmr(par, 0x214C, point(4095, 2047));
428
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700429 switch ((pitch * bpp) / 8) {
430 case 8192:
431 case 512:
432 x |= 0x00;
433 break;
434 case 1024:
435 x |= 0x04;
436 break;
437 case 2048:
438 x |= 0x08;
439 break;
440 case 4096:
441 x |= 0x0C;
442 break;
443 }
444
445 fb_writew(x, par->io_virt + 0x2122);
446}
447
448static void tgui_fill_rect(struct tridentfb_par *par,
449 u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop)
450{
451 t_outb(par, ROP_P, 0x2127);
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700452 writemmr(par, OLDCLR, c);
453 writemmr(par, DRAWFL, 0x4020);
454 writemmr(par, OLDDIM, point(w - 1, h - 1));
455 writemmr(par, OLDDST, point(x, y));
456 t_outb(par, 1, OLDCMD);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700457}
458
459static void tgui_copy_rect(struct tridentfb_par *par,
460 u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h)
461{
462 int flags = 0;
463 u16 x1_tmp, x2_tmp, y1_tmp, y2_tmp;
464
465 if ((x1 < x2) && (y1 == y2)) {
466 flags |= 0x0200;
467 x1_tmp = x1 + w - 1;
468 x2_tmp = x2 + w - 1;
469 } else {
470 x1_tmp = x1;
471 x2_tmp = x2;
472 }
473
474 if (y1 < y2) {
475 flags |= 0x0100;
476 y1_tmp = y1 + h - 1;
477 y2_tmp = y2 + h - 1;
478 } else {
479 y1_tmp = y1;
480 y2_tmp = y2;
481 }
482
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700483 writemmr(par, DRAWFL, 0x4 | flags);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700484 t_outb(par, ROP_S, 0x2127);
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700485 writemmr(par, OLDSRC, point(x1_tmp, y1_tmp));
486 writemmr(par, OLDDST, point(x2_tmp, y2_tmp));
487 writemmr(par, OLDDIM, point(w - 1, h - 1));
488 t_outb(par, 1, OLDCMD);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700489}
490
491/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 * Accel functions called by the upper layers
493 */
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}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569/*
570 * Hardware access functions
571 */
572
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700573static inline unsigned char read3X4(struct tridentfb_par *par, int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700575 return vga_mm_rcrt(par->io_virt, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
577
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700578static inline void write3X4(struct tridentfb_par *par, int reg,
579 unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700581 vga_mm_wcrt(par->io_virt, reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582}
583
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700584static inline unsigned char read3CE(struct tridentfb_par *par,
585 unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700587 return vga_mm_rgfx(par->io_virt, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
589
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700590static inline void writeAttr(struct tridentfb_par *par, int reg,
591 unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700593 fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
594 vga_mm_wattr(par->io_virt, reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700597static inline void write3CE(struct tridentfb_par *par, int reg,
598 unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700600 vga_mm_wgfx(par->io_virt, reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
Krzysztof Helt13b0de42008-07-23 21:31:06 -0700603static void enable_mmio(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
605 /* Goto New Mode */
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700606 vga_io_rseq(0x0B);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608 /* Unprotect registers */
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700609 vga_io_wseq(NewMode1, 0x80);
Krzysztof Helt13b0de42008-07-23 21:31:06 -0700610 if (!is_oldprotect(par->chip_id))
611 vga_io_wseq(Protection, 0x92);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 /* Enable MMIO */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700614 outb(PCIReg, 0x3D4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 outb(inb(0x3D5) | 0x01, 0x3D5);
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800616}
617
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700618static void disable_mmio(struct tridentfb_par *par)
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800619{
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800620 /* Goto New Mode */
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700621 vga_mm_rseq(par->io_virt, 0x0B);
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800622
623 /* Unprotect registers */
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700624 vga_mm_wseq(par->io_virt, NewMode1, 0x80);
Krzysztof Helt13b0de42008-07-23 21:31:06 -0700625 if (!is_oldprotect(par->chip_id))
626 vga_mm_wseq(par->io_virt, Protection, 0x92);
Krzysztof Helte8ed8572008-03-04 14:28:39 -0800627
628 /* Disable MMIO */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700629 t_outb(par, PCIReg, 0x3D4);
630 t_outb(par, t_inb(par, 0x3D5) & ~0x01, 0x3D5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631}
632
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700633static inline void crtc_unlock(struct tridentfb_par *par)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700634{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700635 write3X4(par, VGA_CRTC_V_SYNC_END,
636 read3X4(par, VGA_CRTC_V_SYNC_END) & 0x7F);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700637}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639/* Return flat panel's maximum x resolution */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700640static int __devinit get_nativex(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700642 int x, y, tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644 if (nativex)
645 return nativex;
646
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700647 tmp = (read3CE(par, VertStretch) >> 4) & 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 switch (tmp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700650 case 0:
651 x = 1280; y = 1024;
652 break;
653 case 2:
654 x = 1024; y = 768;
655 break;
656 case 3:
657 x = 800; y = 600;
658 break;
659 case 4:
660 x = 1400; y = 1050;
661 break;
662 case 1:
663 default:
664 x = 640; y = 480;
665 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 }
667
668 output("%dx%d flat panel found\n", x, y);
669 return x;
670}
671
672/* Set pitch */
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700673static inline void set_lwidth(struct tridentfb_par *par, int width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700675 write3X4(par, VGA_CRTC_OFFSET, width & 0xFF);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700676 write3X4(par, AddColReg,
677 (read3X4(par, AddColReg) & 0xCF) | ((width & 0x300) >> 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
680/* For resolutions smaller than FP resolution stretch */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700681static void screen_stretch(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Krzysztof Helt122e8ad2008-07-23 21:30:52 -0700683 if (par->chip_id != CYBERBLADEXPAi1)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700684 write3CE(par, BiosReg, 0);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700685 else
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700686 write3CE(par, BiosReg, 8);
687 write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 1);
688 write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
691/* For resolutions smaller than FP resolution center */
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700692static inline void screen_center(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700694 write3CE(par, VertStretch, (read3CE(par, VertStretch) & 0x7C) | 0x80);
695 write3CE(par, HorStretch, (read3CE(par, HorStretch) & 0x7C) | 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
697
698/* Address of first shown pixel in display memory */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700699static void set_screen_start(struct tridentfb_par *par, int base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700701 u8 tmp;
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700702 write3X4(par, VGA_CRTC_START_LO, base & 0xFF);
703 write3X4(par, VGA_CRTC_START_HI, (base & 0xFF00) >> 8);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700704 tmp = read3X4(par, CRTCModuleTest) & 0xDF;
705 write3X4(par, CRTCModuleTest, tmp | ((base & 0x10000) >> 11));
706 tmp = read3X4(par, CRTHiOrd) & 0xF8;
707 write3X4(par, CRTHiOrd, tmp | ((base & 0xE0000) >> 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710/* Set dotclock frequency */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700711static void set_vclk(struct tridentfb_par *par, unsigned long freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700713 int m, n, k;
Krzysztof Helt6bdf1032008-07-23 21:30:56 -0700714 unsigned long fi, d, di;
715 unsigned char best_m = 0, best_n = 0, best_k = 0;
716 unsigned char hi, lo;
Krzysztof Helt6280fd42008-07-23 21:31:08 -0700717 unsigned char shift = !is_oldclock(par->chip_id) ? 2 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Krzysztof Helt3f275ea2008-05-12 14:02:11 -0700719 d = 20000;
Krzysztof Helt6280fd42008-07-23 21:31:08 -0700720 for (k = shift; k >= 0; k--)
721 for (m = 1; m < 32; m++) {
722 n = ((m + 2) << shift) - 8;
Krzysztof Helt34dec242008-07-23 21:31:04 -0700723 for (n = (n < 0 ? 0 : n); n < 122; n++) {
Krzysztof Helt3f275ea2008-05-12 14:02:11 -0700724 fi = ((14318l * (n + 8)) / (m + 2)) >> k;
Krzysztof Helt34dec242008-07-23 21:31:04 -0700725 di = abs(fi - freq);
Krzysztof Helt6280fd42008-07-23 21:31:08 -0700726 if (di < d || (di == d && k == best_k)) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700727 d = di;
Krzysztof Helt6bdf1032008-07-23 21:30:56 -0700728 best_n = n;
729 best_m = m;
730 best_k = k;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700731 }
Krzysztof Helt3f275ea2008-05-12 14:02:11 -0700732 if (fi > freq)
733 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700734 }
Krzysztof Helt34dec242008-07-23 21:31:04 -0700735 }
Krzysztof Helt6bdf1032008-07-23 21:30:56 -0700736
737 if (is_oldclock(par->chip_id)) {
738 lo = best_n | (best_m << 7);
739 hi = (best_m >> 1) | (best_k << 4);
740 } else {
741 lo = best_n;
742 hi = best_m | (best_k << 6);
743 }
744
Krzysztof Helt122e8ad2008-07-23 21:30:52 -0700745 if (is3Dchip(par->chip_id)) {
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700746 vga_mm_wseq(par->io_virt, ClockHigh, hi);
747 vga_mm_wseq(par->io_virt, ClockLow, lo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 } else {
Krzysztof Heltc1724fe2008-07-23 21:30:56 -0700749 t_outb(par, lo, 0x43C8);
750 t_outb(par, hi, 0x43C9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700752 debug("VCLK = %X %X\n", hi, lo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753}
754
755/* Set number of lines for flat panels*/
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700756static void set_number_of_lines(struct tridentfb_par *par, int lines)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700758 int tmp = read3CE(par, CyberEnhance) & 0x8F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 if (lines > 1024)
760 tmp |= 0x50;
761 else if (lines > 768)
762 tmp |= 0x30;
763 else if (lines > 600)
764 tmp |= 0x20;
765 else if (lines > 480)
766 tmp |= 0x10;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700767 write3CE(par, CyberEnhance, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768}
769
770/*
771 * If we see that FP is active we assume we have one.
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700772 * Otherwise we have a CRT display. User can override.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 */
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700774static int __devinit is_flatpanel(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
776 if (fp)
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700777 return 1;
Krzysztof Helt122e8ad2008-07-23 21:30:52 -0700778 if (crt || !iscyber(par->chip_id))
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700779 return 0;
780 return (read3CE(par, FPConfig) & 0x10) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
782
783/* Try detecting the video memory size */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700784static unsigned int __devinit get_memsize(struct tridentfb_par *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
786 unsigned char tmp, tmp2;
787 unsigned int k;
788
789 /* If memory size provided by user */
790 if (memsize)
791 k = memsize * Kb;
792 else
Krzysztof Helt122e8ad2008-07-23 21:30:52 -0700793 switch (par->chip_id) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700794 case CYBER9525DVD:
795 k = 2560 * Kb;
796 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 default:
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700798 tmp = read3X4(par, SPR) & 0x0F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 switch (tmp) {
800
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700801 case 0x01:
Krzysztof Heltb614ce82008-03-10 11:43:37 -0700802 k = 512 * Kb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700804 case 0x02:
805 k = 6 * Mb; /* XP */
806 break;
807 case 0x03:
808 k = 1 * Mb;
809 break;
810 case 0x04:
811 k = 8 * Mb;
812 break;
813 case 0x06:
814 k = 10 * Mb; /* XP */
815 break;
816 case 0x07:
817 k = 2 * Mb;
818 break;
819 case 0x08:
820 k = 12 * Mb; /* XP */
821 break;
822 case 0x0A:
823 k = 14 * Mb; /* XP */
824 break;
825 case 0x0C:
826 k = 16 * Mb; /* XP */
827 break;
828 case 0x0E: /* XP */
829
Krzysztof Helt10172ed2008-07-23 21:30:54 -0700830 tmp2 = vga_mm_rseq(par->io_virt, 0xC1);
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700831 switch (tmp2) {
832 case 0x00:
833 k = 20 * Mb;
834 break;
835 case 0x01:
836 k = 24 * Mb;
837 break;
838 case 0x10:
839 k = 28 * Mb;
840 break;
841 case 0x11:
842 k = 32 * Mb;
843 break;
844 default:
845 k = 1 * Mb;
846 break;
847 }
848 break;
849
850 case 0x0F:
851 k = 4 * Mb;
852 break;
853 default:
854 k = 1 * Mb;
855 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 }
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700857 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
859 k -= memdiff * Kb;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700860 output("framebuffer size = %d Kb\n", k / Kb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 return k;
862}
863
864/* See if we can handle the video mode described in var */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700865static int tridentfb_check_var(struct fb_var_screeninfo *var,
866 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700868 struct tridentfb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 int bpp = var->bits_per_pixel;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700870 int line_length;
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700871 int ramdac = 230000; /* 230MHz for most 3D chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 debug("enter\n");
873
874 /* check color depth */
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700875 if (bpp == 24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 bpp = var->bits_per_pixel = 32;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700877 if (bpp != 8 && bpp != 16 && bpp != 32)
878 return -EINVAL;
Krzysztof Helt54f019e2008-07-23 21:31:01 -0700879 if (par->chip_id == TGUI9440 && bpp == 32)
880 return -EINVAL;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700881 /* check whether resolution fits on panel and in memory */
Krzysztof Helt6eed8e12008-07-23 21:30:53 -0700882 if (par->flatpanel && nativex && var->xres > nativex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 return -EINVAL;
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700884 /* various resolution checks */
885 var->xres = (var->xres + 7) & ~0x7;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700886 if (var->xres > var->xres_virtual)
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700887 var->xres_virtual = var->xres;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700888 if (var->yres > var->yres_virtual)
889 var->yres_virtual = var->yres;
890 if (var->xres_virtual > 4095 || var->yres > 2048)
891 return -EINVAL;
892 /* prevent from position overflow for acceleration */
893 if (var->yres_virtual > 0xffff)
894 return -EINVAL;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700895 line_length = var->xres_virtual * bpp / 8;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -0700896
897 if (!is3Dchip(par->chip_id) &&
898 !(info->flags & FBINFO_HWACCEL_DISABLED)) {
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700899 /* acceleration requires line length to be power of 2 */
900 if (line_length <= 512)
901 var->xres_virtual = 512 * 8 / bpp;
902 else if (line_length <= 1024)
903 var->xres_virtual = 1024 * 8 / bpp;
904 else if (line_length <= 2048)
905 var->xres_virtual = 2048 * 8 / bpp;
906 else if (line_length <= 4096)
907 var->xres_virtual = 4096 * 8 / bpp;
908 else if (line_length <= 8192)
909 var->xres_virtual = 8192 * 8 / bpp;
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -0700910 else
911 return -EINVAL;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700912
913 line_length = var->xres_virtual * bpp / 8;
914 }
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -0700915
Krzysztof Heltf330c4b2008-07-23 21:31:07 -0700916 /* datasheet specifies how to set panning only up to 4 MB */
917 if (line_length * (var->yres_virtual - var->yres) > (4 << 20))
918 var->yres_virtual = ((4 << 20) / line_length) + var->yres;
919
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700920 if (line_length * var->yres_virtual > info->fix.smem_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 return -EINVAL;
922
923 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700924 case 8:
925 var->red.offset = 0;
Krzysztof Helta4af1792008-07-23 21:31:06 -0700926 var->red.length = 8;
927 var->green = var->red;
928 var->blue = var->red;
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700929 break;
930 case 16:
931 var->red.offset = 11;
932 var->green.offset = 5;
933 var->blue.offset = 0;
934 var->red.length = 5;
935 var->green.length = 6;
936 var->blue.length = 5;
937 break;
938 case 32:
939 var->red.offset = 16;
940 var->green.offset = 8;
941 var->blue.offset = 0;
942 var->red.length = 8;
943 var->green.length = 8;
944 var->blue.length = 8;
945 break;
946 default:
947 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 }
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700949
950 if (is_xp(par->chip_id))
951 ramdac = 350000;
952
953 switch (par->chip_id) {
954 case TGUI9440:
Krzysztof Helt54f019e2008-07-23 21:31:01 -0700955 ramdac = (bpp >= 16) ? 45000 : 90000;
Krzysztof Helt74a933f2008-07-23 21:31:00 -0700956 break;
957 case CYBER9320:
958 case TGUI9660:
959 ramdac = 135000;
960 break;
961 case PROVIDIA9685:
962 case CYBER9388:
963 case CYBER9382:
964 case CYBER9385:
965 ramdac = 170000;
966 break;
967 }
968
969 /* The clock is doubled for 32 bpp */
970 if (bpp == 32)
971 ramdac /= 2;
972
973 if (PICOS2KHZ(var->pixclock) > ramdac)
974 return -EINVAL;
975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 debug("exit\n");
977
978 return 0;
979
980}
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982/* Pan the display */
983static int tridentfb_pan_display(struct fb_var_screeninfo *var,
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700984 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985{
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700986 struct tridentfb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 unsigned int offset;
988
989 debug("enter\n");
Krzysztof Heltbcac2d52008-07-23 21:31:01 -0700990 offset = (var->xoffset + (var->yoffset * var->xres_virtual))
Krzysztof Helt245a2c22007-10-16 01:28:42 -0700991 * var->bits_per_pixel / 32;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700992 set_screen_start(par, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 debug("exit\n");
994 return 0;
995}
996
Krzysztof Helt5cf13842008-07-23 21:31:05 -0700997static inline void shadowmode_on(struct tridentfb_par *par)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -0700998{
999 write3CE(par, CyberControl, read3CE(par, CyberControl) | 0x81);
1000}
1001
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001002static inline void shadowmode_off(struct tridentfb_par *par)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001003{
1004 write3CE(par, CyberControl, read3CE(par, CyberControl) & 0x7E);
1005}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007/* Set the hardware to the requested video mode */
1008static int tridentfb_set_par(struct fb_info *info)
1009{
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001010 struct tridentfb_par *par = info->par;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001011 u32 htotal, hdispend, hsyncstart, hsyncend, hblankstart, hblankend;
1012 u32 vtotal, vdispend, vsyncstart, vsyncend, vblankstart, vblankend;
1013 struct fb_var_screeninfo *var = &info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 int bpp = var->bits_per_pixel;
1015 unsigned char tmp;
Krzysztof Helt3f275ea2008-05-12 14:02:11 -07001016 unsigned long vclk;
1017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 debug("enter\n");
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001019 hdispend = var->xres / 8 - 1;
Krzysztof Helt34dec242008-07-23 21:31:04 -07001020 hsyncstart = (var->xres + var->right_margin) / 8;
1021 hsyncend = (var->xres + var->right_margin + var->hsync_len) / 8;
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001022 htotal = (var->xres + var->left_margin + var->right_margin +
1023 var->hsync_len) / 8 - 5;
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001024 hblankstart = hdispend + 1;
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001025 hblankend = htotal + 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 vdispend = var->yres - 1;
1028 vsyncstart = var->yres + var->lower_margin;
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001029 vsyncend = vsyncstart + var->vsync_len;
1030 vtotal = var->upper_margin + vsyncend - 2;
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001031 vblankstart = vdispend + 1;
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001032 vblankend = vtotal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
Krzysztof Helt34dec242008-07-23 21:31:04 -07001034 if (info->var.vmode & FB_VMODE_INTERLACED) {
1035 vtotal /= 2;
1036 vdispend /= 2;
1037 vsyncstart /= 2;
1038 vsyncend /= 2;
1039 vblankstart /= 2;
1040 vblankend /= 2;
1041 }
1042
Krzysztof Helt13b0de42008-07-23 21:31:06 -07001043 enable_mmio(par);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001044 crtc_unlock(par);
1045 write3CE(par, CyberControl, 8);
Krzysztof Helt34dec242008-07-23 21:31:04 -07001046 tmp = 0xEB;
1047 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
1048 tmp &= ~0x40;
1049 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
1050 tmp &= ~0x80;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001052 if (par->flatpanel && var->xres < nativex) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 /*
1054 * on flat panels with native size larger
1055 * than requested resolution decide whether
1056 * we stretch or center
1057 */
Krzysztof Helt34dec242008-07-23 21:31:04 -07001058 t_outb(par, tmp | 0xC0, VGA_MIS_W);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001060 shadowmode_on(par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001062 if (center)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001063 screen_center(par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 else if (stretch)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001065 screen_stretch(par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
1067 } else {
Krzysztof Helt34dec242008-07-23 21:31:04 -07001068 t_outb(par, tmp, VGA_MIS_W);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001069 write3CE(par, CyberControl, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
1071
1072 /* vertical timing values */
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001073 write3X4(par, VGA_CRTC_V_TOTAL, vtotal & 0xFF);
1074 write3X4(par, VGA_CRTC_V_DISP_END, vdispend & 0xFF);
1075 write3X4(par, VGA_CRTC_V_SYNC_START, vsyncstart & 0xFF);
1076 write3X4(par, VGA_CRTC_V_SYNC_END, (vsyncend & 0x0F));
1077 write3X4(par, VGA_CRTC_V_BLANK_START, vblankstart & 0xFF);
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001078 write3X4(par, VGA_CRTC_V_BLANK_END, vblankend & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 /* horizontal timing values */
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001081 write3X4(par, VGA_CRTC_H_TOTAL, htotal & 0xFF);
1082 write3X4(par, VGA_CRTC_H_DISP, hdispend & 0xFF);
1083 write3X4(par, VGA_CRTC_H_SYNC_START, hsyncstart & 0xFF);
1084 write3X4(par, VGA_CRTC_H_SYNC_END,
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001085 (hsyncend & 0x1F) | ((hblankend & 0x20) << 2));
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001086 write3X4(par, VGA_CRTC_H_BLANK_START, hblankstart & 0xFF);
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001087 write3X4(par, VGA_CRTC_H_BLANK_END, hblankend & 0x1F);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 /* higher bits of vertical timing values */
1090 tmp = 0x10;
1091 if (vtotal & 0x100) tmp |= 0x01;
1092 if (vdispend & 0x100) tmp |= 0x02;
1093 if (vsyncstart & 0x100) tmp |= 0x04;
1094 if (vblankstart & 0x100) tmp |= 0x08;
1095
1096 if (vtotal & 0x200) tmp |= 0x20;
1097 if (vdispend & 0x200) tmp |= 0x40;
1098 if (vsyncstart & 0x200) tmp |= 0x80;
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001099 write3X4(par, VGA_CRTC_OVERFLOW, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001101 tmp = read3X4(par, CRTHiOrd) & 0x07;
1102 tmp |= 0x08; /* line compare bit 10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 if (vtotal & 0x400) tmp |= 0x80;
1104 if (vblankstart & 0x400) tmp |= 0x40;
1105 if (vsyncstart & 0x400) tmp |= 0x20;
1106 if (vdispend & 0x400) tmp |= 0x10;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001107 write3X4(par, CRTHiOrd, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Krzysztof Helt7f762d22008-07-23 21:30:55 -07001109 tmp = (htotal >> 8) & 0x01;
1110 tmp |= (hdispend >> 7) & 0x02;
1111 tmp |= (hsyncstart >> 5) & 0x08;
1112 tmp |= (hblankstart >> 4) & 0x10;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001113 write3X4(par, HorizOverflow, tmp);
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 tmp = 0x40;
1116 if (vblankstart & 0x200) tmp |= 0x20;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001117//FIXME if (info->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; /* double scan for 200 line modes */
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001118 write3X4(par, VGA_CRTC_MAX_SCAN, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001120 write3X4(par, VGA_CRTC_LINE_COMPARE, 0xFF);
1121 write3X4(par, VGA_CRTC_PRESET_ROW, 0);
1122 write3X4(par, VGA_CRTC_MODE, 0xC3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001124 write3X4(par, LinearAddReg, 0x20); /* enable linear addressing */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001126 tmp = (info->var.vmode & FB_VMODE_INTERLACED) ? 0x84 : 0x80;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001127 /* enable access extended memory */
1128 write3X4(par, CRTCModuleTest, tmp);
Krzysztof Helt34dec242008-07-23 21:31:04 -07001129 tmp = read3CE(par, MiscIntContReg) & ~0x4;
1130 if (info->var.vmode & FB_VMODE_INTERLACED)
1131 tmp |= 0x4;
1132 write3CE(par, MiscIntContReg, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001134 /* enable GE for text acceleration */
1135 write3X4(par, GraphEngReg, 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001138 case 8:
1139 tmp = 0x00;
1140 break;
1141 case 16:
1142 tmp = 0x05;
1143 break;
1144 case 24:
1145 tmp = 0x29;
1146 break;
1147 case 32:
1148 tmp = 0x09;
1149 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 }
1151
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001152 write3X4(par, PixelBusReg, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001154 tmp = read3X4(par, DRAMControl);
1155 if (!is_oldprotect(par->chip_id))
1156 tmp |= 0x10;
Krzysztof Helt122e8ad2008-07-23 21:30:52 -07001157 if (iscyber(par->chip_id))
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001158 tmp |= 0x20;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001159 write3X4(par, DRAMControl, tmp); /* both IO, linear enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001161 write3X4(par, InterfaceSel, read3X4(par, InterfaceSel) | 0x40);
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001162 if (!is_xp(par->chip_id))
1163 write3X4(par, Performance, read3X4(par, Performance) | 0x10);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001164 /* MMIO & PCI read and write burst enable */
Krzysztof Helt13b0de42008-07-23 21:31:06 -07001165 if (par->chip_id != TGUI9440 && par->chip_id != IMAGE975)
Krzysztof Helta0d92252008-07-23 21:30:58 -07001166 write3X4(par, PCIReg, read3X4(par, PCIReg) | 0x06);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001168 vga_mm_wseq(par->io_virt, 0, 3);
1169 vga_mm_wseq(par->io_virt, 1, 1); /* set char clock 8 dots wide */
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001170 /* enable 4 maps because needed in chain4 mode */
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001171 vga_mm_wseq(par->io_virt, 2, 0x0F);
1172 vga_mm_wseq(par->io_virt, 3, 0);
1173 vga_mm_wseq(par->io_virt, 4, 0x0E); /* memory mode enable bitmaps ?? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Krzysztof Helt54f019e2008-07-23 21:31:01 -07001175 /* convert from picoseconds to kHz */
1176 vclk = PICOS2KHZ(info->var.pixclock);
1177
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001178 /* divide clock by 2 if 32bpp chain4 mode display and CPU path */
Krzysztof Helt65e93e02008-07-23 21:31:00 -07001179 tmp = read3CE(par, MiscExtFunc) & 0xF0;
Krzysztof Helt54f019e2008-07-23 21:31:01 -07001180 if (bpp == 32 || (par->chip_id == TGUI9440 && bpp == 16)) {
Krzysztof Helt65e93e02008-07-23 21:31:00 -07001181 tmp |= 8;
Krzysztof Helt54f019e2008-07-23 21:31:01 -07001182 vclk *= 2;
1183 }
1184 set_vclk(par, vclk);
Krzysztof Helt65e93e02008-07-23 21:31:00 -07001185 write3CE(par, MiscExtFunc, tmp | 0x12);
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001186 write3CE(par, 0x5, 0x40); /* no CGA compat, allow 256 col */
1187 write3CE(par, 0x6, 0x05); /* graphics mode */
1188 write3CE(par, 0x7, 0x0F); /* planes? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001190 /* graphics mode and support 256 color modes */
1191 writeAttr(par, 0x10, 0x41);
1192 writeAttr(par, 0x12, 0x0F); /* planes */
1193 writeAttr(par, 0x13, 0); /* horizontal pel panning */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001195 /* colors */
1196 for (tmp = 0; tmp < 0x10; tmp++)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001197 writeAttr(par, tmp, tmp);
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001198 fb_readb(par->io_virt + VGA_IS1_RC); /* flip-flop to index */
1199 t_outb(par, 0x20, VGA_ATT_W); /* enable attr */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 switch (bpp) {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001202 case 8:
1203 tmp = 0;
1204 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001205 case 16:
1206 tmp = 0x30;
1207 break;
1208 case 24:
1209 case 32:
1210 tmp = 0xD0;
1211 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 }
1213
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001214 t_inb(par, VGA_PEL_IW);
1215 t_inb(par, VGA_PEL_MSK);
1216 t_inb(par, VGA_PEL_MSK);
1217 t_inb(par, VGA_PEL_MSK);
1218 t_inb(par, VGA_PEL_MSK);
1219 t_outb(par, tmp, VGA_PEL_MSK);
1220 t_inb(par, VGA_PEL_IW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001222 if (par->flatpanel)
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001223 set_number_of_lines(par, info->var.yres);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -07001224 info->fix.line_length = info->var.xres_virtual * bpp / 8;
1225 set_lwidth(par, info->fix.line_length / 8);
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001226
1227 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
1228 par->init_accel(par, info->var.xres_virtual, bpp);
Krzysztof Helt2c86a0c2008-07-23 21:31:03 -07001229
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 info->fix.visual = (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001231 info->cmap.len = (bpp == 8) ? 256 : 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 debug("exit\n");
1233 return 0;
1234}
1235
1236/* Set one color register */
1237static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green,
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001238 unsigned blue, unsigned transp,
1239 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240{
1241 int bpp = info->var.bits_per_pixel;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001242 struct tridentfb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 if (regno >= info->cmap.len)
1245 return 1;
1246
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001247 if (bpp == 8) {
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001248 t_outb(par, 0xFF, VGA_PEL_MSK);
1249 t_outb(par, regno, VGA_PEL_IW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001251 t_outb(par, red >> 10, VGA_PEL_D);
1252 t_outb(par, green >> 10, VGA_PEL_D);
1253 t_outb(par, blue >> 10, VGA_PEL_D);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001255 } else if (regno < 16) {
1256 if (bpp == 16) { /* RGB 565 */
1257 u32 col;
Antonino A. Daplas8dad46c2005-08-01 23:46:44 +08001258
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001259 col = (red & 0xF800) | ((green & 0xFC00) >> 5) |
1260 ((blue & 0xF800) >> 11);
1261 col |= col << 16;
1262 ((u32 *)(info->pseudo_palette))[regno] = col;
1263 } else if (bpp == 32) /* ARGB 8888 */
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001264 ((u32 *)info->pseudo_palette)[regno] =
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001265 ((transp & 0xFF00) << 16) |
1266 ((red & 0xFF00) << 8) |
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001267 ((green & 0xFF00)) |
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001268 ((blue & 0xFF00) >> 8);
Antonino A. Daplas973d9ab2007-07-17 04:05:41 -07001269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 return 0;
1272}
1273
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001274/* Try blanking the screen. For flat panels it does nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275static int tridentfb_blank(int blank_mode, struct fb_info *info)
1276{
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001277 unsigned char PMCont, DPMSCont;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001278 struct tridentfb_par *par = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 debug("enter\n");
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001281 if (par->flatpanel)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 return 0;
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001283 t_outb(par, 0x04, 0x83C8); /* Read DPMS Control */
1284 PMCont = t_inb(par, 0x83C6) & 0xFC;
1285 DPMSCont = read3CE(par, PowerStatus) & 0xFC;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001286 switch (blank_mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 case FB_BLANK_UNBLANK:
1288 /* Screen: On, HSync: On, VSync: On */
1289 case FB_BLANK_NORMAL:
1290 /* Screen: Off, HSync: On, VSync: On */
1291 PMCont |= 0x03;
1292 DPMSCont |= 0x00;
1293 break;
1294 case FB_BLANK_HSYNC_SUSPEND:
1295 /* Screen: Off, HSync: Off, VSync: On */
1296 PMCont |= 0x02;
1297 DPMSCont |= 0x01;
1298 break;
1299 case FB_BLANK_VSYNC_SUSPEND:
1300 /* Screen: Off, HSync: On, VSync: Off */
1301 PMCont |= 0x02;
1302 DPMSCont |= 0x02;
1303 break;
1304 case FB_BLANK_POWERDOWN:
1305 /* Screen: Off, HSync: Off, VSync: Off */
1306 PMCont |= 0x00;
1307 DPMSCont |= 0x03;
1308 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Krzysztof Helt306fa6f62008-07-23 21:30:50 -07001311 write3CE(par, PowerStatus, DPMSCont);
1312 t_outb(par, 4, 0x83C8);
1313 t_outb(par, PMCont, 0x83C6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
1315 debug("exit\n");
1316
1317 /* let fbcon do a softblank for us */
1318 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
1319}
1320
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001321static struct fb_ops tridentfb_ops = {
1322 .owner = THIS_MODULE,
1323 .fb_setcolreg = tridentfb_setcolreg,
1324 .fb_pan_display = tridentfb_pan_display,
1325 .fb_blank = tridentfb_blank,
1326 .fb_check_var = tridentfb_check_var,
1327 .fb_set_par = tridentfb_set_par,
1328 .fb_fillrect = tridentfb_fillrect,
1329 .fb_copyarea = tridentfb_copyarea,
Krzysztof Helt0292be42008-07-23 21:31:08 -07001330 .fb_imageblit = tridentfb_imageblit,
Krzysztof Helt49b1f4b42008-07-23 21:31:02 -07001331 .fb_sync = tridentfb_sync,
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001332};
1333
Krzysztof Helte09ed092008-07-23 21:30:51 -07001334static int __devinit trident_pci_probe(struct pci_dev *dev,
1335 const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
1337 int err;
1338 unsigned char revision;
Krzysztof Helte09ed092008-07-23 21:30:51 -07001339 struct fb_info *info;
1340 struct tridentfb_par *default_par;
Krzysztof Helt122e8ad2008-07-23 21:30:52 -07001341 int chip3D;
1342 int chip_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 err = pci_enable_device(dev);
1345 if (err)
1346 return err;
1347
Krzysztof Helte09ed092008-07-23 21:30:51 -07001348 info = framebuffer_alloc(sizeof(struct tridentfb_par), &dev->dev);
1349 if (!info)
1350 return -ENOMEM;
1351 default_par = info->par;
1352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 chip_id = id->device;
1354
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 /* If PCI id is 0x9660 then further detect chip type */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001356
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 if (chip_id == TGUI9660) {
Krzysztof Helt10172ed2008-07-23 21:30:54 -07001358 revision = vga_io_rseq(RevisionID);
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001359
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 switch (revision) {
Krzysztof Helt0e73a472008-07-23 21:30:58 -07001361 case 0x21:
1362 chip_id = PROVIDIA9685;
1363 break;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001364 case 0x22:
1365 case 0x23:
1366 chip_id = CYBER9397;
1367 break;
1368 case 0x2A:
1369 chip_id = CYBER9397DVD;
1370 break;
1371 case 0x30:
1372 case 0x33:
1373 case 0x34:
1374 case 0x35:
1375 case 0x38:
1376 case 0x3A:
1377 case 0xB3:
1378 chip_id = CYBER9385;
1379 break;
1380 case 0x40 ... 0x43:
1381 chip_id = CYBER9382;
1382 break;
1383 case 0x4A:
1384 chip_id = CYBER9388;
1385 break;
1386 default:
1387 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 }
1389 }
1390
1391 chip3D = is3Dchip(chip_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
1393 if (is_xp(chip_id)) {
Krzysztof Heltd9cad042008-07-23 21:30:54 -07001394 default_par->init_accel = xp_init_accel;
1395 default_par->wait_engine = xp_wait_engine;
1396 default_par->fill_rect = xp_fill_rect;
1397 default_par->copy_rect = xp_copy_rect;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001398 tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADEXP;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001399 } else if (is_blade(chip_id)) {
Krzysztof Heltd9cad042008-07-23 21:30:54 -07001400 default_par->init_accel = blade_init_accel;
1401 default_par->wait_engine = blade_wait_engine;
1402 default_par->fill_rect = blade_fill_rect;
1403 default_par->copy_rect = blade_copy_rect;
Krzysztof Helt0292be42008-07-23 21:31:08 -07001404 default_par->image_blit = blade_image_blit;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001405 tridentfb_fix.accel = FB_ACCEL_TRIDENT_BLADE3D;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -07001406 } else if (chip3D) { /* 3DImage family left */
Krzysztof Heltd9cad042008-07-23 21:30:54 -07001407 default_par->init_accel = image_init_accel;
1408 default_par->wait_engine = image_wait_engine;
1409 default_par->fill_rect = image_fill_rect;
1410 default_par->copy_rect = image_copy_rect;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001411 tridentfb_fix.accel = FB_ACCEL_TRIDENT_3DIMAGE;
Krzysztof Heltbcac2d52008-07-23 21:31:01 -07001412 } else { /* TGUI 9440/96XX family */
1413 default_par->init_accel = tgui_init_accel;
1414 default_par->wait_engine = xp_wait_engine;
1415 default_par->fill_rect = tgui_fill_rect;
1416 default_par->copy_rect = tgui_copy_rect;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001417 tridentfb_fix.accel = FB_ACCEL_TRIDENT_TGUI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 }
1419
Krzysztof Helt122e8ad2008-07-23 21:30:52 -07001420 default_par->chip_id = chip_id;
1421
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 /* setup MMIO region */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001423 tridentfb_fix.mmio_start = pci_resource_start(dev, 1);
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001424 tridentfb_fix.mmio_len = pci_resource_len(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001426 if (!request_mem_region(tridentfb_fix.mmio_start,
1427 tridentfb_fix.mmio_len, "tridentfb")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 debug("request_region failed!\n");
Krzysztof Helt3876ae82008-07-23 21:30:57 -07001429 framebuffer_release(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 return -1;
1431 }
1432
Krzysztof Helte09ed092008-07-23 21:30:51 -07001433 default_par->io_virt = ioremap_nocache(tridentfb_fix.mmio_start,
1434 tridentfb_fix.mmio_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Krzysztof Helte09ed092008-07-23 21:30:51 -07001436 if (!default_par->io_virt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 debug("ioremap failed\n");
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001438 err = -1;
1439 goto out_unmap1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
1441
Krzysztof Helt13b0de42008-07-23 21:31:06 -07001442 enable_mmio(default_par);
Krzysztof Heltbcac2d52008-07-23 21:31:01 -07001443
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 /* setup framebuffer memory */
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001445 tridentfb_fix.smem_start = pci_resource_start(dev, 0);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001446 tridentfb_fix.smem_len = get_memsize(default_par);
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001447
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001448 if (!request_mem_region(tridentfb_fix.smem_start,
1449 tridentfb_fix.smem_len, "tridentfb")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 debug("request_mem_region failed!\n");
Krzysztof Helte09ed092008-07-23 21:30:51 -07001451 disable_mmio(info->par);
Amol Lada02f6402006-12-08 02:40:03 -08001452 err = -1;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001453 goto out_unmap1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 }
1455
Krzysztof Helte09ed092008-07-23 21:30:51 -07001456 info->screen_base = ioremap_nocache(tridentfb_fix.smem_start,
1457 tridentfb_fix.smem_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Krzysztof Helte09ed092008-07-23 21:30:51 -07001459 if (!info->screen_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 debug("ioremap failed\n");
Amol Lada02f6402006-12-08 02:40:03 -08001461 err = -1;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001462 goto out_unmap2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 }
1464
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001465 default_par->flatpanel = is_flatpanel(default_par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001467 if (default_par->flatpanel)
Krzysztof Helte09ed092008-07-23 21:30:51 -07001468 nativex = get_nativex(default_par);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Krzysztof Helte09ed092008-07-23 21:30:51 -07001470 info->fix = tridentfb_fix;
1471 info->fbops = &tridentfb_ops;
Krzysztof Heltaa0aa8a2008-07-23 21:30:59 -07001472 info->pseudo_palette = default_par->pseudo_pal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Krzysztof Helte09ed092008-07-23 21:30:51 -07001474 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
Krzysztof Helt01a2d9e2008-07-23 21:31:04 -07001475 if (!noaccel && default_par->init_accel) {
1476 info->flags &= ~FBINFO_HWACCEL_DISABLED;
1477 info->flags |= FBINFO_HWACCEL_COPYAREA;
1478 info->flags |= FBINFO_HWACCEL_FILLRECT;
1479 } else
1480 info->flags |= FBINFO_HWACCEL_DISABLED;
1481
Krzysztof Heltddb53d42009-03-31 15:25:40 -07001482 if (is_blade(chip_id) && chip_id != BLADE3D)
1483 info->flags |= FBINFO_READS_FAST;
1484
Krzysztof Helt0292be42008-07-23 21:31:08 -07001485 info->pixmap.addr = kmalloc(4096, GFP_KERNEL);
1486 if (!info->pixmap.addr) {
1487 err = -ENOMEM;
1488 goto out_unmap2;
1489 }
1490
1491 info->pixmap.size = 4096;
1492 info->pixmap.buf_align = 4;
1493 info->pixmap.scan_align = 1;
1494 info->pixmap.access_align = 32;
1495 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1496
1497 if (default_par->image_blit) {
1498 info->flags |= FBINFO_HWACCEL_IMAGEBLIT;
1499 info->pixmap.scan_align = 4;
1500 }
1501
1502 if (noaccel) {
1503 printk(KERN_DEBUG "disabling acceleration\n");
1504 info->flags |= FBINFO_HWACCEL_DISABLED;
1505 info->pixmap.scan_align = 1;
1506 }
1507
Krzysztof Heltea8ee552008-07-23 21:30:51 -07001508 if (!fb_find_mode(&info->var, info,
Krzysztof Helt07f41e42008-04-28 02:15:06 -07001509 mode_option, NULL, 0, NULL, bpp)) {
Amol Lada02f6402006-12-08 02:40:03 -08001510 err = -EINVAL;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001511 goto out_unmap2;
Amol Lada02f6402006-12-08 02:40:03 -08001512 }
Krzysztof Helte09ed092008-07-23 21:30:51 -07001513 err = fb_alloc_cmap(&info->cmap, 256, 0);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001514 if (err < 0)
1515 goto out_unmap2;
1516
Krzysztof Heltea8ee552008-07-23 21:30:51 -07001517 info->var.activate |= FB_ACTIVATE_NOW;
Krzysztof Helte09ed092008-07-23 21:30:51 -07001518 info->device = &dev->dev;
1519 if (register_framebuffer(info) < 0) {
Krzysztof Helt5cf13842008-07-23 21:31:05 -07001520 printk(KERN_ERR "tridentfb: could not register framebuffer\n");
Krzysztof Helte09ed092008-07-23 21:30:51 -07001521 fb_dealloc_cmap(&info->cmap);
Amol Lada02f6402006-12-08 02:40:03 -08001522 err = -EINVAL;
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001523 goto out_unmap2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 }
1525 output("fb%d: %s frame buffer device %dx%d-%dbpp\n",
Krzysztof Heltea8ee552008-07-23 21:30:51 -07001526 info->node, info->fix.id, info->var.xres,
1527 info->var.yres, info->var.bits_per_pixel);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001528
1529 pci_set_drvdata(dev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 return 0;
Amol Lada02f6402006-12-08 02:40:03 -08001531
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001532out_unmap2:
Krzysztof Helt0292be42008-07-23 21:31:08 -07001533 kfree(info->pixmap.addr);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001534 if (info->screen_base)
1535 iounmap(info->screen_base);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001536 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001537 disable_mmio(info->par);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001538out_unmap1:
Krzysztof Helte09ed092008-07-23 21:30:51 -07001539 if (default_par->io_virt)
1540 iounmap(default_par->io_virt);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001541 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001542 framebuffer_release(info);
Amol Lada02f6402006-12-08 02:40:03 -08001543 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544}
1545
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001546static void __devexit trident_pci_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547{
Krzysztof Helte09ed092008-07-23 21:30:51 -07001548 struct fb_info *info = pci_get_drvdata(dev);
1549 struct tridentfb_par *par = info->par;
1550
1551 unregister_framebuffer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 iounmap(par->io_virt);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001553 iounmap(info->screen_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
Krzysztof Helte8ed8572008-03-04 14:28:39 -08001555 release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001556 pci_set_drvdata(dev, NULL);
Krzysztof Helt0292be42008-07-23 21:31:08 -07001557 kfree(info->pixmap.addr);
Andres Salomon07b39b42009-03-31 15:25:22 -07001558 fb_dealloc_cmap(&info->cmap);
Krzysztof Helte09ed092008-07-23 21:30:51 -07001559 framebuffer_release(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560}
1561
1562/* List of boards that we are trying to support */
1563static struct pci_device_id trident_devices[] = {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001564 {PCI_VENDOR_ID_TRIDENT, BLADE3D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1565 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1566 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi7D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1567 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1568 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1569 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1570 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEAi1D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1571 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEE4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Krzysztof Helta0d92252008-07-23 21:30:58 -07001572 {PCI_VENDOR_ID_TRIDENT, TGUI9440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001573 {PCI_VENDOR_ID_TRIDENT, TGUI9660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1574 {PCI_VENDOR_ID_TRIDENT, IMAGE975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1575 {PCI_VENDOR_ID_TRIDENT, IMAGE985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1576 {PCI_VENDOR_ID_TRIDENT, CYBER9320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1577 {PCI_VENDOR_ID_TRIDENT, CYBER9388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1578 {PCI_VENDOR_ID_TRIDENT, CYBER9520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1579 {PCI_VENDOR_ID_TRIDENT, CYBER9525DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1580 {PCI_VENDOR_ID_TRIDENT, CYBER9397, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1581 {PCI_VENDOR_ID_TRIDENT, CYBER9397DVD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1582 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPAi1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1583 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1584 {PCI_VENDOR_ID_TRIDENT, CYBERBLADEXPm16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 {0,}
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001586};
1587
1588MODULE_DEVICE_TABLE(pci, trident_devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
1590static struct pci_driver tridentfb_pci_driver = {
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001591 .name = "tridentfb",
1592 .id_table = trident_devices,
1593 .probe = trident_pci_probe,
1594 .remove = __devexit_p(trident_pci_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595};
1596
1597/*
1598 * Parse user specified options (`video=trident:')
1599 * example:
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001600 * video=trident:800x600,bpp=16,noaccel
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 */
1602#ifndef MODULE
Krzysztof Helt07f41e42008-04-28 02:15:06 -07001603static int __init tridentfb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604{
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001605 char *opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 if (!options || !*options)
1607 return 0;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001608 while ((opt = strsep(&options, ",")) != NULL) {
1609 if (!*opt)
1610 continue;
1611 if (!strncmp(opt, "noaccel", 7))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 noaccel = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001613 else if (!strncmp(opt, "fp", 2))
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001614 fp = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001615 else if (!strncmp(opt, "crt", 3))
Krzysztof Helt6eed8e12008-07-23 21:30:53 -07001616 fp = 0;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001617 else if (!strncmp(opt, "bpp=", 4))
1618 bpp = simple_strtoul(opt + 4, NULL, 0);
1619 else if (!strncmp(opt, "center", 6))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 center = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001621 else if (!strncmp(opt, "stretch", 7))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 stretch = 1;
Krzysztof Helt245a2c22007-10-16 01:28:42 -07001623 else if (!strncmp(opt, "memsize=", 8))
1624 memsize = simple_strtoul(opt + 8, NULL, 0);
1625 else if (!strncmp(opt, "memdiff=", 8))
1626 memdiff = simple_strtoul(opt + 8, NULL, 0);
1627 else if (!strncmp(opt, "nativex=", 8))
1628 nativex = simple_strtoul(opt + 8, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 else
Krzysztof Helt07f41e42008-04-28 02:15:06 -07001630 mode_option = opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 }
1632 return 0;
1633}
1634#endif
1635
1636static int __init tridentfb_init(void)
1637{
1638#ifndef MODULE
1639 char *option = NULL;
1640
1641 if (fb_get_options("tridentfb", &option))
1642 return -ENODEV;
1643 tridentfb_setup(option);
1644#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 return pci_register_driver(&tridentfb_pci_driver);
1646}
1647
1648static void __exit tridentfb_exit(void)
1649{
1650 pci_unregister_driver(&tridentfb_pci_driver);
1651}
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653module_init(tridentfb_init);
1654module_exit(tridentfb_exit);
1655
1656MODULE_AUTHOR("Jani Monoses <jani@iv.ro>");
1657MODULE_DESCRIPTION("Framebuffer driver for Trident cards");
1658MODULE_LICENSE("GPL");
Krzysztof Heltddb53d42009-03-31 15:25:40 -07001659MODULE_ALIAS("cyblafb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660