tridentfb.c

来自「linux 内核源代码」· C语言 代码 · 共 1,427 行 · 第 1/3 页

C
1,427
字号
/* * Frame buffer driver for Trident Blade and Image series * * Copyright 2001, 2002 - Jani Monoses   <jani@iv.ro> * * * CREDITS:(in order of appearance) *	skeletonfb.c by Geert Uytterhoeven and other fb code in drivers/video *	Special thanks ;) to Mattia Crivellini <tia@mclink.it> *	much inspired by the XFree86 4.x Trident driver sources *	by Alan Hourihane the FreeVGA project *	Francesco Salvestrini <salvestrini@users.sf.net> XP support, *	code, suggestions * TODO: *	timing value tweaking so it looks good on every monitor in every mode *	TGUI acceleration */#include <linux/module.h>#include <linux/fb.h>#include <linux/init.h>#include <linux/pci.h>#include <linux/delay.h>#include <video/trident.h>#define VERSION		"0.7.8-NEWAPI"struct tridentfb_par {	int vclk;		/* in MHz */	void __iomem *io_virt;	/* iospace virtual memory address */};static unsigned char eng_oper;	/* engine operation... */static struct fb_ops tridentfb_ops;static struct tridentfb_par default_par;/* FIXME:kmalloc these 3 instead */static struct fb_info fb_info;static u32 pseudo_pal[16];static struct fb_var_screeninfo default_var;static struct fb_fix_screeninfo tridentfb_fix = {	.id = "Trident",	.type = FB_TYPE_PACKED_PIXELS,	.ypanstep = 1,	.visual = FB_VISUAL_PSEUDOCOLOR,	.accel = FB_ACCEL_NONE,};static int chip_id;static int defaultaccel;static int displaytype;/* defaults which are normally overriden by user values *//* video mode */static char *mode = "640x480";static int bpp = 8;static int noaccel;static int center;static int stretch;static int fp;static int crt;static int memsize;static int memdiff;static int nativex;module_param(mode, charp, 0);module_param(bpp, int, 0);module_param(center, int, 0);module_param(stretch, int, 0);module_param(noaccel, int, 0);module_param(memsize, int, 0);module_param(memdiff, int, 0);module_param(nativex, int, 0);module_param(fp, int, 0);module_param(crt, int, 0);static int chip3D;static int chipcyber;static int is3Dchip(int id){	return ((id == BLADE3D) || (id == CYBERBLADEE4) ||		(id == CYBERBLADEi7) || (id == CYBERBLADEi7D) ||		(id == CYBER9397) || (id == CYBER9397DVD) ||		(id == CYBER9520) || (id == CYBER9525DVD) ||		(id == IMAGE975) || (id == IMAGE985) ||		(id == CYBERBLADEi1) || (id == CYBERBLADEi1D) ||		(id == CYBERBLADEAi1) || (id == CYBERBLADEAi1D) ||		(id == CYBERBLADEXPm8) || (id == CYBERBLADEXPm16) ||		(id == CYBERBLADEXPAi1));}static int iscyber(int id){	switch (id) {	case CYBER9388:	case CYBER9382:	case CYBER9385:	case CYBER9397:	case CYBER9397DVD:	case CYBER9520:	case CYBER9525DVD:	case CYBERBLADEE4:	case CYBERBLADEi7D:	case CYBERBLADEi1:	case CYBERBLADEi1D:	case CYBERBLADEAi1:	case CYBERBLADEAi1D:	case CYBERBLADEXPAi1:		return 1;	case CYBER9320:	case TGUI9660:	case IMAGE975:	case IMAGE985:	case BLADE3D:	case CYBERBLADEi7:	/* VIA MPV4 integrated version */	default:		/* case CYBERBLDAEXPm8:  Strange */		/* case CYBERBLDAEXPm16: Strange */		return 0;	}}#define CRT 0x3D0		/* CRTC registers offset for color display */#ifndef TRIDENT_MMIO	#define TRIDENT_MMIO 1#endif#if TRIDENT_MMIO	#define t_outb(val, reg)	writeb(val,((struct tridentfb_par *)(fb_info.par))->io_virt + reg)	#define t_inb(reg)	readb(((struct tridentfb_par*)(fb_info.par))->io_virt + reg)#else	#define t_outb(val, reg) outb(val, reg)	#define t_inb(reg) inb(reg)#endifstatic struct accel_switch {	void (*init_accel) (int, int);	void (*wait_engine) (void);	void (*fill_rect) (u32, u32, u32, u32, u32, u32);	void (*copy_rect) (u32, u32, u32, u32, u32, u32);} *acc;#define writemmr(r, v)	writel(v, ((struct tridentfb_par *)fb_info.par)->io_virt + r)#define readmmr(r)	readl(((struct tridentfb_par *)fb_info.par)->io_virt + r)/* * Blade specific acceleration. */#define point(x, y) ((y) << 16 | (x))#define STA	0x2120#define CMD	0x2144#define ROP	0x2148#define CLR	0x2160#define SR1	0x2100#define SR2	0x2104#define DR1	0x2108#define DR2	0x210C#define ROP_S	0xCCstatic void blade_init_accel(int pitch, int bpp){	int v1 = (pitch >> 3) << 20;	int tmp = 0, v2;	switch (bpp) {	case 8:		tmp = 0;		break;	case 15:		tmp = 5;		break;	case 16:		tmp = 1;		break;	case 24:	case 32:		tmp = 2;		break;	}	v2 = v1 | (tmp << 29);	writemmr(0x21C0, v2);	writemmr(0x21C4, v2);	writemmr(0x21B8, v2);	writemmr(0x21BC, v2);	writemmr(0x21D0, v1);	writemmr(0x21D4, v1);	writemmr(0x21C8, v1);	writemmr(0x21CC, v1);	writemmr(0x216C, 0);}static void blade_wait_engine(void){	while (readmmr(STA) & 0xFA800000) ;}static void blade_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop){	writemmr(CLR, c);	writemmr(ROP, rop ? 0x66 : ROP_S);	writemmr(CMD, 0x20000000 | 1 << 19 | 1 << 4 | 2 << 2);	writemmr(DR1, point(x, y));	writemmr(DR2, point(x + w - 1, y + h - 1));}static void blade_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h){	u32 s1, s2, d1, d2;	int direction = 2;	s1 = point(x1, y1);	s2 = point(x1 + w - 1, y1 + h - 1);	d1 = point(x2, y2);	d2 = point(x2 + w - 1, y2 + h - 1);	if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))		direction = 0;	writemmr(ROP, ROP_S);	writemmr(CMD, 0xE0000000 | 1 << 19 | 1 << 4 | 1 << 2 | direction);	writemmr(SR1, direction ? s2 : s1);	writemmr(SR2, direction ? s1 : s2);	writemmr(DR1, direction ? d2 : d1);	writemmr(DR2, direction ? d1 : d2);}static struct accel_switch accel_blade = {	blade_init_accel,	blade_wait_engine,	blade_fill_rect,	blade_copy_rect,};/* * BladeXP specific acceleration functions */#define ROP_P 0xF0#define masked_point(x, y) ((y & 0xffff)<<16|(x & 0xffff))static void xp_init_accel(int pitch, int bpp){	int tmp = 0, v1;	unsigned char x = 0;	switch (bpp) {	case 8:		x = 0;		break;	case 16:		x = 1;		break;	case 24:		x = 3;		break;	case 32:		x = 2;		break;	}	switch (pitch << (bpp >> 3)) {	case 8192:	case 512:		x |= 0x00;		break;	case 1024:		x |= 0x04;		break;	case 2048:		x |= 0x08;		break;	case 4096:		x |= 0x0C;		break;	}	t_outb(x, 0x2125);	eng_oper = x | 0x40;	switch (bpp) {	case 8:		tmp = 18;		break;	case 15:	case 16:		tmp = 19;		break;	case 24:	case 32:		tmp = 20;		break;	}	v1 = pitch << tmp;	writemmr(0x2154, v1);	writemmr(0x2150, v1);	t_outb(3, 0x2126);}static void xp_wait_engine(void){	int busy;	int count, timeout;	count = 0;	timeout = 0;	for (;;) {		busy = t_inb(STA) & 0x80;		if (busy != 0x80)			return;		count++;		if (count == 10000000) {			/* Timeout */			count = 9990000;			timeout++;			if (timeout == 8) {				/* Reset engine */				t_outb(0x00, 0x2120);				return;			}		}	}}static void xp_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop){	writemmr(0x2127, ROP_P);	writemmr(0x2158, c);	writemmr(0x2128, 0x4000);	writemmr(0x2140, masked_point(h, w));	writemmr(0x2138, masked_point(y, x));	t_outb(0x01, 0x2124);	t_outb(eng_oper, 0x2125);}static void xp_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h){	int direction;	u32 x1_tmp, x2_tmp, y1_tmp, y2_tmp;	direction = 0x0004;	if ((x1 < x2) && (y1 == y2)) {		direction |= 0x0200;		x1_tmp = x1 + w - 1;		x2_tmp = x2 + w - 1;	} else {		x1_tmp = x1;		x2_tmp = x2;	}	if (y1 < y2) {		direction |= 0x0100;		y1_tmp = y1 + h - 1;		y2_tmp = y2 + h - 1;	} else {		y1_tmp = y1;		y2_tmp = y2;	}	writemmr(0x2128, direction);	t_outb(ROP_S, 0x2127);	writemmr(0x213C, masked_point(y1_tmp, x1_tmp));	writemmr(0x2138, masked_point(y2_tmp, x2_tmp));	writemmr(0x2140, masked_point(h, w));	t_outb(0x01, 0x2124);}static struct accel_switch accel_xp = {	xp_init_accel,	xp_wait_engine,	xp_fill_rect,	xp_copy_rect,};/* * Image specific acceleration functions */static void image_init_accel(int pitch, int bpp){	int tmp = 0;	switch (bpp) {	case 8:		tmp = 0;		break;	case 15:		tmp = 5;		break;	case 16:		tmp = 1;		break;	case 24:	case 32:		tmp = 2;		break;	}	writemmr(0x2120, 0xF0000000);	writemmr(0x2120, 0x40000000 | tmp);	writemmr(0x2120, 0x80000000);	writemmr(0x2144, 0x00000000);	writemmr(0x2148, 0x00000000);	writemmr(0x2150, 0x00000000);	writemmr(0x2154, 0x00000000);	writemmr(0x2120, 0x60000000 | (pitch << 16) | pitch);	writemmr(0x216C, 0x00000000);	writemmr(0x2170, 0x00000000);	writemmr(0x217C, 0x00000000);	writemmr(0x2120, 0x10000000);	writemmr(0x2130, (2047 << 16) | 2047);}static void image_wait_engine(void){	while (readmmr(0x2164) & 0xF0000000) ;}static void image_fill_rect(u32 x, u32 y, u32 w, u32 h, u32 c, u32 rop){	writemmr(0x2120, 0x80000000);	writemmr(0x2120, 0x90000000 | ROP_S);	writemmr(0x2144, c);	writemmr(DR1, point(x, y));	writemmr(DR2, point(x + w - 1, y + h - 1));	writemmr(0x2124, 0x80000000 | 3 << 22 | 1 << 10 | 1 << 9);}static void image_copy_rect(u32 x1, u32 y1, u32 x2, u32 y2, u32 w, u32 h){	u32 s1, s2, d1, d2;	int direction = 2;	s1 = point(x1, y1);	s2 = point(x1 + w - 1, y1 + h - 1);	d1 = point(x2, y2);	d2 = point(x2 + w - 1, y2 + h - 1);	if ((y1 > y2) || ((y1 == y2) && (x1 > x2)))		direction = 0;	writemmr(0x2120, 0x80000000);	writemmr(0x2120, 0x90000000 | ROP_S);	writemmr(SR1, direction ? s2 : s1);	writemmr(SR2, direction ? s1 : s2);	writemmr(DR1, direction ? d2 : d1);	writemmr(DR2, direction ? d1 : d2);	writemmr(0x2124, 0x80000000 | 1 << 22 | 1 << 10 | 1 << 7 | direction);}static struct accel_switch accel_image = {	image_init_accel,	image_wait_engine,	image_fill_rect,	image_copy_rect,};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?