.. | .. |
---|
11 | 11 | * 2. add hdr mode exposure limit issue. |
---|
12 | 12 | * 3. fix hdr mode highlighting pink issue. |
---|
13 | 13 | * 4. add some debug info. |
---|
14 | | - * V0.0X01.0X03 fix hdr mode not support vts change |
---|
15 | | - * V0.0X01.0X04 add 24M MCLK register setting. |
---|
16 | 14 | */ |
---|
17 | 15 | //#define DEBUG |
---|
18 | 16 | #include <linux/clk.h> |
---|
.. | .. |
---|
34 | 32 | #include <media/v4l2-device.h> |
---|
35 | 33 | #include <media/v4l2-fwnode.h> |
---|
36 | 34 | #include <media/v4l2-subdev.h> |
---|
| 35 | +#include "../platform/rockchip/isp/rkisp_tb_helper.h" |
---|
37 | 36 | |
---|
38 | | -#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x04) |
---|
| 37 | +#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x02) |
---|
39 | 38 | #define GC2093_NAME "gc2093" |
---|
40 | 39 | #define GC2093_MEDIA_BUS_FMT MEDIA_BUS_FMT_SRGGB10_1X10 |
---|
41 | 40 | |
---|
42 | 41 | #define MIPI_FREQ_297M 297000000 |
---|
43 | 42 | #define MIPI_FREQ_396M 396000000 |
---|
44 | 43 | |
---|
45 | | -/* 27M or 24M */ |
---|
46 | | -#define MCLK_27M |
---|
47 | | - |
---|
48 | | -#ifdef MCLK_27M |
---|
49 | 44 | #define GC2093_XVCLK_FREQ 27000000 |
---|
50 | | -#else |
---|
51 | | -#define GC2093_XVCLK_FREQ 24000000 |
---|
52 | | -#endif |
---|
53 | 45 | |
---|
54 | 46 | #define GC2093_REG_CHIP_ID_H 0x03F0 |
---|
55 | 47 | #define GC2093_REG_CHIP_ID_L 0x03F1 |
---|
.. | .. |
---|
99 | 91 | #define GC2093_NUM_SUPPLIES ARRAY_SIZE(gc2093_supply_names) |
---|
100 | 92 | |
---|
101 | 93 | #define to_gc2093(sd) container_of(sd, struct gc2093, subdev) |
---|
102 | | - |
---|
103 | | -enum { |
---|
104 | | - PAD0, |
---|
105 | | - PAD1, |
---|
106 | | - PAD2, |
---|
107 | | - PAD3, |
---|
108 | | - PAD_MAX, |
---|
109 | | -}; |
---|
110 | 94 | |
---|
111 | 95 | enum { |
---|
112 | 96 | LINK_FREQ_297M_INDEX, |
---|
.. | .. |
---|
165 | 149 | const char *module_facing; |
---|
166 | 150 | const char *module_name; |
---|
167 | 151 | const char *len_name; |
---|
168 | | - u32 cur_vts; |
---|
169 | 152 | |
---|
170 | | - bool has_init_exp; |
---|
| 153 | + struct v4l2_fract cur_fps; |
---|
| 154 | + u32 cur_vts; |
---|
| 155 | + |
---|
| 156 | + bool has_init_exp; |
---|
| 157 | + bool is_thunderboot; |
---|
| 158 | + bool is_first_streamoff; |
---|
171 | 159 | struct preisp_hdrae_exp_s init_hdrae_exp; |
---|
172 | 160 | }; |
---|
173 | 161 | |
---|
.. | .. |
---|
189 | 177 | * row_time=29.62us frame_rate=30fps |
---|
190 | 178 | */ |
---|
191 | 179 | static const struct reg_sequence gc2093_1080p_liner_settings[] = { |
---|
192 | | -#ifdef MCLK_27M |
---|
193 | 180 | /* System */ |
---|
194 | 181 | {0x03fe, 0x80}, |
---|
195 | 182 | {0x03fe, 0x80}, |
---|
.. | .. |
---|
300 | 287 | {0x0212, 0x80}, |
---|
301 | 288 | {0x0213, 0x07}, |
---|
302 | 289 | {0x003e, 0x91}, |
---|
303 | | -#else |
---|
304 | | - /****system****/ |
---|
305 | | - {0x03fe, 0xf0}, |
---|
306 | | - {0x03fe, 0xf0}, |
---|
307 | | - {0x03fe, 0xf0}, |
---|
308 | | - {0x03fe, 0x00}, |
---|
309 | | - {0x03f2, 0x00}, |
---|
310 | | - {0x03f3, 0x00}, |
---|
311 | | - {0x03f4, 0x36}, |
---|
312 | | - {0x03f5, 0xc0}, |
---|
313 | | - {0x03f6, 0x0B}, |
---|
314 | | - {0x03f7, 0x11}, |
---|
315 | | - {0x03f8, 0x30}, |
---|
316 | | - {0x03f9, 0x42}, |
---|
317 | | - {0x03fc, 0x8e}, |
---|
318 | | - /****CISCTL & ANALOG****/ |
---|
319 | | - {0x0087, 0x18}, |
---|
320 | | - {0x00ee, 0x30}, |
---|
321 | | - {0x00d0, 0xbf}, |
---|
322 | | - {0x01a0, 0x00}, |
---|
323 | | - {0x01a4, 0x40}, |
---|
324 | | - {0x01a5, 0x40}, |
---|
325 | | - {0x01a6, 0x40}, |
---|
326 | | - {0x01af, 0x09}, |
---|
327 | | - {0x0003, 0x04}, |
---|
328 | | - {0x0004, 0x65}, |
---|
329 | | - {0x0005, 0x05}, |
---|
330 | | - {0x0006, 0x8e}, |
---|
331 | | - {0x0007, 0x00}, |
---|
332 | | - {0x0008, 0x11}, |
---|
333 | | - {0x0009, 0x00}, |
---|
334 | | - {0x000a, 0x02}, |
---|
335 | | - {0x000b, 0x00}, |
---|
336 | | - {0x000c, 0x04}, |
---|
337 | | - {0x000d, 0x04}, |
---|
338 | | - {0x000e, 0x40}, |
---|
339 | | - {0x000f, 0x07}, |
---|
340 | | - {0x0010, 0x8c}, |
---|
341 | | - {0x0013, 0x15}, |
---|
342 | | - {0x0019, 0x0c}, |
---|
343 | | - {0x0041, 0x04}, |
---|
344 | | - {0x0042, 0x65}, |
---|
345 | | - {0x0053, 0x60}, |
---|
346 | | - {0x008d, 0x92}, |
---|
347 | | - {0x0090, 0x00}, |
---|
348 | | - {0x00c7, 0xe1}, |
---|
349 | | - {0x001b, 0x73}, |
---|
350 | | - {0x0028, 0x0d}, |
---|
351 | | - {0x0029, 0x40}, |
---|
352 | | - {0x002b, 0x04}, |
---|
353 | | - {0x002e, 0x23}, |
---|
354 | | - {0x0037, 0x03}, |
---|
355 | | - {0x0043, 0x04}, |
---|
356 | | - {0x0044, 0x30}, |
---|
357 | | - {0x004a, 0x01}, |
---|
358 | | - {0x004b, 0x28}, |
---|
359 | | - {0x0055, 0x30}, |
---|
360 | | - {0x0066, 0x3f}, |
---|
361 | | - {0x0068, 0x3f}, |
---|
362 | | - {0x006b, 0x44}, |
---|
363 | | - {0x0077, 0x00}, |
---|
364 | | - {0x0078, 0x20}, |
---|
365 | | - {0x007c, 0xa1}, |
---|
366 | | - {0x00ce, 0x7c}, |
---|
367 | | - {0x00d3, 0xd4}, |
---|
368 | | - {0x00e6, 0x50}, |
---|
369 | | - /*gain*/ |
---|
370 | | - {0x00b6, 0xc0}, |
---|
371 | | - {0x00b0, 0x68}, |
---|
372 | | - {0x00b3, 0x00}, |
---|
373 | | - {0x00b8, 0x01}, |
---|
374 | | - {0x00b9, 0x00}, |
---|
375 | | - {0x00b1, 0x01}, |
---|
376 | | - {0x00b2, 0x00}, |
---|
377 | | - /*isp*/ |
---|
378 | | - {0x0101, 0x0c}, |
---|
379 | | - {0x0102, 0x89}, |
---|
380 | | - {0x0104, 0x01}, |
---|
381 | | - {0x0107, 0xa6}, |
---|
382 | | - {0x0108, 0xa9}, |
---|
383 | | - {0x0109, 0xa8}, |
---|
384 | | - {0x010a, 0xa7}, |
---|
385 | | - {0x010b, 0xff}, |
---|
386 | | - {0x010c, 0xff}, |
---|
387 | | - {0x010f, 0x00}, |
---|
388 | | - {0x0158, 0x00}, |
---|
389 | | - {0x0428, 0x86}, |
---|
390 | | - {0x0429, 0x86}, |
---|
391 | | - {0x042a, 0x86}, |
---|
392 | | - {0x042b, 0x68}, |
---|
393 | | - {0x042c, 0x68}, |
---|
394 | | - {0x042d, 0x68}, |
---|
395 | | - {0x042e, 0x68}, |
---|
396 | | - {0x042f, 0x68}, |
---|
397 | | - {0x0430, 0x4f}, |
---|
398 | | - {0x0431, 0x68}, |
---|
399 | | - {0x0432, 0x67}, |
---|
400 | | - {0x0433, 0x66}, |
---|
401 | | - {0x0434, 0x66}, |
---|
402 | | - {0x0435, 0x66}, |
---|
403 | | - {0x0436, 0x66}, |
---|
404 | | - {0x0437, 0x66}, |
---|
405 | | - {0x0438, 0x62}, |
---|
406 | | - {0x0439, 0x62}, |
---|
407 | | - {0x043a, 0x62}, |
---|
408 | | - {0x043b, 0x62}, |
---|
409 | | - {0x043c, 0x62}, |
---|
410 | | - {0x043d, 0x62}, |
---|
411 | | - {0x043e, 0x62}, |
---|
412 | | - {0x043f, 0x62}, |
---|
413 | | - /*dark sun*/ |
---|
414 | | - {0x0123, 0x08}, |
---|
415 | | - {0x0123, 0x00}, |
---|
416 | | - {0x0120, 0x01}, |
---|
417 | | - {0x0121, 0x04}, |
---|
418 | | - {0x0122, 0x65}, |
---|
419 | | - {0x0124, 0x03}, |
---|
420 | | - {0x0125, 0xff}, |
---|
421 | | - {0x001a, 0x8c}, |
---|
422 | | - {0x00c6, 0xe0}, |
---|
423 | | - /*blk*/ |
---|
424 | | - {0x0026, 0x30}, |
---|
425 | | - {0x0142, 0x00}, |
---|
426 | | - {0x0149, 0x1e}, |
---|
427 | | - {0x014a, 0x0f}, |
---|
428 | | - {0x014b, 0x00}, |
---|
429 | | - {0x0155, 0x07}, |
---|
430 | | - {0x0414, 0x78}, |
---|
431 | | - {0x0415, 0x78}, |
---|
432 | | - {0x0416, 0x78}, |
---|
433 | | - {0x0417, 0x78}, |
---|
434 | | - {0x04e0, 0x18}, |
---|
435 | | - /*window*/ |
---|
436 | | - {0x0192, 0x02}, |
---|
437 | | - {0x0194, 0x03}, |
---|
438 | | - {0x0195, 0x04}, |
---|
439 | | - {0x0196, 0x38}, |
---|
440 | | - {0x0197, 0x07}, |
---|
441 | | - {0x0198, 0x80}, |
---|
442 | | - /****DVP & MIPI****/ |
---|
443 | | - {0x019a, 0x06}, |
---|
444 | | - {0x007b, 0x2a}, |
---|
445 | | - {0x0023, 0x2d}, |
---|
446 | | - {0x0201, 0x27}, |
---|
447 | | - {0x0202, 0x56}, |
---|
448 | | - {0x0203, 0xb6}, |
---|
449 | | - {0x0212, 0x80}, |
---|
450 | | - {0x0213, 0x07}, |
---|
451 | | - {0x0215, 0x10}, |
---|
452 | | - {0x003e, 0x91}, |
---|
453 | | -#endif |
---|
454 | 290 | }; |
---|
455 | 291 | |
---|
456 | 292 | /* |
---|
.. | .. |
---|
460 | 296 | * row_time=13.33us frame_rate=60fps |
---|
461 | 297 | */ |
---|
462 | 298 | static const struct reg_sequence gc2093_1080p_hdr_settings[] = { |
---|
463 | | -#ifdef MCLK_27M |
---|
464 | 299 | /* System */ |
---|
465 | 300 | {0x03fe, 0x80}, |
---|
466 | 301 | {0x03fe, 0x80}, |
---|
.. | .. |
---|
502 | 337 | {0x0010, 0x8c}, |
---|
503 | 338 | {0x0013, 0x15}, |
---|
504 | 339 | {0x0019, 0x0c}, |
---|
505 | | - {0x0041, 0x05}, //30fps: 0x4e2; 25FPS: 0x5dc: 20FPS: 0x753 |
---|
506 | | - {0x0042, 0xdc}, |
---|
| 340 | + {0x0041, 0x04}, |
---|
| 341 | + {0x0042, 0xe2}, |
---|
507 | 342 | {0x0053, 0x60}, |
---|
508 | 343 | {0x008d, 0x92}, |
---|
509 | 344 | {0x0090, 0x00}, |
---|
.. | .. |
---|
584 | 419 | {0x0027, 0x71}, |
---|
585 | 420 | {0x0215, 0x92}, |
---|
586 | 421 | {0x024d, 0x01}, |
---|
587 | | -#else |
---|
588 | | - /****system****/ |
---|
589 | | - {0x03fe, 0xf0}, |
---|
590 | | - {0x03fe, 0xf0}, |
---|
591 | | - {0x03fe, 0xf0}, |
---|
592 | | - {0x03fe, 0x00}, |
---|
593 | | - {0x03f2, 0x00}, |
---|
594 | | - {0x03f3, 0x00}, |
---|
595 | | - {0x03f4, 0x36}, |
---|
596 | | - {0x03f5, 0xc0}, |
---|
597 | | - {0x03f6, 0x0B}, |
---|
598 | | - {0x03f7, 0x01}, |
---|
599 | | - {0x03f8, 0x63}, |
---|
600 | | - {0x03f9, 0x40}, |
---|
601 | | - {0x03fc, 0x8e}, |
---|
602 | | - /****CISCTL & ANALOG****/ |
---|
603 | | - {0x0087, 0x18}, |
---|
604 | | - {0x00ee, 0x30}, |
---|
605 | | - {0x00d0, 0xbf}, |
---|
606 | | - {0x01a0, 0x00}, |
---|
607 | | - {0x01a4, 0x40}, |
---|
608 | | - {0x01a5, 0x40}, |
---|
609 | | - {0x01a6, 0x40}, |
---|
610 | | - {0x01af, 0x09}, |
---|
611 | | - {0x0001, 0x00}, |
---|
612 | | - {0x0002, 0x02}, |
---|
613 | | - {0x0003, 0x04}, |
---|
614 | | - {0x0004, 0x02}, |
---|
615 | | - {0x0005, 0x02}, |
---|
616 | | - {0x0006, 0x94}, |
---|
617 | | - {0x0007, 0x00}, |
---|
618 | | - {0x0008, 0x11}, |
---|
619 | | - {0x0009, 0x00}, |
---|
620 | | - {0x000a, 0x02}, |
---|
621 | | - {0x000b, 0x00}, |
---|
622 | | - {0x000c, 0x04}, |
---|
623 | | - {0x000d, 0x04}, |
---|
624 | | - {0x000e, 0x40}, |
---|
625 | | - {0x000f, 0x07}, |
---|
626 | | - {0x0010, 0x8c}, |
---|
627 | | - {0x0013, 0x15}, |
---|
628 | | - {0x0019, 0x0c}, |
---|
629 | | - {0x0041, 0x05}, //30fps: 0x4e2; 25FPS: 0x5dc: 20FPS: 0x753 |
---|
630 | | - {0x0042, 0xdc}, |
---|
631 | | - {0x0053, 0x60}, |
---|
632 | | - {0x008d, 0x92}, |
---|
633 | | - {0x0090, 0x00}, |
---|
634 | | - {0x00c7, 0xe1}, |
---|
635 | | - {0x001b, 0x73}, |
---|
636 | | - {0x0028, 0x0d}, |
---|
637 | | - {0x0029, 0x24}, |
---|
638 | | - {0x002b, 0x04}, |
---|
639 | | - {0x002e, 0x23}, |
---|
640 | | - {0x0037, 0x03}, |
---|
641 | | - {0x0043, 0x04}, |
---|
642 | | - {0x0044, 0x28}, |
---|
643 | | - {0x004a, 0x01}, |
---|
644 | | - {0x004b, 0x20}, |
---|
645 | | - {0x0055, 0x28}, |
---|
646 | | - {0x0066, 0x3f}, |
---|
647 | | - {0x0068, 0x3f}, |
---|
648 | | - {0x006b, 0x44}, |
---|
649 | | - {0x0077, 0x00}, |
---|
650 | | - {0x0078, 0x20}, |
---|
651 | | - {0x007c, 0xa1}, |
---|
652 | | - {0x00ce, 0x7c}, |
---|
653 | | - {0x00d3, 0xd4}, |
---|
654 | | - {0x00e6, 0x50}, |
---|
655 | | - /*gain*/ |
---|
656 | | - {0x00b6, 0xc0}, |
---|
657 | | - {0x00b0, 0x68}, |
---|
658 | | - /*isp*/ |
---|
659 | | - {0x0101, 0x0c}, |
---|
660 | | - {0x0102, 0x89}, |
---|
661 | | - {0x0104, 0x01}, |
---|
662 | | - {0x010e, 0x01}, |
---|
663 | | - {0x010f, 0x00}, |
---|
664 | | - {0x0158, 0x00}, |
---|
665 | | - {0x0183, 0x01}, |
---|
666 | | - {0x0187, 0x50}, |
---|
667 | | - /*dark sun*/ |
---|
668 | | - {0x0123, 0x08}, |
---|
669 | | - {0x0123, 0x00}, |
---|
670 | | - {0x0120, 0x01}, |
---|
671 | | - {0x0121, 0x04}, |
---|
672 | | - {0x0122, 0xd8}, |
---|
673 | | - {0x0124, 0x03}, |
---|
674 | | - {0x0125, 0xff}, |
---|
675 | | - {0x001a, 0x8c}, |
---|
676 | | - {0x00c6, 0xe0}, |
---|
677 | | - /*blk*/ |
---|
678 | | - {0x0026, 0x30}, |
---|
679 | | - {0x0142, 0x00}, |
---|
680 | | - {0x0149, 0x1e}, |
---|
681 | | - {0x014a, 0x0f}, |
---|
682 | | - {0x014b, 0x00}, |
---|
683 | | - {0x0155, 0x07}, |
---|
684 | | - {0x0414, 0x78}, |
---|
685 | | - {0x0415, 0x78}, |
---|
686 | | - {0x0416, 0x78}, |
---|
687 | | - {0x0417, 0x78}, |
---|
688 | | - {0x0454, 0x78}, |
---|
689 | | - {0x0455, 0x78}, |
---|
690 | | - {0x0456, 0x78}, |
---|
691 | | - {0x0457, 0x78}, |
---|
692 | | - {0x04e0, 0x18}, |
---|
693 | | - /*window*/ |
---|
694 | | - {0x0192, 0x02}, |
---|
695 | | - {0x0194, 0x03}, |
---|
696 | | - {0x0195, 0x04}, |
---|
697 | | - {0x0196, 0x38}, |
---|
698 | | - {0x0197, 0x07}, |
---|
699 | | - {0x0198, 0x80}, |
---|
700 | | - /****DVP & MIPI****/ |
---|
701 | | - {0x019a, 0x06}, |
---|
702 | | - {0x007b, 0x2a}, |
---|
703 | | - {0x0023, 0x2d}, |
---|
704 | | - {0x0201, 0x27}, |
---|
705 | | - {0x0202, 0x56}, |
---|
706 | | - {0x0203, 0xb6}, //try 0xce or 0x8e |
---|
707 | | - {0x0212, 0x80}, |
---|
708 | | - {0x0213, 0x07}, |
---|
709 | | - {0x0215, 0x10}, |
---|
710 | | - {0x003e, 0x91}, |
---|
711 | | - /****HDR EN****/ |
---|
712 | | - {0x0027, 0x71}, |
---|
713 | | - {0x0215, 0x92}, |
---|
714 | | - {0x024d, 0x01}, |
---|
715 | | -#endif |
---|
716 | 422 | }; |
---|
717 | 423 | |
---|
718 | 424 | static const struct gc2093_mode supported_modes[] = { |
---|
.. | .. |
---|
737 | 443 | .height = 1080, |
---|
738 | 444 | .max_fps = { |
---|
739 | 445 | .numerator = 10000, |
---|
740 | | - .denominator = 250000, |
---|
| 446 | + .denominator = 300000, |
---|
741 | 447 | }, |
---|
742 | 448 | .exp_def = 0x460, |
---|
743 | 449 | .hts_def = 0xa50, |
---|
744 | | - .vts_def = 0x5dc,//30fps: 0x4e2; 25FPS: 0x5dc: 20FPS: 0x753 |
---|
| 450 | + .vts_def = 0x4e2, |
---|
745 | 451 | .link_freq_index = LINK_FREQ_396M_INDEX, |
---|
746 | 452 | .reg_list = gc2093_1080p_hdr_settings, |
---|
747 | 453 | .reg_num = ARRAY_SIZE(gc2093_1080p_hdr_settings), |
---|
.. | .. |
---|
847 | 553 | return ret; |
---|
848 | 554 | } |
---|
849 | 555 | |
---|
| 556 | +static void gc2093_modify_fps_info(struct gc2093 *gc2093) |
---|
| 557 | +{ |
---|
| 558 | + const struct gc2093_mode *mode = gc2093->cur_mode; |
---|
| 559 | + |
---|
| 560 | + gc2093->cur_fps.denominator = mode->max_fps.denominator * mode->vts_def / |
---|
| 561 | + gc2093->cur_vts; |
---|
| 562 | +} |
---|
| 563 | + |
---|
850 | 564 | static int gc2093_set_ctrl(struct v4l2_ctrl *ctrl) |
---|
851 | 565 | { |
---|
852 | 566 | struct gc2093 *gc2093 = container_of(ctrl->handler, |
---|
.. | .. |
---|
886 | 600 | gc2093_set_gain(gc2093, ctrl->val); |
---|
887 | 601 | break; |
---|
888 | 602 | case V4L2_CID_VBLANK: |
---|
889 | | - if (gc2093->cur_mode->hdr_mode != NO_HDR) |
---|
890 | | - goto ctrl_end; |
---|
891 | 603 | vts = gc2093->cur_mode->height + ctrl->val; |
---|
892 | 604 | gc2093->cur_vts = vts; |
---|
893 | 605 | ret = gc2093_write_reg(gc2093, GC2093_REG_VTS_H, |
---|
894 | 606 | (vts >> 8) & 0x3f); |
---|
895 | 607 | ret |= gc2093_write_reg(gc2093, GC2093_REG_VTS_L, |
---|
896 | 608 | vts & 0xff); |
---|
| 609 | + if (gc2093->cur_vts != gc2093->cur_mode->vts_def) |
---|
| 610 | + gc2093_modify_fps_info(gc2093); |
---|
897 | 611 | dev_dbg(gc2093->dev, " set blank value 0x%x\n", ctrl->val); |
---|
898 | 612 | break; |
---|
899 | 613 | case V4L2_CID_HFLIP: |
---|
.. | .. |
---|
992 | 706 | |
---|
993 | 707 | gc2093->subdev.ctrl_handler = handler; |
---|
994 | 708 | gc2093->has_init_exp = false; |
---|
| 709 | + gc2093->cur_vts = mode->vts_def; |
---|
| 710 | + gc2093->cur_fps = mode->max_fps; |
---|
995 | 711 | |
---|
996 | 712 | return 0; |
---|
997 | 713 | |
---|
.. | .. |
---|
1018 | 734 | return ret; |
---|
1019 | 735 | } |
---|
1020 | 736 | |
---|
| 737 | + if (gc2093->is_thunderboot) |
---|
| 738 | + return 0; |
---|
| 739 | + |
---|
1021 | 740 | ret = regulator_bulk_enable(GC2093_NUM_SUPPLIES, gc2093->supplies); |
---|
1022 | 741 | if (ret < 0) { |
---|
1023 | 742 | dev_err(dev, "Failed to enable regulators\n"); |
---|
.. | .. |
---|
1025 | 744 | } |
---|
1026 | 745 | |
---|
1027 | 746 | if (!IS_ERR(gc2093->reset_gpio)) |
---|
1028 | | - gpiod_set_value_cansleep(gc2093->reset_gpio, 1); |
---|
| 747 | + gpiod_direction_output(gc2093->reset_gpio, 1); |
---|
1029 | 748 | |
---|
1030 | 749 | usleep_range(1000, 2000); |
---|
1031 | 750 | |
---|
1032 | 751 | if (!IS_ERR(gc2093->pwdn_gpio)) |
---|
1033 | | - gpiod_set_value_cansleep(gc2093->pwdn_gpio, 1); |
---|
| 752 | + gpiod_direction_output(gc2093->pwdn_gpio, 1); |
---|
1034 | 753 | if (!IS_ERR(gc2093->reset_gpio)) |
---|
1035 | | - gpiod_set_value_cansleep(gc2093->reset_gpio, 0); |
---|
| 754 | + gpiod_direction_output(gc2093->reset_gpio, 0); |
---|
1036 | 755 | |
---|
1037 | 756 | usleep_range(10000, 20000); |
---|
1038 | 757 | |
---|
.. | .. |
---|
1045 | 764 | |
---|
1046 | 765 | static void __gc2093_power_off(struct gc2093 *gc2093) |
---|
1047 | 766 | { |
---|
| 767 | + clk_disable_unprepare(gc2093->xvclk); |
---|
| 768 | + if (gc2093->is_thunderboot) { |
---|
| 769 | + if (gc2093->is_first_streamoff) { |
---|
| 770 | + gc2093->is_thunderboot = false; |
---|
| 771 | + gc2093->is_first_streamoff = false; |
---|
| 772 | + } else { |
---|
| 773 | + return; |
---|
| 774 | + } |
---|
| 775 | + } |
---|
| 776 | + |
---|
1048 | 777 | if (!IS_ERR(gc2093->reset_gpio)) |
---|
1049 | | - gpiod_set_value_cansleep(gc2093->reset_gpio, 1); |
---|
| 778 | + gpiod_direction_output(gc2093->reset_gpio, 1); |
---|
1050 | 779 | if (!IS_ERR(gc2093->pwdn_gpio)) |
---|
1051 | | - gpiod_set_value_cansleep(gc2093->pwdn_gpio, 0); |
---|
| 780 | + gpiod_direction_output(gc2093->pwdn_gpio, 0); |
---|
1052 | 781 | |
---|
1053 | 782 | regulator_bulk_disable(GC2093_NUM_SUPPLIES, gc2093->supplies); |
---|
1054 | | - clk_disable_unprepare(gc2093->xvclk); |
---|
1055 | 783 | } |
---|
1056 | 784 | |
---|
1057 | 785 | static int gc2093_check_sensor_id(struct gc2093 *gc2093) |
---|
1058 | 786 | { |
---|
| 787 | + struct device *dev = gc2093->dev; |
---|
1059 | 788 | u8 id_h = 0, id_l = 0; |
---|
1060 | 789 | u16 id = 0; |
---|
1061 | 790 | int ret = 0; |
---|
| 791 | + |
---|
| 792 | + if (gc2093->is_thunderboot) { |
---|
| 793 | + dev_info(dev, "Enable thunderboot mode, skip sensor id check\n"); |
---|
| 794 | + return 0; |
---|
| 795 | + } |
---|
1062 | 796 | |
---|
1063 | 797 | ret = gc2093_read_reg(gc2093, GC2093_REG_CHIP_ID_H, &id_h); |
---|
1064 | 798 | ret |= gc2093_read_reg(gc2093, GC2093_REG_CHIP_ID_L, &id_l); |
---|
.. | .. |
---|
1107 | 841 | dev_info(gc2093->dev, "don't streaming, record hdrae\n"); |
---|
1108 | 842 | break; |
---|
1109 | 843 | } |
---|
1110 | | - /* group hold start*/ |
---|
1111 | | - gc2093_write_reg(gc2093, 0x031d, 0x2c); |
---|
| 844 | + |
---|
1112 | 845 | ret = gc2093_set_gain(gc2093, hdrae_exp->short_gain_reg); |
---|
1113 | 846 | if (ret) { |
---|
1114 | 847 | dev_err(gc2093->dev, "Failed to set gain!)\n"); |
---|
.. | .. |
---|
1171 | 904 | (short_exp >> 8) & 0x3f); |
---|
1172 | 905 | ret |= gc2093_write_reg(gc2093, GC2093_REG_EXP_SHORT_L, |
---|
1173 | 906 | short_exp & 0xff); |
---|
1174 | | - /* group hold end*/ |
---|
1175 | | - gc2093_write_reg(gc2093, 0x031d, 0x28); |
---|
1176 | 907 | break; |
---|
1177 | 908 | case RKMODULE_GET_HDR_CFG: |
---|
1178 | 909 | hdr_cfg = (struct rkmodule_hdr_cfg *)arg; |
---|
.. | .. |
---|
1203 | 934 | GC2093_VTS_MAX - gc2093->cur_mode->height, |
---|
1204 | 935 | 1, h); |
---|
1205 | 936 | gc2093->cur_vts = gc2093->cur_mode->vts_def; |
---|
| 937 | + gc2093->cur_fps = gc2093->cur_mode->max_fps; |
---|
1206 | 938 | dev_info(gc2093->dev, "sensor mode: %d\n", |
---|
1207 | 939 | gc2093->cur_mode->hdr_mode); |
---|
1208 | 940 | } |
---|
.. | .. |
---|
1237 | 969 | { |
---|
1238 | 970 | int ret; |
---|
1239 | 971 | |
---|
1240 | | - ret = regmap_multi_reg_write(gc2093->regmap, |
---|
1241 | | - gc2093->cur_mode->reg_list, |
---|
1242 | | - gc2093->cur_mode->reg_num); |
---|
1243 | | - if (ret) |
---|
1244 | | - return ret; |
---|
1245 | | - |
---|
1246 | | - /* Apply customized control from user */ |
---|
1247 | | - mutex_unlock(&gc2093->lock); |
---|
1248 | | - v4l2_ctrl_handler_setup(&gc2093->ctrl_handler); |
---|
1249 | | - mutex_lock(&gc2093->lock); |
---|
1250 | | - |
---|
1251 | | - if (gc2093->has_init_exp && gc2093->cur_mode->hdr_mode != NO_HDR) { |
---|
1252 | | - ret = gc2093_ioctl(&gc2093->subdev, PREISP_CMD_SET_HDRAE_EXP, |
---|
1253 | | - &gc2093->init_hdrae_exp); |
---|
1254 | | - if (ret) { |
---|
1255 | | - dev_err(gc2093->dev, "init exp fail in hdr mode\n"); |
---|
| 972 | + if (!gc2093->is_thunderboot) { |
---|
| 973 | + ret = regmap_multi_reg_write(gc2093->regmap, |
---|
| 974 | + gc2093->cur_mode->reg_list, |
---|
| 975 | + gc2093->cur_mode->reg_num); |
---|
| 976 | + if (ret) |
---|
1256 | 977 | return ret; |
---|
| 978 | + |
---|
| 979 | + /* Apply customized control from user */ |
---|
| 980 | + mutex_unlock(&gc2093->lock); |
---|
| 981 | + v4l2_ctrl_handler_setup(&gc2093->ctrl_handler); |
---|
| 982 | + mutex_lock(&gc2093->lock); |
---|
| 983 | + |
---|
| 984 | + if (gc2093->has_init_exp && gc2093->cur_mode->hdr_mode != NO_HDR) { |
---|
| 985 | + ret = gc2093_ioctl(&gc2093->subdev, PREISP_CMD_SET_HDRAE_EXP, |
---|
| 986 | + &gc2093->init_hdrae_exp); |
---|
| 987 | + if (ret) { |
---|
| 988 | + dev_err(gc2093->dev, "init exp fail in hdr mode\n"); |
---|
| 989 | + return ret; |
---|
| 990 | + } |
---|
1257 | 991 | } |
---|
1258 | 992 | } |
---|
1259 | | - |
---|
1260 | 993 | return gc2093_write_reg(gc2093, GC2093_REG_CTRL_MODE, |
---|
1261 | 994 | GC2093_MODE_STREAMING); |
---|
1262 | 995 | } |
---|
.. | .. |
---|
1264 | 997 | static int __gc2093_stop_stream(struct gc2093 *gc2093) |
---|
1265 | 998 | { |
---|
1266 | 999 | gc2093->has_init_exp = false; |
---|
| 1000 | + if (gc2093->is_thunderboot) { |
---|
| 1001 | + gc2093->is_first_streamoff = true; |
---|
| 1002 | + pm_runtime_put(gc2093->dev); |
---|
| 1003 | + } |
---|
1267 | 1004 | return gc2093_write_reg(gc2093, GC2093_REG_CTRL_MODE, |
---|
1268 | 1005 | GC2093_MODE_SW_STANDBY); |
---|
1269 | 1006 | } |
---|
.. | .. |
---|
1374 | 1111 | goto unlock_and_return; |
---|
1375 | 1112 | |
---|
1376 | 1113 | if (on) { |
---|
| 1114 | + if (gc2093->is_thunderboot && rkisp_tb_get_state() == RKISP_TB_NG) { |
---|
| 1115 | + gc2093->is_thunderboot = false; |
---|
| 1116 | + __gc2093_power_on(gc2093); |
---|
| 1117 | + } |
---|
1377 | 1118 | ret = pm_runtime_get_sync(gc2093->dev); |
---|
1378 | 1119 | if (ret < 0) { |
---|
1379 | 1120 | pm_runtime_put_noidle(gc2093->dev); |
---|
.. | .. |
---|
1410 | 1151 | struct gc2093 *gc2093 = to_gc2093(sd); |
---|
1411 | 1152 | const struct gc2093_mode *mode = gc2093->cur_mode; |
---|
1412 | 1153 | |
---|
1413 | | - mutex_lock(&gc2093->lock); |
---|
1414 | 1154 | fi->interval = mode->max_fps; |
---|
1415 | | - mutex_unlock(&gc2093->lock); |
---|
1416 | 1155 | |
---|
1417 | 1156 | return 0; |
---|
1418 | 1157 | } |
---|
1419 | 1158 | |
---|
1420 | | -static int gc2093_g_mbus_config(struct v4l2_subdev *sd, |
---|
| 1159 | +static int gc2093_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id, |
---|
1421 | 1160 | struct v4l2_mbus_config *config) |
---|
1422 | 1161 | { |
---|
1423 | 1162 | struct gc2093 *gc2093 = to_gc2093(sd); |
---|
1424 | 1163 | u32 val = 1 << (GC2093_LANES - 1) | V4L2_MBUS_CSI2_CHANNEL_0 | |
---|
1425 | 1164 | V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; |
---|
1426 | 1165 | |
---|
1427 | | - config->type = V4L2_MBUS_CSI2; |
---|
| 1166 | + config->type = V4L2_MBUS_CSI2_DPHY; |
---|
1428 | 1167 | config->flags = (gc2093->cur_mode->hdr_mode == NO_HDR) ? |
---|
1429 | 1168 | val : (val | V4L2_MBUS_CSI2_CHANNEL_1); |
---|
1430 | 1169 | |
---|
.. | .. |
---|
1515 | 1254 | __v4l2_ctrl_modify_range(gc2093->vblank, vblank_def, |
---|
1516 | 1255 | GC2093_VTS_MAX - mode->height, |
---|
1517 | 1256 | 1, vblank_def); |
---|
| 1257 | + gc2093->cur_vts = mode->vts_def; |
---|
| 1258 | + gc2093->cur_fps = mode->max_fps; |
---|
1518 | 1259 | } |
---|
1519 | 1260 | |
---|
1520 | 1261 | mutex_unlock(&gc2093->lock); |
---|
.. | .. |
---|
1618 | 1359 | static const struct v4l2_subdev_video_ops gc2093_video_ops = { |
---|
1619 | 1360 | .s_stream = gc2093_s_stream, |
---|
1620 | 1361 | .g_frame_interval = gc2093_g_frame_interval, |
---|
1621 | | - .g_mbus_config = gc2093_g_mbus_config, |
---|
1622 | 1362 | }; |
---|
1623 | 1363 | |
---|
1624 | 1364 | static const struct v4l2_subdev_pad_ops gc2093_pad_ops = { |
---|
.. | .. |
---|
1627 | 1367 | .enum_frame_interval = gc2093_enum_frame_interval, |
---|
1628 | 1368 | .get_fmt = gc2093_get_fmt, |
---|
1629 | 1369 | .set_fmt = gc2093_set_fmt, |
---|
| 1370 | + .get_mbus_config = gc2093_g_mbus_config, |
---|
1630 | 1371 | }; |
---|
1631 | 1372 | |
---|
1632 | 1373 | static const struct v4l2_subdev_ops gc2093_subdev_ops = { |
---|
.. | .. |
---|
1635 | 1376 | .pad = &gc2093_pad_ops, |
---|
1636 | 1377 | }; |
---|
1637 | 1378 | |
---|
1638 | | -static int gc2093_runtime_resume(struct device *dev) |
---|
| 1379 | +static int __maybe_unused gc2093_runtime_resume(struct device *dev) |
---|
1639 | 1380 | { |
---|
1640 | 1381 | struct i2c_client *client = to_i2c_client(dev); |
---|
1641 | 1382 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
---|
.. | .. |
---|
1645 | 1386 | return 0; |
---|
1646 | 1387 | } |
---|
1647 | 1388 | |
---|
1648 | | -static int gc2093_runtime_suspend(struct device *dev) |
---|
| 1389 | +static int __maybe_unused gc2093_runtime_suspend(struct device *dev) |
---|
1649 | 1390 | { |
---|
1650 | 1391 | struct i2c_client *client = to_i2c_client(dev); |
---|
1651 | 1392 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
---|
.. | .. |
---|
1699 | 1440 | return -EINVAL; |
---|
1700 | 1441 | } |
---|
1701 | 1442 | |
---|
| 1443 | + gc2093->is_thunderboot = IS_ENABLED(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP); |
---|
| 1444 | + |
---|
1702 | 1445 | gc2093->xvclk = devm_clk_get(gc2093->dev, "xvclk"); |
---|
1703 | 1446 | if (IS_ERR(gc2093->xvclk)) { |
---|
1704 | 1447 | dev_err(gc2093->dev, "Failed to get xvclk\n"); |
---|
1705 | 1448 | return -EINVAL; |
---|
1706 | 1449 | } |
---|
1707 | 1450 | |
---|
1708 | | - gc2093->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); |
---|
| 1451 | + gc2093->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS); |
---|
1709 | 1452 | if (IS_ERR(gc2093->reset_gpio)) |
---|
1710 | 1453 | dev_warn(dev, "Failed to get reset-gpios\n"); |
---|
1711 | 1454 | |
---|
1712 | | - gc2093->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_HIGH); |
---|
| 1455 | + gc2093->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_ASIS); |
---|
1713 | 1456 | if (IS_ERR(gc2093->pwdn_gpio)) |
---|
1714 | 1457 | dev_warn(dev, "Failed to get pwdn-gpios\n"); |
---|
1715 | 1458 | |
---|
.. | .. |
---|
1771 | 1514 | |
---|
1772 | 1515 | pm_runtime_set_active(dev); |
---|
1773 | 1516 | pm_runtime_enable(dev); |
---|
1774 | | - pm_runtime_idle(dev); |
---|
| 1517 | + if (gc2093->is_thunderboot) |
---|
| 1518 | + pm_runtime_get_sync(dev); |
---|
| 1519 | + else |
---|
| 1520 | + pm_runtime_idle(dev); |
---|
1775 | 1521 | |
---|
1776 | 1522 | return 0; |
---|
1777 | 1523 | |
---|
.. | .. |
---|
1839 | 1585 | i2c_del_driver(&gc2093_i2c_driver); |
---|
1840 | 1586 | } |
---|
1841 | 1587 | |
---|
| 1588 | +#if defined(CONFIG_VIDEO_ROCKCHIP_THUNDER_BOOT_ISP) && !defined(CONFIG_INITCALL_ASYNC) |
---|
| 1589 | +subsys_initcall(sensor_mod_init); |
---|
| 1590 | +#else |
---|
1842 | 1591 | device_initcall_sync(sensor_mod_init); |
---|
| 1592 | +#endif |
---|
1843 | 1593 | module_exit(sensor_mod_exit); |
---|
1844 | 1594 | |
---|
1845 | 1595 | MODULE_DESCRIPTION("Galaxycore GC2093 Image Sensor driver"); |
---|