一、開發(fā)環(huán)境
主 ?機(jī):VMWare--Fedora 9
開發(fā)板:Mini2440--64MB Nand, Kernel:2.6.30.4
二、背景知識
1. LCD工作的硬件需求:
要使一塊LCD正常的顯示文字或圖像,不僅需要LCD驅(qū)動器,而且還需要相應(yīng)的LCD控制器。在通常情況下,生產(chǎn)廠商把LCD驅(qū)動器會以COF/COG的形式與LCD玻璃基板制作在一起,而LCD控制器則是由外部的電路來實(shí)現(xiàn),現(xiàn)在很多的MCU內(nèi)部都集成了LCD控制器,如S3C2410/2440等。通過LCD控制器就可以產(chǎn)生LCD驅(qū)動器所需要的控制信號來控制STN/TFT屏了。
2. S3C2440內(nèi)部LCD控制器結(jié)構(gòu)圖:
我們根據(jù)數(shù)據(jù)手冊來描述一下這個集成在S3C2440內(nèi)部的LCD控制器:
a:LCD控制器由REGBANK、LCDCDMA、TIMEGEN、VIDPRCS寄存器組成;
b:REGBANK由17個可編程的寄存器組和一塊256*16的調(diào)色板內(nèi)存組成,它們用來配置LCD控制器的;
c:LCDCDMA是一個專用的DMA,它能自動地把在偵內(nèi)存中的視頻數(shù)據(jù)傳送到LCD驅(qū)動器,通過使用這個DMA通道,視頻數(shù)據(jù)在不需要CPU的干預(yù)的情況下顯示在LCD屏上;
d:VIDPRCS接收來自LCDCDMA的數(shù)據(jù),將數(shù)據(jù)轉(zhuǎn)換為合適的數(shù)據(jù)格式,比如說4/8位單掃,4位雙掃顯示模式,然后通過數(shù)據(jù)端口VD[23:0]傳送視頻數(shù)據(jù)到LCD驅(qū)動器;
e:TIMEGEN由可編程的邏輯組成,他生成LCD驅(qū)動器需要的控制信號,比如VSYNC、HSYNC、VCLK和LEND等等,而這些控制信號又與REGBANK寄存器組中的LCDCON1/2/3/4/5的配置密切相關(guān),通過不同的配置,TIMEGEN就能產(chǎn)生這些信號的不同形態(tài),從而支持不同的LCD驅(qū)動器(即不同的STN/TFT屏)。
3. 常見TFT屏工作時序分析:
LCD提供的外部接口信號:
VSYNC/VFRAME/STV:垂直同步信號(TFT)/幀同步信號(STN)/SEC TFT信號;
HSYNC/VLINE/CPV:水平同步信號(TFT)/行同步脈沖信號(STN)/SEC TFT信號;
VCLK/LCD_HCLK:象素時鐘信號(TFT/STN)/SEC TFT信號;
VD[23:0]:LCD像素?cái)?shù)據(jù)輸出端口(TFT/STN/SEC TFT);
VDEN/VM/TP:數(shù)據(jù)使能信號(TFT)/LCD驅(qū)動交流偏置信號(STN)/SEC TFT 信號;
LEND/STH:行結(jié)束信號(TFT)/SEC TFT信號;
LCD_LPCOE:SEC TFT OE信號;
LCD_LPCREV:SEC TFT REV信號;
LCD_LPCREVB:SEC TFT REVB信號。
所有顯示器顯示圖像的原理都是從上到下,從左到右的。這是什么意思呢?這么說吧,一副圖像可以看做是一個矩形,由很多排列整齊的點(diǎn)一行一行組成,這些點(diǎn)稱之為像素。那么這幅圖在LCD上的顯示原理就是:
A:顯示指針從矩形左上角的第一行第一個點(diǎn)開始,一個點(diǎn)一個點(diǎn)的在LCD上顯示,在上面的時序圖上用時間線表示就為VCLK,我們稱之為像素時鐘信號;
B:當(dāng)顯示指針一直顯示到矩形的右邊就結(jié)束這一行,那么這一行的動作在上面的時序圖中就稱之為1 Line;
C:接下來顯示指針又回到矩形的左邊從第二行開始顯示,注意,顯示指針在從第一行的右邊回到第二行的左邊是需要一定的時間的,我們稱之為行切換;
D:如此類推,顯示指針就這樣一行一行的顯示至矩形的右下角才把一副圖顯示完成。因此,這一行一行的顯示在時間線上看,就是時序圖上的HSYNC;
E:然而,LCD的顯示并不是對一副圖像快速的顯示一下,為了持續(xù)和穩(wěn)定的在LCD上顯示,就需要切換到另一幅圖上(另一幅圖可以和上一副圖一樣或者不一樣,目的只是為了將圖像持續(xù)的顯示在LCD上)。那么這一副一副的圖像就稱之為幀,在時序圖上就表示為1 Frame,因此從時序圖上可以看出1 Line只是1 Frame中的一行;
F:同樣的,在幀與幀切換之間也是需要一定的時間的,我們稱之為幀切換,那么LCD整個顯示的過程在時間線上看,就可表示為時序圖上的VSYNC。
上面時序圖上各時鐘延時參數(shù)的含義如下:(這些參數(shù)的值,LCD產(chǎn)生廠商會提供相應(yīng)的數(shù)據(jù)手冊)
VBPD(vertical back porch):表示在一幀圖像開始時,垂直同步信號以后的無效的行數(shù),對應(yīng)驅(qū)動中的upper_margin;
VFBD(vertical front porch):表示在一幀圖像結(jié)束后,垂直同步信號以前的無效的行數(shù),對應(yīng)驅(qū)動中的lower_margin;
VSPW(vertical sync pulse width):表示垂直同步脈沖的寬度,用行數(shù)計(jì)算,對應(yīng)驅(qū)動中的vsync_len;
HBPD(horizontal back porch):表示從水平同步信號開始到一行的有效數(shù)據(jù)開始之間的VCLK的個數(shù),對應(yīng)驅(qū)動中的left_margin;
HFPD(horizontal front porth):表示一行的有效數(shù)據(jù)結(jié)束到下一個水平同步信號開始之間的VCLK的個數(shù),對應(yīng)驅(qū)動中的right_margin;
HSPW(horizontal sync pulse width):表示水平同步信號的寬度,用VCLK計(jì)算,對應(yīng)驅(qū)動中的hsync_len;
對于以上這些參數(shù)的值將分別保存到REGBANK寄存器組中的LCDCON1/2/3/4/5寄存器中:(對寄存器的操作請查看S3c2440數(shù)據(jù)手冊LCD部分)
LCDCON1:17?- 8位CLKVAL
??????????6?- 5位掃描模式(對于STN屏:4位單/雙掃、8位單掃)
??????????4?- 1位色位模式(1BPP、8BPP、16BPP等)
LCDCON2:31 - 24位VBPD
?????????23 - 14位LINEVAL
?????????13 - 6位VFPD
??????????5 - 0位VSPW
LCDCON3:25 - 19位HBPD
?????????18 - 8位HOZVAL
??????????7 - 0位HFPD
LCDCON4: 7 - 0位HSPW
LCDCON5:
4. 幀緩沖(FrameBuffer):
幀緩沖是Linux為顯示設(shè)備提供的一個接口,它把一些顯示設(shè)備描述成一個緩沖區(qū),允許應(yīng)用程序通過FrameBuffer定義好的接口訪問這些圖形設(shè)備,從而不用去關(guān)心具體的硬件細(xì)節(jié)。對于幀緩沖設(shè)備而言,只要在顯示緩沖區(qū)與顯示點(diǎn)對應(yīng)的區(qū)域?qū)懭腩伾?,對?yīng)的顏色就會自動的在屏幕上顯示。下面來看一下在不同色位模式下緩沖區(qū)與顯示點(diǎn)的對應(yīng)關(guān)系:
三、幀緩沖(FrameBuffer)設(shè)備驅(qū)動結(jié)構(gòu):
幀緩沖設(shè)備為標(biāo)準(zhǔn)的字符型設(shè)備,在Linux中主設(shè)備號29,定義在/include/linux/major.h中的FB_MAJOR,次設(shè)備號定義幀緩沖的個數(shù),最大允許有32個FrameBuffer,定義在/include/linux/fb.h中的FB_MAX,對應(yīng)于文件系統(tǒng)下/dev/fb%d設(shè)備文件。
1. 幀緩沖設(shè)備驅(qū)動在Linux子系統(tǒng)中的結(jié)構(gòu)如下:
我們從上面這幅圖看,幀緩沖設(shè)備在Linux中也可以看做是一個完整的子系統(tǒng),大體由fbmem.c和xxxfb.c組成。向上給應(yīng)用程序提供完善的設(shè)備文件操作接口(即對FrameBuffer設(shè)備進(jìn)行read、write、ioctl等操作),接口在Linux提供的fbmem.c文件中實(shí)現(xiàn);向下提供了硬件操作的接口,只是這些接口Linux并沒有提供實(shí)現(xiàn),因?yàn)檫@要根據(jù)具體的LCD控制器硬件進(jìn)行設(shè)置,所以這就是我們要做的事情了(即xxxfb.c部分的實(shí)現(xiàn))。
2. 幀緩沖相關(guān)的重要數(shù)據(jù)結(jié)構(gòu):
???從幀緩沖設(shè)備驅(qū)動程序結(jié)構(gòu)看,該驅(qū)動主要跟fb_info結(jié)構(gòu)體有關(guān),該結(jié)構(gòu)體記錄了幀緩沖設(shè)備的全部信息,包括設(shè)備的設(shè)置參數(shù)、狀態(tài)以及對底層硬件操作的函數(shù)指針。在Linux中,每一個幀緩沖設(shè)備都必須對應(yīng)一個fb_info,fb_info在/linux/fb.h中的定義如下:(只列出重要的一些)
fb_ops結(jié)構(gòu)體是對底層硬件操作的函數(shù)指針,該結(jié)構(gòu)體中定義了對硬件的操作有:(這里只列出了常用的操作)
struct fb_ops {
????struct module *owner;
????//檢查可變參數(shù)并進(jìn)行設(shè)置
????int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);
????//根據(jù)設(shè)置的值進(jìn)行更新,使之有效
????int (*fb_set_par)(struct fb_info *info);
????//設(shè)置顏色寄存器
????int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
?????????????unsigned blue, unsigned transp, struct fb_info *info);
????//顯示空白
????int (*fb_blank)(int blank, struct fb_info *info);
????//矩形填充
????void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);
????//復(fù)制數(shù)據(jù)
????void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);
????//圖形填充
????void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);
};
3. 幀緩沖設(shè)備作為平臺設(shè)備:
???在S3C2440中,LCD控制器被集成在芯片的內(nèi)部作為一個相對獨(dú)立的單元,所以Linux把它看做是一個平臺設(shè)備,故在內(nèi)核代碼/arch/arm/plat-s3c24xx/devs.c中定義有LCD相關(guān)的平臺設(shè)備及資源,代碼如下:
?? 除此之外,Linux還在/arch/arm/mach-s3c2410/include/mach/fb.h中為LCD平臺設(shè)備定義了一個s3c2410fb_mach_info結(jié)構(gòu)體,該結(jié)構(gòu)體主要是記錄LCD的硬件參數(shù)信息(比如該結(jié)構(gòu)體的s3c2410fb_display成員結(jié)構(gòu)中就用于記錄LCD的屏幕尺寸、屏幕信息、可變的屏幕參數(shù)、LCD配置寄存器等),這樣在寫驅(qū)動的時候就直接使用這個結(jié)構(gòu)體。下面,我們來看一下內(nèi)核是如果使用這個結(jié)構(gòu)體的。在/arch/arm/mach-s3c2440/mach-smdk2440.c中定義有:
/* LCD driver info */
//LCD硬件的配置信息,注意這里我使用的LCD是NEC 3.5寸TFT屏,這些參數(shù)要根據(jù)具體的LCD屏進(jìn)行設(shè)置
static struct s3c2410fb_display smdk2440_lcd_cfg __initdata = {
//這個地方的設(shè)置是配置LCD寄存器5,這些宏定義在regs-lcd.h中,計(jì)算后二進(jìn)制為:111111111111,然后對照數(shù)據(jù)手冊上LCDCON5的各位來看,注意是從右邊開始
????.lcdcon5?= S3C2410_LCDCON5_FRM565 |
?????????????? S3C2410_LCDCON5_INVVLINE |
?????????????? S3C2410_LCDCON5_INVVFRAME |
?????????????? S3C2410_LCDCON5_PWREN |
?????????????? S3C2410_LCDCON5_HWSWP,
????.type????= S3C2410_LCDCON1_TFT,//TFT類型
????/* NEC 3.5'' */
????.width??????? = 240,//屏幕寬度
????.height?????? = 320,//屏幕高度
//以下一些參數(shù)在上面的時序圖分析中講到過,各參數(shù)的值請跟據(jù)具體的LCD屏數(shù)據(jù)手冊結(jié)合上面時序分析來設(shè)定
????.pixclock???? = 100000,//像素時鐘
????.xres???????? = 240,//水平可見的有效像素
????.yres???????? = 320,//垂直可見的有效像素
????.bpp????????? = 16,//色位模式
????.left_margin??= 19,//行切換,從同步到繪圖之間的延遲
????.right_margin?= 36,//行切換,從繪圖到同步之間的延遲
????.hsync_len????= 5,//水平同步的長度
????.upper_margin?= 1,//幀切換,從同步到繪圖之間的延遲
????.lower_margin?= 5,//幀切換,從繪圖到同步之間的延遲
????.vsync_len????= 1,//垂直同步的長度
};
static struct s3c2410fb_mach_info smdk2440_fb_info __initdata = {
????.displays??????? = &smdk2440_lcd_cfg,//應(yīng)用上面定義的配置信息
????.num_displays????= 1,
????.default_display = 0,
????.gpccon??????????= 0xaaaa555a,//將GPC0、GPC1配置成LEND和VCLK,將GPC8-15配置成VD0-7,其他配置成普通輸出IO口
????.gpccon_mask???? = 0xffffffff,
????.gpcup???????????= 0x0000ffff,//禁止GPIOC的上拉功能
????.gpcup_mask??????= 0xffffffff,
????.gpdcon??????????= 0xaaaaaaaa,//將GPD0-15配置成VD8-23
????.gpdcon_mask???? = 0xffffffff,
????.gpdup???????????= 0x0000ffff,//禁止GPIOD的上拉功能
????.gpdup_mask??????= 0xffffffff,
????.lpcsel????????? = 0x0,//這個是三星TFT屏的參數(shù),這里不用
};
注意:可能有很多朋友不知道上面紅色部分的參數(shù)是做什么的,其值又是怎么設(shè)置的?其實(shí)它是跟你的開發(fā)板LCD控制器密切相關(guān)的,看了下面兩幅圖相信就大概知道他們是干什么用的:
上面第一幅圖是開發(fā)板原理圖的LCD控制器部分,第二幅圖是S3c2440數(shù)據(jù)手冊中IO端口C和IO端口D控制器部分。原理圖中使用了GPC8-15和GPD0-15來用做LCD控制器VD0-VD23的數(shù)據(jù)端口,又分別使用GPC0、GPC1端口用做LCD控制器的LEND和VCLK信號,對于GPC2-7則是用做STN屏或者三星專業(yè)TFT屏的相關(guān)信號。然而,S3C2440的各個IO口并不是單一的功能,都是復(fù)用端口,要使用他們首先要對他們進(jìn)行配置。所以上面紅色部分的參數(shù)就是把GPC和GPD的部分端口配置成LCD控制功能模式。
從以上講述的內(nèi)容來看,要使LCD控制器支持其他的LCD屏,重要的是根據(jù)LCD的數(shù)據(jù)手冊修改以上這些參數(shù)的值。下面,我們再看一下在驅(qū)動中是如果引用到s3c2410fb_mach_info結(jié)構(gòu)體的(注意上面講的是在內(nèi)核中如何使用的)。在mach-smdk2440.c中有:
s3c24xx_fb_set_platdata定義在plat-s3c24xx/devs.c中:
這里再講一個小知識:不知大家有沒有留意,在平臺設(shè)備驅(qū)動中,platform_data可以保存各自平臺設(shè)備實(shí)例的數(shù)據(jù),但這些數(shù)據(jù)的類型都是不同的,為什么都可以保存?這就要看看platform_data的定義,定義在/linux/device.h中,void *platform_data是一個void類型的指針,在Linux中void可保存任何數(shù)據(jù)類型。
四、幀緩沖(FrameBuffer)設(shè)備驅(qū)動實(shí)例代碼:
①、建立驅(qū)動文件:my2440_lcd.c,依就是驅(qū)動程序的最基本結(jié)構(gòu):FrameBuffer驅(qū)動的初始化和卸載部分及其他,如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/*FrameBuffer設(shè)備名稱*/
static char?driver_name[] = "my2440_lcd";
/*定義一個結(jié)構(gòu)體用來維護(hù)驅(qū)動程序中各函數(shù)中用到的變量
??先別看結(jié)構(gòu)體要定義這些成員,到各函數(shù)使用的地方就明白了*/
struct my2440fb_var
{
????int lcd_irq_no;?????????? /*保存LCD中斷號*/
????struct clk *lcd_clock;????/*保存從平臺時鐘隊(duì)列中獲取的LCD時鐘*/
????struct resource *lcd_mem;?/*LCD的IO空間*/
????void __iomem *lcd_base;???/*LCD的IO空間映射到虛擬地址*/
????struct device *dev;
????struct s3c2410fb_hw?regs;?/*表示5個LCD配置寄存器,s3c2410fb_hw定義在mach-s3c2410/include/mach/fb.h中*/
????/*定義一個數(shù)組來充當(dāng)調(diào)色板。
????據(jù)數(shù)據(jù)手冊描述,TFT屏色位模式為8BPP時,調(diào)色板(顏色表)的長度為256,調(diào)色板起始地址為0x4D000400*/
????u32????palette_buffer[256];?
u32?pseudo_pal[16];???
????unsigned int palette_ready;?/*標(biāo)識調(diào)色板是否準(zhǔn)備好了*/
};
/*用做清空調(diào)色板(顏色表)*/
#define PALETTE_BUFF_CLEAR (0x80000000)????
/*LCD平臺驅(qū)動結(jié)構(gòu)體,平臺驅(qū)動結(jié)構(gòu)體定義在platform_device.h中,該結(jié)構(gòu)體成員接口函數(shù)在第②步中實(shí)現(xiàn)*/
static struct platform_driver lcd_fb_driver =
{
????.probe?????= lcd_fb_probe,?????????????? /*FrameBuffer設(shè)備探測*/
????.remove????= __devexit_p(lcd_fb_remove),?/*FrameBuffer設(shè)備移除*/
????.suspend???= lcd_fb_suspend,???????????? /*FrameBuffer設(shè)備掛起*/
????.resume????= lcd_fb_resume,??????????????/*FrameBuffer設(shè)備恢復(fù)*/
????.driver????=
????{
????????/*注意這里的名稱一定要和系統(tǒng)中定義平臺設(shè)備的地方一致,這樣才能把平臺設(shè)備與該平臺設(shè)備的驅(qū)動關(guān)聯(lián)起來*/
????????.name?= "s3c2410-lcd",
????????.owner?= THIS_MODULE,
????},
};
static int __init lcd_init(void)
{
????/*在Linux中,幀緩沖設(shè)備被看做是平臺設(shè)備,所以這里注冊平臺設(shè)備*/
????return platform_driver_register(&lcd_fb_driver);
}
static void __exit lcd_exit(void)
{
????/*注銷平臺設(shè)備*/
????platform_driver_unregister(&lcd_fb_driver);
}
module_init(lcd_init);
module_exit(lcd_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Huang Gang");
MODULE_DESCRIPTION("My2440 LCD FrameBuffer Driver");
②、LCD平臺設(shè)備各接口函數(shù)的實(shí)現(xiàn):
/*LCD FrameBuffer設(shè)備探測的實(shí)現(xiàn),注意這里使用一個__devinit宏,到lcd_fb_remove接口函數(shù)實(shí)現(xiàn)的地方講解*/
static int __devinit lcd_fb_probe(struct platform_device *pdev)
{
????int i;
????int ret;
????struct resource?*res;??/*用來保存從LCD平臺設(shè)備中獲取的LCD資源*/
????struct fb_info??*fbinfo;?/*FrameBuffer驅(qū)動所對應(yīng)的fb_info結(jié)構(gòu)體*/
????struct s3c2410fb_mach_info?*mach_info;?/*保存從內(nèi)核中獲取的平臺設(shè)備數(shù)據(jù)*/
????struct my2440fb_var?*fbvar;?/*上面定義的驅(qū)動程序全局變量結(jié)構(gòu)體*/
????struct s3c2410fb_display?*display;?/*LCD屏的配置信息結(jié)構(gòu)體,該結(jié)構(gòu)體定義在mach-s3c2410/include/mach/fb.h中*/
????/*獲取LCD硬件相關(guān)信息數(shù)據(jù),在前面講過內(nèi)核使用s3c24xx_fb_set_platdata函數(shù)將LCD的硬件相關(guān)信息保存到
???? 了LCD平臺數(shù)據(jù)中,所以這里我們就從平臺數(shù)據(jù)中取出來在驅(qū)動中使用*/
????mach_info = pdev->dev.platform_data;
????if(mach_info == NULL)
????{
????????/*判斷獲取數(shù)據(jù)是否成功*/
????????dev_err(&pdev->dev, "no platform data for lcd/n");
????????return -EINVAL;
????}
????/*獲得在內(nèi)核中定義的FrameBuffer平臺設(shè)備的LCD配置信息結(jié)構(gòu)體數(shù)據(jù)*/
????display = mach_info->displays + mach_info->default_display;
/*給fb_info分配空間,大小為my2440fb_var結(jié)構(gòu)的內(nèi)存,framebuffer_alloc定義在fb.h中在fbsysfs.c中實(shí)現(xiàn)*/
????fbinfo = framebuffer_alloc(sizeof(struct my2440fb_var), &pdev->dev);
????if(!fbinfo)
????{
????????dev_err(&pdev->dev, "framebuffer alloc of registers failed/n");
????????ret = -ENOMEM;
????????goto err_noirq;
????}
????platform_set_drvdata(pdev, fbinfo);/*重新將LCD平臺設(shè)備數(shù)據(jù)設(shè)置為fbinfo,好在后面的一些函數(shù)中來使用*/
????/*這里的用途其實(shí)就是將fb_info的成員par(注意是一個void類型的指針)指向這里的私有變量結(jié)構(gòu)體fbvar,
???? 目的是到其他接口函數(shù)中再取出fb_info的成員par,從而能繼續(xù)使用這里的私有變量*/
????fbvar = fbinfo->par;
????fbvar->dev = &pdev->dev;
????/*在系統(tǒng)定義的LCD平臺設(shè)備資源中獲取LCD中斷號,platform_get_irq定義在platform_device.h中*/
????fbvar->lcd_irq_no = platform_get_irq(pdev, 0);
????if(fbvar->lcd_irq_no < 0)
????{
????????/*判斷獲取中斷號是否成功*/
????????dev_err(&pdev->dev, "no lcd irq for platform/n");
????????return -ENOENT;
????}
????/*獲取LCD平臺設(shè)備所使用的IO端口資源,注意這個IORESOURCE_MEM標(biāo)志和LCD平臺設(shè)備定義中的一致*/
????res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
????if(res == NULL)
????{
????????/*判斷獲取資源是否成功*/
????????dev_err(&pdev->dev, "failed to get memory region resource/n");
????????return -ENOENT;
????}
????/*申請LCD IO端口所占用的IO空間(注意理解IO空間和內(nèi)存空間的區(qū)別),request_mem_region定義在ioport.h中*/
????fbvar->lcd_mem = request_mem_region(res->start, res->end - res->start + 1, pdev->name);
????if(fbvar->lcd_mem == NULL)
????{
????????/*判斷申請IO空間是否成功*/
????????dev_err(&pdev->dev, "failed to reserve memory region/n");
????????return -ENOENT;
????}
????/*將LCD的IO端口占用的這段IO空間映射到內(nèi)存的虛擬地址,ioremap定義在io.h中
???? 注意:IO空間要映射后才能使用,以后對虛擬地址的操作就是對IO空間的操作*/
????fbvar->lcd_base = ioremap(res->start, res->end - res->start + 1);
????if(fbvar->lcd_base == NULL)
????{
????????/*判斷映射虛擬地址是否成功*/
????????dev_err(&pdev->dev, "ioremap() of registers failed/n");
????????ret = -EINVAL;
????????goto err_nomem;
????}
????/*從平臺時鐘隊(duì)列中獲取LCD的時鐘,這里為什么要取得這個時鐘,從LCD屏的時序圖上看,各種控制信號的延遲
???? 都跟LCD的時鐘有關(guān)。系統(tǒng)的一些時鐘定義在arch/arm/plat-s3c24xx/s3c2410-clock.c中*/
????fbvar->lcd_clock = clk_get(NULL, "lcd");
????if(!fbvar->lcd_clock)
????{
????????/*判斷獲取時鐘是否成功*/
????????dev_err(&pdev->dev, "failed to find lcd clock source/n");
????????ret = -ENOENT;
????????goto err_nomap;
????}
????/*時鐘獲取后要使能后才可以使用,clk_enable定義在arch/arm/plat-s3c/clock.c中*/
????clk_enable(fbvar->lcd_clock);
????/*申請LCD中斷服務(wù),上面獲取的中斷號lcd_fb_irq,使用快速中斷方式:IRQF_DISABLED
???? 中斷服務(wù)程序?yàn)?lcd_fb_irq,將LCD平臺設(shè)備pdev做參數(shù)傳遞過去了*/
????ret = request_irq(fbvar->lcd_irq_no, lcd_fb_irq, IRQF_DISABLED, pdev->name, fbvar);
????if(ret)
????{
????????/*判斷申請中斷服務(wù)是否成功*/
????????dev_err(&pdev->dev, "IRQ%d error %d/n", fbvar->lcd_irq_no, ret);
????????ret = -EBUSY;
????????goto err_noclk;
????}
????/*好了,以上是對要使用的資源進(jìn)行了獲取和設(shè)置。下面就開始初始化填充fb_info結(jié)構(gòu)體*/
????/*首先初始化fb_info中代表LCD固定參數(shù)的結(jié)構(gòu)體fb_fix_screeninfo*/
????/*像素值與顯示內(nèi)存的映射關(guān)系有5種,定義在fb.h中。現(xiàn)在采用FB_TYPE_PACKED_PIXELS方式,在該方式下,
????像素值與內(nèi)存直接對應(yīng),比如在顯示內(nèi)存某單元寫入一個"1"時,該單元對應(yīng)的像素值也將是"1",這使得應(yīng)用層
????把顯示內(nèi)存映射到用戶空間變得非常方便。Linux中當(dāng)LCD為TFT屏?xí)r,顯示驅(qū)動管理顯示內(nèi)存就是基于這種方式*/
????strcpy(fbinfo->fix.id, driver_name);/*字符串形式的標(biāo)識符*/
????fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
????fbinfo->fix.type_aux = 0;/*以下這些根據(jù)fb_fix_screeninfo定義中的描述,當(dāng)沒有硬件是都設(shè)為0*/
????fbinfo->fix.xpanstep = 0;
????fbinfo->fix.ypanstep = 0;
????fbinfo->fix.ywrapstep= 0;
????fbinfo->fix.accel = FB_ACCEL_NONE;
/*接著,再初始化fb_info中代表LCD可變參數(shù)的結(jié)構(gòu)體fb_var_screeninfo*/
????fbinfo->var.nonstd??????????= 0;
????fbinfo->var.activate????????= FB_ACTIVATE_NOW;
????fbinfo->var.accel_flags?????= 0;
????fbinfo->var.vmode???????????= FB_VMODE_NONINTERLACED;
????fbinfo->var.xres????????????= display->xres;
????fbinfo->var.yres????????????= display->yres;
????fbinfo->var.bits_per_pixel??= display->bpp;
/*指定對底層硬件操作的函數(shù)指針, 因內(nèi)容較多故其定義在第③步中再講*/
????fbinfo->fbops???????????????= &my2440fb_ops;
/*初始化色調(diào)色板(顏色表)為空*/
????for(i = 0; i < 256; i++)
????{
????????fbvar->palette_buffer[i] = PALETTE_BUFF_CLEAR;
????}
????for (i = 0; i < mach_info->num_displays; i++) /*fb緩存的長度*/
????{
????????/*計(jì)算FrameBuffer緩存的最大大小,這里右移3位(即除以8)是因?yàn)樯荒J紹PP是以位為單位*/
????????unsigned long smem_len = (mach_info->displays[i].xres * mach_info->displays[i].yres * mach_info->displays[i].bpp) >> 3;
????????if(fbinfo->fix.smem_len < smem_len)
????????{
????????????fbinfo->fix.smem_len = smem_len;
????????}
????}
????/*初始化LCD控制器之前要延遲一段時間*/
????msleep(1);
????/*初始化完fb_info后,開始對LCD各寄存器進(jìn)行初始化,其定義在后面講到*/
????my2440fb_init_registers(fbinfo);
????/*初始化完寄存器后,開始檢查fb_info中的可變參數(shù),其定義在后面講到*/
????my2440fb_check_var(fbinfo);
????
????/*申請幀緩沖設(shè)備fb_info的顯示緩沖區(qū)空間,其定義在后面講到*/
????ret = my2440fb_map_video_memory(fbinfo);
????if (ret)
????{
????????dev_err(&pdev->dev, "failed to allocate video RAM: %d/n", ret);
????????ret = -ENOMEM;
????????goto err_nofb;
????}
????/*最后,注冊這個幀緩沖設(shè)備fb_info到系統(tǒng)中, register_framebuffer定義在fb.h中在fbmem.c中實(shí)現(xiàn)*/
????ret = register_framebuffer(fbinfo);
????if (ret < 0)
????{
????????dev_err(&pdev->dev, "failed to register framebuffer device: %d/n", ret);
????????goto err_video_nomem;
????}
????/*對設(shè)備文件系統(tǒng)的支持(對設(shè)備文件系統(tǒng)的理解請參閱:嵌入式Linux之我行——設(shè)備文件系統(tǒng)剖析與使用)
???? 創(chuàng)建frambuffer設(shè)備文件,device_create_file定義在linux/device.h中*/
????ret = device_create_file(&pdev->dev, &dev_attr_debug);
????if (ret)
????{
????????dev_err(&pdev->dev, "failed to add debug attribute/n");
????}
????return 0;
/*以下是上面錯誤處理的跳轉(zhuǎn)點(diǎn)*/
err_nomem:
????release_resource(fbvar->lcd_mem);
????kfree(fbvar->lcd_mem);
err_nomap:
????iounmap(fbvar->lcd_base);
err_noclk:
????clk_disable(fbvar->lcd_clock);
????clk_put(fbvar->lcd_clock);
err_noirq:
????free_irq(fbvar->lcd_irq_no, fbvar);
err_nofb:
????platform_set_drvdata(pdev, NULL);
????framebuffer_release(fbinfo);
err_video_nomem:
????my2440fb_unmap_video_memory(fbinfo);
????return ret;
}
/*LCD中斷服務(wù)程序*/
static irqreturn_t lcd_fb_irq(int irq, void *dev_id)
{
????struct my2440fb_var????*fbvar = dev_id;
????void __iomem *lcd_irq_base;
????unsigned long lcdirq;
????/*LCD中斷掛起寄存器基地址*/
????lcd_irq_base = fbvar->lcd_base + S3C2410_LCDINTBASE;
????/*讀取LCD中斷掛起寄存器的值*/
????lcdirq = readl(lcd_irq_base + S3C24XX_LCDINTPND);
????/*判斷是否為中斷掛起狀態(tài)*/
????if(lcdirq & S3C2410_LCDINT_FRSYNC)
????{
????????/*填充調(diào)色板*/
????????if (fbvar->palette_ready)
????????{
????????????my2440fb_write_palette(fbvar);
????????}
????????/*設(shè)置幀已插入中斷請求*/
????????writel(S3C2410_LCDINT_FRSYNC, lcd_irq_base + S3C24XX_LCDINTPND);
????????writel(S3C2410_LCDINT_FRSYNC, lcd_irq_base + S3C24XX_LCDSRCPND);
????}
????return IRQ_HANDLED;
}
/*填充調(diào)色板*/
static void my2440fb_write_palette(struct my2440fb_var *fbvar)
{
????unsigned int i;
????void __iomem *regs = fbvar->lcd_base;
????fbvar->palette_ready = 0;
????for (i = 0; i < 256; i++)
????{
????????unsigned long ent = fbvar->palette_buffer[i];
????????if (ent == PALETTE_BUFF_CLEAR)
????????{
????????????continue;
????????}
????????writel(ent, regs + S3C2410_TFTPAL(i));
????????if (readw(regs + S3C2410_TFTPAL(i)) == ent)
????????{
????????????fbvar->palette_buffer[i] = PALETTE_BUFF_CLEAR;
????????}
????????else
????????{
????????????fbvar->palette_ready = 1;
????????}
????}
}
/*LCD各寄存器進(jìn)行初始化*/
static int my2440fb_init_registers(struct fb_info *fbinfo)
{
????unsigned long flags;
????void __iomem *tpal;
????void __iomem *lpcsel;
????/*從lcd_fb_probe探測函數(shù)設(shè)置的私有變量結(jié)構(gòu)體中再獲得LCD相關(guān)信息的數(shù)據(jù)*/
????struct my2440fb_var????*fbvar = fbinfo->par;
????struct s3c2410fb_mach_info *mach_info = fbvar->dev->platform_data;
????/*獲得臨時調(diào)色板寄存器基地址,S3C2410_TPAL宏定義在mach-s3c2410/include/mach/regs-lcd.h中。
????注意對于lpcsel這是一個針對三星TFT屏的一個專用寄存器,如果用的不是三星的TFT屏應(yīng)該不用管它。*/
????tpal = fbvar->lcd_base + S3C2410_TPAL;
????lpcsel = fbvar->lcd_base + S3C2410_LPCSEL;
????/*在修改下面寄存器值之前先屏蔽中斷,將中斷狀態(tài)保存到flags中*/
????local_irq_save(flags);
????/*這里就是在上一篇章中講到的把IO端口C和D配置成LCD模式*/
????modify_gpio(S3C2410_GPCUP, mach_info->gpcup, mach_info->gpcup_mask);
????modify_gpio(S3C2410_GPCCON, mach_info->gpccon, mach_info->gpccon_mask);
????modify_gpio(S3C2410_GPDUP, mach_info->gpdup, mach_info->gpdup_mask);
????modify_gpio(S3C2410_GPDCON, mach_info->gpdcon, mach_info->gpdcon_mask);
????/*恢復(fù)被屏蔽的中斷*/
????local_irq_restore(flags);
????writel(0x00, tpal);/*臨時調(diào)色板寄存器使能禁止*/
????writel(mach_info->lpcsel, lpcsel);/*在上一篇中講到過,它是三星TFT屏的一個寄存器,這里可以不管*/
????return 0;
}
/*該函數(shù)實(shí)現(xiàn)修改GPIO端口的值,注意第三個參數(shù)mask的作用是將要設(shè)置的寄存器值先清零*/
static inline void modify_gpio(void __iomem *reg, unsigned long set, unsigned long mask)
{
????unsigned long tmp;
????tmp = readl(reg) & ~mask;
????writel(tmp | set, reg);
}
/*檢查fb_info中的可變參數(shù)*/
static int my2440fb_check_var(struct fb_info *fbinfo)
{
????unsigned i;
????/*從lcd_fb_probe探測函數(shù)設(shè)置的平臺數(shù)據(jù)中再獲得LCD相關(guān)信息的數(shù)據(jù)*/
????struct fb_var_screeninfo *var = &fbinfo->var;/*fb_info中的可變參數(shù)*/
????struct my2440fb_var????*fbvar = fbinfo->par;/*在lcd_fb_probe探測函數(shù)中設(shè)置的私有結(jié)構(gòu)體數(shù)據(jù)*/
????struct s3c2410fb_mach_info *mach_info = fbvar->dev->platform_data;/*LCD的配置結(jié)構(gòu)體數(shù)據(jù),這個配置結(jié)構(gòu)體的賦值在上一篇章的"3. 幀緩沖設(shè)備作為平臺設(shè)備"中*/
????struct s3c2410fb_display *display = NULL;
????struct s3c2410fb_display *default_display = mach_info->displays + mach_info->default_display;
????int type = default_display->type;/*LCD的類型,看上一篇章的"3. 幀緩沖設(shè)備作為平臺設(shè)備"中的type賦值是TFT類型*/
????/*驗(yàn)證X/Y解析度*/
????if (var->yres == default_display->yres &&
????????var->xres == default_display->xres &&
????????var->bits_per_pixel == default_display->bpp)
????{
????????display = default_display;
????}
????else
????{
????????for (i = 0; i < mach_info->num_displays; i++)
????????{
????????????if (type == mach_info->displays[i].type &&
???????????? var->yres == mach_info->displays[i].yres &&
???????????? var->xres == mach_info->displays[i].xres &&
???????????? var->bits_per_pixel == mach_info->displays[i].bpp)
????????????{
????????????????display = mach_info->displays + i;
????????????????break;
????????????}
????????}
????}
????if (!display)
????{
????????return -EINVAL;
????}
????/*配置LCD配置寄存器1中的5-6位(配置成TFT類型)和配置LCD配置寄存器5*/
????fbvar->regs.lcdcon1 = display->type;
????fbvar->regs.lcdcon5 = display->lcdcon5;
????/* 設(shè)置屏幕的虛擬解析像素和高度寬度 */
????var->xres_virtual = display->xres;
????var->yres_virtual = display->yres;
????var->height = display->height;
????var->width = display->width;
????/* 設(shè)置時鐘像素,行、幀切換值,水平同步、垂直同步長度值 */
????var->pixclock = display->pixclock;
????var->left_margin = display->left_margin;
????var->right_margin = display->right_margin;
????var->upper_margin = display->upper_margin;
????var->lower_margin = display->lower_margin;
????var->vsync_len = display->vsync_len;
????var->hsync_len = display->hsync_len;
????/*設(shè)置透明度*/
????var->transp.offset = 0;
????var->transp.length = 0;
????/*根據(jù)色位模式(BPP)來設(shè)置可變參數(shù)中R、G、B的顏色位域。對于這些參數(shù)值的設(shè)置請參考CPU數(shù)據(jù)
????手冊中"顯示緩沖區(qū)與顯示點(diǎn)對應(yīng)關(guān)系圖",例如在上一篇章中我就畫出了8BPP和16BPP時的對應(yīng)關(guān)系圖*/
????switch (var->bits_per_pixel)
????{
????????case 1:
????????case 2:
????????case 4:
????????????var->red.offset??= 0;
????????????var->red.length??= var->bits_per_pixel;
????????????var->green?????? = var->red;
????????????var->blue??????? = var->red;
????????????break;
????????case 8:/* 8 bpp 332 */
????????????if (display->type != S3C2410_LCDCON1_TFT)
????????????{
????????????????var->red.length?????= 3;
????????????????var->red.offset?????= 5;
????????????????var->green.length???= 3;
????????????????var->green.offset???= 2;
????????????????var->blue.length????= 2;
????????????????var->blue.offset????= 0;
????????????}else{
????????????????var->red.offset?????= 0;
????????????????var->red.length?????= 8;
????????????????var->green????????? = var->red;
????????????????var->blue?????????? = var->red;
????????????}
????????????break;
????????case 12:/* 12 bpp 444 */
????????????var->red.length???????? = 4;
????????????var->red.offset???????? = 8;
????????????var->green.length?????? = 4;
????????????var->green.offset?????? = 4;
????????????var->blue.length??????? = 4;
????????????var->blue.offset??????? = 0;
????????????break;
????????case 16:/* 16 bpp */
????????????if (display->lcdcon5 & S3C2410_LCDCON5_FRM565)
????????????{
????????????????/* 565 format */
????????????????var->red.offset??????= 11;
????????????????var->green.offset????= 5;
????????????????var->blue.offset???? = 0;
????????????????var->red.length??????= 5;
????????????????var->green.length????= 6;
????????????????var->blue.length???? = 5;
????????????} else {
????????????????/* 5551 format */
????????????????var->red.offset??????= 11;
????????????????var->green.offset????= 6;
????????????????var->blue.offset???? = 1;
????????????????var->red.length??????= 5;
????????????????var->green.length????= 5;
????????????????var->blue.length???? = 5;
????????????}
????????????break;
????????case 32:/* 24 bpp 888 and 8 dummy */
????????????var->red.length????????= 8;
????????????var->red.offset????????= 16;
????????????var->green.length????? = 8;
????????????var->green.offset????? = 8;
????????????var->blue.length?????? = 8;
????????????var->blue.offset?????? = 0;
????????????break;
????}
????return 0;
}
/*申請幀緩沖設(shè)備fb_info的顯示緩沖區(qū)空間*/
static int __init my2440fb_map_video_memory(struct fb_info *fbinfo)
{
????dma_addr_t map_dma;/*用于保存DMA緩沖區(qū)總線地址*/
????struct my2440fb_var????*fbvar = fbinfo->par;/*獲得在lcd_fb_probe探測函數(shù)中設(shè)置的私有結(jié)構(gòu)體數(shù)據(jù)*/
????unsigned map_size = PAGE_ALIGN(fbinfo->fix.smem_len);/*獲得FrameBuffer緩存的大小, PAGE_ALIGN定義在mm.h中*/
????/*將分配的一個寫合并DMA緩存區(qū)設(shè)置為LCD屏幕的虛擬地址(對于DMA請參考DMA相關(guān)知識)
????dma_alloc_writecombine定義在arch/arm/mm/dma-mapping.c中*/
????fbinfo->screen_base = dma_alloc_writecombine(fbvar->dev, map_size, &map_dma, GFP_KERNEL);
????if (fbinfo->screen_base)
????{
????????/*設(shè)置這片DMA緩存區(qū)的內(nèi)容為空*/
????????memset(fbinfo->screen_base, 0x00, map_size);
????????/*將DMA緩沖區(qū)總線地址設(shè)成fb_info不可變參數(shù)中framebuffer緩存的開始位置*/
????????fbinfo->fix.smem_start = map_dma;
????}
????return fbinfo->screen_base ? 0 : -ENOMEM;
}
/*釋放幀緩沖設(shè)備fb_info的顯示緩沖區(qū)空間*/
static inline void my2440fb_unmap_video_memory(struct fb_info *fbinfo)
{
????struct my2440fb_var????*fbvar = fbinfo->par;
????unsigned map_size = PAGE_ALIGN(fbinfo->fix.smem_len);
????/*跟申請DMA的地方想對應(yīng)*/
????dma_free_writecombine(fbvar->dev, map_size, fbinfo->screen_base, fbinfo->fix.smem_start);
}
/*LCD FrameBuffer設(shè)備移除的實(shí)現(xiàn),注意這里使用一個__devexit宏,和lcd_fb_probe接口函數(shù)相對應(yīng)。
??在Linux內(nèi)核中,使用了大量不同的宏來標(biāo)記具有不同作用的函數(shù)和數(shù)據(jù)結(jié)構(gòu),這些宏在include/linux/init.h
??頭文件中定義,編譯器通過這些宏可以把代碼優(yōu)化放到合適的內(nèi)存位置,以減少內(nèi)存占用和提高內(nèi)核效率。
??__devinit、__devexit就是這些宏之一,在probe()和remove()函數(shù)中應(yīng)該使用__devinit和__devexit宏。
??又當(dāng)remove()函數(shù)使用了__devexit宏時,則在驅(qū)動結(jié)構(gòu)體中一定要使用__devexit_p宏來引用remove(),
??所以在第①步中就用__devexit_p來引用lcd_fb_remove接口函數(shù)。*/
static int __devexit lcd_fb_remove(struct platform_device *pdev)
{
????struct fb_info *fbinfo = platform_get_drvdata(pdev);
????struct my2440fb_var????*fbvar = fbinfo->par;
????/*從系統(tǒng)中注銷幀緩沖設(shè)備*/
????unregister_framebuffer(fbinfo);
????/*停止LCD控制器的工作*/
????my2440fb_lcd_enable(fbvar, 0);
????/*延遲一段時間,因?yàn)橥V筁CD控制器需要一點(diǎn)時間 */
????msleep(1);
????/*釋放幀緩沖設(shè)備fb_info的顯示緩沖區(qū)空間*/
????my2440fb_unmap_video_memory(fbinfo);
????/*將LCD平臺數(shù)據(jù)清空和釋放fb_info空間資源*/
????platform_set_drvdata(pdev, NULL);
????framebuffer_release(fbinfo);
????/*釋放中斷資源*/
????free_irq(fbvar->lcd_irq_no, fbvar);
????/*釋放時鐘資源*/
????if (fbvar->lcd_clock)
????{
????????clk_disable(fbvar->lcd_clock);
????????clk_put(fbvar->lcd_clock);
????????fbvar->lcd_clock = NULL;
????}
????/*釋放LCD IO空間映射的虛擬內(nèi)存空間*/
????iounmap(fbvar->lcd_base);
????/*釋放申請的LCD IO端口所占用的IO空間*/
????release_resource(fbvar->lcd_mem);
????kfree(fbvar->lcd_mem);
????return 0;
}
/*停止LCD控制器的工作*/
static void my2440fb_lcd_enable(struct my2440fb_var *fbvar, int enable)
{
????unsigned long flags;
????/*在修改下面寄存器值之前先屏蔽中斷,將中斷狀態(tài)保存到flags中*/
????local_irq_save(flags);
????if (enable)
????{
????????fbvar->regs.lcdcon1 |= S3C2410_LCDCON1_ENVID;
????}
????else
????{
????????fbvar->regs.lcdcon1 &= ~S3C2410_LCDCON1_ENVID;
????}
????writel(fbvar->regs.lcdcon1, fbvar->lcd_base + S3C2410_LCDCON1);
????/*恢復(fù)被屏蔽的中斷*/
????local_irq_restore(flags);
}
/*對LCD FrameBuffer平臺設(shè)備驅(qū)動電源管理的支持,CONFIG_PM這個宏定義在內(nèi)核中*/
#ifdef CONFIG_PM
/*當(dāng)配置內(nèi)核時選上電源管理,則平臺設(shè)備的驅(qū)動就支持掛起和恢復(fù)功能*/
static int lcd_fb_suspend(struct platform_device *pdev, pm_message_t state)
{
????/*掛起LCD設(shè)備,注意這里掛起LCD時并沒有保存LCD控制器的各種狀態(tài),所以在恢復(fù)后LCD不會繼續(xù)顯示掛起前的內(nèi)容
???? 若要繼續(xù)顯示掛起前的內(nèi)容,則要在這里保存LCD控制器的各種狀態(tài),這里就不講這個了,以后講到電源管理再講*/
????struct fb_info *fbinfo = platform_get_drvdata(pdev);
????struct my2440fb_var????*fbvar = fbinfo->par;
????/*停止LCD控制器的工作*/
????my2440fb_lcd_enable(fbvar, 0);
????msleep(1);
????/*停止時鐘*/
????clk_disable(fbvar->lcd_clock);
????return 0;
}
static?int lcd_fb_resume(struct platform_device *pdev)
{
????/*恢復(fù)掛起的LCD設(shè)備*/
????struct fb_info *fbinfo = platform_get_drvdata(pdev);
????struct my2440fb_var????*fbvar = fbinfo->par;
????/*開啟時鐘*/
????clk_enable(fbvar->lcd_clock);
????/*初始化LCD控制器之前要延遲一段時間*/
????msleep(1);
????/*恢復(fù)時重新初始化LCD各寄存器*/
????my2440fb_init_registers(fbinfo);
????/*重新激活fb_info中所有的參數(shù)配置,該函數(shù)定義在第③步中再講*/
????my2440fb_activate_var(fbinfo);
????/*正與掛起時講到的那樣,因?yàn)闆]保存掛起時LCD控制器的各種狀態(tài),
????所以恢復(fù)后就讓LCD顯示空白,該函數(shù)定義也在第③步中再講*/
????my2440fb_blank(FB_BLANK_UNBLANK, fbinfo);
????return 0;
}
#else
/*如果配置內(nèi)核時沒選上電源管理,則平臺設(shè)備的驅(qū)動就不支持掛起和恢復(fù)功能,這兩個函數(shù)也就無需實(shí)現(xiàn)了*/
#define lcd_fb_suspend????NULL
#define lcd_fb_resume????NULL
#endif
fbinfo->flags?????????????? = FBINFO_FLAG_DEFAULT;
fbinfo->pseudo_palette????? = &fbvar->pseudo_pal;
③、幀緩沖設(shè)備驅(qū)動對底層硬件操作的函數(shù)接口實(shí)現(xiàn)(即:my2440fb_ops的實(shí)現(xiàn)):
/*Framebuffer底層硬件操作各接口函數(shù)*/
static struct fb_ops my2440fb_ops =
{
????.owner??????????= THIS_MODULE,
????.fb_check_var???= my2440fb_check_var,/*第②步中已實(shí)現(xiàn)*/
????.fb_set_par?????= my2440fb_set_par,/*設(shè)置fb_info中的參數(shù),主要是LCD的顯示模式*/
????.fb_blank???????= my2440fb_blank,/*顯示空白(即:LCD開關(guān)控制)*/
????.fb_setcolreg???= my2440fb_setcolreg,/*設(shè)置顏色表*/
????/*以下三個函數(shù)是可選的,主要是提供fb_console的支持,在內(nèi)核中已經(jīng)實(shí)現(xiàn),這里直接調(diào)用即可*/
????.fb_fillrect????= cfb_fillrect,/*定義在drivers/video/cfbfillrect.c中*/
????.fb_copyarea????= cfb_copyarea,/*定義在drivers/video/cfbcopyarea.c中*/
????.fb_imageblit???= cfb_imageblit,/*定義在drivers/video/cfbimgblt.c中*/
};
/*設(shè)置fb_info中的參數(shù),這里根據(jù)用戶設(shè)置的可變參數(shù)var調(diào)整固定參數(shù)fix*/
static int my2440fb_set_par(struct fb_info *fbinfo)
{
????/*獲得fb_info中的可變參數(shù)*/
????struct fb_var_screeninfo *var = &fbinfo->var;
????/*判斷可變參數(shù)中的色位模式,根據(jù)色位模式來設(shè)置色彩模式*/
????switch (var->bits_per_pixel)
????{
????????case 32:
????????case 16:
????????case 12:/*12BPP時,設(shè)置為真彩色(分成紅、綠、藍(lán)三基色)*/
????????????fbinfo->fix.visual = FB_VISUAL_TRUECOLOR;
????????????break;
????????case 1:/*1BPP時,設(shè)置為黑白色(分黑、白兩種色,F(xiàn)B_VISUAL_MONO01代表黑,F(xiàn)B_VISUAL_MONO10代表白)*/
????????????fbinfo->fix.visual = FB_VISUAL_MONO01;
????????????break;
????????default:/*默認(rèn)設(shè)置為偽彩色,采用索引顏色顯示*/
????????????fbinfo->fix.visual = FB_VISUAL_PSEUDOCOLOR;
????????????break;
????}
????/*設(shè)置fb_info中固定參數(shù)中一行的字節(jié)數(shù),公式:1行字節(jié)數(shù)=(1行像素個數(shù)*每像素位數(shù)BPP)/8 */
????fbinfo->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
????/*修改以上參數(shù)后,重新激活fb_info中的參數(shù)配置(即:使修改后的參數(shù)在硬件上生效)*/
????my2440fb_activate_var(fbinfo);
????return 0;
}
/*重新激活fb_info中的參數(shù)配置*/
static void my2440fb_activate_var(struct fb_info *fbinfo)
{
????/*獲得結(jié)構(gòu)體變量*/
????struct my2440fb_var?*fbvar = fbinfo->par;
????void __iomem *regs = fbvar->lcd_base;
????/*獲得fb_info可變參數(shù)*/
????struct fb_var_screeninfo *var = &fbinfo->var;
????/*計(jì)算LCD控制寄存器1中的CLKVAL值, 根據(jù)數(shù)據(jù)手冊中該寄存器的描述,計(jì)算公式如下:
????* STN屏:VCLK = HCLK / (CLKVAL * 2), CLKVAL要求>= 2
????* TFT屏:VCLK = HCLK / [(CLKVAL + 1) * 2], CLKVAL要求>= 0*/
????int clkdiv = my2440fb_calc_pixclk(fbvar, var->pixclock) / 2;
????/*獲得屏幕的類型*/
????int type = fbvar->regs.lcdcon1 & S3C2410_LCDCON1_TFT;
????if (type == S3C2410_LCDCON1_TFT)
????{
????????/*根據(jù)數(shù)據(jù)手冊按照TFT屏的要求配置LCD控制寄存器1-5*/
????????my2440fb_config_tft_lcd_regs(fbinfo, &fbvar->regs);
????????--clkdiv;
????????if (clkdiv < 0)
????????{
????????????clkdiv = 0;
????????}
????}
????else
????{
????????/*根據(jù)數(shù)據(jù)手冊按照STN屏的要求配置LCD控制寄存器1-5*/
????????my2440fb_config_stn_lcd_regs(fbinfo, &fbvar->regs);
????????if (clkdiv < 2)
????????{
????????????clkdiv = 2;
????????}
????}
????/*設(shè)置計(jì)算的LCD控制寄存器1中的CLKVAL值*/
????fbvar->regs.lcdcon1 |= S3C2410_LCDCON1_CLKVAL(clkdiv);
????/*將各參數(shù)值寫入LCD控制寄存器1-5中*/
????writel(fbvar->regs.lcdcon1 & ~S3C2410_LCDCON1_ENVID, regs + S3C2410_LCDCON1);
????writel(fbvar->regs.lcdcon2, regs + S3C2410_LCDCON2);
????writel(fbvar->regs.lcdcon3, regs + S3C2410_LCDCON3);
????writel(fbvar->regs.lcdcon4, regs + S3C2410_LCDCON4);
????writel(fbvar->regs.lcdcon5, regs + S3C2410_LCDCON5);
????/*配置幀緩沖起始地址寄存器1-3*/
????my2440fb_set_lcdaddr(fbinfo);
????fbvar->regs.lcdcon1 |= S3C2410_LCDCON1_ENVID,
????writel(fbvar->regs.lcdcon1, regs + S3C2410_LCDCON1);
}
/*計(jì)算LCD控制寄存器1中的CLKVAL值*/
static unsigned int my2440fb_calc_pixclk(struct my2440fb_var *fbvar, unsigned long pixclk)
{
????/*獲得LCD的時鐘*/
????unsigned long clk = clk_get_rate(fbvar->lcd_clock);
????/* 像素時鐘單位是皮秒,而時鐘的單位是赫茲,所以計(jì)算公式為:
???? * Hz -> picoseconds is / 10^-12
???? */
????unsigned long long div = (unsigned long long)clk * pixclk;
????div >>= 12;????????????/* div / 2^12 */
????do_div(div, 625 * 625UL * 625); /* div / 5^12, do_div宏定義在asm/div64.h中*/
????return div;
}
/*根據(jù)數(shù)據(jù)手冊按照TFT屏的要求配置LCD控制寄存器1-5*/
static void my2440fb_config_tft_lcd_regs(const struct fb_info *fbinfo, struct s3c2410fb_hw *regs)
{
????const struct my2440fb_var?*fbvar = fbinfo->par;
????const struct fb_var_screeninfo *var = &fbinfo->var;
????/*根據(jù)色位模式設(shè)置LCD控制寄存器1和5,參考數(shù)據(jù)手冊*/
????switch (var->bits_per_pixel)
????{
????????case 1:/*1BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_TFT1BPP;
????????????break;
????????case 2:/*2BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_TFT2BPP;
????????????break;
????????case 4:/*4BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_TFT4BPP;
????????????break;
????????case 8:/*8BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_TFT8BPP;
????????????regs->lcdcon5 |= S3C2410_LCDCON5_BSWP | S3C2410_LCDCON5_FRM565;
????????????regs->lcdcon5 &= ~S3C2410_LCDCON5_HWSWP;
????????????break;
????????case 16:/*16BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_TFT16BPP;
????????????regs->lcdcon5 &= ~S3C2410_LCDCON5_BSWP;
????????????regs->lcdcon5 |= S3C2410_LCDCON5_HWSWP;
????????????break;
????????case 32:/*32BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_TFT24BPP;
????????????regs->lcdcon5 &= ~(S3C2410_LCDCON5_BSWP | S3C2410_LCDCON5_HWSWP | S3C2410_LCDCON5_BPP24BL);
????????????break;
????????default:/*無效的BPP*/
????????????dev_err(fbvar->dev, "invalid bpp %d/n", var->bits_per_pixel);
????}
????/*設(shè)置LCD配置寄存器2、3、4*/
????regs->lcdcon2 = S3C2410_LCDCON2_LINEVAL(var->yres - 1) |
????????????S3C2410_LCDCON2_VBPD(var->upper_margin - 1) |
????????????S3C2410_LCDCON2_VFPD(var->lower_margin - 1) |
????????????S3C2410_LCDCON2_VSPW(var->vsync_len - 1);
????regs->lcdcon3 = S3C2410_LCDCON3_HBPD(var->right_margin - 1) |
????????????S3C2410_LCDCON3_HFPD(var->left_margin - 1) |
????????????S3C2410_LCDCON3_HOZVAL(var->xres - 1);
????regs->lcdcon4 = S3C2410_LCDCON4_HSPW(var->hsync_len - 1);
}
/*根據(jù)數(shù)據(jù)手冊按照STN屏的要求配置LCD控制寄存器1-5*/
static void my2440fb_config_stn_lcd_regs(const struct fb_info *fbinfo, struct s3c2410fb_hw *regs)
{
????const struct my2440fb_var????*fbvar = fbinfo->par;
????const struct fb_var_screeninfo *var = &fbinfo->var;
????int type = regs->lcdcon1 & ~S3C2410_LCDCON1_TFT;
????int hs = var->xres >> 2;
????unsigned wdly = (var->left_margin >> 4) - 1;
????unsigned wlh = (var->hsync_len >> 4) - 1;
????if (type != S3C2410_LCDCON1_STN4)
????{
????????hs >>= 1;
????}
????/*根據(jù)色位模式設(shè)置LCD控制寄存器1,參考數(shù)據(jù)手冊*/
????switch (var->bits_per_pixel)
????{
????????case 1:/*1BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_STN1BPP;
????????????break;
????????case 2:/*2BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_STN2GREY;
????????????break;
????????case 4:/*4BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_STN4GREY;
????????????break;
????????case 8:/*8BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_STN8BPP;
????????????hs *= 3;
????????????break;
????????case 12:/*12BPP*/
????????????regs->lcdcon1 |= S3C2410_LCDCON1_STN12BPP;
????????????hs *= 3;
????????????break;
????????default:/*無效的BPP*/
????????????dev_err(fbvar->dev, "invalid bpp %d/n", var->bits_per_pixel);
????}
????
????/*設(shè)置LCD配置寄存器2、3、4, 參考數(shù)據(jù)手冊*/
????if (wdly > 3) wdly = 3;
????if (wlh > 3) wlh = 3;
????regs->lcdcon2 = S3C2410_LCDCON2_LINEVAL(var->yres - 1);
????regs->lcdcon3 =?S3C2410_LCDCON3_WDLY(wdly) |
????????????S3C2410_LCDCON3_LINEBLANK(var->right_margin / 8) |
????????????S3C2410_LCDCON3_HOZVAL(hs - 1);
????regs->lcdcon4 = S3C2410_LCDCON4_WLH(wlh);
}
/*配置幀緩沖起始地址寄存器1-3,參考數(shù)據(jù)手冊*/
static void my2440fb_set_lcdaddr(struct fb_info *fbinfo)
{
????unsigned long saddr1, saddr2, saddr3;
????struct my2440fb_var?*fbvar = fbinfo->par;
????void __iomem *regs = fbvar->lcd_base;
????saddr1 = fbinfo->fix.smem_start >> 1;
????saddr2 = fbinfo->fix.smem_start;
????saddr2 += fbinfo->fix.line_length * fbinfo->var.yres;
????saddr2 >>= 1;
????saddr3 = S3C2410_OFFSIZE(0) | S3C2410_PAGEWIDTH((fbinfo->fix.line_length / 2) & 0x3ff);
????writel(saddr1, regs + S3C2410_LCDSADDR1);
????writel(saddr2, regs + S3C2410_LCDSADDR2);
????writel(saddr3, regs + S3C2410_LCDSADDR3);
}
/*顯示空白,blank mode有5種模式,定義在fb.h中,是一個枚舉*/
static int my2440fb_blank(int blank_mode, struct fb_info *fbinfo)
{
????struct my2440fb_var?*fbvar = fbinfo->par;
????void __iomem *regs = fbvar->lcd_base;
????/*根據(jù)顯示空白的模式來設(shè)置LCD是開啟還是停止*/
????if (blank_mode == FB_BLANK_POWERDOWN)
????{
????????my2440fb_lcd_enable(fbvar, 0);/*在第②步中定義*/
????}
????else
????{
????????my2440fb_lcd_enable(fbvar, 1);/*在第②步中定義*/
????}
????/*根據(jù)顯示空白的模式來控制臨時調(diào)色板寄存器*/
????if (blank_mode == FB_BLANK_UNBLANK)
????{
????????/*臨時調(diào)色板寄存器無效*/
????????writel(0x0, regs + S3C2410_TPAL);
????}
????else
????{
????????/*臨時調(diào)色板寄存器有效*/
????????writel(S3C2410_TPAL_EN, regs + S3C2410_TPAL);
????}
????return 0;
}
/*設(shè)置顏色表*/
static int my2440fb_setcolreg(unsigned regno,unsigned red,unsigned green,unsigned blue,unsigned transp,struct fb_info *fbinfo)
{
????unsigned int val;
????struct my2440fb_var?*fbvar = fbinfo->par;
????void __iomem *regs = fbvar->lcd_base;
????switch (fbinfo->fix.visual)
????{
????????case FB_VISUAL_TRUECOLOR:
????????????/*真彩色*/
????????????if (regno < 16)
????????????{
????????????????u32 *pal = fbinfo->pseudo_palette;
????????????????val = chan_to_field(red, &fbinfo->var.red);
????????????????val |= chan_to_field(green, &fbinfo->var.green);
????????????????val |= chan_to_field(blue, &fbinfo->var.blue);
????????????????pal[regno] = val;
????????????}
????????????break;
????????case FB_VISUAL_PSEUDOCOLOR:
????????????/*偽彩色*/
????????????if (regno < 256)
????????????{
????????????????val = (red >> 0) & 0xf800;
????????????????val |= (green >> 5) & 0x07e0;
????????????????val |= (blue >> 11) & 0x001f;
????????????????writel(val, regs + S3C2410_TFTPAL(regno));
????????????????/*修改調(diào)色板*/
????????????????schedule_palette_update(fbvar, regno, val);
????????????}
????????????break;
????????default:
????????????return 1;
????}
????return 0;
}
static inline unsigned int chan_to_field(unsigned int chan, struct fb_bitfield *bf)
{
????chan &= 0xffff;
????chan >>= 16 - bf->length;
????return chan << bf->offset;
}
/*修改調(diào)色板*/
static void schedule_palette_update(struct my2440fb_var????*fbvar, unsigned int regno, unsigned int val)
{
????unsigned long flags;
????unsigned long irqen;
????/*LCD中斷掛起寄存器基地址*/
????void __iomem *lcd_irq_base = fbvar->lcd_base + S3C2410_LCDINTBASE;
????/*在修改中斷寄存器值之前先屏蔽中斷,將中斷狀態(tài)保存到flags中*/
????local_irq_save(flags);
????fbvar->palette_buffer[regno] = val;
????/*判斷調(diào)色板是否準(zhǔn)備就像*/
????if (!fbvar->palette_ready)
????{
????????fbvar->palette_ready = 1;
????????/*使能中斷屏蔽寄存器*/
????????irqen = readl(lcd_irq_base + S3C24XX_LCDINTMSK);
????????irqen &= ~S3C2410_LCDINT_FRSYNC;
????????writel(irqen, lcd_irq_base + S3C24XX_LCDINTMSK);
????}
????/*恢復(fù)被屏蔽的中斷*/
????local_irq_restore(flags);
}
五、從整體上再描述一下FrameBuffer設(shè)備驅(qū)動實(shí)例代碼的結(jié)構(gòu):
1、在第①部分代碼中主要做的事情有:
a.將LCD設(shè)備注冊到系統(tǒng)平臺設(shè)備中;
b.定義LCD平臺設(shè)備結(jié)構(gòu)體lcd_fb_driver。
2、在第②部分代碼中主要做的事情有:
a.獲取和設(shè)置LCD平臺設(shè)備的各種資源;
b.分配fb_info結(jié)構(gòu)體空間;
c.初始化fb_info結(jié)構(gòu)體中的各參數(shù);
d.初始化LCD控制器;
e.檢查fb_info中可變參數(shù);
f.申請幀緩沖設(shè)備的顯示緩沖區(qū)空間;
g.注冊fb_info。
3、在第③部分代碼中主要做的事情有:
a.實(shí)現(xiàn)對fb_info相關(guān)參數(shù)進(jìn)行檢查的硬件接口函數(shù);
b.實(shí)現(xiàn)對LCD顯示模式進(jìn)行設(shè)定的硬件接口函數(shù);
c.實(shí)現(xiàn)對LCD顯示開關(guān)(空白)的硬件接口函數(shù)等。
void __init s3c24xx_fb_set_platdata(struct s3c2410fb_mach_info *pd)
{
????struct s3c2410fb_mach_info *npd;
????npd = kmalloc(sizeof(*npd), GFP_KERNEL);
????if (npd) {
????????memcpy(npd, pd, sizeof(*npd));
//這里就是將內(nèi)核中定義的s3c2410fb_mach_info結(jié)構(gòu)體數(shù)據(jù)保存到LCD平臺數(shù)據(jù)中,所以在寫驅(qū)動的時候就可以直接在平臺數(shù)據(jù)中獲取s3c2410fb_mach_info結(jié)構(gòu)體的數(shù)據(jù)(即LCD各種參數(shù)信息)進(jìn)行操作
????????s3c_device_lcd.dev.platform_data = npd;
????} else {
????????printk(KERN_ERR "no memory for LCD platform data/n");
????}
}
//S3C2440初始化函數(shù)
static void __init smdk2440_machine_init(void)
{
//調(diào)用該函數(shù)將上面定義的LCD硬件信息保存到平臺數(shù)據(jù)中
????s3c24xx_fb_set_platdata(&smdk2440_fb_info);
????
????s3c_i2c0_set_platdata(NULL);
????platform_add_devices(smdk2440_devices, ARRAY_SIZE(smdk2440_devices));
????smdk_machine_init();
}
/* LCD Controller */
//LCD控制器的資源信息
static struct resource s3c_lcd_resource[] = {
????[0] = {
????????.start = S3C24XX_PA_LCD, //控制器IO端口開始地址
????????.end = S3C24XX_PA_LCD + S3C24XX_SZ_LCD - 1,//控制器IO端口結(jié)束地址
????????.flags = IORESOURCE_MEM,//標(biāo)識為LCD控制器IO端口,在驅(qū)動中引用這個就表示引用IO端口
????},
????[1] = {
????????.start = IRQ_LCD,//LCD中斷
????????.end = IRQ_LCD,
????????.flags = IORESOURCE_IRQ,//標(biāo)識為LCD中斷
????}
};
static u64 s3c_device_lcd_dmamask = 0xffffffffUL;
struct platform_device s3c_device_lcd = {
????.name???????? = "s3c2410-lcd",//作為平臺設(shè)備的LCD設(shè)備名
????.id???????? = -1,
????.num_resources?= ARRAY_SIZE(s3c_lcd_resource),//資源數(shù)量
????.resource???? = s3c_lcd_resource,//引用上面定義的資源
????.dev = {
????????.dma_mask?= &s3c_device_lcd_dmamask,
????????.coherent_dma_mask?= 0xffffffffUL
????}
};
EXPORT_SYMBOL(s3c_device_lcd);//導(dǎo)出定義的LCD平臺設(shè)備,好在mach-smdk2440.c的smdk2440_devices[]中添加到平臺設(shè)備列表中
struct fb_info {
????int node;
????int flags;
????struct fb_var_screeninfo var;/*LCD可變參數(shù)結(jié)構(gòu)體*/
????struct fb_fix_screeninfo fix;/*LCD固定參數(shù)結(jié)構(gòu)體*/
????struct fb_monspecs monspecs;?/*LCD顯示器標(biāo)準(zhǔn)*/
????struct work_struct queue;????/*幀緩沖事件隊(duì)列*/
????struct fb_pixmap pixmap;???? /*圖像硬件mapper*/
????struct fb_pixmap sprite;???? /*光標(biāo)硬件mapper*/
????struct fb_cmap cmap;???????? /*當(dāng)前的顏色表*/
????struct fb_videomode *mode;???/*當(dāng)前的顯示模式*/
#ifdef CONFIG_FB_BACKLIGHT
????struct backlight_device *bl_dev;/*對應(yīng)的背光設(shè)備*/
????struct mutex bl_curve_mutex;
????u8 bl_curve[FB_BACKLIGHT_LEVELS];/*背光調(diào)整*/
#endif
#ifdef CONFIG_FB_DEFERRED_IO
????struct delayed_work deferred_work;
????struct fb_deferred_io *fbdefio;
#endif
????struct fb_ops *fbops; /*對底層硬件操作的函數(shù)指針*/
????struct device *device;
????struct device *dev;???/*fb設(shè)備*/
????int class_flag;????
#ifdef CONFIG_FB_TILEBLITTING
????struct fb_tile_ops *tileops; /*圖塊Blitting*/
#endif
????char __iomem *screen_base;???/*虛擬基地址*/
????unsigned long screen_size;???/*LCD IO映射的虛擬內(nèi)存大小*/
????void *pseudo_palette;????????/*偽16色顏色表*/
#define FBINFO_STATE_RUNNING????0
#define FBINFO_STATE_SUSPENDED??1
????u32 state;??/*LCD的掛起或恢復(fù)狀態(tài)*/
????void *fbcon_par;
????void *par;????
};
其中,比較重要的成員有struct fb_var_screeninfo var、struct fb_fix_screeninfo fix和struct fb_ops *fbops,他們也都是結(jié)構(gòu)體。下面我們一個一個的來看。
fb_var_screeninfo結(jié)構(gòu)體主要記錄用戶可以修改的控制器的參數(shù),比如屏幕的分辨率和每個像素的比特?cái)?shù)等,該結(jié)構(gòu)體定義如下:
而fb_fix_screeninfo結(jié)構(gòu)體又主要記錄用戶不可以修改的控制器的參數(shù),比如屏幕緩沖區(qū)的物理地址和長度等,該結(jié)構(gòu)體的定義如下:
struct fb_fix_screeninfo {
????char id[16];????????????????/*字符串形式的標(biāo)示符 */
????unsigned long smem_start;???/*fb緩存的開始位置 */
????__u32 smem_len;?????????????/*fb緩存的長度 */
????__u32 type;?????????????????/*看FB_TYPE_* */
????__u32 type_aux;?????????????/*分界*/
????__u32 visual;???????????????/*看FB_VISUAL_* */
????__u16 xpanstep;?????????????/*如果沒有硬件panning就賦值為0 */
????__u16 ypanstep;?????????????/*如果沒有硬件panning就賦值為0 */
????__u16 ywrapstep;????????????/*如果沒有硬件ywrap就賦值為0 */
????__u32 line_length;??????????/*一行的字節(jié)數(shù) */
????unsigned long mmio_start;???/*內(nèi)存映射IO的開始位置*/
????__u32 mmio_len;?????????????/*內(nèi)存映射IO的長度*/
????__u32 accel;
????__u16 reserved[3];??????????/*保留*/
};
struct fb_var_screeninfo {
????__u32 xres;????????????????/*可見屏幕一行有多少個像素點(diǎn)*/
????__u32 yres;????????????????/*可見屏幕一列有多少個像素點(diǎn)*/
????__u32 xres_virtual;????????/*虛擬屏幕一行有多少個像素點(diǎn)*/????????
????__u32 yres_virtual;????????/*虛擬屏幕一列有多少個像素點(diǎn)*/
????__u32 xoffset;?????????????/*虛擬到可見屏幕之間的行偏移*/
????__u32 yoffset;?????????????/*虛擬到可見屏幕之間的列偏移*/
????__u32 bits_per_pixel;??????/*每個像素的位數(shù)即BPP*/
????__u32 grayscale;???????????/*非0時,指的是灰度*/
????struct fb_bitfield red;????/*fb緩存的R位域*/
????struct fb_bitfield green;??/*fb緩存的G位域*/
????struct fb_bitfield blue;???/*fb緩存的B位域*/
????struct fb_bitfield transp;?/*透明度*/????
????__u32 nonstd;??????????????/* != 0 非標(biāo)準(zhǔn)像素格式*/
????__u32 activate;????????????????
????__u32 height;??????????????/*高度*/
????__u32 width;???????????????/*寬度*/
????__u32 accel_flags;????
????/*定時:除了pixclock本身外,其他的都以像素時鐘為單位*/
????__u32 pixclock;????????????/*像素時鐘(皮秒)*/
????__u32 left_margin;?????????/*行切換,從同步到繪圖之間的延遲*/
????__u32 right_margin;????????/*行切換,從繪圖到同步之間的延遲*/
????__u32 upper_margin;????????/*幀切換,從同步到繪圖之間的延遲*/
????__u32 lower_margin;????????/*幀切換,從繪圖到同步之間的延遲*/
????__u32 hsync_len;???????????/*水平同步的長度*/
????__u32 vsync_len;???????????/*垂直同步的長度*/
????__u32 sync;
????__u32 vmode;
????__u32 rotate;
????__u32 reserved[5];?????????/*保留*/
};
?
評論
查看更多