2 * Samsung S5P G2D - 2D Graphics Accelerator Driver
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5 * Kamil Debski, <k.debski@samsung.com>
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 by the
9 * Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version
13 #include <linux/module.h>
15 #include <linux/timer.h>
16 #include <linux/sched.h>
17 #include <linux/slab.h>
18 #include <linux/clk.h>
19 #include <linux/interrupt.h>
22 #include <linux/platform_device.h>
23 #include <media/v4l2-mem2mem.h>
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-ioctl.h>
26 #include <media/videobuf2-v4l2.h>
27 #include <media/videobuf2-dma-contig.h>
32 #define fh2ctx(__fh) container_of(__fh, struct g2d_ctx, fh)
34 static struct g2d_fmt formats
[] = {
37 .fourcc
= V4L2_PIX_FMT_RGB32
,
39 .hw
= COLOR_MODE(ORDER_XRGB
, MODE_XRGB_8888
),
43 .fourcc
= V4L2_PIX_FMT_RGB565X
,
45 .hw
= COLOR_MODE(ORDER_XRGB
, MODE_RGB_565
),
49 .fourcc
= V4L2_PIX_FMT_RGB555X
,
51 .hw
= COLOR_MODE(ORDER_XRGB
, MODE_XRGB_1555
),
55 .fourcc
= V4L2_PIX_FMT_RGB444
,
57 .hw
= COLOR_MODE(ORDER_XRGB
, MODE_XRGB_4444
),
60 .name
= "PACKED_RGB_888",
61 .fourcc
= V4L2_PIX_FMT_RGB24
,
63 .hw
= COLOR_MODE(ORDER_XRGB
, MODE_PACKED_RGB_888
),
66 #define NUM_FORMATS ARRAY_SIZE(formats)
68 static struct g2d_frame def_frame
= {
69 .width
= DEFAULT_WIDTH
,
70 .height
= DEFAULT_HEIGHT
,
71 .c_width
= DEFAULT_WIDTH
,
72 .c_height
= DEFAULT_HEIGHT
,
76 .right
= DEFAULT_WIDTH
,
77 .bottom
= DEFAULT_HEIGHT
,
80 static struct g2d_fmt
*find_fmt(struct v4l2_format
*f
)
83 for (i
= 0; i
< NUM_FORMATS
; i
++) {
84 if (formats
[i
].fourcc
== f
->fmt
.pix
.pixelformat
)
91 static struct g2d_frame
*get_frame(struct g2d_ctx
*ctx
,
92 enum v4l2_buf_type type
)
95 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
97 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
100 return ERR_PTR(-EINVAL
);
104 static int g2d_queue_setup(struct vb2_queue
*vq
,
105 unsigned int *nbuffers
, unsigned int *nplanes
,
106 unsigned int sizes
[], struct device
*alloc_devs
[])
108 struct g2d_ctx
*ctx
= vb2_get_drv_priv(vq
);
109 struct g2d_frame
*f
= get_frame(ctx
, vq
->type
);
123 static int g2d_buf_prepare(struct vb2_buffer
*vb
)
125 struct g2d_ctx
*ctx
= vb2_get_drv_priv(vb
->vb2_queue
);
126 struct g2d_frame
*f
= get_frame(ctx
, vb
->vb2_queue
->type
);
130 vb2_set_plane_payload(vb
, 0, f
->size
);
134 static void g2d_buf_queue(struct vb2_buffer
*vb
)
136 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
137 struct g2d_ctx
*ctx
= vb2_get_drv_priv(vb
->vb2_queue
);
138 v4l2_m2m_buf_queue(ctx
->fh
.m2m_ctx
, vbuf
);
141 static const struct vb2_ops g2d_qops
= {
142 .queue_setup
= g2d_queue_setup
,
143 .buf_prepare
= g2d_buf_prepare
,
144 .buf_queue
= g2d_buf_queue
,
145 .wait_prepare
= vb2_ops_wait_prepare
,
146 .wait_finish
= vb2_ops_wait_finish
,
149 static int queue_init(void *priv
, struct vb2_queue
*src_vq
,
150 struct vb2_queue
*dst_vq
)
152 struct g2d_ctx
*ctx
= priv
;
155 src_vq
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
156 src_vq
->io_modes
= VB2_MMAP
| VB2_USERPTR
;
157 src_vq
->drv_priv
= ctx
;
158 src_vq
->ops
= &g2d_qops
;
159 src_vq
->mem_ops
= &vb2_dma_contig_memops
;
160 src_vq
->buf_struct_size
= sizeof(struct v4l2_m2m_buffer
);
161 src_vq
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_COPY
;
162 src_vq
->lock
= &ctx
->dev
->mutex
;
163 src_vq
->dev
= ctx
->dev
->v4l2_dev
.dev
;
165 ret
= vb2_queue_init(src_vq
);
169 dst_vq
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
170 dst_vq
->io_modes
= VB2_MMAP
| VB2_USERPTR
;
171 dst_vq
->drv_priv
= ctx
;
172 dst_vq
->ops
= &g2d_qops
;
173 dst_vq
->mem_ops
= &vb2_dma_contig_memops
;
174 dst_vq
->buf_struct_size
= sizeof(struct v4l2_m2m_buffer
);
175 dst_vq
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_COPY
;
176 dst_vq
->lock
= &ctx
->dev
->mutex
;
177 dst_vq
->dev
= ctx
->dev
->v4l2_dev
.dev
;
179 return vb2_queue_init(dst_vq
);
182 static int g2d_s_ctrl(struct v4l2_ctrl
*ctrl
)
184 struct g2d_ctx
*ctx
= container_of(ctrl
->handler
, struct g2d_ctx
,
188 spin_lock_irqsave(&ctx
->dev
->ctrl_lock
, flags
);
190 case V4L2_CID_COLORFX
:
191 if (ctrl
->val
== V4L2_COLORFX_NEGATIVE
)
192 ctx
->rop
= ROP4_INVERT
;
194 ctx
->rop
= ROP4_COPY
;
198 ctx
->flip
= ctx
->ctrl_hflip
->val
| (ctx
->ctrl_vflip
->val
<< 1);
202 spin_unlock_irqrestore(&ctx
->dev
->ctrl_lock
, flags
);
206 static const struct v4l2_ctrl_ops g2d_ctrl_ops
= {
207 .s_ctrl
= g2d_s_ctrl
,
210 static int g2d_setup_ctrls(struct g2d_ctx
*ctx
)
212 struct g2d_dev
*dev
= ctx
->dev
;
214 v4l2_ctrl_handler_init(&ctx
->ctrl_handler
, 3);
216 ctx
->ctrl_hflip
= v4l2_ctrl_new_std(&ctx
->ctrl_handler
, &g2d_ctrl_ops
,
217 V4L2_CID_HFLIP
, 0, 1, 1, 0);
219 ctx
->ctrl_vflip
= v4l2_ctrl_new_std(&ctx
->ctrl_handler
, &g2d_ctrl_ops
,
220 V4L2_CID_VFLIP
, 0, 1, 1, 0);
222 v4l2_ctrl_new_std_menu(
226 V4L2_COLORFX_NEGATIVE
,
227 ~((1 << V4L2_COLORFX_NONE
) | (1 << V4L2_COLORFX_NEGATIVE
)),
230 if (ctx
->ctrl_handler
.error
) {
231 int err
= ctx
->ctrl_handler
.error
;
232 v4l2_err(&dev
->v4l2_dev
, "g2d_setup_ctrls failed\n");
233 v4l2_ctrl_handler_free(&ctx
->ctrl_handler
);
237 v4l2_ctrl_cluster(2, &ctx
->ctrl_hflip
);
242 static int g2d_open(struct file
*file
)
244 struct g2d_dev
*dev
= video_drvdata(file
);
245 struct g2d_ctx
*ctx
= NULL
;
248 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
252 /* Set default formats */
254 ctx
->out
= def_frame
;
256 if (mutex_lock_interruptible(&dev
->mutex
)) {
260 ctx
->fh
.m2m_ctx
= v4l2_m2m_ctx_init(dev
->m2m_dev
, ctx
, &queue_init
);
261 if (IS_ERR(ctx
->fh
.m2m_ctx
)) {
262 ret
= PTR_ERR(ctx
->fh
.m2m_ctx
);
263 mutex_unlock(&dev
->mutex
);
267 v4l2_fh_init(&ctx
->fh
, video_devdata(file
));
268 file
->private_data
= &ctx
->fh
;
269 v4l2_fh_add(&ctx
->fh
);
271 g2d_setup_ctrls(ctx
);
273 /* Write the default values to the ctx struct */
274 v4l2_ctrl_handler_setup(&ctx
->ctrl_handler
);
276 ctx
->fh
.ctrl_handler
= &ctx
->ctrl_handler
;
277 mutex_unlock(&dev
->mutex
);
279 v4l2_info(&dev
->v4l2_dev
, "instance opened\n");
283 static int g2d_release(struct file
*file
)
285 struct g2d_dev
*dev
= video_drvdata(file
);
286 struct g2d_ctx
*ctx
= fh2ctx(file
->private_data
);
288 v4l2_ctrl_handler_free(&ctx
->ctrl_handler
);
289 v4l2_fh_del(&ctx
->fh
);
290 v4l2_fh_exit(&ctx
->fh
);
292 v4l2_info(&dev
->v4l2_dev
, "instance closed\n");
297 static int vidioc_querycap(struct file
*file
, void *priv
,
298 struct v4l2_capability
*cap
)
300 strncpy(cap
->driver
, G2D_NAME
, sizeof(cap
->driver
) - 1);
301 strncpy(cap
->card
, G2D_NAME
, sizeof(cap
->card
) - 1);
302 cap
->bus_info
[0] = 0;
303 cap
->device_caps
= V4L2_CAP_VIDEO_M2M
| V4L2_CAP_STREAMING
;
304 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
308 static int vidioc_enum_fmt(struct file
*file
, void *prv
, struct v4l2_fmtdesc
*f
)
311 if (f
->index
>= NUM_FORMATS
)
313 fmt
= &formats
[f
->index
];
314 f
->pixelformat
= fmt
->fourcc
;
315 strncpy(f
->description
, fmt
->name
, sizeof(f
->description
) - 1);
319 static int vidioc_g_fmt(struct file
*file
, void *prv
, struct v4l2_format
*f
)
321 struct g2d_ctx
*ctx
= prv
;
322 struct vb2_queue
*vq
;
323 struct g2d_frame
*frm
;
325 vq
= v4l2_m2m_get_vq(ctx
->fh
.m2m_ctx
, f
->type
);
328 frm
= get_frame(ctx
, f
->type
);
332 f
->fmt
.pix
.width
= frm
->width
;
333 f
->fmt
.pix
.height
= frm
->height
;
334 f
->fmt
.pix
.field
= V4L2_FIELD_NONE
;
335 f
->fmt
.pix
.pixelformat
= frm
->fmt
->fourcc
;
336 f
->fmt
.pix
.bytesperline
= (frm
->width
* frm
->fmt
->depth
) >> 3;
337 f
->fmt
.pix
.sizeimage
= frm
->size
;
341 static int vidioc_try_fmt(struct file
*file
, void *prv
, struct v4l2_format
*f
)
344 enum v4l2_field
*field
;
350 field
= &f
->fmt
.pix
.field
;
351 if (*field
== V4L2_FIELD_ANY
)
352 *field
= V4L2_FIELD_NONE
;
353 else if (*field
!= V4L2_FIELD_NONE
)
356 if (f
->fmt
.pix
.width
> MAX_WIDTH
)
357 f
->fmt
.pix
.width
= MAX_WIDTH
;
358 if (f
->fmt
.pix
.height
> MAX_HEIGHT
)
359 f
->fmt
.pix
.height
= MAX_HEIGHT
;
361 if (f
->fmt
.pix
.width
< 1)
362 f
->fmt
.pix
.width
= 1;
363 if (f
->fmt
.pix
.height
< 1)
364 f
->fmt
.pix
.height
= 1;
366 f
->fmt
.pix
.bytesperline
= (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
367 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
371 static int vidioc_s_fmt(struct file
*file
, void *prv
, struct v4l2_format
*f
)
373 struct g2d_ctx
*ctx
= prv
;
374 struct g2d_dev
*dev
= ctx
->dev
;
375 struct vb2_queue
*vq
;
376 struct g2d_frame
*frm
;
380 /* Adjust all values accordingly to the hardware capabilities
381 * and chosen format. */
382 ret
= vidioc_try_fmt(file
, prv
, f
);
385 vq
= v4l2_m2m_get_vq(ctx
->fh
.m2m_ctx
, f
->type
);
386 if (vb2_is_busy(vq
)) {
387 v4l2_err(&dev
->v4l2_dev
, "queue (%d) bust\n", f
->type
);
390 frm
= get_frame(ctx
, f
->type
);
396 frm
->width
= f
->fmt
.pix
.width
;
397 frm
->height
= f
->fmt
.pix
.height
;
398 frm
->size
= f
->fmt
.pix
.sizeimage
;
399 /* Reset crop settings */
402 frm
->c_width
= frm
->width
;
403 frm
->c_height
= frm
->height
;
404 frm
->right
= frm
->width
;
405 frm
->bottom
= frm
->height
;
407 frm
->stride
= f
->fmt
.pix
.bytesperline
;
411 static int vidioc_g_selection(struct file
*file
, void *prv
,
412 struct v4l2_selection
*s
)
414 struct g2d_ctx
*ctx
= prv
;
417 f
= get_frame(ctx
, s
->type
);
422 case V4L2_SEL_TGT_CROP
:
423 case V4L2_SEL_TGT_CROP_DEFAULT
:
424 case V4L2_SEL_TGT_CROP_BOUNDS
:
425 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
428 case V4L2_SEL_TGT_COMPOSE
:
429 case V4L2_SEL_TGT_COMPOSE_DEFAULT
:
430 case V4L2_SEL_TGT_COMPOSE_BOUNDS
:
431 if (s
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
439 case V4L2_SEL_TGT_CROP
:
440 case V4L2_SEL_TGT_COMPOSE
:
441 s
->r
.left
= f
->o_height
;
442 s
->r
.top
= f
->o_width
;
443 s
->r
.width
= f
->c_width
;
444 s
->r
.height
= f
->c_height
;
446 case V4L2_SEL_TGT_CROP_DEFAULT
:
447 case V4L2_SEL_TGT_CROP_BOUNDS
:
448 case V4L2_SEL_TGT_COMPOSE_DEFAULT
:
449 case V4L2_SEL_TGT_COMPOSE_BOUNDS
:
452 s
->r
.width
= f
->width
;
453 s
->r
.height
= f
->height
;
461 static int vidioc_try_selection(struct file
*file
, void *prv
,
462 const struct v4l2_selection
*s
)
464 struct g2d_ctx
*ctx
= prv
;
465 struct g2d_dev
*dev
= ctx
->dev
;
468 f
= get_frame(ctx
, s
->type
);
472 if (s
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
473 if (s
->target
!= V4L2_SEL_TGT_COMPOSE
)
475 } else if (s
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
) {
476 if (s
->target
!= V4L2_SEL_TGT_CROP
)
480 if (s
->r
.top
< 0 || s
->r
.left
< 0) {
481 v4l2_err(&dev
->v4l2_dev
,
482 "doesn't support negative values for top & left\n");
489 static int vidioc_s_selection(struct file
*file
, void *prv
,
490 struct v4l2_selection
*s
)
492 struct g2d_ctx
*ctx
= prv
;
496 ret
= vidioc_try_selection(file
, prv
, s
);
499 f
= get_frame(ctx
, s
->type
);
503 f
->c_width
= s
->r
.width
;
504 f
->c_height
= s
->r
.height
;
505 f
->o_width
= s
->r
.left
;
506 f
->o_height
= s
->r
.top
;
507 f
->bottom
= f
->o_height
+ f
->c_height
;
508 f
->right
= f
->o_width
+ f
->c_width
;
512 static void device_run(void *prv
)
514 struct g2d_ctx
*ctx
= prv
;
515 struct g2d_dev
*dev
= ctx
->dev
;
516 struct vb2_v4l2_buffer
*src
, *dst
;
522 src
= v4l2_m2m_next_src_buf(ctx
->fh
.m2m_ctx
);
523 dst
= v4l2_m2m_next_dst_buf(ctx
->fh
.m2m_ctx
);
525 clk_enable(dev
->gate
);
528 spin_lock_irqsave(&dev
->ctrl_lock
, flags
);
530 g2d_set_src_size(dev
, &ctx
->in
);
531 g2d_set_src_addr(dev
, vb2_dma_contig_plane_dma_addr(&src
->vb2_buf
, 0));
533 g2d_set_dst_size(dev
, &ctx
->out
);
534 g2d_set_dst_addr(dev
, vb2_dma_contig_plane_dma_addr(&dst
->vb2_buf
, 0));
536 g2d_set_rop4(dev
, ctx
->rop
);
537 g2d_set_flip(dev
, ctx
->flip
);
539 if (ctx
->in
.c_width
!= ctx
->out
.c_width
||
540 ctx
->in
.c_height
!= ctx
->out
.c_height
) {
541 if (dev
->variant
->hw_rev
== TYPE_G2D_3X
)
542 cmd
|= CMD_V3_ENABLE_STRETCH
;
544 g2d_set_v41_stretch(dev
, &ctx
->in
, &ctx
->out
);
547 g2d_set_cmd(dev
, cmd
);
550 spin_unlock_irqrestore(&dev
->ctrl_lock
, flags
);
553 static irqreturn_t
g2d_isr(int irq
, void *prv
)
555 struct g2d_dev
*dev
= prv
;
556 struct g2d_ctx
*ctx
= dev
->curr
;
557 struct vb2_v4l2_buffer
*src
, *dst
;
560 clk_disable(dev
->gate
);
564 src
= v4l2_m2m_src_buf_remove(ctx
->fh
.m2m_ctx
);
565 dst
= v4l2_m2m_dst_buf_remove(ctx
->fh
.m2m_ctx
);
570 dst
->timecode
= src
->timecode
;
571 dst
->vb2_buf
.timestamp
= src
->vb2_buf
.timestamp
;
572 dst
->flags
&= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK
;
574 src
->flags
& V4L2_BUF_FLAG_TSTAMP_SRC_MASK
;
576 v4l2_m2m_buf_done(src
, VB2_BUF_STATE_DONE
);
577 v4l2_m2m_buf_done(dst
, VB2_BUF_STATE_DONE
);
578 v4l2_m2m_job_finish(dev
->m2m_dev
, ctx
->fh
.m2m_ctx
);
584 static const struct v4l2_file_operations g2d_fops
= {
585 .owner
= THIS_MODULE
,
587 .release
= g2d_release
,
588 .poll
= v4l2_m2m_fop_poll
,
589 .unlocked_ioctl
= video_ioctl2
,
590 .mmap
= v4l2_m2m_fop_mmap
,
593 static const struct v4l2_ioctl_ops g2d_ioctl_ops
= {
594 .vidioc_querycap
= vidioc_querycap
,
596 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt
,
597 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt
,
598 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt
,
599 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt
,
601 .vidioc_enum_fmt_vid_out
= vidioc_enum_fmt
,
602 .vidioc_g_fmt_vid_out
= vidioc_g_fmt
,
603 .vidioc_try_fmt_vid_out
= vidioc_try_fmt
,
604 .vidioc_s_fmt_vid_out
= vidioc_s_fmt
,
606 .vidioc_reqbufs
= v4l2_m2m_ioctl_reqbufs
,
607 .vidioc_querybuf
= v4l2_m2m_ioctl_querybuf
,
608 .vidioc_qbuf
= v4l2_m2m_ioctl_qbuf
,
609 .vidioc_dqbuf
= v4l2_m2m_ioctl_dqbuf
,
611 .vidioc_streamon
= v4l2_m2m_ioctl_streamon
,
612 .vidioc_streamoff
= v4l2_m2m_ioctl_streamoff
,
614 .vidioc_g_selection
= vidioc_g_selection
,
615 .vidioc_s_selection
= vidioc_s_selection
,
618 static const struct video_device g2d_videodev
= {
621 .ioctl_ops
= &g2d_ioctl_ops
,
623 .release
= video_device_release
,
624 .vfl_dir
= VFL_DIR_M2M
,
627 static const struct v4l2_m2m_ops g2d_m2m_ops
= {
628 .device_run
= device_run
,
631 static const struct of_device_id exynos_g2d_match
[];
633 static int g2d_probe(struct platform_device
*pdev
)
636 struct video_device
*vfd
;
637 struct resource
*res
;
638 const struct of_device_id
*of_id
;
641 dev
= devm_kzalloc(&pdev
->dev
, sizeof(*dev
), GFP_KERNEL
);
645 spin_lock_init(&dev
->ctrl_lock
);
646 mutex_init(&dev
->mutex
);
647 atomic_set(&dev
->num_inst
, 0);
649 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
651 dev
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
652 if (IS_ERR(dev
->regs
))
653 return PTR_ERR(dev
->regs
);
655 dev
->clk
= clk_get(&pdev
->dev
, "sclk_fimg2d");
656 if (IS_ERR(dev
->clk
)) {
657 dev_err(&pdev
->dev
, "failed to get g2d clock\n");
661 ret
= clk_prepare(dev
->clk
);
663 dev_err(&pdev
->dev
, "failed to prepare g2d clock\n");
667 dev
->gate
= clk_get(&pdev
->dev
, "fimg2d");
668 if (IS_ERR(dev
->gate
)) {
669 dev_err(&pdev
->dev
, "failed to get g2d clock gate\n");
674 ret
= clk_prepare(dev
->gate
);
676 dev_err(&pdev
->dev
, "failed to prepare g2d clock gate\n");
680 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
682 dev_err(&pdev
->dev
, "failed to find IRQ\n");
684 goto unprep_clk_gate
;
687 dev
->irq
= res
->start
;
689 ret
= devm_request_irq(&pdev
->dev
, dev
->irq
, g2d_isr
,
692 dev_err(&pdev
->dev
, "failed to install IRQ\n");
693 goto unprep_clk_gate
;
696 vb2_dma_contig_set_max_seg_size(&pdev
->dev
, DMA_BIT_MASK(32));
698 ret
= v4l2_device_register(&pdev
->dev
, &dev
->v4l2_dev
);
700 goto unprep_clk_gate
;
701 vfd
= video_device_alloc();
703 v4l2_err(&dev
->v4l2_dev
, "Failed to allocate video device\n");
708 set_bit(V4L2_FL_QUIRK_INVERTED_CROP
, &vfd
->flags
);
709 vfd
->lock
= &dev
->mutex
;
710 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
711 ret
= video_register_device(vfd
, VFL_TYPE_GRABBER
, 0);
713 v4l2_err(&dev
->v4l2_dev
, "Failed to register video device\n");
716 video_set_drvdata(vfd
, dev
);
718 v4l2_info(&dev
->v4l2_dev
, "device registered as /dev/video%d\n",
720 platform_set_drvdata(pdev
, dev
);
721 dev
->m2m_dev
= v4l2_m2m_init(&g2d_m2m_ops
);
722 if (IS_ERR(dev
->m2m_dev
)) {
723 v4l2_err(&dev
->v4l2_dev
, "Failed to init mem2mem device\n");
724 ret
= PTR_ERR(dev
->m2m_dev
);
725 goto unreg_video_dev
;
728 def_frame
.stride
= (def_frame
.width
* def_frame
.fmt
->depth
) >> 3;
730 of_id
= of_match_node(exynos_g2d_match
, pdev
->dev
.of_node
);
733 goto unreg_video_dev
;
735 dev
->variant
= (struct g2d_variant
*)of_id
->data
;
740 video_unregister_device(dev
->vfd
);
742 video_device_release(vfd
);
744 v4l2_device_unregister(&dev
->v4l2_dev
);
746 clk_unprepare(dev
->gate
);
750 clk_unprepare(dev
->clk
);
757 static int g2d_remove(struct platform_device
*pdev
)
759 struct g2d_dev
*dev
= platform_get_drvdata(pdev
);
761 v4l2_info(&dev
->v4l2_dev
, "Removing " G2D_NAME
);
762 v4l2_m2m_release(dev
->m2m_dev
);
763 video_unregister_device(dev
->vfd
);
764 v4l2_device_unregister(&dev
->v4l2_dev
);
765 vb2_dma_contig_clear_max_seg_size(&pdev
->dev
);
766 clk_unprepare(dev
->gate
);
768 clk_unprepare(dev
->clk
);
773 static struct g2d_variant g2d_drvdata_v3x
= {
774 .hw_rev
= TYPE_G2D_3X
, /* Revision 3.0 for S5PV210 and Exynos4210 */
777 static struct g2d_variant g2d_drvdata_v4x
= {
778 .hw_rev
= TYPE_G2D_4X
, /* Revision 4.1 for Exynos4X12 and Exynos5 */
781 static const struct of_device_id exynos_g2d_match
[] = {
783 .compatible
= "samsung,s5pv210-g2d",
784 .data
= &g2d_drvdata_v3x
,
786 .compatible
= "samsung,exynos4212-g2d",
787 .data
= &g2d_drvdata_v4x
,
791 MODULE_DEVICE_TABLE(of
, exynos_g2d_match
);
793 static struct platform_driver g2d_pdrv
= {
795 .remove
= g2d_remove
,
798 .of_match_table
= exynos_g2d_match
,
802 module_platform_driver(g2d_pdrv
);
804 MODULE_AUTHOR("Kamil Debski <k.debski@samsung.com>");
805 MODULE_DESCRIPTION("S5P G2D 2d graphics accelerator driver");
806 MODULE_LICENSE("GPL");