]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/media/video/cx18/cx18-streams.c
V4L/DVB (9132): cx18: Fix warning message for DMA done notification for inactive...
[net-next-2.6.git] / drivers / media / video / cx18 / cx18-streams.c
CommitLineData
1c1e45d1
HV
1/*
2 * cx18 init/start/stop/exit stream functions
3 *
4 * Derived from ivtv-streams.c
5 *
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 * 02111-1307 USA
22 */
23
24#include "cx18-driver.h"
b1526421 25#include "cx18-io.h"
1c1e45d1
HV
26#include "cx18-fileops.h"
27#include "cx18-mailbox.h"
28#include "cx18-i2c.h"
29#include "cx18-queue.h"
30#include "cx18-ioctl.h"
31#include "cx18-streams.h"
32#include "cx18-cards.h"
33#include "cx18-scb.h"
34#include "cx18-av-core.h"
35#include "cx18-dvb.h"
36
37#define CX18_DSP0_INTERRUPT_MASK 0xd0004C
38
39static struct file_operations cx18_v4l2_enc_fops = {
daf20d95
HV
40 .owner = THIS_MODULE,
41 .read = cx18_v4l2_read,
42 .open = cx18_v4l2_open,
3b6fe58f 43 /* FIXME change to video_ioctl2 if serialization lock can be removed */
daf20d95
HV
44 .ioctl = cx18_v4l2_ioctl,
45 .compat_ioctl = v4l_compat_ioctl32,
46 .release = cx18_v4l2_close,
47 .poll = cx18_v4l2_enc_poll,
1c1e45d1
HV
48};
49
50/* offset from 0 to register ts v4l2 minors on */
51#define CX18_V4L2_ENC_TS_OFFSET 16
52/* offset from 0 to register pcm v4l2 minors on */
53#define CX18_V4L2_ENC_PCM_OFFSET 24
54/* offset from 0 to register yuv v4l2 minors on */
55#define CX18_V4L2_ENC_YUV_OFFSET 32
56
57static struct {
58 const char *name;
59 int vfl_type;
60 int minor_offset;
61 int dma;
62 enum v4l2_buf_type buf_type;
63 struct file_operations *fops;
64} cx18_stream_info[] = {
65 { /* CX18_ENC_STREAM_TYPE_MPG */
66 "encoder MPEG",
67 VFL_TYPE_GRABBER, 0,
68 PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
69 &cx18_v4l2_enc_fops
70 },
71 { /* CX18_ENC_STREAM_TYPE_TS */
72 "TS",
73 VFL_TYPE_GRABBER, -1,
74 PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
75 &cx18_v4l2_enc_fops
76 },
77 { /* CX18_ENC_STREAM_TYPE_YUV */
78 "encoder YUV",
79 VFL_TYPE_GRABBER, CX18_V4L2_ENC_YUV_OFFSET,
80 PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
81 &cx18_v4l2_enc_fops
82 },
83 { /* CX18_ENC_STREAM_TYPE_VBI */
84 "encoder VBI",
85 VFL_TYPE_VBI, 0,
86 PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VBI_CAPTURE,
87 &cx18_v4l2_enc_fops
88 },
89 { /* CX18_ENC_STREAM_TYPE_PCM */
90 "encoder PCM audio",
91 VFL_TYPE_GRABBER, CX18_V4L2_ENC_PCM_OFFSET,
92 PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_PRIVATE,
93 &cx18_v4l2_enc_fops
94 },
95 { /* CX18_ENC_STREAM_TYPE_IDX */
96 "encoder IDX",
97 VFL_TYPE_GRABBER, -1,
98 PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
99 &cx18_v4l2_enc_fops
100 },
101 { /* CX18_ENC_STREAM_TYPE_RAD */
102 "encoder radio",
103 VFL_TYPE_RADIO, 0,
104 PCI_DMA_NONE, V4L2_BUF_TYPE_PRIVATE,
105 &cx18_v4l2_enc_fops
106 },
107};
108
109static void cx18_stream_init(struct cx18 *cx, int type)
110{
111 struct cx18_stream *s = &cx->streams[type];
112 struct video_device *dev = s->v4l2dev;
113 u32 max_size = cx->options.megabytes[type] * 1024 * 1024;
114
115 /* we need to keep v4l2dev, so restore it afterwards */
116 memset(s, 0, sizeof(*s));
117 s->v4l2dev = dev;
118
119 /* initialize cx18_stream fields */
120 s->cx = cx;
121 s->type = type;
122 s->name = cx18_stream_info[type].name;
d3c5e707 123 s->handle = CX18_INVALID_TASK_HANDLE;
1c1e45d1
HV
124
125 s->dma = cx18_stream_info[type].dma;
126 s->buf_size = cx->stream_buf_size[type];
127 if (s->buf_size)
128 s->buffers = max_size / s->buf_size;
129 if (s->buffers > 63) {
130 /* Each stream has a maximum of 63 buffers,
131 ensure we do not exceed that. */
132 s->buffers = 63;
133 s->buf_size = (max_size / s->buffers) & ~0xfff;
134 }
135 spin_lock_init(&s->qlock);
136 init_waitqueue_head(&s->waitq);
137 s->id = -1;
138 cx18_queue_init(&s->q_free);
139 cx18_queue_init(&s->q_full);
140 cx18_queue_init(&s->q_io);
141}
142
143static int cx18_prep_dev(struct cx18 *cx, int type)
144{
145 struct cx18_stream *s = &cx->streams[type];
146 u32 cap = cx->v4l2_cap;
147 int minor_offset = cx18_stream_info[type].minor_offset;
148 int minor;
149
150 /* These four fields are always initialized. If v4l2dev == NULL, then
151 this stream is not in use. In that case no other fields but these
152 four can be used. */
153 s->v4l2dev = NULL;
154 s->cx = cx;
155 s->type = type;
156 s->name = cx18_stream_info[type].name;
157
158 /* Check whether the radio is supported */
159 if (type == CX18_ENC_STREAM_TYPE_RAD && !(cap & V4L2_CAP_RADIO))
160 return 0;
161
162 /* Check whether VBI is supported */
163 if (type == CX18_ENC_STREAM_TYPE_VBI &&
164 !(cap & (V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE)))
165 return 0;
166
167 /* card number + user defined offset + device offset */
168 minor = cx->num + cx18_first_minor + minor_offset;
169
170 /* User explicitly selected 0 buffers for these streams, so don't
171 create them. */
172 if (cx18_stream_info[type].dma != PCI_DMA_NONE &&
173 cx->options.megabytes[type] == 0) {
174 CX18_INFO("Disabled %s device\n", cx18_stream_info[type].name);
175 return 0;
176 }
177
178 cx18_stream_init(cx, type);
179
180 if (minor_offset == -1)
181 return 0;
182
183 /* allocate and initialize the v4l2 video device structure */
184 s->v4l2dev = video_device_alloc();
185 if (s->v4l2dev == NULL) {
186 CX18_ERR("Couldn't allocate v4l2 video_device for %s\n",
187 s->name);
188 return -ENOMEM;
189 }
190
37f89f95
HV
191 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18-%d",
192 cx->num);
1c1e45d1
HV
193
194 s->v4l2dev->minor = minor;
5e85e732 195 s->v4l2dev->parent = &cx->dev->dev;
1c1e45d1
HV
196 s->v4l2dev->fops = cx18_stream_info[type].fops;
197 s->v4l2dev->release = video_device_release;
3b6fe58f
AW
198 s->v4l2dev->tvnorms = V4L2_STD_ALL;
199 cx18_set_funcs(s->v4l2dev);
1c1e45d1
HV
200 return 0;
201}
202
203/* Initialize v4l2 variables and register v4l2 devices */
204int cx18_streams_setup(struct cx18 *cx)
205{
206 int type;
207
208 /* Setup V4L2 Devices */
209 for (type = 0; type < CX18_MAX_STREAMS; type++) {
210 /* Prepare device */
211 if (cx18_prep_dev(cx, type))
212 break;
213
214 /* Allocate Stream */
215 if (cx18_stream_alloc(&cx->streams[type]))
216 break;
217 }
218 if (type == CX18_MAX_STREAMS)
219 return 0;
220
221 /* One or more streams could not be initialized. Clean 'em all up. */
3f98387e 222 cx18_streams_cleanup(cx, 0);
1c1e45d1
HV
223 return -ENOMEM;
224}
225
226static int cx18_reg_dev(struct cx18 *cx, int type)
227{
228 struct cx18_stream *s = &cx->streams[type];
229 int vfl_type = cx18_stream_info[type].vfl_type;
230 int minor;
231
232 /* TODO: Shouldn't this be a VFL_TYPE_TRANSPORT or something?
233 * We need a VFL_TYPE_TS defined.
234 */
235 if (strcmp("TS", s->name) == 0) {
236 /* just return if no DVB is supported */
237 if ((cx->card->hw_all & CX18_HW_DVB) == 0)
238 return 0;
239 if (cx18_dvb_register(s) < 0) {
240 CX18_ERR("DVB failed to register\n");
241 return -EINVAL;
242 }
243 }
244
245 if (s->v4l2dev == NULL)
246 return 0;
247
248 minor = s->v4l2dev->minor;
249
250 /* Register device. First try the desired minor, then any free one. */
251 if (video_register_device(s->v4l2dev, vfl_type, minor) &&
252 video_register_device(s->v4l2dev, vfl_type, -1)) {
253 CX18_ERR("Couldn't register v4l2 device for %s minor %d\n",
254 s->name, minor);
255 video_device_release(s->v4l2dev);
256 s->v4l2dev = NULL;
257 return -ENOMEM;
258 }
259 minor = s->v4l2dev->minor;
260
261 switch (vfl_type) {
262 case VFL_TYPE_GRABBER:
263 CX18_INFO("Registered device video%d for %s (%d MB)\n",
264 minor, s->name, cx->options.megabytes[type]);
265 break;
266
267 case VFL_TYPE_RADIO:
268 CX18_INFO("Registered device radio%d for %s\n",
269 minor - MINOR_VFL_TYPE_RADIO_MIN, s->name);
270 break;
271
272 case VFL_TYPE_VBI:
273 if (cx->options.megabytes[type])
274 CX18_INFO("Registered device vbi%d for %s (%d MB)\n",
275 minor - MINOR_VFL_TYPE_VBI_MIN,
276 s->name, cx->options.megabytes[type]);
277 else
278 CX18_INFO("Registered device vbi%d for %s\n",
279 minor - MINOR_VFL_TYPE_VBI_MIN, s->name);
280 break;
281 }
282
283 return 0;
284}
285
286/* Register v4l2 devices */
287int cx18_streams_register(struct cx18 *cx)
288{
289 int type;
290 int err = 0;
291
292 /* Register V4L2 devices */
293 for (type = 0; type < CX18_MAX_STREAMS; type++)
294 err |= cx18_reg_dev(cx, type);
295
296 if (err == 0)
297 return 0;
298
299 /* One or more streams could not be initialized. Clean 'em all up. */
3f98387e 300 cx18_streams_cleanup(cx, 1);
1c1e45d1
HV
301 return -ENOMEM;
302}
303
304/* Unregister v4l2 devices */
3f98387e 305void cx18_streams_cleanup(struct cx18 *cx, int unregister)
1c1e45d1
HV
306{
307 struct video_device *vdev;
308 int type;
309
310 /* Teardown all streams */
311 for (type = 0; type < CX18_MAX_STREAMS; type++) {
fac3639d 312 if (cx->streams[type].dvb.enabled) {
1c1e45d1 313 cx18_dvb_unregister(&cx->streams[type]);
fac3639d
HV
314 cx->streams[type].dvb.enabled = false;
315 }
1c1e45d1
HV
316
317 vdev = cx->streams[type].v4l2dev;
318
319 cx->streams[type].v4l2dev = NULL;
320 if (vdev == NULL)
321 continue;
322
323 cx18_stream_free(&cx->streams[type]);
324
3f98387e
HV
325 /* Unregister or release device */
326 if (unregister)
327 video_unregister_device(vdev);
328 else
329 video_device_release(vdev);
1c1e45d1
HV
330 }
331}
332
333static void cx18_vbi_setup(struct cx18_stream *s)
334{
335 struct cx18 *cx = s->cx;
336 int raw = cx->vbi.sliced_in->service_set == 0;
337 u32 data[CX2341X_MBOX_MAX_DATA];
338 int lines;
339
340 if (cx->is_60hz) {
341 cx->vbi.count = 12;
342 cx->vbi.start[0] = 10;
343 cx->vbi.start[1] = 273;
344 } else { /* PAL/SECAM */
345 cx->vbi.count = 18;
346 cx->vbi.start[0] = 6;
347 cx->vbi.start[1] = 318;
348 }
349
350 /* setup VBI registers */
351 cx18_av_cmd(cx, VIDIOC_S_FMT, &cx->vbi.in);
352
353 /* determine number of lines and total number of VBI bytes.
354 A raw line takes 1443 bytes: 2 * 720 + 4 byte frame header - 1
355 The '- 1' byte is probably an unused U or V byte. Or something...
356 A sliced line takes 51 bytes: 4 byte frame header, 4 byte internal
357 header, 42 data bytes + checksum (to be confirmed) */
358 if (raw) {
359 lines = cx->vbi.count * 2;
360 } else {
361 lines = cx->is_60hz ? 24 : 38;
362 if (cx->is_60hz)
363 lines += 2;
364 }
365
366 cx->vbi.enc_size = lines *
367 (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
368
369 data[0] = s->handle;
370 /* Lines per field */
371 data[1] = (lines / 2) | ((lines / 2) << 16);
372 /* bytes per line */
373 data[2] = (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
374 /* Every X number of frames a VBI interrupt arrives
375 (frames as in 25 or 30 fps) */
376 data[3] = 1;
377 /* Setup VBI for the cx25840 digitizer */
378 if (raw) {
379 data[4] = 0x20602060;
380 data[5] = 0x30703070;
381 } else {
382 data[4] = 0xB0F0B0F0;
383 data[5] = 0xA0E0A0E0;
384 }
385
386 CX18_DEBUG_INFO("Setup VBI h: %d lines %x bpl %d fr %d %x %x\n",
387 data[0], data[1], data[2], data[3], data[4], data[5]);
388
389 if (s->type == CX18_ENC_STREAM_TYPE_VBI)
390 cx18_api(cx, CX18_CPU_SET_RAW_VBI_PARAM, 6, data);
391}
392
393int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
394{
395 u32 data[MAX_MB_ARGUMENTS];
396 struct cx18 *cx = s->cx;
397 struct list_head *p;
398 int ts = 0;
399 int captype = 0;
400
401 if (s->v4l2dev == NULL && s->dvb.enabled == 0)
402 return -EINVAL;
403
404 CX18_DEBUG_INFO("Start encoder stream %s\n", s->name);
405
406 switch (s->type) {
407 case CX18_ENC_STREAM_TYPE_MPG:
408 captype = CAPTURE_CHANNEL_TYPE_MPEG;
409 cx->mpg_data_received = cx->vbi_data_inserted = 0;
410 cx->dualwatch_jiffies = jiffies;
411 cx->dualwatch_stereo_mode = cx->params.audio_properties & 0x300;
412 cx->search_pack_header = 0;
413 break;
414
415 case CX18_ENC_STREAM_TYPE_TS:
416 captype = CAPTURE_CHANNEL_TYPE_TS;
417 ts = 1;
418 break;
419 case CX18_ENC_STREAM_TYPE_YUV:
420 captype = CAPTURE_CHANNEL_TYPE_YUV;
421 break;
422 case CX18_ENC_STREAM_TYPE_PCM:
423 captype = CAPTURE_CHANNEL_TYPE_PCM;
424 break;
425 case CX18_ENC_STREAM_TYPE_VBI:
426 captype = cx->vbi.sliced_in->service_set ?
427 CAPTURE_CHANNEL_TYPE_SLICED_VBI : CAPTURE_CHANNEL_TYPE_VBI;
428 cx->vbi.frame = 0;
429 cx->vbi.inserted_frame = 0;
430 memset(cx->vbi.sliced_mpeg_size,
431 0, sizeof(cx->vbi.sliced_mpeg_size));
432 break;
433 default:
434 return -EINVAL;
435 }
1c1e45d1
HV
436
437 /* mute/unmute video */
438 cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2,
439 s->handle, !!test_bit(CX18_F_I_RADIO_USER, &cx->i_flags));
440
441 /* Clear Streamoff flags in case left from last capture */
442 clear_bit(CX18_F_S_STREAMOFF, &s->s_flags);
443
444 cx18_vapi_result(cx, data, CX18_CREATE_TASK, 1, CPU_CMD_MASK_CAPTURE);
445 s->handle = data[0];
446 cx18_vapi(cx, CX18_CPU_SET_CHANNEL_TYPE, 2, s->handle, captype);
447
31554ae5 448 if (atomic_read(&cx->ana_capturing) == 0 && !ts) {
1c1e45d1
HV
449 /* Stuff from Windows, we don't know what it is */
450 cx18_vapi(cx, CX18_CPU_SET_VER_CROP_LINE, 2, s->handle, 0);
451 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 3, 1);
452 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 8, 0);
453 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 4, 1);
454 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2, s->handle, 12);
455
456 cx18_vapi(cx, CX18_CPU_SET_CAPTURE_LINE_NO, 3,
457 s->handle, cx->digitizer, cx->digitizer);
458
459 /* Setup VBI */
460 if (cx->v4l2_cap & V4L2_CAP_VBI_CAPTURE)
461 cx18_vbi_setup(s);
462
463 /* assign program index info.
464 Mask 7: select I/P/B, Num_req: 400 max */
465 cx18_vapi_result(cx, data, CX18_CPU_SET_INDEXTABLE, 1, 0);
466
467 /* Setup API for Stream */
468 cx2341x_update(cx, cx18_api_func, NULL, &cx->params);
469 }
470
31554ae5 471 if (atomic_read(&cx->tot_capturing) == 0) {
1c1e45d1 472 clear_bit(CX18_F_I_EOS, &cx->i_flags);
b1526421 473 cx18_write_reg(cx, 7, CX18_DSP0_INTERRUPT_MASK);
1c1e45d1
HV
474 }
475
476 cx18_vapi(cx, CX18_CPU_DE_SET_MDL_ACK, 3, s->handle,
990c81c8
AV
477 (void __iomem *)&cx->scb->cpu_mdl_ack[s->type][0] - cx->enc_mem,
478 (void __iomem *)&cx->scb->cpu_mdl_ack[s->type][1] - cx->enc_mem);
1c1e45d1
HV
479
480 list_for_each(p, &s->q_free.list) {
481 struct cx18_buffer *buf = list_entry(p, struct cx18_buffer, list);
482
b1526421
AW
483 cx18_writel(cx, buf->dma_handle,
484 &cx->scb->cpu_mdl[buf->id].paddr);
485 cx18_writel(cx, s->buf_size, &cx->scb->cpu_mdl[buf->id].length);
1c1e45d1 486 cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle,
990c81c8
AV
487 (void __iomem *)&cx->scb->cpu_mdl[buf->id] - cx->enc_mem,
488 1, buf->id, s->buf_size);
1c1e45d1
HV
489 }
490 /* begin_capture */
491 if (cx18_vapi(cx, CX18_CPU_CAPTURE_START, 1, s->handle)) {
492 CX18_DEBUG_WARN("Error starting capture!\n");
3b5df8ea
AW
493 /* Ensure we're really not capturing before releasing MDLs */
494 if (s->type == CX18_ENC_STREAM_TYPE_MPG)
495 cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 2, s->handle, 1);
496 else
497 cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 1, s->handle);
498 cx18_vapi(cx, CX18_CPU_DE_RELEASE_MDL, 1, s->handle);
1c1e45d1 499 cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
3b5df8ea 500 /* FIXME - clean-up DSP0_INT mask, i_flags, s_flags, etc. */
1c1e45d1
HV
501 return -EINVAL;
502 }
503
504 /* you're live! sit back and await interrupts :) */
31554ae5
HV
505 if (!ts)
506 atomic_inc(&cx->ana_capturing);
507 atomic_inc(&cx->tot_capturing);
1c1e45d1
HV
508 return 0;
509}
510
511void cx18_stop_all_captures(struct cx18 *cx)
512{
513 int i;
514
515 for (i = CX18_MAX_STREAMS - 1; i >= 0; i--) {
516 struct cx18_stream *s = &cx->streams[i];
517
518 if (s->v4l2dev == NULL && s->dvb.enabled == 0)
519 continue;
520 if (test_bit(CX18_F_S_STREAMING, &s->s_flags))
521 cx18_stop_v4l2_encode_stream(s, 0);
522 }
523}
524
525int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
526{
527 struct cx18 *cx = s->cx;
528 unsigned long then;
529
530 if (s->v4l2dev == NULL && s->dvb.enabled == 0)
531 return -EINVAL;
532
533 /* This function assumes that you are allowed to stop the capture
534 and that we are actually capturing */
535
536 CX18_DEBUG_INFO("Stop Capture\n");
537
31554ae5 538 if (atomic_read(&cx->tot_capturing) == 0)
1c1e45d1
HV
539 return 0;
540
541 if (s->type == CX18_ENC_STREAM_TYPE_MPG)
542 cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 2, s->handle, !gop_end);
543 else
544 cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 1, s->handle);
545
546 then = jiffies;
547
548 if (s->type == CX18_ENC_STREAM_TYPE_MPG && gop_end) {
549 CX18_INFO("ignoring gop_end: not (yet?) supported by the firmware\n");
550 }
551
3b5df8ea
AW
552 /* Tell the CX23418 it can't use our buffers anymore */
553 cx18_vapi(cx, CX18_CPU_DE_RELEASE_MDL, 1, s->handle);
554
31554ae5
HV
555 if (s->type != CX18_ENC_STREAM_TYPE_TS)
556 atomic_dec(&cx->ana_capturing);
557 atomic_dec(&cx->tot_capturing);
1c1e45d1
HV
558
559 /* Clear capture and no-read bits */
560 clear_bit(CX18_F_S_STREAMING, &s->s_flags);
561
562 cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
d3c5e707 563 s->handle = CX18_INVALID_TASK_HANDLE;
1c1e45d1 564
31554ae5 565 if (atomic_read(&cx->tot_capturing) > 0)
1c1e45d1
HV
566 return 0;
567
b1526421 568 cx18_write_reg(cx, 5, CX18_DSP0_INTERRUPT_MASK);
1c1e45d1
HV
569 wake_up(&s->waitq);
570
571 return 0;
572}
573
574u32 cx18_find_handle(struct cx18 *cx)
575{
576 int i;
577
578 /* find first available handle to be used for global settings */
579 for (i = 0; i < CX18_MAX_STREAMS; i++) {
580 struct cx18_stream *s = &cx->streams[i];
581
d3c5e707 582 if (s->v4l2dev && (s->handle != CX18_INVALID_TASK_HANDLE))
1c1e45d1
HV
583 return s->handle;
584 }
d3c5e707 585 return CX18_INVALID_TASK_HANDLE;
1c1e45d1 586}