cx18-streams.c 15 KB

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