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

📄 gbefb.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 3 页
字号:
static void gbefb_setup_flatpanel(struct gbe_timing_info *timing){	int fp_wid, fp_hgt, fp_vbs, fp_vbe;	u32 outputVal = 0;	SET_GBE_FIELD(VT_FLAGS, HDRV_INVERT, outputVal,		(timing->flags & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1);	SET_GBE_FIELD(VT_FLAGS, VDRV_INVERT, outputVal,		(timing->flags & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1);	gbe->vt_flags = outputVal;	/* Turn on the flat panel */	fp_wid = 1600;	fp_hgt = 1024;	fp_vbs = 0;	fp_vbe = 1600;	timing->pll_m = 4;	timing->pll_n = 1;	timing->pll_p = 0;	outputVal = 0;	SET_GBE_FIELD(FP_DE, ON, outputVal, fp_vbs);	SET_GBE_FIELD(FP_DE, OFF, outputVal, fp_vbe);	gbe->fp_de = outputVal;	outputVal = 0;	SET_GBE_FIELD(FP_HDRV, OFF, outputVal, fp_wid);	gbe->fp_hdrv = outputVal;	outputVal = 0;	SET_GBE_FIELD(FP_VDRV, ON, outputVal, 1);	SET_GBE_FIELD(FP_VDRV, OFF, outputVal, fp_hgt + 1);	gbe->fp_vdrv = outputVal;}struct gbe_pll_info {	int clock_rate;	int fvco_min;	int fvco_max;};static struct gbe_pll_info gbe_pll_table[2] = {	{ 20, 80, 220 },	{ 27, 80, 220 },};static int compute_gbe_timing(struct fb_var_screeninfo *var,			      struct gbe_timing_info *timing){	int pll_m, pll_n, pll_p, error, best_m, best_n, best_p, best_error;	int pixclock;	struct gbe_pll_info *gbe_pll;	if (gbe_revision < 2)		gbe_pll = &gbe_pll_table[0];	else		gbe_pll = &gbe_pll_table[1];	/* Determine valid resolution and timing	 * GBE crystal runs at 20Mhz or 27Mhz	 * pll_m, pll_n, pll_p define the following frequencies	 * fvco = pll_m * 20Mhz / pll_n	 * fout = fvco / (2**pll_p) */	best_error = 1000000000;	best_n = best_m = best_p = 0;	for (pll_p = 0; pll_p < 4; pll_p++)		for (pll_m = 1; pll_m < 256; pll_m++)			for (pll_n = 1; pll_n < 64; pll_n++) {				pixclock = (1000000 / gbe_pll->clock_rate) *						(pll_n << pll_p) / pll_m;				error = var->pixclock - pixclock;				if (error < 0)					error = -error;				if (error < best_error &&				    pll_m / pll_n >				    gbe_pll->fvco_min / gbe_pll->clock_rate && 				    pll_m / pll_n <				    gbe_pll->fvco_max / gbe_pll->clock_rate) {					best_error = error;					best_m = pll_m;					best_n = pll_n;					best_p = pll_p;				}			}	if (!best_n || !best_m)		return -EINVAL;	/* Resolution to high */	pixclock = (1000000 / gbe_pll->clock_rate) *		(best_n << best_p) / best_m;	/* set video timing information */	if (timing) {		timing->width = var->xres;		timing->height = var->yres;		timing->pll_m = best_m;		timing->pll_n = best_n;		timing->pll_p = best_p;		timing->cfreq = gbe_pll->clock_rate * 1000 * timing->pll_m /			(timing->pll_n << timing->pll_p);		timing->htotal = var->left_margin + var->xres +				var->right_margin + var->hsync_len;		timing->vtotal = var->upper_margin + var->yres +				var->lower_margin + var->vsync_len;		timing->fields_sec = 1000 * timing->cfreq / timing->htotal *				1000 / timing->vtotal;		timing->hblank_start = var->xres;		timing->vblank_start = var->yres;		timing->hblank_end = timing->htotal;		timing->hsync_start = var->xres + var->right_margin + 1;		timing->hsync_end = timing->hsync_start + var->hsync_len;		timing->vblank_end = timing->vtotal;		timing->vsync_start = var->yres + var->lower_margin + 1;		timing->vsync_end = timing->vsync_start + var->vsync_len;	}	return pixclock;}static void gbe_set_timing_info(struct gbe_timing_info *timing){	int temp;	unsigned int val;	/* setup dot clock PLL */	val = 0;	SET_GBE_FIELD(DOTCLK, M, val, timing->pll_m - 1);	SET_GBE_FIELD(DOTCLK, N, val, timing->pll_n - 1);	SET_GBE_FIELD(DOTCLK, P, val, timing->pll_p);	SET_GBE_FIELD(DOTCLK, RUN, val, 0);	/* do not start yet */	gbe->dotclock = val;	udelay(10000);	/* setup pixel counter */	val = 0;	SET_GBE_FIELD(VT_XYMAX, MAXX, val, timing->htotal);	SET_GBE_FIELD(VT_XYMAX, MAXY, val, timing->vtotal);	gbe->vt_xymax = val;	/* setup video timing signals */	val = 0;	SET_GBE_FIELD(VT_VSYNC, VSYNC_ON, val, timing->vsync_start);	SET_GBE_FIELD(VT_VSYNC, VSYNC_OFF, val, timing->vsync_end);	gbe->vt_vsync = val;	val = 0;	SET_GBE_FIELD(VT_HSYNC, HSYNC_ON, val, timing->hsync_start);	SET_GBE_FIELD(VT_HSYNC, HSYNC_OFF, val, timing->hsync_end);	gbe->vt_hsync = val;	val = 0;	SET_GBE_FIELD(VT_VBLANK, VBLANK_ON, val, timing->vblank_start);	SET_GBE_FIELD(VT_VBLANK, VBLANK_OFF, val, timing->vblank_end);	gbe->vt_vblank = val;	val = 0;	SET_GBE_FIELD(VT_HBLANK, HBLANK_ON, val,		      timing->hblank_start - 5);	SET_GBE_FIELD(VT_HBLANK, HBLANK_OFF, val,		      timing->hblank_end - 3);	gbe->vt_hblank = val;	/* setup internal timing signals */	val = 0;	SET_GBE_FIELD(VT_VCMAP, VCMAP_ON, val, timing->vblank_start);	SET_GBE_FIELD(VT_VCMAP, VCMAP_OFF, val, timing->vblank_end);	gbe->vt_vcmap = val;	val = 0;	SET_GBE_FIELD(VT_HCMAP, HCMAP_ON, val, timing->hblank_start);	SET_GBE_FIELD(VT_HCMAP, HCMAP_OFF, val, timing->hblank_end);	gbe->vt_hcmap = val;	val = 0;	temp = timing->vblank_start - timing->vblank_end - 1;	if (temp > 0)		temp = -temp;	if (flat_panel_enabled)		gbefb_setup_flatpanel(timing);	SET_GBE_FIELD(DID_START_XY, DID_STARTY, val, (u32) temp);	if (timing->hblank_end >= 20)		SET_GBE_FIELD(DID_START_XY, DID_STARTX, val,			      timing->hblank_end - 20);	else		SET_GBE_FIELD(DID_START_XY, DID_STARTX, val,			      timing->htotal - (20 - timing->hblank_end));	gbe->did_start_xy = val;	val = 0;	SET_GBE_FIELD(CRS_START_XY, CRS_STARTY, val, (u32) (temp + 1));	if (timing->hblank_end >= GBE_CRS_MAGIC)		SET_GBE_FIELD(CRS_START_XY, CRS_STARTX, val,			      timing->hblank_end - GBE_CRS_MAGIC);	else		SET_GBE_FIELD(CRS_START_XY, CRS_STARTX, val,			      timing->htotal - (GBE_CRS_MAGIC -						timing->hblank_end));	gbe->crs_start_xy = val;	val = 0;	SET_GBE_FIELD(VC_START_XY, VC_STARTY, val, (u32) temp);	SET_GBE_FIELD(VC_START_XY, VC_STARTX, val, timing->hblank_end - 4);	gbe->vc_start_xy = val;	val = 0;	temp = timing->hblank_end - GBE_PIXEN_MAGIC_ON;	if (temp < 0)		temp += timing->htotal;	/* allow blank to wrap around */	SET_GBE_FIELD(VT_HPIXEN, HPIXEN_ON, val, temp);	SET_GBE_FIELD(VT_HPIXEN, HPIXEN_OFF, val,		      ((temp + timing->width -			GBE_PIXEN_MAGIC_OFF) % timing->htotal));	gbe->vt_hpixen = val;	val = 0;	SET_GBE_FIELD(VT_VPIXEN, VPIXEN_ON, val, timing->vblank_end);	SET_GBE_FIELD(VT_VPIXEN, VPIXEN_OFF, val, timing->vblank_start);	gbe->vt_vpixen = val;	/* turn off sync on green */	val = 0;	SET_GBE_FIELD(VT_FLAGS, SYNC_LOW, val, 1);	gbe->vt_flags = val;}/* *  Set the hardware according to 'par'. */static int gbefb_set_par(struct fb_info *info){	int i;	unsigned int val;	int wholeTilesX, partTilesX, maxPixelsPerTileX;	int height_pix;	int xpmax, ypmax;	/* Monitor resolution */	int bytesPerPixel;	/* Bytes per pixel */	struct gbefb_par *par = (struct gbefb_par *) info->par;	compute_gbe_timing(&info->var, &par->timing);	bytesPerPixel = info->var.bits_per_pixel / 8;	info->fix.line_length = info->var.xres_virtual * bytesPerPixel;	xpmax = par->timing.width;	ypmax = par->timing.height;	/* turn off GBE */	gbe_turn_off();	/* set timing info */	gbe_set_timing_info(&par->timing);	/* initialize DIDs */	val = 0;	switch (bytesPerPixel) {	case 1:		SET_GBE_FIELD(WID, TYP, val, GBE_CMODE_I8);		break;	case 2:		SET_GBE_FIELD(WID, TYP, val, GBE_CMODE_ARGB5);		break;	case 4:		SET_GBE_FIELD(WID, TYP, val, GBE_CMODE_RGB8);		break;	}	SET_GBE_FIELD(WID, BUF, val, GBE_BMODE_BOTH);	for (i = 0; i < 32; i++)		gbe->mode_regs[i] = val;	/* Initialize interrupts */	gbe->vt_intr01 = 0xffffffff;	gbe->vt_intr23 = 0xffffffff;	/* HACK:	   The GBE hardware uses a tiled memory to screen mapping. Tiles are	   blocks of 512x128, 256x128 or 128x128 pixels, respectively for 8bit,	   16bit and 32 bit modes (64 kB). They cover the screen with partial	   tiles on the right and/or bottom of the screen if needed.	   For exemple in 640x480 8 bit mode the mapping is:	   <-------- 640 ----->	   <---- 512 ----><128|384 offscreen>	   ^  ^	   | 128    [tile 0]        [tile 1]	   |  v	   ^	   4 128    [tile 2]        [tile 3]	   8  v	   0  ^	   128    [tile 4]        [tile 5]	   |  v	   |  ^	   v  96    [tile 6]        [tile 7]	   32 offscreen	   Tiles have the advantage that they can be allocated individually in	   memory. However, this mapping is not linear at all, which is not	   really convienient. In order to support linear addressing, the GBE	   DMA hardware is fooled into thinking the screen is only one tile	   large and but has a greater height, so that the DMA transfer covers	   the same region.	   Tiles are still allocated as independent chunks of 64KB of	   continuous physical memory and remapped so that the kernel sees the	   framebuffer as a continuous virtual memory. The GBE tile table is	   set up so that each tile references one of these 64k blocks:	   GBE -> tile list    framebuffer           TLB   <------------ CPU	          [ tile 0 ] -> [ 64KB ]  <- [ 16x 4KB page entries ]     ^	             ...           ...              ...       linear virtual FB	          [ tile n ] -> [ 64KB ]  <- [ 16x 4KB page entries ]     v	   The GBE hardware is then told that the buffer is 512*tweaked_height,	   with tweaked_height = real_width*real_height/pixels_per_tile.	   Thus the GBE hardware will scan the first tile, filing the first 64k	   covered region of the screen, and then will proceed to the next	   tile, until the whole screen is covered.	   Here is what would happen at 640x480 8bit:	   normal tiling               linear	   ^   11111111111111112222    11111111111111111111  ^	   128 11111111111111112222    11111111111111111111 102 lines	       11111111111111112222    11111111111111111111  v	   V   11111111111111112222    11111111222222222222	       33333333333333334444    22222222222222222222	       33333333333333334444    22222222222222222222	       <      512     >        <  256 >               102*640+256 = 64k	   NOTE: The only mode for which this is not working is 800x600 8bit,	   as 800*600/512 = 937.5 which is not integer and thus causes	   flickering.	   I guess this is not so important as one can use 640x480 8bit or	   800x600 16bit anyway.	 */	/* Tell gbe about the tiles table location */	/* tile_ptr -> [ tile 1 ] -> FB mem */	/*             [ tile 2 ] -> FB mem */	/*               ...                */	val = 0;	SET_GBE_FIELD(FRM_CONTROL, FRM_TILE_PTR, val, gbe_tiles.dma >> 9);	SET_GBE_FIELD(FRM_CONTROL, FRM_DMA_ENABLE, val, 0); /* do not start */	SET_GBE_FIELD(FRM_CONTROL, FRM_LINEAR, val, 0);	gbe->frm_control = val;	maxPixelsPerTileX = 512 / bytesPerPixel;	wholeTilesX = 1;	partTilesX = 0;	/* Initialize the framebuffer */	val = 0;	SET_GBE_FIELD(FRM_SIZE_TILE, FRM_WIDTH_TILE, val, wholeTilesX);	SET_GBE_FIELD(FRM_SIZE_TILE, FRM_RHS, val, partTilesX);	switch (bytesPerPixel) {	case 1:		SET_GBE_FIELD(FRM_SIZE_TILE, FRM_DEPTH, val,			      GBE_FRM_DEPTH_8);		break;	case 2:		SET_GBE_FIELD(FRM_SIZE_TILE, FRM_DEPTH, val,			      GBE_FRM_DEPTH_16);		break;	case 4:		SET_GBE_FIELD(FRM_SIZE_TILE, FRM_DEPTH, val,			      GBE_FRM_DEPTH_32);		break;	}	gbe->frm_size_tile = val;	/* compute tweaked height */	height_pix = xpmax * ypmax / maxPixelsPerTileX;	val = 0;	SET_GBE_FIELD(FRM_SIZE_PIXEL, FB_HEIGHT_PIX, val, height_pix);	gbe->frm_size_pixel = val;	/* turn off DID and overlay DMA */	gbe->did_control = 0;	gbe->ovr_width_tile = 0;	/* Turn off mouse cursor */	gbe->crs_ctl = 0;	/* Turn on GBE */	gbe_turn_on();	/* Initialize the gamma map */	udelay(10);	for (i = 0; i < 256; i++)		gbe->gmap[i] = (i << 24) | (i << 16) | (i << 8);	/* Initialize the color map */	for (i = 0; i < 256; i++) {		int j;		for (j = 0; j < 1000 && gbe->cm_fifo >= 63; j++)			udelay(10);		if (j == 1000)			printk(KERN_ERR "gbefb: cmap FIFO timeout\n");		gbe->cmap[i] = (i << 8) | (i << 16) | (i << 24);

⌨️ 快捷键说明

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