v4l1-compat.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /*
  2. *
  3. * Video for Linux Two
  4. * Backward Compatibility Layer
  5. *
  6. * Support subroutines for providing V4L2 drivers with backward
  7. * compatibility with applications using the old API.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. *
  14. * Author: Bill Dirks <bill@thedirks.org>
  15. * et al.
  16. *
  17. */
  18. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/sched.h>
  23. #include <linux/mm.h>
  24. #include <linux/fs.h>
  25. #include <linux/file.h>
  26. #include <linux/string.h>
  27. #include <linux/errno.h>
  28. #include <linux/slab.h>
  29. #include <linux/videodev.h>
  30. #include <media/v4l2-common.h>
  31. #include <media/v4l2-ioctl.h>
  32. #include <asm/uaccess.h>
  33. #include <asm/system.h>
  34. #include <asm/pgtable.h>
  35. static unsigned int debug;
  36. module_param(debug, int, 0644);
  37. MODULE_PARM_DESC(debug, "enable debug messages");
  38. MODULE_AUTHOR("Bill Dirks");
  39. MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
  40. MODULE_LICENSE("GPL");
  41. #define dprintk(fmt, arg...) \
  42. do { \
  43. if (debug) \
  44. printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg);\
  45. } while (0)
  46. /*
  47. * I O C T L T R A N S L A T I O N
  48. *
  49. * From here on down is the code for translating the numerous
  50. * ioctl commands from the old API to the new API.
  51. */
  52. static int
  53. get_v4l_control(struct file *file,
  54. int cid,
  55. v4l2_kioctl drv)
  56. {
  57. struct v4l2_queryctrl qctrl2;
  58. struct v4l2_control ctrl2;
  59. int err;
  60. qctrl2.id = cid;
  61. err = drv(file, VIDIOC_QUERYCTRL, &qctrl2);
  62. if (err < 0)
  63. dprintk("VIDIOC_QUERYCTRL: %d\n", err);
  64. if (err == 0 && !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) {
  65. ctrl2.id = qctrl2.id;
  66. err = drv(file, VIDIOC_G_CTRL, &ctrl2);
  67. if (err < 0) {
  68. dprintk("VIDIOC_G_CTRL: %d\n", err);
  69. return 0;
  70. }
  71. return ((ctrl2.value - qctrl2.minimum) * 65535
  72. + (qctrl2.maximum - qctrl2.minimum) / 2)
  73. / (qctrl2.maximum - qctrl2.minimum);
  74. }
  75. return 0;
  76. }
  77. static int
  78. set_v4l_control(struct file *file,
  79. int cid,
  80. int value,
  81. v4l2_kioctl drv)
  82. {
  83. struct v4l2_queryctrl qctrl2;
  84. struct v4l2_control ctrl2;
  85. int err;
  86. qctrl2.id = cid;
  87. err = drv(file, VIDIOC_QUERYCTRL, &qctrl2);
  88. if (err < 0)
  89. dprintk("VIDIOC_QUERYCTRL: %d\n", err);
  90. if (err == 0 &&
  91. !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) &&
  92. !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED)) {
  93. if (value < 0)
  94. value = 0;
  95. if (value > 65535)
  96. value = 65535;
  97. if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN)
  98. value = 65535;
  99. ctrl2.id = qctrl2.id;
  100. ctrl2.value =
  101. (value * (qctrl2.maximum - qctrl2.minimum)
  102. + 32767)
  103. / 65535;
  104. ctrl2.value += qctrl2.minimum;
  105. err = drv(file, VIDIOC_S_CTRL, &ctrl2);
  106. if (err < 0)
  107. dprintk("VIDIOC_S_CTRL: %d\n", err);
  108. }
  109. return 0;
  110. }
  111. /* ----------------------------------------------------------------- */
  112. static const unsigned int palette2pixelformat[] = {
  113. [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY,
  114. [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555,
  115. [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565,
  116. [VIDEO_PALETTE_RGB24] = V4L2_PIX_FMT_BGR24,
  117. [VIDEO_PALETTE_RGB32] = V4L2_PIX_FMT_BGR32,
  118. /* yuv packed pixel */
  119. [VIDEO_PALETTE_YUYV] = V4L2_PIX_FMT_YUYV,
  120. [VIDEO_PALETTE_YUV422] = V4L2_PIX_FMT_YUYV,
  121. [VIDEO_PALETTE_UYVY] = V4L2_PIX_FMT_UYVY,
  122. /* yuv planar */
  123. [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410,
  124. [VIDEO_PALETTE_YUV420] = V4L2_PIX_FMT_YUV420,
  125. [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420,
  126. [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P,
  127. [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
  128. };
  129. static unsigned int __pure
  130. palette_to_pixelformat(unsigned int palette)
  131. {
  132. if (palette < ARRAY_SIZE(palette2pixelformat))
  133. return palette2pixelformat[palette];
  134. else
  135. return 0;
  136. }
  137. static unsigned int __attribute_const__
  138. pixelformat_to_palette(unsigned int pixelformat)
  139. {
  140. int palette = 0;
  141. switch (pixelformat) {
  142. case V4L2_PIX_FMT_GREY:
  143. palette = VIDEO_PALETTE_GREY;
  144. break;
  145. case V4L2_PIX_FMT_RGB555:
  146. palette = VIDEO_PALETTE_RGB555;
  147. break;
  148. case V4L2_PIX_FMT_RGB565:
  149. palette = VIDEO_PALETTE_RGB565;
  150. break;
  151. case V4L2_PIX_FMT_BGR24:
  152. palette = VIDEO_PALETTE_RGB24;
  153. break;
  154. case V4L2_PIX_FMT_BGR32:
  155. palette = VIDEO_PALETTE_RGB32;
  156. break;
  157. /* yuv packed pixel */
  158. case V4L2_PIX_FMT_YUYV:
  159. palette = VIDEO_PALETTE_YUYV;
  160. break;
  161. case V4L2_PIX_FMT_UYVY:
  162. palette = VIDEO_PALETTE_UYVY;
  163. break;
  164. /* yuv planar */
  165. case V4L2_PIX_FMT_YUV410:
  166. palette = VIDEO_PALETTE_YUV420;
  167. break;
  168. case V4L2_PIX_FMT_YUV420:
  169. palette = VIDEO_PALETTE_YUV420;
  170. break;
  171. case V4L2_PIX_FMT_YUV411P:
  172. palette = VIDEO_PALETTE_YUV411P;
  173. break;
  174. case V4L2_PIX_FMT_YUV422P:
  175. palette = VIDEO_PALETTE_YUV422P;
  176. break;
  177. }
  178. return palette;
  179. }
  180. /* ----------------------------------------------------------------- */
  181. static int poll_one(struct file *file, struct poll_wqueues *pwq)
  182. {
  183. int retval = 1;
  184. poll_table *table;
  185. poll_initwait(pwq);
  186. table = &pwq->pt;
  187. for (;;) {
  188. int mask;
  189. mask = file->f_op->poll(file, table);
  190. if (mask & POLLIN)
  191. break;
  192. table = NULL;
  193. if (signal_pending(current)) {
  194. retval = -ERESTARTSYS;
  195. break;
  196. }
  197. poll_schedule(pwq, TASK_INTERRUPTIBLE);
  198. }
  199. poll_freewait(pwq);
  200. return retval;
  201. }
  202. static int count_inputs(
  203. struct file *file,
  204. v4l2_kioctl drv)
  205. {
  206. struct v4l2_input input2;
  207. int i;
  208. for (i = 0;; i++) {
  209. memset(&input2, 0, sizeof(input2));
  210. input2.index = i;
  211. if (0 != drv(file, VIDIOC_ENUMINPUT, &input2))
  212. break;
  213. }
  214. return i;
  215. }
  216. static int check_size(
  217. struct file *file,
  218. v4l2_kioctl drv,
  219. int *maxw,
  220. int *maxh)
  221. {
  222. struct v4l2_fmtdesc desc2;
  223. struct v4l2_format fmt2;
  224. memset(&desc2, 0, sizeof(desc2));
  225. memset(&fmt2, 0, sizeof(fmt2));
  226. desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  227. if (0 != drv(file, VIDIOC_ENUM_FMT, &desc2))
  228. goto done;
  229. fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  230. fmt2.fmt.pix.width = 10000;
  231. fmt2.fmt.pix.height = 10000;
  232. fmt2.fmt.pix.pixelformat = desc2.pixelformat;
  233. if (0 != drv(file, VIDIOC_TRY_FMT, &fmt2))
  234. goto done;
  235. *maxw = fmt2.fmt.pix.width;
  236. *maxh = fmt2.fmt.pix.height;
  237. done:
  238. return 0;
  239. }
  240. /* ----------------------------------------------------------------- */
  241. static noinline long v4l1_compat_get_capabilities(
  242. struct video_capability *cap,
  243. struct file *file,
  244. v4l2_kioctl drv)
  245. {
  246. long err;
  247. struct v4l2_framebuffer fbuf;
  248. struct v4l2_capability *cap2;
  249. cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
  250. if (!cap2) {
  251. err = -ENOMEM;
  252. return err;
  253. }
  254. memset(cap, 0, sizeof(*cap));
  255. memset(&fbuf, 0, sizeof(fbuf));
  256. err = drv(file, VIDIOC_QUERYCAP, cap2);
  257. if (err < 0) {
  258. dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %ld\n", err);
  259. goto done;
  260. }
  261. if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
  262. err = drv(file, VIDIOC_G_FBUF, &fbuf);
  263. if (err < 0) {
  264. dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %ld\n", err);
  265. memset(&fbuf, 0, sizeof(fbuf));
  266. }
  267. err = 0;
  268. }
  269. memcpy(cap->name, cap2->card,
  270. min(sizeof(cap->name), sizeof(cap2->card)));
  271. cap->name[sizeof(cap->name) - 1] = 0;
  272. if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
  273. cap->type |= VID_TYPE_CAPTURE;
  274. if (cap2->capabilities & V4L2_CAP_TUNER)
  275. cap->type |= VID_TYPE_TUNER;
  276. if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
  277. cap->type |= VID_TYPE_TELETEXT;
  278. if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
  279. cap->type |= VID_TYPE_OVERLAY;
  280. if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
  281. cap->type |= VID_TYPE_CLIPPING;
  282. cap->channels = count_inputs(file, drv);
  283. check_size(file, drv,
  284. &cap->maxwidth, &cap->maxheight);
  285. cap->audios = 0; /* FIXME */
  286. cap->minwidth = 48; /* FIXME */
  287. cap->minheight = 32; /* FIXME */
  288. done:
  289. kfree(cap2);
  290. return err;
  291. }
  292. static noinline long v4l1_compat_get_frame_buffer(
  293. struct video_buffer *buffer,
  294. struct file *file,
  295. v4l2_kioctl drv)
  296. {
  297. long err;
  298. struct v4l2_framebuffer fbuf;
  299. memset(buffer, 0, sizeof(*buffer));
  300. memset(&fbuf, 0, sizeof(fbuf));
  301. err = drv(file, VIDIOC_G_FBUF, &fbuf);
  302. if (err < 0) {
  303. dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %ld\n", err);
  304. goto done;
  305. }
  306. buffer->base = fbuf.base;
  307. buffer->height = fbuf.fmt.height;
  308. buffer->width = fbuf.fmt.width;
  309. switch (fbuf.fmt.pixelformat) {
  310. case V4L2_PIX_FMT_RGB332:
  311. buffer->depth = 8;
  312. break;
  313. case V4L2_PIX_FMT_RGB555:
  314. buffer->depth = 15;
  315. break;
  316. case V4L2_PIX_FMT_RGB565:
  317. buffer->depth = 16;
  318. break;
  319. case V4L2_PIX_FMT_BGR24:
  320. buffer->depth = 24;
  321. break;
  322. case V4L2_PIX_FMT_BGR32:
  323. buffer->depth = 32;
  324. break;
  325. default:
  326. buffer->depth = 0;
  327. }
  328. if (fbuf.fmt.bytesperline) {
  329. buffer->bytesperline = fbuf.fmt.bytesperline;
  330. if (!buffer->depth && buffer->width)
  331. buffer->depth = ((fbuf.fmt.bytesperline<<3)
  332. + (buffer->width-1))
  333. / buffer->width;
  334. } else {
  335. buffer->bytesperline =
  336. (buffer->width * buffer->depth + 7) & 7;
  337. buffer->bytesperline >>= 3;
  338. }
  339. done:
  340. return err;
  341. }
  342. static noinline long v4l1_compat_set_frame_buffer(
  343. struct video_buffer *buffer,
  344. struct file *file,
  345. v4l2_kioctl drv)
  346. {
  347. long err;
  348. struct v4l2_framebuffer fbuf;
  349. memset(&fbuf, 0, sizeof(fbuf));
  350. fbuf.base = buffer->base;
  351. fbuf.fmt.height = buffer->height;
  352. fbuf.fmt.width = buffer->width;
  353. switch (buffer->depth) {
  354. case 8:
  355. fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
  356. break;
  357. case 15:
  358. fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
  359. break;
  360. case 16:
  361. fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
  362. break;
  363. case 24:
  364. fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
  365. break;
  366. case 32:
  367. fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
  368. break;
  369. }
  370. fbuf.fmt.bytesperline = buffer->bytesperline;
  371. err = drv(file, VIDIOC_S_FBUF, &fbuf);
  372. if (err < 0)
  373. dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %ld\n", err);
  374. return err;
  375. }
  376. static noinline long v4l1_compat_get_win_cap_dimensions(
  377. struct video_window *win,
  378. struct file *file,
  379. v4l2_kioctl drv)
  380. {
  381. long err;
  382. struct v4l2_format *fmt;
  383. fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
  384. if (!fmt) {
  385. err = -ENOMEM;
  386. return err;
  387. }
  388. memset(win, 0, sizeof(*win));
  389. fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
  390. err = drv(file, VIDIOC_G_FMT, fmt);
  391. if (err < 0)
  392. dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %ld\n", err);
  393. if (err == 0) {
  394. win->x = fmt->fmt.win.w.left;
  395. win->y = fmt->fmt.win.w.top;
  396. win->width = fmt->fmt.win.w.width;
  397. win->height = fmt->fmt.win.w.height;
  398. win->chromakey = fmt->fmt.win.chromakey;
  399. win->clips = NULL;
  400. win->clipcount = 0;
  401. goto done;
  402. }
  403. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  404. err = drv(file, VIDIOC_G_FMT, fmt);
  405. if (err < 0) {
  406. dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %ld\n", err);
  407. goto done;
  408. }
  409. win->x = 0;
  410. win->y = 0;
  411. win->width = fmt->fmt.pix.width;
  412. win->height = fmt->fmt.pix.height;
  413. win->chromakey = 0;
  414. win->clips = NULL;
  415. win->clipcount = 0;
  416. done:
  417. kfree(fmt);
  418. return err;
  419. }
  420. static noinline long v4l1_compat_set_win_cap_dimensions(
  421. struct video_window *win,
  422. struct file *file,
  423. v4l2_kioctl drv)
  424. {
  425. long err, err1, err2;
  426. struct v4l2_format *fmt;
  427. fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
  428. if (!fmt) {
  429. err = -ENOMEM;
  430. return err;
  431. }
  432. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  433. drv(file, VIDIOC_STREAMOFF, &fmt->type);
  434. err1 = drv(file, VIDIOC_G_FMT, fmt);
  435. if (err1 < 0)
  436. dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %ld\n", err1);
  437. if (err1 == 0) {
  438. fmt->fmt.pix.width = win->width;
  439. fmt->fmt.pix.height = win->height;
  440. fmt->fmt.pix.field = V4L2_FIELD_ANY;
  441. fmt->fmt.pix.bytesperline = 0;
  442. err = drv(file, VIDIOC_S_FMT, fmt);
  443. if (err < 0)
  444. dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %ld\n",
  445. err);
  446. win->width = fmt->fmt.pix.width;
  447. win->height = fmt->fmt.pix.height;
  448. }
  449. memset(fmt, 0, sizeof(*fmt));
  450. fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
  451. fmt->fmt.win.w.left = win->x;
  452. fmt->fmt.win.w.top = win->y;
  453. fmt->fmt.win.w.width = win->width;
  454. fmt->fmt.win.w.height = win->height;
  455. fmt->fmt.win.chromakey = win->chromakey;
  456. fmt->fmt.win.clips = (void __user *)win->clips;
  457. fmt->fmt.win.clipcount = win->clipcount;
  458. err2 = drv(file, VIDIOC_S_FMT, fmt);
  459. if (err2 < 0)
  460. dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %ld\n", err2);
  461. if (err1 != 0 && err2 != 0)
  462. err = err1;
  463. else
  464. err = 0;
  465. kfree(fmt);
  466. return err;
  467. }
  468. static noinline long v4l1_compat_turn_preview_on_off(
  469. int *on,
  470. struct file *file,
  471. v4l2_kioctl drv)
  472. {
  473. long err;
  474. enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  475. if (0 == *on) {
  476. /* dirty hack time. But v4l1 has no STREAMOFF
  477. * equivalent in the API, and this one at
  478. * least comes close ... */
  479. drv(file, VIDIOC_STREAMOFF, &captype);
  480. }
  481. err = drv(file, VIDIOC_OVERLAY, on);
  482. if (err < 0)
  483. dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %ld\n", err);
  484. return err;
  485. }
  486. static noinline long v4l1_compat_get_input_info(
  487. struct video_channel *chan,
  488. struct file *file,
  489. v4l2_kioctl drv)
  490. {
  491. long err;
  492. struct v4l2_input input2;
  493. v4l2_std_id sid;
  494. memset(&input2, 0, sizeof(input2));
  495. input2.index = chan->channel;
  496. err = drv(file, VIDIOC_ENUMINPUT, &input2);
  497. if (err < 0) {
  498. dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
  499. "channel=%d err=%ld\n", chan->channel, err);
  500. goto done;
  501. }
  502. chan->channel = input2.index;
  503. memcpy(chan->name, input2.name,
  504. min(sizeof(chan->name), sizeof(input2.name)));
  505. chan->name[sizeof(chan->name) - 1] = 0;
  506. chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
  507. chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
  508. switch (input2.type) {
  509. case V4L2_INPUT_TYPE_TUNER:
  510. chan->type = VIDEO_TYPE_TV;
  511. break;
  512. default:
  513. case V4L2_INPUT_TYPE_CAMERA:
  514. chan->type = VIDEO_TYPE_CAMERA;
  515. break;
  516. }
  517. chan->norm = 0;
  518. err = drv(file, VIDIOC_G_STD, &sid);
  519. if (err < 0)
  520. dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %ld\n", err);
  521. if (err == 0) {
  522. if (sid & V4L2_STD_PAL)
  523. chan->norm = VIDEO_MODE_PAL;
  524. if (sid & V4L2_STD_NTSC)
  525. chan->norm = VIDEO_MODE_NTSC;
  526. if (sid & V4L2_STD_SECAM)
  527. chan->norm = VIDEO_MODE_SECAM;
  528. }
  529. done:
  530. return err;
  531. }
  532. static noinline long v4l1_compat_set_input(
  533. struct video_channel *chan,
  534. struct file *file,
  535. v4l2_kioctl drv)
  536. {
  537. long err;
  538. v4l2_std_id sid = 0;
  539. err = drv(file, VIDIOC_S_INPUT, &chan->channel);
  540. if (err < 0)
  541. dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %ld\n", err);
  542. switch (chan->norm) {
  543. case VIDEO_MODE_PAL:
  544. sid = V4L2_STD_PAL;
  545. break;
  546. case VIDEO_MODE_NTSC:
  547. sid = V4L2_STD_NTSC;
  548. break;
  549. case VIDEO_MODE_SECAM:
  550. sid = V4L2_STD_SECAM;
  551. break;
  552. }
  553. if (0 != sid) {
  554. err = drv(file, VIDIOC_S_STD, &sid);
  555. if (err < 0)
  556. dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %ld\n", err);
  557. }
  558. return err;
  559. }
  560. static noinline long v4l1_compat_get_picture(
  561. struct video_picture *pict,
  562. struct file *file,
  563. v4l2_kioctl drv)
  564. {
  565. long err;
  566. struct v4l2_format *fmt;
  567. fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
  568. if (!fmt) {
  569. err = -ENOMEM;
  570. return err;
  571. }
  572. pict->brightness = get_v4l_control(file,
  573. V4L2_CID_BRIGHTNESS, drv);
  574. pict->hue = get_v4l_control(file,
  575. V4L2_CID_HUE, drv);
  576. pict->contrast = get_v4l_control(file,
  577. V4L2_CID_CONTRAST, drv);
  578. pict->colour = get_v4l_control(file,
  579. V4L2_CID_SATURATION, drv);
  580. pict->whiteness = get_v4l_control(file,
  581. V4L2_CID_WHITENESS, drv);
  582. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  583. err = drv(file, VIDIOC_G_FMT, fmt);
  584. if (err < 0) {
  585. dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %ld\n", err);
  586. goto done;
  587. }
  588. pict->depth = ((fmt->fmt.pix.bytesperline << 3)
  589. + (fmt->fmt.pix.width - 1))
  590. / fmt->fmt.pix.width;
  591. pict->palette = pixelformat_to_palette(
  592. fmt->fmt.pix.pixelformat);
  593. done:
  594. kfree(fmt);
  595. return err;
  596. }
  597. static noinline long v4l1_compat_set_picture(
  598. struct video_picture *pict,
  599. struct file *file,
  600. v4l2_kioctl drv)
  601. {
  602. long err;
  603. struct v4l2_framebuffer fbuf;
  604. int mem_err = 0, ovl_err = 0;
  605. struct v4l2_format *fmt;
  606. fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
  607. if (!fmt) {
  608. err = -ENOMEM;
  609. return err;
  610. }
  611. memset(&fbuf, 0, sizeof(fbuf));
  612. set_v4l_control(file,
  613. V4L2_CID_BRIGHTNESS, pict->brightness, drv);
  614. set_v4l_control(file,
  615. V4L2_CID_HUE, pict->hue, drv);
  616. set_v4l_control(file,
  617. V4L2_CID_CONTRAST, pict->contrast, drv);
  618. set_v4l_control(file,
  619. V4L2_CID_SATURATION, pict->colour, drv);
  620. set_v4l_control(file,
  621. V4L2_CID_WHITENESS, pict->whiteness, drv);
  622. /*
  623. * V4L1 uses this ioctl to set both memory capture and overlay
  624. * pixel format, while V4L2 has two different ioctls for this.
  625. * Some cards may not support one or the other, and may support
  626. * different pixel formats for memory vs overlay.
  627. */
  628. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  629. err = drv(file, VIDIOC_G_FMT, fmt);
  630. /* If VIDIOC_G_FMT failed, then the driver likely doesn't
  631. support memory capture. Trying to set the memory capture
  632. parameters would be pointless. */
  633. if (err < 0) {
  634. dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %ld\n", err);
  635. mem_err = -1000; /* didn't even try */
  636. } else if (fmt->fmt.pix.pixelformat !=
  637. palette_to_pixelformat(pict->palette)) {
  638. fmt->fmt.pix.pixelformat = palette_to_pixelformat(
  639. pict->palette);
  640. mem_err = drv(file, VIDIOC_S_FMT, fmt);
  641. if (mem_err < 0)
  642. dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
  643. mem_err);
  644. }
  645. err = drv(file, VIDIOC_G_FBUF, &fbuf);
  646. /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
  647. support overlay. Trying to set the overlay parameters
  648. would be quite pointless. */
  649. if (err < 0) {
  650. dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %ld\n", err);
  651. ovl_err = -1000; /* didn't even try */
  652. } else if (fbuf.fmt.pixelformat !=
  653. palette_to_pixelformat(pict->palette)) {
  654. fbuf.fmt.pixelformat = palette_to_pixelformat(
  655. pict->palette);
  656. ovl_err = drv(file, VIDIOC_S_FBUF, &fbuf);
  657. if (ovl_err < 0)
  658. dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
  659. ovl_err);
  660. }
  661. if (ovl_err < 0 && mem_err < 0) {
  662. /* ioctl failed, couldn't set either parameter */
  663. if (mem_err != -1000)
  664. err = mem_err;
  665. else if (ovl_err == -EPERM)
  666. err = 0;
  667. else
  668. err = ovl_err;
  669. } else
  670. err = 0;
  671. kfree(fmt);
  672. return err;
  673. }
  674. static noinline long v4l1_compat_get_tuner(
  675. struct video_tuner *tun,
  676. struct file *file,
  677. v4l2_kioctl drv)
  678. {
  679. long err;
  680. int i;
  681. struct v4l2_tuner tun2;
  682. struct v4l2_standard std2;
  683. v4l2_std_id sid;
  684. memset(&tun2, 0, sizeof(tun2));
  685. err = drv(file, VIDIOC_G_TUNER, &tun2);
  686. if (err < 0) {
  687. dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %ld\n", err);
  688. goto done;
  689. }
  690. memcpy(tun->name, tun2.name,
  691. min(sizeof(tun->name), sizeof(tun2.name)));
  692. tun->name[sizeof(tun->name) - 1] = 0;
  693. tun->rangelow = tun2.rangelow;
  694. tun->rangehigh = tun2.rangehigh;
  695. tun->flags = 0;
  696. tun->mode = VIDEO_MODE_AUTO;
  697. for (i = 0; i < 64; i++) {
  698. memset(&std2, 0, sizeof(std2));
  699. std2.index = i;
  700. if (0 != drv(file, VIDIOC_ENUMSTD, &std2))
  701. break;
  702. if (std2.id & V4L2_STD_PAL)
  703. tun->flags |= VIDEO_TUNER_PAL;
  704. if (std2.id & V4L2_STD_NTSC)
  705. tun->flags |= VIDEO_TUNER_NTSC;
  706. if (std2.id & V4L2_STD_SECAM)
  707. tun->flags |= VIDEO_TUNER_SECAM;
  708. }
  709. err = drv(file, VIDIOC_G_STD, &sid);
  710. if (err < 0)
  711. dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %ld\n", err);
  712. if (err == 0) {
  713. if (sid & V4L2_STD_PAL)
  714. tun->mode = VIDEO_MODE_PAL;
  715. if (sid & V4L2_STD_NTSC)
  716. tun->mode = VIDEO_MODE_NTSC;
  717. if (sid & V4L2_STD_SECAM)
  718. tun->mode = VIDEO_MODE_SECAM;
  719. }
  720. if (tun2.capability & V4L2_TUNER_CAP_LOW)
  721. tun->flags |= VIDEO_TUNER_LOW;
  722. if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
  723. tun->flags |= VIDEO_TUNER_STEREO_ON;
  724. tun->signal = tun2.signal;
  725. done:
  726. return err;
  727. }
  728. static noinline long v4l1_compat_select_tuner(
  729. struct video_tuner *tun,
  730. struct file *file,
  731. v4l2_kioctl drv)
  732. {
  733. long err;
  734. struct v4l2_tuner t;/*84 bytes on x86_64*/
  735. memset(&t, 0, sizeof(t));
  736. t.index = tun->tuner;
  737. err = drv(file, VIDIOC_S_INPUT, &t);
  738. if (err < 0)
  739. dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %ld\n", err);
  740. return err;
  741. }
  742. static noinline long v4l1_compat_get_frequency(
  743. unsigned long *freq,
  744. struct file *file,
  745. v4l2_kioctl drv)
  746. {
  747. long err;
  748. struct v4l2_frequency freq2;
  749. memset(&freq2, 0, sizeof(freq2));
  750. freq2.tuner = 0;
  751. err = drv(file, VIDIOC_G_FREQUENCY, &freq2);
  752. if (err < 0)
  753. dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %ld\n", err);
  754. if (0 == err)
  755. *freq = freq2.frequency;
  756. return err;
  757. }
  758. static noinline long v4l1_compat_set_frequency(
  759. unsigned long *freq,
  760. struct file *file,
  761. v4l2_kioctl drv)
  762. {
  763. long err;
  764. struct v4l2_frequency freq2;
  765. memset(&freq2, 0, sizeof(freq2));
  766. drv(file, VIDIOC_G_FREQUENCY, &freq2);
  767. freq2.frequency = *freq;
  768. err = drv(file, VIDIOC_S_FREQUENCY, &freq2);
  769. if (err < 0)
  770. dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %ld\n", err);
  771. return err;
  772. }
  773. static noinline long v4l1_compat_get_audio(
  774. struct video_audio *aud,
  775. struct file *file,
  776. v4l2_kioctl drv)
  777. {
  778. long err;
  779. int i;
  780. struct v4l2_queryctrl qctrl2;
  781. struct v4l2_audio aud2;
  782. struct v4l2_tuner tun2;
  783. memset(&aud2, 0, sizeof(aud2));
  784. err = drv(file, VIDIOC_G_AUDIO, &aud2);
  785. if (err < 0) {
  786. dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %ld\n", err);
  787. goto done;
  788. }
  789. memcpy(aud->name, aud2.name,
  790. min(sizeof(aud->name), sizeof(aud2.name)));
  791. aud->name[sizeof(aud->name) - 1] = 0;
  792. aud->audio = aud2.index;
  793. aud->flags = 0;
  794. i = get_v4l_control(file, V4L2_CID_AUDIO_VOLUME, drv);
  795. if (i >= 0) {
  796. aud->volume = i;
  797. aud->flags |= VIDEO_AUDIO_VOLUME;
  798. }
  799. i = get_v4l_control(file, V4L2_CID_AUDIO_BASS, drv);
  800. if (i >= 0) {
  801. aud->bass = i;
  802. aud->flags |= VIDEO_AUDIO_BASS;
  803. }
  804. i = get_v4l_control(file, V4L2_CID_AUDIO_TREBLE, drv);
  805. if (i >= 0) {
  806. aud->treble = i;
  807. aud->flags |= VIDEO_AUDIO_TREBLE;
  808. }
  809. i = get_v4l_control(file, V4L2_CID_AUDIO_BALANCE, drv);
  810. if (i >= 0) {
  811. aud->balance = i;
  812. aud->flags |= VIDEO_AUDIO_BALANCE;
  813. }
  814. i = get_v4l_control(file, V4L2_CID_AUDIO_MUTE, drv);
  815. if (i >= 0) {
  816. if (i)
  817. aud->flags |= VIDEO_AUDIO_MUTE;
  818. aud->flags |= VIDEO_AUDIO_MUTABLE;
  819. }
  820. aud->step = 1;
  821. qctrl2.id = V4L2_CID_AUDIO_VOLUME;
  822. if (drv(file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
  823. !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
  824. aud->step = qctrl2.step;
  825. aud->mode = 0;
  826. memset(&tun2, 0, sizeof(tun2));
  827. err = drv(file, VIDIOC_G_TUNER, &tun2);
  828. if (err < 0) {
  829. dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %ld\n", err);
  830. err = 0;
  831. goto done;
  832. }
  833. if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
  834. aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
  835. else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
  836. aud->mode = VIDEO_SOUND_STEREO;
  837. else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
  838. aud->mode = VIDEO_SOUND_MONO;
  839. done:
  840. return err;
  841. }
  842. static noinline long v4l1_compat_set_audio(
  843. struct video_audio *aud,
  844. struct file *file,
  845. v4l2_kioctl drv)
  846. {
  847. long err;
  848. struct v4l2_audio aud2;
  849. struct v4l2_tuner tun2;
  850. memset(&aud2, 0, sizeof(aud2));
  851. memset(&tun2, 0, sizeof(tun2));
  852. aud2.index = aud->audio;
  853. err = drv(file, VIDIOC_S_AUDIO, &aud2);
  854. if (err < 0) {
  855. dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %ld\n", err);
  856. goto done;
  857. }
  858. set_v4l_control(file, V4L2_CID_AUDIO_VOLUME,
  859. aud->volume, drv);
  860. set_v4l_control(file, V4L2_CID_AUDIO_BASS,
  861. aud->bass, drv);
  862. set_v4l_control(file, V4L2_CID_AUDIO_TREBLE,
  863. aud->treble, drv);
  864. set_v4l_control(file, V4L2_CID_AUDIO_BALANCE,
  865. aud->balance, drv);
  866. set_v4l_control(file, V4L2_CID_AUDIO_MUTE,
  867. !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
  868. err = drv(file, VIDIOC_G_TUNER, &tun2);
  869. if (err < 0)
  870. dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %ld\n", err);
  871. if (err == 0) {
  872. switch (aud->mode) {
  873. default:
  874. case VIDEO_SOUND_MONO:
  875. case VIDEO_SOUND_LANG1:
  876. tun2.audmode = V4L2_TUNER_MODE_MONO;
  877. break;
  878. case VIDEO_SOUND_STEREO:
  879. tun2.audmode = V4L2_TUNER_MODE_STEREO;
  880. break;
  881. case VIDEO_SOUND_LANG2:
  882. tun2.audmode = V4L2_TUNER_MODE_LANG2;
  883. break;
  884. }
  885. err = drv(file, VIDIOC_S_TUNER, &tun2);
  886. if (err < 0)
  887. dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %ld\n", err);
  888. }
  889. err = 0;
  890. done:
  891. return err;
  892. }
  893. static noinline long v4l1_compat_capture_frame(
  894. struct video_mmap *mm,
  895. struct file *file,
  896. v4l2_kioctl drv)
  897. {
  898. long err;
  899. enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  900. struct v4l2_buffer buf;
  901. struct v4l2_format *fmt;
  902. fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
  903. if (!fmt) {
  904. err = -ENOMEM;
  905. return err;
  906. }
  907. memset(&buf, 0, sizeof(buf));
  908. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  909. err = drv(file, VIDIOC_G_FMT, fmt);
  910. if (err < 0) {
  911. dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %ld\n", err);
  912. goto done;
  913. }
  914. if (mm->width != fmt->fmt.pix.width ||
  915. mm->height != fmt->fmt.pix.height ||
  916. palette_to_pixelformat(mm->format) !=
  917. fmt->fmt.pix.pixelformat) {
  918. /* New capture format... */
  919. fmt->fmt.pix.width = mm->width;
  920. fmt->fmt.pix.height = mm->height;
  921. fmt->fmt.pix.pixelformat =
  922. palette_to_pixelformat(mm->format);
  923. fmt->fmt.pix.field = V4L2_FIELD_ANY;
  924. fmt->fmt.pix.bytesperline = 0;
  925. err = drv(file, VIDIOC_S_FMT, fmt);
  926. if (err < 0) {
  927. dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %ld\n", err);
  928. goto done;
  929. }
  930. }
  931. buf.index = mm->frame;
  932. buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  933. err = drv(file, VIDIOC_QUERYBUF, &buf);
  934. if (err < 0) {
  935. dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %ld\n", err);
  936. goto done;
  937. }
  938. err = drv(file, VIDIOC_QBUF, &buf);
  939. if (err < 0) {
  940. dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %ld\n", err);
  941. goto done;
  942. }
  943. err = drv(file, VIDIOC_STREAMON, &captype);
  944. if (err < 0)
  945. dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %ld\n", err);
  946. done:
  947. kfree(fmt);
  948. return err;
  949. }
  950. static noinline long v4l1_compat_sync(
  951. int *i,
  952. struct file *file,
  953. v4l2_kioctl drv)
  954. {
  955. long err;
  956. enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  957. struct v4l2_buffer buf;
  958. struct poll_wqueues *pwq;
  959. memset(&buf, 0, sizeof(buf));
  960. buf.index = *i;
  961. buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  962. err = drv(file, VIDIOC_QUERYBUF, &buf);
  963. if (err < 0) {
  964. /* No such buffer */
  965. dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err);
  966. goto done;
  967. }
  968. if (!(buf.flags & V4L2_BUF_FLAG_MAPPED)) {
  969. /* Buffer is not mapped */
  970. err = -EINVAL;
  971. goto done;
  972. }
  973. /* make sure capture actually runs so we don't block forever */
  974. err = drv(file, VIDIOC_STREAMON, &captype);
  975. if (err < 0) {
  976. dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %ld\n", err);
  977. goto done;
  978. }
  979. pwq = kmalloc(sizeof(*pwq), GFP_KERNEL);
  980. /* Loop as long as the buffer is queued, but not done */
  981. while ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
  982. == V4L2_BUF_FLAG_QUEUED) {
  983. err = poll_one(file, pwq);
  984. if (err < 0 || /* error or sleep was interrupted */
  985. err == 0) /* timeout? Shouldn't occur. */
  986. break;
  987. err = drv(file, VIDIOC_QUERYBUF, &buf);
  988. if (err < 0)
  989. dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err);
  990. }
  991. kfree(pwq);
  992. if (!(buf.flags & V4L2_BUF_FLAG_DONE)) /* not done */
  993. goto done;
  994. do {
  995. err = drv(file, VIDIOC_DQBUF, &buf);
  996. if (err < 0)
  997. dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %ld\n", err);
  998. } while (err == 0 && buf.index != *i);
  999. done:
  1000. return err;
  1001. }
  1002. static noinline long v4l1_compat_get_vbi_format(
  1003. struct vbi_format *fmt,
  1004. struct file *file,
  1005. v4l2_kioctl drv)
  1006. {
  1007. long err;
  1008. struct v4l2_format *fmt2;
  1009. fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
  1010. if (!fmt2) {
  1011. err = -ENOMEM;
  1012. return err;
  1013. }
  1014. fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
  1015. err = drv(file, VIDIOC_G_FMT, fmt2);
  1016. if (err < 0) {
  1017. dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %ld\n", err);
  1018. goto done;
  1019. }
  1020. if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
  1021. err = -EINVAL;
  1022. goto done;
  1023. }
  1024. memset(fmt, 0, sizeof(*fmt));
  1025. fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
  1026. fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
  1027. fmt->sample_format = VIDEO_PALETTE_RAW;
  1028. fmt->start[0] = fmt2->fmt.vbi.start[0];
  1029. fmt->count[0] = fmt2->fmt.vbi.count[0];
  1030. fmt->start[1] = fmt2->fmt.vbi.start[1];
  1031. fmt->count[1] = fmt2->fmt.vbi.count[1];
  1032. fmt->flags = fmt2->fmt.vbi.flags & 0x03;
  1033. done:
  1034. kfree(fmt2);
  1035. return err;
  1036. }
  1037. static noinline long v4l1_compat_set_vbi_format(
  1038. struct vbi_format *fmt,
  1039. struct file *file,
  1040. v4l2_kioctl drv)
  1041. {
  1042. long err;
  1043. struct v4l2_format *fmt2 = NULL;
  1044. if (VIDEO_PALETTE_RAW != fmt->sample_format) {
  1045. err = -EINVAL;
  1046. return err;
  1047. }
  1048. fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
  1049. if (!fmt2) {
  1050. err = -ENOMEM;
  1051. return err;
  1052. }
  1053. fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
  1054. fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
  1055. fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
  1056. fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
  1057. fmt2->fmt.vbi.start[0] = fmt->start[0];
  1058. fmt2->fmt.vbi.count[0] = fmt->count[0];
  1059. fmt2->fmt.vbi.start[1] = fmt->start[1];
  1060. fmt2->fmt.vbi.count[1] = fmt->count[1];
  1061. fmt2->fmt.vbi.flags = fmt->flags;
  1062. err = drv(file, VIDIOC_TRY_FMT, fmt2);
  1063. if (err < 0) {
  1064. dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %ld\n", err);
  1065. goto done;
  1066. }
  1067. if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
  1068. fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
  1069. fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
  1070. fmt2->fmt.vbi.start[0] != fmt->start[0] ||
  1071. fmt2->fmt.vbi.count[0] != fmt->count[0] ||
  1072. fmt2->fmt.vbi.start[1] != fmt->start[1] ||
  1073. fmt2->fmt.vbi.count[1] != fmt->count[1] ||
  1074. fmt2->fmt.vbi.flags != fmt->flags) {
  1075. err = -EINVAL;
  1076. goto done;
  1077. }
  1078. err = drv(file, VIDIOC_S_FMT, fmt2);
  1079. if (err < 0)
  1080. dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %ld\n", err);
  1081. done:
  1082. kfree(fmt2);
  1083. return err;
  1084. }
  1085. /*
  1086. * This function is exported.
  1087. */
  1088. long
  1089. v4l_compat_translate_ioctl(struct file *file,
  1090. int cmd,
  1091. void *arg,
  1092. v4l2_kioctl drv)
  1093. {
  1094. long err;
  1095. switch (cmd) {
  1096. case VIDIOCGCAP: /* capability */
  1097. err = v4l1_compat_get_capabilities(arg, file, drv);
  1098. break;
  1099. case VIDIOCGFBUF: /* get frame buffer */
  1100. err = v4l1_compat_get_frame_buffer(arg, file, drv);
  1101. break;
  1102. case VIDIOCSFBUF: /* set frame buffer */
  1103. err = v4l1_compat_set_frame_buffer(arg, file, drv);
  1104. break;
  1105. case VIDIOCGWIN: /* get window or capture dimensions */
  1106. err = v4l1_compat_get_win_cap_dimensions(arg, file, drv);
  1107. break;
  1108. case VIDIOCSWIN: /* set window and/or capture dimensions */
  1109. err = v4l1_compat_set_win_cap_dimensions(arg, file, drv);
  1110. break;
  1111. case VIDIOCCAPTURE: /* turn on/off preview */
  1112. err = v4l1_compat_turn_preview_on_off(arg, file, drv);
  1113. break;
  1114. case VIDIOCGCHAN: /* get input information */
  1115. err = v4l1_compat_get_input_info(arg, file, drv);
  1116. break;
  1117. case VIDIOCSCHAN: /* set input */
  1118. err = v4l1_compat_set_input(arg, file, drv);
  1119. break;
  1120. case VIDIOCGPICT: /* get tone controls & partial capture format */
  1121. err = v4l1_compat_get_picture(arg, file, drv);
  1122. break;
  1123. case VIDIOCSPICT: /* set tone controls & partial capture format */
  1124. err = v4l1_compat_set_picture(arg, file, drv);
  1125. break;
  1126. case VIDIOCGTUNER: /* get tuner information */
  1127. err = v4l1_compat_get_tuner(arg, file, drv);
  1128. break;
  1129. case VIDIOCSTUNER: /* select a tuner input */
  1130. err = v4l1_compat_select_tuner(arg, file, drv);
  1131. break;
  1132. case VIDIOCGFREQ: /* get frequency */
  1133. err = v4l1_compat_get_frequency(arg, file, drv);
  1134. break;
  1135. case VIDIOCSFREQ: /* set frequency */
  1136. err = v4l1_compat_set_frequency(arg, file, drv);
  1137. break;
  1138. case VIDIOCGAUDIO: /* get audio properties/controls */
  1139. err = v4l1_compat_get_audio(arg, file, drv);
  1140. break;
  1141. case VIDIOCSAUDIO: /* set audio controls */
  1142. err = v4l1_compat_set_audio(arg, file, drv);
  1143. break;
  1144. case VIDIOCMCAPTURE: /* capture a frame */
  1145. err = v4l1_compat_capture_frame(arg, file, drv);
  1146. break;
  1147. case VIDIOCSYNC: /* wait for a frame */
  1148. err = v4l1_compat_sync(arg, file, drv);
  1149. break;
  1150. case VIDIOCGVBIFMT: /* query VBI data capture format */
  1151. err = v4l1_compat_get_vbi_format(arg, file, drv);
  1152. break;
  1153. case VIDIOCSVBIFMT:
  1154. err = v4l1_compat_set_vbi_format(arg, file, drv);
  1155. break;
  1156. default:
  1157. err = -ENOIOCTLCMD;
  1158. break;
  1159. }
  1160. return err;
  1161. }
  1162. EXPORT_SYMBOL(v4l_compat_translate_ioctl);
  1163. /*
  1164. * Local variables:
  1165. * c-basic-offset: 8
  1166. * End:
  1167. */