How to Write Linux LCD drivers

Source: Internet
Author: User

 

How to Write Linux LCD Driver) Author:
Liu Peng Date:

2008-12-27

This article analyzes the main data structure of the frame buffer device driver, and introduces the development of the LCD driver program. Basic Principles
  • Through framebuffer, the application uses MMAP to map the video memory to the virtual address space of the application. The data to be displayed can be displayed on the screen after being written to the memory space;
  • The driver allocates system memory as the memory for display; implements interfaces in the file_operations structure to serve the application; implements interfaces in the fb_ops structure to control and operate the LDC controller;
  • The driver transmits the starting address and length of the video memory to the registers of the LCD controller (usually completed by fb_set_var). The LDC controller automatically displays the data in the video memory on the LCD screen.
What should I do to write the framebuffer driver?
  • To put it simply, the function of the framebuffer driver is to allocate a piece of memory for memory display and then set the registers of the LCD controller.
  • Specifically:
    1. Fill in a fbinfo Structure
    2. Use reigster_framebuffer (fbinfo *) to register the fbinfo structure to the kernel
  • For the fbinfo structure, the most important thing is its fs_ops member. You need to implement interfaces in fs_ops for specific devices.
  • Whether to use interrupt handling
  • Memory Access
    1. If the video card does not have its own video memory, the system memory is allocated as the video memory.
    2. The graphics card comes with a video memory and is accessed using the I/O memory interface (request_mem_region/ioremap ),
  • For more information about how to write drivers, see "Linux frame buffer driver writing howto" at http:/linux-fbdev.sourceforge.net/howto/index.html"
LCD module/driver/Controller

For more information about LCD Devices, see the following:

  • Datasheet of LCD Device
  • Book: LCD technology
  • Book: LCD display
What is a frame buffer device?

The frame buffer device is an abstraction of the graphic hardware. It represents the detection buffer of the graphic hardware and allows
The program accesses the graphic hardware through the specified interface. Therefore, applications do not have to care about the underlying hardware details.

A device is accessed through a specific device node, usually in the/dev directory, such as/dev/FB *.

For more information about frame buffer device, see the following two files: Linux
/Documentation/FB/framebuffer.txt and Linux/documentation/FB
/Interal.txt, but the content of these materials is not much, you need to take a look at the specific analysis with the code.

Linux frame buffer driver hierarchy

The driver of the frame buffer device can be viewed in three layers:

  1. Application and system calls;
  2. Common Code applicable to all devices to avoid duplication, including the file_operations structure and the Register/unregister framebuffer interface;
  3. Code for operating specific hardware, mainly fs_ops structure.

In the Linux kernel, the source code of the frame buffer device driver is mainly in the following two files:
In the middle layer of the frame buffer driver architecture, it provides system calls for upper-layer user programs,
It also provides interfaces for underlying hardware drivers:

  1. Linux/inlcude/FB. h
  2. Linux/Drivers/Video/fbmem. c
Data Structure

The header file FB. h defines all the data structures:

  • Fb_var_screeninfo: Describes all information about the display mode of a video card, such as width, height, and color depth. Different display modes correspond to different information;
  • Fb_fix_screeninfo: defines the video card information, such as the starting address and address length of framebuffer memory;
  • Fb_cmap: The colormap information of the device. You can use the fbiogetcmap and fbioputcmap commands of IOCTL to set the colormap;
  • Fb_info: displays the status information of the current video card. Only fb_info is visible to the kernel;
  • Fb_ops: applications use IOCTL system calls to operate the underlying LCD hardware. methods defined in the fb_ops structure are used to support these operations;
  • The relationships between these structures are as follows:
Framebuffer driver main Data Structure
Interface

Fbmem. c implements common code used by all drivers to avoid duplication.

Global variables:

     struct fb_info *registered_fb [FB_MAX]
int num_registered_fb;

These two variables are used to record the fb_info structure instance in use. Fb_info indicates the current status of the video card. All fb_info
The structure is put in the array. When a frame buffer is logged in the kernel, a new fb_info
The structure is added to this array, and num_registered_fb is added with 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 to the kernel, a new entry must be added to this table. If the driver is dynamically loaded to the kernel using insmod/rmmod, you do not have to worry 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 interface of your application. 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 interface of the driver of the underlying frame buffer device. The driver uses this pair of functions for registration and revocation. The underlying driver basically fills in the fb_info structure and registers it.

One LCD controller driver

To implement an LCD controller driver, perform the following two steps:

  • Allocate system memory for memory display
  • Implement the fb_ops interface based on specific hardware features
  • In Linux/Drivers/FB/skeletonfb. C, there is a frame buffer driver framework, which shows how to implement a frame buffer driver with few code.
Allocate system memory as memory

Because most LDC controllers do not have their own video memory, they need to allocate a system memory as the video memory.
The starting address and length of the system memory will be stored in fb_fix_screeninfo
Smem_start and smem_len domains. The memory should be physically consecutive.

For graphics cards with independent video memory, use request_mem_region and ioremap to map the peripheral memory of the graphics card to the virtual address space of the processor.

Implement the fb_ops Structure

Currently, the file_operations method that is not discussed is IOCTL (). User Application Usage
Ioctrl system calls to operate LCD hardware. The methods defined in the fb_ops structure provide support for these operations
Hold. Note that the fb_ops structure is not the file_operations structure. Fb_ops is the extraction of underlying operations
And file_operations provide support for upper-level system calling interfaces.

The following describes the implementation methods. The relationship between the ioctl command and the interface in the fb_ops structure is shown in figure
As shown below:

    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

If we implement those fb_xxx functions, the user application can use the fbioxxxx macro.
To operate the LDC hardware. How can we implement those interfaces? Refer
Driver in the Linux/Drivers/video directory.

Among the many interfaces, fb_set_var is the most important. It is used to set information such as video mode. Lower
The plane is a general step for implementing the fb_set_var function:

  1. Check whether it is necessary to set mode
  2. Set Mode
  3. Set colormap
  4. Reconfigure the LCD controller register according to the above settings

Step 4 is the underlying hardware operation.

Reference
  • Writing Linux LCD drivers-in-depth analysis of the structure of the framebuffer Device Driver
  • Linux frame buffer driver howto
  • S3c2410_ LCD frame buffer Driver Analysis
  • Linux 2.6 Device Model
  • Linux 2.6 kernel device model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.