.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Coda multi-standard codec IP |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2012 Vista Silicon S.L. |
---|
5 | 6 | * Javier Martin, <javier.martin@vista-silicon.com> |
---|
6 | 7 | * Xavier Duret |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
11 | | - * (at your option) any later version. |
---|
12 | 8 | */ |
---|
13 | 9 | |
---|
14 | 10 | #include <linux/clk.h> |
---|
.. | .. |
---|
51 | 47 | |
---|
52 | 48 | #define CODA_ISRAM_SIZE (2048 * 2) |
---|
53 | 49 | |
---|
54 | | -#define MIN_W 176 |
---|
55 | | -#define MIN_H 144 |
---|
| 50 | +#define MIN_W 48 |
---|
| 51 | +#define MIN_H 16 |
---|
56 | 52 | |
---|
57 | 53 | #define S_ALIGN 1 /* multiple of 2 */ |
---|
58 | 54 | #define W_ALIGN 1 /* multiple of 2 */ |
---|
.. | .. |
---|
78 | 74 | |
---|
79 | 75 | void coda_write(struct coda_dev *dev, u32 data, u32 reg) |
---|
80 | 76 | { |
---|
81 | | - v4l2_dbg(2, coda_debug, &dev->v4l2_dev, |
---|
| 77 | + v4l2_dbg(3, coda_debug, &dev->v4l2_dev, |
---|
82 | 78 | "%s: data=0x%x, reg=0x%x\n", __func__, data, reg); |
---|
83 | 79 | writel(data, dev->regs_base + reg); |
---|
84 | 80 | } |
---|
.. | .. |
---|
88 | 84 | u32 data; |
---|
89 | 85 | |
---|
90 | 86 | data = readl(dev->regs_base + reg); |
---|
91 | | - v4l2_dbg(2, coda_debug, &dev->v4l2_dev, |
---|
| 87 | + v4l2_dbg(3, coda_debug, &dev->v4l2_dev, |
---|
92 | 88 | "%s: data=0x%x, reg=0x%x\n", __func__, data, reg); |
---|
93 | 89 | return data; |
---|
94 | 90 | } |
---|
.. | .. |
---|
159 | 155 | static const struct coda_codec coda9_codecs[] = { |
---|
160 | 156 | CODA_CODEC(CODA9_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1920, 1088), |
---|
161 | 157 | CODA_CODEC(CODA9_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1920, 1088), |
---|
| 158 | + CODA_CODEC(CODA9_MODE_ENCODE_MJPG, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_JPEG, 8192, 8192), |
---|
162 | 159 | CODA_CODEC(CODA9_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1088), |
---|
163 | 160 | CODA_CODEC(CODA9_MODE_DECODE_MP2, V4L2_PIX_FMT_MPEG2, V4L2_PIX_FMT_YUV420, 1920, 1088), |
---|
164 | 161 | CODA_CODEC(CODA9_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1088), |
---|
| 162 | + CODA_CODEC(CODA9_MODE_DECODE_MJPG, V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_YUV420, 8192, 8192), |
---|
165 | 163 | }; |
---|
166 | 164 | |
---|
167 | 165 | struct coda_video_device { |
---|
.. | .. |
---|
239 | 237 | }, |
---|
240 | 238 | }; |
---|
241 | 239 | |
---|
| 240 | +static const struct coda_video_device coda9_jpeg_encoder = { |
---|
| 241 | + .name = "coda-jpeg-encoder", |
---|
| 242 | + .type = CODA_INST_ENCODER, |
---|
| 243 | + .ops = &coda9_jpeg_encode_ops, |
---|
| 244 | + .direct = true, |
---|
| 245 | + .src_formats = { |
---|
| 246 | + V4L2_PIX_FMT_NV12, |
---|
| 247 | + V4L2_PIX_FMT_YUV420, |
---|
| 248 | + V4L2_PIX_FMT_YVU420, |
---|
| 249 | + V4L2_PIX_FMT_YUV422P, |
---|
| 250 | + }, |
---|
| 251 | + .dst_formats = { |
---|
| 252 | + V4L2_PIX_FMT_JPEG, |
---|
| 253 | + }, |
---|
| 254 | +}; |
---|
| 255 | + |
---|
| 256 | +static const struct coda_video_device coda9_jpeg_decoder = { |
---|
| 257 | + .name = "coda-jpeg-decoder", |
---|
| 258 | + .type = CODA_INST_DECODER, |
---|
| 259 | + .ops = &coda9_jpeg_decode_ops, |
---|
| 260 | + .direct = true, |
---|
| 261 | + .src_formats = { |
---|
| 262 | + V4L2_PIX_FMT_JPEG, |
---|
| 263 | + }, |
---|
| 264 | + .dst_formats = { |
---|
| 265 | + V4L2_PIX_FMT_NV12, |
---|
| 266 | + V4L2_PIX_FMT_YUV420, |
---|
| 267 | + V4L2_PIX_FMT_YVU420, |
---|
| 268 | + V4L2_PIX_FMT_YUV422P, |
---|
| 269 | + }, |
---|
| 270 | +}; |
---|
| 271 | + |
---|
242 | 272 | static const struct coda_video_device *codadx6_video_devices[] = { |
---|
243 | 273 | &coda_bit_encoder, |
---|
244 | 274 | }; |
---|
.. | .. |
---|
256 | 286 | }; |
---|
257 | 287 | |
---|
258 | 288 | static const struct coda_video_device *coda9_video_devices[] = { |
---|
| 289 | + &coda9_jpeg_encoder, |
---|
| 290 | + &coda9_jpeg_decoder, |
---|
259 | 291 | &coda_bit_encoder, |
---|
260 | 292 | &coda_bit_decoder, |
---|
261 | 293 | }; |
---|
.. | .. |
---|
376 | 408 | if (!vdoa_data) |
---|
377 | 409 | vdoa_data = ERR_PTR(-EPROBE_DEFER); |
---|
378 | 410 | |
---|
| 411 | + put_device(&vdoa_pdev->dev); |
---|
379 | 412 | out: |
---|
380 | | - if (vdoa_node) |
---|
381 | | - of_node_put(vdoa_node); |
---|
| 413 | + of_node_put(vdoa_node); |
---|
382 | 414 | |
---|
383 | 415 | return vdoa_data; |
---|
384 | 416 | } |
---|
.. | .. |
---|
391 | 423 | { |
---|
392 | 424 | struct coda_ctx *ctx = fh_to_ctx(priv); |
---|
393 | 425 | |
---|
394 | | - strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver)); |
---|
395 | | - strlcpy(cap->card, coda_product_name(ctx->dev->devtype->product), |
---|
| 426 | + strscpy(cap->driver, CODA_NAME, sizeof(cap->driver)); |
---|
| 427 | + strscpy(cap->card, coda_product_name(ctx->dev->devtype->product), |
---|
396 | 428 | sizeof(cap->card)); |
---|
397 | | - strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info)); |
---|
398 | | - cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING; |
---|
399 | | - cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
---|
400 | | - |
---|
| 429 | + strscpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info)); |
---|
401 | 430 | return 0; |
---|
402 | 431 | } |
---|
| 432 | + |
---|
| 433 | +static const u32 coda_formats_420[CODA_MAX_FORMATS] = { |
---|
| 434 | + V4L2_PIX_FMT_NV12, |
---|
| 435 | + V4L2_PIX_FMT_YUV420, |
---|
| 436 | + V4L2_PIX_FMT_YVU420, |
---|
| 437 | +}; |
---|
403 | 438 | |
---|
404 | 439 | static int coda_enum_fmt(struct file *file, void *priv, |
---|
405 | 440 | struct v4l2_fmtdesc *f) |
---|
.. | .. |
---|
411 | 446 | |
---|
412 | 447 | if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) |
---|
413 | 448 | formats = cvd->src_formats; |
---|
414 | | - else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
---|
| 449 | + else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
---|
| 450 | + struct coda_q_data *q_data_src; |
---|
| 451 | + struct vb2_queue *src_vq; |
---|
| 452 | + |
---|
415 | 453 | formats = cvd->dst_formats; |
---|
416 | | - else |
---|
| 454 | + |
---|
| 455 | + /* |
---|
| 456 | + * If the source format is already fixed, only allow the same |
---|
| 457 | + * chroma subsampling. |
---|
| 458 | + */ |
---|
| 459 | + q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
---|
| 460 | + src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, |
---|
| 461 | + V4L2_BUF_TYPE_VIDEO_OUTPUT); |
---|
| 462 | + if (q_data_src->fourcc == V4L2_PIX_FMT_JPEG && |
---|
| 463 | + vb2_is_streaming(src_vq)) { |
---|
| 464 | + if (ctx->params.jpeg_chroma_subsampling == |
---|
| 465 | + V4L2_JPEG_CHROMA_SUBSAMPLING_420) { |
---|
| 466 | + formats = coda_formats_420; |
---|
| 467 | + } else if (ctx->params.jpeg_chroma_subsampling == |
---|
| 468 | + V4L2_JPEG_CHROMA_SUBSAMPLING_422) { |
---|
| 469 | + f->pixelformat = V4L2_PIX_FMT_YUV422P; |
---|
| 470 | + return f->index ? -EINVAL : 0; |
---|
| 471 | + } |
---|
| 472 | + } |
---|
| 473 | + } else { |
---|
417 | 474 | return -EINVAL; |
---|
| 475 | + } |
---|
418 | 476 | |
---|
419 | 477 | if (f->index >= CODA_MAX_FORMATS || formats[f->index] == 0) |
---|
420 | 478 | return -EINVAL; |
---|
.. | .. |
---|
604 | 662 | |
---|
605 | 663 | /* |
---|
606 | 664 | * If the source format is already fixed, only allow the same output |
---|
607 | | - * resolution |
---|
| 665 | + * resolution. When decoding JPEG images, we also have to make sure to |
---|
| 666 | + * use the same chroma subsampling. |
---|
608 | 667 | */ |
---|
609 | 668 | src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
---|
610 | 669 | if (vb2_is_streaming(src_vq)) { |
---|
611 | 670 | f->fmt.pix.width = q_data_src->width; |
---|
612 | 671 | f->fmt.pix.height = q_data_src->height; |
---|
| 672 | + |
---|
| 673 | + if (q_data_src->fourcc == V4L2_PIX_FMT_JPEG) { |
---|
| 674 | + if (ctx->params.jpeg_chroma_subsampling == |
---|
| 675 | + V4L2_JPEG_CHROMA_SUBSAMPLING_420 && |
---|
| 676 | + f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUV422P) |
---|
| 677 | + f->fmt.pix.pixelformat = V4L2_PIX_FMT_NV12; |
---|
| 678 | + else if (ctx->params.jpeg_chroma_subsampling == |
---|
| 679 | + V4L2_JPEG_CHROMA_SUBSAMPLING_422) |
---|
| 680 | + f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P; |
---|
| 681 | + } |
---|
613 | 682 | } |
---|
614 | 683 | |
---|
615 | 684 | f->fmt.pix.colorspace = ctx->colorspace; |
---|
.. | .. |
---|
627 | 696 | if (ret < 0) |
---|
628 | 697 | return ret; |
---|
629 | 698 | |
---|
630 | | - /* The h.264 decoder only returns complete 16x16 macroblocks */ |
---|
631 | | - if (codec && codec->src_fourcc == V4L2_PIX_FMT_H264) { |
---|
632 | | - f->fmt.pix.height = round_up(f->fmt.pix.height, 16); |
---|
| 699 | + /* The decoders always write complete macroblocks or MCUs */ |
---|
| 700 | + if (ctx->inst_type == CODA_INST_DECODER) { |
---|
633 | 701 | f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16); |
---|
634 | | - f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * |
---|
635 | | - f->fmt.pix.height * 3 / 2; |
---|
| 702 | + f->fmt.pix.height = round_up(f->fmt.pix.height, 16); |
---|
| 703 | + if (codec->src_fourcc == V4L2_PIX_FMT_JPEG && |
---|
| 704 | + f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUV422P) { |
---|
| 705 | + f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * |
---|
| 706 | + f->fmt.pix.height * 2; |
---|
| 707 | + } else { |
---|
| 708 | + f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * |
---|
| 709 | + f->fmt.pix.height * 3 / 2; |
---|
| 710 | + } |
---|
636 | 711 | |
---|
637 | 712 | ret = coda_try_fmt_vdoa(ctx, f, &use_vdoa); |
---|
638 | 713 | if (ret < 0) |
---|
.. | .. |
---|
705 | 780 | return -EINVAL; |
---|
706 | 781 | |
---|
707 | 782 | if (vb2_is_busy(vq)) { |
---|
708 | | - v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__); |
---|
| 783 | + v4l2_err(&ctx->dev->v4l2_dev, "%s: %s queue busy: %d\n", |
---|
| 784 | + __func__, v4l2_type_names[f->type], vq->num_buffers); |
---|
709 | 785 | return -EBUSY; |
---|
710 | 786 | } |
---|
711 | 787 | |
---|
.. | .. |
---|
728 | 804 | ctx->tiled_map_type = GDI_TILED_FRAME_MB_RASTER_MAP; |
---|
729 | 805 | break; |
---|
730 | 806 | case V4L2_PIX_FMT_NV12: |
---|
731 | | - if (!disable_tiling) { |
---|
| 807 | + if (!disable_tiling && ctx->use_bit && |
---|
| 808 | + ctx->dev->devtype->product == CODA_960) { |
---|
732 | 809 | ctx->tiled_map_type = GDI_TILED_FRAME_MB_RASTER_MAP; |
---|
733 | 810 | break; |
---|
734 | 811 | } |
---|
735 | | - /* else fall through */ |
---|
| 812 | + fallthrough; |
---|
736 | 813 | case V4L2_PIX_FMT_YUV420: |
---|
737 | 814 | case V4L2_PIX_FMT_YVU420: |
---|
| 815 | + case V4L2_PIX_FMT_YUV422P: |
---|
738 | 816 | ctx->tiled_map_type = GDI_LINEAR_FRAME_MAP; |
---|
739 | 817 | break; |
---|
740 | 818 | default: |
---|
.. | .. |
---|
751 | 829 | else |
---|
752 | 830 | ctx->use_vdoa = false; |
---|
753 | 831 | |
---|
754 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
755 | | - "Setting format for type %d, wxh: %dx%d, fmt: %4.4s %c\n", |
---|
756 | | - f->type, q_data->width, q_data->height, |
---|
757 | | - (char *)&q_data->fourcc, |
---|
758 | | - (ctx->tiled_map_type == GDI_LINEAR_FRAME_MAP) ? 'L' : 'T'); |
---|
| 832 | + coda_dbg(1, ctx, "Setting %s format, wxh: %dx%d, fmt: %4.4s %c\n", |
---|
| 833 | + v4l2_type_names[f->type], q_data->width, q_data->height, |
---|
| 834 | + (char *)&q_data->fourcc, |
---|
| 835 | + (ctx->tiled_map_type == GDI_LINEAR_FRAME_MAP) ? 'L' : 'T'); |
---|
759 | 836 | |
---|
760 | 837 | return 0; |
---|
761 | 838 | } |
---|
.. | .. |
---|
765 | 842 | { |
---|
766 | 843 | struct coda_ctx *ctx = fh_to_ctx(priv); |
---|
767 | 844 | struct coda_q_data *q_data_src; |
---|
| 845 | + const struct coda_codec *codec; |
---|
768 | 846 | struct v4l2_rect r; |
---|
769 | 847 | int ret; |
---|
770 | 848 | |
---|
.. | .. |
---|
785 | 863 | if (ctx->inst_type != CODA_INST_ENCODER) |
---|
786 | 864 | return 0; |
---|
787 | 865 | |
---|
| 866 | + /* Setting the coded format determines the selected codec */ |
---|
| 867 | + codec = coda_find_codec(ctx->dev, q_data_src->fourcc, |
---|
| 868 | + f->fmt.pix.pixelformat); |
---|
| 869 | + if (!codec) { |
---|
| 870 | + v4l2_err(&ctx->dev->v4l2_dev, "failed to determine codec\n"); |
---|
| 871 | + return -EINVAL; |
---|
| 872 | + } |
---|
| 873 | + ctx->codec = codec; |
---|
| 874 | + |
---|
788 | 875 | ctx->colorspace = f->fmt.pix.colorspace; |
---|
789 | 876 | ctx->xfer_func = f->fmt.pix.xfer_func; |
---|
790 | 877 | ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc; |
---|
.. | .. |
---|
797 | 884 | struct v4l2_format *f) |
---|
798 | 885 | { |
---|
799 | 886 | struct coda_ctx *ctx = fh_to_ctx(priv); |
---|
| 887 | + const struct coda_codec *codec; |
---|
800 | 888 | struct v4l2_format f_cap; |
---|
801 | 889 | struct vb2_queue *dst_vq; |
---|
802 | 890 | int ret; |
---|
.. | .. |
---|
809 | 897 | if (ret) |
---|
810 | 898 | return ret; |
---|
811 | 899 | |
---|
812 | | - if (ctx->inst_type != CODA_INST_DECODER) |
---|
813 | | - return 0; |
---|
814 | | - |
---|
815 | 900 | ctx->colorspace = f->fmt.pix.colorspace; |
---|
816 | 901 | ctx->xfer_func = f->fmt.pix.xfer_func; |
---|
817 | 902 | ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc; |
---|
818 | 903 | ctx->quantization = f->fmt.pix.quantization; |
---|
| 904 | + |
---|
| 905 | + if (ctx->inst_type != CODA_INST_DECODER) |
---|
| 906 | + return 0; |
---|
| 907 | + |
---|
| 908 | + /* Setting the coded format determines the selected codec */ |
---|
| 909 | + codec = coda_find_codec(ctx->dev, f->fmt.pix.pixelformat, |
---|
| 910 | + V4L2_PIX_FMT_YUV420); |
---|
| 911 | + if (!codec) { |
---|
| 912 | + v4l2_err(&ctx->dev->v4l2_dev, "failed to determine codec\n"); |
---|
| 913 | + return -EINVAL; |
---|
| 914 | + } |
---|
| 915 | + ctx->codec = codec; |
---|
819 | 916 | |
---|
820 | 917 | dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
---|
821 | 918 | if (!dst_vq) |
---|
.. | .. |
---|
864 | 961 | { |
---|
865 | 962 | struct coda_ctx *ctx = fh_to_ctx(priv); |
---|
866 | 963 | |
---|
| 964 | + if (ctx->inst_type == CODA_INST_DECODER && |
---|
| 965 | + buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) |
---|
| 966 | + buf->flags &= ~V4L2_BUF_FLAG_LAST; |
---|
| 967 | + |
---|
867 | 968 | return v4l2_m2m_qbuf(file, ctx->fh.m2m_ctx, buf); |
---|
868 | 969 | } |
---|
869 | 970 | |
---|
870 | | -static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx, |
---|
871 | | - struct vb2_v4l2_buffer *buf) |
---|
| 971 | +static int coda_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) |
---|
872 | 972 | { |
---|
873 | | - return ((ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) && |
---|
874 | | - (buf->sequence == (ctx->qsequence - 1))); |
---|
| 973 | + struct coda_ctx *ctx = fh_to_ctx(priv); |
---|
| 974 | + int ret; |
---|
| 975 | + |
---|
| 976 | + ret = v4l2_m2m_dqbuf(file, ctx->fh.m2m_ctx, buf); |
---|
| 977 | + |
---|
| 978 | + if (ctx->inst_type == CODA_INST_DECODER && |
---|
| 979 | + buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) |
---|
| 980 | + buf->flags &= ~V4L2_BUF_FLAG_LAST; |
---|
| 981 | + |
---|
| 982 | + return ret; |
---|
875 | 983 | } |
---|
876 | 984 | |
---|
877 | 985 | void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf, |
---|
.. | .. |
---|
881 | 989 | .type = V4L2_EVENT_EOS |
---|
882 | 990 | }; |
---|
883 | 991 | |
---|
884 | | - if (coda_buf_is_end_of_stream(ctx, buf)) { |
---|
885 | | - buf->flags |= V4L2_BUF_FLAG_LAST; |
---|
886 | | - |
---|
| 992 | + if (buf->flags & V4L2_BUF_FLAG_LAST) |
---|
887 | 993 | v4l2_event_queue_fh(&ctx->fh, &eos_event); |
---|
888 | | - } |
---|
889 | 994 | |
---|
890 | 995 | v4l2_m2m_buf_done(buf, state); |
---|
891 | 996 | } |
---|
.. | .. |
---|
911 | 1016 | case V4L2_SEL_TGT_CROP_DEFAULT: |
---|
912 | 1017 | case V4L2_SEL_TGT_CROP_BOUNDS: |
---|
913 | 1018 | rsel = &r; |
---|
914 | | - /* fallthrough */ |
---|
| 1019 | + fallthrough; |
---|
915 | 1020 | case V4L2_SEL_TGT_CROP: |
---|
916 | | - if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) |
---|
| 1021 | + if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT || |
---|
| 1022 | + ctx->inst_type == CODA_INST_DECODER) |
---|
917 | 1023 | return -EINVAL; |
---|
918 | 1024 | break; |
---|
919 | 1025 | case V4L2_SEL_TGT_COMPOSE_BOUNDS: |
---|
920 | 1026 | case V4L2_SEL_TGT_COMPOSE_PADDED: |
---|
921 | 1027 | rsel = &r; |
---|
922 | | - /* fallthrough */ |
---|
| 1028 | + fallthrough; |
---|
923 | 1029 | case V4L2_SEL_TGT_COMPOSE: |
---|
924 | 1030 | case V4L2_SEL_TGT_COMPOSE_DEFAULT: |
---|
925 | | - if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
---|
| 1031 | + if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || |
---|
| 1032 | + ctx->inst_type == CODA_INST_ENCODER) |
---|
926 | 1033 | return -EINVAL; |
---|
927 | 1034 | break; |
---|
928 | 1035 | default: |
---|
.. | .. |
---|
940 | 1047 | struct coda_ctx *ctx = fh_to_ctx(fh); |
---|
941 | 1048 | struct coda_q_data *q_data; |
---|
942 | 1049 | |
---|
943 | | - if (ctx->inst_type == CODA_INST_ENCODER && |
---|
944 | | - s->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && |
---|
945 | | - s->target == V4L2_SEL_TGT_CROP) { |
---|
946 | | - q_data = get_q_data(ctx, s->type); |
---|
947 | | - if (!q_data) |
---|
948 | | - return -EINVAL; |
---|
| 1050 | + switch (s->target) { |
---|
| 1051 | + case V4L2_SEL_TGT_CROP: |
---|
| 1052 | + if (ctx->inst_type == CODA_INST_ENCODER && |
---|
| 1053 | + s->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
---|
| 1054 | + q_data = get_q_data(ctx, s->type); |
---|
| 1055 | + if (!q_data) |
---|
| 1056 | + return -EINVAL; |
---|
949 | 1057 | |
---|
950 | | - s->r.left = 0; |
---|
951 | | - s->r.top = 0; |
---|
952 | | - s->r.width = clamp(s->r.width, 2U, q_data->width); |
---|
953 | | - s->r.height = clamp(s->r.height, 2U, q_data->height); |
---|
| 1058 | + s->r.left = 0; |
---|
| 1059 | + s->r.top = 0; |
---|
| 1060 | + s->r.width = clamp(s->r.width, 2U, q_data->width); |
---|
| 1061 | + s->r.height = clamp(s->r.height, 2U, q_data->height); |
---|
954 | 1062 | |
---|
955 | | - if (s->flags & V4L2_SEL_FLAG_LE) { |
---|
956 | | - s->r.width = round_up(s->r.width, 2); |
---|
957 | | - s->r.height = round_up(s->r.height, 2); |
---|
958 | | - } else { |
---|
959 | | - s->r.width = round_down(s->r.width, 2); |
---|
960 | | - s->r.height = round_down(s->r.height, 2); |
---|
| 1063 | + if (s->flags & V4L2_SEL_FLAG_LE) { |
---|
| 1064 | + s->r.width = round_up(s->r.width, 2); |
---|
| 1065 | + s->r.height = round_up(s->r.height, 2); |
---|
| 1066 | + } else { |
---|
| 1067 | + s->r.width = round_down(s->r.width, 2); |
---|
| 1068 | + s->r.height = round_down(s->r.height, 2); |
---|
| 1069 | + } |
---|
| 1070 | + |
---|
| 1071 | + q_data->rect = s->r; |
---|
| 1072 | + |
---|
| 1073 | + coda_dbg(1, ctx, "Setting crop rectangle: %dx%d\n", |
---|
| 1074 | + s->r.width, s->r.height); |
---|
| 1075 | + |
---|
| 1076 | + return 0; |
---|
961 | 1077 | } |
---|
962 | | - |
---|
963 | | - q_data->rect = s->r; |
---|
964 | | - |
---|
965 | | - return 0; |
---|
| 1078 | + fallthrough; |
---|
| 1079 | + case V4L2_SEL_TGT_NATIVE_SIZE: |
---|
| 1080 | + case V4L2_SEL_TGT_COMPOSE: |
---|
| 1081 | + return coda_g_selection(file, fh, s); |
---|
| 1082 | + default: |
---|
| 1083 | + /* v4l2-compliance expects this to fail for read-only targets */ |
---|
| 1084 | + return -EINVAL; |
---|
966 | 1085 | } |
---|
967 | | - |
---|
968 | | - return coda_g_selection(file, fh, s); |
---|
969 | 1086 | } |
---|
970 | 1087 | |
---|
971 | 1088 | static int coda_try_encoder_cmd(struct file *file, void *fh, |
---|
972 | 1089 | struct v4l2_encoder_cmd *ec) |
---|
973 | 1090 | { |
---|
974 | | - if (ec->cmd != V4L2_ENC_CMD_STOP) |
---|
975 | | - return -EINVAL; |
---|
| 1091 | + struct coda_ctx *ctx = fh_to_ctx(fh); |
---|
976 | 1092 | |
---|
977 | | - if (ec->flags & V4L2_ENC_CMD_STOP_AT_GOP_END) |
---|
978 | | - return -EINVAL; |
---|
| 1093 | + if (ctx->inst_type != CODA_INST_ENCODER) |
---|
| 1094 | + return -ENOTTY; |
---|
979 | 1095 | |
---|
980 | | - return 0; |
---|
| 1096 | + return v4l2_m2m_ioctl_try_encoder_cmd(file, fh, ec); |
---|
| 1097 | +} |
---|
| 1098 | + |
---|
| 1099 | +static void coda_wake_up_capture_queue(struct coda_ctx *ctx) |
---|
| 1100 | +{ |
---|
| 1101 | + struct vb2_queue *dst_vq; |
---|
| 1102 | + |
---|
| 1103 | + coda_dbg(1, ctx, "waking up capture queue\n"); |
---|
| 1104 | + |
---|
| 1105 | + dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
---|
| 1106 | + dst_vq->last_buffer_dequeued = true; |
---|
| 1107 | + wake_up(&dst_vq->done_wq); |
---|
981 | 1108 | } |
---|
982 | 1109 | |
---|
983 | 1110 | static int coda_encoder_cmd(struct file *file, void *fh, |
---|
984 | 1111 | struct v4l2_encoder_cmd *ec) |
---|
985 | 1112 | { |
---|
986 | 1113 | struct coda_ctx *ctx = fh_to_ctx(fh); |
---|
987 | | - struct vb2_queue *dst_vq; |
---|
| 1114 | + struct vb2_v4l2_buffer *buf; |
---|
988 | 1115 | int ret; |
---|
989 | 1116 | |
---|
990 | 1117 | ret = coda_try_encoder_cmd(file, fh, ec); |
---|
991 | 1118 | if (ret < 0) |
---|
992 | 1119 | return ret; |
---|
993 | 1120 | |
---|
994 | | - /* Ignore encoder stop command silently in decoder context */ |
---|
995 | | - if (ctx->inst_type != CODA_INST_ENCODER) |
---|
996 | | - return 0; |
---|
| 1121 | + mutex_lock(&ctx->wakeup_mutex); |
---|
| 1122 | + buf = v4l2_m2m_last_src_buf(ctx->fh.m2m_ctx); |
---|
| 1123 | + if (buf) { |
---|
| 1124 | + /* |
---|
| 1125 | + * If the last output buffer is still on the queue, make sure |
---|
| 1126 | + * that decoder finish_run will see the last flag and report it |
---|
| 1127 | + * to userspace. |
---|
| 1128 | + */ |
---|
| 1129 | + buf->flags |= V4L2_BUF_FLAG_LAST; |
---|
| 1130 | + } else { |
---|
| 1131 | + /* Set the stream-end flag on this context */ |
---|
| 1132 | + ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; |
---|
997 | 1133 | |
---|
998 | | - /* Set the stream-end flag on this context */ |
---|
999 | | - ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; |
---|
1000 | | - |
---|
1001 | | - flush_work(&ctx->pic_run_work); |
---|
1002 | | - |
---|
1003 | | - /* If there is no buffer in flight, wake up */ |
---|
1004 | | - if (!ctx->streamon_out || ctx->qsequence == ctx->osequence) { |
---|
1005 | | - dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, |
---|
1006 | | - V4L2_BUF_TYPE_VIDEO_CAPTURE); |
---|
1007 | | - dst_vq->last_buffer_dequeued = true; |
---|
1008 | | - wake_up(&dst_vq->done_wq); |
---|
| 1134 | + /* |
---|
| 1135 | + * If the last output buffer has already been taken from the |
---|
| 1136 | + * queue, wake up the capture queue and signal end of stream |
---|
| 1137 | + * via the -EPIPE mechanism. |
---|
| 1138 | + */ |
---|
| 1139 | + coda_wake_up_capture_queue(ctx); |
---|
1009 | 1140 | } |
---|
| 1141 | + mutex_unlock(&ctx->wakeup_mutex); |
---|
1010 | 1142 | |
---|
1011 | 1143 | return 0; |
---|
1012 | 1144 | } |
---|
.. | .. |
---|
1014 | 1146 | static int coda_try_decoder_cmd(struct file *file, void *fh, |
---|
1015 | 1147 | struct v4l2_decoder_cmd *dc) |
---|
1016 | 1148 | { |
---|
1017 | | - if (dc->cmd != V4L2_DEC_CMD_STOP) |
---|
1018 | | - return -EINVAL; |
---|
| 1149 | + struct coda_ctx *ctx = fh_to_ctx(fh); |
---|
1019 | 1150 | |
---|
1020 | | - if (dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK) |
---|
1021 | | - return -EINVAL; |
---|
| 1151 | + if (ctx->inst_type != CODA_INST_DECODER) |
---|
| 1152 | + return -ENOTTY; |
---|
1022 | 1153 | |
---|
1023 | | - if (!(dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY) && (dc->stop.pts != 0)) |
---|
1024 | | - return -EINVAL; |
---|
| 1154 | + return v4l2_m2m_ioctl_try_decoder_cmd(file, fh, dc); |
---|
| 1155 | +} |
---|
1025 | 1156 | |
---|
1026 | | - return 0; |
---|
| 1157 | +static bool coda_mark_last_meta(struct coda_ctx *ctx) |
---|
| 1158 | +{ |
---|
| 1159 | + struct coda_buffer_meta *meta; |
---|
| 1160 | + |
---|
| 1161 | + coda_dbg(1, ctx, "marking last meta\n"); |
---|
| 1162 | + |
---|
| 1163 | + spin_lock(&ctx->buffer_meta_lock); |
---|
| 1164 | + if (list_empty(&ctx->buffer_meta_list)) { |
---|
| 1165 | + spin_unlock(&ctx->buffer_meta_lock); |
---|
| 1166 | + return false; |
---|
| 1167 | + } |
---|
| 1168 | + |
---|
| 1169 | + meta = list_last_entry(&ctx->buffer_meta_list, struct coda_buffer_meta, |
---|
| 1170 | + list); |
---|
| 1171 | + meta->last = true; |
---|
| 1172 | + |
---|
| 1173 | + spin_unlock(&ctx->buffer_meta_lock); |
---|
| 1174 | + return true; |
---|
| 1175 | +} |
---|
| 1176 | + |
---|
| 1177 | +static bool coda_mark_last_dst_buf(struct coda_ctx *ctx) |
---|
| 1178 | +{ |
---|
| 1179 | + struct vb2_v4l2_buffer *buf; |
---|
| 1180 | + struct vb2_buffer *dst_vb; |
---|
| 1181 | + struct vb2_queue *dst_vq; |
---|
| 1182 | + unsigned long flags; |
---|
| 1183 | + |
---|
| 1184 | + coda_dbg(1, ctx, "marking last capture buffer\n"); |
---|
| 1185 | + |
---|
| 1186 | + dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
---|
| 1187 | + spin_lock_irqsave(&dst_vq->done_lock, flags); |
---|
| 1188 | + if (list_empty(&dst_vq->done_list)) { |
---|
| 1189 | + spin_unlock_irqrestore(&dst_vq->done_lock, flags); |
---|
| 1190 | + return false; |
---|
| 1191 | + } |
---|
| 1192 | + |
---|
| 1193 | + dst_vb = list_last_entry(&dst_vq->done_list, struct vb2_buffer, |
---|
| 1194 | + done_entry); |
---|
| 1195 | + buf = to_vb2_v4l2_buffer(dst_vb); |
---|
| 1196 | + buf->flags |= V4L2_BUF_FLAG_LAST; |
---|
| 1197 | + |
---|
| 1198 | + spin_unlock_irqrestore(&dst_vq->done_lock, flags); |
---|
| 1199 | + return true; |
---|
1027 | 1200 | } |
---|
1028 | 1201 | |
---|
1029 | 1202 | static int coda_decoder_cmd(struct file *file, void *fh, |
---|
1030 | 1203 | struct v4l2_decoder_cmd *dc) |
---|
1031 | 1204 | { |
---|
1032 | 1205 | struct coda_ctx *ctx = fh_to_ctx(fh); |
---|
| 1206 | + struct coda_dev *dev = ctx->dev; |
---|
| 1207 | + struct vb2_v4l2_buffer *buf; |
---|
| 1208 | + struct vb2_queue *dst_vq; |
---|
| 1209 | + bool stream_end; |
---|
| 1210 | + bool wakeup; |
---|
1033 | 1211 | int ret; |
---|
1034 | 1212 | |
---|
1035 | 1213 | ret = coda_try_decoder_cmd(file, fh, dc); |
---|
1036 | 1214 | if (ret < 0) |
---|
1037 | 1215 | return ret; |
---|
1038 | 1216 | |
---|
1039 | | - /* Ignore decoder stop command silently in encoder context */ |
---|
1040 | | - if (ctx->inst_type != CODA_INST_DECODER) |
---|
1041 | | - return 0; |
---|
| 1217 | + switch (dc->cmd) { |
---|
| 1218 | + case V4L2_DEC_CMD_START: |
---|
| 1219 | + mutex_lock(&dev->coda_mutex); |
---|
| 1220 | + mutex_lock(&ctx->bitstream_mutex); |
---|
| 1221 | + coda_bitstream_flush(ctx); |
---|
| 1222 | + dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, |
---|
| 1223 | + V4L2_BUF_TYPE_VIDEO_CAPTURE); |
---|
| 1224 | + vb2_clear_last_buffer_dequeued(dst_vq); |
---|
| 1225 | + ctx->bit_stream_param &= ~CODA_BIT_STREAM_END_FLAG; |
---|
| 1226 | + coda_fill_bitstream(ctx, NULL); |
---|
| 1227 | + mutex_unlock(&ctx->bitstream_mutex); |
---|
| 1228 | + mutex_unlock(&dev->coda_mutex); |
---|
| 1229 | + break; |
---|
| 1230 | + case V4L2_DEC_CMD_STOP: |
---|
| 1231 | + stream_end = false; |
---|
| 1232 | + wakeup = false; |
---|
1042 | 1233 | |
---|
1043 | | - /* Set the stream-end flag on this context */ |
---|
1044 | | - coda_bit_stream_end_flag(ctx); |
---|
1045 | | - ctx->hold = false; |
---|
1046 | | - v4l2_m2m_try_schedule(ctx->fh.m2m_ctx); |
---|
| 1234 | + mutex_lock(&ctx->wakeup_mutex); |
---|
| 1235 | + |
---|
| 1236 | + buf = v4l2_m2m_last_src_buf(ctx->fh.m2m_ctx); |
---|
| 1237 | + if (buf) { |
---|
| 1238 | + coda_dbg(1, ctx, "marking last pending buffer\n"); |
---|
| 1239 | + |
---|
| 1240 | + /* Mark last buffer */ |
---|
| 1241 | + buf->flags |= V4L2_BUF_FLAG_LAST; |
---|
| 1242 | + |
---|
| 1243 | + if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) == 0) { |
---|
| 1244 | + coda_dbg(1, ctx, "all remaining buffers queued\n"); |
---|
| 1245 | + stream_end = true; |
---|
| 1246 | + } |
---|
| 1247 | + } else { |
---|
| 1248 | + if (ctx->use_bit) |
---|
| 1249 | + if (coda_mark_last_meta(ctx)) |
---|
| 1250 | + stream_end = true; |
---|
| 1251 | + else |
---|
| 1252 | + wakeup = true; |
---|
| 1253 | + else |
---|
| 1254 | + if (!coda_mark_last_dst_buf(ctx)) |
---|
| 1255 | + wakeup = true; |
---|
| 1256 | + } |
---|
| 1257 | + |
---|
| 1258 | + if (stream_end) { |
---|
| 1259 | + coda_dbg(1, ctx, "all remaining buffers queued\n"); |
---|
| 1260 | + |
---|
| 1261 | + /* Set the stream-end flag on this context */ |
---|
| 1262 | + coda_bit_stream_end_flag(ctx); |
---|
| 1263 | + ctx->hold = false; |
---|
| 1264 | + v4l2_m2m_try_schedule(ctx->fh.m2m_ctx); |
---|
| 1265 | + } |
---|
| 1266 | + |
---|
| 1267 | + if (wakeup) { |
---|
| 1268 | + /* If there is no buffer in flight, wake up */ |
---|
| 1269 | + coda_wake_up_capture_queue(ctx); |
---|
| 1270 | + } |
---|
| 1271 | + |
---|
| 1272 | + mutex_unlock(&ctx->wakeup_mutex); |
---|
| 1273 | + break; |
---|
| 1274 | + default: |
---|
| 1275 | + return -EINVAL; |
---|
| 1276 | + } |
---|
| 1277 | + |
---|
| 1278 | + return 0; |
---|
| 1279 | +} |
---|
| 1280 | + |
---|
| 1281 | +static int coda_enum_framesizes(struct file *file, void *fh, |
---|
| 1282 | + struct v4l2_frmsizeenum *fsize) |
---|
| 1283 | +{ |
---|
| 1284 | + struct coda_ctx *ctx = fh_to_ctx(fh); |
---|
| 1285 | + struct coda_q_data *q_data_dst; |
---|
| 1286 | + const struct coda_codec *codec; |
---|
| 1287 | + |
---|
| 1288 | + if (ctx->inst_type != CODA_INST_ENCODER) |
---|
| 1289 | + return -ENOTTY; |
---|
| 1290 | + |
---|
| 1291 | + if (fsize->index) |
---|
| 1292 | + return -EINVAL; |
---|
| 1293 | + |
---|
| 1294 | + if (coda_format_normalize_yuv(fsize->pixel_format) == |
---|
| 1295 | + V4L2_PIX_FMT_YUV420) { |
---|
| 1296 | + q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
---|
| 1297 | + codec = coda_find_codec(ctx->dev, fsize->pixel_format, |
---|
| 1298 | + q_data_dst->fourcc); |
---|
| 1299 | + } else { |
---|
| 1300 | + codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_YUV420, |
---|
| 1301 | + fsize->pixel_format); |
---|
| 1302 | + } |
---|
| 1303 | + if (!codec) |
---|
| 1304 | + return -EINVAL; |
---|
| 1305 | + |
---|
| 1306 | + fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; |
---|
| 1307 | + fsize->stepwise.min_width = MIN_W; |
---|
| 1308 | + fsize->stepwise.max_width = codec->max_w; |
---|
| 1309 | + fsize->stepwise.step_width = 1; |
---|
| 1310 | + fsize->stepwise.min_height = MIN_H; |
---|
| 1311 | + fsize->stepwise.max_height = codec->max_h; |
---|
| 1312 | + fsize->stepwise.step_height = 1; |
---|
| 1313 | + |
---|
| 1314 | + return 0; |
---|
| 1315 | +} |
---|
| 1316 | + |
---|
| 1317 | +static int coda_enum_frameintervals(struct file *file, void *fh, |
---|
| 1318 | + struct v4l2_frmivalenum *f) |
---|
| 1319 | +{ |
---|
| 1320 | + struct coda_ctx *ctx = fh_to_ctx(fh); |
---|
| 1321 | + struct coda_q_data *q_data; |
---|
| 1322 | + const struct coda_codec *codec; |
---|
| 1323 | + |
---|
| 1324 | + if (f->index) |
---|
| 1325 | + return -EINVAL; |
---|
| 1326 | + |
---|
| 1327 | + /* Disallow YUYV if the vdoa is not available */ |
---|
| 1328 | + if (!ctx->vdoa && f->pixel_format == V4L2_PIX_FMT_YUYV) |
---|
| 1329 | + return -EINVAL; |
---|
| 1330 | + |
---|
| 1331 | + if (coda_format_normalize_yuv(f->pixel_format) == V4L2_PIX_FMT_YUV420) { |
---|
| 1332 | + q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
---|
| 1333 | + codec = coda_find_codec(ctx->dev, f->pixel_format, |
---|
| 1334 | + q_data->fourcc); |
---|
| 1335 | + } else { |
---|
| 1336 | + codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_YUV420, |
---|
| 1337 | + f->pixel_format); |
---|
| 1338 | + } |
---|
| 1339 | + if (!codec) |
---|
| 1340 | + return -EINVAL; |
---|
| 1341 | + |
---|
| 1342 | + if (f->width < MIN_W || f->width > codec->max_w || |
---|
| 1343 | + f->height < MIN_H || f->height > codec->max_h) |
---|
| 1344 | + return -EINVAL; |
---|
| 1345 | + |
---|
| 1346 | + f->type = V4L2_FRMIVAL_TYPE_CONTINUOUS; |
---|
| 1347 | + f->stepwise.min.numerator = 1; |
---|
| 1348 | + f->stepwise.min.denominator = 65535; |
---|
| 1349 | + f->stepwise.max.numerator = 65536; |
---|
| 1350 | + f->stepwise.max.denominator = 1; |
---|
| 1351 | + f->stepwise.step.numerator = 1; |
---|
| 1352 | + f->stepwise.step.denominator = 1; |
---|
1047 | 1353 | |
---|
1048 | 1354 | return 0; |
---|
1049 | 1355 | } |
---|
.. | .. |
---|
1084 | 1390 | return; |
---|
1085 | 1391 | } |
---|
1086 | 1392 | |
---|
1087 | | - /* Upper bound is 65536/1, map everything above to infinity */ |
---|
| 1393 | + /* Upper bound is 65536/1 */ |
---|
1088 | 1394 | if (s.denominator == 0 || s.numerator / s.denominator > 65536) { |
---|
1089 | | - timeperframe->numerator = 1; |
---|
1090 | | - timeperframe->denominator = 0; |
---|
| 1395 | + timeperframe->numerator = 65536; |
---|
| 1396 | + timeperframe->denominator = 1; |
---|
1091 | 1397 | return; |
---|
1092 | 1398 | } |
---|
1093 | 1399 | |
---|
.. | .. |
---|
1139 | 1445 | if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) |
---|
1140 | 1446 | return -EINVAL; |
---|
1141 | 1447 | |
---|
| 1448 | + a->parm.output.capability = V4L2_CAP_TIMEPERFRAME; |
---|
1142 | 1449 | tpf = &a->parm.output.timeperframe; |
---|
1143 | 1450 | coda_approximate_timeperframe(tpf); |
---|
1144 | 1451 | ctx->params.framerate = coda_timeperframe_to_frate(tpf); |
---|
| 1452 | + ctx->params.framerate_changed = true; |
---|
1145 | 1453 | |
---|
1146 | 1454 | return 0; |
---|
1147 | 1455 | } |
---|
.. | .. |
---|
1149 | 1457 | static int coda_subscribe_event(struct v4l2_fh *fh, |
---|
1150 | 1458 | const struct v4l2_event_subscription *sub) |
---|
1151 | 1459 | { |
---|
| 1460 | + struct coda_ctx *ctx = fh_to_ctx(fh); |
---|
| 1461 | + |
---|
1152 | 1462 | switch (sub->type) { |
---|
1153 | 1463 | case V4L2_EVENT_EOS: |
---|
1154 | 1464 | return v4l2_event_subscribe(fh, sub, 0, NULL); |
---|
| 1465 | + case V4L2_EVENT_SOURCE_CHANGE: |
---|
| 1466 | + if (ctx->inst_type == CODA_INST_DECODER) |
---|
| 1467 | + return v4l2_event_subscribe(fh, sub, 0, NULL); |
---|
| 1468 | + else |
---|
| 1469 | + return -EINVAL; |
---|
1155 | 1470 | default: |
---|
1156 | 1471 | return v4l2_ctrl_subscribe_event(fh, sub); |
---|
1157 | 1472 | } |
---|
.. | .. |
---|
1175 | 1490 | |
---|
1176 | 1491 | .vidioc_qbuf = coda_qbuf, |
---|
1177 | 1492 | .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, |
---|
1178 | | - .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, |
---|
| 1493 | + .vidioc_dqbuf = coda_dqbuf, |
---|
1179 | 1494 | .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, |
---|
1180 | 1495 | .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, |
---|
1181 | 1496 | |
---|
.. | .. |
---|
1192 | 1507 | |
---|
1193 | 1508 | .vidioc_g_parm = coda_g_parm, |
---|
1194 | 1509 | .vidioc_s_parm = coda_s_parm, |
---|
| 1510 | + |
---|
| 1511 | + .vidioc_enum_framesizes = coda_enum_framesizes, |
---|
| 1512 | + .vidioc_enum_frameintervals = coda_enum_frameintervals, |
---|
1195 | 1513 | |
---|
1196 | 1514 | .vidioc_subscribe_event = coda_subscribe_event, |
---|
1197 | 1515 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
---|
.. | .. |
---|
1228 | 1546 | |
---|
1229 | 1547 | if (!wait_for_completion_timeout(&ctx->completion, |
---|
1230 | 1548 | msecs_to_jiffies(1000))) { |
---|
1231 | | - dev_err(&dev->plat_dev->dev, "CODA PIC_RUN timeout\n"); |
---|
| 1549 | + if (ctx->use_bit) { |
---|
| 1550 | + dev_err(dev->dev, "CODA PIC_RUN timeout\n"); |
---|
1232 | 1551 | |
---|
1233 | | - ctx->hold = true; |
---|
| 1552 | + ctx->hold = true; |
---|
1234 | 1553 | |
---|
1235 | | - coda_hw_reset(ctx); |
---|
| 1554 | + coda_hw_reset(ctx); |
---|
| 1555 | + } |
---|
1236 | 1556 | |
---|
1237 | 1557 | if (ctx->ops->run_timeout) |
---|
1238 | 1558 | ctx->ops->run_timeout(ctx); |
---|
1239 | | - } else if (!ctx->aborting) { |
---|
| 1559 | + } else { |
---|
1240 | 1560 | ctx->ops->finish_run(ctx); |
---|
1241 | 1561 | } |
---|
1242 | 1562 | |
---|
.. | .. |
---|
1261 | 1581 | * the compressed frame can be in the bitstream. |
---|
1262 | 1582 | */ |
---|
1263 | 1583 | if (!src_bufs && ctx->inst_type != CODA_INST_DECODER) { |
---|
1264 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1265 | | - "not ready: not enough video buffers.\n"); |
---|
| 1584 | + coda_dbg(1, ctx, "not ready: not enough vid-out buffers.\n"); |
---|
1266 | 1585 | return 0; |
---|
1267 | 1586 | } |
---|
1268 | 1587 | |
---|
1269 | 1588 | if (!v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx)) { |
---|
1270 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1271 | | - "not ready: not enough video capture buffers.\n"); |
---|
| 1589 | + coda_dbg(1, ctx, "not ready: not enough vid-cap buffers.\n"); |
---|
1272 | 1590 | return 0; |
---|
1273 | 1591 | } |
---|
1274 | 1592 | |
---|
.. | .. |
---|
1276 | 1594 | bool stream_end = ctx->bit_stream_param & |
---|
1277 | 1595 | CODA_BIT_STREAM_END_FLAG; |
---|
1278 | 1596 | int num_metas = ctx->num_metas; |
---|
| 1597 | + struct coda_buffer_meta *meta; |
---|
1279 | 1598 | unsigned int count; |
---|
1280 | 1599 | |
---|
1281 | 1600 | count = hweight32(ctx->frm_dis_flg); |
---|
1282 | 1601 | if (ctx->use_vdoa && count >= (ctx->num_internal_frames - 1)) { |
---|
1283 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1284 | | - "%d: not ready: all internal buffers in use: %d/%d (0x%x)", |
---|
1285 | | - ctx->idx, count, ctx->num_internal_frames, |
---|
| 1602 | + coda_dbg(1, ctx, |
---|
| 1603 | + "not ready: all internal buffers in use: %d/%d (0x%x)", |
---|
| 1604 | + count, ctx->num_internal_frames, |
---|
1286 | 1605 | ctx->frm_dis_flg); |
---|
1287 | 1606 | return 0; |
---|
1288 | 1607 | } |
---|
1289 | 1608 | |
---|
1290 | 1609 | if (ctx->hold && !src_bufs) { |
---|
1291 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1292 | | - "%d: not ready: on hold for more buffers.\n", |
---|
1293 | | - ctx->idx); |
---|
| 1610 | + coda_dbg(1, ctx, |
---|
| 1611 | + "not ready: on hold for more buffers.\n"); |
---|
1294 | 1612 | return 0; |
---|
1295 | 1613 | } |
---|
1296 | 1614 | |
---|
1297 | 1615 | if (!stream_end && (num_metas + src_bufs) < 2) { |
---|
1298 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1299 | | - "%d: not ready: need 2 buffers available (%d, %d)\n", |
---|
1300 | | - ctx->idx, num_metas, src_bufs); |
---|
| 1616 | + coda_dbg(1, ctx, |
---|
| 1617 | + "not ready: need 2 buffers available (queue:%d + bitstream:%d)\n", |
---|
| 1618 | + num_metas, src_bufs); |
---|
1301 | 1619 | return 0; |
---|
1302 | 1620 | } |
---|
1303 | 1621 | |
---|
1304 | | - |
---|
1305 | | - if (!src_bufs && !stream_end && |
---|
1306 | | - (coda_get_bitstream_payload(ctx) < 512)) { |
---|
1307 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1308 | | - "%d: not ready: not enough bitstream data (%d).\n", |
---|
1309 | | - ctx->idx, coda_get_bitstream_payload(ctx)); |
---|
| 1622 | + meta = list_first_entry(&ctx->buffer_meta_list, |
---|
| 1623 | + struct coda_buffer_meta, list); |
---|
| 1624 | + if (!coda_bitstream_can_fetch_past(ctx, meta->end) && |
---|
| 1625 | + !stream_end) { |
---|
| 1626 | + coda_dbg(1, ctx, |
---|
| 1627 | + "not ready: not enough bitstream data to read past %u (%u)\n", |
---|
| 1628 | + meta->end, ctx->bitstream_fifo.kfifo.in); |
---|
1310 | 1629 | return 0; |
---|
1311 | 1630 | } |
---|
1312 | 1631 | } |
---|
1313 | 1632 | |
---|
1314 | 1633 | if (ctx->aborting) { |
---|
1315 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1316 | | - "not ready: aborting\n"); |
---|
| 1634 | + coda_dbg(1, ctx, "not ready: aborting\n"); |
---|
1317 | 1635 | return 0; |
---|
1318 | 1636 | } |
---|
1319 | 1637 | |
---|
1320 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1321 | | - "job ready\n"); |
---|
| 1638 | + coda_dbg(2, ctx, "job ready\n"); |
---|
1322 | 1639 | |
---|
1323 | 1640 | return 1; |
---|
1324 | 1641 | } |
---|
.. | .. |
---|
1329 | 1646 | |
---|
1330 | 1647 | ctx->aborting = 1; |
---|
1331 | 1648 | |
---|
1332 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1333 | | - "Aborting task\n"); |
---|
| 1649 | + coda_dbg(1, ctx, "job abort\n"); |
---|
1334 | 1650 | } |
---|
1335 | 1651 | |
---|
1336 | 1652 | static const struct v4l2_m2m_ops coda_m2m_ops = { |
---|
.. | .. |
---|
1404 | 1720 | q_data = get_q_data(ctx, vq->type); |
---|
1405 | 1721 | size = q_data->sizeimage; |
---|
1406 | 1722 | |
---|
| 1723 | + if (*nplanes) |
---|
| 1724 | + return sizes[0] < size ? -EINVAL : 0; |
---|
| 1725 | + |
---|
1407 | 1726 | *nplanes = 1; |
---|
1408 | 1727 | sizes[0] = size; |
---|
1409 | 1728 | |
---|
1410 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1411 | | - "get %d buffer(s) of size %d each.\n", *nbuffers, size); |
---|
| 1729 | + coda_dbg(1, ctx, "get %d buffer(s) of size %d each.\n", *nbuffers, |
---|
| 1730 | + size); |
---|
1412 | 1731 | |
---|
1413 | 1732 | return 0; |
---|
1414 | 1733 | } |
---|
1415 | 1734 | |
---|
1416 | 1735 | static int coda_buf_prepare(struct vb2_buffer *vb) |
---|
1417 | 1736 | { |
---|
| 1737 | + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
---|
1418 | 1738 | struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
---|
1419 | 1739 | struct coda_q_data *q_data; |
---|
1420 | 1740 | |
---|
1421 | 1741 | q_data = get_q_data(ctx, vb->vb2_queue->type); |
---|
| 1742 | + if (V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) { |
---|
| 1743 | + if (vbuf->field == V4L2_FIELD_ANY) |
---|
| 1744 | + vbuf->field = V4L2_FIELD_NONE; |
---|
| 1745 | + if (vbuf->field != V4L2_FIELD_NONE) { |
---|
| 1746 | + v4l2_warn(&ctx->dev->v4l2_dev, |
---|
| 1747 | + "%s field isn't supported\n", __func__); |
---|
| 1748 | + return -EINVAL; |
---|
| 1749 | + } |
---|
| 1750 | + } |
---|
1422 | 1751 | |
---|
1423 | 1752 | if (vb2_plane_size(vb, 0) < q_data->sizeimage) { |
---|
1424 | 1753 | v4l2_warn(&ctx->dev->v4l2_dev, |
---|
.. | .. |
---|
1457 | 1786 | v4l2_ctrl_unlock(ctrl); |
---|
1458 | 1787 | } |
---|
1459 | 1788 | |
---|
1460 | | -static void coda_update_h264_profile_ctrl(struct coda_ctx *ctx) |
---|
| 1789 | +void coda_update_profile_level_ctrls(struct coda_ctx *ctx, u8 profile_idc, |
---|
| 1790 | + u8 level_idc) |
---|
1461 | 1791 | { |
---|
1462 | 1792 | const char * const *profile_names; |
---|
1463 | | - int profile; |
---|
1464 | | - |
---|
1465 | | - profile = coda_h264_profile(ctx->params.h264_profile_idc); |
---|
1466 | | - if (profile < 0) { |
---|
1467 | | - v4l2_warn(&ctx->dev->v4l2_dev, "Invalid H264 Profile: %u\n", |
---|
1468 | | - ctx->params.h264_profile_idc); |
---|
1469 | | - return; |
---|
1470 | | - } |
---|
1471 | | - |
---|
1472 | | - coda_update_menu_ctrl(ctx->h264_profile_ctrl, profile); |
---|
1473 | | - |
---|
1474 | | - profile_names = v4l2_ctrl_get_menu(V4L2_CID_MPEG_VIDEO_H264_PROFILE); |
---|
1475 | | - |
---|
1476 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "Parsed H264 Profile: %s\n", |
---|
1477 | | - profile_names[profile]); |
---|
1478 | | -} |
---|
1479 | | - |
---|
1480 | | -static void coda_update_h264_level_ctrl(struct coda_ctx *ctx) |
---|
1481 | | -{ |
---|
1482 | 1793 | const char * const *level_names; |
---|
| 1794 | + struct v4l2_ctrl *profile_ctrl; |
---|
| 1795 | + struct v4l2_ctrl *level_ctrl; |
---|
| 1796 | + const char *codec_name; |
---|
| 1797 | + u32 profile_cid; |
---|
| 1798 | + u32 level_cid; |
---|
| 1799 | + int profile; |
---|
1483 | 1800 | int level; |
---|
1484 | 1801 | |
---|
1485 | | - level = coda_h264_level(ctx->params.h264_level_idc); |
---|
1486 | | - if (level < 0) { |
---|
1487 | | - v4l2_warn(&ctx->dev->v4l2_dev, "Invalid H264 Level: %u\n", |
---|
1488 | | - ctx->params.h264_level_idc); |
---|
| 1802 | + switch (ctx->codec->src_fourcc) { |
---|
| 1803 | + case V4L2_PIX_FMT_H264: |
---|
| 1804 | + codec_name = "H264"; |
---|
| 1805 | + profile_cid = V4L2_CID_MPEG_VIDEO_H264_PROFILE; |
---|
| 1806 | + level_cid = V4L2_CID_MPEG_VIDEO_H264_LEVEL; |
---|
| 1807 | + profile_ctrl = ctx->h264_profile_ctrl; |
---|
| 1808 | + level_ctrl = ctx->h264_level_ctrl; |
---|
| 1809 | + profile = coda_h264_profile(profile_idc); |
---|
| 1810 | + level = coda_h264_level(level_idc); |
---|
| 1811 | + break; |
---|
| 1812 | + case V4L2_PIX_FMT_MPEG2: |
---|
| 1813 | + codec_name = "MPEG-2"; |
---|
| 1814 | + profile_cid = V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE; |
---|
| 1815 | + level_cid = V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL; |
---|
| 1816 | + profile_ctrl = ctx->mpeg2_profile_ctrl; |
---|
| 1817 | + level_ctrl = ctx->mpeg2_level_ctrl; |
---|
| 1818 | + profile = coda_mpeg2_profile(profile_idc); |
---|
| 1819 | + level = coda_mpeg2_level(level_idc); |
---|
| 1820 | + break; |
---|
| 1821 | + case V4L2_PIX_FMT_MPEG4: |
---|
| 1822 | + codec_name = "MPEG-4"; |
---|
| 1823 | + profile_cid = V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE; |
---|
| 1824 | + level_cid = V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL; |
---|
| 1825 | + profile_ctrl = ctx->mpeg4_profile_ctrl; |
---|
| 1826 | + level_ctrl = ctx->mpeg4_level_ctrl; |
---|
| 1827 | + profile = coda_mpeg4_profile(profile_idc); |
---|
| 1828 | + level = coda_mpeg4_level(level_idc); |
---|
| 1829 | + break; |
---|
| 1830 | + default: |
---|
1489 | 1831 | return; |
---|
1490 | 1832 | } |
---|
1491 | 1833 | |
---|
1492 | | - coda_update_menu_ctrl(ctx->h264_level_ctrl, level); |
---|
| 1834 | + profile_names = v4l2_ctrl_get_menu(profile_cid); |
---|
| 1835 | + level_names = v4l2_ctrl_get_menu(level_cid); |
---|
1493 | 1836 | |
---|
1494 | | - level_names = v4l2_ctrl_get_menu(V4L2_CID_MPEG_VIDEO_H264_LEVEL); |
---|
| 1837 | + if (profile < 0) { |
---|
| 1838 | + v4l2_warn(&ctx->dev->v4l2_dev, "Invalid %s profile: %u\n", |
---|
| 1839 | + codec_name, profile_idc); |
---|
| 1840 | + } else { |
---|
| 1841 | + coda_dbg(1, ctx, "Parsed %s profile: %s\n", codec_name, |
---|
| 1842 | + profile_names[profile]); |
---|
| 1843 | + coda_update_menu_ctrl(profile_ctrl, profile); |
---|
| 1844 | + } |
---|
1495 | 1845 | |
---|
1496 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "Parsed H264 Level: %s\n", |
---|
1497 | | - level_names[level]); |
---|
| 1846 | + if (level < 0) { |
---|
| 1847 | + v4l2_warn(&ctx->dev->v4l2_dev, "Invalid %s level: %u\n", |
---|
| 1848 | + codec_name, level_idc); |
---|
| 1849 | + } else { |
---|
| 1850 | + coda_dbg(1, ctx, "Parsed %s level: %s\n", codec_name, |
---|
| 1851 | + level_names[level]); |
---|
| 1852 | + coda_update_menu_ctrl(level_ctrl, level); |
---|
| 1853 | + } |
---|
| 1854 | +} |
---|
| 1855 | + |
---|
| 1856 | +static void coda_queue_source_change_event(struct coda_ctx *ctx) |
---|
| 1857 | +{ |
---|
| 1858 | + static const struct v4l2_event source_change_event = { |
---|
| 1859 | + .type = V4L2_EVENT_SOURCE_CHANGE, |
---|
| 1860 | + .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION, |
---|
| 1861 | + }; |
---|
| 1862 | + |
---|
| 1863 | + v4l2_event_queue_fh(&ctx->fh, &source_change_event); |
---|
1498 | 1864 | } |
---|
1499 | 1865 | |
---|
1500 | 1866 | static void coda_buf_queue(struct vb2_buffer *vb) |
---|
.. | .. |
---|
1527 | 1893 | */ |
---|
1528 | 1894 | if (!ctx->params.h264_profile_idc) { |
---|
1529 | 1895 | coda_sps_parse_profile(ctx, vb); |
---|
1530 | | - coda_update_h264_profile_ctrl(ctx); |
---|
1531 | | - coda_update_h264_level_ctrl(ctx); |
---|
| 1896 | + coda_update_profile_level_ctrls(ctx, |
---|
| 1897 | + ctx->params.h264_profile_idc, |
---|
| 1898 | + ctx->params.h264_level_idc); |
---|
1532 | 1899 | } |
---|
1533 | 1900 | } |
---|
1534 | 1901 | |
---|
.. | .. |
---|
1538 | 1905 | /* This set buf->sequence = ctx->qsequence++ */ |
---|
1539 | 1906 | coda_fill_bitstream(ctx, NULL); |
---|
1540 | 1907 | mutex_unlock(&ctx->bitstream_mutex); |
---|
| 1908 | + |
---|
| 1909 | + if (!ctx->initialized) { |
---|
| 1910 | + /* |
---|
| 1911 | + * Run sequence initialization in case the queued |
---|
| 1912 | + * buffer contained headers. |
---|
| 1913 | + */ |
---|
| 1914 | + if (vb2_is_streaming(vb->vb2_queue) && |
---|
| 1915 | + ctx->ops->seq_init_work) { |
---|
| 1916 | + queue_work(ctx->dev->workqueue, |
---|
| 1917 | + &ctx->seq_init_work); |
---|
| 1918 | + flush_work(&ctx->seq_init_work); |
---|
| 1919 | + } |
---|
| 1920 | + |
---|
| 1921 | + if (ctx->initialized) |
---|
| 1922 | + coda_queue_source_change_event(ctx); |
---|
| 1923 | + } |
---|
1541 | 1924 | } else { |
---|
1542 | | - if (ctx->inst_type == CODA_INST_ENCODER && |
---|
| 1925 | + if ((ctx->inst_type == CODA_INST_ENCODER || !ctx->use_bit) && |
---|
1543 | 1926 | vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) |
---|
1544 | 1927 | vbuf->sequence = ctx->qsequence++; |
---|
1545 | 1928 | v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf); |
---|
.. | .. |
---|
1549 | 1932 | int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf, |
---|
1550 | 1933 | size_t size, const char *name, struct dentry *parent) |
---|
1551 | 1934 | { |
---|
1552 | | - buf->vaddr = dma_alloc_coherent(&dev->plat_dev->dev, size, &buf->paddr, |
---|
| 1935 | + buf->vaddr = dma_alloc_coherent(dev->dev, size, &buf->paddr, |
---|
1553 | 1936 | GFP_KERNEL); |
---|
1554 | 1937 | if (!buf->vaddr) { |
---|
1555 | 1938 | v4l2_err(&dev->v4l2_dev, |
---|
.. | .. |
---|
1565 | 1948 | buf->blob.size = size; |
---|
1566 | 1949 | buf->dentry = debugfs_create_blob(name, 0644, parent, |
---|
1567 | 1950 | &buf->blob); |
---|
1568 | | - if (!buf->dentry) |
---|
1569 | | - dev_warn(&dev->plat_dev->dev, |
---|
1570 | | - "failed to create debugfs entry %s\n", name); |
---|
1571 | 1951 | } |
---|
1572 | 1952 | |
---|
1573 | 1953 | return 0; |
---|
.. | .. |
---|
1577 | 1957 | struct coda_aux_buf *buf) |
---|
1578 | 1958 | { |
---|
1579 | 1959 | if (buf->vaddr) { |
---|
1580 | | - dma_free_coherent(&dev->plat_dev->dev, buf->size, |
---|
1581 | | - buf->vaddr, buf->paddr); |
---|
| 1960 | + dma_free_coherent(dev->dev, buf->size, buf->vaddr, buf->paddr); |
---|
1582 | 1961 | buf->vaddr = NULL; |
---|
1583 | 1962 | buf->size = 0; |
---|
1584 | 1963 | debugfs_remove(buf->dentry); |
---|
.. | .. |
---|
1599 | 1978 | if (count < 1) |
---|
1600 | 1979 | return -EINVAL; |
---|
1601 | 1980 | |
---|
| 1981 | + coda_dbg(1, ctx, "start streaming %s\n", v4l2_type_names[q->type]); |
---|
| 1982 | + |
---|
1602 | 1983 | INIT_LIST_HEAD(&list); |
---|
1603 | 1984 | |
---|
1604 | 1985 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
---|
.. | .. |
---|
1609 | 1990 | coda_fill_bitstream(ctx, &list); |
---|
1610 | 1991 | mutex_unlock(&ctx->bitstream_mutex); |
---|
1611 | 1992 | |
---|
1612 | | - if (coda_get_bitstream_payload(ctx) < 512) { |
---|
| 1993 | + if (ctx->dev->devtype->product != CODA_960 && |
---|
| 1994 | + coda_get_bitstream_payload(ctx) < 512) { |
---|
| 1995 | + v4l2_err(v4l2_dev, "start payload < 512\n"); |
---|
1613 | 1996 | ret = -EINVAL; |
---|
1614 | 1997 | goto err; |
---|
1615 | 1998 | } |
---|
| 1999 | + |
---|
| 2000 | + if (!ctx->initialized) { |
---|
| 2001 | + /* Run sequence initialization */ |
---|
| 2002 | + if (ctx->ops->seq_init_work) { |
---|
| 2003 | + queue_work(ctx->dev->workqueue, |
---|
| 2004 | + &ctx->seq_init_work); |
---|
| 2005 | + flush_work(&ctx->seq_init_work); |
---|
| 2006 | + } |
---|
| 2007 | + } |
---|
1616 | 2008 | } |
---|
1617 | 2009 | |
---|
| 2010 | + /* |
---|
| 2011 | + * Check the first input JPEG buffer to determine chroma |
---|
| 2012 | + * subsampling. |
---|
| 2013 | + */ |
---|
| 2014 | + if (q_data_src->fourcc == V4L2_PIX_FMT_JPEG) { |
---|
| 2015 | + buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); |
---|
| 2016 | + ret = coda_jpeg_decode_header(ctx, &buf->vb2_buf); |
---|
| 2017 | + if (ret < 0) { |
---|
| 2018 | + v4l2_err(v4l2_dev, |
---|
| 2019 | + "failed to decode JPEG header: %d\n", |
---|
| 2020 | + ret); |
---|
| 2021 | + goto err; |
---|
| 2022 | + } |
---|
| 2023 | + |
---|
| 2024 | + q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
---|
| 2025 | + q_data_dst->width = round_up(q_data_src->width, 16); |
---|
| 2026 | + q_data_dst->height = round_up(q_data_src->height, 16); |
---|
| 2027 | + q_data_dst->bytesperline = q_data_dst->width; |
---|
| 2028 | + if (ctx->params.jpeg_chroma_subsampling == |
---|
| 2029 | + V4L2_JPEG_CHROMA_SUBSAMPLING_420) { |
---|
| 2030 | + q_data_dst->sizeimage = |
---|
| 2031 | + q_data_dst->bytesperline * |
---|
| 2032 | + q_data_dst->height * 3 / 2; |
---|
| 2033 | + if (q_data_dst->fourcc != V4L2_PIX_FMT_YUV420) |
---|
| 2034 | + q_data_dst->fourcc = V4L2_PIX_FMT_NV12; |
---|
| 2035 | + } else { |
---|
| 2036 | + q_data_dst->sizeimage = |
---|
| 2037 | + q_data_dst->bytesperline * |
---|
| 2038 | + q_data_dst->height * 2; |
---|
| 2039 | + q_data_dst->fourcc = V4L2_PIX_FMT_YUV422P; |
---|
| 2040 | + } |
---|
| 2041 | + q_data_dst->rect.left = 0; |
---|
| 2042 | + q_data_dst->rect.top = 0; |
---|
| 2043 | + q_data_dst->rect.width = q_data_src->width; |
---|
| 2044 | + q_data_dst->rect.height = q_data_src->height; |
---|
| 2045 | + } |
---|
1618 | 2046 | ctx->streamon_out = 1; |
---|
1619 | 2047 | } else { |
---|
1620 | 2048 | ctx->streamon_cap = 1; |
---|
.. | .. |
---|
1641 | 2069 | v4l2_m2m_set_src_buffered(ctx->fh.m2m_ctx, true); |
---|
1642 | 2070 | |
---|
1643 | 2071 | ctx->gopcounter = ctx->params.gop_size - 1; |
---|
1644 | | - |
---|
1645 | | - ctx->codec = coda_find_codec(ctx->dev, q_data_src->fourcc, |
---|
1646 | | - q_data_dst->fourcc); |
---|
1647 | | - if (!ctx->codec) { |
---|
1648 | | - v4l2_err(v4l2_dev, "couldn't tell instance type.\n"); |
---|
1649 | | - ret = -EINVAL; |
---|
1650 | | - goto err; |
---|
1651 | | - } |
---|
1652 | 2072 | |
---|
1653 | 2073 | if (q_data_dst->fourcc == V4L2_PIX_FMT_JPEG) |
---|
1654 | 2074 | ctx->params.gop_size = 1; |
---|
.. | .. |
---|
1691 | 2111 | struct coda_ctx *ctx = vb2_get_drv_priv(q); |
---|
1692 | 2112 | struct coda_dev *dev = ctx->dev; |
---|
1693 | 2113 | struct vb2_v4l2_buffer *buf; |
---|
1694 | | - unsigned long flags; |
---|
1695 | 2114 | bool stop; |
---|
1696 | 2115 | |
---|
1697 | 2116 | stop = ctx->streamon_out && ctx->streamon_cap; |
---|
1698 | 2117 | |
---|
| 2118 | + coda_dbg(1, ctx, "stop streaming %s\n", v4l2_type_names[q->type]); |
---|
| 2119 | + |
---|
1699 | 2120 | if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
---|
1700 | | - v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
---|
1701 | | - "%s: output\n", __func__); |
---|
1702 | 2121 | ctx->streamon_out = 0; |
---|
1703 | 2122 | |
---|
1704 | 2123 | coda_bit_stream_end_flag(ctx); |
---|
.. | .. |
---|
1708 | 2127 | while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx))) |
---|
1709 | 2128 | v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR); |
---|
1710 | 2129 | } else { |
---|
1711 | | - v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
---|
1712 | | - "%s: capture\n", __func__); |
---|
1713 | 2130 | ctx->streamon_cap = 0; |
---|
1714 | 2131 | |
---|
1715 | 2132 | ctx->osequence = 0; |
---|
.. | .. |
---|
1726 | 2143 | queue_work(dev->workqueue, &ctx->seq_end_work); |
---|
1727 | 2144 | flush_work(&ctx->seq_end_work); |
---|
1728 | 2145 | } |
---|
1729 | | - spin_lock_irqsave(&ctx->buffer_meta_lock, flags); |
---|
| 2146 | + spin_lock(&ctx->buffer_meta_lock); |
---|
1730 | 2147 | while (!list_empty(&ctx->buffer_meta_list)) { |
---|
1731 | 2148 | meta = list_first_entry(&ctx->buffer_meta_list, |
---|
1732 | 2149 | struct coda_buffer_meta, list); |
---|
.. | .. |
---|
1734 | 2151 | kfree(meta); |
---|
1735 | 2152 | } |
---|
1736 | 2153 | ctx->num_metas = 0; |
---|
1737 | | - spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags); |
---|
| 2154 | + spin_unlock(&ctx->buffer_meta_lock); |
---|
1738 | 2155 | kfifo_init(&ctx->bitstream_fifo, |
---|
1739 | 2156 | ctx->bitstream.vaddr, ctx->bitstream.size); |
---|
1740 | 2157 | ctx->runcounter = 0; |
---|
.. | .. |
---|
1758 | 2175 | |
---|
1759 | 2176 | static int coda_s_ctrl(struct v4l2_ctrl *ctrl) |
---|
1760 | 2177 | { |
---|
| 2178 | + const char * const *val_names = v4l2_ctrl_get_menu(ctrl->id); |
---|
1761 | 2179 | struct coda_ctx *ctx = |
---|
1762 | 2180 | container_of(ctrl->handler, struct coda_ctx, ctrls); |
---|
1763 | 2181 | |
---|
1764 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1765 | | - "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val); |
---|
| 2182 | + if (val_names) |
---|
| 2183 | + coda_dbg(2, ctx, "s_ctrl: id = 0x%x, name = \"%s\", val = %d (\"%s\")\n", |
---|
| 2184 | + ctrl->id, ctrl->name, ctrl->val, val_names[ctrl->val]); |
---|
| 2185 | + else |
---|
| 2186 | + coda_dbg(2, ctx, "s_ctrl: id = 0x%x, name = \"%s\", val = %d\n", |
---|
| 2187 | + ctrl->id, ctrl->name, ctrl->val); |
---|
1766 | 2188 | |
---|
1767 | 2189 | switch (ctrl->id) { |
---|
1768 | 2190 | case V4L2_CID_HFLIP: |
---|
.. | .. |
---|
1779 | 2201 | break; |
---|
1780 | 2202 | case V4L2_CID_MPEG_VIDEO_BITRATE: |
---|
1781 | 2203 | ctx->params.bitrate = ctrl->val / 1000; |
---|
| 2204 | + ctx->params.bitrate_changed = true; |
---|
1782 | 2205 | break; |
---|
1783 | 2206 | case V4L2_CID_MPEG_VIDEO_GOP_SIZE: |
---|
1784 | 2207 | ctx->params.gop_size = ctrl->val; |
---|
1785 | 2208 | break; |
---|
1786 | 2209 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: |
---|
1787 | 2210 | ctx->params.h264_intra_qp = ctrl->val; |
---|
| 2211 | + ctx->params.h264_intra_qp_changed = true; |
---|
1788 | 2212 | break; |
---|
1789 | 2213 | case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: |
---|
1790 | 2214 | ctx->params.h264_inter_qp = ctrl->val; |
---|
.. | .. |
---|
1804 | 2228 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: |
---|
1805 | 2229 | ctx->params.h264_disable_deblocking_filter_idc = ctrl->val; |
---|
1806 | 2230 | break; |
---|
| 2231 | + case V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION: |
---|
| 2232 | + ctx->params.h264_constrained_intra_pred_flag = ctrl->val; |
---|
| 2233 | + break; |
---|
| 2234 | + case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE: |
---|
| 2235 | + ctx->params.frame_rc_enable = ctrl->val; |
---|
| 2236 | + break; |
---|
| 2237 | + case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE: |
---|
| 2238 | + ctx->params.mb_rc_enable = ctrl->val; |
---|
| 2239 | + break; |
---|
| 2240 | + case V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET: |
---|
| 2241 | + ctx->params.h264_chroma_qp_index_offset = ctrl->val; |
---|
| 2242 | + break; |
---|
1807 | 2243 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: |
---|
1808 | 2244 | /* TODO: switch between baseline and constrained baseline */ |
---|
1809 | 2245 | if (ctx->inst_type == CODA_INST_ENCODER) |
---|
.. | .. |
---|
1818 | 2254 | case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: |
---|
1819 | 2255 | ctx->params.mpeg4_inter_qp = ctrl->val; |
---|
1820 | 2256 | break; |
---|
| 2257 | + case V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE: |
---|
| 2258 | + case V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL: |
---|
1821 | 2259 | case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE: |
---|
1822 | 2260 | case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: |
---|
1823 | 2261 | /* nothing to do, these are fixed */ |
---|
1824 | 2262 | break; |
---|
1825 | 2263 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: |
---|
1826 | 2264 | ctx->params.slice_mode = ctrl->val; |
---|
| 2265 | + ctx->params.slice_mode_changed = true; |
---|
1827 | 2266 | break; |
---|
1828 | 2267 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: |
---|
1829 | 2268 | ctx->params.slice_max_mb = ctrl->val; |
---|
| 2269 | + ctx->params.slice_mode_changed = true; |
---|
1830 | 2270 | break; |
---|
1831 | 2271 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: |
---|
1832 | 2272 | ctx->params.slice_max_bits = ctrl->val * 8; |
---|
| 2273 | + ctx->params.slice_mode_changed = true; |
---|
1833 | 2274 | break; |
---|
1834 | 2275 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: |
---|
1835 | 2276 | break; |
---|
1836 | 2277 | case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: |
---|
1837 | 2278 | ctx->params.intra_refresh = ctrl->val; |
---|
| 2279 | + ctx->params.intra_refresh_changed = true; |
---|
1838 | 2280 | break; |
---|
1839 | 2281 | case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: |
---|
1840 | 2282 | ctx->params.force_ipicture = true; |
---|
.. | .. |
---|
1852 | 2294 | ctx->params.vbv_size = min(ctrl->val * 8192, 0x7fffffff); |
---|
1853 | 2295 | break; |
---|
1854 | 2296 | default: |
---|
1855 | | - v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
---|
1856 | | - "Invalid control, id=%d, val=%d\n", |
---|
1857 | | - ctrl->id, ctrl->val); |
---|
| 2297 | + coda_dbg(1, ctx, "Invalid control, id=%d, val=%d\n", |
---|
| 2298 | + ctrl->id, ctrl->val); |
---|
1858 | 2299 | return -EINVAL; |
---|
1859 | 2300 | } |
---|
1860 | 2301 | |
---|
.. | .. |
---|
1891 | 2332 | V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE, |
---|
1892 | 2333 | V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY, |
---|
1893 | 2334 | 0x0, V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED); |
---|
| 2335 | + v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
---|
| 2336 | + V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION, 0, 1, 1, |
---|
| 2337 | + 0); |
---|
| 2338 | + v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
---|
| 2339 | + V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE, 0, 1, 1, 1); |
---|
| 2340 | + v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
---|
| 2341 | + V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE, 0, 1, 1, 1); |
---|
| 2342 | + v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
---|
| 2343 | + V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET, -12, 12, 1, 0); |
---|
1894 | 2344 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
---|
1895 | 2345 | V4L2_CID_MPEG_VIDEO_H264_PROFILE, |
---|
1896 | | - V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE, 0x0, |
---|
1897 | | - V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE); |
---|
| 2346 | + V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE, 0x0, |
---|
| 2347 | + V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE); |
---|
1898 | 2348 | if (ctx->dev->devtype->product == CODA_HX4 || |
---|
1899 | 2349 | ctx->dev->devtype->product == CODA_7541) { |
---|
1900 | 2350 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
---|
.. | .. |
---|
1908 | 2358 | if (ctx->dev->devtype->product == CODA_960) { |
---|
1909 | 2359 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
---|
1910 | 2360 | V4L2_CID_MPEG_VIDEO_H264_LEVEL, |
---|
1911 | | - V4L2_MPEG_VIDEO_H264_LEVEL_4_0, |
---|
1912 | | - ~((1 << V4L2_MPEG_VIDEO_H264_LEVEL_2_0) | |
---|
| 2361 | + V4L2_MPEG_VIDEO_H264_LEVEL_4_2, |
---|
| 2362 | + ~((1 << V4L2_MPEG_VIDEO_H264_LEVEL_1_0) | |
---|
| 2363 | + (1 << V4L2_MPEG_VIDEO_H264_LEVEL_2_0) | |
---|
1913 | 2364 | (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_0) | |
---|
1914 | 2365 | (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_1) | |
---|
1915 | 2366 | (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_2) | |
---|
1916 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_0)), |
---|
| 2367 | + (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_0) | |
---|
| 2368 | + (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_1) | |
---|
| 2369 | + (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_2)), |
---|
1917 | 2370 | V4L2_MPEG_VIDEO_H264_LEVEL_4_0); |
---|
1918 | 2371 | } |
---|
1919 | 2372 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
---|
.. | .. |
---|
1935 | 2388 | } |
---|
1936 | 2389 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
---|
1937 | 2390 | V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE, |
---|
1938 | | - V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES, 0x0, |
---|
| 2391 | + V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES, 0x0, |
---|
1939 | 2392 | V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE); |
---|
1940 | 2393 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
---|
1941 | 2394 | V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB, 1, 0x3fffffff, 1, 1); |
---|
.. | .. |
---|
1970 | 2423 | |
---|
1971 | 2424 | static void coda_decode_ctrls(struct coda_ctx *ctx) |
---|
1972 | 2425 | { |
---|
1973 | | - u64 mask; |
---|
1974 | 2426 | u8 max; |
---|
1975 | 2427 | |
---|
1976 | 2428 | ctx->h264_profile_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls, |
---|
1977 | 2429 | &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_H264_PROFILE, |
---|
1978 | 2430 | V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, |
---|
1979 | | - ~((1 << V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) | |
---|
| 2431 | + ~((1 << V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) | |
---|
1980 | 2432 | (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) | |
---|
1981 | 2433 | (1 << V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)), |
---|
1982 | 2434 | V4L2_MPEG_VIDEO_H264_PROFILE_HIGH); |
---|
.. | .. |
---|
1984 | 2436 | ctx->h264_profile_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
---|
1985 | 2437 | |
---|
1986 | 2438 | if (ctx->dev->devtype->product == CODA_HX4 || |
---|
1987 | | - ctx->dev->devtype->product == CODA_7541) { |
---|
| 2439 | + ctx->dev->devtype->product == CODA_7541) |
---|
1988 | 2440 | max = V4L2_MPEG_VIDEO_H264_LEVEL_4_0; |
---|
1989 | | - mask = ~((1 << V4L2_MPEG_VIDEO_H264_LEVEL_2_0) | |
---|
1990 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_0) | |
---|
1991 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_1) | |
---|
1992 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_2) | |
---|
1993 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_0)); |
---|
1994 | | - } else if (ctx->dev->devtype->product == CODA_960) { |
---|
| 2441 | + else if (ctx->dev->devtype->product == CODA_960) |
---|
1995 | 2442 | max = V4L2_MPEG_VIDEO_H264_LEVEL_4_1; |
---|
1996 | | - mask = ~((1 << V4L2_MPEG_VIDEO_H264_LEVEL_2_0) | |
---|
1997 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_0) | |
---|
1998 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_1) | |
---|
1999 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_2) | |
---|
2000 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_0) | |
---|
2001 | | - (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_1)); |
---|
2002 | | - } else { |
---|
| 2443 | + else |
---|
2003 | 2444 | return; |
---|
2004 | | - } |
---|
2005 | 2445 | ctx->h264_level_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls, |
---|
2006 | | - &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_H264_LEVEL, max, mask, |
---|
2007 | | - max); |
---|
| 2446 | + &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_H264_LEVEL, max, 0, max); |
---|
2008 | 2447 | if (ctx->h264_level_ctrl) |
---|
2009 | 2448 | ctx->h264_level_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
---|
| 2449 | + |
---|
| 2450 | + ctx->mpeg2_profile_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls, |
---|
| 2451 | + &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE, |
---|
| 2452 | + V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH, 0, |
---|
| 2453 | + V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH); |
---|
| 2454 | + if (ctx->mpeg2_profile_ctrl) |
---|
| 2455 | + ctx->mpeg2_profile_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
---|
| 2456 | + |
---|
| 2457 | + ctx->mpeg2_level_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls, |
---|
| 2458 | + &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL, |
---|
| 2459 | + V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH, 0, |
---|
| 2460 | + V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH); |
---|
| 2461 | + if (ctx->mpeg2_level_ctrl) |
---|
| 2462 | + ctx->mpeg2_level_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
---|
| 2463 | + |
---|
| 2464 | + ctx->mpeg4_profile_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls, |
---|
| 2465 | + &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE, |
---|
| 2466 | + V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY, 0, |
---|
| 2467 | + V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY); |
---|
| 2468 | + if (ctx->mpeg4_profile_ctrl) |
---|
| 2469 | + ctx->mpeg4_profile_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
---|
| 2470 | + |
---|
| 2471 | + ctx->mpeg4_level_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls, |
---|
| 2472 | + &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL, |
---|
| 2473 | + V4L2_MPEG_VIDEO_MPEG4_LEVEL_5, 0, |
---|
| 2474 | + V4L2_MPEG_VIDEO_MPEG4_LEVEL_5); |
---|
| 2475 | + if (ctx->mpeg4_level_ctrl) |
---|
| 2476 | + ctx->mpeg4_level_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
---|
2010 | 2477 | } |
---|
2011 | 2478 | |
---|
2012 | 2479 | static int coda_ctrls_setup(struct coda_ctx *ctx) |
---|
.. | .. |
---|
2018 | 2485 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
---|
2019 | 2486 | V4L2_CID_VFLIP, 0, 1, 1, 0); |
---|
2020 | 2487 | if (ctx->inst_type == CODA_INST_ENCODER) { |
---|
| 2488 | + v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
---|
| 2489 | + V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, |
---|
| 2490 | + 1, 1, 1, 1); |
---|
2021 | 2491 | if (ctx->cvd->dst_formats[0] == V4L2_PIX_FMT_JPEG) |
---|
2022 | 2492 | coda_jpeg_encode_ctrls(ctx); |
---|
2023 | 2493 | else |
---|
2024 | 2494 | coda_encode_ctrls(ctx); |
---|
2025 | 2495 | } else { |
---|
| 2496 | + v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
---|
| 2497 | + V4L2_CID_MIN_BUFFERS_FOR_CAPTURE, |
---|
| 2498 | + 1, 1, 1, 1); |
---|
2026 | 2499 | if (ctx->cvd->src_formats[0] == V4L2_PIX_FMT_H264) |
---|
2027 | 2500 | coda_decode_ctrls(ctx); |
---|
2028 | 2501 | } |
---|
.. | .. |
---|
2057 | 2530 | * queues to have at least one buffer queued. |
---|
2058 | 2531 | */ |
---|
2059 | 2532 | vq->min_buffers_needed = 1; |
---|
2060 | | - vq->dev = &ctx->dev->plat_dev->dev; |
---|
| 2533 | + vq->dev = ctx->dev->dev; |
---|
2061 | 2534 | |
---|
2062 | 2535 | return vb2_queue_init(vq); |
---|
2063 | 2536 | } |
---|
.. | .. |
---|
2097 | 2570 | |
---|
2098 | 2571 | dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
---|
2099 | 2572 | dst_vq->io_modes = VB2_DMABUF | VB2_MMAP; |
---|
| 2573 | + dst_vq->dma_attrs = DMA_ATTR_NO_KERNEL_MAPPING; |
---|
2100 | 2574 | dst_vq->mem_ops = &vb2_dma_contig_memops; |
---|
2101 | 2575 | |
---|
2102 | 2576 | return coda_queue_init(priv, dst_vq); |
---|
.. | .. |
---|
2143 | 2617 | ctx->use_bit = !ctx->cvd->direct; |
---|
2144 | 2618 | init_completion(&ctx->completion); |
---|
2145 | 2619 | INIT_WORK(&ctx->pic_run_work, coda_pic_run_work); |
---|
| 2620 | + if (ctx->ops->seq_init_work) |
---|
| 2621 | + INIT_WORK(&ctx->seq_init_work, ctx->ops->seq_init_work); |
---|
2146 | 2622 | if (ctx->ops->seq_end_work) |
---|
2147 | 2623 | INIT_WORK(&ctx->seq_end_work, ctx->ops->seq_end_work); |
---|
2148 | 2624 | v4l2_fh_init(&ctx->fh, video_devdata(file)); |
---|
.. | .. |
---|
2150 | 2626 | v4l2_fh_add(&ctx->fh); |
---|
2151 | 2627 | ctx->dev = dev; |
---|
2152 | 2628 | ctx->idx = idx; |
---|
| 2629 | + |
---|
| 2630 | + coda_dbg(1, ctx, "open instance (%p)\n", ctx); |
---|
| 2631 | + |
---|
2153 | 2632 | switch (dev->devtype->product) { |
---|
2154 | 2633 | case CODA_960: |
---|
2155 | 2634 | /* |
---|
.. | .. |
---|
2160 | 2639 | */ |
---|
2161 | 2640 | if (enable_bwb || ctx->inst_type == CODA_INST_ENCODER) |
---|
2162 | 2641 | ctx->frame_mem_ctrl = CODA9_FRAME_ENABLE_BWB; |
---|
2163 | | - /* fallthrough */ |
---|
| 2642 | + fallthrough; |
---|
2164 | 2643 | case CODA_HX4: |
---|
2165 | 2644 | case CODA_7541: |
---|
2166 | 2645 | ctx->reg_idx = 0; |
---|
.. | .. |
---|
2177 | 2656 | ctx->use_vdoa = false; |
---|
2178 | 2657 | |
---|
2179 | 2658 | /* Power up and upload firmware if necessary */ |
---|
2180 | | - ret = pm_runtime_get_sync(&dev->plat_dev->dev); |
---|
| 2659 | + ret = pm_runtime_get_sync(dev->dev); |
---|
2181 | 2660 | if (ret < 0) { |
---|
2182 | 2661 | v4l2_err(&dev->v4l2_dev, "failed to power up: %d\n", ret); |
---|
2183 | 2662 | goto err_pm_get; |
---|
.. | .. |
---|
2185 | 2664 | |
---|
2186 | 2665 | ret = clk_prepare_enable(dev->clk_per); |
---|
2187 | 2666 | if (ret) |
---|
2188 | | - goto err_clk_per; |
---|
| 2667 | + goto err_pm_get; |
---|
2189 | 2668 | |
---|
2190 | 2669 | ret = clk_prepare_enable(dev->clk_ahb); |
---|
2191 | 2670 | if (ret) |
---|
.. | .. |
---|
2212 | 2691 | |
---|
2213 | 2692 | mutex_init(&ctx->bitstream_mutex); |
---|
2214 | 2693 | mutex_init(&ctx->buffer_mutex); |
---|
| 2694 | + mutex_init(&ctx->wakeup_mutex); |
---|
2215 | 2695 | INIT_LIST_HEAD(&ctx->buffer_meta_list); |
---|
2216 | 2696 | spin_lock_init(&ctx->buffer_meta_lock); |
---|
2217 | | - |
---|
2218 | | - mutex_lock(&dev->dev_mutex); |
---|
2219 | | - list_add(&ctx->list, &dev->instances); |
---|
2220 | | - mutex_unlock(&dev->dev_mutex); |
---|
2221 | | - |
---|
2222 | | - v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Created instance %d (%p)\n", |
---|
2223 | | - ctx->idx, ctx); |
---|
2224 | 2697 | |
---|
2225 | 2698 | return 0; |
---|
2226 | 2699 | |
---|
.. | .. |
---|
2230 | 2703 | clk_disable_unprepare(dev->clk_ahb); |
---|
2231 | 2704 | err_clk_ahb: |
---|
2232 | 2705 | clk_disable_unprepare(dev->clk_per); |
---|
2233 | | -err_clk_per: |
---|
2234 | | - pm_runtime_put_sync(&dev->plat_dev->dev); |
---|
2235 | 2706 | err_pm_get: |
---|
| 2707 | + pm_runtime_put_sync(dev->dev); |
---|
2236 | 2708 | v4l2_fh_del(&ctx->fh); |
---|
2237 | 2709 | v4l2_fh_exit(&ctx->fh); |
---|
2238 | 2710 | err_coda_name_init: |
---|
.. | .. |
---|
2247 | 2719 | struct coda_dev *dev = video_drvdata(file); |
---|
2248 | 2720 | struct coda_ctx *ctx = fh_to_ctx(file->private_data); |
---|
2249 | 2721 | |
---|
2250 | | - v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n", |
---|
2251 | | - ctx); |
---|
| 2722 | + coda_dbg(1, ctx, "release instance (%p)\n", ctx); |
---|
2252 | 2723 | |
---|
2253 | 2724 | if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit) |
---|
2254 | 2725 | coda_bit_stream_end_flag(ctx); |
---|
.. | .. |
---|
2265 | 2736 | flush_work(&ctx->seq_end_work); |
---|
2266 | 2737 | } |
---|
2267 | 2738 | |
---|
2268 | | - mutex_lock(&dev->dev_mutex); |
---|
2269 | | - list_del(&ctx->list); |
---|
2270 | | - mutex_unlock(&dev->dev_mutex); |
---|
2271 | | - |
---|
2272 | 2739 | if (ctx->dev->devtype->product == CODA_DX6) |
---|
2273 | 2740 | coda_free_aux_buf(dev, &ctx->workbuf); |
---|
2274 | 2741 | |
---|
2275 | 2742 | v4l2_ctrl_handler_free(&ctx->ctrls); |
---|
2276 | 2743 | clk_disable_unprepare(dev->clk_ahb); |
---|
2277 | 2744 | clk_disable_unprepare(dev->clk_per); |
---|
2278 | | - pm_runtime_put_sync(&dev->plat_dev->dev); |
---|
| 2745 | + pm_runtime_put_sync(dev->dev); |
---|
2279 | 2746 | v4l2_fh_del(&ctx->fh); |
---|
2280 | 2747 | v4l2_fh_exit(&ctx->fh); |
---|
2281 | 2748 | ida_free(&dev->ida, ctx->idx); |
---|
.. | .. |
---|
2398 | 2865 | static int coda_register_device(struct coda_dev *dev, int i) |
---|
2399 | 2866 | { |
---|
2400 | 2867 | struct video_device *vfd = &dev->vfd[i]; |
---|
| 2868 | + enum coda_inst_type type; |
---|
| 2869 | + int ret; |
---|
2401 | 2870 | |
---|
2402 | 2871 | if (i >= dev->devtype->num_vdevs) |
---|
2403 | 2872 | return -EINVAL; |
---|
| 2873 | + type = dev->devtype->vdevs[i]->type; |
---|
2404 | 2874 | |
---|
2405 | | - strlcpy(vfd->name, dev->devtype->vdevs[i]->name, sizeof(vfd->name)); |
---|
| 2875 | + strscpy(vfd->name, dev->devtype->vdevs[i]->name, sizeof(vfd->name)); |
---|
2406 | 2876 | vfd->fops = &coda_fops; |
---|
2407 | 2877 | vfd->ioctl_ops = &coda_ioctl_ops; |
---|
2408 | 2878 | vfd->release = video_device_release_empty, |
---|
2409 | 2879 | vfd->lock = &dev->dev_mutex; |
---|
2410 | 2880 | vfd->v4l2_dev = &dev->v4l2_dev; |
---|
2411 | 2881 | vfd->vfl_dir = VFL_DIR_M2M; |
---|
| 2882 | + vfd->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING; |
---|
2412 | 2883 | video_set_drvdata(vfd, dev); |
---|
2413 | 2884 | |
---|
2414 | 2885 | /* Not applicable, use the selection API instead */ |
---|
.. | .. |
---|
2416 | 2887 | v4l2_disable_ioctl(vfd, VIDIOC_G_CROP); |
---|
2417 | 2888 | v4l2_disable_ioctl(vfd, VIDIOC_S_CROP); |
---|
2418 | 2889 | |
---|
2419 | | - return video_register_device(vfd, VFL_TYPE_GRABBER, 0); |
---|
| 2890 | + ret = video_register_device(vfd, VFL_TYPE_VIDEO, 0); |
---|
| 2891 | + if (!ret) |
---|
| 2892 | + v4l2_info(&dev->v4l2_dev, "%s registered as %s\n", |
---|
| 2893 | + type == CODA_INST_ENCODER ? "encoder" : "decoder", |
---|
| 2894 | + video_device_node_name(vfd)); |
---|
| 2895 | + return ret; |
---|
2420 | 2896 | } |
---|
2421 | 2897 | |
---|
2422 | 2898 | static void coda_copy_firmware(struct coda_dev *dev, const u8 * const buf, |
---|
.. | .. |
---|
2462 | 2938 | |
---|
2463 | 2939 | fw = dev->devtype->firmware[dev->firmware]; |
---|
2464 | 2940 | |
---|
2465 | | - dev_dbg(&dev->plat_dev->dev, "requesting firmware '%s' for %s\n", fw, |
---|
| 2941 | + dev_dbg(dev->dev, "requesting firmware '%s' for %s\n", fw, |
---|
2466 | 2942 | coda_product_name(dev->devtype->product)); |
---|
2467 | 2943 | |
---|
2468 | | - return request_firmware_nowait(THIS_MODULE, true, fw, |
---|
2469 | | - &dev->plat_dev->dev, GFP_KERNEL, dev, |
---|
2470 | | - coda_fw_callback); |
---|
| 2944 | + return request_firmware_nowait(THIS_MODULE, true, fw, dev->dev, |
---|
| 2945 | + GFP_KERNEL, dev, coda_fw_callback); |
---|
2471 | 2946 | } |
---|
2472 | 2947 | |
---|
2473 | 2948 | static void coda_fw_callback(const struct firmware *fw, void *context) |
---|
2474 | 2949 | { |
---|
2475 | 2950 | struct coda_dev *dev = context; |
---|
2476 | | - struct platform_device *pdev = dev->plat_dev; |
---|
2477 | 2951 | int i, ret; |
---|
2478 | 2952 | |
---|
2479 | 2953 | if (!fw) { |
---|
.. | .. |
---|
2491 | 2965 | * firmware requests, report that the fallback firmware was |
---|
2492 | 2966 | * found. |
---|
2493 | 2967 | */ |
---|
2494 | | - dev_info(&pdev->dev, "Using fallback firmware %s\n", |
---|
| 2968 | + dev_info(dev->dev, "Using fallback firmware %s\n", |
---|
2495 | 2969 | dev->devtype->firmware[dev->firmware]); |
---|
2496 | 2970 | } |
---|
2497 | 2971 | |
---|
.. | .. |
---|
2530 | 3004 | } |
---|
2531 | 3005 | } |
---|
2532 | 3006 | |
---|
2533 | | - v4l2_info(&dev->v4l2_dev, "codec registered as /dev/video[%d-%d]\n", |
---|
2534 | | - dev->vfd[0].num, dev->vfd[i - 1].num); |
---|
2535 | | - |
---|
2536 | | - pm_runtime_put_sync(&pdev->dev); |
---|
| 3007 | + pm_runtime_put_sync(dev->dev); |
---|
2537 | 3008 | return; |
---|
2538 | 3009 | |
---|
2539 | 3010 | rel_vfd: |
---|
.. | .. |
---|
2541 | 3012 | video_unregister_device(&dev->vfd[i]); |
---|
2542 | 3013 | v4l2_m2m_release(dev->m2m_dev); |
---|
2543 | 3014 | put_pm: |
---|
2544 | | - pm_runtime_put_sync(&pdev->dev); |
---|
| 3015 | + pm_runtime_put_sync(dev->dev); |
---|
2545 | 3016 | } |
---|
2546 | 3017 | |
---|
2547 | 3018 | enum coda_platform { |
---|
.. | .. |
---|
2656 | 3127 | struct device_node *np = pdev->dev.of_node; |
---|
2657 | 3128 | struct gen_pool *pool; |
---|
2658 | 3129 | struct coda_dev *dev; |
---|
2659 | | - struct resource *res; |
---|
2660 | 3130 | int ret, irq; |
---|
2661 | 3131 | |
---|
2662 | 3132 | dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); |
---|
.. | .. |
---|
2672 | 3142 | else |
---|
2673 | 3143 | return -EINVAL; |
---|
2674 | 3144 | |
---|
2675 | | - spin_lock_init(&dev->irqlock); |
---|
2676 | | - INIT_LIST_HEAD(&dev->instances); |
---|
2677 | | - |
---|
2678 | | - dev->plat_dev = pdev; |
---|
| 3145 | + dev->dev = &pdev->dev; |
---|
2679 | 3146 | dev->clk_per = devm_clk_get(&pdev->dev, "per"); |
---|
2680 | 3147 | if (IS_ERR(dev->clk_per)) { |
---|
2681 | 3148 | dev_err(&pdev->dev, "Could not get per clock\n"); |
---|
.. | .. |
---|
2689 | 3156 | } |
---|
2690 | 3157 | |
---|
2691 | 3158 | /* Get memory for physical registers */ |
---|
2692 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
2693 | | - dev->regs_base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 3159 | + dev->regs_base = devm_platform_ioremap_resource(pdev, 0); |
---|
2694 | 3160 | if (IS_ERR(dev->regs_base)) |
---|
2695 | 3161 | return PTR_ERR(dev->regs_base); |
---|
2696 | 3162 | |
---|
.. | .. |
---|
2698 | 3164 | irq = platform_get_irq_byname(pdev, "bit"); |
---|
2699 | 3165 | if (irq < 0) |
---|
2700 | 3166 | irq = platform_get_irq(pdev, 0); |
---|
2701 | | - if (irq < 0) { |
---|
2702 | | - dev_err(&pdev->dev, "failed to get irq resource\n"); |
---|
| 3167 | + if (irq < 0) |
---|
2703 | 3168 | return irq; |
---|
2704 | | - } |
---|
2705 | 3169 | |
---|
2706 | | - ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, coda_irq_handler, |
---|
2707 | | - IRQF_ONESHOT, dev_name(&pdev->dev), dev); |
---|
| 3170 | + ret = devm_request_irq(&pdev->dev, irq, coda_irq_handler, 0, |
---|
| 3171 | + dev_name(&pdev->dev), dev); |
---|
2708 | 3172 | if (ret < 0) { |
---|
2709 | 3173 | dev_err(&pdev->dev, "failed to request irq: %d\n", ret); |
---|
2710 | 3174 | return ret; |
---|
| 3175 | + } |
---|
| 3176 | + |
---|
| 3177 | + /* JPEG IRQ */ |
---|
| 3178 | + if (dev->devtype->product == CODA_960) { |
---|
| 3179 | + irq = platform_get_irq_byname(pdev, "jpeg"); |
---|
| 3180 | + if (irq < 0) |
---|
| 3181 | + return irq; |
---|
| 3182 | + |
---|
| 3183 | + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, |
---|
| 3184 | + coda9_jpeg_irq_handler, |
---|
| 3185 | + IRQF_ONESHOT, CODA_NAME " jpeg", |
---|
| 3186 | + dev); |
---|
| 3187 | + if (ret < 0) { |
---|
| 3188 | + dev_err(&pdev->dev, "failed to request jpeg irq\n"); |
---|
| 3189 | + return ret; |
---|
| 3190 | + } |
---|
2711 | 3191 | } |
---|
2712 | 3192 | |
---|
2713 | 3193 | dev->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, |
---|
.. | .. |
---|
2742 | 3222 | ida_init(&dev->ida); |
---|
2743 | 3223 | |
---|
2744 | 3224 | dev->debugfs_root = debugfs_create_dir("coda", NULL); |
---|
2745 | | - if (!dev->debugfs_root) |
---|
2746 | | - dev_warn(&pdev->dev, "failed to create debugfs root\n"); |
---|
2747 | 3225 | |
---|
2748 | 3226 | /* allocate auxiliary per-device buffers for the BIT processor */ |
---|
2749 | 3227 | if (dev->devtype->product == CODA_DX6) { |
---|
.. | .. |
---|
2800 | 3278 | return 0; |
---|
2801 | 3279 | |
---|
2802 | 3280 | err_alloc_workqueue: |
---|
| 3281 | + pm_runtime_disable(&pdev->dev); |
---|
| 3282 | + pm_runtime_put_noidle(&pdev->dev); |
---|
2803 | 3283 | destroy_workqueue(dev->workqueue); |
---|
2804 | 3284 | err_v4l2_register: |
---|
2805 | 3285 | v4l2_device_unregister(&dev->v4l2_dev); |
---|