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