⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vt8623fb.c

📁 Linux环境下视频显示卡设备的驱动程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		pr_debug("fb%d: text mode\n", info->node);		svga_set_textmode_vga_regs();		svga_wseq_mask(0x15, 0x00, 0xFE);		svga_wcrt_mask(0x11, 0x60, 0x70);		break;	case 1:		pr_debug("fb%d: 4 bit pseudocolor\n", info->node);		vga_wgfx(NULL, VGA_GFX_MODE, 0x40);		svga_wseq_mask(0x15, 0x20, 0xFE);		svga_wcrt_mask(0x11, 0x00, 0x70);		break;	case 2:		pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);		svga_wseq_mask(0x15, 0x00, 0xFE);		svga_wcrt_mask(0x11, 0x00, 0x70);		break;	case 3:		pr_debug("fb%d: 8 bit pseudocolor\n", info->node);		svga_wseq_mask(0x15, 0x22, 0xFE);		break;	case 4:		pr_debug("fb%d: 5/6/5 truecolor\n", info->node);		svga_wseq_mask(0x15, 0xB6, 0xFE);		break;	case 5:		pr_debug("fb%d: 8/8/8 truecolor\n", info->node);		svga_wseq_mask(0x15, 0xAE, 0xFE);		break;	default:		printk(KERN_ERR "vt8623fb: unsupported mode - bug\n");		return (-EINVAL);	}	vt8623_set_pixclock(info, info->var.pixclock);	svga_set_timings(&vt8623_timing_regs, &(info->var), 1, 1,			 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1, 1,			 1, info->node);	memset_io(info->screen_base, 0x00, screen_size);	/* Device and screen back on */	svga_wcrt_mask(0x17, 0x80, 0x80);	svga_wcrt_mask(0x36, 0x00, 0x30);	svga_wseq_mask(0x01, 0x00, 0x20);	return 0;}static int vt8623fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,				u_int transp, struct fb_info *fb){	switch (fb->var.bits_per_pixel) {	case 0:	case 4:		if (regno >= 16)			return -EINVAL;		outb(0x0F, VGA_PEL_MSK);		outb(regno, VGA_PEL_IW);		outb(red >> 10, VGA_PEL_D);		outb(green >> 10, VGA_PEL_D);		outb(blue >> 10, VGA_PEL_D);		break;	case 8:		if (regno >= 256)			return -EINVAL;		outb(0xFF, VGA_PEL_MSK);		outb(regno, VGA_PEL_IW);		outb(red >> 10, VGA_PEL_D);		outb(green >> 10, VGA_PEL_D);		outb(blue >> 10, VGA_PEL_D);		break;	case 16:		if (regno >= 16)			return 0;		if (fb->var.green.length == 5)			((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |				((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);		else if (fb->var.green.length == 6)			((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |				((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);		else			return -EINVAL;		break;	case 24:	case 32:		if (regno >= 16)			return 0;		/* ((transp & 0xFF00) << 16) */		((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |			(green & 0xFF00) | ((blue & 0xFF00) >> 8);		break;	default:		return -EINVAL;	}	return 0;}static int vt8623fb_blank(int blank_mode, struct fb_info *info){	switch (blank_mode) {	case FB_BLANK_UNBLANK:		pr_debug("fb%d: unblank\n", info->node);		svga_wcrt_mask(0x36, 0x00, 0x30);		svga_wseq_mask(0x01, 0x00, 0x20);		break;	case FB_BLANK_NORMAL:		pr_debug("fb%d: blank\n", info->node);		svga_wcrt_mask(0x36, 0x00, 0x30);		svga_wseq_mask(0x01, 0x20, 0x20);		break;	case FB_BLANK_HSYNC_SUSPEND:		pr_debug("fb%d: DPMS standby (hsync off)\n", info->node);		svga_wcrt_mask(0x36, 0x10, 0x30);		svga_wseq_mask(0x01, 0x20, 0x20);		break;	case FB_BLANK_VSYNC_SUSPEND:		pr_debug("fb%d: DPMS suspend (vsync off)\n", info->node);		svga_wcrt_mask(0x36, 0x20, 0x30);		svga_wseq_mask(0x01, 0x20, 0x20);		break;	case FB_BLANK_POWERDOWN:		pr_debug("fb%d: DPMS off (no sync)\n", info->node);		svga_wcrt_mask(0x36, 0x30, 0x30);		svga_wseq_mask(0x01, 0x20, 0x20);		break;	}	return 0;}static int vt8623fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info){	unsigned int offset;	/* Calculate the offset */	if (var->bits_per_pixel == 0) {		offset = (var->yoffset / 16) * var->xres_virtual + var->xoffset;		offset = offset >> 3;	} else {		offset = (var->yoffset * info->fix.line_length) +			 (var->xoffset * var->bits_per_pixel / 8);		offset = offset >> ((var->bits_per_pixel == 4) ? 2 : 1);	}	/* Set the offset */	svga_wcrt_multi(vt8623_start_address_regs, offset);	return 0;}/* ------------------------------------------------------------------------- *//* Frame buffer operations */static struct fb_ops vt8623fb_ops = {	.owner		= THIS_MODULE,	.fb_open	= vt8623fb_open,	.fb_release	= vt8623fb_release,	.fb_check_var	= vt8623fb_check_var,	.fb_set_par	= vt8623fb_set_par,	.fb_setcolreg	= vt8623fb_setcolreg,	.fb_blank	= vt8623fb_blank,	.fb_pan_display	= vt8623fb_pan_display,	.fb_fillrect	= vt8623fb_fillrect,	.fb_copyarea	= cfb_copyarea,	.fb_imageblit	= vt8623fb_imageblit,	.fb_get_caps    = svga_get_caps,};/* PCI probe */static int __devinit vt8623_pci_probe(struct pci_dev *dev, const struct pci_device_id *id){	struct fb_info *info;	struct vt8623fb_info *par;	unsigned int memsize1, memsize2;	int rc;	/* Ignore secondary VGA device because there is no VGA arbitration */	if (! svga_primary_device(dev)) {		dev_info(&(dev->dev), "ignoring secondary device\n");		return -ENODEV;	}	/* Allocate and fill driver data structure */	info = framebuffer_alloc(sizeof(struct vt8623fb_info), &(dev->dev));	if (! info) {		dev_err(&(dev->dev), "cannot allocate memory\n");		return -ENOMEM;	}	par = info->par;	mutex_init(&par->open_lock);	info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;	info->fbops = &vt8623fb_ops;	/* Prepare PCI device */	rc = pci_enable_device(dev);	if (rc < 0) {		dev_err(info->device, "cannot enable PCI device\n");		goto err_enable_device;	}	rc = pci_request_regions(dev, "vt8623fb");	if (rc < 0) {		dev_err(info->device, "cannot reserve framebuffer region\n");		goto err_request_regions;	}	info->fix.smem_start = pci_resource_start(dev, 0);	info->fix.smem_len = pci_resource_len(dev, 0);	info->fix.mmio_start = pci_resource_start(dev, 1);	info->fix.mmio_len = pci_resource_len(dev, 1);	/* Map physical IO memory address into kernel space */	info->screen_base = pci_iomap(dev, 0, 0);	if (! info->screen_base) {		rc = -ENOMEM;		dev_err(info->device, "iomap for framebuffer failed\n");		goto err_iomap_1;	}	par->mmio_base = pci_iomap(dev, 1, 0);	if (! par->mmio_base) {		rc = -ENOMEM;		dev_err(info->device, "iomap for MMIO failed\n");		goto err_iomap_2;	}	/* Find how many physical memory there is on card */	memsize1 = (vga_rseq(NULL, 0x34) + 1) >> 1;	memsize2 = vga_rseq(NULL, 0x39) << 2;	if ((16 <= memsize1) && (memsize1 <= 64) && (memsize1 == memsize2))		info->screen_size = memsize1 << 20;	else {		dev_err(info->device, "memory size detection failed (%x %x), suppose 16 MB\n", memsize1, memsize2);		info->screen_size = 16 << 20;	}	info->fix.smem_len = info->screen_size;	strcpy(info->fix.id, "VIA VT8623");	info->fix.type = FB_TYPE_PACKED_PIXELS;	info->fix.visual = FB_VISUAL_PSEUDOCOLOR;	info->fix.ypanstep = 0;	info->fix.accel = FB_ACCEL_NONE;	info->pseudo_palette = (void*)par->pseudo_palette;	/* Prepare startup mode */	rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);	if (! ((rc == 1) || (rc == 2))) {		rc = -EINVAL;		dev_err(info->device, "mode %s not found\n", mode_option);		goto err_find_mode;	}	rc = fb_alloc_cmap(&info->cmap, 256, 0);	if (rc < 0) {		dev_err(info->device, "cannot allocate colormap\n");		goto err_alloc_cmap;	}	rc = register_framebuffer(info);	if (rc < 0) {		dev_err(info->device, "cannot register framebugger\n");		goto err_reg_fb;	}	printk(KERN_INFO "fb%d: %s on %s, %d MB RAM\n", info->node, info->fix.id,		 pci_name(dev), info->fix.smem_len >> 20);	/* Record a reference to the driver data */	pci_set_drvdata(dev, info);#ifdef CONFIG_MTRR	if (mtrr) {		par->mtrr_reg = -1;		par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);	}#endif	return 0;	/* Error handling */err_reg_fb:	fb_dealloc_cmap(&info->cmap);err_alloc_cmap:err_find_mode:	pci_iounmap(dev, par->mmio_base);err_iomap_2:	pci_iounmap(dev, info->screen_base);err_iomap_1:	pci_release_regions(dev);err_request_regions:/*	pci_disable_device(dev); */err_enable_device:	framebuffer_release(info);	return rc;}/* PCI remove */static void __devexit vt8623_pci_remove(struct pci_dev *dev){	struct fb_info *info = pci_get_drvdata(dev);	if (info) {		struct vt8623fb_info *par = info->par;#ifdef CONFIG_MTRR		if (par->mtrr_reg >= 0) {			mtrr_del(par->mtrr_reg, 0, 0);			par->mtrr_reg = -1;		}#endif		unregister_framebuffer(info);		fb_dealloc_cmap(&info->cmap);		pci_iounmap(dev, info->screen_base);		pci_iounmap(dev, par->mmio_base);		pci_release_regions(dev);/*		pci_disable_device(dev); */		pci_set_drvdata(dev, NULL);		framebuffer_release(info);	}}#ifdef CONFIG_PM/* PCI suspend */static int vt8623_pci_suspend(struct pci_dev* dev, pm_message_t state){	struct fb_info *info = pci_get_drvdata(dev);	struct vt8623fb_info *par = info->par;	dev_info(info->device, "suspend\n");	acquire_console_sem();	mutex_lock(&(par->open_lock));	if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {		mutex_unlock(&(par->open_lock));		release_console_sem();		return 0;	}	fb_set_suspend(info, 1);	pci_save_state(dev);	pci_disable_device(dev);	pci_set_power_state(dev, pci_choose_state(dev, state));	mutex_unlock(&(par->open_lock));	release_console_sem();	return 0;}/* PCI resume */static int vt8623_pci_resume(struct pci_dev* dev){	struct fb_info *info = pci_get_drvdata(dev);	struct vt8623fb_info *par = info->par;	dev_info(info->device, "resume\n");	acquire_console_sem();	mutex_lock(&(par->open_lock));	if (par->ref_count == 0)		goto fail;	pci_set_power_state(dev, PCI_D0);	pci_restore_state(dev);	if (pci_enable_device(dev))		goto fail;	pci_set_master(dev);	vt8623fb_set_par(info);	fb_set_suspend(info, 0);fail:	mutex_unlock(&(par->open_lock));	release_console_sem();	return 0;}#else#define vt8623_pci_suspend NULL#define vt8623_pci_resume NULL#endif /* CONFIG_PM *//* List of boards that we are trying to support */static struct pci_device_id vt8623_devices[] __devinitdata = {	{PCI_DEVICE(PCI_VENDOR_ID_VIA, 0x3122)},	{0, 0, 0, 0, 0, 0, 0}};MODULE_DEVICE_TABLE(pci, vt8623_devices);static struct pci_driver vt8623fb_pci_driver = {	.name		= "vt8623fb",	.id_table	= vt8623_devices,	.probe		= vt8623_pci_probe,	.remove		= __devexit_p(vt8623_pci_remove),	.suspend	= vt8623_pci_suspend,	.resume		= vt8623_pci_resume,};/* Cleanup */static void __exit vt8623fb_cleanup(void){	pr_debug("vt8623fb: cleaning up\n");	pci_unregister_driver(&vt8623fb_pci_driver);}/* Driver Initialisation */static int __init vt8623fb_init(void){#ifndef MODULE	char *option = NULL;	if (fb_get_options("vt8623fb", &option))		return -ENODEV;	if (option && *option)		mode_option = option;#endif	pr_debug("vt8623fb: initializing\n");	return pci_register_driver(&vt8623fb_pci_driver);}/* ------------------------------------------------------------------------- *//* Modularization */module_init(vt8623fb_init);module_exit(vt8623fb_cleanup);

⌨️ 快捷键说明

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