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

📄 fsl-diu-fb.c

📁 Linux环境下视频显示卡设备的驱动程序源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
		var->green.length = 6;		var->green.offset = 5;		var->green.msb_right = 0;		var->blue.length = 5;		var->blue.offset = 0;		var->blue.msb_right = 0;		var->transp.length = 0;		var->transp.offset = 0;		var->transp.msb_right = 0;		break;	case 24:		var->red.length = 8;		var->red.offset = 0;		var->red.msb_right = 0;		var->green.length = 8;		var->green.offset = 8;		var->green.msb_right = 0;		var->blue.length = 8;		var->blue.offset = 16;		var->blue.msb_right = 0;		var->transp.length = 0;		var->transp.offset = 0;		var->transp.msb_right = 0;		break;	case 32:		var->red.length = 8;		var->red.offset = 16;		var->red.msb_right = 0;		var->green.length = 8;		var->green.offset = 8;		var->green.msb_right = 0;		var->blue.length = 8;		var->blue.offset = 0;		var->blue.msb_right = 0;		var->transp.length = 8;		var->transp.offset = 24;		var->transp.msb_right = 0;		break;	}	/* If the pixclock is below the minimum spec'd value then set to	 * refresh rate for 60Hz since this is supported by most monitors.	 * Refer to Documentation/fb/ for calculations.	 */	if ((var->pixclock < MIN_PIX_CLK) || (var->pixclock > MAX_PIX_CLK)) {		htotal = var->xres + var->right_margin + var->hsync_len +		    var->left_margin;		vtotal = var->yres + var->lower_margin + var->vsync_len +		    var->upper_margin;		var->pixclock = (vtotal * htotal * 6UL) / 100UL;		var->pixclock = KHZ2PICOS(var->pixclock);		pr_debug("pixclock set for 60Hz refresh = %u ps\n",			var->pixclock);	}	var->height = -1;	var->width = -1;	var->grayscale = 0;	/* Copy nonstd field to/from sync for fbset usage */	var->sync |= var->nonstd;	var->nonstd |= var->sync;	adjust_aoi_size_position(var, info);	return 0;}static void set_fix(struct fb_info *info){	struct fb_fix_screeninfo *fix = &info->fix;	struct fb_var_screeninfo *var = &info->var;	struct mfb_info *mfbi = info->par;	strncpy(fix->id, mfbi->id, strlen(mfbi->id));	fix->line_length = var->xres_virtual * var->bits_per_pixel / 8;	fix->type = FB_TYPE_PACKED_PIXELS;	fix->accel = FB_ACCEL_NONE;	fix->visual = FB_VISUAL_TRUECOLOR;	fix->xpanstep = 1;	fix->ypanstep = 1;}static void update_lcdc(struct fb_info *info){	struct fb_var_screeninfo *var = &info->var;	struct mfb_info *mfbi = info->par;	struct fsl_diu_data *machine_data = mfbi->parent;	struct diu *hw;	int i, j;	char __iomem *cursor_base, *gamma_table_base;	u32 temp;	hw = dr.diu_reg;	if (mfbi->type == MFB_TYPE_OFF) {		fsl_diu_disable_panel(info);		return;	}	diu_ops.set_monitor_port(machine_data->monitor_port);	gamma_table_base = pool.gamma.vaddr;	cursor_base = pool.cursor.vaddr;	/* Prep for DIU init  - gamma table, cursor table */	for (i = 0; i <= 2; i++)	   for (j = 0; j <= 255; j++)	      *gamma_table_base++ = j;	diu_ops.set_gamma_table(machine_data->monitor_port, pool.gamma.vaddr);	pr_debug("update-lcdc: HW - %p\n Disabling DIU\n", hw);	disable_lcdc(info);	/* Program DIU registers */	out_be32(&hw->gamma, pool.gamma.paddr);	out_be32(&hw->cursor, pool.cursor.paddr);	out_be32(&hw->bgnd, 0x007F7F7F); 	/* BGND */	out_be32(&hw->bgnd_wb, 0); 		/* BGND_WB */	out_be32(&hw->disp_size, (var->yres << 16 | var->xres));						/* DISP SIZE */	pr_debug("DIU xres: %d\n", var->xres);	pr_debug("DIU yres: %d\n", var->yres);	out_be32(&hw->wb_size, 0); /* WB SIZE */	out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */	/* Horizontal and vertical configuration register */	temp = var->left_margin << 22 | /* BP_H */	       var->hsync_len << 11 |   /* PW_H */	       var->right_margin;       /* FP_H */	out_be32(&hw->hsyn_para, temp);	temp = var->upper_margin << 22 | /* BP_V */	       var->vsync_len << 11 |    /* PW_V  */	       var->lower_margin;        /* FP_V  */	out_be32(&hw->vsyn_para, temp);	pr_debug("DIU right_margin - %d\n", var->right_margin);	pr_debug("DIU left_margin - %d\n", var->left_margin);	pr_debug("DIU hsync_len - %d\n", var->hsync_len);	pr_debug("DIU upper_margin - %d\n", var->upper_margin);	pr_debug("DIU lower_margin - %d\n", var->lower_margin);	pr_debug("DIU vsync_len - %d\n", var->vsync_len);	pr_debug("DIU HSYNC - 0x%08x\n", hw->hsyn_para);	pr_debug("DIU VSYNC - 0x%08x\n", hw->vsyn_para);	diu_ops.set_pixel_clock(var->pixclock);	out_be32(&hw->syn_pol, 0);	/* SYNC SIGNALS POLARITY */	out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */	out_be32(&hw->int_status, 0);	/* INTERRUPT STATUS */	out_be32(&hw->plut, 0x01F5F666);	/* Enable the DIU */	enable_lcdc(info);}static int map_video_memory(struct fb_info *info){	phys_addr_t phys;	pr_debug("info->var.xres_virtual = %d\n", info->var.xres_virtual);	pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);	pr_debug("info->fix.line_length  = %d\n", info->fix.line_length);	info->fix.smem_len = info->fix.line_length * info->var.yres_virtual;	pr_debug("MAP_VIDEO_MEMORY: smem_len = %d\n", info->fix.smem_len);	info->screen_base = fsl_diu_alloc(info->fix.smem_len, &phys);	if (info->screen_base == NULL) {		printk(KERN_ERR "Unable to allocate fb memory\n");		return -ENOMEM;	}	info->fix.smem_start = (unsigned long) phys;	info->screen_size = info->fix.smem_len;	pr_debug("Allocated fb @ paddr=0x%08lx, size=%d.\n",				info->fix.smem_start,		info->fix.smem_len);	pr_debug("screen base %p\n", info->screen_base);	return 0;}static void unmap_video_memory(struct fb_info *info){	fsl_diu_free(info->screen_base, info->fix.smem_len);	info->screen_base = NULL;	info->fix.smem_start = 0;	info->fix.smem_len = 0;}/* * Using the fb_var_screeninfo in fb_info we set the aoi of this * particular framebuffer. It is a light version of fsl_diu_set_par. */static int fsl_diu_set_aoi(struct fb_info *info){	struct fb_var_screeninfo *var = &info->var;	struct mfb_info *mfbi = info->par;	struct diu_ad *ad = mfbi->ad;	/* AOI should not be greater than display size */	ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);	ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);	return 0;}/* * Using the fb_var_screeninfo in fb_info we set the resolution of this * particular framebuffer. This function alters the fb_fix_screeninfo stored * in fb_info. It does not alter var in fb_info since we are using that * data. This means we depend on the data in var inside fb_info to be * supported by the hardware. fsl_diu_check_var is always called before * fsl_diu_set_par to ensure this. */static int fsl_diu_set_par(struct fb_info *info){	unsigned long len;	struct fb_var_screeninfo *var = &info->var;	struct mfb_info *mfbi = info->par;	struct fsl_diu_data *machine_data = mfbi->parent;	struct diu_ad *ad = mfbi->ad;	struct diu *hw;	hw = dr.diu_reg;	set_fix(info);	mfbi->cursor_reset = 1;	len = info->var.yres_virtual * info->fix.line_length;	/* Alloc & dealloc each time resolution/bpp change */	if (len != info->fix.smem_len) {		if (info->fix.smem_start)			unmap_video_memory(info);		pr_debug("SET PAR: smem_len = %d\n", info->fix.smem_len);		/* Memory allocation for framebuffer */		if (map_video_memory(info)) {			printk(KERN_ERR "Unable to allocate fb memory 1\n");			return -ENOMEM;		}	}	ad->pix_fmt =		diu_ops.get_pixel_format(var->bits_per_pixel,					 machine_data->monitor_port);	ad->addr    = cpu_to_le32(info->fix.smem_start);	ad->src_size_g_alpha = cpu_to_le32((var->yres_virtual << 12) |				var->xres_virtual) | mfbi->g_alpha;	/* AOI should not be greater than display size */	ad->aoi_size 	= cpu_to_le32((var->yres << 16) | var->xres);	ad->offset_xyi = cpu_to_le32((var->yoffset << 16) | var->xoffset);	ad->offset_xyd = cpu_to_le32((mfbi->y_aoi_d << 16) | mfbi->x_aoi_d);	/* Disable chroma keying function */	ad->ckmax_r = 0;	ad->ckmax_g = 0;	ad->ckmax_b = 0;	ad->ckmin_r = 255;	ad->ckmin_g = 255;	ad->ckmin_b = 255;	if (mfbi->index == 0)		update_lcdc(info);	return 0;}static inline __u32 CNVT_TOHW(__u32 val, __u32 width){	return ((val<<width) + 0x7FFF - val)>>16;}/* * Set a single color register. The values supplied have a 16 bit magnitude * which needs to be scaled in this function for the hardware. Things to take * into consideration are how many color registers, if any, are supported with * the current color visual. With truecolor mode no color palettes are * supported. Here a psuedo palette is created which we store the value in * pseudo_palette in struct fb_info. For pseudocolor mode we have a limited * color palette. */static int fsl_diu_setcolreg(unsigned regno, unsigned red, unsigned green,			   unsigned blue, unsigned transp, struct fb_info *info){	int ret = 1;	/*	 * If greyscale is true, then we convert the RGB value	 * to greyscale no matter what visual we are using.	 */	if (info->var.grayscale)		red = green = blue = (19595 * red + 38470 * green +				      7471 * blue) >> 16;	switch (info->fix.visual) {	case FB_VISUAL_TRUECOLOR:		/*		 * 16-bit True Colour.  We encode the RGB value		 * according to the RGB bitfield information.		 */		if (regno < 16) {			u32 *pal = info->pseudo_palette;			u32 v;			red = CNVT_TOHW(red, info->var.red.length);			green = CNVT_TOHW(green, info->var.green.length);			blue = CNVT_TOHW(blue, info->var.blue.length);			transp = CNVT_TOHW(transp, info->var.transp.length);			v = (red << info->var.red.offset) |			    (green << info->var.green.offset) |			    (blue << info->var.blue.offset) |			    (transp << info->var.transp.offset);			pal[regno] = v;			ret = 0;		}		break;	case FB_VISUAL_STATIC_PSEUDOCOLOR:	case FB_VISUAL_PSEUDOCOLOR:		break;	}	return ret;}/* * Pan (or wrap, depending on the `vmode' field) the display using the * 'xoffset' and 'yoffset' fields of the 'var' structure. If the values * don't fit, return -EINVAL. */static int fsl_diu_pan_display(struct fb_var_screeninfo *var,			     struct fb_info *info){	if ((info->var.xoffset == var->xoffset) &&	    (info->var.yoffset == var->yoffset))		return 0;	/* No change, do nothing */	if (var->xoffset < 0 || var->yoffset < 0	    || var->xoffset + info->var.xres > info->var.xres_virtual	    || var->yoffset + info->var.yres > info->var.yres_virtual)		return -EINVAL;	info->var.xoffset = var->xoffset;	info->var.yoffset = var->yoffset;	if (var->vmode & FB_VMODE_YWRAP)		info->var.vmode |= FB_VMODE_YWRAP;	else		info->var.vmode &= ~FB_VMODE_YWRAP;	fsl_diu_set_aoi(info);	return 0;}/* * Blank the screen if blank_mode != 0, else unblank. Return 0 if blanking * succeeded, != 0 if un-/blanking failed. * blank_mode == 2: suspend vsync * blank_mode == 3: suspend hsync * blank_mode == 4: powerdown */static int fsl_diu_blank(int blank_mode, struct fb_info *info){	struct mfb_info *mfbi = info->par;	mfbi->blank = blank_mode;	switch (blank_mode) {	case FB_BLANK_VSYNC_SUSPEND:	case FB_BLANK_HSYNC_SUSPEND:	/* FIXME: fixes to enable_panel and enable lcdc needed */	case FB_BLANK_NORMAL:	/*	fsl_diu_disable_panel(info);*/		break;	case FB_BLANK_POWERDOWN:	/*	disable_lcdc(info);	*/		break;	case FB_BLANK_UNBLANK:	/*	fsl_diu_enable_panel(info);*/		break;	}	return 0;}static int fsl_diu_ioctl(struct fb_info *info, unsigned int cmd,		       unsigned long arg){	struct mfb_info *mfbi = info->par;	struct diu_ad *ad = mfbi->ad;	struct mfb_chroma_key ck;	unsigned char global_alpha;	struct aoi_display_offset aoi_d;	__u32 pix_fmt;	void __user *buf = (void __user *)arg;	if (!arg)		return -EINVAL;	switch (cmd) {	case MFB_SET_PIXFMT:		if (copy_from_user(&pix_fmt, buf, sizeof(pix_fmt)))			return -EFAULT;		ad->pix_fmt = pix_fmt;		pr_debug("Set pixel format to 0x%08x\n", ad->pix_fmt);		break;	case MFB_GET_PIXFMT:		pix_fmt = ad->pix_fmt;		if (copy_to_user(buf, &pix_fmt, sizeof(pix_fmt)))			return -EFAULT;		pr_debug("get pixel format 0x%08x\n", ad->pix_fmt);		break;	case MFB_SET_AOID:		if (copy_from_user(&aoi_d, buf, sizeof(aoi_d)))			return -EFAULT;		mfbi->x_aoi_d = aoi_d.x_aoi_d;		mfbi->y_aoi_d = aoi_d.y_aoi_d;		pr_debug("set AOI display offset of index %d to (%d,%d)\n",				 mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);		fsl_diu_check_var(&info->var, info);		fsl_diu_set_aoi(info);		break;	case MFB_GET_AOID:		aoi_d.x_aoi_d = mfbi->x_aoi_d;		aoi_d.y_aoi_d = mfbi->y_aoi_d;		if (copy_to_user(buf, &aoi_d, sizeof(aoi_d)))			return -EFAULT;		pr_debug("get AOI display offset of index %d (%d,%d)\n",				mfbi->index, aoi_d.x_aoi_d, aoi_d.y_aoi_d);		break;	case MFB_GET_ALPHA:		global_alpha = mfbi->g_alpha;		if (copy_to_user(buf, &global_alpha, sizeof(global_alpha)))			return -EFAULT;		pr_debug("get global alpha of index %d\n", mfbi->index);		break;	case MFB_SET_ALPHA:		/* set panel information */		if (copy_from_user(&global_alpha, buf, sizeof(global_alpha)))			return -EFAULT;		ad->src_size_g_alpha = (ad->src_size_g_alpha & (~0xff)) |							(global_alpha & 0xff);		mfbi->g_alpha = global_alpha;		pr_debug("set global alpha for index %d\n", mfbi->index);		break;	case MFB_SET_CHROMA_KEY:		/* set panel winformation */		if (copy_from_user(&ck, buf, sizeof(ck)))			return -EFAULT;		if (ck.enable &&		   (ck.red_max < ck.red_min ||		    ck.green_max < ck.green_min ||		    ck.blue_max < ck.blue_min))			return -EINVAL;		if (!ck.enable) {			ad->ckmax_r = 0;			ad->ckmax_g = 0;			ad->ckmax_b = 0;			ad->ckmin_r = 255;			ad->ckmin_g = 255;			ad->ckmin_b = 255;		} else {			ad->ckmax_r = ck.red_max;			ad->ckmax_g = ck.green_max;			ad->ckmax_b = ck.blue_max;			ad->ckmin_r = ck.red_min;			ad->ckmin_g = ck.green_min;			ad->ckmin_b = ck.blue_min;		}		pr_debug("set chroma key\n");		break;	case FBIOGET_GWINFO:		if (mfbi->type == MFB_TYPE_OFF)			return -ENODEV;		/* get graphic window information */		if (copy_to_user(buf, ad, sizeof(*ad)))			return -EFAULT;		break;	case FBIOGET_HWCINFO:		pr_debug("FBIOGET_HWCINFO:0x%08x\n", FBIOGET_HWCINFO);		break;	case FBIOPUT_MODEINFO:		pr_debug("FBIOPUT_MODEINFO:0x%08x\n", FBIOPUT_MODEINFO);		break;	case FBIOGET_DISPINFO:		pr_debug("FBIOGET_DISPINFO:0x%08x\n", FBIOGET_DISPINFO);		break;	default:		printk(KERN_ERR "Unknown ioctl command (0x%08X)\n", cmd);		return -ENOIOCTLCMD;	}	return 0;}/* turn on fb if count == 1 */static int fsl_diu_open(struct fb_info *info, int user){	struct mfb_info *mfbi = info->par;	int res = 0;	spin_lock(&diu_lock);	mfbi->count++;	if (mfbi->count == 1) {		pr_debug("open plane index %d\n", mfbi->index);		fsl_diu_check_var(&info->var, info);		res = fsl_diu_set_par(info);		if (res < 0)			mfbi->count--;		else {			res = fsl_diu_enable_panel(info);			if (res < 0)				mfbi->count--;		}	}	spin_unlock(&diu_lock);	return res;}/* turn off fb if count == 0 */static int fsl_diu_release(struct fb_info *info, int user){	struct mfb_info *mfbi = info->par;	int res = 0;	spin_lock(&diu_lock);	mfbi->count--;	if (mfbi->count == 0) {		pr_debug("release plane index %d\n", mfbi->index);		res = fsl_diu_disable_panel(info);		if (res < 0)			mfbi->count++;	}	spin_unlock(&diu_lock);	return res;}static struct fb_ops fsl_diu_ops = {	.owner = THIS_MODULE,	.fb_check_var = fsl_diu_check_var,	.fb_set_par = fsl_diu_set_par,	.fb_setcolreg = fsl_diu_setcolreg,	.fb_blank = fsl_diu_blank,	.fb_pan_display = fsl_diu_pan_display,	.fb_fillrect = cfb_fillrect,	.fb_copyarea = cfb_copyarea,	.fb_imageblit = cfb_imageblit,	.fb_ioctl = fsl_diu_ioctl,	.fb_open = fsl_diu_open,	.fb_release = fsl_diu_release,};static int init_fbinfo(struct fb_info *info){	struct mfb_info *mfbi = info->par;	info->device = NULL;

⌨️ 快捷键说明

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