1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "em28xx.h"
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/hardirq.h>
29#include <linux/init.h>
30#include <linux/usb.h>
31
32#include "em28xx-v4l.h"
33
34
35
36static int vbi_queue_setup(struct vb2_queue *vq,
37 unsigned int *nbuffers, unsigned int *nplanes,
38 unsigned int sizes[], struct device *alloc_devs[])
39{
40 struct em28xx *dev = vb2_get_drv_priv(vq);
41 struct em28xx_v4l2 *v4l2 = dev->v4l2;
42 unsigned long size = v4l2->vbi_width * v4l2->vbi_height * 2;
43
44 if (*nbuffers < 2)
45 *nbuffers = 2;
46
47 if (*nplanes) {
48 if (sizes[0] < size)
49 return -EINVAL;
50 size = sizes[0];
51 }
52
53 *nplanes = 1;
54 sizes[0] = size;
55
56 return 0;
57}
58
59static int vbi_buffer_prepare(struct vb2_buffer *vb)
60{
61 struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
62 struct em28xx_v4l2 *v4l2 = dev->v4l2;
63 unsigned long size;
64
65 size = v4l2->vbi_width * v4l2->vbi_height * 2;
66
67 if (vb2_plane_size(vb, 0) < size) {
68 dev_info(&dev->intf->dev,
69 "%s data will not fit into plane (%lu < %lu)\n",
70 __func__, vb2_plane_size(vb, 0), size);
71 return -EINVAL;
72 }
73 vb2_set_plane_payload(vb, 0, size);
74
75 return 0;
76}
77
78static void
79vbi_buffer_queue(struct vb2_buffer *vb)
80{
81 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
82 struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
83 struct em28xx_buffer *buf =
84 container_of(vbuf, struct em28xx_buffer, vb);
85 struct em28xx_dmaqueue *vbiq = &dev->vbiq;
86 unsigned long flags = 0;
87
88 buf->mem = vb2_plane_vaddr(vb, 0);
89 buf->length = vb2_plane_size(vb, 0);
90
91 spin_lock_irqsave(&dev->slock, flags);
92 list_add_tail(&buf->list, &vbiq->active);
93 spin_unlock_irqrestore(&dev->slock, flags);
94}
95
96struct vb2_ops em28xx_vbi_qops = {
97 .queue_setup = vbi_queue_setup,
98 .buf_prepare = vbi_buffer_prepare,
99 .buf_queue = vbi_buffer_queue,
100 .start_streaming = em28xx_start_analog_streaming,
101 .stop_streaming = em28xx_stop_vbi_streaming,
102 .wait_prepare = vb2_ops_wait_prepare,
103 .wait_finish = vb2_ops_wait_finish,
104};
105