summaryrefslogtreecommitdiff
path: root/drivers/media/sprd_isp/isp2.0/pike/src/isp_k_nlm.c
blob: ee4d40762bf5339a0bb160b7f8b580d7efc611bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * Copyright (C) 2012 Spreadtrum Communications Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/uaccess.h>
#include <linux/sprd_mm.h>
#include <video/sprd_isp.h>
#include <linux/vmalloc.h>
#include "isp_reg.h"

static int32_t isp_k_vst_block(struct isp_io_param *param)
{
	int32_t ret = 0;
	struct isp_dev_vst_info_v1 vst_info;

	ret = copy_from_user((void *)&vst_info, param->property_param, sizeof(vst_info));
	if (0 != ret) {
		printk("isp_k_vst_block: copy error, ret=0x%x\n", (uint32_t)ret);
		return -1;
	}

	REG_MWR(ISP_VST_PARA, BIT_0, vst_info.bypass);

	REG_MWR(ISP_VST_PARA, BIT_1, vst_info.buf_sel << 1);

	return ret;

}

static int32_t isp_k_nlm_block(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t val = 0;
	uint32_t i = 0;
	struct isp_dev_nlm_info_v2 nlm_info;
	uint32_t *buff0 = NULL;
	uint32_t *buff1 = NULL;
	unsigned long buf_addr = 0;
	void *vst_addr = NULL;
	void *ivst_addr = NULL;
	void *nlm_addr = NULL;

	ret = copy_from_user((void *)&nlm_info, param->property_param, sizeof(nlm_info));
	if (0 != ret) {
		printk("isp_k_nlm_block: copy error, ret=0x%x\n", (uint32_t)ret);
		return -1;
	}

	buff0 = vzalloc(nlm_info.vst_len);
	if (NULL == buff0) {
		printk("isp_k_nlm_block:vst kmalloc error\n");
		return -1;
	}

	buff1 = vzalloc(nlm_info.ivst_len);
	if (NULL == buff1) {
		printk("isp_k_nlm_block:ivst kmalloc error\n");
		vfree(buff0);
		return -1;
	}

#ifdef CONFIG_64BIT
	vst_addr = (void*)(((unsigned long)nlm_info.vst_addr[1] << 32) | nlm_info.vst_addr[0]);
#else
	vst_addr = (void*)(nlm_info.vst_addr[0]);
#endif
	ret = copy_from_user((void *)buff0, vst_addr, nlm_info.vst_len);
	if (0 != ret) {
		printk("isp_k_nlm_block: vst copy error, ret=0x%x\n", (uint32_t)ret);
		vfree(buff0);
		vfree(buff1);
		return -1;
	}

#ifdef CONFIG_64BIT
	ivst_addr = (void*)(((unsigned long)nlm_info.ivst_addr[1] << 32) | nlm_info.ivst_addr[0]);
#else
	ivst_addr = (void*)(nlm_info.ivst_addr[0]);
#endif
	ret = copy_from_user((void *)buff1, ivst_addr, nlm_info.ivst_len);
	if (0 != ret) {
		printk("isp_k_nlm_block: ivst copy error, ret=0x%x\n", (uint32_t)ret);
		vfree(buff0);
		vfree(buff1);
		return -1;
	}

	REG_MWR(ISP_NLM_PARA, BIT_1, nlm_info.imp_opt_bypass << 1);
	REG_MWR(ISP_NLM_PARA, BIT_2, nlm_info.flat_opt_bypass << 2);

	for (i = 0; i < 5; i++) {
		val = (nlm_info.thresh[i] & 0x3FFF) | ((nlm_info.cnt[i] & 0x1F) << 16)
			| ((nlm_info.strength[i] & 0x7F) << 24);
		REG_WR(ISP_NLM_FLAT_PARA_0 + i * 4, val);
	}

	REG_MWR(ISP_NLM_STERNGTH, 0x7F, nlm_info.streng_th);

	REG_MWR(ISP_NLM_STERNGTH, 0x7F80, nlm_info.texture_dec << 7);

	REG_WR(ISP_NLM_IS_FLAT, nlm_info.is_flat & 0xFF);

	REG_MWR(ISP_NLM_ADD_BACK, 0x7F, nlm_info.addback);


	for (i = 0; i < 24; i++) {
		val = (nlm_info.lut_w[i*3+0] & 0x3FF) | ((nlm_info.lut_w[i*3+1] & 0x3FF) << 10)
			| ((nlm_info.lut_w[i*3+2] & 0x3FF) << 20);
		REG_WR(ISP_NLM_LUT_W_0 + i * 4, val);
	}


	if (nlm_info.buf_sel ) {
		//buf_addr = ISP_VST_BUF1_CH0;
		//memcpy((void *)buf_addr, buff0, ISP_VST_IVST_NUM * sizeof(uint32_t));
	} else {
		buf_addr = ISP_VST_BUF0_CH0;
		memcpy((void *)buf_addr, buff0, ISP_VST_IVST_NUM * sizeof(uint32_t));
	}

	if (nlm_info.buf_sel ) {
		//buf_addr = ISP_IVST_BUF1_CH0;
		//memcpy((void *)buf_addr, buff1, ISP_VST_IVST_NUM * sizeof(uint32_t));
	} else {
		buf_addr = ISP_IVST_BUF0_CH0;
		memcpy((void *)buf_addr, buff1, ISP_VST_IVST_NUM * sizeof(uint32_t));
	}

	/*vst ivst follow nlm*/
	REG_MWR(ISP_VST_PARA, BIT_1, nlm_info.buf_sel << 1);
	REG_MWR(ISP_IVST_PARA, BIT_1, nlm_info.buf_sel << 1);

	REG_MWR(ISP_NLM_PARA, BIT_0, nlm_info.bypass);
	REG_MWR(ISP_IVST_PARA, BIT_0, nlm_info.bypass);
	REG_MWR(ISP_VST_PARA, BIT_0, nlm_info.bypass);

	vfree(buff0);
	vfree(buff1);
	return ret;

}

static int32_t isp_k_ivst_block(struct isp_io_param *param)
{
	int32_t ret = 0;

	struct isp_dev_ivst_info_v1 ivst_info;

	ret = copy_from_user((void *)&ivst_info, param->property_param, sizeof(ivst_info));
	if (0 != ret) {
		printk("isp_k_ivst_block: copy error, ret=0x%x\n", (uint32_t)ret);
		return -1;
	}

	REG_MWR(ISP_IVST_PARA, BIT_0, ivst_info.bypass);

	REG_MWR(ISP_IVST_PARA, BIT_1, ivst_info.buf_sel << 1);

	return ret;

}

int32_t isp_k_cfg_nlm(struct isp_io_param *param)
{
	int32_t ret = 0;

	if (!param) {
		printk("isp_k_cfg_nlm: param is null error.\n");
		return -1;
	}

	if (NULL == param->property_param) {
		printk("isp_k_cfg_nlm: property_param is null error.\n");
		return -1;
	}

	switch(param->property) {
	case ISP_PRO_VST_BLOCK:
		ret = isp_k_vst_block(param);
		break;
	case ISP_PRO_NLM_BLOCK:
		ret = isp_k_nlm_block(param);
		break;
	case ISP_PRO_IVST_BLOCK:
		ret = isp_k_ivst_block(param);
		break;
	default:
		printk("isp_k_cfg_nlm: fail cmd id:%d, not supported.\n", param->property);
		break;
	}

	return ret;
}