cx18-ioctl.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. /*
  2. * cx18 ioctl system call
  3. *
  4. * Derived from ivtv-ioctl.c
  5. *
  6. * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
  7. * Copyright (C) 2008 Andy Walls <awalls@md.metrocast.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  22. * 02111-1307 USA
  23. */
  24. #include "cx18-driver.h"
  25. #include "cx18-io.h"
  26. #include "cx18-version.h"
  27. #include "cx18-mailbox.h"
  28. #include "cx18-i2c.h"
  29. #include "cx18-queue.h"
  30. #include "cx18-fileops.h"
  31. #include "cx18-vbi.h"
  32. #include "cx18-audio.h"
  33. #include "cx18-video.h"
  34. #include "cx18-streams.h"
  35. #include "cx18-ioctl.h"
  36. #include "cx18-gpio.h"
  37. #include "cx18-controls.h"
  38. #include "cx18-cards.h"
  39. #include "cx18-av-core.h"
  40. #include <media/tveeprom.h>
  41. u16 cx18_service2vbi(int type)
  42. {
  43. switch (type) {
  44. case V4L2_SLICED_TELETEXT_B:
  45. return CX18_SLICED_TYPE_TELETEXT_B;
  46. case V4L2_SLICED_CAPTION_525:
  47. return CX18_SLICED_TYPE_CAPTION_525;
  48. case V4L2_SLICED_WSS_625:
  49. return CX18_SLICED_TYPE_WSS_625;
  50. case V4L2_SLICED_VPS:
  51. return CX18_SLICED_TYPE_VPS;
  52. default:
  53. return 0;
  54. }
  55. }
  56. /* Check if VBI services are allowed on the (field, line) for the video std */
  57. static int valid_service_line(int field, int line, int is_pal)
  58. {
  59. return (is_pal && line >= 6 &&
  60. ((field == 0 && line <= 23) || (field == 1 && line <= 22))) ||
  61. (!is_pal && line >= 10 && line < 22);
  62. }
  63. /*
  64. * For a (field, line, std) and inbound potential set of services for that line,
  65. * return the first valid service of those passed in the incoming set for that
  66. * line in priority order:
  67. * CC, VPS, or WSS over TELETEXT for well known lines
  68. * TELETEXT, before VPS, before CC, before WSS, for other lines
  69. */
  70. static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
  71. {
  72. u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);
  73. int i;
  74. set = set & valid_set;
  75. if (set == 0 || !valid_service_line(field, line, is_pal))
  76. return 0;
  77. if (!is_pal) {
  78. if (line == 21 && (set & V4L2_SLICED_CAPTION_525))
  79. return V4L2_SLICED_CAPTION_525;
  80. } else {
  81. if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS))
  82. return V4L2_SLICED_VPS;
  83. if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625))
  84. return V4L2_SLICED_WSS_625;
  85. if (line == 23)
  86. return 0;
  87. }
  88. for (i = 0; i < 32; i++) {
  89. if ((1 << i) & set)
  90. return 1 << i;
  91. }
  92. return 0;
  93. }
  94. /*
  95. * Expand the service_set of *fmt into valid service_lines for the std,
  96. * and clear the passed in fmt->service_set
  97. */
  98. void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
  99. {
  100. u16 set = fmt->service_set;
  101. int f, l;
  102. fmt->service_set = 0;
  103. for (f = 0; f < 2; f++) {
  104. for (l = 0; l < 24; l++)
  105. fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal);
  106. }
  107. }
  108. /*
  109. * Sanitize the service_lines in *fmt per the video std, and return 1
  110. * if any service_line is left as valid after santization
  111. */
  112. static int check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
  113. {
  114. int f, l;
  115. u16 set = 0;
  116. for (f = 0; f < 2; f++) {
  117. for (l = 0; l < 24; l++) {
  118. fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal);
  119. set |= fmt->service_lines[f][l];
  120. }
  121. }
  122. return set != 0;
  123. }
  124. /* Compute the service_set from the assumed valid service_lines of *fmt */
  125. u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt)
  126. {
  127. int f, l;
  128. u16 set = 0;
  129. for (f = 0; f < 2; f++) {
  130. for (l = 0; l < 24; l++)
  131. set |= fmt->service_lines[f][l];
  132. }
  133. return set;
  134. }
  135. static int cx18_g_fmt_vid_cap(struct file *file, void *fh,
  136. struct v4l2_format *fmt)
  137. {
  138. struct cx18_open_id *id = fh2id(fh);
  139. struct cx18 *cx = id->cx;
  140. struct cx18_stream *s = &cx->streams[id->type];
  141. struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
  142. pixfmt->width = cx->cxhdl.width;
  143. pixfmt->height = cx->cxhdl.height;
  144. pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
  145. pixfmt->field = V4L2_FIELD_INTERLACED;
  146. pixfmt->priv = 0;
  147. if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
  148. pixfmt->pixelformat = s->pixelformat;
  149. pixfmt->sizeimage = s->vb_bytes_per_frame;
  150. pixfmt->bytesperline = 720;
  151. } else {
  152. pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
  153. pixfmt->sizeimage = 128 * 1024;
  154. pixfmt->bytesperline = 0;
  155. }
  156. return 0;
  157. }
  158. static int cx18_g_fmt_vbi_cap(struct file *file, void *fh,
  159. struct v4l2_format *fmt)
  160. {
  161. struct cx18 *cx = fh2id(fh)->cx;
  162. struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi;
  163. vbifmt->sampling_rate = 27000000;
  164. vbifmt->offset = 248; /* FIXME - slightly wrong for both 50 & 60 Hz */
  165. vbifmt->samples_per_line = vbi_active_samples - 4;
  166. vbifmt->sample_format = V4L2_PIX_FMT_GREY;
  167. vbifmt->start[0] = cx->vbi.start[0];
  168. vbifmt->start[1] = cx->vbi.start[1];
  169. vbifmt->count[0] = vbifmt->count[1] = cx->vbi.count;
  170. vbifmt->flags = 0;
  171. vbifmt->reserved[0] = 0;
  172. vbifmt->reserved[1] = 0;
  173. return 0;
  174. }
  175. static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh,
  176. struct v4l2_format *fmt)
  177. {
  178. struct cx18 *cx = fh2id(fh)->cx;
  179. struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
  180. /* sane, V4L2 spec compliant, defaults */
  181. vbifmt->reserved[0] = 0;
  182. vbifmt->reserved[1] = 0;
  183. vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
  184. memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines));
  185. vbifmt->service_set = 0;
  186. /*
  187. * Fetch the configured service_lines and total service_set from the
  188. * digitizer/slicer. Note, cx18_av_vbi() wipes the passed in
  189. * fmt->fmt.sliced under valid calling conditions
  190. */
  191. if (v4l2_subdev_call(cx->sd_av, vbi, g_sliced_fmt, &fmt->fmt.sliced))
  192. return -EINVAL;
  193. vbifmt->service_set = cx18_get_service_set(vbifmt);
  194. return 0;
  195. }
  196. static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
  197. struct v4l2_format *fmt)
  198. {
  199. struct cx18_open_id *id = fh2id(fh);
  200. struct cx18 *cx = id->cx;
  201. int w = fmt->fmt.pix.width;
  202. int h = fmt->fmt.pix.height;
  203. int min_h = 2;
  204. w = min(w, 720);
  205. w = max(w, 2);
  206. if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
  207. /* YUV height must be a multiple of 32 */
  208. h &= ~0x1f;
  209. min_h = 32;
  210. }
  211. h = min(h, cx->is_50hz ? 576 : 480);
  212. h = max(h, min_h);
  213. fmt->fmt.pix.width = w;
  214. fmt->fmt.pix.height = h;
  215. return 0;
  216. }
  217. static int cx18_try_fmt_vbi_cap(struct file *file, void *fh,
  218. struct v4l2_format *fmt)
  219. {
  220. return cx18_g_fmt_vbi_cap(file, fh, fmt);
  221. }
  222. static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh,
  223. struct v4l2_format *fmt)
  224. {
  225. struct cx18 *cx = fh2id(fh)->cx;
  226. struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
  227. vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
  228. vbifmt->reserved[0] = 0;
  229. vbifmt->reserved[1] = 0;
  230. /* If given a service set, expand it validly & clear passed in set */
  231. if (vbifmt->service_set)
  232. cx18_expand_service_set(vbifmt, cx->is_50hz);
  233. /* Sanitize the service_lines, and compute the new set if any valid */
  234. if (check_service_set(vbifmt, cx->is_50hz))
  235. vbifmt->service_set = cx18_get_service_set(vbifmt);
  236. return 0;
  237. }
  238. static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
  239. struct v4l2_format *fmt)
  240. {
  241. struct cx18_open_id *id = fh2id(fh);
  242. struct cx18 *cx = id->cx;
  243. struct v4l2_mbus_framefmt mbus_fmt;
  244. struct cx18_stream *s = &cx->streams[id->type];
  245. int ret;
  246. int w, h;
  247. ret = cx18_try_fmt_vid_cap(file, fh, fmt);
  248. if (ret)
  249. return ret;
  250. w = fmt->fmt.pix.width;
  251. h = fmt->fmt.pix.height;
  252. if (cx->cxhdl.width == w && cx->cxhdl.height == h &&
  253. s->pixelformat == fmt->fmt.pix.pixelformat)
  254. return 0;
  255. if (atomic_read(&cx->ana_capturing) > 0)
  256. return -EBUSY;
  257. s->pixelformat = fmt->fmt.pix.pixelformat;
  258. /* HM12 YUV size is (Y=(h*720) + UV=(h*(720/2)))
  259. UYUV YUV size is (Y=(h*720) + UV=(h*(720))) */
  260. if (s->pixelformat == V4L2_PIX_FMT_HM12)
  261. s->vb_bytes_per_frame = h * 720 * 3 / 2;
  262. else
  263. s->vb_bytes_per_frame = h * 720 * 2;
  264. mbus_fmt.width = cx->cxhdl.width = w;
  265. mbus_fmt.height = cx->cxhdl.height = h;
  266. mbus_fmt.code = V4L2_MBUS_FMT_FIXED;
  267. v4l2_subdev_call(cx->sd_av, video, s_mbus_fmt, &mbus_fmt);
  268. return cx18_g_fmt_vid_cap(file, fh, fmt);
  269. }
  270. static int cx18_s_fmt_vbi_cap(struct file *file, void *fh,
  271. struct v4l2_format *fmt)
  272. {
  273. struct cx18_open_id *id = fh2id(fh);
  274. struct cx18 *cx = id->cx;
  275. int ret;
  276. /*
  277. * Changing the Encoder's Raw VBI parameters won't have any effect
  278. * if any analog capture is ongoing
  279. */
  280. if (!cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
  281. return -EBUSY;
  282. /*
  283. * Set the digitizer registers for raw active VBI.
  284. * Note cx18_av_vbi_wipes out a lot of the passed in fmt under valid
  285. * calling conditions
  286. */
  287. ret = v4l2_subdev_call(cx->sd_av, vbi, s_raw_fmt, &fmt->fmt.vbi);
  288. if (ret)
  289. return ret;
  290. /* Store our new v4l2 (non-)sliced VBI state */
  291. cx->vbi.sliced_in->service_set = 0;
  292. cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
  293. return cx18_g_fmt_vbi_cap(file, fh, fmt);
  294. }
  295. static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
  296. struct v4l2_format *fmt)
  297. {
  298. struct cx18_open_id *id = fh2id(fh);
  299. struct cx18 *cx = id->cx;
  300. int ret;
  301. struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
  302. cx18_try_fmt_sliced_vbi_cap(file, fh, fmt);
  303. /*
  304. * Changing the Encoder's Raw VBI parameters won't have any effect
  305. * if any analog capture is ongoing
  306. */
  307. if (cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
  308. return -EBUSY;
  309. /*
  310. * Set the service_lines requested in the digitizer/slicer registers.
  311. * Note, cx18_av_vbi() wipes some "impossible" service lines in the
  312. * passed in fmt->fmt.sliced under valid calling conditions
  313. */
  314. ret = v4l2_subdev_call(cx->sd_av, vbi, s_sliced_fmt, &fmt->fmt.sliced);
  315. if (ret)
  316. return ret;
  317. /* Store our current v4l2 sliced VBI settings */
  318. cx->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
  319. memcpy(cx->vbi.sliced_in, vbifmt, sizeof(*cx->vbi.sliced_in));
  320. return 0;
  321. }
  322. #ifdef CONFIG_VIDEO_ADV_DEBUG
  323. static int cx18_g_register(struct file *file, void *fh,
  324. struct v4l2_dbg_register *reg)
  325. {
  326. struct cx18 *cx = fh2id(fh)->cx;
  327. if (reg->reg & 0x3)
  328. return -EINVAL;
  329. if (reg->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
  330. return -EINVAL;
  331. reg->size = 4;
  332. reg->val = cx18_read_enc(cx, reg->reg);
  333. return 0;
  334. }
  335. static int cx18_s_register(struct file *file, void *fh,
  336. const struct v4l2_dbg_register *reg)
  337. {
  338. struct cx18 *cx = fh2id(fh)->cx;
  339. if (reg->reg & 0x3)
  340. return -EINVAL;
  341. if (reg->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
  342. return -EINVAL;
  343. cx18_write_enc(cx, reg->val, reg->reg);
  344. return 0;
  345. }
  346. #endif
  347. static int cx18_querycap(struct file *file, void *fh,
  348. struct v4l2_capability *vcap)
  349. {
  350. struct cx18_open_id *id = fh2id(fh);
  351. struct cx18 *cx = id->cx;
  352. strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
  353. strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
  354. snprintf(vcap->bus_info, sizeof(vcap->bus_info),
  355. "PCI:%s", pci_name(cx->pci_dev));
  356. vcap->capabilities = cx->v4l2_cap; /* capabilities */
  357. if (id->type == CX18_ENC_STREAM_TYPE_YUV)
  358. vcap->capabilities |= V4L2_CAP_STREAMING;
  359. return 0;
  360. }
  361. static int cx18_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
  362. {
  363. struct cx18 *cx = fh2id(fh)->cx;
  364. return cx18_get_audio_input(cx, vin->index, vin);
  365. }
  366. static int cx18_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
  367. {
  368. struct cx18 *cx = fh2id(fh)->cx;
  369. vin->index = cx->audio_input;
  370. return cx18_get_audio_input(cx, vin->index, vin);
  371. }
  372. static int cx18_s_audio(struct file *file, void *fh, const struct v4l2_audio *vout)
  373. {
  374. struct cx18 *cx = fh2id(fh)->cx;
  375. if (vout->index >= cx->nof_audio_inputs)
  376. return -EINVAL;
  377. cx->audio_input = vout->index;
  378. cx18_audio_set_io(cx);
  379. return 0;
  380. }
  381. static int cx18_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
  382. {
  383. struct cx18 *cx = fh2id(fh)->cx;
  384. /* set it to defaults from our table */
  385. return cx18_get_input(cx, vin->index, vin);
  386. }
  387. static int cx18_cropcap(struct file *file, void *fh,
  388. struct v4l2_cropcap *cropcap)
  389. {
  390. struct cx18 *cx = fh2id(fh)->cx;
  391. if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  392. return -EINVAL;
  393. cropcap->bounds.top = cropcap->bounds.left = 0;
  394. cropcap->bounds.width = 720;
  395. cropcap->bounds.height = cx->is_50hz ? 576 : 480;
  396. cropcap->pixelaspect.numerator = cx->is_50hz ? 59 : 10;
  397. cropcap->pixelaspect.denominator = cx->is_50hz ? 54 : 11;
  398. cropcap->defrect = cropcap->bounds;
  399. return 0;
  400. }
  401. static int cx18_s_crop(struct file *file, void *fh, const struct v4l2_crop *crop)
  402. {
  403. struct cx18_open_id *id = fh2id(fh);
  404. struct cx18 *cx = id->cx;
  405. if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  406. return -EINVAL;
  407. CX18_DEBUG_WARN("VIDIOC_S_CROP not implemented\n");
  408. return -EINVAL;
  409. }
  410. static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
  411. {
  412. struct cx18 *cx = fh2id(fh)->cx;
  413. if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  414. return -EINVAL;
  415. CX18_DEBUG_WARN("VIDIOC_G_CROP not implemented\n");
  416. return -EINVAL;
  417. }
  418. static int cx18_enum_fmt_vid_cap(struct file *file, void *fh,
  419. struct v4l2_fmtdesc *fmt)
  420. {
  421. static const struct v4l2_fmtdesc formats[] = {
  422. { 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
  423. "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
  424. },
  425. { 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
  426. "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
  427. },
  428. { 2, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
  429. "UYVY 4:2:2", V4L2_PIX_FMT_UYVY, { 0, 0, 0, 0 }
  430. },
  431. };
  432. if (fmt->index > ARRAY_SIZE(formats) - 1)
  433. return -EINVAL;
  434. *fmt = formats[fmt->index];
  435. return 0;
  436. }
  437. static int cx18_g_input(struct file *file, void *fh, unsigned int *i)
  438. {
  439. struct cx18 *cx = fh2id(fh)->cx;
  440. *i = cx->active_input;
  441. return 0;
  442. }
  443. int cx18_s_input(struct file *file, void *fh, unsigned int inp)
  444. {
  445. struct cx18_open_id *id = fh2id(fh);
  446. struct cx18 *cx = id->cx;
  447. if (inp >= cx->nof_inputs)
  448. return -EINVAL;
  449. if (inp == cx->active_input) {
  450. CX18_DEBUG_INFO("Input unchanged\n");
  451. return 0;
  452. }
  453. CX18_DEBUG_INFO("Changing input from %d to %d\n",
  454. cx->active_input, inp);
  455. cx->active_input = inp;
  456. /* Set the audio input to whatever is appropriate for the input type. */
  457. cx->audio_input = cx->card->video_inputs[inp].audio_index;
  458. /* prevent others from messing with the streams until
  459. we're finished changing inputs. */
  460. cx18_mute(cx);
  461. cx18_video_set_io(cx);
  462. cx18_audio_set_io(cx);
  463. cx18_unmute(cx);
  464. return 0;
  465. }
  466. static int cx18_g_frequency(struct file *file, void *fh,
  467. struct v4l2_frequency *vf)
  468. {
  469. struct cx18 *cx = fh2id(fh)->cx;
  470. if (vf->tuner != 0)
  471. return -EINVAL;
  472. cx18_call_all(cx, tuner, g_frequency, vf);
  473. return 0;
  474. }
  475. int cx18_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *vf)
  476. {
  477. struct cx18_open_id *id = fh2id(fh);
  478. struct cx18 *cx = id->cx;
  479. if (vf->tuner != 0)
  480. return -EINVAL;
  481. cx18_mute(cx);
  482. CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
  483. cx18_call_all(cx, tuner, s_frequency, vf);
  484. cx18_unmute(cx);
  485. return 0;
  486. }
  487. static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std)
  488. {
  489. struct cx18 *cx = fh2id(fh)->cx;
  490. *std = cx->std;
  491. return 0;
  492. }
  493. int cx18_s_std(struct file *file, void *fh, v4l2_std_id std)
  494. {
  495. struct cx18_open_id *id = fh2id(fh);
  496. struct cx18 *cx = id->cx;
  497. if ((std & V4L2_STD_ALL) == 0)
  498. return -EINVAL;
  499. if (std == cx->std)
  500. return 0;
  501. if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ||
  502. atomic_read(&cx->ana_capturing) > 0) {
  503. /* Switching standard would turn off the radio or mess
  504. with already running streams, prevent that by
  505. returning EBUSY. */
  506. return -EBUSY;
  507. }
  508. cx->std = std;
  509. cx->is_60hz = (std & V4L2_STD_525_60) ? 1 : 0;
  510. cx->is_50hz = !cx->is_60hz;
  511. cx2341x_handler_set_50hz(&cx->cxhdl, cx->is_50hz);
  512. cx->cxhdl.width = 720;
  513. cx->cxhdl.height = cx->is_50hz ? 576 : 480;
  514. cx->vbi.count = cx->is_50hz ? 18 : 12;
  515. cx->vbi.start[0] = cx->is_50hz ? 6 : 10;
  516. cx->vbi.start[1] = cx->is_50hz ? 318 : 273;
  517. CX18_DEBUG_INFO("Switching standard to %llx.\n",
  518. (unsigned long long) cx->std);
  519. /* Tuner */
  520. cx18_call_all(cx, core, s_std, cx->std);
  521. return 0;
  522. }
  523. static int cx18_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *vt)
  524. {
  525. struct cx18_open_id *id = fh2id(fh);
  526. struct cx18 *cx = id->cx;
  527. if (vt->index != 0)
  528. return -EINVAL;
  529. cx18_call_all(cx, tuner, s_tuner, vt);
  530. return 0;
  531. }
  532. static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
  533. {
  534. struct cx18 *cx = fh2id(fh)->cx;
  535. if (vt->index != 0)
  536. return -EINVAL;
  537. cx18_call_all(cx, tuner, g_tuner, vt);
  538. if (vt->type == V4L2_TUNER_RADIO)
  539. strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name));
  540. else
  541. strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name));
  542. return 0;
  543. }
  544. static int cx18_g_sliced_vbi_cap(struct file *file, void *fh,
  545. struct v4l2_sliced_vbi_cap *cap)
  546. {
  547. struct cx18 *cx = fh2id(fh)->cx;
  548. int set = cx->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
  549. int f, l;
  550. if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
  551. return -EINVAL;
  552. cap->service_set = 0;
  553. for (f = 0; f < 2; f++) {
  554. for (l = 0; l < 24; l++) {
  555. if (valid_service_line(f, l, cx->is_50hz)) {
  556. /*
  557. * We can find all v4l2 supported vbi services
  558. * for the standard, on a valid line for the std
  559. */
  560. cap->service_lines[f][l] = set;
  561. cap->service_set |= set;
  562. } else
  563. cap->service_lines[f][l] = 0;
  564. }
  565. }
  566. for (f = 0; f < 3; f++)
  567. cap->reserved[f] = 0;
  568. return 0;
  569. }
  570. static int _cx18_process_idx_data(struct cx18_buffer *buf,
  571. struct v4l2_enc_idx *idx)
  572. {
  573. int consumed, remaining;
  574. struct v4l2_enc_idx_entry *e_idx;
  575. struct cx18_enc_idx_entry *e_buf;
  576. /* Frame type lookup: 1=I, 2=P, 4=B */
  577. const int mapping[8] = {
  578. -1, V4L2_ENC_IDX_FRAME_I, V4L2_ENC_IDX_FRAME_P,
  579. -1, V4L2_ENC_IDX_FRAME_B, -1, -1, -1
  580. };
  581. /*
  582. * Assumption here is that a buf holds an integral number of
  583. * struct cx18_enc_idx_entry objects and is properly aligned.
  584. * This is enforced by the module options on IDX buffer sizes.
  585. */
  586. remaining = buf->bytesused - buf->readpos;
  587. consumed = 0;
  588. e_idx = &idx->entry[idx->entries];
  589. e_buf = (struct cx18_enc_idx_entry *) &buf->buf[buf->readpos];
  590. while (remaining >= sizeof(struct cx18_enc_idx_entry) &&
  591. idx->entries < V4L2_ENC_IDX_ENTRIES) {
  592. e_idx->offset = (((u64) le32_to_cpu(e_buf->offset_high)) << 32)
  593. | le32_to_cpu(e_buf->offset_low);
  594. e_idx->pts = (((u64) (le32_to_cpu(e_buf->pts_high) & 1)) << 32)
  595. | le32_to_cpu(e_buf->pts_low);
  596. e_idx->length = le32_to_cpu(e_buf->length);
  597. e_idx->flags = mapping[le32_to_cpu(e_buf->flags) & 0x7];
  598. e_idx->reserved[0] = 0;
  599. e_idx->reserved[1] = 0;
  600. idx->entries++;
  601. e_idx = &idx->entry[idx->entries];
  602. e_buf++;
  603. remaining -= sizeof(struct cx18_enc_idx_entry);
  604. consumed += sizeof(struct cx18_enc_idx_entry);
  605. }
  606. /* Swallow any partial entries at the end, if there are any */
  607. if (remaining > 0 && remaining < sizeof(struct cx18_enc_idx_entry))
  608. consumed += remaining;
  609. buf->readpos += consumed;
  610. return consumed;
  611. }
  612. static int cx18_process_idx_data(struct cx18_stream *s, struct cx18_mdl *mdl,
  613. struct v4l2_enc_idx *idx)
  614. {
  615. if (s->type != CX18_ENC_STREAM_TYPE_IDX)
  616. return -EINVAL;
  617. if (mdl->curr_buf == NULL)
  618. mdl->curr_buf = list_first_entry(&mdl->buf_list,
  619. struct cx18_buffer, list);
  620. if (list_entry_is_past_end(mdl->curr_buf, &mdl->buf_list, list)) {
  621. /*
  622. * For some reason we've exhausted the buffers, but the MDL
  623. * object still said some data was unread.
  624. * Fix that and bail out.
  625. */
  626. mdl->readpos = mdl->bytesused;
  627. return 0;
  628. }
  629. list_for_each_entry_from(mdl->curr_buf, &mdl->buf_list, list) {
  630. /* Skip any empty buffers in the MDL */
  631. if (mdl->curr_buf->readpos >= mdl->curr_buf->bytesused)
  632. continue;
  633. mdl->readpos += _cx18_process_idx_data(mdl->curr_buf, idx);
  634. /* exit when MDL drained or request satisfied */
  635. if (idx->entries >= V4L2_ENC_IDX_ENTRIES ||
  636. mdl->curr_buf->readpos < mdl->curr_buf->bytesused ||
  637. mdl->readpos >= mdl->bytesused)
  638. break;
  639. }
  640. return 0;
  641. }
  642. static int cx18_g_enc_index(struct file *file, void *fh,
  643. struct v4l2_enc_idx *idx)
  644. {
  645. struct cx18 *cx = fh2id(fh)->cx;
  646. struct cx18_stream *s = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
  647. s32 tmp;
  648. struct cx18_mdl *mdl;
  649. if (!cx18_stream_enabled(s)) /* Module options inhibited IDX stream */
  650. return -EINVAL;
  651. /* Compute the best case number of entries we can buffer */
  652. tmp = s->buffers -
  653. s->bufs_per_mdl * CX18_ENC_STREAM_TYPE_IDX_FW_MDL_MIN;
  654. if (tmp <= 0)
  655. tmp = 1;
  656. tmp = tmp * s->buf_size / sizeof(struct cx18_enc_idx_entry);
  657. /* Fill out the header of the return structure */
  658. idx->entries = 0;
  659. idx->entries_cap = tmp;
  660. memset(idx->reserved, 0, sizeof(idx->reserved));
  661. /* Pull IDX MDLs and buffers from q_full and populate the entries */
  662. do {
  663. mdl = cx18_dequeue(s, &s->q_full);
  664. if (mdl == NULL) /* No more IDX data right now */
  665. break;
  666. /* Extract the Index entry data from the MDL and buffers */
  667. cx18_process_idx_data(s, mdl, idx);
  668. if (mdl->readpos < mdl->bytesused) {
  669. /* We finished with data remaining, push the MDL back */
  670. cx18_push(s, mdl, &s->q_full);
  671. break;
  672. }
  673. /* We drained this MDL, schedule it to go to the firmware */
  674. cx18_enqueue(s, mdl, &s->q_free);
  675. } while (idx->entries < V4L2_ENC_IDX_ENTRIES);
  676. /* Tell the work handler to send free IDX MDLs to the firmware */
  677. cx18_stream_load_fw_queue(s);
  678. return 0;
  679. }
  680. static struct videobuf_queue *cx18_vb_queue(struct cx18_open_id *id)
  681. {
  682. struct videobuf_queue *q = NULL;
  683. struct cx18 *cx = id->cx;
  684. struct cx18_stream *s = &cx->streams[id->type];
  685. switch (s->vb_type) {
  686. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  687. q = &s->vbuf_q;
  688. break;
  689. case V4L2_BUF_TYPE_VBI_CAPTURE:
  690. break;
  691. default:
  692. break;
  693. }
  694. return q;
  695. }
  696. static int cx18_streamon(struct file *file, void *priv,
  697. enum v4l2_buf_type type)
  698. {
  699. struct cx18_open_id *id = file->private_data;
  700. struct cx18 *cx = id->cx;
  701. struct cx18_stream *s = &cx->streams[id->type];
  702. /* Start the hardware only if we're the video device */
  703. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  704. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  705. return -EINVAL;
  706. if (id->type != CX18_ENC_STREAM_TYPE_YUV)
  707. return -EINVAL;
  708. /* Establish a buffer timeout */
  709. mod_timer(&s->vb_timeout, msecs_to_jiffies(2000) + jiffies);
  710. return videobuf_streamon(cx18_vb_queue(id));
  711. }
  712. static int cx18_streamoff(struct file *file, void *priv,
  713. enum v4l2_buf_type type)
  714. {
  715. struct cx18_open_id *id = file->private_data;
  716. struct cx18 *cx = id->cx;
  717. struct cx18_stream *s = &cx->streams[id->type];
  718. /* Start the hardware only if we're the video device */
  719. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  720. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  721. return -EINVAL;
  722. if (id->type != CX18_ENC_STREAM_TYPE_YUV)
  723. return -EINVAL;
  724. return videobuf_streamoff(cx18_vb_queue(id));
  725. }
  726. static int cx18_reqbufs(struct file *file, void *priv,
  727. struct v4l2_requestbuffers *rb)
  728. {
  729. struct cx18_open_id *id = file->private_data;
  730. struct cx18 *cx = id->cx;
  731. struct cx18_stream *s = &cx->streams[id->type];
  732. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  733. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  734. return -EINVAL;
  735. return videobuf_reqbufs(cx18_vb_queue(id), rb);
  736. }
  737. static int cx18_querybuf(struct file *file, void *priv,
  738. struct v4l2_buffer *b)
  739. {
  740. struct cx18_open_id *id = file->private_data;
  741. struct cx18 *cx = id->cx;
  742. struct cx18_stream *s = &cx->streams[id->type];
  743. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  744. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  745. return -EINVAL;
  746. return videobuf_querybuf(cx18_vb_queue(id), b);
  747. }
  748. static int cx18_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  749. {
  750. struct cx18_open_id *id = file->private_data;
  751. struct cx18 *cx = id->cx;
  752. struct cx18_stream *s = &cx->streams[id->type];
  753. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  754. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  755. return -EINVAL;
  756. return videobuf_qbuf(cx18_vb_queue(id), b);
  757. }
  758. static int cx18_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  759. {
  760. struct cx18_open_id *id = file->private_data;
  761. struct cx18 *cx = id->cx;
  762. struct cx18_stream *s = &cx->streams[id->type];
  763. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  764. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  765. return -EINVAL;
  766. return videobuf_dqbuf(cx18_vb_queue(id), b, file->f_flags & O_NONBLOCK);
  767. }
  768. static int cx18_encoder_cmd(struct file *file, void *fh,
  769. struct v4l2_encoder_cmd *enc)
  770. {
  771. struct cx18_open_id *id = fh2id(fh);
  772. struct cx18 *cx = id->cx;
  773. u32 h;
  774. switch (enc->cmd) {
  775. case V4L2_ENC_CMD_START:
  776. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
  777. enc->flags = 0;
  778. return cx18_start_capture(id);
  779. case V4L2_ENC_CMD_STOP:
  780. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
  781. enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
  782. cx18_stop_capture(id,
  783. enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
  784. break;
  785. case V4L2_ENC_CMD_PAUSE:
  786. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
  787. enc->flags = 0;
  788. if (!atomic_read(&cx->ana_capturing))
  789. return -EPERM;
  790. if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
  791. return 0;
  792. h = cx18_find_handle(cx);
  793. if (h == CX18_INVALID_TASK_HANDLE) {
  794. CX18_ERR("Can't find valid task handle for "
  795. "V4L2_ENC_CMD_PAUSE\n");
  796. return -EBADFD;
  797. }
  798. cx18_mute(cx);
  799. cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h);
  800. break;
  801. case V4L2_ENC_CMD_RESUME:
  802. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
  803. enc->flags = 0;
  804. if (!atomic_read(&cx->ana_capturing))
  805. return -EPERM;
  806. if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
  807. return 0;
  808. h = cx18_find_handle(cx);
  809. if (h == CX18_INVALID_TASK_HANDLE) {
  810. CX18_ERR("Can't find valid task handle for "
  811. "V4L2_ENC_CMD_RESUME\n");
  812. return -EBADFD;
  813. }
  814. cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h);
  815. cx18_unmute(cx);
  816. break;
  817. default:
  818. CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
  819. return -EINVAL;
  820. }
  821. return 0;
  822. }
  823. static int cx18_try_encoder_cmd(struct file *file, void *fh,
  824. struct v4l2_encoder_cmd *enc)
  825. {
  826. struct cx18 *cx = fh2id(fh)->cx;
  827. switch (enc->cmd) {
  828. case V4L2_ENC_CMD_START:
  829. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
  830. enc->flags = 0;
  831. break;
  832. case V4L2_ENC_CMD_STOP:
  833. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
  834. enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
  835. break;
  836. case V4L2_ENC_CMD_PAUSE:
  837. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
  838. enc->flags = 0;
  839. break;
  840. case V4L2_ENC_CMD_RESUME:
  841. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
  842. enc->flags = 0;
  843. break;
  844. default:
  845. CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
  846. return -EINVAL;
  847. }
  848. return 0;
  849. }
  850. static int cx18_log_status(struct file *file, void *fh)
  851. {
  852. struct cx18 *cx = fh2id(fh)->cx;
  853. struct v4l2_input vidin;
  854. struct v4l2_audio audin;
  855. int i;
  856. CX18_INFO("Version: %s Card: %s\n", CX18_VERSION, cx->card_name);
  857. if (cx->hw_flags & CX18_HW_TVEEPROM) {
  858. struct tveeprom tv;
  859. cx18_read_eeprom(cx, &tv);
  860. }
  861. cx18_call_all(cx, core, log_status);
  862. cx18_get_input(cx, cx->active_input, &vidin);
  863. cx18_get_audio_input(cx, cx->audio_input, &audin);
  864. CX18_INFO("Video Input: %s\n", vidin.name);
  865. CX18_INFO("Audio Input: %s\n", audin.name);
  866. mutex_lock(&cx->gpio_lock);
  867. CX18_INFO("GPIO: direction 0x%08x, value 0x%08x\n",
  868. cx->gpio_dir, cx->gpio_val);
  869. mutex_unlock(&cx->gpio_lock);
  870. CX18_INFO("Tuner: %s\n",
  871. test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV");
  872. v4l2_ctrl_handler_log_status(&cx->cxhdl.hdl, cx->v4l2_dev.name);
  873. CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags);
  874. for (i = 0; i < CX18_MAX_STREAMS; i++) {
  875. struct cx18_stream *s = &cx->streams[i];
  876. if (s->video_dev == NULL || s->buffers == 0)
  877. continue;
  878. CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
  879. s->name, s->s_flags,
  880. atomic_read(&s->q_full.depth) * s->bufs_per_mdl * 100
  881. / s->buffers,
  882. (s->buffers * s->buf_size) / 1024, s->buffers);
  883. }
  884. CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
  885. (long long)cx->mpg_data_received,
  886. (long long)cx->vbi_data_inserted);
  887. return 0;
  888. }
  889. static long cx18_default(struct file *file, void *fh, bool valid_prio,
  890. unsigned int cmd, void *arg)
  891. {
  892. struct cx18 *cx = fh2id(fh)->cx;
  893. switch (cmd) {
  894. case VIDIOC_INT_RESET: {
  895. u32 val = *(u32 *)arg;
  896. if ((val == 0) || (val & 0x01))
  897. cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL, core, reset,
  898. (u32) CX18_GPIO_RESET_Z8F0811);
  899. break;
  900. }
  901. default:
  902. return -ENOTTY;
  903. }
  904. return 0;
  905. }
  906. static const struct v4l2_ioctl_ops cx18_ioctl_ops = {
  907. .vidioc_querycap = cx18_querycap,
  908. .vidioc_s_audio = cx18_s_audio,
  909. .vidioc_g_audio = cx18_g_audio,
  910. .vidioc_enumaudio = cx18_enumaudio,
  911. .vidioc_enum_input = cx18_enum_input,
  912. .vidioc_cropcap = cx18_cropcap,
  913. .vidioc_s_crop = cx18_s_crop,
  914. .vidioc_g_crop = cx18_g_crop,
  915. .vidioc_g_input = cx18_g_input,
  916. .vidioc_s_input = cx18_s_input,
  917. .vidioc_g_frequency = cx18_g_frequency,
  918. .vidioc_s_frequency = cx18_s_frequency,
  919. .vidioc_s_tuner = cx18_s_tuner,
  920. .vidioc_g_tuner = cx18_g_tuner,
  921. .vidioc_g_enc_index = cx18_g_enc_index,
  922. .vidioc_g_std = cx18_g_std,
  923. .vidioc_s_std = cx18_s_std,
  924. .vidioc_log_status = cx18_log_status,
  925. .vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap,
  926. .vidioc_encoder_cmd = cx18_encoder_cmd,
  927. .vidioc_try_encoder_cmd = cx18_try_encoder_cmd,
  928. .vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap,
  929. .vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap,
  930. .vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap,
  931. .vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap,
  932. .vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap,
  933. .vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap,
  934. .vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap,
  935. .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap,
  936. .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap,
  937. .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap,
  938. #ifdef CONFIG_VIDEO_ADV_DEBUG
  939. .vidioc_g_register = cx18_g_register,
  940. .vidioc_s_register = cx18_s_register,
  941. #endif
  942. .vidioc_default = cx18_default,
  943. .vidioc_streamon = cx18_streamon,
  944. .vidioc_streamoff = cx18_streamoff,
  945. .vidioc_reqbufs = cx18_reqbufs,
  946. .vidioc_querybuf = cx18_querybuf,
  947. .vidioc_qbuf = cx18_qbuf,
  948. .vidioc_dqbuf = cx18_dqbuf,
  949. };
  950. void cx18_set_funcs(struct video_device *vdev)
  951. {
  952. vdev->ioctl_ops = &cx18_ioctl_ops;
  953. }