13 #include <linux/module.h>
15 #include <linux/version.h>
17 #include <linux/sched.h>
18 #include <linux/slab.h>
32 #define fh2ctx(__fh) container_of(__fh, struct g2d_ctx, fh)
60 .name =
"PACKED_RGB_888",
66 #define NUM_FORMATS ARRAY_SIZE(formats)
105 unsigned int *nbuffers,
unsigned int *nplanes,
106 unsigned int sizes[],
void *alloc_ctxs[])
108 struct g2d_ctx *ctx = vb2_get_drv_priv(vq);
116 alloc_ctxs[0] = ctx->
dev->alloc_ctx;
124 static int g2d_buf_prepare(
struct vb2_buffer *vb)
131 vb2_set_plane_payload(vb, 0, f->
size);
135 static void g2d_buf_queue(
struct vb2_buffer *vb)
142 static struct vb2_ops g2d_qops = {
143 .queue_setup = g2d_queue_setup,
144 .buf_prepare = g2d_buf_prepare,
145 .buf_queue = g2d_buf_queue,
157 src_vq->
ops = &g2d_qops;
168 dst_vq->
ops = &g2d_qops;
195 spin_unlock_irqrestore(&ctx->
dev->ctrl_lock, flags);
200 .s_ctrl = g2d_s_ctrl,
203 static int g2d_setup_ctrls(
struct g2d_ctx *ctx)
235 static int g2d_open(
struct file *
file)
237 struct g2d_dev *dev = video_drvdata(file);
247 ctx->
out = def_frame;
264 g2d_setup_ctrls(ctx);
276 static int g2d_release(
struct file *file)
278 struct g2d_dev *dev = video_drvdata(file);
290 static int vidioc_querycap(
struct file *file,
void *priv,
296 cap->
version = KERNEL_VERSION(1, 0, 0);
307 static int vidioc_enum_fmt(
struct file *file,
void *prv,
struct v4l2_fmtdesc *f)
310 if (f->
index >= NUM_FORMATS)
312 fmt = &formats[f->
index];
318 static int vidioc_g_fmt(
struct file *file,
void *prv,
struct v4l2_format *f)
327 frm = get_frame(ctx, f->
type);
334 f->
fmt.
pix.pixelformat = frm->
fmt->fourcc;
340 static int vidioc_try_fmt(
struct file *file,
void *prv,
struct v4l2_format *f)
349 field = &f->
fmt.
pix.field;
362 if (f->
fmt.
pix.height < 1)
370 static int vidioc_s_fmt(
struct file *file,
void *prv,
struct v4l2_format *f)
381 ret = vidioc_try_fmt(file, prv, f);
385 if (vb2_is_busy(vq)) {
389 frm = get_frame(ctx, f->
type);
422 static int g2d_mmap(
struct file *file,
struct vm_area_struct *vma)
435 static int vidioc_reqbufs(
struct file *file,
void *priv,
442 static int vidioc_querybuf(
struct file *file,
void *priv,
449 static int vidioc_qbuf(
struct file *file,
void *priv,
struct v4l2_buffer *
buf)
455 static int vidioc_dqbuf(
struct file *file,
void *priv,
struct v4l2_buffer *
buf)
462 static int vidioc_streamon(
struct file *file,
void *priv,
469 static int vidioc_streamoff(
struct file *file,
void *priv,
476 static int vidioc_cropcap(
struct file *file,
void *priv,
482 f = get_frame(ctx, cr->
type);
494 static int vidioc_g_crop(
struct file *file,
void *prv,
struct v4l2_crop *cr)
499 f = get_frame(ctx, cr->
type);
510 static int vidioc_try_crop(
struct file *file,
void *prv,
const struct v4l2_crop *cr)
516 f = get_frame(ctx, cr->
type);
520 if (cr->
c.top < 0 || cr->
c.left < 0) {
522 "doesn't support negative values for top & left\n");
529 static int vidioc_s_crop(
struct file *file,
void *prv,
const struct v4l2_crop *cr)
535 ret = vidioc_try_crop(file, prv, cr);
538 f = get_frame(ctx, cr->
type);
551 static void g2d_lock(
void *prv)
558 static void g2d_unlock(
void *prv)
565 static void job_abort(
void *prv)
579 static void device_run(
void *prv)
589 src = v4l2_m2m_next_src_buf(ctx->
m2m_ctx);
590 dst = v4l2_m2m_next_dst_buf(ctx->
m2m_ctx);
606 if (ctx->
in.c_width != ctx->
out.c_width ||
607 ctx->
in.c_height != ctx->
out.c_height)
612 spin_unlock_irqrestore(&dev->
ctrl_lock, flags);
626 src = v4l2_m2m_src_buf_remove(ctx->
m2m_ctx);
627 dst = v4l2_m2m_dst_buf_remove(ctx->
m2m_ctx);
644 .release = g2d_release,
653 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt,
654 .vidioc_g_fmt_vid_cap = vidioc_g_fmt,
655 .vidioc_try_fmt_vid_cap = vidioc_try_fmt,
656 .vidioc_s_fmt_vid_cap = vidioc_s_fmt,
658 .vidioc_enum_fmt_vid_out = vidioc_enum_fmt,
659 .vidioc_g_fmt_vid_out = vidioc_g_fmt,
660 .vidioc_try_fmt_vid_out = vidioc_try_fmt,
661 .vidioc_s_fmt_vid_out = vidioc_s_fmt,
680 .ioctl_ops = &g2d_ioctl_ops,
690 .unlock = g2d_unlock,
713 dev_err(&pdev->
dev,
"Failed to obtain io memory\n");
718 if (IS_ERR_OR_NULL(dev->
clk)) {
719 dev_err(&pdev->
dev,
"failed to get g2d clock\n");
725 dev_err(&pdev->
dev,
"failed to prepare g2d clock\n");
730 if (IS_ERR_OR_NULL(dev->
gate)) {
731 dev_err(&pdev->
dev,
"failed to get g2d clock gate\n");
738 dev_err(&pdev->
dev,
"failed to prepare g2d clock gate\n");
746 goto unprep_clk_gate;
751 ret = devm_request_irq(&pdev->
dev, dev->
irq, g2d_isr,
754 dev_err(&pdev->
dev,
"failed to install IRQ\n");
761 goto unprep_clk_gate;
766 goto alloc_ctx_cleanup;
780 video_set_drvdata(vfd, dev);
785 platform_set_drvdata(pdev, dev);
790 goto unreg_video_dev;
819 struct g2d_dev *dev = (
struct g2d_dev *)platform_get_drvdata(pdev);
835 .remove = g2d_remove,