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 #define ISP_AFM_WIN_NUM_V1 25
21 static int32_t isp_k_yiq_afm_block(struct isp_io_param *param)
26 int max_num = ISP_AFM_WIN_NUM_V1;
27 struct isp_dev_yiq_afm_info_v1 afm_info;
29 memset(&afm_info, 0x00, sizeof(afm_info));
31 ret = copy_from_user((void *)&afm_info, param->property_param, sizeof(afm_info));
33 printk("isp_k_yiq_afm_block: copy error, ret=0x%x\n", (uint32_t)ret);
37 REG_MWR(ISP_YIQ_AFM_PARAM, BIT_6, afm_info.mode << 6);
39 REG_MWR(ISP_COMMON_3A_CTRL0, BIT_0, afm_info.source_pos);
41 REG_MWR(ISP_YIQ_AFM_PARAM, 0x1F<<1, (afm_info.shift << 1));
43 REG_MWR(ISP_YIQ_AFM_PARAM, 0xF<<7, (afm_info.skip_num << 7));
45 REG_MWR(ISP_YIQ_AFM_PARAM, BIT_11, afm_info.skip_num_clear << 11);
47 REG_MWR(ISP_YIQ_AFM_PARAM, 0x7<<13, (afm_info.format << 13));
49 REG_MWR(ISP_YIQ_AFM_PARAM, BIT_16, afm_info.iir_bypass << 16);
51 for (i = 0; i < max_num; i++) {
52 val = ((afm_info.coord[i].start_y <<16) & 0xffff0000)
53 | (afm_info.coord[i].start_x & 0xffff);
54 REG_WR((ISP_YIQ_AFM_WIN_RANGE0 + 4*2*i), val);
56 val = ((afm_info.coord[i].end_y <<16) & 0xffff0000)
57 | (afm_info.coord[i].end_x & 0xffff);
58 REG_WR((ISP_YIQ_AFM_WIN_RANGE0 + 4*(2*i+1)), val);
61 for (i = 0; i < 10; i+= 2) {
62 val = (afm_info.IIR_c[i] & 0xFFF) | ((afm_info.IIR_c[i + 1] & 0xFFF) << 16);
63 REG_WR(ISP_YIQ_AFM_COEF0_1 + (i / 2) * 4, val);
65 val = afm_info.IIR_c[10] & 0xFFF;
66 REG_WR(ISP_YIQ_AFM_COEF10, val);
68 REG_MWR(ISP_YIQ_AFM_PARAM, BIT_0, afm_info.bypass);
74 static int32_t isp_k_yiq_afm_statistic(struct isp_io_param *param)
78 int max_item = ISP_AFM_WIN_NUM_V1*4;
79 struct isp_yiq_afm_statistic item;
81 memset(&item, 0, sizeof(struct isp_yiq_afm_statistic));
82 for (i = 0; i < max_item; i++) {
83 item.val[i] = REG_RD((ISP_YIQ_AFM_LAPLACE0 + 4*i));
85 ret = copy_to_user(param->property_param, (void*)&item, sizeof(item));
88 printk("isp_k_yiq_afm_statistic: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
94 static int32_t isp_k_yiq_afm_slice_size(struct isp_io_param *param)
98 struct isp_img_size slice_size= {0, 0};
100 ret = copy_from_user((void *)&slice_size, param->property_param, sizeof(slice_size));
102 printk("isp_k_ae_skip_num: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
106 val = (slice_size.width& 0xFFFF) | ((slice_size.height& 0xFFFF) << 16);
107 REG_WR( ISP_YIQ_AFM_SLICE_SIZE, val);
113 static int32_t isp_k_yiq_afm_win(struct isp_io_param *param)
117 int max_num = ISP_AFM_WIN_NUM_V1;
118 struct isp_coord coord[ISP_AFM_WIN_NUM_V1];
122 memset(coord, 0, sizeof(coord));
123 ret = copy_from_user((void *)&coord, param->property_param, sizeof(coord));
125 printk("isp_k_yiq_afm_win: read copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
129 for (i = 0; i < max_num; i++) {
130 val = ((coord[i].start_y <<16) & 0xffff0000)
131 | (coord[i].start_x & 0xffff);
132 REG_WR((ISP_YIQ_AFM_WIN_RANGE0 + 4*2*i), val);
134 val = ((coord[i].end_y <<16) & 0xffff0000)
135 | (coord[i].end_x & 0xffff);
136 REG_WR((ISP_YIQ_AFM_WIN_RANGE0 + 4*(2*i+1)), val);
142 static int32_t isp_k_yiq_afm_win_num(struct isp_io_param *param)
145 uint32_t num = ISP_AFM_WIN_NUM_V1;
147 ret = copy_to_user(param->property_param, (void*)&num, sizeof(num));
150 printk("isp_k_yiq_afm_win_num: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
157 int32_t isp_k_cfg_yiq_afm(struct isp_io_param *param)
162 printk("isp_k_cfg_afm: param is null error.\n");
166 if (NULL == param->property_param) {
167 printk("isp_k_cfg_afm: property_param is null error.\n");
171 switch (param->property) {
172 case ISP_PRO_YIQ_AFM_BLOCK:
173 ret = isp_k_yiq_afm_block(param);
175 case ISP_PRO_YIQ_AFM_SLICE_SIZE:
176 ret = isp_k_yiq_afm_slice_size(param);
178 case ISP_PRO_YIQ_AFM_STATISTIC:
179 ret = isp_k_yiq_afm_statistic(param);
181 case ISP_PRO_YIQ_AFM_WIN_NUM:
182 ret = isp_k_yiq_afm_win_num(param);
184 case ISP_PRO_YIQ_AFM_WIN:
185 ret = isp_k_yiq_afm_win(param);
188 printk("isp_k_cfg_yiq_afm: fail cmd id:%d, not supported.\n", param->property);