• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * A V4L2 driver for nvp6324 cameras and AHD Coax protocol.
3  *
4  * Copyright (c) 2017 by Allwinnertech Co., Ltd.  http://www.allwinnertech.com
5  *
6  * Authors:  Li Huiyu <lihuiyu@allwinnertech.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12 
13 #include <linux/string.h>
14 #include <linux/delay.h>
15 #include "jaguar1_common.h"
16 #include "jaguar1_motion.h"
17 
18 /**************************************************************************************
19  * @desc
20  * 	JAGUAR1's
21  *
22  * @param_in		(motion_mode *)p_param->channel                  FW Update channel
23  *
24  * @return   	void  		       								 None
25  *
26  * ioctl : IOC_VDEC_MOTION_SET
27  ***************************************************************************************/
28 
motion_detection_get(motion_mode * motion_set)29 void motion_detection_get(motion_mode *motion_set)
30 {
31 
32 	unsigned char ReadVal = 0;
33 	unsigned char ch_mask = 1;
34 	unsigned char ch = motion_set->ch;
35 	unsigned char ret = 0;
36 
37 	ch_mask = ch_mask<<ch;
38 
39 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x00);
40 	ReadVal = gpio_i2c_read(jaguar1_i2c_addr[motion_set->devnum], 0xA1);
41 
42 	ret = ReadVal&ch_mask;
43 	motion_set->set_val = ret;
44 
45 }
46 
motion_onoff_set(motion_mode * motion_set)47 void motion_onoff_set(motion_mode *motion_set)
48 {
49 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
50 
51 	if (motion_set->fmtdef == TVI_3M_18P || motion_set->fmtdef == TVI_5M_12_5P || motion_set->fmtdef == TVI_5M_12_5P/*TVI_5M_20P*/) {
52 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x00 + (0x07 * motion_set->ch), 0x0C);
53 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x02 + (0x07 * motion_set->ch), 0x23);
54 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x11);
55 
56 		if (motion_set->fmtdef == TVI_3M_18P) {
57 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0x78);
58 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x40);
59 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x72);
60 		} else if (motion_set->fmtdef == TVI_5M_12_5P) {
61 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0xA2);
62 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x51);
63 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x96);
64 		}
65 
66 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2B + (0x06 * motion_set->ch), 0x6);
67 
68 		printk("[DRV_Motion_OnOff] ch(%d) fmtdef(%d)\n", motion_set->ch, motion_set->fmtdef);
69 	} else {
70 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x00);
71 	}
72 
73 	if (motion_set->set_val < 0 || motion_set->set_val > 1) {
74 		printk("[DRV_Motion_OnOff]Error!! ch(%d) Setting Value Over:%x!! Only 0 or 1\n", motion_set->ch, motion_set->set_val);
75 		return;
76 	}
77 
78 	switch (motion_set->set_val) {
79 	case FUNC_OFF:
80 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x00 + (0x07 * motion_set->ch)), 0x0D);
81 						gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x00);
82 						break;
83 	case FUNC_ON:
84 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x00 + (0x07 * motion_set->ch)), 0x0C);
85 					   break;
86 	}
87 
88 
89 }
motion_pixel_all_onoff_set(motion_mode * motion_set)90 void motion_pixel_all_onoff_set(motion_mode *motion_set)
91 {
92 	int ii = 0;
93 	unsigned char addr = 0;
94 
95 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
96 	if (motion_set->fmtdef == TVI_3M_18P || motion_set->fmtdef == TVI_5M_12_5P || motion_set->fmtdef == TVI_5M_12_5P/*TVI_5M_20P*/) {
97 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x00 + (0x07 * motion_set->ch), 0x0C);
98 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x02 + (0x07 * motion_set->ch), 0x23);
99 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x11);
100 
101 		if (motion_set->fmtdef == TVI_3M_18P) {
102 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0x78);
103 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x40);
104 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x72);
105 		} else if (motion_set->fmtdef == TVI_5M_12_5P) {
106 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0xA2);
107 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x51);
108 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x96);
109 		}
110 
111 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2B + (0x06 * motion_set->ch), 0x6);
112 
113 		printk("[DRV_Motion_OnOff] ch(%d) fmtdef(%d)\n", motion_set->ch, motion_set->fmtdef);
114 	} else {
115 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x00);
116 	}
117 
118 	for (ii = 0; ii < 24; ii++) {
119 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x40 + (0x18 * motion_set->ch)) + ii, motion_set->set_val);
120 		addr = (0x40 + (0x18 * motion_set->ch)) + ii;
121 	}
122 }
123 
motion_pixel_onoff_set(motion_mode * motion_set)124 void motion_pixel_onoff_set(motion_mode *motion_set)
125 {
126 	unsigned char val = 0x80;
127 	unsigned char ReadVal;
128 	unsigned char on;
129 
130 	unsigned char ch      = motion_set->ch;
131 	unsigned char SetPix  = motion_set->set_val/8;
132 	unsigned char SetVal  = motion_set->set_val%8;
133 
134 	val = val >> SetVal;
135 
136 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
137 
138 	if (motion_set->fmtdef == TVI_3M_18P || motion_set->fmtdef == TVI_5M_12_5P || motion_set->fmtdef == TVI_5M_12_5P/*TVI_5M_20P*/) {
139 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x00 + (0x07 * motion_set->ch), 0x0C);
140 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x02 + (0x07 * motion_set->ch), 0x23);
141 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x11);
142 
143 		if (motion_set->fmtdef == TVI_3M_18P) {
144 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0x78);
145 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x40);
146 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x72);
147 		} else if (motion_set->fmtdef == TVI_5M_12_5P) {
148 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x29 + (0x06 * motion_set->ch), 0xA2);
149 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2A + (0x06 * motion_set->ch), 0x51);
150 			gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2C + (0x06 * motion_set->ch), 0x96);
151 		}
152 
153 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x2B + (0x06 * motion_set->ch), 0x6);
154 
155 		printk("[DRV_Motion_OnOff] ch(%d) fmtdef(%d)\n", motion_set->ch, motion_set->fmtdef);
156 	} else {
157 		gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0x28 + (0x06 * motion_set->ch), 0x00);
158 	}
159 
160 	ReadVal = gpio_i2c_read(jaguar1_i2c_addr[motion_set->devnum], (0x40 + (0x18 * ch)) + SetPix);
161 	on = val&ReadVal;
162 	if (on) {
163 		val = ~val;
164 		val = val&ReadVal;
165 	} else {
166 		val = val|ReadVal;
167 	}
168 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x40 + (0x18 * ch)) + SetPix, val);
169 }
170 
motion_pixel_onoff_get(motion_mode * motion_set)171 void motion_pixel_onoff_get(motion_mode *motion_set)
172 {
173 	unsigned char val = 0x80;
174 	unsigned char ReadVal;
175 	unsigned char on;
176 
177 	unsigned char Ch      = motion_set->ch;
178 	unsigned char SetPix  = motion_set->set_val/8;
179 	unsigned char SetVal  = motion_set->set_val%8;
180 
181 	val = val >> SetVal;
182 
183 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
184 	ReadVal = gpio_i2c_read(jaguar1_i2c_addr[motion_set->devnum], (0x40 + (0x18 * Ch)) + SetPix);
185 
186 	on = val&ReadVal;
187 
188 	if (on) {
189 		motion_set->set_val = 1;
190 	} else {
191 		motion_set->set_val = 0;
192 	}
193 }
194 
motion_tsen_set(motion_mode * motion_set)195 void motion_tsen_set(motion_mode *motion_set)
196 {
197 	unsigned char ch = motion_set->ch;
198 	unsigned char SetVal = motion_set->set_val;
199 
200 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
201 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x01 + (0x07 * ch)), SetVal);
202 	printk("[DRV_Motion]ch(%d), TSEN Val(%x)\n", ch, SetVal);
203 }
204 
motion_psen_set(motion_mode * motion_set)205 void motion_psen_set(motion_mode *motion_set)
206 {
207 	unsigned char msb_mask = 0xf0;
208 	unsigned char lsb_mask = 0x07;
209 	unsigned char ch = motion_set->ch;
210 	unsigned char SetVal = motion_set->set_val;
211 	unsigned char ReadVal;
212 
213 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], 0xFF, 0x04);
214 	ReadVal = gpio_i2c_read(jaguar1_i2c_addr[motion_set->devnum], (0x02 + (0x07 * ch)));
215 
216 	msb_mask = msb_mask&ReadVal;
217 	SetVal = lsb_mask&SetVal;
218 
219 	SetVal = SetVal|msb_mask;
220 
221 	gpio_i2c_write(jaguar1_i2c_addr[motion_set->devnum], (0x02 + (0x07 * ch)), SetVal);
222 	printk("[DRV_Motion]ch(%d), readVal(%x), SetVal(%x)\n", ch, ReadVal, SetVal);
223 }
224 
225