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

📄 macfb.c

📁 Linux环境下视频显示卡设备的驱动程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * The CSC is the framebuffer on the PowerBook 190 series * (and the 5300 too, but that's a PowerMac). This function * brought to you in part by the ECSC driver for MkLinux. */static int csc_setpalette (unsigned int regno, unsigned int red,			   unsigned int green, unsigned int blue,			   struct fb_info *info){	mdelay(1);	nubus_writeb(regno, &csc_cmap_regs->clut_waddr);	nubus_writeb(red,   &csc_cmap_regs->clut_data);	nubus_writeb(green, &csc_cmap_regs->clut_data);	nubus_writeb(blue,  &csc_cmap_regs->clut_data);	return 0;}static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,			   unsigned blue, unsigned transp,			   struct fb_info *fb_info){	/*	 *  Set a single color register. The values supplied are	 *  already rounded down to the hardware's capabilities	 *  (according to the entries in the `var' structure). Return	 *  != 0 for invalid regno.	 */		if (regno >= fb_info->cmap.len)		return 1;	if (fb_info->var.bits_per_pixel <= 8) {		switch (fb_info->var.bits_per_pixel) {		case 1:			/* We shouldn't get here */			break;		case 2:		case 4:		case 8:			if (macfb_setpalette)				macfb_setpalette(regno, red, green, blue,						 fb_info);			else				return 1;			break;		}	} else if (regno < 16) {		switch (fb_info->var.bits_per_pixel) {		case 16:			if (fb_info->var.red.offset == 10) {				/* 1:5:5:5 */				((u32*) (fb_info->pseudo_palette))[regno] =					((red   & 0xf800) >>  1) |					((green & 0xf800) >>  6) |					((blue  & 0xf800) >> 11) |					((transp != 0) << 15);			} else {				/* 0:5:6:5 */				((u32*) (fb_info->pseudo_palette))[regno] =					((red   & 0xf800)      ) |					((green & 0xfc00) >>  5) |					((blue  & 0xf800) >> 11);			}			break;			/* I'm pretty sure that one or the other of these			   doesn't exist on 68k Macs */		case 24:			red   >>= 8;			green >>= 8;			blue  >>= 8;			((u32 *)(fb_info->pseudo_palette))[regno] =				(red   << fb_info->var.red.offset)   |				(green << fb_info->var.green.offset) |				(blue  << fb_info->var.blue.offset);			break;		case 32:			red   >>= 8;			green >>= 8;			blue  >>= 8;			((u32 *)(fb_info->pseudo_palette))[regno] =				(red   << fb_info->var.red.offset)   |				(green << fb_info->var.green.offset) |				(blue  << fb_info->var.blue.offset);			break;		}	}	return 0;}static struct fb_ops macfb_ops = {	.owner		= THIS_MODULE,	.fb_setcolreg	= macfb_setcolreg,	.fb_fillrect	= cfb_fillrect,	.fb_copyarea	= cfb_copyarea,	.fb_imageblit	= cfb_imageblit,};static void __init macfb_setup(char *options){	char *this_opt;		if (!options || !*options)		return;		while ((this_opt = strsep(&options, ",")) != NULL) {		if (!*this_opt) continue;				if (! strcmp(this_opt, "inverse"))			inverse=1;		/* This means "turn on experimental CLUT code" */		else if (!strcmp(this_opt, "vidtest"))			vidtest=1;	}}static void __init iounmap_macfb(void){	if (valkyrie_cmap_regs)		iounmap(valkyrie_cmap_regs);	if (dafb_cmap_regs)		iounmap(dafb_cmap_regs);	if (v8_brazil_cmap_regs)		iounmap(v8_brazil_cmap_regs);	if (rbv_cmap_regs)		iounmap(rbv_cmap_regs);	if (civic_cmap_regs)		iounmap(civic_cmap_regs);	if (csc_cmap_regs)		iounmap(csc_cmap_regs);}static int __init macfb_init(void){	int video_cmap_len, video_is_nubus = 0;	struct nubus_dev* ndev = NULL;	char *option = NULL;	int err;	if (fb_get_options("macfb", &option))		return -ENODEV;	macfb_setup(option);	if (!MACH_IS_MAC) 		return -ENODEV;	/* There can only be one internal video controller anyway so	   we're not too worried about this */	macfb_defined.xres = mac_bi_data.dimensions & 0xFFFF;	macfb_defined.yres = mac_bi_data.dimensions >> 16;	macfb_defined.bits_per_pixel = mac_bi_data.videodepth;	macfb_fix.line_length = mac_bi_data.videorow;	macfb_fix.smem_len = macfb_fix.line_length * macfb_defined.yres;	/* Note: physical address (since 2.1.127) */	macfb_fix.smem_start = mac_bi_data.videoaddr;	/* This is actually redundant with the initial mappings.	   However, there are some non-obvious aspects to the way	   those mappings are set up, so this is in fact the safest	   way to ensure that this driver will work on every possible	   Mac */	fb_info.screen_base = ioremap(mac_bi_data.videoaddr, macfb_fix.smem_len);		printk("macfb: framebuffer at 0x%08lx, mapped to 0x%p, size %dk\n",	       macfb_fix.smem_start, fb_info.screen_base, macfb_fix.smem_len/1024);	printk("macfb: mode is %dx%dx%d, linelength=%d\n",	       macfb_defined.xres, macfb_defined.yres, macfb_defined.bits_per_pixel, macfb_fix.line_length);		/*	 *	Fill in the available video resolution	 */	 	macfb_defined.xres_virtual   = macfb_defined.xres;	macfb_defined.yres_virtual   = macfb_defined.yres;	macfb_defined.height = PIXEL_TO_MM(macfb_defined.yres);	macfb_defined.width  = PIXEL_TO_MM(macfb_defined.xres);	 	printk("macfb: scrolling: redraw\n");	macfb_defined.yres_virtual = macfb_defined.yres;	/* some dummy values for timing to make fbset happy */	macfb_defined.pixclock     = 10000000 / macfb_defined.xres * 1000 / macfb_defined.yres;	macfb_defined.left_margin  = (macfb_defined.xres / 8) & 0xf8;	macfb_defined.hsync_len    = (macfb_defined.xres / 8) & 0xf8;	switch (macfb_defined.bits_per_pixel) {	case 1:		/* XXX: I think this will catch any program that tries		   to do FBIO_PUTCMAP when the visual is monochrome */		macfb_defined.red.length = macfb_defined.bits_per_pixel;		macfb_defined.green.length = macfb_defined.bits_per_pixel;		macfb_defined.blue.length = macfb_defined.bits_per_pixel;		video_cmap_len = 0;		macfb_fix.visual = FB_VISUAL_MONO01;		break;	case 2:	case 4:	case 8:		macfb_defined.red.length = macfb_defined.bits_per_pixel;		macfb_defined.green.length = macfb_defined.bits_per_pixel;		macfb_defined.blue.length = macfb_defined.bits_per_pixel;		video_cmap_len = 1 << macfb_defined.bits_per_pixel;		macfb_fix.visual = FB_VISUAL_PSEUDOCOLOR;		break;	case 16:		macfb_defined.transp.offset = 15;		macfb_defined.transp.length = 1;		macfb_defined.red.offset = 10;		macfb_defined.red.length = 5;		macfb_defined.green.offset = 5;		macfb_defined.green.length = 5;		macfb_defined.blue.offset = 0;		macfb_defined.blue.length = 5;		printk("macfb: directcolor: "		       "size=1:5:5:5, shift=15:10:5:0\n");		video_cmap_len = 16;		/* Should actually be FB_VISUAL_DIRECTCOLOR, but this		   works too */		macfb_fix.visual = FB_VISUAL_TRUECOLOR;		break;	case 24:	case 32:		/* XXX: have to test these... can any 68k Macs		   actually do this on internal video? */		macfb_defined.red.offset = 16;		macfb_defined.red.length = 8;		macfb_defined.green.offset = 8;		macfb_defined.green.length = 8;		macfb_defined.blue.offset = 0;		macfb_defined.blue.length = 8;		printk("macfb: truecolor: "		       "size=0:8:8:8, shift=0:16:8:0\n");		video_cmap_len = 16;		macfb_fix.visual = FB_VISUAL_TRUECOLOR;	default:		video_cmap_len = 0;		macfb_fix.visual = FB_VISUAL_MONO01;		printk("macfb: unknown or unsupported bit depth: %d\n", macfb_defined.bits_per_pixel);		break;	}		/* Hardware dependent stuff */	/*  We take a wild guess that if the video physical address is	 *  in nubus slot space, that the nubus card is driving video.	 *  Penguin really ought to tell us whether we are using internal	 *  video or not.	 */	/* Hopefully we only find one of them.  Otherwise our NuBus           code is really broken :-) */	while ((ndev = nubus_find_type(NUBUS_CAT_DISPLAY, NUBUS_TYPE_VIDEO, ndev))		!= NULL)	{		if (!(mac_bi_data.videoaddr >= ndev->board->slot_addr		      && (mac_bi_data.videoaddr <			  (unsigned long)nubus_slot_addr(ndev->board->slot+1))))			continue;		video_is_nubus = 1;		/* We should probably just use the slot address... */		video_slot = ndev->board->slot;		switch(ndev->dr_hw) {		case NUBUS_DRHW_APPLE_MDC:			strcpy(macfb_fix.id, "Mac Disp. Card");			macfb_setpalette = mdc_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			break;		case NUBUS_DRHW_APPLE_TFB:			strcpy(macfb_fix.id, "Toby");			macfb_setpalette = toby_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			break;		case NUBUS_DRHW_APPLE_JET:			strcpy(macfb_fix.id, "Jet");			macfb_setpalette = jet_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			break;					default:			strcpy(macfb_fix.id, "Generic NuBus");			break;		}	}	/* If it's not a NuBus card, it must be internal video */	/* FIXME: this function is getting way too big.  (this driver           is too...) */	if (!video_is_nubus)		switch( mac_bi_data.id )		{			/* Valkyrie Quadras */		case MAC_MODEL_Q630:			/* I'm not sure about this one */		case MAC_MODEL_P588:			strcpy(macfb_fix.id, "Valkyrie");			macfb_setpalette = valkyrie_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			valkyrie_cmap_regs = ioremap(DAC_BASE, 0x1000);			break;			/* DAFB Quadras */			/* Note: these first four have the v7 DAFB, which is			   known to be rather unlike the ones used in the			   other models */		case MAC_MODEL_P475:		case MAC_MODEL_P475F:		case MAC_MODEL_P575:		case MAC_MODEL_Q605:			case MAC_MODEL_Q800:		case MAC_MODEL_Q650:		case MAC_MODEL_Q610:		case MAC_MODEL_C650:		case MAC_MODEL_C610:		case MAC_MODEL_Q700:		case MAC_MODEL_Q900:		case MAC_MODEL_Q950:			strcpy(macfb_fix.id, "DAFB");			macfb_setpalette = dafb_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000);			break;			/* LC II uses the V8 framebuffer */		case MAC_MODEL_LCII:			strcpy(macfb_fix.id, "V8");			macfb_setpalette = v8_brazil_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);			break;					/* IIvi, IIvx use the "Brazil" framebuffer (which is			   very much like the V8, it seems, and probably uses			   the same DAC) */		case MAC_MODEL_IIVI:		case MAC_MODEL_IIVX:		case MAC_MODEL_P600:			strcpy(macfb_fix.id, "Brazil");			macfb_setpalette = v8_brazil_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);			break;					/* LC III (and friends) use the Sonora framebuffer */			/* Incidentally this is also used in the non-AV models			   of the x100 PowerMacs */			/* These do in fact seem to use the same DAC interface			   as the LC II. */		case MAC_MODEL_LCIII:		case MAC_MODEL_P520:		case MAC_MODEL_P550:		case MAC_MODEL_P460:			macfb_setpalette = v8_brazil_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			strcpy(macfb_fix.id, "Sonora");			v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);			break;			/* IIci and IIsi use the infamous RBV chip                           (the IIsi is just a rebadged and crippled                           IIci in a different case, BTW) */		case MAC_MODEL_IICI:		case MAC_MODEL_IISI:			macfb_setpalette = rbv_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			strcpy(macfb_fix.id, "RBV");			rbv_cmap_regs = ioremap(DAC_BASE, 0x1000);			break;			/* AVs use the Civic framebuffer */		case MAC_MODEL_Q840:		case MAC_MODEL_C660:			macfb_setpalette = civic_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			strcpy(macfb_fix.id, "Civic");			civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);			break;					/* Write a setpalette function for your machine, then			   you can add something similar here.  These are			   grouped by classes of video chipsets.  Some of this			   information is from the VideoToolbox "Bugs" web			   page at			   http://rajsky.psych.nyu.edu/Tips/VideoBugs.html */			/* Assorted weirdos */			/* We think this may be like the LC II */		case MAC_MODEL_LC:			if (vidtest) {				macfb_setpalette = v8_brazil_setpalette;				macfb_defined.activate = FB_ACTIVATE_NOW;				v8_brazil_cmap_regs =					ioremap(DAC_BASE, 0x1000);			}			strcpy(macfb_fix.id, "LC");			break;			/* We think this may be like the LC II */		case MAC_MODEL_CCL:			if (vidtest) {				macfb_setpalette = v8_brazil_setpalette;				macfb_defined.activate = FB_ACTIVATE_NOW;				v8_brazil_cmap_regs =					ioremap(DAC_BASE, 0x1000);			}			strcpy(macfb_fix.id, "Color Classic");			break;			/* And we *do* mean "weirdos" */		case MAC_MODEL_TV:			strcpy(macfb_fix.id, "Mac TV");			break;			/* These don't have colour, so no need to worry */		case MAC_MODEL_SE30:		case MAC_MODEL_CLII:			strcpy(macfb_fix.id, "Monochrome");			break;			/* Powerbooks are particularly difficult.  Many of			   them have separate framebuffers for external and			   internal video, which is admittedly pretty cool,			   but will be a bit of a headache to support here.			   Also, many of them are grayscale, and we don't			   really support that. */		case MAC_MODEL_PB140:		case MAC_MODEL_PB145:		case MAC_MODEL_PB170:			strcpy(macfb_fix.id, "DDC");			break;			/* Internal is GSC, External (if present) is ViSC */		case MAC_MODEL_PB150:	/* no external video */		case MAC_MODEL_PB160:		case MAC_MODEL_PB165:		case MAC_MODEL_PB180:		case MAC_MODEL_PB210:		case MAC_MODEL_PB230:			strcpy(macfb_fix.id, "GSC");			break;			/* Internal is TIM, External is ViSC */		case MAC_MODEL_PB165C:		case MAC_MODEL_PB180C:			strcpy(macfb_fix.id, "TIM");			break;			/* Internal is CSC, External is Keystone+Ariel. */		case MAC_MODEL_PB190:	/* external video is optional */		case MAC_MODEL_PB520:		case MAC_MODEL_PB250:		case MAC_MODEL_PB270C:		case MAC_MODEL_PB280:		case MAC_MODEL_PB280C:			macfb_setpalette = csc_setpalette;			macfb_defined.activate = FB_ACTIVATE_NOW;			strcpy(macfb_fix.id, "CSC");			csc_cmap_regs = ioremap(CSC_BASE, 0x1000);			break;				default:			strcpy(macfb_fix.id, "Unknown");			break;		}	fb_info.fbops		= &macfb_ops;	fb_info.var		= macfb_defined;	fb_info.fix		= macfb_fix;	fb_info.pseudo_palette	= pseudo_palette;	fb_info.flags		= FBINFO_DEFAULT;	err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);	if (err)		goto fail_unmap;		err = register_framebuffer(&fb_info);	if (err)		goto fail_dealloc;	printk("fb%d: %s frame buffer device\n",	       fb_info.node, fb_info.fix.id);	return 0;fail_dealloc:	fb_dealloc_cmap(&fb_info.cmap);fail_unmap:	iounmap(fb_info.screen_base);	iounmap_macfb();	return err;}module_init(macfb_init);MODULE_LICENSE("GPL");

⌨️ 快捷键说明

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