18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200, G400 and G450
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * (c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef __MATROXFB_H__
108c2ecf20Sopenharmony_ci#define __MATROXFB_H__
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* general, but fairly heavy, debugging */
138c2ecf20Sopenharmony_ci#undef MATROXFB_DEBUG
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* heavy debugging: */
168c2ecf20Sopenharmony_ci/* -- logs putc[s], so every time a char is displayed, it's logged */
178c2ecf20Sopenharmony_ci#undef MATROXFB_DEBUG_HEAVY
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* This one _could_ cause infinite loops */
208c2ecf20Sopenharmony_ci/* It _does_ cause lots and lots of messages during idle loops */
218c2ecf20Sopenharmony_ci#undef MATROXFB_DEBUG_LOOP
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/* Debug register calls, too? */
248c2ecf20Sopenharmony_ci#undef MATROXFB_DEBUG_REG
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* Guard accelerator accesses with spin_lock_irqsave... */
278c2ecf20Sopenharmony_ci#undef MATROXFB_USE_SPINLOCKS
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include <linux/module.h>
308c2ecf20Sopenharmony_ci#include <linux/kernel.h>
318c2ecf20Sopenharmony_ci#include <linux/errno.h>
328c2ecf20Sopenharmony_ci#include <linux/string.h>
338c2ecf20Sopenharmony_ci#include <linux/mm.h>
348c2ecf20Sopenharmony_ci#include <linux/slab.h>
358c2ecf20Sopenharmony_ci#include <linux/delay.h>
368c2ecf20Sopenharmony_ci#include <linux/fb.h>
378c2ecf20Sopenharmony_ci#include <linux/console.h>
388c2ecf20Sopenharmony_ci#include <linux/selection.h>
398c2ecf20Sopenharmony_ci#include <linux/ioport.h>
408c2ecf20Sopenharmony_ci#include <linux/init.h>
418c2ecf20Sopenharmony_ci#include <linux/timer.h>
428c2ecf20Sopenharmony_ci#include <linux/pci.h>
438c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
448c2ecf20Sopenharmony_ci#include <linux/kd.h>
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#include <asm/io.h>
478c2ecf20Sopenharmony_ci#include <asm/unaligned.h>
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#if defined(CONFIG_PPC_PMAC)
508c2ecf20Sopenharmony_ci#include <asm/prom.h>
518c2ecf20Sopenharmony_ci#include "../macmodes.h"
528c2ecf20Sopenharmony_ci#endif
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#ifdef MATROXFB_DEBUG
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define DEBUG
578c2ecf20Sopenharmony_ci#define DBG(x)		printk(KERN_DEBUG "matroxfb: %s\n", (x));
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#ifdef MATROXFB_DEBUG_HEAVY
608c2ecf20Sopenharmony_ci#define DBG_HEAVY(x)	DBG(x)
618c2ecf20Sopenharmony_ci#else /* MATROXFB_DEBUG_HEAVY */
628c2ecf20Sopenharmony_ci#define DBG_HEAVY(x)	/* DBG_HEAVY */
638c2ecf20Sopenharmony_ci#endif /* MATROXFB_DEBUG_HEAVY */
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#ifdef MATROXFB_DEBUG_LOOP
668c2ecf20Sopenharmony_ci#define DBG_LOOP(x)	DBG(x)
678c2ecf20Sopenharmony_ci#else /* MATROXFB_DEBUG_LOOP */
688c2ecf20Sopenharmony_ci#define DBG_LOOP(x)	/* DBG_LOOP */
698c2ecf20Sopenharmony_ci#endif /* MATROXFB_DEBUG_LOOP */
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#ifdef MATROXFB_DEBUG_REG
728c2ecf20Sopenharmony_ci#define DBG_REG(x)	DBG(x)
738c2ecf20Sopenharmony_ci#else /* MATROXFB_DEBUG_REG */
748c2ecf20Sopenharmony_ci#define DBG_REG(x)	/* DBG_REG */
758c2ecf20Sopenharmony_ci#endif /* MATROXFB_DEBUG_REG */
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#else /* MATROXFB_DEBUG */
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define DBG(x)		/* DBG */
808c2ecf20Sopenharmony_ci#define DBG_HEAVY(x)	/* DBG_HEAVY */
818c2ecf20Sopenharmony_ci#define DBG_REG(x)	/* DBG_REG */
828c2ecf20Sopenharmony_ci#define DBG_LOOP(x)	/* DBG_LOOP */
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#endif /* MATROXFB_DEBUG */
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#ifdef DEBUG
878c2ecf20Sopenharmony_ci#define dprintk(X...)	printk(X)
888c2ecf20Sopenharmony_ci#else
898c2ecf20Sopenharmony_ci#define dprintk(X...)	no_printk(X)
908c2ecf20Sopenharmony_ci#endif
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#ifndef PCI_SS_VENDOR_ID_SIEMENS_NIXDORF
938c2ecf20Sopenharmony_ci#define PCI_SS_VENDOR_ID_SIEMENS_NIXDORF	0x110A
948c2ecf20Sopenharmony_ci#endif
958c2ecf20Sopenharmony_ci#ifndef PCI_SS_VENDOR_ID_MATROX
968c2ecf20Sopenharmony_ci#define PCI_SS_VENDOR_ID_MATROX		PCI_VENDOR_ID_MATROX
978c2ecf20Sopenharmony_ci#endif
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#ifndef PCI_SS_ID_MATROX_PRODUCTIVA_G100_AGP
1008c2ecf20Sopenharmony_ci#define PCI_SS_ID_MATROX_GENERIC		0xFF00
1018c2ecf20Sopenharmony_ci#define PCI_SS_ID_MATROX_PRODUCTIVA_G100_AGP	0xFF01
1028c2ecf20Sopenharmony_ci#define PCI_SS_ID_MATROX_MYSTIQUE_G200_AGP	0xFF02
1038c2ecf20Sopenharmony_ci#define PCI_SS_ID_MATROX_MILLENIUM_G200_AGP	0xFF03
1048c2ecf20Sopenharmony_ci#define PCI_SS_ID_MATROX_MARVEL_G200_AGP	0xFF04
1058c2ecf20Sopenharmony_ci#define PCI_SS_ID_MATROX_MGA_G100_PCI		0xFF05
1068c2ecf20Sopenharmony_ci#define PCI_SS_ID_MATROX_MGA_G100_AGP		0x1001
1078c2ecf20Sopenharmony_ci#define PCI_SS_ID_MATROX_MILLENNIUM_G400_MAX_AGP	0x2179
1088c2ecf20Sopenharmony_ci#define PCI_SS_ID_SIEMENS_MGA_G100_AGP		0x001E /* 30 */
1098c2ecf20Sopenharmony_ci#define PCI_SS_ID_SIEMENS_MGA_G200_AGP		0x0032 /* 50 */
1108c2ecf20Sopenharmony_ci#endif
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define MX_VISUAL_TRUECOLOR	FB_VISUAL_DIRECTCOLOR
1138c2ecf20Sopenharmony_ci#define MX_VISUAL_DIRECTCOLOR	FB_VISUAL_TRUECOLOR
1148c2ecf20Sopenharmony_ci#define MX_VISUAL_PSEUDOCOLOR	FB_VISUAL_PSEUDOCOLOR
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* G-series and Mystique have (almost) same DAC */
1198c2ecf20Sopenharmony_ci#undef NEED_DAC1064
1208c2ecf20Sopenharmony_ci#if defined(CONFIG_FB_MATROX_MYSTIQUE) || defined(CONFIG_FB_MATROX_G)
1218c2ecf20Sopenharmony_ci#define NEED_DAC1064 1
1228c2ecf20Sopenharmony_ci#endif
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_citypedef struct {
1258c2ecf20Sopenharmony_ci	void __iomem*	vaddr;
1268c2ecf20Sopenharmony_ci} vaddr_t;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_cistatic inline unsigned int mga_readb(vaddr_t va, unsigned int offs) {
1298c2ecf20Sopenharmony_ci	return readb(va.vaddr + offs);
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic inline void mga_writeb(vaddr_t va, unsigned int offs, u_int8_t value) {
1338c2ecf20Sopenharmony_ci	writeb(value, va.vaddr + offs);
1348c2ecf20Sopenharmony_ci}
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_cistatic inline void mga_writew(vaddr_t va, unsigned int offs, u_int16_t value) {
1378c2ecf20Sopenharmony_ci	writew(value, va.vaddr + offs);
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic inline u_int32_t mga_readl(vaddr_t va, unsigned int offs) {
1418c2ecf20Sopenharmony_ci	return readl(va.vaddr + offs);
1428c2ecf20Sopenharmony_ci}
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistatic inline void mga_writel(vaddr_t va, unsigned int offs, u_int32_t value) {
1458c2ecf20Sopenharmony_ci	writel(value, va.vaddr + offs);
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic inline void mga_memcpy_toio(vaddr_t va, const void* src, int len) {
1498c2ecf20Sopenharmony_ci#if defined(__alpha__) || defined(__i386__) || defined(__x86_64__)
1508c2ecf20Sopenharmony_ci	/*
1518c2ecf20Sopenharmony_ci	 * iowrite32_rep works for us if:
1528c2ecf20Sopenharmony_ci	 *  (1) Copies data as 32bit quantities, not byte after byte,
1538c2ecf20Sopenharmony_ci	 *  (2) Performs LE ordered stores, and
1548c2ecf20Sopenharmony_ci	 *  (3) It copes with unaligned source (destination is guaranteed to be page
1558c2ecf20Sopenharmony_ci	 *      aligned and length is guaranteed to be multiple of 4).
1568c2ecf20Sopenharmony_ci	 */
1578c2ecf20Sopenharmony_ci	iowrite32_rep(va.vaddr, src, len >> 2);
1588c2ecf20Sopenharmony_ci#else
1598c2ecf20Sopenharmony_ci        u_int32_t __iomem* addr = va.vaddr;
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	if ((unsigned long)src & 3) {
1628c2ecf20Sopenharmony_ci		while (len >= 4) {
1638c2ecf20Sopenharmony_ci			fb_writel(get_unaligned((u32 *)src), addr);
1648c2ecf20Sopenharmony_ci			addr++;
1658c2ecf20Sopenharmony_ci			len -= 4;
1668c2ecf20Sopenharmony_ci			src += 4;
1678c2ecf20Sopenharmony_ci		}
1688c2ecf20Sopenharmony_ci	} else {
1698c2ecf20Sopenharmony_ci		while (len >= 4) {
1708c2ecf20Sopenharmony_ci			fb_writel(*(u32 *)src, addr);
1718c2ecf20Sopenharmony_ci			addr++;
1728c2ecf20Sopenharmony_ci			len -= 4;
1738c2ecf20Sopenharmony_ci			src += 4;
1748c2ecf20Sopenharmony_ci		}
1758c2ecf20Sopenharmony_ci	}
1768c2ecf20Sopenharmony_ci#endif
1778c2ecf20Sopenharmony_ci}
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic inline void vaddr_add(vaddr_t* va, unsigned long offs) {
1808c2ecf20Sopenharmony_ci	va->vaddr += offs;
1818c2ecf20Sopenharmony_ci}
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistatic inline void __iomem* vaddr_va(vaddr_t va) {
1848c2ecf20Sopenharmony_ci	return va.vaddr;
1858c2ecf20Sopenharmony_ci}
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistruct my_timming {
1888c2ecf20Sopenharmony_ci	unsigned int pixclock;
1898c2ecf20Sopenharmony_ci	int mnp;
1908c2ecf20Sopenharmony_ci	unsigned int crtc;
1918c2ecf20Sopenharmony_ci	unsigned int HDisplay;
1928c2ecf20Sopenharmony_ci	unsigned int HSyncStart;
1938c2ecf20Sopenharmony_ci	unsigned int HSyncEnd;
1948c2ecf20Sopenharmony_ci	unsigned int HTotal;
1958c2ecf20Sopenharmony_ci	unsigned int VDisplay;
1968c2ecf20Sopenharmony_ci	unsigned int VSyncStart;
1978c2ecf20Sopenharmony_ci	unsigned int VSyncEnd;
1988c2ecf20Sopenharmony_ci	unsigned int VTotal;
1998c2ecf20Sopenharmony_ci	unsigned int sync;
2008c2ecf20Sopenharmony_ci	int	     dblscan;
2018c2ecf20Sopenharmony_ci	int	     interlaced;
2028c2ecf20Sopenharmony_ci	unsigned int delay;	/* CRTC delay */
2038c2ecf20Sopenharmony_ci};
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_cienum { M_SYSTEM_PLL, M_PIXEL_PLL_A, M_PIXEL_PLL_B, M_PIXEL_PLL_C, M_VIDEO_PLL };
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistruct matrox_pll_cache {
2088c2ecf20Sopenharmony_ci	unsigned int	valid;
2098c2ecf20Sopenharmony_ci	struct {
2108c2ecf20Sopenharmony_ci		unsigned int	mnp_key;
2118c2ecf20Sopenharmony_ci		unsigned int	mnp_value;
2128c2ecf20Sopenharmony_ci		      } data[4];
2138c2ecf20Sopenharmony_ci};
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_cistruct matrox_pll_limits {
2168c2ecf20Sopenharmony_ci	unsigned int	vcomin;
2178c2ecf20Sopenharmony_ci	unsigned int	vcomax;
2188c2ecf20Sopenharmony_ci};
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistruct matrox_pll_features {
2218c2ecf20Sopenharmony_ci	unsigned int	vco_freq_min;
2228c2ecf20Sopenharmony_ci	unsigned int	ref_freq;
2238c2ecf20Sopenharmony_ci	unsigned int	feed_div_min;
2248c2ecf20Sopenharmony_ci	unsigned int	feed_div_max;
2258c2ecf20Sopenharmony_ci	unsigned int	in_div_min;
2268c2ecf20Sopenharmony_ci	unsigned int	in_div_max;
2278c2ecf20Sopenharmony_ci	unsigned int	post_shift_max;
2288c2ecf20Sopenharmony_ci};
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_cistruct matroxfb_par
2318c2ecf20Sopenharmony_ci{
2328c2ecf20Sopenharmony_ci	unsigned int	final_bppShift;
2338c2ecf20Sopenharmony_ci	unsigned int	cmap_len;
2348c2ecf20Sopenharmony_ci	struct {
2358c2ecf20Sopenharmony_ci		unsigned int bytes;
2368c2ecf20Sopenharmony_ci		unsigned int pixels;
2378c2ecf20Sopenharmony_ci		unsigned int chunks;
2388c2ecf20Sopenharmony_ci		      } ydstorg;
2398c2ecf20Sopenharmony_ci};
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistruct matrox_fb_info;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_cistruct matrox_DAC1064_features {
2448c2ecf20Sopenharmony_ci	u_int8_t	xvrefctrl;
2458c2ecf20Sopenharmony_ci	u_int8_t	xmiscctrl;
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci/* current hardware status */
2498c2ecf20Sopenharmony_cistruct mavenregs {
2508c2ecf20Sopenharmony_ci	u_int8_t regs[256];
2518c2ecf20Sopenharmony_ci	int	 mode;
2528c2ecf20Sopenharmony_ci	int	 vlines;
2538c2ecf20Sopenharmony_ci	int	 xtal;
2548c2ecf20Sopenharmony_ci	int	 fv;
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	u_int16_t htotal;
2578c2ecf20Sopenharmony_ci	u_int16_t hcorr;
2588c2ecf20Sopenharmony_ci};
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistruct matrox_crtc2 {
2618c2ecf20Sopenharmony_ci	u_int32_t ctl;
2628c2ecf20Sopenharmony_ci};
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_cistruct matrox_hw_state {
2658c2ecf20Sopenharmony_ci	u_int32_t	MXoptionReg;
2668c2ecf20Sopenharmony_ci	unsigned char	DACclk[6];
2678c2ecf20Sopenharmony_ci	unsigned char	DACreg[80];
2688c2ecf20Sopenharmony_ci	unsigned char	MiscOutReg;
2698c2ecf20Sopenharmony_ci	unsigned char	DACpal[768];
2708c2ecf20Sopenharmony_ci	unsigned char	CRTC[25];
2718c2ecf20Sopenharmony_ci	unsigned char	CRTCEXT[9];
2728c2ecf20Sopenharmony_ci	unsigned char	SEQ[5];
2738c2ecf20Sopenharmony_ci	/* unused for MGA mode, but who knows... */
2748c2ecf20Sopenharmony_ci	unsigned char	GCTL[9];
2758c2ecf20Sopenharmony_ci	/* unused for MGA mode, but who knows... */
2768c2ecf20Sopenharmony_ci	unsigned char	ATTR[21];
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	/* TVOut only */
2798c2ecf20Sopenharmony_ci	struct mavenregs	maven;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	struct matrox_crtc2	crtc2;
2828c2ecf20Sopenharmony_ci};
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cistruct matrox_accel_data {
2858c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_MATROX_MILLENIUM
2868c2ecf20Sopenharmony_ci	unsigned char	ramdac_rev;
2878c2ecf20Sopenharmony_ci#endif
2888c2ecf20Sopenharmony_ci	u_int32_t	m_dwg_rect;
2898c2ecf20Sopenharmony_ci	u_int32_t	m_opmode;
2908c2ecf20Sopenharmony_ci	u_int32_t	m_access;
2918c2ecf20Sopenharmony_ci	u_int32_t	m_pitch;
2928c2ecf20Sopenharmony_ci};
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_cistruct v4l2_queryctrl;
2958c2ecf20Sopenharmony_cistruct v4l2_control;
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_cistruct matrox_altout {
2988c2ecf20Sopenharmony_ci	const char	*name;
2998c2ecf20Sopenharmony_ci	int		(*compute)(void* altout_dev, struct my_timming* input);
3008c2ecf20Sopenharmony_ci	int		(*program)(void* altout_dev);
3018c2ecf20Sopenharmony_ci	int		(*start)(void* altout_dev);
3028c2ecf20Sopenharmony_ci	int		(*verifymode)(void* altout_dev, u_int32_t mode);
3038c2ecf20Sopenharmony_ci	int		(*getqueryctrl)(void* altout_dev,
3048c2ecf20Sopenharmony_ci					struct v4l2_queryctrl* ctrl);
3058c2ecf20Sopenharmony_ci	int		(*getctrl)(void* altout_dev,
3068c2ecf20Sopenharmony_ci				   struct v4l2_control* ctrl);
3078c2ecf20Sopenharmony_ci	int		(*setctrl)(void* altout_dev,
3088c2ecf20Sopenharmony_ci				   struct v4l2_control* ctrl);
3098c2ecf20Sopenharmony_ci};
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci#define MATROXFB_SRC_NONE	0
3128c2ecf20Sopenharmony_ci#define MATROXFB_SRC_CRTC1	1
3138c2ecf20Sopenharmony_ci#define MATROXFB_SRC_CRTC2	2
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_cienum mga_chip { MGA_2064, MGA_2164, MGA_1064, MGA_1164, MGA_G100, MGA_G200, MGA_G400, MGA_G450, MGA_G550 };
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_cistruct matrox_bios {
3188c2ecf20Sopenharmony_ci	unsigned int	bios_valid : 1;
3198c2ecf20Sopenharmony_ci	unsigned int	pins_len;
3208c2ecf20Sopenharmony_ci	unsigned char	pins[128];
3218c2ecf20Sopenharmony_ci	struct {
3228c2ecf20Sopenharmony_ci		unsigned char vMaj, vMin, vRev;
3238c2ecf20Sopenharmony_ci		      } version;
3248c2ecf20Sopenharmony_ci	struct {
3258c2ecf20Sopenharmony_ci		unsigned char state, tvout;
3268c2ecf20Sopenharmony_ci		      } output;
3278c2ecf20Sopenharmony_ci};
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistruct matrox_switch;
3308c2ecf20Sopenharmony_cistruct matroxfb_driver;
3318c2ecf20Sopenharmony_cistruct matroxfb_dh_fb_info;
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_cistruct matrox_vsync {
3348c2ecf20Sopenharmony_ci	wait_queue_head_t	wait;
3358c2ecf20Sopenharmony_ci	unsigned int		cnt;
3368c2ecf20Sopenharmony_ci};
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_cistruct matrox_fb_info {
3398c2ecf20Sopenharmony_ci	struct fb_info		fbcon;
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	struct list_head	next_fb;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	int			dead;
3448c2ecf20Sopenharmony_ci	int                     initialized;
3458c2ecf20Sopenharmony_ci	unsigned int		usecount;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	unsigned int		userusecount;
3488c2ecf20Sopenharmony_ci	unsigned long		irq_flags;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	struct matroxfb_par	curr;
3518c2ecf20Sopenharmony_ci	struct matrox_hw_state	hw;
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	struct matrox_accel_data accel;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	struct pci_dev*		pcidev;
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	struct {
3588c2ecf20Sopenharmony_ci		struct matrox_vsync	vsync;
3598c2ecf20Sopenharmony_ci		unsigned int	pixclock;
3608c2ecf20Sopenharmony_ci		int		mnp;
3618c2ecf20Sopenharmony_ci		int		panpos;
3628c2ecf20Sopenharmony_ci			      } crtc1;
3638c2ecf20Sopenharmony_ci	struct {
3648c2ecf20Sopenharmony_ci		struct matrox_vsync	vsync;
3658c2ecf20Sopenharmony_ci		unsigned int 	pixclock;
3668c2ecf20Sopenharmony_ci		int		mnp;
3678c2ecf20Sopenharmony_ci	struct matroxfb_dh_fb_info*	info;
3688c2ecf20Sopenharmony_ci	struct rw_semaphore	lock;
3698c2ecf20Sopenharmony_ci			      } crtc2;
3708c2ecf20Sopenharmony_ci	struct {
3718c2ecf20Sopenharmony_ci	struct rw_semaphore	lock;
3728c2ecf20Sopenharmony_ci	struct {
3738c2ecf20Sopenharmony_ci		int brightness, contrast, saturation, hue, gamma;
3748c2ecf20Sopenharmony_ci		int testout, deflicker;
3758c2ecf20Sopenharmony_ci				} tvo_params;
3768c2ecf20Sopenharmony_ci			      } altout;
3778c2ecf20Sopenharmony_ci#define MATROXFB_MAX_OUTPUTS		3
3788c2ecf20Sopenharmony_ci	struct {
3798c2ecf20Sopenharmony_ci	unsigned int		src;
3808c2ecf20Sopenharmony_ci	struct matrox_altout*	output;
3818c2ecf20Sopenharmony_ci	void*			data;
3828c2ecf20Sopenharmony_ci	unsigned int		mode;
3838c2ecf20Sopenharmony_ci	unsigned int		default_src;
3848c2ecf20Sopenharmony_ci			      } outputs[MATROXFB_MAX_OUTPUTS];
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci#define MATROXFB_MAX_FB_DRIVERS		5
3878c2ecf20Sopenharmony_ci	struct matroxfb_driver* (drivers[MATROXFB_MAX_FB_DRIVERS]);
3888c2ecf20Sopenharmony_ci	void*			(drivers_data[MATROXFB_MAX_FB_DRIVERS]);
3898c2ecf20Sopenharmony_ci	unsigned int		drivers_count;
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	struct {
3928c2ecf20Sopenharmony_ci	unsigned long	base;	/* physical */
3938c2ecf20Sopenharmony_ci	vaddr_t		vbase;	/* CPU view */
3948c2ecf20Sopenharmony_ci	unsigned int	len;
3958c2ecf20Sopenharmony_ci	unsigned int	len_usable;
3968c2ecf20Sopenharmony_ci	unsigned int	len_maximum;
3978c2ecf20Sopenharmony_ci		      } video;
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci	struct {
4008c2ecf20Sopenharmony_ci	unsigned long	base;	/* physical */
4018c2ecf20Sopenharmony_ci	vaddr_t		vbase;	/* CPU view */
4028c2ecf20Sopenharmony_ci	unsigned int	len;
4038c2ecf20Sopenharmony_ci		      } mmio;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	unsigned int	max_pixel_clock;
4068c2ecf20Sopenharmony_ci	unsigned int	max_pixel_clock_panellink;
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	struct matrox_switch*	hw_switch;
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	struct {
4118c2ecf20Sopenharmony_ci		struct matrox_pll_features pll;
4128c2ecf20Sopenharmony_ci		struct matrox_DAC1064_features DAC1064;
4138c2ecf20Sopenharmony_ci			      } features;
4148c2ecf20Sopenharmony_ci	struct {
4158c2ecf20Sopenharmony_ci		spinlock_t	DAC;
4168c2ecf20Sopenharmony_ci		spinlock_t	accel;
4178c2ecf20Sopenharmony_ci			      } lock;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	enum mga_chip		chip;
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	int			interleave;
4228c2ecf20Sopenharmony_ci	int			millenium;
4238c2ecf20Sopenharmony_ci	int			milleniumII;
4248c2ecf20Sopenharmony_ci	struct {
4258c2ecf20Sopenharmony_ci		int		cfb4;
4268c2ecf20Sopenharmony_ci		const int*	vxres;
4278c2ecf20Sopenharmony_ci		int		cross4MB;
4288c2ecf20Sopenharmony_ci		int		text;
4298c2ecf20Sopenharmony_ci		int		plnwt;
4308c2ecf20Sopenharmony_ci		int		srcorg;
4318c2ecf20Sopenharmony_ci			      } capable;
4328c2ecf20Sopenharmony_ci	int			wc_cookie;
4338c2ecf20Sopenharmony_ci	struct {
4348c2ecf20Sopenharmony_ci		int		precise_width;
4358c2ecf20Sopenharmony_ci		int		mga_24bpp_fix;
4368c2ecf20Sopenharmony_ci		int		novga;
4378c2ecf20Sopenharmony_ci		int		nobios;
4388c2ecf20Sopenharmony_ci		int		nopciretry;
4398c2ecf20Sopenharmony_ci		int		noinit;
4408c2ecf20Sopenharmony_ci		int		sgram;
4418c2ecf20Sopenharmony_ci		int		support32MB;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci		int		accelerator;
4448c2ecf20Sopenharmony_ci		int		text_type_aux;
4458c2ecf20Sopenharmony_ci		int		video64bits;
4468c2ecf20Sopenharmony_ci		int		crtc2;
4478c2ecf20Sopenharmony_ci		int		maven_capable;
4488c2ecf20Sopenharmony_ci		unsigned int	vgastep;
4498c2ecf20Sopenharmony_ci		unsigned int	textmode;
4508c2ecf20Sopenharmony_ci		unsigned int	textstep;
4518c2ecf20Sopenharmony_ci		unsigned int	textvram;	/* character cells */
4528c2ecf20Sopenharmony_ci		unsigned int	ydstorg;	/* offset in bytes from video start to usable memory */
4538c2ecf20Sopenharmony_ci						/* 0 except for 6MB Millenium */
4548c2ecf20Sopenharmony_ci		int		memtype;
4558c2ecf20Sopenharmony_ci		int		g450dac;
4568c2ecf20Sopenharmony_ci		int		dfp_type;
4578c2ecf20Sopenharmony_ci		int		panellink;	/* G400 DFP possible (not G450/G550) */
4588c2ecf20Sopenharmony_ci		int		dualhead;
4598c2ecf20Sopenharmony_ci		unsigned int	fbResource;
4608c2ecf20Sopenharmony_ci			      } devflags;
4618c2ecf20Sopenharmony_ci	struct fb_ops		fbops;
4628c2ecf20Sopenharmony_ci	struct matrox_bios	bios;
4638c2ecf20Sopenharmony_ci	struct {
4648c2ecf20Sopenharmony_ci		struct matrox_pll_limits	pixel;
4658c2ecf20Sopenharmony_ci		struct matrox_pll_limits	system;
4668c2ecf20Sopenharmony_ci		struct matrox_pll_limits	video;
4678c2ecf20Sopenharmony_ci			      } limits;
4688c2ecf20Sopenharmony_ci	struct {
4698c2ecf20Sopenharmony_ci		struct matrox_pll_cache	pixel;
4708c2ecf20Sopenharmony_ci		struct matrox_pll_cache	system;
4718c2ecf20Sopenharmony_ci		struct matrox_pll_cache	video;
4728c2ecf20Sopenharmony_ci				      } cache;
4738c2ecf20Sopenharmony_ci	struct {
4748c2ecf20Sopenharmony_ci		struct {
4758c2ecf20Sopenharmony_ci			unsigned int	video;
4768c2ecf20Sopenharmony_ci			unsigned int	system;
4778c2ecf20Sopenharmony_ci				      } pll;
4788c2ecf20Sopenharmony_ci		struct {
4798c2ecf20Sopenharmony_ci			u_int32_t	opt;
4808c2ecf20Sopenharmony_ci			u_int32_t	opt2;
4818c2ecf20Sopenharmony_ci			u_int32_t	opt3;
4828c2ecf20Sopenharmony_ci			u_int32_t	mctlwtst;
4838c2ecf20Sopenharmony_ci			u_int32_t	mctlwtst_core;
4848c2ecf20Sopenharmony_ci			u_int32_t	memmisc;
4858c2ecf20Sopenharmony_ci			u_int32_t	memrdbk;
4868c2ecf20Sopenharmony_ci			u_int32_t	maccess;
4878c2ecf20Sopenharmony_ci				      } reg;
4888c2ecf20Sopenharmony_ci		struct {
4898c2ecf20Sopenharmony_ci			unsigned int	ddr:1,
4908c2ecf20Sopenharmony_ci			                emrswen:1,
4918c2ecf20Sopenharmony_ci					dll:1;
4928c2ecf20Sopenharmony_ci				      } memory;
4938c2ecf20Sopenharmony_ci			      } values;
4948c2ecf20Sopenharmony_ci	u_int32_t cmap[16];
4958c2ecf20Sopenharmony_ci};
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci#define info2minfo(info) container_of(info, struct matrox_fb_info, fbcon)
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_cistruct matrox_switch {
5008c2ecf20Sopenharmony_ci	int	(*preinit)(struct matrox_fb_info *minfo);
5018c2ecf20Sopenharmony_ci	void	(*reset)(struct matrox_fb_info *minfo);
5028c2ecf20Sopenharmony_ci	int	(*init)(struct matrox_fb_info *minfo, struct my_timming*);
5038c2ecf20Sopenharmony_ci	void	(*restore)(struct matrox_fb_info *minfo);
5048c2ecf20Sopenharmony_ci};
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_cistruct matroxfb_driver {
5078c2ecf20Sopenharmony_ci	struct list_head	node;
5088c2ecf20Sopenharmony_ci	char*			name;
5098c2ecf20Sopenharmony_ci	void*			(*probe)(struct matrox_fb_info* info);
5108c2ecf20Sopenharmony_ci	void			(*remove)(struct matrox_fb_info* info, void* data);
5118c2ecf20Sopenharmony_ci};
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ciint matroxfb_register_driver(struct matroxfb_driver* drv);
5148c2ecf20Sopenharmony_civoid matroxfb_unregister_driver(struct matroxfb_driver* drv);
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci#define PCI_OPTION_REG	0x40
5178c2ecf20Sopenharmony_ci#define   PCI_OPTION_ENABLE_ROM		0x40000000
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci#define PCI_MGA_INDEX	0x44
5208c2ecf20Sopenharmony_ci#define PCI_MGA_DATA	0x48
5218c2ecf20Sopenharmony_ci#define PCI_OPTION2_REG	0x50
5228c2ecf20Sopenharmony_ci#define PCI_OPTION3_REG	0x54
5238c2ecf20Sopenharmony_ci#define PCI_MEMMISC_REG	0x58
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci#define M_DWGCTL	0x1C00
5268c2ecf20Sopenharmony_ci#define M_MACCESS	0x1C04
5278c2ecf20Sopenharmony_ci#define M_CTLWTST	0x1C08
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci#define M_PLNWT		0x1C1C
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci#define M_BCOL		0x1C20
5328c2ecf20Sopenharmony_ci#define M_FCOL		0x1C24
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci#define M_SGN		0x1C58
5358c2ecf20Sopenharmony_ci#define M_LEN		0x1C5C
5368c2ecf20Sopenharmony_ci#define M_AR0		0x1C60
5378c2ecf20Sopenharmony_ci#define M_AR1		0x1C64
5388c2ecf20Sopenharmony_ci#define M_AR2		0x1C68
5398c2ecf20Sopenharmony_ci#define M_AR3		0x1C6C
5408c2ecf20Sopenharmony_ci#define M_AR4		0x1C70
5418c2ecf20Sopenharmony_ci#define M_AR5		0x1C74
5428c2ecf20Sopenharmony_ci#define M_AR6		0x1C78
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci#define M_CXBNDRY	0x1C80
5458c2ecf20Sopenharmony_ci#define M_FXBNDRY	0x1C84
5468c2ecf20Sopenharmony_ci#define M_YDSTLEN	0x1C88
5478c2ecf20Sopenharmony_ci#define M_PITCH		0x1C8C
5488c2ecf20Sopenharmony_ci#define M_YDST		0x1C90
5498c2ecf20Sopenharmony_ci#define M_YDSTORG	0x1C94
5508c2ecf20Sopenharmony_ci#define M_YTOP		0x1C98
5518c2ecf20Sopenharmony_ci#define M_YBOT		0x1C9C
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_ci/* mystique only */
5548c2ecf20Sopenharmony_ci#define M_CACHEFLUSH	0x1FFF
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci#define M_EXEC		0x0100
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci#define M_DWG_TRAP	0x04
5598c2ecf20Sopenharmony_ci#define M_DWG_BITBLT	0x08
5608c2ecf20Sopenharmony_ci#define M_DWG_ILOAD	0x09
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_ci#define M_DWG_LINEAR	0x0080
5638c2ecf20Sopenharmony_ci#define M_DWG_SOLID	0x0800
5648c2ecf20Sopenharmony_ci#define M_DWG_ARZERO	0x1000
5658c2ecf20Sopenharmony_ci#define M_DWG_SGNZERO	0x2000
5668c2ecf20Sopenharmony_ci#define M_DWG_SHIFTZERO	0x4000
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci#define M_DWG_REPLACE	0x000C0000
5698c2ecf20Sopenharmony_ci#define M_DWG_REPLACE2	(M_DWG_REPLACE | 0x40)
5708c2ecf20Sopenharmony_ci#define M_DWG_XOR	0x00060010
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci#define M_DWG_BFCOL	0x04000000
5738c2ecf20Sopenharmony_ci#define M_DWG_BMONOWF	0x08000000
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci#define M_DWG_TRANSC	0x40000000
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci#define M_FIFOSTATUS	0x1E10
5788c2ecf20Sopenharmony_ci#define M_STATUS	0x1E14
5798c2ecf20Sopenharmony_ci#define M_ICLEAR	0x1E18
5808c2ecf20Sopenharmony_ci#define M_IEN		0x1E1C
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_ci#define M_VCOUNT	0x1E20
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ci#define M_RESET		0x1E40
5858c2ecf20Sopenharmony_ci#define M_MEMRDBK	0x1E44
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci#define M_AGP2PLL	0x1E4C
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci#define M_OPMODE	0x1E54
5908c2ecf20Sopenharmony_ci#define     M_OPMODE_DMA_GEN_WRITE	0x00
5918c2ecf20Sopenharmony_ci#define     M_OPMODE_DMA_BLIT		0x04
5928c2ecf20Sopenharmony_ci#define     M_OPMODE_DMA_VECTOR_WRITE	0x08
5938c2ecf20Sopenharmony_ci#define     M_OPMODE_DMA_LE		0x0000		/* little endian - no transformation */
5948c2ecf20Sopenharmony_ci#define     M_OPMODE_DMA_BE_8BPP	0x0000
5958c2ecf20Sopenharmony_ci#define     M_OPMODE_DMA_BE_16BPP	0x0100
5968c2ecf20Sopenharmony_ci#define     M_OPMODE_DMA_BE_32BPP	0x0200
5978c2ecf20Sopenharmony_ci#define     M_OPMODE_DIR_LE		0x000000	/* little endian - no transformation */
5988c2ecf20Sopenharmony_ci#define     M_OPMODE_DIR_BE_8BPP	0x000000
5998c2ecf20Sopenharmony_ci#define     M_OPMODE_DIR_BE_16BPP	0x010000
6008c2ecf20Sopenharmony_ci#define     M_OPMODE_DIR_BE_32BPP	0x020000
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci#define M_ATTR_INDEX	0x1FC0
6038c2ecf20Sopenharmony_ci#define M_ATTR_DATA	0x1FC1
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci#define M_MISC_REG	0x1FC2
6068c2ecf20Sopenharmony_ci#define M_3C2_RD	0x1FC2
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci#define M_SEQ_INDEX	0x1FC4
6098c2ecf20Sopenharmony_ci#define M_SEQ_DATA	0x1FC5
6108c2ecf20Sopenharmony_ci#define     M_SEQ1		0x01
6118c2ecf20Sopenharmony_ci#define        M_SEQ1_SCROFF		0x20
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci#define M_MISC_REG_READ	0x1FCC
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_ci#define M_GRAPHICS_INDEX 0x1FCE
6168c2ecf20Sopenharmony_ci#define M_GRAPHICS_DATA	0x1FCF
6178c2ecf20Sopenharmony_ci
6188c2ecf20Sopenharmony_ci#define M_CRTC_INDEX	0x1FD4
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci#define M_ATTR_RESET	0x1FDA
6218c2ecf20Sopenharmony_ci#define M_3DA_WR	0x1FDA
6228c2ecf20Sopenharmony_ci#define M_INSTS1	0x1FDA
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci#define M_EXTVGA_INDEX	0x1FDE
6258c2ecf20Sopenharmony_ci#define M_EXTVGA_DATA	0x1FDF
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci/* G200 only */
6288c2ecf20Sopenharmony_ci#define M_SRCORG	0x2CB4
6298c2ecf20Sopenharmony_ci#define M_DSTORG	0x2CB8
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci#define M_RAMDAC_BASE	0x3C00
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci/* fortunately, same on TVP3026 and MGA1064 */
6348c2ecf20Sopenharmony_ci#define M_DAC_REG	(M_RAMDAC_BASE+0)
6358c2ecf20Sopenharmony_ci#define M_DAC_VAL	(M_RAMDAC_BASE+1)
6368c2ecf20Sopenharmony_ci#define M_PALETTE_MASK	(M_RAMDAC_BASE+2)
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci#define M_X_INDEX	0x00
6398c2ecf20Sopenharmony_ci#define M_X_DATAREG	0x0A
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_ci#define DAC_XGENIOCTRL		0x2A
6428c2ecf20Sopenharmony_ci#define DAC_XGENIODATA		0x2B
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_ci#define M_C2CTL		0x3C10
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci#define MX_OPTION_BSWAP         0x00000000
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_ci#ifdef __LITTLE_ENDIAN
6498c2ecf20Sopenharmony_ci#define M_OPMODE_4BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
6508c2ecf20Sopenharmony_ci#define M_OPMODE_8BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
6518c2ecf20Sopenharmony_ci#define M_OPMODE_16BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
6528c2ecf20Sopenharmony_ci#define M_OPMODE_24BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
6538c2ecf20Sopenharmony_ci#define M_OPMODE_32BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_LE | M_OPMODE_DMA_BLIT)
6548c2ecf20Sopenharmony_ci#else
6558c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN
6568c2ecf20Sopenharmony_ci#define M_OPMODE_4BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_LE       | M_OPMODE_DMA_BLIT)	/* TODO */
6578c2ecf20Sopenharmony_ci#define M_OPMODE_8BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_BE_8BPP  | M_OPMODE_DMA_BLIT)
6588c2ecf20Sopenharmony_ci#define M_OPMODE_16BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_BE_16BPP | M_OPMODE_DMA_BLIT)
6598c2ecf20Sopenharmony_ci#define M_OPMODE_24BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_BE_8BPP  | M_OPMODE_DMA_BLIT)	/* TODO, ?32 */
6608c2ecf20Sopenharmony_ci#define M_OPMODE_32BPP	(M_OPMODE_DMA_LE | M_OPMODE_DIR_BE_32BPP | M_OPMODE_DMA_BLIT)
6618c2ecf20Sopenharmony_ci#else
6628c2ecf20Sopenharmony_ci#error "Byte ordering have to be defined. Cannot continue."
6638c2ecf20Sopenharmony_ci#endif
6648c2ecf20Sopenharmony_ci#endif
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci#define mga_inb(addr)		mga_readb(minfo->mmio.vbase, (addr))
6678c2ecf20Sopenharmony_ci#define mga_inl(addr)		mga_readl(minfo->mmio.vbase, (addr))
6688c2ecf20Sopenharmony_ci#define mga_outb(addr,val)	mga_writeb(minfo->mmio.vbase, (addr), (val))
6698c2ecf20Sopenharmony_ci#define mga_outw(addr,val)	mga_writew(minfo->mmio.vbase, (addr), (val))
6708c2ecf20Sopenharmony_ci#define mga_outl(addr,val)	mga_writel(minfo->mmio.vbase, (addr), (val))
6718c2ecf20Sopenharmony_ci#define mga_readr(port,idx)	(mga_outb((port),(idx)), mga_inb((port)+1))
6728c2ecf20Sopenharmony_ci#define mga_setr(addr,port,val)	mga_outw(addr, ((val)<<8) | (port))
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ci#define mga_fifo(n)	do {} while ((mga_inl(M_FIFOSTATUS) & 0xFF) < (n))
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci#define WaitTillIdle()	do { mga_inl(M_STATUS); do {} while (mga_inl(M_STATUS) & 0x10000); } while (0)
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci/* code speedup */
6798c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_MATROX_MILLENIUM
6808c2ecf20Sopenharmony_ci#define isInterleave(x)	 (x->interleave)
6818c2ecf20Sopenharmony_ci#define isMillenium(x)	 (x->millenium)
6828c2ecf20Sopenharmony_ci#define isMilleniumII(x) (x->milleniumII)
6838c2ecf20Sopenharmony_ci#else
6848c2ecf20Sopenharmony_ci#define isInterleave(x)  (0)
6858c2ecf20Sopenharmony_ci#define isMillenium(x)	 (0)
6868c2ecf20Sopenharmony_ci#define isMilleniumII(x) (0)
6878c2ecf20Sopenharmony_ci#endif
6888c2ecf20Sopenharmony_ci
6898c2ecf20Sopenharmony_ci#define matroxfb_DAC_lock()                   spin_lock(&minfo->lock.DAC)
6908c2ecf20Sopenharmony_ci#define matroxfb_DAC_unlock()                 spin_unlock(&minfo->lock.DAC)
6918c2ecf20Sopenharmony_ci#define matroxfb_DAC_lock_irqsave(flags)      spin_lock_irqsave(&minfo->lock.DAC, flags)
6928c2ecf20Sopenharmony_ci#define matroxfb_DAC_unlock_irqrestore(flags) spin_unlock_irqrestore(&minfo->lock.DAC, flags)
6938c2ecf20Sopenharmony_ciextern void matroxfb_DAC_out(const struct matrox_fb_info *minfo, int reg,
6948c2ecf20Sopenharmony_ci			     int val);
6958c2ecf20Sopenharmony_ciextern int matroxfb_DAC_in(const struct matrox_fb_info *minfo, int reg);
6968c2ecf20Sopenharmony_ciextern void matroxfb_var2my(struct fb_var_screeninfo* fvsi, struct my_timming* mt);
6978c2ecf20Sopenharmony_ciextern int matroxfb_wait_for_sync(struct matrox_fb_info *minfo, u_int32_t crtc);
6988c2ecf20Sopenharmony_ciextern int matroxfb_enable_irq(struct matrox_fb_info *minfo, int reenable);
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_ci#ifdef MATROXFB_USE_SPINLOCKS
7018c2ecf20Sopenharmony_ci#define CRITBEGIN  spin_lock_irqsave(&minfo->lock.accel, critflags);
7028c2ecf20Sopenharmony_ci#define CRITEND	   spin_unlock_irqrestore(&minfo->lock.accel, critflags);
7038c2ecf20Sopenharmony_ci#define CRITFLAGS  unsigned long critflags;
7048c2ecf20Sopenharmony_ci#else
7058c2ecf20Sopenharmony_ci#define CRITBEGIN
7068c2ecf20Sopenharmony_ci#define CRITEND
7078c2ecf20Sopenharmony_ci#define CRITFLAGS
7088c2ecf20Sopenharmony_ci#endif
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci#endif	/* __MATROXFB_H__ */
711