summaryrefslogtreecommitdiff
path: root/drivers/media/sprd_isp/isp2.0/pike/src/isp_k_common.c
blob: 336f173a9147e2788962fd4e5724e06ba2f8fa2d (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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/*
 * 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 "isp_reg.h"

static int32_t isp_k_common_block(struct isp_io_param *param)
{
	int32_t ret = 0;
	struct isp_dev_common_info_v2 common_info;

	memset(&common_info, 0x00, sizeof(common_info));

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

	REG_MWR(ISP_COMMON_CTRL_CH0, 3, common_info.fetch_sel_0);
	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 4, common_info.sizer_sel_0  << 4);
	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 16, common_info.store_sel_0  << 16);
	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 2, common_info.fetch_sel_1);
	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 6, common_info.sizer_sel_1);
	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 18, common_info.store_sel_1);
	//REG_MWR(ISP_COMMON_CTRL_CH1, 3, common_info.fetch_sel_1);
	//REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 4, common_info.sizer_sel_1  << 4);
	//REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 16, common_info.store_sel_1  << 16);
	REG_MWR(ISP_COMMON_SPACE_SEL, 3 , common_info.fetch_color_format) ;
	REG_MWR(ISP_COMMON_SPACE_SEL, 3  << 2, common_info.store_color_format << 2) ;
	//REG_MWR(ISP_COMMON_CTRL_AWBM, BIT_0 , common_info.awbm_pos) ;
	//REG_MWR(ISP_COMMON_3A_CTRL0, 3, common_info.y_afm_pos_0);
	//REG_MWR(ISP_COMMON_3A_CTRL0, 3 << 4, common_info.y_aem_pos_0  << 4);
	//REG_MWR(ISP_COMMON_3A_CTRL1, 3, common_info.y_afm_pos_1);
	//REG_MWR(ISP_COMMON_3A_CTRL1, 3 << 4, common_info.y_aem_pos_1  << 4);

	REG_MWR(ISP_COMMON_LBUF_OFFSET, 0xFFFF, 0x460);
	//REG_WR(ISP_COMMON_LBUF_OFFSET0, ((common_info.lbuf_off.cfae_lbuf_offset & 0xFFFF) << 16 ) | (common_info.lbuf_off.comm_lbuf_offset & 0xFFFF));
	//REG_WR(ISP_COMMON_LBUF_OFFSET1, ((common_info.lbuf_off.ydly_lbuf_offset& 0xFFFF) << 16 ) | (common_info.lbuf_off.awbm_lbuf_offset & 0xFFFF));

	return ret;
}

static int32_t isp_k_common_version(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t version = 0;

	version = REG_RD(ISP_COMMON_VERSION);

	ret = copy_to_user(param->property_param, (void*)&version, sizeof(version));
	if (0 != ret) {
		ret = -1;
		printk("isp_k_common_version: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
	}

	return ret;
}

static int32_t isp_k_common_status0(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t status = 0;

	status = REG_RD(ISP_COMMON_STATUS0);

	ret = copy_to_user(param->property_param, (void*)&status, sizeof(status));
	if (0 != ret) {
		ret = -1;
		printk("isp_k_common_status0: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
	}

	return ret;
}

static int32_t isp_k_common_status1(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t status = 0;

	status = REG_RD(ISP_COMMON_STATUS1);

	ret = copy_to_user(param->property_param, (void*)&status, sizeof(status));
	if (0 != ret) {
		ret = -1;
		printk("isp_k_common_status1: copy_to_user error, ret = 0x%x\n", (uint32_t)ret);
	}

	return ret;
}

static int32_t isp_k_common_channel0_fetch_sel(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t fetch_sel = 0;

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

	REG_MWR(ISP_COMMON_CTRL_CH0, 3, fetch_sel);

	return ret;
}

static int32_t isp_k_common_channel0_sizer_sel(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t sizer_sel = 0;

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

	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 4, sizer_sel  << 4);

	return ret;
}

static int32_t isp_k_common_channel0_store_sel(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t store_sel = 0;

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

	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 16, store_sel  << 16);

	return ret;
}

static int32_t isp_k_common_channel1_fetch_sel(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t fetch_sel = 0;

	ret = copy_from_user((void *)&fetch_sel, param->property_param, sizeof(fetch_sel));
	if (0 != ret) {
		printk("isp_k_channel1_fetch_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
		return -1;
	}
	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 2, fetch_sel << 2);

//	REG_MWR(ISP_COMMON_CTRL_CH1, 3, fetch_sel);

	return ret;
}

static int32_t isp_k_common_channel1_sizer_sel(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t sizer_sel = 0;

	ret = copy_from_user((void *)&sizer_sel, param->property_param, sizeof(sizer_sel));
	if (0 != ret) {
		printk("isp_k_common_channel1_sizer_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
		return -1;
	}
	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 6, sizer_sel << 6);

	//REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 4, sizer_sel  << 4);

	return ret;
}

static int32_t isp_k_common_channel1_store_sel(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t store_sel = 0;

	ret = copy_from_user((void *)&store_sel, param->property_param, sizeof(store_sel));
	if (0 != ret) {
		printk("isp_k_common_channel1_store_sel: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
		return -1;
	}
	REG_MWR(ISP_COMMON_CTRL_CH0, 3 << 18, store_sel << 18);

//	REG_MWR(ISP_COMMON_CTRL_CH1, 3 << 16, store_sel  << 16);

	return ret;
}

static int32_t isp_k_common_fetch_color_space_sel(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t color_space = 0;

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

	REG_MWR(ISP_COMMON_SPACE_SEL, 3 , color_space) ;

	return ret;
}

static int32_t isp_k_common_store_color_space_sel(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t color_space = 0;

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

	REG_MWR(ISP_COMMON_SPACE_SEL, 3  << 2, color_space << 2) ;

	return ret;
}

static int32_t isp_k_common_awbm_pos_sel(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t awbm_pos = 0;

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

	//REG_MWR(ISP_COMMON_CTRL_AWBM, BIT_0 , awbm_pos) ;

	return ret;
}

static int32_t isp_k_common_channel0_y_afm_pos(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t position = 0;

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

//	REG_MWR(ISP_COMMON_3A_CTRL0, 3, position);

	return ret;
}

static int32_t isp_k_common_channel0_y_aem_pos(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t position = 0;

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

//	REG_MWR(ISP_COMMON_3A_CTRL0, 3 << 4, position  << 4);

	return ret;
}

static int32_t isp_k_common_channel1_y_afm_pos(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t position = 0;

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

//	REG_MWR(ISP_COMMON_3A_CTRL1, 3, position);

	return ret;
}

static int32_t isp_k_common_channel1_y_aem_pos(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t position = 0;

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

//	REG_MWR(ISP_COMMON_3A_CTRL1, 3 << 4, position  << 4);

	return ret;
}

static int32_t isp_k_common_lbuf_offset(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t lbuf_off;

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


	REG_MWR(ISP_COMMON_LBUF_OFFSET, 0xFFFF, lbuf_off);

//	REG_WR(ISP_COMMON_LBUF_OFFSET0, ((lbuf_off.cfae_lbuf_offset & 0xFFFF) << 16 ) | (lbuf_off.comm_lbuf_offset & 0xFFFF));
//	REG_WR(ISP_COMMON_LBUF_OFFSET1, ((lbuf_off.ydly_lbuf_offset& 0xFFFF) << 16 ) | (lbuf_off.awbm_lbuf_offset & 0xFFFF));

	return ret;
}

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

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

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

	switch (param->property) {
	case ISP_PRO_COMMON_BLOCK:
		ret = isp_k_common_block(param);
		break;
	case ISP_PRO_COMMON_VERSION:
		ret = isp_k_common_version(param);
		break;
	case ISP_PRO_COMMON_STATUS0:
		ret = isp_k_common_status0(param);
		break;
	case ISP_PRO_COMMON_STATUS1:
		ret = isp_k_common_status1(param);
		break;
	case ISP_PRO_COMMON_CH0_FETCH_SEL:
		ret = isp_k_common_channel0_fetch_sel(param);
		break;
	case ISP_PRO_COMMON_CH0_SIZER_SEL:
		ret = isp_k_common_channel0_sizer_sel(param);
		break;
	case ISP_PRO_COMMON_CH0_STORE_SEL:
		ret = isp_k_common_channel0_store_sel(param);
		break;
	case ISP_PRO_COMMON_CH1_FETCH_SEL:
		ret = isp_k_common_channel1_fetch_sel(param);
		break;
	case ISP_PRO_COMMON_CH1_SIZER_SEL:
		ret = isp_k_common_channel1_sizer_sel(param);
		break;
	case ISP_PRO_COMMON_CH1_STORE_SEL:
		ret = isp_k_common_channel1_store_sel(param);
		break;
	case ISP_PRO_COMMON_FETCH_COLOR_SPACE_SEL:
		ret = isp_k_common_fetch_color_space_sel(param);
		break;
	case ISP_PRO_COMMON_STORE_COLOR_SPACE_SEL:
		ret = isp_k_common_store_color_space_sel(param);
		break;
	case ISP_PRO_COMMON_AWBM_POS_SEL:
		ret = isp_k_common_awbm_pos_sel(param);
		break;
	case ISP_PRO_COMMON_CH0_AEM2_POS:
		ret = isp_k_common_channel0_y_aem_pos(param);
		break;
	case ISP_PRO_COMMON_CH0_Y_AFM_POS:
		ret = isp_k_common_channel0_y_afm_pos(param);
		break;
	case ISP_PRO_COMMON_CH1_AEM2_POS:
		ret = isp_k_common_channel1_y_aem_pos(param);
		break;
	case ISP_PRO_COMMON_CH1_Y_AFM_POS:
		ret = isp_k_common_channel1_y_afm_pos(param);
		break;
	case ISP_PRO_COMMON_LBUF_OFFSET:
		ret = isp_k_common_lbuf_offset(param);
		break;
	default:
		printk("isp_k_cfg_common: fail cmd id:%d, not supported.\n", param->property);
		break;
	}

	return ret;
}