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