2 * Copyright (C) 2012 Spreadtrum Communications Inc.
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.
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.
14 #include <linux/uaccess.h>
15 #include <linux/sprd_mm.h>
16 #include <video/sprd_isp.h>
17 #include <asm/cacheflush.h>
21 static int32_t isp_k_binging_param_update(struct isp_k_private *isp_private)
26 void *buf_ptr = (void *)isp_private->bing4awb_buf_addr;
28 uint32_t buf_len = isp_private->bing4awb_buf_len;
30 if((0x00 != isp_private->bing4awb_buf_addr) && (0x00 != isp_private->bing4awb_buf_len)) {
33 dmac_flush_range(buf_ptr, buf_ptr + buf_len);
34 outer_flush_range(__pa(buf_ptr), __pa(buf_ptr) + buf_len);
36 addr = (uint32_t)__pa(isp_private->bing4awb_buf_addr);
38 REG_WR(ISP_BINNING_MEM_ADDR, addr);
44 static int32_t isp_k_binning_block(struct isp_io_param *param,
45 struct isp_k_private *isp_private)
50 struct isp_dev_binning4awb_info_v1 binning_info;
52 ret = copy_from_user((void *)&binning_info, param->property_param, sizeof(binning_info));
54 printk("isp_k_binning_block: copy error, ret=0x%x\n", (uint32_t)ret);
58 // isp_k_binging_param_update(isp_private);
60 val = (binning_info.burst_mode & 0x3) << 2;
61 REG_MWR(ISP_BINNING_PARAM, 0xC, val);
63 val = (binning_info.endian & 0x1) << 1;
64 REG_MWR(ISP_BINNING_PARAM, BIT_1, val);
66 val = (binning_info.mem_fifo_clr & 0x1) << 7;
67 REG_MWR(ISP_BINNING_PARAM, 0x80, val);
69 val = ((binning_info.hx & 0x7) << 4) | ((binning_info.vx & 0x7) << 8);
70 REG_MWR(ISP_BINNING_PARAM, 0x770, val);
72 REG_WR(ISP_BINNING_PITCH, binning_info.pitch);
74 REG_MWR(ISP_BINNING_PARAM, BIT_0, binning_info.bypass);
80 static int32_t isp_k_binging_bypass(struct isp_io_param *param)
84 ret = copy_from_user((void *)&bypass, param->property_param, sizeof(uint32_t));
86 printk("isp_k_binning_scaling_ratio: copy_from_user error, ret = 0x%x\n",(uint32_t)ret);
90 REG_MWR(ISP_BINNING_PARAM, BIT_0, bypass);
95 static int32_t isp_k_binning_scaling_ratio(struct isp_io_param *param)
99 struct isp_scaling_ratio scaling_ratio;
100 ret = copy_from_user((void *)&scaling_ratio, param->property_param, sizeof(struct isp_scaling_ratio));
102 printk("isp_k_binning_scaling_ratio: copy_from_user error, ret = 0x%x\n",(uint32_t)ret);
106 val = ((scaling_ratio.vertical & 0x7)<< 8)| ((scaling_ratio.horizontal & 0x7) << 4);
107 REG_MWR(ISP_BINNING_PARAM, 0x770, val);
112 static int32_t isp_k_binging_mem_addr(struct isp_io_param *param)
117 ret = copy_from_user((void *)&addr, param->property_param, sizeof(uint32_t));
119 printk("isp_k_binning_scaling_ratio: copy_from_user error, ret = 0x%x\n",(uint32_t)ret);
123 REG_WR(ISP_BINNING_MEM_ADDR, addr);
128 static int32_t isp_k_binning_statistics_buf(struct isp_io_param *param,
129 struct isp_k_private *isp_private)
134 if (isp_private->b4awb_buf[0].buf_flag == 0) {
135 buf_id = isp_private->b4awb_buf[0].buf_id;
136 } else if (isp_private->b4awb_buf[1].buf_flag == 0) {
137 buf_id = isp_private->b4awb_buf[0].buf_id;
140 ret = copy_to_user(param->property_param, (void*)&buf_id, sizeof(uint32_t));
143 printk("isp_k_binning_statistics_buf: copy error, ret=0x%x\n", (uint32_t)ret);
149 static int32_t isp_k_binning_buffaddr(struct isp_io_param *param,
150 struct isp_k_private *isp_private)
154 unsigned long phys_addr[2];
155 struct isp_b4awb_phys phy_addr;
157 ret = copy_from_user((void *)&phy_addr, param->property_param, sizeof(struct isp_b4awb_phys));
159 phys_addr[0] = phy_addr.phys0;
160 phys_addr[1] = phy_addr.phys1;
162 for (i = 0; i < ISP_BING4AWB_NUM; i++) {
163 isp_private->b4awb_buf[i].buf_id = i;
164 isp_private->b4awb_buf[i].buf_flag = 0;
165 isp_private->b4awb_buf[i].buf_phys_addr = phys_addr[i];
168 /*config buf_id 0 as default*/
169 isp_private->b4awb_buf[0].buf_flag = 1;
170 REG_WR(ISP_BINNING_MEM_ADDR, isp_private->b4awb_buf[0].buf_phys_addr);
172 printk("eric phys_addr 0x%x, 0x%x\n",phys_addr[0], phys_addr[1]);
177 int32_t isp_k_cfg_binning(struct isp_io_param *param, struct isp_k_private *isp_private)
182 printk("isp_k_cfg_binning: param is null error.\n");
186 if (NULL == param->property_param) {
187 printk("isp_k_cfg_binning: property_param is null error.\n");
191 switch(param->property) {
192 case ISP_PRO_BINNING4AWB_BLOCK:
193 ret = isp_k_binning_block(param, isp_private);
195 case ISP_PRO_BINNING4AWB_BYPASS:
196 ret = isp_k_binging_bypass(param);
198 case ISP_PRO_BINNING4AWB_SCALING_RATIO:
199 ret = isp_k_binning_scaling_ratio(param);
201 case ISP_PRO_BINNING4AWB_MEM_ADDR:
202 ret = isp_k_binging_mem_addr(param);
204 case ISP_PRO_BINNING4AWB_STATISTICS_BUF:
205 ret = isp_k_binning_statistics_buf(param, isp_private);
207 case ISP_PRO_BINNING4AWB_TRANSADDR:
208 ret = isp_k_binning_buffaddr(param, isp_private);
211 printk("isp_k_cfg_binning: fail cmd id:%d, not supported.\n", param->property);