Enscript Output

extractedLnx/linux-2.5.65/drivers/video/sis/sis_main.c_sisfb_set_var.c

static int sisfb_set_var(struct fb_var_screeninfo *var, int con,
			 struct fb_info *info)
{
	int err;
	unsigned int cols, rows;

	fb_display[con].var.activate = FB_ACTIVATE_NOW;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,23)
	if (sisfb_do_set_var(var, con == info->currcon, info)) {
#else
        if (sisfb_do_set_var(var, con == currcon, info)) {
#endif
		sisfb_crtc_to_var(var);
		return -EINVAL;
	}

	sisfb_crtc_to_var(var);
	
	sisfb_set_disp(con, var);

	if (info->changevar)
		(*info->changevar) (con);

	if ((err = fb_alloc_cmap(&fb_display[con].cmap, 0, 0)))
		return err;

	sisfb_do_install_cmap(con, info);
	
	cols = sisbios_mode[sisfb_mode_idx].cols;
	rows = sisbios_mode[sisfb_mode_idx].rows;
	vc_resize_con(rows, cols, fb_display[con].conp->vc_num);

	return 0;
}

static int sisfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
			  struct fb_info *info)
{
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,23)
	if (con == info->currcon)
#else
        if (con == currcon)
#endif
		return fb_get_cmap(cmap, kspc, sis_getcolreg, info);
	else if (fb_display[con].cmap.len)	
		fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
	else
		fb_copy_cmap(fb_default_cmap(video_cmap_len), cmap, kspc ? 0 : 2);

	return 0;
}

static int sisfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
			  struct fb_info *info)
{
	int err;

	if (!fb_display[con].cmap.len) {
		err = fb_alloc_cmap(&fb_display[con].cmap, video_cmap_len, 0);
		if (err)
			return err;
	}
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,23)
	if (con == info->currcon)
		return fb_set_cmap(cmap, kspc, info);
#else
        if (con == currcon)
		return fb_set_cmap(cmap, kspc, sisfb_setcolreg, info);
#endif
	else
		fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1);
	return 0;
}

static int sisfb_ioctl(struct inode *inode, struct file *file,
		       unsigned int cmd, unsigned long arg, int con,
		       struct fb_info *info)
{
	switch (cmd) {
	   case FBIO_ALLOC:
		if (!capable(CAP_SYS_RAWIO))
			return -EPERM;
		sis_malloc((struct sis_memreq *) arg);
		break;
	   case FBIO_FREE:
		if (!capable(CAP_SYS_RAWIO))
			return -EPERM;
		sis_free(*(unsigned long *) arg);
		break;
	   case FBIOGET_GLYPH:
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,23)
		sis_get_glyph((SIS_GLYINFO *) arg);
#else
                sis_get_glyph(info,(SIS_GLYINFO *) arg);
#endif
		break;
	   case FBIOGET_HWCINFO:
		{
			unsigned long *hwc_offset = (unsigned long *) arg;

			if (sisfb_caps & HW_CURSOR_CAP)
				*hwc_offset = sisfb_hwcursor_vbase -
				    (unsigned long) ivideo.video_vbase;
			else
				*hwc_offset = 0;

			break;
		}
	   case FBIOPUT_MODEINFO:
		{
			struct mode_info *x = (struct mode_info *)arg;
			
			ivideo.video_bpp      = x->bpp;
			ivideo.video_width    = x->xres;
			ivideo.video_height   = x->yres;
			ivideo.video_vwidth   = x->v_xres;
			ivideo.video_vheight  = x->v_yres;
			ivideo.org_x          = x->org_x;
			ivideo.org_y          = x->org_y;
			ivideo.refresh_rate   = x->vrate;
			
			break;
		}
	   case FBIOGET_DISPINFO:
		sis_dispinfo((struct ap_data *)arg);
		break;
	   case SISFB_GET_INFO:  /* TW: New for communication with X driver */
	        {
			sisfb_info *x = (sisfb_info *)arg;

			x->sisfb_id = SISFB_ID;
			x->sisfb_version = VER_MAJOR;
			x->sisfb_revision = VER_MINOR;
			x->sisfb_patchlevel = VER_LEVEL;
			x->chip_id = ivideo.chip_id;
			x->memory = ivideo.video_size / 1024;
			x->heapstart = ivideo.heapstart / 1024;
			x->fbvidmode = sisfb_mode_no;
	                break;
		}
	   default:
		return -EINVAL;
	}
	return 0;

}

static int sisfb_mmap(struct fb_info *info, struct file *file,
		      struct vm_area_struct *vma)
{
	struct fb_var_screeninfo var;
	unsigned long start;
	unsigned long off;
	u32 len;

	if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
		return -EINVAL;
	off = vma->vm_pgoff << PAGE_SHIFT;
	
	start = (unsigned long) ivideo.video_base;
	len = PAGE_ALIGN((start & ~PAGE_MASK) + ivideo.video_size);

	if (off >= len) {
		off -= len;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,23)
		sisfb_get_var(&var, info->currcon, info);
#else
		sisfb_get_var(&var, currcon, info);
#endif
		if (var.accel_flags)
			return -EINVAL;
		start = (unsigned long) ivideo.mmio_base;
		len = PAGE_ALIGN((start & ~PAGE_MASK) + sisfb_mmio_size);
	}

	start &= PAGE_MASK;
	if ((vma->vm_end - vma->vm_start + off) > len)
		return -EINVAL;
	off += start;
	vma->vm_pgoff = off >> PAGE_SHIFT;

#if defined(__i386__) || defined(__x86_64__)
	if (boot_cpu_data.x86 > 3)
		pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
	if (io_remap_page_range(vma->vm_start, off, vma->vm_end - vma->vm_start,
				vma->vm_page_prot))
#else	/* TW: 2.5 API */
	if (io_remap_page_range(vma, vma->vm_start, off, vma->vm_end - vma->vm_start,
				vma->vm_page_prot))
#endif
		return -EAGAIN;
	return 0;

}

static struct fb_ops sisfb_ops = {
	.owner		= THIS_MODULE,
	.fb_get_fix	= sisfb_get_fix,
	.fb_get_var	= sisfb_get_var,
	.fb_set_var	= sisfb_set_var,
	.fb_get_cmap	= sisfb_get_cmap,
	.fb_set_cmap	= sisfb_set_cmap,
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,23)
        .fb_setcolreg	= sisfb_setcolreg,
        .fb_blank	= sisfb_blank,
#endif
	.fb_ioctl	= sisfb_ioctl,
	.fb_mmap	= sisfb_mmap,
};

/* ------------ Interface to the low level console driver -------------*/

static int sisfb_update_var(int con, struct fb_info *info)
{
	return 0;
}

static int sisfb_switch(int con, struct fb_info *info)
{
	int cols, rows;

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,23)
	if (fb_display[info->currcon].cmap.len)
		fb_get_cmap(&fb_display[info->currcon].cmap, 1, sis_getcolreg, info);
#else
        if (fb_display[currcon].cmap.len)
		fb_get_cmap(&fb_display[currcon].cmap, 1, sis_getcolreg, info);
#endif

	fb_display[con].var.activate = FB_ACTIVATE_NOW;

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,23)
	if (!memcmp(&fb_display[con].var, &fb_display[info->currcon].var,
	                           sizeof(struct fb_var_screeninfo))) {
		info->currcon = con;
		return 1;
	}

	info->currcon = con;
#else
	if (!memcmp(&fb_display[con].var, &fb_display[currcon].var,
	                           sizeof(struct fb_var_screeninfo))) {
		currcon = con;
		return 1;
	}

	currcon = con;
#endif

	sisfb_do_set_var(&fb_display[con].var, 1, info);

	sisfb_set_disp(con, &fb_display[con].var);
	
	sisfb_do_install_cmap(con, info);

	cols = sisbios_mode[sisfb_mode_idx].cols;
	rows = sisbios_mode[sisfb_mode_idx].rows;
	vc_resize_con(rows, cols, fb_display[con].conp->vc_num);

	sisfb_update_var(con, info);

	return 1;
}

static void sisfb_blank(int blank, struct fb_info *info)
{
	u8 reg;

	vgawb(CRTC_ADR, 0x17);
	reg = vgarb(CRTC_DATA);

	if (blank > 0)		
		reg &= 0x7f;
	else			
		reg |= 0x80;

	vgawb(CRTC_ADR, 0x17);
	vgawb(CRTC_DATA, reg);
}

int sisfb_setup(char *options)
{
	char *this_opt;

	fb_info.fontname[0] = '\0';
	ivideo.refresh_rate = 0;

	if (!options || !*options)
		return 0;

	while((this_opt = strsep(&options, ",")) != NULL) {
		if (!*this_opt)
			continue;

		if (!strcmp(this_opt, "inverse")) {
			sisfb_inverse = 1;
			fb_invert_cmaps();
		} else if (!strncmp(this_opt, "font:", 5)) {
			strcpy(fb_info.fontname, this_opt + 5);
		} else if (!strncmp(this_opt, "mode:", 5)) {
			sisfb_search_mode(this_opt + 5);
		} else if (!strncmp(this_opt, "vrate:", 6)) {
			ivideo.refresh_rate =
			    simple_strtoul(this_opt + 6, NULL, 0);
		} else if (!strncmp(this_opt, "rate:", 5)) {
			ivideo.refresh_rate =
			    simple_strtoul(this_opt + 5, NULL, 0);
		} else if (!strncmp(this_opt, "off", 3)) {
			sisfb_off = 1;
		} else if (!strncmp(this_opt, "crt1off", 7)) {
			sisfb_crt1off = 1;
		} else if (!strncmp(this_opt, "filter:", 7)) {
			filter = (int)simple_strtoul(this_opt + 7, NULL, 0);
		} else if (!strncmp(this_opt, "forcecrt2type:", 14)) {
			sisfb_search_crt2type(this_opt + 14);
		} else if (!strncmp(this_opt, "forcecrt1:", 10)) {
			sisfb_forcecrt1 = (int)simple_strtoul(this_opt + 10, NULL, 0);
                } else if (!strncmp(this_opt, "tvmode:",7)) {
                        if (!strncmp(this_opt + 7, "pal",3))
                         	sisfb_tvmode = 1;
                        if (!strncmp(this_opt + 7, "ntsc",4))
                         	sisfb_tvmode = 2;
                } else if (!strncmp(this_opt, "mem:",4)) {
		        sisfb_mem = simple_strtoul(this_opt + 4, NULL, 0);
                } else if (!strncmp(this_opt, "dstn:", 5)) {
			enable_dstn = simple_strtoul(this_opt + 5, NULL, 0);
			/* TW: DSTN overrules forcecrt2type */
			if (enable_dstn) sisfb_crt2type = DISPTYPE_LCD;
		} else if (!strncmp(this_opt, "queuemode:", 10)) {
			sisfb_search_queuemode(this_opt + 10);
		} else if (!strncmp(this_opt, "pdc:", 4)) {
		        sisfb_pdc = simple_strtoul(this_opt + 4, NULL, 0);
		        if(sisfb_pdc & ~0x3c) {
			   printk(KERN_INFO "sisfb: Illegal pdc parameter\n");
			   sisfb_pdc = 0;
		        }
		} else {
			printk(KERN_INFO "sisfb: Invalid parameter %s\n", this_opt);
		}
	}
	return 0;
}

int __init sisfb_init(void)
{
	struct pci_dev *pdev = NULL;
	struct board *b;
	int pdev_valid = 0;
	//unsigned long rom_vbase;
	u32 reg32;
	u16 reg16;
	u8  reg;
	int temp1, temp2;

	outb(0x77, 0x80);

#if 0 	
	/* for DOC VB */
	sisfb_set_reg4(0xcf8,0x800000e0);
	reg32 = sisfb_get_reg3(0xcfc);
	reg32 = reg32 | 0x00001000;
	sisfb_set_reg4(0xcfc,reg32);
	}
#endif

	if (sisfb_off)
		return -ENXIO;

	if (enable_dstn)
		SetEnableDstn();

	pci_for_each_dev(pdev) {
		for (b = sisdev_list; b->vendor; b++) {
			if ((b->vendor == pdev->vendor)
			    && (b->device == pdev->device)) {
				pdev_valid = 1;
				strcpy(fb_info.modename, b->name);
				ivideo.chip_id = pdev->device;
				pci_read_config_byte(pdev, PCI_REVISION_ID,
				                     &ivideo.revision_id);
				pci_read_config_word(pdev, PCI_COMMAND, &reg16);
				sishw_ext.jChipRevision = ivideo.revision_id;
				sisvga_enabled = reg16 & 0x1;
				break;
			}
		}

		if (pdev_valid)
			break;
	}

	if (!pdev_valid)
		return -1;

// Eden Chen
	switch (ivideo.chip_id) {
	   case PCI_DEVICE_ID_SI_300:
		ivideo.chip = SIS_300;
		sisvga_engine = SIS_300_VGA;
		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_300;
		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_300;
		break;
	   case PCI_DEVICE_ID_SI_630_VGA:
		{
			sisfb_set_reg4(0xCF8, 0x80000000);
			reg32 = sisfb_get_reg3(0xCFC);
			if (reg32 == 0x07301039) {
				ivideo.chip = SIS_730;
				strcpy(fb_info.modename, "SIS 730");
			} else
				ivideo.chip = SIS_630;

			sisvga_engine = SIS_300_VGA;
			sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_300;
			sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_300;
			break;
		}
	   case PCI_DEVICE_ID_SI_540_VGA:
		ivideo.chip = SIS_540;
		sisvga_engine = SIS_300_VGA;
		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_300;
		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_300;
		break;
	   case PCI_DEVICE_ID_SI_315H:
		ivideo.chip = SIS_315H;
		sisvga_engine = SIS_315_VGA;
		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_315;
		break;
	   case PCI_DEVICE_ID_SI_315:
		ivideo.chip = SIS_315;
		sisvga_engine = SIS_315_VGA;
		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_315;
		break;
	   case PCI_DEVICE_ID_SI_315PRO:
		ivideo.chip = SIS_315PRO;
		sisvga_engine = SIS_315_VGA;
		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_315;
		break;
	   case PCI_DEVICE_ID_SI_550_VGA:
		ivideo.chip = SIS_550;
		sisvga_engine = SIS_315_VGA;
		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_315;
		break;
	   case PCI_DEVICE_ID_SI_650_VGA:
		ivideo.chip = SIS_650;
		sisvga_engine = SIS_315_VGA;
		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_315;
		break;
	}
	sishw_ext.jChipType = ivideo.chip;
	// for Debug
	if ((sishw_ext.jChipType == SIS_315PRO) 
	   || (sishw_ext.jChipType == SIS_315) )
		sishw_ext.jChipType = SIS_315H;

	DPRINTK("%s is used as %s device(VGA Engine %d).\n", 
		fb_info.modename, sisvga_enabled ? "primary" : "secondary", sisvga_engine);

	ivideo.video_base = pci_resource_start(pdev, 0);
	ivideo.mmio_base = pci_resource_start(pdev, 1);
	sishw_ext.ulIOAddress = (unsigned short) ivideo.vga_base =
		                   pci_resource_start(pdev, 2) + 0x30;

	sisfb_mmio_size =  pci_resource_len(pdev, 1);

	if (!sisvga_enabled)
		if (pci_enable_device(pdev))   return -EIO;

// Eden Eden
//#ifdef LINUXBIOS
//	sishw_ext.VirtualRomBase = rom_vbase = (unsigned long) rom_data;
//#else
//	{
//	unsigned long rom_base  = 0x000C0000;
//
//	request_region(rom_base, 32, "sisfb");
//	sishw_ext.VirtualRomBase = rom_vbase 
//		= (unsigned long) ioremap(rom_base, MAX_ROM_SCAN);
//	}
//#endif
// ~Eden Chen
	
	vgawb(SEQ_ADR, IND_SIS_PASSWORD);
	vgawb(SEQ_DATA, SIS_PASSWORD);

        /* TW: Debug kernel 2.5 problem */
	vgawb(SEQ_ADR, 0x14);
	reg = vgarb(SEQ_DATA);
	printk("sisfb: SR14 = 0x%02x\n", reg);
	/* /TW */

#ifdef LINUXBIOS
#ifdef CONFIG_FB_SIS_300
	if (sisvga_engine == SIS_300_VGA) {
		vgawb(SEQ_ADR, 0x28);
		vgawb(SEQ_DATA, 0x37);

		vgawb(SEQ_ADR, 0x29);
		vgawb(SEQ_DATA, 0x61);

		vgawb(SEQ_ADR, IND_SIS_SCRATCH_REG_1A);
		reg = vgarb(SEQ_DATA);
		reg |= SIS_SCRATCH_REG_1A_MASK;
		vgawb(SEQ_DATA, reg);
	}
#endif
#ifdef CONFIG_FB_SIS_315
	if (ivideo.chip == SIS_550 || ivideo.chip == SIS_650) {
		vgawb(SEQ_ADR,  0x28);
		vgawb(SEQ_DATA, 0x5A);

		vgawb(SEQ_ADR,  0x29);
		vgawb(SEQ_DATA, 0x64);

		vgawb(CRTC_ADR,  0x3A);
		vgawb(CRTC_DATA, 0x00);
	}
#endif
#endif /* LinuxBIOS */

	if (sisvga_engine == SIS_315_VGA) {
		switch (ivideo.chip) {
		   case SIS_315H:
		   case SIS_315:
			sishw_ext.bIntegratedMMEnabled = TRUE;
			break;
		   case SIS_550:
		   case SIS_650:
			// Eden Chen
			//vgawb(SEQ_ADR, IND_SIS_SCRATCH_REG_1A);
			//reg = vgarb(SEQ_DATA);
			//if (reg & SIS_SCRATCH_REG_1A_MASK)
			//	sishw_ext.bIntegratedMMEnabled = TRUE;
			//else
			//	sishw_ext.bIntegratedMMEnabled = FALSE;
			//for Debug
			sishw_ext.bIntegratedMMEnabled = TRUE;
			// ~Eden Chen
			break;
		   default:
			break;
		}
	} else if (sisvga_engine == SIS_300_VGA) {
		if (ivideo.chip == SIS_300) {
			sishw_ext.bIntegratedMMEnabled = TRUE;
		} else {
			vgawb(SEQ_ADR, IND_SIS_SCRATCH_REG_1A);
			reg = vgarb(SEQ_DATA);
			if (reg & SIS_SCRATCH_REG_1A_MASK)
				sishw_ext.bIntegratedMMEnabled = TRUE;
			else
				sishw_ext.bIntegratedMMEnabled = FALSE;
		}
	}

	sishw_ext.pDevice = NULL;
	sishw_ext.pjVirtualRomBase = NULL;
	sishw_ext.pjCustomizedROMImage = NULL;
	sishw_ext.bSkipDramSizing = 0;
	sishw_ext.pQueryVGAConfigSpace = &sisfb_query_VGA_config_space;
	sishw_ext.pQueryNorthBridgeSpace = &sisfb_query_north_bridge_space;
	strcpy(sishw_ext.szVBIOSVer, "0.84");

	/* TW: Mode numbers for 1280x960 are different for 300 and 310/325 series */
	if(sisvga_engine == SIS_300_VGA) {
		sisbios_mode[MODEINDEX_1280x960].mode_no = 0x6e;
		sisbios_mode[MODEINDEX_1280x960+1].mode_no = 0x6f;
		sisbios_mode[MODEINDEX_1280x960+2].mode_no = 0x7b;
		sisbios_mode[MODEINDEX_1280x960+3].mode_no = 0x7b;
	}

	sishw_ext.pSR = vmalloc(sizeof(SIS_DSReg) * SR_BUFFER_SIZE);
	if (sishw_ext.pSR == NULL) {
		printk(KERN_INFO "sisfb: Fatal error: Allocating SRReg space failed.\n");
		return -ENODEV;
	}
	sishw_ext.pSR[0].jIdx = sishw_ext.pSR[0].jVal = 0xFF;

	sishw_ext.pCR = vmalloc(sizeof(SIS_DSReg) * CR_BUFFER_SIZE);
	if (sishw_ext.pCR == NULL) {
		printk(KERN_INFO "sisfb: Fatal error: Allocating CRReg space failed.\n");
		return -ENODEV;
	}
	sishw_ext.pCR[0].jIdx = sishw_ext.pCR[0].jVal = 0xFF;

#ifdef CONFIG_FB_SIS_300
	if (sisvga_engine == SIS_300_VGA) {
		if (!sisvga_enabled) {
			sishw_ext.pjVideoMemoryAddress
				= ioremap(ivideo.video_base, 0x2000000);
			if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
				SiSInit(&sishw_ext);
				vgawb(SEQ_ADR, IND_SIS_PASSWORD);
				vgawb(SEQ_DATA, SIS_PASSWORD);
			}
		}
#ifdef LINUXBIOS
		else {
			sishw_ext.pjVideoMemoryAddress
				= ioremap(ivideo.video_base, 0x2000000);
			if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
				SiSInit(&sishw_ext);
				vgawb(SEQ_ADR, IND_SIS_PASSWORD);
				vgawb(SEQ_DATA, SIS_PASSWORD);
			}
		}
		if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
			vgawb(SEQ_ADR, 0x7);
			reg = vgarb(SEQ_DATA);
			reg |= 0x10;
			vgawb(SEQ_DATA, reg);
		}
#endif
		if (sisfb_get_dram_size_300()) {
			printk(KERN_INFO "sisfb: Fatal error: Unable to determine RAM size\n");
			return -ENODEV;
		}
	}
#endif

#ifdef CONFIG_FB_SIS_315
	if (sisvga_engine == SIS_315_VGA) {
		if (!sisvga_enabled) {
			/* Mapping Max FB Size for 315 Init */
			// Eden Chen
			//sishw_ext.VirtualVideoMemoryAddress 
			sishw_ext.pjVideoMemoryAddress 
				= ioremap(ivideo.video_base, 0x8000000);
			if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
				SiSInit(&sishw_ext);

				vgawb(SEQ_ADR, IND_SIS_PASSWORD);
				vgawb(SEQ_DATA, SIS_PASSWORD);

				sishw_ext.bSkipDramSizing = TRUE;
				vgawb(SEQ_ADR, 0x13);
				sishw_ext.pSR[0].jIdx = 0x13;
				sishw_ext.pSR[0].jVal = vgarb(SEQ_DATA);
				vgawb(SEQ_ADR, 0x14);
				sishw_ext.pSR[1].jIdx = 0x14;
				sishw_ext.pSR[1].jVal = vgarb(SEQ_DATA);
				sishw_ext.pSR[2].jIdx = 0xFF;
				sishw_ext.pSR[2].jVal = 0xFF;
			}
		}
#ifdef LINUXBIOS
		else {
			sishw_ext.pjVideoMemoryAddress
				= ioremap(ivideo.video_base, 0x8000000);
			if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
				SiSInit(&sishw_ext);
				vgawb(SEQ_ADR, IND_SIS_PASSWORD);
				vgawb(SEQ_DATA, SIS_PASSWORD);

				sishw_ext.bSkipDramSizing = TRUE;
				vgawb(SEQ_ADR, 0x13);
				sishw_ext.pSR[0].jIdx = 0x13;
				sishw_ext.pSR[0].jVal = vgarb(SEQ_DATA);
				vgawb(SEQ_ADR, 0x14);
				sishw_ext.pSR[1].jIdx = 0x14;
				sishw_ext.pSR[1].jVal = vgarb(SEQ_DATA);
				sishw_ext.pSR[2].jIdx = 0xFF;
				sishw_ext.pSR[2].jVal = 0xFF;
			}
		}
#endif
		if (sisfb_get_dram_size_315()) {
			printk(KERN_INFO "sisfb: Fatal error: Unable to determine RAM size.\n");
			return -ENODEV;
		}
	}
#endif
	if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */

		vgawb(SEQ_ADR, IND_SIS_PCI_ADDRESS_SET);
		reg = vgarb(SEQ_DATA);
		reg |= SIS_PCI_ADDR_ENABLE;    	/* Enable PCI_LINEAR_ADDRESSING */
		reg |= SIS_MEM_MAP_IO_ENABLE;  	/* Enable MMIO_ENABLE */
		vgawb(SEQ_DATA, reg);

		vgawb(SEQ_ADR, IND_SIS_MODULE_ENABLE);
		reg = vgarb(SEQ_DATA);
		reg |= SIS_ENABLE_2D;		/* Enable 2D accelerator engine */
		vgawb(SEQ_DATA, reg);

	}

	sishw_ext.ulVideoMemorySize = ivideo.video_size;

	if(sisfb_pdc) {
	    sishw_ext.pdc = sisfb_pdc;
	} else {
	    sishw_ext.pdc = 0;
	}

	if (!request_mem_region(ivideo.video_base, ivideo.video_size, "sisfb FB")) {
		printk(KERN_ERR "sisfb: Fatal error: Unable to reserve frame buffer memory\n");
		printk(KERN_ERR "sisfb: Is there another framebuffer driver active?\n");
		return -ENODEV;
	}

	if (!request_mem_region(ivideo.mmio_base, sisfb_mmio_size, "sisfb MMIO")) {
		printk(KERN_ERR "sisfb: Fatal error: Unable to reserve MMIO region\n");
		release_mem_region(ivideo.video_base, ivideo.video_size);
		return -ENODEV;
	}

	sishw_ext.pjVideoMemoryAddress = ivideo.video_vbase
		= ioremap(ivideo.video_base, ivideo.video_size);
	ivideo.mmio_vbase = ioremap(ivideo.mmio_base, sisfb_mmio_size);

	printk(KERN_INFO
	       "sisfb: Framebuffer at 0x%lx, mapped to 0x%p, size %dk\n",
	       ivideo.video_base, ivideo.video_vbase,
	       ivideo.video_size / 1024);

	printk(KERN_INFO
	       "sisfb: MMIO at 0x%lx, mapped to 0x%p, size %ldk\n",
	       ivideo.mmio_base, ivideo.mmio_vbase,
	       sisfb_mmio_size / 1024);

	if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */

#ifdef CONFIG_FB_SIS_300
		if (sisvga_engine == SIS_300_VGA) {
			sisfb_get_VB_type_300();
			if (ivideo.hasVB != HASVB_NONE) {
				sisfb_detect_VB_connect_300();
			}
		}
#endif

#ifdef CONFIG_FB_SIS_315
		if (sisvga_engine == SIS_315_VGA) {
			sisfb_get_VB_type_315();
			if (ivideo.hasVB != HASVB_NONE) {
				sisfb_detect_VB_connect_315();
			}
		}
#endif

		sishw_ext.ujVBChipID = VB_CHIP_UNKNOWN;
		sishw_ext.usExternalChip = 0;

		switch (ivideo.hasVB) {

		case HASVB_301:
			vgawb(VB_PART4_ADR,0x01);
			reg = vgarb(VB_PART4_DATA);
			if (reg >= 0xD0) {
				sishw_ext.ujVBChipID = VB_CHIP_301LV;
				printk(KERN_INFO "sisfb: SiS301LV bridge detected (revision 0x%02x)\n",reg);
	  		} else if (reg >= 0xB0) {
				sishw_ext.ujVBChipID = VB_CHIP_301B;
				printk(KERN_INFO "sisfb: SiS301B bridge detected (revision 0x%02x\n",reg);
			} else {
				sishw_ext.ujVBChipID = VB_CHIP_301;
				printk(KERN_INFO "sisfb: SiS301 bridge detected\n");
			}
			break;
		case HASVB_302:
			vgawb(VB_PART4_ADR,0x01);
			reg = vgarb(VB_PART4_DATA);
			if (reg >= 0xD0) {
				sishw_ext.ujVBChipID = VB_CHIP_302LV;
				printk(KERN_INFO "sisfb: SiS302LV bridge detected (revision 0x%02x)\n",reg);
	  		} else if (reg >= 0xB0) {
			        sishw_ext.ujVBChipID = VB_CHIP_302B;
				printk(KERN_INFO "sisfb: SiS302B bridge detected (revision 0x%02x)\n",reg);
			} else {
			        sishw_ext.ujVBChipID = VB_CHIP_302;
				printk(KERN_INFO "sisfb: SiS302 bridge detected\n");
			}
			break;
		case HASVB_303:
			sishw_ext.ujVBChipID = VB_CHIP_303;
			printk(KERN_INFO "sisfb: SiS303 bridge detected (not supported)\n");
			break;
		case HASVB_LVDS:
			sishw_ext.usExternalChip = 0x1;
			printk(KERN_INFO "sisfb: LVDS transmitter detected\n");
			break;
		case HASVB_TRUMPION:
			sishw_ext.usExternalChip = 0x2;
			printk(KERN_INFO "sisfb: Trumpion Zurac LVDS scaler detected\n");
			break;
		case HASVB_CHRONTEL:
			sishw_ext.usExternalChip = 0x4;
			printk(KERN_INFO "sisfb: Chrontel TV encoder detected\n");
			break;
		case HASVB_LVDS_CHRONTEL:
			sishw_ext.usExternalChip = 0x5;
			printk(KERN_INFO "sisfb: LVDS transmitter and Chrontel TV encoder detected\n");
			break;
		default:
			printk(KERN_INFO "sisfb: No or unknown bridge type detected\n");
			break;
		}

		/* TW: Determine and detect attached TV's on Chrontel */
		if (sishw_ext.usExternalChip == 0x04 || sishw_ext.usExternalChip == 0x05) {
		    SiSRegInit(sishw_ext.ulIOAddress);
		    if(ivideo.chip < SIS_315H) {    /* TW: Chrontel 7005 */
#ifdef CONFIG_FB_SIS_300
                       SiS_IF_DEF_CH70xx = 1;
		       temp1=SiS_GetCH700x(0x25);
		       if ((temp1 >= 50) && (temp1 <= 100)) {
	    		   /* TW: Read power status */
	    		   temp1 = SiS_GetCH700x(0x0e);
	    		   if ((temp1&0x03)!=0x03) {
		        	/* TW: Power all outputs */
	        		SiS_SetCH70xxANDOR(0x030E,0xF8);
	    		   }
			   /* TW: Sense connected TV devices */
	    		   SiS_SetCH700x(0x0110);
	    		   SiS_SetCH700x(0x0010);
	    		   temp1 = SiS_GetCH700x(0x10);
	    		   if (!(temp1 & 0x08)) {
				/* TW: So we can be sure that there IS a SVHS output */
				printk(KERN_INFO
				   "sisfb: Chrontel: Detected TV connected to SVHS output\n");
				ivideo.TV_plug = TVPLUG_SVIDEO;
				vgawb(CRTC_ADR, 0x32);
				temp2 = vgarb(CRTC_DATA) | 0x02;
				vgawb(CRTC_DATA, temp2);
			   } else if (!(temp1 & 0x02)) {
				/* TW: So we can be sure that there IS a CVBS output */
				printk(KERN_INFO
				   "sisfb: Chrontel: Detected TV connected to CVBS output\n");
				ivideo.TV_plug = TVPLUG_COMPOSITE;
				vgawb(CRTC_ADR, 0x32);
				temp2 = vgarb(CRTC_DATA) | 0x01;
				vgawb(CRTC_DATA, temp2);
	    		   } else {
		    		SiS_SetCH70xxANDOR(0x010E,0xF8);
	    		   }
		       } else if (temp1==0) {
	    		        SiS_SetCH70xxANDOR(0x010E,0xF8);
	    	       }
#endif
		   } else {  /* TW: Chrontel 7019 */
#ifdef CONFIG_FB_SIS_315
			SiS_IF_DEF_CH70xx = 2;
                        temp1 = SiS_GetCH701x(0x49);
			SiS_SetCH701x(0x2049);
			SiS_DDC2Delay(0x96);
			temp2 = SiS_GetCH701x(0x20);
			temp2 |= 0x01;
			SiS_SetCH701x((temp2 << 8) | 0x20);
			SiS_DDC2Delay(0x96);
			temp2 ^= 0x01;
			SiS_SetCH701x((temp2 << 8) | 0x20);
			SiS_DDC2Delay(0x96);
			temp2 = SiS_GetCH701x(0x20);
			SiS_SetCH701x((temp1 << 8) | 0x49);
                        temp1 = 0;
			if(temp2 & 0x02) temp1 |= 0x01;
			if(temp2 & 0x10) temp1 |= 0x01;
			if(temp2 & 0x04) temp1 |= 0x02;
			if( (temp1 & 0x01) && (temp1 & 0x02) ) temp1 = 0x04;
			switch(temp1) {
			case 0x01:
			     printk(KERN_INFO
				"sisfb: Chrontel: Detected TV connected to CVBS output\n");
			     ivideo.TV_plug = TVPLUG_COMPOSITE;
			     vgawb(CRTC_ADR, 0x32);
                             temp2 = vgarb(CRTC_DATA) | 0x01;
			     vgawb(CRTC_DATA, temp2);
                             break;
			case 0x02:
			     printk(KERN_INFO
				"sisfb: Chrontel: Detected TV connected to SVHS output\n");
			     ivideo.TV_plug = TVPLUG_SVIDEO;
			     vgawb(CRTC_ADR, 0x32);
			     temp2 = vgarb(CRTC_DATA) | 0x02;
			     vgawb(CRTC_DATA, temp2);
                             break;
			case 0x04:
			     /* TW: This should not happen */
			     printk(KERN_INFO
				"sisfb: Chrontel: Detected TV connected to SCART output!?\n");
                             break;
			}
#endif
		   }
	    	}

		if (ivideo.disp_state & DISPTYPE_DISP2) {
			if (sisfb_crt1off)
				ivideo.disp_state |= DISPMODE_SINGLE;
			else
				ivideo.disp_state |= (DISPMODE_MIRROR | DISPTYPE_CRT1);
		} else {
			ivideo.disp_state = DISPMODE_SINGLE | DISPTYPE_CRT1;
		}

		if (ivideo.disp_state & DISPTYPE_LCD) {
		    if (!enable_dstn) {
			vgawb(CRTC_ADR, IND_SIS_LCD_PANEL);
			reg = vgarb(CRTC_DATA) & 0x0f;
			if (sisvga_engine == SIS_300_VGA) {
			    sishw_ext.ulCRT2LCDType = sis300paneltype[reg];
			} else {
			    sishw_ext.ulCRT2LCDType = sis310paneltype[reg];
			}
		    } else {
		        /* TW: FSTN/DSTN */
			sishw_ext.ulCRT2LCDType = LCD_320x480;
		    }
		}

		if (sisfb_mode_idx >= 0)
			sisfb_validate_mode();

		if (sisfb_mode_idx < 0) {
			switch (ivideo.disp_state & DISPTYPE_DISP2) {
			   case DISPTYPE_LCD:
				sisfb_mode_idx = DEFAULT_LCDMODE;
				break;
			   case DISPTYPE_TV:
				sisfb_mode_idx = DEFAULT_TVMODE;
				break;
			   default:
				sisfb_mode_idx = DEFAULT_MODE;
				break;
			}
		}

		sisfb_mode_no = sisbios_mode[sisfb_mode_idx].mode_no;

		if (ivideo.refresh_rate != 0)
			sisfb_search_refresh_rate(ivideo.refresh_rate);

		if (sisfb_rate_idx == 0) {
			sisfb_rate_idx = sisbios_mode[sisfb_mode_idx].rate_idx;
			ivideo.refresh_rate = 60;
		}

		ivideo.video_bpp = sisbios_mode[sisfb_mode_idx].bpp;
		ivideo.video_vwidth = ivideo.video_width = sisbios_mode[sisfb_mode_idx].xres;
		ivideo.video_vheight = ivideo.video_height = sisbios_mode[sisfb_mode_idx].yres;
		ivideo.org_x = ivideo.org_y = 0;
		video_linelength = ivideo.video_width * (ivideo.video_bpp >> 3);

		printk(KERN_INFO "sisfb: Mode is %dx%dx%d (%dHz), linelength=%d\n",
	       		ivideo.video_width, ivideo.video_height, ivideo.video_bpp,
			ivideo.refresh_rate, video_linelength);

		// Eden Chen
		// Check interface correction  For Debug
		DPRINTK("VM Adr=0x%p\n", sishw_ext.pjVideoMemoryAddress);
		DPRINTK("VM Size=%ldK\n", sishw_ext.ulVideoMemorySize/1024);
		DPRINTK("IO Adr=0x%lx\n", sishw_ext.ulIOAddress);
		DPRINTK("Chip=%d\n", sishw_ext.jChipType);
		DPRINTK("ChipRevision=%d\n", sishw_ext.jChipRevision);
		DPRINTK("VBChip=%d\n", sishw_ext.ujVBChipID);
		DPRINTK("ExtVB=%d\n", sishw_ext.usExternalChip);
		DPRINTK("LCD=%ld\n", sishw_ext.ulCRT2LCDType);
		DPRINTK("bIntegratedMMEnabled=%d\n", sishw_ext.bIntegratedMMEnabled);
		// ~Eden Chen

		sisfb_pre_setmode();

		if (SiSSetMode(&sishw_ext, sisfb_mode_no) == 0) {
			printk("sisfb: Setting mode[0x%x] failed, using default mode\n", sisfb_mode_no);
			return -1;
		}

		vgawb(SEQ_ADR, IND_SIS_PASSWORD);
		vgawb(SEQ_DATA, SIS_PASSWORD);

		sisfb_post_setmode();

		sisfb_crtc_to_var(&default_var);

		fb_info.changevar = NULL;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
		fb_info.node = -1;
#else
		fb_info.node = NODEV;
#endif
		fb_info.fbops = &sisfb_ops;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,23)
		fb_info.screen_base = ivideo.video_vbase;
		fb_info.currcon = -1;
#endif
		fb_info.disp = &disp;
		fb_info.switch_con = &sisfb_switch;
		fb_info.updatevar = &sisfb_update_var;
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,23)
		fb_info.blank = &sisfb_blank;
#endif
		fb_info.flags = FBINFO_FLAG_DEFAULT;

		sisfb_set_disp(-1, &default_var);

	} /* TW: if mode = "none" */

	if (sisfb_heap_init()) {
		printk("sisfb: Failed to initialize offscreen memory heap\n");
	}

        ivideo.mtrr = (unsigned int) 0;
	if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
         	/*H.C.*/
		ivideo.mtrr = mtrr_add((unsigned int) ivideo.video_base,
				(unsigned int) ivideo.video_size,
				MTRR_TYPE_WRCOMB, 1);
		/*
		if (ivideo.mtrr >= 0) {
           	    printk(KERN_INFO "Succeed to turn on Write-Combining on VideoMemory %08XH, Size: %08XH\n",
					ivideo.video_base, ivideo.video_size);
      		} else	{
           	    printk(KERN_INFO "Fail to turn on Write-Combining on Video Memory 0x%08X, Size: 0x%08X\n",
					ivideo.video_base, ivideo.video_size);
      		}
		*/
		vc_resize_con(1, 1, 0);

		if (register_framebuffer(&fb_info) < 0)
			return -EINVAL;

		printk(KERN_INFO "fb%d: %s frame buffer device, Version %d.%d.%02d\n",
	       		minor(fb_info.node), fb_info.modename, VER_MAJOR, VER_MINOR,
	       		VER_LEVEL);

		printk(KERN_INFO "sisfb: Added SISFB_GET_INFO ioctl = %x\n", SISFB_GET_INFO);

	}	/* TW: if mode = "none" */
	return 0;
}

Generated by GNU enscript 1.6.4.