xref: /OK3568_Linux_fs/kernel/drivers/media/i2c/jaguar1_drv/jaguar1_motion.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // SPDX-License-Identifier: GPL-2.0
2 /********************************************************************************
3  *
4  *  Copyright (C) 2017 	NEXTCHIP Inc. All rights reserved.
5  *  Module		: motion.c
6  *  Description	:
7  *  Author		:
8  *  Date         :
9  *  Version		: Version 1.0
10  *
11  ********************************************************************************
12  *  History      :
13  *
14  *
15  ********************************************************************************/
16 #include <linux/string.h>
17 #include <linux/delay.h>
18 #include "jaguar1_common.h"
19 #include "jaguar1_motion.h"
20 
21 /**************************************************************************************
22  * @desc
23  * 	JAGUAR1's
24  *
25  * @param_in		(motion_mode *)p_param->channel                  FW Update channel
26  *
27  * @return   	void  		       								 None
28  *
29  * ioctl : IOC_VDEC_MOTION_SET
30  ***************************************************************************************/
31 
motion_detection_get(motion_mode * motion_set)32 void motion_detection_get(motion_mode *motion_set)
33 {
34 	//BANK2_MOTION
35 	unsigned char ReadVal = 0;
36 	unsigned char ch_mask = 1;
37 	unsigned char ch = motion_set->ch;
38 	unsigned char ret = 0;
39 
40 	ch_mask = ch_mask<<ch;
41 
42 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x00);
43 	ReadVal = gpio_i2c_read(jaguar1_i2c_addr[motion_set->devnum], 0xA1);
44 
45 	ret = ReadVal&ch_mask;
46 	motion_set->set_val = ret;
47 
48 	//	printk("motion_detection_get:: %x\n", motion_set->set_val);
49 
50 }
51 
motion_onoff_set(motion_mode * motion_set)52 void motion_onoff_set(motion_mode *motion_set)
53 {
54 	//BANK2_MOTION
55 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
56 
57 	if(motion_set->fmtdef == TVI_3M_18P || motion_set->fmtdef == TVI_5M_12_5P || motion_set->fmtdef == TVI_5M_12_5P/*TVI_5M_20P*/)
58 	{
59 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x00 + (0x07 * motion_set->ch), 0x0C);
60 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x02 + (0x07 * motion_set->ch), 0x23);
61 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x11);
62 
63 		if(motion_set->fmtdef == TVI_3M_18P)
64 		{
65 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0x78);
66 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x40);
67 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x72);
68 		}
69 		else if(motion_set->fmtdef == TVI_5M_12_5P)
70 		{
71 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0xA2);
72 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x51);
73 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x96);
74 		}
75 
76 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2B + (0x06 * motion_set->ch), 0x6);
77 
78 		printk("[DRV_Motion_OnOff] ch(%d) fmtdef(%d)\n", motion_set->ch, motion_set->fmtdef);
79 	}
80 	else
81 	{
82 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x00);
83 	}
84 
85 	if(motion_set->set_val<0 || motion_set->set_val>1)
86 	{
87 		printk("[DRV_Motion_OnOff]Error!! ch(%d) Setting Value Over:%x!! Only 0 or 1\n", motion_set->ch, motion_set->set_val);
88 		return;
89 	}
90 
91 	switch(motion_set->set_val)
92 	{
93 		case FUNC_OFF : gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x00 + (0x07 * motion_set->ch)), 0x0D);
94 						gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x00);
95 						break;
96 		case FUNC_ON : gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x00 + (0x07 * motion_set->ch)), 0x0C);
97 					   break;
98 	}
99 
100 
101 }
102 
motion_pixel_all_onoff_set(motion_mode * motion_set)103 void motion_pixel_all_onoff_set(motion_mode *motion_set)
104 {
105 	int ii=0;
106 	unsigned char addr = 0;
107 
108 	//BANK2_MOTION
109 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
110 
111 	if(motion_set->fmtdef == TVI_3M_18P || motion_set->fmtdef == TVI_5M_12_5P || motion_set->fmtdef == TVI_5M_12_5P/*TVI_5M_20P*/)
112 	{
113 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x00 + (0x07 * motion_set->ch), 0x0C);
114 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x02 + (0x07 * motion_set->ch), 0x23);
115 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x11);
116 
117 		if(motion_set->fmtdef == TVI_3M_18P)
118 		{
119 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0x78);
120 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x40);
121 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x72);
122 		}
123 		else if(motion_set->fmtdef == TVI_5M_12_5P)
124 		{
125 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0xA2);
126 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x51);
127 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x96);
128 		}
129 
130 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2B + (0x06 * motion_set->ch), 0x6);
131 
132 		printk("[DRV_Motion_OnOff] ch(%d) fmtdef(%d)\n", motion_set->ch, motion_set->fmtdef);
133 	}
134 	else
135 	{
136 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x00);
137 	}
138 
139 	for(ii=0; ii<24; ii++)
140 	{
141 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x40 +(0x18 *motion_set->ch)) + ii, motion_set->set_val);
142 		addr = (0x40 +(0x18 *motion_set->ch)) + ii;
143 	}
144 }
145 
motion_pixel_onoff_set(motion_mode * motion_set)146 void motion_pixel_onoff_set(motion_mode *motion_set)
147 {
148 	unsigned char val = 0x80;
149 	unsigned char ReadVal;
150 	unsigned char on;
151 
152 	unsigned char ch      = motion_set->ch;
153 	unsigned char SetPix  = motion_set->set_val/8;
154 	unsigned char SetVal  = motion_set->set_val%8;
155 
156 	val = val >> SetVal;
157 
158 	//BANK2_MOTION
159 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
160 
161 	if(motion_set->fmtdef == TVI_3M_18P || motion_set->fmtdef == TVI_5M_12_5P || motion_set->fmtdef == TVI_5M_12_5P/*TVI_5M_20P*/)
162 	{
163 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x00 + (0x07 * motion_set->ch), 0x0C);
164 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x02 + (0x07 * motion_set->ch), 0x23);
165 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x11);
166 
167 		if(motion_set->fmtdef == TVI_3M_18P)
168 		{
169 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0x78);
170 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x40);
171 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x72);
172 		}
173 		else if(motion_set->fmtdef == TVI_5M_12_5P)
174 		{
175 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0xA2);
176 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x51);
177 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x96);
178 		}
179 
180 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2B + (0x06 * motion_set->ch), 0x6);
181 
182 		printk("[DRV_Motion_OnOff] ch(%d) fmtdef(%d)\n", motion_set->ch, motion_set->fmtdef);
183 	}
184 	else
185 	{
186 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x00);
187 	}
188 
189 	ReadVal = gpio_i2c_read(jaguar1_i2c_addr[motion_set->devnum], (0x40 +(0x18 *ch)) + SetPix);
190 	on = val&ReadVal;
191 	if(on)
192 	{
193 		val = ~val;
194 		val = val&ReadVal;
195 	}
196 	else
197 	{
198 		val = val|ReadVal;
199 	}
200 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x40 +(0x18 *ch)) + SetPix, val);
201 }
202 
motion_pixel_onoff_get(motion_mode * motion_set)203 void motion_pixel_onoff_get(motion_mode *motion_set)
204 {
205 	unsigned char val = 0x80;
206 	unsigned char ReadVal;
207 	unsigned char on;
208 
209 	unsigned char Ch      = motion_set->ch;
210 	unsigned char SetPix  = motion_set->set_val/8;
211 	unsigned char SetVal  = motion_set->set_val%8;
212 
213 	val = val >> SetVal;
214 
215 	//BANK2_MOTION
216 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
217 	ReadVal = gpio_i2c_read(jaguar1_i2c_addr[motion_set->devnum], (0x40 +(0x18 *Ch)) + SetPix);
218 
219 	on = val&ReadVal;
220 
221 	if(on)
222 	{
223 		motion_set->set_val = 1;
224 	}
225 	else
226 	{
227 		motion_set->set_val = 0;
228 	}
229 }
230 
motion_tsen_set(motion_mode * motion_set)231 void motion_tsen_set(motion_mode *motion_set)
232 {
233 	unsigned char ch = motion_set->ch;
234 	unsigned char SetVal = motion_set->set_val;
235 
236 	//BANK2_MOTION
237 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
238 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x01 +(0x07 * ch)), SetVal);
239 	printk("[DRV_Motion]ch(%d), TSEN Val(%x)\n", ch, SetVal);
240 }
241 
motion_psen_set(motion_mode * motion_set)242 void motion_psen_set(motion_mode *motion_set)
243 {
244 	unsigned char msb_mask = 0xf0;
245 	unsigned char lsb_mask = 0x07;
246 	unsigned char ch = motion_set->ch;
247 	unsigned char SetVal = motion_set->set_val;
248 	unsigned char ReadVal;
249 
250 	//BANK2_MOTION
251 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
252 	ReadVal = gpio_i2c_read(jaguar1_i2c_addr[motion_set->devnum], (0x02 +(0x07 * ch)));
253 
254 	msb_mask = msb_mask&ReadVal;
255 	SetVal = lsb_mask&SetVal;
256 
257 	SetVal = SetVal|msb_mask;
258 
259 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x02 +(0x07 * ch)), SetVal);
260 	printk("[DRV_Motion]ch(%d), readVal(%x), SetVal(%x)\n", ch, ReadVal, SetVal);
261 }
262 
263