1 // SPDX-License-Identifier: GPL-2.0+
3 // em28xx-vbi.c - VBI driver for em28xx
5 // Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
7 // This work was sponsored by EyeMagnet Limited.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/hardirq.h>
14 #include <linux/init.h>
15 #include <linux/usb.h>
17 #include "em28xx-v4l.h"
19 /* ------------------------------------------------------------------ */
21 static int vbi_queue_setup(struct vb2_queue
*vq
,
22 unsigned int *nbuffers
, unsigned int *nplanes
,
23 unsigned int sizes
[], struct device
*alloc_devs
[])
25 struct em28xx
*dev
= vb2_get_drv_priv(vq
);
26 struct em28xx_v4l2
*v4l2
= dev
->v4l2
;
27 unsigned long size
= v4l2
->vbi_width
* v4l2
->vbi_height
* 2;
44 static int vbi_buffer_prepare(struct vb2_buffer
*vb
)
46 struct em28xx
*dev
= vb2_get_drv_priv(vb
->vb2_queue
);
47 struct em28xx_v4l2
*v4l2
= dev
->v4l2
;
50 size
= v4l2
->vbi_width
* v4l2
->vbi_height
* 2;
52 if (vb2_plane_size(vb
, 0) < size
) {
53 dev_info(&dev
->intf
->dev
,
54 "%s data will not fit into plane (%lu < %lu)\n",
55 __func__
, vb2_plane_size(vb
, 0), size
);
58 vb2_set_plane_payload(vb
, 0, size
);
64 vbi_buffer_queue(struct vb2_buffer
*vb
)
66 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
67 struct em28xx
*dev
= vb2_get_drv_priv(vb
->vb2_queue
);
68 struct em28xx_buffer
*buf
=
69 container_of(vbuf
, struct em28xx_buffer
, vb
);
70 struct em28xx_dmaqueue
*vbiq
= &dev
->vbiq
;
71 unsigned long flags
= 0;
73 buf
->mem
= vb2_plane_vaddr(vb
, 0);
74 buf
->length
= vb2_plane_size(vb
, 0);
76 spin_lock_irqsave(&dev
->slock
, flags
);
77 list_add_tail(&buf
->list
, &vbiq
->active
);
78 spin_unlock_irqrestore(&dev
->slock
, flags
);
81 const struct vb2_ops em28xx_vbi_qops
= {
82 .queue_setup
= vbi_queue_setup
,
83 .buf_prepare
= vbi_buffer_prepare
,
84 .buf_queue
= vbi_buffer_queue
,
85 .start_streaming
= em28xx_start_analog_streaming
,
86 .stop_streaming
= em28xx_stop_vbi_streaming
,