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