23
Introduction to Linux Frame Buffer Driver Model Jollen's Consulting | Jollen [email protected] http://www.jollen.org 演講日期 : 2007 8 29 日(週三) 演講地點 : 國立政治大學公共行政及企業管理教育中心 主辦單位:經濟部工業局

Linux FB Driver Intro v0.2

Embed Size (px)

DESCRIPTION

linux frame buffer

Citation preview

Page 1: Linux FB Driver Intro v0.2

Introduction to Linux Frame Buffer Driver Model

Jollen's Consulting | [email protected]

http://www.jollen.org

演講日期 : 2007 年 8 月 29 日(週三)

演講地點 : 國立政治大學公共行政及企業管理教育中心

主辦單位:經濟部工業局

Page 2: Linux FB Driver Intro v0.2

1. Background Knowledge

2. s3c2410fb.c as an example

Page 3: Linux FB Driver Intro v0.2

Linux 2.6 Driver Model• Linux Kernel Driver Model• Generic, centralized driver model• A unification of all the disparate driver

models that were previously used in the kernel.

• See– include/linux/device.h – driver/base/driver.c

Source: linux/Documentation/driver-model/overview.txt

Page 4: Linux FB Driver Intro v0.2

Ideas and Benefits• It is intended to augment the bus-specific

drivers for bridges and devices by consolidating a set of data and operations into globally accessible data structures.

• Traditional driver models implemented some sort of tree-like structure (sometimes just a list) for the devices they control. There wasn't any uniformity across the different bus types.

Source: linux/Documentation/driver-model/overview.txt

Page 5: Linux FB Driver Intro v0.2

Platform Driver• Drivers for platform devices are typically

very simple and unstructured. Either the device was present at a particular I/O port and the driver was loaded, or it was not.

• There was no possibility of hotplugging or alternative discovery besides probing at a specific I/O address and expecting a specific response.

Source: linux/Documentation/driver-model/platform.txt

Page 6: Linux FB Driver Intro v0.2

Traditional Device Driver Model

VFS

Driver A

Driver B

Driver C

Driver D

Driver E

Page 7: Linux FB Driver Intro v0.2

Core Driver Model – Subsystems (ksets…)

New Linux 2.6 Driver Model

Driver A

Driver B

Driver C

Driver D

Driver E

buses devices classes firmwarekernel

/syskobject

Page 8: Linux FB Driver Intro v0.2

Consolusion

• Generic device driver– 驅動程式開發者的框架( framework )、特定

裝置的驅動程式設計( architecture )或kernel API

• kobject– A unification of all the disparate driver models

that were previously used in the kernel.• Platform driver

– Linux 2.6 的 machine-dependent driver ( low-level )

Page 9: Linux FB Driver Intro v0.2

TFT-LCD 驅動程式設定

• Device Drivers -> Graphics support

Drivers/videoCONFIG_FBCONFIG_FB_S3C2410Files: linux/drivers/video/s3c2410fb.c

Page 10: Linux FB Driver Intro v0.2

Linux FB Subsystem• linux/drivers/video/dummycon.c

– A dummy console driver• linux/drivers/video/fbcmap.c

– Colormap handling for frame buffer devices• linux/drivers/video/fbcon.c

– Low level frame buffer based console driver• linux/drivers/video/cfbxx.c

– Low level frame buffer operations for xx bpp truecolor packed pixels

• linux/drivers/video/fbcon-vga.c– Low level frame buffer operations for VGA characters/attributes

Page 11: Linux FB Driver Intro v0.2

cont...• linux/drivers/video/fbgen.c

– Generic routines for frame buffer devices• linux/drivers/video/fbmem.c

– Core of Linux Framebuffer subsystem • linux/drivers/video/font_*.c

– Fonts• linux/drivers/video/vesafb.c

– framebuffer driver for VBE 2.0 compliant graphic boards, see arch/i386/boot/video.S

• linux/drivers/video/vfb.c– Virtual frame buffer device

• linux/drivers/video/vgacon.c– Low level VGA based console driver

• linux/drivers/video/s3c2410fb.c– Low-level framebuffer driver for S3C2410

Page 12: Linux FB Driver Intro v0.2

Porting Your Machine

Core Driver Model – Subsystems (ksets…)

s3c2410fb

buses

/syskobject

Platform bus

System bus

Page 13: Linux FB Driver Intro v0.2

使用 Platform Driver 觀念

static struct platform_driver s3c2410fb_driver = {.probe = s3c2410fb_probe,.remove = s3c2410fb_remove,.suspend = s3c2410fb_suspend,.resume = s3c2410fb_resume,.driver = {

.name = "s3c2410-lcd",

.owner = THIS_MODULE,},

};

int __devinit s3c2410fb_init(void){

return platform_driver_register(&s3c2410fb_driver);}

static void __exit s3c2410fb_cleanup(void){

platform_driver_unregister(&s3c2410fb_driver);}

Page 14: Linux FB Driver Intro v0.2

probe() callback 註冊到 fbmem

static int __init s3c2410fb_probe(struct platform_device *pdev){ struct fb_info *fbinfo;

…ret = register_framebuffer(fbinfo);if (ret < 0) {

printk(KERN_ERR "Failed to register framebuffer device: %d\n", ret);

goto free_video_memory;…

}

Page 15: Linux FB Driver Intro v0.2

整體關係

Core Driver Model – Subsystems (ksets…)

s3c2410fb

buses

/syskobject

Platform bus

System bus

VFS switchprobe() callback

fbmem

Register to…

Page 16: Linux FB Driver Intro v0.2

s3c2410fb_probe()填寫 struct fb_info 表格,這是 low-level 的 framebuffer 向上層註冊所要

傳入的 fops 資料結構。

填寫 struct fb_var_screeninfo 表格 (console display)

填寫 struct fb_ops / fb operations

Request memory region / request IRQ 。

設定 S3C2410 的 GPIO 腳位功能 / 設定為 LCD controller 。

register_framebuffer() :向 fbmem.c 層做註冊。

Page 17: Linux FB Driver Intro v0.2

fb_opsstatic struct fb_ops s3c2410fb_ops = { .owner = THIS_MODULE, .fb_check_var = s3c2410fb_check_var, .fb_set_par = s3c2410fb_set_par, .fb_blank = s3c2410fb_blank, .fb_setcolreg = s3c2410fb_setcolreg, .fb_fillrect = cfb_fillrect, .fb_copyarea = cfb_copyarea, .fb_imageblit = cfb_imageblit,};

Page 18: Linux FB Driver Intro v0.2

Set s3c2410 LCD Controllerstatic int s3c2410fb_set_par(struct fb_info *info){ struct s3c2410fb_info *fbi = info->par; struct fb_var_screeninfo *var = &info->var; ... s3c2410fb_activate_var(fbi, var); return 0;}

Page 19: Linux FB Driver Intro v0.2
Page 20: Linux FB Driver Intro v0.2
Page 21: Linux FB Driver Intro v0.2

LCD Controller: dirty code reg : { lcdcon1 : LCD1_BPP_24T | LCD1_PNR_TFT | LCD1_CLKVAL(8) , lcdcon2 : LCD2_VBPD(9) | LCD2_VFPD(2) | LCD2_VSPW(1), lcdcon3 : LCD3_HBPD(19) | LCD3_HFPD(2), lcdcon4 : LCD4_HSPW(5) | LCD4_MVAL(13), lcdcon5 : LCD5_INVVLINE | LCD5_INVVFRAME, },

Page 22: Linux FB Driver Intro v0.2
Page 23: Linux FB Driver Intro v0.2

{END}