cx18-ioctl.c 30 KB

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