cx18-ioctl.c 32 KB

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