blob: 73ad59822ea1bf8649e7119594f717773e50180e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
3 * Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200 and G400
4 *
5 * (c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>
6 *
7 * Portions Copyright (c) 2001 Matrox Graphics Inc.
8 *
9 * Version: 1.65 2002/08/14
10 *
11 * MTRR stuff: 1998 Tom Rini <trini@kernel.crashing.org>
12 *
13 * Contributors: "menion?" <menion@mindless.com>
14 * Betatesting, fixes, ideas
15 *
16 * "Kurt Garloff" <garloff@suse.de>
17 * Betatesting, fixes, ideas, videomodes, videomodes timmings
18 *
19 * "Tom Rini" <trini@kernel.crashing.org>
20 * MTRR stuff, PPC cleanups, betatesting, fixes, ideas
21 *
22 * "Bibek Sahu" <scorpio@dodds.net>
23 * Access device through readb|w|l and write b|w|l
24 * Extensive debugging stuff
25 *
26 * "Daniel Haun" <haund@usa.net>
27 * Testing, hardware cursor fixes
28 *
29 * "Scott Wood" <sawst46+@pitt.edu>
30 * Fixes
31 *
32 * "Gerd Knorr" <kraxel@goldbach.isdn.cs.tu-berlin.de>
33 * Betatesting
34 *
35 * "Kelly French" <targon@hazmat.com>
36 * "Fernando Herrera" <fherrera@eurielec.etsit.upm.es>
37 * Betatesting, bug reporting
38 *
39 * "Pablo Bianucci" <pbian@pccp.com.ar>
40 * Fixes, ideas, betatesting
41 *
42 * "Inaky Perez Gonzalez" <inaky@peloncho.fis.ucm.es>
43 * Fixes, enhandcements, ideas, betatesting
44 *
45 * "Ryuichi Oikawa" <roikawa@rr.iiij4u.or.jp>
46 * PPC betatesting, PPC support, backward compatibility
47 *
48 * "Paul Womar" <Paul@pwomar.demon.co.uk>
49 * "Owen Waller" <O.Waller@ee.qub.ac.uk>
50 * PPC betatesting
51 *
52 * "Thomas Pornin" <pornin@bolet.ens.fr>
53 * Alpha betatesting
54 *
55 * "Pieter van Leuven" <pvl@iae.nl>
56 * "Ulf Jaenicke-Roessler" <ujr@physik.phy.tu-dresden.de>
57 * G100 testing
58 *
59 * "H. Peter Arvin" <hpa@transmeta.com>
60 * Ideas
61 *
62 * "Cort Dougan" <cort@cs.nmt.edu>
63 * CHRP fixes and PReP cleanup
64 *
65 * "Mark Vojkovich" <mvojkovi@ucsd.edu>
66 * G400 support
67 *
68 * "Samuel Hocevar" <sam@via.ecp.fr>
69 * Fixes
70 *
71 * "Anton Altaparmakov" <AntonA@bigfoot.com>
72 * G400 MAX/non-MAX distinction
73 *
74 * "Ken Aaker" <kdaaker@rchland.vnet.ibm.com>
75 * memtype extension (needed for GXT130P RS/6000 adapter)
76 *
77 * "Uns Lider" <unslider@miranda.org>
78 * G100 PLNWT fixes
79 *
80 * "Denis Zaitsev" <zzz@cd-club.ru>
81 * Fixes
82 *
83 * "Mike Pieper" <mike@pieper-family.de>
84 * TVOut enhandcements, V4L2 control interface.
85 *
86 * "Diego Biurrun" <diego@biurrun.de>
87 * DFP testing
88 *
89 * (following author is not in any relation with this code, but his code
90 * is included in this driver)
91 *
92 * Based on framebuffer driver for VBE 2.0 compliant graphic boards
93 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
94 *
95 * (following author is not in any relation with this code, but his ideas
Robert P. J. Daybeb7dd82007-05-09 07:14:03 +020096 * were used when writing this driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 *
98 * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk>
99 *
100 */
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#include <linux/version.h>
103
Andrew Mortona50d9132006-06-21 01:57:39 -0300104#define __OLD_VIDIOC_
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#include "matroxfb_base.h"
107#include "matroxfb_misc.h"
108#include "matroxfb_accel.h"
109#include "matroxfb_DAC1064.h"
110#include "matroxfb_Ti3026.h"
111#include "matroxfb_maven.h"
112#include "matroxfb_crtc2.h"
113#include "matroxfb_g450.h"
114#include <linux/matroxfb.h>
115#include <linux/interrupt.h>
Krzysztof Helt84902b72007-10-16 01:29:04 -0700116#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118#ifdef CONFIG_PPC_PMAC
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100119#include <asm/machdep.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120unsigned char nvram_read_byte(int);
121static int default_vmode = VMODE_NVRAM;
122static int default_cmode = CMODE_NVRAM;
123#endif
124
125static void matroxfb_unregister_device(struct matrox_fb_info* minfo);
126
127/* --------------------------------------------------------------------- */
128
129/*
130 * card parameters
131 */
132
133/* --------------------------------------------------------------------- */
134
135static struct fb_var_screeninfo vesafb_defined = {
136 640,480,640,480,/* W,H, W, H (virtual) load xres,xres_virtual*/
137 0,0, /* virtual -> visible no offset */
138 8, /* depth -> load bits_per_pixel */
139 0, /* greyscale ? */
140 {0,0,0}, /* R */
141 {0,0,0}, /* G */
142 {0,0,0}, /* B */
143 {0,0,0}, /* transparency */
144 0, /* standard pixel format */
145 FB_ACTIVATE_NOW,
146 -1,-1,
147 FB_ACCELF_TEXT, /* accel flags */
148 39721L,48L,16L,33L,10L,
149 96L,2L,~0, /* No sync info */
150 FB_VMODE_NONINTERLACED,
151 0, {0,0,0,0,0}
152};
153
154
155
156/* --------------------------------------------------------------------- */
Jean Delvare316b4d62009-09-22 16:47:49 -0700157static void update_crtc2(struct matrox_fb_info *minfo, unsigned int pos)
158{
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700159 struct matroxfb_dh_fb_info *info = minfo->crtc2.info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 /* Make sure that displays are compatible */
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700162 if (info && (info->fbcon.var.bits_per_pixel == minfo->fbcon.var.bits_per_pixel)
163 && (info->fbcon.var.xres_virtual == minfo->fbcon.var.xres_virtual)
164 && (info->fbcon.var.green.length == minfo->fbcon.var.green.length)
Andrew Mortona50d9132006-06-21 01:57:39 -0300165 ) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700166 switch (minfo->fbcon.var.bits_per_pixel) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 case 16:
168 case 32:
169 pos = pos * 8;
170 if (info->interlaced) {
171 mga_outl(0x3C2C, pos);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700172 mga_outl(0x3C28, pos + minfo->fbcon.var.xres_virtual * minfo->fbcon.var.bits_per_pixel / 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 } else {
174 mga_outl(0x3C28, pos);
175 }
176 break;
177 }
178 }
179}
180
Jean Delvare316b4d62009-09-22 16:47:49 -0700181static void matroxfb_crtc1_panpos(struct matrox_fb_info *minfo)
182{
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700183 if (minfo->crtc1.panpos >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 unsigned long flags;
185 int panpos;
186
187 matroxfb_DAC_lock_irqsave(flags);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700188 panpos = minfo->crtc1.panpos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 if (panpos >= 0) {
190 unsigned int extvga_reg;
191
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700192 minfo->crtc1.panpos = -1; /* No update pending anymore */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 extvga_reg = mga_inb(M_EXTVGA_INDEX);
194 mga_setr(M_EXTVGA_INDEX, 0x00, panpos);
195 if (extvga_reg != 0x00) {
196 mga_outb(M_EXTVGA_INDEX, extvga_reg);
197 }
198 }
199 matroxfb_DAC_unlock_irqrestore(flags);
200 }
201}
202
David Howells7d12e782006-10-05 14:55:46 +0100203static irqreturn_t matrox_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
205 u_int32_t status;
206 int handled = 0;
207
208 MINFO_FROM(dev_id);
209
210 status = mga_inl(M_STATUS);
211
212 if (status & 0x20) {
213 mga_outl(M_ICLEAR, 0x20);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700214 minfo->crtc1.vsync.cnt++;
Jean Delvare316b4d62009-09-22 16:47:49 -0700215 matroxfb_crtc1_panpos(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700216 wake_up_interruptible(&minfo->crtc1.vsync.wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 handled = 1;
218 }
219 if (status & 0x200) {
220 mga_outl(M_ICLEAR, 0x200);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700221 minfo->crtc2.vsync.cnt++;
222 wake_up_interruptible(&minfo->crtc2.vsync.wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 handled = 1;
224 }
225 return IRQ_RETVAL(handled);
226}
227
Jean Delvare316b4d62009-09-22 16:47:49 -0700228int matroxfb_enable_irq(struct matrox_fb_info *minfo, int reenable)
229{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 u_int32_t bm;
Andrew Mortona50d9132006-06-21 01:57:39 -0300231
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700232 if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 bm = 0x220;
234 else
235 bm = 0x020;
236
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700237 if (!test_and_set_bit(0, &minfo->irq_flags)) {
238 if (request_irq(minfo->pcidev->irq, matrox_irq,
239 IRQF_SHARED, "matroxfb", minfo)) {
240 clear_bit(0, &minfo->irq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return -EINVAL;
242 }
243 /* Clear any pending field interrupts */
244 mga_outl(M_ICLEAR, bm);
245 mga_outl(M_IEN, mga_inl(M_IEN) | bm);
246 } else if (reenable) {
247 u_int32_t ien;
Andrew Mortona50d9132006-06-21 01:57:39 -0300248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 ien = mga_inl(M_IEN);
250 if ((ien & bm) != bm) {
251 printk(KERN_DEBUG "matroxfb: someone disabled IRQ [%08X]\n", ien);
252 mga_outl(M_IEN, ien | bm);
253 }
254 }
255 return 0;
256}
257
Jean Delvare316b4d62009-09-22 16:47:49 -0700258static void matroxfb_disable_irq(struct matrox_fb_info *minfo)
259{
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700260 if (test_and_clear_bit(0, &minfo->irq_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 /* Flush pending pan-at-vbl request... */
Jean Delvare316b4d62009-09-22 16:47:49 -0700262 matroxfb_crtc1_panpos(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700263 if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 mga_outl(M_IEN, mga_inl(M_IEN) & ~0x220);
265 else
266 mga_outl(M_IEN, mga_inl(M_IEN) & ~0x20);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700267 free_irq(minfo->pcidev->irq, minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269}
270
Jean Delvare316b4d62009-09-22 16:47:49 -0700271int matroxfb_wait_for_sync(struct matrox_fb_info *minfo, u_int32_t crtc)
272{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 struct matrox_vsync *vs;
274 unsigned int cnt;
275 int ret;
276
277 switch (crtc) {
278 case 0:
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700279 vs = &minfo->crtc1.vsync;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 break;
281 case 1:
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700282 if (minfo->devflags.accelerator != FB_ACCEL_MATROX_MGAG400) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 return -ENODEV;
284 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700285 vs = &minfo->crtc2.vsync;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 break;
287 default:
288 return -ENODEV;
289 }
Jean Delvare316b4d62009-09-22 16:47:49 -0700290 ret = matroxfb_enable_irq(minfo, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 if (ret) {
292 return ret;
293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 cnt = vs->cnt;
296 ret = wait_event_interruptible_timeout(vs->wait, cnt != vs->cnt, HZ/10);
297 if (ret < 0) {
298 return ret;
299 }
300 if (ret == 0) {
Jean Delvare316b4d62009-09-22 16:47:49 -0700301 matroxfb_enable_irq(minfo, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 return -ETIMEDOUT;
303 }
304 return 0;
305}
306
307/* --------------------------------------------------------------------- */
308
Jean Delvare316b4d62009-09-22 16:47:49 -0700309static void matrox_pan_var(struct matrox_fb_info *minfo,
310 struct fb_var_screeninfo *var)
311{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 unsigned int pos;
313 unsigned short p0, p1, p2;
314#ifdef CONFIG_FB_MATROX_32MB
315 unsigned int p3;
316#endif
317 int vbl;
318 unsigned long flags;
319
320 CRITFLAGS
321
Harvey Harrison5ae12172008-04-28 02:15:47 -0700322 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700324 if (minfo->dead)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 return;
326
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700327 minfo->fbcon.var.xoffset = var->xoffset;
328 minfo->fbcon.var.yoffset = var->yoffset;
329 pos = (minfo->fbcon.var.yoffset * minfo->fbcon.var.xres_virtual + minfo->fbcon.var.xoffset) * minfo->curr.final_bppShift / 32;
330 pos += minfo->curr.ydstorg.chunks;
331 p0 = minfo->hw.CRTC[0x0D] = pos & 0xFF;
332 p1 = minfo->hw.CRTC[0x0C] = (pos & 0xFF00) >> 8;
333 p2 = minfo->hw.CRTCEXT[0] = (minfo->hw.CRTCEXT[0] & 0xB0) | ((pos >> 16) & 0x0F) | ((pos >> 14) & 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#ifdef CONFIG_FB_MATROX_32MB
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700335 p3 = minfo->hw.CRTCEXT[8] = pos >> 21;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#endif
337
338 /* FB_ACTIVATE_VBL and we can acquire interrupts? Honor FB_ACTIVATE_VBL then... */
Jean Delvare316b4d62009-09-22 16:47:49 -0700339 vbl = (var->activate & FB_ACTIVATE_VBL) && (matroxfb_enable_irq(minfo, 0) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 CRITBEGIN
342
343 matroxfb_DAC_lock_irqsave(flags);
344 mga_setr(M_CRTC_INDEX, 0x0D, p0);
345 mga_setr(M_CRTC_INDEX, 0x0C, p1);
346#ifdef CONFIG_FB_MATROX_32MB
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700347 if (minfo->devflags.support32MB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 mga_setr(M_EXTVGA_INDEX, 0x08, p3);
349#endif
350 if (vbl) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700351 minfo->crtc1.panpos = p2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 } else {
353 /* Abort any pending change */
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700354 minfo->crtc1.panpos = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 mga_setr(M_EXTVGA_INDEX, 0x00, p2);
356 }
357 matroxfb_DAC_unlock_irqrestore(flags);
Andrew Mortona50d9132006-06-21 01:57:39 -0300358
Jean Delvare316b4d62009-09-22 16:47:49 -0700359 update_crtc2(minfo, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 CRITEND
362}
363
Jean Delvare316b4d62009-09-22 16:47:49 -0700364static void matroxfb_remove(struct matrox_fb_info *minfo, int dummy)
365{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 /* Currently we are holding big kernel lock on all dead & usecount updates.
367 * Destroy everything after all users release it. Especially do not unregister
368 * framebuffer and iounmap memory, neither fbmem nor fbcon-cfb* does not check
369 * for device unplugged when in use.
370 * In future we should point mmio.vbase & video.vbase somewhere where we can
371 * write data without causing too much damage...
372 */
373
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700374 minfo->dead = 1;
375 if (minfo->usecount) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 /* destroy it later */
377 return;
378 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700379 matroxfb_unregister_device(minfo);
380 unregister_framebuffer(&minfo->fbcon);
Jean Delvare316b4d62009-09-22 16:47:49 -0700381 matroxfb_g450_shutdown(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#ifdef CONFIG_MTRR
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700383 if (minfo->mtrr.vram_valid)
384 mtrr_del(minfo->mtrr.vram, minfo->video.base, minfo->video.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#endif
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700386 mga_iounmap(minfo->mmio.vbase);
387 mga_iounmap(minfo->video.vbase);
388 release_mem_region(minfo->video.base, minfo->video.len_maximum);
389 release_mem_region(minfo->mmio.base, 16384);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 kfree(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
393 /*
394 * Open/Release the frame buffer device
395 */
396
397static int matroxfb_open(struct fb_info *info, int user)
398{
399 MINFO_FROM_INFO(info);
Andrew Mortona50d9132006-06-21 01:57:39 -0300400
Harvey Harrison5ae12172008-04-28 02:15:47 -0700401 DBG_LOOP(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700403 if (minfo->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return -ENXIO;
405 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700406 minfo->usecount++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 if (user) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700408 minfo->userusecount++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410 return(0);
411}
412
413static int matroxfb_release(struct fb_info *info, int user)
414{
415 MINFO_FROM_INFO(info);
Andrew Mortona50d9132006-06-21 01:57:39 -0300416
Harvey Harrison5ae12172008-04-28 02:15:47 -0700417 DBG_LOOP(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 if (user) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700420 if (0 == --minfo->userusecount) {
Jean Delvare316b4d62009-09-22 16:47:49 -0700421 matroxfb_disable_irq(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
423 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700424 if (!(--minfo->usecount) && minfo->dead) {
Jean Delvare316b4d62009-09-22 16:47:49 -0700425 matroxfb_remove(minfo, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
427 return(0);
428}
429
430static int matroxfb_pan_display(struct fb_var_screeninfo *var,
431 struct fb_info* info) {
432 MINFO_FROM_INFO(info);
433
Harvey Harrison5ae12172008-04-28 02:15:47 -0700434 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Jean Delvare316b4d62009-09-22 16:47:49 -0700436 matrox_pan_var(minfo, var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 return 0;
438}
439
Jean Delvare316b4d62009-09-22 16:47:49 -0700440static int matroxfb_get_final_bppShift(const struct matrox_fb_info *minfo,
441 int bpp)
442{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 int bppshft2;
444
Harvey Harrison5ae12172008-04-28 02:15:47 -0700445 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 bppshft2 = bpp;
448 if (!bppshft2) {
449 return 8;
450 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700451 if (isInterleave(minfo))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 bppshft2 >>= 1;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700453 if (minfo->devflags.video64bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 bppshft2 >>= 1;
455 return bppshft2;
456}
457
Jean Delvare316b4d62009-09-22 16:47:49 -0700458static int matroxfb_test_and_set_rounding(const struct matrox_fb_info *minfo,
459 int xres, int bpp)
460{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 int over;
462 int rounding;
463
Harvey Harrison5ae12172008-04-28 02:15:47 -0700464 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 switch (bpp) {
467 case 0: return xres;
468 case 4: rounding = 128;
469 break;
470 case 8: rounding = 64; /* doc says 64; 32 is OK for G400 */
471 break;
472 case 16: rounding = 32;
473 break;
474 case 24: rounding = 64; /* doc says 64; 32 is OK for G400 */
475 break;
476 default: rounding = 16;
477 /* on G400, 16 really does not work */
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700478 if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 rounding = 32;
480 break;
481 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700482 if (isInterleave(minfo)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 rounding *= 2;
484 }
485 over = xres % rounding;
486 if (over)
487 xres += rounding-over;
488 return xres;
489}
490
Jean Delvare316b4d62009-09-22 16:47:49 -0700491static int matroxfb_pitch_adjust(const struct matrox_fb_info *minfo, int xres,
492 int bpp)
493{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 const int* width;
495 int xres_new;
496
Harvey Harrison5ae12172008-04-28 02:15:47 -0700497 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 if (!bpp) return xres;
500
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700501 width = minfo->capable.vxres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700503 if (minfo->devflags.precise_width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 while (*width) {
Jean Delvare316b4d62009-09-22 16:47:49 -0700505 if ((*width >= xres) && (matroxfb_test_and_set_rounding(minfo, *width, bpp) == *width)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 break;
507 }
508 width++;
509 }
510 xres_new = *width;
511 } else {
Jean Delvare316b4d62009-09-22 16:47:49 -0700512 xres_new = matroxfb_test_and_set_rounding(minfo, xres, bpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return xres_new;
515}
516
517static int matroxfb_get_cmap_len(struct fb_var_screeninfo *var) {
518
Harvey Harrison5ae12172008-04-28 02:15:47 -0700519 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521 switch (var->bits_per_pixel) {
522 case 4:
523 return 16; /* pseudocolor... 16 entries HW palette */
524 case 8:
525 return 256; /* pseudocolor... 256 entries HW palette */
526 case 16:
527 return 16; /* directcolor... 16 entries SW palette */
528 /* Mystique: truecolor, 16 entries SW palette, HW palette hardwired into 1:1 mapping */
529 case 24:
530 return 16; /* directcolor... 16 entries SW palette */
531 /* Mystique: truecolor, 16 entries SW palette, HW palette hardwired into 1:1 mapping */
532 case 32:
533 return 16; /* directcolor... 16 entries SW palette */
534 /* Mystique: truecolor, 16 entries SW palette, HW palette hardwired into 1:1 mapping */
535 }
536 return 16; /* return something reasonable... or panic()? */
537}
538
Jean Delvare316b4d62009-09-22 16:47:49 -0700539static int matroxfb_decode_var(const struct matrox_fb_info *minfo,
540 struct fb_var_screeninfo *var, int *visual,
541 int *video_cmap_len, unsigned int* ydstorg)
542{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 struct RGBT {
544 unsigned char bpp;
545 struct {
546 unsigned char offset,
547 length;
548 } red,
549 green,
550 blue,
551 transp;
552 signed char visual;
553 };
554 static const struct RGBT table[]= {
555 { 8,{ 0,8},{0,8},{0,8},{ 0,0},MX_VISUAL_PSEUDOCOLOR},
556 {15,{10,5},{5,5},{0,5},{15,1},MX_VISUAL_DIRECTCOLOR},
557 {16,{11,5},{5,6},{0,5},{ 0,0},MX_VISUAL_DIRECTCOLOR},
558 {24,{16,8},{8,8},{0,8},{ 0,0},MX_VISUAL_DIRECTCOLOR},
559 {32,{16,8},{8,8},{0,8},{24,8},MX_VISUAL_DIRECTCOLOR}
560 };
561 struct RGBT const *rgbt;
562 unsigned int bpp = var->bits_per_pixel;
563 unsigned int vramlen;
564 unsigned int memlen;
565
Harvey Harrison5ae12172008-04-28 02:15:47 -0700566 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 switch (bpp) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700569 case 4: if (!minfo->capable.cfb4) return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 break;
571 case 8: break;
572 case 16: break;
573 case 24: break;
574 case 32: break;
575 default: return -EINVAL;
576 }
577 *ydstorg = 0;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700578 vramlen = minfo->video.len_usable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 if (var->yres_virtual < var->yres)
580 var->yres_virtual = var->yres;
581 if (var->xres_virtual < var->xres)
582 var->xres_virtual = var->xres;
583
Jean Delvare316b4d62009-09-22 16:47:49 -0700584 var->xres_virtual = matroxfb_pitch_adjust(minfo, var->xres_virtual, bpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 memlen = var->xres_virtual * bpp * var->yres_virtual / 8;
586 if (memlen > vramlen) {
587 var->yres_virtual = vramlen * 8 / (var->xres_virtual * bpp);
588 memlen = var->xres_virtual * bpp * var->yres_virtual / 8;
589 }
590 /* There is hardware bug that no line can cross 4MB boundary */
591 /* give up for CFB24, it is impossible to easy workaround it */
592 /* for other try to do something */
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700593 if (!minfo->capable.cross4MB && (memlen > 0x400000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (bpp == 24) {
595 /* sorry */
596 } else {
597 unsigned int linelen;
598 unsigned int m1 = linelen = var->xres_virtual * bpp / 8;
599 unsigned int m2 = PAGE_SIZE; /* or 128 if you do not need PAGE ALIGNED address */
600 unsigned int max_yres;
601
602 while (m1) {
603 int t;
604
605 while (m2 >= m1) m2 -= m1;
606 t = m1;
607 m1 = m2;
608 m2 = t;
609 }
610 m2 = linelen * PAGE_SIZE / m2;
611 *ydstorg = m2 = 0x400000 % m2;
612 max_yres = (vramlen - m2) / linelen;
613 if (var->yres_virtual > max_yres)
614 var->yres_virtual = max_yres;
615 }
616 }
617 /* YDSTLEN contains only signed 16bit value */
618 if (var->yres_virtual > 32767)
619 var->yres_virtual = 32767;
620 /* we must round yres/xres down, we already rounded y/xres_virtual up
621 if it was possible. We should return -EINVAL, but I disagree */
622 if (var->yres_virtual < var->yres)
623 var->yres = var->yres_virtual;
624 if (var->xres_virtual < var->xres)
625 var->xres = var->xres_virtual;
626 if (var->xoffset + var->xres > var->xres_virtual)
627 var->xoffset = var->xres_virtual - var->xres;
628 if (var->yoffset + var->yres > var->yres_virtual)
629 var->yoffset = var->yres_virtual - var->yres;
630
631 if (bpp == 16 && var->green.length == 5) {
632 bpp--; /* an artifical value - 15 */
633 }
634
635 for (rgbt = table; rgbt->bpp < bpp; rgbt++);
636#define SETCLR(clr)\
637 var->clr.offset = rgbt->clr.offset;\
638 var->clr.length = rgbt->clr.length
639 SETCLR(red);
640 SETCLR(green);
641 SETCLR(blue);
642 SETCLR(transp);
643#undef SETCLR
644 *visual = rgbt->visual;
645
646 if (bpp > 8)
647 dprintk("matroxfb: truecolor: "
648 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
649 var->transp.length, var->red.length, var->green.length, var->blue.length,
650 var->transp.offset, var->red.offset, var->green.offset, var->blue.offset);
651
652 *video_cmap_len = matroxfb_get_cmap_len(var);
653 dprintk(KERN_INFO "requested %d*%d/%dbpp (%d*%d)\n", var->xres, var->yres, var->bits_per_pixel,
654 var->xres_virtual, var->yres_virtual);
655 return 0;
656}
657
658static int matroxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
659 unsigned blue, unsigned transp,
660 struct fb_info *fb_info)
661{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 struct matrox_fb_info* minfo = container_of(fb_info, struct matrox_fb_info, fbcon);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Harvey Harrison5ae12172008-04-28 02:15:47 -0700664 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 /*
667 * Set a single color register. The values supplied are
668 * already rounded down to the hardware's capabilities
669 * (according to the entries in the `var' structure). Return
670 * != 0 for invalid regno.
671 */
672
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700673 if (regno >= minfo->curr.cmap_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 return 1;
675
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700676 if (minfo->fbcon.var.grayscale) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 /* gray = 0.30*R + 0.59*G + 0.11*B */
678 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
679 }
680
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700681 red = CNVT_TOHW(red, minfo->fbcon.var.red.length);
682 green = CNVT_TOHW(green, minfo->fbcon.var.green.length);
683 blue = CNVT_TOHW(blue, minfo->fbcon.var.blue.length);
684 transp = CNVT_TOHW(transp, minfo->fbcon.var.transp.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700686 switch (minfo->fbcon.var.bits_per_pixel) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 case 4:
688 case 8:
689 mga_outb(M_DAC_REG, regno);
690 mga_outb(M_DAC_VAL, red);
691 mga_outb(M_DAC_VAL, green);
692 mga_outb(M_DAC_VAL, blue);
693 break;
694 case 16:
Antonino A. Daplas08a498d2007-07-17 04:05:45 -0700695 if (regno >= 16)
696 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 {
698 u_int16_t col =
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700699 (red << minfo->fbcon.var.red.offset) |
700 (green << minfo->fbcon.var.green.offset) |
701 (blue << minfo->fbcon.var.blue.offset) |
702 (transp << minfo->fbcon.var.transp.offset); /* for 1:5:5:5 */
703 minfo->cmap[regno] = col | (col << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 }
705 break;
706 case 24:
707 case 32:
Antonino A. Daplas08a498d2007-07-17 04:05:45 -0700708 if (regno >= 16)
709 break;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700710 minfo->cmap[regno] =
711 (red << minfo->fbcon.var.red.offset) |
712 (green << minfo->fbcon.var.green.offset) |
713 (blue << minfo->fbcon.var.blue.offset) |
714 (transp << minfo->fbcon.var.transp.offset); /* 8:8:8:8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 break;
716 }
717 return 0;
718}
719
Jean Delvare316b4d62009-09-22 16:47:49 -0700720static void matroxfb_init_fix(struct matrox_fb_info *minfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721{
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700722 struct fb_fix_screeninfo *fix = &minfo->fbcon.fix;
Harvey Harrison5ae12172008-04-28 02:15:47 -0700723 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 strcpy(fix->id,"MATROX");
726
727 fix->xpanstep = 8; /* 8 for 8bpp, 4 for 16bpp, 2 for 32bpp */
728 fix->ypanstep = 1;
729 fix->ywrapstep = 0;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700730 fix->mmio_start = minfo->mmio.base;
731 fix->mmio_len = minfo->mmio.len;
732 fix->accel = minfo->devflags.accelerator;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733}
734
Jean Delvare316b4d62009-09-22 16:47:49 -0700735static void matroxfb_update_fix(struct matrox_fb_info *minfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700737 struct fb_fix_screeninfo *fix = &minfo->fbcon.fix;
Harvey Harrison5ae12172008-04-28 02:15:47 -0700738 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700740 mutex_lock(&minfo->fbcon.mm_lock);
741 fix->smem_start = minfo->video.base + minfo->curr.ydstorg.bytes;
742 fix->smem_len = minfo->video.len_usable - minfo->curr.ydstorg.bytes;
743 mutex_unlock(&minfo->fbcon.mm_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744}
745
746static int matroxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
747{
748 int err;
749 int visual;
750 int cmap_len;
751 unsigned int ydstorg;
752 MINFO_FROM_INFO(info);
753
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700754 if (minfo->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 return -ENXIO;
756 }
Jean Delvare316b4d62009-09-22 16:47:49 -0700757 if ((err = matroxfb_decode_var(minfo, var, &visual, &cmap_len, &ydstorg)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 return err;
759 return 0;
760}
761
762static int matroxfb_set_par(struct fb_info *info)
763{
764 int err;
765 int visual;
766 int cmap_len;
767 unsigned int ydstorg;
768 struct fb_var_screeninfo *var;
769 MINFO_FROM_INFO(info);
770
Harvey Harrison5ae12172008-04-28 02:15:47 -0700771 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700773 if (minfo->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 return -ENXIO;
775 }
776
777 var = &info->var;
Jean Delvare316b4d62009-09-22 16:47:49 -0700778 if ((err = matroxfb_decode_var(minfo, var, &visual, &cmap_len, &ydstorg)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 return err;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700780 minfo->fbcon.screen_base = vaddr_va(minfo->video.vbase) + ydstorg;
Jean Delvare316b4d62009-09-22 16:47:49 -0700781 matroxfb_update_fix(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700782 minfo->fbcon.fix.visual = visual;
783 minfo->fbcon.fix.type = FB_TYPE_PACKED_PIXELS;
784 minfo->fbcon.fix.type_aux = 0;
785 minfo->fbcon.fix.line_length = (var->xres_virtual * var->bits_per_pixel) >> 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 {
787 unsigned int pos;
788
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700789 minfo->curr.cmap_len = cmap_len;
790 ydstorg += minfo->devflags.ydstorg;
791 minfo->curr.ydstorg.bytes = ydstorg;
792 minfo->curr.ydstorg.chunks = ydstorg >> (isInterleave(minfo) ? 3 : 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 if (var->bits_per_pixel == 4)
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700794 minfo->curr.ydstorg.pixels = ydstorg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 else
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700796 minfo->curr.ydstorg.pixels = (ydstorg * 8) / var->bits_per_pixel;
Jean Delvare316b4d62009-09-22 16:47:49 -0700797 minfo->curr.final_bppShift = matroxfb_get_final_bppShift(minfo, var->bits_per_pixel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 { struct my_timming mt;
799 struct matrox_hw_state* hw;
800 int out;
801
802 matroxfb_var2my(var, &mt);
803 mt.crtc = MATROXFB_SRC_CRTC1;
804 /* CRTC1 delays */
805 switch (var->bits_per_pixel) {
806 case 0: mt.delay = 31 + 0; break;
807 case 16: mt.delay = 21 + 8; break;
808 case 24: mt.delay = 17 + 8; break;
809 case 32: mt.delay = 16 + 8; break;
810 default: mt.delay = 31 + 8; break;
811 }
812
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700813 hw = &minfo->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700815 down_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700817 if (minfo->outputs[out].src == MATROXFB_SRC_CRTC1 &&
818 minfo->outputs[out].output->compute) {
819 minfo->outputs[out].output->compute(minfo->outputs[out].data, &mt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 }
821 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700822 up_read(&minfo->altout.lock);
823 minfo->crtc1.pixclock = mt.pixclock;
824 minfo->crtc1.mnp = mt.mnp;
Jean Delvare316b4d62009-09-22 16:47:49 -0700825 minfo->hw_switch->init(minfo, &mt);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700826 pos = (var->yoffset * var->xres_virtual + var->xoffset) * minfo->curr.final_bppShift / 32;
827 pos += minfo->curr.ydstorg.chunks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 hw->CRTC[0x0D] = pos & 0xFF;
830 hw->CRTC[0x0C] = (pos & 0xFF00) >> 8;
831 hw->CRTCEXT[0] = (hw->CRTCEXT[0] & 0xF0) | ((pos >> 16) & 0x0F) | ((pos >> 14) & 0x40);
832 hw->CRTCEXT[8] = pos >> 21;
Jean Delvare316b4d62009-09-22 16:47:49 -0700833 minfo->hw_switch->restore(minfo);
834 update_crtc2(minfo, pos);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700835 down_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700837 if (minfo->outputs[out].src == MATROXFB_SRC_CRTC1 &&
838 minfo->outputs[out].output->program) {
839 minfo->outputs[out].output->program(minfo->outputs[out].data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 }
841 }
842 for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700843 if (minfo->outputs[out].src == MATROXFB_SRC_CRTC1 &&
844 minfo->outputs[out].output->start) {
845 minfo->outputs[out].output->start(minfo->outputs[out].data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 }
847 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700848 up_read(&minfo->altout.lock);
Jean Delvare316b4d62009-09-22 16:47:49 -0700849 matrox_cfbX_init(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 }
851 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700852 minfo->initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 return 0;
854}
855
Jean Delvare316b4d62009-09-22 16:47:49 -0700856static int matroxfb_get_vblank(struct matrox_fb_info *minfo,
857 struct fb_vblank *vblank)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
859 unsigned int sts1;
860
Jean Delvare316b4d62009-09-22 16:47:49 -0700861 matroxfb_enable_irq(minfo, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 memset(vblank, 0, sizeof(*vblank));
863 vblank->flags = FB_VBLANK_HAVE_VCOUNT | FB_VBLANK_HAVE_VSYNC |
864 FB_VBLANK_HAVE_VBLANK | FB_VBLANK_HAVE_HBLANK;
865 sts1 = mga_inb(M_INSTS1);
866 vblank->vcount = mga_inl(M_VCOUNT);
867 /* BTW, on my PIII/450 with G400, reading M_INSTS1
868 byte makes this call about 12% slower (1.70 vs. 2.05 us
869 per ioctl()) */
870 if (sts1 & 1)
871 vblank->flags |= FB_VBLANK_HBLANKING;
872 if (sts1 & 8)
873 vblank->flags |= FB_VBLANK_VSYNCING;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700874 if (vblank->vcount >= minfo->fbcon.var.yres)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 vblank->flags |= FB_VBLANK_VBLANKING;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700876 if (test_bit(0, &minfo->irq_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 vblank->flags |= FB_VBLANK_HAVE_COUNT;
Andrew Mortona50d9132006-06-21 01:57:39 -0300878 /* Only one writer, aligned int value...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 it should work without lock and without atomic_t */
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700880 vblank->count = minfo->crtc1.vsync.cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
882 return 0;
883}
884
885static struct matrox_altout panellink_output = {
886 .name = "Panellink output",
887};
888
Christoph Hellwig67a66802006-01-14 13:21:25 -0800889static int matroxfb_ioctl(struct fb_info *info,
890 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
892 void __user *argp = (void __user *)arg;
893 MINFO_FROM_INFO(info);
Andrew Mortona50d9132006-06-21 01:57:39 -0300894
Harvey Harrison5ae12172008-04-28 02:15:47 -0700895 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700897 if (minfo->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 return -ENXIO;
899 }
900
901 switch (cmd) {
902 case FBIOGET_VBLANK:
903 {
904 struct fb_vblank vblank;
905 int err;
906
Jean Delvare316b4d62009-09-22 16:47:49 -0700907 err = matroxfb_get_vblank(minfo, &vblank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 if (err)
909 return err;
910 if (copy_to_user(argp, &vblank, sizeof(vblank)))
911 return -EFAULT;
912 return 0;
913 }
914 case FBIO_WAITFORVSYNC:
915 {
916 u_int32_t crt;
917
918 if (get_user(crt, (u_int32_t __user *)arg))
919 return -EFAULT;
920
Jean Delvare316b4d62009-09-22 16:47:49 -0700921 return matroxfb_wait_for_sync(minfo, crt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 }
923 case MATROXFB_SET_OUTPUT_MODE:
924 {
925 struct matroxioc_output_mode mom;
926 struct matrox_altout *oproc;
927 int val;
928
929 if (copy_from_user(&mom, argp, sizeof(mom)))
930 return -EFAULT;
931 if (mom.output >= MATROXFB_MAX_OUTPUTS)
932 return -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700933 down_read(&minfo->altout.lock);
934 oproc = minfo->outputs[mom.output].output;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 if (!oproc) {
936 val = -ENXIO;
937 } else if (!oproc->verifymode) {
938 if (mom.mode == MATROXFB_OUTPUT_MODE_MONITOR) {
939 val = 0;
940 } else {
941 val = -EINVAL;
942 }
943 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700944 val = oproc->verifymode(minfo->outputs[mom.output].data, mom.mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 }
946 if (!val) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700947 if (minfo->outputs[mom.output].mode != mom.mode) {
948 minfo->outputs[mom.output].mode = mom.mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 val = 1;
950 }
951 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700952 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 if (val != 1)
954 return val;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700955 switch (minfo->outputs[mom.output].src) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 case MATROXFB_SRC_CRTC1:
957 matroxfb_set_par(info);
958 break;
959 case MATROXFB_SRC_CRTC2:
960 {
961 struct matroxfb_dh_fb_info* crtc2;
962
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700963 down_read(&minfo->crtc2.lock);
964 crtc2 = minfo->crtc2.info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 if (crtc2)
966 crtc2->fbcon.fbops->fb_set_par(&crtc2->fbcon);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700967 up_read(&minfo->crtc2.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 }
969 break;
970 }
971 return 0;
972 }
973 case MATROXFB_GET_OUTPUT_MODE:
974 {
975 struct matroxioc_output_mode mom;
976 struct matrox_altout *oproc;
977 int val;
978
979 if (copy_from_user(&mom, argp, sizeof(mom)))
980 return -EFAULT;
981 if (mom.output >= MATROXFB_MAX_OUTPUTS)
982 return -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700983 down_read(&minfo->altout.lock);
984 oproc = minfo->outputs[mom.output].output;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 if (!oproc) {
986 val = -ENXIO;
987 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700988 mom.mode = minfo->outputs[mom.output].mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 val = 0;
990 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700991 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 if (val)
993 return val;
994 if (copy_to_user(argp, &mom, sizeof(mom)))
995 return -EFAULT;
996 return 0;
997 }
998 case MATROXFB_SET_OUTPUT_CONNECTION:
999 {
1000 u_int32_t tmp;
1001 int i;
1002 int changes;
1003
1004 if (copy_from_user(&tmp, argp, sizeof(tmp)))
1005 return -EFAULT;
1006 for (i = 0; i < 32; i++) {
1007 if (tmp & (1 << i)) {
1008 if (i >= MATROXFB_MAX_OUTPUTS)
1009 return -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001010 if (!minfo->outputs[i].output)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 return -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001012 switch (minfo->outputs[i].src) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 case MATROXFB_SRC_NONE:
1014 case MATROXFB_SRC_CRTC1:
1015 break;
1016 default:
1017 return -EBUSY;
1018 }
1019 }
1020 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001021 if (minfo->devflags.panellink) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (tmp & MATROXFB_OUTPUT_CONN_DFP) {
1023 if (tmp & MATROXFB_OUTPUT_CONN_SECONDARY)
1024 return -EINVAL;
1025 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001026 if (minfo->outputs[i].src == MATROXFB_SRC_CRTC2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 return -EBUSY;
1028 }
1029 }
1030 }
1031 }
1032 changes = 0;
1033 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
1034 if (tmp & (1 << i)) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001035 if (minfo->outputs[i].src != MATROXFB_SRC_CRTC1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 changes = 1;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001037 minfo->outputs[i].src = MATROXFB_SRC_CRTC1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001039 } else if (minfo->outputs[i].src == MATROXFB_SRC_CRTC1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 changes = 1;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001041 minfo->outputs[i].src = MATROXFB_SRC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043 }
1044 if (!changes)
1045 return 0;
1046 matroxfb_set_par(info);
1047 return 0;
1048 }
1049 case MATROXFB_GET_OUTPUT_CONNECTION:
1050 {
1051 u_int32_t conn = 0;
1052 int i;
1053
1054 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001055 if (minfo->outputs[i].src == MATROXFB_SRC_CRTC1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 conn |= 1 << i;
1057 }
1058 }
1059 if (put_user(conn, (u_int32_t __user *)arg))
1060 return -EFAULT;
1061 return 0;
1062 }
1063 case MATROXFB_GET_AVAILABLE_OUTPUTS:
1064 {
1065 u_int32_t conn = 0;
1066 int i;
1067
1068 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001069 if (minfo->outputs[i].output) {
1070 switch (minfo->outputs[i].src) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 case MATROXFB_SRC_NONE:
1072 case MATROXFB_SRC_CRTC1:
1073 conn |= 1 << i;
1074 break;
1075 }
1076 }
1077 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001078 if (minfo->devflags.panellink) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 if (conn & MATROXFB_OUTPUT_CONN_DFP)
1080 conn &= ~MATROXFB_OUTPUT_CONN_SECONDARY;
1081 if (conn & MATROXFB_OUTPUT_CONN_SECONDARY)
1082 conn &= ~MATROXFB_OUTPUT_CONN_DFP;
1083 }
1084 if (put_user(conn, (u_int32_t __user *)arg))
1085 return -EFAULT;
1086 return 0;
1087 }
1088 case MATROXFB_GET_ALL_OUTPUTS:
1089 {
1090 u_int32_t conn = 0;
1091 int i;
1092
1093 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001094 if (minfo->outputs[i].output) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 conn |= 1 << i;
1096 }
1097 }
1098 if (put_user(conn, (u_int32_t __user *)arg))
1099 return -EFAULT;
1100 return 0;
1101 }
1102 case VIDIOC_QUERYCAP:
1103 {
1104 struct v4l2_capability r;
Andrew Mortona50d9132006-06-21 01:57:39 -03001105
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 memset(&r, 0, sizeof(r));
1107 strcpy(r.driver, "matroxfb");
1108 strcpy(r.card, "Matrox");
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001109 sprintf(r.bus_info, "PCI:%s", pci_name(minfo->pcidev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 r.version = KERNEL_VERSION(1,0,0);
1111 r.capabilities = V4L2_CAP_VIDEO_OUTPUT;
1112 if (copy_to_user(argp, &r, sizeof(r)))
1113 return -EFAULT;
1114 return 0;
Andrew Mortona50d9132006-06-21 01:57:39 -03001115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 }
1117 case VIDIOC_QUERYCTRL:
1118 {
1119 struct v4l2_queryctrl qctrl;
1120 int err;
1121
1122 if (copy_from_user(&qctrl, argp, sizeof(qctrl)))
1123 return -EFAULT;
1124
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001125 down_read(&minfo->altout.lock);
1126 if (!minfo->outputs[1].output) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 err = -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001128 } else if (minfo->outputs[1].output->getqueryctrl) {
1129 err = minfo->outputs[1].output->getqueryctrl(minfo->outputs[1].data, &qctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 } else {
1131 err = -EINVAL;
1132 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001133 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 if (err >= 0 &&
1135 copy_to_user(argp, &qctrl, sizeof(qctrl)))
1136 return -EFAULT;
1137 return err;
1138 }
1139 case VIDIOC_G_CTRL:
1140 {
1141 struct v4l2_control ctrl;
1142 int err;
1143
1144 if (copy_from_user(&ctrl, argp, sizeof(ctrl)))
1145 return -EFAULT;
1146
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001147 down_read(&minfo->altout.lock);
1148 if (!minfo->outputs[1].output) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 err = -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001150 } else if (minfo->outputs[1].output->getctrl) {
1151 err = minfo->outputs[1].output->getctrl(minfo->outputs[1].data, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 } else {
1153 err = -EINVAL;
1154 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001155 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 if (err >= 0 &&
1157 copy_to_user(argp, &ctrl, sizeof(ctrl)))
1158 return -EFAULT;
1159 return err;
1160 }
1161 case VIDIOC_S_CTRL_OLD:
1162 case VIDIOC_S_CTRL:
1163 {
1164 struct v4l2_control ctrl;
1165 int err;
1166
1167 if (copy_from_user(&ctrl, argp, sizeof(ctrl)))
1168 return -EFAULT;
1169
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001170 down_read(&minfo->altout.lock);
1171 if (!minfo->outputs[1].output) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 err = -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001173 } else if (minfo->outputs[1].output->setctrl) {
1174 err = minfo->outputs[1].output->setctrl(minfo->outputs[1].data, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 } else {
1176 err = -EINVAL;
1177 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001178 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 return err;
1180 }
1181 }
1182 return -ENOTTY;
1183}
1184
1185/* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
1186
1187static int matroxfb_blank(int blank, struct fb_info *info)
1188{
1189 int seq;
1190 int crtc;
1191 CRITFLAGS
1192 MINFO_FROM_INFO(info);
1193
Harvey Harrison5ae12172008-04-28 02:15:47 -07001194 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001196 if (minfo->dead)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 return 1;
1198
1199 switch (blank) {
1200 case FB_BLANK_NORMAL: seq = 0x20; crtc = 0x00; break; /* works ??? */
1201 case FB_BLANK_VSYNC_SUSPEND: seq = 0x20; crtc = 0x10; break;
1202 case FB_BLANK_HSYNC_SUSPEND: seq = 0x20; crtc = 0x20; break;
1203 case FB_BLANK_POWERDOWN: seq = 0x20; crtc = 0x30; break;
1204 default: seq = 0x00; crtc = 0x00; break;
1205 }
1206
1207 CRITBEGIN
1208
1209 mga_outb(M_SEQ_INDEX, 1);
1210 mga_outb(M_SEQ_DATA, (mga_inb(M_SEQ_DATA) & ~0x20) | seq);
1211 mga_outb(M_EXTVGA_INDEX, 1);
1212 mga_outb(M_EXTVGA_DATA, (mga_inb(M_EXTVGA_DATA) & ~0x30) | crtc);
1213
1214 CRITEND
1215 return 0;
1216}
1217
1218static struct fb_ops matroxfb_ops = {
1219 .owner = THIS_MODULE,
1220 .fb_open = matroxfb_open,
1221 .fb_release = matroxfb_release,
1222 .fb_check_var = matroxfb_check_var,
1223 .fb_set_par = matroxfb_set_par,
1224 .fb_setcolreg = matroxfb_setcolreg,
1225 .fb_pan_display =matroxfb_pan_display,
1226 .fb_blank = matroxfb_blank,
1227 .fb_ioctl = matroxfb_ioctl,
1228/* .fb_fillrect = <set by matrox_cfbX_init>, */
1229/* .fb_copyarea = <set by matrox_cfbX_init>, */
1230/* .fb_imageblit = <set by matrox_cfbX_init>, */
1231/* .fb_cursor = <set by matrox_cfbX_init>, */
1232};
1233
1234#define RSDepth(X) (((X) >> 8) & 0x0F)
1235#define RS8bpp 0x1
1236#define RS15bpp 0x2
1237#define RS16bpp 0x3
1238#define RS32bpp 0x4
1239#define RS4bpp 0x5
1240#define RS24bpp 0x6
1241#define RSText 0x7
1242#define RSText8 0x8
1243/* 9-F */
1244static struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
1245 { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 8 },
1246 { { 10, 5, 0}, { 5, 5, 0}, { 0, 5, 0}, { 15, 1, 0}, 16 },
1247 { { 11, 5, 0}, { 5, 6, 0}, { 0, 5, 0}, { 0, 0, 0}, 16 },
1248 { { 16, 8, 0}, { 8, 8, 0}, { 0, 8, 0}, { 24, 8, 0}, 32 },
1249 { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 4 },
1250 { { 16, 8, 0}, { 8, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 24 },
1251 { { 0, 6, 0}, { 0, 6, 0}, { 0, 6, 0}, { 0, 0, 0}, 0 }, /* textmode with (default) VGA8x16 */
1252 { { 0, 6, 0}, { 0, 6, 0}, { 0, 6, 0}, { 0, 0, 0}, 0 }, /* textmode hardwired to VGA8x8 */
1253};
1254
1255/* initialized by setup, see explanation at end of file (search for MODULE_PARM_DESC) */
1256static unsigned int mem; /* "matrox:mem:xxxxxM" */
1257static int option_precise_width = 1; /* cannot be changed, option_precise_width==0 must imply noaccel */
1258static int inv24; /* "matrox:inv24" */
1259static int cross4MB = -1; /* "matrox:cross4MB" */
1260static int disabled; /* "matrox:disabled" */
1261static int noaccel; /* "matrox:noaccel" */
1262static int nopan; /* "matrox:nopan" */
1263static int no_pci_retry; /* "matrox:nopciretry" */
1264static int novga; /* "matrox:novga" */
1265static int nobios; /* "matrox:nobios" */
1266static int noinit = 1; /* "matrox:init" */
1267static int inverse; /* "matrox:inverse" */
1268static int sgram; /* "matrox:sgram" */
1269#ifdef CONFIG_MTRR
1270static int mtrr = 1; /* "matrox:nomtrr" */
1271#endif
1272static int grayscale; /* "matrox:grayscale" */
1273static int dev = -1; /* "matrox:dev:xxxxx" */
1274static unsigned int vesa = ~0; /* "matrox:vesa:xxxxx" */
1275static int depth = -1; /* "matrox:depth:xxxxx" */
1276static unsigned int xres; /* "matrox:xres:xxxxx" */
1277static unsigned int yres; /* "matrox:yres:xxxxx" */
1278static unsigned int upper = ~0; /* "matrox:upper:xxxxx" */
1279static unsigned int lower = ~0; /* "matrox:lower:xxxxx" */
1280static unsigned int vslen; /* "matrox:vslen:xxxxx" */
1281static unsigned int left = ~0; /* "matrox:left:xxxxx" */
1282static unsigned int right = ~0; /* "matrox:right:xxxxx" */
1283static unsigned int hslen; /* "matrox:hslen:xxxxx" */
1284static unsigned int pixclock; /* "matrox:pixclock:xxxxx" */
1285static int sync = -1; /* "matrox:sync:xxxxx" */
1286static unsigned int fv; /* "matrox:fv:xxxxx" */
1287static unsigned int fh; /* "matrox:fh:xxxxxk" */
1288static unsigned int maxclk; /* "matrox:maxclk:xxxxM" */
1289static int dfp; /* "matrox:dfp */
1290static int dfp_type = -1; /* "matrox:dfp:xxx */
1291static int memtype = -1; /* "matrox:memtype:xxx" */
1292static char outputs[8]; /* "matrox:outputs:xxx" */
1293
1294#ifndef MODULE
1295static char videomode[64]; /* "matrox:mode:xxxxx" or "matrox:xxxxx" */
1296#endif
1297
Jean Delvare316b4d62009-09-22 16:47:49 -07001298static int matroxfb_getmemory(struct matrox_fb_info *minfo,
1299 unsigned int maxSize, unsigned int *realSize)
1300{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 vaddr_t vm;
1302 unsigned int offs;
1303 unsigned int offs2;
Ville Syrjälä6c12f302005-11-07 01:00:58 -08001304 unsigned char orig;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 unsigned char bytes[32];
1306 unsigned char* tmp;
1307
Harvey Harrison5ae12172008-04-28 02:15:47 -07001308 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001310 vm = minfo->video.vbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 maxSize &= ~0x1FFFFF; /* must be X*2MB (really it must be 2 or X*4MB) */
1312 /* at least 2MB */
1313 if (maxSize < 0x0200000) return 0;
1314 if (maxSize > 0x2000000) maxSize = 0x2000000;
1315
1316 mga_outb(M_EXTVGA_INDEX, 0x03);
Jan Beulich438e5c52005-09-13 01:25:45 -07001317 orig = mga_inb(M_EXTVGA_DATA);
1318 mga_outb(M_EXTVGA_DATA, orig | 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 tmp = bytes;
1321 for (offs = 0x100000; offs < maxSize; offs += 0x200000)
1322 *tmp++ = mga_readb(vm, offs);
1323 for (offs = 0x100000; offs < maxSize; offs += 0x200000)
1324 mga_writeb(vm, offs, 0x02);
Ville Syrjälä6c12f302005-11-07 01:00:58 -08001325 mga_outb(M_CACHEFLUSH, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 for (offs = 0x100000; offs < maxSize; offs += 0x200000) {
1327 if (mga_readb(vm, offs) != 0x02)
1328 break;
1329 mga_writeb(vm, offs, mga_readb(vm, offs) - 0x02);
1330 if (mga_readb(vm, offs))
1331 break;
1332 }
1333 tmp = bytes;
1334 for (offs2 = 0x100000; offs2 < maxSize; offs2 += 0x200000)
1335 mga_writeb(vm, offs2, *tmp++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
1337 mga_outb(M_EXTVGA_INDEX, 0x03);
Jan Beulich438e5c52005-09-13 01:25:45 -07001338 mga_outb(M_EXTVGA_DATA, orig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
1340 *realSize = offs - 0x100000;
1341#ifdef CONFIG_FB_MATROX_MILLENIUM
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001342 minfo->interleave = !(!isMillenium(minfo) || ((offs - 0x100000) & 0x3FFFFF));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343#endif
1344 return 1;
1345}
1346
1347struct video_board {
1348 int maxvram;
1349 int maxdisplayable;
1350 int accelID;
1351 struct matrox_switch* lowlevel;
1352 };
1353#ifdef CONFIG_FB_MATROX_MILLENIUM
1354static struct video_board vbMillennium = {0x0800000, 0x0800000, FB_ACCEL_MATROX_MGA2064W, &matrox_millennium};
1355static struct video_board vbMillennium2 = {0x1000000, 0x0800000, FB_ACCEL_MATROX_MGA2164W, &matrox_millennium};
1356static struct video_board vbMillennium2A = {0x1000000, 0x0800000, FB_ACCEL_MATROX_MGA2164W_AGP, &matrox_millennium};
1357#endif /* CONFIG_FB_MATROX_MILLENIUM */
1358#ifdef CONFIG_FB_MATROX_MYSTIQUE
1359static struct video_board vbMystique = {0x0800000, 0x0800000, FB_ACCEL_MATROX_MGA1064SG, &matrox_mystique};
1360#endif /* CONFIG_FB_MATROX_MYSTIQUE */
1361#ifdef CONFIG_FB_MATROX_G
1362static struct video_board vbG100 = {0x0800000, 0x0800000, FB_ACCEL_MATROX_MGAG100, &matrox_G100};
1363static struct video_board vbG200 = {0x1000000, 0x1000000, FB_ACCEL_MATROX_MGAG200, &matrox_G100};
1364#ifdef CONFIG_FB_MATROX_32MB
1365/* from doc it looks like that accelerator can draw only to low 16MB :-( Direct accesses & displaying are OK for
1366 whole 32MB */
1367static struct video_board vbG400 = {0x2000000, 0x1000000, FB_ACCEL_MATROX_MGAG400, &matrox_G100};
1368#else
1369static struct video_board vbG400 = {0x2000000, 0x1000000, FB_ACCEL_MATROX_MGAG400, &matrox_G100};
1370#endif
1371#endif
1372
1373#define DEVF_VIDEO64BIT 0x0001
1374#define DEVF_SWAPS 0x0002
1375#define DEVF_SRCORG 0x0004
1376#define DEVF_DUALHEAD 0x0008
1377#define DEVF_CROSS4MB 0x0010
1378#define DEVF_TEXT4B 0x0020
1379/* #define DEVF_recycled 0x0040 */
1380/* #define DEVF_recycled 0x0080 */
1381#define DEVF_SUPPORT32MB 0x0100
1382#define DEVF_ANY_VXRES 0x0200
1383#define DEVF_TEXT16B 0x0400
1384#define DEVF_CRTC2 0x0800
1385#define DEVF_MAVEN_CAPABLE 0x1000
1386#define DEVF_PANELLINK_CAPABLE 0x2000
1387#define DEVF_G450DAC 0x4000
1388
1389#define DEVF_GCORE (DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB)
1390#define DEVF_G2CORE (DEVF_GCORE | DEVF_ANY_VXRES | DEVF_MAVEN_CAPABLE | DEVF_PANELLINK_CAPABLE | DEVF_SRCORG | DEVF_DUALHEAD)
1391#define DEVF_G100 (DEVF_GCORE) /* no doc, no vxres... */
1392#define DEVF_G200 (DEVF_G2CORE)
1393#define DEVF_G400 (DEVF_G2CORE | DEVF_SUPPORT32MB | DEVF_TEXT16B | DEVF_CRTC2)
1394/* if you'll find how to drive DFP... */
1395#define DEVF_G450 (DEVF_GCORE | DEVF_ANY_VXRES | DEVF_SUPPORT32MB | DEVF_TEXT16B | DEVF_CRTC2 | DEVF_G450DAC | DEVF_SRCORG | DEVF_DUALHEAD)
1396#define DEVF_G550 (DEVF_G450)
1397
1398static struct board {
1399 unsigned short vendor, device, rev, svid, sid;
1400 unsigned int flags;
1401 unsigned int maxclk;
1402 enum mga_chip chip;
1403 struct video_board* base;
1404 const char* name;
1405 } dev_list[] = {
1406#ifdef CONFIG_FB_MATROX_MILLENIUM
1407 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL, 0xFF,
1408 0, 0,
1409 DEVF_TEXT4B,
1410 230000,
1411 MGA_2064,
1412 &vbMillennium,
1413 "Millennium (PCI)"},
1414 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2, 0xFF,
1415 0, 0,
1416 DEVF_SWAPS,
1417 220000,
1418 MGA_2164,
1419 &vbMillennium2,
1420 "Millennium II (PCI)"},
1421 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2_AGP, 0xFF,
1422 0, 0,
1423 DEVF_SWAPS,
1424 250000,
1425 MGA_2164,
1426 &vbMillennium2A,
1427 "Millennium II (AGP)"},
1428#endif
1429#ifdef CONFIG_FB_MATROX_MYSTIQUE
1430 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS, 0x02,
1431 0, 0,
1432 DEVF_VIDEO64BIT | DEVF_CROSS4MB,
1433 180000,
1434 MGA_1064,
1435 &vbMystique,
1436 "Mystique (PCI)"},
1437 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS, 0xFF,
1438 0, 0,
1439 DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB,
1440 220000,
1441 MGA_1164,
1442 &vbMystique,
1443 "Mystique 220 (PCI)"},
Ville Syrjälä63921fb2005-11-07 01:00:57 -08001444 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS_AGP, 0x02,
1445 0, 0,
1446 DEVF_VIDEO64BIT | DEVF_CROSS4MB,
1447 180000,
1448 MGA_1064,
1449 &vbMystique,
1450 "Mystique (AGP)"},
1451 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS_AGP, 0xFF,
1452 0, 0,
1453 DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB,
1454 220000,
1455 MGA_1164,
1456 &vbMystique,
1457 "Mystique 220 (AGP)"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458#endif
1459#ifdef CONFIG_FB_MATROX_G
1460 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_MM, 0xFF,
1461 0, 0,
1462 DEVF_G100,
1463 230000,
1464 MGA_G100,
1465 &vbG100,
1466 "MGA-G100 (PCI)"},
1467 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_AGP, 0xFF,
1468 0, 0,
1469 DEVF_G100,
1470 230000,
1471 MGA_G100,
1472 &vbG100,
1473 "MGA-G100 (AGP)"},
Darrick J. Wonge3a19382008-10-15 22:03:52 -07001474 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200EV_PCI, 0xFF,
1475 0, 0,
1476 DEVF_G200,
1477 230000,
1478 MGA_G200,
1479 &vbG200,
1480 "MGA-G200eV (PCI)"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, 0xFF,
1482 0, 0,
1483 DEVF_G200,
1484 250000,
1485 MGA_G200,
1486 &vbG200,
1487 "MGA-G200 (PCI)"},
1488 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1489 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_GENERIC,
1490 DEVF_G200,
1491 220000,
1492 MGA_G200,
1493 &vbG200,
1494 "MGA-G200 (AGP)"},
1495 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1496 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MYSTIQUE_G200_AGP,
1497 DEVF_G200,
1498 230000,
1499 MGA_G200,
1500 &vbG200,
1501 "Mystique G200 (AGP)"},
1502 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1503 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MILLENIUM_G200_AGP,
1504 DEVF_G200,
1505 250000,
1506 MGA_G200,
1507 &vbG200,
1508 "Millennium G200 (AGP)"},
1509 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1510 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MARVEL_G200_AGP,
1511 DEVF_G200,
1512 230000,
1513 MGA_G200,
1514 &vbG200,
1515 "Marvel G200 (AGP)"},
1516 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1517 PCI_SS_VENDOR_ID_SIEMENS_NIXDORF, PCI_SS_ID_SIEMENS_MGA_G200_AGP,
1518 DEVF_G200,
1519 230000,
1520 MGA_G200,
1521 &vbG200,
1522 "MGA-G200 (AGP)"},
1523 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1524 0, 0,
1525 DEVF_G200,
1526 230000,
1527 MGA_G200,
1528 &vbG200,
1529 "G200 (AGP)"},
1530 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, 0x80,
1531 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MILLENNIUM_G400_MAX_AGP,
1532 DEVF_G400,
1533 360000,
1534 MGA_G400,
1535 &vbG400,
1536 "Millennium G400 MAX (AGP)"},
1537 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, 0x80,
1538 0, 0,
1539 DEVF_G400,
1540 300000,
1541 MGA_G400,
1542 &vbG400,
1543 "G400 (AGP)"},
1544 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, 0xFF,
1545 0, 0,
1546 DEVF_G450,
1547 360000,
1548 MGA_G450,
1549 &vbG400,
1550 "G450"},
1551 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G550, 0xFF,
1552 0, 0,
1553 DEVF_G550,
1554 360000,
1555 MGA_G550,
1556 &vbG400,
1557 "G550"},
1558#endif
1559 {0, 0, 0xFF,
1560 0, 0,
1561 0,
1562 0,
1563 0,
1564 NULL,
1565 NULL}};
1566
1567#ifndef MODULE
1568static struct fb_videomode defaultmode = {
1569 /* 640x480 @ 60Hz, 31.5 kHz */
1570 NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
1571 0, FB_VMODE_NONINTERLACED
1572};
1573#endif /* !MODULE */
1574
1575static int hotplug = 0;
1576
Jean Delvare316b4d62009-09-22 16:47:49 -07001577static void setDefaultOutputs(struct matrox_fb_info *minfo)
1578{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 unsigned int i;
1580 const char* ptr;
1581
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001582 minfo->outputs[0].default_src = MATROXFB_SRC_CRTC1;
1583 if (minfo->devflags.g450dac) {
1584 minfo->outputs[1].default_src = MATROXFB_SRC_CRTC1;
1585 minfo->outputs[2].default_src = MATROXFB_SRC_CRTC1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 } else if (dfp) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001587 minfo->outputs[2].default_src = MATROXFB_SRC_CRTC1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 }
1589 ptr = outputs;
1590 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
1591 char c = *ptr++;
1592
1593 if (c == 0) {
1594 break;
1595 }
1596 if (c == '0') {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001597 minfo->outputs[i].default_src = MATROXFB_SRC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 } else if (c == '1') {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001599 minfo->outputs[i].default_src = MATROXFB_SRC_CRTC1;
1600 } else if (c == '2' && minfo->devflags.crtc2) {
1601 minfo->outputs[i].default_src = MATROXFB_SRC_CRTC2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 } else {
1603 printk(KERN_ERR "matroxfb: Unknown outputs setting\n");
1604 break;
1605 }
1606 }
1607 /* Nullify this option for subsequent adapters */
1608 outputs[0] = 0;
1609}
1610
Jean Delvare316b4d62009-09-22 16:47:49 -07001611static int initMatrox2(struct matrox_fb_info *minfo, struct board *b)
1612{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 unsigned long ctrlptr_phys = 0;
1614 unsigned long video_base_phys = 0;
1615 unsigned int memsize;
1616 int err;
1617
1618 static struct pci_device_id intel_82437[] = {
1619 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437) },
1620 { },
1621 };
1622
Harvey Harrison5ae12172008-04-28 02:15:47 -07001623 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625 /* set default values... */
1626 vesafb_defined.accel_flags = FB_ACCELF_TEXT;
1627
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001628 minfo->hw_switch = b->base->lowlevel;
1629 minfo->devflags.accelerator = b->base->accelID;
1630 minfo->max_pixel_clock = b->maxclk;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
1632 printk(KERN_INFO "matroxfb: Matrox %s detected\n", b->name);
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001633 minfo->capable.plnwt = 1;
1634 minfo->chip = b->chip;
1635 minfo->capable.srcorg = b->flags & DEVF_SRCORG;
1636 minfo->devflags.video64bits = b->flags & DEVF_VIDEO64BIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 if (b->flags & DEVF_TEXT4B) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001638 minfo->devflags.vgastep = 4;
1639 minfo->devflags.textmode = 4;
1640 minfo->devflags.text_type_aux = FB_AUX_TEXT_MGA_STEP16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 } else if (b->flags & DEVF_TEXT16B) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001642 minfo->devflags.vgastep = 16;
1643 minfo->devflags.textmode = 1;
1644 minfo->devflags.text_type_aux = FB_AUX_TEXT_MGA_STEP16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001646 minfo->devflags.vgastep = 8;
1647 minfo->devflags.textmode = 1;
1648 minfo->devflags.text_type_aux = FB_AUX_TEXT_MGA_STEP8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 }
1650#ifdef CONFIG_FB_MATROX_32MB
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001651 minfo->devflags.support32MB = (b->flags & DEVF_SUPPORT32MB) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652#endif
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001653 minfo->devflags.precise_width = !(b->flags & DEVF_ANY_VXRES);
1654 minfo->devflags.crtc2 = (b->flags & DEVF_CRTC2) != 0;
1655 minfo->devflags.maven_capable = (b->flags & DEVF_MAVEN_CAPABLE) != 0;
1656 minfo->devflags.dualhead = (b->flags & DEVF_DUALHEAD) != 0;
1657 minfo->devflags.dfp_type = dfp_type;
1658 minfo->devflags.g450dac = (b->flags & DEVF_G450DAC) != 0;
1659 minfo->devflags.textstep = minfo->devflags.vgastep * minfo->devflags.textmode;
1660 minfo->devflags.textvram = 65536 / minfo->devflags.textmode;
Jean Delvare316b4d62009-09-22 16:47:49 -07001661 setDefaultOutputs(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 if (b->flags & DEVF_PANELLINK_CAPABLE) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001663 minfo->outputs[2].data = minfo;
1664 minfo->outputs[2].output = &panellink_output;
1665 minfo->outputs[2].src = minfo->outputs[2].default_src;
1666 minfo->outputs[2].mode = MATROXFB_OUTPUT_MODE_MONITOR;
1667 minfo->devflags.panellink = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 }
1669
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001670 if (minfo->capable.cross4MB < 0)
1671 minfo->capable.cross4MB = b->flags & DEVF_CROSS4MB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 if (b->flags & DEVF_SWAPS) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001673 ctrlptr_phys = pci_resource_start(minfo->pcidev, 1);
1674 video_base_phys = pci_resource_start(minfo->pcidev, 0);
1675 minfo->devflags.fbResource = PCI_BASE_ADDRESS_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001677 ctrlptr_phys = pci_resource_start(minfo->pcidev, 0);
1678 video_base_phys = pci_resource_start(minfo->pcidev, 1);
1679 minfo->devflags.fbResource = PCI_BASE_ADDRESS_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 }
1681 err = -EINVAL;
1682 if (!ctrlptr_phys) {
1683 printk(KERN_ERR "matroxfb: control registers are not available, matroxfb disabled\n");
1684 goto fail;
1685 }
1686 if (!video_base_phys) {
1687 printk(KERN_ERR "matroxfb: video RAM is not available in PCI address space, matroxfb disabled\n");
1688 goto fail;
1689 }
1690 memsize = b->base->maxvram;
1691 if (!request_mem_region(ctrlptr_phys, 16384, "matroxfb MMIO")) {
1692 goto fail;
1693 }
1694 if (!request_mem_region(video_base_phys, memsize, "matroxfb FB")) {
1695 goto failCtrlMR;
1696 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001697 minfo->video.len_maximum = memsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 /* convert mem (autodetect k, M) */
1699 if (mem < 1024) mem *= 1024;
1700 if (mem < 0x00100000) mem *= 1024;
1701
1702 if (mem && (mem < memsize))
1703 memsize = mem;
1704 err = -ENOMEM;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001705 if (mga_ioremap(ctrlptr_phys, 16384, MGA_IOREMAP_MMIO, &minfo->mmio.vbase)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 printk(KERN_ERR "matroxfb: cannot ioremap(%lX, 16384), matroxfb disabled\n", ctrlptr_phys);
1707 goto failVideoMR;
1708 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001709 minfo->mmio.base = ctrlptr_phys;
1710 minfo->mmio.len = 16384;
1711 minfo->video.base = video_base_phys;
1712 if (mga_ioremap(video_base_phys, memsize, MGA_IOREMAP_FB, &minfo->video.vbase)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 printk(KERN_ERR "matroxfb: cannot ioremap(%lX, %d), matroxfb disabled\n",
1714 video_base_phys, memsize);
1715 goto failCtrlIO;
1716 }
1717 {
1718 u_int32_t cmd;
1719 u_int32_t mga_option;
1720
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001721 pci_read_config_dword(minfo->pcidev, PCI_OPTION_REG, &mga_option);
1722 pci_read_config_dword(minfo->pcidev, PCI_COMMAND, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 mga_option &= 0x7FFFFFFF; /* clear BIG_ENDIAN */
1724 mga_option |= MX_OPTION_BSWAP;
Andrew Mortona50d9132006-06-21 01:57:39 -03001725 /* disable palette snooping */
1726 cmd &= ~PCI_COMMAND_VGA_PALETTE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 if (pci_dev_present(intel_82437)) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001728 if (!(mga_option & 0x20000000) && !minfo->devflags.nopciretry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 printk(KERN_WARNING "matroxfb: Disabling PCI retries due to i82437 present\n");
1730 }
1731 mga_option |= 0x20000000;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001732 minfo->devflags.nopciretry = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001734 pci_write_config_dword(minfo->pcidev, PCI_COMMAND, cmd);
1735 pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, mga_option);
1736 minfo->hw.MXoptionReg = mga_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738 /* select non-DMA memory for PCI_MGA_DATA, otherwise dump of PCI cfg space can lock PCI bus */
1739 /* maybe preinit() candidate, but it is same... for all devices... at this time... */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001740 pci_write_config_dword(minfo->pcidev, PCI_MGA_INDEX, 0x00003C00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 }
1742
1743 err = -ENXIO;
Jean Delvare316b4d62009-09-22 16:47:49 -07001744 matroxfb_read_pins(minfo);
1745 if (minfo->hw_switch->preinit(minfo)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 goto failVideoIO;
1747 }
1748
1749 err = -ENOMEM;
Jean Delvare316b4d62009-09-22 16:47:49 -07001750 if (!matroxfb_getmemory(minfo, memsize, &minfo->video.len) || !minfo->video.len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 printk(KERN_ERR "matroxfb: cannot determine memory size\n");
1752 goto failVideoIO;
1753 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001754 minfo->devflags.ydstorg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001756 minfo->video.base = video_base_phys;
1757 minfo->video.len_usable = minfo->video.len;
1758 if (minfo->video.len_usable > b->base->maxdisplayable)
1759 minfo->video.len_usable = b->base->maxdisplayable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760#ifdef CONFIG_MTRR
1761 if (mtrr) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001762 minfo->mtrr.vram = mtrr_add(video_base_phys, minfo->video.len, MTRR_TYPE_WRCOMB, 1);
1763 minfo->mtrr.vram_valid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 printk(KERN_INFO "matroxfb: MTRR's turned on\n");
1765 }
1766#endif /* CONFIG_MTRR */
1767
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001768 if (!minfo->devflags.novga)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 request_region(0x3C0, 32, "matrox");
Jean Delvare316b4d62009-09-22 16:47:49 -07001770 matroxfb_g450_connect(minfo);
1771 minfo->hw_switch->reset(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001773 minfo->fbcon.monspecs.hfmin = 0;
1774 minfo->fbcon.monspecs.hfmax = fh;
1775 minfo->fbcon.monspecs.vfmin = 0;
1776 minfo->fbcon.monspecs.vfmax = fv;
1777 minfo->fbcon.monspecs.dpms = 0; /* TBD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
1779 /* static settings */
1780 vesafb_defined.red = colors[depth-1].red;
1781 vesafb_defined.green = colors[depth-1].green;
1782 vesafb_defined.blue = colors[depth-1].blue;
1783 vesafb_defined.bits_per_pixel = colors[depth-1].bits_per_pixel;
1784 vesafb_defined.grayscale = grayscale;
1785 vesafb_defined.vmode = 0;
1786 if (noaccel)
1787 vesafb_defined.accel_flags &= ~FB_ACCELF_TEXT;
1788
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001789 minfo->fbops = matroxfb_ops;
1790 minfo->fbcon.fbops = &minfo->fbops;
1791 minfo->fbcon.pseudo_palette = minfo->cmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 /* after __init time we are like module... no logo */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001793 minfo->fbcon.flags = hotplug ? FBINFO_FLAG_MODULE : FBINFO_FLAG_DEFAULT;
1794 minfo->fbcon.flags |= FBINFO_PARTIAL_PAN_OK | /* Prefer panning for scroll under MC viewer/edit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 FBINFO_HWACCEL_COPYAREA | /* We have hw-assisted bmove */
1796 FBINFO_HWACCEL_FILLRECT | /* And fillrect */
1797 FBINFO_HWACCEL_IMAGEBLIT | /* And imageblit */
1798 FBINFO_HWACCEL_XPAN | /* And we support both horizontal */
1799 FBINFO_HWACCEL_YPAN; /* And vertical panning */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001800 minfo->video.len_usable &= PAGE_MASK;
1801 fb_alloc_cmap(&minfo->fbcon.cmap, 256, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
1803#ifndef MODULE
1804 /* mode database is marked __init!!! */
1805 if (!hotplug) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001806 fb_find_mode(&vesafb_defined, &minfo->fbcon, videomode[0] ? videomode : NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 NULL, 0, &defaultmode, vesafb_defined.bits_per_pixel);
1808 }
1809#endif /* !MODULE */
1810
1811 /* mode modifiers */
1812 if (hslen)
1813 vesafb_defined.hsync_len = hslen;
1814 if (vslen)
1815 vesafb_defined.vsync_len = vslen;
1816 if (left != ~0)
1817 vesafb_defined.left_margin = left;
1818 if (right != ~0)
1819 vesafb_defined.right_margin = right;
1820 if (upper != ~0)
1821 vesafb_defined.upper_margin = upper;
1822 if (lower != ~0)
1823 vesafb_defined.lower_margin = lower;
1824 if (xres)
1825 vesafb_defined.xres = xres;
1826 if (yres)
1827 vesafb_defined.yres = yres;
1828 if (sync != -1)
1829 vesafb_defined.sync = sync;
1830 else if (vesafb_defined.sync == ~0) {
1831 vesafb_defined.sync = 0;
1832 if (yres < 400)
1833 vesafb_defined.sync |= FB_SYNC_HOR_HIGH_ACT;
1834 else if (yres < 480)
1835 vesafb_defined.sync |= FB_SYNC_VERT_HIGH_ACT;
1836 }
1837
1838 /* fv, fh, maxclk limits was specified */
1839 {
1840 unsigned int tmp;
1841
1842 if (fv) {
1843 tmp = fv * (vesafb_defined.upper_margin + vesafb_defined.yres
Andrew Mortona50d9132006-06-21 01:57:39 -03001844 + vesafb_defined.lower_margin + vesafb_defined.vsync_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 if ((tmp < fh) || (fh == 0)) fh = tmp;
1846 }
1847 if (fh) {
1848 tmp = fh * (vesafb_defined.left_margin + vesafb_defined.xres
Andrew Mortona50d9132006-06-21 01:57:39 -03001849 + vesafb_defined.right_margin + vesafb_defined.hsync_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 if ((tmp < maxclk) || (maxclk == 0)) maxclk = tmp;
1851 }
1852 tmp = (maxclk + 499) / 500;
1853 if (tmp) {
1854 tmp = (2000000000 + tmp) / tmp;
1855 if (tmp > pixclock) pixclock = tmp;
1856 }
1857 }
1858 if (pixclock) {
1859 if (pixclock < 2000) /* > 500MHz */
1860 pixclock = 4000; /* 250MHz */
1861 if (pixclock > 1000000)
1862 pixclock = 1000000; /* 1MHz */
1863 vesafb_defined.pixclock = pixclock;
1864 }
1865
1866 /* FIXME: Where to move this?! */
1867#if defined(CONFIG_PPC_PMAC)
1868#ifndef MODULE
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +11001869 if (machine_is(powermac)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 struct fb_var_screeninfo var;
1871 if (default_vmode <= 0 || default_vmode > VMODE_MAX)
1872 default_vmode = VMODE_640_480_60;
1873#ifdef CONFIG_NVRAM
1874 if (default_cmode == CMODE_NVRAM)
1875 default_cmode = nvram_read_byte(NV_CMODE);
1876#endif
1877 if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
1878 default_cmode = CMODE_8;
1879 if (!mac_vmode_to_var(default_vmode, default_cmode, &var)) {
1880 var.accel_flags = vesafb_defined.accel_flags;
1881 var.xoffset = var.yoffset = 0;
1882 /* Note: mac_vmode_to_var() does not set all parameters */
1883 vesafb_defined = var;
1884 }
1885 }
1886#endif /* !MODULE */
1887#endif /* CONFIG_PPC_PMAC */
1888 vesafb_defined.xres_virtual = vesafb_defined.xres;
1889 if (nopan) {
1890 vesafb_defined.yres_virtual = vesafb_defined.yres;
1891 } else {
1892 vesafb_defined.yres_virtual = 65536; /* large enough to be INF, but small enough
1893 to yres_virtual * xres_virtual < 2^32 */
1894 }
Jean Delvare316b4d62009-09-22 16:47:49 -07001895 matroxfb_init_fix(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001896 minfo->fbcon.screen_base = vaddr_va(minfo->video.vbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 /* Normalize values (namely yres_virtual) */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001898 matroxfb_check_var(&vesafb_defined, &minfo->fbcon);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 /* And put it into "current" var. Do NOT program hardware yet, or we'll not take over
1900 * vgacon correctly. fbcon_startup will call fb_set_par for us, WITHOUT check_var,
1901 * and unfortunately it will do it BEFORE vgacon contents is saved, so it won't work
1902 * anyway. But we at least tried... */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001903 minfo->fbcon.var = vesafb_defined;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 err = -EINVAL;
1905
1906 printk(KERN_INFO "matroxfb: %dx%dx%dbpp (virtual: %dx%d)\n",
1907 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel,
1908 vesafb_defined.xres_virtual, vesafb_defined.yres_virtual);
1909 printk(KERN_INFO "matroxfb: framebuffer at 0x%lX, mapped to 0x%p, size %d\n",
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001910 minfo->video.base, vaddr_va(minfo->video.vbase), minfo->video.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
1912/* We do not have to set currcon to 0... register_framebuffer do it for us on first console
1913 * and we do not want currcon == 0 for subsequent framebuffers */
1914
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001915 minfo->fbcon.device = &minfo->pcidev->dev;
1916 if (register_framebuffer(&minfo->fbcon) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 goto failVideoIO;
1918 }
1919 printk("fb%d: %s frame buffer device\n",
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001920 minfo->fbcon.node, minfo->fbcon.fix.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 /* there is no console on this fb... but we have to initialize hardware
1923 * until someone tells me what is proper thing to do */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001924 if (!minfo->initialized) {
Andrew Mortona50d9132006-06-21 01:57:39 -03001925 printk(KERN_INFO "fb%d: initializing hardware\n",
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001926 minfo->fbcon.node);
Andrew Mortona50d9132006-06-21 01:57:39 -03001927 /* We have to use FB_ACTIVATE_FORCE, as we had to put vesafb_defined to the fbcon.var
1928 * already before, so register_framebuffer works correctly. */
1929 vesafb_defined.activate |= FB_ACTIVATE_FORCE;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001930 fb_set_var(&minfo->fbcon, &vesafb_defined);
Andrew Mortona50d9132006-06-21 01:57:39 -03001931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
1933 return 0;
1934failVideoIO:;
Jean Delvare316b4d62009-09-22 16:47:49 -07001935 matroxfb_g450_shutdown(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001936 mga_iounmap(minfo->video.vbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937failCtrlIO:;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001938 mga_iounmap(minfo->mmio.vbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939failVideoMR:;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001940 release_mem_region(video_base_phys, minfo->video.len_maximum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941failCtrlMR:;
1942 release_mem_region(ctrlptr_phys, 16384);
1943fail:;
1944 return err;
1945}
1946
1947static LIST_HEAD(matroxfb_list);
1948static LIST_HEAD(matroxfb_driver_list);
1949
1950#define matroxfb_l(x) list_entry(x, struct matrox_fb_info, next_fb)
1951#define matroxfb_driver_l(x) list_entry(x, struct matroxfb_driver, node)
1952int matroxfb_register_driver(struct matroxfb_driver* drv) {
1953 struct matrox_fb_info* minfo;
1954
1955 list_add(&drv->node, &matroxfb_driver_list);
1956 for (minfo = matroxfb_l(matroxfb_list.next);
1957 minfo != matroxfb_l(&matroxfb_list);
1958 minfo = matroxfb_l(minfo->next_fb.next)) {
1959 void* p;
1960
1961 if (minfo->drivers_count == MATROXFB_MAX_FB_DRIVERS)
1962 continue;
1963 p = drv->probe(minfo);
1964 if (p) {
1965 minfo->drivers_data[minfo->drivers_count] = p;
1966 minfo->drivers[minfo->drivers_count++] = drv;
1967 }
1968 }
1969 return 0;
1970}
1971
1972void matroxfb_unregister_driver(struct matroxfb_driver* drv) {
1973 struct matrox_fb_info* minfo;
1974
1975 list_del(&drv->node);
1976 for (minfo = matroxfb_l(matroxfb_list.next);
1977 minfo != matroxfb_l(&matroxfb_list);
1978 minfo = matroxfb_l(minfo->next_fb.next)) {
1979 int i;
1980
1981 for (i = 0; i < minfo->drivers_count; ) {
1982 if (minfo->drivers[i] == drv) {
1983 if (drv && drv->remove)
1984 drv->remove(minfo, minfo->drivers_data[i]);
1985 minfo->drivers[i] = minfo->drivers[--minfo->drivers_count];
1986 minfo->drivers_data[i] = minfo->drivers_data[minfo->drivers_count];
1987 } else
1988 i++;
1989 }
1990 }
1991}
1992
1993static void matroxfb_register_device(struct matrox_fb_info* minfo) {
1994 struct matroxfb_driver* drv;
1995 int i = 0;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001996 list_add(&minfo->next_fb, &matroxfb_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 for (drv = matroxfb_driver_l(matroxfb_driver_list.next);
1998 drv != matroxfb_driver_l(&matroxfb_driver_list);
1999 drv = matroxfb_driver_l(drv->node.next)) {
2000 if (drv && drv->probe) {
2001 void *p = drv->probe(minfo);
2002 if (p) {
2003 minfo->drivers_data[i] = p;
2004 minfo->drivers[i++] = drv;
2005 if (i == MATROXFB_MAX_FB_DRIVERS)
2006 break;
2007 }
2008 }
2009 }
2010 minfo->drivers_count = i;
2011}
2012
2013static void matroxfb_unregister_device(struct matrox_fb_info* minfo) {
2014 int i;
2015
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002016 list_del(&minfo->next_fb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 for (i = 0; i < minfo->drivers_count; i++) {
2018 struct matroxfb_driver* drv = minfo->drivers[i];
2019
2020 if (drv && drv->remove)
2021 drv->remove(minfo, minfo->drivers_data[i]);
2022 }
2023}
2024
2025static int matroxfb_probe(struct pci_dev* pdev, const struct pci_device_id* dummy) {
2026 struct board* b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 u_int16_t svid;
2028 u_int16_t sid;
2029 struct matrox_fb_info* minfo;
2030 int err;
2031 u_int32_t cmd;
Harvey Harrison5ae12172008-04-28 02:15:47 -07002032 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 svid = pdev->subsystem_vendor;
2035 sid = pdev->subsystem_device;
2036 for (b = dev_list; b->vendor; b++) {
Auke Kok44c10132007-06-08 15:46:36 -07002037 if ((b->vendor != pdev->vendor) || (b->device != pdev->device) || (b->rev < pdev->revision)) continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 if (b->svid)
2039 if ((b->svid != svid) || (b->sid != sid)) continue;
2040 break;
2041 }
2042 /* not match... */
2043 if (!b->vendor)
Jan Beulich438e5c52005-09-13 01:25:45 -07002044 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 if (dev > 0) {
2046 /* not requested one... */
2047 dev--;
Jan Beulich438e5c52005-09-13 01:25:45 -07002048 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 }
2050 pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
2051 if (pci_enable_device(pdev)) {
2052 return -1;
2053 }
2054
Robert P. J. Day5cbded52006-12-13 00:35:56 -08002055 minfo = kmalloc(sizeof(*minfo), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 if (!minfo)
2057 return -1;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002058 memset(minfo, 0, sizeof(*minfo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002060 minfo->pcidev = pdev;
2061 minfo->dead = 0;
2062 minfo->usecount = 0;
2063 minfo->userusecount = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002065 pci_set_drvdata(pdev, minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 /* DEVFLAGS */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002067 minfo->devflags.memtype = memtype;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 if (memtype != -1)
2069 noinit = 0;
2070 if (cmd & PCI_COMMAND_MEMORY) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002071 minfo->devflags.novga = novga;
2072 minfo->devflags.nobios = nobios;
2073 minfo->devflags.noinit = noinit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 /* subsequent heads always needs initialization and must not enable BIOS */
2075 novga = 1;
2076 nobios = 1;
2077 noinit = 0;
2078 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002079 minfo->devflags.novga = 1;
2080 minfo->devflags.nobios = 1;
2081 minfo->devflags.noinit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 }
2083
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002084 minfo->devflags.nopciretry = no_pci_retry;
2085 minfo->devflags.mga_24bpp_fix = inv24;
2086 minfo->devflags.precise_width = option_precise_width;
2087 minfo->devflags.sgram = sgram;
2088 minfo->capable.cross4MB = cross4MB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002090 spin_lock_init(&minfo->lock.DAC);
2091 spin_lock_init(&minfo->lock.accel);
2092 init_rwsem(&minfo->crtc2.lock);
2093 init_rwsem(&minfo->altout.lock);
2094 mutex_init(&minfo->fbcon.mm_lock);
2095 minfo->irq_flags = 0;
2096 init_waitqueue_head(&minfo->crtc1.vsync.wait);
2097 init_waitqueue_head(&minfo->crtc2.vsync.wait);
2098 minfo->crtc1.panpos = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Jean Delvare316b4d62009-09-22 16:47:49 -07002100 err = initMatrox2(minfo, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 if (!err) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002102 matroxfb_register_device(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 return 0;
2104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 kfree(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 return -1;
2107}
2108
2109static void pci_remove_matrox(struct pci_dev* pdev) {
2110 struct matrox_fb_info* minfo;
2111
2112 minfo = pci_get_drvdata(pdev);
Jean Delvare316b4d62009-09-22 16:47:49 -07002113 matroxfb_remove(minfo, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114}
2115
2116static struct pci_device_id matroxfb_devices[] = {
2117#ifdef CONFIG_FB_MATROX_MILLENIUM
2118 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL,
2119 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2120 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2,
2121 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2122 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2_AGP,
2123 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2124#endif
2125#ifdef CONFIG_FB_MATROX_MYSTIQUE
2126 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS,
2127 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2128#endif
2129#ifdef CONFIG_FB_MATROX_G
2130 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_MM,
2131 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2132 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_AGP,
2133 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Darrick J. Wonge3a19382008-10-15 22:03:52 -07002134 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200EV_PCI,
2135 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI,
2137 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2138 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP,
2139 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2140 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400,
2141 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2142 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G550,
2143 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2144#endif
2145 {0, 0,
2146 0, 0, 0, 0, 0}
2147};
2148
2149MODULE_DEVICE_TABLE(pci, matroxfb_devices);
2150
2151
2152static struct pci_driver matroxfb_driver = {
2153 .name = "matroxfb",
2154 .id_table = matroxfb_devices,
2155 .probe = matroxfb_probe,
2156 .remove = pci_remove_matrox,
2157};
2158
2159/* **************************** init-time only **************************** */
2160
2161#define RSResolution(X) ((X) & 0x0F)
2162#define RS640x400 1
2163#define RS640x480 2
2164#define RS800x600 3
2165#define RS1024x768 4
2166#define RS1280x1024 5
2167#define RS1600x1200 6
2168#define RS768x576 7
2169#define RS960x720 8
2170#define RS1152x864 9
2171#define RS1408x1056 10
2172#define RS640x350 11
2173#define RS1056x344 12 /* 132 x 43 text */
2174#define RS1056x400 13 /* 132 x 50 text */
2175#define RS1056x480 14 /* 132 x 60 text */
2176#define RSNoxNo 15
2177/* 10-FF */
2178static struct { int xres, yres, left, right, upper, lower, hslen, vslen, vfreq; } timmings[] __initdata = {
2179 { 640, 400, 48, 16, 39, 8, 96, 2, 70 },
2180 { 640, 480, 48, 16, 33, 10, 96, 2, 60 },
2181 { 800, 600, 144, 24, 28, 8, 112, 6, 60 },
2182 { 1024, 768, 160, 32, 30, 4, 128, 4, 60 },
2183 { 1280, 1024, 224, 32, 32, 4, 136, 4, 60 },
2184 { 1600, 1200, 272, 48, 32, 5, 152, 5, 60 },
2185 { 768, 576, 144, 16, 28, 6, 112, 4, 60 },
2186 { 960, 720, 144, 24, 28, 8, 112, 4, 60 },
2187 { 1152, 864, 192, 32, 30, 4, 128, 4, 60 },
2188 { 1408, 1056, 256, 40, 32, 5, 144, 5, 60 },
2189 { 640, 350, 48, 16, 39, 8, 96, 2, 70 },
2190 { 1056, 344, 96, 24, 59, 44, 160, 2, 70 },
2191 { 1056, 400, 96, 24, 39, 8, 160, 2, 70 },
2192 { 1056, 480, 96, 24, 36, 12, 160, 3, 60 },
2193 { 0, 0, ~0, ~0, ~0, ~0, 0, 0, 0 }
2194};
2195
2196#define RSCreate(X,Y) ((X) | ((Y) << 8))
2197static struct { unsigned int vesa; unsigned int info; } *RSptr, vesamap[] __initdata = {
2198/* default must be first */
2199 { ~0, RSCreate(RSNoxNo, RS8bpp ) },
2200 { 0x101, RSCreate(RS640x480, RS8bpp ) },
2201 { 0x100, RSCreate(RS640x400, RS8bpp ) },
2202 { 0x180, RSCreate(RS768x576, RS8bpp ) },
2203 { 0x103, RSCreate(RS800x600, RS8bpp ) },
2204 { 0x188, RSCreate(RS960x720, RS8bpp ) },
2205 { 0x105, RSCreate(RS1024x768, RS8bpp ) },
2206 { 0x190, RSCreate(RS1152x864, RS8bpp ) },
2207 { 0x107, RSCreate(RS1280x1024, RS8bpp ) },
2208 { 0x198, RSCreate(RS1408x1056, RS8bpp ) },
2209 { 0x11C, RSCreate(RS1600x1200, RS8bpp ) },
2210 { 0x110, RSCreate(RS640x480, RS15bpp) },
2211 { 0x181, RSCreate(RS768x576, RS15bpp) },
2212 { 0x113, RSCreate(RS800x600, RS15bpp) },
2213 { 0x189, RSCreate(RS960x720, RS15bpp) },
2214 { 0x116, RSCreate(RS1024x768, RS15bpp) },
2215 { 0x191, RSCreate(RS1152x864, RS15bpp) },
2216 { 0x119, RSCreate(RS1280x1024, RS15bpp) },
2217 { 0x199, RSCreate(RS1408x1056, RS15bpp) },
2218 { 0x11D, RSCreate(RS1600x1200, RS15bpp) },
2219 { 0x111, RSCreate(RS640x480, RS16bpp) },
2220 { 0x182, RSCreate(RS768x576, RS16bpp) },
2221 { 0x114, RSCreate(RS800x600, RS16bpp) },
2222 { 0x18A, RSCreate(RS960x720, RS16bpp) },
2223 { 0x117, RSCreate(RS1024x768, RS16bpp) },
2224 { 0x192, RSCreate(RS1152x864, RS16bpp) },
2225 { 0x11A, RSCreate(RS1280x1024, RS16bpp) },
2226 { 0x19A, RSCreate(RS1408x1056, RS16bpp) },
2227 { 0x11E, RSCreate(RS1600x1200, RS16bpp) },
2228 { 0x1B2, RSCreate(RS640x480, RS24bpp) },
2229 { 0x184, RSCreate(RS768x576, RS24bpp) },
2230 { 0x1B5, RSCreate(RS800x600, RS24bpp) },
2231 { 0x18C, RSCreate(RS960x720, RS24bpp) },
2232 { 0x1B8, RSCreate(RS1024x768, RS24bpp) },
2233 { 0x194, RSCreate(RS1152x864, RS24bpp) },
2234 { 0x1BB, RSCreate(RS1280x1024, RS24bpp) },
2235 { 0x19C, RSCreate(RS1408x1056, RS24bpp) },
2236 { 0x1BF, RSCreate(RS1600x1200, RS24bpp) },
2237 { 0x112, RSCreate(RS640x480, RS32bpp) },
2238 { 0x183, RSCreate(RS768x576, RS32bpp) },
2239 { 0x115, RSCreate(RS800x600, RS32bpp) },
2240 { 0x18B, RSCreate(RS960x720, RS32bpp) },
2241 { 0x118, RSCreate(RS1024x768, RS32bpp) },
2242 { 0x193, RSCreate(RS1152x864, RS32bpp) },
2243 { 0x11B, RSCreate(RS1280x1024, RS32bpp) },
2244 { 0x19B, RSCreate(RS1408x1056, RS32bpp) },
2245 { 0x11F, RSCreate(RS1600x1200, RS32bpp) },
2246 { 0x010, RSCreate(RS640x350, RS4bpp ) },
2247 { 0x012, RSCreate(RS640x480, RS4bpp ) },
2248 { 0x102, RSCreate(RS800x600, RS4bpp ) },
2249 { 0x104, RSCreate(RS1024x768, RS4bpp ) },
2250 { 0x106, RSCreate(RS1280x1024, RS4bpp ) },
2251 { 0, 0 }};
2252
2253static void __init matroxfb_init_params(void) {
2254 /* fh from kHz to Hz */
2255 if (fh < 1000)
2256 fh *= 1000; /* 1kHz minimum */
2257 /* maxclk */
2258 if (maxclk < 1000) maxclk *= 1000; /* kHz -> Hz, MHz -> kHz */
2259 if (maxclk < 1000000) maxclk *= 1000; /* kHz -> Hz, 1MHz minimum */
2260 /* fix VESA number */
2261 if (vesa != ~0)
2262 vesa &= 0x1DFF; /* mask out clearscreen, acceleration and so on */
2263
2264 /* static settings */
2265 for (RSptr = vesamap; RSptr->vesa; RSptr++) {
2266 if (RSptr->vesa == vesa) break;
2267 }
2268 if (!RSptr->vesa) {
2269 printk(KERN_ERR "Invalid vesa mode 0x%04X\n", vesa);
2270 RSptr = vesamap;
2271 }
2272 {
2273 int res = RSResolution(RSptr->info)-1;
2274 if (left == ~0)
2275 left = timmings[res].left;
2276 if (!xres)
2277 xres = timmings[res].xres;
2278 if (right == ~0)
2279 right = timmings[res].right;
2280 if (!hslen)
2281 hslen = timmings[res].hslen;
2282 if (upper == ~0)
2283 upper = timmings[res].upper;
2284 if (!yres)
2285 yres = timmings[res].yres;
2286 if (lower == ~0)
2287 lower = timmings[res].lower;
2288 if (!vslen)
2289 vslen = timmings[res].vslen;
2290 if (!(fv||fh||maxclk||pixclock))
2291 fv = timmings[res].vfreq;
2292 if (depth == -1)
2293 depth = RSDepth(RSptr->info);
2294 }
2295}
2296
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002297static int __init matrox_init(void) {
2298 int err;
2299
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 matroxfb_init_params();
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002301 err = pci_register_driver(&matroxfb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 dev = -1; /* accept all new devices... */
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002303 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304}
2305
2306/* **************************** exit-time only **************************** */
2307
2308static void __exit matrox_done(void) {
2309 pci_unregister_driver(&matroxfb_driver);
2310}
2311
2312#ifndef MODULE
2313
2314/* ************************* init in-kernel code ************************** */
2315
2316static int __init matroxfb_setup(char *options) {
2317 char *this_opt;
2318
Harvey Harrison5ae12172008-04-28 02:15:47 -07002319 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
2321 if (!options || !*options)
2322 return 0;
2323
2324 while ((this_opt = strsep(&options, ",")) != NULL) {
2325 if (!*this_opt) continue;
2326
2327 dprintk("matroxfb_setup: option %s\n", this_opt);
2328
2329 if (!strncmp(this_opt, "dev:", 4))
2330 dev = simple_strtoul(this_opt+4, NULL, 0);
2331 else if (!strncmp(this_opt, "depth:", 6)) {
2332 switch (simple_strtoul(this_opt+6, NULL, 0)) {
2333 case 0: depth = RSText; break;
2334 case 4: depth = RS4bpp; break;
2335 case 8: depth = RS8bpp; break;
2336 case 15:depth = RS15bpp; break;
2337 case 16:depth = RS16bpp; break;
2338 case 24:depth = RS24bpp; break;
2339 case 32:depth = RS32bpp; break;
2340 default:
2341 printk(KERN_ERR "matroxfb: unsupported color depth\n");
2342 }
2343 } else if (!strncmp(this_opt, "xres:", 5))
2344 xres = simple_strtoul(this_opt+5, NULL, 0);
2345 else if (!strncmp(this_opt, "yres:", 5))
2346 yres = simple_strtoul(this_opt+5, NULL, 0);
2347 else if (!strncmp(this_opt, "vslen:", 6))
2348 vslen = simple_strtoul(this_opt+6, NULL, 0);
2349 else if (!strncmp(this_opt, "hslen:", 6))
2350 hslen = simple_strtoul(this_opt+6, NULL, 0);
2351 else if (!strncmp(this_opt, "left:", 5))
2352 left = simple_strtoul(this_opt+5, NULL, 0);
2353 else if (!strncmp(this_opt, "right:", 6))
2354 right = simple_strtoul(this_opt+6, NULL, 0);
2355 else if (!strncmp(this_opt, "upper:", 6))
2356 upper = simple_strtoul(this_opt+6, NULL, 0);
2357 else if (!strncmp(this_opt, "lower:", 6))
2358 lower = simple_strtoul(this_opt+6, NULL, 0);
2359 else if (!strncmp(this_opt, "pixclock:", 9))
2360 pixclock = simple_strtoul(this_opt+9, NULL, 0);
2361 else if (!strncmp(this_opt, "sync:", 5))
2362 sync = simple_strtoul(this_opt+5, NULL, 0);
2363 else if (!strncmp(this_opt, "vesa:", 5))
2364 vesa = simple_strtoul(this_opt+5, NULL, 0);
2365 else if (!strncmp(this_opt, "maxclk:", 7))
2366 maxclk = simple_strtoul(this_opt+7, NULL, 0);
2367 else if (!strncmp(this_opt, "fh:", 3))
2368 fh = simple_strtoul(this_opt+3, NULL, 0);
2369 else if (!strncmp(this_opt, "fv:", 3))
2370 fv = simple_strtoul(this_opt+3, NULL, 0);
2371 else if (!strncmp(this_opt, "mem:", 4))
2372 mem = simple_strtoul(this_opt+4, NULL, 0);
2373 else if (!strncmp(this_opt, "mode:", 5))
2374 strlcpy(videomode, this_opt+5, sizeof(videomode));
2375 else if (!strncmp(this_opt, "outputs:", 8))
2376 strlcpy(outputs, this_opt+8, sizeof(outputs));
2377 else if (!strncmp(this_opt, "dfp:", 4)) {
2378 dfp_type = simple_strtoul(this_opt+4, NULL, 0);
2379 dfp = 1;
Andrew Mortona50d9132006-06-21 01:57:39 -03002380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381#ifdef CONFIG_PPC_PMAC
2382 else if (!strncmp(this_opt, "vmode:", 6)) {
2383 unsigned int vmode = simple_strtoul(this_opt+6, NULL, 0);
2384 if (vmode > 0 && vmode <= VMODE_MAX)
2385 default_vmode = vmode;
2386 } else if (!strncmp(this_opt, "cmode:", 6)) {
2387 unsigned int cmode = simple_strtoul(this_opt+6, NULL, 0);
2388 switch (cmode) {
2389 case 0:
2390 case 8:
2391 default_cmode = CMODE_8;
2392 break;
2393 case 15:
2394 case 16:
2395 default_cmode = CMODE_16;
2396 break;
2397 case 24:
2398 case 32:
2399 default_cmode = CMODE_32;
2400 break;
2401 }
2402 }
2403#endif
2404 else if (!strcmp(this_opt, "disabled")) /* nodisabled does not exist */
2405 disabled = 1;
2406 else if (!strcmp(this_opt, "enabled")) /* noenabled does not exist */
2407 disabled = 0;
2408 else if (!strcmp(this_opt, "sgram")) /* nosgram == sdram */
2409 sgram = 1;
2410 else if (!strcmp(this_opt, "sdram"))
2411 sgram = 0;
2412 else if (!strncmp(this_opt, "memtype:", 8))
2413 memtype = simple_strtoul(this_opt+8, NULL, 0);
2414 else {
2415 int value = 1;
2416
2417 if (!strncmp(this_opt, "no", 2)) {
2418 value = 0;
2419 this_opt += 2;
2420 }
2421 if (! strcmp(this_opt, "inverse"))
2422 inverse = value;
2423 else if (!strcmp(this_opt, "accel"))
2424 noaccel = !value;
2425 else if (!strcmp(this_opt, "pan"))
2426 nopan = !value;
2427 else if (!strcmp(this_opt, "pciretry"))
2428 no_pci_retry = !value;
2429 else if (!strcmp(this_opt, "vga"))
2430 novga = !value;
2431 else if (!strcmp(this_opt, "bios"))
2432 nobios = !value;
2433 else if (!strcmp(this_opt, "init"))
2434 noinit = !value;
2435#ifdef CONFIG_MTRR
2436 else if (!strcmp(this_opt, "mtrr"))
2437 mtrr = value;
2438#endif
2439 else if (!strcmp(this_opt, "inv24"))
2440 inv24 = value;
2441 else if (!strcmp(this_opt, "cross4MB"))
2442 cross4MB = value;
2443 else if (!strcmp(this_opt, "grayscale"))
2444 grayscale = value;
2445 else if (!strcmp(this_opt, "dfp"))
2446 dfp = value;
2447 else {
2448 strlcpy(videomode, this_opt, sizeof(videomode));
2449 }
2450 }
2451 }
2452 return 0;
2453}
2454
2455static int __initdata initialized = 0;
2456
2457static int __init matroxfb_init(void)
2458{
2459 char *option = NULL;
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002460 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
Harvey Harrison5ae12172008-04-28 02:15:47 -07002462 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
2464 if (fb_get_options("matroxfb", &option))
2465 return -ENODEV;
2466 matroxfb_setup(option);
2467
2468 if (disabled)
2469 return -ENXIO;
2470 if (!initialized) {
2471 initialized = 1;
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002472 err = matrox_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 }
2474 hotplug = 1;
2475 /* never return failure, user can hotplug matrox later... */
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002476 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477}
2478
2479module_init(matroxfb_init);
2480
2481#else
2482
2483/* *************************** init module code **************************** */
2484
2485MODULE_AUTHOR("(c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>");
2486MODULE_DESCRIPTION("Accelerated FBDev driver for Matrox Millennium/Mystique/G100/G200/G400/G450/G550");
2487MODULE_LICENSE("GPL");
2488
2489module_param(mem, int, 0);
2490MODULE_PARM_DESC(mem, "Size of available memory in MB, KB or B (2,4,8,12,16MB, default=autodetect)");
2491module_param(disabled, int, 0);
2492MODULE_PARM_DESC(disabled, "Disabled (0 or 1=disabled) (default=0)");
2493module_param(noaccel, int, 0);
2494MODULE_PARM_DESC(noaccel, "Do not use accelerating engine (0 or 1=disabled) (default=0)");
2495module_param(nopan, int, 0);
2496MODULE_PARM_DESC(nopan, "Disable pan on startup (0 or 1=disabled) (default=0)");
2497module_param(no_pci_retry, int, 0);
2498MODULE_PARM_DESC(no_pci_retry, "PCI retries enabled (0 or 1=disabled) (default=0)");
2499module_param(novga, int, 0);
2500MODULE_PARM_DESC(novga, "VGA I/O (0x3C0-0x3DF) disabled (0 or 1=disabled) (default=0)");
2501module_param(nobios, int, 0);
2502MODULE_PARM_DESC(nobios, "Disables ROM BIOS (0 or 1=disabled) (default=do not change BIOS state)");
2503module_param(noinit, int, 0);
2504MODULE_PARM_DESC(noinit, "Disables W/SG/SD-RAM and bus interface initialization (0 or 1=do not initialize) (default=0)");
2505module_param(memtype, int, 0);
2506MODULE_PARM_DESC(memtype, "Memory type for G200/G400 (see Documentation/fb/matroxfb.txt for explanation) (default=3 for G200, 0 for G400)");
2507#ifdef CONFIG_MTRR
2508module_param(mtrr, int, 0);
2509MODULE_PARM_DESC(mtrr, "This speeds up video memory accesses (0=disabled or 1) (default=1)");
2510#endif
2511module_param(sgram, int, 0);
2512MODULE_PARM_DESC(sgram, "Indicates that G100/G200/G400 has SGRAM memory (0=SDRAM, 1=SGRAM) (default=0)");
2513module_param(inv24, int, 0);
2514MODULE_PARM_DESC(inv24, "Inverts clock polarity for 24bpp and loop frequency > 100MHz (default=do not invert polarity)");
2515module_param(inverse, int, 0);
2516MODULE_PARM_DESC(inverse, "Inverse (0 or 1) (default=0)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517module_param(dev, int, 0);
2518MODULE_PARM_DESC(dev, "Multihead support, attach to device ID (0..N) (default=all working)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519module_param(vesa, int, 0);
2520MODULE_PARM_DESC(vesa, "Startup videomode (0x000-0x1FF) (default=0x101)");
2521module_param(xres, int, 0);
2522MODULE_PARM_DESC(xres, "Horizontal resolution (px), overrides xres from vesa (default=vesa)");
2523module_param(yres, int, 0);
2524MODULE_PARM_DESC(yres, "Vertical resolution (scans), overrides yres from vesa (default=vesa)");
2525module_param(upper, int, 0);
2526MODULE_PARM_DESC(upper, "Upper blank space (scans), overrides upper from vesa (default=vesa)");
2527module_param(lower, int, 0);
2528MODULE_PARM_DESC(lower, "Lower blank space (scans), overrides lower from vesa (default=vesa)");
2529module_param(vslen, int, 0);
2530MODULE_PARM_DESC(vslen, "Vertical sync length (scans), overrides lower from vesa (default=vesa)");
2531module_param(left, int, 0);
2532MODULE_PARM_DESC(left, "Left blank space (px), overrides left from vesa (default=vesa)");
2533module_param(right, int, 0);
2534MODULE_PARM_DESC(right, "Right blank space (px), overrides right from vesa (default=vesa)");
2535module_param(hslen, int, 0);
2536MODULE_PARM_DESC(hslen, "Horizontal sync length (px), overrides hslen from vesa (default=vesa)");
2537module_param(pixclock, int, 0);
2538MODULE_PARM_DESC(pixclock, "Pixelclock (ns), overrides pixclock from vesa (default=vesa)");
2539module_param(sync, int, 0);
2540MODULE_PARM_DESC(sync, "Sync polarity, overrides sync from vesa (default=vesa)");
2541module_param(depth, int, 0);
2542MODULE_PARM_DESC(depth, "Color depth (0=text,8,15,16,24,32) (default=vesa)");
2543module_param(maxclk, int, 0);
2544MODULE_PARM_DESC(maxclk, "Startup maximal clock, 0-999MHz, 1000-999999kHz, 1000000-INF Hz");
2545module_param(fh, int, 0);
2546MODULE_PARM_DESC(fh, "Startup horizontal frequency, 0-999kHz, 1000-INF Hz");
2547module_param(fv, int, 0);
2548MODULE_PARM_DESC(fv, "Startup vertical frequency, 0-INF Hz\n"
Niels de Vos61a2d072008-07-31 00:07:23 -07002549"You should specify \"fv:max_monitor_vsync,fh:max_monitor_hsync,maxclk:max_monitor_dotclock\"");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550module_param(grayscale, int, 0);
2551MODULE_PARM_DESC(grayscale, "Sets display into grayscale. Works perfectly with paletized videomode (4, 8bpp), some limitations apply to 16, 24 and 32bpp videomodes (default=nograyscale)");
2552module_param(cross4MB, int, 0);
2553MODULE_PARM_DESC(cross4MB, "Specifies that 4MB boundary can be in middle of line. (default=autodetected)");
2554module_param(dfp, int, 0);
2555MODULE_PARM_DESC(dfp, "Specifies whether to use digital flat panel interface of G200/G400 (0 or 1) (default=0)");
2556module_param(dfp_type, int, 0);
2557MODULE_PARM_DESC(dfp_type, "Specifies DFP interface type (0 to 255) (default=read from hardware)");
2558module_param_string(outputs, outputs, sizeof(outputs), 0);
2559MODULE_PARM_DESC(outputs, "Specifies which CRTC is mapped to which output (string of up to three letters, consisting of 0 (disabled), 1 (CRTC1), 2 (CRTC2)) (default=111 for Gx50, 101 for G200/G400 with DFP, and 100 for all other devices)");
2560#ifdef CONFIG_PPC_PMAC
2561module_param_named(vmode, default_vmode, int, 0);
2562MODULE_PARM_DESC(vmode, "Specify the vmode mode number that should be used (640x480 default)");
2563module_param_named(cmode, default_cmode, int, 0);
2564MODULE_PARM_DESC(cmode, "Specify the video depth that should be used (8bit default)");
2565#endif
2566
2567int __init init_module(void){
2568
Harvey Harrison5ae12172008-04-28 02:15:47 -07002569 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570
2571 if (disabled)
2572 return -ENXIO;
2573
2574 if (depth == 0)
2575 depth = RSText;
2576 else if (depth == 4)
2577 depth = RS4bpp;
2578 else if (depth == 8)
2579 depth = RS8bpp;
2580 else if (depth == 15)
2581 depth = RS15bpp;
2582 else if (depth == 16)
2583 depth = RS16bpp;
2584 else if (depth == 24)
2585 depth = RS24bpp;
2586 else if (depth == 32)
2587 depth = RS32bpp;
2588 else if (depth != -1) {
2589 printk(KERN_ERR "matroxfb: depth %d is not supported, using default\n", depth);
2590 depth = -1;
2591 }
2592 matrox_init();
2593 /* never return failure; user can hotplug matrox later... */
2594 return 0;
2595}
2596#endif /* MODULE */
2597
2598module_exit(matrox_done);
2599EXPORT_SYMBOL(matroxfb_register_driver);
2600EXPORT_SYMBOL(matroxfb_unregister_driver);
2601EXPORT_SYMBOL(matroxfb_wait_for_sync);
2602EXPORT_SYMBOL(matroxfb_enable_irq);
2603
2604/*
2605 * Overrides for Emacs so that we follow Linus's tabbing style.
2606 * ---------------------------------------------------------------------------
2607 * Local variables:
2608 * c-basic-offset: 8
2609 * End:
2610 */
2611