Basic principles
Through the framebuffer, application memory using mmap to map the virtual address space to the application, write the data to be displayed in this memory space can be displayed on the screen;
       Driver to allocate system memory as video memory; to achieve file_operations structure interface for application services; to achieve fb_ops structure interface, control and operation of LCD controller;
       Driver memory to pass the starting address and length of the LCD controller registers (usually completed by the fb_set_var), LCD controller, the memory will be automatically displayed on the LCD data screen.

Write framebuffer driver what to do
Simply put, framebuffer driver’s function is to allocate a block of memory for video memory, then the LCD controller registers to make some settings.
       Specifically:
                Fill a fbinfo structure
                With reigster_framebuffer (fbinfo *) will be registered with the kernel fbinfo structure
                For fbinfo structure, the most important members of its fs_ops need specific equipment to achieve the interface fs_ops
                Consider the use of interrupt handling
                Consider the memory access mode
                Memory card does not own, and to allocate system memory as graphics memory
                Comes with memory card, using I / O memory interface to access
LCD display module \ drivers \ controller

LCD devices can be found on the following information:

Datasheet of LCD device
Book: liquid crystal display technology
Book: liquid crystal display
What is the frame buffer device
graphics frame buffer device is a hardware abstraction, which represents the graphics hardware detection buffer, allows applications to access the graphics hardware interfaces specified. Therefore, the application need not care about the underlying hardware details.

Equipment access through a specific device node, usually in the / dev directory, such as / dev / fb *.

More information about the frame buffer device can be found in the following two files: linux / Documentation / fb / framebuffer.txt and linux / Documentation / fb / interal.txt, but the information content of small, also need to look at with code specific analysis.

Linux Frame Buffer driver hierarchy
Frame Buffer device lcd driver ic can look at three levels:

Application and system calls;
Applicable to all devices common code, to avoid duplication, including the file_operations structure, register / unregister framebuffer interface;
Operation code specific hardware, mainly fs_ops structure.
In the Linux kernel, Frame Buffer device driver source code, mainly in the following two files, they are driven architecture in the frame buffer in the middle layer, which provided for the upper system calls the user program, but also provides the underlying hardware driver specific interface:

linux / inlcude / fb.h
linux / drivers / video / fbmem.c

Data structure
Fb.h header file defines all the data structures:

fb_var_screeninfo: describes a video card all of the information display mode, such as width, height, color depth, different display modes correspond to different information;
fb_fix_screeninfo: definition of the graphics information, such as framebuffer memory starting address, address, length, etc.;
fb_cmap: device independent of the colormap information, through the FBIOGETCMAP and FBIOPUTCMAP ioctl command to set colormap;
fb_info: video card that contains the current state information, only fb_info visible to the kernel;
fb_ops: application uses the underlying operating system call ioctl LCD hardware, fb_ops methods defined structure used to support these operations

Interface
fbmem.c achieve common code used by all drivers to avoid duplication.

Global variables:

     struct fb_info * registered_fb [FB_MAX]
     int num_registered_fb;
The two variables used to record instances of being used fb_info structure. fb_info representative of the current state of video card, all the fb_info structures on the array. When a frame buffer in the kernel, the time of registration, a new fb_info structure is added to the array, num_registered_fb plus 1.

fb_drivers array:

static struct {
    const char * name;
    int (* init) (void);
    int (* setup) (void);
} Fb_drivers [] __initdata = {….};

If the frame buffer driver is statically linked into the kernel, a new entry must be added to this table. If the LCD driver is dynamically loaded into the kernel using insmod, you do not care about this structure.

static struct file_operations fb_ops = {
    owner: THIS_MODULE,
    read: fb_read,
    write: fb_write,
    ioctl: fb_ioctl,
    mmap: fb_mmap,
    open: fb_open,
    release: fb_release
};
This is the user application interface, fbmem.c implements these functions.

register / unregister framebuffer:

 register_framebuffer (struct fb_info * fb_info)
 unregister_framebuffer (struct fb_info * fb_info)
This is the underlying frame buffer device driver interface. Driver uses this function to achieve registration and undo. The underlying driver is essentially filled fb_info structure, and then register it.

An LCD controller driver
An LCD controller driver to achieve the main job of the following steps:

Allocate system memory for video memory
Depending on the hardware features, the interface to achieve fb_ops
In linux / drivers / fb / skeletonfb.c have a frame buffer driver framework that very few examples of how to code with a frame buffer driver.
Allocate system memory as graphics memory
Since most of the LDC controller did not have a memory, a system memory is allocated as graphics memory. This system memory starting address and length will be stored in fb_fix_screeninfo after the smem_start and smem_len domain. The memory should be physically contiguous.

With separate video memory for use request_mem_region and ioremap memory-mapped peripherals to the graphics processor virtual address space.

Structure to achieve fb_ops
There is no discussion of the file_operations method is ioctl (). User application operating system calls using the ioctrl LCD hardware. fb_ops methods defined structure to provide support for these operations. Note, fb_ops structure is not the file_operations structure. fb_ops is the abstraction of the underlying operations, and file_operations system call interface for the upper support.

Consider the need to achieve what method. ioctl command and fb_ops structure the relationship between the interface as follows:

    FBIOGET_VSCREENINFO fb_get_var
    FBIOPUT_VSCREENINFO fb_set_var
    FBIOGET_FSCREENINFO fb_get_fix
    FBIOPUTCMAP fb_set_cmap
    FBIOGETCMAP fb_get_cmap
    FBIOPAN_DISPLAY fb_pan_display
As long as we realize that fb_XXX function, then the user application can use a macro to operate the LDC FBIOXXXX hardware. How to implement those interfaces that it? Can refer to the linux / drivers / video directory driver.

Among the many interfaces, fb_set_var is the most important. It is used to set the video mode and other information. The following are the general steps to achieve fb_set_var function:

Check whether it is necessary to set mode
Setting mode
Set the colormap
Based on the above settings to reconfigure LCD controller registers
The fourth step is the underlying hardware operations.