Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] s5p-jpeg: Use mem-to-mem ioctl helpers

Simplify the driver by using the m2m ioctl and vb2 helpers.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Kamil Debski <k.debski@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Sylwester Nawrocki and committed by
Mauro Carvalho Chehab
718cf4a9 43894d84

+24 -112
+24 -110
drivers/media/platform/s5p-jpeg/jpeg-core.c
··· 316 316 if (ret < 0) 317 317 goto error; 318 318 319 - ctx->m2m_ctx = v4l2_m2m_ctx_init(jpeg->m2m_dev, ctx, queue_init); 320 - if (IS_ERR(ctx->m2m_ctx)) { 321 - ret = PTR_ERR(ctx->m2m_ctx); 319 + ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(jpeg->m2m_dev, ctx, queue_init); 320 + if (IS_ERR(ctx->fh.m2m_ctx)) { 321 + ret = PTR_ERR(ctx->fh.m2m_ctx); 322 322 goto error; 323 323 } 324 324 ··· 342 342 struct s5p_jpeg_ctx *ctx = fh_to_ctx(file->private_data); 343 343 344 344 mutex_lock(&jpeg->lock); 345 - v4l2_m2m_ctx_release(ctx->m2m_ctx); 345 + v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); 346 346 mutex_unlock(&jpeg->lock); 347 347 v4l2_ctrl_handler_free(&ctx->ctrl_handler); 348 348 v4l2_fh_del(&ctx->fh); ··· 352 352 return 0; 353 353 } 354 354 355 - static unsigned int s5p_jpeg_poll(struct file *file, 356 - struct poll_table_struct *wait) 357 - { 358 - struct s5p_jpeg *jpeg = video_drvdata(file); 359 - struct s5p_jpeg_ctx *ctx = fh_to_ctx(file->private_data); 360 - unsigned int res; 361 - 362 - mutex_lock(&jpeg->lock); 363 - res = v4l2_m2m_poll(file, ctx->m2m_ctx, wait); 364 - mutex_unlock(&jpeg->lock); 365 - return res; 366 - } 367 - 368 - static int s5p_jpeg_mmap(struct file *file, struct vm_area_struct *vma) 369 - { 370 - struct s5p_jpeg *jpeg = video_drvdata(file); 371 - struct s5p_jpeg_ctx *ctx = fh_to_ctx(file->private_data); 372 - int ret; 373 - 374 - if (mutex_lock_interruptible(&jpeg->lock)) 375 - return -ERESTARTSYS; 376 - ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); 377 - mutex_unlock(&jpeg->lock); 378 - return ret; 379 - } 380 - 381 355 static const struct v4l2_file_operations s5p_jpeg_fops = { 382 356 .owner = THIS_MODULE, 383 357 .open = s5p_jpeg_open, 384 358 .release = s5p_jpeg_release, 385 - .poll = s5p_jpeg_poll, 359 + .poll = v4l2_m2m_fop_poll, 386 360 .unlocked_ioctl = video_ioctl2, 387 - .mmap = s5p_jpeg_mmap, 361 + .mmap = v4l2_m2m_fop_mmap, 388 362 }; 389 363 390 364 /* ··· 563 589 struct v4l2_pix_format *pix = &f->fmt.pix; 564 590 struct s5p_jpeg_ctx *ct = fh_to_ctx(priv); 565 591 566 - vq = v4l2_m2m_get_vq(ct->m2m_ctx, f->type); 592 + vq = v4l2_m2m_get_vq(ct->fh.m2m_ctx, f->type); 567 593 if (!vq) 568 594 return -EINVAL; 569 595 ··· 719 745 struct s5p_jpeg_q_data *q_data = NULL; 720 746 struct v4l2_pix_format *pix = &f->fmt.pix; 721 747 722 - vq = v4l2_m2m_get_vq(ct->m2m_ctx, f->type); 748 + vq = v4l2_m2m_get_vq(ct->fh.m2m_ctx, f->type); 723 749 if (!vq) 724 750 return -EINVAL; 725 751 ··· 764 790 return ret; 765 791 766 792 return s5p_jpeg_s_fmt(fh_to_ctx(priv), f); 767 - } 768 - 769 - static int s5p_jpeg_reqbufs(struct file *file, void *priv, 770 - struct v4l2_requestbuffers *reqbufs) 771 - { 772 - struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv); 773 - 774 - return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs); 775 - } 776 - 777 - static int s5p_jpeg_querybuf(struct file *file, void *priv, 778 - struct v4l2_buffer *buf) 779 - { 780 - struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv); 781 - 782 - return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf); 783 - } 784 - 785 - static int s5p_jpeg_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 786 - { 787 - struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv); 788 - 789 - return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf); 790 - } 791 - 792 - static int s5p_jpeg_dqbuf(struct file *file, void *priv, 793 - struct v4l2_buffer *buf) 794 - { 795 - struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv); 796 - 797 - return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf); 798 - } 799 - 800 - static int s5p_jpeg_streamon(struct file *file, void *priv, 801 - enum v4l2_buf_type type) 802 - { 803 - struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv); 804 - 805 - return v4l2_m2m_streamon(file, ctx->m2m_ctx, type); 806 - } 807 - 808 - static int s5p_jpeg_streamoff(struct file *file, void *priv, 809 - enum v4l2_buf_type type) 810 - { 811 - struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv); 812 - 813 - return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type); 814 793 } 815 794 816 795 static int s5p_jpeg_g_selection(struct file *file, void *priv, ··· 899 972 .vidioc_s_fmt_vid_cap = s5p_jpeg_s_fmt_vid_cap, 900 973 .vidioc_s_fmt_vid_out = s5p_jpeg_s_fmt_vid_out, 901 974 902 - .vidioc_reqbufs = s5p_jpeg_reqbufs, 903 - .vidioc_querybuf = s5p_jpeg_querybuf, 975 + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, 976 + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, 977 + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, 978 + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, 904 979 905 - .vidioc_qbuf = s5p_jpeg_qbuf, 906 - .vidioc_dqbuf = s5p_jpeg_dqbuf, 907 - 908 - .vidioc_streamon = s5p_jpeg_streamon, 909 - .vidioc_streamoff = s5p_jpeg_streamoff, 980 + .vidioc_streamon = v4l2_m2m_ioctl_streamon, 981 + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, 910 982 911 983 .vidioc_g_selection = s5p_jpeg_g_selection, 912 984 }; ··· 923 997 struct vb2_buffer *src_buf, *dst_buf; 924 998 unsigned long src_addr, dst_addr; 925 999 926 - src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx); 927 - dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); 1000 + src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); 1001 + dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); 928 1002 src_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0); 929 1003 dst_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0); 930 1004 ··· 1096 1170 ); 1097 1171 q_data->size = q_data->w * q_data->h * q_data->fmt->depth >> 3; 1098 1172 } 1099 - if (ctx->m2m_ctx) 1100 - v4l2_m2m_buf_queue(ctx->m2m_ctx, vb); 1101 - } 1102 1173 1103 - static void s5p_jpeg_wait_prepare(struct vb2_queue *vq) 1104 - { 1105 - struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(vq); 1106 - 1107 - mutex_unlock(&ctx->jpeg->lock); 1108 - } 1109 - 1110 - static void s5p_jpeg_wait_finish(struct vb2_queue *vq) 1111 - { 1112 - struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(vq); 1113 - 1114 - mutex_lock(&ctx->jpeg->lock); 1174 + v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); 1115 1175 } 1116 1176 1117 1177 static int s5p_jpeg_start_streaming(struct vb2_queue *q, unsigned int count) ··· 1123 1211 .queue_setup = s5p_jpeg_queue_setup, 1124 1212 .buf_prepare = s5p_jpeg_buf_prepare, 1125 1213 .buf_queue = s5p_jpeg_buf_queue, 1126 - .wait_prepare = s5p_jpeg_wait_prepare, 1127 - .wait_finish = s5p_jpeg_wait_finish, 1214 + .wait_prepare = vb2_ops_wait_prepare, 1215 + .wait_finish = vb2_ops_wait_finish, 1128 1216 .start_streaming = s5p_jpeg_start_streaming, 1129 1217 .stop_streaming = s5p_jpeg_stop_streaming, 1130 1218 }; ··· 1142 1230 src_vq->ops = &s5p_jpeg_qops; 1143 1231 src_vq->mem_ops = &vb2_dma_contig_memops; 1144 1232 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1233 + src_vq->lock = &ctx->jpeg->lock; 1145 1234 1146 1235 ret = vb2_queue_init(src_vq); 1147 1236 if (ret) ··· 1155 1242 dst_vq->ops = &s5p_jpeg_qops; 1156 1243 dst_vq->mem_ops = &vb2_dma_contig_memops; 1157 1244 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1245 + dst_vq->lock = &ctx->jpeg->lock; 1158 1246 1159 1247 return vb2_queue_init(dst_vq); 1160 1248 } ··· 1181 1267 1182 1268 curr_ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev); 1183 1269 1184 - src_buf = v4l2_m2m_src_buf_remove(curr_ctx->m2m_ctx); 1185 - dst_buf = v4l2_m2m_dst_buf_remove(curr_ctx->m2m_ctx); 1270 + src_buf = v4l2_m2m_src_buf_remove(curr_ctx->fh.m2m_ctx); 1271 + dst_buf = v4l2_m2m_dst_buf_remove(curr_ctx->fh.m2m_ctx); 1186 1272 1187 1273 if (curr_ctx->mode == S5P_JPEG_ENCODE) 1188 1274 enc_jpeg_too_large = jpeg_enc_stream_stat(jpeg->regs); ··· 1210 1296 if (curr_ctx->mode == S5P_JPEG_ENCODE) 1211 1297 vb2_set_plane_payload(dst_buf, 0, payload_size); 1212 1298 v4l2_m2m_buf_done(dst_buf, state); 1213 - v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->m2m_ctx); 1299 + v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx); 1214 1300 1215 1301 curr_ctx->subsampling = jpeg_get_subsampling_mode(jpeg->regs); 1216 1302 spin_unlock(&jpeg->slock);
-2
drivers/media/platform/s5p-jpeg/jpeg-core.h
··· 115 115 * @jpeg: JPEG IP device for this context 116 116 * @mode: compression (encode) operation or decompression (decode) 117 117 * @compr_quality: destination image quality in compression (encode) mode 118 - * @m2m_ctx: mem2mem device context 119 118 * @out_q: source (output) queue information 120 119 * @cap_fmt: destination (capture) queue queue information 121 120 * @hdr_parsed: set if header has been parsed during decompression ··· 126 127 unsigned short compr_quality; 127 128 unsigned short restart_interval; 128 129 unsigned short subsampling; 129 - struct v4l2_m2m_ctx *m2m_ctx; 130 130 struct s5p_jpeg_q_data out_q; 131 131 struct s5p_jpeg_q_data cap_q; 132 132 struct v4l2_fh fh;