LCD device driver in Linux (1) - framebuffer

Publisher:AngelicHeartLatest update time:2022-06-13 Source: eefocusKeywords:linux Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. framebuffer


Framebuffer is an interface provided by Linux system for display devices. It abstracts the display buffer, shields the underlying differences of image hardware, and allows upper-level applications to directly read and write the display buffer in graphics mode. Users do not need to care about the specific location and storage method of the physical display buffer, which are all completed by the framebuffer device driver itself.


The framebuffer mechanism imitates the function of the graphics card, abstracting the graphics card hardware structure into a series of data structures, and can directly operate the video memory through the reading and writing of the framebuffer. Users can regard the framebuffer as an image of the video memory. After mapping it to the process space, they can directly perform read and write operations, and the write operations will be directly reflected on the screen.


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


Usually, the following format is used (the number in front indicates the minor device number)

  0 = /dev/fb0 the first fb device

  1 = /dev/fb1 the second fb device


fb is also a common memory device, and its contents can be read and written. For example, screen capture: cp /dev/fb0 myfilefb can be read, written, sought and mmaped like a memory device (/dev/mem). However, the difference is that fb does not use the entire memory area, but the video memory part.


2. Interaction between Facebook and applications


For user programs, it is no different from other devices. Users can regard fb as a piece of memory, and can write data to the memory and read data. The display buffer of fb is located in the kernel space, and the application can map this space to its own user space and perform operations.


In the application, the general steps to operate /dev/fbn are as follows:

(1) Open the /dev/fbn device file.

(2) Use ioctl() to obtain the current display screen parameters, such as screen resolution,

The size of the screen buffer can be calculated based on the screen parameters.

(3) Use the mmap() function to map the screen buffer to user space.

(4) After mapping, you can directly read/write the screen buffer to perform drawing and image display.


3. The structure of fb and its related structures


In Linux, the source code of the fb device driver is mainly in the two files Fb.h (linux2.6.28includelinux) and Fbmem.c (linux2.6.28driversvideo). They are the middle layer of the fb device driver, providing system calls for the upper layer and interfaces for the underlying driver.

There are many structures that the fb driver needs to use in the fb.h file. Let's first explain these structures:


(1)、


A frame buffer corresponds to a struct fb_info structure, which includes a complete set of properties and operations of the frame buffer device. Each frame device has an fb_info structure. The source code is as follows:


struct fb_info {

int node;

int flags;

struct mutex lock;/* Lock for open/release/ioctl funcs */mutex lock

struct fb_var_screeninfo var;/* Current var */Variable parameters of the current buffer

struct fb_fix_screeninfo fix;/* Current fix */Fixed parameters

struct fb_monspecs monspecs;/* Current Monitor specs */Current monitor flag

struct work_struct queue;/* Framebuffer event queue */Framebuffer event queue

struct fb_pixmap pixmap;/* Image hardware mapper */Image hardware mapper

struct fb_pixmap sprite;/* Cursor hardware mapper */Cursor hardware mapper

struct fb_cmap cmap;/* Current cmap */Current palette

struct list_head modelist;      /* mode list */

struct fb_videomode *mode;/* current mode */Current video mode



#ifdef CONFIG_FB_BACKLIGHT If LCD is configured to support backlight

/* assigned backlight device */

/* set before framebuffer registration, 

  remove after unregister */backlight adjustment

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; frame buffer operation function set

struct device *device;/* This is the parent */parent device

struct device *dev;/* This is this fb device */fb设备

int class_flag; /* private sysfs flags */private sysfs flag

#ifdef CONFIG_FB_TILEBLITTING

struct fb_tile_ops *tileops;    /* Tile Blitting */图块blitting

#endif

char __iomem *screen_base;/* Virtual address */Virtual base address

unsigned long screen_size;/* Amount of ioremapped VRAM or 0 */ ioremap virtual memory size

void *pseudo_palette;/* Fake palette of 16 colors */ Pseudo 16-bit palette

#define FBINFO_STATE_RUNNING 0

#define FBINFO_STATE_SUSPENDED 1

u32 state; /* Hardware state ie suspend */Hardware state

void *fbcon_par;                /* fbcon use-only private area */

/* From here on everything is device dependent */

void *by; 

};


(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.

 */

The fb_ops structure is used to implement operations on the frame buffer device. These functions need to be written by the driver developer.


struct fb_ops {

/* open/release and usage marking */

struct module *owner;


          Open and release

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


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


          These two functions are needed for framebuffer devices with non-linear layouts/where regular memory mapping does not work.

/* 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);


           Detect variable parameters and adjust to supported values

/* 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

/* set the video mode according to info->var */

int (*fb_set_par)(struct fb_info *info);


           Set the value of the color register

/* set color register */

int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,

   unsigned blue, unsigned transp, struct fb_info *info);


            Batch set color registers and set color table

/* set color registers in batch */

int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);


          Display Blank

/* blank display */

int (*fb_blank)(int blank, struct fb_info *info);


          pan display

/* pan display */

int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);


          Filled Rectangle

/* Draws a rectangle */

void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);


            Data replication

/* Copy data from area to another */

void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);


           Shape Fill

/* Draws a image to the display */

void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);


           Draw the cursor

/* Draws cursor */

int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);


            Rotate display

/* Rotates the display */

void (*fb_rotate)(struct fb_info *info, int angle);


            Wait for blit to be free

/* wait for blit idle, optional */

int (*fb_sync)(struct fb_info *info);


             fb-specific ioctl operations

/* perform fb specific ioctl (optional) */

int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,

unsigned long arg);


              Handle 32-compatible ioctl operations

/* Handle 32bit compat ioctl (optional) */

int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd,

unsigned long arg);


             fb-specific mmap operations

/* perform fb specific mmap */

int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);


           Save the current hardware status

/* save current hardware state */

void (*fb_save_state)(struct fb_info *info);


            Restore the saved hardware state

/* restore saved state */

void (*fb_restore_state)(struct fb_info *info);


           Get framebuffer capabilities through fb_info

/* get capability given var */

void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps,

   struct fb_var_screeninfo *var);

};


(3)、


The fb_fix_screeninfo structure records the fixed display controller parameters that cannot be modified by the user, such as the physical address of the buffer, the length of the buffer, etc.

struct fb_fix_screeninfo {

char id[16];  /* identification string eg "TT Builtin" */


        Identifier as a string

unsigned long smem_start;/* Start of frame buffer mem */


/* (physical address) */


        The starting position of the fb cache

__u32 smem_len;/* Length of frame buffer mem */


        The length of the fb cache

__u32 type;  /* see FB_TYPE_* */


        FB_TYPE_*

__u32 type_aux;/* Interleave for interleaved Planes */


         Demarcation

__u32 visual;  /* see FB_VISUAL_* */


       The color mode used by the screen 

__u16 xpanstep;/* zero if no hardware panning  */


        If there is no hardware panning, set to 0

__u16 ypanstep;/* zero if no hardware panning  */


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


         Number of bytes per line

__u32 line_length;/* length of a line in bytes    */


         The start position of memory-mapped I/O

unsigned long mmio_start;/* Start of Memory Mapped I/O   */

/* (physical address) */


         Length of memory-mapped 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)、


The fb_var_screeninfo structure stores display control parameters that can be modified by the user, such as screen resolution, transparency, etc.


struct fb_var_screeninfo {

__u32 xres;  /* visible resolution */

__u32 yres;


        Visible resolution, or resolution

__u32 xres_virtual;/* virtual resolution*/

[1] [2]
Keywords:linux Reference address:LCD device driver in Linux (1) - framebuffer

Previous article:LCD device driver in Linux (4) - based on s3c6410 platform
Next article:LCD device driver in Linux (3) - based on s3c6410 platform

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号