cx18-ioctl.c 30 KB

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