platform:rk3399 OS:Android 7.1 Kernel:4.4 //Reference resources: 1. KrisFei https://blog.csdn.net/kris_fei/article/details/79298971
brief introduction
RK platform abstracts a common camera driver, which provides a common camera driver registration and operation interface for application layer. In this way, the camera driver and configuration are all extracted from the user space without recompiling and debugging the kernel, which greatly simplifies the migration and debugging of camera.
Except for the USB Camera with v4l2, all other types of cameras use a set of public Camera driver interface defined by RK.
- Camera usbadapter: a camera with USB interface, go to v4l2
- CameraIspSOCAdapter: dvp interface, received by isp controller.
- CameraIspAdapter: mipi interface, received by isp controller, not v4l2
- CameraSOCAdapter: dvp interface, received by VIP controller.
Important data structure
data structure
//isp device description structure typedef struct camsys_dev_s { unsigned int dev_id; camsys_irq_t irq; camsys_devmems_t devmems; struct miscdevice miscdev; void *clk; camsys_phyinfo_t *mipiphy; camsys_phyinfo_t cifphy; camsys_exdevs_t extdevs; struct list_head list; struct platform_device *pdev; void *soc; camsys_meminfo_t *csiphy_reg; camsys_meminfo_t *dsiphy_reg; camsys_meminfo_t *isp0_reg; unsigned long rk_grf_base; unsigned long rk_cru_base; unsigned long rk_isp_base; atomic_t refcount; struct iommu_domain *domain; camsys_dma_buf_t dma_buf[CAMSYS_DMA_BUF_MAX_NUM]; int dma_buf_cnt; int (*clkin_cb)(void *ptr, unsigned int on); int (*clkout_cb)(void *ptr, unsigned int on, unsigned int clk); int (*reset_cb)(void *ptr, unsigned int on); int (*phy_cb) (camsys_extdev_t *extdev, camsys_sysctrl_t *devctl, void *ptr); int (*iomux)(camsys_extdev_t *extdev, void *ptr); int (*platform_remove)(struct platform_device *pdev); int (*flash_trigger_cb)(void *ptr, int mode, unsigned int on); int (*iommu_cb)(void *ptr, camsys_sysctrl_t *devctl); } camsys_dev_t; //Memory information description structure typedef struct camsys_meminfo_s { unsigned char name[32]; unsigned long phy_base; unsigned long vir_base; unsigned int size; unsigned int vmas; struct list_head list; } camsys_meminfo_t; //phy information description structure typedef struct camsys_phyinfo_s { unsigned int phycnt; void *clk; camsys_meminfo_t *reg; int (*clkin_cb)(void *ptr, unsigned int on); int (*ops)(void *ptr, camsys_mipiphy_t *phy); int (*remove)(struct platform_device *pdev); } camsys_phyinfo_t; //Disconnect description structure typedef struct camsys_irqcnnt_s { int pid; unsigned int timeout; //us unsigned int mis; unsigned int icr; } camsys_irqcnnt_t;
ioctl codes
IOCTL CODES | Explain |
---|---|
CAMSYS_VERCHK | Check the driver version and header file version |
CAMSYS_I2CRD | Read i2c register |
CAMSYS_I2CWR | Write i2c register |
CAMSYS_SYSCTRL | sysctl control (vdd,gpio,clk,phyflash,iommu) |
CAMSYS_REGRD | empty |
CAMSYS_REGWR | empty |
CAMSYS_REGISTER_DEVIO | Registered camera |
CAMSYS_DEREGISTER_DEVIO | Write off camera |
CAMSYS_IRQCONNECT | break link |
CAMSYS_IRQWAIT | Interrupt waiting |
CAMSYS_IRQDISCONNECT | Break off |
CAMSYS_QUREYMEM | Query i2c or register mapping |
CAMSYS_QUREYIOMMU | Query if IOMMU is available |
rk_camsys
ISP
camsys_platform_probe(struct platform_device *pdev) //ISP probe -->camsys_soc_init(CHIP_TYPE); //Select the corresponding configuration function according to chip? Type -->camsys_soc_p->soc_cfg = camsys_rk3399_cfg; --->irq_id = irq_of_parse_and_map(dev->of_node, 0); //Mapping interrupt ----> INIT_LIST_HEAD(&camsys_dev->extdevs.list); //Initialize the camera list (two cameras are supported) ----> INIT_LIST_HEAD(&camsys_dev->extdevs.active); //Initialize open device list ----> INIT_LIST_HEAD(&camsys_dev->list); //Initializing the isp linked list (supports two ISPs) //Register mipiphy driver if (camsys_mipiphy_probe_cb(pdev, camsys_dev) < 0) { camsys_err("Mipi phy probe failed!"); } //Register camsys? Marvin driver camsys_mrv_probe_cb(pdev, camsys_dev); //Initialize ext flash linked list camsys_init_ext_fsh_module();
mipiphy
Mainly filled with camsys ﹣ phyinfo ﹣ s structure
//Get number of mipiphy err = of_property_read_u32(dev->of_node,"rockchip,isp,mipiphy", &mipiphy_cnt); //Initialize meminfo camsys_dev->mipiphy[i].reg = meminfo; //Initialize clk camsys_dev->mipiphy[i].clk = (void *)phyclk; //Initialize member functions camsys_dev->mipiphy[i].phycnt = mipiphy_cnt; camsys_dev->mipiphy[i].clkin_cb = camsys_mipiphy_clkin_cb; camsys_dev->mipiphy[i].ops = camsys_mipiphy_ops; camsys_dev->mipiphy[i].remove = camsys_mipiphy_remove_cb; //Get cru base address camsys_dev->rk_cru_base = (unsigned long)of_iomap(node, 0); //Get grf base address camsys_dev->rk_grf_base = (unsigned long)of_iomap(node, 0);
camsys_marvin
struct file_operations camsys_fops = { .owner = THIS_MODULE, .open = camsys_open, .release = camsys_release, .unlocked_ioctl = camsys_ioctl, .mmap = camsys_mmap, .compat_ioctl = camsys_ioctl_compat, };
camsys_mrv_probe_cb -->err = request_irq(camsys_dev->irq.irq_id, camsys_mrv_irq, //Application interruption IRQF_SHARED, CAMSYS_MARVIN_IRQNAME, camsys_dev); ---> pm_runtime_enable(&pdev->dev); //Enabling pm ---> clk_set_rate(mrv_clk->isp, 210000000); //Initialize clk clk_set_rate(mrv_clk->isp_jpe, 210000000); ---->domain = iommu_domain_alloc(&platform_bus_type); //Configure domain according to bus type -----> err = iommu_get_dma_cookie(domain); //Get DMA-API resources according to domain --->group = iommu_group_alloc(); //Assign a group ---->err = iommu_group_add_device(group, &pdev->dev); //Add dev to IOMMU group ----> camsys_dev->iommu_cb = camsys_mrv_drm_iommu_cb; // dma_buf map -----> err = misc_register(&camsys_dev->miscdev); //Register miscellaneous equipment camsys? Marvin1 ---->camsys_dev->dev_id = CAMSYS_DEVID_MARVIN; //Initialize dev? ID camsys_dev->platform_remove = camsys_mrv_remove_cb; //Initialize the probe? Remove function
ext_flash
Important structure
struct rt8547_platform_data { int flen_gpio; int flen_active; int ctl_gpio; int ctl_active; int flset_gpio; int flset_active; unsigned char def_lvp:4; unsigned char def_tol:3; }; typedef struct ext_fsh_info_s{ struct platform_device pdev; char* dev_model; struct list_head list; }ext_fsh_info_t;
Register flash dev(rt8547)
camsys_register_ext_fsh_dev //Camsys? Register? Device --->platform_device_register(&new_dev->pdev) //Register rt8547 platform driver ---->list_add_tail(&new_dev->list, &g_ext_fsh_devs.dev_list); //Add flash device to linked list
flash ctrl
mode: 0: CAM_ENGINE_FLASH_OFF = 0x00, 1: CAM_ENGINE_FLASH_AUTO = 0x01, 2: CAM_ENGINE_FLASH_ON = 0x02, 3: CAM_ENGINE_FLASH_RED_EYE = 0x03, 5: CAM_ENGINE_FLASH_TORCH = 0x05
Personal blog: www.letcos.top