Smart210学习-----lcd驱动

帧缓冲设备

1.1帧缓冲设备:
帧缓冲(framebuffer)是 Linux 系统为显示设备提供的一个接口,它将显示缓冲区抽象,屏蔽图像硬件的底层差异,允许上层应用程序在图形模式下直接对显示缓冲区进行读写操作。用户不必关心物理显示缓冲区的具体位置及存放方式,这些都由帧缓冲设备驱动本身来完成。对于帧缓冲设备而言,只要在显示缓冲区中与显示点对应的区域写入颜色值,对应的颜色会自动在屏幕上显示。

1.2 Linux帧缓冲相关数据结构与函数
   fb_info结构体
     帧缓冲设备最关键的一个数据结构体是fb_info结构体(为了便于记忆,我们把它简称为“FBI”),
  FBI中包括了关于帧缓冲设备属性和操作的完整描述。

FBI 中记录了帧缓冲设备的全部信息,包括设备的设置参数、状态以及操作函数指针。每一个帧缓冲设备都必须对应一个 FBI。

1  struct fb_info {  
2     int node;  
3     int flags;  
4     struct mutex lock;              /* 用于 open/release/ioctl 的锁 */   
5     struct fb_var_screeninfo var; /*可变参数 */  
6     struct fb_fix_screeninfo fix; /*固定参数 */  
7     struct fb_monspecs monspecs; /*显示器标准 */  
8     struct work_struct queue; /* 帧缓冲事件队列 */  
9     struct fb_pixmap pixmap; /* 图像硬件 mapper */  
10    struct fb_pixmap sprite; /* 光标硬件 mapper */  
11    struct fb_cmap cmap; /* 目前的颜色表*/  
12    struct list_head modelist;   
13    struct fb_videomode *mode; /* 目前的 video 模式 */  
14   
15    #ifdef CONFIG_FB_BACKLIGHT  
16       /* 对应的背光设备 */  
17       struct backlight_device *bl_dev;  
18       /* 背光调整 */  
19       struct mutex bl_mutex;  
20       u8 bl_curve[FB_BACKLIGHT_LEVELS];  
21     #endif  
22     #ifdef CONFIG_FB_DEFERRED_IO  
23         struct delayed_work deferred_work;  
24         struct fb_deferred_io *fbdefio;  
25     #endif  
26     struct fb_ops *fbops; /* fb_ops,帧缓冲操作 */  
27     struct device *device; /* 父设备 */  
28     struct device *dev;             /* fb 设备 */  
29     int class_flag; /* 私有 sysfs 标志 */  
30     #ifdef CONFIG_FB_TILEBLITTING  
31         struct fb_tile_ops *tileops; /* 图块 Blitting */  
32     #endif  
33     char _ _iomem *screen_base; /* 虚拟基地址 */  
34     unsigned long screen_size; /* ioremapped 的虚拟内存大小 */  
35     void *pseudo_palette; /* 伪 16 色颜色表 */  
36     #define FBINFO_STATE_RUNNING 0  
37     #define FBINFO_STATE_SUSPENDED         1  
38     u32 state; /* 硬件状态,如挂起 */  
39     void *fbcon_par;  
40     void *par;  
41 };  
fb_info结构体


  fb_ops 结构体
 FBI 的成员变量 fbops 为指向底层操作的函数的指针,这些函数是需要驱动程序开发人员编
写的。

1  struct fb_ops {  
2      struct module *owner;  
3       /* 打开/释放 */  
4      int(*fb_open)(struct fb_info *info, int user);  
5      int(*fb_release)(struct fb_info *info, int user);  
6    
7      /* 对于非线性布局的/常规内存映射无法工作的帧缓冲设备需要 */  
8      ssize_t(*fb_read)(struct file *file, char _ _user *buf, size_t count,  
9         loff_t*ppos);  
10     ssize_t(*fb_write)(struct file *file, const char _ _user *buf, size_t count,  
11        loff_t *ppos);  
12   
13     /* 检测可变参数,并调整到支持的值*/  
14     int(*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);  
15   
16    /* 根据 info->var 设置 video 模式 */  
17    int(*fb_set_par)(struct fb_info *info);  
18   
19    /* 设置 color 寄存器 */  
20    int(*fb_setcolreg)(unsigned regno, unsigned red, unsigned green, unsigned  
21        blue, unsigned transp, struct fb_info *info);  
22   
23     /* 批量设置 color 寄存器,设置颜色表 */  
24     int(*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);  
25   
26     /*显示空白 */  
27     int(*fb_blank)(int blank, struct fb_info *info);  
28   
29     /* pan 显示 */  
30     int(*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);  
31   
32     /* 矩形填充 */  
33     void(*fb_fillrect)(struct fb_info *info, const struct fb_fillrect *rect);  
34     /* 数据复制 */  
35     void(*fb_copyarea)(struct fb_info *info, const struct fb_copyarea *region);  
36     /* 图形填充 */  
37     void(*fb_imageblit)(struct fb_info *info, const struct fb_image *image);  
38   
39     /* 绘制光标 */  
40     int(*fb_cursor)(struct fb_info *info, struct fb_cursor *cursor);  
41   
42     /* 旋转显示 */  
43     void(*fb_rotate)(struct fb_info *info, int angle);  
44   
45     /* 等待 blit 空闲 (可选) */  
46     int(*fb_sync)(struct fb_info *info);  
47   
48     /* fb 特定的 ioctl (可选) */  
49   int(*fb_ioctl)(struct fb_info *info, unsigned int cmd, unsigned long arg);  
50   
51   /* 处理 32 位的 compat ioctl (可选) */  
52   int(*fb_compat_ioctl)(struct fb_info *info, unsigned cmd, unsigned long arg);  
53   
54   /* fb 特定的 mmap */  
55   int(*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);  
56   
57   /* 保存目前的硬件状态 */  
58   void(*fb_save_state)(struct fb_info *info);  
59   
60   /* 恢复被保存的硬件状态 */  
61   void(*fb_restore_state)(struct fb_info *info);  
62  
63   void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps,  
64            struct fb_var_screeninfo *var);  
65 };    
fb_ops 结构体

  

 fb_var_screeninfo 和 fb_fix_screeninfo 结构体


    FBI 的 fb_var_screeninfo 和 fb_fix_screeninfo 成员也是结构体,fb_var_screeninfo 记录用户可修改的显示控制器参数,包括屏幕分辨率和每个像素点的比特数。fb_var_screeninfo 中的 xres 定义屏幕一行有多少个点,yres 定义屏幕一列有多少个点,bits_per_pixel 定义每个点用多少个字节表示。而 fb_fix_screeninfo 中记录用户不能修改的显示控制器的参数,如屏幕缓冲区的物理地址、长度。当对帧缓冲设备进行映射操作的时候,就是从 fb_fix_screeninfo 中取得缓冲区物理地址的。上述数据成员都需要在驱动程序中初始化和设置。

1  struct fb_var_screeninfo {  
2     /* 可见解析度 */  
3     u32 xres;  
4     u32 yres;  
5     /* 虚拟解析度  */  
6     u32 xres_virtual;  
7     u32 yres_virtual;  
8     /* 虚拟到可见之间的偏移 */  
9     u32 xoffset;  
10    u32 yoffset;  
11   
12    u32 bits_per_pixel; /* 每像素位数,BPP */  
13    u32 grayscale; /非 0 时指灰度 */  
14   
15    /* fb 缓存的 RGB 位域 */  
16    struct fb_bitfield red;  
17    struct fb_bitfield green;  
18    struct fb_bitfield blue;  
19    struct fb_bitfield transp; /* 透明度 */  
20   
21    u32 nonstd; /* != 0 非标准像素格式 */  
22   
23    u32 activate;  
24   
25    u32 height; /*高度 */  
26    u32 width; /*宽度 */  
27   
28    u32 accel_flags; /* 看 fb_info.flags */  
29   
30    /* 定时: 除了 pixclock 本身外,其他的都以像素时钟为单位 */  
31    u32 pixclock; /* 像素时钟(皮秒) */  
32    u32 left_margin; /* 行切换:从同步到绘图之间的延迟    */  
33    u32 right_margin; /* 行切换:从绘图到同步之间的延迟   */  
34    u32 upper_margin; /* 帧切换:从同步到绘图之间的延迟  */  
35    u32 lower_margin; /* 帧切换:从绘图到同步之间的延迟  */  
36    u32 hsync_len; /* 水平同步的长度     */  
37    u32 vsync_len; /* 垂直同步的长度     */  
38    u32 sync;  
39    u32 vmode;  
40    u32 rotate; /* 顺时钟旋转的角度 */  
41    u32 reserved[5]; /* 保留 */  
42 };  
fb_var_screeninfo 结构体 
1  struct fb_fix_screeninfo {  
2      char id[16]; /* 字符串形式的标识符 */  
3      unsigned long smem_start; /* fb 缓冲内存的开始位置(物理地址) */  
4      u32 smem_len; /* fb 缓冲的长度 */  
5      u32 type; /* FB_TYPE_*        */  
6      u32 type_aux; /* Interleave */  
7      u32 visual; /* FB_VISUAL_*  */  
8      u16 xpanstep; /* 如果没有硬件 panning ,赋 0 */  
9      u16 ypanstep;   
10     u16 ywrapstep;/  
11     u32 line_length; /* 1 行的字节数 */  
12     unsigned long mmio_start; /* 内存映射 I/O 的开始位置 */  
13     u32 mmio_len; /* 内存映射 I/O 的长度  */  
14     u32 accel;  
15     u16 reserved[3]; /* 保留*/  
16 };  
fb_fix_screeninfo 结构体

文件操作结构体 
      作为一种字符设备,帧缓冲设备的文件操作结构体定义于/linux/drivers/vedio/fbmem.c文件中。
 代码清单 帧缓冲设备文件操作结构体

1  static struct file_operations fb_fops = {  
2      .owner = THIS_MODULE,  
3      .read = fb_read,  
4      .write = fb_write,  
5      .ioctl = fb_ioctl,  
6      #ifdef CONFIG_COMPAT  
7         .compat_ioctl = fb_compat_ioctl,  
8      #endif  
9      .mmap = fb_mmap,  
10     .open = fb_open,  
11     .release = fb_release,  
12     #ifdef HAVE_ARCH_FB_UNMAPPED_AREA  
13        .get_unmapped_area = get_fb_unmapped_area,  
14     #endif  
15     #ifdef CONFIG_FB_DEFERRED_IO  
16        .fsync =        fb_deferred_io_fsync,  
17     #endif  
18 };
文件操作结构体

帧缓冲设备驱动的文件操作接口函数已经在 fbmem.c 中被统一实现,一般不需要由驱动工程师再编写。

 注册与注销帧缓冲设备
    Linux 内核提供了 register_framebuffer()和 unregister_framebuffer()函数分别注册和注销帧缓冲设备,这两个函数都接受 FBI 指针为参数,原型为:
int register_framebuffer(struct fb_info *fb_info); 
int unregister_framebuffer(struct fb_info *fb_info); 
对于 register_framebuffer()函数而言,如果注册的帧缓冲设备数超过了 FB_MAX(目前定义为32),则函数返回-ENXIO,注册成功则返回 0。

在帧缓冲设备驱动的模块加载函数中,应该完成如下 4 个工作。
(1)申请 FBI 结构体的内存空间(framebuffer_alloc),初始化 FBI 结构体中固定和可变的屏幕参数,即填充 FBI
中 fb_var_screeninfo var 和 struct fb_fix_screeninfo fix 成员。
(2)根据具体 LCD 屏幕的特点,完成 LCD 控制器硬件的初始化。
(3)申请帧缓冲设备的显示缓冲区空间(dma_alloc_writecombine)。
(4)注册帧缓冲设备。

     在帧缓冲设备驱动的模块卸载函数中,应该完成相反的工作,包括释放 FBI 结构体内存、关闭 LCD、释放显示缓冲区以及注销帧缓冲设备。
     由于LCD控制器经常被集成在SoC上作为一个独立的硬件模块而存在(成为platform_device),因此,LCD 驱动中也经常包含平台驱动,这样,在帧缓冲设备驱动的模块加载函数中完成的工作只是注册平台驱动,而初始化FBI结构体中的固定和可变参数、LCD 控制器硬件的初始化、申请帧缓冲设备的显示缓冲区空间和注册帧缓冲设备的工作则移交到平台驱动的探测函数中完成。 同样地,在使用平台驱动的情况下,释放 FBI 结构体内存、关闭 LCD、释放显示缓冲区以及注销帧缓冲设备的工作也移交到平台驱动的移除函数中完成。

帧缓冲设备驱动的模块加载/卸载及平台驱动的探测/移除函数的模板 :

1  /* 平台驱动结构体 */  
2  static struct platform_driver xxxfb_driver = {  
3     .probe = xxxfb_probe,  
4     .remove = xxxfb_remove,  
5     .suspend = xxxfb_suspend,  
6     .resume = xxxfb_resume,  
7     .driver = {  
8         .name = "xxx-lcd",  /* 驱动名 */  
9         .owner = THIS_MODULE,  
10    }   
11 };  
12   
13 /* 平台驱动探测函数 */  
14 static int _ _init xxxfb_probe(...)  
15 {  
16     struct fb_info *info;  
17   
18     /*分配 fb_info 结构体*/  
19     info = framebuffer_alloc(...);  
20   
21     info->screen_base = framebuffer_virtual_memory;  
22     info->var = xxxfb_var;  /* 可变参数 */  
23     info->fix = xxxfb_fix;  /* 固定参数 */  
24   
25     /*分配显示缓冲区*/  
26     alloc_dis_buffer(...);  
27   
28     /*初始化 LCD 控制器*/  
29     lcd_init(...);  
30   
31     /*检查可变参数*/  
32     xxxfb_check_var(&info->var, info);  
33   
34     /*注册 fb_info*/  
35     if (register_framebuffer(info) < 0)  
36         return  - EINVAL;  
37   
38     return 0;  
39 }  
40   
41 /* 平台驱动移除函数 */  
42 static void _ _exit xxxfb_remove(...)  
43 {  
44     struct fb_info *info = dev_get_drv_data(dev);  
45   
46     if (info) {  
47          unregister_framebuffer(info); /* 注销 fb_info */  
48          dealloc_dis_buffer(...); /* 释放显示缓冲区 */  
49          framebuffer_release(info); /* 注销 fb_info */  
50     }  
51   
52     return 0;  
53 }  
54   
55 /* 帧缓冲设备驱动模块加载与卸载函数  */  
56 int __init xxxfb_init(void)  
57 {  
58     return platform_driver_register(&xxxfb_driver); /* 注册平台设备 */  
59 }  
60   
61 static void __exit xxxfb_cleanup(void)  
62 {  
63     platform_driver_unregister(&xxxfb_driver); /* 注销平台设备 */  
64 }  
65   
66 module_init(xxxfb_init);  
67 module_exit(xxxfb_cleanup);  
模板

总结:
     帧缓冲设备是一种典型的字符设备,它统一了显存,将显示缓冲区直接映射到用户空间。帧缓冲设备驱动 file_operations 中 VFS 接口函数由 fbmem.c 文件统一实现。这样,驱动工程师的工作重点将是实现针对特定设备 fb_info 中的 fb_ops 的成员函数,另外,理解并能灵活地修改fb_info 中的 var 和 fix 参数非常关键。fb_info 中的 var 参数直接和 LCD 控制器的硬件设置以及LCD 屏幕对应。 在用户空间,应用程序直接按照预先设置的 R、G、B 位数和偏移写经过 mmap()映射后的显示缓冲区就可实现图形的显示,省去了内存从用户空间到内核空间的复制过程。

lcd驱动实例:(基于Smart210)

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/dma-mapping.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/cpufreq.h>

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

#include <asm/mach/map.h>
#include <mach/regs-gpio.h>

//lcd控制器寄存器
struct lcd_regs {
     unsigned long VIDCON0; 
     unsigned long VIDCON1; 
     unsigned long VIDCON2; 
     unsigned long VIDCON3; 
     unsigned long VIDTCON0; 
     unsigned long VIDTCON1 ;
     unsigned long VIDTCON2 ;
     unsigned long VIDTCON3 ;
     unsigned long WINCON0 ;
     unsigned long WINCON1 ;
     unsigned long WINCON2 ;
     unsigned long WINCON3 ;
     unsigned long WINCON4 ;
     unsigned long SHADOWCON; 
};
static unsigned long *VIDOSD0A; 
static unsigned long *VIDOSD0B; 
static unsigned long *VIDOSD0C;
static unsigned long *VIDW00ADD0B0;
static unsigned long *VIDW00ADD1B0;


static struct lcd_regs *lcd_reg;

static unsigned long *DISPLAY_CONTROL;

/* LCD参数 */
#define VSPW       9  
#define VBPD       13 
#define LINEVAL    479
#define VFPD       21 

#define HSPW       19 
#define HBPD       25 
#define HOZVAL     799
#define HFPD       209

#define LINEVAL    479
#define HOZVAL     799

#define LeftTopX_F  0
#define LeftTopY_F  0
#define RightBotX_F 799
#define RightBotY_F 479


/* 用于LCD的GPIO */
static unsigned long *gpf0con;
static unsigned long *gpf1con;
static unsigned long *gpf2con;
static unsigned long *gpf3con;
static unsigned long *gpd0con;
static unsigned long *gpd0dat;



static struct fb_info  *lcd_info;

static unsigned int pseudo_palette[16];

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 smart210_lcdfb_setcolreg(unsigned regno, unsigned red, unsigned green,
                  unsigned blue, unsigned 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 struct fb_ops  smart210_lcd_ops = {
    .owner        =  THIS_MODULE,
    .fb_setcolreg    = smart210_lcdfb_setcolreg,
    .fb_fillrect    = cfb_fillrect,
    .fb_copyarea    = cfb_copyarea,
    .fb_imageblit    = cfb_imageblit,
};



static int __init my_lcd_init(void)
{
    struct clk *lcd_clk;
    /*分配一个fb_info的结构体*/
    lcd_info = framebuffer_alloc(0 ,NULL);
    if(IS_ERR(lcd_info)) {
        printk(KERN_ALERT"framebuffer_alloc error
");
        return -ENOMEM;
    }
    /*设置*/
    /*配置fix固定参数*/
    strcpy(lcd_info->fix.id, "Smart210_lcd");
    //lcd_info->fix.smem_start
    lcd_info->fix.smem_len = 800 * 480 * 4;           /*7寸屏,rgb 8:8:8*/
    lcd_info->fix.type     = FB_TYPE_PACKED_PIXELS;
    lcd_info->fix.visual   = FB_VISUAL_TRUECOLOR;     //真彩
    lcd_info->fix.line_length = 800 * 4;
    /*配置可变参数var*/
    lcd_info->var.xres     = 800;
    lcd_info->var.yres     = 480;
    lcd_info->var.xres_virtual = 800;
    lcd_info->var.yres_virtual = 480;
    lcd_info->var.xoffset      = 0;
    lcd_info->var.yoffset      = 0;
    lcd_info->var.bits_per_pixel = 32;    //每个像素多少位 32位
    lcd_info->var.grayscale      = 0;     //灰度级设为0
    
    lcd_info->var.red.length     = 8;
    lcd_info->var.red.offset     = 16;
    lcd_info->var.green.length   = 8;
    lcd_info->var.green.offset   = 8;
    lcd_info->var.blue.length    = 8;
    lcd_info->var.blue.offset    = 0;
    
    lcd_info->var.nonstd         = 0;    //标准像素
    lcd_info->var.activate       = FB_ACTIVATE_NOW;

    /*配置操作函数*/
    lcd_info->fbops              = &smart210_lcd_ops;
    //lcd_info->screen_base = ;   /*虚拟基地址*/
    lcd_info->screen_size        = 800 * 480 * 4;
    lcd_info->pseudo_palette     = pseudo_palette;  //调色板

    /*硬件相关的操作*/
    gpf0con = ioremap(0xE0200120, 4);
    gpf1con = ioremap(0xE0200140, 4);
    gpf2con = ioremap(0xE0200160, 4);
    gpf3con = ioremap(0xE0200180, 4);
    gpd0con = ioremap(0xE02000A0, 4);
    gpd0dat = ioremap(0xE02000A4, 4);

    *gpf0con = 0x22222222;
    *gpf1con = 0x22222222;
    *gpf2con = 0x22222222;
    *gpf3con = 0x22222222;
    *gpd0con |= 1<<4;
    *gpd0dat |= 1<<1;

    lcd_clk = clk_get(NULL, "lcd");
    if(IS_ERR(lcd_clk)) {
        printk(KERN_ALERT"clk_get error
");
        return -EINVAL;
    }
    clk_enable(lcd_clk);

    
    DISPLAY_CONTROL = ioremap( 0xE0107008, 4);
    lcd_reg  = ioremap(0xF8000000, sizeof(struct lcd_regs));
    VIDOSD0A = ioremap(0xF8000040, 4);
    VIDOSD0B = ioremap(0xF8000044, 4);
    VIDOSD0C = ioremap(0xF8000048, 4);
    VIDW00ADD0B0 = ioremap(0xF80000A0 , 4);
    VIDW00ADD1B0 = ioremap(0xF80000D0 , 4);
    
    *DISPLAY_CONTROL  |= (2 << 0);  //显示路径,必须

    /*
     *vidcon0[28:26]     000 = WB interface and  RGB interface 
     *vidcon0[18]        0
     *vidcon0[13:6]      0x4  5分频
     *vidcon0[4]         1 = Divided by CLKVAL_F 
     *vidcon0[2]         0 = HCLK   166.75 MHz
     *vidcon0[1]:ENVID     0 = Disables the video output and display control signal
     *vidcon0[0]:ENVID_F 0 = Disables the video output and display control signal.
     *NOTE:  Display On: ENVID and ENVID_F are set to “1”. 
               Direct Off: ENVID and ENVID_F are set to “0” simultaneously. 
               Per Frame Off: ENVID_F is set to “0” and ENVID is set to “1”. 
    */
    lcd_reg->VIDCON0 &= ~((7 << 26) | (1 << 18) | (0xff << 6) | (1 << 2));
    lcd_reg->VIDCON0  |= (0x4 << 6) | (1 << 4);

    /*
     *vidcon1[6] IHSYNC   1 = 反转  根据芯片手册和lcd手册
     *vidcon1[5] IVSYNC   1 = 反转
    */
    lcd_reg->VIDCON1  &= ~(1<<7);   /* 在vclk的下降沿获取数据 */
    lcd_reg->VIDCON1  |= (1 << 6) | (1 << 5);

        /* 设置时序(需要修改) */
    lcd_reg->VIDTCON0 = (VBPD << 16) | (VFPD << 8) | (VSPW << 0);
    lcd_reg->VIDTCON1 = (HBPD << 16) | (HFPD << 8) | (HSPW << 0);

    /*设置水平大小,垂直大小*/
    lcd_reg->VIDTCON2 |= LINEVAL << 11;
    lcd_reg->VIDTCON2 |= HOZVAL << 0;

    /*
     *WSWP_F   [15] :1    = Swap Enable(为什么要使能),,能够解决掉重影问题
     *BPPMODE_F  [5:2]  0xb = 24bpp 
     *ENWIN_F    [0]    1   Enables/ disables video output and logic immediately. 
    */
    lcd_reg->WINCON0 |= 1 << 15;
    lcd_reg->WINCON0 &= ~(0xf << 2);
    lcd_reg->WINCON0 |= 0xb << 2 | 1 << 0;

    /*窗口0  指定左上方,右下方像素的水平屏幕坐标*/
    *VIDOSD0A |= (LeftTopX_F << 11) | (LeftTopY_F << 0);
    *VIDOSD0B |= (RightBotX_F << 11) | (RightBotX_F << 0);
    *VIDOSD0C |= ((LINEVAL + 1) * (HOZVAL + 1));

    /*分配显存*/
    lcd_info->screen_base = dma_alloc_writecombine(NULL, lcd_info->fix.smem_len, (dma_addr_t *)&(lcd_info->fix.smem_start), GFP_KERNEL);
    *VIDW00ADD0B0 = lcd_info->fix.smem_start;  //显存的起始地址
    *VIDW00ADD1B0 = lcd_info->fix.smem_start + lcd_info->fix.smem_len;//显存的结束地址

    lcd_reg->SHADOWCON |= 0x1; //我们使用的是 Window0,所有需要使能 DMA 通道 0

    /* LCD控制器开启 */
    lcd_reg->VIDCON0 |= 0x3;
    lcd_reg->WINCON0 |= 0x1;

    /*注册*/
    register_framebuffer(lcd_info);
    return 0;
}

static void __exit my_lcd_exit(void)
{
    unregister_framebuffer(lcd_info);
    dma_free_writecombine(NULL, lcd_info->fix.smem_len, &(lcd_info->fix.smem_start), GFP_KERNEL);
    iounmap(gpf0con);
    iounmap(gpf1con);
    iounmap(gpf2con);
    iounmap(gpf3con);
    iounmap(gpd0con);
    iounmap(gpd0dat);
    iounmap(lcd_reg);
    iounmap(VIDOSD0A);
    iounmap(VIDOSD0B);
    iounmap(VIDOSD0C);
    iounmap(VIDW00ADD0B0);
    iounmap(VIDW00ADD1B0);
    framebuffer_release(lcd_info);
}


MODULE_LICENSE("GPL");
module_init(my_lcd_init);
module_exit(my_lcd_exit);
lcd驱动实例:

s5pv210 lcd裸机分析网址:

http://blog.csdn.net/a158337/article/details/39802159

原文地址:https://www.cnblogs.com/qigaohua/p/5469192.html