tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / sprd_isp / isp2.0 / pike / src / isp_k_bdn.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_bdn_block(struct isp_io_param *param)
20 {
21         int32_t ret = 0;
22         uint32_t val = 0;
23         uint32_t i = 0;
24         uint32_t j = 0;
25         struct isp_dev_bdn_info_v1 bdn_info;
26
27         memset(&bdn_info, 0x00, sizeof(bdn_info));
28
29         ret = copy_from_user((void *)&bdn_info, param->property_param, sizeof(bdn_info));
30         if (0 != ret) {
31                 printk("isp_k_bdn_block: copy error, ret=0x%x\n", (uint32_t)ret);
32                 return -1;
33         }
34
35         REG_MWR(ISP_BDN_PARAM, BIT_1, bdn_info.radial_bypass << 1);
36
37         REG_MWR(ISP_BDN_PARAM, 0x7F0, bdn_info.addback << 4);
38
39         for (i = 0; i < 10; i++) {
40                 REG_WR(ISP_BDN_DISWEI0_0 + 40 * i, bdn_info.dis[i][0]);
41
42                 REG_WR(ISP_BDN_DISWEI0_1 + 40 * i, bdn_info.dis[i][1]);
43         }
44
45         for (i = 0; i < 10; i++) {
46                 for (j = 0; j < 7; j++) {
47                         REG_WR(ISP_BDN_RANWEI0_0 + i * 40 + j * 4, bdn_info.ran[i][j]);
48                 }
49
50                 REG_WR(ISP_BDN_RANWEI0_7 + i * 40, bdn_info.ran[i][7]);
51         }
52
53         val = ((bdn_info.offset_x & 0x1FFF) << 12) | (bdn_info.offset_y & 0xFFF);
54         REG_WR(ISP_BDN_1DLNC_CENTER, val);
55
56         val = bdn_info.squ_x2 & 0x3FFFFFF;
57         REG_WR(ISP_BDN_1DLNC_SQUARE_X, val);
58         val = bdn_info.squ_y2 & 0xFFFFFF;
59         REG_WR(ISP_BDN_1DLNC_SQUARE_Y, val);
60
61         val = ((bdn_info.coef2 & 0xFFFF) << 11) | (bdn_info.coef & 0x7FF);
62         REG_WR(ISP_BDN_1DLNC_P, val);
63
64         val = ((bdn_info.start_pos_x & 0x1FFF) << 12) | (bdn_info.start_pos_y & 0xFFF);
65         REG_WR(ISP_BDN_1DLNC_POS, val);
66
67         REG_WR(ISP_BDN_1DLNC_OFFSET, bdn_info.offset & 0x3FFFFFF);
68
69         REG_MWR(ISP_BDN_PARAM, BIT_0, bdn_info.bypass);
70
71         return ret;
72
73 }
74
75 static int32_t isp_k_bdn_1d_slice_size(struct isp_io_param *param)
76 {
77         int32_t ret = 0;
78         struct isp_img_size size = {0, 0};
79         uint32_t val = 0;
80
81         ret = copy_from_user((void *)&size, param->property_param, sizeof(struct isp_img_size));
82         if (0 != ret) {
83                 printk("isp_k_bdn_1d_slice_size: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
84                 return -1;
85         }
86
87         val = ((size.width & 0x1FFF) << 12) | (size.height & 0xFFF);
88         REG_WR(ISP_BDN_1DLNC_SIZE, val);
89
90         return ret;
91 }
92
93 int32_t isp_k_cfg_bdn(struct isp_io_param *param)
94 {
95         int32_t ret = 0;
96
97         if (!param) {
98                 printk("isp_k_cfg_bdn: param is null error.\n");
99                 return -1;
100         }
101
102         if (NULL == param->property_param) {
103                 printk("isp_k_cfg_bdn: property_param is null error.\n");
104                 return -1;
105         }
106
107         switch(param->property) {
108         case ISP_PRO_BDN_BLOCK:
109                 ret = isp_k_bdn_block(param);
110                 break;
111         case ISP_PRO_BDN_SLICE_SIZE:
112                 ret = isp_k_bdn_1d_slice_size(param);
113                 break;
114         default:
115                 printk("isp_k_cfg_bdn: fail cmd id:%d, not supported.\n", param->property);
116                 break;
117         }
118
119         return ret;
120 }
121