cx18-streams.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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. #include "cx18-driver.h"
  24. #include "cx18-fileops.h"
  25. #include "cx18-mailbox.h"
  26. #include "cx18-i2c.h"
  27. #include "cx18-queue.h"
  28. #include "cx18-ioctl.h"
  29. #include "cx18-streams.h"
  30. #include "cx18-cards.h"
  31. #include "cx18-scb.h"
  32. #include "cx18-av-core.h"
  33. #include "cx18-dvb.h"
  34. #define CX18_DSP0_INTERRUPT_MASK 0xd0004C
  35. static struct file_operations cx18_v4l2_enc_fops = {
  36. .owner = THIS_MODULE,
  37. .read = cx18_v4l2_read,
  38. .open = cx18_v4l2_open,
  39. .ioctl = cx18_v4l2_ioctl,
  40. .compat_ioctl = v4l_compat_ioctl32,
  41. .release = cx18_v4l2_close,
  42. .poll = cx18_v4l2_enc_poll,
  43. };
  44. /* offset from 0 to register ts v4l2 minors on */
  45. #define CX18_V4L2_ENC_TS_OFFSET 16
  46. /* offset from 0 to register pcm v4l2 minors on */
  47. #define CX18_V4L2_ENC_PCM_OFFSET 24
  48. /* offset from 0 to register yuv v4l2 minors on */
  49. #define CX18_V4L2_ENC_YUV_OFFSET 32
  50. static struct {
  51. const char *name;
  52. int vfl_type;
  53. int minor_offset;
  54. int dma;
  55. enum v4l2_buf_type buf_type;
  56. struct file_operations *fops;
  57. } cx18_stream_info[] = {
  58. { /* CX18_ENC_STREAM_TYPE_MPG */
  59. "encoder MPEG",
  60. VFL_TYPE_GRABBER, 0,
  61. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
  62. &cx18_v4l2_enc_fops
  63. },
  64. { /* CX18_ENC_STREAM_TYPE_TS */
  65. "TS",
  66. VFL_TYPE_GRABBER, -1,
  67. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
  68. &cx18_v4l2_enc_fops
  69. },
  70. { /* CX18_ENC_STREAM_TYPE_YUV */
  71. "encoder YUV",
  72. VFL_TYPE_GRABBER, CX18_V4L2_ENC_YUV_OFFSET,
  73. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
  74. &cx18_v4l2_enc_fops
  75. },
  76. { /* CX18_ENC_STREAM_TYPE_VBI */
  77. "encoder VBI",
  78. VFL_TYPE_VBI, 0,
  79. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VBI_CAPTURE,
  80. &cx18_v4l2_enc_fops
  81. },
  82. { /* CX18_ENC_STREAM_TYPE_PCM */
  83. "encoder PCM audio",
  84. VFL_TYPE_GRABBER, CX18_V4L2_ENC_PCM_OFFSET,
  85. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_PRIVATE,
  86. &cx18_v4l2_enc_fops
  87. },
  88. { /* CX18_ENC_STREAM_TYPE_IDX */
  89. "encoder IDX",
  90. VFL_TYPE_GRABBER, -1,
  91. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
  92. &cx18_v4l2_enc_fops
  93. },
  94. { /* CX18_ENC_STREAM_TYPE_RAD */
  95. "encoder radio",
  96. VFL_TYPE_RADIO, 0,
  97. PCI_DMA_NONE, V4L2_BUF_TYPE_PRIVATE,
  98. &cx18_v4l2_enc_fops
  99. },
  100. };
  101. static void cx18_stream_init(struct cx18 *cx, int type)
  102. {
  103. struct cx18_stream *s = &cx->streams[type];
  104. struct video_device *dev = s->v4l2dev;
  105. u32 max_size = cx->options.megabytes[type] * 1024 * 1024;
  106. /* we need to keep v4l2dev, so restore it afterwards */
  107. memset(s, 0, sizeof(*s));
  108. s->v4l2dev = dev;
  109. /* initialize cx18_stream fields */
  110. s->cx = cx;
  111. s->type = type;
  112. s->name = cx18_stream_info[type].name;
  113. s->handle = 0xffffffff;
  114. s->dma = cx18_stream_info[type].dma;
  115. s->buf_size = cx->stream_buf_size[type];
  116. if (s->buf_size)
  117. s->buffers = max_size / s->buf_size;
  118. if (s->buffers > 63) {
  119. /* Each stream has a maximum of 63 buffers,
  120. ensure we do not exceed that. */
  121. s->buffers = 63;
  122. s->buf_size = (max_size / s->buffers) & ~0xfff;
  123. }
  124. spin_lock_init(&s->qlock);
  125. init_waitqueue_head(&s->waitq);
  126. s->id = -1;
  127. cx18_queue_init(&s->q_free);
  128. cx18_queue_init(&s->q_full);
  129. cx18_queue_init(&s->q_io);
  130. }
  131. static int cx18_prep_dev(struct cx18 *cx, int type)
  132. {
  133. struct cx18_stream *s = &cx->streams[type];
  134. u32 cap = cx->v4l2_cap;
  135. int minor_offset = cx18_stream_info[type].minor_offset;
  136. int minor;
  137. /* These four fields are always initialized. If v4l2dev == NULL, then
  138. this stream is not in use. In that case no other fields but these
  139. four can be used. */
  140. s->v4l2dev = NULL;
  141. s->cx = cx;
  142. s->type = type;
  143. s->name = cx18_stream_info[type].name;
  144. /* Check whether the radio is supported */
  145. if (type == CX18_ENC_STREAM_TYPE_RAD && !(cap & V4L2_CAP_RADIO))
  146. return 0;
  147. /* Check whether VBI is supported */
  148. if (type == CX18_ENC_STREAM_TYPE_VBI &&
  149. !(cap & (V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE)))
  150. return 0;
  151. /* card number + user defined offset + device offset */
  152. minor = cx->num + cx18_first_minor + minor_offset;
  153. /* User explicitly selected 0 buffers for these streams, so don't
  154. create them. */
  155. if (cx18_stream_info[type].dma != PCI_DMA_NONE &&
  156. cx->options.megabytes[type] == 0) {
  157. CX18_INFO("Disabled %s device\n", cx18_stream_info[type].name);
  158. return 0;
  159. }
  160. cx18_stream_init(cx, type);
  161. if (minor_offset == -1)
  162. return 0;
  163. /* allocate and initialize the v4l2 video device structure */
  164. s->v4l2dev = video_device_alloc();
  165. if (s->v4l2dev == NULL) {
  166. CX18_ERR("Couldn't allocate v4l2 video_device for %s\n",
  167. s->name);
  168. return -ENOMEM;
  169. }
  170. s->v4l2dev->type =
  171. VID_TYPE_CAPTURE | VID_TYPE_TUNER | VID_TYPE_TELETEXT |
  172. VID_TYPE_CLIPPING | VID_TYPE_SCALES | VID_TYPE_MPEG_ENCODER;
  173. snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18%d %s",
  174. cx->num, s->name);
  175. s->v4l2dev->minor = minor;
  176. s->v4l2dev->dev = &cx->dev->dev;
  177. s->v4l2dev->fops = cx18_stream_info[type].fops;
  178. s->v4l2dev->release = video_device_release;
  179. return 0;
  180. }
  181. /* Initialize v4l2 variables and register v4l2 devices */
  182. int cx18_streams_setup(struct cx18 *cx)
  183. {
  184. int type;
  185. /* Setup V4L2 Devices */
  186. for (type = 0; type < CX18_MAX_STREAMS; type++) {
  187. /* Prepare device */
  188. if (cx18_prep_dev(cx, type))
  189. break;
  190. /* Allocate Stream */
  191. if (cx18_stream_alloc(&cx->streams[type]))
  192. break;
  193. }
  194. if (type == CX18_MAX_STREAMS)
  195. return 0;
  196. /* One or more streams could not be initialized. Clean 'em all up. */
  197. cx18_streams_cleanup(cx, 0);
  198. return -ENOMEM;
  199. }
  200. static int cx18_reg_dev(struct cx18 *cx, int type)
  201. {
  202. struct cx18_stream *s = &cx->streams[type];
  203. int vfl_type = cx18_stream_info[type].vfl_type;
  204. int minor;
  205. /* TODO: Shouldn't this be a VFL_TYPE_TRANSPORT or something?
  206. * We need a VFL_TYPE_TS defined.
  207. */
  208. if (strcmp("TS", s->name) == 0) {
  209. /* just return if no DVB is supported */
  210. if ((cx->card->hw_all & CX18_HW_DVB) == 0)
  211. return 0;
  212. if (cx18_dvb_register(s) < 0) {
  213. CX18_ERR("DVB failed to register\n");
  214. return -EINVAL;
  215. }
  216. }
  217. if (s->v4l2dev == NULL)
  218. return 0;
  219. minor = s->v4l2dev->minor;
  220. /* Register device. First try the desired minor, then any free one. */
  221. if (video_register_device(s->v4l2dev, vfl_type, minor) &&
  222. video_register_device(s->v4l2dev, vfl_type, -1)) {
  223. CX18_ERR("Couldn't register v4l2 device for %s minor %d\n",
  224. s->name, minor);
  225. video_device_release(s->v4l2dev);
  226. s->v4l2dev = NULL;
  227. return -ENOMEM;
  228. }
  229. minor = s->v4l2dev->minor;
  230. switch (vfl_type) {
  231. case VFL_TYPE_GRABBER:
  232. CX18_INFO("Registered device video%d for %s (%d MB)\n",
  233. minor, s->name, cx->options.megabytes[type]);
  234. break;
  235. case VFL_TYPE_RADIO:
  236. CX18_INFO("Registered device radio%d for %s\n",
  237. minor - MINOR_VFL_TYPE_RADIO_MIN, s->name);
  238. break;
  239. case VFL_TYPE_VBI:
  240. if (cx->options.megabytes[type])
  241. CX18_INFO("Registered device vbi%d for %s (%d MB)\n",
  242. minor - MINOR_VFL_TYPE_VBI_MIN,
  243. s->name, cx->options.megabytes[type]);
  244. else
  245. CX18_INFO("Registered device vbi%d for %s\n",
  246. minor - MINOR_VFL_TYPE_VBI_MIN, s->name);
  247. break;
  248. }
  249. return 0;
  250. }
  251. /* Register v4l2 devices */
  252. int cx18_streams_register(struct cx18 *cx)
  253. {
  254. int type;
  255. int err = 0;
  256. /* Register V4L2 devices */
  257. for (type = 0; type < CX18_MAX_STREAMS; type++)
  258. err |= cx18_reg_dev(cx, type);
  259. if (err == 0)
  260. return 0;
  261. /* One or more streams could not be initialized. Clean 'em all up. */
  262. cx18_streams_cleanup(cx, 1);
  263. return -ENOMEM;
  264. }
  265. /* Unregister v4l2 devices */
  266. void cx18_streams_cleanup(struct cx18 *cx, int unregister)
  267. {
  268. struct video_device *vdev;
  269. int type;
  270. /* Teardown all streams */
  271. for (type = 0; type < CX18_MAX_STREAMS; type++) {
  272. if (cx->streams[type].dvb.enabled)
  273. cx18_dvb_unregister(&cx->streams[type]);
  274. vdev = cx->streams[type].v4l2dev;
  275. cx->streams[type].v4l2dev = NULL;
  276. if (vdev == NULL)
  277. continue;
  278. cx18_stream_free(&cx->streams[type]);
  279. /* Unregister or release device */
  280. if (unregister)
  281. video_unregister_device(vdev);
  282. else
  283. video_device_release(vdev);
  284. }
  285. }
  286. static void cx18_vbi_setup(struct cx18_stream *s)
  287. {
  288. struct cx18 *cx = s->cx;
  289. int raw = cx->vbi.sliced_in->service_set == 0;
  290. u32 data[CX2341X_MBOX_MAX_DATA];
  291. int lines;
  292. if (cx->is_60hz) {
  293. cx->vbi.count = 12;
  294. cx->vbi.start[0] = 10;
  295. cx->vbi.start[1] = 273;
  296. } else { /* PAL/SECAM */
  297. cx->vbi.count = 18;
  298. cx->vbi.start[0] = 6;
  299. cx->vbi.start[1] = 318;
  300. }
  301. /* setup VBI registers */
  302. cx18_av_cmd(cx, VIDIOC_S_FMT, &cx->vbi.in);
  303. /* determine number of lines and total number of VBI bytes.
  304. A raw line takes 1443 bytes: 2 * 720 + 4 byte frame header - 1
  305. The '- 1' byte is probably an unused U or V byte. Or something...
  306. A sliced line takes 51 bytes: 4 byte frame header, 4 byte internal
  307. header, 42 data bytes + checksum (to be confirmed) */
  308. if (raw) {
  309. lines = cx->vbi.count * 2;
  310. } else {
  311. lines = cx->is_60hz ? 24 : 38;
  312. if (cx->is_60hz)
  313. lines += 2;
  314. }
  315. cx->vbi.enc_size = lines *
  316. (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
  317. data[0] = s->handle;
  318. /* Lines per field */
  319. data[1] = (lines / 2) | ((lines / 2) << 16);
  320. /* bytes per line */
  321. data[2] = (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
  322. /* Every X number of frames a VBI interrupt arrives
  323. (frames as in 25 or 30 fps) */
  324. data[3] = 1;
  325. /* Setup VBI for the cx25840 digitizer */
  326. if (raw) {
  327. data[4] = 0x20602060;
  328. data[5] = 0x30703070;
  329. } else {
  330. data[4] = 0xB0F0B0F0;
  331. data[5] = 0xA0E0A0E0;
  332. }
  333. CX18_DEBUG_INFO("Setup VBI h: %d lines %x bpl %d fr %d %x %x\n",
  334. data[0], data[1], data[2], data[3], data[4], data[5]);
  335. if (s->type == CX18_ENC_STREAM_TYPE_VBI)
  336. cx18_api(cx, CX18_CPU_SET_RAW_VBI_PARAM, 6, data);
  337. }
  338. int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
  339. {
  340. u32 data[MAX_MB_ARGUMENTS];
  341. struct cx18 *cx = s->cx;
  342. struct list_head *p;
  343. int ts = 0;
  344. int captype = 0;
  345. if (s->v4l2dev == NULL && s->dvb.enabled == 0)
  346. return -EINVAL;
  347. CX18_DEBUG_INFO("Start encoder stream %s\n", s->name);
  348. switch (s->type) {
  349. case CX18_ENC_STREAM_TYPE_MPG:
  350. captype = CAPTURE_CHANNEL_TYPE_MPEG;
  351. cx->mpg_data_received = cx->vbi_data_inserted = 0;
  352. cx->dualwatch_jiffies = jiffies;
  353. cx->dualwatch_stereo_mode = cx->params.audio_properties & 0x300;
  354. cx->search_pack_header = 0;
  355. break;
  356. case CX18_ENC_STREAM_TYPE_TS:
  357. captype = CAPTURE_CHANNEL_TYPE_TS;
  358. ts = 1;
  359. break;
  360. case CX18_ENC_STREAM_TYPE_YUV:
  361. captype = CAPTURE_CHANNEL_TYPE_YUV;
  362. break;
  363. case CX18_ENC_STREAM_TYPE_PCM:
  364. captype = CAPTURE_CHANNEL_TYPE_PCM;
  365. break;
  366. case CX18_ENC_STREAM_TYPE_VBI:
  367. captype = cx->vbi.sliced_in->service_set ?
  368. CAPTURE_CHANNEL_TYPE_SLICED_VBI : CAPTURE_CHANNEL_TYPE_VBI;
  369. cx->vbi.frame = 0;
  370. cx->vbi.inserted_frame = 0;
  371. memset(cx->vbi.sliced_mpeg_size,
  372. 0, sizeof(cx->vbi.sliced_mpeg_size));
  373. break;
  374. default:
  375. return -EINVAL;
  376. }
  377. s->buffers_stolen = 0;
  378. /* mute/unmute video */
  379. cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2,
  380. s->handle, !!test_bit(CX18_F_I_RADIO_USER, &cx->i_flags));
  381. /* Clear Streamoff flags in case left from last capture */
  382. clear_bit(CX18_F_S_STREAMOFF, &s->s_flags);
  383. cx18_vapi_result(cx, data, CX18_CREATE_TASK, 1, CPU_CMD_MASK_CAPTURE);
  384. s->handle = data[0];
  385. cx18_vapi(cx, CX18_CPU_SET_CHANNEL_TYPE, 2, s->handle, captype);
  386. if (atomic_read(&cx->ana_capturing) == 0 && !ts) {
  387. /* Stuff from Windows, we don't know what it is */
  388. cx18_vapi(cx, CX18_CPU_SET_VER_CROP_LINE, 2, s->handle, 0);
  389. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 3, 1);
  390. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 8, 0);
  391. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 4, 1);
  392. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2, s->handle, 12);
  393. cx18_vapi(cx, CX18_CPU_SET_CAPTURE_LINE_NO, 3,
  394. s->handle, cx->digitizer, cx->digitizer);
  395. /* Setup VBI */
  396. if (cx->v4l2_cap & V4L2_CAP_VBI_CAPTURE)
  397. cx18_vbi_setup(s);
  398. /* assign program index info.
  399. Mask 7: select I/P/B, Num_req: 400 max */
  400. cx18_vapi_result(cx, data, CX18_CPU_SET_INDEXTABLE, 1, 0);
  401. /* Setup API for Stream */
  402. cx2341x_update(cx, cx18_api_func, NULL, &cx->params);
  403. }
  404. if (atomic_read(&cx->tot_capturing) == 0) {
  405. clear_bit(CX18_F_I_EOS, &cx->i_flags);
  406. write_reg(7, CX18_DSP0_INTERRUPT_MASK);
  407. }
  408. cx18_vapi(cx, CX18_CPU_DE_SET_MDL_ACK, 3, s->handle,
  409. (void __iomem *)&cx->scb->cpu_mdl_ack[s->type][0] - cx->enc_mem,
  410. (void __iomem *)&cx->scb->cpu_mdl_ack[s->type][1] - cx->enc_mem);
  411. list_for_each(p, &s->q_free.list) {
  412. struct cx18_buffer *buf = list_entry(p, struct cx18_buffer, list);
  413. writel(buf->dma_handle, &cx->scb->cpu_mdl[buf->id].paddr);
  414. writel(s->buf_size, &cx->scb->cpu_mdl[buf->id].length);
  415. cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle,
  416. (void __iomem *)&cx->scb->cpu_mdl[buf->id] - cx->enc_mem,
  417. 1, buf->id, s->buf_size);
  418. }
  419. /* begin_capture */
  420. if (cx18_vapi(cx, CX18_CPU_CAPTURE_START, 1, s->handle)) {
  421. CX18_DEBUG_WARN("Error starting capture!\n");
  422. cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
  423. return -EINVAL;
  424. }
  425. /* you're live! sit back and await interrupts :) */
  426. if (!ts)
  427. atomic_inc(&cx->ana_capturing);
  428. atomic_inc(&cx->tot_capturing);
  429. return 0;
  430. }
  431. void cx18_stop_all_captures(struct cx18 *cx)
  432. {
  433. int i;
  434. for (i = CX18_MAX_STREAMS - 1; i >= 0; i--) {
  435. struct cx18_stream *s = &cx->streams[i];
  436. if (s->v4l2dev == NULL && s->dvb.enabled == 0)
  437. continue;
  438. if (test_bit(CX18_F_S_STREAMING, &s->s_flags))
  439. cx18_stop_v4l2_encode_stream(s, 0);
  440. }
  441. }
  442. int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
  443. {
  444. struct cx18 *cx = s->cx;
  445. unsigned long then;
  446. if (s->v4l2dev == NULL && s->dvb.enabled == 0)
  447. return -EINVAL;
  448. /* This function assumes that you are allowed to stop the capture
  449. and that we are actually capturing */
  450. CX18_DEBUG_INFO("Stop Capture\n");
  451. if (atomic_read(&cx->tot_capturing) == 0)
  452. return 0;
  453. if (s->type == CX18_ENC_STREAM_TYPE_MPG)
  454. cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 2, s->handle, !gop_end);
  455. else
  456. cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 1, s->handle);
  457. then = jiffies;
  458. if (s->type == CX18_ENC_STREAM_TYPE_MPG && gop_end) {
  459. CX18_INFO("ignoring gop_end: not (yet?) supported by the firmware\n");
  460. }
  461. if (s->type != CX18_ENC_STREAM_TYPE_TS)
  462. atomic_dec(&cx->ana_capturing);
  463. atomic_dec(&cx->tot_capturing);
  464. /* Clear capture and no-read bits */
  465. clear_bit(CX18_F_S_STREAMING, &s->s_flags);
  466. cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
  467. s->handle = 0xffffffff;
  468. if (atomic_read(&cx->tot_capturing) > 0)
  469. return 0;
  470. write_reg(5, CX18_DSP0_INTERRUPT_MASK);
  471. wake_up(&s->waitq);
  472. return 0;
  473. }
  474. u32 cx18_find_handle(struct cx18 *cx)
  475. {
  476. int i;
  477. /* find first available handle to be used for global settings */
  478. for (i = 0; i < CX18_MAX_STREAMS; i++) {
  479. struct cx18_stream *s = &cx->streams[i];
  480. if (s->v4l2dev && s->handle)
  481. return s->handle;
  482. }
  483. return 0;
  484. }