summaryrefslogtreecommitdiff
path: root/drivers/media/sprd_isp/isp2.0/tshark2/src/isp_k_awb.c
blob: 0c33d35549e072b2886bd42ce5b474b513e3e136 (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
/*
 * 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"
#include "isp_drv.h"

static int32_t isp_k_awb_block(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t val = 0;
	uint32_t i = 0;
	struct isp_dev_awb_info_v1 awb_info;

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

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

	//printk("isp_k_awb_block: %d  %d  %d  %d \n",awb_info.slice_size.width,awb_info.slice_size.height,awb_info.block_size.width,awb_info.block_size.height);
	//printk("isp_k_awb_block: gain r=%d  gr=%d  b=%d \n",awb_info.gain.r,awb_info.gain.gr,awb_info.gain.b);
	//printk("isp_k_awb_block: offset r=%d  gr=%d  b=%d  \n",awb_info.gain_offset.r,awb_info.gain_offset.gr,awb_info.gain_offset.b);
	/*AWBM*/

	REG_MWR(ISP_AWBM_PARAM, BIT_0, awb_info.awbm_bypass);

	REG_MWR(ISP_AWBM_PARAM, BIT_1, awb_info.mode << 1);

	val = (awb_info.skip_num & 0x0F) << 2;
	REG_MWR(ISP_AWBM_PARAM, (BIT_5 | BIT_4 | BIT_3 | BIT_2), val);

	val = ((awb_info.block_offset.y & 0xFFFF) << 16) | (awb_info.block_offset.x & 0xFFFF);
	REG_WR(ISP_AWBM_BLOCK_OFFSET, val);

	val = ((awb_info.block_size.height & 0x1FF) << 9) | (awb_info.block_size.width & 0x1FF);
	REG_MWR(ISP_AWBM_BLOCK_SIZE, 0x1FFFF, val);

	val = (awb_info.shift & 0x1F) << 18;
	REG_MWR(ISP_AWBM_BLOCK_SIZE, (0x1F << 18), val);

	REG_MWR(ISP_AWBM_PARAM, BIT_8, awb_info.thr_bypass << 8);

	for (i = 0; i < 5; i++) {
		val = ((awb_info.rect_pos.start_x[i] & 0x3FF) << 16) | (awb_info.rect_pos.start_y[i] & 0x3FF);
		REG_WR(ISP_AWBM_WR_0_S + i * 8, val);
		val = ((awb_info.rect_pos.end_x[i] & 0x3FF) << 16) | (awb_info.rect_pos.end_y[i] & 0x3FF);
		REG_WR(ISP_AWBM_WR_0_E + i * 8, val);
	}

	for (i = 0; i < 5; i++) {
		val = ((awb_info.circle_pos.x[i] & 0x3FF) << 18) | ((awb_info.circle_pos.y[i] & 0x3FF) << 8) | (awb_info.circle_pos.r[i] & 0xFF);
		REG_WR(ISP_AWBM_NW_0_XYR + i * 4, val);
	}

	for (i = 0; i < 5; i++) {
		val = ((awb_info.clctor_pos.start_x[i] & 0x3FF) << 16) | (awb_info.clctor_pos.start_y[i] & 0x3FF);
		REG_WR(ISP_AWBM_CLCTOR_0_S + i * 8, val);
		val = ((awb_info.clctor_pos.end_x[i] & 0x3FF) << 16) | (awb_info.clctor_pos.end_y[i] & 0x3FF);
		REG_WR(ISP_AWBM_CLCTOR_0_E + i * 8, val);
	}

	val = ((awb_info.thr.g_low & 0x3FF) << 20) | ((awb_info.thr.r_high & 0x3FF) << 10) | (awb_info.thr.r_low & 0x3FF);
	REG_WR(ISP_AWBM_THR_VALUE1, val);
	val = ((awb_info.thr.b_high & 0x3FF) << 20) | ((awb_info.thr.b_low & 0x3FF) << 10) | (awb_info.thr.g_high & 0x3FF);
	REG_WR(ISP_AWBM_THR_VALUE2, val);

//	val = ((awb_info.slice_size.height & 0xFFFF) << 16) | (awb_info.slice_size.width & 0xFFFF);
//	REG_WR(ISP_AEM_SLICE_SIZE, val);

	REG_MWR(ISP_AWBM_PARAM, BIT_6, awb_info.skip_num_clear << 6);

	REG_WR(ISP_AWBM_MEM_ADDR, awb_info.mem_addr);

	/*AWBC*/

	REG_MWR(ISP_AWBC_PARAM, BIT_0, awb_info.awbc_bypass);

	REG_MWR(ISP_AWBC_PARAM, BIT_1, awb_info.alpha_bypass << 1);

	val = (awb_info.alpha_value & 0x3FF) << 4;
	REG_MWR(ISP_AWBC_PARAM, 0x3FF0, val);

	REG_MWR(ISP_AWBC_PARAM, BIT_3, awb_info.buf_sel << 3);

	val = ((awb_info.gain.b & 0x3FFF) << 16) | (awb_info.gain.r & 0x3FFF);
	REG_WR(ISP_AWBC_GAIN0, val);
	val = ((awb_info.gain.gb & 0x3FFF) << 16) | (awb_info.gain.gr & 0x3FFF);
	REG_WR(ISP_AWBC_GAIN1, val);

	val = ((awb_info.thrd.b & 0x3FF) << 20) | ((awb_info.thrd.g & 0x3FF) << 10) | (awb_info.thrd.r & 0x3FF);
	REG_WR(ISP_AWBC_THRD, val);

	val = ((awb_info.gain_offset.b & 0xFFFF) << 16) | (awb_info.gain_offset.r & 0xFFFF);
	REG_WR(ISP_AWBC_OFFSET0, val);
	val = ((awb_info.gain_offset.gb & 0xFFFF) << 16) | (awb_info.gain_offset.gr & 0xFFFF);
	REG_WR(ISP_AWBC_OFFSET1, val);

	val = ((awb_info.gain_buff.b & 0x3FFF) << 16) | (awb_info.gain_buff.r & 0x3FFF);
	REG_WR(ISP_AWBC_GAIN0_BUF, val);
	val = ((awb_info.gain_buff.gb & 0x3FFF) << 16) | (awb_info.gain_buff.gr & 0x3FFF);
	REG_WR(ISP_AWBC_GAIN1_BUF, val);

	val = ((awb_info.gain_offset_buff.b & 0xFFFF) << 16) | (awb_info.gain_offset_buff.r & 0xFFFF);
	REG_WR(ISP_AWBC_OFFSET0_BUF, val);
	val = ((awb_info.gain_offset_buff.gb & 0xFFFF) << 16) | (awb_info.gain_offset_buff.gr & 0xFFFF);
	REG_WR(ISP_AWBC_OFFSET1_BUF, val);

	return ret;
}

static int32_t isp_k_raw_awb_statistics(struct isp_io_param *param,
	struct isp_k_private *isp_private)
{
	int32_t ret = 0, i = 0;
	unsigned long addr = 0;
	struct isp_raw_awbm_statistics *awbm_statistics = NULL;

	awbm_statistics = (struct isp_raw_awbm_statistics *)isp_private->raw_awbm_buf_addr;
	if (!awbm_statistics) {
		ret = -1;
		printk("isp_k_raw_awb_statistics: alloc memory error.\n");
		return -1;
	}

	addr = ISP_RAW_AWBM_OUTPUT;

	for (i = 0x00; i < ISP_RAW_AWBM_ITEM; i++) {
		(awbm_statistics + i)->num4 = REG_RD(addr) >> 16;
		(awbm_statistics + i)->num_t = REG_RD(addr) & 0xffff;
		(awbm_statistics + i)->num2 = REG_RD(addr + 4) >> 16;
		(awbm_statistics + i)->num3 = REG_RD(addr + 4) & 0xffff;
		(awbm_statistics + i)->num0 = REG_RD(addr + 8) >> 16;
		(awbm_statistics + i)->num1 = REG_RD(addr + 8) & 0xffff;
		(awbm_statistics + i)->block_b = REG_RD(addr + 12);
		(awbm_statistics + i)->block_g = REG_RD(addr + 16);
		(awbm_statistics + i)->block_r = REG_RD(addr + 20);
		addr += 32;
	}

	ret = copy_to_user(param->property_param, (void*)awbm_statistics, sizeof(struct isp_raw_awbm_statistics) * ISP_RAW_AWBM_ITEM);
	if (0 != ret) {
		ret = -1;
		printk("isp_k_raw_awb_statistics: copy error, ret=0x%x\n", (uint32_t)ret);
	}

	return ret;
}

int32_t isp_k_cfg_awb(struct isp_io_param *param,
	struct isp_k_private *isp_private)
{
	int32_t ret = 0;

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

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

	switch(param->property) {
	case ISP_PRO_AWB_BLOCK:
		ret = isp_k_awb_block(param);
		break;
	case ISP_PRO_AWBM_STATISTICS:
		ret = isp_k_raw_awb_statistics(param, isp_private);
		break;
	default:
		printk("isp_k_cfg_awb: fail cmd id:%d, not supported.\n", param->property);
		break;
	}

	return ret;
}