1 // SPDX-License-Identifier: GPL-2.0
2 /********************************************************************************
3 *
4 * Copyright (C) 2017 NEXTCHIP Inc. All rights reserved.
5 * Module : jaguar1_drv.c
6 * Description :
7 * Author :
8 * Date :
9 * Version : Version 1.0
10 *
11 ********************************************************************************
12 * History :
13 *
14 *
15 ********************************************************************************/
16
17 #include <linux/kernel.h>
18 #include <linux/version.h>
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/errno.h>
22 #include <linux/fcntl.h>
23 #include <linux/mm.h>
24 #include <linux/proc_fs.h>
25 #include <linux/miscdevice.h>
26 #include <linux/fs.h>
27 #include <linux/slab.h>
28 #include <linux/init.h>
29 #include <linux/uaccess.h>
30 #include <asm/io.h>
31 #include <linux/interrupt.h>
32 #include <linux/ioport.h>
33 #include <linux/string.h>
34 #include <linux/list.h>
35 #include <asm/delay.h>
36 #include <linux/timer.h>
37 #include <linux/delay.h>
38 #include <linux/proc_fs.h>
39 #include <linux/poll.h>
40 #include <asm/bitops.h>
41 #include <linux/uaccess.h>
42 #include <asm/irq.h>
43 #include <linux/moduleparam.h>
44 #include <linux/ioport.h>
45 #include <linux/interrupt.h>
46 #include <linux/semaphore.h>
47 #include <linux/kthread.h>
48 #include <linux/i2c.h>
49 #include <linux/i2c-dev.h>
50
51 #include "jaguar1_common.h"
52 #include "jaguar1_video.h"
53 #include "jaguar1_coax_protocol.h"
54 #include "jaguar1_motion.h"
55 #include "jaguar1_ioctl.h"
56 #include "jaguar1_video_eq.h"
57 #include "jaguar1_mipi.h"
58 #include "jaguar1_drv.h"
59 #ifdef FOR_IMX6
60 #include "imx_mipi.h"
61 #endif
62 //#include "video_eq.h" //To do
63
64 //#define STREAM_ON_DEFLAULT
65
66 #define I2C_0 (0)
67 #define I2C_1 (1)
68 #define I2C_2 (2)
69 #define I2C_3 (3)
70
71 #define JAGUAR1_4PORT_R0_ID 0xB0
72 #define JAGUAR1_2PORT_R0_ID 0xA0
73 #define JAGUAR1_1PORT_R0_ID 0xA2
74 #define AFE_NVP6134E_R0_ID 0x80
75
76 #define JAGUAR1_4PORT_REV_ID 0x00
77 #define JAGUAR1_2PORT_REV_ID 0x00
78 #define JAGUAR1_1PORT_REV_ID 0x00
79
80 static int chip_id[4];
81 static int rev_id[4];
82 static int jaguar1_cnt;
83 unsigned int jaguar1_i2c_addr[4] = {0x60, 0x62, 0x64, 0x66};
84 unsigned int jaguar1_mclk = 0; //0:756 1:594 2:378 3:1242
85 module_param_named(jaguar1_mclk, jaguar1_mclk, uint, S_IRUGO);
86 unsigned int jaguar1_lane = 4; //2 or 4
87 module_param_named(jaguar1_lane, jaguar1_lane, uint, S_IRUGO);
88 static unsigned int chn = 4;
89 module_param_named(jaguar1_chn, chn, uint, S_IRUGO);
90 static unsigned int init = 0;
91 module_param_named(jaguar1_init, init, uint, S_IRUGO);
92 static unsigned int fmt = 2; //0:960H;1:720P 2:1080P 3:960P 4:SH720
93 module_param_named(jaguar1_fmt, fmt, uint, S_IRUGO);
94 static unsigned int ntpal = 0;
95 module_param_named(jaguar1_ntpal, ntpal, uint, S_IRUGO);
96
97 static bool jaguar1_init_state;
98 struct semaphore jaguar1_lock;
99 struct i2c_client* jaguar1_client;
100 static struct i2c_board_info hi_info =
101 {
102 I2C_BOARD_INFO("jaguar1", 0x60),
103 };
104 decoder_get_information_str decoder_inform;
105
106 unsigned int acp_mode_enable = 1;
107 module_param(acp_mode_enable, uint, S_IRUGO);
108
vd_pattern_enable(void)109 static void vd_pattern_enable(void)
110 {
111 gpio_i2c_write(0x60, 0xFF, 0x00);
112 gpio_i2c_write(0x60, 0x1C, 0x1A);
113 gpio_i2c_write(0x60, 0x1D, 0x1A);
114 gpio_i2c_write(0x60, 0x1E, 0x1A);
115 gpio_i2c_write(0x60, 0x1F, 0x1A);
116
117 gpio_i2c_write(0x60, 0xFF, 0x05);
118 gpio_i2c_write(0x60, 0x6A, 0x80);
119 gpio_i2c_write(0x60, 0xFF, 0x06);
120 gpio_i2c_write(0x60, 0x6A, 0x80);
121 gpio_i2c_write(0x60, 0xFF, 0x07);
122 gpio_i2c_write(0x60, 0x6A, 0x80);
123 gpio_i2c_write(0x60, 0xFF, 0x08);
124 gpio_i2c_write(0x60, 0x6A, 0x80);
125 }
126
127 /*******************************************************************************
128 * Description : Sample function - for select video format
129 * Argurments : int dev_num(i2c_address array's num)
130 * Return value : void
131 * Modify :
132 * warning :
133 *******************************************************************************/
134 #if 0
135 static void set_default_video_fmt(int dev_num)
136 {
137 #if 0 // Activate this block if a default video-setting is required.
138 int i;
139 video_input_init video_val;
140
141 /* default video datatype setting */
142 mipi_datatype_set(VD_DATA_TYPE_YUV422);
143
144 /* mipi_tx_initial */
145 mipi_tx_init(dev_num);
146
147 /* run default video format setting */
148 for( i=0 ; i<4 ; i++)
149 {
150 video_val.ch = i;
151
152 /* select video format, include struct'vd_vi_init_list' in jaguar1_video_table.h
153 * ex > AHD20_1080P_30P / AHD20_720P_25P_EX_Btype / AHD20_SD_H960_2EX_Btype_NT */
154 video_val.format = AHD20_720P_30P_EX_Btype;
155 // select analog input type, SINGLE_ENDED or DIFFERENTIAL
156 video_val.input = SINGLE_ENDED;
157 // select decoder to soc interface
158 video_val.interface = YUV_422;
159
160 // run video setting
161 vd_jaguar1_init_set(&video_val);
162
163 // run video format setting for mipi/arbiter
164 mipi_video_format_set(&video_val);
165 set_imx_video_format(&video_val);
166 init_imx_mipi(i);
167 }
168 arb_init(dev_num);
169 disable_parallel(dev_num);
170 #endif
171 }
172 #endif
173
174 /*******************************************************************************
175 * Description : Check ID
176 * Argurments : dec(slave address)
177 * Return value : Device ID
178 * Modify :
179 * warning :
180 *******************************************************************************/
vd_set_all(video_init_all * param)181 static void vd_set_all(video_init_all *param)
182 {
183 int i, dev_num=0;
184 video_input_init video_val[4];
185
186 #if 0
187 for(i=0 ; i<4 ; i++)
188 {
189 printk("[DRV || %s] ch%d / fmt:%d / input:%d / interface:%d\n",__func__
190 , param->ch_param[i].ch
191 , param->ch_param[i].format
192 , param->ch_param[i].input
193 , param->ch_param[i].interface);
194 }
195 #endif
196 mipi_datatype_set(VD_DATA_TYPE_YUV422); // to do
197 mipi_tx_init(dev_num);
198
199 for( i=0 ; i<4 ; i++)
200 {
201 video_val[i].ch = param->ch_param[i].ch;
202 video_val[i].format = param->ch_param[i].format;
203 video_val[i].input = param->ch_param[i].input;
204 if(i<chn)
205 video_val[i].interface = param->ch_param[i].interface;
206 else
207 video_val[i].interface = DISABLE;
208
209 vd_jaguar1_init_set(&video_val[i]);
210 mipi_video_format_set(&video_val[i]);
211 #ifdef FOR_IMX6
212 set_imx_video_format(&video_val[i]);
213 if(video_val[i].interface == DISABLE)
214 {
215 printk("[DRV] Nothing selected [video ch : %d]\n", i);
216 }
217 else
218 {
219 init_imx_mipi(i);
220 }
221 #endif
222 }
223 arb_init(dev_num);
224 disable_parallel(dev_num);
225 vd_pattern_enable();
226 }
227
228 /*******************************************************************************
229 * Description : Check ID
230 * Argurments : dec(slave address)
231 * Return value : Device ID
232 * Modify :
233 * warning :
234 *******************************************************************************/
check_id(unsigned int dec)235 static int check_id(unsigned int dec)
236 {
237 int ret;
238 gpio_i2c_write(dec, 0xFF, 0x00);
239 ret = gpio_i2c_read(dec, 0xf4);
240 return ret;
241 }
242
243 /*******************************************************************************
244 * Description : Get rev ID
245 * Argurments : dec(slave address)
246 * Return value : rev ID
247 * Modify :
248 * warning :
249 *******************************************************************************/
check_rev(unsigned int dec)250 static int check_rev(unsigned int dec)
251 {
252 int ret;
253 gpio_i2c_write(dec, 0xFF, 0x00);
254 ret = gpio_i2c_read(dec, 0xf5);
255 return ret;
256 }
257
258 /*******************************************************************************
259 * Description : Check decoder count
260 * Argurments : void
261 * Return value : (total chip count - 1) or -1(not found any chip)
262 * Modify :
263 * warning :
264 *******************************************************************************/
check_decoder_count(void)265 static int check_decoder_count(void)
266 {
267 int chip, i;
268 int ret = -1;
269
270 for(chip=0;chip<4;chip++)
271 {
272 chip_id[chip] = check_id(jaguar1_i2c_addr[chip]);
273 rev_id[chip] = check_rev(jaguar1_i2c_addr[chip]);
274 if( (chip_id[chip] != JAGUAR1_4PORT_R0_ID ) &&
275 (chip_id[chip] != JAGUAR1_2PORT_R0_ID) &&
276 (chip_id[chip] != JAGUAR1_1PORT_R0_ID) &&
277 (chip_id[chip] != AFE_NVP6134E_R0_ID)
278 )
279 {
280 printk("Device ID Error... %x, Chip Count:[%d]\n", chip_id[chip], chip);
281 jaguar1_i2c_addr[chip] = 0xFF;
282 chip_id[chip] = 0xFF;
283 }
284 else
285 {
286 printk("Device (0x%x) ID OK... %x , Chip Count:[%d]\n", jaguar1_i2c_addr[chip], chip_id[chip], chip);
287 printk("Device (0x%x) REV %x\n", jaguar1_i2c_addr[chip], rev_id[chip]);
288 jaguar1_i2c_addr[jaguar1_cnt] = jaguar1_i2c_addr[chip];
289
290 if(jaguar1_cnt<chip)
291 {
292 jaguar1_i2c_addr[chip] = 0xFF;
293 }
294
295 chip_id[jaguar1_cnt] = chip_id[chip];
296 rev_id[jaguar1_cnt] = rev_id[chip];
297
298 jaguar1_cnt++;
299 }
300
301 if((chip == 3) && (jaguar1_cnt < chip))
302 {
303 for(i = jaguar1_cnt; i < 4; i++)
304 {
305 chip_id[i] = 0xff;
306 rev_id[i] = 0xff;
307 }
308 }
309 }
310 printk("Chip Count = %d\n", jaguar1_cnt);
311 printk("Address [0x%x][0x%x][0x%x][0x%x]\n",jaguar1_i2c_addr[0],jaguar1_i2c_addr[1],jaguar1_i2c_addr[2],jaguar1_i2c_addr[3]);
312 printk("Chip Id [0x%x][0x%x][0x%x][0x%x]\n",chip_id[0],chip_id[1],chip_id[2],chip_id[3]);
313 printk("Rev Id [0x%x][0x%x][0x%x][0x%x]\n",rev_id[0],rev_id[1],rev_id[2],rev_id[3]);
314
315 for( i = 0; i < 4; i++ )
316 {
317 decoder_inform.chip_id[i] = chip_id[i];
318 decoder_inform.chip_rev[i] = rev_id[i];
319 decoder_inform.chip_addr[i] = jaguar1_i2c_addr[i];
320 }
321 decoder_inform.Total_Chip_Cnt = jaguar1_cnt;
322 ret = jaguar1_cnt;
323
324 return ret;
325 }
326
327 /*******************************************************************************
328 * Description : Video decoder initial
329 * Argurments : void
330 * Return value : void
331 * Modify :
332 * warning :
333 *******************************************************************************/
video_decoder_init(void)334 static void video_decoder_init(void)
335 {
336 int ii = 0;
337
338 // Pad Control Setting
339 gpio_i2c_write(jaguar1_i2c_addr[0], 0xff, 0x04);
340
341 for(ii =0; ii<36; ii++)
342 {
343 gpio_i2c_write(jaguar1_i2c_addr[0], 0xa0 + ii , 0x24);
344 }
345
346 // Clock Delay Setting
347 gpio_i2c_write(jaguar1_i2c_addr[0], 0xff, 0x01);
348 for(ii =0; ii<4; ii++)
349 {
350 gpio_i2c_write(jaguar1_i2c_addr[0], 0xcc + ii , 0x64);
351 }
352 #if 1
353 // MIPI_V_REG_OFF
354 gpio_i2c_write(jaguar1_i2c_addr[0], 0xff, 0x21);
355 gpio_i2c_write(jaguar1_i2c_addr[0], 0x07, 0x80);
356 gpio_i2c_write(jaguar1_i2c_addr[0], 0x07, 0x00);
357 #endif
358
359 #if 1
360 // AGC_OFF 08.31
361 gpio_i2c_write(jaguar1_i2c_addr[0], 0xff, 0x0A);
362 gpio_i2c_write(jaguar1_i2c_addr[0], 0x77, 0x8F);
363 gpio_i2c_write(jaguar1_i2c_addr[0], 0xF7, 0x8F);
364 gpio_i2c_write(jaguar1_i2c_addr[0], 0xff, 0x0B);
365 gpio_i2c_write(jaguar1_i2c_addr[0], 0x77, 0x8F);
366 gpio_i2c_write(jaguar1_i2c_addr[0], 0xF7, 0x8F);
367 #endif
368 }
369
370 /*******************************************************************************
371 * Description : Driver open
372 * Argurments :
373 * Return value :
374 * Modify :
375 * warning :
376 *******************************************************************************/
jaguar1_open(struct inode * inode,struct file * file)377 static int jaguar1_open(struct inode * inode, struct file * file)
378 {
379 printk("[DRV] Jaguar1 Driver Open\n");
380 printk("[DRV] Jaguar1 Driver Ver::%s\n", DRIVER_VER);
381 return 0;
382 }
383
384 /*******************************************************************************
385 * Description : Driver close
386 * Argurments :
387 * Return value :
388 * Modify :
389 * warning :
390 *******************************************************************************/
jaguar1_close(struct inode * inode,struct file * file)391 static int jaguar1_close(struct inode * inode, struct file * file)
392 {
393 printk("[DRV] Jaguar1 Driver Close\n");
394 return 0;
395 }
396
397 /*******************************************************************************
398 * Description : Driver IOCTL function
399 * Argurments :
400 * Return value :
401 * Modify :
402 * warning :
403 *******************************************************************************/
jaguar1_ioctl(struct file * file,unsigned int cmd,unsigned long arg)404 static long jaguar1_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
405 {
406 int cpy2usr_ret;
407 unsigned int __user *argp = (unsigned int __user *)arg;
408
409 /* AllVideo Variable */
410 video_init_all all_vd_val;
411
412 /* Video Variable */
413 video_input_init video_val;
414 video_output_init vo_seq_set;
415 video_equalizer_info_s video_eq;
416 video_video_loss_s vidloss;
417
418 /* Coaxial Protocol Variable */
419 NC_VD_COAX_STR coax_val;
420 NC_VD_COAX_BANK_DUMP_STR coax_bank_dump;
421 FIRMWARE_UP_FILE_INFO coax_fw_val;
422 NC_VD_COAX_TEST_STR coax_test_val;
423
424 /* Motion Variable */
425 motion_mode motion_set;
426
427 nc_acp_rw_data ispdata;
428
429 down(&jaguar1_lock);
430
431 switch (cmd)
432 {
433 /*===============================================================================================
434 * Set All - for MIPI Interface
435 *===============================================================================================*/
436 case IOC_VDEC_INIT_ALL:
437 if(copy_from_user(&all_vd_val, argp, sizeof(video_init_all)))
438 printk("IOC_VDEC_INPUT_INIT error\n");
439 vd_set_all(&all_vd_val);
440 break;
441 /*===============================================================================================
442 * Video Initialize
443 *===============================================================================================*/
444 case IOC_VDEC_INPUT_INIT:
445 if(copy_from_user(&video_val, argp, sizeof(video_input_init)))
446 printk("IOC_VDEC_INPUT_INIT error\n");
447 vd_jaguar1_init_set(&video_val);
448 break;
449 case IOC_VDEC_OUTPUT_SEQ_SET:
450 if(copy_from_user(&vo_seq_set, argp, sizeof(video_output_init)))
451 printk("IOC_VDEC_INPUT_INIT error\n");
452 vd_jaguar1_vo_ch_seq_set(&vo_seq_set);
453 break;
454 case IOC_VDEC_VIDEO_EQ_SET:
455 if(copy_from_user(&video_eq, argp, sizeof(video_equalizer_info_s)))
456 printk("IOC_VDEC_INPUT_INIT error\n");
457 video_input_eq_val_set(&video_eq);
458 break;
459 case IOC_VDEC_VIDEO_SW_RESET:
460 if(copy_from_user(&video_val, argp, sizeof(video_input_init)))
461 printk("IOC_VDEC_INPUT_INIT error\n");
462 vd_jaguar1_sw_reset(&video_val);
463 break;
464 case IOC_VDEC_VIDEO_EQ_CABLE_SET:
465 if(copy_from_user(&video_eq, argp, sizeof(video_equalizer_info_s)))
466 printk("IOC_VDEC_INPUT_INIT error\n");
467 video_input_eq_cable_set(&video_eq);
468 break;
469 case IOC_VDEC_VIDEO_EQ_ANALOG_INPUT_SET:
470 if(copy_from_user(&video_eq, argp, sizeof(video_equalizer_info_s)))
471 printk("IOC_VDEC_INPUT_INIT error\n");
472 video_input_eq_analog_input_set(&video_eq);
473 break;
474 case IOC_VDEC_VIDEO_GET_VIDEO_LOSS:
475 if(copy_from_user(&vidloss, argp, sizeof(video_video_loss_s)))
476 printk("IOC_VDEC_VIDEO_GET_VIDEO_LOSS error\n");
477 vd_jaguar1_get_novideo(&vidloss);
478 cpy2usr_ret = copy_to_user(argp, &vidloss, sizeof(video_video_loss_s));
479 break;
480 /*===============================================================================================
481 * Coaxial Protocol
482 *===============================================================================================*/
483 case IOC_VDEC_COAX_TX_INIT: //SK_CHANGE 170703
484 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
485 printk("IOC_VDEC_COAX_TX_INIT error\n");
486 coax_tx_init(&coax_val);
487 break;
488 case IOC_VDEC_COAX_TX_16BIT_INIT: //SK_CHANGE 170703
489 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
490 printk("IOC_VDEC_COAX_TX_INIT error\n");
491 coax_tx_16bit_init(&coax_val);
492 break;
493 case IOC_VDEC_COAX_TX_CMD_SEND: //SK_CHANGE 170703
494 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
495 printk(" IOC_VDEC_COAX_TX_CMD_SEND error\n");
496 coax_tx_cmd_send(&coax_val);
497 break;
498 case IOC_VDEC_COAX_TX_16BIT_CMD_SEND: //SK_CHANGE 170703
499 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
500 printk(" IOC_VDEC_COAX_TX_CMD_SEND error\n");
501 coax_tx_16bit_cmd_send(&coax_val);
502 break;
503 case IOC_VDEC_COAX_TX_CVI_NEW_CMD_SEND: //SK_CHANGE 170703
504 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
505 printk(" IOC_VDEC_COAX_TX_CMD_SEND error\n");
506 coax_tx_cvi_new_cmd_send(&coax_val);
507 break;
508 case IOC_VDEC_COAX_RX_INIT:
509 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
510 printk(" IOC_VDEC_COAX_RX_INIT error\n");
511 coax_rx_init(&coax_val);
512 break;
513 case IOC_VDEC_COAX_RX_DATA_READ:
514 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
515 printk(" IOC_VDEC_COAX_RX_DATA_READ error\n");
516 coax_rx_data_get(&coax_val);
517 cpy2usr_ret = copy_to_user(argp, &coax_val, sizeof(NC_VD_COAX_STR));
518 break;
519 case IOC_VDEC_COAX_RX_BUF_CLEAR:
520 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
521 printk(" IOC_VDEC_COAX_RX_BUF_CLEAR error\n");
522 coax_rx_buffer_clear(&coax_val);
523 break;
524 case IOC_VDEC_COAX_RX_DEINIT:
525 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
526 printk("IOC_VDEC_COAX_RX_DEINIT error\n");
527 coax_rx_deinit(&coax_val);
528 break;
529 case IOC_VDEC_COAX_BANK_DUMP_GET:
530 if(copy_from_user(&coax_bank_dump, argp, sizeof(NC_VD_COAX_BANK_DUMP_STR)))
531 printk("IOC_VDEC_COAX_BANK_DUMP_GET error\n");
532 coax_test_Bank_dump_get(&coax_bank_dump);
533 cpy2usr_ret = copy_to_user(argp, &coax_bank_dump, sizeof(NC_VD_COAX_BANK_DUMP_STR));
534 break;
535 case IOC_VDEC_COAX_RX_DETECTION_READ:
536 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
537 printk(" IOC_VDEC_COAX_RX_DATA_READ error\n");
538 coax_acp_rx_detect_get(&coax_val);
539 cpy2usr_ret = copy_to_user(argp, &coax_val, sizeof(NC_VD_COAX_STR));
540 break;
541 /*===============================================================================================
542 * Coaxial Protocol. Function
543 *===============================================================================================*/
544 case IOC_VDEC_COAX_RT_NRT_MODE_CHANGE_SET:
545 if(copy_from_user(&coax_val, argp, sizeof(NC_VD_COAX_STR)))
546 printk(" IOC_VDEC_COAX_SHOT_SET error\n");
547 coax_option_rt_nrt_mode_change_set(&coax_val);
548 cpy2usr_ret = copy_to_user(argp, &coax_val, sizeof(NC_VD_COAX_STR));
549 break;
550 case IOC_VDEC_ACP_WRITE:
551 if (copy_from_user(&ispdata, argp, sizeof(nc_acp_rw_data))) {
552 up(&jaguar1_lock);
553 return -1;
554 }
555 if(ispdata.opt == 0)
556 acp_isp_write(ispdata.ch, ispdata.addr, ispdata.data);
557 else
558 {
559 ispdata.data = acp_isp_read(ispdata.ch, ispdata.addr);
560 if(copy_to_user(argp, &ispdata, sizeof(nc_acp_rw_data)))
561 printk("IOC_VDEC_ACP_WRITE error\n");
562 }
563 break;
564 /*===============================================================================================
565 * Coaxial Protocol FW Update
566 *===============================================================================================*/
567 case IOC_VDEC_COAX_FW_ACP_HEADER_GET:
568 if(copy_from_user(&coax_fw_val, argp, sizeof(FIRMWARE_UP_FILE_INFO)))
569 printk("IOC_VDEC_COAX_FW_READY_CMD_SET error\n");
570 coax_fw_ready_header_check_from_isp_recv(&coax_fw_val);
571 cpy2usr_ret = copy_to_user(argp, &coax_fw_val, sizeof(FIRMWARE_UP_FILE_INFO));
572 break;
573 case IOC_VDEC_COAX_FW_READY_CMD_SET:
574 if(copy_from_user(&coax_fw_val, argp, sizeof(FIRMWARE_UP_FILE_INFO)))
575 printk("IOC_VDEC_COAX_FW_READY_CMD_SET error\n");
576 coax_fw_ready_cmd_to_isp_send(&coax_fw_val);
577 cpy2usr_ret = copy_to_user(argp, &coax_fw_val, sizeof(FIRMWARE_UP_FILE_INFO));
578 break;
579 case IOC_VDEC_COAX_FW_READY_ACK_GET:
580 if(copy_from_user(&coax_fw_val, argp, sizeof(FIRMWARE_UP_FILE_INFO)))
581 printk("IOC_VDEC_COAX_FW_READY_ISP_STATUS_GET error\n");
582 coax_fw_ready_cmd_ack_from_isp_recv(&coax_fw_val);
583 cpy2usr_ret = copy_to_user(argp, &coax_fw_val, sizeof(FIRMWARE_UP_FILE_INFO));
584 break;
585 case IOC_VDEC_COAX_FW_START_CMD_SET:
586 if(copy_from_user(&coax_fw_val, argp, sizeof(FIRMWARE_UP_FILE_INFO)))
587 printk("IOC_VDEC_COAX_FW_START_CMD_SET error\n");
588 coax_fw_start_cmd_to_isp_send(&coax_fw_val);
589 cpy2usr_ret = copy_to_user(argp, &coax_fw_val, sizeof(FIRMWARE_UP_FILE_INFO));
590 break;
591 case IOC_VDEC_COAX_FW_START_ACK_GET:
592 if(copy_from_user(&coax_fw_val, argp, sizeof(FIRMWARE_UP_FILE_INFO)))
593 printk("IOC_VDEC_COAX_FW_START_CMD_SET error\n");
594 coax_fw_start_cmd_ack_from_isp_recv(&coax_fw_val);
595 cpy2usr_ret = copy_to_user(argp, &coax_fw_val, sizeof(FIRMWARE_UP_FILE_INFO));
596 break;
597 case IOC_VDEC_COAX_FW_SEND_DATA_SET:
598 if(copy_from_user(&coax_fw_val, argp, sizeof(FIRMWARE_UP_FILE_INFO)))
599 printk("IOC_VDEC_COAX_FW_START_CMD_SET error\n");
600 coax_fw_one_packet_data_to_isp_send(&coax_fw_val);
601 cpy2usr_ret = copy_to_user(argp, &coax_fw_val, sizeof(FIRMWARE_UP_FILE_INFO));
602 break;
603 case IOC_VDEC_COAX_FW_SEND_ACK_GET:
604 if(copy_from_user(&coax_fw_val, argp, sizeof(FIRMWARE_UP_FILE_INFO)))
605 printk("IOC_VDEC_COAX_FW_START_CMD_SET error\n");
606 coax_fw_one_packet_data_ack_from_isp_recv(&coax_fw_val);
607 cpy2usr_ret = copy_to_user(argp, &coax_fw_val, sizeof(FIRMWARE_UP_FILE_INFO));
608 break;
609 case IOC_VDEC_COAX_FW_END_CMD_SET:
610 if(copy_from_user(&coax_fw_val, argp, sizeof(FIRMWARE_UP_FILE_INFO)))
611 printk("IOC_VDEC_COAX_FW_START_CMD_SET error\n");
612 coax_fw_end_cmd_to_isp_send(&coax_fw_val);
613 cpy2usr_ret = copy_to_user(argp, &coax_fw_val, sizeof(FIRMWARE_UP_FILE_INFO));
614 break;
615 case IOC_VDEC_COAX_FW_END_ACK_GET:
616 if(copy_from_user(&coax_fw_val, argp, sizeof(FIRMWARE_UP_FILE_INFO)))
617 printk("IOC_VDEC_COAX_FW_START_CMD_SET error\n");
618 coax_fw_end_cmd_ack_from_isp_recv(&coax_fw_val);
619 cpy2usr_ret = copy_to_user(argp, &coax_fw_val, sizeof(FIRMWARE_UP_FILE_INFO));
620 break;
621 /*===============================================================================================
622 * Test Function
623 *===============================================================================================*/
624 case IOC_VDEC_COAX_TEST_TX_INIT_DATA_READ:
625 if(copy_from_user(&coax_test_val, argp, sizeof(NC_VD_COAX_TEST_STR)))
626 printk("IOC_VDEC_COAX_INIT_SET error\n");
627 coax_test_tx_init_read(&coax_test_val);
628 cpy2usr_ret = copy_to_user(argp, &coax_test_val, sizeof(NC_VD_COAX_TEST_STR));
629 break;
630 case IOC_VDEC_COAX_TEST_DATA_SET:
631 if(copy_from_user(&coax_test_val, argp, sizeof(NC_VD_COAX_TEST_STR)))
632 printk("IOC_VDEC_COAX_TEST_DATA_SET error\n");
633 coax_test_data_set(&coax_test_val);
634 break;
635 case IOC_VDEC_COAX_TEST_DATA_READ:
636 if(copy_from_user(&coax_test_val, argp, sizeof(NC_VD_COAX_TEST_STR)))
637 printk("IOC_VDEC_COAX_TEST_DATA_SET error\n");
638 coax_test_data_get(&coax_test_val);
639 cpy2usr_ret = copy_to_user(argp, &coax_test_val, sizeof(NC_VD_COAX_TEST_STR));
640 break;
641 /*===============================================================================================
642 * Motion
643 *===============================================================================================*/
644 case IOC_VDEC_MOTION_DETECTION_GET :
645 if(copy_from_user(&motion_set, argp, sizeof(motion_set)))
646 printk("IOC_VDEC_MOTION_SET error\n");
647 motion_detection_get(&motion_set);
648 cpy2usr_ret = copy_to_user(argp, &motion_set, sizeof(motion_mode));
649 break;
650 case IOC_VDEC_MOTION_SET :
651 if(copy_from_user(&motion_set, argp, sizeof(motion_set)))
652 printk("IOC_VDEC_MOTION_SET error\n");
653 motion_onoff_set(&motion_set);
654 break;
655 case IOC_VDEC_MOTION_PIXEL_SET :
656 if(copy_from_user(&motion_set, argp, sizeof(motion_set)))
657 printk("IOC_VDEC_MOTION_Pixel_SET error\n");
658 motion_pixel_onoff_set(&motion_set);
659 break;
660 case IOC_VDEC_MOTION_PIXEL_GET :
661 if(copy_from_user(&motion_set, argp, sizeof(motion_set)))
662 printk("IOC_VDEC_MOTION_Pixel_SET error\n");
663 motion_pixel_onoff_get(&motion_set);
664 cpy2usr_ret = copy_to_user(argp, &motion_set, sizeof(motion_mode));
665 break;
666 case IOC_VDEC_MOTION_ALL_PIXEL_SET :
667 if(copy_from_user(&motion_set, argp, sizeof(motion_set)))
668 printk("IOC_VDEC_MOTION_Pixel_SET error\n");
669 motion_pixel_all_onoff_set(&motion_set);
670 break;
671 case IOC_VDEC_MOTION_TSEN_SET :
672 if(copy_from_user(&motion_set, argp, sizeof(motion_set)))
673 printk("IOC_VDEC_MOTION_TSEN_SET error\n");
674 motion_tsen_set(&motion_set);
675 break;
676 case IOC_VDEC_MOTION_PSEN_SET :
677 if(copy_from_user(&motion_set, argp, sizeof(motion_set)))
678 printk("IOC_VDEC_MOTION_PSEN_SET error\n");
679 motion_psen_set(&motion_set);
680 break;
681 /*===============================================================================================
682 * Version
683 *===============================================================================================*/
684 case IOC_VDEC_GET_DRIVERVER :
685 if(copy_to_user(argp, &DRIVER_VER, sizeof(DRIVER_VER)))
686 printk("IOC_VDEC_GET_DRIVERVER error\n");
687 break;
688 }
689
690 up(&jaguar1_lock);
691
692 return 0;
693 }
694
695 /*
696 * mclk
697 * default: 756MHZ
698 * 1: 378MHZ
699 * 2: 594MHZ
700 * 3: 1242MHZ
701 */
jaguar1_set_mclk(unsigned int mclk)702 void jaguar1_set_mclk(unsigned int mclk)
703 {
704 jaguar1_mclk = mclk;
705 }
706
jaguar1_start(video_init_all * video_init)707 void jaguar1_start(video_init_all *video_init)
708 {
709 down(&jaguar1_lock);
710 vd_set_all(video_init);
711 up(&jaguar1_lock);
712 }
713
jaguar1_stop(void)714 void jaguar1_stop(void)
715 {
716 video_input_init video_val;
717
718 down(&jaguar1_lock);
719 arb_disable(0);
720 gpio_i2c_write(0x60, 0xff, 0x20);
721
722 // ARB RESET High
723 gpio_i2c_write(0x60, 0x40, 0x11);
724 usleep_range(3000, 5000);
725 gpio_i2c_write(0x60, 0x40, 0x00);
726 vd_jaguar1_sw_reset(&video_val);
727 up(&jaguar1_lock);
728 }
729
730 /*******************************************************************************
731 * Description : i2c client initial
732 * Argurments : void
733 * Return value : 0
734 * Modify :
735 * warning :
736 *******************************************************************************/
i2c_client_init(int i2c_bus)737 static int i2c_client_init(int i2c_bus)
738 {
739 struct i2c_adapter* i2c_adap;
740
741 printk("[DRV] I2C Client Init \n");
742 i2c_adap = i2c_get_adapter(i2c_bus);
743 if (!i2c_adap)
744 return -EINVAL;
745
746 jaguar1_client = i2c_new_client_device(i2c_adap, &hi_info);
747 i2c_put_adapter(i2c_adap);
748
749 return 0;
750 }
751
752 /*******************************************************************************
753 * Description : i2c client release
754 * Argurments : void
755 * Return value : void
756 * Modify :
757 * warning :
758 *******************************************************************************/
i2c_client_exit(void)759 static void i2c_client_exit(void)
760 {
761 i2c_unregister_device(jaguar1_client);
762 }
763
764 static struct file_operations jaguar1_fops = {
765 .owner = THIS_MODULE,
766 .unlocked_ioctl = jaguar1_ioctl,
767 .open = jaguar1_open,
768 .release = jaguar1_close
769 };
770
771 static struct miscdevice jaguar1_dev = {
772 .minor = MISC_DYNAMIC_MINOR,
773 .name = "jaguar1",
774 .fops = &jaguar1_fops,
775 };
776
jaguar1_init(int i2c_bus)777 int jaguar1_init(int i2c_bus)
778 {
779 int ret = 0;
780 #ifdef FMT_SETTING_SAMPLE
781 int dev_num = 0;
782 #endif
783
784 if (jaguar1_init_state)
785 return 0;
786
787 ret = i2c_client_init(i2c_bus);
788 if (ret) {
789 printk(KERN_ERR "ERROR: could not find jaguar1\n");
790 return ret;
791 }
792
793 /* decoder count function */
794 ret = check_decoder_count();
795 if (ret <= 0) {
796 printk(KERN_ERR "ERROR: could not find jaguar1 devices:%#x\n", ret);
797 i2c_client_exit();
798 return -ENODEV;
799 }
800
801 /* initialize semaphore */
802 sema_init(&jaguar1_lock, 1);
803 down(&jaguar1_lock);
804 video_decoder_init();
805 up(&jaguar1_lock);
806 jaguar1_init_state = true;
807
808 return 0;
809 }
810
jaguar1_exit(void)811 void jaguar1_exit(void)
812 {
813 i2c_client_exit();
814 jaguar1_init_state = false;
815 }
816
817 /*******************************************************************************
818 * Description : It is called when "insmod jaguar1.ko" command run
819 * Argurments : void
820 * Return value : -1(could not register jaguar1 device), 0(success)
821 * Modify :
822 * warning :
823 *******************************************************************************/
jaguar1_module_init(void)824 static int __init jaguar1_module_init(void)
825 {
826 int ret = 0;
827 #ifdef STREAM_ON_DEFLAULT
828 video_init_all sVideoall;
829 int ch;
830
831 jaguar1_mclk= 3;
832 init = true;
833 fmt = 2;
834 #endif
835
836 ret = misc_register(&jaguar1_dev);
837 if (ret)
838 {
839 printk(KERN_ERR "ERROR: could not register jaguar1-i2c :%#x\n", ret);
840 return -1;
841 }
842
843 #ifdef STREAM_ON_DEFLAULT
844 ret = jaguar1_init(I2C_3);
845 if (ret)
846 {
847 printk(KERN_ERR "ERROR: jaguar1 init failed\n");
848 return -1;
849 }
850
851 down(&jaguar1_lock);
852 if(init)
853 {
854 for(ch=0;ch<jaguar1_cnt*4;ch++)
855 {
856 sVideoall.ch_param[ch].ch = ch;
857 switch(fmt)
858 {
859 case 0:
860 sVideoall.ch_param[ch].format = AHD20_SD_H960_2EX_Btype_NT+ntpal;
861 break;
862 case 2:
863 sVideoall.ch_param[ch].format = AHD20_1080P_25P+ntpal;
864 break;
865 case 3:
866 sVideoall.ch_param[ch].format = AHD20_720P_960P_30P+ntpal;
867 break;
868 case 4:
869 sVideoall.ch_param[ch].format = AHD20_SD_SH720_NT+ntpal;
870 break;
871 default:
872 sVideoall.ch_param[ch].format = AHD20_720P_30P_EX_Btype+ntpal;
873 break;
874 }
875 sVideoall.ch_param[ch].input = SINGLE_ENDED;
876 if(ch<chn)
877 sVideoall.ch_param[ch].interface = YUV_422;
878 else
879 sVideoall.ch_param[ch].interface = DISABLE;
880 }
881 vd_set_all(&sVideoall);
882 }
883
884 up(&jaguar1_lock);
885 #endif
886
887 return 0;
888 }
889
890 /*******************************************************************************
891 * Description : It is called when "rmmod nvp61XX_ex.ko" command run
892 * Argurments : void
893 * Return value : void
894 * Modify :
895 * warning :
896 *******************************************************************************/
jaguar1_module_exit(void)897 static void __exit jaguar1_module_exit(void)
898 {
899 #ifdef FOR_IMX6
900 close_imx_mipi();
901 #endif
902 misc_deregister(&jaguar1_dev);
903
904 #ifdef STREAM_ON_DEFLAULT
905 jaguar1_exit();
906 #endif
907
908 printk("JAGUAR1 DEVICE DRIVER UNLOAD SUCCESS\n");
909 }
910
911 module_init(jaguar1_module_init);
912 module_exit(jaguar1_module_exit);
913
914 MODULE_LICENSE("GPL");
915
916 /*******************************************************************************
917 * End of file
918 *******************************************************************************/
919