cx18-ioctl.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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 (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) {
  602. strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name));
  603. vt->type = V4L2_TUNER_RADIO;
  604. } else {
  605. strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name));
  606. vt->type = V4L2_TUNER_ANALOG_TV;
  607. }
  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("================= START STATUS CARD #%d "
  923. "=================\n", cx->instance);
  924. CX18_INFO("Version: %s Card: %s\n", CX18_VERSION, cx->card_name);
  925. if (cx->hw_flags & CX18_HW_TVEEPROM) {
  926. struct tveeprom tv;
  927. cx18_read_eeprom(cx, &tv);
  928. }
  929. cx18_call_all(cx, core, log_status);
  930. cx18_get_input(cx, cx->active_input, &vidin);
  931. cx18_get_audio_input(cx, cx->audio_input, &audin);
  932. CX18_INFO("Video Input: %s\n", vidin.name);
  933. CX18_INFO("Audio Input: %s\n", audin.name);
  934. mutex_lock(&cx->gpio_lock);
  935. CX18_INFO("GPIO: direction 0x%08x, value 0x%08x\n",
  936. cx->gpio_dir, cx->gpio_val);
  937. mutex_unlock(&cx->gpio_lock);
  938. CX18_INFO("Tuner: %s\n",
  939. test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV");
  940. v4l2_ctrl_handler_log_status(&cx->cxhdl.hdl, cx->v4l2_dev.name);
  941. CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags);
  942. for (i = 0; i < CX18_MAX_STREAMS; i++) {
  943. struct cx18_stream *s = &cx->streams[i];
  944. if (s->video_dev == NULL || s->buffers == 0)
  945. continue;
  946. CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
  947. s->name, s->s_flags,
  948. atomic_read(&s->q_full.depth) * s->bufs_per_mdl * 100
  949. / s->buffers,
  950. (s->buffers * s->buf_size) / 1024, s->buffers);
  951. }
  952. CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
  953. (long long)cx->mpg_data_received,
  954. (long long)cx->vbi_data_inserted);
  955. CX18_INFO("================== END STATUS CARD #%d "
  956. "==================\n", cx->instance);
  957. return 0;
  958. }
  959. static long cx18_default(struct file *file, void *fh, bool valid_prio,
  960. int cmd, void *arg)
  961. {
  962. struct cx18 *cx = fh2id(fh)->cx;
  963. switch (cmd) {
  964. case VIDIOC_INT_RESET: {
  965. u32 val = *(u32 *)arg;
  966. if ((val == 0) || (val & 0x01))
  967. cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL, core, reset,
  968. (u32) CX18_GPIO_RESET_Z8F0811);
  969. break;
  970. }
  971. default:
  972. return -EINVAL;
  973. }
  974. return 0;
  975. }
  976. long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd,
  977. unsigned long arg)
  978. {
  979. struct video_device *vfd = video_devdata(filp);
  980. struct cx18_open_id *id = file2id(filp);
  981. struct cx18 *cx = id->cx;
  982. long res;
  983. mutex_lock(&cx->serialize_lock);
  984. if (cx18_debug & CX18_DBGFLG_IOCTL)
  985. vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
  986. res = video_ioctl2(filp, cmd, arg);
  987. vfd->debug = 0;
  988. mutex_unlock(&cx->serialize_lock);
  989. return res;
  990. }
  991. static const struct v4l2_ioctl_ops cx18_ioctl_ops = {
  992. .vidioc_querycap = cx18_querycap,
  993. .vidioc_s_audio = cx18_s_audio,
  994. .vidioc_g_audio = cx18_g_audio,
  995. .vidioc_enumaudio = cx18_enumaudio,
  996. .vidioc_enum_input = cx18_enum_input,
  997. .vidioc_cropcap = cx18_cropcap,
  998. .vidioc_s_crop = cx18_s_crop,
  999. .vidioc_g_crop = cx18_g_crop,
  1000. .vidioc_g_input = cx18_g_input,
  1001. .vidioc_s_input = cx18_s_input,
  1002. .vidioc_g_frequency = cx18_g_frequency,
  1003. .vidioc_s_frequency = cx18_s_frequency,
  1004. .vidioc_s_tuner = cx18_s_tuner,
  1005. .vidioc_g_tuner = cx18_g_tuner,
  1006. .vidioc_g_enc_index = cx18_g_enc_index,
  1007. .vidioc_g_std = cx18_g_std,
  1008. .vidioc_s_std = cx18_s_std,
  1009. .vidioc_log_status = cx18_log_status,
  1010. .vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap,
  1011. .vidioc_encoder_cmd = cx18_encoder_cmd,
  1012. .vidioc_try_encoder_cmd = cx18_try_encoder_cmd,
  1013. .vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap,
  1014. .vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap,
  1015. .vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap,
  1016. .vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap,
  1017. .vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap,
  1018. .vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap,
  1019. .vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap,
  1020. .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap,
  1021. .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap,
  1022. .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap,
  1023. .vidioc_g_chip_ident = cx18_g_chip_ident,
  1024. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1025. .vidioc_g_register = cx18_g_register,
  1026. .vidioc_s_register = cx18_s_register,
  1027. #endif
  1028. .vidioc_default = cx18_default,
  1029. .vidioc_streamon = cx18_streamon,
  1030. .vidioc_streamoff = cx18_streamoff,
  1031. .vidioc_reqbufs = cx18_reqbufs,
  1032. .vidioc_querybuf = cx18_querybuf,
  1033. .vidioc_qbuf = cx18_qbuf,
  1034. .vidioc_dqbuf = cx18_dqbuf,
  1035. };
  1036. void cx18_set_funcs(struct video_device *vdev)
  1037. {
  1038. vdev->ioctl_ops = &cx18_ioctl_ops;
  1039. }