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