blob: b95779b57c0650e69070ebf028aefa9fd96f8651 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
3 * Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200, G400 and G450
4 *
5 * (c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>
6 *
7 */
8#ifndef __MATROXFB_H__
9#define __MATROXFB_H__
10
11/* general, but fairly heavy, debugging */
12#undef MATROXFB_DEBUG
13
14/* heavy debugging: */
15/* -- logs putc[s], so everytime a char is displayed, it's logged */
16#undef MATROXFB_DEBUG_HEAVY
17
18/* This one _could_ cause infinite loops */
19/* It _does_ cause lots and lots of messages during idle loops */
20#undef MATROXFB_DEBUG_LOOP
21
22/* Debug register calls, too? */
23#undef MATROXFB_DEBUG_REG
24
25/* Guard accelerator accesses with spin_lock_irqsave... */
26#undef MATROXFB_USE_SPINLOCKS
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/errno.h>
31#include <linux/string.h>
32#include <linux/mm.h>
33#include <linux/tty.h>
34#include <linux/slab.h>
35#include <linux/delay.h>
36#include <linux/fb.h>
37#include <linux/console.h>
38#include <linux/selection.h>
39#include <linux/ioport.h>
40#include <linux/init.h>
41#include <linux/timer.h>
42#include <linux/pci.h>
43#include <linux/spinlock.h>
44#include <linux/kd.h>
45
46#include <asm/io.h>
47#include <asm/unaligned.h>
48#ifdef CONFIG_MTRR
49#include <asm/mtrr.h>
50#endif
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#if defined(CONFIG_PPC_PMAC)
53#include <asm/prom.h>
54#include <asm/pci-bridge.h>
55#include "../macmodes.h"
56#endif
57
58/* always compile support for 32MB... It cost almost nothing */
59#define CONFIG_FB_MATROX_32MB
60
61#ifdef MATROXFB_DEBUG
62
63#define DEBUG
64#define DBG(x) printk(KERN_DEBUG "matroxfb: %s\n", (x));
65
66#ifdef MATROXFB_DEBUG_HEAVY
67#define DBG_HEAVY(x) DBG(x)
68#else /* MATROXFB_DEBUG_HEAVY */
69#define DBG_HEAVY(x) /* DBG_HEAVY */
70#endif /* MATROXFB_DEBUG_HEAVY */
71
72#ifdef MATROXFB_DEBUG_LOOP
73#define DBG_LOOP(x) DBG(x)
74#else /* MATROXFB_DEBUG_LOOP */
75#define DBG_LOOP(x) /* DBG_LOOP */
76#endif /* MATROXFB_DEBUG_LOOP */
77
78#ifdef MATROXFB_DEBUG_REG
79#define DBG_REG(x) DBG(x)
80#else /* MATROXFB_DEBUG_REG */
81#define DBG_REG(x) /* DBG_REG */
82#endif /* MATROXFB_DEBUG_REG */
83
84#else /* MATROXFB_DEBUG */
85
86#define DBG(x) /* DBG */
87#define DBG_HEAVY(x) /* DBG_HEAVY */
88#define DBG_REG(x) /* DBG_REG */
89#define DBG_LOOP(x) /* DBG_LOOP */
90
91#endif /* MATROXFB_DEBUG */
92
93#ifdef DEBUG
94#define dprintk(X...) printk(X)
95#else
96#define dprintk(X...)
97#endif
98
99#ifndef PCI_SS_VENDOR_ID_SIEMENS_NIXDORF
100#define PCI_SS_VENDOR_ID_SIEMENS_NIXDORF 0x110A
101#endif
102#ifndef PCI_SS_VENDOR_ID_MATROX
103#define PCI_SS_VENDOR_ID_MATROX PCI_VENDOR_ID_MATROX
104#endif
105
106#ifndef PCI_SS_ID_MATROX_PRODUCTIVA_G100_AGP
107#define PCI_SS_ID_MATROX_GENERIC 0xFF00
108#define PCI_SS_ID_MATROX_PRODUCTIVA_G100_AGP 0xFF01
109#define PCI_SS_ID_MATROX_MYSTIQUE_G200_AGP 0xFF02
110#define PCI_SS_ID_MATROX_MILLENIUM_G200_AGP 0xFF03
111#define PCI_SS_ID_MATROX_MARVEL_G200_AGP 0xFF04
112#define PCI_SS_ID_MATROX_MGA_G100_PCI 0xFF05
113#define PCI_SS_ID_MATROX_MGA_G100_AGP 0x1001
114#define PCI_SS_ID_MATROX_MILLENNIUM_G400_MAX_AGP 0x2179
115#define PCI_SS_ID_SIEMENS_MGA_G100_AGP 0x001E /* 30 */
116#define PCI_SS_ID_SIEMENS_MGA_G200_AGP 0x0032 /* 50 */
117#endif
118
119#define MX_VISUAL_TRUECOLOR FB_VISUAL_DIRECTCOLOR
120#define MX_VISUAL_DIRECTCOLOR FB_VISUAL_TRUECOLOR
121#define MX_VISUAL_PSEUDOCOLOR FB_VISUAL_PSEUDOCOLOR
122
123#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
124
125/* G-series and Mystique have (almost) same DAC */
126#undef NEED_DAC1064
127#if defined(CONFIG_FB_MATROX_MYSTIQUE) || defined(CONFIG_FB_MATROX_G)
128#define NEED_DAC1064 1
129#endif
130
131typedef struct {
132 void __iomem* vaddr;
133} vaddr_t;
134
135static inline unsigned int mga_readb(vaddr_t va, unsigned int offs) {
136 return readb(va.vaddr + offs);
137}
138
139static inline void mga_writeb(vaddr_t va, unsigned int offs, u_int8_t value) {
140 writeb(value, va.vaddr + offs);
141}
142
143static inline void mga_writew(vaddr_t va, unsigned int offs, u_int16_t value) {
144 writew(value, va.vaddr + offs);
145}
146
147static inline u_int32_t mga_readl(vaddr_t va, unsigned int offs) {
148 return readl(va.vaddr + offs);
149}
150
151static inline void mga_writel(vaddr_t va, unsigned int offs, u_int32_t value) {
152 writel(value, va.vaddr + offs);
153}
154
155static inline void mga_memcpy_toio(vaddr_t va, const void* src, int len) {
156#if defined(__alpha__) || defined(__i386__) || defined(__x86_64__)
157 /*
158 * memcpy_toio works for us if:
159 * (1) Copies data as 32bit quantities, not byte after byte,
160 * (2) Performs LE ordered stores, and
161 * (3) It copes with unaligned source (destination is guaranteed to be page
162 * aligned and length is guaranteed to be multiple of 4).
163 */
164 memcpy_toio(va.vaddr, src, len);
165#else
166 u_int32_t __iomem* addr = va.vaddr;
167
168 if ((unsigned long)src & 3) {
169 while (len >= 4) {
170 fb_writel(get_unaligned((u32 *)src), addr);
171 addr++;
172 len -= 4;
173 src += 4;
174 }
175 } else {
176 while (len >= 4) {
177 fb_writel(*(u32 *)src, addr);
178 addr++;
179 len -= 4;
180 src += 4;
181 }
182 }
183#endif
184}
185
186static inline void vaddr_add(vaddr_t* va, unsigned long offs) {
187 va->vaddr += offs;
188}
189
190static inline void __iomem* vaddr_va(vaddr_t va) {
191 return va.vaddr;
192}
193
194#define MGA_IOREMAP_NORMAL 0
195#define MGA_IOREMAP_NOCACHE 1
196
197#define MGA_IOREMAP_FB MGA_IOREMAP_NOCACHE
198#define MGA_IOREMAP_MMIO MGA_IOREMAP_NOCACHE
199static inline int mga_ioremap(unsigned long phys, unsigned long size, int flags, vaddr_t* virt) {
200 if (flags & MGA_IOREMAP_NOCACHE)
201 virt->vaddr = ioremap_nocache(phys, size);
202 else
203 virt->vaddr = ioremap(phys, size);
204 return (virt->vaddr == 0); /* 0, !0... 0, error_code in future */
205}
206
207static inline void mga_iounmap(vaddr_t va) {
208 iounmap(va.vaddr);
209}
210
211struct my_timming {
212 unsigned int pixclock;
213 int mnp;
214 unsigned int crtc;
215 unsigned int HDisplay;
216 unsigned int HSyncStart;
217 unsigned int HSyncEnd;
218 unsigned int HTotal;
219 unsigned int VDisplay;
220 unsigned int VSyncStart;
221 unsigned int VSyncEnd;
222 unsigned int VTotal;
223 unsigned int sync;
224 int dblscan;
225 int interlaced;
226 unsigned int delay; /* CRTC delay */
227};
228
229enum { M_SYSTEM_PLL, M_PIXEL_PLL_A, M_PIXEL_PLL_B, M_PIXEL_PLL_C, M_VIDEO_PLL };
230
231struct matrox_pll_cache {
232 unsigned int valid;
233 struct {
234 unsigned int mnp_key;
235 unsigned int mnp_value;
236 } data[4];
237};
238
239struct matrox_pll_limits {
240 unsigned int vcomin;
241 unsigned int vcomax;
242};
243
244struct matrox_pll_features {
245 unsigned int vco_freq_min;
246 unsigned int ref_freq;
247 unsigned int feed_div_min;
248 unsigned int feed_div_max;
249 unsigned int in_div_min;
250 unsigned int in_div_max;
251 unsigned int post_shift_max;
252};
253
254struct matroxfb_par
255{
256 unsigned int final_bppShift;
257 unsigned int cmap_len;
258 struct {
259 unsigned int bytes;
260 unsigned int pixels;
261 unsigned int chunks;
262 } ydstorg;
263};
264
265struct matrox_fb_info;
266
267struct matrox_DAC1064_features {
268 u_int8_t xvrefctrl;
269 u_int8_t xmiscctrl;
270};
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272/* current hardware status */
273struct mavenregs {
274 u_int8_t regs[256];
275 int mode;
276 int vlines;
277 int xtal;
278 int fv;
279
280 u_int16_t htotal;
281 u_int16_t hcorr;
282};
283
284struct matrox_crtc2 {
285 u_int32_t ctl;
286};
287
288struct matrox_hw_state {
289 u_int32_t MXoptionReg;
290 unsigned char DACclk[6];
291 unsigned char DACreg[80];
292 unsigned char MiscOutReg;
293 unsigned char DACpal[768];
294 unsigned char CRTC[25];
295 unsigned char CRTCEXT[9];
296 unsigned char SEQ[5];
297 /* unused for MGA mode, but who knows... */
298 unsigned char GCTL[9];
299 /* unused for MGA mode, but who knows... */
300 unsigned char ATTR[21];
301
302 /* TVOut only */
303 struct mavenregs maven;
304
305 struct matrox_crtc2 crtc2;
306};
307
308struct matrox_accel_data {
309#ifdef CONFIG_FB_MATROX_MILLENIUM
310 unsigned char ramdac_rev;
311#endif
312 u_int32_t m_dwg_rect;
313 u_int32_t m_opmode;
314};
315
316struct v4l2_queryctrl;
317struct v4l2_control;
318
319struct matrox_altout {
320 const char *name;
321 int (*compute)(void* altout_dev, struct my_timming* input);
322 int (*program)(void* altout_dev);
323 int (*start)(void* altout_dev);
324 int (*verifymode)(void* altout_dev, u_int32_t mode);
325 int (*getqueryctrl)(void* altout_dev,
326 struct v4l2_queryctrl* ctrl);
327 int (*getctrl)(void* altout_dev,
328 struct v4l2_control* ctrl);
329 int (*setctrl)(void* altout_dev,
330 struct v4l2_control* ctrl);
331};
332
333#define MATROXFB_SRC_NONE 0
334#define MATROXFB_SRC_CRTC1 1
335#define MATROXFB_SRC_CRTC2 2
336
337enum mga_chip { MGA_2064, MGA_2164, MGA_1064, MGA_1164, MGA_G100, MGA_G200, MGA_G400, MGA_G450, MGA_G550 };
338
339struct matrox_bios {
340 unsigned int bios_valid : 1;
341 unsigned int pins_len;
342 unsigned char pins[128];
343 struct {
344 unsigned char vMaj, vMin, vRev;
345 } version;
346 struct {
347 unsigned char state, tvout;
348 } output;
349};
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351struct matrox_switch;
352struct matroxfb_driver;
353struct matroxfb_dh_fb_info;
354
355struct matrox_vsync {
356 wait_queue_head_t wait;
357 unsigned int cnt;
358};
359
360struct matrox_fb_info {
361 struct fb_info fbcon;
362
363 struct list_head next_fb;
364
365 int dead;
366 int initialized;
367 unsigned int usecount;
368
369 unsigned int userusecount;
370 unsigned long irq_flags;
371
372 struct matroxfb_par curr;
373 struct matrox_hw_state hw;
374
375 struct matrox_accel_data accel;
376
377 struct pci_dev* pcidev;
378
379 struct {
380 struct matrox_vsync vsync;
381 unsigned int pixclock;
382 int mnp;
383 int panpos;
384 } crtc1;
385 struct {
386 struct matrox_vsync vsync;
387 unsigned int pixclock;
388 int mnp;
389 struct matroxfb_dh_fb_info* info;
390 struct rw_semaphore lock;
391 } crtc2;
392 struct {
393 struct rw_semaphore lock;
394 struct {
395 int brightness, contrast, saturation, hue, gamma;
396 int testout, deflicker;
397 } tvo_params;
398 } altout;
399#define MATROXFB_MAX_OUTPUTS 3
400 struct {
401 unsigned int src;
402 struct matrox_altout* output;
403 void* data;
404 unsigned int mode;
405 unsigned int default_src;
406 } outputs[MATROXFB_MAX_OUTPUTS];
407
408#define MATROXFB_MAX_FB_DRIVERS 5
409 struct matroxfb_driver* (drivers[MATROXFB_MAX_FB_DRIVERS]);
410 void* (drivers_data[MATROXFB_MAX_FB_DRIVERS]);
411 unsigned int drivers_count;
412
413 struct {
414 unsigned long base; /* physical */
415 vaddr_t vbase; /* CPU view */
416 unsigned int len;
417 unsigned int len_usable;
418 unsigned int len_maximum;
419 } video;
420
421 struct {
422 unsigned long base; /* physical */
423 vaddr_t vbase; /* CPU view */
424 unsigned int len;
425 } mmio;
426
427 unsigned int max_pixel_clock;
428
429 struct matrox_switch* hw_switch;
430
431 struct {
432 struct matrox_pll_features pll;
433 struct matrox_DAC1064_features DAC1064;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 } features;
435 struct {
436 spinlock_t DAC;
437 spinlock_t accel;
438 } lock;
439
440 enum mga_chip chip;
441
442 int interleave;
443 int millenium;
444 int milleniumII;
445 struct {
446 int cfb4;
447 const int* vxres;
448 int cross4MB;
449 int text;
450 int plnwt;
451 int srcorg;
452 } capable;
453#ifdef CONFIG_MTRR
454 struct {
455 int vram;
456 int vram_valid;
457 } mtrr;
458#endif
459 struct {
460 int precise_width;
461 int mga_24bpp_fix;
462 int novga;
463 int nobios;
464 int nopciretry;
465 int noinit;
466 int sgram;
467#ifdef CONFIG_FB_MATROX_32MB
468 int support32MB;
469#endif
470
471 int accelerator;
472 int text_type_aux;
473 int video64bits;
474 int crtc2;
475 int maven_capable;
476 unsigned int vgastep;
477 unsigned int textmode;
478 unsigned int textstep;
479 unsigned int textvram; /* character cells */
480 unsigned int ydstorg; /* offset in bytes from video start to usable memory */
481 /* 0 except for 6MB Millenium */
482 int memtype;
483 int g450dac;
484 int dfp_type;
485 int panellink; /* G400 DFP possible (not G450/G550) */
486 int dualhead;
487 unsigned int fbResource;
488 } devflags;
489 struct fb_ops fbops;
490 struct matrox_bios bios;
491 struct {
492 struct matrox_pll_limits pixel;
493 struct matrox_pll_limits system;
494 struct matrox_pll_limits video;
495 } limits;
496 struct {
497 struct matrox_pll_cache pixel;
498 struct matrox_pll_cache system;
499 struct matrox_pll_cache video;
500 } cache;
501 struct {
502 struct {
503 unsigned int video;
504 unsigned int system;
505 } pll;
506 struct {
507 u_int32_t opt;
508 u_int32_t opt2;
509 u_int32_t opt3;
510 u_int32_t mctlwtst;
511 u_int32_t mctlwtst_core;
512 u_int32_t memmisc;
513 u_int32_t memrdbk;
514 u_int32_t maccess;
515 } reg;
516 struct {
517 unsigned int ddr:1,
518 emrswen:1,
519 dll:1;
520 } memory;
521 } values;
522 u_int32_t cmap[17];
523};
524
525#define info2minfo(info) container_of(info, struct matrox_fb_info, fbcon)
526
527#ifdef CONFIG_FB_MATROX_MULTIHEAD
528#define ACCESS_FBINFO2(info, x) (info->x)
529#define ACCESS_FBINFO(x) ACCESS_FBINFO2(minfo,x)
530
531#define MINFO minfo
532
533#define WPMINFO2 struct matrox_fb_info* minfo
534#define WPMINFO WPMINFO2 ,
535#define CPMINFO2 const struct matrox_fb_info* minfo
536#define CPMINFO CPMINFO2 ,
537#define PMINFO2 minfo
538#define PMINFO PMINFO2 ,
539
540#define MINFO_FROM(x) struct matrox_fb_info* minfo = x
541#else
542
543extern struct matrox_fb_info matroxfb_global_mxinfo;
544
545#define ACCESS_FBINFO(x) (matroxfb_global_mxinfo.x)
546#define ACCESS_FBINFO2(info, x) (matroxfb_global_mxinfo.x)
547
548#define MINFO (&matroxfb_global_mxinfo)
549
550#define WPMINFO2 void
551#define WPMINFO
552#define CPMINFO2 void
553#define CPMINFO
554#define PMINFO2
555#define PMINFO
556
557#define MINFO_FROM(x)
558
559#endif
560
561#define MINFO_FROM_INFO(x) MINFO_FROM(info2minfo(x))
562
563struct matrox_switch {
564 int (*preinit)(WPMINFO2);
565 void (*reset)(WPMINFO2);
566 int (*init)(WPMINFO struct my_timming*);
567 void (*restore)(WPMINFO2);
568};
569
570struct matroxfb_driver {
571 struct list_head node;
572 char* name;
573 void* (*probe)(struct matrox_fb_info* info);
574 void (*remove)(struct matrox_fb_info* info, void* data);
575};
576
577int matroxfb_register_driver(struct matroxfb_driver* drv);
578void matroxfb_unregister_driver(struct matroxfb_driver* drv);
579
580#define PCI_OPTION_REG 0x40
581#define PCI_OPTION_ENABLE_ROM 0x40000000
582
583#define PCI_MGA_INDEX 0x44
584#define PCI_MGA_DATA 0x48
585#define PCI_OPTION2_REG 0x50
586#define PCI_OPTION3_REG 0x54
587#define PCI_MEMMISC_REG 0x58
588
589#define M_DWGCTL 0x1C00
590#define M_MACCESS 0x1C04
591#define M_CTLWTST 0x1C08
592
593#define M_PLNWT 0x1C1C
594
595#define M_BCOL 0x1C20
596#define M_FCOL 0x1C24
597
598#define M_SGN 0x1C58
599#define M_LEN 0x1C5C
600#define M_AR0 0x1C60
601#define M_AR1 0x1C64
602#define M_AR2 0x1C68
603#define M_AR3 0x1C6C
604#define M_AR4 0x1C70
605#define M_AR5 0x1C74
606#define M_AR6 0x1C78
607
608#define M_CXBNDRY 0x1C80
609#define M_FXBNDRY 0x1C84
610#define M_YDSTLEN 0x1C88
611#define M_PITCH 0x1C8C
612#define M_YDST 0x1C90
613#define M_YDSTORG 0x1C94
614#define M_YTOP 0x1C98
615#define M_YBOT 0x1C9C
616
617/* mystique only */
618#define M_CACHEFLUSH 0x1FFF
619
620#define M_EXEC 0x0100
621
622#define M_DWG_TRAP 0x04
623#define M_DWG_BITBLT 0x08
624#define M_DWG_ILOAD 0x09
625
626#define M_DWG_LINEAR 0x0080
627#define M_DWG_SOLID 0x0800
628#define M_DWG_ARZERO 0x1000
629#define M_DWG_SGNZERO 0x2000
630#define M_DWG_SHIFTZERO 0x4000
631
632#define M_DWG_REPLACE 0x000C0000
633#define M_DWG_REPLACE2 (M_DWG_REPLACE | 0x40)
634#define M_DWG_XOR 0x00060010
635
636#define M_DWG_BFCOL 0x04000000
637#define M_DWG_BMONOWF 0x08000000
638
639#define M_DWG_TRANSC 0x40000000
640
641#define M_FIFOSTATUS 0x1E10
642#define M_STATUS 0x1E14
643#define M_ICLEAR 0x1E18
644#define M_IEN 0x1E1C
645
646#define M_VCOUNT 0x1E20
647
648#define M_RESET 0x1E40
649#define M_MEMRDBK 0x1E44
650
651#define M_AGP2PLL 0x1E4C
652
653#define M_OPMODE 0x1E54
654#define M_OPMODE_DMA_GEN_WRITE 0x00
655#define M_OPMODE_DMA_BLIT 0x04
656#define M_OPMODE_DMA_VECTOR_WRITE 0x08
657#define M_OPMODE_DMA_LE 0x0000 /* little endian - no transformation */
658#define M_OPMODE_DMA_BE_8BPP 0x0000
659#define M_OPMODE_DMA_BE_16BPP 0x0100
660#define M_OPMODE_DMA_BE_32BPP 0x0200
661#define M_OPMODE_DIR_LE 0x000000 /* little endian - no transformation */
662#define M_OPMODE_DIR_BE_8BPP 0x000000
663#define M_OPMODE_DIR_BE_16BPP 0x010000
664#define M_OPMODE_DIR_BE_32BPP 0x020000
665
666#define M_ATTR_INDEX 0x1FC0
667#define M_ATTR_DATA 0x1FC1
668
669#define M_MISC_REG 0x1FC2
670#define M_3C2_RD 0x1FC2
671
672#define M_SEQ_INDEX 0x1FC4
673#define M_SEQ_DATA 0x1FC5
Paul A. Clarke6d39bed2006-05-20 14:59:51 -0700674#define M_SEQ1 0x01
675#define M_SEQ1_SCROFF 0x20
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677#define M_MISC_REG_READ 0x1FCC
678
679#define M_GRAPHICS_INDEX 0x1FCE
680#define M_GRAPHICS_DATA 0x1FCF
681
682#define M_CRTC_INDEX 0x1FD4
683
684#define M_ATTR_RESET 0x1FDA
685#define M_3DA_WR 0x1FDA
686#define M_INSTS1 0x1FDA
687
688#define M_EXTVGA_INDEX 0x1FDE
689#define M_EXTVGA_DATA 0x1FDF
690
691/* G200 only */
692#define M_SRCORG 0x2CB4
693#define M_DSTORG 0x2CB8
694
695#define M_RAMDAC_BASE 0x3C00
696
697/* fortunately, same on TVP3026 and MGA1064 */
698#define M_DAC_REG (M_RAMDAC_BASE+0)
699#define M_DAC_VAL (M_RAMDAC_BASE+1)
700#define M_PALETTE_MASK (M_RAMDAC_BASE+2)
701
702#define M_X_INDEX 0x00
703#define M_X_DATAREG 0x0A
704
705#define DAC_XGENIOCTRL 0x2A
706#define DAC_XGENIODATA 0x2B
707
708#define M_C2CTL 0x3C10
709
710#define MX_OPTION_BSWAP 0x00000000
711
712#ifdef __LITTLE_ENDIAN
713#define M_OPMODE_4BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
714#define M_OPMODE_8BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
715#define M_OPMODE_16BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
716#define M_OPMODE_24BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
717#define M_OPMODE_32BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
718#else
719#ifdef __BIG_ENDIAN
720#define M_OPMODE_4BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT) /* TODO */
721#define M_OPMODE_8BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_BE_8BPP | M_OPMODE_DMA_BLIT)
722#define M_OPMODE_16BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_BE_16BPP | M_OPMODE_DMA_BLIT)
723#define M_OPMODE_24BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_BE_8BPP | M_OPMODE_DMA_BLIT) /* TODO, ?32 */
724#define M_OPMODE_32BPP (M_OPMODE_DMA_LE | M_OPMODE_DIR_BE_32BPP | M_OPMODE_DMA_BLIT)
725#else
726#error "Byte ordering have to be defined. Cannot continue."
727#endif
728#endif
729
730#define mga_inb(addr) mga_readb(ACCESS_FBINFO(mmio.vbase), (addr))
731#define mga_inl(addr) mga_readl(ACCESS_FBINFO(mmio.vbase), (addr))
732#define mga_outb(addr,val) mga_writeb(ACCESS_FBINFO(mmio.vbase), (addr), (val))
733#define mga_outw(addr,val) mga_writew(ACCESS_FBINFO(mmio.vbase), (addr), (val))
734#define mga_outl(addr,val) mga_writel(ACCESS_FBINFO(mmio.vbase), (addr), (val))
735#define mga_readr(port,idx) (mga_outb((port),(idx)), mga_inb((port)+1))
736#define mga_setr(addr,port,val) mga_outw(addr, ((val)<<8) | (port))
737
738#define mga_fifo(n) do {} while ((mga_inl(M_FIFOSTATUS) & 0xFF) < (n))
739
740#define WaitTillIdle() do {} while (mga_inl(M_STATUS) & 0x10000)
741
742/* code speedup */
743#ifdef CONFIG_FB_MATROX_MILLENIUM
744#define isInterleave(x) (x->interleave)
745#define isMillenium(x) (x->millenium)
746#define isMilleniumII(x) (x->milleniumII)
747#else
748#define isInterleave(x) (0)
749#define isMillenium(x) (0)
750#define isMilleniumII(x) (0)
751#endif
752
753#define matroxfb_DAC_lock() spin_lock(&ACCESS_FBINFO(lock.DAC))
754#define matroxfb_DAC_unlock() spin_unlock(&ACCESS_FBINFO(lock.DAC))
755#define matroxfb_DAC_lock_irqsave(flags) spin_lock_irqsave(&ACCESS_FBINFO(lock.DAC),flags)
756#define matroxfb_DAC_unlock_irqrestore(flags) spin_unlock_irqrestore(&ACCESS_FBINFO(lock.DAC),flags)
757extern void matroxfb_DAC_out(CPMINFO int reg, int val);
758extern int matroxfb_DAC_in(CPMINFO int reg);
759extern void matroxfb_var2my(struct fb_var_screeninfo* fvsi, struct my_timming* mt);
760extern int matroxfb_wait_for_sync(WPMINFO u_int32_t crtc);
761extern int matroxfb_enable_irq(WPMINFO int reenable);
762
763#ifdef MATROXFB_USE_SPINLOCKS
764#define CRITBEGIN spin_lock_irqsave(&ACCESS_FBINFO(lock.accel), critflags);
765#define CRITEND spin_unlock_irqrestore(&ACCESS_FBINFO(lock.accel), critflags);
766#define CRITFLAGS unsigned long critflags;
767#else
768#define CRITBEGIN
769#define CRITEND
770#define CRITFLAGS
771#endif
772
773#endif /* __MATROXFB_H__ */