tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / sprd_isp / isp2.0 / tshark2 / src / isp_k_binning4awb.c
1 /*
2  * Copyright (C) 2012 Spreadtrum Communications Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #include <linux/uaccess.h>
15 #include <linux/sprd_mm.h>
16 #include <video/sprd_isp.h>
17 #include <asm/cacheflush.h>
18 #include "isp_reg.h"
19 #include "isp_drv.h"
20
21 static int32_t isp_k_binging_param_update(struct isp_k_private *isp_private)
22 {
23         int32_t ret = 0;
24         uint32_t addr = 0;
25 #ifndef CONFIG_64BIT
26         void *buf_ptr = (void *)isp_private->bing4awb_buf_addr;
27 #endif
28         uint32_t buf_len = isp_private->bing4awb_buf_len;
29
30         if((0x00 != isp_private->bing4awb_buf_addr) && (0x00 != isp_private->bing4awb_buf_len)) {
31
32 #ifndef CONFIG_64BIT
33                 dmac_flush_range(buf_ptr, buf_ptr + buf_len);
34                 outer_flush_range(__pa(buf_ptr), __pa(buf_ptr) + buf_len);
35 #endif
36                 addr = (uint32_t)__pa(isp_private->bing4awb_buf_addr);
37
38                 REG_WR(ISP_BINNING_MEM_ADDR, addr);
39         }
40
41         return ret;
42 }
43
44 static int32_t isp_k_binning_block(struct isp_io_param *param,
45                         struct isp_k_private *isp_private)
46 {
47         int32_t ret = 0;
48         uint32_t val = 0;
49         int32_t i = 0;
50         struct isp_dev_binning4awb_info_v1 binning_info;
51
52         ret = copy_from_user((void *)&binning_info, param->property_param, sizeof(binning_info));
53         if (0 != ret) {
54                 printk("isp_k_binning_block: copy error, ret=0x%x\n", (uint32_t)ret);
55                 return -1;
56         }
57
58 //      isp_k_binging_param_update(isp_private);
59
60         val = (binning_info.burst_mode & 0x3) << 2;
61         REG_MWR(ISP_BINNING_PARAM, 0xC, val);
62
63         val = (binning_info.endian & 0x1) << 1;
64         REG_MWR(ISP_BINNING_PARAM, BIT_1, val);
65
66         val = (binning_info.mem_fifo_clr & 0x1) << 7;
67         REG_MWR(ISP_BINNING_PARAM, 0x80, val);
68
69         val = ((binning_info.hx & 0x7) << 4) | ((binning_info.vx & 0x7) << 8);
70         REG_MWR(ISP_BINNING_PARAM, 0x770, val);
71
72         REG_WR(ISP_BINNING_PITCH, binning_info.pitch);
73
74         REG_MWR(ISP_BINNING_PARAM, BIT_0, binning_info.bypass);
75
76         return ret;
77
78 }
79
80 static int32_t isp_k_binging_bypass(struct isp_io_param *param)
81 {
82         int32_t ret = 0;
83         uint32_t bypass = 0;
84         ret = copy_from_user((void *)&bypass, param->property_param, sizeof(uint32_t));
85         if (0 != ret) {
86                 printk("isp_k_binning_scaling_ratio: copy_from_user error, ret = 0x%x\n",(uint32_t)ret);
87                 return -1;
88         }
89
90         REG_MWR(ISP_BINNING_PARAM, BIT_0, bypass);
91
92         return ret;
93 }
94
95 static int32_t isp_k_binning_scaling_ratio(struct isp_io_param *param)
96 {
97         int32_t ret = 0;
98         uint32_t val = 0;
99         struct isp_scaling_ratio scaling_ratio;
100         ret = copy_from_user((void *)&scaling_ratio, param->property_param, sizeof(struct isp_scaling_ratio));
101         if (0 != ret) {
102                 printk("isp_k_binning_scaling_ratio: copy_from_user error, ret = 0x%x\n",(uint32_t)ret);
103                 return -1;
104         }
105
106         val = ((scaling_ratio.vertical & 0x7)<< 8)| ((scaling_ratio.horizontal & 0x7) << 4);
107         REG_MWR(ISP_BINNING_PARAM, 0x770, val);
108
109         return ret;
110 }
111
112 static int32_t isp_k_binging_mem_addr(struct isp_io_param *param)
113 {
114         int32_t ret = 0;
115         uint32_t addr = 0;
116
117         ret = copy_from_user((void *)&addr, param->property_param, sizeof(uint32_t));
118         if (0 != ret) {
119                 printk("isp_k_binning_scaling_ratio: copy_from_user error, ret = 0x%x\n",(uint32_t)ret);
120                 return -1;
121         }
122
123         REG_WR(ISP_BINNING_MEM_ADDR, addr);
124
125         return ret;
126 }
127
128 static int32_t isp_k_binning_statistics_buf(struct isp_io_param *param,
129                         struct isp_k_private *isp_private)
130 {
131         int32_t ret = 0;
132         uint32_t buf_id = 0;
133
134         if (isp_private->b4awb_buf[0].buf_flag == 0) {
135                 buf_id = isp_private->b4awb_buf[0].buf_id;
136         } else if (isp_private->b4awb_buf[1].buf_flag == 0) {
137                 buf_id = isp_private->b4awb_buf[0].buf_id;
138         }
139
140         ret = copy_to_user(param->property_param, (void*)&buf_id, sizeof(uint32_t));
141         if (0 != ret) {
142                 ret = -1;
143                 printk("isp_k_binning_statistics_buf: copy error, ret=0x%x\n", (uint32_t)ret);
144         }
145
146         return ret;
147 }
148
149 static int32_t isp_k_binning_buffaddr(struct isp_io_param *param,
150                         struct isp_k_private *isp_private)
151 {
152         int32_t ret = 0;
153         int32_t i = 0;
154         unsigned long phys_addr[2];
155         struct isp_b4awb_phys phy_addr;
156
157         ret = copy_from_user((void *)&phy_addr, param->property_param, sizeof(struct isp_b4awb_phys));
158         
159         phys_addr[0] = phy_addr.phys0;
160         phys_addr[1] = phy_addr.phys1;
161
162         for (i = 0; i < ISP_BING4AWB_NUM; i++) {
163                 isp_private->b4awb_buf[i].buf_id = i;
164                 isp_private->b4awb_buf[i].buf_flag = 0;
165                 isp_private->b4awb_buf[i].buf_phys_addr = phys_addr[i];
166         }
167
168         /*config buf_id 0 as default*/
169         isp_private->b4awb_buf[0].buf_flag = 1;
170         REG_WR(ISP_BINNING_MEM_ADDR, isp_private->b4awb_buf[0].buf_phys_addr);
171
172         printk("eric phys_addr 0x%x, 0x%x\n",phys_addr[0], phys_addr[1]);
173
174         return ret;
175 }
176
177 int32_t isp_k_cfg_binning(struct isp_io_param *param, struct isp_k_private *isp_private)
178 {
179         int32_t ret = 0;
180
181         if (!param) {
182                 printk("isp_k_cfg_binning: param is null error.\n");
183                 return -1;
184         }
185
186         if (NULL == param->property_param) {
187                 printk("isp_k_cfg_binning: property_param is null error.\n");
188                 return -1;
189         }
190
191         switch(param->property) {
192         case ISP_PRO_BINNING4AWB_BLOCK:
193                 ret = isp_k_binning_block(param, isp_private);
194                 break;
195         case ISP_PRO_BINNING4AWB_BYPASS:
196                 ret = isp_k_binging_bypass(param);
197                 break;
198         case ISP_PRO_BINNING4AWB_SCALING_RATIO:
199                 ret = isp_k_binning_scaling_ratio(param);
200                         break;
201         case ISP_PRO_BINNING4AWB_MEM_ADDR:
202                 ret = isp_k_binging_mem_addr(param);
203                 break;
204         case ISP_PRO_BINNING4AWB_STATISTICS_BUF:
205                 ret = isp_k_binning_statistics_buf(param, isp_private);
206                 break;
207         case ISP_PRO_BINNING4AWB_TRANSADDR:
208                 ret = isp_k_binning_buffaddr(param, isp_private);
209                 break;
210         default:
211                 printk("isp_k_cfg_binning: fail cmd id:%d, not supported.\n", param->property);
212                 break;
213         }
214
215         return ret;
216 }