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

📄 s3c2410fb.c

📁 s3c2410的linux操作系统中LCD驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/interrupt.h>#include <linux/slab.h>#include <linux/fb.h>#include <linux/delay.h>#include <linux/pm.h>#include <linux/init.h>#include <asm/hardware.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/mach-types.h>#include <asm/uaccess.h>#include <video/fbcon.h>#include <video/fbcon-mfb.h>#include <video/fbcon-cfb4.h>#include <video/fbcon-cfb8.h>#include <video/fbcon-cfb16.h>#include "s3c2410fb.h"void (*s3c2410fb_blank_helper)(int blank);EXPORT_SYMBOL(s3c2410fb_blank_helper);/*  * CONFIG_FB_S3C2410_EMUL * * 伙己 炮饭皋平胶 ? : 96*320 俊鼓饭捞记.  * *  var.xres = 96 栏肺 窍绊, *  fix.line_length = 240*2 肺 茄促. *  app 啊 linux FB spec. 阑 霖荐茄促搁 巩力啊 绝阑 巴捞促. * *  var.xres_virtual 阑 炼沥窍绰 规过档 积阿秦 杭 荐 乐瘤父, spec. 苞绰 喊档肺 *  app. 啊 决没 度度秦具 且 挥父 酒聪扼, panning/wrapping 苞 部老 堪妨啊 *  乐栏骨肺 硅力茄促. */static struct s3c2410fb_rgb	rgb_8 = {	red:	{offset: 0, length: 4, },	green:	{offset: 0, length: 4, },	blue:	{offset: 0, length: 4, },	transp:	{offset: 0, length: 0, },};static struct s3c2410fb_rgb	def_rgb_16 = {    	red:	{offset: 11, length: 5, },	green:	{offset: 5,  length: 6, },	blue:	{offset: 0,  length: 5, },	transp:	{offset: 0,  length: 0, },};#if 0static struct s3c2410fb_rgb	xxx_tft_rgb_16 = {    	red:	{offset: 11,	length: 5, },	green:	{offset: 6,	length: 5, },	blue:	{offset: 1,	length: 5, },	transp:	{offset: 0,	length: 1, },};#elsestatic struct s3c2410fb_rgb	xxx_tft_rgb_16 = {    	red:	{offset: 11,	length: 5, },	green:	{offset: 5,	length: 6, },	blue:	{offset: 0,	length: 5, },	transp:	{offset: 0,	length: 0, },};#endif/*#ifdef CONFIG_S3C2410_SMDKstatic struct s3c2410fb_mach_info xxx_stn_info __initdata = {    	pixclock:	174757,		bpp:		16,#ifdef CONFIG_FB_S3C2410_EMUL	xres:		96,#else	xres:		240,#endif	yres:		320,	hsync_len   :  5,    vsync_len    :  1,	left_margin :  7,    upper_margin :  1,	right_margin:  3,    lower_margin :  3,	sync:		0,		cmap_static:	1,	reg : {		lcdcon1 : LCD1_BPP_16T | LCD1_PNR_TFT | LCD1_CLKVAL(7) ,		lcdcon2 : LCD2_VBPD(1) | LCD2_VFPD(2) | LCD2_VSPW(1),		lcdcon3 : LCD3_HBPD(6) | LCD3_HFPD(2),		lcdcon4 : LCD4_HSPW(4) | LCD4_MVAL(13),		lcdcon5 : LCD5_FRM565 | LCD5_INVVLINE | LCD5_INVVFRAME | LCD5_HWSWP | LCD5_PWREN,	},};#endif*///add by HHTECH#ifdef CONFIG_S3C2410_SMDKstatic struct s3c2410fb_mach_info xxx_stn_info __initdata = {    	pixclock:	174757,		bpp:		16,#ifdef CONFIG_FB_S3C2410_EMUL	xres:		96,#else	xres:		240,#endif	yres:		320,	hsync_len   :  5,    vsync_len    :  1,	left_margin :  7,    upper_margin :  1,	right_margin:  3,    lower_margin :  3,	sync:		0,		cmap_static:	1,	reg : {		lcdcon1 : LCD1_BPP_16T | LCD1_PNR_TFT | LCD1_CLKVAL(7) ,		lcdcon2 : LCD2_VBPD(4) | LCD2_VFPD(1) | LCD2_VSPW(1),		lcdcon3 : LCD3_HBPD(6) | LCD3_HFPD(30),		lcdcon4 : LCD4_HSPW(3) | LCD4_MVAL(13),		lcdcon5 : LCD5_FRM565 | LCD5_HWSWP | LCD5_PWREN,	},};#endifstatic inline u_intchan_to_field(u_int chan, struct fb_bitfield *bf){    chan &= 0xffff;    chan >>= 16 - bf->length;    return chan << bf->offset;}/* * Convert bits-per-pixel to a hardware palette PBS value. */static inline u_intpalette_pbs(struct fb_var_screeninfo *var){   int ret = 0;   switch (var->bits_per_pixel) {#ifdef FBCON_HAS_CFB4      case 4:  ret = 0 << 12; break;#endif#ifdef FBCON_HAS_CFB8      case 8:  ret = 1 << 12; break;#endif#ifdef FBCON_HAS_CFB16      case 16: ret = 2 << 12; break;#endif   }   return ret;}static struct s3c2410fb_mach_info * __inits3c2410fb_get_machine_info(struct s3c2410fb_info *fbi){    struct s3c2410fb_mach_info *inf = NULL;    inf = &xxx_stn_info;	fbi->reg = inf->reg;    fbi->rgb[RGB_16] = &xxx_tft_rgb_16;    return inf;}static inline struct fb_var_screeninfo *get_con_var(struct fb_info *info, int con){    struct s3c2410fb_info *fbi = (struct s3c2410fb_info *)info;    return (con == fbi->currcon || con == -1) ? &fbi->fb.var : &fb_display[con].var;}static inline struct fb_cmap *get_con_cmap(struct fb_info *info, int con){    struct s3c2410fb_info *fbi = (struct s3c2410fb_info *)info;    return (con == fbi->currcon || con == -1) ? &fbi->fb.cmap : &fb_display[con].cmap;}static inline struct display *get_con_display(struct fb_info *info, int con){    struct s3c2410fb_info *fbi = (struct s3c2410fb_info *)info;    return (con < 0) ? (fbi->fb.disp) : &(fb_display[con]);}static ints3c2410fb_validate_var(struct fb_var_screeninfo *var,			      struct s3c2410fb_info *fbi){    int ret = -EINVAL;    if (var->xres < MIN_XRES)		var->xres = MIN_XRES;    if (var->yres < MIN_YRES)		var->yres = MIN_YRES;    if (var->xres > fbi->max_xres)		var->xres = fbi->max_xres;    if (var->yres > fbi->max_yres)		var->yres = fbi->max_yres;    var->xres_virtual =	var->xres_virtual < var->xres ? var->xres : var->xres_virtual;    var->yres_virtual = 	var->yres_virtual < var->yres ? var->yres : var->yres_virtual;    switch(var->bits_per_pixel) {#ifdef FBCON_HAS_CFB4	case 4:		ret = 0; break;#endif#ifdef FBCON_HAS_CFB8	case 8:		ret = 0; break;#endif#ifdef FBCON_HAS_CFB16	case 16:	ret = 0; break;#endif	default:			break;    }    return ret;}static ints3c2410fb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,			u_int trans, struct fb_info *info){    struct s3c2410fb_info *fbi = (struct s3c2410fb_info *)info;    u_int val, ret = 1;    if (regno < fbi->palette_size) {#ifndef CONFIG_S3C2400_GAMEPARK	val = ((red >> 4) & 0xf00);	val |= ((green >> 8) & 0x0f0);	val |= ((blue >> 12) & 0x00f);#else	val = ((blue >> 16) & 0x001f);    val |= ((green >> 11) & 0x07e0);    val |= ((red >> 5) & 0x0f800);	val |= 1; /* intensity bit */#endif		if (regno == 0)	    val |= palette_pbs(&fbi->fb.var);	fbi->palette_cpu[regno] = val;	ret = 0;    }    return ret;}static ints3c2410fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,		    u_int trans, struct fb_info *info){    struct s3c2410fb_info *fbi = (struct s3c2410fb_info *)info;    struct display *disp = get_con_display(info, fbi->currcon);    u_int var;    int ret = 1;    if (disp->inverse) {	red 	= 0xffff - red;	green 	= 0xffff - green;	blue	= 0xffff - blue;    }    if (fbi->fb.var.grayscale) 	red = green = blue = (19595 * red + 38470 * green + 7471 * blue) >> 16;    switch (fbi->fb.disp->visual) {	case FB_VISUAL_TRUECOLOR:	    if (regno < 16) {		u16 *pal = fbi->fb.pseudo_palette;		var = chan_to_field(red, &fbi->fb.var.red);		var |= chan_to_field(green, &fbi->fb.var.green);		var |= chan_to_field(blue, &fbi->fb.var.blue);		pal[regno] = var;		ret = 0;	    }	    break;	case FB_VISUAL_STATIC_PSEUDOCOLOR:	case FB_VISUAL_PSEUDOCOLOR:	    ret = s3c2410fb_setpalettereg(regno, red, green, blue, trans, info);	    break;    }    return ret;}static int s3c2410fb_activate_var(struct fb_var_screeninfo *var, struct s3c2410fb_info *fbi){    struct s3c2410fb_lcd_reg new_regs;    u_int half_screen_size, yres;    u_long flags;    /*new_reg 啊 绢录绊 历录绊 */    unsigned long VideoPhysicalTemp = fbi->screen_dma;    save_flags_cli(flags);    new_regs.lcdcon1 = fbi->reg.lcdcon1 & ~LCD1_ENVID;    new_regs.lcdcon2 = (fbi->reg.lcdcon2 & ~LCD2_LINEVAL_MSK) 						| LCD2_LINEVAL(var->yres - 1);	/* TFT LCD only ! */    new_regs.lcdcon3 = (fbi->reg.lcdcon3 & ~LCD3_HOZVAL_MSK)						| LCD3_HOZVAL(var->xres - 1);    new_regs.lcdcon4 = fbi->reg.lcdcon4;    new_regs.lcdcon5 = fbi->reg.lcdcon5;    new_regs.lcdsaddr1 = 		LCDADDR_BANK(((unsigned long)VideoPhysicalTemp >> 22))		| LCDADDR_BASEU(((unsigned long)VideoPhysicalTemp >> 1));	/* 16bpp */    new_regs.lcdsaddr2 = LCDADDR_BASEL( 		((unsigned long)VideoPhysicalTemp + (var->xres * 2 * (var->yres/*-1*/)))		>> 1);    new_regs.lcdsaddr3 = LCDADDR_OFFSET(0) | (LCDADDR_PAGE(var->xres) /*>> 1*/);    yres = var->yres;    /* if ( dual 捞搁) */    //yres /= 2;    half_screen_size = var->bits_per_pixel;    half_screen_size = half_screen_size * var->xres * var->yres / 16;	fbi->reg.lcdcon1 = new_regs.lcdcon1;	fbi->reg.lcdcon2 = new_regs.lcdcon2;	fbi->reg.lcdcon3 = new_regs.lcdcon3;	fbi->reg.lcdcon4 = new_regs.lcdcon4;	fbi->reg.lcdcon5 = new_regs.lcdcon5;	fbi->reg.lcdsaddr1 = new_regs.lcdsaddr1;	fbi->reg.lcdsaddr2 = new_regs.lcdsaddr2;	fbi->reg.lcdsaddr3 = new_regs.lcdsaddr3;    LCDCON1 = fbi->reg.lcdcon1;    LCDCON2 = fbi->reg.lcdcon2;    LCDCON3 = fbi->reg.lcdcon3;    LCDCON4 = fbi->reg.lcdcon4;    LCDCON5 = fbi->reg.lcdcon5;    LCDADDR1 = fbi->reg.lcdsaddr1;    LCDADDR2 = fbi->reg.lcdsaddr2;    LCDADDR3 = fbi->reg.lcdsaddr3;#if defined(CONFIG_S3C2410_SMDK) && !defined(CONFIG_SMDK_AIJI)    LCDLPCSEL = 0x2;	#elif defined(CONFIG_S3C2410_SMDK) && defined(CONFIG_SMDK_AIJI)     LCDLPCSEL = 0x7;#endif//add by HHTECH    LCDLPCSEL = 0x2;//HHARM9-LCD-R4 must to add the following	LCDCON2 &= ~(0xff << 24); //vertical	LCDCON2 |=   0x00 << 24 ;	LCDCON3 &= ~(0x7f << 19); //horizontal	LCDCON3 |=   0x12 << 19 ;//HHARM9-LCD-R4..........    	    TPAL = 0;    LCDCON1 |= LCD1_ENVID;#if 0	{	printk("con1 = 0x%08lx\n", LCDCON1);	printk("con2 = 0x%08lx\n", LCDCON2);	printk("con3 = 0x%08lx\n", LCDCON3);	printk("con4 = 0x%08lx\n", LCDCON4);	printk("con5 = 0x%08lx\n", LCDCON5);	printk("addr1 = 0x%08lx\n", LCDADDR1);	printk("addr2 = 0x%08lx\n", LCDADDR2);	printk("addr3 = 0x%08lx\n", LCDADDR3);	}#endif    restore_flags(flags);    return 0;}static inline void s3c2410fb_set_truecolor(u_int is_true_color){    if (is_true_color) {    }    else {    }}    static voids3c2410fb_hw_set_var(struct fb_var_screeninfo *var, struct s3c2410fb_info *fbi){    u_long palette_mem_size;    fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;    palette_mem_size = fbi->palette_size * sizeof(u16);    fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);    fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;    fb_set_cmap(&fbi->fb.cmap, 1, s3c2410fb_setcolreg, &fbi->fb);    s3c2410fb_set_truecolor(var->bits_per_pixel >= 16);    s3c2410fb_activate_var(var, fbi);    fbi->palette_cpu[0] = (fbi->palette_cpu[0] &				0xcfff) | palette_pbs(var);}static ints3c2410fb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info){    struct s3c2410fb_info *fbi = (struct s3c2410fb_info *)info;    struct fb_var_screeninfo *dvar = get_con_var(&fbi->fb, con);    struct display *display = get_con_display(&fbi->fb, con);    int err, chgvar = 0, rgbidx;        err = s3c2410fb_validate_var(var, fbi);    if (err) 	return err;

⌨️ 快捷键说明

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