tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / sprd_isp / isp2.0 / tshark2 / src / isp_k_1d_lsc.c
1 /*
2  * Copyright (C) 2012 Spreadtrum Communications Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #include <linux/uaccess.h>
15 #include <linux/sprd_mm.h>
16 #include <video/sprd_isp.h>
17 #include "isp_reg.h"
18
19 static int32_t isp_k_1d_lsc_block(struct isp_io_param *param)
20 {
21         int32_t ret = 0;
22         uint32_t val = 0;
23         struct isp_dev_1d_lsc_info lnc_info;
24
25         ret = copy_from_user((void *)&lnc_info, param->property_param, sizeof(lnc_info));
26         if (0 != ret) {
27                 printk("isp_k_1d_lsc_block: copy error, ret=0x%x\n", (uint32_t)ret);
28                 return -1;
29         }
30
31         REG_MWR(ISP_1D_LNC_PARAM, BIT_0, lnc_info.bypass);
32
33         val = (lnc_info.gain_max_thr & 0x1FFF) << 1;
34         REG_MWR(ISP_1D_LNC_PARAM, 0x3FFE, val);
35
36         val = ((lnc_info.center_r0c0_col_x & 0x1FFF) << 12) | (lnc_info.center_r0c0_row_y & 0xFFF);
37         REG_WR(ISP_1D_LNC_PARAM1, val);
38         val = ((lnc_info.center_r0c1_col_x & 0x1FFF) << 12) | (lnc_info.center_r0c1_row_y & 0xFFF);
39         REG_WR(ISP_1D_LNC_PARAM2, val);
40         val = ((lnc_info.center_r1c0_col_x & 0x1FFF) << 12) | (lnc_info.center_r1c0_row_y & 0xFFF);
41         REG_WR(ISP_1D_LNC_PARAM3, val);
42         val = ((lnc_info.center_r1c1_col_x & 0x1FFF) << 12) | (lnc_info.center_r1c1_row_y & 0xFFF);
43         REG_WR(ISP_1D_LNC_PARAM4, val);
44
45         val = lnc_info.delta_square_r0c0_x & 0x3FFFFFF;
46         REG_WR(ISP_1D_LNC_PARAM5, val);
47         val = lnc_info.delta_square_r0c1_x & 0x3FFFFFF;
48         REG_WR(ISP_1D_LNC_PARAM7, val);
49         val = lnc_info.delta_square_r1c0_x & 0x3FFFFFF;
50         REG_WR(ISP_1D_LNC_PARAM9, val);
51         val = lnc_info.delta_square_r1c1_x & 0x3FFFFFF;
52         REG_WR(ISP_1D_LNC_PARAM11, val);
53         val = lnc_info.delta_square_r0c0_y & 0xFFFFFF;
54         REG_WR(ISP_1D_LNC_PARAM6, val);
55         val = lnc_info.delta_square_r0c1_y & 0xFFFFFF;
56         REG_WR(ISP_1D_LNC_PARAM8, val);
57         val = lnc_info.delta_square_r1c0_y & 0xFFFFFF;
58         REG_WR(ISP_1D_LNC_PARAM10, val);
59         val = lnc_info.delta_square_r1c1_y & 0xFFFFFF;
60         REG_WR(ISP_1D_LNC_PARAM12, val);
61
62         val = ((lnc_info.coef_r0c0_p1 & 0xFFFF) << 11) | (lnc_info.coef_r0c0_p2 & 0x7FF);
63         REG_WR(ISP_1D_LNC_PARAM13, val);
64         val = ((lnc_info.coef_r0c1_p1 & 0xFFFF) << 11) | (lnc_info.coef_r0c1_p2 & 0x7FF);
65         REG_WR(ISP_1D_LNC_PARAM14, val);
66         val = ((lnc_info.coef_r1c0_p1 & 0xFFFF) << 11) | (lnc_info.coef_r1c0_p2 & 0x7FF);
67         REG_WR(ISP_1D_LNC_PARAM15, val);
68         val = ((lnc_info.coef_r1c1_p1 & 0xFFFF) << 11) | (lnc_info.coef_r1c1_p2 & 0x7FF);
69         REG_WR(ISP_1D_LNC_PARAM16, val);
70
71         val = ((lnc_info.start_pos.x & 0x1FFF) << 12) | (lnc_info.start_pos.y & 0xFFF);
72         REG_WR(ISP_1D_LNC_PARAM18, val);
73
74         return ret;
75 }
76
77 static int32_t isp_k_1d_lsc_slice_size(struct isp_io_param *param)
78 {
79         int32_t ret = 0;
80         uint32_t val = 0;
81         struct isp_img_size size;
82
83         ret = copy_from_user((void *)&size, param->property_param, sizeof(struct isp_img_size));
84         if (0 != ret) {
85                 printk("isp_k_1d_lsc_slice_size: read copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
86                 return -1;
87         }
88
89         val = ((size.width & 0x1FFF) << 12) | (size.height & 0xFFF);
90
91         REG_WR(ISP_1D_LNC_PARAM17, val);
92
93         return ret;
94 }
95
96 static int32_t isp_k_1d_lsc_pos(struct isp_io_param *param)
97 {
98         int32_t ret = 0;
99         uint32_t val = 0;
100         struct img_offset pos;
101
102         ret = copy_from_user((void *)&pos, param->property_param, sizeof(struct img_offset));
103         if (0 != ret) {
104                 printk("isp_k_1d_lsc_pos: read copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
105                 return -1;
106         }
107
108         val = ((pos.x & 0x1FFF) << 12) | (pos.y & 0xFFF);
109
110         REG_WR(ISP_1D_LNC_PARAM18, val);
111
112         return ret;
113 }
114
115 int32_t isp_k_cfg_1d_lsc(struct isp_io_param *param)
116 {
117         int32_t ret = 0;
118
119         if (!param) {
120                 printk("isp_k_cfg_1d_lsc: param is null error.\n");
121                 return -1;
122         }
123
124         if (NULL == param->property_param) {
125                 printk("isp_k_cfg_1d_lsc: property_param is null error.\n");
126                 return -1;
127         }
128
129         switch(param->property) {
130         case ISP_PRO_1D_LSC_BLOCK:
131                 ret = isp_k_1d_lsc_block(param);
132                 break;
133         case ISP_PRO_1D_LSC_SLICE_SIZE:
134                 ret = isp_k_1d_lsc_slice_size(param);
135                 break;
136         case ISP_PRO_1D_LSC_POS:
137                 ret = isp_k_1d_lsc_pos(param);
138                 break;
139         default:
140                 printk("isp_k_cfg_1d_lsc: fail cmd id:%d, not supported.\n", param->property);
141                 break;
142         }
143
144         return ret;
145 }
146