| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * linux/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2011 Samsung Electronics Co., Ltd. |
|---|
| 5 | 6 | * http://www.samsung.com/ |
|---|
| 6 | 7 | * Kamil Debski, <k.debski@samsung.com> |
|---|
| 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> |
|---|
| .. | .. |
|---|
| 33 | 29 | |
|---|
| 34 | 30 | static struct s5p_mfc_fmt formats[] = { |
|---|
| 35 | 31 | { |
|---|
| 36 | | - .name = "4:2:0 2 Planes 16x16 Tiles", |
|---|
| 37 | 32 | .fourcc = V4L2_PIX_FMT_NV12MT_16X16, |
|---|
| 38 | 33 | .codec_mode = S5P_MFC_CODEC_NONE, |
|---|
| 39 | 34 | .type = MFC_FMT_RAW, |
|---|
| .. | .. |
|---|
| 41 | 36 | .versions = MFC_V6_BIT | MFC_V7_BIT, |
|---|
| 42 | 37 | }, |
|---|
| 43 | 38 | { |
|---|
| 44 | | - .name = "4:2:0 2 Planes 64x32 Tiles", |
|---|
| 45 | 39 | .fourcc = V4L2_PIX_FMT_NV12MT, |
|---|
| 46 | 40 | .codec_mode = S5P_MFC_CODEC_NONE, |
|---|
| 47 | 41 | .type = MFC_FMT_RAW, |
|---|
| .. | .. |
|---|
| 49 | 43 | .versions = MFC_V5_BIT, |
|---|
| 50 | 44 | }, |
|---|
| 51 | 45 | { |
|---|
| 52 | | - .name = "4:2:0 2 Planes Y/CbCr", |
|---|
| 53 | 46 | .fourcc = V4L2_PIX_FMT_NV12M, |
|---|
| 54 | 47 | .codec_mode = S5P_MFC_CODEC_NONE, |
|---|
| 55 | 48 | .type = MFC_FMT_RAW, |
|---|
| .. | .. |
|---|
| 57 | 50 | .versions = MFC_V6PLUS_BITS, |
|---|
| 58 | 51 | }, |
|---|
| 59 | 52 | { |
|---|
| 60 | | - .name = "4:2:0 2 Planes Y/CrCb", |
|---|
| 61 | 53 | .fourcc = V4L2_PIX_FMT_NV21M, |
|---|
| 62 | 54 | .codec_mode = S5P_MFC_CODEC_NONE, |
|---|
| 63 | 55 | .type = MFC_FMT_RAW, |
|---|
| .. | .. |
|---|
| 65 | 57 | .versions = MFC_V6PLUS_BITS, |
|---|
| 66 | 58 | }, |
|---|
| 67 | 59 | { |
|---|
| 68 | | - .name = "H264 Encoded Stream", |
|---|
| 69 | 60 | .fourcc = V4L2_PIX_FMT_H264, |
|---|
| 70 | 61 | .codec_mode = S5P_MFC_CODEC_H264_DEC, |
|---|
| 71 | 62 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 73 | 64 | .versions = MFC_V5PLUS_BITS, |
|---|
| 74 | 65 | }, |
|---|
| 75 | 66 | { |
|---|
| 76 | | - .name = "H264/MVC Encoded Stream", |
|---|
| 77 | 67 | .fourcc = V4L2_PIX_FMT_H264_MVC, |
|---|
| 78 | 68 | .codec_mode = S5P_MFC_CODEC_H264_MVC_DEC, |
|---|
| 79 | 69 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 81 | 71 | .versions = MFC_V6PLUS_BITS, |
|---|
| 82 | 72 | }, |
|---|
| 83 | 73 | { |
|---|
| 84 | | - .name = "H263 Encoded Stream", |
|---|
| 85 | 74 | .fourcc = V4L2_PIX_FMT_H263, |
|---|
| 86 | 75 | .codec_mode = S5P_MFC_CODEC_H263_DEC, |
|---|
| 87 | 76 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 89 | 78 | .versions = MFC_V5PLUS_BITS, |
|---|
| 90 | 79 | }, |
|---|
| 91 | 80 | { |
|---|
| 92 | | - .name = "MPEG1 Encoded Stream", |
|---|
| 93 | 81 | .fourcc = V4L2_PIX_FMT_MPEG1, |
|---|
| 94 | 82 | .codec_mode = S5P_MFC_CODEC_MPEG2_DEC, |
|---|
| 95 | 83 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 97 | 85 | .versions = MFC_V5PLUS_BITS, |
|---|
| 98 | 86 | }, |
|---|
| 99 | 87 | { |
|---|
| 100 | | - .name = "MPEG2 Encoded Stream", |
|---|
| 101 | 88 | .fourcc = V4L2_PIX_FMT_MPEG2, |
|---|
| 102 | 89 | .codec_mode = S5P_MFC_CODEC_MPEG2_DEC, |
|---|
| 103 | 90 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 105 | 92 | .versions = MFC_V5PLUS_BITS, |
|---|
| 106 | 93 | }, |
|---|
| 107 | 94 | { |
|---|
| 108 | | - .name = "MPEG4 Encoded Stream", |
|---|
| 109 | 95 | .fourcc = V4L2_PIX_FMT_MPEG4, |
|---|
| 110 | 96 | .codec_mode = S5P_MFC_CODEC_MPEG4_DEC, |
|---|
| 111 | 97 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 113 | 99 | .versions = MFC_V5PLUS_BITS, |
|---|
| 114 | 100 | }, |
|---|
| 115 | 101 | { |
|---|
| 116 | | - .name = "XviD Encoded Stream", |
|---|
| 117 | 102 | .fourcc = V4L2_PIX_FMT_XVID, |
|---|
| 118 | 103 | .codec_mode = S5P_MFC_CODEC_MPEG4_DEC, |
|---|
| 119 | 104 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 121 | 106 | .versions = MFC_V5PLUS_BITS, |
|---|
| 122 | 107 | }, |
|---|
| 123 | 108 | { |
|---|
| 124 | | - .name = "VC1 Encoded Stream", |
|---|
| 125 | 109 | .fourcc = V4L2_PIX_FMT_VC1_ANNEX_G, |
|---|
| 126 | 110 | .codec_mode = S5P_MFC_CODEC_VC1_DEC, |
|---|
| 127 | 111 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 129 | 113 | .versions = MFC_V5PLUS_BITS, |
|---|
| 130 | 114 | }, |
|---|
| 131 | 115 | { |
|---|
| 132 | | - .name = "VC1 RCV Encoded Stream", |
|---|
| 133 | 116 | .fourcc = V4L2_PIX_FMT_VC1_ANNEX_L, |
|---|
| 134 | 117 | .codec_mode = S5P_MFC_CODEC_VC1RCV_DEC, |
|---|
| 135 | 118 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 137 | 120 | .versions = MFC_V5PLUS_BITS, |
|---|
| 138 | 121 | }, |
|---|
| 139 | 122 | { |
|---|
| 140 | | - .name = "VP8 Encoded Stream", |
|---|
| 141 | 123 | .fourcc = V4L2_PIX_FMT_VP8, |
|---|
| 142 | 124 | .codec_mode = S5P_MFC_CODEC_VP8_DEC, |
|---|
| 143 | 125 | .type = MFC_FMT_DEC, |
|---|
| .. | .. |
|---|
| 186 | 168 | .default_value = 0, |
|---|
| 187 | 169 | }, |
|---|
| 188 | 170 | { |
|---|
| 171 | + .id = V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY, |
|---|
| 172 | + .type = V4L2_CTRL_TYPE_INTEGER, |
|---|
| 173 | + .minimum = 0, |
|---|
| 174 | + .maximum = 16383, |
|---|
| 175 | + .step = 1, |
|---|
| 176 | + .default_value = 0, |
|---|
| 177 | + }, |
|---|
| 178 | + { |
|---|
| 189 | 179 | .id = V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE, |
|---|
| 190 | 180 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
|---|
| 191 | 181 | .name = "H264 Display Delay Enable", |
|---|
| 192 | 182 | .minimum = 0, |
|---|
| 193 | 183 | .maximum = 1, |
|---|
| 194 | 184 | .step = 1, |
|---|
| 185 | + .default_value = 0, |
|---|
| 186 | + }, |
|---|
| 187 | + { |
|---|
| 188 | + .id = V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE, |
|---|
| 189 | + .type = V4L2_CTRL_TYPE_BOOLEAN, |
|---|
| 190 | + .minimum = 0, |
|---|
| 191 | + .maximum = 1, |
|---|
| 195 | 192 | .default_value = 0, |
|---|
| 196 | 193 | }, |
|---|
| 197 | 194 | { |
|---|
| .. | .. |
|---|
| 271 | 268 | { |
|---|
| 272 | 269 | struct s5p_mfc_dev *dev = video_drvdata(file); |
|---|
| 273 | 270 | |
|---|
| 274 | | - strlcpy(cap->driver, S5P_MFC_NAME, sizeof(cap->driver)); |
|---|
| 275 | | - strlcpy(cap->card, dev->vfd_dec->name, sizeof(cap->card)); |
|---|
| 271 | + strscpy(cap->driver, S5P_MFC_NAME, sizeof(cap->driver)); |
|---|
| 272 | + strscpy(cap->card, dev->vfd_dec->name, sizeof(cap->card)); |
|---|
| 276 | 273 | snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", |
|---|
| 277 | 274 | dev_name(&dev->plat_dev->dev)); |
|---|
| 278 | | - /* |
|---|
| 279 | | - * This is only a mem-to-mem video device. The capture and output |
|---|
| 280 | | - * device capability flags are left only for backward compatibility |
|---|
| 281 | | - * and are scheduled for removal. |
|---|
| 282 | | - */ |
|---|
| 283 | | - cap->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; |
|---|
| 284 | | - cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
|---|
| 285 | 275 | return 0; |
|---|
| 286 | 276 | } |
|---|
| 287 | 277 | |
|---|
| .. | .. |
|---|
| 290 | 280 | bool out) |
|---|
| 291 | 281 | { |
|---|
| 292 | 282 | struct s5p_mfc_dev *dev = video_drvdata(file); |
|---|
| 293 | | - struct s5p_mfc_fmt *fmt; |
|---|
| 294 | 283 | int i, j = 0; |
|---|
| 295 | 284 | |
|---|
| 296 | 285 | for (i = 0; i < ARRAY_SIZE(formats); ++i) { |
|---|
| .. | .. |
|---|
| 307 | 296 | } |
|---|
| 308 | 297 | if (i == ARRAY_SIZE(formats)) |
|---|
| 309 | 298 | return -EINVAL; |
|---|
| 310 | | - fmt = &formats[i]; |
|---|
| 311 | | - strlcpy(f->description, fmt->name, sizeof(f->description)); |
|---|
| 312 | | - f->pixelformat = fmt->fourcc; |
|---|
| 299 | + f->pixelformat = formats[i].fourcc; |
|---|
| 313 | 300 | return 0; |
|---|
| 314 | 301 | } |
|---|
| 315 | 302 | |
|---|
| 316 | | -static int vidioc_enum_fmt_vid_cap_mplane(struct file *file, void *pirv, |
|---|
| 317 | | - struct v4l2_fmtdesc *f) |
|---|
| 303 | +static int vidioc_enum_fmt_vid_cap(struct file *file, void *pirv, |
|---|
| 304 | + struct v4l2_fmtdesc *f) |
|---|
| 318 | 305 | { |
|---|
| 319 | 306 | return vidioc_enum_fmt(file, f, false); |
|---|
| 320 | 307 | } |
|---|
| 321 | 308 | |
|---|
| 322 | | -static int vidioc_enum_fmt_vid_out_mplane(struct file *file, void *priv, |
|---|
| 323 | | - struct v4l2_fmtdesc *f) |
|---|
| 309 | +static int vidioc_enum_fmt_vid_out(struct file *file, void *priv, |
|---|
| 310 | + struct v4l2_fmtdesc *f) |
|---|
| 324 | 311 | { |
|---|
| 325 | 312 | return vidioc_enum_fmt(file, f, true); |
|---|
| 326 | 313 | } |
|---|
| .. | .. |
|---|
| 602 | 589 | int i; |
|---|
| 603 | 590 | |
|---|
| 604 | 591 | if (buf->memory != V4L2_MEMORY_MMAP) { |
|---|
| 605 | | - mfc_err("Only mmaped buffers can be used\n"); |
|---|
| 592 | + mfc_err("Only mmapped buffers can be used\n"); |
|---|
| 606 | 593 | return -EINVAL; |
|---|
| 607 | 594 | } |
|---|
| 608 | 595 | mfc_debug(2, "State: %d, buf->type: %d\n", ctx->state, buf->type); |
|---|
| .. | .. |
|---|
| 632 | 619 | return -EIO; |
|---|
| 633 | 620 | } |
|---|
| 634 | 621 | if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) |
|---|
| 635 | | - return vb2_qbuf(&ctx->vq_src, buf); |
|---|
| 622 | + return vb2_qbuf(&ctx->vq_src, NULL, buf); |
|---|
| 636 | 623 | else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
|---|
| 637 | | - return vb2_qbuf(&ctx->vq_dst, buf); |
|---|
| 624 | + return vb2_qbuf(&ctx->vq_dst, NULL, buf); |
|---|
| 638 | 625 | return -EINVAL; |
|---|
| 639 | 626 | } |
|---|
| 640 | 627 | |
|---|
| .. | .. |
|---|
| 718 | 705 | |
|---|
| 719 | 706 | switch (ctrl->id) { |
|---|
| 720 | 707 | case V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY: |
|---|
| 708 | + case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY: |
|---|
| 721 | 709 | ctx->display_delay = ctrl->val; |
|---|
| 722 | 710 | break; |
|---|
| 723 | 711 | case V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE: |
|---|
| 712 | + case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE: |
|---|
| 724 | 713 | ctx->display_delay_enable = ctrl->val; |
|---|
| 725 | 714 | break; |
|---|
| 726 | 715 | case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER: |
|---|
| .. | .. |
|---|
| 773 | 762 | .g_volatile_ctrl = s5p_mfc_dec_g_v_ctrl, |
|---|
| 774 | 763 | }; |
|---|
| 775 | 764 | |
|---|
| 776 | | -/* Get cropping information */ |
|---|
| 777 | | -static int vidioc_g_crop(struct file *file, void *priv, |
|---|
| 778 | | - struct v4l2_crop *cr) |
|---|
| 765 | +/* Get compose information */ |
|---|
| 766 | +static int vidioc_g_selection(struct file *file, void *priv, |
|---|
| 767 | + struct v4l2_selection *s) |
|---|
| 779 | 768 | { |
|---|
| 780 | 769 | struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); |
|---|
| 781 | 770 | struct s5p_mfc_dev *dev = ctx->dev; |
|---|
| 782 | 771 | u32 left, right, top, bottom; |
|---|
| 772 | + u32 width, height; |
|---|
| 773 | + |
|---|
| 774 | + if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
|---|
| 775 | + return -EINVAL; |
|---|
| 783 | 776 | |
|---|
| 784 | 777 | if (ctx->state != MFCINST_HEAD_PARSED && |
|---|
| 785 | 778 | ctx->state != MFCINST_RUNNING && |
|---|
| 786 | 779 | ctx->state != MFCINST_FINISHING && |
|---|
| 787 | 780 | ctx->state != MFCINST_FINISHED) { |
|---|
| 788 | | - mfc_err("Can not get crop information\n"); |
|---|
| 781 | + mfc_err("Can not get compose information\n"); |
|---|
| 789 | 782 | return -EINVAL; |
|---|
| 790 | 783 | } |
|---|
| 791 | 784 | if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_H264) { |
|---|
| .. | .. |
|---|
| 795 | 788 | top = s5p_mfc_hw_call(dev->mfc_ops, get_crop_info_v, ctx); |
|---|
| 796 | 789 | bottom = top >> S5P_FIMV_SHARED_CROP_BOTTOM_SHIFT; |
|---|
| 797 | 790 | top = top & S5P_FIMV_SHARED_CROP_TOP_MASK; |
|---|
| 798 | | - cr->c.left = left; |
|---|
| 799 | | - cr->c.top = top; |
|---|
| 800 | | - cr->c.width = ctx->img_width - left - right; |
|---|
| 801 | | - cr->c.height = ctx->img_height - top - bottom; |
|---|
| 802 | | - mfc_debug(2, "Cropping info [h264]: l=%d t=%d w=%d h=%d (r=%d b=%d fw=%d fh=%d\n", |
|---|
| 803 | | - left, top, cr->c.width, cr->c.height, right, bottom, |
|---|
| 791 | + width = ctx->img_width - left - right; |
|---|
| 792 | + height = ctx->img_height - top - bottom; |
|---|
| 793 | + mfc_debug(2, "Composing info [h264]: l=%d t=%d w=%d h=%d (r=%d b=%d fw=%d fh=%d\n", |
|---|
| 794 | + left, top, s->r.width, s->r.height, right, bottom, |
|---|
| 804 | 795 | ctx->buf_width, ctx->buf_height); |
|---|
| 805 | 796 | } else { |
|---|
| 806 | | - cr->c.left = 0; |
|---|
| 807 | | - cr->c.top = 0; |
|---|
| 808 | | - cr->c.width = ctx->img_width; |
|---|
| 809 | | - cr->c.height = ctx->img_height; |
|---|
| 810 | | - mfc_debug(2, "Cropping info: w=%d h=%d fw=%d fh=%d\n", |
|---|
| 811 | | - cr->c.width, cr->c.height, ctx->buf_width, |
|---|
| 797 | + left = 0; |
|---|
| 798 | + top = 0; |
|---|
| 799 | + width = ctx->img_width; |
|---|
| 800 | + height = ctx->img_height; |
|---|
| 801 | + mfc_debug(2, "Composing info: w=%d h=%d fw=%d fh=%d\n", |
|---|
| 802 | + s->r.width, s->r.height, ctx->buf_width, |
|---|
| 812 | 803 | ctx->buf_height); |
|---|
| 804 | + } |
|---|
| 805 | + |
|---|
| 806 | + switch (s->target) { |
|---|
| 807 | + case V4L2_SEL_TGT_COMPOSE: |
|---|
| 808 | + case V4L2_SEL_TGT_COMPOSE_DEFAULT: |
|---|
| 809 | + case V4L2_SEL_TGT_COMPOSE_BOUNDS: |
|---|
| 810 | + s->r.left = left; |
|---|
| 811 | + s->r.top = top; |
|---|
| 812 | + s->r.width = width; |
|---|
| 813 | + s->r.height = height; |
|---|
| 814 | + break; |
|---|
| 815 | + default: |
|---|
| 816 | + return -EINVAL; |
|---|
| 813 | 817 | } |
|---|
| 814 | 818 | return 0; |
|---|
| 815 | 819 | } |
|---|
| .. | .. |
|---|
| 872 | 876 | /* v4l2_ioctl_ops */ |
|---|
| 873 | 877 | static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = { |
|---|
| 874 | 878 | .vidioc_querycap = vidioc_querycap, |
|---|
| 875 | | - .vidioc_enum_fmt_vid_cap_mplane = vidioc_enum_fmt_vid_cap_mplane, |
|---|
| 876 | | - .vidioc_enum_fmt_vid_out_mplane = vidioc_enum_fmt_vid_out_mplane, |
|---|
| 879 | + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
|---|
| 880 | + .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out, |
|---|
| 877 | 881 | .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt, |
|---|
| 878 | 882 | .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt, |
|---|
| 879 | 883 | .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt, |
|---|
| .. | .. |
|---|
| 887 | 891 | .vidioc_expbuf = vidioc_expbuf, |
|---|
| 888 | 892 | .vidioc_streamon = vidioc_streamon, |
|---|
| 889 | 893 | .vidioc_streamoff = vidioc_streamoff, |
|---|
| 890 | | - .vidioc_g_crop = vidioc_g_crop, |
|---|
| 894 | + .vidioc_g_selection = vidioc_g_selection, |
|---|
| 891 | 895 | .vidioc_decoder_cmd = vidioc_decoder_cmd, |
|---|
| 892 | 896 | .vidioc_subscribe_event = vidioc_subscribe_event, |
|---|
| 893 | 897 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
|---|