Introduction to Linux Frame Buffer Driver Model Jollen's Consulting | Jollen
[email protected] http://www.jollen.org 演講日期 : 2007 年 8 月 29 日(週三) 演講地點 : 國立政治大學公共行政及企業管理教育中心 主辦單位:經濟部工業局
1. Background Knowledge 2. s3c2410fb.c as an example
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
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
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
Traditional Device Driver Model VFS
Driver D
Driver B Driver A
Driver E Driver C
New Linux 2.6 Driver Model kernel
buses devices classes firmware Core Driver Model – Subsystems (ksets…)
kobject
Driver D
Driver B Driver A
Driver E Driver C
/sys
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 )
TFT-LCD 驅動程式設定 • Device Drivers -> Graphics support
Drivers/video CONFIG_FB CONFIG_FB_S3C2410 Files: linux/drivers/video/s3c2410fb.c
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
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
Porting Your Machine
Platform bus
buses System bus
Core Driver Model – Subsystems (ksets…)
s3c2410fb
kobject
/sys
使用 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); }
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; … }
整體關係 Platform bus
buses System bus
kobject
Core Driver Model – Subsystems (ksets…)
/sys
probe() callback
VFS switch s3c2410fb fbmem Register to…
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 層做註冊。
fb_ops static 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, };
Set s3c2410 LCD Controller static 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; }
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, },
{END}