一. 理論分析1. 幾個概念:FIMC : Fully Interactive Mobile Camera (完全互動式移動攝像機)FIMD: Fully Interactive Mobile Display (完全互動式移動顯示設備)2. 設置VCLK在VIDCON0中bit[3:2]-->Sel
一. 理論分析
1. 幾個概念:
FIMC :
Fully Interactive Mobile Camera (完全互動式移動攝像機)
FIMD:
Fully Interactive Mobile Display (完全互動式移動顯示設備)
2. 設置VCLK
在VIDCON0中
bit[3:2]-->Select the Video Clock source =00 --> HCLK=133MHZ
bit[13:6] --> CLKVAL_F = 13 (這個值是在驅動中計算出來的)
VCLK = Video Clock Source / (CLKVAL+1) where CLKVAL >= 1
= 133MHZ / (13+1) = 9.5MHZ
3. 刷新頻率計算
Frame Rate = VCLK / (HSPW + HBPD + HOZVAL + HFPD) / (VSPW + VBPD + LINEVAL + VFPD)
= 9.5MHZ/(2+41+2+480)/(2+272+10+2)
=0.00006327MHZ
=63HZ
二. 驅動分析
首先在平臺的目錄中定義platform_device
在arch/arm/plat-samsung/dev-fb.c中
- static struct resource s3c_fb_resource[] = {
- [0] = {
- .start = S3C_PA_FB,
- .end = S3C_PA_FB + SZ_16K - 1,
- .flags = IORESOURCE_MEM,
- },
- [1] = {
- .start = IRQ_LCD_VSYNC,
- .end = IRQ_LCD_VSYNC,
- .flags = IORESOURCE_IRQ,
- },
- [2] = {
- .start = IRQ_LCD_FIFO,
- .end = IRQ_LCD_FIFO,
- .flags = IORESOURCE_IRQ,
- },
- [3] = {
- .start = IRQ_LCD_SYSTEM,
- .end = IRQ_LCD_SYSTEM,
- .flags = IORESOURCE_IRQ,
- },
- };
- struct platform_device s3c_device_fb = {
- .name = "s3c-fb",
- .id = -1,
- .num_resources = ARRAY_SIZE(s3c_fb_resource),
- .resource = s3c_fb_resource,
- .dev.dma_mask = &s3c_device_fb.dev.coherent_dma_mask,
- .dev.coherent_dma_mask = 0xffffffffUL,
- };
然後在驅動的probe函數中:
在driver/video/samsun/s3cfb.c中
- static int __init s3cfb_probe(struct platform_device *pdev)
- {
- struct resource *res;
- struct fb_info *fbinfo;
- s3cfb_info_t *info;
- char driver_name[] = "s3cfb";
- int index = 0, ret, size;
- //分配sizeof(fb_info+私有成員)大小的記憶體,使par指向s3cfb_info_t結構體
- fbinfo = framebuffer_alloc(sizeof(s3cfb_info_t), &pdev->dev);
- platform_set_drvdata(pdev, fbinfo);
- info = fbinfo->par; //私有數據是一個結構體s3cfb_info_t
- info->dev = &pdev->dev;
- //獲取LCD的io埠,並映射
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- size = (res->end - res->start) + 1;
- info->mem = request_mem_region(res->start, size, pdev->name);
- info->io = ioremap(res->start, size);
- s3cfb_pre_init(); //2.使能中斷寄存器,s3cfb_fimd的第一次初始化
- s3cfb_set_backlight_power(1); //設置backlight_power = 1;
- s3cfb_set_lcd_power(1); //設置lcd_power = 1;
- s3cfb_set_backlight_level(S3CFB_DEFAULT_BACKLIGHT_LEVEL); //設置backlight_level = 2;
- //獲取時鐘,並使能
- info->clk = clk_get(NULL, "lcd"); //133.000Mhz,使用的是HCLK
- clk_enable(info->clk);
- s3cfb_fimd.vsync_info.count = 0;
- init_waitqueue_head(&s3cfb_fimd.vsync_info.wait_queue);
- //申請中斷
- res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
- ret = request_irq(res->start, s3cfb_irq, 0, "s3c-lcd", pdev);
- msleep(5);
- //對4個framebuffer分別初始化
- for (index = 0; index < S3CFB_NUM; index++) {
- s3cfb_info[index].mem = info->mem;
- s3cfb_info[index].io = info->io;
- s3cfb_info[index].clk = info->clk;
- s3cfb_init_fbinfo(&s3cfb_info[index], driver_name, index); //3.初始化fbinfo
- ret = s3cfb_map_video_memory(&s3cfb_info[index]); //4.分配dma記憶體
- ret = s3cfb_init_registers(&s3cfb_info[index]); //5.寫寄存器
- ret = s3cfb_check_var(&s3cfb_info[index].fb.var, &s3cfb_info[index].fb); //6.設置var範圍
- if (index < 2){
- if (fb_alloc_cmap(&s3cfb_info[index].fb.cmap, 256, 0) < 0) //7.申請color map
- goto dealloc_fb;
- } else {
- if (fb_alloc_cmap(&s3cfb_info[index].fb.cmap, 16, 0) < 0)
- goto dealloc_fb;
- }
- ret = register_framebuffer(&s3cfb_info[index].fb); //8.註冊framebuffer
- }
- ret = device_create_file(&(pdev->dev), &dev_attr_backlight_power);
- ret = device_create_file(&(pdev->dev), &dev_attr_backlight_level);
- ret = device_create_file(&(pdev->dev), &dev_attr_lcd_power);
- return 0;
- }
1.分配記憶體
分配fb_info+size大小的記憶體,並使par指向私有數據size
- struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
- {
- fb_info_size += PADDING; //加上PADDING是讓私有數據4位元組對齊
- char *p = kzalloc(fb_info_size + size, GFP_KERNEL);
- struct fb_info * info = (struct fb_info *) p;
- info->par = p + fb_info_size; //par指向私有數據
- info->device = dev;
- return info; //返回申請記憶體的首指針
- }
2. 初始化視頻中斷控制寄存器0
在drivers/video/samsun/s3cfb_fimd4x.c中
- void s3cfb_pre_init(void)
- {
- //Video Frame Interrupt 0 at start of VSYNC,並使能
- s3cfb_fimd.vidintcon0 &= ~S3C_VIDINTCON0_FRAMESEL0_MASK;
- s3cfb_fimd.vidintcon0 |= S3C_VIDINTCON0_FRAMESEL0_VSYNC;
- s3cfb_fimd.vidintcon0 |= S3C_VIDINTCON0_INTFRMEN_ENABLE;
- //0x9021=1001 0000 0010 0001
- //打開video 中斷,關閉fifo 中斷
- //打開 video frame 中斷, Video Frame Interrupt 0 at start of VSYNC
writel(s3cfb_fimd.vidintcon0, S3C_VIDINTCON0); - }
在driver/vidoe/samsun/s3cfb.c中
- static void s3cfb_set_lcd_power(int to)
- {
- s3cfb_fimd.lcd_power = to;
- }
- static void s3cfb_set_backlight_power(int to)
- {
- s3cfb_fimd.backlight_power = to;
- }
- static void s3cfb_set_backlight_level(int to)
- {
- s3cfb_fimd.backlight_level = to;
- }
3. 初始化s3cfb_info_t結構體
在driver/vidoe/samsun/s3cfb.c中
- static void s3cfb_init_fbinfo(s3cfb_info_t *finfo, char *drv_name, int index)
- {
- int i = 0;
- if (index == 0)
- {
- if(lcdsize == 1)
- s3cfb_init_hw_43(); //3.1 s3cfb_fimd及gpio的初始化
- }
- strcpy(finfo->fb.fix.id, drv_name);
- //下麵一大段就是要將初始化好後的s3cfb_fimd賦給finfo,類似於結構體轉化
- finfo->win_id = index;
- finfo->fb.fix.type = FB_TYPE_PACKED_PIXELS;
- finfo->fb.fix.type_aux = 0;
- finfo->fb.fix.xpanstep = 0;
- finfo->fb.fix.ypanstep = 1;
- finfo->fb.fix.ywrapstep = 0;
- finfo->fb.fix.accel = FB_ACCEL_NONE;
- finfo->fb.fbops = &s3cfb_ops; //fb操作函數
- finfo->fb.flags = FBINFO_FLAG_DEFAULT;
- finfo->fb.pseudo_palette = &finfo->pseudo_pal;
- finfo->fb.var.nonstd = 0;
- finfo->fb.var.activate = FB_ACTIVATE_NOW;
- finfo->fb.var.accel_flags = 0;
- finfo->fb.var.vmode = FB_VMODE_NONINTERLACED;
- finfo->fb.var.xoffset = s3cfb_fimd.xoffset; //xoffset=0
- finfo->fb.var.yoffset = s3cfb_fimd.yoffset; //yoffset=0
- if (index == 0) {
- finfo->fb.var.height = s3cfb_fimd.height; //height=272
- finfo->fb.var.width = s3cfb_fimd.width; //width=480
- finfo->fb.var.xres = s3cfb_fimd.xres; //xres=480
- finfo->fb.var.yres = s3cfb_fimd.yres; //yres=272
- finfo->fb.var.xres_virtual = s3cfb_fimd.xres_virtual; //xres_virtual=480
- finfo->fb.var.yres_virtual = s3cfb_fimd.yres_virtual; //yres_virtual=544
- } else {
- finfo->fb.var.height = s3cfb_fimd.osd_height; //osd_height=272
- finfo->fb.var.width = s3cfb_fimd.osd_width; //osd_height=480
- finfo->fb.var.xres = s3cfb_fimd.osd_xres; //osd_xres=480
- finfo->fb.var.yres = s3cfb_fimd.osd_yres; //osd_yres=272
- finfo->fb.var.xres_virtual = s3cfb_fimd.osd_xres_virtual; //osd_xres_virtual=480
- finfo->fb.var.yres_virtual = s3cfb_fimd.osd_yres_virtual; //osd_yres_virtaul=272
- }
- finfo->fb.var.bits_per_pixel = s3cfb_fimd.bpp; //16
- finfo->fb.var.pixclock = s3cfb_fimd.pixclock; //9009000
- finfo->fb.var.hsync_len = s3cfb_fimd.hsync_len; //41
- finfo->fb.var.left_margin = s3cfb_fimd.left_margin; //2
- finfo->fb.var.right_margin = s3cfb_fimd.right_margin; //2
- finfo->fb.var.vsync_len = s3cfb_fimd.vsync_len; //10
- finfo->fb.var.upper_margin = s3cfb_fimd.upper_margin; //2
- finfo->fb.var.lower_margin = s3cfb_fimd.lower_margin; //2
- finfo->fb.var.sync = s3cfb_fimd.sync; //0
- finfo->fb.var.grayscale = s3cfb_fimd.cmap_grayscale; //0
- //480*544*2=522240
- finfo->fb.fix.smem_len = finfo->fb.var.xres_virtual * finfo->fb.var.yres_virtual * s3cfb_fimd.bytes_per_pixel;
- finfo->fb.fix.line_length = finfo->fb.var.width * s3cfb_fimd.bytes_per_pixel; //480*2=960
- for (i = 0; i < 256; i++)
- finfo->palette_buffer[i] = S3CFB_PALETTE_BUFF_CLEAR; //(0x80000000)
- }
3.1 初始化s3cfb_fimd及gpio的初始化
在drviers/video/samsung/s3cfb_WXCAT43.c中
- void s3cfb_init_hw_43(void)
- {
- s3cfb_set_fimd_info(); //3.1.1 s3cfb_fimd的第二次初始化
- s3cfb_set_gpio(); //3.1.2 gpio口初始化
- }
3.1.1 s3cfb_fimd結構體的第二次初始化
s3cfb_probe
--> s3cfb_init_fbinfo
--> s3cfb_init_hw_43
--> s3cfb_set_fimd_info
- static void s3cfb_set_fimd_info(void)
- {
- // bit[7]= 0: RGB type LCD driver gets the video data at VCLK falling edge,下降沿獲取數據
- // bit[6]= 1: HSYNC 極性反轉
- // bit[5]= 1: VSYNC 極性反轉
- // bit[4]= 0: VDEN 極性不變
- s3cfb_fimd.vidcon1 = S3C_VIDCON1_IHSYNC_INVERT | S3C_VIDCON1_IVSYNC_INVERT | S3C_VIDCON1_IVDEN_NORMAL; //0x60
- //VBPDE[31-24]=0x0
- //VBPD[23-16]=0x01
- //VFPD[15-8]=0x01
- //VSPW[7-0]=0x09
- s3cfb_fimd.vidtcon0 = S3C_VIDTCON0_VBPD(S3CFB_VBP - 1) | S3C_VIDTCON0_VFPD(S3CFB_VFP - 1) | S3C_VIDTCON0_VSPW(S3CFB_VSW - 1); //0x10109
- //HBPDE[31-24]=0x0
- //HBPD[23-16]=0x01
- //HFPD[15-8]=0x01
- //HSPW[7-0]=0x28=40
- s3cfb_fimd.vidtcon1 = S3C_VIDTCON1_HBPD(S3CFB_HBP - 1) | S3C_VIDTCON1_HFPD(S3CFB_HFP - 1) | S3C_VIDTCON1_HSPW(S3CFB_HSW - 1); //0x10128
- //LINEVAL[21-11]=(Vertical display size)–1=10F=271
- //HOZVAL[10-0] = (Horizontal display size)-1=1DF=479
- s3cfb_fimd.vidtcon2 = S3C_VIDTCON2_LINEVAL(S3CFB_VRES - 1) | S3C_VIDTCON2_HOZVAL(S3CFB_HRES - 1); //0x879df
- //OSD_LeftTopX_F[21-11] = 0
- //OSD_LeftTopY_F[10-0] = 0 window_0左上角的坐標是(0,0)
- s3cfb_fimd.vidosd0a = S3C_VIDOSDxA_OSD_LTX_F(0) | S3C_VIDOSDxA_OSD_LTY_F(0); //0x0
- //OSD_RightBotX_F[21-11] = 0x1DF=479
- //OSD_RightBotY_F[10-0] = 0x10f =271 window_0右下角的坐標是(479,271)
- s3cfb_fimd.vidosd0b = S3C_VIDOSDxB_OSD_RBX_F(S3CFB_HRES - 1) | S3C_VIDOSDxB_OSD_RBY_F(S3CFB_VRES - 1); //0xef90f
- //OSD_LeftTopX_F[21-11] = 0
- //OSD_LeftTopY_F[10-0] = 0 window_1左上角的坐標是(0,0)
- s3cfb_fimd.vidosd1a = S3C_VIDOSDxA_OSD_LTX_F(0) | S3C_VIDOSDxA_OSD_LTY_F(0); //0x0
- //OSD_RightBotX_F[21-11] = 0x1DF=479
- //OSD_RightBotY_F[10-0] = 0x10f =271 window_1右下角的坐標是(479,271)
- s3cfb_fimd.vidosd1b = S3C_VIDOSDxB_OSD_RBX_F(S3CFB_HRES_OSD - 1) | S3C_VIDOSDxB_OSD_RBY_F(S3CFB_VRES_OSD - 1); //0xef90f
- s3cfb_fimd.width = S3CFB_HRES; //480
- s3cfb_fimd.height = S3CFB_VRES; //272
- s3cfb_fimd.xres = S3CFB_HRES; //480
- s3cfb_fimd.yres = S3CFB_VRES; //272
- //定義了(CONFIG_FB_S3C_EXT_VIRTUAL_SCREEN)
- s3cfb_fimd.xres_virtual = S3CFB_HRES_VIRTUAL; //如果定義了Virtual_screen則為480*544
- s3cfb_fimd.yres_virtual = S3CFB_VRES_VIRTUAL; //如果沒有定義Virtual_screen則為480*272
- s3cfb_fimd.osd_width = S3CFB_HRES_OSD; //480
- s3cfb_fimd.osd_height = S3CFB_VRES_OSD; //272
- s3cfb_fimd.osd_xres = S3CFB_HRES_OSD; //480
- s3cfb_fimd.osd_yres = S3CFB_VRES_OSD; //272
- s3cfb_fimd.osd_xres_virtual = S3CFB_HRES_OSD; //480
- s3cfb_fimd.osd_yres_virtual = S3CFB_VRES_OSD; //272
- s3cfb_fimd.pixclock = S3CFB_PIXEL_CLOCK; //9009000
- s3cfb_fimd.hsync_len = S3CFB_HSW; //41
- s3cfb_fimd.vsync_len = S3CFB_VSW; //10
- s3cfb_fimd.left_margin = S3CFB_HFP; //2
- s3cfb_fimd.upper_margin = S3CFB_VFP; //2
- s3cfb_fimd.right_margin = S3CFB_HBP; //2
- s3cfb_fimd.lower_margin = S3CFB_VBP; //2
- }
小總結一下:
全局變數s3cfb_fimd_info_t s3cfb_fimd
首先定義在drivers/video/samsun/s3cfb_fimd4x.c中
第1次初始化
s3cfb_probe
--> s3cfb_pre_init();
打開video 中斷,關閉fifo 中斷
打開 video frame 中斷, Video Frame Interrupt 0 at start of VSYNC
第2次初始化
s3cfb_probe
--> s3cfb_init_fbinfo
--> s3cfb_init_hw_43
--> s3cfb_set_fimd_info
3.1.2 gpio口初始化
在
- int s3cfb_set_gpio(void)
- {
- //將HCLK clock gating control寄存器0x7E00_F030的bit3設為1,即使能LCD的時鐘
- val = readl(S3C_HCLK_GATE);
- val |= S3C_CLKCON_HCLK_LCD;
- writel(val, S3C_HCLK_GATE);
- //設置Special PortControl Register寄存器0x7F0081A0的bit[0-1]設為01,即RGB I/F style
- val = readl(S3C64XX_SPCON);
- val &= ~0x3;
- val |= (1 << 0);
- writel(val, S3C64XX_SPCON);
- //VD[0-15]連在了GPI[0-15]上,所以要把GPI口配成LCD
- for (i = 0; i < 16; i++)
- s3c_gpio_cfgpin(S3C64XX_GPI(i), S3C_GPIO_SFN(2));
- //VD[16-23]連在了GPJ[0-7]上,所以要把GPJ口配成LCD
- //HSYNC-->GPJ8, VSYNC-->GPJ9, VDEN-->GPJ10, VCLK-->GPJ11
- for (i = 0; i < 12; i++)
- s3c_gpio_cfgpin(S3C64XX_GPJ(i), S3C_GPIO_SFN(2));
//ok6410跟GPE0好像沒有什麼關係,這兒可以去掉- if (gpio_is_valid(S3C64XX_GPE(0))) {
- err = gpio_request(S3C64XX_GPE(0), "GPE");
- gpio_direction_output(S3C64XX_GPE(0), 1);
- }
- gpio_set_value(S3C64XX_GPE(0), 1);
- gpio_free(S3C64XX_GPE(0));
- gpio_free(S3C64XX_GPF(14));
- return 0;
- }
4. 分配DMA記憶體
第1個window,雙緩衝 0x7f8000=320*240*3*2
FB1: map_video_memory: dma=5f180000 cpu=ff600000 size=0007f800
Window[0] - FB2: map_video_memory: dma=5f1bfc00 cpu=ff63fc00 size=0003fc00
第2個window,雙緩衝
FB1: map_video_memory: dma=5f200000 cpu=ff700000 size=0007f800
Window[1] - FB2: map_video_memory: dma=5f23fc00 cpu=ff73fc00 size=0003fc00
在drivers/vidoe/samsun/s3cfb.c中
- static int __init s3cfb_map_video_memory(s3cfb_info_t *fbi)
- {
- fbi->map_size_f1 = PAGE_ALIGN(fbi->fb.fix.smem_len); //480*272*n對齊到4K
- //index=0時在DMA空間分配480*272*4=0x7f800=對齊後0x80000大小的DMA記憶體
- //index=1,2,3時在DMA空間分配480*272*2=0x3fc00=對齊後0x40000大小的DMA記憶體
- fbi->map_cpu_f1 = dma_alloc_writecombine(fbi->dev, fbi->map_size_f1, &fbi->map_dma_f1, GFP_KERNEL); //分配dma記憶體
- fbi->map_size_f1 = fbi->fb.fix.smem_len; //480*272*n原始大小,不對齊到4K
- if (fbi->map_cpu_f1) { //map_cpu_f1是將dma映射到虛擬記憶體空間的地址
- memset(fbi->map_cpu_f1, 0xf0, fbi->map_size_f1); //初始化成0xf0?這兒為什麼不是0?
- fbi->screen_dma_f1 = fbi->map_dma_f1;
- fbi->fb.screen_base = fbi->map_cpu_f1;
- fbi->fb.fix.smem_start = fbi->screen_dma_f1;
- }
- //下麵的指針指向第二個 buffer
- #if defined(CONFIG_FB_S3C_EXT_DOUBLE_BUFFERING)
- if (fbi->win_id<2 && fbi->map_cpu_f1) {
- fbi->map_size_f2 = (fbi->fb.fix.smem_len / 2);
- fbi->map_cpu_f2 = fbi->map_cpu_f1 + fbi->map_size_f2;
- fbi->map_dma_f2 = fbi->map_dma_f1 + fbi->map_size_f2;
- fbi->screen_dma_f2 = fbi->map_dma_f2;
- }
- #endif
- return 0;
- }
註: void *dma_alloc_writecombine(struct device *, size_t, dma_addr_t *, gfp_t);
arg1是設備名
arg2是分配dma buffer的長度
arg3是分配dma的物理地址,利用指針改寫
arg4是標誌GFP_KERNEL
ret 返回分配dma的虛擬地址
ret 與 arg3都指向同一塊記憶體,只不過argc3是物理地址,ret是虛擬地址.
dma_alloc_coherent: 禁止頁表項中的C(cacheable)以及B(bufferable)域
dma_alloc_writecombine只是禁止C(Cacheable)域.即不使用cache
5. 寫寄存器
在driver/video/samsun中
- int s3cfb_init_registers(s3cfb_info_t *fbi)
- {
- struct clk *lcd_clock;
- struct fb_var_screeninfo *var = &fbi->fb.var;
- unsigned long flags = 0, page_width = 0, offset = 0;
- unsigned long video_phy_temp_f1 = fbi->screen_dma_f1;
- unsigned long video_phy_temp_f2 = fbi->screen_dma_f2;
- int win_num = fbi->win_id;
- local_irq_save(flags); //關中斷,並保存
- page_width = var->xres * s3cfb_fimd.bytes_per_pixel; //page_width=960
- offset = (var->xres_virtual - var->xres) * s3cfb_fimd.bytes_per_pixel; //offset=0
- if (win_num == 0) {
- s3cfb_fimd.vidcon0 = s3cfb_fimd.vidcon0 & ~(S3C_VIDCON0_ENVID_ENABLE | S3C_VIDCON0_ENVID_F_ENABLE);
- writel(s3cfb_fimd.vidcon0, S3C_VIDCON0); //設置lcd的clk分頻-->Divided by CLKVAL_F
- lcd_clock = clk_get(NULL, "lcd");
- s3cfb_fimd.vidcon0 |= S3C_VIDCON0_CLKVAL_F((int) ((clk_get_rate(lcd_clock) / s3cfb_fimd.pixclock) - 1));
- //lcd_clock->rate=13M, s3cfb_fimd.pixclock=9M, s3cfb_fimd.vidcon0[13-6]=13
- #if defined(CONFIG_FB_S3C_EXT_VIRTUAL_SCREEN)
- offset = 0;
- s3cfb_fimd.vidw00add0b0 = video_phy_temp_f1;
- s3cfb_fimd.vidw00add0b1 = video_phy_temp_f2;
- s3cfb_fimd.vidw00add1b0 = S3C_VIDWxxADD1_VBASEL_F((unsigned long) video_phy_temp_f1 + (page_width + offset) * (var->yres));
- s3cfb_fimd.vidw00add1b1 = S3C_VIDWxxADD1_VBASEL_F((unsigned long) video_phy_temp_f2 + (page_width + offset) * (var->yres));
- #endif
- }
- writel(video_phy_temp_f1, S3C_VIDW00ADD0B0 + (0x08 * win_num));
- writel(S3C_VIDWxxADD1_VBASEL_F((unsigned long) video_phy_temp_f1 + (page_width + offset) * (var->yres)), S3C_VIDW00ADD1B0 + (0x08 * win_num));
- writel(S3C_VIDWxxADD2_OFFSIZE_F(offset) | (S3C_VIDWxxADD2_PAGEWIDTH_F(page_width)), S3C_VIDW00ADD2 + (0x04 * win_num));
- if (win_num < 2) {
- writel(video_phy_temp_f2, S3C_VIDW00ADD0B1 + (0x08 * win_num));
- writel(S3C_VIDWxxADD1_VBASEL_F((unsigned long) video_phy_temp_f2 + (page_width + offset) * (var->yres)), S3C_VIDW00ADD1B1 + (0x08 * win_num));
- }
- switch (win_num) {
- case 0:
- //wincon0=0x110014=0001 0001 0000 0000 0001 0100
- //bit[0]=video output disable --> 導致bit[22]=0
- //bit[5-2]=0101=16BPP (R5 G6 B5)
- //bit[10-9]=00 = DMA's Burst Max len 16word
- //bit[13] = 0 = input color space RGB
- //bit[16] = 1 = half wrod swap enabel
- //bit[20] = 1 = select buf 1
- writel(s3cfb_fimd.wincon0, S3C_WINCON0);
- //vidcon0=0x350=0011 0101 0000
- //bit[3-2]=00 = VideoClock source = HCLK
- //bit[4]=1=video clock Divided by CLKVAL_F
- //bit[13-6]=00 1101 = 13 HCLK/CLKVAL_F=133/13=10.230769231M
- writel(s3cfb_fimd.vidcon0, S3C_VIDCON0);
- //vidcon1=0x60 = 0110 0000
- //bit[4]= VDEN polarity noraml
- //bit[5]=VSYNC polarity inverted
- //bit[6]=HSYNC polarity inverted
- //bit[7]=gets the video data at vclk falling
- writel(s3cfb_fimd.vidcon1, S3C_VIDCON1);
- //vidtcon0=0x10109
- //VBPDE[31-24]= 0x0
- //VBPD[23-16]= 0x01
- //VFPD[15-8]= 0x01
- //VSPW[7-0]= 0x09
- writel(s3cfb_fimd.vidtcon0, S3C_VIDTCON0);
- //vidtcon1=0x10128
- //VFPDE[31-24]=0x0
- //HBPD[23-16]=0x01
- //HFPD[15-8]=0x01
- //HSPW[7-0]= 0x28=40
- writel(s3cfb_fimd.vidtcon1, S3C_VIDTCON1);
- //vidtcon2=0x879df
- //LINEVAL[21-11]=(Vertical display size)–1=10F=271
//HOZVAL[10-0] = (Horizontal display size)-1=1DF=479 - writel(s3cfb_fimd.vidtcon2, S3C_VIDTCON2);
- //dithmode=0x0
- //禁用dither
- writel(s3cfb_fimd.dithmode, S3C_DITHMODE);
- //vidintcon0=0x9021=0x1001 0000 0010 0001
- //bit[0]=Video Interrupt Enable
- //bit[1]=FIFO disable
- //bit[4-2]=FIFO int level =25
- //bit[11-5]=FIFO int -->win 0 control enable
- //bit[12]=video Frame interrupt enable
- //bit[14-13]=video frame int 1 start of None
- //bit[16-15]=video frame int 0 start of VSYNC
- writel(s3cfb_fimd.vidintcon0, S3C_VIDINTCON0);
- //vidintcon1=0x0
- //沒看出什麼用
- writel(s3cfb_fimd.vidintcon1, S3C_VIDINTCON1);
- //vidosd0a=0x0
- //window_0左上角坐標(0,0)
- writel(s3cfb_fimd.vidosd0a, S3C_VIDOSD0A);
- //vidosd0b=0xef90f
- //window_0右下角的坐標是(479,271)
- writel(s3cfb_fimd.vidosd0b, S3C_VIDOSD0B);
- //vidosd0c=0x0
- //bit[23-0]=Window Size = 竟然為0?
- writel(s3cfb_fimd.vidosd0c, S3C_VIDOSD0C);
- //wpalcon=0x6
- //
- //
- //
- writel(s3cfb_fimd.wpalcon, S3C_WPALCON);
- //
- s3cfb_onoff_win(fbi, ON);
- break;
- case 1-4:
- 類推,省略.
- break;
- }
- local_irq_restore(flags); //開中斷,並恢復,於上面的local_irq_save正好相反
- return 0;
- }
6. 規定範圍
- static int s3cfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
- {
- s3cfb_info_t *fbi = (s3cfb_info_t *) info;
- switch (var->bits_per_pixel) {
- case 16:
- var->red = s3cfb_rgb_16.red; //{.offset = 11, .length = 5,},
- var->green = s3cfb_rgb_16.green; //{.offset = 5, .length = 6,},
- var->blue = s3cfb_rgb_16.blue; //{.offset = 0, .length = 5,},
- var->transp = s3cfb_rgb_16.transp; //{.offset = 0, .length = 0,},
- s3cfb_fimd.bytes_per_pixel = 2; //每個像素2個位元組
- break;
- }
- //對視窗0進行特殊處理
- if( (fbi->win_id == 0) && (var->bits_per_pixel == 28) )
- var->transp.length = 0;
- return 0;
- }
7. 分配並初始化color map
fb_alloc_cmap(&s3cfb_info[index].fb.cmap, 256, 0);
- int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp)
- {
- return fb_alloc_cmap_gfp(cmap, len, transp, GFP_ATOMIC);
- }
在driver/video/fbcmap.c中
- int fb_alloc_cmap_gfp(struct fb_cmap *cmap, int len, int transp, gfp_t flags)
- {
- int size = len * sizeof(u16);
- if (cmap->len != len) {
- fb_dealloc_cmap(cmap); //把以前申請的rgb記憶體kfree掉
- cmap->red = kmalloc(size, flags); //重新分配記憶體,GFP_ATOMIC
- cmap->green = kmalloc(size, flags); //重新分配記憶體,GFP_ATOMIC
- cmap->blue = kmalloc(size, flags); //重新分配記憶體,GFP_ATOMIC
- if (transp) {
- cmap->transp = kmalloc(size, flags);
- } else {
- cmap->transp = NULL; //transp設為NULL
- }
- }
- cmap->start = 0;
- cmap->len = len;
- ret = fb_copy_cmap(fb_default_cmap(len), cmap); //把default的cmap複製到新分配的cmap中
- return 0;
- }
上層執行fb_set_par
--> s3cfb_set_par
- static int s3cfb_set_par(struct fb_info *info)
- {
- //var->bits_per_pixel=16, s3cfb_fimd.bytes_per_pixel=2
- fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
- fbi->fb.fix.line_length = var->width * s3cfb_fimd.bytes_per_pixel;
- s3cfb_activate_var(fbi, var);
- return 0;
- }
上層執行fb_set_par
--> s3cfb_set_par
--> s3cfb_activate_var
根據像素位數設置寄存器.
- void s3cfb_activate_var(s3cfb_info_t *fbi, struct fb_var_screeninfo *var)
- {
- switch (var->bits_per_pixel) {
- case 16:
- s3cfb_fimd.wincon0 = S3C_WINCONx_HAWSWP_ENABLE | S3C_WINCONx_BURSTLEN_16WORD | S3C_WINCONx_BPPMODE_F_16BPP_565;
- s3cfb_fimd.wincon1 = S3C_WINCONx_HAWSWP_ENABLE | S3C_WINCONx_BURSTLEN_16WORD | S3C_WINCONx_BPPMODE_F_16BPP_565 | S3C_WINCONx_BLD_PIX_PLANE | S3C_WINCONx_ALPHA_SEL_1;
- s3cfb_fimd.wincon2 = S3C_WINCONx_HAWSWP_ENABLE | S3C_WINCONx_BURSTLEN_16WORD | S3C_WINCONx_BPPMODE_F_16BPP_565 | S3C_WINCONx_BLD_PIX_PLANE | S3C_WINCONx_ALPHA_SEL_1;
- s3cfb_fimd.wincon3 = S3C_WINCONx_HAWSWP_ENABLE | S3C_WINCONx_BURSTLEN_16WORD | S3C_WINCONx_BPPMODE_F_16BPP_565 | S3C_WINCONx_BLD_PIX_PLANE | S3C_WINCONx_ALPHA_SEL_1;
- s3cfb_fimd.wincon4 = S3C_WINCONx_HAWSWP_ENABLE | S3C_WINCONx_BURSTLEN_16WORD | S3C_WINCONx_BPPMODE_F_16BPP_565 | S3C_WINCONx_BLD_PIX_PLANE | S3C_WINCONx_ALPHA_SEL_1;
- s3cfb_fimd.bpp = S3CFB_PIXEL_BPP_16;
- s3cfb_fimd.bytes_per_pixel = 2;
- break;
- }
- //配置為窗口0,1,2,3,4為rgb565模式,dma直傳,burst mode, BURSTLEN=16Word
- writel(s3cfb_fimd.wincon0, S3C_WINCON0); //0x10014
- writel(s3cfb_fimd.wincon1, S3C_WINCON1); //0x10016
- writel(s3cfb_fimd.wincon2, S3C_WINCON2); //0x10016
- writel(s3cfb_fimd.wincon3, S3C_WINCON3); //0x10016
- writel(s3cfb_fimd.wincon4, S3C_WINCON4); //0x10016
- writel(s3cfb_fimd.wpalcon, S3C_WPALCON); //0x00006
- //啟動video output
- writel(s3cfb_fimd.wincon0 | S3C_WINCONx_ENWIN_F_ENABLE, S3C_WINCON0); //0x10014
- //設置clock並啟動video output
- writel(s3cfb_fimd.vidcon0 | S3C_VIDCON0_ENVID_ENABLE | S3C_VIDCON0_ENVID_F_ENABLE, S3C_VIDCON0); //0x350
- }
三. 中斷及數據傳輸
3.1 中斷過程
- irqreturn_t s3cfb_irq(int irqno, void *param)
- {
- writel(readl(S3C_VIDINTCON1), S3C_VIDINTCON1); //清中斷
- s3cfb_fimd.vsync_info.count++;
- wake_up_interruptible(&s3cfb_fimd.vsync_info.wait_queue); //喚醒工作隊列
- return IRQ_HANDLED;
- }
這個地方正在等侍工作隊列,收到喚醒信號之後,就返回
- int s3cfb_wait_for_vsync(void)
- {
- cnt = s3cfb_fimd.vsync_info.count;
- wait_event_interruptible_timeout(s3cfb_fimd.vsync_info.wait_queue, cnt != s3cfb_fimd.vsync_info.count, HZ / 10);
- return cnt;
- }
- int s3cfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
- {
- switch(cmd){
- case FBIO_WAITFORVSYNC:
- if (get_user(crt, (unsigned int __user *)arg))
- return -EFAULT;
- return s3cfb_wait_for_vsync();
- }
- }
附錄:
1. local_irq_save
s3cfb_probe
--> s3cfb_init_registers
--> local_irq_save
2. 關於DMA
s3cfb_probe
--> s3cfb_map_video_memory
--> dma_alloc_writecombine
--> __dma_alloc