7d62386ee2eaba82b06ae70b14cd6ac4cc0cdfbc
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / rk_camsys / camsys_soc_priv.c
1
2 #include "camsys_soc_priv.h"
3
4
5
6 static camsys_soc_priv_t* camsys_soc_p;
7
8 #include "camsys_soc_rk3288.c"
9
10 static int camsys_rk3288_cfg (camsys_soc_cfg_t cfg_cmd, void* cfg_para)
11 {
12     unsigned int *para_int;
13     
14     switch (cfg_cmd)
15     {
16         case Clk_DriverStrength_Cfg:
17         {
18             para_int = (unsigned int*)cfg_para;
19             __raw_writel((((*para_int)&0x03)<<3)|(0x03<<3), RK_GRF_VIRT+0x01d4);
20             break;
21         }
22
23         case Cif_IoDomain_Cfg:
24         {
25             para_int = (unsigned int*)cfg_para;
26             if (*para_int < 28000000) {
27                 __raw_writel(((1<<1)|(1<<(1+16))),RK_GRF_VIRT+0x0380);    // 1.8v IO
28             } else {
29                 __raw_writel(((0<<1)|(1<<(1+16))),RK_GRF_VIRT+0x0380);    // 3.3v IO
30             }
31             break;
32         }
33
34         case Mipi_Phy_Cfg:
35         {
36             camsys_rk3288_mipihpy_cfg((camsys_mipiphy_soc_para_t*)cfg_para);
37             break;
38         }
39
40         case Isp_SoftRst:         /* ddl@rock-chips.com: v0.d.0 */
41         {
42             unsigned int reset;
43             reset = (unsigned int)cfg_para;
44
45             if (reset == 1)
46                 cru_writel(0x40004000,0x1d0);
47             else 
48                 cru_writel(0x40000000,0x1d0);
49             camsys_trace(1, "Isp_SoftRst: %d",reset);
50             break;
51         }
52
53         default:
54         {
55             camsys_warn("cfg_cmd: 0x%x isn't support for %s",cfg_cmd,camsys_soc_p->name);
56             break;
57         }
58
59     }
60
61     return 0;
62
63
64 }
65
66 camsys_soc_priv_t* camsys_soc_get(void)
67 {
68     if (camsys_soc_p != NULL) {
69         return camsys_soc_p;
70     } else {
71         return NULL;
72     }
73 }
74
75 int camsys_soc_init(void)
76 {    
77     camsys_soc_p = kzalloc(sizeof(camsys_soc_priv_t),GFP_KERNEL);
78     if (camsys_soc_p == NULL) {
79         camsys_err("malloc camsys_soc_priv_t failed!");
80         goto fail;
81     }
82
83     if (soc_is_rk3288()) {
84         strlcpy(camsys_soc_p->name,"camsys_rk3288",31);
85         camsys_soc_p->soc_cfg = camsys_rk3288_cfg;
86     } else {
87         camsys_err("camsys isn't support soc: 0x%lx!",rockchip_soc_id);
88         goto fail;
89     }
90     
91     return 0;
92 fail:
93     if (camsys_soc_p != NULL) {
94         kfree(camsys_soc_p);
95         camsys_soc_p = NULL;
96     }
97     return -1;
98 }
99
100 int camsys_soc_deinit(void)
101 {
102     if (camsys_soc_p != NULL) {
103         kfree(camsys_soc_p);
104         camsys_soc_p = NULL;
105     }
106     return 0;
107 }