102
void cx18_dma_free(struct videobuf_queue *q,
103
struct cx18_stream *s, struct cx18_videobuf_buffer *buf)
105
videobuf_waiton(q, &buf->vb, 0, 0);
106
videobuf_vmalloc_free(&buf->vb);
107
buf->vb.state = VIDEOBUF_NEEDS_INIT;
110
static int cx18_prepare_buffer(struct videobuf_queue *q,
111
struct cx18_stream *s,
112
struct cx18_videobuf_buffer *buf,
114
unsigned int width, unsigned int height,
115
enum v4l2_field field)
117
struct cx18 *cx = s->cx;
123
if ((width < 48) || (height < 32))
126
buf->vb.size = (width * height * 2);
127
if ((buf->vb.baddr != 0) && (buf->vb.bsize < buf->vb.size))
130
/* alloc + fill struct (if changed) */
131
if (buf->vb.width != width || buf->vb.height != height ||
132
buf->vb.field != field || s->pixelformat != pixelformat ||
133
buf->tvnorm != cx->std) {
135
buf->vb.width = width;
136
buf->vb.height = height;
137
buf->vb.field = field;
138
buf->tvnorm = cx->std;
139
s->pixelformat = pixelformat;
141
cx18_dma_free(q, s, buf);
144
if ((buf->vb.baddr != 0) && (buf->vb.bsize < buf->vb.size))
147
if (buf->vb.field == 0)
148
buf->vb.field = V4L2_FIELD_INTERLACED;
150
if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
151
buf->vb.width = width;
152
buf->vb.height = height;
153
buf->vb.field = field;
154
buf->tvnorm = cx->std;
155
s->pixelformat = pixelformat;
157
rc = videobuf_iolock(q, &buf->vb, NULL);
161
buf->vb.state = VIDEOBUF_PREPARED;
165
cx18_dma_free(q, s, buf);
170
/* VB_MIN_BUFSIZE is lcm(1440 * 480, 1440 * 576)
171
1440 is a single line of 4:2:2 YUV at 720 luma samples wide
173
#define VB_MIN_BUFFERS 32
174
#define VB_MIN_BUFSIZE 4147200
176
static int buffer_setup(struct videobuf_queue *q,
177
unsigned int *count, unsigned int *size)
179
struct cx18_stream *s = q->priv_data;
180
struct cx18 *cx = s->cx;
182
*size = 2 * cx->cxhdl.width * cx->cxhdl.height;
184
*count = VB_MIN_BUFFERS;
186
while (*size * *count > VB_MIN_BUFFERS * VB_MIN_BUFSIZE)
189
q->field = V4L2_FIELD_INTERLACED;
190
q->last = V4L2_FIELD_INTERLACED;
195
static int buffer_prepare(struct videobuf_queue *q,
196
struct videobuf_buffer *vb,
197
enum v4l2_field field)
199
struct cx18_videobuf_buffer *buf =
200
container_of(vb, struct cx18_videobuf_buffer, vb);
201
struct cx18_stream *s = q->priv_data;
202
struct cx18 *cx = s->cx;
204
return cx18_prepare_buffer(q, s, buf, s->pixelformat,
205
cx->cxhdl.width, cx->cxhdl.height, field);
208
static void buffer_release(struct videobuf_queue *q,
209
struct videobuf_buffer *vb)
211
struct cx18_videobuf_buffer *buf =
212
container_of(vb, struct cx18_videobuf_buffer, vb);
213
struct cx18_stream *s = q->priv_data;
215
cx18_dma_free(q, s, buf);
218
static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
220
struct cx18_videobuf_buffer *buf =
221
container_of(vb, struct cx18_videobuf_buffer, vb);
222
struct cx18_stream *s = q->priv_data;
224
buf->vb.state = VIDEOBUF_QUEUED;
226
list_add_tail(&buf->vb.queue, &s->vb_capture);
229
static struct videobuf_queue_ops cx18_videobuf_qops = {
230
.buf_setup = buffer_setup,
231
.buf_prepare = buffer_prepare,
232
.buf_queue = buffer_queue,
233
.buf_release = buffer_release,
100
236
static void cx18_stream_init(struct cx18 *cx, int type)
102
238
struct cx18_stream *s = &cx->streams[type];
132
268
cx18_queue_init(&s->q_idle);
134
270
INIT_WORK(&s->out_work_order, cx18_out_work_handler);
272
INIT_LIST_HEAD(&s->vb_capture);
273
s->vb_timeout.function = cx18_vb_timeout;
274
s->vb_timeout.data = (unsigned long)s;
275
init_timer(&s->vb_timeout);
276
spin_lock_init(&s->vb_lock);
277
if (type == CX18_ENC_STREAM_TYPE_YUV) {
278
spin_lock_init(&s->vbuf_q_lock);
280
s->vb_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
281
videobuf_queue_vmalloc_init(&s->vbuf_q, &cx18_videobuf_qops,
282
&cx->pci_dev->dev, &s->vbuf_q_lock,
283
V4L2_BUF_TYPE_VIDEO_CAPTURE,
284
V4L2_FIELD_INTERLACED,
285
sizeof(struct cx18_videobuf_buffer),
286
s, &cx->serialize_lock);
288
/* Assume the previous pixel default */
289
s->pixelformat = V4L2_PIX_FMT_HM12;
137
293
static int cx18_prep_dev(struct cx18 *cx, int type)
729
891
test_bit(CX18_F_I_RADIO_USER, &cx->i_flags))
730
892
cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2, s->handle,
731
893
(v4l2_ctrl_g_ctrl(cx->cxhdl.video_mute_yuv) << 8) | 1);
895
/* Enable the Video Format Converter for UYVY 4:2:2 support,
896
* rather than the default HM12 Macroblovk 4:2:0 support.
898
if (captype == CAPTURE_CHANNEL_TYPE_YUV) {
899
if (s->pixelformat == V4L2_PIX_FMT_UYVY)
900
cx18_vapi(cx, CX18_CPU_SET_VFC_PARAM, 2,
903
/* If in doubt, default to HM12 */
904
cx18_vapi(cx, CX18_CPU_SET_VFC_PARAM, 2,
734
909
if (atomic_read(&cx->tot_capturing) == 0) {