isp:camsys_head ver:v0.0.5
authorzyc <zyc@rock-chips.com>
Thu, 27 Mar 2014 03:26:25 +0000 (11:26 +0800)
committerzyc <zyc@rock-chips.com>
Thu, 27 Mar 2014 03:26:25 +0000 (11:26 +0800)
update D-phy driver,support one lane now.

arch/arm/boot/dts/rk3288.dtsi
drivers/media/video/rk_camsys/Kconfig
drivers/media/video/rk_camsys/camsys_drv.c
drivers/media/video/rk_camsys/camsys_internal.h
drivers/media/video/rk_camsys/camsys_marvin.c
drivers/media/video/rk_camsys/camsys_mipicsi_phy.c
include/media/camsys_head.h

index 181ca0244c8e0cd070d2b7991d2a329d3e2c5e2f..58f08be1054495c8cc1b9da91af286633cd4e725 100755 (executable)
                                                     >;           
             };
 
-          isp:isp@0xFF910000{
+          isp:isp@ff910000{
                compatible = "rockchip,isp";
-               reg = <0xFF910000 0x10000>;
+               reg = <0xff910000 0x10000>;
                interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&clk_gates16 2>, <&clk_gates16 1>, <&clk_isp>, <&clk_isp_jpe>, <&dummy>, <&clk_cif_out>;
                        clock_names = "aclk_isp", "hclk_isp", "clk_isp", "clk_isp_jpe", "pclkin_isp", "clk_vipout";
                        pinctrl-2 = <&isp_mipi &isp_dvp_sync_d2d9 &isp_dvp_d0d1>;
                        pinctrl-3 = <&isp_mipi &isp_dvp_sync_d2d9 &isp_dvp_d0d1 &isp_dvpd10d11>;
                        
-                       status = "disabled";
+                       status = "okay";
        };
        
        tsadc: tsadc@ff280000{
index c4aba692c6774d690d965bd7a02b1d1189739633..8d22522235c7e350067882e8c3e7fe5f0834e25e 100755 (executable)
@@ -1,13 +1,13 @@
 config CAMSYS_DRV
        tristate "camsys driver "
-       default n
+       default y
        
 menu "RockChip camera system driver"
        depends on CAMSYS_DRV
        
 config CAMSYS_MRV
        tristate "camsys driver for marvin isp "
-       default n
+       default y
        ---help---
 
 config CAMSYS_CIF
index fb2a2a0cedd92b434e3eb376212dd56a5d9a1939..e662c080f943305e60efabcdf260feb669e7ef7d 100755 (executable)
@@ -174,13 +174,13 @@ static int camsys_extdev_register(camsys_devio_name_t *devio, camsys_dev_t *cams
     camsys_gpio_info_t *gpio_info;
     camsys_gpio_t *gpio;
     
-    
     if ((devio->dev_id & CAMSYS_DEVID_EXTERNAL) == 0) {
         err = -EINVAL;
         camsys_err("dev_id: 0x%x is not support for camsys!",devio->dev_id);
         goto end;
     }
 
+#if 0
     if (devio->phy.type == CamSys_Phy_Mipi) {
         if (camsys_find_devmem(CAMSYS_REGISTER_MIPIPHY_RES_NAME, camsys_dev) == NULL) {
             camsys_err("dev_id: 0x%x is connect to MIPI CSI, but %s isn't support",devio->dev_id,
@@ -190,7 +190,7 @@ static int camsys_extdev_register(camsys_devio_name_t *devio, camsys_dev_t *cams
             goto end;
         }
     }
-    
+#endif    
 
     extdev = camsys_find_extdev(devio->dev_id, camsys_dev);
     if (extdev != NULL) {
@@ -235,7 +235,7 @@ static int camsys_extdev_register(camsys_devio_name_t *devio, camsys_dev_t *cams
 
     gpio_info = &devio->pwrdn;
     gpio = &extdev->pwrdn;
-    for (i=0; i<4; i++) {
+    for (i=0; i<5; i++) {
         if (strcmp(gpio_info->name,"NC")) {
             gpio->io = camsys_gpio_get(gpio_info->name);
             if (gpio->io < 0) {
@@ -401,6 +401,15 @@ static int camsys_sysctl(camsys_sysctrl_t *devctl, camsys_dev_t *camsys_dev)
                 camsys_dev->reset_cb(camsys_dev);
                 break;
             }
+            #if 0
+            //for mipi
+            case CamSys_Gpio_Tag:
+            {
+                if((camsys_dev->mipiphy.ops )){
+                    camsys_dev->mipiphy.ops(NULL,NULL,devctl->on);
+                }
+            }
+            #endif
             default:
                 break;
 
@@ -480,7 +489,13 @@ static int camsys_irq_connect(camsys_irqcnnt_t *irqcnnt, camsys_dev_t *camsys_de
         err = -EINVAL;
         goto end;
     }
-        
+#if 0
+    //zyc for test mipi
+    if((camsys_dev->mipiphy.ops ) && (irqcnnt->mis == MRV_ISP_MIS)){
+        camsys_dev->mipiphy.ops(NULL,NULL,0);
+    }
+#endif    
+
     spin_lock_irqsave(&camsys_dev->irq.lock,flags);
     if (!list_empty(&camsys_dev->irq.irq_pool)) {
         list_for_each_entry(irqpool, &camsys_dev->irq.irq_pool, list) {
@@ -579,7 +594,7 @@ static int camsys_irq_wait(camsys_irqsta_t *irqsta, camsys_dev_t *camsys_dev)
                 list_add_tail(&irqstas->list,&irqpool->deactive);
                 spin_unlock_irqrestore(&irqpool->lock,flags);
             } else {
-                camsys_warn("Thread(pid: %d) wait irq timeout!!",current->pid);
+           //     camsys_warn("Thread(pid: %d) wait irq timeout!!",current->pid);
                 err = -EAGAIN;
             }
         } else {
@@ -606,7 +621,6 @@ static int camsys_irq_disconnect(camsys_irqcnnt_t *irqcnnt, camsys_dev_t *camsys
     
     if (all == false) {
         spin_lock_irqsave(&camsys_dev->irq.lock,flags);
-        printk("%s++++++++++++++++\n",__func__);
                if (!list_empty(&camsys_dev->irq.irq_pool)) {
             list_for_each_entry(irqpool, &camsys_dev->irq.irq_pool, list) {
                 if (irqpool->pid == irqcnnt->pid) {
@@ -616,7 +630,6 @@ static int camsys_irq_disconnect(camsys_irqcnnt_t *irqcnnt, camsys_dev_t *camsys
                 }
             }
         }
-               printk("%s -------------\n",__func__);
         spin_unlock_irqrestore(&camsys_dev->irq.lock,flags);
 
         if (find_pool == false) {
@@ -861,9 +874,7 @@ static long camsys_ioctl(struct file *filp,unsigned int cmd, unsigned long arg)
 
             if (copy_from_user((void*)&irqcnnt,(void __user *)arg, sizeof(camsys_irqcnnt_t))) 
                 return -EFAULT;
-               printk("disconnect ++++++++++++++++\n"); 
             err = camsys_irq_disconnect(&irqcnnt,camsys_dev,false);
-            printk("disconnect ----------------\n");
                        break;
         }
 
@@ -981,7 +992,7 @@ struct file_operations camsys_fops = {
        .mmap =             camsys_mmap,
 };
 
-static int camsys_platform_probe_new(struct platform_device *pdev){
+static int camsys_platform_probe(struct platform_device *pdev){
     int err = 0;
        camsys_dev_t *camsys_dev;
     struct resource register_res ;
@@ -989,7 +1000,6 @@ static int camsys_platform_probe_new(struct platform_device *pdev){
     unsigned long i2cmem;
        camsys_meminfo_t *meminfo;
     unsigned int irq_id;
-
     err = of_address_to_resource(dev->of_node, 0, &register_res);
     if (err < 0){
         camsys_err("Get register resource from %s platform device failed!",pdev->name);
@@ -1083,7 +1093,8 @@ static int camsys_platform_probe_new(struct platform_device *pdev){
             camsys_err("Mipi phy probe failed!");
         }
     }
-    
+
+#if 0
     if (strcmp(dev_name(&pdev->dev),CAMSYS_PLATFORM_MARVIN_NAME) == 0) {
         #if (defined(CONFIG_CAMSYS_MRV))
         camsys_mrv_probe_cb(pdev, camsys_dev);        
@@ -1097,179 +1108,15 @@ static int camsys_platform_probe_new(struct platform_device *pdev){
         camsys_err("CIF controller camsys driver haven't been complie!!!");
         #endif
     }
-
-    camsys_trace(1, "%s memory:",dev_name(&pdev->dev));
-    list_for_each_entry(meminfo, &camsys_dev->devmems.memslist, list) {
-        if (strcmp(meminfo->name,CAMSYS_I2C_MEM_NAME) == 0) {
-            camsys_dev->devmems.i2cmem = meminfo;
-            camsys_trace(1,"    I2c memory (phy: 0x%x vir: 0x%x size: 0x%x)",
-                        meminfo->phy_base,meminfo->vir_base,meminfo->size);
-        }
-        if (strcmp(meminfo->name,CAMSYS_REGISTER_MEM_NAME) == 0) {
-            camsys_dev->devmems.registermem = meminfo;
-            camsys_trace(1,"    Register memory (phy: 0x%x vir: 0x%x size: 0x%x)",
-                        meminfo->phy_base,meminfo->vir_base,meminfo->size);
-        }
-    }
-
-    camsys_dev->phy_cb = camsys_phy_ops;
-    platform_set_drvdata(pdev,(void*)camsys_dev);
-    //Camsys_devs list add    
-    spin_lock(&camsys_devs.lock);    
-    list_add_tail(&camsys_dev->list, &camsys_devs.devs);
-    spin_unlock(&camsys_devs.lock);
-
-    
-    camsys_trace(1, "Probe %s device success ", dev_name(&pdev->dev));
-    return 0;
-request_mem_fail:
-    if (camsys_dev != NULL) {
-    
-        while(!list_empty(&camsys_dev->devmems.memslist)) {
-            meminfo = list_first_entry(&camsys_dev->devmems.memslist, camsys_meminfo_t, list);
-            if (meminfo) {
-                list_del_init(&meminfo->list);
-                if (strcmp(meminfo->name,CAMSYS_REGISTER_MEM_NAME)==0) {
-                    iounmap((void __iomem *)meminfo->vir_base);
-                    release_mem_region(meminfo->phy_base,meminfo->size);
-                } else if (strcmp(meminfo->name,CAMSYS_I2C_MEM_NAME)==0) {
-                    kfree((void*)meminfo->vir_base);
-                }
-                kfree(meminfo);
-                meminfo = NULL;
-            }
-        } 
-    
-        kfree(camsys_dev);
-        camsys_dev = NULL;
-    }
-fail_end:
-    return -1;
-
-    
-}
-#if 0
-static int camsys_platform_probe(struct platform_device *pdev)
-{
-    int err = 0;
-    unsigned int irq_id;
-    camsys_dev_t *camsys_dev;
-    unsigned long i2cmem;
-    camsys_meminfo_t *meminfo;
-    struct resource *register_res, *mipiphy_register_res;
-
-    camsys_trace(1, "Probe %s device now", dev_name(&pdev->dev));
-    register_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, CAMSYS_REGISTER_RES_NAME);
-    if (register_res == NULL) {
-        camsys_err("Get register resource from %s platform device failed!",pdev->name);
-        err = -ENODEV;
-        goto fail_end;
-    }
-
-    mipiphy_register_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, CAMSYS_REGISTER_MIPIPHY_RES_NAME);
-    
-    irq_id = platform_get_irq_byname(pdev, CAMSYS_IRQ_RES_NAME);
-    if (irq_id < 0) {
-        camsys_err("Get irq resource from %s platform device failed!",pdev->name);
-        err = -ENODEV;
-        goto fail_end;
-    }
-    
-    camsys_dev = (camsys_dev_t*)kzalloc(sizeof(camsys_dev_t), GFP_KERNEL);
-    if (camsys_dev == NULL) {
-        camsys_err("Allocate camsys_dev for %s platform device failed",pdev->name);
-        err = -ENOMEM;
-        goto fail_end;
-    }
-
-    //spin_lock_init(&camsys_dev->lock);
-    mutex_init(&camsys_dev->extdevs.mut);
-    INIT_LIST_HEAD(&camsys_dev->extdevs.list);
-    INIT_LIST_HEAD(&camsys_dev->extdevs.active);
-    INIT_LIST_HEAD(&camsys_dev->list);
-    
-
-    //IRQ init
-    camsys_dev->irq.irq_id = irq_id;  
-    spin_lock_init(&camsys_dev->irq.lock);
-    INIT_LIST_HEAD(&camsys_dev->irq.irq_pool); 
-    //init_waitqueue_head(&camsys_dev->irq.irq_done);
-    
-    INIT_LIST_HEAD(&camsys_dev->devmems.memslist);
-    if (!request_mem_region(register_res->start, register_res->end - register_res->start + 1,
-                            dev_name(&pdev->dev))) {
-        err = -ENOMEM;
-        goto request_mem_fail;
-    }
-
-    //Register mem init
-    meminfo = kzalloc(sizeof(camsys_meminfo_t),GFP_KERNEL);
-    if (meminfo == NULL) {
-        err = -ENOMEM;
-        goto request_mem_fail;
-    }
-    
-    meminfo->vir_base = (unsigned int)ioremap(register_res->start, register_res->end - register_res->start + 1);
-    if (meminfo->vir_base == 0) {
-        camsys_err("%s ioremap %s failed",dev_name(&pdev->dev), CAMSYS_REGISTER_MEM_NAME);
-        err = -ENXIO;
-        goto request_mem_fail;
-    }
-
-    strlcpy(meminfo->name, CAMSYS_REGISTER_MEM_NAME,sizeof(meminfo->name));
-    meminfo->phy_base = register_res->start;
-    meminfo->size = register_res->end - register_res->start + 1;  
-    list_add_tail(&meminfo->list, &camsys_dev->devmems.memslist);
-
-    //I2c mem init
-    i2cmem = __get_free_page(GFP_KERNEL);
-    if (i2cmem == 0) {
-        camsys_err("Allocate i2cmem failed!");
-        err = -ENOMEM;
-        goto request_mem_fail;
-    }
-    SetPageReserved(virt_to_page(i2cmem));
-    
-    meminfo = kzalloc(sizeof(camsys_meminfo_t),GFP_KERNEL);
-    if (meminfo == NULL) {
-        err = -ENOMEM;
-        goto request_mem_fail;
-    }
-    strlcpy(meminfo->name,CAMSYS_I2C_MEM_NAME,sizeof(meminfo->name));
-    meminfo->vir_base = i2cmem;
-    meminfo->phy_base = virt_to_phys((void*)i2cmem);
-    meminfo->size = PAGE_SIZE;
-    list_add_tail(&meminfo->list, &camsys_dev->devmems.memslist);
-
-    {
-        unsigned int *tmpp;
-
-        tmpp = (unsigned int*)meminfo->vir_base;
-        *tmpp = 0xfa561243;
-    }
-
-    //Special init
-
-    if (mipiphy_register_res) {        
-        if (camsys_mipiphy_probe_cb(pdev, camsys_dev) <0) {
-            camsys_err("Mipi phy probe failed!");
-        }
-    }
-    
-    if (strcmp(dev_name(&pdev->dev),CAMSYS_PLATFORM_MARVIN_NAME) == 0) {
+#else
         #if (defined(CONFIG_CAMSYS_MRV))
         camsys_mrv_probe_cb(pdev, camsys_dev);        
-        #else
-        camsys_err("Marvin controller camsys driver haven't been complie!!!");
-        #endif
-    } else {
-        #if (defined(CONFIG_CAMSYS_CIF))
+        #elif (defined(CONFIG_CAMSYS_CIF))
         camsys_cif_probe_cb(pdev,camsys_dev);
         #else
-        camsys_err("CIF controller camsys driver haven't been complie!!!");
+        camsys_err("camsys driver haven't been complie!!!");
         #endif
-    }
-
+#endif
     camsys_trace(1, "%s memory:",dev_name(&pdev->dev));
     list_for_each_entry(meminfo, &camsys_dev->devmems.memslist, list) {
         if (strcmp(meminfo->name,CAMSYS_I2C_MEM_NAME) == 0) {
@@ -1284,10 +1131,11 @@ static int camsys_platform_probe(struct platform_device *pdev)
         }
     }
 
+
     camsys_dev->phy_cb = camsys_phy_ops;
     camsys_dev->pdev    =   pdev;
+
     platform_set_drvdata(pdev,(void*)camsys_dev);
-    
     //Camsys_devs list add    
     spin_lock(&camsys_devs.lock);    
     list_add_tail(&camsys_dev->list, &camsys_devs.devs);
@@ -1319,8 +1167,9 @@ request_mem_fail:
     }
 fail_end:
     return -1;
+
+    
 }
-#endif
 static int  camsys_platform_remove(struct platform_device *pdev)
 {
     camsys_dev_t *camsys_dev = platform_get_drvdata(pdev);
@@ -1378,7 +1227,7 @@ static int  camsys_platform_remove(struct platform_device *pdev)
 
 
 static const struct of_device_id cif_of_match[] = {
-    { .compatible = "rodkchip,isp" },
+    { .compatible = "rockchip,isp" },
 };
 MODULE_DEVICE_TABLE(of, cif_of_match);
 
@@ -1386,13 +1235,13 @@ static struct platform_driver camsys_platform_driver =
 {
     .driver    = {
         .name  = CAMSYS_PLATFORM_DRV_NAME,
-        .of_match_table = cif_of_match,
+        .of_match_table = of_match_ptr(cif_of_match),
     },
-    .probe             = camsys_platform_probe_new,
+    .probe             = camsys_platform_probe,
     .remove            = (camsys_platform_remove),
 };
 
-
+MODULE_ALIAS(CAMSYS_PLATFORM_DRV_NAME);
 static int __init camsys_platform_init(void)  
 {
     printk("CamSys driver version: v%d.%d.%d,  CamSys head file version: v%d.%d.%d\n",
@@ -1403,7 +1252,7 @@ static int __init camsys_platform_init(void)
     spin_lock_init(&camsys_devs.lock);
     INIT_LIST_HEAD(&camsys_devs.devs);
     platform_driver_register(&camsys_platform_driver);
-
+   // platform_driver_probe(&camsys_platform_driver, camsys_platform_probe_new);
     
     return 0;
 }  
index e027dca69efb4509cf54b0cde6ec7f372801e1fa..15c540d90b3f9de0516a100ed2fec24a008df737 100755 (executable)
@@ -170,6 +170,7 @@ typedef struct camsys_extdev_s {
     camsys_gpio_t            rst;
     camsys_gpio_t            afpwr;
     camsys_gpio_t            afpwrdn;
+       camsys_gpio_t            pwren;
 
     camsys_flash_t           fl;
 
index 295355793416bd957cf25b3d8862022c33c123ef..0a7a0282dc5e8a0805859886626f3c3723f4f31f 100755 (executable)
@@ -2,7 +2,6 @@
 
 static const char miscdev_name[] = CAMSYS_MARVIN_DEVNAME;
 
-
 static int camsys_mrv_iomux_cb(camsys_extdev_t *extdev,void *ptr)
 {  
     unsigned int cif_vol_sel;
@@ -76,6 +75,10 @@ static int camsys_mrv_iomux_cb(camsys_extdev_t *extdev,void *ptr)
                 }
     }
 
+    //set 1.8v vol domain for rk32
+    __raw_writel(((1<<1)|(1<<(1+16))),RK_GRF_VIRT+0x0380);
+   __raw_writel(0xffffffff, RK_GRF_VIRT+0x01d4);   
+
     //set cif vol domain
     if (extdev->phy.type == CamSys_Phy_Cif) {
 
@@ -90,11 +93,13 @@ static int camsys_mrv_iomux_cb(camsys_extdev_t *extdev,void *ptr)
             __raw_writel(((1<<1)|(1<<(1+16))),RK30_GRF_BASE+0x018c);
         }
         #else
-        __raw_writel(((1<<1)|(1<<(1+16))),RK_GRF_VIRT+0x018c);
+
+        //set 1.8v vol domain
+        __raw_writel(((1<<1)|(1<<(1+16))),RK_GRF_VIRT+0x0380);
         #endif
         
         //set driver strength
-        __raw_writel(0xffffffff, RK_GRF_VIRT+0x01dc);   
+      //  __raw_writel(0xffffffff, RK_GRF_VIRT+0x01dc);   
     }
     
     return 0;
@@ -117,14 +122,26 @@ static int camsys_mrv_clkin_cb(void *ptr, unsigned int on)
     camsys_dev_t *camsys_dev = (camsys_dev_t*)ptr;
     camsys_mrv_clk_t *clk = (camsys_mrv_clk_t*)camsys_dev->clk;
     
-    spin_lock(&clk->lock);
-    if (on && !clk->in_on) {        
-        clk_enable(clk->pd_isp);
-        clk_enable(clk->aclk_isp);
-       clk_enable(clk->hclk_isp);      
-       clk_enable(clk->isp);
-       clk_enable(clk->isp_jpe);
-       clk_enable(clk->pclkin_isp);
+  //  spin_lock(&clk->lock);
+    if (on && !clk->in_on) {
+        clk_set_rate(clk->isp,180000000);
+        clk_set_rate(clk->isp_jpe, 180000000);
+   //     clk_set_rate(clk->aclk_isp,24000000);
+   //     clk_set_rate(clk->hclk_isp,24000000);
+
+
+        clk_prepare_enable(clk->aclk_isp);
+        clk_prepare_enable(clk->hclk_isp);
+        clk_prepare_enable(clk->isp);
+        clk_prepare_enable( clk->isp_jpe);
+        
+
+ //       clk_enable(clk->pd_isp);
+  //      clk_enable(clk->aclk_isp);
+  //   clk_enable(clk->hclk_isp);      
+  //   clk_enable(clk->isp);
+ //    clk_enable(clk->isp_jpe);
+ //    clk_enable(clk->pclkin_isp);
        
         clk->in_on = true;
 
@@ -132,16 +149,24 @@ static int camsys_mrv_clkin_cb(void *ptr, unsigned int on)
         camsys_mrv_reset_cb(ptr);       
         
     } else if (!on && clk->in_on) {
-        clk_disable(clk->pd_isp);
-        clk_disable(clk->aclk_isp);
-       clk_disable(clk->hclk_isp);
-       clk_disable(clk->isp);
-       clk_disable(clk->isp_jpe);
-       clk_disable(clk->pclkin_isp);
+
+
+         clk_disable_unprepare(clk->aclk_isp);
+        clk_disable_unprepare(clk->hclk_isp);
+        clk_disable_unprepare(clk->isp);
+        clk_disable_unprepare( clk->isp_jpe);
+
+  //      clk_disable(clk->pd_isp);
+  //      clk_disable(clk->aclk_isp);
+   //  clk_disable(clk->hclk_isp);
+  //   clk_disable(clk->isp);
+  //   clk_disable(clk->isp_jpe);
+ //    clk_disable(clk->pclkin_isp);
+
         clk->in_on = false;
         camsys_trace(1, "%s clock in turn off",dev_name(camsys_dev->miscdev.this_device));
     }
-    spin_unlock(&clk->lock);
+  //  spin_unlock(&clk->lock);
     return 0;
 }
 
@@ -152,8 +177,10 @@ static int camsys_mrv_clkout_cb(void *ptr, unsigned int on)
     struct clk *cif_clk_out_div;
     
     spin_lock(&clk->lock);
-    if (on && (clk->out_on != on)) {        
-        clk_enable(clk->cif_clk_out);
+    if (on && (clk->out_on != on)) {  
+        clk_prepare_enable(clk->cif_clk_out);
+
+//        clk_enable(clk->cif_clk_out);
         clk_set_rate(clk->cif_clk_out,on);
        
         clk->out_on = on;
@@ -171,7 +198,10 @@ static int camsys_mrv_clkout_cb(void *ptr, unsigned int on)
         } else {
             camsys_warn("%s clock out may be not off!", dev_name(camsys_dev->miscdev.this_device));
         }
-        clk_disable(clk->cif_clk_out);
+
+        clk_disable_unprepare( clk->cif_clk_out);
+//        clk_disable(clk->cif_clk_out);
+
         clk->out_on = 0;
 
         camsys_trace(1, "%s clock out turn off",dev_name(camsys_dev->miscdev.this_device));
@@ -194,7 +224,7 @@ static irqreturn_t camsys_mrv_irq(int irq, void *data)
     __raw_writel(isp_mis, (void volatile *)(camsys_dev->devmems.registermem->vir_base + MRV_ISP_ICR)); 
     __raw_writel(mipi_mis, (void volatile *)(camsys_dev->devmems.registermem->vir_base + MRV_MIPI_ICR)); 
     __raw_writel(mi_mis, (void volatile *)(camsys_dev->devmems.registermem->vir_base + MRV_MI_ICR)); 
-    
+
     spin_lock(&camsys_dev->irq.lock);
     if (!list_empty(&camsys_dev->irq.irq_pool)) {
         list_for_each_entry(irqpool, &camsys_dev->irq.irq_pool, list) {
@@ -307,22 +337,24 @@ int camsys_mrv_probe_cb(struct platform_device *pdev, camsys_dev_t *camsys_dev)
      
    // mrv_clk->pd_isp = devm_clk_get(&pdev->dev, "pd_isp");
     mrv_clk->pd_isp = NULL;
-    mrv_clk->aclk_isp = devm_clk_get(&pdev->dev, "aclk_isp");
-    mrv_clk->hclk_isp = devm_clk_get(&pdev->dev, "hclk_isp");
+    mrv_clk->aclk_isp = devm_clk_get(&pdev->dev, "g_aclk_isp");
+    mrv_clk->hclk_isp = devm_clk_get(&pdev->dev, "g_hclk_isp");
     mrv_clk->isp = devm_clk_get(&pdev->dev, "clk_isp");
     mrv_clk->isp_jpe = devm_clk_get(&pdev->dev, "clk_isp_jpe");
     mrv_clk->pclkin_isp = devm_clk_get(&pdev->dev, "pclkin_isp");
-    mrv_clk->cif_clk_out = devm_clk_get(&pdev->dev, "clk_vipout");
+    mrv_clk->cif_clk_out = devm_clk_get(&pdev->dev, "clk_cif_out");
+    
     if (/*IS_ERR_OR_NULL(mrv_clk->pd_isp) ||*/ IS_ERR_OR_NULL(mrv_clk->aclk_isp) || IS_ERR_OR_NULL(mrv_clk->hclk_isp) ||
-        IS_ERR_OR_NULL(mrv_clk->isp) || IS_ERR_OR_NULL(mrv_clk->isp_jpe) || IS_ERR_OR_NULL(mrv_clk->pclkin_isp) || 
+        IS_ERR_OR_NULL(mrv_clk->isp) || IS_ERR_OR_NULL(mrv_clk->isp_jpe) /*|| IS_ERR_OR_NULL(mrv_clk->pclkin_isp)*/ || 
         IS_ERR_OR_NULL(mrv_clk->cif_clk_out)) {
         camsys_err("Get %s clock resouce failed!\n",miscdev_name);
         err = -EINVAL;
         goto clk_failed;
     }
+
     
-    clk_set_rate(mrv_clk->isp,320000000);
-    clk_set_rate(mrv_clk->isp_jpe,320000000);
+//    clk_set_rate(mrv_clk->isp,1800000000);
+//    clk_set_rate(mrv_clk->isp_jpe,180000000);
     
     spin_lock_init(&mrv_clk->lock);
     
index 62335ad55ec7095fd800a3619def21586c51d7f2..f973906d43ca08adbd2c5ea0cb1c7cfd6c55089b 100755 (executable)
 #define DPHY_RX0_TESTEN     (1<<2)
 #define DPHY_RX0_TESTDIN_OFFSET    (3)
 
+#define DPHY_TX1RX1_ENABLECLK_MASK   (0x1<<28)
+#define DPHY_RX1_SRC_SEL_MASK        (0x1<<29)
+#define DPHY_TX1RX1_MASTERSLAVEZ_MASK (0x1<<30)
+#define DPHY_TX1RX1_BASEDIR_OFFSET  (0x1<<31)
+
+#define DPHY_TX1RX1_ENABLECLK           (0x1<<12)
+#define DPHY_TX1RX1_DISABLECLK          (0x0<<12)
+#define DPHY_RX1_SRC_SEL_ISP          (0x1<<13)
+#define DPHY_TX1RX1_SLAVEZ            (0x0<<14)
+#define DPHY_TX1RX1_BASEDIR_REC       (0x1<<15)
+
+
 
 //GRF_SOC_CON6
 //bit 0 grf_con_disable_isp
 //bit 1 grf_con_isp_dphy_sel  1'b0 mipi phy rx0
 #define GRF_SOC_CON6_OFFSET    (0x025c)
-#define MIPI_PHY_RX0_MASK       (0x1<<16)
-#define MIPI_PHY_RX0            (0x1<<0)
+#define MIPI_PHY_DISABLE_ISP_MASK       (0x1<<16)
+#define MIPI_PHY_DISABLE_ISP            (0x0<<0)
+
+#define DSI_CSI_TESTBUS_SEL_MASK        (0x1<<30)
+#define DSI_CSI_TESTBUS_SEL_OFFSET_BIT  (14)
+
+
+#define MIPI_PHY_DPHYSEL_OFFSET_MASK (0x1<<17)
+#define MIPI_PHY_DPHYSEL_OFFSET_BIT (0x1)
+
+//GRF_SOC_CON10
+//bit12:15 grf_dphy_rx0_enable
+//bit 0:3 turn disable
+#define GRF_SOC_CON10_OFFSET                (0x026c)
+#define DPHY_RX0_TURN_DISABLE_MASK          (0xf<<16)
+#define DPHY_RX0_TURN_DISABLE_OFFSET_BITS   (0x0)
+#define DPHY_RX0_ENABLE_MASK                (0xf<<28)
+#define DPHY_RX0_ENABLE_OFFSET_BITS         (12)
+
+//GRF_SOC_CON9
+//bit12:15 grf_dphy_rx0_enable
+//bit 0:3 turn disable
+#define GRF_SOC_CON9_OFFSET                (0x0268)
+#define DPHY_TX1RX1_TURN_DISABLE_MASK          (0xf<<16)
+#define DPHY_TX1RX1_TURN_DISABLE_OFFSET_BITS   (0x0)
+#define DPHY_TX1RX1_ENABLE_MASK                (0xf<<28)
+#define DPHY_TX1RX1_ENABLE_OFFSET_BITS         (12)
+
+//GRF_SOC_CON15
+//bit 0:3   turn request
+#define GRF_SOC_CON15_OFFSET                (0x03a4) 
+#define DPHY_RX0_TURN_REQUEST_MASK          (0xf<<16)
+#define DPHY_RX0_TURN_REQUEST_OFFSET_BITS   (0x0)
+
+#define DPHY_TX1RX1_TURN_REQUEST_MASK          (0xf<<20)
+#define DPHY_TX1RX1_TURN_REQUEST_OFFSET_BITS   (0x0)
+
 
 #endif
 
-static void phy0_WriteReg(uint8_t addr, uint8_t data)
+
+static void phy_select(uint8_t index)
 {
+    if((index == 0) || (index == 1)){
+        write_grf_reg(GRF_SOC_CON6_OFFSET, MIPI_PHY_DPHYSEL_OFFSET_MASK | (index<<MIPI_PHY_DPHYSEL_OFFSET_BIT)); 
+        if(index == 1){
+            write_grf_reg(GRF_SOC_CON6_OFFSET, DSI_CSI_TESTBUS_SEL_MASK | (1<<DSI_CSI_TESTBUS_SEL_OFFSET_BIT)); 
+
+            write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX1_SRC_SEL_ISP | DPHY_RX1_SRC_SEL_MASK); 
+            write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_TX1RX1_SLAVEZ | DPHY_TX1RX1_MASTERSLAVEZ_MASK); 
+            write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_TX1RX1_BASEDIR_REC | DPHY_TX1RX1_BASEDIR_OFFSET); 
+        }
+
+    }else{
+        camsys_err("phy index is erro!");
+        
+    }
+}
+
 
+static void phy0_WriteReg(uint8_t addr, uint8_t data)
+{
+   // uint8_t test_data = 0;
     //TESTEN =1,TESTDIN=addr
     write_grf_reg(GRF_SOC_CON14_OFFSET,(( addr << DPHY_RX0_TESTDIN_OFFSET) |DPHY_RX0_TESTDIN_MASK | DPHY_RX0_TESTEN| DPHY_RX0_TESTEN_MASK)); 
+//     //TESTCLK=1
+    write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK |DPHY_RX0_TESTCLK);
+    
     //TESTCLK=0
-    write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK); 
-    //TESTEN =0,TESTDIN=data
-    write_grf_reg(GRF_SOC_CON14_OFFSET, (( data << DPHY_RX0_TESTDIN_OFFSET)|DPHY_RX0_TESTDIN_MASK |DPHY_RX0_TESTEN)); 
-    //TESTCLK=1
-    write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK |DPHY_RX0_TESTCLK); 
+        write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK); 
+  
+    if(data != -1){ //write data ?
+        //TESTEN =0,TESTDIN=data
+        write_grf_reg(GRF_SOC_CON14_OFFSET, (( data << DPHY_RX0_TESTDIN_OFFSET)|DPHY_RX0_TESTDIN_MASK |DPHY_RX0_TESTEN)); 
 
+        //TESTCLK=1
+        write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK |DPHY_RX0_TESTCLK); 
+    }
 }
 
-static uint8_t phy0_ReadReg(uint8_t addr)  //read 0xff968034 bit8~15
+static uint8_t phy0_ReadReg(uint8_t addr)  
 {
     uint8_t data = 0;
+    
     //TESTEN =1,TESTDIN=addr
     write_grf_reg(GRF_SOC_CON14_OFFSET,(( addr << DPHY_RX0_TESTDIN_OFFSET) |DPHY_RX0_TESTDIN_MASK | DPHY_RX0_TESTEN| DPHY_RX0_TESTEN_MASK)); 
+
     //TESTCLK=0
     write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK); 
 
-    data = ((read_grf_reg(GRF_SOC_CON14_OFFSET) >> DPHY_RX0_TESTDIN_OFFSET) & (0xff));
-
-    camsys_err("%s phy addr = 0x%x,value = 0x%x\n",__func__,addr,data);
     return data ;
 
     
 }
 
-
-static void PHY0_Init(int numLane,int clkfreq)
+static void phy_config_num_lane(uint8_t index,int numLane)
 {
-    
-//  select phy rx0
-    write_grf_reg(GRF_SOC_CON6_OFFSET, MIPI_PHY_RX0_MASK | MIPI_PHY_RX0); 
+    uint8_t lane_mask =0;
+    int i = 0;
 
+    for(i=0;i<numLane;i++){
+        lane_mask |= 1<<i;
+    }
+    camsys_trace(1,"lane num = 0x%d\n",lane_mask);
+    if(index == 0){
+    //  set lane num
+        write_grf_reg(GRF_SOC_CON10_OFFSET, DPHY_RX0_ENABLE_MASK | (lane_mask << DPHY_RX0_ENABLE_OFFSET_BITS)); 
+    //  set lan turndisab as 1
+        write_grf_reg(GRF_SOC_CON10_OFFSET, DPHY_RX0_TURN_DISABLE_MASK | (0xf << DPHY_RX0_TURN_DISABLE_OFFSET_BITS));
+
+        write_grf_reg(GRF_SOC_CON10_OFFSET, (0xc<<4)|(0xf<<20));
+
+    //  set lan turnrequest as 0   
+        write_grf_reg(GRF_SOC_CON15_OFFSET, DPHY_RX0_TURN_REQUEST_MASK | (0x0 << DPHY_RX0_TURN_REQUEST_OFFSET_BITS));
+    }else if(index == 1){
+    //  set lane num
+        write_grf_reg(GRF_SOC_CON9_OFFSET, DPHY_TX1RX1_ENABLE_MASK | (lane_mask << DPHY_TX1RX1_ENABLE_OFFSET_BITS)); 
+    //  set lan turndisab as 1
+        write_grf_reg(GRF_SOC_CON9_OFFSET, DPHY_TX1RX1_TURN_DISABLE_MASK | (0xf << DPHY_TX1RX1_TURN_DISABLE_OFFSET_BITS));
+    //  set lan turnrequest as 0   
+        write_grf_reg(GRF_SOC_CON15_OFFSET, DPHY_TX1RX1_TURN_REQUEST_MASK | (0x0 << DPHY_TX1RX1_TURN_REQUEST_OFFSET_BITS));
+    }
+}
+
+static void phy0_start(int freq,int numLane)
+{
 //TESTCLK=1
     write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK |DPHY_RX0_TESTCLK); 
 //TESTCLR=1    
-    write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK |DPHY_RX0_TESTCLK | DPHY_RX0_TESTCLR_MASK |DPHY_RX0_TESTCLR);   
+    write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLR_MASK |DPHY_RX0_TESTCLR);   
 //TESTCLR=0  zyc
-    write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK |DPHY_RX0_TESTCLK); 
+//    write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLR_MASK); 
+    udelay(1000);
 
 //**********************************************************************//
 
+#if 1
 //set clock lane
     phy0_WriteReg(0x34,0x14);
 
@@ -84,23 +182,69 @@ static void PHY0_Init(int numLane,int clkfreq)
     360M     0x2A
     *******************/
     phy0_WriteReg(0x44,0x10);
+    if(numLane > 1)
+        phy0_WriteReg(0x54,0x10);
+#endif
  
  //**********************************************************************//
 
 //Normal operation
-    phy0_ReadReg(0x00);                           
+    phy0_WriteReg(0x0,-1);
     //TESTCLK=1
     write_grf_reg(GRF_SOC_CON14_OFFSET, DPHY_RX0_TESTCLK_MASK |DPHY_RX0_TESTCLK); 
 
     //TESTEN =0
-    write_grf_reg(GRF_SOC_CON14_OFFSET, (DPHY_RX0_TESTEN)); 
+    write_grf_reg(GRF_SOC_CON14_OFFSET, (DPHY_RX0_TESTEN_MASK)); 
+
+}
 
- }
 
 
 static int camsys_mipiphy_ops (void *phy, void *phyinfo, unsigned int on)
 {
-    PHY0_Init(1,0);
+#if 0
+    camsys_phyinfo_t* phyinfo_s = (camsys_phyinfo_t*)phyinfo;
+    struct camsys_mipiphy_s* phy_s = (struct camsys_mipiphy_s*)phy;
+    if(phy_s->phy_index == 0){
+        phy_select(phy_s->phy_index);
+        phy_config_num_lane(phy_s->data_en_bit);
+        phy0_start(0,phy_s->data_en_bit);
+
+    }else if(phy_s->phy_index == 1){
+
+    }else{
+
+        camsys_err("phy index is erro!");
+    }
+#else
+#if 0
+    if(on == 1){
+    //disable isp
+        write_grf_reg(GRF_SOC_CON6_OFFSET, MIPI_PHY_DISABLE_ISP_MASK | 1); 
+        phy_select(0);
+    //    phy_config_num_lane(0,2);
+        phy0_start(0,2);
+
+        phy_config_num_lane(0,2);
+        udelay(200);
+    //enable isp
+        write_grf_reg(GRF_SOC_CON6_OFFSET, MIPI_PHY_DISABLE_ISP_MASK | 0); 
+    }else
+#endif
+    {
+    //disable isp
+        write_grf_reg(GRF_SOC_CON6_OFFSET, MIPI_PHY_DISABLE_ISP_MASK | 1); 
+        phy_select(0);
+    //    phy_config_num_lane(0,2);
+        phy0_start(0,1);
+
+        phy_config_num_lane(0,1);
+        udelay(200);
+    //enable isp
+        write_grf_reg(GRF_SOC_CON6_OFFSET, MIPI_PHY_DISABLE_ISP_MASK | 0); 
+    }
+
+#endif   
     return 0;
 }
 
@@ -120,6 +264,7 @@ int camsys_mipiphy_probe_cb(struct platform_device *pdev, camsys_dev_t *camsys_d
     camsys_dev->mipiphy.ops = camsys_mipiphy_ops;
     camsys_dev->mipiphy.remove = camsys_mipiphy_remove_cb;
 
+
     return 0;
   
 }
index 3adc33a13c735707f0e95a8819c18613ea54111c..44974b1dfc25a453a803a784047eebf86572becf 100755 (executable)
 *        1) add support cif phy for marvin;
 *v0.0.4:
 *        1) add clock information in struct camsys_devio_name_s;
+*v0.0.5:
+                1) add pwren control
 */
-#define CAMSYS_HEAD_VERSION           KERNEL_VERSION(0,0,4)
+#define CAMSYS_HEAD_VERSION           KERNEL_VERSION(0,0,5)
 
 #define CAMSYS_MARVIN_DEVNAME         "camsys_marvin"           
 #define CAMSYS_CIF0_DEVNAME           "camsys_cif0"
@@ -95,7 +97,8 @@ typedef enum camsys_sysctrl_ops_e {
     CamSys_Rst,
     CamSys_AfPwr,
     CamSys_AfPwrDn,
-
+    CamSys_PwrEn,
+    
     CamSys_Gpio_Tag = 50,
 
     CamSys_ClkIn   
@@ -124,6 +127,10 @@ typedef struct camsys_flash_info_s {
 
 typedef struct camsys_mipiphy_s {
     unsigned int                data_en_bit;        //data lane enable bit;
+    #if 0
+    unsigned int                freq;
+    unsigned int                phy_index;          //phy0,phy1
+    #endif
 } camsys_mipiphy_t;
 
 typedef enum camsys_fmt_e {
@@ -176,9 +183,11 @@ typedef struct camsys_devio_name_s {
     camsys_regulator_info_t     afvdd; 
 
     camsys_gpio_info_t          pwrdn;        // standby gpio name
-    camsys_gpio_info_t          rst;          // hard reset gpio name  
+    camsys_gpio_info_t          rst;          // hard reset gpio name 
     camsys_gpio_info_t          afpwr;        // auto focus vcm driver ic power gpio name
     camsys_gpio_info_t          afpwrdn;      // auto focus vcm driver ic standby gpio 
+    camsys_gpio_info_t          pwren;          // power enable gpio name  
+
 
     camsys_flash_info_t         fl;