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

📄 bf54x-lq043fb.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		return 0;	else		return -EINVAL;	/* just to force soft_cursor() call */}static int bfin_bf54x_fb_setcolreg(u_int regno, u_int red, u_int green,				   u_int blue, u_int transp,				   struct fb_info *info){	if (regno >= BFIN_LCD_NBR_PALETTE_ENTRIES)		return -EINVAL;	if (info->var.grayscale) {		/* grayscale = 0.30*R + 0.59*G + 0.11*B */		red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;	}	if (info->fix.visual == FB_VISUAL_TRUECOLOR) {		u32 value;		/* Place color in the pseudopalette */		if (regno > 16)			return -EINVAL;		red >>= (16 - info->var.red.length);		green >>= (16 - info->var.green.length);		blue >>= (16 - info->var.blue.length);		value = (red << info->var.red.offset) |		    (green << info->var.green.offset) |		    (blue << info->var.blue.offset);		value &= 0xFFFFFF;		((u32 *) (info->pseudo_palette))[regno] = value;	}	return 0;}static struct fb_ops bfin_bf54x_fb_ops = {	.owner = THIS_MODULE,	.fb_open = bfin_bf54x_fb_open,	.fb_release = bfin_bf54x_fb_release,	.fb_check_var = bfin_bf54x_fb_check_var,	.fb_fillrect = cfb_fillrect,	.fb_copyarea = cfb_copyarea,	.fb_imageblit = cfb_imageblit,	.fb_mmap = bfin_bf54x_fb_mmap,	.fb_cursor = bfin_bf54x_fb_cursor,	.fb_setcolreg = bfin_bf54x_fb_setcolreg,};#ifndef NO_BL_SUPPORTstatic int bl_get_brightness(struct backlight_device *bd){	return 0;}static struct backlight_ops bfin_lq043fb_bl_ops = {	.get_brightness = bl_get_brightness,};static struct backlight_device *bl_dev;static int bfin_lcd_get_power(struct lcd_device *dev){	return 0;}static int bfin_lcd_set_power(struct lcd_device *dev, int power){	return 0;}static int bfin_lcd_get_contrast(struct lcd_device *dev){	return 0;}static int bfin_lcd_set_contrast(struct lcd_device *dev, int contrast){	return 0;}static int bfin_lcd_check_fb(struct fb_info *fi){	if (!fi || (fi == &bfin_bf54x_fb))		return 1;	return 0;}static struct lcd_ops bfin_lcd_ops = {	.get_power = bfin_lcd_get_power,	.set_power = bfin_lcd_set_power,	.get_contrast = bfin_lcd_get_contrast,	.set_contrast = bfin_lcd_set_contrast,	.check_fb = bfin_lcd_check_fb,};static struct lcd_device *lcd_dev;#endifstatic irqreturn_t bfin_bf54x_irq_error(int irq, void *dev_id){	/*struct bfin_bf54xfb_info *info = (struct bfin_bf54xfb_info *)dev_id;*/	u16 status = bfin_read_EPPI0_STATUS();	bfin_write_EPPI0_STATUS(0xFFFF);	if (status) {		bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN);		disable_dma(CH_EPPI0);		/* start dma */		enable_dma(CH_EPPI0);		bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);		bfin_write_EPPI0_STATUS(0xFFFF);	}	return IRQ_HANDLED;}static int __init bfin_bf54x_probe(struct platform_device *pdev){	struct bfin_bf54xfb_info *info;	struct fb_info *fbinfo;	int ret;	printk(KERN_INFO DRIVER_NAME ": FrameBuffer initializing...\n");	if (request_dma(CH_EPPI0, "CH_EPPI0") < 0) {		printk(KERN_ERR DRIVER_NAME		       ": couldn't request CH_EPPI0 DMA\n");		ret = -EFAULT;		goto out1;	}	fbinfo =	    framebuffer_alloc(sizeof(struct bfin_bf54xfb_info), &pdev->dev);	if (!fbinfo) {		ret = -ENOMEM;		goto out2;	}	info = fbinfo->par;	info->fb = fbinfo;	info->dev = &pdev->dev;	platform_set_drvdata(pdev, fbinfo);	strcpy(fbinfo->fix.id, driver_name);	info->mach_info = pdev->dev.platform_data;	if (info->mach_info == NULL) {		dev_err(&pdev->dev,			"no platform data for lcd, cannot attach\n");		ret = -EINVAL;		goto out3;	}	fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;	fbinfo->fix.type_aux = 0;	fbinfo->fix.xpanstep = 0;	fbinfo->fix.ypanstep = 0;	fbinfo->fix.ywrapstep = 0;	fbinfo->fix.accel = FB_ACCEL_NONE;	fbinfo->fix.visual = FB_VISUAL_TRUECOLOR;	fbinfo->var.nonstd = 0;	fbinfo->var.activate = FB_ACTIVATE_NOW;	fbinfo->var.height = info->mach_info->height;	fbinfo->var.width = info->mach_info->width;	fbinfo->var.accel_flags = 0;	fbinfo->var.vmode = FB_VMODE_NONINTERLACED;	fbinfo->fbops = &bfin_bf54x_fb_ops;	fbinfo->flags = FBINFO_FLAG_DEFAULT;	fbinfo->var.xres = info->mach_info->xres.defval;	fbinfo->var.xres_virtual = info->mach_info->xres.defval;	fbinfo->var.yres = info->mach_info->yres.defval;	fbinfo->var.yres_virtual = info->mach_info->yres.defval;	fbinfo->var.bits_per_pixel = info->mach_info->bpp.defval;	fbinfo->var.upper_margin = 0;	fbinfo->var.lower_margin = 0;	fbinfo->var.vsync_len = 0;	fbinfo->var.left_margin = 0;	fbinfo->var.right_margin = 0;	fbinfo->var.hsync_len = 0;	fbinfo->var.red.offset = 16;	fbinfo->var.green.offset = 8;	fbinfo->var.blue.offset = 0;	fbinfo->var.transp.offset = 0;	fbinfo->var.red.length = 8;	fbinfo->var.green.length = 8;	fbinfo->var.blue.length = 8;	fbinfo->var.transp.length = 0;	fbinfo->fix.smem_len = info->mach_info->xres.max *	    info->mach_info->yres.max * info->mach_info->bpp.max / 8;	fbinfo->fix.line_length = fbinfo->var.xres_virtual *	    fbinfo->var.bits_per_pixel / 8;	info->fb_buffer =	    dma_alloc_coherent(NULL, fbinfo->fix.smem_len, &info->dma_handle,			       GFP_KERNEL);	if (NULL == info->fb_buffer) {		printk(KERN_ERR DRIVER_NAME		       ": couldn't allocate dma buffer.\n");		ret = -ENOMEM;		goto out3;	}	memset(info->fb_buffer, 0, fbinfo->fix.smem_len);	fbinfo->screen_base = (void *)info->fb_buffer;	fbinfo->fix.smem_start = (int)info->fb_buffer;	fbinfo->fbops = &bfin_bf54x_fb_ops;	fbinfo->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);	if (!fbinfo->pseudo_palette) {		printk(KERN_ERR DRIVER_NAME		       "Fail to allocate pseudo_palette\n");		ret = -ENOMEM;		goto out4;	}	memset(fbinfo->pseudo_palette, 0, sizeof(u32) * 16);	if (fb_alloc_cmap(&fbinfo->cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0)	    < 0) {		printk(KERN_ERR DRIVER_NAME		       "Fail to allocate colormap (%d entries)\n",		       BFIN_LCD_NBR_PALETTE_ENTRIES);		ret = -EFAULT;		goto out5;	}	if (request_ports(info)) {		printk(KERN_ERR DRIVER_NAME ": couldn't request gpio port.\n");		ret = -EFAULT;		goto out6;	}	info->irq = platform_get_irq(pdev, 0);	if (info->irq < 0) {		ret = -EINVAL;		goto out7;	}	if (request_irq(info->irq, (void *)bfin_bf54x_irq_error, IRQF_DISABLED,			"PPI ERROR", info) < 0) {		printk(KERN_ERR DRIVER_NAME		       ": unable to request PPI ERROR IRQ\n");		ret = -EFAULT;		goto out7;	}	if (register_framebuffer(fbinfo) < 0) {		printk(KERN_ERR DRIVER_NAME		       ": unable to register framebuffer.\n");		ret = -EINVAL;		goto out8;	}#ifndef NO_BL_SUPPORT	bl_dev =	    backlight_device_register("bf54x-bl", NULL, NULL,				      &bfin_lq043fb_bl_ops);	bl_dev->props.max_brightness = 255;	lcd_dev = lcd_device_register(DRIVER_NAME, NULL, &bfin_lcd_ops);	lcd_dev->props.max_contrast = 255, printk(KERN_INFO "Done.\n");#endif	return 0;out8:	free_irq(info->irq, info);out7:	free_ports(info);out6:	fb_dealloc_cmap(&fbinfo->cmap);out5:	kfree(fbinfo->pseudo_palette);out4:	dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,			  info->dma_handle);out3:	framebuffer_release(fbinfo);out2:	free_dma(CH_EPPI0);out1:	platform_set_drvdata(pdev, NULL);	return ret;}static int bfin_bf54x_remove(struct platform_device *pdev){	struct fb_info *fbinfo = platform_get_drvdata(pdev);	struct bfin_bf54xfb_info *info = fbinfo->par;	free_dma(CH_EPPI0);	free_irq(info->irq, info);	if (info->fb_buffer != NULL)		dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,				  info->dma_handle);	kfree(fbinfo->pseudo_palette);	fb_dealloc_cmap(&fbinfo->cmap);#ifndef NO_BL_SUPPORT	lcd_device_unregister(lcd_dev);	backlight_device_unregister(bl_dev);#endif	unregister_framebuffer(fbinfo);	free_ports(info);	printk(KERN_INFO DRIVER_NAME ": Unregister LCD driver.\n");	return 0;}#ifdef CONFIG_PMstatic int bfin_bf54x_suspend(struct platform_device *pdev, pm_message_t state){	struct fb_info *fbinfo = platform_get_drvdata(pdev);	struct bfin_bf54xfb_info *info = fbinfo->par;	bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN);	disable_dma(CH_EPPI0);	bfin_write_EPPI0_STATUS(0xFFFF);	return 0;}static int bfin_bf54x_resume(struct platform_device *pdev){	struct fb_info *fbinfo = platform_get_drvdata(pdev);	struct bfin_bf54xfb_info *info = fbinfo->par;	enable_dma(CH_EPPI0);	bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);	return 0;}#else#define bfin_bf54x_suspend	NULL#define bfin_bf54x_resume	NULL#endifstatic struct platform_driver bfin_bf54x_driver = {	.probe = bfin_bf54x_probe,	.remove = bfin_bf54x_remove,	.suspend = bfin_bf54x_suspend,	.resume = bfin_bf54x_resume,	.driver = {		   .name = DRIVER_NAME,		   .owner = THIS_MODULE,		   },};static int __devinit bfin_bf54x_driver_init(void){	return platform_driver_register(&bfin_bf54x_driver);}static void __exit bfin_bf54x_driver_cleanup(void){	platform_driver_unregister(&bfin_bf54x_driver);}MODULE_DESCRIPTION("Blackfin BF54x TFT LCD Driver");MODULE_LICENSE("GPL");module_init(bfin_bf54x_driver_init);module_exit(bfin_bf54x_driver_cleanup);

⌨️ 快捷键说明

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