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>
17 #include <linux/vmalloc.h>
20 static int32_t isp_k_vst_block(struct isp_io_param *param)
23 struct isp_dev_vst_info_v1 vst_info;
25 ret = copy_from_user((void *)&vst_info, param->property_param, sizeof(vst_info));
27 printk("isp_k_vst_block: copy error, ret=0x%x\n", (uint32_t)ret);
31 REG_MWR(ISP_VST_PARA, BIT_0, vst_info.bypass);
33 REG_MWR(ISP_VST_PARA, BIT_1, vst_info.buf_sel << 1);
39 static int32_t isp_k_nlm_block(struct isp_io_param *param)
44 struct isp_dev_nlm_info_v1 nlm_info;
45 uint32_t *buff0 = NULL;
46 uint32_t *buff1 = NULL;
47 uint32_t *buff2 = NULL;
48 unsigned long buf_addr = 0;
49 void *vst_addr = NULL;
50 void *ivst_addr = NULL;
51 void *nlm_addr = NULL;
53 ret = copy_from_user((void *)&nlm_info, param->property_param, sizeof(nlm_info));
55 printk("isp_k_nlm_block: copy error, ret=0x%x\n", (uint32_t)ret);
59 buff0 = vzalloc(nlm_info.vst_len);
61 printk("isp_k_nlm_block:vst kmalloc error\n");
65 buff1 = vzalloc(nlm_info.ivst_len);
67 printk("isp_k_nlm_block:ivst kmalloc error\n");
72 buff2 = vzalloc(nlm_info.nlm_len);
74 printk("isp_k_nlm_block:nlm kmalloc error\n");
81 vst_addr = (void*)(((unsigned long)nlm_info.vst_addr[1] << 32) | nlm_info.vst_addr[0]);
83 vst_addr = (void*)(nlm_info.vst_addr[0]);
85 ret = copy_from_user((void *)buff0, vst_addr, nlm_info.vst_len);
87 printk("isp_k_nlm_block: vst copy error, ret=0x%x\n", (uint32_t)ret);
95 ivst_addr = (void*)(((unsigned long)nlm_info.ivst_addr[1] << 32) | nlm_info.ivst_addr[0]);
97 ivst_addr = (void*)(nlm_info.ivst_addr[0]);
99 ret = copy_from_user((void *)buff1, ivst_addr, nlm_info.ivst_len);
101 printk("isp_k_nlm_block: ivst copy error, ret=0x%x\n", (uint32_t)ret);
109 nlm_addr = (void*)(((unsigned long)nlm_info.nlm_addr[1] << 32) | nlm_info.nlm_addr[0]);
111 nlm_addr = (void*)(nlm_info.nlm_addr[0]);
113 ret = copy_from_user((void *)buff2, nlm_addr, nlm_info.nlm_len);
115 printk("isp_k_nlm_block: nlm copy error, ret=0x%x\n", (uint32_t)ret);
122 REG_MWR(ISP_NLM_PARA, BIT_1, nlm_info.imp_opt_bypass << 1);
123 REG_MWR(ISP_NLM_PARA, BIT_2, nlm_info.flat_opt_bypass << 2);
124 REG_MWR(ISP_NLM_PARA, BIT_3, nlm_info.flat_thr_bypass << 3);
125 REG_MWR(ISP_NLM_PARA, BIT_4, nlm_info.direction_mode_bypass << 4);
127 REG_MWR(ISP_NLM_PARA, BIT_31, nlm_info.buf_sel);
129 for (i = 0; i < 5; i++) {
130 val = (nlm_info.thresh[i] & 0x3FFF) | ((nlm_info.cnt[i] & 0x1F) << 16)
131 | ((nlm_info.strength[i] & 0xFF) << 24);
132 REG_WR(ISP_NLM_FLAT_PARA_0 + i * 4, val);
135 REG_MWR(ISP_NLM_STERNGTH, 0x7F, nlm_info.streng_th);
137 REG_MWR(ISP_NLM_STERNGTH, 0xFF00, nlm_info.texture_dec << 8);
139 //REG_WR(ISP_NLM_IS_FLAT, nlm_info.is_flat & 0xFF);
141 REG_MWR(ISP_NLM_ADD_BACK, 0x7F, nlm_info.addback);
143 REG_MWR(ISP_NLM_ADD_BACK, BIT_7, nlm_info.opt_mode << 7);
145 REG_MWR(ISP_NLM_DIRECTION_0, BIT_17 | BIT_16, nlm_info.dist_mode << 16);
147 val = ((nlm_info.w_shift[0] & 0x3) << 4) | ((nlm_info.w_shift[1] & 0x3) << 6) | ((nlm_info.w_shift[2] & 0x3) << 8);
148 REG_MWR(ISP_NLM_DIRECTION_0, 0x3F0, val);
150 REG_MWR(ISP_NLM_DIRECTION_0, 0x7, nlm_info.cnt_th);
152 REG_MWR(ISP_NLM_DIRECTION_1, 0xFFFF0000, nlm_info.tdist_min_th << 16);
154 REG_MWR(ISP_NLM_DIRECTION_1, 0xFFFF, nlm_info.diff_th);
156 for (i = 0; i < 24; i++) {
157 val = (nlm_info.lut_w[i*3+0] & 0x3FF) | ((nlm_info.lut_w[i*3+1] & 0x3FF) << 10)
158 | ((nlm_info.lut_w[i*3+2] & 0x3FF) << 20);
159 REG_WR(ISP_NLM_LUT_W_0 + i * 4, val);
162 if(nlm_info.buf_sel) {
163 buf_addr = ISP_NLM_BUF1_CH0;
164 memcpy((void *)buf_addr, buff2, ISP_VST_IVST_NUM * sizeof(uint32_t));
166 buf_addr = ISP_NLM_BUF0_CH0;
167 memcpy((void *)buf_addr, buff2, ISP_VST_IVST_NUM * sizeof(uint32_t));
170 if (nlm_info.buf_sel ) {
171 buf_addr = ISP_VST_BUF1_CH0;
172 memcpy((void *)buf_addr, buff0, ISP_VST_IVST_NUM * sizeof(uint32_t));
174 buf_addr = ISP_VST_BUF0_CH0;
175 memcpy((void *)buf_addr, buff0, ISP_VST_IVST_NUM * sizeof(uint32_t));
178 if (nlm_info.buf_sel ) {
179 buf_addr = ISP_IVST_BUF1_CH0;
180 memcpy((void *)buf_addr, buff1, ISP_VST_IVST_NUM * sizeof(uint32_t));
182 buf_addr = ISP_IVST_BUF0_CH0;
183 memcpy((void *)buf_addr, buff1, ISP_VST_IVST_NUM * sizeof(uint32_t));
186 /*vst ivst follow nlm*/
187 REG_MWR(ISP_VST_PARA, BIT_1, nlm_info.buf_sel << 1);
188 REG_MWR(ISP_IVST_PARA, BIT_1, nlm_info.buf_sel << 1);
190 REG_MWR(ISP_NLM_PARA, BIT_0, nlm_info.bypass);
191 REG_MWR(ISP_IVST_PARA, BIT_0, nlm_info.bypass);
192 REG_MWR(ISP_VST_PARA, BIT_0, nlm_info.bypass);
200 static int32_t isp_k_ivst_block(struct isp_io_param *param)
204 struct isp_dev_ivst_info_v1 ivst_info;
206 ret = copy_from_user((void *)&ivst_info, param->property_param, sizeof(ivst_info));
208 printk("isp_k_ivst_block: copy error, ret=0x%x\n", (uint32_t)ret);
212 REG_MWR(ISP_IVST_PARA, BIT_0, ivst_info.bypass);
214 REG_MWR(ISP_IVST_PARA, BIT_1, ivst_info.buf_sel << 1);
220 int32_t isp_k_cfg_nlm(struct isp_io_param *param)
225 printk("isp_k_cfg_nlm: param is null error.\n");
229 if (NULL == param->property_param) {
230 printk("isp_k_cfg_nlm: property_param is null error.\n");
234 switch(param->property) {
235 case ISP_PRO_VST_BLOCK:
236 ret = isp_k_vst_block(param);
238 case ISP_PRO_NLM_BLOCK:
239 ret = isp_k_nlm_block(param);;
241 case ISP_PRO_IVST_BLOCK:
242 ret = isp_k_ivst_block(param);;
245 printk("isp_k_cfg_nlm: fail cmd id:%d, not supported.\n", param->property);