summaryrefslogtreecommitdiff
path: root/drivers/media/sprd_isp/isp2.0/pike/src/isp_k_bpc.c
blob: 29248946c3d7f44a1ae67223ddccc1cc48cfb7ec (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
/*
 * 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_bpc_block(struct isp_io_param *param)
{
	int32_t ret = 0;
	uint32_t val = 0;
	uint32_t i = 0;
	struct isp_dev_bpc_info_v1 bpc_info;

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

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

	REG_MWR(ISP_BPC_PARAM, BIT_0, bpc_info.bypass);

	REG_MWR(ISP_BPC_PARAM, BIT_1, bpc_info.pvd_bypass << 1);

	REG_MWR(ISP_BPC_PARAM, BIT_4 | BIT_5, bpc_info.bpc_mode << 4);

	REG_MWR(ISP_BPC_PARAM, BIT_10 | BIT_9 | BIT_8, bpc_info.mask_mode << 8);

	val = ((bpc_info.kmax & 0x7) << 20) | ((bpc_info.kmin & 0x7) << 16);
	REG_MWR(ISP_BPC_PARAM, 0x770000, val);

	REG_MWR(ISP_BPC_NEW_OLD_SEL, BIT_0, bpc_info.new_old_sel);

	REG_MWR(ISP_BPC_NEW_OLD_SEL, BIT_1, bpc_info.map_done_sel << 1);

	val = ((bpc_info.safe_factor & 0x1F) << 4) | (bpc_info.flat_factor & 0x7);
	REG_WR(ISP_BPC_FACTOR, val);

	val = ((bpc_info.dead_coeff & 0x7) << 4) | (bpc_info.spike_coeff & 0x7);
	REG_WR(ISP_BPC_COEFF, val);

	for (i = 0; i < 8; i++) {
		val = ((bpc_info.lut_level[i] & 0x3FF) << 20) | ((bpc_info.slope_k[i] & 0x3FF) << 10) | (bpc_info.intercept_b[i] & 0x3FF);
		REG_WR(ISP_BPC_LUTWORD0 + i * 4, val);
	}

	REG_MWR(ISP_BPC_CFG, BIT_10 | BIT_9 | BIT_8, bpc_info.delta << 8);

	REG_MWR(ISP_BPC_CFG, BIT_7, bpc_info.bpc_map_fifo_clr << 7);

	REG_MWR(ISP_BPC_CFG, BIT_6 | BIT_5 | BIT_4, bpc_info.ktimes << 4);

	REG_MWR(ISP_BPC_CFG, 0x7, bpc_info.cntr_threshold);

	REG_MWR(ISP_BPC_CFG, BIT_3, bpc_info.bad_map_hw_fifo_clr_en << 3);

	REG_WR(ISP_BPC_MAP_ADDR, bpc_info.bpc_map_addr_new);

	REG_MWR(ISP_BPC_CFG, 0xFFFF0000, bpc_info.bad_pixel_num << 16);

	return ret;
}

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

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

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

	switch(param->property) {
	case ISP_PRO_BPC_BLOCK:
		ret = isp_k_bpc_block(param);
		break;
	default:
		printk("isp_k_cfg_bpc: fail cmd id:%d, not supported.\n", param->property);
		break;
	}

	return ret;
}