cx18-ioctl.c 33 KB

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