2 * Copyright (C) 2012 Spreadtrum Communications Inc.
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.
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.
14 #include <linux/uaccess.h>
15 #include <linux/sprd_mm.h>
16 #include <video/sprd_isp.h>
19 static int32_t isp_k_common_block(struct isp_io_param *param)
22 struct isp_dev_common_info_v2 common_info;
24 memset(&common_info, 0x00, sizeof(common_info));
26 ret = copy_from_user((void *)&common_info, param->property_param, sizeof(common_info));
28 printk("isp_k_common_block: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
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);
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));
56 static int32_t isp_k_common_version(struct isp_io_param *param)
61 version = REG_RD(ISP_COMMON_VERSION);
63 ret = copy_to_user(param->property_param, (void*)&version, sizeof(version));
66 printk("isp_k_common_version: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
72 static int32_t isp_k_common_status0(struct isp_io_param *param)
77 status = REG_RD(ISP_COMMON_STATUS0);
79 ret = copy_to_user(param->property_param, (void*)&status, sizeof(status));
82 printk("isp_k_common_status0: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
88 static int32_t isp_k_common_status1(struct isp_io_param *param)
93 status = REG_RD(ISP_COMMON_STATUS1);
95 ret = copy_to_user(param->property_param, (void*)&status, sizeof(status));
98 printk("isp_k_common_status1: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
104 static int32_t isp_k_common_channel0_fetch_sel(struct isp_io_param *param)
107 uint32_t fetch_sel = 0;
109 ret = copy_from_user((void *)&fetch_sel, param->property_param, sizeof(fetch_sel));
111 printk("isp_k_channel0_fetch_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
115 REG_MWR(ISP_COMMON_CTRL_CH0, 3, fetch_sel);
120 static int32_t isp_k_common_channel0_sizer_sel(struct isp_io_param *param)
123 uint32_t sizer_sel = 0;
125 ret = copy_from_user((void *)&sizer_sel, param->property_param, sizeof(sizer_sel));
127 printk("isp_k_channel0_sizer_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
131 REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 4, sizer_sel << 4);
136 static int32_t isp_k_common_channel0_store_sel(struct isp_io_param *param)
139 uint32_t store_sel = 0;
141 ret = copy_from_user((void *)&store_sel, param->property_param, sizeof(store_sel));
143 printk("isp_k_common_channel0_store_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
147 REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 16, store_sel << 16);
152 static int32_t isp_k_common_channel1_fetch_sel(struct isp_io_param *param)
155 uint32_t fetch_sel = 0;
157 ret = copy_from_user((void *)&fetch_sel, param->property_param, sizeof(fetch_sel));
159 printk("isp_k_channel1_fetch_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
162 REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 2, fetch_sel << 2);
164 // REG_MWR(ISP_COMMON_CTRL_CH1, 3, fetch_sel);
169 static int32_t isp_k_common_channel1_sizer_sel(struct isp_io_param *param)
172 uint32_t sizer_sel = 0;
174 ret = copy_from_user((void *)&sizer_sel, param->property_param, sizeof(sizer_sel));
176 printk("isp_k_common_channel1_sizer_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
179 REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 6, sizer_sel << 6);
181 //REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 4, sizer_sel << 4);
186 static int32_t isp_k_common_channel1_store_sel(struct isp_io_param *param)
189 uint32_t store_sel = 0;
191 ret = copy_from_user((void *)&store_sel, param->property_param, sizeof(store_sel));
193 printk("isp_k_common_channel1_store_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
196 REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 18, store_sel << 18);
198 // REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 16, store_sel << 16);
203 static int32_t isp_k_common_fetch_color_space_sel(struct isp_io_param *param)
206 uint32_t color_space = 0;
208 ret = copy_from_user((void *)&color_space, param->property_param, sizeof(color_space));
210 printk("isp_k_common_fetch_color_space_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
214 REG_MWR(ISP_COMMON_SPACE_SEL, 3 , color_space) ;
219 static int32_t isp_k_common_store_color_space_sel(struct isp_io_param *param)
222 uint32_t color_space = 0;
224 ret = copy_from_user((void *)&color_space, param->property_param, sizeof(color_space));
226 printk("isp_k_common_store_color_space_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
230 REG_MWR(ISP_COMMON_SPACE_SEL, 3 << 2, color_space << 2) ;
235 static int32_t isp_k_common_awbm_pos_sel(struct isp_io_param *param)
238 uint32_t awbm_pos = 0;
240 ret = copy_from_user((void *)&awbm_pos, param->property_param, sizeof(awbm_pos));
242 printk("isp_k_common_awbm_pos_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
246 //REG_MWR(ISP_COMMON_CTRL_AWBM, BIT_0 , awbm_pos) ;
251 static int32_t isp_k_common_channel0_y_afm_pos(struct isp_io_param *param)
254 uint32_t position = 0;
256 ret = copy_from_user((void *)&position, param->property_param, sizeof(position));
258 printk("isp_k_common_channel0_y_afm_pos: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
262 // REG_MWR(ISP_COMMON_3A_CTRL0, 3, position);
267 static int32_t isp_k_common_channel0_y_aem_pos(struct isp_io_param *param)
270 uint32_t position = 0;
272 ret = copy_from_user((void *)&position, param->property_param, sizeof(position));
274 printk("isp_k_common_channel0_y_aem_pos: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
278 // REG_MWR(ISP_COMMON_3A_CTRL0, 3 << 4, position << 4);
283 static int32_t isp_k_common_channel1_y_afm_pos(struct isp_io_param *param)
286 uint32_t position = 0;
288 ret = copy_from_user((void *)&position, param->property_param, sizeof(position));
290 printk("isp_k_common_channel1_y_afm_pos: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
294 // REG_MWR(ISP_COMMON_3A_CTRL1, 3, position);
299 static int32_t isp_k_common_channel1_y_aem_pos(struct isp_io_param *param)
302 uint32_t position = 0;
304 ret = copy_from_user((void *)&position, param->property_param, sizeof(position));
306 printk("isp_k_common_channel1_y_aem_pos: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
310 // REG_MWR(ISP_COMMON_3A_CTRL1, 3 << 4, position << 4);
315 static int32_t isp_k_common_lbuf_offset(struct isp_io_param *param)
320 memset(&lbuf_off, 0x00, sizeof(lbuf_off));
321 ret = copy_from_user((void *)&lbuf_off, param->property_param, sizeof(lbuf_off));
323 printk("isp_k_common_lbuf_offset: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
328 REG_MWR(ISP_COMMON_LBUF_OFFSET, 0xFFFF, lbuf_off);
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));
336 static int32_t isp_k_all_shadow_ctrl(struct isp_io_param *param)
339 uint32_t auto_shadow = 0;
341 ret = copy_from_user((void *)&auto_shadow, param->property_param, sizeof(auto_shadow));
343 printk("isp_k_all_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
347 // REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 16, auto_shadow << 16);
352 static int32_t isp_k_awbm_shadow_ctrl(struct isp_io_param *param)
355 uint32_t shadow_done = 0;
357 ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
359 printk("isp_k_awbm_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
363 // REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 17, shadow_done << 17);
368 static int32_t isp_k_ae_shadow_ctrl(struct isp_io_param *param)
371 uint32_t shadow_done = 0;
373 ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
375 printk("isp_k_ae_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
379 // REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 18, shadow_done << 18);
384 static int32_t isp_k_af_shadow_ctrl(struct isp_io_param *param)
387 uint32_t shadow_done = 0;
389 ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
391 printk("isp_k_af_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
395 // REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 19, shadow_done << 19);
400 static int32_t isp_k_afl_shadow_ctrl(struct isp_io_param *param)
403 uint32_t shadow_done = 0;
405 ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
407 printk("isp_k_afl_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
411 // REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 20, shadow_done << 20);
416 static int32_t isp_k_comm_shadow_ctrl(struct isp_io_param *param)
419 uint32_t shadow_done = 0;
421 ret = copy_from_user((void *)&shadow_done, param->property_param, sizeof(shadow_done));
423 printk("isp_k_comm_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
427 // REG_MWR(ISP_SHADOW_CTRL_CH0, 1 << 21, shadow_done << 21);
432 static int32_t isp_k_3a_shadow_ctrl(struct isp_io_param *param)
437 ret = copy_from_user((void *)&enable, param->property_param, sizeof(enable));
439 printk("isp_k_3a_shadow_ctrl: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
443 REG_MWR(ISP_COMMON_RESERVED0, 1 << 2, enable << 2);
448 int32_t isp_k_cfg_common(struct isp_io_param *param)
453 printk("isp_k_cfg_common: param is null error.\n");
457 if (NULL == param->property_param) {
458 printk("isp_k_cfg_common: property_param is null error.\n");
462 switch (param->property) {
463 case ISP_PRO_COMMON_BLOCK:
464 ret = isp_k_common_block(param);
466 case ISP_PRO_COMMON_VERSION:
467 ret = isp_k_common_version(param);
469 case ISP_PRO_COMMON_STATUS0:
470 ret = isp_k_common_status0(param);
472 case ISP_PRO_COMMON_STATUS1:
473 ret = isp_k_common_status1(param);
475 case ISP_PRO_COMMON_CH0_FETCH_SEL:
476 ret = isp_k_common_channel0_fetch_sel(param);
478 case ISP_PRO_COMMON_CH0_SIZER_SEL:
479 ret = isp_k_common_channel0_sizer_sel(param);
481 case ISP_PRO_COMMON_CH0_STORE_SEL:
482 ret = isp_k_common_channel0_store_sel(param);
484 case ISP_PRO_COMMON_CH1_FETCH_SEL:
485 ret = isp_k_common_channel1_fetch_sel(param);
487 case ISP_PRO_COMMON_CH1_SIZER_SEL:
488 ret = isp_k_common_channel1_sizer_sel(param);
490 case ISP_PRO_COMMON_CH1_STORE_SEL:
491 ret = isp_k_common_channel1_store_sel(param);
493 case ISP_PRO_COMMON_FETCH_COLOR_SPACE_SEL:
494 ret = isp_k_common_fetch_color_space_sel(param);
496 case ISP_PRO_COMMON_STORE_COLOR_SPACE_SEL:
497 ret = isp_k_common_store_color_space_sel(param);
499 case ISP_PRO_COMMON_AWBM_POS_SEL:
500 ret = isp_k_common_awbm_pos_sel(param);
502 case ISP_PRO_COMMON_CH0_AEM2_POS:
503 ret = isp_k_common_channel0_y_aem_pos(param);
505 case ISP_PRO_COMMON_CH0_Y_AFM_POS:
506 ret = isp_k_common_channel0_y_afm_pos(param);
508 case ISP_PRO_COMMON_CH1_AEM2_POS:
509 ret = isp_k_common_channel1_y_aem_pos(param);
511 case ISP_PRO_COMMON_CH1_Y_AFM_POS:
512 ret = isp_k_common_channel1_y_afm_pos(param);
514 case ISP_PRO_COMMON_LBUF_OFFSET:
515 ret = isp_k_common_lbuf_offset(param);
517 case ISP_PRO_COMMON_SHADOW_ALL_CTRL:
518 ret = isp_k_all_shadow_ctrl(param);
520 case ISP_PRO_COMMON_AWBM_SHADOW:
521 ret = isp_k_awbm_shadow_ctrl(param);
523 case ISP_PRO_COMMON_AE_SHADOW:
524 ret = isp_k_ae_shadow_ctrl(param);
526 case ISP_PRO_COMMON_AF_SHADOW:
527 ret = isp_k_af_shadow_ctrl(param);
529 case ISP_PRO_COMMON_AFL_SHADOW:
530 ret = isp_k_afl_shadow_ctrl(param);
532 case ISP_PRO_COMMON_COMM_SHADOW:
533 ret = isp_k_comm_shadow_ctrl(param);
535 case ISP_PRO_COMMON_3A_SINGLE_FRAME_CTRL:
536 ret = isp_k_3a_shadow_ctrl(param);
539 printk("isp_k_cfg_common: fail cmd id:%d, not supported.\n", param->property);