.. | .. |
---|
11 | 11 | #include <media/videobuf2-dma-contig.h> |
---|
12 | 12 | #include "dev.h" |
---|
13 | 13 | #include "regs.h" |
---|
| 14 | +#include "rkisp_tb_helper.h" |
---|
14 | 15 | |
---|
15 | 16 | #define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416 |
---|
16 | 17 | #define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT 3312 |
---|
17 | 18 | #define STREAM_MAX_SP_RSZ_OUTPUT_WIDTH 1920 |
---|
18 | 19 | #define STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT 1080 |
---|
19 | 20 | #define STREAM_MIN_RSZ_OUTPUT_WIDTH 32 |
---|
20 | | -#define STREAM_MIN_RSZ_OUTPUT_HEIGHT 16 |
---|
| 21 | +#define STREAM_MIN_RSZ_OUTPUT_HEIGHT 32 |
---|
21 | 22 | #define STREAM_OUTPUT_STEP_WISE 8 |
---|
22 | 23 | |
---|
23 | | -#define STREAM_MIN_MP_SP_INPUT_WIDTH 32 |
---|
24 | | -#define STREAM_MIN_MP_SP_INPUT_HEIGHT 32 |
---|
| 24 | +#define STREAM_MIN_MP_SP_INPUT_WIDTH STREAM_MIN_RSZ_OUTPUT_WIDTH |
---|
| 25 | +#define STREAM_MIN_MP_SP_INPUT_HEIGHT STREAM_MIN_RSZ_OUTPUT_HEIGHT |
---|
25 | 26 | |
---|
26 | 27 | static int hdr_dma_frame(struct rkisp_device *dev) |
---|
27 | 28 | { |
---|
.. | .. |
---|
124 | 125 | if (atomic_read(&dev->cap_dev.refcnt) > 1 || |
---|
125 | 126 | !dev->active_sensor || |
---|
126 | 127 | (dev->active_sensor && |
---|
127 | | - dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) || |
---|
| 128 | + dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) || |
---|
128 | 129 | (dev->isp_inp & INP_CIF) || |
---|
129 | 130 | (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21)) |
---|
130 | 131 | return; |
---|
.. | .. |
---|
157 | 158 | |
---|
158 | 159 | if (!dev->active_sensor || |
---|
159 | 160 | (dev->active_sensor && |
---|
160 | | - dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) || |
---|
| 161 | + dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) || |
---|
161 | 162 | (dev->isp_inp & INP_CIF) || |
---|
162 | 163 | (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21)) |
---|
163 | 164 | return 0; |
---|
.. | .. |
---|
165 | 166 | for (i = RKISP_STREAM_DMATX0; i <= RKISP_STREAM_DMATX2; i++) { |
---|
166 | 167 | dmatx = &dev->cap_dev.stream[i]; |
---|
167 | 168 | if (dmatx->ops && dmatx->ops->frame_end) |
---|
168 | | - dmatx->ops->frame_end(dmatx); |
---|
| 169 | + dmatx->ops->frame_end(dmatx, FRAME_INIT); |
---|
169 | 170 | } |
---|
170 | 171 | |
---|
171 | 172 | if (dev->dmarx_dev.trigger) |
---|
.. | .. |
---|
225 | 226 | if (atomic_inc_return(&dev->hdr.refcnt) > 1 || |
---|
226 | 227 | !dev->active_sensor || |
---|
227 | 228 | (dev->active_sensor && |
---|
228 | | - dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) || |
---|
| 229 | + dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) || |
---|
229 | 230 | (dev->isp_inp & INP_CIF) || |
---|
230 | 231 | (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21)) |
---|
231 | 232 | return 0; |
---|
.. | .. |
---|
294 | 295 | if (atomic_dec_return(&dev->hdr.refcnt) || |
---|
295 | 296 | !dev->active_sensor || |
---|
296 | 297 | (dev->active_sensor && |
---|
297 | | - dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) || |
---|
| 298 | + dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) || |
---|
298 | 299 | (dev->isp_inp & INP_CIF) || |
---|
299 | 300 | (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21)) |
---|
300 | 301 | return; |
---|
.. | .. |
---|
351 | 352 | if (!hw->dummy_buf.mem_priv || |
---|
352 | 353 | !dev->active_sensor || |
---|
353 | 354 | (dev->active_sensor && |
---|
354 | | - dev->active_sensor->mbus.type != V4L2_MBUS_CSI2) || |
---|
| 355 | + dev->active_sensor->mbus.type != V4L2_MBUS_CSI2_DPHY) || |
---|
355 | 356 | (dev->isp_inp & INP_CIF) || |
---|
356 | 357 | (dev->isp_ver != ISP_V20 && dev->isp_ver != ISP_V21)) |
---|
357 | 358 | return; |
---|
.. | .. |
---|
360 | 361 | */ |
---|
361 | 362 | for (i = 0; i < hw->dev_num; i++) { |
---|
362 | 363 | isp = hw->isp[i]; |
---|
363 | | - if (!(isp->isp_inp & INP_CSI)) |
---|
| 364 | + if (!isp || |
---|
| 365 | + (isp && !(isp->isp_inp & INP_CSI))) |
---|
364 | 366 | continue; |
---|
365 | 367 | for (j = RKISP_STREAM_DMATX0; j < RKISP_MAX_STREAM; j++) { |
---|
366 | 368 | stream = &isp->cap_dev.stream[j]; |
---|
367 | | - if (!stream->linked || stream->u.dmatx.is_config) |
---|
| 369 | + if (!stream->linked || stream->curr_buf || stream->next_buf) |
---|
368 | 370 | continue; |
---|
369 | 371 | mi_set_y_addr(stream, hw->dummy_buf.dma_addr); |
---|
370 | 372 | } |
---|
.. | .. |
---|
392 | 394 | case V4L2_PIX_FMT_NV16: |
---|
393 | 395 | case V4L2_PIX_FMT_NV61: |
---|
394 | 396 | case V4L2_PIX_FMT_YVU422M: |
---|
| 397 | + case V4L2_PIX_FMT_FBC2: |
---|
395 | 398 | *xsubs = 2; |
---|
396 | 399 | *ysubs = 1; |
---|
397 | 400 | break; |
---|
.. | .. |
---|
402 | 405 | case V4L2_PIX_FMT_YUV420: |
---|
403 | 406 | case V4L2_PIX_FMT_YVU420: |
---|
404 | 407 | case V4L2_PIX_FMT_FBCG: |
---|
| 408 | + case V4L2_PIX_FMT_FBC0: |
---|
405 | 409 | *xsubs = 2; |
---|
406 | 410 | *ysubs = 2; |
---|
407 | 411 | break; |
---|
.. | .. |
---|
430 | 434 | return 0; |
---|
431 | 435 | } |
---|
432 | 436 | |
---|
433 | | -static const struct capture_fmt mp_fmts[] = { |
---|
434 | | - /* yuv422 */ |
---|
435 | | - { |
---|
436 | | - .fourcc = V4L2_PIX_FMT_UYVY, |
---|
437 | | - .fmt_type = FMT_YUV, |
---|
438 | | - .bpp = { 16 }, |
---|
439 | | - .cplanes = 1, |
---|
440 | | - .mplanes = 1, |
---|
441 | | - .uv_swap = 0, |
---|
442 | | - .write_format = MI_CTRL_MP_WRITE_YUVINT, |
---|
443 | | - }, { |
---|
444 | | - .fourcc = V4L2_PIX_FMT_YUV422P, |
---|
445 | | - .fmt_type = FMT_YUV, |
---|
446 | | - .bpp = { 8, 4, 4 }, |
---|
447 | | - .cplanes = 3, |
---|
448 | | - .mplanes = 1, |
---|
449 | | - .uv_swap = 0, |
---|
450 | | - .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, |
---|
451 | | - }, { |
---|
452 | | - .fourcc = V4L2_PIX_FMT_NV16, |
---|
453 | | - .fmt_type = FMT_YUV, |
---|
454 | | - .bpp = { 8, 16 }, |
---|
455 | | - .cplanes = 2, |
---|
456 | | - .mplanes = 1, |
---|
457 | | - .uv_swap = 0, |
---|
458 | | - .write_format = MI_CTRL_MP_WRITE_YUV_SPLA, |
---|
459 | | - }, { |
---|
460 | | - .fourcc = V4L2_PIX_FMT_NV61, |
---|
461 | | - .fmt_type = FMT_YUV, |
---|
462 | | - .bpp = { 8, 16 }, |
---|
463 | | - .cplanes = 2, |
---|
464 | | - .mplanes = 1, |
---|
465 | | - .uv_swap = 1, |
---|
466 | | - .write_format = MI_CTRL_MP_WRITE_YUV_SPLA, |
---|
467 | | - }, { |
---|
468 | | - .fourcc = V4L2_PIX_FMT_YUV422M, |
---|
469 | | - .fmt_type = FMT_YUV, |
---|
470 | | - .bpp = { 8, 8, 8 }, |
---|
471 | | - .cplanes = 3, |
---|
472 | | - .mplanes = 3, |
---|
473 | | - .uv_swap = 0, |
---|
474 | | - .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, |
---|
475 | | - }, |
---|
476 | | - /* yuv420 */ |
---|
477 | | - { |
---|
478 | | - .fourcc = V4L2_PIX_FMT_NV21, |
---|
479 | | - .fmt_type = FMT_YUV, |
---|
480 | | - .bpp = { 8, 16 }, |
---|
481 | | - .cplanes = 2, |
---|
482 | | - .mplanes = 1, |
---|
483 | | - .uv_swap = 1, |
---|
484 | | - .write_format = MI_CTRL_MP_WRITE_YUV_SPLA, |
---|
485 | | - }, { |
---|
486 | | - .fourcc = V4L2_PIX_FMT_NV12, |
---|
487 | | - .fmt_type = FMT_YUV, |
---|
488 | | - .bpp = { 8, 16 }, |
---|
489 | | - .cplanes = 2, |
---|
490 | | - .mplanes = 1, |
---|
491 | | - .uv_swap = 0, |
---|
492 | | - .write_format = MI_CTRL_MP_WRITE_YUV_SPLA, |
---|
493 | | - }, { |
---|
494 | | - .fourcc = V4L2_PIX_FMT_NV21M, |
---|
495 | | - .fmt_type = FMT_YUV, |
---|
496 | | - .bpp = { 8, 16 }, |
---|
497 | | - .cplanes = 2, |
---|
498 | | - .mplanes = 2, |
---|
499 | | - .uv_swap = 1, |
---|
500 | | - .write_format = MI_CTRL_MP_WRITE_YUV_SPLA, |
---|
501 | | - }, { |
---|
502 | | - .fourcc = V4L2_PIX_FMT_NV12M, |
---|
503 | | - .fmt_type = FMT_YUV, |
---|
504 | | - .bpp = { 8, 16 }, |
---|
505 | | - .cplanes = 2, |
---|
506 | | - .mplanes = 2, |
---|
507 | | - .uv_swap = 0, |
---|
508 | | - .write_format = MI_CTRL_MP_WRITE_YUV_SPLA, |
---|
509 | | - }, { |
---|
510 | | - .fourcc = V4L2_PIX_FMT_YUV420, |
---|
511 | | - .fmt_type = FMT_YUV, |
---|
512 | | - .bpp = { 8, 8, 8 }, |
---|
513 | | - .cplanes = 3, |
---|
514 | | - .mplanes = 1, |
---|
515 | | - .uv_swap = 0, |
---|
516 | | - .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, |
---|
517 | | - }, |
---|
518 | | - /* yuv444 */ |
---|
519 | | - { |
---|
520 | | - .fourcc = V4L2_PIX_FMT_YUV444M, |
---|
521 | | - .fmt_type = FMT_YUV, |
---|
522 | | - .bpp = { 8, 8, 8 }, |
---|
523 | | - .cplanes = 3, |
---|
524 | | - .mplanes = 3, |
---|
525 | | - .uv_swap = 0, |
---|
526 | | - .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, |
---|
527 | | - }, |
---|
528 | | - /* raw */ |
---|
529 | | - { |
---|
530 | | - .fourcc = V4L2_PIX_FMT_SRGGB8, |
---|
531 | | - .fmt_type = FMT_BAYER, |
---|
532 | | - .bpp = { 8 }, |
---|
533 | | - .mplanes = 1, |
---|
534 | | - .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, |
---|
535 | | - }, { |
---|
536 | | - .fourcc = V4L2_PIX_FMT_SGRBG8, |
---|
537 | | - .fmt_type = FMT_BAYER, |
---|
538 | | - .bpp = { 8 }, |
---|
539 | | - .mplanes = 1, |
---|
540 | | - .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, |
---|
541 | | - }, { |
---|
542 | | - .fourcc = V4L2_PIX_FMT_SGBRG8, |
---|
543 | | - .fmt_type = FMT_BAYER, |
---|
544 | | - .bpp = { 8 }, |
---|
545 | | - .mplanes = 1, |
---|
546 | | - .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, |
---|
547 | | - }, { |
---|
548 | | - .fourcc = V4L2_PIX_FMT_SBGGR8, |
---|
549 | | - .fmt_type = FMT_BAYER, |
---|
550 | | - .bpp = { 8 }, |
---|
551 | | - .mplanes = 1, |
---|
552 | | - .write_format = MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, |
---|
553 | | - }, { |
---|
554 | | - .fourcc = V4L2_PIX_FMT_SRGGB10, |
---|
555 | | - .fmt_type = FMT_BAYER, |
---|
556 | | - .bpp = { 10 }, |
---|
557 | | - .mplanes = 1, |
---|
558 | | - .write_format = MI_CTRL_MP_WRITE_RAW12, |
---|
559 | | - }, { |
---|
560 | | - .fourcc = V4L2_PIX_FMT_SGRBG10, |
---|
561 | | - .fmt_type = FMT_BAYER, |
---|
562 | | - .bpp = { 10 }, |
---|
563 | | - .mplanes = 1, |
---|
564 | | - .write_format = MI_CTRL_MP_WRITE_RAW12, |
---|
565 | | - }, { |
---|
566 | | - .fourcc = V4L2_PIX_FMT_SGBRG10, |
---|
567 | | - .fmt_type = FMT_BAYER, |
---|
568 | | - .bpp = { 10 }, |
---|
569 | | - .mplanes = 1, |
---|
570 | | - .write_format = MI_CTRL_MP_WRITE_RAW12, |
---|
571 | | - }, { |
---|
572 | | - .fourcc = V4L2_PIX_FMT_SBGGR10, |
---|
573 | | - .fmt_type = FMT_BAYER, |
---|
574 | | - .bpp = { 10 }, |
---|
575 | | - .mplanes = 1, |
---|
576 | | - .write_format = MI_CTRL_MP_WRITE_RAW12, |
---|
577 | | - }, { |
---|
578 | | - .fourcc = V4L2_PIX_FMT_SRGGB12, |
---|
579 | | - .fmt_type = FMT_BAYER, |
---|
580 | | - .bpp = { 12 }, |
---|
581 | | - .mplanes = 1, |
---|
582 | | - .write_format = MI_CTRL_MP_WRITE_RAW12, |
---|
583 | | - }, { |
---|
584 | | - .fourcc = V4L2_PIX_FMT_SGRBG12, |
---|
585 | | - .fmt_type = FMT_BAYER, |
---|
586 | | - .bpp = { 12 }, |
---|
587 | | - .mplanes = 1, |
---|
588 | | - .write_format = MI_CTRL_MP_WRITE_RAW12, |
---|
589 | | - }, { |
---|
590 | | - .fourcc = V4L2_PIX_FMT_SGBRG12, |
---|
591 | | - .fmt_type = FMT_BAYER, |
---|
592 | | - .bpp = { 12 }, |
---|
593 | | - .mplanes = 1, |
---|
594 | | - .write_format = MI_CTRL_MP_WRITE_RAW12, |
---|
595 | | - }, { |
---|
596 | | - .fourcc = V4L2_PIX_FMT_SBGGR12, |
---|
597 | | - .fmt_type = FMT_BAYER, |
---|
598 | | - .bpp = { 12 }, |
---|
599 | | - .mplanes = 1, |
---|
600 | | - .write_format = MI_CTRL_MP_WRITE_RAW12, |
---|
601 | | - }, |
---|
602 | | -}; |
---|
| 437 | +int rkisp_stream_frame_start(struct rkisp_device *dev, u32 isp_mis) |
---|
| 438 | +{ |
---|
| 439 | + struct rkisp_stream *stream; |
---|
| 440 | + int i; |
---|
603 | 441 | |
---|
604 | | -static const struct capture_fmt sp_fmts[] = { |
---|
605 | | - /* yuv422 */ |
---|
606 | | - { |
---|
607 | | - .fourcc = V4L2_PIX_FMT_UYVY, |
---|
608 | | - .fmt_type = FMT_YUV, |
---|
609 | | - .bpp = { 16 }, |
---|
610 | | - .cplanes = 1, |
---|
611 | | - .mplanes = 1, |
---|
612 | | - .uv_swap = 0, |
---|
613 | | - .write_format = MI_CTRL_SP_WRITE_INT, |
---|
614 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV422, |
---|
615 | | - }, { |
---|
616 | | - .fourcc = V4L2_PIX_FMT_YUV422P, |
---|
617 | | - .fmt_type = FMT_YUV, |
---|
618 | | - .bpp = { 8, 8, 8 }, |
---|
619 | | - .cplanes = 3, |
---|
620 | | - .mplanes = 1, |
---|
621 | | - .uv_swap = 0, |
---|
622 | | - .write_format = MI_CTRL_SP_WRITE_PLA, |
---|
623 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV422, |
---|
624 | | - }, { |
---|
625 | | - .fourcc = V4L2_PIX_FMT_NV16, |
---|
626 | | - .fmt_type = FMT_YUV, |
---|
627 | | - .bpp = { 8, 16 }, |
---|
628 | | - .cplanes = 2, |
---|
629 | | - .mplanes = 1, |
---|
630 | | - .uv_swap = 0, |
---|
631 | | - .write_format = MI_CTRL_SP_WRITE_SPLA, |
---|
632 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV422, |
---|
633 | | - }, { |
---|
634 | | - .fourcc = V4L2_PIX_FMT_NV61, |
---|
635 | | - .fmt_type = FMT_YUV, |
---|
636 | | - .bpp = { 8, 16 }, |
---|
637 | | - .cplanes = 2, |
---|
638 | | - .mplanes = 1, |
---|
639 | | - .uv_swap = 1, |
---|
640 | | - .write_format = MI_CTRL_SP_WRITE_SPLA, |
---|
641 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV422, |
---|
642 | | - }, { |
---|
643 | | - .fourcc = V4L2_PIX_FMT_YUV422M, |
---|
644 | | - .fmt_type = FMT_YUV, |
---|
645 | | - .bpp = { 8, 8, 8 }, |
---|
646 | | - .cplanes = 3, |
---|
647 | | - .mplanes = 3, |
---|
648 | | - .uv_swap = 0, |
---|
649 | | - .write_format = MI_CTRL_SP_WRITE_PLA, |
---|
650 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV422, |
---|
651 | | - }, |
---|
652 | | - /* yuv420 */ |
---|
653 | | - { |
---|
654 | | - .fourcc = V4L2_PIX_FMT_NV21, |
---|
655 | | - .fmt_type = FMT_YUV, |
---|
656 | | - .bpp = { 8, 16 }, |
---|
657 | | - .cplanes = 2, |
---|
658 | | - .mplanes = 1, |
---|
659 | | - .uv_swap = 1, |
---|
660 | | - .write_format = MI_CTRL_SP_WRITE_SPLA, |
---|
661 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV420, |
---|
662 | | - }, { |
---|
663 | | - .fourcc = V4L2_PIX_FMT_NV12, |
---|
664 | | - .fmt_type = FMT_YUV, |
---|
665 | | - .bpp = { 8, 16 }, |
---|
666 | | - .cplanes = 2, |
---|
667 | | - .mplanes = 1, |
---|
668 | | - .uv_swap = 0, |
---|
669 | | - .write_format = MI_CTRL_SP_WRITE_SPLA, |
---|
670 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV420, |
---|
671 | | - }, { |
---|
672 | | - .fourcc = V4L2_PIX_FMT_NV21M, |
---|
673 | | - .fmt_type = FMT_YUV, |
---|
674 | | - .bpp = { 8, 16 }, |
---|
675 | | - .cplanes = 2, |
---|
676 | | - .mplanes = 2, |
---|
677 | | - .uv_swap = 1, |
---|
678 | | - .write_format = MI_CTRL_SP_WRITE_SPLA, |
---|
679 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV420, |
---|
680 | | - }, { |
---|
681 | | - .fourcc = V4L2_PIX_FMT_NV12M, |
---|
682 | | - .fmt_type = FMT_YUV, |
---|
683 | | - .bpp = { 8, 16 }, |
---|
684 | | - .cplanes = 2, |
---|
685 | | - .mplanes = 2, |
---|
686 | | - .uv_swap = 0, |
---|
687 | | - .write_format = MI_CTRL_SP_WRITE_SPLA, |
---|
688 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV420, |
---|
689 | | - }, { |
---|
690 | | - .fourcc = V4L2_PIX_FMT_YUV420, |
---|
691 | | - .fmt_type = FMT_YUV, |
---|
692 | | - .bpp = { 8, 8, 8 }, |
---|
693 | | - .cplanes = 3, |
---|
694 | | - .mplanes = 1, |
---|
695 | | - .uv_swap = 0, |
---|
696 | | - .write_format = MI_CTRL_SP_WRITE_PLA, |
---|
697 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV420, |
---|
698 | | - }, |
---|
699 | | - /* yuv444 */ |
---|
700 | | - { |
---|
701 | | - .fourcc = V4L2_PIX_FMT_YUV444M, |
---|
702 | | - .fmt_type = FMT_YUV, |
---|
703 | | - .bpp = { 8, 8, 8 }, |
---|
704 | | - .cplanes = 3, |
---|
705 | | - .mplanes = 3, |
---|
706 | | - .uv_swap = 0, |
---|
707 | | - .write_format = MI_CTRL_SP_WRITE_PLA, |
---|
708 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV444, |
---|
709 | | - }, |
---|
710 | | - /* yuv400 */ |
---|
711 | | - { |
---|
712 | | - .fourcc = V4L2_PIX_FMT_GREY, |
---|
713 | | - .fmt_type = FMT_YUV, |
---|
714 | | - .bpp = { 8 }, |
---|
715 | | - .cplanes = 1, |
---|
716 | | - .mplanes = 1, |
---|
717 | | - .uv_swap = 0, |
---|
718 | | - .write_format = MI_CTRL_SP_WRITE_PLA, |
---|
719 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV400, |
---|
720 | | - }, |
---|
721 | | - /* rgb */ |
---|
722 | | - { |
---|
723 | | - .fourcc = V4L2_PIX_FMT_XBGR32, |
---|
724 | | - .fmt_type = FMT_RGB, |
---|
725 | | - .bpp = { 32 }, |
---|
726 | | - .mplanes = 1, |
---|
727 | | - .write_format = MI_CTRL_SP_WRITE_PLA, |
---|
728 | | - .output_format = MI_CTRL_SP_OUTPUT_RGB888, |
---|
729 | | - }, { |
---|
730 | | - .fourcc = V4L2_PIX_FMT_RGB565, |
---|
731 | | - .fmt_type = FMT_RGB, |
---|
732 | | - .bpp = { 16 }, |
---|
733 | | - .mplanes = 1, |
---|
734 | | - .write_format = MI_CTRL_SP_WRITE_PLA, |
---|
735 | | - .output_format = MI_CTRL_SP_OUTPUT_RGB565, |
---|
736 | | - }, |
---|
737 | | - /* fbcg */ |
---|
738 | | - { |
---|
739 | | - .fourcc = V4L2_PIX_FMT_FBCG, |
---|
740 | | - .fmt_type = FMT_FBCGAIN, |
---|
741 | | - .bpp = { 8, 16 }, |
---|
742 | | - .cplanes = 2, |
---|
743 | | - .mplanes = 2, |
---|
744 | | - .uv_swap = 0, |
---|
745 | | - .write_format = MI_CTRL_SP_WRITE_SPLA, |
---|
746 | | - .output_format = MI_CTRL_SP_OUTPUT_YUV420, |
---|
| 442 | + if (isp_mis) |
---|
| 443 | + rkisp_dvbm_event(dev, CIF_ISP_V_START); |
---|
| 444 | + rkisp_bridge_update_mi(dev, isp_mis); |
---|
| 445 | + |
---|
| 446 | + for (i = 0; i < RKISP_MAX_STREAM; i++) { |
---|
| 447 | + if (i == RKISP_STREAM_VIR || i == RKISP_STREAM_LUMA) |
---|
| 448 | + continue; |
---|
| 449 | + stream = &dev->cap_dev.stream[i]; |
---|
| 450 | + if (stream->streaming && |
---|
| 451 | + stream->ops && stream->ops->frame_start) |
---|
| 452 | + stream->ops->frame_start(stream, isp_mis); |
---|
747 | 453 | } |
---|
748 | | -}; |
---|
| 454 | + |
---|
| 455 | + return 0; |
---|
| 456 | +} |
---|
| 457 | + |
---|
| 458 | +void rkisp_stream_buf_done_early(struct rkisp_device *dev) |
---|
| 459 | +{ |
---|
| 460 | + struct rkisp_stream *stream; |
---|
| 461 | + int i; |
---|
| 462 | + |
---|
| 463 | + if (!dev->cap_dev.is_done_early) |
---|
| 464 | + return; |
---|
| 465 | + |
---|
| 466 | + for (i = 0; i < RKISP_MAX_STREAM; i++) { |
---|
| 467 | + if (i == RKISP_STREAM_VIR || i == RKISP_STREAM_LUMA || |
---|
| 468 | + i == RKISP_STREAM_DMATX0 || i == RKISP_STREAM_DMATX1 || |
---|
| 469 | + i == RKISP_STREAM_DMATX2 || i == RKISP_STREAM_DMATX3) |
---|
| 470 | + continue; |
---|
| 471 | + stream = &dev->cap_dev.stream[i]; |
---|
| 472 | + if (stream->streaming && !stream->stopping && |
---|
| 473 | + stream->ops && stream->ops->frame_end) |
---|
| 474 | + stream->ops->frame_end(stream, FRAME_WORK); |
---|
| 475 | + } |
---|
| 476 | +} |
---|
749 | 477 | |
---|
750 | 478 | struct stream_config rkisp_mp_stream_config = { |
---|
751 | | - .fmts = mp_fmts, |
---|
752 | | - .fmt_size = ARRAY_SIZE(mp_fmts), |
---|
753 | 479 | /* constraints */ |
---|
754 | 480 | .max_rsz_width = STREAM_MAX_MP_RSZ_OUTPUT_WIDTH, |
---|
755 | 481 | .max_rsz_height = STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT, |
---|
.. | .. |
---|
801 | 527 | .cb_offs_cnt_init = CIF_MI_MP_CB_OFFS_CNT_INIT, |
---|
802 | 528 | .cr_offs_cnt_init = CIF_MI_MP_CR_OFFS_CNT_INIT, |
---|
803 | 529 | .y_base_ad_shd = CIF_MI_MP_Y_BASE_AD_SHD, |
---|
| 530 | + .y_pic_size = ISP3X_MI_MP_WR_Y_PIC_SIZE, |
---|
804 | 531 | }, |
---|
805 | 532 | }; |
---|
806 | 533 | |
---|
807 | 534 | struct stream_config rkisp_sp_stream_config = { |
---|
808 | | - .fmts = sp_fmts, |
---|
809 | | - .fmt_size = ARRAY_SIZE(sp_fmts), |
---|
810 | 535 | /* constraints */ |
---|
811 | 536 | .max_rsz_width = STREAM_MAX_SP_RSZ_OUTPUT_WIDTH, |
---|
812 | 537 | .max_rsz_height = STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT, |
---|
.. | .. |
---|
858 | 583 | .cb_offs_cnt_init = CIF_MI_SP_CB_OFFS_CNT_INIT, |
---|
859 | 584 | .cr_offs_cnt_init = CIF_MI_SP_CR_OFFS_CNT_INIT, |
---|
860 | 585 | .y_base_ad_shd = CIF_MI_SP_Y_BASE_AD_SHD, |
---|
| 586 | + .y_pic_size = ISP3X_MI_SP_WR_Y_PIC_SIZE, |
---|
861 | 587 | }, |
---|
862 | 588 | }; |
---|
863 | 589 | |
---|
.. | .. |
---|
875 | 601 | return NULL; |
---|
876 | 602 | } |
---|
877 | 603 | |
---|
878 | | -/* |
---|
879 | | - * Make sure max resize/output resolution is smaller than |
---|
880 | | - * isp sub device output size. This assumes it's not |
---|
881 | | - * recommended to use ISP scale-up function to get output size |
---|
882 | | - * that exceeds sensor max resolution. |
---|
883 | | - */ |
---|
884 | | -static void restrict_rsz_resolution(struct rkisp_device *dev, |
---|
885 | | - const struct stream_config *config, |
---|
| 604 | +static void restrict_rsz_resolution(struct rkisp_stream *stream, |
---|
| 605 | + const struct stream_config *cfg, |
---|
886 | 606 | struct v4l2_rect *max_rsz) |
---|
887 | 607 | { |
---|
888 | | - struct v4l2_rect *input_win; |
---|
| 608 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 609 | + struct v4l2_rect *input_win = rkisp_get_isp_sd_win(&dev->isp_sdev); |
---|
889 | 610 | |
---|
890 | | - input_win = rkisp_get_isp_sd_win(&dev->isp_sdev); |
---|
891 | | - max_rsz->width = min_t(int, input_win->width, config->max_rsz_width); |
---|
892 | | - max_rsz->height = min_t(int, input_win->height, config->max_rsz_height); |
---|
| 611 | + if (stream->id == RKISP_STREAM_VIR || |
---|
| 612 | + (dev->isp_ver == ISP_V30 && stream->id == RKISP_STREAM_BP)) { |
---|
| 613 | + max_rsz->width = input_win->width; |
---|
| 614 | + max_rsz->height = input_win->height; |
---|
| 615 | + } else if (stream->id == RKISP_STREAM_FBC) { |
---|
| 616 | + max_rsz->width = stream->dcrop.width; |
---|
| 617 | + max_rsz->height = stream->dcrop.height; |
---|
| 618 | + } else if (stream->id == RKISP_STREAM_MPDS || |
---|
| 619 | + stream->id == RKISP_STREAM_BPDS) { |
---|
| 620 | + struct rkisp_stream *t = &dev->cap_dev.stream[stream->conn_id]; |
---|
| 621 | + |
---|
| 622 | + max_rsz->width = t->out_fmt.width / 4; |
---|
| 623 | + max_rsz->height = t->out_fmt.height / 4; |
---|
| 624 | + } else if (stream->id == RKISP_STREAM_LUMA) { |
---|
| 625 | + u32 div = dev->is_bigmode ? 32 : 16; |
---|
| 626 | + |
---|
| 627 | + max_rsz->width = ALIGN(DIV_ROUND_UP(input_win->width, div), 4); |
---|
| 628 | + max_rsz->height = DIV_ROUND_UP(input_win->height, div); |
---|
| 629 | + } else if (dev->hw_dev->unite) { |
---|
| 630 | + /* scale down only for unite mode */ |
---|
| 631 | + max_rsz->width = min_t(int, input_win->width, cfg->max_rsz_width); |
---|
| 632 | + max_rsz->height = min_t(int, input_win->height, cfg->max_rsz_height); |
---|
| 633 | + } else { |
---|
| 634 | + /* scale up/down */ |
---|
| 635 | + max_rsz->width = cfg->max_rsz_width; |
---|
| 636 | + max_rsz->height = cfg->max_rsz_height; |
---|
| 637 | + } |
---|
893 | 638 | } |
---|
894 | 639 | |
---|
895 | 640 | static int rkisp_set_fmt(struct rkisp_stream *stream, |
---|
.. | .. |
---|
897 | 642 | bool try) |
---|
898 | 643 | { |
---|
899 | 644 | const struct capture_fmt *fmt; |
---|
| 645 | + struct rkisp_vdev_node *node = &stream->vnode; |
---|
900 | 646 | const struct stream_config *config = stream->config; |
---|
901 | 647 | struct rkisp_device *dev = stream->ispdev; |
---|
902 | | - struct rkisp_stream *other_stream; |
---|
903 | | - unsigned int imagsize = 0; |
---|
904 | | - unsigned int planes; |
---|
905 | | - u32 xsubs = 1, ysubs = 1; |
---|
906 | | - unsigned int i; |
---|
| 648 | + struct v4l2_rect max_rsz; |
---|
| 649 | + u32 i, planes, imagsize = 0, xsubs = 1, ysubs = 1; |
---|
907 | 650 | |
---|
908 | 651 | fmt = find_fmt(stream, pixm->pixelformat); |
---|
909 | 652 | if (!fmt) { |
---|
910 | | - v4l2_err(&stream->ispdev->v4l2_dev, |
---|
911 | | - "nonsupport pixelformat:%c%c%c%c\n", |
---|
| 653 | + v4l2_err(&dev->v4l2_dev, |
---|
| 654 | + "%s nonsupport pixelformat:%c%c%c%c\n", |
---|
| 655 | + node->vdev.name, |
---|
912 | 656 | pixm->pixelformat, |
---|
913 | 657 | pixm->pixelformat >> 8, |
---|
914 | 658 | pixm->pixelformat >> 16, |
---|
.. | .. |
---|
916 | 660 | return -EINVAL; |
---|
917 | 661 | } |
---|
918 | 662 | |
---|
| 663 | + /* do checks on resolution */ |
---|
| 664 | + restrict_rsz_resolution(stream, config, &max_rsz); |
---|
919 | 665 | if (stream->id == RKISP_STREAM_MP || |
---|
920 | | - stream->id == RKISP_STREAM_SP) { |
---|
921 | | - struct v4l2_rect max_rsz; |
---|
| 666 | + stream->id == RKISP_STREAM_SP || |
---|
| 667 | + (stream->id == RKISP_STREAM_BP && dev->isp_ver != ISP_V30)) { |
---|
| 668 | + pixm->width = clamp_t(u32, pixm->width, config->min_rsz_width, max_rsz.width); |
---|
| 669 | + } else if (pixm->width != max_rsz.width && |
---|
| 670 | + pixm->height != max_rsz.height && |
---|
| 671 | + (stream->id == RKISP_STREAM_LUMA || |
---|
| 672 | + (dev->isp_ver == ISP_V30 && |
---|
| 673 | + (stream->id == RKISP_STREAM_BP || stream->id == RKISP_STREAM_FBC)))) { |
---|
| 674 | + v4l2_warn(&dev->v4l2_dev, |
---|
| 675 | + "%s no scale %dx%d should equal to %dx%d\n", |
---|
| 676 | + node->vdev.name, |
---|
| 677 | + pixm->width, pixm->height, |
---|
| 678 | + max_rsz.width, max_rsz.height); |
---|
| 679 | + pixm->width = max_rsz.width; |
---|
| 680 | + pixm->height = max_rsz.height; |
---|
| 681 | + } else if (stream->id == RKISP_STREAM_MPDS || stream->id == RKISP_STREAM_BPDS) { |
---|
| 682 | + struct rkisp_stream *t = &dev->cap_dev.stream[stream->conn_id]; |
---|
922 | 683 | |
---|
923 | | - other_stream = (stream->id == RKISP_STREAM_MP) ? |
---|
924 | | - &dev->cap_dev.stream[RKISP_STREAM_SP] : |
---|
925 | | - &dev->cap_dev.stream[RKISP_STREAM_MP]; |
---|
926 | | - /* do checks on resolution */ |
---|
927 | | - restrict_rsz_resolution(stream->ispdev, config, &max_rsz); |
---|
928 | | - pixm->width = clamp_t(u32, pixm->width, |
---|
929 | | - config->min_rsz_width, max_rsz.width); |
---|
930 | | - pixm->height = clamp_t(u32, pixm->height, |
---|
931 | | - config->min_rsz_height, max_rsz.height); |
---|
932 | | - } else { |
---|
933 | | - other_stream = |
---|
934 | | - &stream->ispdev->cap_dev.stream[RKISP_STREAM_MP]; |
---|
| 684 | + if (pixm->pixelformat != t->out_fmt.pixelformat || |
---|
| 685 | + pixm->width != max_rsz.width || pixm->height != max_rsz.height) { |
---|
| 686 | + v4l2_warn(&dev->v4l2_dev, |
---|
| 687 | + "%s from %s, force to %dx%d %c%c%c%c\n", |
---|
| 688 | + node->vdev.name, t->vnode.vdev.name, |
---|
| 689 | + max_rsz.width, max_rsz.height, |
---|
| 690 | + t->out_fmt.pixelformat, |
---|
| 691 | + t->out_fmt.pixelformat >> 8, |
---|
| 692 | + t->out_fmt.pixelformat >> 16, |
---|
| 693 | + t->out_fmt.pixelformat >> 24); |
---|
| 694 | + pixm->pixelformat = t->out_fmt.pixelformat; |
---|
| 695 | + pixm->width = max_rsz.width; |
---|
| 696 | + pixm->height = max_rsz.height; |
---|
| 697 | + } |
---|
| 698 | + } else if (stream->id == RKISP_STREAM_VIR) { |
---|
| 699 | + struct rkisp_stream *t; |
---|
| 700 | + |
---|
| 701 | + if (stream->conn_id != -1) { |
---|
| 702 | + t = &dev->cap_dev.stream[stream->conn_id]; |
---|
| 703 | + *pixm = t->out_fmt; |
---|
| 704 | + } else { |
---|
| 705 | + for (i = RKISP_STREAM_MP; i < RKISP_STREAM_VIR; i++) { |
---|
| 706 | + t = &dev->cap_dev.stream[i]; |
---|
| 707 | + if (t->out_isp_fmt.fmt_type != FMT_YUV || !t->streaming) |
---|
| 708 | + continue; |
---|
| 709 | + if (t->out_fmt.plane_fmt[0].sizeimage > imagsize) { |
---|
| 710 | + imagsize = t->out_fmt.plane_fmt[0].sizeimage; |
---|
| 711 | + *pixm = t->out_fmt; |
---|
| 712 | + stream->conn_id = t->id; |
---|
| 713 | + } |
---|
| 714 | + } |
---|
| 715 | + } |
---|
| 716 | + if (stream->conn_id == -1) { |
---|
| 717 | + v4l2_err(&dev->v4l2_dev, "no output stream for iqtool\n"); |
---|
| 718 | + return -EINVAL; |
---|
| 719 | + } |
---|
| 720 | + imagsize = 0; |
---|
935 | 721 | } |
---|
| 722 | + |
---|
936 | 723 | pixm->num_planes = fmt->mplanes; |
---|
937 | 724 | pixm->field = V4L2_FIELD_NONE; |
---|
938 | 725 | /* get quantization from ispsd */ |
---|
939 | 726 | pixm->quantization = stream->ispdev->isp_sdev.quantization; |
---|
940 | | - |
---|
941 | | - /* output full range by default, take effect in isp_params */ |
---|
942 | | - if (!pixm->quantization) |
---|
943 | | - pixm->quantization = V4L2_QUANTIZATION_FULL_RANGE; |
---|
944 | | - /* can not change quantization when stream-on */ |
---|
945 | | - if (other_stream->streaming) |
---|
946 | | - pixm->quantization = other_stream->out_fmt.quantization; |
---|
947 | 727 | |
---|
948 | 728 | /* calculate size */ |
---|
949 | 729 | rkisp_fcc_xysubs(fmt->fourcc, &xsubs, &ysubs); |
---|
950 | 730 | planes = fmt->cplanes ? fmt->cplanes : fmt->mplanes; |
---|
951 | 731 | for (i = 0; i < planes; i++) { |
---|
952 | 732 | struct v4l2_plane_pix_format *plane_fmt; |
---|
953 | | - unsigned int width, height, bytesperline; |
---|
| 733 | + unsigned int width, height, bytesperline, w, h; |
---|
954 | 734 | |
---|
955 | 735 | plane_fmt = pixm->plane_fmt + i; |
---|
956 | 736 | |
---|
957 | | - if (i == 0) { |
---|
958 | | - width = pixm->width; |
---|
959 | | - height = pixm->height; |
---|
960 | | - } else { |
---|
961 | | - width = pixm->width / xsubs; |
---|
962 | | - height = pixm->height / ysubs; |
---|
963 | | - } |
---|
| 737 | + w = (fmt->fmt_type == FMT_FBC) ? |
---|
| 738 | + ALIGN(pixm->width, 16) : pixm->width; |
---|
| 739 | + h = (fmt->fmt_type == FMT_FBC) ? |
---|
| 740 | + ALIGN(pixm->height, 16) : pixm->height; |
---|
| 741 | + /* mainpath for warp default */ |
---|
| 742 | + if (dev->cap_dev.wrap_line && stream->id == RKISP_STREAM_MP) |
---|
| 743 | + h = dev->cap_dev.wrap_line; |
---|
| 744 | + width = i ? w / xsubs : w; |
---|
| 745 | + height = i ? h / ysubs : h; |
---|
964 | 746 | |
---|
965 | 747 | if (dev->isp_ver == ISP_V20 && |
---|
966 | 748 | fmt->fmt_type == FMT_BAYER && |
---|
.. | .. |
---|
977 | 759 | bytesperline = ALIGN(width * fmt->bpp[i] / 8, 256); |
---|
978 | 760 | else |
---|
979 | 761 | bytesperline = width * DIV_ROUND_UP(fmt->bpp[i], 8); |
---|
980 | | - /* 128bit AXI, 16byte align for bytesperline */ |
---|
981 | | - if (dev->isp_ver >= ISP_V20 && stream->id == RKISP_STREAM_SP) |
---|
982 | | - bytesperline = ALIGN(bytesperline, 16); |
---|
983 | | - /* stride is only available for sp stream and y plane */ |
---|
984 | | - if (stream->id != RKISP_STREAM_SP || i != 0 || |
---|
985 | | - plane_fmt->bytesperline < bytesperline) |
---|
| 762 | + |
---|
| 763 | + if (i != 0 || plane_fmt->bytesperline < bytesperline) |
---|
986 | 764 | plane_fmt->bytesperline = bytesperline; |
---|
| 765 | + |
---|
| 766 | + /* 128bit AXI, 16byte align for bytesperline */ |
---|
| 767 | + if ((dev->isp_ver == ISP_V20 && stream->id == RKISP_STREAM_SP) || |
---|
| 768 | + dev->isp_ver >= ISP_V30) |
---|
| 769 | + plane_fmt->bytesperline = ALIGN(plane_fmt->bytesperline, 16); |
---|
987 | 770 | |
---|
988 | 771 | plane_fmt->sizeimage = plane_fmt->bytesperline * height; |
---|
989 | 772 | |
---|
990 | | - /* uv address is y size offset need 64 align */ |
---|
| 773 | + /* FMT_FBCGAIN: uv address is y size offset need 64 align |
---|
| 774 | + * FMT_FBC: width and height need 16 align |
---|
| 775 | + * header: width * height / 16, and 4096 align for mpp |
---|
| 776 | + * payload: yuv420 or yuv422 size |
---|
| 777 | + */ |
---|
991 | 778 | if (fmt->fmt_type == FMT_FBCGAIN && i == 0) |
---|
992 | 779 | plane_fmt->sizeimage = ALIGN(plane_fmt->sizeimage, 64); |
---|
993 | | - |
---|
| 780 | + else if (fmt->fmt_type == FMT_FBC && i == 0) |
---|
| 781 | + plane_fmt->sizeimage = ALIGN(plane_fmt->sizeimage >> 4, RK_MPP_ALIGN); |
---|
| 782 | + else if (fmt->fmt_type == FMT_FBC) |
---|
| 783 | + plane_fmt->sizeimage += w * h; |
---|
994 | 784 | imagsize += plane_fmt->sizeimage; |
---|
995 | 785 | } |
---|
996 | 786 | |
---|
.. | .. |
---|
1014 | 804 | } |
---|
1015 | 805 | |
---|
1016 | 806 | v4l2_dbg(1, rkisp_debug, &stream->ispdev->v4l2_dev, |
---|
1017 | | - "%s: stream: %d req(%d, %d) out(%d, %d)\n", __func__, |
---|
1018 | | - stream->id, pixm->width, pixm->height, |
---|
| 807 | + "%s: %s req(%d, %d) out(%d, %d)\n", __func__, |
---|
| 808 | + node->vdev.name, pixm->width, pixm->height, |
---|
1019 | 809 | stream->out_fmt.width, stream->out_fmt.height); |
---|
1020 | 810 | } |
---|
1021 | 811 | |
---|
1022 | 812 | return 0; |
---|
1023 | 813 | } |
---|
1024 | 814 | |
---|
| 815 | +struct rockit_isp_ops rockit_isp_ops = { |
---|
| 816 | + .rkisp_set_fmt = rkisp_set_fmt, |
---|
| 817 | +}; |
---|
| 818 | + |
---|
1025 | 819 | int rkisp_fh_open(struct file *filp) |
---|
1026 | 820 | { |
---|
1027 | 821 | struct rkisp_stream *stream = video_drvdata(filp); |
---|
1028 | 822 | int ret; |
---|
1029 | 823 | |
---|
| 824 | + if (!stream->ispdev->is_probe_end) |
---|
| 825 | + return -EINVAL; |
---|
| 826 | + |
---|
1030 | 827 | ret = v4l2_fh_open(filp); |
---|
1031 | 828 | if (!ret) { |
---|
1032 | | - ret = v4l2_pipeline_pm_use(&stream->vnode.vdev.entity, 1); |
---|
| 829 | + ret = v4l2_pipeline_pm_get(&stream->vnode.vdev.entity); |
---|
1033 | 830 | if (ret < 0) |
---|
1034 | 831 | vb2_fop_release(filp); |
---|
1035 | 832 | } |
---|
.. | .. |
---|
1043 | 840 | int ret; |
---|
1044 | 841 | |
---|
1045 | 842 | ret = vb2_fop_release(file); |
---|
1046 | | - if (!ret) { |
---|
1047 | | - ret = v4l2_pipeline_pm_use(&stream->vnode.vdev.entity, 0); |
---|
1048 | | - if (ret < 0) |
---|
1049 | | - v4l2_err(&stream->ispdev->v4l2_dev, |
---|
1050 | | - "set pipeline power failed %d\n", ret); |
---|
1051 | | - } |
---|
| 843 | + if (!ret) |
---|
| 844 | + v4l2_pipeline_pm_put(&stream->vnode.vdev.entity); |
---|
1052 | 845 | return ret; |
---|
1053 | 846 | } |
---|
1054 | 847 | |
---|
.. | .. |
---|
1065 | 858 | pixm.pixelformat = stream->out_isp_fmt.fourcc; |
---|
1066 | 859 | if (!pixm.pixelformat) |
---|
1067 | 860 | return; |
---|
1068 | | - pixm.width = width; |
---|
1069 | | - pixm.height = height; |
---|
1070 | | - rkisp_set_fmt(stream, &pixm, false); |
---|
1071 | 861 | |
---|
1072 | 862 | stream->dcrop.left = 0; |
---|
1073 | 863 | stream->dcrop.top = 0; |
---|
1074 | 864 | stream->dcrop.width = width; |
---|
1075 | 865 | stream->dcrop.height = height; |
---|
| 866 | + |
---|
| 867 | + pixm.width = width; |
---|
| 868 | + pixm.height = height; |
---|
| 869 | + rkisp_set_fmt(stream, &pixm, false); |
---|
1076 | 870 | } |
---|
1077 | 871 | |
---|
1078 | 872 | /************************* v4l2_file_operations***************************/ |
---|
.. | .. |
---|
1082 | 876 | .unlocked_ioctl = video_ioctl2, |
---|
1083 | 877 | .poll = vb2_fop_poll, |
---|
1084 | 878 | .mmap = vb2_fop_mmap, |
---|
| 879 | +#ifdef CONFIG_COMPAT |
---|
| 880 | + .compat_ioctl32 = video_ioctl2, |
---|
| 881 | +#endif |
---|
1085 | 882 | }; |
---|
1086 | 883 | |
---|
1087 | 884 | /* |
---|
.. | .. |
---|
1115 | 912 | const struct stream_config *config = stream->config; |
---|
1116 | 913 | struct v4l2_frmsize_stepwise *s = &fsize->stepwise; |
---|
1117 | 914 | struct v4l2_frmsize_discrete *d = &fsize->discrete; |
---|
1118 | | - const struct ispsd_out_fmt *input_isp_fmt; |
---|
| 915 | + struct rkisp_device *dev = stream->ispdev; |
---|
1119 | 916 | struct v4l2_rect max_rsz; |
---|
| 917 | + struct v4l2_rect *input_win = rkisp_get_isp_sd_win(&dev->isp_sdev); |
---|
1120 | 918 | |
---|
1121 | 919 | if (fsize->index != 0) |
---|
1122 | 920 | return -EINVAL; |
---|
.. | .. |
---|
1124 | 922 | if (!find_fmt(stream, fsize->pixel_format)) |
---|
1125 | 923 | return -EINVAL; |
---|
1126 | 924 | |
---|
1127 | | - restrict_rsz_resolution(stream->ispdev, config, &max_rsz); |
---|
| 925 | + restrict_rsz_resolution(stream, config, &max_rsz); |
---|
1128 | 926 | |
---|
1129 | | - input_isp_fmt = rkisp_get_ispsd_out_fmt(&stream->ispdev->isp_sdev); |
---|
1130 | | - if (input_isp_fmt->fmt_type == FMT_BAYER) { |
---|
| 927 | + if (stream->out_isp_fmt.fmt_type == FMT_BAYER || |
---|
| 928 | + stream->id == RKISP_STREAM_FBC || |
---|
| 929 | + stream->id == RKISP_STREAM_BPDS || |
---|
| 930 | + stream->id == RKISP_STREAM_MPDS || |
---|
| 931 | + stream->id == RKISP_STREAM_LUMA || |
---|
| 932 | + stream->id == RKISP_STREAM_VIR || |
---|
| 933 | + (stream->id == RKISP_STREAM_BP && dev->hw_dev->isp_ver == ISP_V30)) { |
---|
1131 | 934 | fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; |
---|
1132 | 935 | d->width = max_rsz.width; |
---|
1133 | 936 | d->height = max_rsz.height; |
---|
.. | .. |
---|
1135 | 938 | fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; |
---|
1136 | 939 | s->min_width = STREAM_MIN_RSZ_OUTPUT_WIDTH; |
---|
1137 | 940 | s->min_height = STREAM_MIN_RSZ_OUTPUT_HEIGHT; |
---|
1138 | | - s->max_width = max_rsz.width; |
---|
1139 | | - s->max_height = max_rsz.height; |
---|
| 941 | + s->max_width = min_t(u32, max_rsz.width, input_win->width); |
---|
| 942 | + s->max_height = input_win->height; |
---|
1140 | 943 | s->step_width = STREAM_OUTPUT_STEP_WISE; |
---|
1141 | 944 | s->step_height = STREAM_OUTPUT_STEP_WISE; |
---|
1142 | 945 | } |
---|
1143 | 946 | |
---|
1144 | 947 | return 0; |
---|
| 948 | +} |
---|
| 949 | + |
---|
| 950 | +static int rkisp_get_cmsk(struct rkisp_stream *stream, struct rkisp_cmsk_cfg *cfg) |
---|
| 951 | +{ |
---|
| 952 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 953 | + unsigned long lock_flags = 0; |
---|
| 954 | + u32 i, win_en, mode; |
---|
| 955 | + |
---|
| 956 | + if ((dev->isp_ver != ISP_V30 && dev->isp_ver != ISP_V32) || |
---|
| 957 | + stream->id == RKISP_STREAM_FBC || |
---|
| 958 | + stream->id == RKISP_STREAM_MPDS || |
---|
| 959 | + stream->id == RKISP_STREAM_BPDS) { |
---|
| 960 | + v4l2_err(&dev->v4l2_dev, "%s not support\n", __func__); |
---|
| 961 | + return -EINVAL; |
---|
| 962 | + } |
---|
| 963 | + |
---|
| 964 | + spin_lock_irqsave(&dev->cmsk_lock, lock_flags); |
---|
| 965 | + *cfg = dev->cmsk_cfg; |
---|
| 966 | + spin_unlock_irqrestore(&dev->cmsk_lock, lock_flags); |
---|
| 967 | + |
---|
| 968 | + switch (stream->id) { |
---|
| 969 | + case RKISP_STREAM_MP: |
---|
| 970 | + win_en = cfg->win[0].win_en; |
---|
| 971 | + mode = cfg->win[0].mode; |
---|
| 972 | + break; |
---|
| 973 | + case RKISP_STREAM_SP: |
---|
| 974 | + win_en = cfg->win[1].win_en; |
---|
| 975 | + mode = cfg->win[1].mode; |
---|
| 976 | + break; |
---|
| 977 | + case RKISP_STREAM_BP: |
---|
| 978 | + default: |
---|
| 979 | + win_en = cfg->win[2].win_en; |
---|
| 980 | + mode = cfg->win[2].mode; |
---|
| 981 | + break; |
---|
| 982 | + } |
---|
| 983 | + |
---|
| 984 | + cfg->width_ro = dev->isp_sdev.out_crop.width; |
---|
| 985 | + cfg->height_ro = dev->isp_sdev.out_crop.height; |
---|
| 986 | + for (i = 0; i < RKISP_CMSK_WIN_MAX; i++) { |
---|
| 987 | + cfg->win[i].win_en = !!(win_en & BIT(i)); |
---|
| 988 | + cfg->win[i].mode = !!(mode & BIT(i)); |
---|
| 989 | + } |
---|
| 990 | + |
---|
| 991 | + return 0; |
---|
| 992 | +} |
---|
| 993 | + |
---|
| 994 | +static int rkisp_set_cmsk(struct rkisp_stream *stream, struct rkisp_cmsk_cfg *cfg) |
---|
| 995 | +{ |
---|
| 996 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 997 | + unsigned long lock_flags = 0; |
---|
| 998 | + u16 i, win_en = 0, mode = 0; |
---|
| 999 | + u16 h_offs, v_offs, h_size, v_size; |
---|
| 1000 | + u32 width = dev->isp_sdev.out_crop.width; |
---|
| 1001 | + u32 height = dev->isp_sdev.out_crop.height; |
---|
| 1002 | + u32 align = (dev->isp_ver == ISP_V30) ? 8 : 2; |
---|
| 1003 | + bool warn = false; |
---|
| 1004 | + |
---|
| 1005 | + if ((dev->isp_ver != ISP_V30 && dev->isp_ver != ISP_V32) || |
---|
| 1006 | + stream->id == RKISP_STREAM_FBC || |
---|
| 1007 | + stream->id == RKISP_STREAM_MPDS || |
---|
| 1008 | + stream->id == RKISP_STREAM_BPDS) { |
---|
| 1009 | + v4l2_err(&dev->v4l2_dev, "%s not support\n", __func__); |
---|
| 1010 | + return -EINVAL; |
---|
| 1011 | + } |
---|
| 1012 | + |
---|
| 1013 | + spin_lock_irqsave(&dev->cmsk_lock, lock_flags); |
---|
| 1014 | + dev->is_cmsk_upd = true; |
---|
| 1015 | + for (i = 0; i < RKISP_CMSK_WIN_MAX; i++) { |
---|
| 1016 | + win_en |= cfg->win[i].win_en ? BIT(i) : 0; |
---|
| 1017 | + mode |= cfg->win[i].mode ? BIT(i) : 0; |
---|
| 1018 | + |
---|
| 1019 | + if (cfg->win[i].win_en) { |
---|
| 1020 | + if (cfg->win[i].mode) { |
---|
| 1021 | + dev->cmsk_cfg.win[i].cover_color_y = cfg->win[i].cover_color_y; |
---|
| 1022 | + dev->cmsk_cfg.win[i].cover_color_u = cfg->win[i].cover_color_u; |
---|
| 1023 | + dev->cmsk_cfg.win[i].cover_color_v = cfg->win[i].cover_color_v; |
---|
| 1024 | + } |
---|
| 1025 | + h_offs = cfg->win[i].h_offs & ~0x1; |
---|
| 1026 | + v_offs = cfg->win[i].v_offs & ~0x1; |
---|
| 1027 | + h_size = ALIGN_DOWN(cfg->win[i].h_size, align); |
---|
| 1028 | + v_size = ALIGN_DOWN(cfg->win[i].v_size, align); |
---|
| 1029 | + if (h_offs != cfg->win[i].h_offs || |
---|
| 1030 | + v_offs != cfg->win[i].v_offs || |
---|
| 1031 | + h_size != cfg->win[i].h_size || |
---|
| 1032 | + v_size != cfg->win[i].v_size) |
---|
| 1033 | + warn = true; |
---|
| 1034 | + if (h_offs + h_size > width) { |
---|
| 1035 | + h_size = ALIGN_DOWN(width - h_offs, align); |
---|
| 1036 | + warn = true; |
---|
| 1037 | + } |
---|
| 1038 | + if (v_offs + v_size > height) { |
---|
| 1039 | + v_size = ALIGN_DOWN(height - v_offs, align); |
---|
| 1040 | + warn = true; |
---|
| 1041 | + } |
---|
| 1042 | + if (warn) { |
---|
| 1043 | + warn = false; |
---|
| 1044 | + v4l2_warn(&dev->v4l2_dev, |
---|
| 1045 | + "%s cmsk offs 2 align, size %d align and offs + size < resolution\n" |
---|
| 1046 | + "\t cmsk win%d result to offs:%d %d, size:%d %d\n", |
---|
| 1047 | + stream->vnode.vdev.name, i, align, h_offs, v_offs, h_size, v_size); |
---|
| 1048 | + } |
---|
| 1049 | + dev->cmsk_cfg.win[i].h_offs = h_offs; |
---|
| 1050 | + dev->cmsk_cfg.win[i].v_offs = v_offs; |
---|
| 1051 | + dev->cmsk_cfg.win[i].h_size = h_size; |
---|
| 1052 | + dev->cmsk_cfg.win[i].v_size = v_size; |
---|
| 1053 | + } |
---|
| 1054 | + } |
---|
| 1055 | + |
---|
| 1056 | + switch (stream->id) { |
---|
| 1057 | + case RKISP_STREAM_MP: |
---|
| 1058 | + dev->cmsk_cfg.win[0].win_en = win_en; |
---|
| 1059 | + dev->cmsk_cfg.win[0].mode = mode; |
---|
| 1060 | + break; |
---|
| 1061 | + case RKISP_STREAM_SP: |
---|
| 1062 | + dev->cmsk_cfg.win[1].win_en = win_en; |
---|
| 1063 | + dev->cmsk_cfg.win[1].mode = mode; |
---|
| 1064 | + break; |
---|
| 1065 | + case RKISP_STREAM_BP: |
---|
| 1066 | + default: |
---|
| 1067 | + dev->cmsk_cfg.win[2].win_en = win_en; |
---|
| 1068 | + dev->cmsk_cfg.win[2].mode = mode; |
---|
| 1069 | + break; |
---|
| 1070 | + } |
---|
| 1071 | + dev->cmsk_cfg.mosaic_block = cfg->mosaic_block; |
---|
| 1072 | + spin_unlock_irqrestore(&dev->cmsk_lock, lock_flags); |
---|
| 1073 | + return 0; |
---|
| 1074 | + |
---|
| 1075 | +} |
---|
| 1076 | + |
---|
| 1077 | +static int rkisp_get_stream_info(struct rkisp_stream *stream, |
---|
| 1078 | + struct rkisp_stream_info *info) |
---|
| 1079 | +{ |
---|
| 1080 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1081 | + u32 id = 0; |
---|
| 1082 | + |
---|
| 1083 | + rkisp_dmarx_get_frame(stream->ispdev, &id, NULL, NULL, true); |
---|
| 1084 | + info->cur_frame_id = stream->dbg.id; |
---|
| 1085 | + info->input_frame_loss = dev->isp_sdev.dbg.frameloss; |
---|
| 1086 | + info->output_frame_loss = stream->dbg.frameloss; |
---|
| 1087 | + info->stream_on = stream->streaming; |
---|
| 1088 | + info->stream_id = stream->id; |
---|
| 1089 | + return 0; |
---|
| 1090 | +} |
---|
| 1091 | + |
---|
| 1092 | +static int rkisp_get_mirror_flip(struct rkisp_stream *stream, |
---|
| 1093 | + struct rkisp_mirror_flip *cfg) |
---|
| 1094 | +{ |
---|
| 1095 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1096 | + |
---|
| 1097 | + if (dev->isp_ver != ISP_V32) |
---|
| 1098 | + return -EINVAL; |
---|
| 1099 | + |
---|
| 1100 | + cfg->mirror = dev->cap_dev.is_mirror; |
---|
| 1101 | + cfg->flip = stream->is_flip; |
---|
| 1102 | + return 0; |
---|
| 1103 | +} |
---|
| 1104 | + |
---|
| 1105 | +static int rkisp_set_mirror_flip(struct rkisp_stream *stream, |
---|
| 1106 | + struct rkisp_mirror_flip *cfg) |
---|
| 1107 | +{ |
---|
| 1108 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1109 | + |
---|
| 1110 | + if (dev->isp_ver != ISP_V32) |
---|
| 1111 | + return -EINVAL; |
---|
| 1112 | + |
---|
| 1113 | + if (dev->cap_dev.wrap_line) { |
---|
| 1114 | + v4l2_warn(&dev->v4l2_dev, "wrap_line mode can not set the mirror"); |
---|
| 1115 | + dev->cap_dev.is_mirror = 0; |
---|
| 1116 | + } else { |
---|
| 1117 | + dev->cap_dev.is_mirror = cfg->mirror; |
---|
| 1118 | + } |
---|
| 1119 | + |
---|
| 1120 | + stream->is_flip = cfg->flip; |
---|
| 1121 | + stream->is_mf_upd = true; |
---|
| 1122 | + return 0; |
---|
| 1123 | +} |
---|
| 1124 | + |
---|
| 1125 | +static int rkisp_get_wrap_line(struct rkisp_stream *stream, struct rkisp_wrap_info *arg) |
---|
| 1126 | +{ |
---|
| 1127 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1128 | + |
---|
| 1129 | + if (dev->isp_ver != ISP_V32 && stream->id != RKISP_STREAM_MP) |
---|
| 1130 | + return -EINVAL; |
---|
| 1131 | + |
---|
| 1132 | + arg->width = dev->cap_dev.wrap_width; |
---|
| 1133 | + arg->height = dev->cap_dev.wrap_line; |
---|
| 1134 | + return 0; |
---|
| 1135 | +} |
---|
| 1136 | + |
---|
| 1137 | +static int rkisp_set_wrap_line(struct rkisp_stream *stream, struct rkisp_wrap_info *arg) |
---|
| 1138 | +{ |
---|
| 1139 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1140 | + |
---|
| 1141 | + if (dev->isp_ver != ISP_V32 || |
---|
| 1142 | + dev->hw_dev->dev_link_num > 1 || |
---|
| 1143 | + !stream->ops->set_wrap || |
---|
| 1144 | + dev->hw_dev->unite) { |
---|
| 1145 | + v4l2_err(&dev->v4l2_dev, |
---|
| 1146 | + "wrap only support for single sensor and mainpath\n"); |
---|
| 1147 | + return -EINVAL; |
---|
| 1148 | + } |
---|
| 1149 | + dev->cap_dev.wrap_width = arg->width; |
---|
| 1150 | + return stream->ops->set_wrap(stream, arg->height); |
---|
| 1151 | +} |
---|
| 1152 | + |
---|
| 1153 | +static int rkisp_set_fps(struct rkisp_stream *stream, int *fps) |
---|
| 1154 | +{ |
---|
| 1155 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1156 | + |
---|
| 1157 | + if (dev->isp_ver != ISP_V32) |
---|
| 1158 | + return -EINVAL; |
---|
| 1159 | + |
---|
| 1160 | + return rkisp_rockit_fps_set(fps, stream); |
---|
| 1161 | +} |
---|
| 1162 | + |
---|
| 1163 | +static int rkisp_get_fps(struct rkisp_stream *stream, int *fps) |
---|
| 1164 | +{ |
---|
| 1165 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1166 | + |
---|
| 1167 | + if (dev->isp_ver != ISP_V32) |
---|
| 1168 | + return -EINVAL; |
---|
| 1169 | + |
---|
| 1170 | + return rkisp_rockit_fps_get(fps, stream); |
---|
| 1171 | +} |
---|
| 1172 | + |
---|
| 1173 | +int rkisp_get_tb_stream_info(struct rkisp_stream *stream, |
---|
| 1174 | + struct rkisp_tb_stream_info *info) |
---|
| 1175 | +{ |
---|
| 1176 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1177 | + |
---|
| 1178 | + if (stream->id != RKISP_STREAM_MP) { |
---|
| 1179 | + v4l2_err(&dev->v4l2_dev, "fast only support for MP\n"); |
---|
| 1180 | + return -EINVAL; |
---|
| 1181 | + } |
---|
| 1182 | + |
---|
| 1183 | + if (!dev->tb_stream_info.buf_max) { |
---|
| 1184 | + v4l2_err(&dev->v4l2_dev, "thunderboot no enough memory for image\n"); |
---|
| 1185 | + return -EINVAL; |
---|
| 1186 | + } |
---|
| 1187 | + |
---|
| 1188 | + memcpy(info, &dev->tb_stream_info, sizeof(*info)); |
---|
| 1189 | + return 0; |
---|
| 1190 | +} |
---|
| 1191 | + |
---|
| 1192 | +int rkisp_free_tb_stream_buf(struct rkisp_stream *stream) |
---|
| 1193 | +{ |
---|
| 1194 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1195 | + struct rkisp_isp_subdev *sdev = &dev->isp_sdev; |
---|
| 1196 | + struct v4l2_subdev *sd = &sdev->sd; |
---|
| 1197 | + |
---|
| 1198 | + return sd->ops->core->ioctl(sd, RKISP_CMD_FREE_SHARED_BUF, NULL); |
---|
| 1199 | +} |
---|
| 1200 | + |
---|
| 1201 | +static int rkisp_set_iqtool_connect_id(struct rkisp_stream *stream, int stream_id) |
---|
| 1202 | +{ |
---|
| 1203 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1204 | + |
---|
| 1205 | + if (stream->id != RKISP_STREAM_VIR) { |
---|
| 1206 | + v4l2_err(&dev->v4l2_dev, "only support for iqtool video\n"); |
---|
| 1207 | + goto err; |
---|
| 1208 | + } |
---|
| 1209 | + |
---|
| 1210 | + if (stream_id != RKISP_STREAM_MP && |
---|
| 1211 | + stream_id != RKISP_STREAM_SP && |
---|
| 1212 | + stream_id != RKISP_STREAM_BP) { |
---|
| 1213 | + v4l2_err(&dev->v4l2_dev, "invalid connect stream id\n"); |
---|
| 1214 | + goto err; |
---|
| 1215 | + } |
---|
| 1216 | + |
---|
| 1217 | + stream->conn_id = stream_id; |
---|
| 1218 | + return 0; |
---|
| 1219 | +err: |
---|
| 1220 | + return -EINVAL; |
---|
1145 | 1221 | } |
---|
1146 | 1222 | |
---|
1147 | 1223 | static long rkisp_ioctl_default(struct file *file, void *fh, |
---|
.. | .. |
---|
1150 | 1226 | struct rkisp_stream *stream = video_drvdata(file); |
---|
1151 | 1227 | long ret = 0; |
---|
1152 | 1228 | |
---|
1153 | | - if (!arg) |
---|
| 1229 | + if (!arg && cmd != RKISP_CMD_FREE_TB_STREAM_BUF) |
---|
1154 | 1230 | return -EINVAL; |
---|
1155 | 1231 | |
---|
1156 | 1232 | switch (cmd) { |
---|
.. | .. |
---|
1180 | 1256 | else |
---|
1181 | 1257 | stream->memory = |
---|
1182 | 1258 | SW_CSI_RWA_WR_SIMG_SWP | SW_CSI_RAW_WR_SIMG_MODE; |
---|
| 1259 | + break; |
---|
| 1260 | + case RKISP_CMD_GET_CMSK: |
---|
| 1261 | + ret = rkisp_get_cmsk(stream, arg); |
---|
| 1262 | + break; |
---|
| 1263 | + case RKISP_CMD_SET_CMSK: |
---|
| 1264 | + ret = rkisp_set_cmsk(stream, arg); |
---|
| 1265 | + break; |
---|
| 1266 | + case RKISP_CMD_GET_STREAM_INFO: |
---|
| 1267 | + ret = rkisp_get_stream_info(stream, arg); |
---|
| 1268 | + break; |
---|
| 1269 | + case RKISP_CMD_GET_MIRROR_FLIP: |
---|
| 1270 | + ret = rkisp_get_mirror_flip(stream, arg); |
---|
| 1271 | + break; |
---|
| 1272 | + case RKISP_CMD_SET_MIRROR_FLIP: |
---|
| 1273 | + ret = rkisp_set_mirror_flip(stream, arg); |
---|
| 1274 | + break; |
---|
| 1275 | + case RKISP_CMD_GET_WRAP_LINE: |
---|
| 1276 | + ret = rkisp_get_wrap_line(stream, arg); |
---|
| 1277 | + break; |
---|
| 1278 | + case RKISP_CMD_SET_WRAP_LINE: |
---|
| 1279 | + ret = rkisp_set_wrap_line(stream, arg); |
---|
| 1280 | + break; |
---|
| 1281 | + case RKISP_CMD_SET_FPS: |
---|
| 1282 | + ret = rkisp_set_fps(stream, arg); |
---|
| 1283 | + break; |
---|
| 1284 | + case RKISP_CMD_GET_FPS: |
---|
| 1285 | + ret = rkisp_get_fps(stream, arg); |
---|
| 1286 | + break; |
---|
| 1287 | + case RKISP_CMD_GET_TB_STREAM_INFO: |
---|
| 1288 | + ret = rkisp_get_tb_stream_info(stream, arg); |
---|
| 1289 | + break; |
---|
| 1290 | + case RKISP_CMD_FREE_TB_STREAM_BUF: |
---|
| 1291 | + ret = rkisp_free_tb_stream_buf(stream); |
---|
| 1292 | + break; |
---|
| 1293 | + case RKISP_CMD_SET_IQTOOL_CONN_ID: |
---|
| 1294 | + ret = rkisp_set_iqtool_connect_id(stream, *(int *)arg); |
---|
1183 | 1295 | break; |
---|
1184 | 1296 | default: |
---|
1185 | 1297 | ret = -EINVAL; |
---|
.. | .. |
---|
1231 | 1343 | { |
---|
1232 | 1344 | struct rkisp_stream *stream = video_drvdata(file); |
---|
1233 | 1345 | const struct capture_fmt *fmt = NULL; |
---|
| 1346 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1347 | + struct ispsd_in_fmt *isp_in_fmt = &dev->isp_sdev.in_fmt; |
---|
| 1348 | + struct ispsd_out_fmt *isp_out_fmt = &dev->isp_sdev.out_fmt; |
---|
| 1349 | + int ret = -EINVAL; |
---|
| 1350 | + |
---|
| 1351 | + /* only one output format for raw */ |
---|
| 1352 | + if (isp_out_fmt->fmt_type == FMT_BAYER || |
---|
| 1353 | + stream->id == RKISP_STREAM_DMATX0 || |
---|
| 1354 | + stream->id == RKISP_STREAM_DMATX1 || |
---|
| 1355 | + stream->id == RKISP_STREAM_DMATX2 || |
---|
| 1356 | + stream->id == RKISP_STREAM_DMATX3) { |
---|
| 1357 | + u32 pixelformat = rkisp_mbus_pixelcode_to_v4l2(isp_in_fmt->mbus_code); |
---|
| 1358 | + |
---|
| 1359 | + if (f->index == 0) { |
---|
| 1360 | + fmt = find_fmt(stream, pixelformat); |
---|
| 1361 | + if (fmt) { |
---|
| 1362 | + f->pixelformat = pixelformat; |
---|
| 1363 | + ret = 0; |
---|
| 1364 | + } |
---|
| 1365 | + } |
---|
| 1366 | + return ret; |
---|
| 1367 | + } |
---|
1234 | 1368 | |
---|
1235 | 1369 | if (f->index >= stream->config->fmt_size) |
---|
1236 | 1370 | return -EINVAL; |
---|
1237 | 1371 | |
---|
1238 | 1372 | fmt = &stream->config->fmts[f->index]; |
---|
| 1373 | + /* only output yuv format */ |
---|
| 1374 | + if (isp_out_fmt->fmt_type == FMT_YUV && fmt->fmt_type == FMT_BAYER) |
---|
| 1375 | + return -EINVAL; |
---|
| 1376 | + |
---|
1239 | 1377 | f->pixelformat = fmt->fourcc; |
---|
| 1378 | + switch (f->pixelformat) { |
---|
| 1379 | + case V4L2_PIX_FMT_FBC2: |
---|
| 1380 | + strscpy(f->description, |
---|
| 1381 | + "Rockchip yuv422sp fbc encoder", |
---|
| 1382 | + sizeof(f->description)); |
---|
| 1383 | + break; |
---|
| 1384 | + case V4L2_PIX_FMT_FBC0: |
---|
| 1385 | + strscpy(f->description, |
---|
| 1386 | + "Rockchip yuv420sp fbc encoder", |
---|
| 1387 | + sizeof(f->description)); |
---|
| 1388 | + break; |
---|
| 1389 | + case V4L2_PIX_FMT_FBCG: |
---|
| 1390 | + strscpy(f->description, |
---|
| 1391 | + "Rockchip fbc gain", |
---|
| 1392 | + sizeof(f->description)); |
---|
| 1393 | + break; |
---|
| 1394 | + case V4l2_PIX_FMT_EBD8: |
---|
| 1395 | + strscpy(f->description, |
---|
| 1396 | + "Embedded data 8-bit", |
---|
| 1397 | + sizeof(f->description)); |
---|
| 1398 | + break; |
---|
| 1399 | + case V4l2_PIX_FMT_SPD16: |
---|
| 1400 | + strscpy(f->description, |
---|
| 1401 | + "Shield pix data 16-bit", |
---|
| 1402 | + sizeof(f->description)); |
---|
| 1403 | + break; |
---|
| 1404 | + default: |
---|
| 1405 | + break; |
---|
| 1406 | + } |
---|
1240 | 1407 | |
---|
1241 | 1408 | return 0; |
---|
1242 | 1409 | } |
---|
.. | .. |
---|
1298 | 1465 | struct v4l2_rect *sel, |
---|
1299 | 1466 | const struct v4l2_rect *in) |
---|
1300 | 1467 | { |
---|
| 1468 | + struct rkisp_device *dev = stream->ispdev; |
---|
| 1469 | + bool is_unite = !!dev->hw_dev->unite; |
---|
| 1470 | + u32 align = is_unite ? 4 : 2; |
---|
| 1471 | + |
---|
1301 | 1472 | /* Not crop for MP bayer raw data and dmatx path */ |
---|
1302 | 1473 | if ((stream->id == RKISP_STREAM_MP && |
---|
1303 | 1474 | stream->out_isp_fmt.fmt_type == FMT_BAYER) || |
---|
1304 | 1475 | stream->id == RKISP_STREAM_DMATX0 || |
---|
1305 | 1476 | stream->id == RKISP_STREAM_DMATX1 || |
---|
1306 | 1477 | stream->id == RKISP_STREAM_DMATX2 || |
---|
1307 | | - stream->id == RKISP_STREAM_DMATX3) { |
---|
| 1478 | + stream->id == RKISP_STREAM_DMATX3 || |
---|
| 1479 | + stream->id == RKISP_STREAM_MPDS || |
---|
| 1480 | + stream->id == RKISP_STREAM_BPDS) { |
---|
1308 | 1481 | sel->left = 0; |
---|
1309 | 1482 | sel->top = 0; |
---|
1310 | 1483 | sel->width = in->width; |
---|
.. | .. |
---|
1313 | 1486 | } |
---|
1314 | 1487 | |
---|
1315 | 1488 | sel->left = ALIGN(sel->left, 2); |
---|
1316 | | - sel->width = ALIGN(sel->width, 2); |
---|
| 1489 | + sel->width = ALIGN(sel->width, align); |
---|
1317 | 1490 | sel->left = clamp_t(u32, sel->left, 0, |
---|
1318 | 1491 | in->width - STREAM_MIN_MP_SP_INPUT_WIDTH); |
---|
1319 | 1492 | sel->top = clamp_t(u32, sel->top, 0, |
---|
.. | .. |
---|
1322 | 1495 | in->width - sel->left); |
---|
1323 | 1496 | sel->height = clamp_t(u32, sel->height, STREAM_MIN_MP_SP_INPUT_HEIGHT, |
---|
1324 | 1497 | in->height - sel->top); |
---|
| 1498 | + if (is_unite && (sel->width + 2 * sel->left) != in->width) { |
---|
| 1499 | + sel->left = ALIGN_DOWN((in->width - sel->width) / 2, 2); |
---|
| 1500 | + v4l2_warn(&dev->v4l2_dev, |
---|
| 1501 | + "try horizontal center crop(%d,%d)/%dx%d for dual isp\n", |
---|
| 1502 | + sel->left, sel->top, sel->width, sel->height); |
---|
| 1503 | + } |
---|
| 1504 | + stream->is_crop_upd = true; |
---|
1325 | 1505 | return sel; |
---|
1326 | 1506 | } |
---|
1327 | 1507 | |
---|
.. | .. |
---|
1329 | 1509 | struct v4l2_selection *sel) |
---|
1330 | 1510 | { |
---|
1331 | 1511 | struct rkisp_stream *stream = video_drvdata(file); |
---|
1332 | | - struct video_device *vdev = &stream->vnode.vdev; |
---|
1333 | | - struct rkisp_vdev_node *node = vdev_to_node(vdev); |
---|
1334 | 1512 | struct rkisp_device *dev = stream->ispdev; |
---|
1335 | 1513 | struct v4l2_rect *dcrop = &stream->dcrop; |
---|
1336 | 1514 | const struct v4l2_rect *input_win; |
---|
1337 | | - |
---|
1338 | | - if (vb2_is_busy(&node->buf_queue)) { |
---|
1339 | | - v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__); |
---|
1340 | | - return -EBUSY; |
---|
1341 | | - } |
---|
1342 | | - |
---|
1343 | | - input_win = rkisp_get_isp_sd_win(&dev->isp_sdev); |
---|
1344 | 1515 | |
---|
1345 | 1516 | if (sel->target != V4L2_SEL_TGT_CROP) |
---|
1346 | 1517 | return -EINVAL; |
---|
.. | .. |
---|
1348 | 1519 | if (sel->flags != 0) |
---|
1349 | 1520 | return -EINVAL; |
---|
1350 | 1521 | |
---|
| 1522 | + input_win = rkisp_get_isp_sd_win(&dev->isp_sdev); |
---|
1351 | 1523 | *dcrop = *rkisp_update_crop(stream, &sel->r, input_win); |
---|
1352 | 1524 | v4l2_dbg(1, rkisp_debug, &dev->v4l2_dev, |
---|
1353 | 1525 | "stream %d crop(%d,%d)/%dx%d\n", stream->id, |
---|
.. | .. |
---|
1385 | 1557 | .vidioc_streamoff = vb2_ioctl_streamoff, |
---|
1386 | 1558 | .vidioc_enum_input = rkisp_enum_input, |
---|
1387 | 1559 | .vidioc_try_fmt_vid_cap_mplane = rkisp_try_fmt_vid_cap_mplane, |
---|
1388 | | - .vidioc_enum_fmt_vid_cap_mplane = rkisp_enum_fmt_vid_cap_mplane, |
---|
| 1560 | + .vidioc_enum_fmt_vid_cap = rkisp_enum_fmt_vid_cap_mplane, |
---|
1389 | 1561 | .vidioc_s_fmt_vid_cap_mplane = rkisp_s_fmt_vid_cap_mplane, |
---|
1390 | 1562 | .vidioc_g_fmt_vid_cap_mplane = rkisp_g_fmt_vid_cap_mplane, |
---|
1391 | 1563 | .vidioc_s_selection = rkisp_s_selection, |
---|
.. | .. |
---|
1396 | 1568 | .vidioc_default = rkisp_ioctl_default, |
---|
1397 | 1569 | }; |
---|
1398 | 1570 | |
---|
| 1571 | +static void rkisp_buf_done_task(unsigned long arg) |
---|
| 1572 | +{ |
---|
| 1573 | + struct rkisp_stream *stream = (struct rkisp_stream *)arg; |
---|
| 1574 | + struct rkisp_buffer *buf = NULL; |
---|
| 1575 | + unsigned long lock_flags = 0; |
---|
| 1576 | + LIST_HEAD(local_list); |
---|
| 1577 | + |
---|
| 1578 | + spin_lock_irqsave(&stream->vbq_lock, lock_flags); |
---|
| 1579 | + list_replace_init(&stream->buf_done_list, &local_list); |
---|
| 1580 | + spin_unlock_irqrestore(&stream->vbq_lock, lock_flags); |
---|
| 1581 | + |
---|
| 1582 | + while (!list_empty(&local_list)) { |
---|
| 1583 | + buf = list_first_entry(&local_list, |
---|
| 1584 | + struct rkisp_buffer, queue); |
---|
| 1585 | + list_del(&buf->queue); |
---|
| 1586 | + |
---|
| 1587 | + v4l2_dbg(2, rkisp_debug, &stream->ispdev->v4l2_dev, |
---|
| 1588 | + "stream:%d seq:%d buf:0x%x done\n", |
---|
| 1589 | + stream->id, buf->vb.sequence, buf->buff_addr[0]); |
---|
| 1590 | + vb2_buffer_done(&buf->vb.vb2_buf, |
---|
| 1591 | + stream->streaming ? VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR); |
---|
| 1592 | + } |
---|
| 1593 | +} |
---|
| 1594 | + |
---|
| 1595 | +void rkisp_stream_buf_done(struct rkisp_stream *stream, |
---|
| 1596 | + struct rkisp_buffer *buf) |
---|
| 1597 | +{ |
---|
| 1598 | + unsigned long lock_flags = 0; |
---|
| 1599 | + |
---|
| 1600 | + if (!stream || !buf) |
---|
| 1601 | + return; |
---|
| 1602 | + spin_lock_irqsave(&stream->vbq_lock, lock_flags); |
---|
| 1603 | + list_add_tail(&buf->queue, &stream->buf_done_list); |
---|
| 1604 | + spin_unlock_irqrestore(&stream->vbq_lock, lock_flags); |
---|
| 1605 | + tasklet_schedule(&stream->buf_done_tasklet); |
---|
| 1606 | +} |
---|
| 1607 | + |
---|
| 1608 | +static void rkisp_stream_fast(struct work_struct *work) |
---|
| 1609 | +{ |
---|
| 1610 | + struct rkisp_capture_device *cap_dev = |
---|
| 1611 | + container_of(work, struct rkisp_capture_device, fast_work); |
---|
| 1612 | + struct rkisp_stream *stream = &cap_dev->stream[0]; |
---|
| 1613 | + struct rkisp_device *ispdev = cap_dev->ispdev; |
---|
| 1614 | + struct v4l2_subdev *sd = ispdev->active_sensor->sd; |
---|
| 1615 | + int ret; |
---|
| 1616 | + |
---|
| 1617 | + if (ispdev->isp_ver != ISP_V32) |
---|
| 1618 | + return; |
---|
| 1619 | + |
---|
| 1620 | + mutex_lock(&ispdev->hw_dev->dev_lock); |
---|
| 1621 | + rkisp_chk_tb_over(ispdev); |
---|
| 1622 | + mutex_unlock(&ispdev->hw_dev->dev_lock); |
---|
| 1623 | + if (ispdev->tb_head.complete != RKISP_TB_OK) |
---|
| 1624 | + return; |
---|
| 1625 | + ret = v4l2_pipeline_pm_get(&stream->vnode.vdev.entity); |
---|
| 1626 | + if (ret < 0) { |
---|
| 1627 | + dev_err(ispdev->dev, "%s PM get fail:%d\n", __func__, ret); |
---|
| 1628 | + ispdev->is_thunderboot = false; |
---|
| 1629 | + return; |
---|
| 1630 | + } |
---|
| 1631 | + |
---|
| 1632 | + if (ispdev->hw_dev->dev_num > 1) |
---|
| 1633 | + ispdev->hw_dev->is_single = false; |
---|
| 1634 | + ispdev->is_pre_on = true; |
---|
| 1635 | + ispdev->is_rdbk_auto = true; |
---|
| 1636 | + ispdev->pipe.open(&ispdev->pipe, &stream->vnode.vdev.entity, true); |
---|
| 1637 | + v4l2_subdev_call(sd, video, s_stream, true); |
---|
| 1638 | +} |
---|
| 1639 | + |
---|
1399 | 1640 | void rkisp_unregister_stream_vdev(struct rkisp_stream *stream) |
---|
1400 | 1641 | { |
---|
| 1642 | + tasklet_kill(&stream->buf_done_tasklet); |
---|
1401 | 1643 | media_entity_cleanup(&stream->vnode.vdev.entity); |
---|
1402 | 1644 | video_unregister_device(&stream->vnode.vdev); |
---|
1403 | 1645 | } |
---|
.. | .. |
---|
1427 | 1669 | node->pad.flags = MEDIA_PAD_FL_SINK; |
---|
1428 | 1670 | vdev->queue = &node->buf_queue; |
---|
1429 | 1671 | |
---|
1430 | | - ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1); |
---|
| 1672 | + ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); |
---|
1431 | 1673 | if (ret < 0) { |
---|
1432 | 1674 | v4l2_err(v4l2_dev, |
---|
1433 | 1675 | "video_register_device failed with error %d\n", ret); |
---|
.. | .. |
---|
1457 | 1699 | sink, 0, stream->linked); |
---|
1458 | 1700 | if (ret < 0) |
---|
1459 | 1701 | goto unreg; |
---|
| 1702 | + INIT_LIST_HEAD(&stream->buf_done_list); |
---|
| 1703 | + tasklet_init(&stream->buf_done_tasklet, |
---|
| 1704 | + rkisp_buf_done_task, |
---|
| 1705 | + (unsigned long)stream); |
---|
| 1706 | + tasklet_disable(&stream->buf_done_tasklet); |
---|
1460 | 1707 | return 0; |
---|
1461 | 1708 | unreg: |
---|
1462 | 1709 | video_unregister_device(vdev); |
---|
.. | .. |
---|
1466 | 1713 | int rkisp_register_stream_vdevs(struct rkisp_device *dev) |
---|
1467 | 1714 | { |
---|
1468 | 1715 | struct rkisp_capture_device *cap_dev = &dev->cap_dev; |
---|
| 1716 | + struct stream_config *st_cfg = &rkisp_mp_stream_config; |
---|
1469 | 1717 | int ret = 0; |
---|
1470 | 1718 | |
---|
1471 | 1719 | memset(cap_dev, 0, sizeof(*cap_dev)); |
---|
1472 | 1720 | cap_dev->ispdev = dev; |
---|
1473 | 1721 | atomic_set(&cap_dev->refcnt, 0); |
---|
1474 | 1722 | |
---|
1475 | | - if (dev->isp_ver <= ISP_V13) |
---|
| 1723 | + if (dev->isp_ver <= ISP_V13) { |
---|
| 1724 | + if (dev->isp_ver == ISP_V12) { |
---|
| 1725 | + st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V12; |
---|
| 1726 | + st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V12; |
---|
| 1727 | + } else if (dev->isp_ver == ISP_V13) { |
---|
| 1728 | + st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V13; |
---|
| 1729 | + st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V13; |
---|
| 1730 | + } |
---|
1476 | 1731 | ret = rkisp_register_stream_v1x(dev); |
---|
1477 | | - else if (dev->isp_ver == ISP_V20) |
---|
| 1732 | + } else if (dev->isp_ver == ISP_V20) { |
---|
1478 | 1733 | ret = rkisp_register_stream_v20(dev); |
---|
1479 | | - else if (dev->isp_ver == ISP_V21) |
---|
| 1734 | + } else if (dev->isp_ver == ISP_V21) { |
---|
| 1735 | + st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V21; |
---|
| 1736 | + st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V21; |
---|
1480 | 1737 | ret = rkisp_register_stream_v21(dev); |
---|
| 1738 | + } else if (dev->isp_ver == ISP_V30) { |
---|
| 1739 | + st_cfg->max_rsz_width = dev->hw_dev->unite ? |
---|
| 1740 | + CIF_ISP_INPUT_W_MAX_V30_UNITE : CIF_ISP_INPUT_W_MAX_V30; |
---|
| 1741 | + st_cfg->max_rsz_height = dev->hw_dev->unite ? |
---|
| 1742 | + CIF_ISP_INPUT_H_MAX_V30_UNITE : CIF_ISP_INPUT_H_MAX_V30; |
---|
| 1743 | + ret = rkisp_register_stream_v30(dev); |
---|
| 1744 | + } else if (dev->isp_ver == ISP_V32) { |
---|
| 1745 | + st_cfg->max_rsz_width = dev->hw_dev->unite ? |
---|
| 1746 | + CIF_ISP_INPUT_W_MAX_V32_UNITE : CIF_ISP_INPUT_W_MAX_V32; |
---|
| 1747 | + st_cfg->max_rsz_height = dev->hw_dev->unite ? |
---|
| 1748 | + CIF_ISP_INPUT_H_MAX_V32_UNITE : CIF_ISP_INPUT_H_MAX_V32; |
---|
| 1749 | + st_cfg = &rkisp_sp_stream_config; |
---|
| 1750 | + st_cfg->max_rsz_width = dev->hw_dev->unite ? |
---|
| 1751 | + CIF_ISP_INPUT_W_MAX_V32_UNITE : CIF_ISP_INPUT_W_MAX_V32; |
---|
| 1752 | + st_cfg->max_rsz_height = dev->hw_dev->unite ? |
---|
| 1753 | + CIF_ISP_INPUT_H_MAX_V32_UNITE : CIF_ISP_INPUT_H_MAX_V32; |
---|
| 1754 | + ret = rkisp_register_stream_v32(dev); |
---|
| 1755 | + } else if (dev->isp_ver == ISP_V32_L) { |
---|
| 1756 | + st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V32_L; |
---|
| 1757 | + st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V32_L; |
---|
| 1758 | + st_cfg = &rkisp_sp_stream_config; |
---|
| 1759 | + st_cfg->max_rsz_width = CIF_ISP_INPUT_W_MAX_V32_L; |
---|
| 1760 | + st_cfg->max_rsz_height = CIF_ISP_INPUT_H_MAX_V32_L; |
---|
| 1761 | + ret = rkisp_register_stream_v32(dev); |
---|
| 1762 | + } |
---|
| 1763 | + |
---|
| 1764 | + INIT_WORK(&cap_dev->fast_work, rkisp_stream_fast); |
---|
1481 | 1765 | return ret; |
---|
1482 | 1766 | } |
---|
1483 | 1767 | |
---|
.. | .. |
---|
1489 | 1773 | rkisp_unregister_stream_v20(dev); |
---|
1490 | 1774 | else if (dev->isp_ver == ISP_V21) |
---|
1491 | 1775 | rkisp_unregister_stream_v21(dev); |
---|
| 1776 | + else if (dev->isp_ver == ISP_V30) |
---|
| 1777 | + rkisp_unregister_stream_v30(dev); |
---|
| 1778 | + else if (dev->isp_ver == ISP_V32 || dev->isp_ver == ISP_V32_L) |
---|
| 1779 | + rkisp_unregister_stream_v32(dev); |
---|
1492 | 1780 | } |
---|
1493 | 1781 | |
---|
1494 | 1782 | void rkisp_mi_isr(u32 mis_val, struct rkisp_device *dev) |
---|
.. | .. |
---|
1499 | 1787 | rkisp_mi_v20_isr(mis_val, dev); |
---|
1500 | 1788 | else if (dev->isp_ver == ISP_V21) |
---|
1501 | 1789 | rkisp_mi_v21_isr(mis_val, dev); |
---|
| 1790 | + else if (dev->isp_ver == ISP_V30) |
---|
| 1791 | + rkisp_mi_v30_isr(mis_val, dev); |
---|
| 1792 | + else if (dev->isp_ver == ISP_V32 || dev->isp_ver == ISP_V32_L) |
---|
| 1793 | + rkisp_mi_v32_isr(mis_val, dev); |
---|
1502 | 1794 | } |
---|