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設備的驅動就寫完了:)
系統的結構如圖:
====
http://www.dzjs.net/html/qianrushixitong/2007/0429/2025_3.html