cx18-ioctl.c 33 KB

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