ep93xxfb.c

来自「非常珍贵的LINUX下的专门针对CIRRUS公司的EP93XX平台的驱动源代码」· C语言 代码 · 共 2,214 行 · 第 1/4 页

C
2,214 行
字号
	display->type_aux = 0;	display->ypanstep = 0;	display->ywrapstep = 0;	display->line_length = display->next_line =		(var->xres * var->bits_per_pixel) / 8;	display->can_soft_blank	= 1;	display->inverse = 0;	switch (display->var.bits_per_pixel) {#ifdef FBCON_HAS_CFB4	case 4:		display->dispsw = &fbcon_cfb4;		break;#endif#ifdef FBCON_HAS_CFB8	case 8:		display->dispsw = &fbcon_cfb8;		break;#endif#ifdef FBCON_HAS_CFB16	case 16:		display->dispsw = &fbcon_cfb16;		display->dispsw_data = info->pseudo_palette;		break;#endif	default:		display->dispsw = &fbcon_dummy;		break;	}	/* If the console has changed and the console has defined */	/* a changevar function, call that function. */	if (chgvar && info && info->changevar)		info->changevar(con);	/* If the current console is selected and it's not truecolor,	 *  update the palette	 */	if ((con == mypar.currcon) && (mypar.visual != FB_VISUAL_TRUECOLOR)) {		struct fb_cmap *cmap;		//TBD what is the juggling of par about?		//mypar = par;		if (display->cmap.len)			cmap = &display->cmap;		else			cmap = fb_default_cmap(mypar.palette_size);		//TBD when is cmap.len set?		fb_set_cmap(cmap, 1, ep93xxfb_setcolreg, info);	}	//	// If the current console is selected, activate the new var.	//	if (con == mypar.currcon)		ConfigureRaster(var, info->par);	return 0;}//TBD why have this if it does nothing?static intep93xxfb_updatevar(int con, struct fb_info *info){	DPRINTK("entered\n");	return 0;}//TBD what is relation between fix data in info and getting fix here?static intep93xxfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info){	struct display *display;	memset(fix, 0, sizeof(struct fb_fix_screeninfo));	strcpy(fix->id, EP93XX_NAME);	if (con >= 0) {		DPRINTK("Using console specific display for con=%d\n",con);		display = &fb_display[con];  /* Display settings for console */	}	else		display = &global_disp;	  /* Default display settings */	//TBD global_disp is only valid after set_var called with -1	fix->smem_start	 = (unsigned long)mypar.p_screen_base;	fix->smem_len	 = mypar.screen_size;	fix->mmio_start	 = RASTER_BASE - IO_BASE_VIRT + IO_BASE_PHYS;#ifdef CONFIG_EP93XX_GRAPHICS	fix->mmio_len	 = 0x00020000;#else	fix->mmio_len	 = 0x00010000;#endif	fix->type	 = display->type;	fix->type_aux	 = display->type_aux;	fix->xpanstep	 = 0;	fix->ypanstep	 = display->ypanstep;	fix->ywrapstep	 = display->ywrapstep;	fix->visual	 = display->visual;	fix->line_length = display->line_length;	fix->accel	 = FB_ACCEL_NONE;	return 0;}static void__init ep93xxfb_init_fbinfo(void){	DPRINTK("Entering.");	//	// Set up the display name and default font.	//	strcpy(fb_info.modename, TimingValues[mode].Name);	strcpy(fb_info.fontname, default_font);	fb_info.node = -1;	fb_info.flags = FBINFO_FLAG_DEFAULT;	fb_info.open = 0;	//	// Set up initial parameters	//	fb_info.var.xres = TimingValues[mode].HRes;	fb_info.var.yres = TimingValues[mode].VRes;	//	// Virtual display not supported	//	fb_info.var.xres_virtual = fb_info.var.xres;	fb_info.var.yres_virtual = fb_info.var.yres;#ifdef CONFIG_FB_EP93XX_8BPP	DPRINTK("Default framebuffer is 8bpp.");	fb_info.var.bits_per_pixel	= 8;	fb_info.var.red.length		= 8;	fb_info.var.green.length	= 8;	fb_info.var.blue.length		= 8;	fb_info.fix.visual = FB_VISUAL_PSEUDOCOLOR;	mypar.bits_per_pixel		= 8;#endif // CONFIG_FB_EP93XX_8BPP#ifdef CONFIG_FB_EP93XX_16BPP_565	DPRINTK("Default framebuffer is 16bpp 565.");	fb_info.var.bits_per_pixel	= 16;	fb_info.var.red.length		= 5;	fb_info.var.blue.length		= 5;	fb_info.var.green.length	= 6;	fb_info.var.transp.length	= 0;	fb_info.var.red.offset		= 11;	fb_info.var.green.offset	= 5;	fb_info.var.blue.offset		= 0;	fb_info.var.transp.offset	= 0;	fb_info.fix.visual		= FB_VISUAL_TRUECOLOR;	fb_info.pseudo_palette		= mypar.palette;	mypar.bits_per_pixel = 16;#endif // CONFIG_FB_EP93XX_16BPP	//TBD wierd to have a flag which has meaning when call set_var	//TBD be copied into fb_info? this is more a parameter than	//TBD some state to keep track of.	fb_info.var.activate		= FB_ACTIVATE_NOW;	fb_info.var.height		= 640;			//TBD unknown	fb_info.var.width		= 480;			//TBD unknown	//	// Set the default timing information.	//	fb_info.var.left_margin		= TimingValues[mode].HFrontPorch;	fb_info.var.right_margin	= TimingValues[mode].HBackPorch;	fb_info.var.upper_margin	= TimingValues[mode].VFrontPorch;	fb_info.var.lower_margin	= TimingValues[mode].VBackPorch;	fb_info.var.hsync_len		= TimingValues[mode].HSyncWidth;	fb_info.var.vsync_len		= TimingValues[mode].VSyncWidth;	fb_info.var.sync		= 0;	fb_info.var.vmode		= FB_VMODE_NONINTERLACED;	fb_info.fix.smem_start		= (__u32) mypar.p_screen_base;	// physical	fb_info.fix.smem_len		= (__u32) mypar.screen_size;	//TBD in bytes	fb_info.fix.mmio_start		= RASTER_BASE - IO_BASE_VIRT + IO_BASE_PHYS;#ifdef CONFIG_EP93XX_GRAPHICS	fb_info.fix.mmio_len		= 0x00020000;#else	fb_info.fix.mmio_len		= 0x00010000;#endif	fb_info.fix.type		= FB_TYPE_PACKED_PIXELS;	fb_info.fix.line_length		= fb_info.var.xres_virtual *					  fb_info.var.bits_per_pixel/8;	// stride in bytes	fb_info.monspecs		= monspecs; // copies structure	fb_info.fbops			= &ep93xxfb_ops;	fb_info.screen_base 		= mypar.v_screen_base;	fb_info.disp			= &global_disp;	fb_info.changevar		= NULL;	fb_info.switch_con		= ep93xxfb_switch;	fb_info.updatevar		= ep93xxfb_updatevar;	//TBD why not NULL?	fb_info.blank			= ep93xxfb_blank;	//	// Save the current TimingValues for later use in Configuration routine.	//	fb_info.par = &TimingValues[mode];	mypar.screen_size		= FB_MAX_MEM_SIZE; // not a particular mode	mypar.palette_size		= MAX_PALETTE_NUM_ENTRIES; // not a particular mode	mypar.montype			= 1;	//TBD why not 0 since single entry?	mypar.currcon			= 0;		//TBD is this right?	// these are also set by set_var	mypar.visual			= FB_VISUAL_PSEUDOCOLOR;}//=============================================================================// MapFramebuffer//=============================================================================// Allocates the memory for the frame buffer.  This buffer is remapped into a// non-cached, non-buffered, memory region to allow pixel writes to occur// without flushing the cache.  Once this area is remapped, all virtual memory// access to the video memory should occur at the new region.//=============================================================================static int __init MapFramebuffer(void){	//	// Make sure that we don't allocate the buffer twice.	//	if (mypar.p_screen_base != 0)		return(-EINVAL);	//	// Allocate the Frame buffer and map it while we are at it.	// Save the Physical address of the Frame buffer in p_screen_base.	//	mypar.v_screen_base = consistent_alloc(GFP_KERNEL, FB_MAPPED_MEM_SIZE,		&mypar.p_screen_base);	if ( mypar.v_screen_base == 0)		return(-ENOMEM);	return 0;}//=============================================================================// ConfigureRaster()://=============================================================================// Configures LCD Controller based on entries in var parameter.//// Note: palette is setup elsewhere.//=============================================================================static intConfigureRaster(struct fb_var_screeninfo *var,		DisplayTimingValues *pTimingValues){	u_long	flags, ulVIDEOATTRIBS;	unsigned int total, uiDevCfg;	unsigned int uiPADDR, uiPADR;	DPRINTK("activating\n");	/* Disable interrupts and save status */	local_irq_save(flags);		// disable interrupts and save flags	RasterSetLocked(BRIGHTNESS, (16<<8)|(20));	//add by hzh	DPRINTK("Configuring %dx%dx%dbpp\n",var->xres, var->yres,		var->bits_per_pixel);	// Setup video mode according to var values.	// Remember to unlock total, startstop, and linecarry registers.	// Disable the video and outputs while changing the video mode.	outl( 0, VIDEOATTRIBS );	if (pTimingValues->RasterConfigure)		pTimingValues->RasterConfigure(pTimingValues);	else {		total = var->vsync_len +  var->upper_margin + var->yres +		var->lower_margin - 1;		RasterSetLocked(VLINESTOTAL, total);		RasterSetLocked(VSYNCSTRTSTOP, total - var->lower_margin +				((total - (var->lower_margin + var->vsync_len)) << 16));		RasterSetLocked(VACTIVESTRTSTOP, var->yres-1 + (total << 16));		// Reverse start/stop since N_VBLANK output		// unblanked same as active		RasterSetLocked(VBLANKSTRTSTOP, var->yres-1 + (total << 16));		RasterSetLocked(VCLKSTRTSTOP, total + (total << 16));		//		// Now configure the Horizontal timings.		//		total = var->hsync_len + var->left_margin + var->xres +			var->right_margin - 1;		RasterSetLocked(HCLKSTOTAL,total);		RasterSetLocked(HSYNCSTRTSTOP, total +				((total - var->hsync_len) << 16));		RasterSetLocked(HACTIVESTRTSTOP, total - var->hsync_len -				var->left_margin + ((var->right_margin - 1) << 16));		RasterSetLocked(HBLANKSTRTSTOP, total - var->hsync_len -				var->left_margin + ((var->right_margin - 1) << 16));		RasterSetLocked(HCLKSTRTSTOP, total + (total << 16));		RasterSetLocked(LINECARRY, 0);		//		// Now that everything else is setup, enable video and outputs		//		// Invert Clock, enable outputs and VSYNC,HSYNC,BLANK active low		// Invert means pixel output data changes on falling edge of clock, to		// provide setup time for the video DAC to latch data on rising edge.		//		if(mode==4)	//sharp 240X320, hzh			RasterSetLocked(VIDEOATTRIBS,					VIDEOATTRIBS_HSPOL | VIDEOATTRIBS_VCPOL |					VIDEOATTRIBS_PCLKEN | VIDEOATTRIBS_SYNCEN |					VIDEOATTRIBS_DATAEN);		else			RasterSetLocked(VIDEOATTRIBS, VIDEOATTRIBS_INVCLK |					VIDEOATTRIBS_PCLKEN | VIDEOATTRIBS_SYNCEN |					VIDEOATTRIBS_DATAEN);	}	//	// Configure the Frame Buffer size.	//	outl( (unsigned int)mypar.p_screen_base, VIDSCRNPAGE );	outl( var->yres, SCRNLINES );	//	// Set up the Line size.	//	total = var->xres * var->bits_per_pixel / 32;	outl( (total - 1), LINELENGTH );	outl( total, VLINESTEP );	if (var->bits_per_pixel == 8)		//		// 8bpp framebuffer, color LUT and convert to 18bpp on pixel bus.		//		outl( (0x8 | PIXELMODE_P_8BPP | PIXELMODE_C_LUT), PIXELMODE );	else if (var->bits_per_pixel == 16)		//		// 16bpp framebuffer and convert to 18bpp on pixel bus.		//		outl( 0x8 | PIXELMODE_P_16BPP | ((PIXELMODE_C_565)<<(PIXELMODE_C_SHIFT)),			  PIXELMODE );	//	// TODO this is more HACKING!	// TODO add configurable framebuffer location and side-band option.	//	uiDevCfg = inl(SYSCON_DEVCFG);	SysconSetLocked(SYSCON_DEVCFG, (uiDevCfg | SYSCON_DEVCFG_RasOnP3) );	//	// TODO add code to calculate this not just slam it in there.	//	SysconSetLocked(SYSCON_VIDDIV, pTimingValues->VDiv);	//	// Enable Raster and make sure that frame buffer chip select is specfied	// since this field is not readable.	//	ulVIDEOATTRIBS = inl(VIDEOATTRIBS) & ~VIDEOATTRIBS_SDSEL_MASK;#ifdef CONFIG_ARCH_EP93XX_SDCSN0	ulVIDEOATTRIBS |= 0 << VIDEOATTRIBS_SDSEL_SHIFT;#endif#ifdef CONFIG_ARCH_EP93XX_SDCSN1	ulVIDEOATTRIBS |= 1 << VIDEOATTRIBS_SDSEL_SHIFT;#endif#ifdef CONFIG_ARCH_EP93XX_SDCSN2	ulVIDEOATTRIBS |= 2 << VIDEOATTRIBS_SDSEL_SHIFT;#endif#ifdef CONFIG_ARCH_EP93XX_SDCSN3	ulVIDEOATTRIBS |= 3 << VIDEOATTRIBS_SDSEL_SHIFT;#endif	RasterSetLocked(VIDEOATTRIBS, ulVIDEOATTRIBS | VIDEOATTRIBS_EN);	//	// Turn on the LCD.	//#if defined(CONFIG_ARCH_EDB9307) || defined(CONFIG_ARCH_EDB9312) || \    defined(CONFIG_ARCH_EDB9315)	if (mode == 1) {		uiPADDR = inl(GPIO_PADDR) | 0x2;		outl( uiPADDR, GPIO_PADDR );		uiPADR = inl(GPIO_PADR) | 0x2;		outl( uiPADR, GPIO_PADR );	}#endif	//	// Restore interrupt status	//	local_irq_restore(flags);	return 0;}/* * ep93xxfb_blank(): *	TBD not implemented */static voidep93xxfb_blank(int blank, struct fb_info *info){}//=============================================================================// ep93xxfb_switch()://=============================================================================// Change to the specified console.  Palette and video mode are changed to the// console's stored parameters.////=============================================================================static int ep93xxfb_switch(int con, struct fb_info *info){	DPRINTK("con=%d info->modename=%s\n", con, info->modename);	if (mypar.visual != FB_VISUAL_TRUECOLOR) {		struct fb_cmap *cmap;		if (mypar.currcon >= 0) {			// Get the colormap for the selected console			cmap = &fb_display[mypar.currcon].cmap;			if (cmap->len)				fb_get_cmap(cmap, 1, ep93xxfb_getcolreg, info);		}	}	mypar.currcon = con;	fb_display[con].var.activate = FB_ACTIVATE_NOW;	DPRINTK("fb_display[%d].var.activate=%x\n", con,		fb_display[con].var.activate);	ep93xxfb_set_var(&fb_display[con].var, con, info);	return 0;}//=============================================================================// ep93xxfb_init(void)//=============================================================================//=============================================================================void SpiCmd(short  cmd){		int i ;        char ddat=0xff;	ddat = (ddat & (~0x1));	outl(ddat,GPIO_PADR);       udelay(100);     	for( i = 0; i < 16 ;i ++,cmd <<= 1)	{				ddat = ddat& (~(0x1<<3));		outl(ddat,GPIO_PADR);		udelay(100);			if(cmd&0x8000)			 ddat = ddat |(1<<1);		else ddat = ddat & (~(0x1<<1));		outl(ddat,GPIO_PADR);		udelay(100);		ddat = ddat |(1<<3);		outl(ddat,GPIO_PADR);		udelay(100);	 	}	ddat = ddat|(1);	outl(ddat,GPIO_PADR);	}      void initlcd(void){   int kkk;     outl(0xff,GPIO_PADDR);     outl(0xff,GPIO_PADR);     mdelay(100);       SpiCmd(0x516);     for(kkk=0;kkk<40;kkk++)     mdelay(40);	SpiCmd(0x596);    mdelay(40);	SpiCmd(0x41b);	mdelay(40);		SpiCmd(0x8c0);	mdelay(40);	SpiCmd(0x5d7); }int __init ep93xxfb_init(void){	int ret;	DPRINTK("Entering: ep93xxfb_init.\n");	//	// Allocate and map video buffer	//	if ((ret = MapFramebuffer()) != 0) {		DPRINTK("Leaving: ep93xxfb_init FAILED %08x.", ret);		return ret;	}	//	// Initialize the Framebuffer Info structure.	//	ep93xxfb_init_fbinfo();	//	// Check and adjust var and set it active.	// TBD is this okay to pass in fb_info.var or	// TBD does it cause some aliasing problem?	// TBD can set var fail?	//	ep93xxfb_set_var(&fb_info.var, -1, &fb_info);	register_framebuffer(&fb_info);#ifdef CONFIG_EP93XX_GRAPHICS	outl(0x00000000, BLOCKCTRL);	request_irq(IRQ_GRAPHICS, ep93xxfb_irq_handler, SA_INTERRUPT,		    "graphics",NULL);#endif    initlcd();	printk("Leaving: ep93xxfb_init.");  	return 0;}__init intep93xxfb_setup(char *options){	char *opt;	if (!options || !*options)		return 0;	while ((opt = strsep(&options, ",")) != NULL) {		if (!*opt)

⌨️ 快捷键说明

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