tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / sprd_isp / isp2.0 / tshark2 / src / isp_k_hist.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_hist_block(struct isp_io_param *param)
20 {
21         int32_t ret = 0;
22         struct isp_dev_hist_info_v1 hist_info;
23         uint32_t val = 0;
24
25         memset(&hist_info, 0x00, sizeof(hist_info));
26
27         ret = copy_from_user((void *)&hist_info, param->property_param, sizeof(hist_info));
28         if (0 != ret) {
29                 printk("isp_k_hist_block: copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
30                 return -1;
31         }
32
33         if (hist_info.buf_rst_en) {
34                 REG_OWR(ISP_HIST_PARAM, BIT_1);
35         } else {
36                 REG_MWR(ISP_HIST_PARAM, BIT_1, 0);
37         }
38
39         if (hist_info.pof_rst_en) {
40                 REG_OWR(ISP_HIST_PARAM, BIT_9);
41         } else {
42                 REG_MWR(ISP_HIST_PARAM, BIT_9, 0);
43         }
44
45         if (hist_info.skip_num_clr) {
46                 REG_OWR(ISP_HIST_PARAM, BIT_8);
47         } else {
48                 REG_MWR(ISP_HIST_PARAM, BIT_8, 0);
49         }
50
51         REG_MWR(ISP_HIST_PARAM, 0xF0, hist_info.skip_num << 4);
52
53         if (hist_info.mode) {
54                 REG_OWR(ISP_HIST_PARAM, BIT_3);
55         } else {
56                 REG_MWR(ISP_HIST_PARAM, BIT_3, 0);
57         }
58
59         val = ((hist_info.high_ratio & 0xFFFF) << 16)
60                         | (hist_info.low_ratio & 0xFFFF);
61
62         REG_WR(ISP_HIST_RATIO, val);
63
64         val = (hist_info.dif_adj & 0xFF) | ((hist_info.small_adj & 0xFF) << 8)
65                 | ((hist_info.big_adj & 0xFF) << 16);
66
67         REG_WR(ISP_HIST_ADJUST, val);
68
69         if (hist_info.off) {
70                 REG_OWR(ISP_HIST_PARAM, BIT_2);
71         } else {
72                 REG_MWR(ISP_HIST_PARAM, BIT_2, 0);
73         }
74
75         if (hist_info.bypass) {
76                 REG_OWR(ISP_HIST_PARAM, BIT_0);
77         } else {
78                 REG_MWR(ISP_HIST_PARAM, BIT_0, 0);
79         }
80
81         return ret;
82 }
83
84 static int32_t isp_k_hist_slice_size(struct isp_io_param *param)
85 {
86         int32_t ret = 0;
87         uint32_t val = 0;
88         struct isp_img_size size = {0};
89
90         ret = copy_from_user((void *)&size, param->property_param, sizeof(size));
91         if (0 != ret) {
92                 printk("isp_k_hist_slice_size: read copy_from_user error, ret = 0x%x\n", (uint32_t)ret);
93                 return -1;
94         }
95
96         val = ((size.height & 0xFFFF) << 16)
97                         | (size.width & 0xFFFF);
98
99         REG_WR(ISP_HIST_SLICE_SIZE, val);
100
101         return ret;
102 }
103
104 int32_t isp_k_cfg_hist(struct isp_io_param *param)
105 {
106         int32_t ret = 0;
107
108         if (!param) {
109                 printk("isp_k_cfg_hist: param is null error.\n");
110                 return -1;
111         }
112
113         if (NULL == param->property_param) {
114                 printk("isp_k_cfg_hist: property_param is null error.\n");
115                 return -1;
116         }
117
118         switch (param->property) {
119         case ISP_PRO_HIST_BLOCK:
120                 ret = isp_k_hist_block(param);
121                 break;
122         case ISP_PRO_HIST_SLICE_SIZE:
123                 ret = isp_k_hist_slice_size(param);
124                 break;
125         default:
126                 printk("isp_k_cfg_hist: fail cmd id:%d, not supported.\n", param->property);
127                 break;
128         }
129
130         return ret;
131 }