summaryrefslogtreecommitdiff
path: root/drivers/media/sprd_isp/isp2.0/tshark2/src/isp_k_y_gamma.c
blob: cc4857403134cc3e340c2297c1fea8904714f615 (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
/*
 * 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"


#define ISP_YUV_YGAMMA_BUF0      0
#define ISP_YUV_YGAMMA_BUF1      1

static int32_t isp_k_pingpang_yuv_ygamma(struct coordinate_xy *nodes,
		struct isp_k_private *isp_private)
{
	int32_t ret = 0;
	uint32_t i = 0, j = 0;
	unsigned long ybuf_addr = 0;
	struct coordinate_xy *p_nodes = NULL;

	if (!nodes) {
		ret = -1;
		printk("isp_k_pingpang_yuv_ygamma: node is null error .\n");
		return ret;
	}
	p_nodes = nodes;

	if (ISP_YUV_YGAMMA_BUF0 == isp_private->yuv_ygamma_buf_id) {
		ybuf_addr = ISP_YGAMMA_BUF1_CH0;
		isp_private->yuv_ygamma_buf_id = ISP_YUV_YGAMMA_BUF1;
	} else {
		ybuf_addr = ISP_YGAMMA_BUF0_CH0;
		isp_private->yuv_ygamma_buf_id = ISP_YUV_YGAMMA_BUF0;
	}

	for (i = 0, j = 0; i < ISP_PINGPANG_YUV_YGAMMA_NUM; i++, j += 4) {
		REG_WR(ybuf_addr + j, p_nodes[i].node_y & 0xff);
	}

	if (isp_private->yuv_ygamma_buf_id) {
		REG_OWR(ISP_YGAMMA_PARAM, BIT_1);
	} else {
		REG_MWR(ISP_YGAMMA_PARAM, BIT_1, 0);
	}

	return ret;
}

static int32_t isp_k_ygamma_block(struct isp_io_param *param,
	struct isp_k_private *isp_private)
{
	int32_t ret = 0;
	uint32_t bypass;
	struct isp_dev_ygamma_info *ygamma_info = (struct isp_dev_ygamma_info *)param->property_param;
	struct coordinate_xy *nodes = NULL;

	nodes = (struct coordinate_xy *)isp_private->yuv_ygamma_buf_addr;
	if (!nodes) {
		ret = -1;
		printk("isp_k_ygamma_block: alloc memory error.\n");
		return -1;
	}

	ret = copy_from_user((void *)&bypass, (void *)&ygamma_info->bypass, sizeof(uint32_t));
	if (0 != ret) {
		printk("isp_k_ygamma_block: copy bypass error, ret=0x%x\n", (uint32_t)ret);
		return -1;
	}
	ret = copy_from_user((void *)nodes, (void *)ygamma_info->nodes, ISP_YUV_YGAMMA_BUF_SIZE);
	if (0 != ret) {
		printk("isp_k_ygamma_block: copy nodes error, ret=0x%x\n", (uint32_t)ret);
		return -1;
	}

	ret = isp_k_pingpang_yuv_ygamma(nodes, isp_private);
	if (0 != ret) {
		printk("isp_k_ygamma_block: pingpang error, ret=0x%x\n", (uint32_t)ret);
		return -1;
	}
	REG_MWR(ISP_YGAMMA_PARAM, BIT_0, bypass);

	return ret;
}

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

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

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

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

	return ret;
}