【Linux高级驱动】LCD驱动框架分析

1.framebuffer接口层(fbmem.c)

    功能:给用户提供接口

fbmem_init  //入口函数
 /*1.申请主设备号,注册字符设备*/
 register_chrdev(FB_MAJOR(29),"fb",&fb_fops)
 
 /*2.创建一个设备类*/
 fb_class = class_create(THIS_MODULE, "graphics");
static const struct file_operations fb_fops = {
 .owner = THIS_MODULE,
 .read =  fb_read,
 .write = fb_write,
 .unlocked_ioctl = fb_ioctl,
#ifdef CONFIG_COMPAT
 .compat_ioctl = fb_compat_ioctl,
#endif
 .mmap =  fb_mmap,
 .open =  fb_open,
 .release = fb_release,
#ifdef HAVE_ARCH_FB_UNMAPPED_AREA
 .get_unmapped_area = get_fb_unmapped_area,
#endif
#ifdef CONFIG_FB_DEFERRED_IO
 .fsync = fb_deferred_io_fsync,
#endif
};

 

2.从应用层往下分析

open

app: open("/dev/xxx",xxx)
===============================
vfs: sys_open
  ...
  ...
fbmem.c struct file_operations fb_fops
   .open =  fb_open,
    /*1.获取此设备号*/
    int fbidx = iminor(inode);
    struct fb_info *info;
    /*2.以此设备号为下标,从register_fb数组中取出fb_info结构体*/
    info = registered_fb[fbidx];
    file->private_data = info;
    if (info->fbops->fb_open) {
     res = info->fbops->fb_open(info,1);

ioctl

app: ioctl(fd,FBIOGET_VSCREENINFO,args)
===========================================
vfs: sys_ioctl
  ...
  ...
fbmem.c struct file_operations fb_fops
   .unlocked_ioctl = fb_ioctl,
    /*1.获取此设备号*/
    struct inode *inode = file->f_path.dentry->d_inode;
    int fbidx = iminor(inode);
    /*2.以此设备号为下标,从register_fb数组中取出fb_info结构体*/
    struct fb_info *info = registered_fb[fbidx];
    do_fb_ioctl(info, cmd, arg);
     struct fb_var_screeninfo var;  //表示可变参数
     struct fb_fix_screeninfo fix;  //表示固定参数
     switch (cmd) {
      case FBIOGET_VSCREENINFO:
       if (!lock_fb_info(info))
        return -ENODEV;
       var = info->var; //取出fb_info中的可变参数
       unlock_fb_info(info);
       ret = copy_to_user(argp, &var, sizeof(var)) ? -EFAULT : 0;
       break;
     }

    搜索registered_fb数组,看在哪里被设置了?

s3c_fb_probe(struct platform_device *pdev)
 ...
 ...
 for (win = 0; win < S3C_FB_MAX_WIN; win++) {
  /*设置一个硬件窗口:一个窗口就是一个帧缓冲设备,一个帧缓冲设备用struct fb_info来描述*/
  s3c_fb_probe_win     //drivers\video\s3c-fb.c
   /*构建fb_info:表示一个帧缓冲设备*/
   
   /*设置fb_info*/
   /*设置它的可变参数*/
   /*设置它的固定参数*/
   /*设置它的操作方法*/
   /*注册一个fb_info结构体*/
   register_framebuffer(struct fb_info *fb_info)
    /*将fb_info加入数组项*/
    registered_fb[i] = fb_info;

 

 

  @成鹏致远

(blogs:http://lcw.cnblogs.com

(emailwwwlllll@126.com)

(qq552158509

 





posted @ 2014-06-22 17:22 Leo.cheng 阅读(...) 评论(...) 编辑 收藏