注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

小白的博客

嵌入式爱好者

 
 
 

日志

 
 

LCD驱动程序  

2012-09-16 18:00:36|  分类: 韦东山视频第二轮 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/device.h>
#include <linux/fb.h>
#include <linux/gpio.h>
#include <linux/dma-mapping.h>
#include <linux/types.h>

#include <asm/uaccess.h>
#include <asm/io.h>

#include <mach/regs-gpio.h>

#define LCDWIDTHPIXEL    240
#define LCDLENGTHPIXEL   320
#define LCDPIXEL         16
#define LCDWIDTH         LCDWIDTHPIXEL*LCDPIXEL/8;
#define LCDLENGTH        LCDLENGTHPIXEL*LCDPIXEL/8;
#define LCDSIZE          LCDWIDTHPIXEL*LCDLENGTHPIXEL*LCDPIXEL/8;

static struct s3c_lcd_reg {
volatile unsigned long lcdcon1;
volatile unsigned long lcdcon2;
volatile unsigned long lcdcon3;
volatile unsigned long lcdcon4;
volatile unsigned long lcdcon5;
volatile unsigned long lcdsaddr1;
volatile unsigned long lcdsaddr2;
volatile unsigned long lcdsaddr3;
volatile unsigned long redlut;
volatile unsigned long greenlut;
volatile unsigned long bluelut;
volatile unsigned long reserve[9];
volatile unsigned long dithmode;
volatile unsigned long tpal;
volatile unsigned long lcdinpnd;
volatile unsigned long lcdsrcpnd;
volatile unsigned long lcdintmsk;
volatile unsigned long tconsel;
};

static volatile unsigned long *gpbcon;
static volatile unsigned long *gpbdat;
static volatile unsigned long *gpccon;
static volatile unsigned long *gpdcon;
static volatile unsigned long *gpgcon;

static struct fb_info *lcd_info;
static int pseudo_palette[16];
static struct s3c_lcd_reg *s3c_lcd_regs;

static unsigned int change(unsigned int color , struct fb_bitfield *colors)
{
color &= 0xffff;
color >>= (16-colors->length);
color <<= colors->offset;
return color;
}

static int lcd_setcolreg(unsigned int regno, unsigned int red, unsigned int green, unsigned int blue, 
                       unsigned int transp, struct fb_info *info)
{
unsigned int val;
if (regno > 16)
return 1;
val  = change(red , &info->var.red);
val |= change(red , &info->var.red);
val |= change(red , &info->var.red);
pseudo_palette[regno] = val;

return 0;
}

static struct fb_ops lcd_fbops = {
.owner = THIS_MODULE,
.fb_setcolreg =lcd_setcolreg,
.fb_fillrect = cfb_fillrect,
.fb_copyarea = cfb_copyarea,
.fb_imageblit = cfb_imageblit,
};

static int lcd_init(void)
{
lcd_info = framebuffer_alloc(0 , NULL);
//设置可变参数
lcd_info->var.xres = 240;
lcd_info->var.yres = 320;
lcd_info->var.xres_virtual = 240;
lcd_info->var.yres_virtual = 320;
lcd_info->var.bits_per_pixel = 16;
//RGB:565
lcd_info->var.red.offset = 11;
lcd_info->var.red.length = 5;
lcd_info->var.green.offset = 5;
lcd_info->var.green.length = 6;
lcd_info->var.blue.offset = 0;
lcd_info->var.blue.length = 5;
lcd_info->var.activate = FB_ACTIVATE_VBL;

//设置固定参数
strcpy(lcd_info->fix.id,"mylcd");
lcd_info->fix.smem_len = LCDSIZE;
lcd_info->fix.type = FB_TYPE_PACKED_PIXELS;
lcd_info->fix.visual = FB_VISUAL_TRUECOLOR;
lcd_info->fix.line_length = LCDWIDTH;

//其他设置
lcd_info->fbops = &lcd_fbops;
lcd_info->screen_base = dma_alloc_coherent(NULL, lcd_info->fix.smem_len , &lcd_info->fix.smem_start ,GFP_KERNEL);
lcd_info->screen_size = LCDSIZE;
lcd_info->pseudo_palette = pseudo_palette;
register_framebuffer(lcd_info);
//设置cpu引脚
gpbcon = (volatile unsigned long *)ioremap(0x56000010 ,8);
gpbdat = gpbcon + 1;
*gpbcon &= ~(3);
*gpbcon |= 1;
*gpbdat &= ~1;

gpccon = (volatile unsigned long *)ioremap(0x56000020 ,4);
*gpccon = 0xaaaaaaaa;

gpdcon = (volatile unsigned long *)ioremap(0x56000030 ,4);
*gpdcon = 0xaaaaaaaa;

gpgcon = (volatile unsigned long *)ioremap(0x56000060 ,4);
*gpgcon |= 3<<4*2;
//设置lcd控制寄存器
s3c_lcd_regs = ioremap(0x4D000000 , sizeof(struct s3c_lcd_reg));
s3c_lcd_regs->lcdcon1 = (4<<8)|(3<<5)|(12<<1);
s3c_lcd_regs->lcdcon2 = (3<<24)|(319<<14)|(1<<6);
s3c_lcd_regs->lcdcon3 = (16<<19)|(239<<8)|(10<<0);
s3c_lcd_regs->lcdcon4 = 4;
s3c_lcd_regs->lcdcon5 = (1<<11)|(1<<9)|(1<<8)|(1<<0);
s3c_lcd_regs->lcdsaddr1 = (lcd_info->fix.smem_start>>1)&0x3fffffff;
s3c_lcd_regs->lcdsaddr2 = ((lcd_info->fix.smem_start+lcd_info->fix.smem_len)>>1)&0x1fffff;
s3c_lcd_regs->lcdsaddr3 = 240;
s3c_lcd_regs->lcdcon1 |= 1;
s3c_lcd_regs->lcdcon5 |= (1<<3);
*gpbdat |= 1;

return 0;
}

static void lcd_exit(void)
{
unregister_framebuffer(lcd_info);
dma_free_writecombine(NULL , lcd_info->fix.smem_len , lcd_info->screen_base, lcd_info->fix.smem_start);
iounmap(s3c_lcd_regs);
iounmap(gpbcon);
iounmap(gpccon);
iounmap(gpdcon);
iounmap(gpgcon);
framebuffer_release(lcd_info);
}

module_init(lcd_init);
module_exit(lcd_exit);
MODULE_LICENSE("GPL");
  评论这张
 
阅读(1218)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017