camsys_drv : v0.0x12.0 ,camsys_head : v0.0x8.0
authorzyc <zyc@rock-chips.com>
Thu, 31 Jul 2014 09:58:15 +0000 (17:58 +0800)
committerzyc <zyc@rock-chips.com>
Thu, 31 Jul 2014 10:01:30 +0000 (18:01 +0800)
arch/arm/boot/dts/rk3288.dtsi
drivers/media/video/rk_camsys/camsys_drv.c
drivers/media/video/rk_camsys/camsys_internal.h
drivers/media/video/rk_camsys/camsys_marvin.c
include/media/camsys_head.h

index f04b1f3aea7c58fdaa68ec5af8e78acc205225f8..9785eb6cb6d152e2ec0485458c3bfc5eecc166f8 100755 (executable)
                rockchip,isp,cifphy = <1>;
                rockchip,isp,mipiphy1,reg = <0xff968000 0x4000>;
                rockchip,gpios = <&gpio7 GPIO_B5 GPIO_ACTIVE_HIGH>;
+               rockchip,isp,iommu_enable = <0>;
                status = "okay";
        };
 
index d8ffa4688bba70d93cb37d19801e1ad4cb58d83f..6517bb38a4aa47727028215822c895790163f465 100755 (executable)
@@ -381,6 +381,14 @@ static int camsys_sysctl(camsys_sysctrl_t *devctl, camsys_dev_t *camsys_dev)
             case CamSys_Flash_Trigger:
             {
                 camsys_dev->flash_trigger_cb(camsys_dev, devctl->on);
+                break;
+            }
+            case CamSys_IOMMU:
+            {
+                if(camsys_dev->iommu_cb(camsys_dev, devctl) < 0){
+                    err = -1;
+                    }
+                break;
             }
             default:
                 break;
@@ -769,7 +777,16 @@ static long camsys_ioctl(struct file *filp,unsigned int cmd, unsigned long arg)
                 return -EFAULT;
             break;
            }
-
+           case CAMSYS_QUREYIOMMU:
+           {
+            int iommu_enabled = 0;
+            #ifdef CONFIG_ROCKCHIP_IOMMU
+                of_property_read_u32(camsys_dev->pdev->dev.of_node, "rockchip,isp,iommu_enable", &iommu_enabled);
+            #endif
+            if (copy_to_user((void __user *)arg,(void*)&iommu_enabled, sizeof(iommu_enabled)))
+                return -EFAULT;
+            break;
+           }
            case CAMSYS_I2CRD:
            {
                camsys_i2c_info_t i2cinfo;
@@ -804,6 +821,10 @@ static long camsys_ioctl(struct file *filp,unsigned int cmd, unsigned long arg)
                 return -EFAULT;
 
             err = camsys_sysctl(&devctl, camsys_dev);
+            if ((err==0) && (devctl.ops == CamSys_IOMMU)){
+                if (copy_to_user((void __user *)arg,(void*)&devctl, sizeof(camsys_sysctrl_t))) 
+                    return -EFAULT;
+            }
             break;
         }
 
index f8b2a193c348a90408f070412789cd43a3f253ac..112299f3de7bb4c00049929f565b855cc6b9fbb6 100755 (executable)
@@ -48,6 +48,8 @@
 #include <linux/of_gpio.h>
 #include <linux/rockchip/cpu.h>
 #include <media/camsys_head.h>
+#include <linux/rockchip/sysmmu.h>
+#include <linux/rockchip/iovmm.h>
 
 
 
                 1) add flash_prelight control.         
 *v0.0x11.0:
          1) raise qos of isp up to the same as lcdc. 
+*v0.0x12.0:
+         1) support iommu. 
 */
-#define CAMSYS_DRIVER_VERSION                   KERNEL_VERSION(0,0x11,0)
+#define CAMSYS_DRIVER_VERSION                   KERNEL_VERSION(0,0x12,0)
 
 
 #define CAMSYS_PLATFORM_DRV_NAME                "RockChip-CamSys"
@@ -250,6 +254,7 @@ typedef struct camsys_dev_s {
     int (*iomux)(camsys_extdev_t *extdev,void *ptr);
     int (*platform_remove)(struct platform_device *pdev);
     int (*flash_trigger_cb)(void *ptr, unsigned int on);
+    int (*iommu_cb)(void *ptr,camsys_sysctrl_t *devctl);
 } camsys_dev_t;
 
 
index 1df03a554248a8eb7b8a4855af0a6a23ec83f910..77a0a23e0ae16684284e5cc5a7ce497b83a92abc 100755 (executable)
@@ -4,6 +4,8 @@
 
 #include <linux/rockchip/common.h> 
 #include <dt-bindings/clock/rk_system_status.h>
+#include <linux/rockchip_ion.h>
+#include <linux/file.h>
 
 extern int rockchip_set_system_status(unsigned long status);
 extern int rockchip_clear_system_status(unsigned long status);
@@ -193,7 +195,70 @@ static int camsys_mrv_flash_trigger_cb(void *ptr,unsigned int on)
     return retval;
 }
 
+static int camsys_mrv_iommu_cb(void *ptr,camsys_sysctrl_t *devctl)
+{
+    struct device *iommu_dev = NULL,*dev = NULL;
+    struct file *file = NULL;
+    struct ion_client *client = NULL;
+    struct ion_handle *handle = NULL;
+    camsys_iommu_t *iommu = NULL;
+    int ret = 0,iommu_enabled = 0;
+    camsys_dev_t * camsys_dev = (camsys_dev_t *)ptr;
+
+    of_property_read_u32(camsys_dev->pdev->dev.of_node, "rockchip,isp,iommu_enable", &iommu_enabled);
+    if(iommu_enabled != 1){
+        camsys_err("isp iommu have not been enabled!\n");
+        ret = -1;
+        goto iommu_end;
+    }
+    
+    iommu_dev = rockchip_get_sysmmu_device_by_compatible("iommu,isp_mmu");
+    if(!iommu_dev){
+        camsys_err("get iommu device erro!\n");
+        ret = -1;
+        goto iommu_end;
+    }
+    dev = &(camsys_dev->pdev->dev);
+    iommu = (camsys_iommu_t *)(devctl->rev);
+    file = fget(iommu->client_fd);
+    if(!file){
+        camsys_err("get client_fd file erro!\n");
+        ret = -1;
+        goto iommu_end;
+    }
+    
+    client = file->private_data;
+    
+    if(!client){
+        camsys_err("get ion_client erro!\n");
+        ret = -1;
+        goto iommu_end;
+    }
+    
+    fput(file);
+
+    handle = ion_import_dma_buf(client,iommu->map_fd);
 
+    camsys_trace(1,"map fd %d ,client fd %d\n",iommu->map_fd,iommu->client_fd);
+    if(!handle){
+        camsys_err("get ion_handle erro!\n");
+        ret = -1;
+        goto iommu_end;
+    }
+    if(devctl->on){
+        platform_set_sysmmu(iommu_dev,dev);
+        ret = iovmm_activate(dev);
+        
+        ret = ion_map_iommu(dev,client,handle,&(iommu->linear_addr),&(iommu->len));
+        
+    }else{
+        ion_unmap_iommu(dev,client,handle);
+        platform_set_sysmmu(iommu_dev,dev);
+        iovmm_deactivate(dev);
+    }
+iommu_end:
+    return ret;
+}
 static int camsys_mrv_reset_cb(void *ptr,unsigned int on)
 {
     camsys_dev_t *camsys_dev = (camsys_dev_t*)ptr;
@@ -419,7 +484,7 @@ int camsys_mrv_probe_cb(struct platform_device *pdev, camsys_dev_t *camsys_dev)
     int err = 0;   
     camsys_mrv_clk_t *mrv_clk=NULL;
     
-       err = request_irq(camsys_dev->irq.irq_id, camsys_mrv_irq, 0, CAMSYS_MARVIN_IRQNAME,camsys_dev);
+       err = request_irq(camsys_dev->irq.irq_id, camsys_mrv_irq, IRQF_SHARED, CAMSYS_MARVIN_IRQNAME,camsys_dev);
     if (err) {
         camsys_err("request irq for %s failed",CAMSYS_MARVIN_IRQNAME);
         goto end;
@@ -465,6 +530,7 @@ int camsys_mrv_probe_cb(struct platform_device *pdev, camsys_dev_t *camsys_dev)
     camsys_dev->reset_cb = camsys_mrv_reset_cb;
     camsys_dev->iomux = camsys_mrv_iomux_cb;
     camsys_dev->flash_trigger_cb = camsys_mrv_flash_trigger_cb;
+    camsys_dev->iommu_cb = camsys_mrv_iommu_cb;
     
     camsys_dev->miscdev.minor = MISC_DYNAMIC_MINOR;
     camsys_dev->miscdev.name = miscdev_name;
index 94d624bcd1824002a76cc2111b71c55ec41d90b8..f56969670393ee755373ed0740a7810c70682d8f 100755 (executable)
 *        2) add support io domain and mclk driver strength configuration;
 *v0.7.0:
                 1) add flash_trigger_out control
+*v0.8.0:
+                1) support isp iommu
 */
-#define CAMSYS_HEAD_VERSION           KERNEL_VERSION(0,7,0)
+#define CAMSYS_HEAD_VERSION           KERNEL_VERSION(0,8,0)
 
 #define CAMSYS_MARVIN_DEVNAME         "camsys_marvin"           
 #define CAMSYS_CIF0_DEVNAME           "camsys_cif0"
@@ -41,9 +43,9 @@
 #define CAMSYS_DEVID_EXTERNAL         0xFF000000
 #define CAMSYS_DEVID_EXTERNAL_NUM     8
 
-#define CAMSYS_DEVCFG_FLASHLIGHT          0x00000001
-#define CAMSYS_DEVCFG_PREFLASHLIGHT       0x00000002
-#define CAMSYS_DEVCFG_SHUTTER             0x00000004
+#define CAMSYS_DEVCFG_FLASHLIGHT      0x00000001
+#define CAMSYS_DEVCFG_PREFLASHLIGHT   0x00000002
+#define CAMSYS_DEVCFG_SHUTTER         0x00000004
 
 typedef struct camsys_irqsta_s {
     unsigned int ris;                 //Raw interrupt status
@@ -116,7 +118,8 @@ typedef enum camsys_sysctrl_ops_e {
     CamSys_Phy_End_Tag,
     CamSys_Flash_Trigger_Start_Tag, 
     CamSys_Flash_Trigger,
-    CamSys_Flash_Trigger_End_Tag
+    CamSys_Flash_Trigger_End_Tag,
+    CamSys_IOMMU
     
 } camsys_sysctrl_ops_t;
 
@@ -131,6 +134,13 @@ typedef struct camsys_gpio_info_s {
     unsigned int      active;
 } camsys_gpio_info_t;
 
+typedef struct camsys_iommu_s{
+    int client_fd;
+    int map_fd;
+    unsigned long linear_addr;
+    unsigned long len;
+}camsys_iommu_t;
+
 typedef struct camsys_sysctrl_s {
     unsigned int              dev_mask;
     camsys_sysctrl_ops_t      ops;
@@ -248,4 +258,5 @@ typedef struct camsys_version_s {
 #define CAMSYS_IRQDISCONNECT     _IOW(CAMSYS_IOC_MAGIC,   10, camsys_irqcnnt_t)
 
 #define CAMSYS_QUREYMEM          _IOR(CAMSYS_IOC_MAGIC,  11, camsys_querymem_t)
+#define CAMSYS_QUREYIOMMU        _IOW(CAMSYS_IOC_MAGIC,  12, int)
 #endif