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. /* 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->capabilities = cx->v4l2_cap; /* capabilities */
  421. return 0;
  422. }
  423. static int cx18_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
  424. {
  425. struct cx18 *cx = fh2id(fh)->cx;
  426. return cx18_get_audio_input(cx, vin->index, vin);
  427. }
  428. static int cx18_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
  429. {
  430. struct cx18 *cx = fh2id(fh)->cx;
  431. vin->index = cx->audio_input;
  432. return cx18_get_audio_input(cx, vin->index, vin);
  433. }
  434. static int cx18_s_audio(struct file *file, void *fh, struct v4l2_audio *vout)
  435. {
  436. struct cx18 *cx = fh2id(fh)->cx;
  437. if (vout->index >= cx->nof_audio_inputs)
  438. return -EINVAL;
  439. cx->audio_input = vout->index;
  440. cx18_audio_set_io(cx);
  441. return 0;
  442. }
  443. static int cx18_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
  444. {
  445. struct cx18 *cx = fh2id(fh)->cx;
  446. /* set it to defaults from our table */
  447. return cx18_get_input(cx, vin->index, vin);
  448. }
  449. static int cx18_cropcap(struct file *file, void *fh,
  450. struct v4l2_cropcap *cropcap)
  451. {
  452. struct cx18 *cx = fh2id(fh)->cx;
  453. if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  454. return -EINVAL;
  455. cropcap->bounds.top = cropcap->bounds.left = 0;
  456. cropcap->bounds.width = 720;
  457. cropcap->bounds.height = cx->is_50hz ? 576 : 480;
  458. cropcap->pixelaspect.numerator = cx->is_50hz ? 59 : 10;
  459. cropcap->pixelaspect.denominator = cx->is_50hz ? 54 : 11;
  460. cropcap->defrect = cropcap->bounds;
  461. return 0;
  462. }
  463. static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
  464. {
  465. struct cx18_open_id *id = fh2id(fh);
  466. struct cx18 *cx = id->cx;
  467. if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  468. return -EINVAL;
  469. CX18_DEBUG_WARN("VIDIOC_S_CROP not implemented\n");
  470. return -EINVAL;
  471. }
  472. static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
  473. {
  474. struct cx18 *cx = fh2id(fh)->cx;
  475. if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  476. return -EINVAL;
  477. CX18_DEBUG_WARN("VIDIOC_G_CROP not implemented\n");
  478. return -EINVAL;
  479. }
  480. static int cx18_enum_fmt_vid_cap(struct file *file, void *fh,
  481. struct v4l2_fmtdesc *fmt)
  482. {
  483. static const struct v4l2_fmtdesc formats[] = {
  484. { 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
  485. "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
  486. },
  487. { 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
  488. "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
  489. },
  490. { 2, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
  491. "UYVY 4:2:2", V4L2_PIX_FMT_UYVY, { 0, 0, 0, 0 }
  492. },
  493. };
  494. if (fmt->index > ARRAY_SIZE(formats) - 1)
  495. return -EINVAL;
  496. *fmt = formats[fmt->index];
  497. return 0;
  498. }
  499. static int cx18_g_input(struct file *file, void *fh, unsigned int *i)
  500. {
  501. struct cx18 *cx = fh2id(fh)->cx;
  502. *i = cx->active_input;
  503. return 0;
  504. }
  505. int cx18_s_input(struct file *file, void *fh, unsigned int inp)
  506. {
  507. struct cx18_open_id *id = fh2id(fh);
  508. struct cx18 *cx = id->cx;
  509. if (inp >= cx->nof_inputs)
  510. return -EINVAL;
  511. if (inp == cx->active_input) {
  512. CX18_DEBUG_INFO("Input unchanged\n");
  513. return 0;
  514. }
  515. CX18_DEBUG_INFO("Changing input from %d to %d\n",
  516. cx->active_input, inp);
  517. cx->active_input = inp;
  518. /* Set the audio input to whatever is appropriate for the input type. */
  519. cx->audio_input = cx->card->video_inputs[inp].audio_index;
  520. /* prevent others from messing with the streams until
  521. we're finished changing inputs. */
  522. cx18_mute(cx);
  523. cx18_video_set_io(cx);
  524. cx18_audio_set_io(cx);
  525. cx18_unmute(cx);
  526. return 0;
  527. }
  528. static int cx18_g_frequency(struct file *file, void *fh,
  529. struct v4l2_frequency *vf)
  530. {
  531. struct cx18 *cx = fh2id(fh)->cx;
  532. if (vf->tuner != 0)
  533. return -EINVAL;
  534. cx18_call_all(cx, tuner, g_frequency, vf);
  535. return 0;
  536. }
  537. int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
  538. {
  539. struct cx18_open_id *id = fh2id(fh);
  540. struct cx18 *cx = id->cx;
  541. if (vf->tuner != 0)
  542. return -EINVAL;
  543. cx18_mute(cx);
  544. CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
  545. cx18_call_all(cx, tuner, s_frequency, vf);
  546. cx18_unmute(cx);
  547. return 0;
  548. }
  549. static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std)
  550. {
  551. struct cx18 *cx = fh2id(fh)->cx;
  552. *std = cx->std;
  553. return 0;
  554. }
  555. int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
  556. {
  557. struct cx18_open_id *id = fh2id(fh);
  558. struct cx18 *cx = id->cx;
  559. if ((*std & V4L2_STD_ALL) == 0)
  560. return -EINVAL;
  561. if (*std == cx->std)
  562. return 0;
  563. if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ||
  564. atomic_read(&cx->ana_capturing) > 0) {
  565. /* Switching standard would turn off the radio or mess
  566. with already running streams, prevent that by
  567. returning EBUSY. */
  568. return -EBUSY;
  569. }
  570. cx->std = *std;
  571. cx->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
  572. cx->is_50hz = !cx->is_60hz;
  573. cx2341x_handler_set_50hz(&cx->cxhdl, cx->is_50hz);
  574. cx->cxhdl.width = 720;
  575. cx->cxhdl.height = cx->is_50hz ? 576 : 480;
  576. cx->vbi.count = cx->is_50hz ? 18 : 12;
  577. cx->vbi.start[0] = cx->is_50hz ? 6 : 10;
  578. cx->vbi.start[1] = cx->is_50hz ? 318 : 273;
  579. CX18_DEBUG_INFO("Switching standard to %llx.\n",
  580. (unsigned long long) cx->std);
  581. /* Tuner */
  582. cx18_call_all(cx, core, s_std, cx->std);
  583. return 0;
  584. }
  585. static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
  586. {
  587. struct cx18_open_id *id = fh2id(fh);
  588. struct cx18 *cx = id->cx;
  589. if (vt->index != 0)
  590. return -EINVAL;
  591. cx18_call_all(cx, tuner, s_tuner, vt);
  592. return 0;
  593. }
  594. static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
  595. {
  596. struct cx18 *cx = fh2id(fh)->cx;
  597. if (vt->index != 0)
  598. return -EINVAL;
  599. cx18_call_all(cx, tuner, g_tuner, vt);
  600. if (vt->type == V4L2_TUNER_RADIO)
  601. strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name));
  602. else
  603. strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name));
  604. return 0;
  605. }
  606. static int cx18_g_sliced_vbi_cap(struct file *file, void *fh,
  607. struct v4l2_sliced_vbi_cap *cap)
  608. {
  609. struct cx18 *cx = fh2id(fh)->cx;
  610. int set = cx->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
  611. int f, l;
  612. if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
  613. return -EINVAL;
  614. cap->service_set = 0;
  615. for (f = 0; f < 2; f++) {
  616. for (l = 0; l < 24; l++) {
  617. if (valid_service_line(f, l, cx->is_50hz)) {
  618. /*
  619. * We can find all v4l2 supported vbi services
  620. * for the standard, on a valid line for the std
  621. */
  622. cap->service_lines[f][l] = set;
  623. cap->service_set |= set;
  624. } else
  625. cap->service_lines[f][l] = 0;
  626. }
  627. }
  628. for (f = 0; f < 3; f++)
  629. cap->reserved[f] = 0;
  630. return 0;
  631. }
  632. static int _cx18_process_idx_data(struct cx18_buffer *buf,
  633. struct v4l2_enc_idx *idx)
  634. {
  635. int consumed, remaining;
  636. struct v4l2_enc_idx_entry *e_idx;
  637. struct cx18_enc_idx_entry *e_buf;
  638. /* Frame type lookup: 1=I, 2=P, 4=B */
  639. const int mapping[8] = {
  640. -1, V4L2_ENC_IDX_FRAME_I, V4L2_ENC_IDX_FRAME_P,
  641. -1, V4L2_ENC_IDX_FRAME_B, -1, -1, -1
  642. };
  643. /*
  644. * Assumption here is that a buf holds an integral number of
  645. * struct cx18_enc_idx_entry objects and is properly aligned.
  646. * This is enforced by the module options on IDX buffer sizes.
  647. */
  648. remaining = buf->bytesused - buf->readpos;
  649. consumed = 0;
  650. e_idx = &idx->entry[idx->entries];
  651. e_buf = (struct cx18_enc_idx_entry *) &buf->buf[buf->readpos];
  652. while (remaining >= sizeof(struct cx18_enc_idx_entry) &&
  653. idx->entries < V4L2_ENC_IDX_ENTRIES) {
  654. e_idx->offset = (((u64) le32_to_cpu(e_buf->offset_high)) << 32)
  655. | le32_to_cpu(e_buf->offset_low);
  656. e_idx->pts = (((u64) (le32_to_cpu(e_buf->pts_high) & 1)) << 32)
  657. | le32_to_cpu(e_buf->pts_low);
  658. e_idx->length = le32_to_cpu(e_buf->length);
  659. e_idx->flags = mapping[le32_to_cpu(e_buf->flags) & 0x7];
  660. e_idx->reserved[0] = 0;
  661. e_idx->reserved[1] = 0;
  662. idx->entries++;
  663. e_idx = &idx->entry[idx->entries];
  664. e_buf++;
  665. remaining -= sizeof(struct cx18_enc_idx_entry);
  666. consumed += sizeof(struct cx18_enc_idx_entry);
  667. }
  668. /* Swallow any partial entries at the end, if there are any */
  669. if (remaining > 0 && remaining < sizeof(struct cx18_enc_idx_entry))
  670. consumed += remaining;
  671. buf->readpos += consumed;
  672. return consumed;
  673. }
  674. static int cx18_process_idx_data(struct cx18_stream *s, struct cx18_mdl *mdl,
  675. struct v4l2_enc_idx *idx)
  676. {
  677. if (s->type != CX18_ENC_STREAM_TYPE_IDX)
  678. return -EINVAL;
  679. if (mdl->curr_buf == NULL)
  680. mdl->curr_buf = list_first_entry(&mdl->buf_list,
  681. struct cx18_buffer, list);
  682. if (list_entry_is_past_end(mdl->curr_buf, &mdl->buf_list, list)) {
  683. /*
  684. * For some reason we've exhausted the buffers, but the MDL
  685. * object still said some data was unread.
  686. * Fix that and bail out.
  687. */
  688. mdl->readpos = mdl->bytesused;
  689. return 0;
  690. }
  691. list_for_each_entry_from(mdl->curr_buf, &mdl->buf_list, list) {
  692. /* Skip any empty buffers in the MDL */
  693. if (mdl->curr_buf->readpos >= mdl->curr_buf->bytesused)
  694. continue;
  695. mdl->readpos += _cx18_process_idx_data(mdl->curr_buf, idx);
  696. /* exit when MDL drained or request satisfied */
  697. if (idx->entries >= V4L2_ENC_IDX_ENTRIES ||
  698. mdl->curr_buf->readpos < mdl->curr_buf->bytesused ||
  699. mdl->readpos >= mdl->bytesused)
  700. break;
  701. }
  702. return 0;
  703. }
  704. static int cx18_g_enc_index(struct file *file, void *fh,
  705. struct v4l2_enc_idx *idx)
  706. {
  707. struct cx18 *cx = fh2id(fh)->cx;
  708. struct cx18_stream *s = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
  709. s32 tmp;
  710. struct cx18_mdl *mdl;
  711. if (!cx18_stream_enabled(s)) /* Module options inhibited IDX stream */
  712. return -EINVAL;
  713. /* Compute the best case number of entries we can buffer */
  714. tmp = s->buffers -
  715. s->bufs_per_mdl * CX18_ENC_STREAM_TYPE_IDX_FW_MDL_MIN;
  716. if (tmp <= 0)
  717. tmp = 1;
  718. tmp = tmp * s->buf_size / sizeof(struct cx18_enc_idx_entry);
  719. /* Fill out the header of the return structure */
  720. idx->entries = 0;
  721. idx->entries_cap = tmp;
  722. memset(idx->reserved, 0, sizeof(idx->reserved));
  723. /* Pull IDX MDLs and buffers from q_full and populate the entries */
  724. do {
  725. mdl = cx18_dequeue(s, &s->q_full);
  726. if (mdl == NULL) /* No more IDX data right now */
  727. break;
  728. /* Extract the Index entry data from the MDL and buffers */
  729. cx18_process_idx_data(s, mdl, idx);
  730. if (mdl->readpos < mdl->bytesused) {
  731. /* We finished with data remaining, push the MDL back */
  732. cx18_push(s, mdl, &s->q_full);
  733. break;
  734. }
  735. /* We drained this MDL, schedule it to go to the firmware */
  736. cx18_enqueue(s, mdl, &s->q_free);
  737. } while (idx->entries < V4L2_ENC_IDX_ENTRIES);
  738. /* Tell the work handler to send free IDX MDLs to the firmware */
  739. cx18_stream_load_fw_queue(s);
  740. return 0;
  741. }
  742. static struct videobuf_queue *cx18_vb_queue(struct cx18_open_id *id)
  743. {
  744. struct videobuf_queue *q = NULL;
  745. struct cx18 *cx = id->cx;
  746. struct cx18_stream *s = &cx->streams[id->type];
  747. switch (s->vb_type) {
  748. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  749. q = &s->vbuf_q;
  750. break;
  751. case V4L2_BUF_TYPE_VBI_CAPTURE:
  752. break;
  753. default:
  754. break;
  755. }
  756. return q;
  757. }
  758. static int cx18_streamon(struct file *file, void *priv,
  759. enum v4l2_buf_type type)
  760. {
  761. struct cx18_open_id *id = file->private_data;
  762. struct cx18 *cx = id->cx;
  763. struct cx18_stream *s = &cx->streams[id->type];
  764. /* Start the hardware only if we're the video device */
  765. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  766. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  767. return -EINVAL;
  768. if (id->type != CX18_ENC_STREAM_TYPE_YUV)
  769. return -EINVAL;
  770. /* Establish a buffer timeout */
  771. mod_timer(&s->vb_timeout, msecs_to_jiffies(2000) + jiffies);
  772. return videobuf_streamon(cx18_vb_queue(id));
  773. }
  774. static int cx18_streamoff(struct file *file, void *priv,
  775. enum v4l2_buf_type type)
  776. {
  777. struct cx18_open_id *id = file->private_data;
  778. struct cx18 *cx = id->cx;
  779. struct cx18_stream *s = &cx->streams[id->type];
  780. /* Start the hardware only if we're the video device */
  781. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  782. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  783. return -EINVAL;
  784. if (id->type != CX18_ENC_STREAM_TYPE_YUV)
  785. return -EINVAL;
  786. return videobuf_streamoff(cx18_vb_queue(id));
  787. }
  788. static int cx18_reqbufs(struct file *file, void *priv,
  789. struct v4l2_requestbuffers *rb)
  790. {
  791. struct cx18_open_id *id = file->private_data;
  792. struct cx18 *cx = id->cx;
  793. struct cx18_stream *s = &cx->streams[id->type];
  794. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  795. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  796. return -EINVAL;
  797. return videobuf_reqbufs(cx18_vb_queue(id), rb);
  798. }
  799. static int cx18_querybuf(struct file *file, void *priv,
  800. struct v4l2_buffer *b)
  801. {
  802. struct cx18_open_id *id = file->private_data;
  803. struct cx18 *cx = id->cx;
  804. struct cx18_stream *s = &cx->streams[id->type];
  805. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  806. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  807. return -EINVAL;
  808. return videobuf_querybuf(cx18_vb_queue(id), b);
  809. }
  810. static int cx18_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  811. {
  812. struct cx18_open_id *id = file->private_data;
  813. struct cx18 *cx = id->cx;
  814. struct cx18_stream *s = &cx->streams[id->type];
  815. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  816. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  817. return -EINVAL;
  818. return videobuf_qbuf(cx18_vb_queue(id), b);
  819. }
  820. static int cx18_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  821. {
  822. struct cx18_open_id *id = file->private_data;
  823. struct cx18 *cx = id->cx;
  824. struct cx18_stream *s = &cx->streams[id->type];
  825. if ((s->vb_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  826. (s->vb_type != V4L2_BUF_TYPE_VBI_CAPTURE))
  827. return -EINVAL;
  828. return videobuf_dqbuf(cx18_vb_queue(id), b, file->f_flags & O_NONBLOCK);
  829. }
  830. static int cx18_encoder_cmd(struct file *file, void *fh,
  831. struct v4l2_encoder_cmd *enc)
  832. {
  833. struct cx18_open_id *id = fh2id(fh);
  834. struct cx18 *cx = id->cx;
  835. u32 h;
  836. switch (enc->cmd) {
  837. case V4L2_ENC_CMD_START:
  838. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
  839. enc->flags = 0;
  840. return cx18_start_capture(id);
  841. case V4L2_ENC_CMD_STOP:
  842. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
  843. enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
  844. cx18_stop_capture(id,
  845. enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
  846. break;
  847. case V4L2_ENC_CMD_PAUSE:
  848. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
  849. enc->flags = 0;
  850. if (!atomic_read(&cx->ana_capturing))
  851. return -EPERM;
  852. if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
  853. return 0;
  854. h = cx18_find_handle(cx);
  855. if (h == CX18_INVALID_TASK_HANDLE) {
  856. CX18_ERR("Can't find valid task handle for "
  857. "V4L2_ENC_CMD_PAUSE\n");
  858. return -EBADFD;
  859. }
  860. cx18_mute(cx);
  861. cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h);
  862. break;
  863. case V4L2_ENC_CMD_RESUME:
  864. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
  865. enc->flags = 0;
  866. if (!atomic_read(&cx->ana_capturing))
  867. return -EPERM;
  868. if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
  869. return 0;
  870. h = cx18_find_handle(cx);
  871. if (h == CX18_INVALID_TASK_HANDLE) {
  872. CX18_ERR("Can't find valid task handle for "
  873. "V4L2_ENC_CMD_RESUME\n");
  874. return -EBADFD;
  875. }
  876. cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h);
  877. cx18_unmute(cx);
  878. break;
  879. default:
  880. CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
  881. return -EINVAL;
  882. }
  883. return 0;
  884. }
  885. static int cx18_try_encoder_cmd(struct file *file, void *fh,
  886. struct v4l2_encoder_cmd *enc)
  887. {
  888. struct cx18 *cx = fh2id(fh)->cx;
  889. switch (enc->cmd) {
  890. case V4L2_ENC_CMD_START:
  891. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
  892. enc->flags = 0;
  893. break;
  894. case V4L2_ENC_CMD_STOP:
  895. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
  896. enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
  897. break;
  898. case V4L2_ENC_CMD_PAUSE:
  899. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
  900. enc->flags = 0;
  901. break;
  902. case V4L2_ENC_CMD_RESUME:
  903. CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
  904. enc->flags = 0;
  905. break;
  906. default:
  907. CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
  908. return -EINVAL;
  909. }
  910. return 0;
  911. }
  912. static int cx18_log_status(struct file *file, void *fh)
  913. {
  914. struct cx18 *cx = fh2id(fh)->cx;
  915. struct v4l2_input vidin;
  916. struct v4l2_audio audin;
  917. int i;
  918. CX18_INFO("================= START STATUS CARD #%d "
  919. "=================\n", cx->instance);
  920. CX18_INFO("Version: %s Card: %s\n", CX18_VERSION, cx->card_name);
  921. if (cx->hw_flags & CX18_HW_TVEEPROM) {
  922. struct tveeprom tv;
  923. cx18_read_eeprom(cx, &tv);
  924. }
  925. cx18_call_all(cx, core, log_status);
  926. cx18_get_input(cx, cx->active_input, &vidin);
  927. cx18_get_audio_input(cx, cx->audio_input, &audin);
  928. CX18_INFO("Video Input: %s\n", vidin.name);
  929. CX18_INFO("Audio Input: %s\n", audin.name);
  930. mutex_lock(&cx->gpio_lock);
  931. CX18_INFO("GPIO: direction 0x%08x, value 0x%08x\n",
  932. cx->gpio_dir, cx->gpio_val);
  933. mutex_unlock(&cx->gpio_lock);
  934. CX18_INFO("Tuner: %s\n",
  935. test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV");
  936. v4l2_ctrl_handler_log_status(&cx->cxhdl.hdl, cx->v4l2_dev.name);
  937. CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags);
  938. for (i = 0; i < CX18_MAX_STREAMS; i++) {
  939. struct cx18_stream *s = &cx->streams[i];
  940. if (s->video_dev == NULL || s->buffers == 0)
  941. continue;
  942. CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
  943. s->name, s->s_flags,
  944. atomic_read(&s->q_full.depth) * s->bufs_per_mdl * 100
  945. / s->buffers,
  946. (s->buffers * s->buf_size) / 1024, s->buffers);
  947. }
  948. CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
  949. (long long)cx->mpg_data_received,
  950. (long long)cx->vbi_data_inserted);
  951. CX18_INFO("================== END STATUS CARD #%d "
  952. "==================\n", cx->instance);
  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. }