一、LCD驱动程序框架分析
app: open("/dev/fb0", ...) 主设备号:29, 次设备号:0
————————————————————————————————————————————————————
kernel:(核心文件/drivers/video/fbmem.c)
fb_open
int fbidx = iminor(inode);
struct fb_info *info;
info = registered_fb[fbidx]; //根据次设备号获得从底层注册的struct fb_info结构体中
file->private_data = info;
if (info->fbops->fb_open) { //调用底层struct fb_info结构体中的fb_open函数
res = info->fbops->fb_open(info,1);
if (res)
module_put(info->fbops->owner);
}
———————————————————————————————————————————————————
app: read()
_____________________________________________________________________________________
kernel:
fb_read
struct inode *inode = file->f_path.dentry->d_inode;
int fbidx = iminor(inode);
struct fb_info *info = registered_fb[fbidx];
if (info->fbops->fb_read)
return info->fbops->fb_read(info, buf, count, ppos);
src = (u32 __iomem *) (info->screen_base + p);
dst = buffer;
*dst++ = fb_readl(src++);
copy_to_user(buf, buffer, c)
怎么写LCD驱动程序?
1.分配一个fb_info结构体:framebuffer_alloc()
2.设置
3.注册:register_framebuffer
4.硬件相关的操作
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include struct lcd_regs { unsigned long lcdcon1; unsigned long lcdcon2; unsigned long lcdcon3; unsigned long lcdcon4; unsigned long lcdcon5; unsigned long lcdsaddr1; unsigned long lcdsaddr2; unsigned long lcdsaddr3; unsigned long redlut; unsigned long greenlut; unsigned long bluelut; unsigned long reserved[9]; unsigned long dithmode; unsigned long tpal; unsigned long lcdintpnd; unsigned long lcdsrcpnd; unsigned long lcdintmsk; unsigned long lpcsel; }; static struct fb_ops* s3c_lcdfb_ops = { .owner = THIS_MODULE, // .fb_setcplreg = atmel_lcdfb_setolreg, .fb_fillrect = cfb_fillrect, .fb_copyarea = cfb_copyarea, .fb_imageblit = cfb_imageblit, }; static struct fb_info* s3c_lcd; 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 volatile struct lcd_regs* lcd_regs; static u32 pseudo_palette[16]; //为了兼容,设置假的调色板 /* from pxafb.c */ static inline unsigned int chan_to_field(unsigned int chan, struct fb_bitfield *bf) { chan &= 0xffff; chan >>= 16 - bf->length; return chan << bf->offset; } static int s3c_lcdfb_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; /* 用red,green,blue三原色构造出val */ val = chan_to_field(red, &info->var.red); val |= chan_to_field(green, &info->var.green); val |= chan_to_field(blue, &info->var.blue); //((u32 *)(info->pseudo_palette))[regno] = val; pseudo_palette[regno] = val; return 0; } static int lcd_init(void) { /* 1. 分配一个fb_info结构体 */ s3c_lcd = framebuffer_alloc(0, NULL); /* 2. 设置 */ /* 2.1 设置固定的参数 */ strcpy(s3c_lcd->fix.id, "mylcd"); s3c_lcd->fix.smem_len = 320*240*32/8; /* MINI2440的LCD位宽是24,但是2440里会分配4字节即32位(浪费1字节) */ s3c_lcd->fix.type = FB_TYPE_PACKED_PIXELS; s3c_lcd->fix.visual = FB_VISUAL_TRUECOLOR; /* 真彩色 */ s3c_lcd->fix.line_length = 320 * 4; /* 1行的字节数 */ /* 2.2 设置可变的参数 */ s3c_lcd->var.xres = 320; s3c_lcd->var.yres = 240; s3c_lcd->var.xres_virtual = 320; s3c_lcd->var.yres_virtual = 240; s3c_lcd->var.bits_per_pixel = 32; /* 每个像素所占的位数 */ /* RGB: 565 */ s3c_lcd->var.red.offset = 16; s3c_lcd->var.red.length = 8; s3c_lcd->var.green.offset = 8; s3c_lcd->var.green.length = 8; s3c_lcd->var.blue.offset = 0; s3c_lcd->var.blue.length = 0; s3c_lcd->var.activate = FB_ACTIVATE_NOW; /* 2.3 设置操作函数 */ s3c_lcd->fops = &s3c_lcdfb_ops; /* 2.4 其他设置 */ //s3c_lcd->pseudo_palette =; // //s3c_lcd->screen_base = ; /* 显存的虚拟地址 */ s3c_lcd->screen_size = 320*240*32/8; /* 3. 硬件相关的操作 */ /* 3.1 配置GPIO用于LCD */ gpbcon = ioremap(0x56000010, 8); gpbdat = gpbcon+1; gpccon = ioremap(0x56000020, 4); gpdcon = ioremap(0x56000030, 4); gpgcon = ioremap(0x56000060, 4); *gpccon = 0xaaaaaaaa; /* GPIO管脚用于VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND */ *gpdcon = 0xaaaaaaaa; /* GPIO管脚用于VD[23:8] */ // *gpbcon &= ~(3); /* GPB0设置为输出引脚 */ // *gpbcon |= 1; // *gpbdat &= ~1; /* 输出低电平 */ *gpgcon |= (3<<8); /* GPG4用作LCD_PWREN */ /* 3.2 根据LCD手册设置LCD控制器,比如VCLK的频率等 */ lcd_regs = ioremap(0x4D000000, sizeof(struct lcd_regs)); /* * MINI2440 LCD 3.5英寸 ZQ3506_V0 SPEC.pdf 第11、12页 * * LCD手册11,12页和2440手册"Figure 15-6. TFT LCD Timing Example"一对比就知道参数含义了 */ /* bit[17:8]: VCLK = HCLK / [(CLKVAL+1) x 2], LCD手册11 (Dclk=6.4MHz~11MHz) * 7.1MHz = 100MHz / [(CLKVAL+1) x 2] * CLKVAL = 6 * bit[6:5]: 0b11, TFT LCD * bit[4:1]: 0b1101, 24 bpp for TFT * bit[0] : 0 = Disable the video output and the LCD control signal. */ lcd_regs->lcdcon1 = (6<<8) | (3<<5) | (0x0d<<1); /* 垂直方向的时间参数 * 根据数据手册 * bit[31:24]: VBPD, VSYNC之后再过多长时间才能发出第1行数据
上一篇:s3c2440的LCD驱动程序
下一篇:基于arm的LM3S811微控制器与TH12864显示模块的技术应用
推荐阅读最新更新时间:2024-10-31 12:07
设计资源 培训 开发板 精华推荐
- ADK-1590、HI-1590 1553B 双路收发器,带 SPI 幅度控制评估板
- DLDZ
- 使用2x SD2932的650 W / 88-108 MHz参考设计
- 一个SFP转TTL转接板(猫棒刷机板)
- 使用 Microchip Technology 的 MIC2843A 的参考设计
- FRDM-PWRSTG: Freedom Accessory Boards for FRDM-GD3000EVB
- 使用具有 B 类 EMI 滤波(双输出)的 RP10-243.3SA DC/DC 转换器的典型应用
- SG117 1.5A 三端可调稳压器基本稳压电路典型应用
- LTC3890MPUH 高效 12V/25A 双相降压转换器的典型应用电路
- MQ-2传感器采集电路