分类: 嵌入式
2011-12-22 14:37:11
本文介绍的设备是位于/video目录下面的anakinfb.c驱动程序。虽然我不清楚那个设备的特性,但是从对程序的分析中我们仍然知道如何编写一个framebuffer设备驱动。
本文是个标准的fb驱动。共221行,包含函数如下:
/*registor constrol*/
1. static int anakinfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue, u_int *transp, struct fb_info *info)
2. static int anakinfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,u_int transp, struct fb_info *info)
/* fb_ops funtions */
3. static int anakinfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
4. static int anakinfb_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
5. static int anakinfb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
6. static int anakinfb_get_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info)
7. static int anakinfb_set_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info)
/* switch console terminal */
8. static int anakinfb_switch_con(int con, struct fb_info *info)
/* update variable */
9. static int anakinfb_updatevar(int con, struct fb_info *info)
/* qlint screen */
10. static void anakinfb_blank(int blank, struct fb_info *info)
/* initial device */
11. int __init anakinfb_init(void)
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, 也就是skeletonfb.c提供的框架完成的。
共230行,包含函数如下:
1. static int sti_encode_fix(struct fb_fix_screeninfo *fix, const void *par, struct fb_info_gen *info)
2. static int sti_decode_var(const struct fb_var_screeninfo *var,void *par, struct fb_info_gen *info)
3. static int sti_encode_var(struct fb_var_screeninfo *var, const void *par, struct fb_info_gen *info)
4. static void sti_get_par(void *par, struct fb_info_gen *info)
5. static void sti_set_par(const void *par, struct fb_info_gen *info)
6. static int sti_getcolreg(unsigned regno, unsigned *red, unsigned *green, unsigned *blue, unsigned *transp, struct fb_info *info)
7. static int sti_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info)
8. static void sti_set_disp(const void *par, struct display *disp, struct fb_info_gen *info)
9. static void sti_detect(void)
10. static int sti_blank(int blank_mode, const struct fb_info *info)
11. int __init stifb_init(void)
12. void stifb_cleanup(struct fb_info *info)
13. int __init stifb_setup(char *options)
其中1到10是必须的,参考下面的图。
11是初始化代码
12.13没有完成具体功能
再给出fb_fix_screeninfo系统调用结构图: