blob: 7064fb4427b6f44b2c45fd26860e31a2e6ccdefc [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;
Jean Delvareee5a2742009-09-22 16:47:50 -0700207 struct matrox_fb_info *minfo = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 status = mga_inl(M_STATUS);
210
211 if (status & 0x20) {
212 mga_outl(M_ICLEAR, 0x20);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700213 minfo->crtc1.vsync.cnt++;
Jean Delvare316b4d62009-09-22 16:47:49 -0700214 matroxfb_crtc1_panpos(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700215 wake_up_interruptible(&minfo->crtc1.vsync.wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 handled = 1;
217 }
218 if (status & 0x200) {
219 mga_outl(M_ICLEAR, 0x200);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700220 minfo->crtc2.vsync.cnt++;
221 wake_up_interruptible(&minfo->crtc2.vsync.wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 handled = 1;
223 }
224 return IRQ_RETVAL(handled);
225}
226
Jean Delvare316b4d62009-09-22 16:47:49 -0700227int matroxfb_enable_irq(struct matrox_fb_info *minfo, int reenable)
228{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 u_int32_t bm;
Andrew Mortona50d9132006-06-21 01:57:39 -0300230
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700231 if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 bm = 0x220;
233 else
234 bm = 0x020;
235
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700236 if (!test_and_set_bit(0, &minfo->irq_flags)) {
237 if (request_irq(minfo->pcidev->irq, matrox_irq,
238 IRQF_SHARED, "matroxfb", minfo)) {
239 clear_bit(0, &minfo->irq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return -EINVAL;
241 }
242 /* Clear any pending field interrupts */
243 mga_outl(M_ICLEAR, bm);
244 mga_outl(M_IEN, mga_inl(M_IEN) | bm);
245 } else if (reenable) {
246 u_int32_t ien;
Andrew Mortona50d9132006-06-21 01:57:39 -0300247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 ien = mga_inl(M_IEN);
249 if ((ien & bm) != bm) {
250 printk(KERN_DEBUG "matroxfb: someone disabled IRQ [%08X]\n", ien);
251 mga_outl(M_IEN, ien | bm);
252 }
253 }
254 return 0;
255}
256
Jean Delvare316b4d62009-09-22 16:47:49 -0700257static void matroxfb_disable_irq(struct matrox_fb_info *minfo)
258{
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700259 if (test_and_clear_bit(0, &minfo->irq_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 /* Flush pending pan-at-vbl request... */
Jean Delvare316b4d62009-09-22 16:47:49 -0700261 matroxfb_crtc1_panpos(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700262 if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 mga_outl(M_IEN, mga_inl(M_IEN) & ~0x220);
264 else
265 mga_outl(M_IEN, mga_inl(M_IEN) & ~0x20);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700266 free_irq(minfo->pcidev->irq, minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268}
269
Jean Delvare316b4d62009-09-22 16:47:49 -0700270int matroxfb_wait_for_sync(struct matrox_fb_info *minfo, u_int32_t crtc)
271{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 struct matrox_vsync *vs;
273 unsigned int cnt;
274 int ret;
275
276 switch (crtc) {
277 case 0:
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700278 vs = &minfo->crtc1.vsync;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 break;
280 case 1:
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700281 if (minfo->devflags.accelerator != FB_ACCEL_MATROX_MGAG400) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 return -ENODEV;
283 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700284 vs = &minfo->crtc2.vsync;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 break;
286 default:
287 return -ENODEV;
288 }
Jean Delvare316b4d62009-09-22 16:47:49 -0700289 ret = matroxfb_enable_irq(minfo, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 if (ret) {
291 return ret;
292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 cnt = vs->cnt;
295 ret = wait_event_interruptible_timeout(vs->wait, cnt != vs->cnt, HZ/10);
296 if (ret < 0) {
297 return ret;
298 }
299 if (ret == 0) {
Jean Delvare316b4d62009-09-22 16:47:49 -0700300 matroxfb_enable_irq(minfo, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 return -ETIMEDOUT;
302 }
303 return 0;
304}
305
306/* --------------------------------------------------------------------- */
307
Jean Delvare316b4d62009-09-22 16:47:49 -0700308static void matrox_pan_var(struct matrox_fb_info *minfo,
309 struct fb_var_screeninfo *var)
310{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 unsigned int pos;
312 unsigned short p0, p1, p2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 unsigned int p3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 int vbl;
315 unsigned long flags;
316
317 CRITFLAGS
318
Harvey Harrison5ae12172008-04-28 02:15:47 -0700319 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700321 if (minfo->dead)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 return;
323
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700324 minfo->fbcon.var.xoffset = var->xoffset;
325 minfo->fbcon.var.yoffset = var->yoffset;
326 pos = (minfo->fbcon.var.yoffset * minfo->fbcon.var.xres_virtual + minfo->fbcon.var.xoffset) * minfo->curr.final_bppShift / 32;
327 pos += minfo->curr.ydstorg.chunks;
328 p0 = minfo->hw.CRTC[0x0D] = pos & 0xFF;
329 p1 = minfo->hw.CRTC[0x0C] = (pos & 0xFF00) >> 8;
330 p2 = minfo->hw.CRTCEXT[0] = (minfo->hw.CRTCEXT[0] & 0xB0) | ((pos >> 16) & 0x0F) | ((pos >> 14) & 0x40);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700331 p3 = minfo->hw.CRTCEXT[8] = pos >> 21;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 /* FB_ACTIVATE_VBL and we can acquire interrupts? Honor FB_ACTIVATE_VBL then... */
Jean Delvare316b4d62009-09-22 16:47:49 -0700334 vbl = (var->activate & FB_ACTIVATE_VBL) && (matroxfb_enable_irq(minfo, 0) == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 CRITBEGIN
337
338 matroxfb_DAC_lock_irqsave(flags);
339 mga_setr(M_CRTC_INDEX, 0x0D, p0);
340 mga_setr(M_CRTC_INDEX, 0x0C, p1);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700341 if (minfo->devflags.support32MB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 mga_setr(M_EXTVGA_INDEX, 0x08, p3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 if (vbl) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700344 minfo->crtc1.panpos = p2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 } else {
346 /* Abort any pending change */
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700347 minfo->crtc1.panpos = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 mga_setr(M_EXTVGA_INDEX, 0x00, p2);
349 }
350 matroxfb_DAC_unlock_irqrestore(flags);
Andrew Mortona50d9132006-06-21 01:57:39 -0300351
Jean Delvare316b4d62009-09-22 16:47:49 -0700352 update_crtc2(minfo, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 CRITEND
355}
356
Jean Delvare316b4d62009-09-22 16:47:49 -0700357static void matroxfb_remove(struct matrox_fb_info *minfo, int dummy)
358{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 /* Currently we are holding big kernel lock on all dead & usecount updates.
360 * Destroy everything after all users release it. Especially do not unregister
361 * framebuffer and iounmap memory, neither fbmem nor fbcon-cfb* does not check
362 * for device unplugged when in use.
363 * In future we should point mmio.vbase & video.vbase somewhere where we can
364 * write data without causing too much damage...
365 */
366
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700367 minfo->dead = 1;
368 if (minfo->usecount) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 /* destroy it later */
370 return;
371 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700372 matroxfb_unregister_device(minfo);
373 unregister_framebuffer(&minfo->fbcon);
Jean Delvare316b4d62009-09-22 16:47:49 -0700374 matroxfb_g450_shutdown(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#ifdef CONFIG_MTRR
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700376 if (minfo->mtrr.vram_valid)
377 mtrr_del(minfo->mtrr.vram, minfo->video.base, minfo->video.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#endif
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700379 mga_iounmap(minfo->mmio.vbase);
380 mga_iounmap(minfo->video.vbase);
381 release_mem_region(minfo->video.base, minfo->video.len_maximum);
382 release_mem_region(minfo->mmio.base, 16384);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 kfree(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
386 /*
387 * Open/Release the frame buffer device
388 */
389
390static int matroxfb_open(struct fb_info *info, int user)
391{
Jean Delvareee5a2742009-09-22 16:47:50 -0700392 struct matrox_fb_info *minfo = info2minfo(info);
Andrew Mortona50d9132006-06-21 01:57:39 -0300393
Harvey Harrison5ae12172008-04-28 02:15:47 -0700394 DBG_LOOP(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700396 if (minfo->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return -ENXIO;
398 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700399 minfo->usecount++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 if (user) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700401 minfo->userusecount++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403 return(0);
404}
405
406static int matroxfb_release(struct fb_info *info, int user)
407{
Jean Delvareee5a2742009-09-22 16:47:50 -0700408 struct matrox_fb_info *minfo = info2minfo(info);
Andrew Mortona50d9132006-06-21 01:57:39 -0300409
Harvey Harrison5ae12172008-04-28 02:15:47 -0700410 DBG_LOOP(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 if (user) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700413 if (0 == --minfo->userusecount) {
Jean Delvare316b4d62009-09-22 16:47:49 -0700414 matroxfb_disable_irq(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700417 if (!(--minfo->usecount) && minfo->dead) {
Jean Delvare316b4d62009-09-22 16:47:49 -0700418 matroxfb_remove(minfo, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420 return(0);
421}
422
423static int matroxfb_pan_display(struct fb_var_screeninfo *var,
424 struct fb_info* info) {
Jean Delvareee5a2742009-09-22 16:47:50 -0700425 struct matrox_fb_info *minfo = info2minfo(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Harvey Harrison5ae12172008-04-28 02:15:47 -0700427 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Jean Delvare316b4d62009-09-22 16:47:49 -0700429 matrox_pan_var(minfo, var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 return 0;
431}
432
Jean Delvare316b4d62009-09-22 16:47:49 -0700433static int matroxfb_get_final_bppShift(const struct matrox_fb_info *minfo,
434 int bpp)
435{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 int bppshft2;
437
Harvey Harrison5ae12172008-04-28 02:15:47 -0700438 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 bppshft2 = bpp;
441 if (!bppshft2) {
442 return 8;
443 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700444 if (isInterleave(minfo))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 bppshft2 >>= 1;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700446 if (minfo->devflags.video64bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 bppshft2 >>= 1;
448 return bppshft2;
449}
450
Jean Delvare316b4d62009-09-22 16:47:49 -0700451static int matroxfb_test_and_set_rounding(const struct matrox_fb_info *minfo,
452 int xres, int bpp)
453{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 int over;
455 int rounding;
456
Harvey Harrison5ae12172008-04-28 02:15:47 -0700457 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 switch (bpp) {
460 case 0: return xres;
461 case 4: rounding = 128;
462 break;
463 case 8: rounding = 64; /* doc says 64; 32 is OK for G400 */
464 break;
465 case 16: rounding = 32;
466 break;
467 case 24: rounding = 64; /* doc says 64; 32 is OK for G400 */
468 break;
469 default: rounding = 16;
470 /* on G400, 16 really does not work */
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700471 if (minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG400)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 rounding = 32;
473 break;
474 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700475 if (isInterleave(minfo)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 rounding *= 2;
477 }
478 over = xres % rounding;
479 if (over)
480 xres += rounding-over;
481 return xres;
482}
483
Jean Delvare316b4d62009-09-22 16:47:49 -0700484static int matroxfb_pitch_adjust(const struct matrox_fb_info *minfo, int xres,
485 int bpp)
486{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 const int* width;
488 int xres_new;
489
Harvey Harrison5ae12172008-04-28 02:15:47 -0700490 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 if (!bpp) return xres;
493
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700494 width = minfo->capable.vxres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700496 if (minfo->devflags.precise_width) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 while (*width) {
Jean Delvare316b4d62009-09-22 16:47:49 -0700498 if ((*width >= xres) && (matroxfb_test_and_set_rounding(minfo, *width, bpp) == *width)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 break;
500 }
501 width++;
502 }
503 xres_new = *width;
504 } else {
Jean Delvare316b4d62009-09-22 16:47:49 -0700505 xres_new = matroxfb_test_and_set_rounding(minfo, xres, bpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 return xres_new;
508}
509
510static int matroxfb_get_cmap_len(struct fb_var_screeninfo *var) {
511
Harvey Harrison5ae12172008-04-28 02:15:47 -0700512 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 switch (var->bits_per_pixel) {
515 case 4:
516 return 16; /* pseudocolor... 16 entries HW palette */
517 case 8:
518 return 256; /* pseudocolor... 256 entries HW palette */
519 case 16:
520 return 16; /* directcolor... 16 entries SW palette */
521 /* Mystique: truecolor, 16 entries SW palette, HW palette hardwired into 1:1 mapping */
522 case 24:
523 return 16; /* directcolor... 16 entries SW palette */
524 /* Mystique: truecolor, 16 entries SW palette, HW palette hardwired into 1:1 mapping */
525 case 32:
526 return 16; /* directcolor... 16 entries SW palette */
527 /* Mystique: truecolor, 16 entries SW palette, HW palette hardwired into 1:1 mapping */
528 }
529 return 16; /* return something reasonable... or panic()? */
530}
531
Jean Delvare316b4d62009-09-22 16:47:49 -0700532static int matroxfb_decode_var(const struct matrox_fb_info *minfo,
533 struct fb_var_screeninfo *var, int *visual,
534 int *video_cmap_len, unsigned int* ydstorg)
535{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 struct RGBT {
537 unsigned char bpp;
538 struct {
539 unsigned char offset,
540 length;
541 } red,
542 green,
543 blue,
544 transp;
545 signed char visual;
546 };
547 static const struct RGBT table[]= {
548 { 8,{ 0,8},{0,8},{0,8},{ 0,0},MX_VISUAL_PSEUDOCOLOR},
549 {15,{10,5},{5,5},{0,5},{15,1},MX_VISUAL_DIRECTCOLOR},
550 {16,{11,5},{5,6},{0,5},{ 0,0},MX_VISUAL_DIRECTCOLOR},
551 {24,{16,8},{8,8},{0,8},{ 0,0},MX_VISUAL_DIRECTCOLOR},
552 {32,{16,8},{8,8},{0,8},{24,8},MX_VISUAL_DIRECTCOLOR}
553 };
554 struct RGBT const *rgbt;
555 unsigned int bpp = var->bits_per_pixel;
556 unsigned int vramlen;
557 unsigned int memlen;
558
Harvey Harrison5ae12172008-04-28 02:15:47 -0700559 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 switch (bpp) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700562 case 4: if (!minfo->capable.cfb4) return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 break;
564 case 8: break;
565 case 16: break;
566 case 24: break;
567 case 32: break;
568 default: return -EINVAL;
569 }
570 *ydstorg = 0;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700571 vramlen = minfo->video.len_usable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 if (var->yres_virtual < var->yres)
573 var->yres_virtual = var->yres;
574 if (var->xres_virtual < var->xres)
575 var->xres_virtual = var->xres;
576
Jean Delvare316b4d62009-09-22 16:47:49 -0700577 var->xres_virtual = matroxfb_pitch_adjust(minfo, var->xres_virtual, bpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 memlen = var->xres_virtual * bpp * var->yres_virtual / 8;
579 if (memlen > vramlen) {
580 var->yres_virtual = vramlen * 8 / (var->xres_virtual * bpp);
581 memlen = var->xres_virtual * bpp * var->yres_virtual / 8;
582 }
583 /* There is hardware bug that no line can cross 4MB boundary */
584 /* give up for CFB24, it is impossible to easy workaround it */
585 /* for other try to do something */
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700586 if (!minfo->capable.cross4MB && (memlen > 0x400000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 if (bpp == 24) {
588 /* sorry */
589 } else {
590 unsigned int linelen;
591 unsigned int m1 = linelen = var->xres_virtual * bpp / 8;
592 unsigned int m2 = PAGE_SIZE; /* or 128 if you do not need PAGE ALIGNED address */
593 unsigned int max_yres;
594
595 while (m1) {
596 int t;
597
598 while (m2 >= m1) m2 -= m1;
599 t = m1;
600 m1 = m2;
601 m2 = t;
602 }
603 m2 = linelen * PAGE_SIZE / m2;
604 *ydstorg = m2 = 0x400000 % m2;
605 max_yres = (vramlen - m2) / linelen;
606 if (var->yres_virtual > max_yres)
607 var->yres_virtual = max_yres;
608 }
609 }
610 /* YDSTLEN contains only signed 16bit value */
611 if (var->yres_virtual > 32767)
612 var->yres_virtual = 32767;
613 /* we must round yres/xres down, we already rounded y/xres_virtual up
614 if it was possible. We should return -EINVAL, but I disagree */
615 if (var->yres_virtual < var->yres)
616 var->yres = var->yres_virtual;
617 if (var->xres_virtual < var->xres)
618 var->xres = var->xres_virtual;
619 if (var->xoffset + var->xres > var->xres_virtual)
620 var->xoffset = var->xres_virtual - var->xres;
621 if (var->yoffset + var->yres > var->yres_virtual)
622 var->yoffset = var->yres_virtual - var->yres;
623
624 if (bpp == 16 && var->green.length == 5) {
625 bpp--; /* an artifical value - 15 */
626 }
627
628 for (rgbt = table; rgbt->bpp < bpp; rgbt++);
629#define SETCLR(clr)\
630 var->clr.offset = rgbt->clr.offset;\
631 var->clr.length = rgbt->clr.length
632 SETCLR(red);
633 SETCLR(green);
634 SETCLR(blue);
635 SETCLR(transp);
636#undef SETCLR
637 *visual = rgbt->visual;
638
639 if (bpp > 8)
640 dprintk("matroxfb: truecolor: "
641 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
642 var->transp.length, var->red.length, var->green.length, var->blue.length,
643 var->transp.offset, var->red.offset, var->green.offset, var->blue.offset);
644
645 *video_cmap_len = matroxfb_get_cmap_len(var);
646 dprintk(KERN_INFO "requested %d*%d/%dbpp (%d*%d)\n", var->xres, var->yres, var->bits_per_pixel,
647 var->xres_virtual, var->yres_virtual);
648 return 0;
649}
650
651static int matroxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
652 unsigned blue, unsigned transp,
653 struct fb_info *fb_info)
654{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 struct matrox_fb_info* minfo = container_of(fb_info, struct matrox_fb_info, fbcon);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Harvey Harrison5ae12172008-04-28 02:15:47 -0700657 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /*
660 * Set a single color register. The values supplied are
661 * already rounded down to the hardware's capabilities
662 * (according to the entries in the `var' structure). Return
663 * != 0 for invalid regno.
664 */
665
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700666 if (regno >= minfo->curr.cmap_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 return 1;
668
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700669 if (minfo->fbcon.var.grayscale) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /* gray = 0.30*R + 0.59*G + 0.11*B */
671 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
672 }
673
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700674 red = CNVT_TOHW(red, minfo->fbcon.var.red.length);
675 green = CNVT_TOHW(green, minfo->fbcon.var.green.length);
676 blue = CNVT_TOHW(blue, minfo->fbcon.var.blue.length);
677 transp = CNVT_TOHW(transp, minfo->fbcon.var.transp.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700679 switch (minfo->fbcon.var.bits_per_pixel) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 case 4:
681 case 8:
682 mga_outb(M_DAC_REG, regno);
683 mga_outb(M_DAC_VAL, red);
684 mga_outb(M_DAC_VAL, green);
685 mga_outb(M_DAC_VAL, blue);
686 break;
687 case 16:
Antonino A. Daplas08a498d2007-07-17 04:05:45 -0700688 if (regno >= 16)
689 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 {
691 u_int16_t col =
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700692 (red << minfo->fbcon.var.red.offset) |
693 (green << minfo->fbcon.var.green.offset) |
694 (blue << minfo->fbcon.var.blue.offset) |
695 (transp << minfo->fbcon.var.transp.offset); /* for 1:5:5:5 */
696 minfo->cmap[regno] = col | (col << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 }
698 break;
699 case 24:
700 case 32:
Antonino A. Daplas08a498d2007-07-17 04:05:45 -0700701 if (regno >= 16)
702 break;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700703 minfo->cmap[regno] =
704 (red << minfo->fbcon.var.red.offset) |
705 (green << minfo->fbcon.var.green.offset) |
706 (blue << minfo->fbcon.var.blue.offset) |
707 (transp << minfo->fbcon.var.transp.offset); /* 8:8:8:8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 break;
709 }
710 return 0;
711}
712
Jean Delvare316b4d62009-09-22 16:47:49 -0700713static void matroxfb_init_fix(struct matrox_fb_info *minfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714{
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700715 struct fb_fix_screeninfo *fix = &minfo->fbcon.fix;
Harvey Harrison5ae12172008-04-28 02:15:47 -0700716 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 strcpy(fix->id,"MATROX");
719
720 fix->xpanstep = 8; /* 8 for 8bpp, 4 for 16bpp, 2 for 32bpp */
721 fix->ypanstep = 1;
722 fix->ywrapstep = 0;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700723 fix->mmio_start = minfo->mmio.base;
724 fix->mmio_len = minfo->mmio.len;
725 fix->accel = minfo->devflags.accelerator;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726}
727
Jean Delvare316b4d62009-09-22 16:47:49 -0700728static void matroxfb_update_fix(struct matrox_fb_info *minfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700730 struct fb_fix_screeninfo *fix = &minfo->fbcon.fix;
Harvey Harrison5ae12172008-04-28 02:15:47 -0700731 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700733 mutex_lock(&minfo->fbcon.mm_lock);
734 fix->smem_start = minfo->video.base + minfo->curr.ydstorg.bytes;
735 fix->smem_len = minfo->video.len_usable - minfo->curr.ydstorg.bytes;
736 mutex_unlock(&minfo->fbcon.mm_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737}
738
739static int matroxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
740{
741 int err;
742 int visual;
743 int cmap_len;
744 unsigned int ydstorg;
Jean Delvareee5a2742009-09-22 16:47:50 -0700745 struct matrox_fb_info *minfo = info2minfo(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700747 if (minfo->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 return -ENXIO;
749 }
Jean Delvare316b4d62009-09-22 16:47:49 -0700750 if ((err = matroxfb_decode_var(minfo, var, &visual, &cmap_len, &ydstorg)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 return err;
752 return 0;
753}
754
755static int matroxfb_set_par(struct fb_info *info)
756{
757 int err;
758 int visual;
759 int cmap_len;
760 unsigned int ydstorg;
761 struct fb_var_screeninfo *var;
Jean Delvareee5a2742009-09-22 16:47:50 -0700762 struct matrox_fb_info *minfo = info2minfo(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Harvey Harrison5ae12172008-04-28 02:15:47 -0700764 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700766 if (minfo->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 return -ENXIO;
768 }
769
770 var = &info->var;
Jean Delvare316b4d62009-09-22 16:47:49 -0700771 if ((err = matroxfb_decode_var(minfo, var, &visual, &cmap_len, &ydstorg)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 return err;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700773 minfo->fbcon.screen_base = vaddr_va(minfo->video.vbase) + ydstorg;
Jean Delvare316b4d62009-09-22 16:47:49 -0700774 matroxfb_update_fix(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700775 minfo->fbcon.fix.visual = visual;
776 minfo->fbcon.fix.type = FB_TYPE_PACKED_PIXELS;
777 minfo->fbcon.fix.type_aux = 0;
778 minfo->fbcon.fix.line_length = (var->xres_virtual * var->bits_per_pixel) >> 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 {
780 unsigned int pos;
781
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700782 minfo->curr.cmap_len = cmap_len;
783 ydstorg += minfo->devflags.ydstorg;
784 minfo->curr.ydstorg.bytes = ydstorg;
785 minfo->curr.ydstorg.chunks = ydstorg >> (isInterleave(minfo) ? 3 : 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 if (var->bits_per_pixel == 4)
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700787 minfo->curr.ydstorg.pixels = ydstorg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 else
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700789 minfo->curr.ydstorg.pixels = (ydstorg * 8) / var->bits_per_pixel;
Jean Delvare316b4d62009-09-22 16:47:49 -0700790 minfo->curr.final_bppShift = matroxfb_get_final_bppShift(minfo, var->bits_per_pixel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 { struct my_timming mt;
792 struct matrox_hw_state* hw;
793 int out;
794
795 matroxfb_var2my(var, &mt);
796 mt.crtc = MATROXFB_SRC_CRTC1;
797 /* CRTC1 delays */
798 switch (var->bits_per_pixel) {
799 case 0: mt.delay = 31 + 0; break;
800 case 16: mt.delay = 21 + 8; break;
801 case 24: mt.delay = 17 + 8; break;
802 case 32: mt.delay = 16 + 8; break;
803 default: mt.delay = 31 + 8; break;
804 }
805
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700806 hw = &minfo->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700808 down_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700810 if (minfo->outputs[out].src == MATROXFB_SRC_CRTC1 &&
811 minfo->outputs[out].output->compute) {
812 minfo->outputs[out].output->compute(minfo->outputs[out].data, &mt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 }
814 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700815 up_read(&minfo->altout.lock);
816 minfo->crtc1.pixclock = mt.pixclock;
817 minfo->crtc1.mnp = mt.mnp;
Jean Delvare316b4d62009-09-22 16:47:49 -0700818 minfo->hw_switch->init(minfo, &mt);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700819 pos = (var->yoffset * var->xres_virtual + var->xoffset) * minfo->curr.final_bppShift / 32;
820 pos += minfo->curr.ydstorg.chunks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 hw->CRTC[0x0D] = pos & 0xFF;
823 hw->CRTC[0x0C] = (pos & 0xFF00) >> 8;
824 hw->CRTCEXT[0] = (hw->CRTCEXT[0] & 0xF0) | ((pos >> 16) & 0x0F) | ((pos >> 14) & 0x40);
825 hw->CRTCEXT[8] = pos >> 21;
Jean Delvare316b4d62009-09-22 16:47:49 -0700826 minfo->hw_switch->restore(minfo);
827 update_crtc2(minfo, pos);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700828 down_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700830 if (minfo->outputs[out].src == MATROXFB_SRC_CRTC1 &&
831 minfo->outputs[out].output->program) {
832 minfo->outputs[out].output->program(minfo->outputs[out].data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 }
834 }
835 for (out = 0; out < MATROXFB_MAX_OUTPUTS; out++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700836 if (minfo->outputs[out].src == MATROXFB_SRC_CRTC1 &&
837 minfo->outputs[out].output->start) {
838 minfo->outputs[out].output->start(minfo->outputs[out].data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 }
840 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700841 up_read(&minfo->altout.lock);
Jean Delvare316b4d62009-09-22 16:47:49 -0700842 matrox_cfbX_init(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
844 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700845 minfo->initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 return 0;
847}
848
Jean Delvare316b4d62009-09-22 16:47:49 -0700849static int matroxfb_get_vblank(struct matrox_fb_info *minfo,
850 struct fb_vblank *vblank)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
852 unsigned int sts1;
853
Jean Delvare316b4d62009-09-22 16:47:49 -0700854 matroxfb_enable_irq(minfo, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 memset(vblank, 0, sizeof(*vblank));
856 vblank->flags = FB_VBLANK_HAVE_VCOUNT | FB_VBLANK_HAVE_VSYNC |
857 FB_VBLANK_HAVE_VBLANK | FB_VBLANK_HAVE_HBLANK;
858 sts1 = mga_inb(M_INSTS1);
859 vblank->vcount = mga_inl(M_VCOUNT);
860 /* BTW, on my PIII/450 with G400, reading M_INSTS1
861 byte makes this call about 12% slower (1.70 vs. 2.05 us
862 per ioctl()) */
863 if (sts1 & 1)
864 vblank->flags |= FB_VBLANK_HBLANKING;
865 if (sts1 & 8)
866 vblank->flags |= FB_VBLANK_VSYNCING;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700867 if (vblank->vcount >= minfo->fbcon.var.yres)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 vblank->flags |= FB_VBLANK_VBLANKING;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700869 if (test_bit(0, &minfo->irq_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 vblank->flags |= FB_VBLANK_HAVE_COUNT;
Andrew Mortona50d9132006-06-21 01:57:39 -0300871 /* Only one writer, aligned int value...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 it should work without lock and without atomic_t */
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700873 vblank->count = minfo->crtc1.vsync.cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 }
875 return 0;
876}
877
878static struct matrox_altout panellink_output = {
879 .name = "Panellink output",
880};
881
Christoph Hellwig67a66802006-01-14 13:21:25 -0800882static int matroxfb_ioctl(struct fb_info *info,
883 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
885 void __user *argp = (void __user *)arg;
Jean Delvareee5a2742009-09-22 16:47:50 -0700886 struct matrox_fb_info *minfo = info2minfo(info);
Andrew Mortona50d9132006-06-21 01:57:39 -0300887
Harvey Harrison5ae12172008-04-28 02:15:47 -0700888 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700890 if (minfo->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 return -ENXIO;
892 }
893
894 switch (cmd) {
895 case FBIOGET_VBLANK:
896 {
897 struct fb_vblank vblank;
898 int err;
899
Jean Delvare316b4d62009-09-22 16:47:49 -0700900 err = matroxfb_get_vblank(minfo, &vblank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 if (err)
902 return err;
903 if (copy_to_user(argp, &vblank, sizeof(vblank)))
904 return -EFAULT;
905 return 0;
906 }
907 case FBIO_WAITFORVSYNC:
908 {
909 u_int32_t crt;
910
911 if (get_user(crt, (u_int32_t __user *)arg))
912 return -EFAULT;
913
Jean Delvare316b4d62009-09-22 16:47:49 -0700914 return matroxfb_wait_for_sync(minfo, crt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
916 case MATROXFB_SET_OUTPUT_MODE:
917 {
918 struct matroxioc_output_mode mom;
919 struct matrox_altout *oproc;
920 int val;
921
922 if (copy_from_user(&mom, argp, sizeof(mom)))
923 return -EFAULT;
924 if (mom.output >= MATROXFB_MAX_OUTPUTS)
925 return -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700926 down_read(&minfo->altout.lock);
927 oproc = minfo->outputs[mom.output].output;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 if (!oproc) {
929 val = -ENXIO;
930 } else if (!oproc->verifymode) {
931 if (mom.mode == MATROXFB_OUTPUT_MODE_MONITOR) {
932 val = 0;
933 } else {
934 val = -EINVAL;
935 }
936 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700937 val = oproc->verifymode(minfo->outputs[mom.output].data, mom.mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 }
939 if (!val) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700940 if (minfo->outputs[mom.output].mode != mom.mode) {
941 minfo->outputs[mom.output].mode = mom.mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 val = 1;
943 }
944 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700945 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 if (val != 1)
947 return val;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700948 switch (minfo->outputs[mom.output].src) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 case MATROXFB_SRC_CRTC1:
950 matroxfb_set_par(info);
951 break;
952 case MATROXFB_SRC_CRTC2:
953 {
954 struct matroxfb_dh_fb_info* crtc2;
955
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700956 down_read(&minfo->crtc2.lock);
957 crtc2 = minfo->crtc2.info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 if (crtc2)
959 crtc2->fbcon.fbops->fb_set_par(&crtc2->fbcon);
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700960 up_read(&minfo->crtc2.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 }
962 break;
963 }
964 return 0;
965 }
966 case MATROXFB_GET_OUTPUT_MODE:
967 {
968 struct matroxioc_output_mode mom;
969 struct matrox_altout *oproc;
970 int val;
971
972 if (copy_from_user(&mom, argp, sizeof(mom)))
973 return -EFAULT;
974 if (mom.output >= MATROXFB_MAX_OUTPUTS)
975 return -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700976 down_read(&minfo->altout.lock);
977 oproc = minfo->outputs[mom.output].output;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 if (!oproc) {
979 val = -ENXIO;
980 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700981 mom.mode = minfo->outputs[mom.output].mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 val = 0;
983 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -0700984 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 if (val)
986 return val;
987 if (copy_to_user(argp, &mom, sizeof(mom)))
988 return -EFAULT;
989 return 0;
990 }
991 case MATROXFB_SET_OUTPUT_CONNECTION:
992 {
993 u_int32_t tmp;
994 int i;
995 int changes;
996
997 if (copy_from_user(&tmp, argp, sizeof(tmp)))
998 return -EFAULT;
999 for (i = 0; i < 32; i++) {
1000 if (tmp & (1 << i)) {
1001 if (i >= MATROXFB_MAX_OUTPUTS)
1002 return -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001003 if (!minfo->outputs[i].output)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 return -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001005 switch (minfo->outputs[i].src) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 case MATROXFB_SRC_NONE:
1007 case MATROXFB_SRC_CRTC1:
1008 break;
1009 default:
1010 return -EBUSY;
1011 }
1012 }
1013 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001014 if (minfo->devflags.panellink) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (tmp & MATROXFB_OUTPUT_CONN_DFP) {
1016 if (tmp & MATROXFB_OUTPUT_CONN_SECONDARY)
1017 return -EINVAL;
1018 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001019 if (minfo->outputs[i].src == MATROXFB_SRC_CRTC2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 return -EBUSY;
1021 }
1022 }
1023 }
1024 }
1025 changes = 0;
1026 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
1027 if (tmp & (1 << i)) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001028 if (minfo->outputs[i].src != MATROXFB_SRC_CRTC1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 changes = 1;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001030 minfo->outputs[i].src = MATROXFB_SRC_CRTC1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001032 } else if (minfo->outputs[i].src == MATROXFB_SRC_CRTC1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 changes = 1;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001034 minfo->outputs[i].src = MATROXFB_SRC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
1036 }
1037 if (!changes)
1038 return 0;
1039 matroxfb_set_par(info);
1040 return 0;
1041 }
1042 case MATROXFB_GET_OUTPUT_CONNECTION:
1043 {
1044 u_int32_t conn = 0;
1045 int i;
1046
1047 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001048 if (minfo->outputs[i].src == MATROXFB_SRC_CRTC1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 conn |= 1 << i;
1050 }
1051 }
1052 if (put_user(conn, (u_int32_t __user *)arg))
1053 return -EFAULT;
1054 return 0;
1055 }
1056 case MATROXFB_GET_AVAILABLE_OUTPUTS:
1057 {
1058 u_int32_t conn = 0;
1059 int i;
1060
1061 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001062 if (minfo->outputs[i].output) {
1063 switch (minfo->outputs[i].src) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 case MATROXFB_SRC_NONE:
1065 case MATROXFB_SRC_CRTC1:
1066 conn |= 1 << i;
1067 break;
1068 }
1069 }
1070 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001071 if (minfo->devflags.panellink) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 if (conn & MATROXFB_OUTPUT_CONN_DFP)
1073 conn &= ~MATROXFB_OUTPUT_CONN_SECONDARY;
1074 if (conn & MATROXFB_OUTPUT_CONN_SECONDARY)
1075 conn &= ~MATROXFB_OUTPUT_CONN_DFP;
1076 }
1077 if (put_user(conn, (u_int32_t __user *)arg))
1078 return -EFAULT;
1079 return 0;
1080 }
1081 case MATROXFB_GET_ALL_OUTPUTS:
1082 {
1083 u_int32_t conn = 0;
1084 int i;
1085
1086 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001087 if (minfo->outputs[i].output) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 conn |= 1 << i;
1089 }
1090 }
1091 if (put_user(conn, (u_int32_t __user *)arg))
1092 return -EFAULT;
1093 return 0;
1094 }
1095 case VIDIOC_QUERYCAP:
1096 {
1097 struct v4l2_capability r;
Andrew Mortona50d9132006-06-21 01:57:39 -03001098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 memset(&r, 0, sizeof(r));
1100 strcpy(r.driver, "matroxfb");
1101 strcpy(r.card, "Matrox");
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001102 sprintf(r.bus_info, "PCI:%s", pci_name(minfo->pcidev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 r.version = KERNEL_VERSION(1,0,0);
1104 r.capabilities = V4L2_CAP_VIDEO_OUTPUT;
1105 if (copy_to_user(argp, &r, sizeof(r)))
1106 return -EFAULT;
1107 return 0;
Andrew Mortona50d9132006-06-21 01:57:39 -03001108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 }
1110 case VIDIOC_QUERYCTRL:
1111 {
1112 struct v4l2_queryctrl qctrl;
1113 int err;
1114
1115 if (copy_from_user(&qctrl, argp, sizeof(qctrl)))
1116 return -EFAULT;
1117
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001118 down_read(&minfo->altout.lock);
1119 if (!minfo->outputs[1].output) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 err = -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001121 } else if (minfo->outputs[1].output->getqueryctrl) {
1122 err = minfo->outputs[1].output->getqueryctrl(minfo->outputs[1].data, &qctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 } else {
1124 err = -EINVAL;
1125 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001126 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 if (err >= 0 &&
1128 copy_to_user(argp, &qctrl, sizeof(qctrl)))
1129 return -EFAULT;
1130 return err;
1131 }
1132 case VIDIOC_G_CTRL:
1133 {
1134 struct v4l2_control ctrl;
1135 int err;
1136
1137 if (copy_from_user(&ctrl, argp, sizeof(ctrl)))
1138 return -EFAULT;
1139
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001140 down_read(&minfo->altout.lock);
1141 if (!minfo->outputs[1].output) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 err = -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001143 } else if (minfo->outputs[1].output->getctrl) {
1144 err = minfo->outputs[1].output->getctrl(minfo->outputs[1].data, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 } else {
1146 err = -EINVAL;
1147 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001148 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 if (err >= 0 &&
1150 copy_to_user(argp, &ctrl, sizeof(ctrl)))
1151 return -EFAULT;
1152 return err;
1153 }
1154 case VIDIOC_S_CTRL_OLD:
1155 case VIDIOC_S_CTRL:
1156 {
1157 struct v4l2_control ctrl;
1158 int err;
1159
1160 if (copy_from_user(&ctrl, argp, sizeof(ctrl)))
1161 return -EFAULT;
1162
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001163 down_read(&minfo->altout.lock);
1164 if (!minfo->outputs[1].output) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 err = -ENXIO;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001166 } else if (minfo->outputs[1].output->setctrl) {
1167 err = minfo->outputs[1].output->setctrl(minfo->outputs[1].data, &ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 } else {
1169 err = -EINVAL;
1170 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001171 up_read(&minfo->altout.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 return err;
1173 }
1174 }
1175 return -ENOTTY;
1176}
1177
1178/* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
1179
1180static int matroxfb_blank(int blank, struct fb_info *info)
1181{
1182 int seq;
1183 int crtc;
1184 CRITFLAGS
Jean Delvareee5a2742009-09-22 16:47:50 -07001185 struct matrox_fb_info *minfo = info2minfo(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
Harvey Harrison5ae12172008-04-28 02:15:47 -07001187 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001189 if (minfo->dead)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 return 1;
1191
1192 switch (blank) {
1193 case FB_BLANK_NORMAL: seq = 0x20; crtc = 0x00; break; /* works ??? */
1194 case FB_BLANK_VSYNC_SUSPEND: seq = 0x20; crtc = 0x10; break;
1195 case FB_BLANK_HSYNC_SUSPEND: seq = 0x20; crtc = 0x20; break;
1196 case FB_BLANK_POWERDOWN: seq = 0x20; crtc = 0x30; break;
1197 default: seq = 0x00; crtc = 0x00; break;
1198 }
1199
1200 CRITBEGIN
1201
1202 mga_outb(M_SEQ_INDEX, 1);
1203 mga_outb(M_SEQ_DATA, (mga_inb(M_SEQ_DATA) & ~0x20) | seq);
1204 mga_outb(M_EXTVGA_INDEX, 1);
1205 mga_outb(M_EXTVGA_DATA, (mga_inb(M_EXTVGA_DATA) & ~0x30) | crtc);
1206
1207 CRITEND
1208 return 0;
1209}
1210
1211static struct fb_ops matroxfb_ops = {
1212 .owner = THIS_MODULE,
1213 .fb_open = matroxfb_open,
1214 .fb_release = matroxfb_release,
1215 .fb_check_var = matroxfb_check_var,
1216 .fb_set_par = matroxfb_set_par,
1217 .fb_setcolreg = matroxfb_setcolreg,
1218 .fb_pan_display =matroxfb_pan_display,
1219 .fb_blank = matroxfb_blank,
1220 .fb_ioctl = matroxfb_ioctl,
1221/* .fb_fillrect = <set by matrox_cfbX_init>, */
1222/* .fb_copyarea = <set by matrox_cfbX_init>, */
1223/* .fb_imageblit = <set by matrox_cfbX_init>, */
1224/* .fb_cursor = <set by matrox_cfbX_init>, */
1225};
1226
1227#define RSDepth(X) (((X) >> 8) & 0x0F)
1228#define RS8bpp 0x1
1229#define RS15bpp 0x2
1230#define RS16bpp 0x3
1231#define RS32bpp 0x4
1232#define RS4bpp 0x5
1233#define RS24bpp 0x6
1234#define RSText 0x7
1235#define RSText8 0x8
1236/* 9-F */
1237static struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
1238 { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 8 },
1239 { { 10, 5, 0}, { 5, 5, 0}, { 0, 5, 0}, { 15, 1, 0}, 16 },
1240 { { 11, 5, 0}, { 5, 6, 0}, { 0, 5, 0}, { 0, 0, 0}, 16 },
1241 { { 16, 8, 0}, { 8, 8, 0}, { 0, 8, 0}, { 24, 8, 0}, 32 },
1242 { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 4 },
1243 { { 16, 8, 0}, { 8, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 24 },
1244 { { 0, 6, 0}, { 0, 6, 0}, { 0, 6, 0}, { 0, 0, 0}, 0 }, /* textmode with (default) VGA8x16 */
1245 { { 0, 6, 0}, { 0, 6, 0}, { 0, 6, 0}, { 0, 0, 0}, 0 }, /* textmode hardwired to VGA8x8 */
1246};
1247
1248/* initialized by setup, see explanation at end of file (search for MODULE_PARM_DESC) */
1249static unsigned int mem; /* "matrox:mem:xxxxxM" */
1250static int option_precise_width = 1; /* cannot be changed, option_precise_width==0 must imply noaccel */
1251static int inv24; /* "matrox:inv24" */
1252static int cross4MB = -1; /* "matrox:cross4MB" */
1253static int disabled; /* "matrox:disabled" */
1254static int noaccel; /* "matrox:noaccel" */
1255static int nopan; /* "matrox:nopan" */
1256static int no_pci_retry; /* "matrox:nopciretry" */
1257static int novga; /* "matrox:novga" */
1258static int nobios; /* "matrox:nobios" */
1259static int noinit = 1; /* "matrox:init" */
1260static int inverse; /* "matrox:inverse" */
1261static int sgram; /* "matrox:sgram" */
1262#ifdef CONFIG_MTRR
1263static int mtrr = 1; /* "matrox:nomtrr" */
1264#endif
1265static int grayscale; /* "matrox:grayscale" */
1266static int dev = -1; /* "matrox:dev:xxxxx" */
1267static unsigned int vesa = ~0; /* "matrox:vesa:xxxxx" */
1268static int depth = -1; /* "matrox:depth:xxxxx" */
1269static unsigned int xres; /* "matrox:xres:xxxxx" */
1270static unsigned int yres; /* "matrox:yres:xxxxx" */
1271static unsigned int upper = ~0; /* "matrox:upper:xxxxx" */
1272static unsigned int lower = ~0; /* "matrox:lower:xxxxx" */
1273static unsigned int vslen; /* "matrox:vslen:xxxxx" */
1274static unsigned int left = ~0; /* "matrox:left:xxxxx" */
1275static unsigned int right = ~0; /* "matrox:right:xxxxx" */
1276static unsigned int hslen; /* "matrox:hslen:xxxxx" */
1277static unsigned int pixclock; /* "matrox:pixclock:xxxxx" */
1278static int sync = -1; /* "matrox:sync:xxxxx" */
1279static unsigned int fv; /* "matrox:fv:xxxxx" */
1280static unsigned int fh; /* "matrox:fh:xxxxxk" */
1281static unsigned int maxclk; /* "matrox:maxclk:xxxxM" */
1282static int dfp; /* "matrox:dfp */
1283static int dfp_type = -1; /* "matrox:dfp:xxx */
1284static int memtype = -1; /* "matrox:memtype:xxx" */
1285static char outputs[8]; /* "matrox:outputs:xxx" */
1286
1287#ifndef MODULE
1288static char videomode[64]; /* "matrox:mode:xxxxx" or "matrox:xxxxx" */
1289#endif
1290
Jean Delvare316b4d62009-09-22 16:47:49 -07001291static int matroxfb_getmemory(struct matrox_fb_info *minfo,
1292 unsigned int maxSize, unsigned int *realSize)
1293{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 vaddr_t vm;
1295 unsigned int offs;
1296 unsigned int offs2;
Ville Syrjälä6c12f302005-11-07 01:00:58 -08001297 unsigned char orig;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 unsigned char bytes[32];
1299 unsigned char* tmp;
1300
Harvey Harrison5ae12172008-04-28 02:15:47 -07001301 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001303 vm = minfo->video.vbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 maxSize &= ~0x1FFFFF; /* must be X*2MB (really it must be 2 or X*4MB) */
1305 /* at least 2MB */
1306 if (maxSize < 0x0200000) return 0;
1307 if (maxSize > 0x2000000) maxSize = 0x2000000;
1308
1309 mga_outb(M_EXTVGA_INDEX, 0x03);
Jan Beulich438e5c52005-09-13 01:25:45 -07001310 orig = mga_inb(M_EXTVGA_DATA);
1311 mga_outb(M_EXTVGA_DATA, orig | 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 tmp = bytes;
1314 for (offs = 0x100000; offs < maxSize; offs += 0x200000)
1315 *tmp++ = mga_readb(vm, offs);
1316 for (offs = 0x100000; offs < maxSize; offs += 0x200000)
1317 mga_writeb(vm, offs, 0x02);
Ville Syrjälä6c12f302005-11-07 01:00:58 -08001318 mga_outb(M_CACHEFLUSH, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 for (offs = 0x100000; offs < maxSize; offs += 0x200000) {
1320 if (mga_readb(vm, offs) != 0x02)
1321 break;
1322 mga_writeb(vm, offs, mga_readb(vm, offs) - 0x02);
1323 if (mga_readb(vm, offs))
1324 break;
1325 }
1326 tmp = bytes;
1327 for (offs2 = 0x100000; offs2 < maxSize; offs2 += 0x200000)
1328 mga_writeb(vm, offs2, *tmp++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
1330 mga_outb(M_EXTVGA_INDEX, 0x03);
Jan Beulich438e5c52005-09-13 01:25:45 -07001331 mga_outb(M_EXTVGA_DATA, orig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 *realSize = offs - 0x100000;
1334#ifdef CONFIG_FB_MATROX_MILLENIUM
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001335 minfo->interleave = !(!isMillenium(minfo) || ((offs - 0x100000) & 0x3FFFFF));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336#endif
1337 return 1;
1338}
1339
1340struct video_board {
1341 int maxvram;
1342 int maxdisplayable;
1343 int accelID;
1344 struct matrox_switch* lowlevel;
1345 };
1346#ifdef CONFIG_FB_MATROX_MILLENIUM
1347static struct video_board vbMillennium = {0x0800000, 0x0800000, FB_ACCEL_MATROX_MGA2064W, &matrox_millennium};
1348static struct video_board vbMillennium2 = {0x1000000, 0x0800000, FB_ACCEL_MATROX_MGA2164W, &matrox_millennium};
1349static struct video_board vbMillennium2A = {0x1000000, 0x0800000, FB_ACCEL_MATROX_MGA2164W_AGP, &matrox_millennium};
1350#endif /* CONFIG_FB_MATROX_MILLENIUM */
1351#ifdef CONFIG_FB_MATROX_MYSTIQUE
1352static struct video_board vbMystique = {0x0800000, 0x0800000, FB_ACCEL_MATROX_MGA1064SG, &matrox_mystique};
1353#endif /* CONFIG_FB_MATROX_MYSTIQUE */
1354#ifdef CONFIG_FB_MATROX_G
1355static struct video_board vbG100 = {0x0800000, 0x0800000, FB_ACCEL_MATROX_MGAG100, &matrox_G100};
1356static struct video_board vbG200 = {0x1000000, 0x1000000, FB_ACCEL_MATROX_MGAG200, &matrox_G100};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357/* from doc it looks like that accelerator can draw only to low 16MB :-( Direct accesses & displaying are OK for
1358 whole 32MB */
1359static struct video_board vbG400 = {0x2000000, 0x1000000, FB_ACCEL_MATROX_MGAG400, &matrox_G100};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360#endif
1361
1362#define DEVF_VIDEO64BIT 0x0001
1363#define DEVF_SWAPS 0x0002
1364#define DEVF_SRCORG 0x0004
1365#define DEVF_DUALHEAD 0x0008
1366#define DEVF_CROSS4MB 0x0010
1367#define DEVF_TEXT4B 0x0020
1368/* #define DEVF_recycled 0x0040 */
1369/* #define DEVF_recycled 0x0080 */
1370#define DEVF_SUPPORT32MB 0x0100
1371#define DEVF_ANY_VXRES 0x0200
1372#define DEVF_TEXT16B 0x0400
1373#define DEVF_CRTC2 0x0800
1374#define DEVF_MAVEN_CAPABLE 0x1000
1375#define DEVF_PANELLINK_CAPABLE 0x2000
1376#define DEVF_G450DAC 0x4000
1377
1378#define DEVF_GCORE (DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB)
1379#define DEVF_G2CORE (DEVF_GCORE | DEVF_ANY_VXRES | DEVF_MAVEN_CAPABLE | DEVF_PANELLINK_CAPABLE | DEVF_SRCORG | DEVF_DUALHEAD)
1380#define DEVF_G100 (DEVF_GCORE) /* no doc, no vxres... */
1381#define DEVF_G200 (DEVF_G2CORE)
1382#define DEVF_G400 (DEVF_G2CORE | DEVF_SUPPORT32MB | DEVF_TEXT16B | DEVF_CRTC2)
1383/* if you'll find how to drive DFP... */
1384#define DEVF_G450 (DEVF_GCORE | DEVF_ANY_VXRES | DEVF_SUPPORT32MB | DEVF_TEXT16B | DEVF_CRTC2 | DEVF_G450DAC | DEVF_SRCORG | DEVF_DUALHEAD)
1385#define DEVF_G550 (DEVF_G450)
1386
1387static struct board {
1388 unsigned short vendor, device, rev, svid, sid;
1389 unsigned int flags;
1390 unsigned int maxclk;
1391 enum mga_chip chip;
1392 struct video_board* base;
1393 const char* name;
1394 } dev_list[] = {
1395#ifdef CONFIG_FB_MATROX_MILLENIUM
1396 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL, 0xFF,
1397 0, 0,
1398 DEVF_TEXT4B,
1399 230000,
1400 MGA_2064,
1401 &vbMillennium,
1402 "Millennium (PCI)"},
1403 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2, 0xFF,
1404 0, 0,
1405 DEVF_SWAPS,
1406 220000,
1407 MGA_2164,
1408 &vbMillennium2,
1409 "Millennium II (PCI)"},
1410 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2_AGP, 0xFF,
1411 0, 0,
1412 DEVF_SWAPS,
1413 250000,
1414 MGA_2164,
1415 &vbMillennium2A,
1416 "Millennium II (AGP)"},
1417#endif
1418#ifdef CONFIG_FB_MATROX_MYSTIQUE
1419 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS, 0x02,
1420 0, 0,
1421 DEVF_VIDEO64BIT | DEVF_CROSS4MB,
1422 180000,
1423 MGA_1064,
1424 &vbMystique,
1425 "Mystique (PCI)"},
1426 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS, 0xFF,
1427 0, 0,
1428 DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB,
1429 220000,
1430 MGA_1164,
1431 &vbMystique,
1432 "Mystique 220 (PCI)"},
Ville Syrjälä63921fb2005-11-07 01:00:57 -08001433 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS_AGP, 0x02,
1434 0, 0,
1435 DEVF_VIDEO64BIT | DEVF_CROSS4MB,
1436 180000,
1437 MGA_1064,
1438 &vbMystique,
1439 "Mystique (AGP)"},
1440 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS_AGP, 0xFF,
1441 0, 0,
1442 DEVF_VIDEO64BIT | DEVF_SWAPS | DEVF_CROSS4MB,
1443 220000,
1444 MGA_1164,
1445 &vbMystique,
1446 "Mystique 220 (AGP)"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447#endif
1448#ifdef CONFIG_FB_MATROX_G
1449 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_MM, 0xFF,
1450 0, 0,
1451 DEVF_G100,
1452 230000,
1453 MGA_G100,
1454 &vbG100,
1455 "MGA-G100 (PCI)"},
1456 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_AGP, 0xFF,
1457 0, 0,
1458 DEVF_G100,
1459 230000,
1460 MGA_G100,
1461 &vbG100,
1462 "MGA-G100 (AGP)"},
Darrick J. Wonge3a19382008-10-15 22:03:52 -07001463 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200EV_PCI, 0xFF,
1464 0, 0,
1465 DEVF_G200,
1466 230000,
1467 MGA_G200,
1468 &vbG200,
1469 "MGA-G200eV (PCI)"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, 0xFF,
1471 0, 0,
1472 DEVF_G200,
1473 250000,
1474 MGA_G200,
1475 &vbG200,
1476 "MGA-G200 (PCI)"},
1477 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1478 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_GENERIC,
1479 DEVF_G200,
1480 220000,
1481 MGA_G200,
1482 &vbG200,
1483 "MGA-G200 (AGP)"},
1484 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1485 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MYSTIQUE_G200_AGP,
1486 DEVF_G200,
1487 230000,
1488 MGA_G200,
1489 &vbG200,
1490 "Mystique G200 (AGP)"},
1491 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1492 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MILLENIUM_G200_AGP,
1493 DEVF_G200,
1494 250000,
1495 MGA_G200,
1496 &vbG200,
1497 "Millennium G200 (AGP)"},
1498 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1499 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MARVEL_G200_AGP,
1500 DEVF_G200,
1501 230000,
1502 MGA_G200,
1503 &vbG200,
1504 "Marvel G200 (AGP)"},
1505 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1506 PCI_SS_VENDOR_ID_SIEMENS_NIXDORF, PCI_SS_ID_SIEMENS_MGA_G200_AGP,
1507 DEVF_G200,
1508 230000,
1509 MGA_G200,
1510 &vbG200,
1511 "MGA-G200 (AGP)"},
1512 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 0xFF,
1513 0, 0,
1514 DEVF_G200,
1515 230000,
1516 MGA_G200,
1517 &vbG200,
1518 "G200 (AGP)"},
1519 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, 0x80,
1520 PCI_SS_VENDOR_ID_MATROX, PCI_SS_ID_MATROX_MILLENNIUM_G400_MAX_AGP,
1521 DEVF_G400,
1522 360000,
1523 MGA_G400,
1524 &vbG400,
1525 "Millennium G400 MAX (AGP)"},
1526 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, 0x80,
1527 0, 0,
1528 DEVF_G400,
1529 300000,
1530 MGA_G400,
1531 &vbG400,
1532 "G400 (AGP)"},
1533 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, 0xFF,
1534 0, 0,
1535 DEVF_G450,
1536 360000,
1537 MGA_G450,
1538 &vbG400,
1539 "G450"},
1540 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G550, 0xFF,
1541 0, 0,
1542 DEVF_G550,
1543 360000,
1544 MGA_G550,
1545 &vbG400,
1546 "G550"},
1547#endif
1548 {0, 0, 0xFF,
1549 0, 0,
1550 0,
1551 0,
1552 0,
1553 NULL,
1554 NULL}};
1555
1556#ifndef MODULE
1557static struct fb_videomode defaultmode = {
1558 /* 640x480 @ 60Hz, 31.5 kHz */
1559 NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
1560 0, FB_VMODE_NONINTERLACED
1561};
1562#endif /* !MODULE */
1563
1564static int hotplug = 0;
1565
Jean Delvare316b4d62009-09-22 16:47:49 -07001566static void setDefaultOutputs(struct matrox_fb_info *minfo)
1567{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 unsigned int i;
1569 const char* ptr;
1570
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001571 minfo->outputs[0].default_src = MATROXFB_SRC_CRTC1;
1572 if (minfo->devflags.g450dac) {
1573 minfo->outputs[1].default_src = MATROXFB_SRC_CRTC1;
1574 minfo->outputs[2].default_src = MATROXFB_SRC_CRTC1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 } else if (dfp) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001576 minfo->outputs[2].default_src = MATROXFB_SRC_CRTC1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 }
1578 ptr = outputs;
1579 for (i = 0; i < MATROXFB_MAX_OUTPUTS; i++) {
1580 char c = *ptr++;
1581
1582 if (c == 0) {
1583 break;
1584 }
1585 if (c == '0') {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001586 minfo->outputs[i].default_src = MATROXFB_SRC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 } else if (c == '1') {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001588 minfo->outputs[i].default_src = MATROXFB_SRC_CRTC1;
1589 } else if (c == '2' && minfo->devflags.crtc2) {
1590 minfo->outputs[i].default_src = MATROXFB_SRC_CRTC2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 } else {
1592 printk(KERN_ERR "matroxfb: Unknown outputs setting\n");
1593 break;
1594 }
1595 }
1596 /* Nullify this option for subsequent adapters */
1597 outputs[0] = 0;
1598}
1599
Jean Delvare316b4d62009-09-22 16:47:49 -07001600static int initMatrox2(struct matrox_fb_info *minfo, struct board *b)
1601{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 unsigned long ctrlptr_phys = 0;
1603 unsigned long video_base_phys = 0;
1604 unsigned int memsize;
1605 int err;
1606
1607 static struct pci_device_id intel_82437[] = {
1608 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437) },
1609 { },
1610 };
1611
Harvey Harrison5ae12172008-04-28 02:15:47 -07001612 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
1614 /* set default values... */
1615 vesafb_defined.accel_flags = FB_ACCELF_TEXT;
1616
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001617 minfo->hw_switch = b->base->lowlevel;
1618 minfo->devflags.accelerator = b->base->accelID;
1619 minfo->max_pixel_clock = b->maxclk;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
1621 printk(KERN_INFO "matroxfb: Matrox %s detected\n", b->name);
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001622 minfo->capable.plnwt = 1;
1623 minfo->chip = b->chip;
1624 minfo->capable.srcorg = b->flags & DEVF_SRCORG;
1625 minfo->devflags.video64bits = b->flags & DEVF_VIDEO64BIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 if (b->flags & DEVF_TEXT4B) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001627 minfo->devflags.vgastep = 4;
1628 minfo->devflags.textmode = 4;
1629 minfo->devflags.text_type_aux = FB_AUX_TEXT_MGA_STEP16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 } else if (b->flags & DEVF_TEXT16B) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001631 minfo->devflags.vgastep = 16;
1632 minfo->devflags.textmode = 1;
1633 minfo->devflags.text_type_aux = FB_AUX_TEXT_MGA_STEP16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001635 minfo->devflags.vgastep = 8;
1636 minfo->devflags.textmode = 1;
1637 minfo->devflags.text_type_aux = FB_AUX_TEXT_MGA_STEP8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001639 minfo->devflags.support32MB = (b->flags & DEVF_SUPPORT32MB) != 0;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001640 minfo->devflags.precise_width = !(b->flags & DEVF_ANY_VXRES);
1641 minfo->devflags.crtc2 = (b->flags & DEVF_CRTC2) != 0;
1642 minfo->devflags.maven_capable = (b->flags & DEVF_MAVEN_CAPABLE) != 0;
1643 minfo->devflags.dualhead = (b->flags & DEVF_DUALHEAD) != 0;
1644 minfo->devflags.dfp_type = dfp_type;
1645 minfo->devflags.g450dac = (b->flags & DEVF_G450DAC) != 0;
1646 minfo->devflags.textstep = minfo->devflags.vgastep * minfo->devflags.textmode;
1647 minfo->devflags.textvram = 65536 / minfo->devflags.textmode;
Jean Delvare316b4d62009-09-22 16:47:49 -07001648 setDefaultOutputs(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 if (b->flags & DEVF_PANELLINK_CAPABLE) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001650 minfo->outputs[2].data = minfo;
1651 minfo->outputs[2].output = &panellink_output;
1652 minfo->outputs[2].src = minfo->outputs[2].default_src;
1653 minfo->outputs[2].mode = MATROXFB_OUTPUT_MODE_MONITOR;
1654 minfo->devflags.panellink = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 }
1656
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001657 if (minfo->capable.cross4MB < 0)
1658 minfo->capable.cross4MB = b->flags & DEVF_CROSS4MB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 if (b->flags & DEVF_SWAPS) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001660 ctrlptr_phys = pci_resource_start(minfo->pcidev, 1);
1661 video_base_phys = pci_resource_start(minfo->pcidev, 0);
1662 minfo->devflags.fbResource = PCI_BASE_ADDRESS_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001664 ctrlptr_phys = pci_resource_start(minfo->pcidev, 0);
1665 video_base_phys = pci_resource_start(minfo->pcidev, 1);
1666 minfo->devflags.fbResource = PCI_BASE_ADDRESS_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 }
1668 err = -EINVAL;
1669 if (!ctrlptr_phys) {
1670 printk(KERN_ERR "matroxfb: control registers are not available, matroxfb disabled\n");
1671 goto fail;
1672 }
1673 if (!video_base_phys) {
1674 printk(KERN_ERR "matroxfb: video RAM is not available in PCI address space, matroxfb disabled\n");
1675 goto fail;
1676 }
1677 memsize = b->base->maxvram;
1678 if (!request_mem_region(ctrlptr_phys, 16384, "matroxfb MMIO")) {
1679 goto fail;
1680 }
1681 if (!request_mem_region(video_base_phys, memsize, "matroxfb FB")) {
1682 goto failCtrlMR;
1683 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001684 minfo->video.len_maximum = memsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 /* convert mem (autodetect k, M) */
1686 if (mem < 1024) mem *= 1024;
1687 if (mem < 0x00100000) mem *= 1024;
1688
1689 if (mem && (mem < memsize))
1690 memsize = mem;
1691 err = -ENOMEM;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001692 if (mga_ioremap(ctrlptr_phys, 16384, MGA_IOREMAP_MMIO, &minfo->mmio.vbase)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 printk(KERN_ERR "matroxfb: cannot ioremap(%lX, 16384), matroxfb disabled\n", ctrlptr_phys);
1694 goto failVideoMR;
1695 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001696 minfo->mmio.base = ctrlptr_phys;
1697 minfo->mmio.len = 16384;
1698 minfo->video.base = video_base_phys;
1699 if (mga_ioremap(video_base_phys, memsize, MGA_IOREMAP_FB, &minfo->video.vbase)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 printk(KERN_ERR "matroxfb: cannot ioremap(%lX, %d), matroxfb disabled\n",
1701 video_base_phys, memsize);
1702 goto failCtrlIO;
1703 }
1704 {
1705 u_int32_t cmd;
1706 u_int32_t mga_option;
1707
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001708 pci_read_config_dword(minfo->pcidev, PCI_OPTION_REG, &mga_option);
1709 pci_read_config_dword(minfo->pcidev, PCI_COMMAND, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 mga_option &= 0x7FFFFFFF; /* clear BIG_ENDIAN */
1711 mga_option |= MX_OPTION_BSWAP;
Andrew Mortona50d9132006-06-21 01:57:39 -03001712 /* disable palette snooping */
1713 cmd &= ~PCI_COMMAND_VGA_PALETTE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 if (pci_dev_present(intel_82437)) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001715 if (!(mga_option & 0x20000000) && !minfo->devflags.nopciretry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 printk(KERN_WARNING "matroxfb: Disabling PCI retries due to i82437 present\n");
1717 }
1718 mga_option |= 0x20000000;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001719 minfo->devflags.nopciretry = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001721 pci_write_config_dword(minfo->pcidev, PCI_COMMAND, cmd);
1722 pci_write_config_dword(minfo->pcidev, PCI_OPTION_REG, mga_option);
1723 minfo->hw.MXoptionReg = mga_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 /* select non-DMA memory for PCI_MGA_DATA, otherwise dump of PCI cfg space can lock PCI bus */
1726 /* maybe preinit() candidate, but it is same... for all devices... at this time... */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001727 pci_write_config_dword(minfo->pcidev, PCI_MGA_INDEX, 0x00003C00);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 }
1729
1730 err = -ENXIO;
Jean Delvare316b4d62009-09-22 16:47:49 -07001731 matroxfb_read_pins(minfo);
1732 if (minfo->hw_switch->preinit(minfo)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 goto failVideoIO;
1734 }
1735
1736 err = -ENOMEM;
Jean Delvare316b4d62009-09-22 16:47:49 -07001737 if (!matroxfb_getmemory(minfo, memsize, &minfo->video.len) || !minfo->video.len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 printk(KERN_ERR "matroxfb: cannot determine memory size\n");
1739 goto failVideoIO;
1740 }
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001741 minfo->devflags.ydstorg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001743 minfo->video.base = video_base_phys;
1744 minfo->video.len_usable = minfo->video.len;
1745 if (minfo->video.len_usable > b->base->maxdisplayable)
1746 minfo->video.len_usable = b->base->maxdisplayable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747#ifdef CONFIG_MTRR
1748 if (mtrr) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001749 minfo->mtrr.vram = mtrr_add(video_base_phys, minfo->video.len, MTRR_TYPE_WRCOMB, 1);
1750 minfo->mtrr.vram_valid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 printk(KERN_INFO "matroxfb: MTRR's turned on\n");
1752 }
1753#endif /* CONFIG_MTRR */
1754
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001755 if (!minfo->devflags.novga)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 request_region(0x3C0, 32, "matrox");
Jean Delvare316b4d62009-09-22 16:47:49 -07001757 matroxfb_g450_connect(minfo);
1758 minfo->hw_switch->reset(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001760 minfo->fbcon.monspecs.hfmin = 0;
1761 minfo->fbcon.monspecs.hfmax = fh;
1762 minfo->fbcon.monspecs.vfmin = 0;
1763 minfo->fbcon.monspecs.vfmax = fv;
1764 minfo->fbcon.monspecs.dpms = 0; /* TBD */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
1766 /* static settings */
1767 vesafb_defined.red = colors[depth-1].red;
1768 vesafb_defined.green = colors[depth-1].green;
1769 vesafb_defined.blue = colors[depth-1].blue;
1770 vesafb_defined.bits_per_pixel = colors[depth-1].bits_per_pixel;
1771 vesafb_defined.grayscale = grayscale;
1772 vesafb_defined.vmode = 0;
1773 if (noaccel)
1774 vesafb_defined.accel_flags &= ~FB_ACCELF_TEXT;
1775
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001776 minfo->fbops = matroxfb_ops;
1777 minfo->fbcon.fbops = &minfo->fbops;
1778 minfo->fbcon.pseudo_palette = minfo->cmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 /* after __init time we are like module... no logo */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001780 minfo->fbcon.flags = hotplug ? FBINFO_FLAG_MODULE : FBINFO_FLAG_DEFAULT;
1781 minfo->fbcon.flags |= FBINFO_PARTIAL_PAN_OK | /* Prefer panning for scroll under MC viewer/edit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 FBINFO_HWACCEL_COPYAREA | /* We have hw-assisted bmove */
1783 FBINFO_HWACCEL_FILLRECT | /* And fillrect */
1784 FBINFO_HWACCEL_IMAGEBLIT | /* And imageblit */
1785 FBINFO_HWACCEL_XPAN | /* And we support both horizontal */
1786 FBINFO_HWACCEL_YPAN; /* And vertical panning */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001787 minfo->video.len_usable &= PAGE_MASK;
1788 fb_alloc_cmap(&minfo->fbcon.cmap, 256, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
1790#ifndef MODULE
1791 /* mode database is marked __init!!! */
1792 if (!hotplug) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001793 fb_find_mode(&vesafb_defined, &minfo->fbcon, videomode[0] ? videomode : NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 NULL, 0, &defaultmode, vesafb_defined.bits_per_pixel);
1795 }
1796#endif /* !MODULE */
1797
1798 /* mode modifiers */
1799 if (hslen)
1800 vesafb_defined.hsync_len = hslen;
1801 if (vslen)
1802 vesafb_defined.vsync_len = vslen;
1803 if (left != ~0)
1804 vesafb_defined.left_margin = left;
1805 if (right != ~0)
1806 vesafb_defined.right_margin = right;
1807 if (upper != ~0)
1808 vesafb_defined.upper_margin = upper;
1809 if (lower != ~0)
1810 vesafb_defined.lower_margin = lower;
1811 if (xres)
1812 vesafb_defined.xres = xres;
1813 if (yres)
1814 vesafb_defined.yres = yres;
1815 if (sync != -1)
1816 vesafb_defined.sync = sync;
1817 else if (vesafb_defined.sync == ~0) {
1818 vesafb_defined.sync = 0;
1819 if (yres < 400)
1820 vesafb_defined.sync |= FB_SYNC_HOR_HIGH_ACT;
1821 else if (yres < 480)
1822 vesafb_defined.sync |= FB_SYNC_VERT_HIGH_ACT;
1823 }
1824
1825 /* fv, fh, maxclk limits was specified */
1826 {
1827 unsigned int tmp;
1828
1829 if (fv) {
1830 tmp = fv * (vesafb_defined.upper_margin + vesafb_defined.yres
Andrew Mortona50d9132006-06-21 01:57:39 -03001831 + vesafb_defined.lower_margin + vesafb_defined.vsync_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 if ((tmp < fh) || (fh == 0)) fh = tmp;
1833 }
1834 if (fh) {
1835 tmp = fh * (vesafb_defined.left_margin + vesafb_defined.xres
Andrew Mortona50d9132006-06-21 01:57:39 -03001836 + vesafb_defined.right_margin + vesafb_defined.hsync_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 if ((tmp < maxclk) || (maxclk == 0)) maxclk = tmp;
1838 }
1839 tmp = (maxclk + 499) / 500;
1840 if (tmp) {
1841 tmp = (2000000000 + tmp) / tmp;
1842 if (tmp > pixclock) pixclock = tmp;
1843 }
1844 }
1845 if (pixclock) {
1846 if (pixclock < 2000) /* > 500MHz */
1847 pixclock = 4000; /* 250MHz */
1848 if (pixclock > 1000000)
1849 pixclock = 1000000; /* 1MHz */
1850 vesafb_defined.pixclock = pixclock;
1851 }
1852
1853 /* FIXME: Where to move this?! */
1854#if defined(CONFIG_PPC_PMAC)
1855#ifndef MODULE
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +11001856 if (machine_is(powermac)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 struct fb_var_screeninfo var;
1858 if (default_vmode <= 0 || default_vmode > VMODE_MAX)
1859 default_vmode = VMODE_640_480_60;
1860#ifdef CONFIG_NVRAM
1861 if (default_cmode == CMODE_NVRAM)
1862 default_cmode = nvram_read_byte(NV_CMODE);
1863#endif
1864 if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
1865 default_cmode = CMODE_8;
1866 if (!mac_vmode_to_var(default_vmode, default_cmode, &var)) {
1867 var.accel_flags = vesafb_defined.accel_flags;
1868 var.xoffset = var.yoffset = 0;
1869 /* Note: mac_vmode_to_var() does not set all parameters */
1870 vesafb_defined = var;
1871 }
1872 }
1873#endif /* !MODULE */
1874#endif /* CONFIG_PPC_PMAC */
1875 vesafb_defined.xres_virtual = vesafb_defined.xres;
1876 if (nopan) {
1877 vesafb_defined.yres_virtual = vesafb_defined.yres;
1878 } else {
1879 vesafb_defined.yres_virtual = 65536; /* large enough to be INF, but small enough
1880 to yres_virtual * xres_virtual < 2^32 */
1881 }
Jean Delvare316b4d62009-09-22 16:47:49 -07001882 matroxfb_init_fix(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001883 minfo->fbcon.screen_base = vaddr_va(minfo->video.vbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 /* Normalize values (namely yres_virtual) */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001885 matroxfb_check_var(&vesafb_defined, &minfo->fbcon);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 /* And put it into "current" var. Do NOT program hardware yet, or we'll not take over
1887 * vgacon correctly. fbcon_startup will call fb_set_par for us, WITHOUT check_var,
1888 * and unfortunately it will do it BEFORE vgacon contents is saved, so it won't work
1889 * anyway. But we at least tried... */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001890 minfo->fbcon.var = vesafb_defined;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 err = -EINVAL;
1892
1893 printk(KERN_INFO "matroxfb: %dx%dx%dbpp (virtual: %dx%d)\n",
1894 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel,
1895 vesafb_defined.xres_virtual, vesafb_defined.yres_virtual);
1896 printk(KERN_INFO "matroxfb: framebuffer at 0x%lX, mapped to 0x%p, size %d\n",
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001897 minfo->video.base, vaddr_va(minfo->video.vbase), minfo->video.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899/* We do not have to set currcon to 0... register_framebuffer do it for us on first console
1900 * and we do not want currcon == 0 for subsequent framebuffers */
1901
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001902 minfo->fbcon.device = &minfo->pcidev->dev;
1903 if (register_framebuffer(&minfo->fbcon) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 goto failVideoIO;
1905 }
1906 printk("fb%d: %s frame buffer device\n",
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001907 minfo->fbcon.node, minfo->fbcon.fix.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
1909 /* there is no console on this fb... but we have to initialize hardware
1910 * until someone tells me what is proper thing to do */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001911 if (!minfo->initialized) {
Andrew Mortona50d9132006-06-21 01:57:39 -03001912 printk(KERN_INFO "fb%d: initializing hardware\n",
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001913 minfo->fbcon.node);
Andrew Mortona50d9132006-06-21 01:57:39 -03001914 /* We have to use FB_ACTIVATE_FORCE, as we had to put vesafb_defined to the fbcon.var
1915 * already before, so register_framebuffer works correctly. */
1916 vesafb_defined.activate |= FB_ACTIVATE_FORCE;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001917 fb_set_var(&minfo->fbcon, &vesafb_defined);
Andrew Mortona50d9132006-06-21 01:57:39 -03001918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
1920 return 0;
1921failVideoIO:;
Jean Delvare316b4d62009-09-22 16:47:49 -07001922 matroxfb_g450_shutdown(minfo);
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001923 mga_iounmap(minfo->video.vbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924failCtrlIO:;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001925 mga_iounmap(minfo->mmio.vbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926failVideoMR:;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001927 release_mem_region(video_base_phys, minfo->video.len_maximum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928failCtrlMR:;
1929 release_mem_region(ctrlptr_phys, 16384);
1930fail:;
1931 return err;
1932}
1933
1934static LIST_HEAD(matroxfb_list);
1935static LIST_HEAD(matroxfb_driver_list);
1936
1937#define matroxfb_l(x) list_entry(x, struct matrox_fb_info, next_fb)
1938#define matroxfb_driver_l(x) list_entry(x, struct matroxfb_driver, node)
1939int matroxfb_register_driver(struct matroxfb_driver* drv) {
1940 struct matrox_fb_info* minfo;
1941
1942 list_add(&drv->node, &matroxfb_driver_list);
1943 for (minfo = matroxfb_l(matroxfb_list.next);
1944 minfo != matroxfb_l(&matroxfb_list);
1945 minfo = matroxfb_l(minfo->next_fb.next)) {
1946 void* p;
1947
1948 if (minfo->drivers_count == MATROXFB_MAX_FB_DRIVERS)
1949 continue;
1950 p = drv->probe(minfo);
1951 if (p) {
1952 minfo->drivers_data[minfo->drivers_count] = p;
1953 minfo->drivers[minfo->drivers_count++] = drv;
1954 }
1955 }
1956 return 0;
1957}
1958
1959void matroxfb_unregister_driver(struct matroxfb_driver* drv) {
1960 struct matrox_fb_info* minfo;
1961
1962 list_del(&drv->node);
1963 for (minfo = matroxfb_l(matroxfb_list.next);
1964 minfo != matroxfb_l(&matroxfb_list);
1965 minfo = matroxfb_l(minfo->next_fb.next)) {
1966 int i;
1967
1968 for (i = 0; i < minfo->drivers_count; ) {
1969 if (minfo->drivers[i] == drv) {
1970 if (drv && drv->remove)
1971 drv->remove(minfo, minfo->drivers_data[i]);
1972 minfo->drivers[i] = minfo->drivers[--minfo->drivers_count];
1973 minfo->drivers_data[i] = minfo->drivers_data[minfo->drivers_count];
1974 } else
1975 i++;
1976 }
1977 }
1978}
1979
1980static void matroxfb_register_device(struct matrox_fb_info* minfo) {
1981 struct matroxfb_driver* drv;
1982 int i = 0;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07001983 list_add(&minfo->next_fb, &matroxfb_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 for (drv = matroxfb_driver_l(matroxfb_driver_list.next);
1985 drv != matroxfb_driver_l(&matroxfb_driver_list);
1986 drv = matroxfb_driver_l(drv->node.next)) {
1987 if (drv && drv->probe) {
1988 void *p = drv->probe(minfo);
1989 if (p) {
1990 minfo->drivers_data[i] = p;
1991 minfo->drivers[i++] = drv;
1992 if (i == MATROXFB_MAX_FB_DRIVERS)
1993 break;
1994 }
1995 }
1996 }
1997 minfo->drivers_count = i;
1998}
1999
2000static void matroxfb_unregister_device(struct matrox_fb_info* minfo) {
2001 int i;
2002
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002003 list_del(&minfo->next_fb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 for (i = 0; i < minfo->drivers_count; i++) {
2005 struct matroxfb_driver* drv = minfo->drivers[i];
2006
2007 if (drv && drv->remove)
2008 drv->remove(minfo, minfo->drivers_data[i]);
2009 }
2010}
2011
2012static int matroxfb_probe(struct pci_dev* pdev, const struct pci_device_id* dummy) {
2013 struct board* b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 u_int16_t svid;
2015 u_int16_t sid;
2016 struct matrox_fb_info* minfo;
2017 int err;
2018 u_int32_t cmd;
Harvey Harrison5ae12172008-04-28 02:15:47 -07002019 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 svid = pdev->subsystem_vendor;
2022 sid = pdev->subsystem_device;
2023 for (b = dev_list; b->vendor; b++) {
Auke Kok44c10132007-06-08 15:46:36 -07002024 if ((b->vendor != pdev->vendor) || (b->device != pdev->device) || (b->rev < pdev->revision)) continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 if (b->svid)
2026 if ((b->svid != svid) || (b->sid != sid)) continue;
2027 break;
2028 }
2029 /* not match... */
2030 if (!b->vendor)
Jan Beulich438e5c52005-09-13 01:25:45 -07002031 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 if (dev > 0) {
2033 /* not requested one... */
2034 dev--;
Jan Beulich438e5c52005-09-13 01:25:45 -07002035 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 }
2037 pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
2038 if (pci_enable_device(pdev)) {
2039 return -1;
2040 }
2041
Robert P. J. Day5cbded52006-12-13 00:35:56 -08002042 minfo = kmalloc(sizeof(*minfo), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 if (!minfo)
2044 return -1;
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002045 memset(minfo, 0, sizeof(*minfo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002047 minfo->pcidev = pdev;
2048 minfo->dead = 0;
2049 minfo->usecount = 0;
2050 minfo->userusecount = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002052 pci_set_drvdata(pdev, minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 /* DEVFLAGS */
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002054 minfo->devflags.memtype = memtype;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 if (memtype != -1)
2056 noinit = 0;
2057 if (cmd & PCI_COMMAND_MEMORY) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002058 minfo->devflags.novga = novga;
2059 minfo->devflags.nobios = nobios;
2060 minfo->devflags.noinit = noinit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 /* subsequent heads always needs initialization and must not enable BIOS */
2062 novga = 1;
2063 nobios = 1;
2064 noinit = 0;
2065 } else {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002066 minfo->devflags.novga = 1;
2067 minfo->devflags.nobios = 1;
2068 minfo->devflags.noinit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 }
2070
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002071 minfo->devflags.nopciretry = no_pci_retry;
2072 minfo->devflags.mga_24bpp_fix = inv24;
2073 minfo->devflags.precise_width = option_precise_width;
2074 minfo->devflags.sgram = sgram;
2075 minfo->capable.cross4MB = cross4MB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002077 spin_lock_init(&minfo->lock.DAC);
2078 spin_lock_init(&minfo->lock.accel);
2079 init_rwsem(&minfo->crtc2.lock);
2080 init_rwsem(&minfo->altout.lock);
2081 mutex_init(&minfo->fbcon.mm_lock);
2082 minfo->irq_flags = 0;
2083 init_waitqueue_head(&minfo->crtc1.vsync.wait);
2084 init_waitqueue_head(&minfo->crtc2.vsync.wait);
2085 minfo->crtc1.panpos = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Jean Delvare316b4d62009-09-22 16:47:49 -07002087 err = initMatrox2(minfo, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 if (!err) {
Jean Delvarefc2d10d2009-09-22 16:47:48 -07002089 matroxfb_register_device(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 return 0;
2091 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 kfree(minfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 return -1;
2094}
2095
2096static void pci_remove_matrox(struct pci_dev* pdev) {
2097 struct matrox_fb_info* minfo;
2098
2099 minfo = pci_get_drvdata(pdev);
Jean Delvare316b4d62009-09-22 16:47:49 -07002100 matroxfb_remove(minfo, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101}
2102
2103static struct pci_device_id matroxfb_devices[] = {
2104#ifdef CONFIG_FB_MATROX_MILLENIUM
2105 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL,
2106 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2107 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2,
2108 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2109 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MIL_2_AGP,
2110 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2111#endif
2112#ifdef CONFIG_FB_MATROX_MYSTIQUE
2113 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_MYS,
2114 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2115#endif
2116#ifdef CONFIG_FB_MATROX_G
2117 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_MM,
2118 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2119 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_AGP,
2120 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Darrick J. Wonge3a19382008-10-15 22:03:52 -07002121 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200EV_PCI,
2122 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI,
2124 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2125 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP,
2126 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2127 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400,
2128 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2129 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G550,
2130 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2131#endif
2132 {0, 0,
2133 0, 0, 0, 0, 0}
2134};
2135
2136MODULE_DEVICE_TABLE(pci, matroxfb_devices);
2137
2138
2139static struct pci_driver matroxfb_driver = {
2140 .name = "matroxfb",
2141 .id_table = matroxfb_devices,
2142 .probe = matroxfb_probe,
2143 .remove = pci_remove_matrox,
2144};
2145
2146/* **************************** init-time only **************************** */
2147
2148#define RSResolution(X) ((X) & 0x0F)
2149#define RS640x400 1
2150#define RS640x480 2
2151#define RS800x600 3
2152#define RS1024x768 4
2153#define RS1280x1024 5
2154#define RS1600x1200 6
2155#define RS768x576 7
2156#define RS960x720 8
2157#define RS1152x864 9
2158#define RS1408x1056 10
2159#define RS640x350 11
2160#define RS1056x344 12 /* 132 x 43 text */
2161#define RS1056x400 13 /* 132 x 50 text */
2162#define RS1056x480 14 /* 132 x 60 text */
2163#define RSNoxNo 15
2164/* 10-FF */
2165static struct { int xres, yres, left, right, upper, lower, hslen, vslen, vfreq; } timmings[] __initdata = {
2166 { 640, 400, 48, 16, 39, 8, 96, 2, 70 },
2167 { 640, 480, 48, 16, 33, 10, 96, 2, 60 },
2168 { 800, 600, 144, 24, 28, 8, 112, 6, 60 },
2169 { 1024, 768, 160, 32, 30, 4, 128, 4, 60 },
2170 { 1280, 1024, 224, 32, 32, 4, 136, 4, 60 },
2171 { 1600, 1200, 272, 48, 32, 5, 152, 5, 60 },
2172 { 768, 576, 144, 16, 28, 6, 112, 4, 60 },
2173 { 960, 720, 144, 24, 28, 8, 112, 4, 60 },
2174 { 1152, 864, 192, 32, 30, 4, 128, 4, 60 },
2175 { 1408, 1056, 256, 40, 32, 5, 144, 5, 60 },
2176 { 640, 350, 48, 16, 39, 8, 96, 2, 70 },
2177 { 1056, 344, 96, 24, 59, 44, 160, 2, 70 },
2178 { 1056, 400, 96, 24, 39, 8, 160, 2, 70 },
2179 { 1056, 480, 96, 24, 36, 12, 160, 3, 60 },
2180 { 0, 0, ~0, ~0, ~0, ~0, 0, 0, 0 }
2181};
2182
2183#define RSCreate(X,Y) ((X) | ((Y) << 8))
2184static struct { unsigned int vesa; unsigned int info; } *RSptr, vesamap[] __initdata = {
2185/* default must be first */
2186 { ~0, RSCreate(RSNoxNo, RS8bpp ) },
2187 { 0x101, RSCreate(RS640x480, RS8bpp ) },
2188 { 0x100, RSCreate(RS640x400, RS8bpp ) },
2189 { 0x180, RSCreate(RS768x576, RS8bpp ) },
2190 { 0x103, RSCreate(RS800x600, RS8bpp ) },
2191 { 0x188, RSCreate(RS960x720, RS8bpp ) },
2192 { 0x105, RSCreate(RS1024x768, RS8bpp ) },
2193 { 0x190, RSCreate(RS1152x864, RS8bpp ) },
2194 { 0x107, RSCreate(RS1280x1024, RS8bpp ) },
2195 { 0x198, RSCreate(RS1408x1056, RS8bpp ) },
2196 { 0x11C, RSCreate(RS1600x1200, RS8bpp ) },
2197 { 0x110, RSCreate(RS640x480, RS15bpp) },
2198 { 0x181, RSCreate(RS768x576, RS15bpp) },
2199 { 0x113, RSCreate(RS800x600, RS15bpp) },
2200 { 0x189, RSCreate(RS960x720, RS15bpp) },
2201 { 0x116, RSCreate(RS1024x768, RS15bpp) },
2202 { 0x191, RSCreate(RS1152x864, RS15bpp) },
2203 { 0x119, RSCreate(RS1280x1024, RS15bpp) },
2204 { 0x199, RSCreate(RS1408x1056, RS15bpp) },
2205 { 0x11D, RSCreate(RS1600x1200, RS15bpp) },
2206 { 0x111, RSCreate(RS640x480, RS16bpp) },
2207 { 0x182, RSCreate(RS768x576, RS16bpp) },
2208 { 0x114, RSCreate(RS800x600, RS16bpp) },
2209 { 0x18A, RSCreate(RS960x720, RS16bpp) },
2210 { 0x117, RSCreate(RS1024x768, RS16bpp) },
2211 { 0x192, RSCreate(RS1152x864, RS16bpp) },
2212 { 0x11A, RSCreate(RS1280x1024, RS16bpp) },
2213 { 0x19A, RSCreate(RS1408x1056, RS16bpp) },
2214 { 0x11E, RSCreate(RS1600x1200, RS16bpp) },
2215 { 0x1B2, RSCreate(RS640x480, RS24bpp) },
2216 { 0x184, RSCreate(RS768x576, RS24bpp) },
2217 { 0x1B5, RSCreate(RS800x600, RS24bpp) },
2218 { 0x18C, RSCreate(RS960x720, RS24bpp) },
2219 { 0x1B8, RSCreate(RS1024x768, RS24bpp) },
2220 { 0x194, RSCreate(RS1152x864, RS24bpp) },
2221 { 0x1BB, RSCreate(RS1280x1024, RS24bpp) },
2222 { 0x19C, RSCreate(RS1408x1056, RS24bpp) },
2223 { 0x1BF, RSCreate(RS1600x1200, RS24bpp) },
2224 { 0x112, RSCreate(RS640x480, RS32bpp) },
2225 { 0x183, RSCreate(RS768x576, RS32bpp) },
2226 { 0x115, RSCreate(RS800x600, RS32bpp) },
2227 { 0x18B, RSCreate(RS960x720, RS32bpp) },
2228 { 0x118, RSCreate(RS1024x768, RS32bpp) },
2229 { 0x193, RSCreate(RS1152x864, RS32bpp) },
2230 { 0x11B, RSCreate(RS1280x1024, RS32bpp) },
2231 { 0x19B, RSCreate(RS1408x1056, RS32bpp) },
2232 { 0x11F, RSCreate(RS1600x1200, RS32bpp) },
2233 { 0x010, RSCreate(RS640x350, RS4bpp ) },
2234 { 0x012, RSCreate(RS640x480, RS4bpp ) },
2235 { 0x102, RSCreate(RS800x600, RS4bpp ) },
2236 { 0x104, RSCreate(RS1024x768, RS4bpp ) },
2237 { 0x106, RSCreate(RS1280x1024, RS4bpp ) },
2238 { 0, 0 }};
2239
2240static void __init matroxfb_init_params(void) {
2241 /* fh from kHz to Hz */
2242 if (fh < 1000)
2243 fh *= 1000; /* 1kHz minimum */
2244 /* maxclk */
2245 if (maxclk < 1000) maxclk *= 1000; /* kHz -> Hz, MHz -> kHz */
2246 if (maxclk < 1000000) maxclk *= 1000; /* kHz -> Hz, 1MHz minimum */
2247 /* fix VESA number */
2248 if (vesa != ~0)
2249 vesa &= 0x1DFF; /* mask out clearscreen, acceleration and so on */
2250
2251 /* static settings */
2252 for (RSptr = vesamap; RSptr->vesa; RSptr++) {
2253 if (RSptr->vesa == vesa) break;
2254 }
2255 if (!RSptr->vesa) {
2256 printk(KERN_ERR "Invalid vesa mode 0x%04X\n", vesa);
2257 RSptr = vesamap;
2258 }
2259 {
2260 int res = RSResolution(RSptr->info)-1;
2261 if (left == ~0)
2262 left = timmings[res].left;
2263 if (!xres)
2264 xres = timmings[res].xres;
2265 if (right == ~0)
2266 right = timmings[res].right;
2267 if (!hslen)
2268 hslen = timmings[res].hslen;
2269 if (upper == ~0)
2270 upper = timmings[res].upper;
2271 if (!yres)
2272 yres = timmings[res].yres;
2273 if (lower == ~0)
2274 lower = timmings[res].lower;
2275 if (!vslen)
2276 vslen = timmings[res].vslen;
2277 if (!(fv||fh||maxclk||pixclock))
2278 fv = timmings[res].vfreq;
2279 if (depth == -1)
2280 depth = RSDepth(RSptr->info);
2281 }
2282}
2283
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002284static int __init matrox_init(void) {
2285 int err;
2286
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 matroxfb_init_params();
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002288 err = pci_register_driver(&matroxfb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 dev = -1; /* accept all new devices... */
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002290 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291}
2292
2293/* **************************** exit-time only **************************** */
2294
2295static void __exit matrox_done(void) {
2296 pci_unregister_driver(&matroxfb_driver);
2297}
2298
2299#ifndef MODULE
2300
2301/* ************************* init in-kernel code ************************** */
2302
2303static int __init matroxfb_setup(char *options) {
2304 char *this_opt;
2305
Harvey Harrison5ae12172008-04-28 02:15:47 -07002306 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
2308 if (!options || !*options)
2309 return 0;
2310
2311 while ((this_opt = strsep(&options, ",")) != NULL) {
2312 if (!*this_opt) continue;
2313
2314 dprintk("matroxfb_setup: option %s\n", this_opt);
2315
2316 if (!strncmp(this_opt, "dev:", 4))
2317 dev = simple_strtoul(this_opt+4, NULL, 0);
2318 else if (!strncmp(this_opt, "depth:", 6)) {
2319 switch (simple_strtoul(this_opt+6, NULL, 0)) {
2320 case 0: depth = RSText; break;
2321 case 4: depth = RS4bpp; break;
2322 case 8: depth = RS8bpp; break;
2323 case 15:depth = RS15bpp; break;
2324 case 16:depth = RS16bpp; break;
2325 case 24:depth = RS24bpp; break;
2326 case 32:depth = RS32bpp; break;
2327 default:
2328 printk(KERN_ERR "matroxfb: unsupported color depth\n");
2329 }
2330 } else if (!strncmp(this_opt, "xres:", 5))
2331 xres = simple_strtoul(this_opt+5, NULL, 0);
2332 else if (!strncmp(this_opt, "yres:", 5))
2333 yres = simple_strtoul(this_opt+5, NULL, 0);
2334 else if (!strncmp(this_opt, "vslen:", 6))
2335 vslen = simple_strtoul(this_opt+6, NULL, 0);
2336 else if (!strncmp(this_opt, "hslen:", 6))
2337 hslen = simple_strtoul(this_opt+6, NULL, 0);
2338 else if (!strncmp(this_opt, "left:", 5))
2339 left = simple_strtoul(this_opt+5, NULL, 0);
2340 else if (!strncmp(this_opt, "right:", 6))
2341 right = simple_strtoul(this_opt+6, NULL, 0);
2342 else if (!strncmp(this_opt, "upper:", 6))
2343 upper = simple_strtoul(this_opt+6, NULL, 0);
2344 else if (!strncmp(this_opt, "lower:", 6))
2345 lower = simple_strtoul(this_opt+6, NULL, 0);
2346 else if (!strncmp(this_opt, "pixclock:", 9))
2347 pixclock = simple_strtoul(this_opt+9, NULL, 0);
2348 else if (!strncmp(this_opt, "sync:", 5))
2349 sync = simple_strtoul(this_opt+5, NULL, 0);
2350 else if (!strncmp(this_opt, "vesa:", 5))
2351 vesa = simple_strtoul(this_opt+5, NULL, 0);
2352 else if (!strncmp(this_opt, "maxclk:", 7))
2353 maxclk = simple_strtoul(this_opt+7, NULL, 0);
2354 else if (!strncmp(this_opt, "fh:", 3))
2355 fh = simple_strtoul(this_opt+3, NULL, 0);
2356 else if (!strncmp(this_opt, "fv:", 3))
2357 fv = simple_strtoul(this_opt+3, NULL, 0);
2358 else if (!strncmp(this_opt, "mem:", 4))
2359 mem = simple_strtoul(this_opt+4, NULL, 0);
2360 else if (!strncmp(this_opt, "mode:", 5))
2361 strlcpy(videomode, this_opt+5, sizeof(videomode));
2362 else if (!strncmp(this_opt, "outputs:", 8))
2363 strlcpy(outputs, this_opt+8, sizeof(outputs));
2364 else if (!strncmp(this_opt, "dfp:", 4)) {
2365 dfp_type = simple_strtoul(this_opt+4, NULL, 0);
2366 dfp = 1;
Andrew Mortona50d9132006-06-21 01:57:39 -03002367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368#ifdef CONFIG_PPC_PMAC
2369 else if (!strncmp(this_opt, "vmode:", 6)) {
2370 unsigned int vmode = simple_strtoul(this_opt+6, NULL, 0);
2371 if (vmode > 0 && vmode <= VMODE_MAX)
2372 default_vmode = vmode;
2373 } else if (!strncmp(this_opt, "cmode:", 6)) {
2374 unsigned int cmode = simple_strtoul(this_opt+6, NULL, 0);
2375 switch (cmode) {
2376 case 0:
2377 case 8:
2378 default_cmode = CMODE_8;
2379 break;
2380 case 15:
2381 case 16:
2382 default_cmode = CMODE_16;
2383 break;
2384 case 24:
2385 case 32:
2386 default_cmode = CMODE_32;
2387 break;
2388 }
2389 }
2390#endif
2391 else if (!strcmp(this_opt, "disabled")) /* nodisabled does not exist */
2392 disabled = 1;
2393 else if (!strcmp(this_opt, "enabled")) /* noenabled does not exist */
2394 disabled = 0;
2395 else if (!strcmp(this_opt, "sgram")) /* nosgram == sdram */
2396 sgram = 1;
2397 else if (!strcmp(this_opt, "sdram"))
2398 sgram = 0;
2399 else if (!strncmp(this_opt, "memtype:", 8))
2400 memtype = simple_strtoul(this_opt+8, NULL, 0);
2401 else {
2402 int value = 1;
2403
2404 if (!strncmp(this_opt, "no", 2)) {
2405 value = 0;
2406 this_opt += 2;
2407 }
2408 if (! strcmp(this_opt, "inverse"))
2409 inverse = value;
2410 else if (!strcmp(this_opt, "accel"))
2411 noaccel = !value;
2412 else if (!strcmp(this_opt, "pan"))
2413 nopan = !value;
2414 else if (!strcmp(this_opt, "pciretry"))
2415 no_pci_retry = !value;
2416 else if (!strcmp(this_opt, "vga"))
2417 novga = !value;
2418 else if (!strcmp(this_opt, "bios"))
2419 nobios = !value;
2420 else if (!strcmp(this_opt, "init"))
2421 noinit = !value;
2422#ifdef CONFIG_MTRR
2423 else if (!strcmp(this_opt, "mtrr"))
2424 mtrr = value;
2425#endif
2426 else if (!strcmp(this_opt, "inv24"))
2427 inv24 = value;
2428 else if (!strcmp(this_opt, "cross4MB"))
2429 cross4MB = value;
2430 else if (!strcmp(this_opt, "grayscale"))
2431 grayscale = value;
2432 else if (!strcmp(this_opt, "dfp"))
2433 dfp = value;
2434 else {
2435 strlcpy(videomode, this_opt, sizeof(videomode));
2436 }
2437 }
2438 }
2439 return 0;
2440}
2441
2442static int __initdata initialized = 0;
2443
2444static int __init matroxfb_init(void)
2445{
2446 char *option = NULL;
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002447 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Harvey Harrison5ae12172008-04-28 02:15:47 -07002449 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
2451 if (fb_get_options("matroxfb", &option))
2452 return -ENODEV;
2453 matroxfb_setup(option);
2454
2455 if (disabled)
2456 return -ENXIO;
2457 if (!initialized) {
2458 initialized = 1;
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002459 err = matrox_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 }
2461 hotplug = 1;
2462 /* never return failure, user can hotplug matrox later... */
Antonino A. Daplasb0b10322006-10-03 01:14:52 -07002463 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464}
2465
2466module_init(matroxfb_init);
2467
2468#else
2469
2470/* *************************** init module code **************************** */
2471
2472MODULE_AUTHOR("(c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>");
2473MODULE_DESCRIPTION("Accelerated FBDev driver for Matrox Millennium/Mystique/G100/G200/G400/G450/G550");
2474MODULE_LICENSE("GPL");
2475
2476module_param(mem, int, 0);
2477MODULE_PARM_DESC(mem, "Size of available memory in MB, KB or B (2,4,8,12,16MB, default=autodetect)");
2478module_param(disabled, int, 0);
2479MODULE_PARM_DESC(disabled, "Disabled (0 or 1=disabled) (default=0)");
2480module_param(noaccel, int, 0);
2481MODULE_PARM_DESC(noaccel, "Do not use accelerating engine (0 or 1=disabled) (default=0)");
2482module_param(nopan, int, 0);
2483MODULE_PARM_DESC(nopan, "Disable pan on startup (0 or 1=disabled) (default=0)");
2484module_param(no_pci_retry, int, 0);
2485MODULE_PARM_DESC(no_pci_retry, "PCI retries enabled (0 or 1=disabled) (default=0)");
2486module_param(novga, int, 0);
2487MODULE_PARM_DESC(novga, "VGA I/O (0x3C0-0x3DF) disabled (0 or 1=disabled) (default=0)");
2488module_param(nobios, int, 0);
2489MODULE_PARM_DESC(nobios, "Disables ROM BIOS (0 or 1=disabled) (default=do not change BIOS state)");
2490module_param(noinit, int, 0);
2491MODULE_PARM_DESC(noinit, "Disables W/SG/SD-RAM and bus interface initialization (0 or 1=do not initialize) (default=0)");
2492module_param(memtype, int, 0);
2493MODULE_PARM_DESC(memtype, "Memory type for G200/G400 (see Documentation/fb/matroxfb.txt for explanation) (default=3 for G200, 0 for G400)");
2494#ifdef CONFIG_MTRR
2495module_param(mtrr, int, 0);
2496MODULE_PARM_DESC(mtrr, "This speeds up video memory accesses (0=disabled or 1) (default=1)");
2497#endif
2498module_param(sgram, int, 0);
2499MODULE_PARM_DESC(sgram, "Indicates that G100/G200/G400 has SGRAM memory (0=SDRAM, 1=SGRAM) (default=0)");
2500module_param(inv24, int, 0);
2501MODULE_PARM_DESC(inv24, "Inverts clock polarity for 24bpp and loop frequency > 100MHz (default=do not invert polarity)");
2502module_param(inverse, int, 0);
2503MODULE_PARM_DESC(inverse, "Inverse (0 or 1) (default=0)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504module_param(dev, int, 0);
2505MODULE_PARM_DESC(dev, "Multihead support, attach to device ID (0..N) (default=all working)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506module_param(vesa, int, 0);
2507MODULE_PARM_DESC(vesa, "Startup videomode (0x000-0x1FF) (default=0x101)");
2508module_param(xres, int, 0);
2509MODULE_PARM_DESC(xres, "Horizontal resolution (px), overrides xres from vesa (default=vesa)");
2510module_param(yres, int, 0);
2511MODULE_PARM_DESC(yres, "Vertical resolution (scans), overrides yres from vesa (default=vesa)");
2512module_param(upper, int, 0);
2513MODULE_PARM_DESC(upper, "Upper blank space (scans), overrides upper from vesa (default=vesa)");
2514module_param(lower, int, 0);
2515MODULE_PARM_DESC(lower, "Lower blank space (scans), overrides lower from vesa (default=vesa)");
2516module_param(vslen, int, 0);
2517MODULE_PARM_DESC(vslen, "Vertical sync length (scans), overrides lower from vesa (default=vesa)");
2518module_param(left, int, 0);
2519MODULE_PARM_DESC(left, "Left blank space (px), overrides left from vesa (default=vesa)");
2520module_param(right, int, 0);
2521MODULE_PARM_DESC(right, "Right blank space (px), overrides right from vesa (default=vesa)");
2522module_param(hslen, int, 0);
2523MODULE_PARM_DESC(hslen, "Horizontal sync length (px), overrides hslen from vesa (default=vesa)");
2524module_param(pixclock, int, 0);
2525MODULE_PARM_DESC(pixclock, "Pixelclock (ns), overrides pixclock from vesa (default=vesa)");
2526module_param(sync, int, 0);
2527MODULE_PARM_DESC(sync, "Sync polarity, overrides sync from vesa (default=vesa)");
2528module_param(depth, int, 0);
2529MODULE_PARM_DESC(depth, "Color depth (0=text,8,15,16,24,32) (default=vesa)");
2530module_param(maxclk, int, 0);
2531MODULE_PARM_DESC(maxclk, "Startup maximal clock, 0-999MHz, 1000-999999kHz, 1000000-INF Hz");
2532module_param(fh, int, 0);
2533MODULE_PARM_DESC(fh, "Startup horizontal frequency, 0-999kHz, 1000-INF Hz");
2534module_param(fv, int, 0);
2535MODULE_PARM_DESC(fv, "Startup vertical frequency, 0-INF Hz\n"
Niels de Vos61a2d072008-07-31 00:07:23 -07002536"You should specify \"fv:max_monitor_vsync,fh:max_monitor_hsync,maxclk:max_monitor_dotclock\"");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537module_param(grayscale, int, 0);
2538MODULE_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)");
2539module_param(cross4MB, int, 0);
2540MODULE_PARM_DESC(cross4MB, "Specifies that 4MB boundary can be in middle of line. (default=autodetected)");
2541module_param(dfp, int, 0);
2542MODULE_PARM_DESC(dfp, "Specifies whether to use digital flat panel interface of G200/G400 (0 or 1) (default=0)");
2543module_param(dfp_type, int, 0);
2544MODULE_PARM_DESC(dfp_type, "Specifies DFP interface type (0 to 255) (default=read from hardware)");
2545module_param_string(outputs, outputs, sizeof(outputs), 0);
2546MODULE_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)");
2547#ifdef CONFIG_PPC_PMAC
2548module_param_named(vmode, default_vmode, int, 0);
2549MODULE_PARM_DESC(vmode, "Specify the vmode mode number that should be used (640x480 default)");
2550module_param_named(cmode, default_cmode, int, 0);
2551MODULE_PARM_DESC(cmode, "Specify the video depth that should be used (8bit default)");
2552#endif
2553
2554int __init init_module(void){
2555
Harvey Harrison5ae12172008-04-28 02:15:47 -07002556 DBG(__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
2558 if (disabled)
2559 return -ENXIO;
2560
2561 if (depth == 0)
2562 depth = RSText;
2563 else if (depth == 4)
2564 depth = RS4bpp;
2565 else if (depth == 8)
2566 depth = RS8bpp;
2567 else if (depth == 15)
2568 depth = RS15bpp;
2569 else if (depth == 16)
2570 depth = RS16bpp;
2571 else if (depth == 24)
2572 depth = RS24bpp;
2573 else if (depth == 32)
2574 depth = RS32bpp;
2575 else if (depth != -1) {
2576 printk(KERN_ERR "matroxfb: depth %d is not supported, using default\n", depth);
2577 depth = -1;
2578 }
2579 matrox_init();
2580 /* never return failure; user can hotplug matrox later... */
2581 return 0;
2582}
2583#endif /* MODULE */
2584
2585module_exit(matrox_done);
2586EXPORT_SYMBOL(matroxfb_register_driver);
2587EXPORT_SYMBOL(matroxfb_unregister_driver);
2588EXPORT_SYMBOL(matroxfb_wait_for_sync);
2589EXPORT_SYMBOL(matroxfb_enable_irq);
2590
2591/*
2592 * Overrides for Emacs so that we follow Linus's tabbing style.
2593 * ---------------------------------------------------------------------------
2594 * Local variables:
2595 * c-basic-offset: 8
2596 * End:
2597 */
2598