tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / sprd_isp / isp2.0 / tshark2 / src / isp_k_common.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 "isp_reg.h"
18
19 static int32_t isp_k_common_block(struct isp_io_param *param)
20 {
21         int32_t ret = 0;
22         struct isp_dev_common_info_v1 common_info;
23
24         memset(&common_info, 0x00, sizeof(common_info));
25
26         ret = copy_from_user((void *)&common_info, param->property_param, sizeof(common_info));
27         if (0 != ret) {
28                 printk("isp_k_common_block: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
29                 return -1;
30         }
31
32         REG_MWR(ISP_COMMON_CTRL_CH0, 3, common_info.fetch_sel_0);
33         REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 4, common_info.sizer_sel_0  << 4);
34         REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 16, common_info.store_sel_0  << 16);
35         REG_MWR(ISP_COMMON_CTRL_CH1, 3, common_info.fetch_sel_1);
36         REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 4, common_info.sizer_sel_1  << 4);
37         REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 16, common_info.store_sel_1  << 16);
38         REG_MWR(ISP_COMMON_SPACE_SEL, 3 , common_info.fetch_color_format) ;
39         REG_MWR(ISP_COMMON_SPACE_SEL, 3  << 2, common_info.store_color_format << 2) ;
40         REG_MWR(ISP_COMMON_CTRL_AWBM, BIT_0 , common_info.awbm_pos) ;
41         REG_MWR(ISP_COMMON_3A_CTRL0, 3, common_info.y_afm_pos_0);
42         REG_MWR(ISP_COMMON_3A_CTRL0, 3 << 4, common_info.y_aem_pos_0  << 4);
43         REG_MWR(ISP_COMMON_3A_CTRL1, 3, common_info.y_afm_pos_1);
44         REG_MWR(ISP_COMMON_3A_CTRL1, 3 << 4, common_info.y_aem_pos_1  << 4);
45         REG_WR(ISP_COMMON_LBUF_OFFSET0, ((common_info.lbuf_off.cfae_lbuf_offset & 0xFFFF) << 16 ) | (common_info.lbuf_off.comm_lbuf_offset & 0xFFFF));
46         REG_WR(ISP_COMMON_LBUF_OFFSET1, ((common_info.lbuf_off.ydly_lbuf_offset& 0xFFFF) << 16 ) | (common_info.lbuf_off.awbm_lbuf_offset & 0xFFFF));
47
48         return ret;
49 }
50
51 static int32_t isp_k_common_version(struct isp_io_param *param)
52 {
53         int32_t ret = 0;
54         uint32_t version = 0;
55
56         version = REG_RD(ISP_COMMON_VERSION);
57
58         ret = copy_to_user(param->property_param, (void*)&version, sizeof(version));
59         if (0 != ret) {
60                 ret = -1;
61                 printk("isp_k_common_version: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
62         }
63
64         return ret;
65 }
66
67 static int32_t isp_k_common_status0(struct isp_io_param *param)
68 {
69         int32_t ret = 0;
70         uint32_t status = 0;
71
72         status = REG_RD(ISP_COMMON_STATUS0);
73
74         ret = copy_to_user(param->property_param, (void*)&status, sizeof(status));
75         if (0 != ret) {
76                 ret = -1;
77                 printk("isp_k_common_status0: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
78         }
79
80         return ret;
81 }
82
83 static int32_t isp_k_common_status1(struct isp_io_param *param)
84 {
85         int32_t ret = 0;
86         uint32_t status = 0;
87
88         status = REG_RD(ISP_COMMON_STATUS1);
89
90         ret = copy_to_user(param->property_param, (void*)&status, sizeof(status));
91         if (0 != ret) {
92                 ret = -1;
93                 printk("isp_k_common_status1: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
94         }
95
96         return ret;
97 }
98
99 static int32_t isp_k_common_channel0_fetch_sel(struct isp_io_param *param)
100 {
101         int32_t ret = 0;
102         uint32_t fetch_sel = 0;
103
104         ret = copy_from_user((void *)&fetch_sel, param->property_param, sizeof(fetch_sel));
105         if (0 != ret) {
106                 printk("isp_k_channel0_fetch_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
107                 return -1;
108         }
109
110         REG_MWR(ISP_COMMON_CTRL_CH0, 3, fetch_sel);
111
112         return ret;
113 }
114
115 static int32_t isp_k_common_channel0_sizer_sel(struct isp_io_param *param)
116 {
117         int32_t ret = 0;
118         uint32_t sizer_sel = 0;
119
120         ret = copy_from_user((void *)&sizer_sel, param->property_param, sizeof(sizer_sel));
121         if (0 != ret) {
122                 printk("isp_k_channel0_sizer_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
123                 return -1;
124         }
125
126         REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 4, sizer_sel  << 4);
127
128         return ret;
129 }
130
131 static int32_t isp_k_common_channel0_store_sel(struct isp_io_param *param)
132 {
133         int32_t ret = 0;
134         uint32_t store_sel = 0;
135
136         ret = copy_from_user((void *)&store_sel, param->property_param, sizeof(store_sel));
137         if (0 != ret) {
138                 printk("isp_k_common_channel0_store_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
139                 return -1;
140         }
141
142         REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 16, store_sel  << 16);
143
144         return ret;
145 }
146
147 static int32_t isp_k_common_channel1_fetch_sel(struct isp_io_param *param)
148 {
149         int32_t ret = 0;
150         uint32_t fetch_sel = 0;
151
152         ret = copy_from_user((void *)&fetch_sel, param->property_param, sizeof(fetch_sel));
153         if (0 != ret) {
154                 printk("isp_k_channel1_fetch_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
155                 return -1;
156         }
157
158         REG_MWR(ISP_COMMON_CTRL_CH1, 3, fetch_sel);
159
160         return ret;
161 }
162
163 static int32_t isp_k_common_channel1_sizer_sel(struct isp_io_param *param)
164 {
165         int32_t ret = 0;
166         uint32_t sizer_sel = 0;
167
168         ret = copy_from_user((void *)&sizer_sel, param->property_param, sizeof(sizer_sel));
169         if (0 != ret) {
170                 printk("isp_k_common_channel1_sizer_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
171                 return -1;
172         }
173
174         REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 4, sizer_sel  << 4);
175
176         return ret;
177 }
178
179 static int32_t isp_k_common_channel1_store_sel(struct isp_io_param *param)
180 {
181         int32_t ret = 0;
182         uint32_t store_sel = 0;
183
184         ret = copy_from_user((void *)&store_sel, param->property_param, sizeof(store_sel));
185         if (0 != ret) {
186                 printk("isp_k_common_channel1_store_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
187                 return -1;
188         }
189
190         REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 16, store_sel  << 16);
191
192         return ret;
193 }
194
195 static int32_t isp_k_common_fetch_color_space_sel(struct isp_io_param *param)
196 {
197         int32_t ret = 0;
198         uint32_t color_space = 0;
199
200         ret = copy_from_user((void *)&color_space, param->property_param, sizeof(color_space));
201         if (0 != ret) {
202                 printk("isp_k_common_fetch_color_space_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
203                 return -1;
204         }
205
206         REG_MWR(ISP_COMMON_SPACE_SEL, 3 , color_space) ;
207
208         return ret;
209 }
210
211 static int32_t isp_k_common_store_color_space_sel(struct isp_io_param *param)
212 {
213         int32_t ret = 0;
214         uint32_t color_space = 0;
215
216         ret = copy_from_user((void *)&color_space, param->property_param, sizeof(color_space));
217         if (0 != ret) {
218                 printk("isp_k_common_store_color_space_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
219                 return -1;
220         }
221
222         REG_MWR(ISP_COMMON_SPACE_SEL, 3  << 2, color_space << 2) ;
223
224         return ret;
225 }
226
227 static int32_t isp_k_common_awbm_pos_sel(struct isp_io_param *param)
228 {
229         int32_t ret = 0;
230         uint32_t awbm_pos = 0;
231
232         ret = copy_from_user((void *)&awbm_pos, param->property_param, sizeof(awbm_pos));
233         if (0 != ret) {
234                 printk("isp_k_common_awbm_pos_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
235                 return -1;
236         }
237
238         REG_MWR(ISP_COMMON_CTRL_AWBM, BIT_0 , awbm_pos) ;
239
240         return ret;
241 }
242
243 static int32_t isp_k_common_channel0_y_afm_pos(struct isp_io_param *param)
244 {
245         int32_t ret = 0;
246         uint32_t position = 0;
247
248         ret = copy_from_user((void *)&position, param->property_param, sizeof(position));
249         if (0 != ret) {
250                 printk("isp_k_common_channel0_y_afm_pos: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
251                 return -1;
252         }
253
254         REG_MWR(ISP_COMMON_3A_CTRL0, 3, position);
255
256         return ret;
257 }
258
259 static int32_t isp_k_common_channel0_y_aem_pos(struct isp_io_param *param)
260 {
261         int32_t ret = 0;
262         uint32_t position = 0;
263
264         ret = copy_from_user((void *)&position, param->property_param, sizeof(position));
265         if (0 != ret) {
266                 printk("isp_k_common_channel0_y_aem_pos: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
267                 return -1;
268         }
269
270         REG_MWR(ISP_COMMON_3A_CTRL0, 3 << 4, position  << 4);
271
272         return ret;
273 }
274
275 static int32_t isp_k_common_channel1_y_afm_pos(struct isp_io_param *param)
276 {
277         int32_t ret = 0;
278         uint32_t position = 0;
279
280         ret = copy_from_user((void *)&position, param->property_param, sizeof(position));
281         if (0 != ret) {
282                 printk("isp_k_common_channel1_y_afm_pos: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
283                 return -1;
284         }
285
286         REG_MWR(ISP_COMMON_3A_CTRL1, 3, position);
287
288         return ret;
289 }
290
291 static int32_t isp_k_common_channel1_y_aem_pos(struct isp_io_param *param)
292 {
293         int32_t ret = 0;
294         uint32_t position = 0;
295
296         ret = copy_from_user((void *)&position, param->property_param, sizeof(position));
297         if (0 != ret) {
298                 printk("isp_k_common_channel1_y_aem_pos: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
299                 return -1;
300         }
301
302         REG_MWR(ISP_COMMON_3A_CTRL1, 3 << 4, position  << 4);
303
304         return ret;
305 }
306
307 static int32_t isp_k_common_lbuf_offset(struct isp_io_param *param)
308 {
309         int32_t ret = 0;
310         struct isp_common_lbuf_param_v1 lbuf_off;
311
312         memset(&lbuf_off, 0x00, sizeof(lbuf_off));
313         ret = copy_from_user((void *)&lbuf_off, param->property_param, sizeof(lbuf_off));
314         if (0 != ret) {
315                 printk("isp_k_common_lbuf_offset: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
316                 return -1;
317         }
318
319         REG_WR(ISP_COMMON_LBUF_OFFSET0, ((lbuf_off.cfae_lbuf_offset & 0xFFFF) << 16 ) | (lbuf_off.comm_lbuf_offset & 0xFFFF));
320         REG_WR(ISP_COMMON_LBUF_OFFSET1, ((lbuf_off.ydly_lbuf_offset& 0xFFFF) << 16 ) | (lbuf_off.awbm_lbuf_offset & 0xFFFF));
321
322         return ret;
323 }
324
325 static int32_t isp_k_all_shadow_ctrl(struct isp_io_param *param)
326 {
327         int32_t ret = 0;
328         uint32_t auto_shadow = 0;
329
330         ret = copy_from_user((void *)&auto_shadow, param->property_param, sizeof(auto_shadow));
331         if (0 != ret) {
332                 printk("isp_k_all_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
333                 return -1;
334         }
335
336         REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 16, auto_shadow  << 16);
337
338         return ret;
339 }
340
341 static int32_t isp_k_awbm_shadow_ctrl(struct isp_io_param *param)
342 {
343         int32_t ret = 0;
344         uint32_t shadow_done = 0;
345
346         ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
347         if (0 != ret) {
348                 printk("isp_k_awbm_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
349                 return -1;
350         }
351
352         REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 17, shadow_done  << 17);
353
354         return ret;
355 }
356
357 static int32_t isp_k_ae_shadow_ctrl(struct isp_io_param *param)
358 {
359         int32_t ret = 0;
360         uint32_t shadow_done = 0;
361
362         ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
363         if (0 != ret) {
364                 printk("isp_k_ae_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
365                 return -1;
366         }
367
368         REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 18, shadow_done  << 18);
369
370         return ret;
371 }
372
373 static int32_t isp_k_af_shadow_ctrl(struct isp_io_param *param)
374 {
375         int32_t ret = 0;
376         uint32_t shadow_done = 0;
377
378         ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
379         if (0 != ret) {
380                 printk("isp_k_af_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
381                 return -1;
382         }
383
384         REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 19, shadow_done  << 19);
385
386         return ret;
387 }
388
389 static int32_t isp_k_afl_shadow_ctrl(struct isp_io_param *param)
390 {
391         int32_t ret = 0;
392         uint32_t shadow_done = 0;
393
394         ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
395         if (0 != ret) {
396                 printk("isp_k_afl_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
397                 return -1;
398         }
399
400         REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 20, shadow_done  << 20);
401
402         return ret;
403 }
404
405 static int32_t isp_k_comm_shadow_ctrl(struct isp_io_param *param)
406 {
407         int32_t ret = 0;
408         uint32_t shadow_done = 0;
409
410         ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
411         if (0 != ret) {
412                 printk("isp_k_comm_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
413                 return -1;
414         }
415
416         REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 21, shadow_done  << 21);
417
418         return ret;
419 }
420
421 static int32_t isp_k_3a_shadow_ctrl(struct isp_io_param *param)
422 {
423         int32_t ret = 0;
424         uint32_t enable = 0;
425
426         ret = copy_from_user((void *)&enable, param->property_param, sizeof(enable));
427         if (0 != ret) {
428                 printk("isp_k_3a_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
429                 return -1;
430         }
431
432         REG_MWR(ISP_COMMON_RESERVED0, 1 << 2, enable  << 2);
433
434         return ret;
435 }
436
437 int32_t isp_k_cfg_common(struct isp_io_param *param)
438 {
439         int32_t ret = 0;
440
441         if (!param) {
442                 printk("isp_k_cfg_common: param is null error.\n");
443                 return -1;
444         }
445
446         if (NULL == param->property_param) {
447                 printk("isp_k_cfg_common: property_param is null error.\n");
448                 return -1;
449         }
450
451         switch (param->property) {
452         case ISP_PRO_COMMON_BLOCK:
453                 ret = isp_k_common_block(param);
454                 break;
455         case ISP_PRO_COMMON_VERSION:
456                 ret = isp_k_common_version(param);
457                 break;
458         case ISP_PRO_COMMON_STATUS0:
459                 ret = isp_k_common_status0(param);
460                 break;
461         case ISP_PRO_COMMON_STATUS1:
462                 ret = isp_k_common_status1(param);
463                 break;
464         case ISP_PRO_COMMON_CH0_FETCH_SEL:
465                 ret = isp_k_common_channel0_fetch_sel(param);
466                 break;
467         case ISP_PRO_COMMON_CH0_SIZER_SEL:
468                 ret = isp_k_common_channel0_sizer_sel(param);
469                 break;
470         case ISP_PRO_COMMON_CH0_STORE_SEL:
471                 ret = isp_k_common_channel0_store_sel(param);
472                 break;
473         case ISP_PRO_COMMON_CH1_FETCH_SEL:
474                 ret = isp_k_common_channel1_fetch_sel(param);
475                 break;
476         case ISP_PRO_COMMON_CH1_SIZER_SEL:
477                 ret = isp_k_common_channel1_sizer_sel(param);
478                 break;
479         case ISP_PRO_COMMON_CH1_STORE_SEL:
480                 ret = isp_k_common_channel1_store_sel(param);
481                 break;
482         case ISP_PRO_COMMON_FETCH_COLOR_SPACE_SEL:
483                 ret = isp_k_common_fetch_color_space_sel(param);
484                 break;
485         case ISP_PRO_COMMON_STORE_COLOR_SPACE_SEL:
486                 ret = isp_k_common_store_color_space_sel(param);
487                 break;
488         case ISP_PRO_COMMON_AWBM_POS_SEL:
489                 ret = isp_k_common_awbm_pos_sel(param);
490                 break;
491         case ISP_PRO_COMMON_CH0_AEM2_POS:
492                 ret = isp_k_common_channel0_y_aem_pos(param);
493                 break;
494         case ISP_PRO_COMMON_CH0_Y_AFM_POS:
495                 ret = isp_k_common_channel0_y_afm_pos(param);
496                 break;
497         case ISP_PRO_COMMON_CH1_AEM2_POS:
498                 ret = isp_k_common_channel1_y_aem_pos(param);
499                 break;
500         case ISP_PRO_COMMON_CH1_Y_AFM_POS:
501                 ret = isp_k_common_channel1_y_afm_pos(param);
502                 break;
503         case ISP_PRO_COMMON_LBUF_OFFSET:
504                 ret = isp_k_common_lbuf_offset(param);
505                 break;
506         case ISP_PRO_COMMON_SHADOW_ALL_CTRL:
507                 ret = isp_k_all_shadow_ctrl(param);
508                 break;
509         case ISP_PRO_COMMON_AWBM_SHADOW:
510                 ret = isp_k_awbm_shadow_ctrl(param);
511                 break;
512         case ISP_PRO_COMMON_AE_SHADOW:
513                 ret = isp_k_ae_shadow_ctrl(param);
514                 break;
515         case ISP_PRO_COMMON_AF_SHADOW:
516                 ret = isp_k_af_shadow_ctrl(param);
517                 break;
518         case ISP_PRO_COMMON_AFL_SHADOW:
519                 ret = isp_k_afl_shadow_ctrl(param);
520                 break;
521         case ISP_PRO_COMMON_COMM_SHADOW:
522                 ret = isp_k_comm_shadow_ctrl(param);
523                 break;
524         case ISP_PRO_COMMON_3A_SINGLE_FRAME_CTRL:
525                 ret = isp_k_3a_shadow_ctrl(param);
526                 break;
527         default:
528                 printk("isp_k_cfg_common: fail cmd id:%d, not supported.\n", param->property);
529                 break;
530         }
531
532         return ret;
533 }