2 * Copyright (c) 2011 - 2012 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
5 * Samsung EXYNOS5 SoC series G-Scaler driver
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 2 of the License,
10 * or (at your option) any later version.
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/types.h>
16 #include <linux/errno.h>
17 #include <linux/bug.h>
18 #include <linux/interrupt.h>
19 #include <linux/workqueue.h>
20 #include <linux/device.h>
21 #include <linux/platform_device.h>
22 #include <linux/list.h>
24 #include <linux/slab.h>
25 #include <linux/clk.h>
27 #include <media/v4l2-ioctl.h>
31 static int gsc_m2m_ctx_stop_req(struct gsc_ctx *ctx)
33 struct gsc_ctx *curr_ctx;
34 struct gsc_dev *gsc = ctx->gsc_dev;
37 curr_ctx = v4l2_m2m_get_curr_priv(gsc->m2m.m2m_dev);
38 if (!gsc_m2m_pending(gsc) || (curr_ctx != ctx))
41 gsc_ctx_state_lock_set(GSC_CTX_STOP_REQ, ctx);
42 ret = wait_event_timeout(gsc->irq_queue,
43 !gsc_ctx_state_is_set(GSC_CTX_STOP_REQ, ctx),
44 GSC_SHUTDOWN_TIMEOUT);
46 return ret == 0 ? -ETIMEDOUT : ret;
49 static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
51 struct gsc_ctx *ctx = q->drv_priv;
54 ret = pm_runtime_get_sync(&ctx->gsc_dev->pdev->dev);
55 return ret > 0 ? 0 : ret;
58 static int gsc_m2m_stop_streaming(struct vb2_queue *q)
60 struct gsc_ctx *ctx = q->drv_priv;
63 ret = gsc_m2m_ctx_stop_req(ctx);
64 if (ret == -ETIMEDOUT)
65 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
67 pm_runtime_put(&ctx->gsc_dev->pdev->dev);
72 void gsc_m2m_job_finish(struct gsc_ctx *ctx, int vb_state)
74 struct vb2_buffer *src_vb, *dst_vb;
76 if (!ctx || !ctx->m2m_ctx)
79 src_vb = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
80 dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
82 if (src_vb && dst_vb) {
83 v4l2_m2m_buf_done(src_vb, vb_state);
84 v4l2_m2m_buf_done(dst_vb, vb_state);
86 v4l2_m2m_job_finish(ctx->gsc_dev->m2m.m2m_dev,
92 static void gsc_m2m_job_abort(void *priv)
94 struct gsc_ctx *ctx = priv;
97 ret = gsc_m2m_ctx_stop_req(ctx);
98 if (ret == -ETIMEDOUT)
99 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
102 static int gsc_get_bufs(struct gsc_ctx *ctx)
104 struct gsc_frame *s_frame, *d_frame;
105 struct vb2_buffer *src_vb, *dst_vb;
108 s_frame = &ctx->s_frame;
109 d_frame = &ctx->d_frame;
111 src_vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
112 ret = gsc_prepare_addr(ctx, src_vb, s_frame, &s_frame->addr);
116 dst_vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
117 ret = gsc_prepare_addr(ctx, dst_vb, d_frame, &d_frame->addr);
121 dst_vb->v4l2_buf.timestamp = src_vb->v4l2_buf.timestamp;
126 static void gsc_m2m_device_run(void *priv)
128 struct gsc_ctx *ctx = priv;
134 if (WARN(!ctx, "null hardware context\n"))
138 spin_lock_irqsave(&gsc->slock, flags);
140 set_bit(ST_M2M_PEND, &gsc->state);
142 /* Reconfigure hardware if the context has changed. */
143 if (gsc->m2m.ctx != ctx) {
144 pr_debug("gsc->m2m.ctx = 0x%p, current_ctx = 0x%p",
146 ctx->state |= GSC_PARAMS;
150 is_set = (ctx->state & GSC_CTX_STOP_REQ) ? 1 : 0;
151 ctx->state &= ~GSC_CTX_STOP_REQ;
153 wake_up(&gsc->irq_queue);
157 ret = gsc_get_bufs(ctx);
159 pr_err("Wrong address");
163 gsc_set_prefbuf(gsc, &ctx->s_frame);
164 gsc_hw_set_input_addr(gsc, &ctx->s_frame.addr, GSC_M2M_BUF_NUM);
165 gsc_hw_set_output_addr(gsc, &ctx->d_frame.addr, GSC_M2M_BUF_NUM);
167 if (ctx->state & GSC_PARAMS) {
168 gsc_hw_set_input_buf_masking(gsc, GSC_M2M_BUF_NUM, false);
169 gsc_hw_set_output_buf_masking(gsc, GSC_M2M_BUF_NUM, false);
170 gsc_hw_set_frm_done_irq_mask(gsc, false);
171 gsc_hw_set_gsc_irq_enable(gsc, true);
173 if (gsc_set_scaler_info(ctx)) {
174 pr_err("Scaler setup error");
178 gsc_hw_set_input_path(ctx);
179 gsc_hw_set_in_size(ctx);
180 gsc_hw_set_in_image_format(ctx);
182 gsc_hw_set_output_path(ctx);
183 gsc_hw_set_out_size(ctx);
184 gsc_hw_set_out_image_format(ctx);
186 gsc_hw_set_prescaler(ctx);
187 gsc_hw_set_mainscaler(ctx);
188 gsc_hw_set_rotation(ctx);
189 gsc_hw_set_global_alpha(ctx);
192 /* update shadow registers */
193 gsc_hw_set_sfr_update(ctx);
195 ctx->state &= ~GSC_PARAMS;
196 gsc_hw_enable_control(gsc, true);
198 spin_unlock_irqrestore(&gsc->slock, flags);
202 ctx->state &= ~GSC_PARAMS;
203 spin_unlock_irqrestore(&gsc->slock, flags);
206 static int gsc_m2m_queue_setup(struct vb2_queue *vq,
207 const struct v4l2_format *fmt,
208 unsigned int *num_buffers, unsigned int *num_planes,
209 unsigned int sizes[], void *allocators[])
211 struct gsc_ctx *ctx = vb2_get_drv_priv(vq);
212 struct gsc_frame *frame;
215 frame = ctx_get_frame(ctx, vq->type);
217 return PTR_ERR(frame);
222 *num_planes = frame->fmt->num_planes;
223 for (i = 0; i < frame->fmt->num_planes; i++) {
224 sizes[i] = frame->payload[i];
225 allocators[i] = ctx->gsc_dev->alloc_ctx;
230 static int gsc_m2m_buf_prepare(struct vb2_buffer *vb)
232 struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
233 struct gsc_frame *frame;
236 frame = ctx_get_frame(ctx, vb->vb2_queue->type);
238 return PTR_ERR(frame);
240 if (!V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
241 for (i = 0; i < frame->fmt->num_planes; i++)
242 vb2_set_plane_payload(vb, i, frame->payload[i]);
248 static void gsc_m2m_buf_queue(struct vb2_buffer *vb)
250 struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
252 pr_debug("ctx: %p, ctx->state: 0x%x", ctx, ctx->state);
255 v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
258 static struct vb2_ops gsc_m2m_qops = {
259 .queue_setup = gsc_m2m_queue_setup,
260 .buf_prepare = gsc_m2m_buf_prepare,
261 .buf_queue = gsc_m2m_buf_queue,
262 .wait_prepare = gsc_unlock,
263 .wait_finish = gsc_lock,
264 .stop_streaming = gsc_m2m_stop_streaming,
265 .start_streaming = gsc_m2m_start_streaming,
268 static int gsc_m2m_querycap(struct file *file, void *fh,
269 struct v4l2_capability *cap)
271 struct gsc_ctx *ctx = fh_to_ctx(fh);
272 struct gsc_dev *gsc = ctx->gsc_dev;
274 strlcpy(cap->driver, gsc->pdev->name, sizeof(cap->driver));
275 strlcpy(cap->card, gsc->pdev->name, sizeof(cap->card));
276 strlcpy(cap->bus_info, "platform", sizeof(cap->bus_info));
277 cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE |
278 V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE;
280 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
284 static int gsc_m2m_enum_fmt_mplane(struct file *file, void *priv,
285 struct v4l2_fmtdesc *f)
287 return gsc_enum_fmt_mplane(f);
290 static int gsc_m2m_g_fmt_mplane(struct file *file, void *fh,
291 struct v4l2_format *f)
293 struct gsc_ctx *ctx = fh_to_ctx(fh);
295 return gsc_g_fmt_mplane(ctx, f);
298 static int gsc_m2m_try_fmt_mplane(struct file *file, void *fh,
299 struct v4l2_format *f)
301 struct gsc_ctx *ctx = fh_to_ctx(fh);
303 return gsc_try_fmt_mplane(ctx, f);
306 static int gsc_m2m_s_fmt_mplane(struct file *file, void *fh,
307 struct v4l2_format *f)
309 struct gsc_ctx *ctx = fh_to_ctx(fh);
310 struct vb2_queue *vq;
311 struct gsc_frame *frame;
312 struct v4l2_pix_format_mplane *pix;
315 ret = gsc_m2m_try_fmt_mplane(file, fh, f);
319 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
321 if (vb2_is_streaming(vq)) {
322 pr_err("queue (%d) busy", f->type);
326 if (V4L2_TYPE_IS_OUTPUT(f->type))
327 frame = &ctx->s_frame;
329 frame = &ctx->d_frame;
331 pix = &f->fmt.pix_mp;
332 frame->fmt = find_fmt(&pix->pixelformat, NULL, 0);
333 frame->colorspace = pix->colorspace;
337 for (i = 0; i < frame->fmt->num_planes; i++)
338 frame->payload[i] = pix->plane_fmt[i].sizeimage;
340 gsc_set_frame_size(frame, pix->width, pix->height);
342 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
343 gsc_ctx_state_lock_set(GSC_PARAMS | GSC_DST_FMT, ctx);
345 gsc_ctx_state_lock_set(GSC_PARAMS | GSC_SRC_FMT, ctx);
347 pr_debug("f_w: %d, f_h: %d", frame->f_width, frame->f_height);
352 static int gsc_m2m_reqbufs(struct file *file, void *fh,
353 struct v4l2_requestbuffers *reqbufs)
355 struct gsc_ctx *ctx = fh_to_ctx(fh);
356 struct gsc_dev *gsc = ctx->gsc_dev;
357 struct gsc_frame *frame;
360 max_cnt = (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) ?
361 gsc->variant->in_buf_cnt : gsc->variant->out_buf_cnt;
362 if (reqbufs->count > max_cnt) {
364 } else if (reqbufs->count == 0) {
365 if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
366 gsc_ctx_state_lock_clear(GSC_SRC_FMT, ctx);
368 gsc_ctx_state_lock_clear(GSC_DST_FMT, ctx);
371 frame = ctx_get_frame(ctx, reqbufs->type);
373 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
376 static int gsc_m2m_expbuf(struct file *file, void *fh,
377 struct v4l2_exportbuffer *eb)
379 struct gsc_ctx *ctx = fh_to_ctx(fh);
380 return v4l2_m2m_expbuf(file, ctx->m2m_ctx, eb);
383 static int gsc_m2m_querybuf(struct file *file, void *fh,
384 struct v4l2_buffer *buf)
386 struct gsc_ctx *ctx = fh_to_ctx(fh);
387 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
390 static int gsc_m2m_qbuf(struct file *file, void *fh,
391 struct v4l2_buffer *buf)
393 struct gsc_ctx *ctx = fh_to_ctx(fh);
394 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
397 static int gsc_m2m_dqbuf(struct file *file, void *fh,
398 struct v4l2_buffer *buf)
400 struct gsc_ctx *ctx = fh_to_ctx(fh);
401 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
404 static int gsc_m2m_streamon(struct file *file, void *fh,
405 enum v4l2_buf_type type)
407 struct gsc_ctx *ctx = fh_to_ctx(fh);
409 /* The source and target color format need to be set */
410 if (V4L2_TYPE_IS_OUTPUT(type)) {
411 if (!gsc_ctx_state_is_set(GSC_SRC_FMT, ctx))
413 } else if (!gsc_ctx_state_is_set(GSC_DST_FMT, ctx)) {
417 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
420 static int gsc_m2m_streamoff(struct file *file, void *fh,
421 enum v4l2_buf_type type)
423 struct gsc_ctx *ctx = fh_to_ctx(fh);
424 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
427 /* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
428 static int is_rectangle_enclosed(struct v4l2_rect *a, struct v4l2_rect *b)
430 if (a->left < b->left || a->top < b->top)
433 if (a->left + a->width > b->left + b->width)
436 if (a->top + a->height > b->top + b->height)
442 static int gsc_m2m_g_selection(struct file *file, void *fh,
443 struct v4l2_selection *s)
445 struct gsc_frame *frame;
446 struct gsc_ctx *ctx = fh_to_ctx(fh);
448 if ((s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) &&
449 (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE))
452 frame = ctx_get_frame(ctx, s->type);
454 return PTR_ERR(frame);
457 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
458 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
459 case V4L2_SEL_TGT_CROP_BOUNDS:
460 case V4L2_SEL_TGT_CROP_DEFAULT:
463 s->r.width = frame->f_width;
464 s->r.height = frame->f_height;
467 case V4L2_SEL_TGT_COMPOSE:
468 case V4L2_SEL_TGT_CROP:
469 s->r.left = frame->crop.left;
470 s->r.top = frame->crop.top;
471 s->r.width = frame->crop.width;
472 s->r.height = frame->crop.height;
479 static int gsc_m2m_s_selection(struct file *file, void *fh,
480 struct v4l2_selection *s)
482 struct gsc_frame *frame;
483 struct gsc_ctx *ctx = fh_to_ctx(fh);
485 struct gsc_variant *variant = ctx->gsc_dev->variant;
491 if ((s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) &&
492 (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE))
495 ret = gsc_try_crop(ctx, &cr);
499 if (s->flags & V4L2_SEL_FLAG_LE &&
500 !is_rectangle_enclosed(&cr.c, &s->r))
503 if (s->flags & V4L2_SEL_FLAG_GE &&
504 !is_rectangle_enclosed(&s->r, &cr.c))
510 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
511 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
512 case V4L2_SEL_TGT_COMPOSE:
513 frame = &ctx->s_frame;
516 case V4L2_SEL_TGT_CROP_BOUNDS:
517 case V4L2_SEL_TGT_CROP:
518 case V4L2_SEL_TGT_CROP_DEFAULT:
519 frame = &ctx->d_frame;
526 /* Check to see if scaling ratio is within supported range */
527 if (gsc_ctx_state_is_set(GSC_DST_FMT | GSC_SRC_FMT, ctx)) {
528 if (s->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
529 ret = gsc_check_scaler_ratio(variant, cr.c.width,
530 cr.c.height, ctx->d_frame.crop.width,
531 ctx->d_frame.crop.height,
532 ctx->gsc_ctrls.rotate->val, ctx->out_path);
534 ret = gsc_check_scaler_ratio(variant,
535 ctx->s_frame.crop.width,
536 ctx->s_frame.crop.height, cr.c.width,
537 cr.c.height, ctx->gsc_ctrls.rotate->val,
542 pr_err("Out of scaler range");
549 gsc_ctx_state_lock_set(GSC_PARAMS, ctx);
553 static const struct v4l2_ioctl_ops gsc_m2m_ioctl_ops = {
554 .vidioc_querycap = gsc_m2m_querycap,
555 .vidioc_enum_fmt_vid_cap_mplane = gsc_m2m_enum_fmt_mplane,
556 .vidioc_enum_fmt_vid_out_mplane = gsc_m2m_enum_fmt_mplane,
557 .vidioc_g_fmt_vid_cap_mplane = gsc_m2m_g_fmt_mplane,
558 .vidioc_g_fmt_vid_out_mplane = gsc_m2m_g_fmt_mplane,
559 .vidioc_try_fmt_vid_cap_mplane = gsc_m2m_try_fmt_mplane,
560 .vidioc_try_fmt_vid_out_mplane = gsc_m2m_try_fmt_mplane,
561 .vidioc_s_fmt_vid_cap_mplane = gsc_m2m_s_fmt_mplane,
562 .vidioc_s_fmt_vid_out_mplane = gsc_m2m_s_fmt_mplane,
563 .vidioc_reqbufs = gsc_m2m_reqbufs,
564 .vidioc_expbuf = gsc_m2m_expbuf,
565 .vidioc_querybuf = gsc_m2m_querybuf,
566 .vidioc_qbuf = gsc_m2m_qbuf,
567 .vidioc_dqbuf = gsc_m2m_dqbuf,
568 .vidioc_streamon = gsc_m2m_streamon,
569 .vidioc_streamoff = gsc_m2m_streamoff,
570 .vidioc_g_selection = gsc_m2m_g_selection,
571 .vidioc_s_selection = gsc_m2m_s_selection
574 static int queue_init(void *priv, struct vb2_queue *src_vq,
575 struct vb2_queue *dst_vq)
577 struct gsc_ctx *ctx = priv;
580 memset(src_vq, 0, sizeof(*src_vq));
581 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
582 src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
583 src_vq->drv_priv = ctx;
584 src_vq->ops = &gsc_m2m_qops;
585 src_vq->mem_ops = &vb2_dma_contig_memops;
586 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
588 ret = vb2_queue_init(src_vq);
592 memset(dst_vq, 0, sizeof(*dst_vq));
593 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
594 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
595 dst_vq->drv_priv = ctx;
596 dst_vq->ops = &gsc_m2m_qops;
597 dst_vq->mem_ops = &vb2_dma_contig_memops;
598 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
600 return vb2_queue_init(dst_vq);
603 static int gsc_m2m_open(struct file *file)
605 struct gsc_dev *gsc = video_drvdata(file);
606 struct gsc_ctx *ctx = NULL;
609 pr_debug("pid: %d, state: 0x%lx", task_pid_nr(current), gsc->state);
611 if (mutex_lock_interruptible(&gsc->lock))
614 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
620 v4l2_fh_init(&ctx->fh, gsc->m2m.vfd);
621 ret = gsc_ctrls_create(ctx);
625 /* Use separate control handler per file handle */
626 ctx->fh.ctrl_handler = &ctx->ctrl_handler;
627 file->private_data = &ctx->fh;
628 v4l2_fh_add(&ctx->fh);
631 /* Default color format */
632 ctx->s_frame.fmt = get_format(0);
633 ctx->d_frame.fmt = get_format(0);
634 /* Setup the device context for mem2mem mode. */
635 ctx->state = GSC_CTX_M2M;
637 ctx->in_path = GSC_DMA;
638 ctx->out_path = GSC_DMA;
640 ctx->m2m_ctx = v4l2_m2m_ctx_init(gsc->m2m.m2m_dev, ctx, queue_init);
641 if (IS_ERR(ctx->m2m_ctx)) {
642 pr_err("Failed to initialize m2m context");
643 ret = PTR_ERR(ctx->m2m_ctx);
647 if (gsc->m2m.refcnt++ == 0)
648 set_bit(ST_M2M_OPEN, &gsc->state);
650 pr_debug("gsc m2m driver is opened, ctx(0x%p)", ctx);
652 mutex_unlock(&gsc->lock);
656 gsc_ctrls_delete(ctx);
658 v4l2_fh_del(&ctx->fh);
659 v4l2_fh_exit(&ctx->fh);
662 mutex_unlock(&gsc->lock);
666 static int gsc_m2m_release(struct file *file)
668 struct gsc_ctx *ctx = fh_to_ctx(file->private_data);
669 struct gsc_dev *gsc = ctx->gsc_dev;
671 pr_debug("pid: %d, state: 0x%lx, refcnt= %d",
672 task_pid_nr(current), gsc->state, gsc->m2m.refcnt);
674 mutex_lock(&gsc->lock);
676 v4l2_m2m_ctx_release(ctx->m2m_ctx);
677 gsc_ctrls_delete(ctx);
678 v4l2_fh_del(&ctx->fh);
679 v4l2_fh_exit(&ctx->fh);
681 if (--gsc->m2m.refcnt <= 0)
682 clear_bit(ST_M2M_OPEN, &gsc->state);
685 mutex_unlock(&gsc->lock);
689 static unsigned int gsc_m2m_poll(struct file *file,
690 struct poll_table_struct *wait)
692 struct gsc_ctx *ctx = fh_to_ctx(file->private_data);
693 struct gsc_dev *gsc = ctx->gsc_dev;
696 if (mutex_lock_interruptible(&gsc->lock))
699 ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
700 mutex_unlock(&gsc->lock);
705 static int gsc_m2m_mmap(struct file *file, struct vm_area_struct *vma)
707 struct gsc_ctx *ctx = fh_to_ctx(file->private_data);
708 struct gsc_dev *gsc = ctx->gsc_dev;
711 if (mutex_lock_interruptible(&gsc->lock))
714 ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
715 mutex_unlock(&gsc->lock);
720 static const struct v4l2_file_operations gsc_m2m_fops = {
721 .owner = THIS_MODULE,
722 .open = gsc_m2m_open,
723 .release = gsc_m2m_release,
724 .poll = gsc_m2m_poll,
725 .unlocked_ioctl = video_ioctl2,
726 .mmap = gsc_m2m_mmap,
729 static struct v4l2_m2m_ops gsc_m2m_ops = {
730 .device_run = gsc_m2m_device_run,
731 .job_abort = gsc_m2m_job_abort,
734 int gsc_register_m2m_device(struct gsc_dev *gsc)
736 struct platform_device *pdev;
744 gsc->vdev.fops = &gsc_m2m_fops;
745 gsc->vdev.ioctl_ops = &gsc_m2m_ioctl_ops;
746 gsc->vdev.release = video_device_release_empty;
747 gsc->vdev.lock = &gsc->lock;
748 gsc->vdev.vfl_dir = VFL_DIR_M2M;
749 snprintf(gsc->vdev.name, sizeof(gsc->vdev.name), "%s.%d:m2m",
750 GSC_MODULE_NAME, gsc->id);
752 video_set_drvdata(&gsc->vdev, gsc);
754 gsc->m2m.vfd = &gsc->vdev;
755 gsc->m2m.m2m_dev = v4l2_m2m_init(&gsc_m2m_ops);
756 if (IS_ERR(gsc->m2m.m2m_dev)) {
757 dev_err(&pdev->dev, "failed to initialize v4l2-m2m device\n");
758 ret = PTR_ERR(gsc->m2m.m2m_dev);
762 ret = video_register_device(&gsc->vdev, VFL_TYPE_GRABBER, -1);
765 "%s(): failed to register video device\n", __func__);
769 pr_debug("gsc m2m driver registered as /dev/video%d", gsc->vdev.num);
773 v4l2_m2m_release(gsc->m2m.m2m_dev);
775 video_device_release(gsc->m2m.vfd);
780 void gsc_unregister_m2m_device(struct gsc_dev *gsc)
783 v4l2_m2m_release(gsc->m2m.m2m_dev);