Linux device driver LCD in the framebuffer (frame buffer)

Linux the LCD device driver

the framebuffer (frame buffer)

[Date: 2012-05-24] Source: Linux community Author: tianxiawuzhei [Font: Tai  Zhong  small ]

1, framebuffer frame buffer

    Frame buffer (the framebuffer) is a Linux interface to provide a display device for the system, it will display buffer abstraction difference image mask underlying hardware, allowing the upper application of the read and write directly to the display buffer in graphics mode. Users do not have the specific physical location of the display buffer and storage methods, which frame buffer by the device driver to complete itself.

    framebuffer mechanism mimic the function of the graphics, the graphics hardware configuration of a series of abstract data structure, the memory can operate by reading and writing directly to the framebuffer. Users can be seen as a framebuffer memory of the image, map it into the process space, you can directly read and write operations, the write operation will be directly reflected on the screen.

    framebuffer is a character device, major number of 29, corresponding to the / dev / fb% d device file.

Typically, the following method (in front of the number indicates minor number)
  0 = / dev / FB0 of
a device fb
  1 = / dev / fb1 second device fb

    fb is a conventional memory device, you can read its contents. For example, the screen is a screen capture: Although cp / dev / fb0 myfilefb can be like memory device (/ dev / mem), it read, write, seek and mmap. But the difference is that not the entire memory area fb used, but the memory part.

2, fb interaction with the application

For the user program, and other devices and it is no different, the user can fb as a piece of memory, either write data to memory, you can also read the data. fb display buffer in the kernel space, the application of this space can be mapped to their user space during operation.

In application, the general steps / dev / fbn as follows:
(1) to open / dev / fbn device file.
(2) () operation to obtain the parameters of the current display screen, such as screen resolution using the ioctl, each of
the number of bits of pixel points. Parameters calculated according to the screen size of screen buffer.
(3) with a mmap () function, the user maps to the screen buffer space.
(4) can be mapped directly after the read / write screen buffer, plotting and display the pictures.

3, fb and its associated structure of

In linux, two source files fb device drivers in the main Fb.h (linux2.6.28 \ include \ linux) and Fbmem.c (linux2.6.28 \ drivers \ video), the device drivers are fb intermediate layer, for the upper layer provides system calls, provides an interface to the underlying driver.



There are many structural fb drive you want to use in fb.h file, we first of these structures is described:

(1)、

A frame buffer corresponding to a struct fb_info structure, which includes a complete set of attributes and operations of the frame buffer devices, each device has a frame structure fb_info. Source as follows:

struct fb_info {
int node;
int flags;
struct mutex lock;/ * Lock for open / release / ioctl funcs * / mutex
struct was fb_var_screeninfo;/ * Current var * / current buffer variable parameter
struct fb_fix_screeninfo fix;/ * Current fix * / fixed parameter
struct fb_monspecs monspecs;/ * Current Monitor specs * / current display flag
struct work_struct queue;/ * Framebuffer event queue * / event queue frame buffer
struct fb_pixmap pixmap;/* Image hardware mapper */图像硬件mapper
struct fb_pixmap sprite;/* Cursor hardware mapper */光标硬件mapper
struct fb_cmap cmap;/* Current cmap */当前的调色板
struct list_head modelist;      /* mode list */
struct fb_videomode *mode;/* current mode */当前的视频模式


#ifdef CONFIG_FB_BACKLIGHT如果配置了LCD支持背光灯
/* assigned backlight device */
/* set before framebuffer registration, 
  remove after unregister */背光调整
struct backlight_device *bl_dev;


/* Backlight level curve */
struct mutex bl_curve_mutex;
u8 bl_curve[FB_BACKLIGHT_LEVELS];
#endif
#ifdef CONFIG_FB_DEFERRED_IO
struct delayed_work deferred_work;
struct fb_deferred_io *fbdefio;
#endif


struct fb_ops *fbops;帧缓冲操作函数集
struct device *device;/* This is the parent */父设备
struct device *dev;/* This is this fb device */fb设备
int class_flag;                    /* private sysfs flags */私有的sysfs标志
#ifdef CONFIG_FB_TILEBLITTING
struct fb_tile_ops *tileops;    /* Tile Blitting */图块blitting
#endif
char __iomem *screen_base;/* Virtual address */虚拟基地址
unsigned long screen_size;/* Amount of ioremapped VRAM or 0 */ ioremap的虚拟内存大小
void *pseudo_palette;/* Fake palette of 16 colors */ 伪16位调色板
#define FBINFO_STATE_RUNNING 0
#define FBINFO_STATE_SUSPENDED 1
u32 state; /* Hardware state i.e suspend */硬件的状态
void *fbcon_par;                /* fbcon use-only private area */
/* From here on everything is device dependent */
void *par;
};

(2)、

/*
 * Frame buffer operations
 *
 * LOCKING NOTE: those functions must _ALL_ be called with the console
 * semaphore held, this is the only suitable locking mechanism we have
 * in 2.6. Some may be called at interrupt time at this point though.
 */
fb_ops结构体用来实现对帧缓冲设备的操作,这些函数需要驱动开发人员编写,

struct fb_ops {
/* open/release and usage marking */
struct module *owner;

          打开和释放
int (*fb_open)(struct fb_info *info, int user);

int (*fb_release)(struct fb_info *info, int user);

          这两个函数对于非线性布局的/常规内存映射无法工作的帧缓冲设备需要
/* For framebuffers with strange non linear layouts or that do not
* work with normal memory mapped access
*/
ssize_t (*fb_read)(struct fb_info *info, char __user *buf,
  size_t count, loff_t *ppos);
ssize_t (*fb_write)(struct fb_info *info, const char __user *buf,
   size_t count, loff_t *ppos);

           检测可变参数,并调整到支持的值
/* checks var and eventually tweaks it to something supported,
* DO NOT MODIFY PAR */
int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);

            设置视频模式
/* set the video mode according to info->var */
int (*fb_set_par)(struct fb_info *info);

           设置color寄存器的值
/* set color register */
int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
   unsigned blue, unsigned transp, struct fb_info *info);

            批量设置color寄存器,设置颜色表
/* set color registers in batch */
int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);

          显示空白
/* blank display */
int (*fb_blank)(int blank, struct fb_info *info);

          pan显示
/* pan display */
int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);

          填充矩形
/* Draws a rectangle */
void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);

            数据复制
/* Copy data from area to another */
void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);

           图形填充
/* Draws a image to the display */
void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);

           绘制光标
/* Draws cursor */
int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);

            旋转显示
/* Rotates the display */
void (*fb_rotate)(struct fb_info *info, int angle);

            等待blit空闲
/* wait for blit idle, optional */
int (*fb_sync)(struct fb_info *info);

             fb特定的ioctl操作
/* perform fb specific ioctl (optional) */
int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,
unsigned long arg);

              处理32兼容的ioctl操作
/* Handle 32bit compat ioctl (optional) */
int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd,
unsigned long arg);

             fb特定的mmap操作
/* perform fb specific mmap */
int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);

           保存目前的硬件状态
/* save current hardware state */
void (*fb_save_state)(struct fb_info *info);

            恢复被保存的硬件状态
/* restore saved state */
void (*fb_restore_state)(struct fb_info *info);

           通过fb_info获得framebuffer的能力
/* get capability given var */
void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps,
   struct fb_var_screeninfo *var);
};

(3)、

fb_fix_screeninfo结构体中,记录了用户不能修改的固定显示控制器参数。这些固定的参数如缓冲区的物理地址、缓冲区的长度等等。
struct fb_fix_screeninfo {
char id[16]; /* identification string eg "TT Builtin" */

        字符串形式的标识符
unsigned long smem_start;/* Start of frame buffer mem */

/* (physical address) */

        fb缓存的开始位置
__u32 smem_len;/* Length of frame buffer mem */

        fb缓存的长度
__u32 type; /* see FB_TYPE_* */

        FB_TYPE_*类型
__u32 type_aux;/* Interleave for interleaved Planes */

         分界
__u32 visual; /* see FB_VISUAL_* */

       屏幕使用的色彩模式 
__u16 xpanstep;/* zero if no hardware panning  */

        如果没有硬件panning ,赋0
__u16 ypanstep;/* zero if no hardware panning  */

__u16 ywrapstep;/* zero if no hardware ywrap    */

         1行的字节数
__u32 line_length;/* length of a line in bytes    */

         内存映射I/O的开始位置
unsigned long mmio_start;/* Start of Memory Mapped I/O   */
/* (physical address) */

         内存映射I/O的长度
__u32 mmio_len;/* Length of Memory Mapped I/O  */
__u32 accel; /* Indicate to driver which */
/*  specific chip/card we have*/
__u16 reserved[3];/* Reserved for future compatibility */
};

(4)、

fb_var_screeninfo结构体中存储了用户可以修改的显示器控制参数,例如屏幕分辨率、透明度等等。

struct fb_var_screeninfo {
__u32 xres; /* visible resolution */
__u32 yres;

        可见解析度,即分辨率
__u32 xres_virtual;/* virtual resolution */
__u32 yres_virtual;

        虚拟解析度
__u32 xoffset;/* offset from virtual to visible */
__u32 yoffset;/* resolution */

        虚拟到可见之间的偏移
__u32 bits_per_pixel;/* guess what */

        每像素位数,BPP
__u32 grayscale;/* != 0 Graylevels instead of colors */

        非0时指灰度


struct fb_bitfield red;/* bitfield in fb mem if true color, */
struct fb_bitfield green;/* else only length is significant */
struct fb_bitfield blue;

         fb缓存的R\G\B位域
struct fb_bitfield transp;/* transparency */

         透明度

__u32 nonstd; /* != 0 Non standard pixel format */

        != 0 非标准像素格式

__u32 activate;/* see FB_ACTIVATE_* */

       
__u32 height; /* height of picture in mm    */

         屏幕的高度
__u32 width; /* width of picture in mm     */

         屏幕的宽度
__u32 accel_flags;/* (OBSOLETE) see fb_info.flags */
         fb_info的标志

/* Timing: All values in pixclocks, except pixclock (of course) */
__u32 pixclock;/* pixel clock in ps (pico seconds) */

         /* 像素时钟(皮秒) */
__u32 left_margin;/* time from sync to picture */

        行切换:从同步到绘图之间的延迟
__u32 right_margin;/* time from picture to sync */

        行切换:从绘图到同步之间的延迟
__u32 upper_margin;/* time from sync to picture */

        帧切换:从同步到绘图之间的延迟
__u32 lower_margin;

         帧切换:从绘图到同步之间的延迟
__u32 hsync_len;/* length of horizontal sync */

         水平同步的长度
__u32 vsync_len;/* length of vertical sync */

         垂直同步的长度
__u32 sync; /* see FB_SYNC_* */
__u32 vmode; /* see FB_VMODE_* */
__u32 rotate; /* angle we rotate counter clockwise */

        顺时钟旋转的角度
__u32 reserved[5];/* Reserved for future compatibility */
};

(5)、

fb_cmap结构体中记录了颜色板信息,即调色板信息。,用户空间可以通过ioctl()的FBIOGETCMAP和 FBIOPUTCMAP命令读取或设定颜色表。

struct fb_cmap {
__u32 start; /* First entry */第一个元素的入口
__u32 len; /* Number of entries */元素个数
__u16 *red; /* Red values */红色、绿色、蓝色
__u16 *green;  
__u16 *blue;
__u16 *transp;/* transparency, can be NULL */透明度
};


上面这些结构体之间有什么关系呢?看下图:



(6)、

fb_bitfield 结构体描述每一像素显示缓冲区的组织方式,包含位域偏移、位域长度和MSB 指示,

struct fb_bitfield {
__u32 offset; /* beginning of bitfield */

         位域偏移
__u32 length; /* length of bitfield */

        位域长度
__u32 msb_right;/* != 0 : Most significant bit is */ 
/* right */

        MSB
};

linux
发布了33 篇原创文章 · 获赞 2 · 访问量 8511

Guess you like

Origin blog.csdn.net/QQ960054653/article/details/71077200