Embedded Linux Device Drivers for ARM Architecture

Review - IV Embedded Linux - I
Linux Device Driver:
1 Char Device Driver
2 Memory and I/O Access
3 Engineering Device Driver
2024/10/4
ARM201819
1
IV Embedded Linux - J
 
2024/10/4
ARM201819
2
Linux Device Driver
2024/10/4
ARM201819
3
4 Block device driver
5 Terminate device driver
6 IIC device driver
7 Network device driver
8 Audio device driver
9 LCD device driver
10 Flash device driver
11 USB device driver
12 PCI
 
device driver
13 Linux device driver debug
14 Linux device driver translate
4 Block device driver
 
2024/10/4
ARM201819
4
5 Terminate device driver
 
2024/10/4
ARM201819
5
6 IIC device driver
 
2024/10/4
ARM201819
6
7 Network device driver
 
2024/10/4
ARM201819
7
8 Audio device driver
 
2024/10/4
ARM201819
8
9 LCD device driver
9.1 LCD hardware principles
9.2 framebuffer principles
9.3 framebuffer driver architeture
9.4 framebuffer driver templates
9.5 framebuffer buffer request
9.6 framebuffer parameter setting
9.7 framebuffer fb_ops functions
9.8 framebuffer fb_fops functions
9.9 framebuffer user space access
9.10 Linux graphical user interface
9.11 Exynos LCD device driver
9.12 summary
2024/10/4
ARM201819
9
9.1 LCD hardware principles
LCD work timing
LCD timing parameters
2024/10/4
ARM201819
10
LCD work timing
 
2024/10/4
ARM201819
11
undefined
2024/10/4
ARM201819
12
LCD timing parameters
2024/10/4
ARM201819
13
9.2 framebuffer principles
9.2.1 framebuffer basic concept
9.2.2 framebuffer data format
9.2.3 framebuffer structures and functions
2024/10/4
ARM201819
14
9.2.1 framebuffer basic concept
Framebuffer
Display device interface, abstract of display buffer
Apps directly access, don’t care low-level hardware
/dev/fb
n
,
 
char
 
device,
 
major
 
device
 
number
 
is 29
X Windows
 
and
 
Qt are both based on framebuffer
2024/10/4
ARM201819
15
9.2.2 framebuffer data format
16 BPP: RGB 565
18 BPP: RGB666
24 BPP:
 
RGB 888
See Exynos4412 SoC user manual
2024/10/4
ARM201819
16
9.2.3 framebuffer structures and functions
fb_info
fb_ops
fb_var|fix_screeninfo
fb_bitfield
fb_cmap
fb_fops
{un}register_framebuffer()
2024/10/4
ARM201819
17
(1) fb_info
The most important structure of framebuffer
Description of device property and operations
Abbreviated as 
FBI (Federal Bureau of Investigation)
2024/10/4
ARM201819
18
fb_info
Variable parameters
Fixed parameters
Current color map
Framebuffer
 
operations
Screen
 
base
 
address
2024/10/4
ARM201819
19
struct fb_info
struct fb_info {
int node;
int flags;
struct fb_var_screeninfo var; //variable
struct fb_fix_screeninfo fix; //fixed
struct fb_monspecs monspecs;
struct work_struct queue;
2024/10/4
ARM201819
20
struct fb_info
struct fb_pixmap pixmap;
struct fb_pixmap sprite;
struct fb_cmap cmap; //color map
struct list_head modelist;
struct fb_videomode *mode;
2024/10/4
ARM201819
21
struct fb_info
struct backlight_device *bl_dev;
struct mutex bl_curve_mutex;
u8 bl_curve[FB_BACKLIGHT_LEVELS];
struct delayed_work deferred_work;
struct fb_deferred_io *fbdefio;
2024/10/4
ARM201819
22
struct fb_info
struct fb_ops *fbops; // = &exynosfb_ops
struct device *device;
struct device *dev;
int class_flag;
2024/10/4
ARM201819
23
struct fb_info
struct fb_tile_ops *tileops;
char __iomem *screen_base; //virtual address
unsigned long screen_size;
void *pseudo_palette;
2024/10/4
ARM201819
24
struct fb_info
#define FBINFO_STATE_RUNNING    0
#define FBINFO_STATE_SUSPENDED 1
u32 state;
void *fbcon_par;
void *par; // -> struct s3cfb_info
};
2024/10/4
ARM201819
25
(2) fb_ops
Maintain 
low level 
pointers of operation functions
Need driver developer to implement it
2024/10/4
ARM201819
26
fb_ops
Open and release
Display blank
Rectangle filling
Data copy
Graphical filling
Cursor drawing
Display rotation
2024/10/4
ARM201819
27
fb_ops
fb_check_var()
Check variable screen parameters and adjust them to
suitable values
fb_set_var()
Make screen parameters, set by user, effective in
hardware
2024/10/4
ARM201819
28
struct fb_ops
struct fb_ops {
// open/release and usage marking
struct module *owner;
int (*
fb_open
)(*info, int user);
int (*
fb_release
)(*info, int user);
2024/10/4
ARM201819
29
struct fb_ops
// get non settable parameters
int (*
fb_get_fix
)(*fix, int con, *info);
// get settable parameters
int (*
fb_get_var
)(*var, int con, *info);
// set settable parameters
int (*
fb_set_var
)(*var, int con, *info);
2024/10/4
ARM201819
30
struct fb_ops
// get colormap
int (*
fb_get_cmap
)(*cmap, kspc, con, *info);
// set colormap
int (*
fb_set_cmap
)(*cmap, kspc, con, *info);
// pan display (optional)
int (*fb_pan_display)(*var, int con, *info);
2024/10/4
ARM201819
31
struct fb_ops
// perform fb specific ioctl (optional)
int (*
fb_ioctl
)(*inode,*file,cmd,ag,cn,*info);
// perform fb specific mmap
int (*
fb_mmap
)(*info, *file, *vma);
// switch to/from raster image mode
int (*fb_rasterimg)(*info, int start);
};
2024/10/4
ARM201819
32
(3) fb_var|fix_screeninfo
fb_var_screeninfo
Display controller parameters which can be changed
by user
fb_fix_screeninfo
Display controller parameters which cannot be changed
by user
2024/10/4
ARM201819
33
fb_var_screeninfo
Visuable resolution
xres, yres
Bit per pixel
bits_per_pixel
Pixel data format
red/green/blue
Timing parameters
Sync pulse width: hsync/vsync_len
Margin: left/right/upper/lower_margin
Pixel clock: pixclock
2024/10/4
ARM201819
34
struct fb_var_screeninfo
struct fb_var_screeninfo
{
__u32 
xres
; // visible resolution
__u32 
yres
; // visible resolution
__u32 xres_virtual; // virtual resolution
__u32 yres_virtual;
__u32 xoffset; // offset from virtual to visible
__u32 yoffset;
2024/10/4
ARM201819
35
struct fb_var_screeninfo
__u32 
bits_per_pixel
;
__u32 grayscale;
struct fb_bitfield 
red
;
struct fb_bitfield 
green
;
struct fb_bitfield 
blue
;
struct fb_bitfield transp; // transparency
__u32 nonstd;
2024/10/4
ARM201819
36
struct fb_var_screeninfo
__u32 activate; // see FB_ACTIVATE_*
__u32 height; // height of picture in mm
__u32 width; // width of picture in mm
__u32 accel_flags; // acceleration flags
2024/10/4
ARM201819
37
struct fb_var_screeninfo
__u32 
pixclock
;//pixel clock in ps
__u32 
left_margin
;//time from sync to pic
__u32 
right_margin
;//time from pic to sync
__u32 
upper_margin
;//time from sync to pic
__u32 
lower_margin
;//time from pic to sync
__u32 
hsync_len
;//length of horizontal sync
__u32 
vsync_len
;//length of vertical sync
2024/10/4
ARM201819
38
undefined
2024/10/4
ARM201819
39
struct fb_var_screeninfo
__u32 sync; // see FB_SYNC_*
__u32 vmode; // see FB_VMODE_*
__u32 
rotate
; // clockwise rotation angle
__u32 reserved[6]; // Reserved for future
};
2024/10/4
ARM201819
40
fb_fix_screeninfo
Starting physical address of framebuffer
smem_start (physical address)
Framebuffer size
smem_len
Starting virtual address of I/O memory
mmio_start (virtual address)
Size of I/O memory mapped by framebuffer
mmio_len
2024/10/4
ARM201819
41
struct fb_fix_screeninfo
struct fb_fix_screeninfo {
char id[16]; // identification string
ulong 
smem_start
; // phys start addr of fb mem
__u32 
smem_len
; // length of fb mem
__u32 type; // see FB_TYPE_*
__u32 type_aux; // interleave for planes
__u32 visual; // see FB_VISUAL_*
2024/10/4
ARM201819
42
struct fb_fix_screeninfo
__u16 xpanstep; // zero if no hw panning
__u16 ypanstep; // zero if no hw panning
__u16 ywrapstep; // zero if no hw ywrap
__u32 line_length; // length of a line in bytes
2024/10/4
ARM201819
43
struct fb_fix_screeninfo
ulong 
mmio_start
; // virt start addr of Memory I/O
__u32 
mmio_len
; // length of Memory I/O
__u32 accel; // type of acceleration
__u16 reserved[3]; // reserved for future
};
2024/10/4
ARM201819
44
(4) fb_bitfield
Describe organization method of each pixel of
display buffer
2024/10/4
ARM201819
45
struct fb_bitfield
struct fb_bitfield {
__u32 offset; // beginning of bitfield
__u32 length; // length of bitfield
__u32 msb_right; // != 0 : MSB is right
};
2024/10/4
ARM201819
46
(5) fb_cmap
Record device-independent color map
2024/10/4
ARM201819
47
struct fbcmap
struct fb_cmap {
__u32 start; // first entry 
__u32 len; // number of entries 
__u16 *red; // red values
__u16 *green; // green values
__u16 *blue; // blue values
__u16 *transp; // transparency 
};
2024/10/4
ARM201819
48
(6) fb_
f
ops
File operation structure, discriminated from 
fb_ops
Located in 
drivers/video/fbmem.c
Interface function is device-independent
Interface function is existed, 
no need to rewrite
2024/10/4
ARM201819
49
struct file_operations fb_fops
static const struct file_operations fb_fops = {
.owner = THIS_MODULE,
.
read
 = fb_read,
.
write
 = fb_write,
.
ioctl
 = fb_ioctl,
.compat_ioctl = fb_compat_ioctl,
2024/10/4
ARM201819
50
struct file_operations fb_fops
.
mmap
 = fb_mmap,
.
open
 = fb_open,
.
release
 = fb_release,
.get_unmapped_area = 
get_fb_unmapped_area
,
.fsync = fb_deferred_io_fsync,
};
2024/10/4
ARM201819
51
(7) {un}register_framebuffer()
int 
register_framebuffer
(
fb_info * fbinfo
);
int 
unregister_framebuffer
(
fb_info * fbinfo
)
2024/10/4
ARM201819
52
9.3 framebuffer driver architecture
fbmeme.c
file_operations: hardware-independent operations
xxxfb.c
fb_info
fb_ops: hardware-dependent operations
2024/10/4
ARM201819
53
undefined
2024/10/4
ARM201819
54
9.4 framebuffer driver templates
Programming template of framebuffer driver
Programming template of framebuffer 
platform
 driver
2024/10/4
ARM201819
55
Template of framebuffer driver
2024/10/4
ARM201819
56
Load function of framebuffer module
Request memory of FBI structure and initialize its fixed
and variable parameters
Initialize display controller according to LCD screen
Request display buffer of framebuffer device
Register framebuffer device
Unload function of framebuffer module
Do inverse work of load function
Template of framebuffer platform driver
Platform driver
LCD controller is in SoC and becomes platform driver
Load function of framebuffer platform driver
Register
 
framebuffer platform driver
Turn over
 
initialization of fixed and variable parameters of
FBI structure, initialization of LCD controller, request for
display buffer of framebuffer device and register of
framebuffer device
 to 
probe function 
of platform driver
LCD initialization is independent (probe)
Unload function of framebuffer platform driver
Unregister
 
framebuffer platform driver
Turn over 
inverse work 
to 
remove function 
of platform driver
2024/10/4
ARM201819
57
Framebuffer platform driver structure
struct platform_driver xxxfb_driver
 = {
.probe = 
xxxfb_probe
,
.remove = 
xxxfb_remove
,
.suspend = xxxfb_suspend,
.resume = xxxfb_resume,
.driver = { .name     = “xxx-lcd",
                .owner    = THIS_MODULE,
              },
};
2024/10/4
ARM201819
58
Framebuffer platform driver probe function
static int __init 
xxxfb_probe
(struct platform_device *pdev)
{
2024/10/4
ARM201819
59
Framebuffer platform driver probe function
//define pointer to fb_info structure
struct fb_info *
info
;
2024/10/4
ARM201819
60
Framebuffer platform driver probe function
//allocate memory for fb_info structure
info = 
framebuffer_alloc
(……);
2024/10/4
ARM201819
61
Framebuffer platform driver probe function
//initialize fb_info structure
info->
screen_base
 = 
fb_virtual_memory
; //later
info->
var
 = xxxfb_var;//variable parameter
info->
fix
 = xxxfb_fix;//fixed parameter
//info->screen_base: 
VA of frame buffer
//info->fix.smem_start:
 
PA of framebuffer
2024/10/4
ARM201819
62
Framebuffer platform driver probe function
//allocate memory for display buffer
alloc_dis_buffer
(); //
initialize
 
fb_virtual_memory
2024/10/4
ARM201819
63
Framebuffer platform driver probe function
//initialize LCD controller by independent function
lcd_init
();
2024/10/4
ARM201819
64
Framebuffer platform driver probe function
//check variable parameters
xxxfb_check
(&info->var, info);
2024/10/4
ARM201819
65
Framebuffer platform driver probe function
//register structure fb_info
if (
register_framebuffer
(info) < 0)
       return –EINVAL;
2024/10/4
ARM201819
66
Framebuffer platform driver probe function
//return
return 0;
}
2024/10/4
ARM201819
67
Framebuffer platform driver remove function
static int __init 
xxxfb_remove
(struct platform_device *pdev)
{
2024/10/4
ARM201819
68
Framebuffer platform driver remove function
// get the pointer to structure fb_info
struct fb_info *
info
 = 
dev_get_drv_data
();
2024/10/4
ARM201819
69
Framebuffer platform driver remove function
if (info)
{
unregister_framebuffer
(info);//unregister fb_info
dealloc_dis_buffer
(……);//release display buffer
framebuffer_release
(info);//release
 
fb_info
}
2024/10/4
ARM201819
70
Framebuffer platform driver remove function
return 0;
}
2024/10/4
ARM201819
71
Framebuffer load function
int __init 
xxxfb_init
(void)
{
return 
platform_driver_register
(&xxxfb_driver);
}
module_init
(xxxfb_init);
2024/10/4
ARM201819
72
Framebuffer unload function
static void __exit 
xxxfb_exit
(void)
{
platform_driver_unregister
(&xxxfb_driver);
}
module_exit
(xxxfb_exit);
2024/10/4
ARM201819
73
9.5 framebuffer buffer request
2024/10/4
ARM201819
74
9.6 framebuffer parameter setting
9.6.1 timing parameter
9.6.2 pixel clock
9.6.3 color bit field
9.6.4 fixed parameter
2024/10/4
ARM201819
75
9.6.1 timing parameter
Search LCD user manual
left _margin
right _margin
upper_margin
lower_margin
hsync_len
vsync_ len
2024/10/4
ARM201819
76
9.6.2 pixel colock
See
 
Exynos4412 LCD controller frame rate
compputing
2024/10/4
ARM201819
77
9.6.3 color bit field
The red, green and blue field setting of FBI
variable parameters is directly determined by the
congruent relationship between display buffer and
display point
2024/10/4
ARM201819
78
Example
RGB666
According to
 
Exynos4412 user manual:
red occupies 6 bits, offset is 12 bits
green occupies 6 bits, offset is 6 bits
blue occupies 6 bits, offset is 0 bit
2024/10/4
ARM201819
79
Example
RGB666
fbinfo - >var.red.offset = 12;
fbinfo - >var.green.offset = 6;
fbinfo - >var.blue.offset = 0;
fbinfo - >var.red.length = 6;
fbinfo - >var.green.length = 6;
fbinfo - >var.blue.lenght = 6;
2024/10/4
ARM201819
80
9.6.4 fixed parameter
smem_start
 = physics address of SDRAM;
smem_len
 = max_xres*max_yres*max_bpp;
2024/10/4
ARM201819
81
9.7 framebuffer fb_ops functions
2024/10/4
ARM201819
82
fb_check_var()
fb_set_var()
fb_fillrect()/copyarea()/imagelbit()
cfb_fillrect()/copyarea()/imagelbit()
drivers/video/cfbfillrect|copyarea|imageblt.c
User can modify depending on need
fb_setcolreg()
Implemnet pseudo color table and color table filling
User can modify depending on need
9.8 framebuffer fb_fops functions
2024/10/4
ARM201819
83
fb_mem.c:
fb_read()
fb_write()
fb_mmap(): display buffer maps to user space
fb_ioctl()
9.9 framebuffer user space access
Operations of user space access
Flowchart of user space access
Template of user space access
2024/10/4
ARM201819
84
(1) Operations of user space access
open/release/read/write operations
frambuffer device file: /dev/fbn
cp /dev/fbn xxx
cp xxx > /dev/fbn
mapping operation
mmap()
I/O
 
control
ioctl()
2024/10/4
ARM201819
85
(2) Flowchart of user space access
2024/10/4
ARM201819
86
Template of user space access
2024/10/4
ARM201819
87
The programming template of user space access to
framebuffer
undefined
2024/10/4
ARM201819
88
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
undefined
2024/10/4
ARM201819
89
int main()
{
undefined
2024/10/4
ARM201819
90
int fbfd = 0; //framebuffer device file ID
struct fb_var_screeninfo vinfo; //variable info
ulong screensize = 0; //size of user space memory
char * fbp = 0; //user space pointer
int x = 0, y = 0;
int i  = 0;
undefined
2024/10/4
ARM201819
91
// Open framebuffer device file for accessing
fbfd
 = 
open
("
/dev/fb0
", O_ RDWR);
if (!fbfd) {
    printf("can’t open framebuffer.\n");
    exit(1);
}
printf("frambuffer was opened successfully.\n");
undefined
2024/10/4
ARM201819
92
// Get variable screen information
if (
ioctl
(fbfd, FBIOGET_VSCREENINFO, 
&vinfo
)
) {
    printf(“error reading variable info.\n");
    exit(1);
}
undefined
2024/10/4
ARM201819
93
// Printf()
printf("%dx%d, %dbpp\ n", vinfo.xres, vinfo.yres,
vinfo.bits_ per _ pixel);
if (vinfo.bits_ per _ pixel != 16) {
    printf("Error: only supports 16 bit\n");
    exit(1);
}
undefined
2024/10/4
ARM201819
94
// Figure out the size of the screen in bytes
screensize
 =  vinfo.xres*vinfo.yres*2;
undefined
2024/10/4
ARM201819
95
 // Map framebuffer to user space memory
fbp
 = (char * )
mmap
(0, 
screensize
, PROT_ READ |
PROT _WRITE, MAP_SHARED, 
fbfd
, 0);
if ((int)fbp ==  - 1) {
    printf("Error: failed to map framebuffer to user
space memory.\n");
    exit(1);
}
printf("frambuffer was mapped to mem.\ n");
undefined
2024/10/4
ARM201819
96
// Draw 3 rect with graduated RED/GREEN/BLUE
for (i = 0; i < 3; i++) {
    for (y=i*(vinfo.yres/3);y<(i+1)*(vinfo.yres/3);y++) {
        for (x=0;x<vinfo.xres;x++) {
            long location = x*2 + y*vinfo.xres*2;
            int r = 0, g = 0, b = 0;  unsigned short rgb;
            if (i  == 0)  r = ((x * 1.0) / vinfo.xres) * 32;
            if (i == 1)  g = ((x *  1.0) / vinfo.xres) * 64;
            if (i == 2)  b = ((x *  1.0) / vinfo.xres) * 32;
            rgb = (r << 11) | (g << 5) | b;
            * ((unsigned short * )(fbp + location)) = rgb;
        }
   }
}
undefined
2024/10/4
ARM201819
97
// munmap()
munmap
(fbp, screensize);
undefined
2024/10/4
ARM201819
98
// close()
close
(fbfd);
undefined
2024/10/4
ARM201819
99
return 0;
}
9.10 Linux graphical user interface
9.10.1 Qt-X11/Embedded/Qtopia
9.10.2 Microwindows/Nano-X
9.10.3 MiniGUI
9.10.4 Android
2024/10/4
ARM201819
100
9.10.1 Qt-X11/Embedded/Qtopia
 
2024/10/4
ARM201819
101
Qt
2024/10/4
ARM201819
102
9.10.2 Microwindows/Nano-X
 
2024/10/4
ARM201819
103
9.10.3 MiniGUI
 
2024/10/4
ARM201819
104
9.10.4 Android
Qt based
2024/10/4
ARM201819
105
9.11 Exynos LCD device driver
drivers/video/samsung
exynos
fb.c
exynos
fb_fimd6x.c
Exynos4412 display controller FIMD6.0
exynos
fb_wanxin.c
LCD timing and hardware parameter control
Need to modify it when changing LCD
2024/10/4
ARM201819
106
Exynos4412 display controller
2024/10/4
ARM201819
107
Exynos4412 LCD interface
 
2024/10/4
ARM201819
108
undefined
2024/10/4
ARM201819
109
exynosfb.c framework
See programming template of framebuffer
2024/10/4
ARM201819
110
exynosfb_wanxin.c timing and hardware parameter
Read LCD user manual
EXYNOSFB_ HFP
EXYNOSFB_ HSW
EXYNOSFB_ HBP
EXYNOSFB_ VFP
EXYNOSFB_ VSW
EXYNOSFB_ VBP
Modify when changing LCD
2024/10/4
ARM201819
111
exynosfb_wanxin.c timing and hardware parameter
#define 
EXYNOSFB_HFP  
2 //front porch
#define 
EXYNOSFB_HSW 
41 //hsync width
#define 
EXYNOSFB_HBP  
2 //back porch
#define 
EXYNOSFB_VFP  
2 //front porch
#define 
EXYNOSFB_VSW 
10 //vsync width
#define 
EXYNOSFB_VBP  
2 //back porch
2024/10/4
ARM201819
112
exynosfb_wanxin.c timing and hardware parameter
#define 
EXYNOSFB_HRES 
1024 //x resolution
#define 
EXYNOSFB_VRES 
768 //y resolution
#define 
EXYNOSFB_HRES_VIRTUAL 
1024
#define 
EXYNOSFB_VRES_VIRTUAL 
(768* 2)
#define 
EXYNOSFB_HRES_OSD 
1024
#define 
EXYNOSFB_VRES_OSD 
768
2024/10/4
ARM201819
113
exynosfb_wanxin.c timing and hardware parameter
// frame rate freq
#define 
EXYNOSFB _VFRAME_FREQ  
60
#define 
EXYNOSFB _PIXEL_CLOCK 
\
    (
EXYNOSFB_ FRAME_FREQ 
* \
    (EXYNOSFB_HFP + EXYNOSFB_H SW + \
     EXYNOSFB_HBP + EXYNOSFB_HRES)  * \
    (EXYNOSFB_ FP + EXYNOSFB_VSW + \
     EXYNOSFB_VBP + EXYNOSFB_VRES))
2024/10/4
ARM201819
114
exynosfb_wanxin.c timing and hardware parameter
static void 
exynosfb_set_fimd_info
(void){ ... }
int 
exynosfb_wanxin_set_gpio
(void) { ... }
void 
exynosfb_init_hw
(void)
{
printk(KERN_INFO "LCD initialized\n");
exynosfb_set_fimd_info
(); 
exynosfb_wanxin_set_gpio
();
}
2024/10/4
ARM201819
115
9.12 summary
LCD hardware principle
framebuffer principle
framebuffer driver structure
framebuffer load/unload function
framebuffer buffer request/free
framebuffer parameter setting
framebuffer fb_ops member function
framebuffer fb_fops member function
framebuffer user space access
Linux graphical user interface
Exynos LCD device driver
2024/10/4
ARM201819
116
Exercises
1 Draw the
 
block
 
diagram
 
of
 
framebuffer driver
architecture.
2 Write the programming template of framebuffer
platform
 driver.
3 Write the programming template of user space
access to framebuffer.
2024/10/4
ARM201819
117
Solutions
 
2024/10/4
ARM201819
118
10 Flash device driver
 
2024/10/4
ARM201819
119
11 USB device driver
 
2024/10/4
ARM201819
120
12 PCI device driver
 
2024/10/4
ARM201819
121
13 Linux device driver debugging
 
2024/10/4
ARM201819
122
14 Linux device driver transplanting
 
2024/10/4
ARM201819
123
Slide Note
Embed
Share

Explore the intricate world of Linux device drivers with a focus on ARM architecture. Delve into topics like character device drivers, memory and I/O access, block device drivers, and various other driver types. Gain insights into the principles and workings of LCD drivers, IIC drivers, network drivers, and more, in this comprehensive study of Embedded Linux.

  • Embedded Linux
  • Device Drivers
  • ARM Architecture
  • Linux
  • Driver Development

Uploaded on Oct 04, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Review - IV Embedded Linux - I 1 Linux Device Driver: 1 Char Device Driver 2 Memory and I/O Access 3 Engineering Device Driver ARM201819 2024/10/4

  2. IV Embedded Linux - J 2 ARM201819 2024/10/4

  3. Linux Device Driver 3 4 Block device driver 5 Terminate device driver 6 IIC device driver 7 Network device driver 8 Audio device driver 9 LCD device driver 10 Flash device driver 11 USB device driver 12 PCI device driver 13 Linux device driver debug 14 Linux device driver translate ARM201819 2024/10/4

  4. 4 Block device driver 4 ARM201819 2024/10/4

  5. 5 Terminate device driver 5 ARM201819 2024/10/4

  6. 6 IIC device driver 6 ARM201819 2024/10/4

  7. 7 Network device driver 7 ARM201819 2024/10/4

  8. 8 Audio device driver 8 ARM201819 2024/10/4

  9. 9 LCD device driver 9 9.1 LCD hardware principles 9.2 framebuffer principles 9.3 framebuffer driver architeture 9.4 framebuffer driver templates 9.5 framebuffer buffer request 9.6 framebuffer parameter setting 9.7 framebuffer fb_ops functions 9.8 framebuffer fb_fops functions 9.9 framebuffer user space access 9.10 Linux graphical user interface 9.11 Exynos LCD device driver 9.12 summary ARM201819 2024/10/4

  10. 9.1 LCD hardware principles 10 LCD work timing LCD timing parameters ARM201819 2024/10/4

  11. LCD work timing 11 ARM201819 2024/10/4

  12. VSPW (vertical sync pulse width) VBPD (vertical back porch delay) VFPD (vertical front porch delay) HSPW (horizontal sync pulse width) HBPD (horizontal back porch delay) HFPD (horizontal front porch delay) ARM201819 2024/10/4 12

  13. LCD timing parameters 13 VSPW+1 VBPD+1 LINEVAL+1 HSPW+1 HBPD+1 HFPD+1 HOZVAL+1 VFPD+1 ARM201819 2024/10/4

  14. 9.2 framebuffer principles 14 9.2.1 framebuffer basic concept 9.2.2 framebuffer data format 9.2.3 framebuffer structures and functions ARM201819 2024/10/4

  15. 9.2.1 framebuffer basic concept 15 Framebuffer Display device interface, abstract of display buffer Apps directly access, don t care low-level hardware /dev/fbn, char device, major device number is 29 X Windows and Qt are both based on framebuffer ARM201819 2024/10/4

  16. 9.2.2 framebuffer data format 16 16 BPP: RGB 565 18 BPP: RGB666 24 BPP: RGB 888 See Exynos4412 SoC user manual ARM201819 2024/10/4

  17. 9.2.3 framebuffer structures and functions 17 fb_info fb_ops fb_var|fix_screeninfo fb_bitfield fb_cmap fb_fops {un}register_framebuffer() ARM201819 2024/10/4

  18. (1) fb_info 18 The most important structure of framebuffer Description of device property and operations Abbreviated as FBI (Federal Bureau of Investigation) ARM201819 2024/10/4

  19. fb_info 19 Variable parameters Fixed parameters Current color map Framebuffer operations Screen base address ARM201819 2024/10/4

  20. struct fb_info 20 struct fb_info { int node; int flags; struct fb_var_screeninfo var; //variable struct fb_fix_screeninfo fix; //fixed struct fb_monspecs monspecs; struct work_struct queue; ARM201819 2024/10/4

  21. struct fb_info 21 struct fb_pixmap pixmap; struct fb_pixmap sprite; struct fb_cmap cmap; //color map struct list_head modelist; struct fb_videomode *mode; ARM201819 2024/10/4

  22. struct fb_info 22 struct backlight_device *bl_dev; struct mutex bl_curve_mutex; u8 bl_curve[FB_BACKLIGHT_LEVELS]; struct delayed_work deferred_work; struct fb_deferred_io *fbdefio; ARM201819 2024/10/4

  23. struct fb_info 23 struct fb_ops *fbops; // = &exynosfb_ops struct device *device; struct device *dev; int class_flag; ARM201819 2024/10/4

  24. struct fb_info 24 struct fb_tile_ops *tileops; char __iomem *screen_base; //virtual address unsigned long screen_size; void *pseudo_palette; ARM201819 2024/10/4

  25. struct fb_info 25 #define FBINFO_STATE_RUNNING 0 #define FBINFO_STATE_SUSPENDED 1 u32 state; void *fbcon_par; void *par; // -> struct s3cfb_info }; ARM201819 2024/10/4

  26. (2) fb_ops 26 Maintain low level pointers of operation functions Need driver developer to implement it ARM201819 2024/10/4

  27. fb_ops 27 Open and release Display blank Rectangle filling Data copy Graphical filling Cursor drawing Display rotation ARM201819 2024/10/4

  28. fb_ops 28 fb_check_var() Check variable screen parameters and adjust them to suitable values fb_set_var() Make screen parameters, set by user, effective in hardware ARM201819 2024/10/4

  29. struct fb_ops 29 struct fb_ops { // open/release and usage marking struct module *owner; int (*fb_open)(*info, int user); int (*fb_release)(*info, int user); ARM201819 2024/10/4

  30. struct fb_ops 30 // get non settable parameters int (*fb_get_fix)(*fix, int con, *info); // get settable parameters int (*fb_get_var)(*var, int con, *info); // set settable parameters int (*fb_set_var)(*var, int con, *info); ARM201819 2024/10/4

  31. struct fb_ops 31 // get colormap int (*fb_get_cmap)(*cmap, kspc, con, *info); // set colormap int (*fb_set_cmap)(*cmap, kspc, con, *info); // pan display (optional) int (*fb_pan_display)(*var, int con, *info); ARM201819 2024/10/4

  32. struct fb_ops 32 // perform fb specific ioctl (optional) int (*fb_ioctl)(*inode,*file,cmd,ag,cn,*info); // perform fb specific mmap int (*fb_mmap)(*info, *file, *vma); // switch to/from raster image mode int (*fb_rasterimg)(*info, int start); }; ARM201819 2024/10/4

  33. (3) fb_var|fix_screeninfo 33 fb_var_screeninfo Display controller parameters which can be changed by user fb_fix_screeninfo Display controller parameters which cannot be changed by user ARM201819 2024/10/4

  34. fb_var_screeninfo 34 Visuable resolution xres, yres Bit per pixel bits_per_pixel Pixel data format red/green/blue Timing parameters Sync pulse width: hsync/vsync_len Margin: left/right/upper/lower_margin Pixel clock: pixclock ARM201819 2024/10/4

  35. struct fb_var_screeninfo 35 struct fb_var_screeninfo { __u32 xres; // visible resolution __u32 yres; // visible resolution __u32 xres_virtual; // virtual resolution __u32 yres_virtual; __u32 xoffset; // offset from virtual to visible __u32 yoffset; ARM201819 2024/10/4

  36. struct fb_var_screeninfo 36 __u32 bits_per_pixel; __u32 grayscale; struct fb_bitfield red; struct fb_bitfield green; struct fb_bitfield blue; struct fb_bitfield transp; // transparency __u32 nonstd; ARM201819 2024/10/4

  37. struct fb_var_screeninfo 37 __u32 activate; // see FB_ACTIVATE_* __u32 height; // height of picture in mm __u32 width; // width of picture in mm __u32 accel_flags; // acceleration flags ARM201819 2024/10/4

  38. struct fb_var_screeninfo 38 __u32 pixclock;//pixel clock in ps __u32 left_margin;//time from sync to pic __u32 right_margin;//time from pic to sync __u32 upper_margin;//time from sync to pic __u32 lower_margin;//time from pic to sync __u32 hsync_len;//length of horizontal sync __u32 vsync_len;//length of vertical sync ARM201819 2024/10/4

  39. VSPW+1 (vsync_len) VBPD+1 (upper_margin) LINEVAL+1 (yres) HSPW+1 (hsync_len) HBPD+1 (left_margin) HFPD+1 (right_margin) HOZVAL+1 (xres) VFPD+1 (lower_margin) ARM201819 2024/10/4 39

  40. struct fb_var_screeninfo 40 __u32 sync; // see FB_SYNC_* __u32 vmode; // see FB_VMODE_* __u32 rotate; // clockwise rotation angle __u32 reserved[6]; // Reserved for future }; ARM201819 2024/10/4

  41. fb_fix_screeninfo 41 Starting physical address of framebuffer smem_start (physical address) Framebuffer size smem_len Starting virtual address of I/O memory mmio_start (virtual address) Size of I/O memory mapped by framebuffer mmio_len ARM201819 2024/10/4

  42. struct fb_fix_screeninfo 42 struct fb_fix_screeninfo { char id[16]; // identification string ulong smem_start; // phys start addr of fb mem __u32 smem_len; // length of fb mem __u32 type; // see FB_TYPE_* __u32 type_aux; // interleave for planes __u32 visual; // see FB_VISUAL_* ARM201819 2024/10/4

  43. struct fb_fix_screeninfo 43 __u16 xpanstep; // zero if no hw panning __u16 ypanstep; // zero if no hw panning __u16 ywrapstep; // zero if no hw ywrap __u32 line_length; // length of a line in bytes ARM201819 2024/10/4

  44. struct fb_fix_screeninfo 44 ulong mmio_start; // virt start addr of Memory I/O __u32 mmio_len; // length of Memory I/O __u32 accel; // type of acceleration __u16 reserved[3]; // reserved for future }; ARM201819 2024/10/4

  45. (4) fb_bitfield 45 Describe organization method of each pixel of display buffer ARM201819 2024/10/4

  46. struct fb_bitfield 46 struct fb_bitfield { __u32 offset; // beginning of bitfield __u32 length; // length of bitfield __u32 msb_right; // != 0 : MSB is right }; ARM201819 2024/10/4

  47. (5) fb_cmap 47 Record device-independent color map ARM201819 2024/10/4

  48. struct fbcmap 48 struct fb_cmap { __u32 start; // first entry __u32 len; // number of entries __u16 *red; // red values __u16 *green; // green values __u16 *blue; // blue values __u16 *transp; // transparency }; ARM201819 2024/10/4

  49. (6) fb_fops 49 File operation structure, discriminated from fb_ops Located in drivers/video/fbmem.c Interface function is device-independent Interface function is existed, no need to rewrite ARM201819 2024/10/4

  50. struct file_operations fb_fops 50 static const struct file_operations fb_fops = { .owner = THIS_MODULE, .read = fb_read, .write = fb_write, .ioctl = fb_ioctl, .compat_ioctl = fb_compat_ioctl, ARM201819 2024/10/4

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#