Linux I2C总线设备驱动模型分析(ov7740)(4)


    /*
    CIPRTRGFMT:
        bit[28:16] -- 表示目标图片的水平像素大小(TargetHsize_Pr)
        bit[15:14] -- 是否旋转,我们这个驱动就不选择了
        bit[12:0]    -- 表示目标图片的垂直像素大小(TargetVsize_Pr)
    */
    *CIPRTRGFMT = (TargetHsize_Pr<<16)|(0x0<<14)|(TargetVsize_Pr<<0);

return 0;
}

static int cmos_ov7740_vidioc_reqbufs(struct file *file, void *priv,
              struct v4l2_requestbuffers *p)
{
    unsigned int order;

order = get_order(buf_size);

img_buff[0].order = order;
    img_buff[0].virt_base = __get_free_pages(GFP_KERNEL|__GFP_DMA, img_buff[0].order);
    if(img_buff[0].virt_base == (unsigned long)NULL)
    {
        printk("error0\n");
        goto error0;
    }
    img_buff[0].phy_base = __virt_to_phys(img_buff[0].virt_base);

img_buff[1].order = order;
    img_buff[1].virt_base = __get_free_pages(GFP_KERNEL|__GFP_DMA, img_buff[1].order);
    if(img_buff[1].virt_base == (unsigned long)NULL)
    {
        printk("error1\n");
        goto error1;
    }
    img_buff[1].phy_base = __virt_to_phys(img_buff[1].virt_base);

img_buff[2].order = order;
    img_buff[2].virt_base = __get_free_pages(GFP_KERNEL|__GFP_DMA, img_buff[2].order);
    if(img_buff[2].virt_base == (unsigned long)NULL)
    {
        printk("error2\n");
        goto error2;
    }
    img_buff[2].phy_base = __virt_to_phys(img_buff[2].virt_base);

img_buff[3].order = order;
    img_buff[3].virt_base = __get_free_pages(GFP_KERNEL|__GFP_DMA, img_buff[3].order);
    if(img_buff[3].virt_base == (unsigned long)NULL)
    {
        printk("error3\n");
        goto error3;
    }
    img_buff[3].phy_base = __virt_to_phys(img_buff[3].virt_base);

*CIPRCLRSA1 = img_buff[0].phy_base;
    *CIPRCLRSA2 = img_buff[1].phy_base;
    *CIPRCLRSA3 = img_buff[2].phy_base;
    *CIPRCLRSA4 = img_buff[3].phy_base;

return 0;
error3:
    free_pages(img_buff[2].virt_base, order);
    img_buff[2].phy_base = (unsigned long)NULL;       
error2:
    free_pages(img_buff[1].virt_base, order);
    img_buff[1].phy_base = (unsigned long)NULL;   
error1:
    free_pages(img_buff[0].virt_base, order);
    img_buff[0].phy_base = (unsigned long)NULL;
error0:   
    return -ENOMEM;
}

static void CalculateBurstSize(unsigned int hSize, unsigned int *mainBusrtSize, unsigned int *remainedBustSize)
{
    unsigned int tmp;

tmp = (hSize/4)%16;
    switch(tmp)
    {
        case 0:
            *mainBusrtSize = 16;
            *remainedBustSize = 16;
            break;
        case 4:
            *mainBusrtSize = 16;
            *remainedBustSize = 4;
            break;
        case 8:
            *mainBusrtSize = 16;
            *remainedBustSize = 8;
            break;
        default:
            tmp = (hSize/4)%8;
            switch(tmp)
            {
                case 0:
                    *mainBusrtSize = 8;
                    *remainedBustSize = 8;
                    break;
                case 4:
                    *mainBusrtSize = 8;
                    *remainedBustSize = 4;
                    break;
                default:
                    *mainBusrtSize = 4;
                    tmp = (hSize/4)%4;
                    *remainedBustSize = (tmp)?tmp:4;
                    break;
            }
            break;
    }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/124de2ba14b952f5a166e369a62106bb.html