tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / sprd_isp / isp2.0 / pike / src / isp_k_hsv.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
15 #include <linux/uaccess.h>
16 #include <linux/sprd_mm.h>
17 #include <video/sprd_isp.h>
18 #include "isp_reg.h"
19
20 static int32_t isp_k_hsv_block(struct isp_io_param *param)
21 {
22         int32_t ret = 0;
23         int32_t buf_size = 0;
24         unsigned long dst_addr = 0;
25         struct isp_dev_hsv_info_v1 hsv_info;
26         void *data_ptr = NULL;
27
28         memset(&hsv_info, 0x00, sizeof(hsv_info));
29
30         ret = copy_from_user((void *)&hsv_info, param->property_param, sizeof(hsv_info));
31         if (0 != ret) {
32                 printk("isp_k_hsv_block: copy error, ret=0x%x\n", (uint32_t)ret);
33                 return -1;
34         }
35
36 #ifdef CONFIG_64BIT
37         data_ptr = (void*)(((unsigned long)hsv_info.data_ptr[1] << 32) | hsv_info.data_ptr[0]);
38 #else
39         data_ptr = (void*)(hsv_info.data_ptr[0]);
40 #endif
41
42         buf_size = ISP_HSV_ITEM * 4;
43         if (NULL == data_ptr || hsv_info.size > buf_size) {
44                 printk("isp_k_hsv_block : memory error %p %x \n",
45                         data_ptr, hsv_info.size);
46                 return -1;
47         }
48
49         if (hsv_info.buf_sel << 1 & BIT_1) {
50                 dst_addr = ISP_HSV_BUF1_OUTPUT;
51         } else {
52                 dst_addr = ISP_HSV_BUF0_OUTPUT;
53         }
54
55         ret = copy_from_user((void *)dst_addr, data_ptr, hsv_info.size);
56         if (0 != ret) {
57                 printk("isp_k_hsv_block: copy error 0x%x \n",(uint32_t)ret);
58                 return -1;
59         }
60
61         REG_MWR(ISP_HSV_PARAM, BIT_1, hsv_info.buf_sel << 1);
62
63         REG_MWR(ISP_HSV_PARAM, BIT_0, hsv_info.bypass);
64
65         return ret;
66
67 }
68
69
70 int32_t isp_k_cfg_hsv(struct isp_io_param *param)
71 {
72         int32_t ret = 0;
73
74         if (!param) {
75                 printk("isp_k_cfg_hsv: param is null error.\n");
76                 return -1;
77         }
78
79         if (NULL == param->property_param) {
80                 printk("isp_k_cfg_hsv: property_param is null error.\n");
81                 return -1;
82         }
83
84         switch(param->property) {
85         case ISP_PRO_HSV_BLOCK:
86                 ret = isp_k_hsv_block(param);
87                 break;
88         default:
89                 printk("isp_k_cfg_hsv: fail cmd id:%d, not supported.\n", param->property);
90                 break;
91         }
92
93         return ret;
94 }