tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / sprd_isp / isp2.0 / tshark2 / src / isp_k_pwd.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_pwd_block(struct isp_io_param *param)
20 {
21         int32_t ret = 0;
22         uint32_t val = 0;
23         struct isp_dev_pre_wavelet_info_v1 pwd_info;
24
25         memset(&pwd_info, 0x00, sizeof(pwd_info));
26
27         ret = copy_from_user((void *)&pwd_info, param->property_param, sizeof(pwd_info));
28         if (0 != ret) {
29                 printk("isp_k_pwd_block: copy error, ret=0x%x\n", (uint32_t)ret);
30                 return -1;
31         }
32
33         val = ((pwd_info.gain_thrs0 & 0x7FF) << 6) | ((pwd_info.gain_thrs1 & 0x7FF) << 17);
34         REG_MWR(ISP_PWD_PARAM, 0x0FFFFFC0, val);
35
36         val = (pwd_info.bitshift0 & 0x7) | ((pwd_info.bitshift1 & 0xFF) << 3);
37         REG_MWR(ISP_PWD_PARAM1, 0x7FF, val);
38
39         val = (pwd_info.offset & 0xFF) << 11;
40         REG_MWR(ISP_PWD_PARAM1, 0x7F800, val);
41
42         val = (pwd_info.nsr_slope & 0x3FF) << 4;
43         REG_MWR(ISP_PWD_PARAM2, 0x3FF0, val);
44
45         val = pwd_info.lum_ratio & 0xF;
46         REG_MWR(ISP_PWD_PARAM2, 0xF, val);
47
48         val = ((pwd_info.center_pos_x & 0x1FFF) << 12) | (pwd_info.center_pos_y & 0xFFF);
49         REG_WR(ISP_PWD_PARAM3, val);
50
51         val = pwd_info.delta_x2 & 0x3FFFFFF;
52         REG_WR(ISP_PWD_PARAM4, val);
53         val = pwd_info.delta_y2 & 0xFFFFFF;
54         REG_WR(ISP_PWD_PARAM5, val);
55
56         val = pwd_info.r2_thr & 0x3FFFFFF;
57         REG_WR(ISP_PWD_PARAM6, val);
58
59         val = ((pwd_info.p_param1 & 0x3FFF) << 12) | (pwd_info.p_param2 & 0xFFF);
60         REG_WR(ISP_PWD_PARAM7, val);
61
62         val = (pwd_info.addback & 0x7F) << 13;
63         REG_MWR(ISP_PWD_PARAM8, 0xFE000, val);
64
65         val = pwd_info.gain_max_thr & 0x1FFF;
66         REG_MWR(ISP_PWD_PARAM8, 0x1FFF, val);
67
68         val = ((pwd_info.pos_x & 0x1FFF) << 12) | (pwd_info.pos_y & 0xFFF);
69         REG_WR(ISP_PWD_PARAM10, val);
70
71         REG_MWR(ISP_PWD_PARAM, BIT_1, pwd_info.radial_bypass << 1);
72         REG_MWR(ISP_PWD_PARAM, BIT_0, pwd_info.bypass);
73
74         return ret;
75 }
76
77 static int32_t isp_k_pwd_slice_size(struct isp_io_param *param)
78 {
79         int32_t ret = 0;
80         uint32_t val = 0;
81         struct isp_img_size size = {0, 0};
82
83         ret = copy_from_user((void *)&size, param->property_param, sizeof(struct isp_img_size));
84         if (0 != ret) {
85                 printk("isp_k_pwd_slice_size: 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         REG_WR(ISP_PWD_PARAM9, val);
91
92         return ret;
93 }
94
95 int32_t isp_k_cfg_pwd(struct isp_io_param *param)
96 {
97         int32_t ret = 0;
98
99         if (!param) {
100                 printk("isp_k_cfg_pwd: param is null error.\n");
101                 return -1;
102         }
103
104         if (NULL == param->property_param) {
105                 printk("isp_k_cfg_pwd: property_param is null error.\n");
106                 return -1;
107         }
108
109         switch(param->property) {
110         case ISP_PRO_PWD_BLOCK:
111                 ret = isp_k_pwd_block(param);
112                 break;
113         case ISP_PRO_PWD_SLICE_SIZE:
114                 ret = isp_k_pwd_slice_size(param);
115                 break;
116         default:
117                 printk("isp_k_cfg_pwd: fail cmd id:%d, not supported.\n", param->property);
118                 break;
119         }
120
121         return ret;
122 }
123