免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 789 | 回复: 0
打印 上一主题 下一主题

Framebuffer驱动程序模型 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-04 09:52 |只看该作者 |倒序浏览

Framebuffer驱动程序模型
下图会向你展示目前的framebuffer设备驱动的结构,最常用的是非标准驱动。很明显他所处的层次最高,程序编写是最容易的。理解了这个图的,你已经很轻松的去完成一个fb驱动,比如给sa1100,s2410,s2440系列的ARM的LCD控制器写驱动。


Color Map 剖析
在framebuffer驱动程序设计中,cmap这个东东太晕了。现在我要把他赤裸裸的剖析给大家:)
1. struct fb_cmap

/*颜色映射表*/
struct fb_cmap {
        __u32 start; /* First entry */
        __u32 len; /* Number of entries */
        __u16 *red; /* 红色 */
        __u16 *green; /*绿色*/
        __u16 *blue; /*蓝色*/
        __u16 *transp; /* 透明度,允许 NULL */
};
该结构在fb.h文件中定义,在struct fb_ops结构中有两个成员函数与其相关:
/*获取颜色表*/
int (*fb_get_cmap)(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info);
/*设定颜色表*/
int (*fb_set_cmap)(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info);
在struct fb_info结构中有变量:
struct fb_cmap cmap; /* Current cmap */
在fpgen基础操作下提供:
extern int
fbgen_get_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info);
extern int
fbgen_set_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info);
在文件/* drivers/video/fbcmap.c */中提供更多的cmap应用
extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
extern void fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to, int fsfromto);
extern int fb_get_cmap(struct fb_cmap *cmap, int kspc,
int (*getcolreg)(u_int, u_int *, u_int *, u_int *,u_int *, struct fb_info *),
                                struct fb_info *fb_info);
extern int fb_set_cmap(struct fb_cmap *cmap, int kspc,
       int (*setcolreg)(u_int, u_int, u_int, u_int, u_int,struct fb_info *),
       struct fb_info *fb_info);
extern struct fb_cmap *fb_default_cmap(int len);
extern void fb_invert_cmaps(void);
2. 通过文件解析
在anakinfb.c文件中,cmap如图




在stifb.c


本文介绍的设备是位于/video目录下面的anakinfb.c驱动程序。虽然我不清楚那个设备的特性,但是从对程序的分析中我们仍然知道如何编写一个frame buffer设备驱动。
    本文是个标准的fb驱动。共221行,包含函数如下:
  • static int anakinfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue, u_int *transp, struct fb_info *info) 31行
  • static int anakinfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,u_int transp, struct fb_info *info) 45行
  • static int anakinfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info) 57行
  • static int anakinfb_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info) 75行
  • static int anakinfb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info) 111行
  • static int anakinfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,     struct fb_info *info) 117行
  • static int anakinfb_set_cmap(struct fb_cmap *cmap, int kspc, int con,     struct fb_info *info) 130行
  • static int anakinfb_switch_con(int con, struct fb_info *info) 147行
  • static int anakinfb_updatevar(int con, struct fb_info *info) 155行
  • static void anakinfb_blank(int blank, struct fb_info *info) 161行
  • int __init anakinfb_init(void) 178行函数1,2是寄存器操作用。函数3,4,5,6,7是fb_ops函数。函数8用于切换控制台。函数9用于更新变量。函数10用于闪烁屏幕。函数11用于初始化设备。
        很奇怪,对fb设备的读写函数怎么没有!值得说明的是open,release,read,write,ioctl,mmap等函数的实现是由 fbmem.c文件实现了。也就是说所有的fb设备在给定了fb_info后,所有的操作都是一样的。在明确的fb_info前提下,fbmem.c中的函数可以工作的很好。这样大家应该感到非常轻松了吧,只要完成上述的几个设备相关的函数,frame buffer设备的驱动就写完了:)
        系统的结构如图:

    Stifb驱动模型
    linux/drivers/video/stifb.c - Generic frame buffer driver for HP * workstations with STI (standard text interface) video firmware.
    这个驱动程序和前面的anakin设备完全不同,因为他不是采用标准的格式,而是根据 based on skeletonfb, which wasCreated 28 Dec 1997 by Geert Uytterhoeven也就是skeletonfb.c提供的框架完成的。
    共230行,包含函数如下:
    static int sti_encode_fix(struct fb_fix_screeninfo *fix, const void *par, struct fb_info_gen *info) 60行
    static int sti_decode_var(const struct fb_var_screeninfo *var,void *par, struct fb_info_gen *info) 71行
    static int sti_encode_var(struct fb_var_screeninfo *var, const void *par, struct fb_info_gen *info) 78行
    static void sti_get_par(void *par, struct fb_info_gen *info) 94行
    static void sti_set_par(const void *par, struct fb_info_gen *info) 99行
    static int sti_getcolreg(unsigned regno, unsigned *red, unsigned *green, unsigned *blue, unsigned *transp, struct fb_info *info) 104行
    static int sti_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info) 111行
    static void sti_set_disp(const void *par, struct display *disp, struct fb_info_gen *info) 118行
    static void sti_detect(void) 127行
    static int sti_blank(int blank_mode, const struct fb_info *info) 132行
    int __init stifb_init(void) 161行
    void stifb_cleanup(struct fb_info *info) 201行
    int __init stifb_setup(char *options) 208行


    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/84216/showart_1358920.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP