1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * vehicle sensor nvp6324
4 *
5 * Copyright (C) 2020 Rockchip Electronics Co.Ltd
6 * Authors:
7 * wpzz <randy.wang@rock-chips.com>
8 *
9 */
10
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/delay.h>
15 #include <linux/sched.h>
16 #include <linux/errno.h>
17 #include <linux/sysctl.h>
18 #include <linux/interrupt.h>
19 #include <linux/platform_device.h>
20 #include <linux/proc_fs.h>
21 #include <linux/suspend.h>
22 #include <linux/delay.h>
23 #include <linux/io.h>
24 #include <linux/irq.h>
25 #include <linux/uaccess.h>
26 #include <linux/of_gpio.h>
27 #include <linux/of_irq.h>
28 #include "vehicle_cfg.h"
29 #include "vehicle_main.h"
30 #include "vehicle_ad.h"
31 #include "vehicle_ad_nvp6324.h"
32
33 enum {
34 CVSTD_720P60 = 0,
35 CVSTD_720P50,
36 CVSTD_1080P30,
37 CVSTD_1080P25,
38 CVSTD_720P30,
39 CVSTD_720P25,
40 CVSTD_SVGAP30,
41 CVSTD_SD,
42 CVSTD_NTSC,
43 CVSTD_PAL
44 };
45
46 enum {
47 FORCE_PAL_WIDTH = 960,
48 FORCE_PAL_HEIGHT = 576,
49 FORCE_NTSC_WIDTH = 960,
50 FORCE_NTSC_HEIGHT = 480,
51 FORCE_SVGA_WIDTH = 800,
52 FORCE_SVGA_HEIGHT = 600,
53 FORCE_720P_WIDTH = 1280,
54 FORCE_720P_HEIGHT = 720,
55 FORCE_1080P_WIDTH = 1920,
56 FORCE_1080P_HEIGHT = 1080,
57 FORCE_CIF_OUTPUT_FORMAT = CIF_OUTPUT_FORMAT_420,
58 };
59
60 enum {
61 VIDEO_UNPLUG,
62 VIDEO_IN,
63 VIDEO_LOCKED,
64 VIDEO_UNLOCK
65 };
66
67 #define JAGUAR1_LINK_FREQ_320M 320000000UL
68 #define JAGUAR1_LINK_FREQ_640M 640000000UL
69
70 static struct vehicle_ad_dev *nvp6324_g_addev;
71 static int cvstd_mode = CVSTD_1080P25;
72 //static int cvstd_old = CVSTD_720P25;
73 static int cvstd_old = CVSTD_NTSC;
74
75 //static int cvstd_sd = CVSTD_NTSC;
76 static int cvstd_state = VIDEO_UNPLUG;
77 static int cvstd_old_state = VIDEO_UNLOCK;
78 static int video_mode;
79 static int video_old;
80
81 static bool g_nvp6324_streaming;
82
83 #define SENSOR_REGISTER_LEN 1 /* sensor register address bytes*/
84 #define SENSOR_VALUE_LEN 1 /* sensor register value bytes*/
85 #define JAGUAR1_CHIP_ID 0xB0
86
87 struct rk_sensor_reg {
88 unsigned int reg;
89 unsigned int val;
90 };
91
92 #define SENSOR_CHANNEL_REG 0x41
93
94 #define SEQCMD_END 0xFF000000
95 #define SensorEnd {SEQCMD_END, 0x00}
96
97 #define SENSOR_ID(_msb, _lsb) ((_msb) << 8 | (_lsb))
98
99 /* NTSC Preview resolution setting*/
100 static struct rk_sensor_reg sensor_preview_data_ntsc_30hz[] = {
101 {0xff, 0x04},
102 {0xa0, 0x24},
103 {0xa1, 0x24},
104 {0xa2, 0x24},
105 {0xa3, 0x24},
106 {0xa4, 0x24},
107 {0xa5, 0x24},
108 {0xa6, 0x24},
109 {0xa7, 0x24},
110 {0xa8, 0x24},
111 {0xa9, 0x24},
112 {0xaa, 0x24},
113 {0xab, 0x24},
114 {0xac, 0x24},
115 {0xad, 0x24},
116 {0xae, 0x24},
117 {0xaf, 0x24},
118 {0xb0, 0x24},
119 {0xb1, 0x24},
120 {0xb2, 0x24},
121 {0xb3, 0x24},
122 {0xb4, 0x24},
123 {0xb5, 0x24},
124 {0xb6, 0x24},
125 {0xb7, 0x24},
126 {0xb8, 0x24},
127 {0xb9, 0x24},
128 {0xba, 0x24},
129 {0xbb, 0x24},
130 {0xbc, 0x24},
131 {0xbd, 0x24},
132 {0xbe, 0x24},
133 {0xbf, 0x24},
134 {0xc0, 0x24},
135 {0xc1, 0x24},
136 {0xc2, 0x24},
137 {0xc3, 0x24},
138 {0xff, 0x21},
139 {0x07, 0x80},
140 {0x07, 0x00},
141 {0xff, 0x0A},
142 {0x77, 0x8F},
143 {0xF7, 0x8F},
144 {0xff, 0x0B},
145 {0x77, 0x8F},
146 {0xF7, 0x8F},
147
148 {0xFF, 0x21},
149 {0x40, 0xAC},
150 {0x41, 0x10},
151 {0x42, 0x03},
152 {0x43, 0x43},
153 {0x11, 0x04},
154 {0x10, 0x0A},
155 {0x12, 0x06},
156 {0x13, 0x09},
157 {0x17, 0x01},
158 {0x18, 0x0D},
159 {0x15, 0x04},
160 {0x14, 0x16},
161 {0x16, 0x05},
162 {0x19, 0x05},
163 {0x1A, 0x0A},
164 {0x1B, 0x08},
165 {0x1C, 0x07},
166 {0x44, 0x00},
167 {0x49, 0xF3},
168 {0x49, 0xF0},
169 {0x44, 0x02},
170 {0x08, 0x40}, //0x40:non-continue;0x48:continuous
171 {0x0F, 0x01},
172 {0x38, 0x1E},
173 {0x39, 0x1E},
174 {0x3A, 0x1E},
175 {0x3B, 0x1E},
176 {0x07, 0x0f}, //0x07:2lane;0x0f:4lane
177 {0x2D, 0x01}, //0x00:2lane;0x01:4lane
178 {0x45, 0x02},
179 {0xFF, 0x13},
180 {0x30, 0x00},
181 {0x31, 0x00},
182 {0x32, 0x00},
183
184 {0xFF, 0x00},
185 {0x00, 0x00},
186 {0x01, 0x00},
187 {0x02, 0x00},
188 {0x03, 0x00},
189 {0x04, 0x0e}, //sd_mode
190 {0x05, 0x0e},
191 {0x06, 0x0e},
192 {0x07, 0x0e},
193 {0x08, 0x00}, //ahd_mode
194 {0x09, 0x00},
195 {0x0a, 0x00},
196 {0x0b, 0x00},
197 {0x0c, 0x00},
198 {0x0d, 0x00},
199 {0x0e, 0x00},
200 {0x0f, 0x00},
201 {0x10, 0xa0}, //video_format
202 {0x11, 0xa0},
203 {0x12, 0xa0},
204 {0x13, 0xa0},
205 {0x14, 0x00},
206 {0x15, 0x00},
207 {0x16, 0x00},
208 {0x17, 0x00},
209 {0x18, 0x13},
210 {0x19, 0x13},
211 {0x1a, 0x13},
212 {0x1b, 0x13},
213 {0x1c, 0x1a},
214 {0x1d, 0x1a},
215 {0x1e, 0x1a},
216 {0x1f, 0x1a},
217 {0x20, 0x00},
218 {0x21, 0x00},
219 {0x22, 0x00},
220 {0x23, 0x00},
221 {0x24, 0x90}, //contrast
222 {0x25, 0x90},
223 {0x26, 0x90},
224 {0x27, 0x90},
225 {0x28, 0x90}, //black_level
226 {0x29, 0x90},
227 {0x2a, 0x90},
228 {0x2b, 0x90},
229 {0x30, 0x00}, //y_peaking_mode
230 {0x31, 0x00},
231 {0x32, 0x00},
232 {0x33, 0x00},
233 {0x34, 0x08}, //y_fir_mode
234 {0x35, 0x08},
235 {0x36, 0x08},
236 {0x37, 0x08},
237 {0x40, 0x00},
238 {0x41, 0x00},
239 {0x42, 0x00},
240 {0x43, 0x00},
241 {0x44, 0x00},
242 {0x45, 0x00},
243 {0x46, 0x00},
244 {0x47, 0x00},
245 {0x48, 0x00},
246 {0x49, 0x00},
247 {0x4a, 0x00},
248 {0x4b, 0x00},
249 {0x4c, 0xfe},
250 {0x4d, 0xfe},
251 {0x4e, 0xfe},
252 {0x4f, 0xfe},
253 {0x50, 0xfb},
254 {0x51, 0xfb},
255 {0x52, 0xfb},
256 {0x53, 0xfb},
257 {0x58, 0x80},
258 {0x59, 0x80},
259 {0x5a, 0x80},
260 {0x5b, 0x80},
261 {0x5c, 0x82}, //pal_cm_off
262 {0x5d, 0x82},
263 {0x5e, 0x82},
264 {0x5f, 0x82},
265 {0x60, 0x10},
266 {0x61, 0x10},
267 {0x62, 0x10},
268 {0x63, 0x10},
269 {0x64, 0x18}, //y_delay
270 {0x65, 0x18},
271 {0x66, 0x18},
272 {0x67, 0x18},
273 {0x68, 0x70}, //h_delay_a //h_delay_lsb
274 {0x69, 0x70},
275 {0x6a, 0x70},
276 {0x6b, 0x70},
277 {0x6c, 0x00},
278 {0x6d, 0x00},
279 {0x6e, 0x00},
280 {0x6f, 0x00},
281 {0x70, 0x9e}, //v_crop_start
282 {0x71, 0x9e},
283 {0x72, 0x9e},
284 {0x73, 0x9e},
285 {0x78, 0xc0},
286 {0x79, 0xc0},
287 {0x7a, 0xc0},
288 {0x7b, 0xc0},
289
290 {0xFF, 0x01},
291 {0x7C, 0x00},
292 {0x84, 0x04},
293 {0x85, 0x04},
294 {0x86, 0x04},
295 {0x87, 0x04},
296 {0x88, 0x01},
297 {0x89, 0x01},
298 {0x8a, 0x01},
299 {0x8b, 0x01},
300 {0x8c, 0x02},
301 {0x8d, 0x02},
302 {0x8e, 0x02},
303 {0x8f, 0x02},
304 {0xEC, 0x00},
305 {0xED, 0x00},
306 {0xEE, 0x00},
307 {0xEF, 0x00},
308
309 {0xFF, 0x05},
310 {0x00, 0xd0},
311 {0x01, 0x2c},
312 {0x05, 0x20}, //d_agc_option
313 {0x1d, 0x0c},
314 {0x21, 0x20}, //sub contrast
315 {0x24, 0x2a},
316 {0x25, 0xdc}, //fsc_lock_mode
317 {0x26, 0x40},
318 {0x27, 0x57},
319 {0x28, 0x80}, //s_point
320 {0x2b, 0xc0}, //saturation_b
321 {0x31, 0x82},
322 {0x32, 0x10},
323 {0x38, 0x00},
324 {0x47, 0x04},
325 {0x50, 0x84},
326 {0x53, 0x04},
327 {0x57, 0x00},
328 {0x58, 0x77},
329 {0x59, 0x00},
330 {0x5C, 0x78},
331 {0x5F, 0x00},
332 {0x62, 0x20},
333 {0x64, 0x01},
334 {0x65, 0x00},
335 {0x69, 0x00},
336 {0x6E, 0x00}, //VBLK_EXT_EN
337 {0x6F, 0x00}, //VBLK_EXT_[7:0]
338 {0x90, 0x01}, //comb_mode
339 {0x92, 0x00},
340 {0x94, 0x00},
341 {0x95, 0x00},
342 {0xa9, 0x00},
343 {0xb5, 0x00},
344 {0xb7, 0xfc},
345 {0xb8, 0xb8},
346 {0xb9, 0x72},
347 {0xbb, 0x0f},
348 {0xd1, 0x30}, //burst_dec_c
349 {0xd5, 0x80},
350
351 {0xFF, 0x09},
352 {0x40, 0x00},
353 {0x41, 0x00},
354 {0x42, 0x00},
355 {0x43, 0x00},
356 {0x44, 0x00},
357 {0x45, 0x00},
358 {0x46, 0x00},
359 {0x47, 0x00},
360 {0x50, 0x30},
361 {0x51, 0x6f},
362 {0x52, 0x67},
363 {0x53, 0x48},
364 {0x54, 0x30},
365 {0x55, 0x6f},
366 {0x56, 0x67},
367 {0x57, 0x48},
368 {0x58, 0x30},
369 {0x59, 0x6f},
370 {0x5a, 0x67},
371 {0x5b, 0x48},
372 {0x5c, 0x30},
373 {0x5d, 0x6f},
374 {0x5e, 0x67},
375 {0x5f, 0x48},
376 {0x96, 0x10},
377 {0x97, 0x10},
378 {0x98, 0x00},
379 {0x99, 0x00},
380 {0x9a, 0x00},
381 {0x9b, 0x00},
382 {0x9c, 0x00},
383 {0x9d, 0x00},
384 {0x9e, 0x00},
385 {0xb6, 0x10},
386 {0xb7, 0x10},
387 {0xb8, 0x00},
388 {0xb9, 0x00},
389 {0xba, 0x00},
390 {0xbb, 0x00},
391 {0xbc, 0x00},
392 {0xbd, 0x00},
393 {0xbe, 0x00},
394 {0xd6, 0x10},
395 {0xd7, 0x10},
396 {0xd8, 0x00},
397 {0xd9, 0x00},
398 {0xda, 0x00},
399 {0xdb, 0x00},
400 {0xdc, 0x00},
401 {0xdd, 0x00},
402 {0xde, 0x00},
403 {0xf6, 0x10},
404 {0xf7, 0x10},
405 {0xf8, 0x00},
406 {0xf9, 0x00},
407 {0xfa, 0x00},
408 {0xfb, 0x00},
409 {0xfc, 0x00},
410 {0xfd, 0x00},
411 {0xfe, 0x00},
412
413 {0xff, 0x0a},
414 {0x3d, 0x00},
415 {0x3c, 0x00},
416 {0x30, 0xac},
417 {0x31, 0x78},
418 {0x32, 0x17},
419 {0x33, 0xc1},
420 {0x34, 0x40},
421 {0x35, 0x00},
422 {0x36, 0xc3},
423 {0x37, 0x0a},
424 {0x38, 0x00},
425 {0x39, 0x02},
426 {0x3a, 0x00},
427 {0x3b, 0xb2},
428 {0x25, 0x10},
429 {0x27, 0x1e},
430 {0xbd, 0x00},
431 {0xbc, 0x00},
432 {0xb0, 0xac},
433 {0xb1, 0x78},
434 {0xb2, 0x17},
435 {0xb3, 0xc1},
436 {0xb4, 0x40},
437 {0xb5, 0x00},
438 {0xb6, 0xc3},
439 {0xb7, 0x0a},
440 {0xb8, 0x00},
441 {0xb9, 0x02},
442 {0xba, 0x00},
443 {0xbb, 0xb2},
444 {0xa5, 0x10},
445 {0xa7, 0x1e},
446
447 {0xff, 0x0b},
448 {0x3d, 0x00},
449 {0x3c, 0x00},
450 {0x30, 0xac},
451 {0x31, 0x78},
452 {0x32, 0x17},
453 {0x33, 0xc1},
454 {0x34, 0x40},
455 {0x35, 0x00},
456 {0x36, 0xc3},
457 {0x37, 0x0a},
458 {0x38, 0x00},
459 {0x39, 0x02},
460 {0x3a, 0x00},
461 {0x3b, 0xb2},
462 {0x25, 0x10},
463 {0x27, 0x1e},
464 {0xbd, 0x00},
465 {0xbc, 0x00},
466 {0xb0, 0xac},
467 {0xb1, 0x78},
468 {0xb2, 0x17},
469 {0xb3, 0xc1},
470 {0xb4, 0x40},
471 {0xb5, 0x00},
472 {0xb6, 0xc3},
473 {0xb7, 0x0a},
474 {0xb8, 0x00},
475 {0xb9, 0x02},
476 {0xba, 0x00},
477 {0xbb, 0xb2},
478 {0xa5, 0x10},
479 {0xa7, 0x1e},
480
481 {0xFF, 0x21},
482 {0x3E, 0x00},
483 {0x3F, 0x00},
484 {0xFF, 0x20},
485 {0x01, 0xaa}, //0x00:1/1;0x55:1/2;0xaa:1/4
486 {0x00, 0x00},
487 {0x40, 0x01},
488 {0x0F, 0x00},
489 {0x0D, 0x01}, //0x01:4lane;0x00:2lane
490 {0x40, 0x00},
491 {0x00, 0xff}, //0xff:ch1/2/3/4 0x33:ch1/2 0x11:ch1
492
493 {0xFF, 0x01},
494 {0xC8, 0x00},
495 {0xC9, 0x00},
496 {0xCA, 0x00},
497 {0xCB, 0x00},
498
499 //pattern enabled
500 {0xFF, 0x00},
501 {0x1C, 0x1A},
502 {0x1D, 0x1A},
503 {0x1E, 0x1A},
504 {0x1F, 0x1A},
505
506 {0xFF, 0x05},
507 {0x6A, 0x80},
508 {0xFF, 0x06},
509 {0x6A, 0x80},
510 {0xFF, 0x07},
511 {0x6A, 0x80},
512 {0xFF, 0x08},
513 {0x6A, 0x80},
514 {0xFF, 0x21}, //add frame num
515 {0x3E, 0x11}, //1 : Fix to 1 for Odd Field, 2 for Even Field
516 {0x3F, 0x11}, //1 : Fix to 1 for Odd Field, 2 for Even Field
517 SensorEnd
518 };
519
520 /* Pal Preview resolution setting*/
521 static struct rk_sensor_reg sensor_preview_data_pal_25hz[] = {
522 {0xff, 0x04},
523 {0xa0, 0x24},
524 {0xa1, 0x24},
525 {0xa2, 0x24},
526 {0xa3, 0x24},
527 {0xa4, 0x24},
528 {0xa5, 0x24},
529 {0xa6, 0x24},
530 {0xa7, 0x24},
531 {0xa8, 0x24},
532 {0xa9, 0x24},
533 {0xaa, 0x24},
534 {0xab, 0x24},
535 {0xac, 0x24},
536 {0xad, 0x24},
537 {0xae, 0x24},
538 {0xaf, 0x24},
539 {0xb0, 0x24},
540 {0xb1, 0x24},
541 {0xb2, 0x24},
542 {0xb3, 0x24},
543 {0xb4, 0x24},
544 {0xb5, 0x24},
545 {0xb6, 0x24},
546 {0xb7, 0x24},
547 {0xb8, 0x24},
548 {0xb9, 0x24},
549 {0xba, 0x24},
550 {0xbb, 0x24},
551 {0xbc, 0x24},
552 {0xbd, 0x24},
553 {0xbe, 0x24},
554 {0xbf, 0x24},
555 {0xc0, 0x24},
556 {0xc1, 0x24},
557 {0xc2, 0x24},
558 {0xc3, 0x24},
559 {0xff, 0x21},
560 {0x07, 0x80},
561 {0x07, 0x00},
562 {0xff, 0x0A},
563 {0x77, 0x8F},
564 {0xF7, 0x8F},
565 {0xff, 0x0B},
566 {0x77, 0x8F},
567 {0xF7, 0x8F},
568
569 {0xFF, 0x21},
570 {0x40, 0xAC},
571 {0x41, 0x10},
572 {0x42, 0x03},
573 {0x43, 0x43},
574 {0x11, 0x04},
575 {0x10, 0x0A},
576 {0x12, 0x06},
577 {0x13, 0x09},
578 {0x17, 0x01},
579 {0x18, 0x0D},
580 {0x15, 0x04},
581 {0x14, 0x16},
582 {0x16, 0x05},
583 {0x19, 0x05},
584 {0x1A, 0x0A},
585 {0x1B, 0x08},
586 {0x1C, 0x07},
587 {0x44, 0x00},
588 {0x49, 0xF3},
589 {0x49, 0xF0},
590 {0x44, 0x02},
591 {0x08, 0x40}, //0x40:non-continue;0x48:continuous
592 {0x0F, 0x01},
593 {0x38, 0x1E},
594 {0x39, 0x1E},
595 {0x3A, 0x1E},
596 {0x3B, 0x1E},
597 {0x07, 0x0f}, //0x07:2lane;0x0f:4lane
598 {0x2D, 0x01}, //0x00:2lane;0x01:4lane
599 {0x45, 0x02},
600 {0xFF, 0x13},
601 {0x30, 0x00},
602 {0x31, 0x00},
603 {0x32, 0x00},
604
605 {0xFF, 0x00},
606 {0x00, 0x00},
607 {0x01, 0x00},
608 {0x02, 0x00},
609 {0x03, 0x00},
610 {0x04, 0x0f}, //sd_mode
611 {0x05, 0x0f},
612 {0x06, 0x0f},
613 {0x07, 0x0f},
614 {0x08, 0x00}, //ahd_mode
615 {0x09, 0x00},
616 {0x0a, 0x00},
617 {0x0b, 0x00},
618 {0x0c, 0x00},
619 {0x0d, 0x00},
620 {0x0e, 0x00},
621 {0x0f, 0x00},
622 {0x10, 0xdd}, //video_format
623 {0x11, 0xdd},
624 {0x12, 0xdd},
625 {0x13, 0xdd},
626 {0x14, 0x00},
627 {0x15, 0x00},
628 {0x16, 0x00},
629 {0x17, 0x00},
630 {0x18, 0x13},
631 {0x19, 0x13},
632 {0x1a, 0x13},
633 {0x1b, 0x13},
634 {0x1c, 0x1a},
635 {0x1d, 0x1a},
636 {0x1e, 0x1a},
637 {0x1f, 0x1a},
638 {0x20, 0x00},
639 {0x21, 0x00},
640 {0x22, 0x00},
641 {0x23, 0x00},
642 {0x24, 0x90}, //contrast
643 {0x25, 0x90},
644 {0x26, 0x90},
645 {0x27, 0x90},
646 {0x28, 0x90}, //black_level
647 {0x29, 0x90},
648 {0x2a, 0x90},
649 {0x2b, 0x90},
650 {0x30, 0x00}, //y_peaking_mode
651 {0x31, 0x00},
652 {0x32, 0x00},
653 {0x33, 0x00},
654 {0x34, 0x08}, //y_fir_mode
655 {0x35, 0x08},
656 {0x36, 0x08},
657 {0x37, 0x08},
658 {0x40, 0x00},
659 {0x41, 0x00},
660 {0x42, 0x00},
661 {0x43, 0x00},
662 {0x44, 0x00},
663 {0x45, 0x00},
664 {0x46, 0x00},
665 {0x47, 0x00},
666 {0x48, 0x00},
667 {0x49, 0x00},
668 {0x4a, 0x00},
669 {0x4b, 0x00},
670 {0x4c, 0xfe},
671 {0x4d, 0xfe},
672 {0x4e, 0xfe},
673 {0x4f, 0xfe},
674 {0x50, 0xfb},
675 {0x51, 0xfb},
676 {0x52, 0xfb},
677 {0x53, 0xfb},
678 {0x58, 0x80},
679 {0x59, 0x80},
680 {0x5a, 0x80},
681 {0x5b, 0x80},
682 {0x5c, 0x82}, //pal_cm_off
683 {0x5d, 0x82},
684 {0x5e, 0x82},
685 {0x5f, 0x82},
686 {0x60, 0x10},
687 {0x61, 0x10},
688 {0x62, 0x10},
689 {0x63, 0x10},
690 {0x64, 0x07}, //y_delay
691 {0x65, 0x07},
692 {0x66, 0x07},
693 {0x67, 0x07},
694 {0x68, 0x68}, //h_delay_a //h_delay_lsb
695 {0x69, 0x68},
696 {0x6a, 0x68},
697 {0x6b, 0x68},
698 {0x6c, 0x00},
699 {0x6d, 0x00},
700 {0x6e, 0x00},
701 {0x6f, 0x00},
702 {0x70, 0x3f}, //v_crop_start
703 {0x71, 0x3f},
704 {0x72, 0x3f},
705 {0x73, 0x3f},
706 {0x78, 0x21},
707 {0x79, 0x21},
708 {0x7a, 0x21},
709 {0x7b, 0x21},
710
711 {0xFF, 0x01},
712 {0x7C, 0x00},
713 {0x84, 0x04},
714 {0x85, 0x04},
715 {0x86, 0x04},
716 {0x87, 0x04},
717 {0x88, 0x01},
718 {0x89, 0x01},
719 {0x8a, 0x01},
720 {0x8b, 0x01},
721 {0x8c, 0x02},
722 {0x8d, 0x02},
723 {0x8e, 0x02},
724 {0x8f, 0x02},
725 {0xEC, 0x00},
726 {0xED, 0x00},
727 {0xEE, 0x00},
728 {0xEF, 0x00},
729
730 {0xFF, 0x05},
731 {0x00, 0xd0},
732 {0x01, 0x2c},
733 {0x05, 0x20}, //d_agc_option
734 {0x1d, 0x0c},
735 {0x21, 0x20}, //sub contrast
736 {0x24, 0x2a},
737 {0x25, 0xcc}, //fsc_lock_mode
738 {0x26, 0x40},
739 {0x27, 0x57},
740 {0x28, 0x80}, //s_point
741 {0x2b, 0xc0}, //saturation_b
742 {0x31, 0x02},
743 {0x32, 0x10},
744 {0x38, 0x00},
745 {0x47, 0xEE},
746 {0x50, 0xc6},
747 {0x53, 0x04},
748 {0x57, 0x00},
749 {0x58, 0x77},
750 {0x59, 0x00},
751 {0x5C, 0x78},
752 {0x5F, 0x00},
753 {0x62, 0x20},
754 {0x64, 0x01},
755 {0x65, 0x00},
756 {0x69, 0x00},
757 {0x6E, 0x00}, //VBLK_EXT_EN
758 {0x6F, 0x00}, //VBLK_EXT_[7:0]
759 {0x90, 0x0d}, //comb_mode
760 {0x92, 0x00},
761 {0x94, 0x00},
762 {0x95, 0x00},
763 {0xa9, 0x00},
764 {0xb5, 0x00},
765 {0xb7, 0xfc},
766 {0xb8, 0xb8},
767 {0xb9, 0x72},
768 {0xbb, 0x0f},
769 {0xd1, 0x30}, //burst_dec_c
770 {0xd5, 0x80},
771
772 {0xFF, 0x09},
773 {0x40, 0x00},
774 {0x41, 0x00},
775 {0x42, 0x00},
776 {0x43, 0x00},
777 {0x44, 0x00},
778 {0x45, 0x00},
779 {0x46, 0x00},
780 {0x47, 0x00},
781 {0x50, 0x30},
782 {0x51, 0x6f},
783 {0x52, 0x67},
784 {0x53, 0x48},
785 {0x54, 0x30},
786 {0x55, 0x6f},
787 {0x56, 0x67},
788 {0x57, 0x48},
789 {0x58, 0x30},
790 {0x59, 0x6f},
791 {0x5a, 0x67},
792 {0x5b, 0x48},
793 {0x5c, 0x30},
794 {0x5d, 0x6f},
795 {0x5e, 0x67},
796 {0x5f, 0x48},
797 {0x96, 0x10},
798 {0x97, 0x10},
799 {0x98, 0x00},
800 {0x99, 0x00},
801 {0x9a, 0x00},
802 {0x9b, 0x00},
803 {0x9c, 0x00},
804 {0x9d, 0x00},
805 {0x9e, 0x00},
806 {0xb6, 0x10},
807 {0xb7, 0x10},
808 {0xb8, 0x00},
809 {0xb9, 0x00},
810 {0xba, 0x00},
811 {0xbb, 0x00},
812 {0xbc, 0x00},
813 {0xbd, 0x00},
814 {0xbe, 0x00},
815 {0xd6, 0x10},
816 {0xd7, 0x10},
817 {0xd8, 0x00},
818 {0xd9, 0x00},
819 {0xda, 0x00},
820 {0xdb, 0x00},
821 {0xdc, 0x00},
822 {0xdd, 0x00},
823 {0xde, 0x00},
824 {0xf6, 0x10},
825 {0xf7, 0x10},
826 {0xf8, 0x00},
827 {0xf9, 0x00},
828 {0xfa, 0x00},
829 {0xfb, 0x00},
830 {0xfc, 0x00},
831 {0xfd, 0x00},
832 {0xfe, 0x00},
833
834 {0xff, 0x0a},
835 {0x3d, 0x00},
836 {0x3c, 0x00},
837 {0x30, 0xac},
838 {0x31, 0x78},
839 {0x32, 0x17},
840 {0x33, 0xc1},
841 {0x34, 0x40},
842 {0x35, 0x00},
843 {0x36, 0xc3},
844 {0x37, 0x0a},
845 {0x38, 0x00},
846 {0x39, 0x02},
847 {0x3a, 0x00},
848 {0x3b, 0xb2},
849 {0x25, 0x10},
850 {0x27, 0x1e},
851 {0xbd, 0x00},
852 {0xbc, 0x00},
853 {0xb0, 0xac},
854 {0xb1, 0x78},
855 {0xb2, 0x17},
856 {0xb3, 0xc1},
857 {0xb4, 0x40},
858 {0xb5, 0x00},
859 {0xb6, 0xc3},
860 {0xb7, 0x0a},
861 {0xb8, 0x00},
862 {0xb9, 0x02},
863 {0xba, 0x00},
864 {0xbb, 0xb2},
865 {0xa5, 0x10},
866 {0xa7, 0x1e},
867
868 {0xff, 0x0b},
869 {0x3d, 0x00},
870 {0x3c, 0x00},
871 {0x30, 0xac},
872 {0x31, 0x78},
873 {0x32, 0x17},
874 {0x33, 0xc1},
875 {0x34, 0x40},
876 {0x35, 0x00},
877 {0x36, 0xc3},
878 {0x37, 0x0a},
879 {0x38, 0x00},
880 {0x39, 0x02},
881 {0x3a, 0x00},
882 {0x3b, 0xb2},
883 {0x25, 0x10},
884 {0x27, 0x1e},
885 {0xbd, 0x00},
886 {0xbc, 0x00},
887 {0xb0, 0xac},
888 {0xb1, 0x78},
889 {0xb2, 0x17},
890 {0xb3, 0xc1},
891 {0xb4, 0x40},
892 {0xb5, 0x00},
893 {0xb6, 0xc3},
894 {0xb7, 0x0a},
895 {0xb8, 0x00},
896 {0xb9, 0x02},
897 {0xba, 0x00},
898 {0xbb, 0xb2},
899 {0xa5, 0x10},
900 {0xa7, 0x1e},
901
902 {0xFF, 0x21},
903 {0x3E, 0x00},
904 {0x3F, 0x00},
905 {0xFF, 0x20},
906 {0x01, 0xaa}, //0x00:1/1;0x55:1/2;0xaa:1/4
907 {0x00, 0x00},
908 {0x40, 0x01},
909 {0x0F, 0x00},
910 {0x0D, 0x01}, //0x01:4lane;0x00:2lane
911 {0x40, 0x00},
912 {0x00, 0xff}, //0xff:ch1/2/3/4 0x33:ch1/2 0x11:ch1
913
914 {0xFF, 0x01},
915 {0xC8, 0x00},
916 {0xC9, 0x00},
917 {0xCA, 0x00},
918 {0xCB, 0x00},
919
920 //pattern enabled
921 {0xFF, 0x00},
922 {0x1C, 0x1A},
923 {0x1D, 0x1A},
924 {0x1E, 0x1A},
925 {0x1F, 0x1A},
926
927 {0xFF, 0x05},
928 {0x6A, 0x80},
929 {0xFF, 0x06},
930 {0x6A, 0x80},
931 {0xFF, 0x07},
932 {0x6A, 0x80},
933 {0xFF, 0x08},
934 {0x6A, 0x80},
935 {0xFF, 0x21}, //add frame num
936 {0x3E, 0x11}, //1 : Fix to 1 for Odd Field, 2 for Even Field
937 {0x3F, 0x11}, //1 : Fix to 1 for Odd Field, 2 for Even Field
938 SensorEnd
939 };
940
941 /* 720p Preview resolution setting*/
942 static struct rk_sensor_reg sensor_preview_data_720p_25hz[] = {
943 {0xff, 0x04},
944 {0xa0, 0x24},
945 {0xa1, 0x24},
946 {0xa2, 0x24},
947 {0xa3, 0x24},
948 {0xa4, 0x24},
949 {0xa5, 0x24},
950 {0xa6, 0x24},
951 {0xa7, 0x24},
952 {0xa8, 0x24},
953 {0xa9, 0x24},
954 {0xaa, 0x24},
955 {0xab, 0x24},
956 {0xac, 0x24},
957 {0xad, 0x24},
958 {0xae, 0x24},
959 {0xaf, 0x24},
960 {0xb0, 0x24},
961 {0xb1, 0x24},
962 {0xb2, 0x24},
963 {0xb3, 0x24},
964 {0xb4, 0x24},
965 {0xb5, 0x24},
966 {0xb6, 0x24},
967 {0xb7, 0x24},
968 {0xb8, 0x24},
969 {0xb9, 0x24},
970 {0xba, 0x24},
971 {0xbb, 0x24},
972 {0xbc, 0x24},
973 {0xbd, 0x24},
974 {0xbe, 0x24},
975 {0xbf, 0x24},
976 {0xc0, 0x24},
977 {0xc1, 0x24},
978 {0xc2, 0x24},
979 {0xc3, 0x24},
980 {0xff, 0x21},
981 {0x07, 0x80},
982 {0x07, 0x00},
983 {0xff, 0x0A},
984 {0x77, 0x8F},
985 {0xF7, 0x8F},
986 {0xff, 0x0B},
987 {0x77, 0x8F},
988 {0xF7, 0x8F},
989 {0xFF, 0x21},
990 {0x40, 0xAC},
991 {0x41, 0x10},
992 {0x42, 0x03},
993 {0x43, 0x43},
994 {0x11, 0x04},
995 {0x10, 0x0A},
996 {0x12, 0x06},
997 {0x13, 0x09},
998 {0x17, 0x01},
999 {0x18, 0x0D},
1000 {0x15, 0x04},
1001 {0x14, 0x16},
1002 {0x16, 0x05},
1003 {0x19, 0x05},
1004 {0x1A, 0x0A},
1005 {0x1B, 0x08},
1006 {0x1C, 0x07},
1007 {0x44, 0x00},
1008 {0x49, 0xF3},
1009 {0x49, 0xF0},
1010 {0x44, 0x02},
1011 {0x08, 0x40}, //0x40:non-continue;0x48:continuous
1012 {0x0F, 0x01},
1013 {0x38, 0x1E},
1014 {0x39, 0x1E},
1015 {0x3A, 0x1E},
1016 {0x3B, 0x1E},
1017 {0x07, 0x0f}, //0x07:2lane;0x0f:4lane
1018 {0x2D, 0x01}, //0x00:2lane;0x01:4lane
1019 {0x45, 0x02},
1020 {0xFF, 0x13},
1021 {0x30, 0x00},
1022 {0x31, 0x00},
1023 {0x32, 0x00},
1024 {0xFF, 0x00},
1025 {0x00, 0x00},
1026 {0x01, 0x00},
1027 {0x02, 0x00},
1028 {0x03, 0x00},
1029 {0x04, 0x00}, //sd_mode
1030 {0x05, 0x00},
1031 {0x06, 0x00},
1032 {0x07, 0x00},
1033 {0x08, 0x0d}, //ahd_mode
1034 {0x09, 0x0d},
1035 {0x0a, 0x0d},
1036 {0x0b, 0x0d},
1037 {0x0c, 0x00},
1038 {0x0d, 0x00},
1039 {0x0e, 0x00},
1040 {0x0f, 0x00},
1041 {0x10, 0x20}, //video_format
1042 {0x11, 0x20},
1043 {0x12, 0x20},
1044 {0x13, 0x20},
1045 {0x14, 0x00},
1046 {0x15, 0x00},
1047 {0x16, 0x00},
1048 {0x17, 0x00},
1049 {0x18, 0x13},
1050 {0x19, 0x13},
1051 {0x1a, 0x13},
1052 {0x1b, 0x13},
1053 {0x1c, 0x1a},
1054 {0x1d, 0x1a},
1055 {0x1e, 0x1a},
1056 {0x1f, 0x1a},
1057 {0x20, 0x00},
1058 {0x21, 0x00},
1059 {0x22, 0x00},
1060 {0x23, 0x00},
1061 {0x24, 0x88}, //contrast
1062 {0x25, 0x88},
1063 {0x26, 0x88},
1064 {0x27, 0x88},
1065 {0x28, 0x84}, //black_level
1066 {0x29, 0x84},
1067 {0x2a, 0x84},
1068 {0x2b, 0x84},
1069 {0x30, 0x03}, //y_peaking_mode
1070 {0x31, 0x03},
1071 {0x32, 0x03},
1072 {0x33, 0x03},
1073 {0x34, 0x0f}, //y_fir_mode
1074 {0x35, 0x0f},
1075 {0x36, 0x0f},
1076 {0x37, 0x0f},
1077 {0x40, 0x00},
1078 {0x41, 0x00},
1079 {0x42, 0x00},
1080 {0x43, 0x00},
1081 {0x44, 0x00},
1082 {0x45, 0x00},
1083 {0x46, 0x00},
1084 {0x47, 0x00},
1085 {0x48, 0x00},
1086 {0x49, 0x00},
1087 {0x4a, 0x00},
1088 {0x4b, 0x00},
1089 {0x4c, 0x00},
1090 {0x4d, 0x00},
1091 {0x4e, 0x00},
1092 {0x4f, 0x00},
1093 {0x50, 0x00},
1094 {0x51, 0x00},
1095 {0x52, 0x00},
1096 {0x53, 0x00},
1097 {0x58, 0x80},
1098 {0x59, 0x80},
1099 {0x5a, 0x80},
1100 {0x5b, 0x80},
1101 {0x5c, 0x82}, //pal_cm_off
1102 {0x5d, 0x82},
1103 {0x5e, 0x82},
1104 {0x5f, 0x82},
1105 {0x60, 0x10},
1106 {0x61, 0x10},
1107 {0x62, 0x10},
1108 {0x63, 0x10},
1109 {0x64, 0x05}, //y_delay
1110 {0x65, 0x05},
1111 {0x66, 0x05},
1112 {0x67, 0x05},
1113 {0x68, 0x43}, //h_delay_a //h_delay_lsb
1114 {0x69, 0x43},
1115 {0x6a, 0x43},
1116 {0x6b, 0x43},
1117 {0x6c, 0x00},
1118 {0x6d, 0x00},
1119 {0x6e, 0x00},
1120 {0x6f, 0x00},
1121 {0x78, 0x21},
1122 {0x79, 0x21},
1123 {0x7a, 0x21},
1124 {0x7b, 0x21},
1125 {0xFF, 0x01},
1126 {0x7C, 0x00},
1127 {0x84, 0x04},
1128 {0x85, 0x04},
1129 {0x86, 0x04},
1130 {0x87, 0x04},
1131 {0x88, 0x01},
1132 {0x89, 0x01},
1133 {0x8a, 0x01},
1134 {0x8b, 0x01},
1135 {0x8c, 0x02},
1136 {0x8d, 0x02},
1137 {0x8e, 0x02},
1138 {0x8f, 0x02},
1139 {0xEC, 0x00},
1140 {0xED, 0x00},
1141 {0xEE, 0x00},
1142 {0xEF, 0x00},
1143 {0xFF, 0x05},
1144 {0x00, 0xd0},
1145 {0x01, 0x2c},
1146 {0x05, 0x24}, //d_agc_option
1147 {0x1d, 0x0c},
1148 {0x24, 0x2a},
1149 {0x25, 0xdc}, //fsc_lock_mode
1150 {0x26, 0x40},
1151 {0x27, 0x57},
1152 {0x28, 0x80}, //s_point
1153 {0x2b, 0xa8}, //saturation_b
1154 {0x31, 0x82},
1155 {0x32, 0x10},
1156 {0x38, 0x00}, //burst_dec_b
1157 {0x47, 0xEE},
1158 {0x50, 0xc6},
1159 {0x53, 0x00},
1160 {0x57, 0x00},
1161 {0x58, 0x77},
1162 {0x59, 0x00},
1163 {0x5C, 0x78},
1164 {0x5F, 0x00},
1165 {0x62, 0x20},
1166 {0x64, 0x00},
1167 {0x65, 0x00},
1168 {0x69, 0x00},
1169 {0x6E, 0x00}, //VBLK_EXT_EN
1170 {0x6F, 0x00}, //VBLK_EXT_[7:0]
1171 {0x90, 0x01}, //comb_mode
1172 {0x92, 0x00},
1173 {0x94, 0x00},
1174 {0x95, 0x00},
1175 {0xa9, 0x00},
1176 {0xb5, 0x80},
1177 {0xb7, 0xfc},
1178 {0xb8, 0x39},
1179 {0xb9, 0x72},
1180 {0xbb, 0x0f},
1181 {0xd1, 0x30}, //burst_dec_c
1182 {0xd5, 0x80},
1183 {0xFF, 0x09},
1184 {0x40, 0x00},
1185 {0x41, 0x00},
1186 {0x42, 0x00},
1187 {0x43, 0x00},
1188 {0x44, 0x00},
1189 {0x45, 0x00},
1190 {0x46, 0x00},
1191 {0x47, 0x00},
1192 {0x50, 0x30},
1193 {0x51, 0x6f},
1194 {0x52, 0x67},
1195 {0x53, 0x48},
1196 {0x54, 0x30},
1197 {0x55, 0x6f},
1198 {0x56, 0x67},
1199 {0x57, 0x48},
1200 {0x58, 0x30},
1201 {0x59, 0x6f},
1202 {0x5a, 0x67},
1203 {0x5b, 0x48},
1204 {0x5c, 0x30},
1205 {0x5d, 0x6f},
1206 {0x5e, 0x67},
1207 {0x5f, 0x48},
1208 {0x96, 0x00},
1209 {0x97, 0x00},
1210 {0x98, 0x00},
1211 {0x99, 0x00},
1212 {0x9a, 0x00},
1213 {0x9b, 0x00},
1214 {0x9c, 0x00},
1215 {0x9d, 0x00},
1216 {0x9e, 0x00},
1217 {0xb6, 0x00},
1218 {0xb7, 0x00},
1219 {0xb8, 0x00},
1220 {0xb9, 0x00},
1221 {0xba, 0x00},
1222 {0xbb, 0x00},
1223 {0xbc, 0x00},
1224 {0xbd, 0x00},
1225 {0xbe, 0x00},
1226 {0xd6, 0x00},
1227 {0xd7, 0x00},
1228 {0xd8, 0x00},
1229 {0xd9, 0x00},
1230 {0xda, 0x00},
1231 {0xdb, 0x00},
1232 {0xdc, 0x00},
1233 {0xdd, 0x00},
1234 {0xde, 0x00},
1235 {0xf6, 0x00},
1236 {0xf7, 0x00},
1237 {0xf8, 0x00},
1238 {0xf9, 0x00},
1239 {0xfa, 0x00},
1240 {0xfb, 0x00},
1241 {0xfc, 0x00},
1242 {0xfd, 0x00},
1243 {0xfe, 0x00},
1244 {0xff, 0x0a},
1245 {0x3d, 0x00},
1246 {0x3c, 0x00},
1247 {0x30, 0xac},
1248 {0x31, 0x78},
1249 {0x32, 0x17},
1250 {0x33, 0xc1},
1251 {0x34, 0x40},
1252 {0x35, 0x00},
1253 {0x36, 0xc3},
1254 {0x37, 0x0a},
1255 {0x38, 0x00},
1256 {0x39, 0x02},
1257 {0x3a, 0x00},
1258 {0x3b, 0xb2},
1259 {0x25, 0x10},
1260 {0x27, 0x1e},
1261 {0xbd, 0x00},
1262 {0xbc, 0x00},
1263 {0xb0, 0xac},
1264 {0xb1, 0x78},
1265 {0xb2, 0x17},
1266 {0xb3, 0xc1},
1267 {0xb4, 0x40},
1268 {0xb5, 0x00},
1269 {0xb6, 0xc3},
1270 {0xb7, 0x0a},
1271 {0xb8, 0x00},
1272 {0xb9, 0x02},
1273 {0xba, 0x00},
1274 {0xbb, 0xb2},
1275 {0xa5, 0x10},
1276 {0xa7, 0x1e},
1277 {0xff, 0x0b},
1278 {0x3d, 0x00},
1279 {0x3c, 0x00},
1280 {0x30, 0xac},
1281 {0x31, 0x78},
1282 {0x32, 0x17},
1283 {0x33, 0xc1},
1284 {0x34, 0x40},
1285 {0x35, 0x00},
1286 {0x36, 0xc3},
1287 {0x37, 0x0a},
1288 {0x38, 0x00},
1289 {0x39, 0x02},
1290 {0x3a, 0x00},
1291 {0x3b, 0xb2},
1292 {0x25, 0x10},
1293 {0x27, 0x1e},
1294 {0xbd, 0x00},
1295 {0xbc, 0x00},
1296 {0xb0, 0xac},
1297 {0xb1, 0x78},
1298 {0xb2, 0x17},
1299 {0xb3, 0xc1},
1300 {0xb4, 0x40},
1301 {0xb5, 0x00},
1302 {0xb6, 0xc3},
1303 {0xb7, 0x0a},
1304 {0xb8, 0x00},
1305 {0xb9, 0x02},
1306 {0xba, 0x00},
1307 {0xbb, 0xb2},
1308 {0xa5, 0x10},
1309 {0xa7, 0x1e},
1310 {0xFF, 0x21},
1311 {0x3E, 0x00},
1312 {0x3F, 0x00},
1313 {0xFF, 0x20},
1314 {0x01, 0x55},
1315 {0x00, 0x00},
1316 {0x40, 0x01},
1317 {0x0F, 0x00},
1318 {0x0D, 0x01}, //0x01:4lane;0x00:2lane
1319 {0x40, 0x00},
1320 {0x00, 0xFF}, //ch1/2/3/4 enabled
1321 //{0x00, 0x33}, //ch1/2 enabled
1322 //{0x00, 0x11}, //ch1 enabled
1323 {0xFF, 0x01},
1324 {0xC8, 0x00},
1325 {0xC9, 0x00},
1326 {0xCA, 0x00},
1327 {0xCB, 0x00},
1328 //pattern enabled
1329 {0xFF, 0x00},
1330 {0x1C, 0x1A},
1331 {0x1D, 0x1A},
1332 {0x1E, 0x1A},
1333 {0x1F, 0x1A},
1334 {0xFF, 0x05},
1335 {0x6A, 0x80},
1336 {0xFF, 0x06},
1337 {0x6A, 0x80},
1338 {0xFF, 0x07},
1339 {0x6A, 0x80},
1340 {0xFF, 0x08},
1341 {0x6A, 0x80},
1342 SensorEnd
1343 };
1344
1345 /* 1080p Preview resolution setting*/
1346 static struct rk_sensor_reg sensor_preview_data_1080p_25hz[] = {
1347 {0xff, 0x04},
1348 {0xa0, 0x24},
1349 {0xa1, 0x24},
1350 {0xa2, 0x24},
1351 {0xa3, 0x24},
1352 {0xa4, 0x24},
1353 {0xa5, 0x24},
1354 {0xa6, 0x24},
1355 {0xa7, 0x24},
1356 {0xa8, 0x24},
1357 {0xa9, 0x24},
1358 {0xaa, 0x24},
1359 {0xab, 0x24},
1360 {0xac, 0x24},
1361 {0xad, 0x24},
1362 {0xae, 0x24},
1363 {0xaf, 0x24},
1364 {0xb0, 0x24},
1365 {0xb1, 0x24},
1366 {0xb2, 0x24},
1367 {0xb3, 0x24},
1368 {0xb4, 0x24},
1369 {0xb5, 0x24},
1370 {0xb6, 0x24},
1371 {0xb7, 0x24},
1372 {0xb8, 0x24},
1373 {0xb9, 0x24},
1374 {0xba, 0x24},
1375 {0xbb, 0x24},
1376 {0xbc, 0x24},
1377 {0xbd, 0x24},
1378 {0xbe, 0x24},
1379 {0xbf, 0x24},
1380 {0xc0, 0x24},
1381 {0xc1, 0x24},
1382 {0xc2, 0x24},
1383 {0xc3, 0x24},
1384 {0xff, 0x21},
1385 {0x07, 0x80},
1386 {0x07, 0x00},
1387 {0xff, 0x0A},
1388 {0x77, 0x8F},
1389 {0xF7, 0x8F},
1390 {0xff, 0x0B},
1391 {0x77, 0x8F},
1392 {0xF7, 0x8F},
1393 {0xFF, 0x21},
1394 {0x40, 0xB4},
1395 {0x41, 0x00},
1396 {0x42, 0x03},
1397 {0x43, 0x43},
1398 {0x11, 0x08},
1399 {0x10, 0x13},
1400 {0x12, 0x0B},
1401 {0x13, 0x12},
1402 {0x17, 0x02},
1403 {0x18, 0x12},
1404 {0x15, 0x07},
1405 {0x14, 0x2D},
1406 {0x16, 0x0B},
1407 {0x19, 0x09},
1408 {0x1A, 0x15},
1409 {0x1B, 0x11},
1410 {0x1C, 0x0E},
1411 {0x44, 0x00},
1412 {0x49, 0xF3},
1413 {0x49, 0xF0},
1414 {0x44, 0x02},
1415 {0x08, 0x40}, //0x40:non-continue;0x48:continuous
1416 {0x0F, 0x01},
1417 {0x38, 0x1E},
1418 {0x39, 0x1E},
1419 {0x3A, 0x1E},
1420 {0x3B, 0x1E},
1421 {0x07, 0x0f}, //0x07:2lane;0x0f:4lane
1422 {0x2D, 0x01}, //0x00:2lane;0x01:4lane
1423 {0x45, 0x02},
1424 {0xFF, 0x13},
1425 {0x30, 0x00},
1426 {0x31, 0x00},
1427 {0x32, 0x00},
1428 {0xFF, 0x00},
1429 {0x00, 0x00},
1430 {0x01, 0x00},
1431 {0x02, 0x00},
1432 {0x03, 0x00},
1433 {0x04, 0x00}, //sd_mode
1434 {0x05, 0x00},
1435 {0x06, 0x00},
1436 {0x07, 0x00},
1437 {0x08, 0x03}, //ahd_mode
1438 {0x09, 0x03},
1439 {0x0a, 0x03},
1440 {0x0b, 0x03},
1441 {0x0c, 0x00},
1442 {0x0d, 0x00},
1443 {0x0e, 0x00},
1444 {0x0f, 0x00},
1445 {0x10, 0x20}, //video_format
1446 {0x11, 0x20},
1447 {0x12, 0x20},
1448 {0x13, 0x20},
1449 {0x14, 0x00},
1450 {0x15, 0x00},
1451 {0x16, 0x00},
1452 {0x17, 0x00},
1453 {0x18, 0x13},
1454 {0x19, 0x13},
1455 {0x1a, 0x13},
1456 {0x1b, 0x13},
1457 {0x1c, 0x1a},
1458 {0x1d, 0x1a},
1459 {0x1e, 0x1a},
1460 {0x1f, 0x1a},
1461 {0x20, 0x00},
1462 {0x21, 0x00},
1463 {0x22, 0x00},
1464 {0x23, 0x00},
1465 {0x24, 0x86}, //contrast
1466 {0x25, 0x86},
1467 {0x26, 0x86},
1468 {0x27, 0x86},
1469 {0x28, 0x80}, //black_level
1470 {0x29, 0x80},
1471 {0x2a, 0x80},
1472 {0x2b, 0x80},
1473 {0x30, 0x00}, //y_peaking_mode
1474 {0x31, 0x00},
1475 {0x32, 0x00},
1476 {0x33, 0x00},
1477 {0x34, 0x00}, //y_fir_mode
1478 {0x35, 0x00},
1479 {0x36, 0x00},
1480 {0x37, 0x00},
1481 {0x40, 0x00},
1482 {0x41, 0x00},
1483 {0x42, 0x00},
1484 {0x43, 0x00},
1485 {0x44, 0x00},
1486 {0x45, 0x00},
1487 {0x46, 0x00},
1488 {0x47, 0x00},
1489 {0x48, 0x00},
1490 {0x49, 0x00},
1491 {0x4a, 0x00},
1492 {0x4b, 0x00},
1493 {0x4c, 0xfe},
1494 {0x4d, 0xfe},
1495 {0x4e, 0xfe},
1496 {0x4f, 0xfe},
1497 {0x50, 0xfb},
1498 {0x51, 0xfb},
1499 {0x52, 0xfb},
1500 {0x53, 0xfb},
1501 {0x58, 0x80},
1502 {0x59, 0x80},
1503 {0x5a, 0x80},
1504 {0x5b, 0x80},
1505 {0x5c, 0x82}, //pal_cm_off
1506 {0x5d, 0x82},
1507 {0x5e, 0x82},
1508 {0x5f, 0x82},
1509 {0x60, 0x10},
1510 {0x61, 0x10},
1511 {0x62, 0x10},
1512 {0x63, 0x10},
1513 {0x64, 0x05}, //y_delay
1514 {0x65, 0x05},
1515 {0x66, 0x05},
1516 {0x67, 0x05},
1517 {0x68, 0x48}, //h_delay_a //h_delay_lsb
1518 {0x69, 0x48},
1519 {0x6a, 0x48},
1520 {0x6b, 0x48},
1521 {0x6c, 0x00},
1522 {0x6d, 0x00},
1523 {0x6e, 0x00},
1524 {0x6f, 0x00},
1525 // {0x78, 0x21},
1526 // {0x79, 0x21},
1527 // {0x7a, 0x21},
1528 // {0x7b, 0x21},
1529 {0x78, 0x22},
1530 {0x79, 0x22},
1531 {0x7a, 0x22},
1532 {0x7b, 0x22},
1533 {0xFF, 0x01},
1534 {0x7C, 0x00},
1535 {0x84, 0x04},
1536 {0x85, 0x04},
1537 {0x86, 0x04},
1538 {0x87, 0x04},
1539 {0x88, 0x01},
1540 {0x89, 0x01},
1541 {0x8a, 0x01},
1542 {0x8b, 0x01},
1543 {0x8c, 0x02},
1544 {0x8d, 0x02},
1545 {0x8e, 0x02},
1546 {0x8f, 0x02},
1547 {0xEC, 0x00},
1548 {0xED, 0x00},
1549 {0xEE, 0x00},
1550 {0xEF, 0x00},
1551 {0xFF, 0x05},
1552 {0x00, 0xd0},
1553 {0x01, 0x2c},
1554 {0x05, 0x24}, //d_agc_option
1555 {0x1d, 0x0c},
1556 {0x24, 0x2a},
1557 {0x25, 0xdc}, //fsc_lock_mode
1558 {0x26, 0x40},
1559 {0x27, 0x57},
1560 {0x28, 0x80}, //s_point
1561 {0x2b, 0xa8}, //saturation_b
1562 {0x31, 0x82},
1563 {0x32, 0x10},
1564 {0x38, 0x13},
1565 {0x47, 0xEE},
1566 {0x50, 0xc6},
1567 {0x53, 0x00},
1568 {0x57, 0x00},
1569 {0x58, 0x77},
1570 {0x59, 0x00},
1571 {0x5C, 0x78},
1572 {0x5F, 0x00},
1573 {0x62, 0x20},
1574 {0x64, 0x00},
1575 {0x65, 0x00},
1576 {0x69, 0x00},
1577 {0x6E, 0x00}, //VBLK_EXT_EN
1578 {0x6F, 0x00}, //VBLK_EXT_[7:0]
1579 {0x90, 0x01}, //comb_mode
1580 {0x92, 0x00},
1581 {0x94, 0x00},
1582 {0x95, 0x00},
1583 {0xa9, 0x00},
1584 {0xb5, 0x80},
1585 {0xb7, 0xfc},
1586 {0xb8, 0x39},
1587 {0xb9, 0x72},
1588 {0xbb, 0x0f},
1589 {0xd1, 0x30}, //burst_dec_c
1590 {0xd5, 0x80},
1591 {0xFF, 0x09},
1592 {0x40, 0x00},
1593 {0x41, 0x00},
1594 {0x42, 0x00},
1595 {0x43, 0x00},
1596 {0x44, 0x00},
1597 {0x45, 0x00},
1598 {0x46, 0x00},
1599 {0x47, 0x00},
1600 {0x50, 0x30},
1601 {0x51, 0x6f},
1602 {0x52, 0x67},
1603 {0x53, 0x48},
1604 {0x54, 0x30},
1605 {0x55, 0x6f},
1606 {0x56, 0x67},
1607 {0x57, 0x48},
1608 {0x58, 0x30},
1609 {0x59, 0x6f},
1610 {0x5a, 0x67},
1611 {0x5b, 0x48},
1612 {0x5c, 0x30},
1613 {0x5d, 0x6f},
1614 {0x5e, 0x67},
1615 {0x5f, 0x48},
1616 {0x96, 0x00},
1617 {0x97, 0x00},
1618 {0x98, 0x00},
1619 {0x99, 0x00},
1620 {0x9a, 0x00},
1621 {0x9b, 0x00},
1622 {0x9c, 0x00},
1623 {0x9d, 0x00},
1624 {0x9e, 0x00},
1625 {0xb6, 0x00},
1626 {0xb7, 0x00},
1627 {0xb8, 0x00},
1628 {0xb9, 0x00},
1629 {0xba, 0x00},
1630 {0xbb, 0x00},
1631 {0xbc, 0x00},
1632 {0xbd, 0x00},
1633 {0xbe, 0x00},
1634 {0xd6, 0x00},
1635 {0xd7, 0x00},
1636 {0xd8, 0x00},
1637 {0xd9, 0x00},
1638 {0xda, 0x00},
1639 {0xdb, 0x00},
1640 {0xdc, 0x00},
1641 {0xdd, 0x00},
1642 {0xde, 0x00},
1643 {0xf6, 0x00},
1644 {0xf7, 0x00},
1645 {0xf8, 0x00},
1646 {0xf9, 0x00},
1647 {0xfa, 0x00},
1648 {0xfb, 0x00},
1649 {0xfc, 0x00},
1650 {0xfd, 0x00},
1651 {0xfe, 0x00},
1652 {0xff, 0x0a},
1653 {0x3d, 0x00},
1654 {0x3c, 0x00},
1655 {0x30, 0xac},
1656 {0x31, 0x78},
1657 {0x32, 0x17},
1658 {0x33, 0xc1},
1659 {0x34, 0x40},
1660 {0x35, 0x00},
1661 {0x36, 0xc3},
1662 {0x37, 0x0a},
1663 {0x38, 0x00},
1664 {0x39, 0x02},
1665 {0x3a, 0x00},
1666 {0x3b, 0xb2},
1667 {0x25, 0x10},
1668 {0x27, 0x1e},
1669 {0xbd, 0x00},
1670 {0xbc, 0x00},
1671 {0xb0, 0xac},
1672 {0xb1, 0x78},
1673 {0xb2, 0x17},
1674 {0xb3, 0xc1},
1675 {0xb4, 0x40},
1676 {0xb5, 0x00},
1677 {0xb6, 0xc3},
1678 {0xb7, 0x0a},
1679 {0xb8, 0x00},
1680 {0xb9, 0x02},
1681 {0xba, 0x00},
1682 {0xbb, 0xb2},
1683 {0xa5, 0x10},
1684 {0xa7, 0x1e},
1685 {0xff, 0x0b},
1686 {0x3d, 0x00},
1687 {0x3c, 0x00},
1688 {0x30, 0xac},
1689 {0x31, 0x78},
1690 {0x32, 0x17},
1691 {0x33, 0xc1},
1692 {0x34, 0x40},
1693 {0x35, 0x00},
1694 {0x36, 0xc3},
1695 {0x37, 0x0a},
1696 {0x38, 0x00},
1697 {0x39, 0x02},
1698 {0x3a, 0x00},
1699 {0x3b, 0xb2},
1700 {0x25, 0x10},
1701 {0x27, 0x1e},
1702 {0xbd, 0x00},
1703 {0xbc, 0x00},
1704 {0xb0, 0xac},
1705 {0xb1, 0x78},
1706 {0xb2, 0x17},
1707 {0xb3, 0xc1},
1708 {0xb4, 0x40},
1709 {0xb5, 0x00},
1710 {0xb6, 0xc3},
1711 {0xb7, 0x0a},
1712 {0xb8, 0x00},
1713 {0xb9, 0x02},
1714 {0xba, 0x00},
1715 {0xbb, 0xb2},
1716 {0xa5, 0x10},
1717 {0xa7, 0x1e},
1718 {0xFF, 0x21},
1719 {0x3E, 0x00},
1720 {0x3F, 0x00},
1721 {0xFF, 0x20},
1722 {0x01, 0x00},
1723 {0x00, 0x00},
1724 {0x40, 0x01},
1725 {0x0F, 0x00},
1726 {0x0D, 0x01}, //0x01:4lane;0x00:2lane
1727 {0x40, 0x00},
1728 {0x00, 0xFF}, //ch1/2/3/4 enabled
1729 //{0x00, 0x33}, //ch1/2 enabled
1730 //{0x00, 0x11}, //ch1 enabled
1731 {0xFF, 0x01},
1732 {0xC8, 0x00},
1733 {0xC9, 0x00},
1734 {0xCA, 0x00},
1735 {0xCB, 0x00},
1736 //pattern enabled
1737 {0xFF, 0x00},
1738 {0x1C, 0x1A},
1739 {0x1D, 0x1A},
1740 {0x1E, 0x1A},
1741 {0x1F, 0x1A},
1742 {0xFF, 0x05},
1743 {0x6A, 0x80},
1744 {0xFF, 0x06},
1745 {0x6A, 0x80},
1746 {0xFF, 0x07},
1747 {0x6A, 0x80},
1748 {0xFF, 0x08},
1749 {0x6A, 0x80},
1750 SensorEnd
1751 };
1752
1753 /* format detect open*/
1754 static struct rk_sensor_reg sensor_open_format_detect[] = {
1755 {0xff, 0x13},
1756 {0x1f, 0x23},
1757 {0x30, 0xff},
1758 {0x31, 0xff},
1759 {0x32, 0xff},
1760 SensorEnd
1761 };
1762
nvp6324_reinit_parameter(struct vehicle_ad_dev * ad,unsigned char cvstd)1763 static void nvp6324_reinit_parameter(struct vehicle_ad_dev *ad, unsigned char cvstd)
1764 {
1765 int i = 0;
1766
1767 switch (cvstd) {
1768 case CVSTD_PAL:
1769 ad->cfg.width = FORCE_PAL_WIDTH;
1770 ad->cfg.height = FORCE_PAL_HEIGHT;
1771 ad->cfg.start_x = 0;
1772 ad->cfg.start_y = 0;
1773 ad->cfg.input_format = CIF_INPUT_FORMAT_PAL;
1774 ad->cfg.output_format = FORCE_CIF_OUTPUT_FORMAT;
1775 ad->cfg.field_order = 1;
1776 ad->cfg.yuv_order = 0;/*00 - UYVY*/
1777 ad->cfg.href = 0;
1778 ad->cfg.vsync = 0;
1779 ad->cfg.frame_rate = 25;//25 30
1780 ad->cfg.mipi_freq = JAGUAR1_LINK_FREQ_320M;
1781 break;
1782 case CVSTD_NTSC:
1783 ad->cfg.width = FORCE_NTSC_WIDTH;
1784 ad->cfg.height = FORCE_NTSC_HEIGHT;
1785 ad->cfg.start_x = 0;
1786 ad->cfg.start_y = 0;
1787 ad->cfg.input_format = CIF_INPUT_FORMAT_NTSC;
1788 ad->cfg.output_format = FORCE_CIF_OUTPUT_FORMAT;
1789 ad->cfg.field_order = 1;
1790 ad->cfg.yuv_order = 0;/*00 - UYVY*/
1791 ad->cfg.href = 0;
1792 ad->cfg.vsync = 0;
1793 ad->cfg.frame_rate = 30;//25 30
1794 ad->cfg.mipi_freq = JAGUAR1_LINK_FREQ_320M;
1795 break;
1796 case CVSTD_720P25:
1797 ad->cfg.width = 1280;
1798 ad->cfg.height = 720;
1799 ad->cfg.start_x = 0;
1800 ad->cfg.start_y = 0;
1801 ad->cfg.input_format = CIF_INPUT_FORMAT_YUV;
1802 ad->cfg.output_format = FORCE_CIF_OUTPUT_FORMAT;
1803 ad->cfg.field_order = 0;
1804 ad->cfg.yuv_order = 0;/*00 - UYVY*/
1805 ad->cfg.href = 0;
1806 ad->cfg.vsync = 0;
1807 ad->cfg.frame_rate = 25;
1808 ad->cfg.mipi_freq = JAGUAR1_LINK_FREQ_320M;
1809 break;
1810
1811 case CVSTD_1080P25:
1812 ad->cfg.width = 1920;
1813 ad->cfg.height = 1080;
1814 ad->cfg.start_x = 0;
1815 ad->cfg.start_y = 0;
1816 ad->cfg.input_format = CIF_INPUT_FORMAT_YUV;
1817 ad->cfg.output_format = FORCE_CIF_OUTPUT_FORMAT;
1818 ad->cfg.field_order = 0;
1819 ad->cfg.yuv_order = 0;/*00 - UYVY*/
1820 ad->cfg.href = 0;
1821 ad->cfg.vsync = 0;
1822 ad->cfg.frame_rate = 25;
1823 ad->cfg.mipi_freq = JAGUAR1_LINK_FREQ_640M;
1824 break;
1825
1826 default:
1827 ad->cfg.width = 1920;
1828 ad->cfg.height = 1080;
1829 ad->cfg.start_x = 0;
1830 ad->cfg.start_y = 0;
1831 ad->cfg.input_format = CIF_INPUT_FORMAT_YUV;
1832 ad->cfg.output_format = FORCE_CIF_OUTPUT_FORMAT;
1833 ad->cfg.field_order = 0;
1834 ad->cfg.yuv_order = 0;/*00 - UYVY*/
1835 ad->cfg.href = 0;
1836 ad->cfg.vsync = 0;
1837 ad->cfg.frame_rate = 25;
1838 ad->cfg.mipi_freq = JAGUAR1_LINK_FREQ_640M;
1839 break;
1840 }
1841 ad->cfg.type = V4L2_MBUS_CSI2_DPHY;
1842 ad->cfg.mbus_flags = V4L2_MBUS_CSI2_4_LANE |
1843 V4L2_MBUS_CSI2_CHANNELS;
1844 ad->cfg.mbus_code = MEDIA_BUS_FMT_UYVY8_2X8;
1845
1846 switch (ad->cfg.mbus_flags & V4L2_MBUS_CSI2_LANES) {
1847 case V4L2_MBUS_CSI2_1_LANE:
1848 ad->cfg.lanes = 1;
1849 break;
1850 case V4L2_MBUS_CSI2_2_LANE:
1851 ad->cfg.lanes = 2;
1852 break;
1853 case V4L2_MBUS_CSI2_3_LANE:
1854 ad->cfg.lanes = 3;
1855 break;
1856 case V4L2_MBUS_CSI2_4_LANE:
1857 ad->cfg.lanes = 4;
1858 break;
1859 default:
1860 ad->cfg.lanes = 1;
1861 break;
1862 }
1863
1864 /* fix crop info from dts config */
1865 for (i = 0; i < 4; i++) {
1866 if ((ad->defrects[i].width == ad->cfg.width) &&
1867 (ad->defrects[i].height == ad->cfg.height)) {
1868 ad->cfg.start_x = ad->defrects[i].crop_x;
1869 ad->cfg.start_y = ad->defrects[i].crop_y;
1870 ad->cfg.width = ad->defrects[i].crop_width;
1871 ad->cfg.height = ad->defrects[i].crop_height;
1872 }
1873 }
1874 }
1875
nvp6324_reg_init(struct vehicle_ad_dev * ad,unsigned char cvstd)1876 static void nvp6324_reg_init(struct vehicle_ad_dev *ad, unsigned char cvstd)
1877 {
1878 struct rk_sensor_reg *sensor;
1879 int i;
1880
1881 switch (cvstd) {
1882 case CVSTD_NTSC:
1883 VEHICLE_DG("%s, init CVSTD_NTSC mode", __func__);
1884 sensor = sensor_preview_data_ntsc_30hz;
1885 break;
1886 case CVSTD_PAL:
1887 VEHICLE_DG("%s, init CVSTD_PAL mode", __func__);
1888 sensor = sensor_preview_data_pal_25hz;
1889 break;
1890 case CVSTD_720P25:
1891 VEHICLE_DG("%s, init CVSTD_720P25 mode)", __func__);
1892 sensor = sensor_preview_data_720p_25hz;
1893 break;
1894 case CVSTD_1080P25:
1895 VEHICLE_DG("%s, init CVSTD_1080P25 mode", __func__);
1896 sensor = sensor_preview_data_1080p_25hz;
1897 break;
1898 default:
1899 VEHICLE_DG("%s, init CVSTD_1080P25 mode", __func__);
1900 sensor = sensor_preview_data_1080p_25hz;
1901 break;
1902 }
1903 i = 0;
1904 while ((sensor[i].reg != SEQCMD_END) && (sensor[i].reg != 0xFC000000)) {
1905 vehicle_sensor_write(ad, sensor[i].reg, sensor[i].val);
1906 i++;
1907 }
1908 /* open format detect*/
1909 sensor = sensor_open_format_detect;
1910 i = 0;
1911 while ((sensor[i].reg != SEQCMD_END) && (sensor[i].reg != 0xFC000000)) {
1912 vehicle_sensor_write(ad, sensor[i].reg, sensor[i].val);
1913 i++;
1914 }
1915
1916 vehicle_sensor_write(ad, 0xff, 0x05 + ad->ad_chl);
1917 vehicle_sensor_write(ad, 0x82, 0xff);
1918 vehicle_sensor_write(ad, 0xb8, 0xb9);
1919 }
1920
nvp6324_channel_set(struct vehicle_ad_dev * ad,int channel)1921 void nvp6324_channel_set(struct vehicle_ad_dev *ad, int channel)
1922 {
1923 unsigned int reg;
1924 unsigned char val = 0x00;
1925
1926 //detect interesting channel
1927 reg = channel;
1928 ad->ad_chl = channel;
1929 VEHICLE_DG("%s, channel set(%d)", __func__, ad->ad_chl);
1930 vehicle_sensor_write(ad, 0xff, 0x00);
1931 vehicle_sensor_write(ad, reg, val);
1932 }
1933
nvp6324_ad_get_cfg(struct vehicle_cfg ** cfg)1934 int nvp6324_ad_get_cfg(struct vehicle_cfg **cfg)
1935 {
1936
1937 if (!nvp6324_g_addev)
1938 return -ENODEV;
1939
1940 switch (cvstd_state) {
1941 case VIDEO_UNPLUG:
1942 nvp6324_g_addev->cfg.ad_ready = false;
1943 break;
1944 case VIDEO_LOCKED:
1945 nvp6324_g_addev->cfg.ad_ready = true;
1946 break;
1947 case VIDEO_IN:
1948 nvp6324_g_addev->cfg.ad_ready = false;
1949 break;
1950 }
1951
1952 nvp6324_g_addev->cfg.ad_ready = true;
1953 nvp6324_g_addev->cfg.drop_frames = nvp6324_g_addev->drop_frames;
1954
1955 *cfg = &nvp6324_g_addev->cfg;
1956
1957 return 0;
1958 }
1959
nvp6324_ad_check_cif_error(struct vehicle_ad_dev * ad,int last_line)1960 void nvp6324_ad_check_cif_error(struct vehicle_ad_dev *ad, int last_line)
1961 {
1962 VEHICLE_DG("%s, last_line %d\n", __func__, last_line);
1963
1964 if (last_line < 1)
1965 return;
1966
1967 ad->cif_error_last_line = last_line;
1968 if (cvstd_mode == CVSTD_PAL) {
1969 if (last_line == FORCE_NTSC_HEIGHT) {
1970 if (ad->state_check_work.state_check_wq)
1971 queue_delayed_work(
1972 ad->state_check_work.state_check_wq,
1973 &ad->state_check_work.work,
1974 msecs_to_jiffies(0));
1975 }
1976 } else if (cvstd_mode == CVSTD_NTSC) {
1977 if (last_line == FORCE_PAL_HEIGHT) {
1978 if (ad->state_check_work.state_check_wq)
1979 queue_delayed_work(
1980 ad->state_check_work.state_check_wq,
1981 &ad->state_check_work.work,
1982 msecs_to_jiffies(0));
1983 }
1984 } else if (cvstd_mode == CVSTD_1080P25) {
1985 if (last_line == FORCE_1080P_HEIGHT) {
1986 if (ad->state_check_work.state_check_wq)
1987 queue_delayed_work(
1988 ad->state_check_work.state_check_wq,
1989 &ad->state_check_work.work,
1990 msecs_to_jiffies(0));
1991 }
1992 } else if (cvstd_mode == CVSTD_720P25) {
1993 if (last_line == FORCE_720P_HEIGHT) {
1994 if (ad->state_check_work.state_check_wq)
1995 queue_delayed_work(
1996 ad->state_check_work.state_check_wq,
1997 &ad->state_check_work.work,
1998 msecs_to_jiffies(0));
1999 }
2000 }
2001 }
2002
nvp6324_check_id(struct vehicle_ad_dev * ad)2003 int nvp6324_check_id(struct vehicle_ad_dev *ad)
2004 {
2005 int ret = 0;
2006 u8 pid;
2007
2008 ret = vehicle_sensor_write(ad, 0xFF, 0x00);
2009 ret |= vehicle_sensor_read(ad, 0xf4, &pid);
2010 if (ret)
2011 return ret;
2012 if (pid != JAGUAR1_CHIP_ID) {
2013 VEHICLE_DGERR("%s: expected 0xB0, detected: 0x%02x !",
2014 ad->ad_name, pid);
2015 ret = -EINVAL;
2016 } else {
2017 VEHICLE_INFO("%s Found NVP6324 sensor: id(0x%2x) !\n", __func__, pid);
2018 }
2019
2020 return ret;
2021 }
2022
nvp6324_check_cvstd(struct vehicle_ad_dev * ad,bool activate_check)2023 static int nvp6324_check_cvstd(struct vehicle_ad_dev *ad, bool activate_check)
2024 {
2025
2026 u8 videoloss = 0;
2027 int ret = 0;
2028 unsigned char cvstd = 0;
2029
2030 ret = vehicle_sensor_write(ad, 0xFF, 0x00);
2031 ret |= vehicle_sensor_read(ad, 0xa4 + ad->ad_chl, &videoloss);
2032
2033 video_mode = videoloss;
2034
2035 ret |= vehicle_sensor_write(ad, 0xFF, 0x01);
2036 ret |= vehicle_sensor_read(ad, 0x10 + (0x20 * (ad->ad_chl%4)), &cvstd);
2037
2038 if (ret)
2039 return ret;
2040
2041 if (cvstd == 0x21) {
2042 cvstd_mode = CVSTD_720P25;
2043 VEHICLE_DG("%s(%d): 720P25\n", __func__, __LINE__);
2044 } else if (cvstd == 0x31) {
2045 cvstd_mode = CVSTD_1080P25;
2046 VEHICLE_DG("%s(%d): 1080P25", __func__, __LINE__);
2047 } else if (cvstd == 0x00) {
2048 cvstd_mode = CVSTD_NTSC;
2049 VEHICLE_DG("%s(%d): 960H NTSC\n", __func__, __LINE__);
2050 } else if (cvstd == 0x10) {
2051 cvstd_mode = CVSTD_PAL;
2052 VEHICLE_DG("%s(%d): 960H PAL\n", __func__, __LINE__);
2053 } else if (cvstd == 0xff) {
2054 cvstd_mode = cvstd_old;
2055 VEHICLE_DG("%s(%d): no ahd plugin!\n", __func__, __LINE__);
2056 } else {
2057 cvstd_mode = cvstd_old;
2058 VEHICLE_DG("%s(%d): not support ahd mode!\n", __func__, __LINE__);
2059 }
2060
2061 return 0;
2062 }
2063
nvp6324_stream(struct vehicle_ad_dev * ad,int enable)2064 int nvp6324_stream(struct vehicle_ad_dev *ad, int enable)
2065 {
2066 VEHICLE_DG("%s on(%d)\n", __func__, enable);
2067
2068 g_nvp6324_streaming = (enable != 0);
2069 if (g_nvp6324_streaming) {
2070 vehicle_sensor_write(ad, 0xff, 0x21);
2071 vehicle_sensor_write(ad, 0x07, 0x0f);
2072 if (ad->state_check_work.state_check_wq)
2073 queue_delayed_work(ad->state_check_work.state_check_wq,
2074 &ad->state_check_work.work, msecs_to_jiffies(200));
2075 } else {
2076 vehicle_sensor_write(ad, 0xff, 0x21);
2077 vehicle_sensor_write(ad, 0x07, 0x8f);
2078 if (ad->state_check_work.state_check_wq)
2079 cancel_delayed_work_sync(&ad->state_check_work.work);
2080 }
2081
2082 return 0;
2083 }
2084
nvp6324_power_on(struct vehicle_ad_dev * ad)2085 static void nvp6324_power_on(struct vehicle_ad_dev *ad)
2086 {
2087 /* gpio_direction_output(ad->power, ad->pwr_active); */
2088 VEHICLE_DG("gpio: power(%d), powerdown(%d), reset(%d)",
2089 ad->power, ad->powerdown, ad->reset);
2090 if (gpio_is_valid(ad->power)) {
2091 gpio_request(ad->power, "nvp6324_power");
2092 gpio_direction_output(ad->power, ad->pwr_active);
2093 /* gpio_set_value(ad->power, ad->pwr_active); */
2094 }
2095
2096 if (gpio_is_valid(ad->powerdown)) {
2097 gpio_request(ad->powerdown, "nvp6324_pwd");
2098 gpio_direction_output(ad->powerdown, 1);
2099 /* gpio_set_value(ad->powerdown, !ad->pwdn_active); */
2100 }
2101
2102 if (gpio_is_valid(ad->reset)) {
2103 gpio_request(ad->reset, "nvp6324_rst");
2104 gpio_direction_output(ad->reset, 0);
2105 usleep_range(1500, 2000);
2106 gpio_direction_output(ad->reset, 1);
2107 }
2108 }
2109
nvp6324_power_deinit(struct vehicle_ad_dev * ad)2110 static void nvp6324_power_deinit(struct vehicle_ad_dev *ad)
2111 {
2112 if (gpio_is_valid(ad->reset))
2113 gpio_free(ad->reset);
2114 if (gpio_is_valid(ad->power))
2115 gpio_free(ad->power);
2116 if (gpio_is_valid(ad->powerdown))
2117 gpio_free(ad->powerdown);
2118 }
2119
nvp6324_check_state_work(struct work_struct * work)2120 static void nvp6324_check_state_work(struct work_struct *work)
2121 {
2122 struct vehicle_ad_dev *ad;
2123
2124 ad = nvp6324_g_addev;
2125
2126 if (ad->cif_error_last_line > 0) {
2127 nvp6324_check_cvstd(ad, true);
2128 ad->cif_error_last_line = 0;
2129 } else {
2130 nvp6324_check_cvstd(ad, false);
2131 }
2132
2133 if (cvstd_old != cvstd_mode ||
2134 cvstd_old_state != cvstd_state || (video_old != video_mode)) {
2135 VEHICLE_INFO("%s:ad sensor std mode change, cvstd_old(%d), cvstd_mode(%d)\n",
2136 __func__, cvstd_old, cvstd_mode);
2137 cvstd_old = cvstd_mode;
2138 cvstd_old_state = cvstd_state;
2139 video_old = video_mode;
2140
2141 nvp6324_reinit_parameter(ad, cvstd_mode);
2142 nvp6324_reg_init(ad, cvstd_mode);
2143 vehicle_ad_stat_change_notify();
2144 }
2145 if (g_nvp6324_streaming) {
2146 queue_delayed_work(ad->state_check_work.state_check_wq,
2147 &ad->state_check_work.work, msecs_to_jiffies(100));
2148 }
2149 }
2150
nvp6324_ad_deinit(void)2151 int nvp6324_ad_deinit(void)
2152 {
2153 struct vehicle_ad_dev *ad;
2154
2155 ad = nvp6324_g_addev;
2156
2157 if (!ad)
2158 return -ENODEV;
2159
2160 if (ad->state_check_work.state_check_wq) {
2161 cancel_delayed_work_sync(&ad->state_check_work.work);
2162 flush_delayed_work(&ad->state_check_work.work);
2163 flush_workqueue(ad->state_check_work.state_check_wq);
2164 destroy_workqueue(ad->state_check_work.state_check_wq);
2165 }
2166 if (ad->irq)
2167 free_irq(ad->irq, ad);
2168 nvp6324_power_deinit(ad);
2169
2170 return 0;
2171 }
2172
get_ad_mode_from_fix_format(int fix_format)2173 static __maybe_unused int get_ad_mode_from_fix_format(int fix_format)
2174 {
2175 int mode = -1;
2176
2177 switch (fix_format) {
2178 case AD_FIX_FORMAT_PAL:
2179 case AD_FIX_FORMAT_NTSC:
2180 case AD_FIX_FORMAT_720P_50FPS:
2181 case AD_FIX_FORMAT_720P_30FPS:
2182 case AD_FIX_FORMAT_720P_25FPS:
2183 mode = CVSTD_720P25;
2184 break;
2185 case AD_FIX_FORMAT_1080P_30FPS:
2186 case AD_FIX_FORMAT_1080P_25FPS:
2187
2188 default:
2189 mode = CVSTD_720P25;
2190 break;
2191 }
2192
2193 return mode;
2194 }
2195
nvp6324_ad_init(struct vehicle_ad_dev * ad)2196 int nvp6324_ad_init(struct vehicle_ad_dev *ad)
2197 {
2198 int val;
2199 int i = 0;
2200
2201 nvp6324_g_addev = ad;
2202
2203 /* 1. i2c init */
2204 while (ad->adapter == NULL) {
2205 ad->adapter = i2c_get_adapter(ad->i2c_chl);
2206 usleep_range(10000, 12000);
2207 }
2208 if (ad->adapter == NULL)
2209 return -ENODEV;
2210
2211 if (!i2c_check_functionality(ad->adapter, I2C_FUNC_I2C))
2212 return -EIO;
2213
2214 nvp6324_power_on(ad);
2215
2216 while (++i < 5) {
2217 usleep_range(10000, 12000);
2218 val = vehicle_generic_sensor_read(ad, 0xf0);
2219 if (val != 0xff)
2220 break;
2221 VEHICLE_DGERR("nvp6324_init i2c_reg_read fail\n");
2222 }
2223
2224 nvp6324_reg_init(ad, cvstd_mode);
2225
2226 nvp6324_reinit_parameter(ad, cvstd_mode);
2227
2228 INIT_DELAYED_WORK(&ad->state_check_work.work, nvp6324_check_state_work);
2229 ad->state_check_work.state_check_wq =
2230 create_singlethread_workqueue("vehicle-ad-nvp6324");
2231
2232 /* nvp6324_check_cvstd(ad, true); */
2233
2234 queue_delayed_work(ad->state_check_work.state_check_wq,
2235 &ad->state_check_work.work, msecs_to_jiffies(100));
2236
2237 return 0;
2238 }
2239