vga_out8(0x3d4, 0x68);	/* memory control 1 */ if( (vga_in8(0x3d5) & 0xC0) == (0x01 << 6) ) 
vga_out8(0x3d4, 0x68, par);	/* memory control 1 */ if( (vga_in8(0x3d5, par) & 0xC0) == (0x01 << 6) ) 
static int __devinit savage_init_hw (struct savagefb_par *par){	unsigned char config1, m, n, n1, n2, sr8, cr3f, cr66 = 0, tmp;	static unsigned char RamSavage3D[] = { 8, 4, 4, 2 };	static unsigned char RamSavage4[] =  { 2, 4, 8, 12, 16, 32, 64, 32 };	static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 };	static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 2, 2 };	int videoRam, videoRambytes, dvi;	DBG("savage_init_hw");	/* unprotect CRTC[0-7] */	vga_out8(0x3d4, 0x11);	tmp = vga_in8(0x3d5);	vga_out8(0x3d5, tmp & 0x7f);	/* unlock extended regs */	vga_out16(0x3d4, 0x4838);	vga_out16(0x3d4, 0xa039);	vga_out16(0x3c4, 0x0608);	vga_out8(0x3d4, 0x40);	tmp = vga_in8(0x3d5);	vga_out8(0x3d5, tmp & ~0x01);	/* unlock sys regs */	vga_out8(0x3d4, 0x38);	vga_out8(0x3d5, 0x48);	/* Unlock system registers. */	vga_out16(0x3d4, 0x4838);	/* Next go on to detect amount of installed ram */	vga_out8(0x3d4, 0x36);            /* for register CR36 (CONFG_REG1), */	config1 = vga_in8(0x3d5);           /* get amount of vram installed */	/* Compute the amount of video memory and offscreen memory. */	switch  (par->chip) {	case S3_SAVAGE3D:		videoRam = RamSavage3D[ (config1 & 0xC0) >> 6 ] * 1024;		break;	case S3_SAVAGE4:		/*		 * The Savage4 has one ugly special case to consider.  On		 * systems with 4 banks of 2Mx32 SDRAM, the BIOS says 4MB		 * when it really means 8MB.  Why do it the same when you		 * can do it different...		 */		vga_out8(0x3d4, 0x68);	/* memory control 1 */		if( (vga_in8(0x3d5) & 0xC0) == (0x01 << 6) )			RamSavage4[1] = 8;		/*FALLTHROUGH*/	case S3_SAVAGE2000:		videoRam = RamSavage4[ (config1 & 0xE0) >> 5 ] * 1024;		break;	case S3_SAVAGE_MX:	case S3_SUPERSAVAGE:		videoRam = RamSavageMX[ (config1 & 0x0E) >> 1 ] * 1024;		break;	case S3_PROSAVAGE:		videoRam = RamSavageNB[ (config1 & 0xE0) >> 5 ] * 1024;		break;	default:		/* How did we get here? */		videoRam = 0;		break;	}	videoRambytes = videoRam * 1024;	printk (KERN_INFO "savagefb: probed videoram:  %dk\n", videoRam);	/* reset graphics engine to avoid memory corruption */	vga_out8 (0x3d4, 0x66);	cr66 = vga_in8 (0x3d5);	vga_out8 (0x3d5, cr66 | 0x02);	udelay (10000);	vga_out8 (0x3d4, 0x66);	vga_out8 (0x3d5, cr66 & ~0x02);	/* clear reset flag */	udelay (10000);	/*	 * reset memory interface, 3D engine, AGP master, PCI master,	 * master engine unit, motion compensation/LPB	 */	vga_out8 (0x3d4, 0x3f);	cr3f = vga_in8 (0x3d5);	vga_out8 (0x3d5, cr3f | 0x08);	udelay (10000);	vga_out8 (0x3d4, 0x3f);	vga_out8 (0x3d5, cr3f & ~0x08);	/* clear reset flags */	udelay (10000);	/* Savage ramdac speeds */	par->numClocks = 4;	par->clock[0] = 250000;	par->clock[1] = 250000;	par->clock[2] = 220000;	par->clock[3] = 220000;	/* detect current mclk */	vga_out8(0x3c4, 0x08);	sr8 = vga_in8(0x3c5);	vga_out8(0x3c5, 0x06);	vga_out8(0x3c4, 0x10);	n = vga_in8(0x3c5);	vga_out8(0x3c4, 0x11);	m = vga_in8(0x3c5);	vga_out8(0x3c4, 0x08);	vga_out8(0x3c5, sr8);	m &= 0x7f;	n1 = n & 0x1f;	n2 = (n >> 5) & 0x03;	par->MCLK = ((1431818 * (m+2)) / (n1+2) / (1 << n2) + 50) / 100;	printk (KERN_INFO "savagefb: Detected current MCLK value of %d kHz\n",		par->MCLK);	/* check for DVI/flat panel */	dvi = 0;	if (par->chip == S3_SAVAGE4) {		unsigned char sr30 = 0x00;		vga_out8(0x3c4, 0x30);		/* clear bit 1 */		vga_out8(0x3c5, vga_in8(0x3c5) & ~0x02);		sr30 = vga_in8(0x3c5);		if (sr30 & 0x02 /*0x04 */) {			dvi = 1;			printk("savagefb: Digital Flat Panel Detected\n");		}	}	if (S3_SAVAGE_MOBILE_SERIES(par->chip) && !par->crtonly)		par->display_type = DISP_LCD;	else if (dvi || (par->chip == S3_SAVAGE4 && par->dvi))		par->display_type = DISP_DFP;	else		par->display_type = DISP_CRT;	/* Check LCD panel parrmation */	if (par->display_type == DISP_LCD) {		unsigned char cr6b = VGArCR( 0x6b );		int panelX = (VGArSEQ (0x61) +			      ((VGArSEQ (0x66) & 0x02) << 7) + 1) * 8;		int panelY = (VGArSEQ (0x69) +			      ((VGArSEQ (0x6e) & 0x70) << 4) + 1);		char * sTechnology = "Unknown";		/* OK, I admit it.  I don't know how to limit the max dot clock		 * for LCD panels of various sizes.  I thought I copied the		 * formula from the BIOS, but many users have parrmed me of		 * my folly.		 *		 * Instead, I'll abandon any attempt to automatically limit the		 * clock, and add an LCDClock option to XF86Config.  Some day,		 * I should come back to this.		 */		enum ACTIVE_DISPLAYS { /* These are the bits in CR6B */			ActiveCRT = 0x01,			ActiveLCD = 0x02,			ActiveTV = 0x04,			ActiveCRT2 = 0x20,			ActiveDUO = 0x80		};		if ((VGArSEQ (0x39) & 0x03) == 0) {			sTechnology = "TFT";		} else if ((VGArSEQ (0x30) & 0x01) == 0) {			sTechnology = "DSTN";		} else 	{			sTechnology = "STN";		}		printk (KERN_INFO "savagefb: %dx%d %s LCD panel detected %s\n",			panelX, panelY, sTechnology,			cr6b & ActiveLCD ? "and active" : "but not active");		if( cr6b & ActiveLCD ) 	{			/*			 * If the LCD is active and panel expansion is enabled,			 * we probably want to kill the HW cursor.			 */			printk (KERN_INFO "savagefb: Limiting video mode to "				"%dx%d\n", panelX, panelY );			par->SavagePanelWidth = panelX;			par->SavagePanelHeight = panelY;		} else			par->display_type = DISP_CRT;	}	savage_get_default_par (par);	if( S3_SAVAGE4_SERIES(par->chip) ) {		/*		 * The Savage4 and ProSavage have COB coherency bugs which		 * render the buffer useless.  We disable it.		 */		par->cob_index = 2;		par->cob_size = 0x8000 << par->cob_index;		par->cob_offset = videoRambytes;	} else {		/* We use 128kB for the COB on all chips. */		par->cob_index  = 7;		par->cob_size   = 0x400 << par->cob_index;		par->cob_offset = videoRambytes - par->cob_size;	}	return videoRambytes;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/1cc650c69f3079ce3c616c998a741bcf6ddf4f4d/savagefb_driver.c/buggy/drivers/video/savage/savagefb_driver.c