tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / sprd_isp / isp2.0 / sharkl / src / isp_k_edge.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_edge_block(struct isp_io_param *param)
20 {
21         int32_t ret = 0;
22         uint32_t val = 0;
23         struct isp_dev_edge_info edge_info;
24
25         memset(&edge_info, 0x00, sizeof(edge_info));
26
27         ret = copy_from_user((void *)&edge_info, param->property_param, sizeof(edge_info));
28         if (0 != ret) {
29                 printk("isp_k_edge_block: copy error, ret=0x%x\n", (uint32_t)ret);
30                 return -1;
31         }
32
33         val = ((edge_info.strength & 0x3F) << 17)
34                 | ((edge_info.smooth_thrd & 0xFF) << 9)
35                 | ((edge_info.detail_thrd & 0xFF) << 1);
36         REG_MWR(ISP_EDGE_PARAM, 0x7FFFFE, val);
37
38         if (edge_info.bypass) {
39                 REG_OWR(ISP_EDGE_PARAM, BIT_0);
40         } else {
41                 REG_MWR(ISP_EDGE_PARAM, BIT_0, 0);
42         }
43
44         return ret;
45 }
46
47 static int32_t isp_k_edge_bypass(struct isp_io_param *param)
48 {
49         int32_t ret = 0;
50         uint32_t bypass = 0;
51
52         ret = copy_from_user((void *)&bypass, param->property_param, sizeof(bypass));
53         if (0 != ret) {
54                 printk("isp_k_edge_bypass: copy error, ret=0x%x\n", (uint32_t)ret);
55                 return -1;
56         }
57
58         if (bypass) {
59                 REG_OWR(ISP_EDGE_PARAM, BIT_0);
60         } else {
61                 REG_MWR(ISP_EDGE_PARAM, BIT_0, 0);
62         }
63
64         return ret;
65 }
66
67 static int32_t isp_k_edge_param(struct isp_io_param *param)
68 {
69         int32_t ret = 0;
70         uint32_t val = 0;
71         struct isp_edge_thrd edge_thrd;
72
73         memset(&edge_thrd, 0x00, sizeof(edge_thrd));
74
75         ret = copy_from_user((void *)&edge_thrd, param->property_param, sizeof(edge_thrd));
76         if (0 != ret) {
77                 printk("isp_k_edge_param: copy error, ret=0x%x\n", (uint32_t)ret);
78                 return -1;
79         }
80
81         val = ((edge_thrd.strength & 0x3F) << 17)
82                 | ((edge_thrd.smooth & 0xFF) << 9)
83                 | ((edge_thrd.detail & 0xFF) << 1);
84         REG_MWR(ISP_EDGE_PARAM, 0x7FFFFE, val);
85
86         return ret;
87 }
88
89 int32_t isp_k_cfg_edge(struct isp_io_param *param)
90 {
91         int32_t ret = 0;
92
93         if (!param) {
94                 printk("isp_k_cfg_edge: param is null error.\n");
95                 return -1;
96         }
97
98         if (NULL == param->property_param) {
99                 printk("isp_k_cfg_edge: property_param is null error.\n");
100                 return -1;
101         }
102
103         switch (param->property) {
104         case ISP_PRO_EDGE_BLOCK:
105                 ret = isp_k_edge_block(param);
106                 break;
107         case ISP_PRO_EDGE_BYPASS:
108                 ret = isp_k_edge_bypass(param);
109                 break;
110         case ISP_PRO_EDGE_PARAM:
111                 ret = isp_k_edge_param(param);
112                 break;
113         default:
114                 printk("isp_k_cfg_edge: fail cmd id:%d, not supported.\n", param->property);
115                 break;
116         }
117
118         return ret;
119 }