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. set_current_state(TASK_INTERRUPTIBLE);
  190. mask = file->f_op->poll(file, table);
  191. if (mask & POLLIN)
  192. break;
  193. table = NULL;
  194. if (signal_pending(current)) {
  195. retval = -ERESTARTSYS;
  196. break;
  197. }
  198. schedule();
  199. }
  200. set_current_state(TASK_RUNNING);
  201. poll_freewait(pwq);
  202. return retval;
  203. }
  204. static int count_inputs(
  205. struct file *file,
  206. v4l2_kioctl drv)
  207. {
  208. struct v4l2_input input2;
  209. int i;
  210. for (i = 0;; i++) {
  211. memset(&input2, 0, sizeof(input2));
  212. input2.index = i;
  213. if (0 != drv(file, VIDIOC_ENUMINPUT, &input2))
  214. break;
  215. }
  216. return i;
  217. }
  218. static int check_size(
  219. struct file *file,
  220. v4l2_kioctl drv,
  221. int *maxw,
  222. int *maxh)
  223. {
  224. struct v4l2_fmtdesc desc2;
  225. struct v4l2_format fmt2;
  226. memset(&desc2, 0, sizeof(desc2));
  227. memset(&fmt2, 0, sizeof(fmt2));
  228. desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  229. if (0 != drv(file, VIDIOC_ENUM_FMT, &desc2))
  230. goto done;
  231. fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  232. fmt2.fmt.pix.width = 10000;
  233. fmt2.fmt.pix.height = 10000;
  234. fmt2.fmt.pix.pixelformat = desc2.pixelformat;
  235. if (0 != drv(file, VIDIOC_TRY_FMT, &fmt2))
  236. goto done;
  237. *maxw = fmt2.fmt.pix.width;
  238. *maxh = fmt2.fmt.pix.height;
  239. done:
  240. return 0;
  241. }
  242. /* ----------------------------------------------------------------- */
  243. static noinline int v4l1_compat_get_capabilities(
  244. struct video_capability *cap,
  245. struct file *file,
  246. v4l2_kioctl drv)
  247. {
  248. int err;
  249. struct v4l2_framebuffer fbuf;
  250. struct v4l2_capability *cap2;
  251. cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
  252. if (!cap2) {
  253. err = -ENOMEM;
  254. return err;
  255. }
  256. memset(cap, 0, sizeof(*cap));
  257. memset(&fbuf, 0, sizeof(fbuf));
  258. err = drv(file, VIDIOC_QUERYCAP, cap2);
  259. if (err < 0) {
  260. dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n", err);
  261. goto done;
  262. }
  263. if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
  264. err = drv(file, VIDIOC_G_FBUF, &fbuf);
  265. if (err < 0) {
  266. dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n", err);
  267. memset(&fbuf, 0, sizeof(fbuf));
  268. }
  269. err = 0;
  270. }
  271. memcpy(cap->name, cap2->card,
  272. min(sizeof(cap->name), sizeof(cap2->card)));
  273. cap->name[sizeof(cap->name) - 1] = 0;
  274. if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
  275. cap->type |= VID_TYPE_CAPTURE;
  276. if (cap2->capabilities & V4L2_CAP_TUNER)
  277. cap->type |= VID_TYPE_TUNER;
  278. if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
  279. cap->type |= VID_TYPE_TELETEXT;
  280. if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
  281. cap->type |= VID_TYPE_OVERLAY;
  282. if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
  283. cap->type |= VID_TYPE_CLIPPING;
  284. cap->channels = count_inputs(file, drv);
  285. check_size(file, drv,
  286. &cap->maxwidth, &cap->maxheight);
  287. cap->audios = 0; /* FIXME */
  288. cap->minwidth = 48; /* FIXME */
  289. cap->minheight = 32; /* FIXME */
  290. done:
  291. kfree(cap2);
  292. return err;
  293. }
  294. static noinline int v4l1_compat_get_frame_buffer(
  295. struct video_buffer *buffer,
  296. struct file *file,
  297. v4l2_kioctl drv)
  298. {
  299. int err;
  300. struct v4l2_framebuffer fbuf;
  301. memset(buffer, 0, sizeof(*buffer));
  302. memset(&fbuf, 0, sizeof(fbuf));
  303. err = drv(file, VIDIOC_G_FBUF, &fbuf);
  304. if (err < 0) {
  305. dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n", err);
  306. goto done;
  307. }
  308. buffer->base = fbuf.base;
  309. buffer->height = fbuf.fmt.height;
  310. buffer->width = fbuf.fmt.width;
  311. switch (fbuf.fmt.pixelformat) {
  312. case V4L2_PIX_FMT_RGB332:
  313. buffer->depth = 8;
  314. break;
  315. case V4L2_PIX_FMT_RGB555:
  316. buffer->depth = 15;
  317. break;
  318. case V4L2_PIX_FMT_RGB565:
  319. buffer->depth = 16;
  320. break;
  321. case V4L2_PIX_FMT_BGR24:
  322. buffer->depth = 24;
  323. break;
  324. case V4L2_PIX_FMT_BGR32:
  325. buffer->depth = 32;
  326. break;
  327. default:
  328. buffer->depth = 0;
  329. }
  330. if (fbuf.fmt.bytesperline) {
  331. buffer->bytesperline = fbuf.fmt.bytesperline;
  332. if (!buffer->depth && buffer->width)
  333. buffer->depth = ((fbuf.fmt.bytesperline<<3)
  334. + (buffer->width-1))
  335. / buffer->width;
  336. } else {
  337. buffer->bytesperline =
  338. (buffer->width * buffer->depth + 7) & 7;
  339. buffer->bytesperline >>= 3;
  340. }
  341. done:
  342. return err;
  343. }
  344. static noinline int v4l1_compat_set_frame_buffer(
  345. struct video_buffer *buffer,
  346. struct file *file,
  347. v4l2_kioctl drv)
  348. {
  349. int err;
  350. struct v4l2_framebuffer fbuf;
  351. memset(&fbuf, 0, sizeof(fbuf));
  352. fbuf.base = buffer->base;
  353. fbuf.fmt.height = buffer->height;
  354. fbuf.fmt.width = buffer->width;
  355. switch (buffer->depth) {
  356. case 8:
  357. fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
  358. break;
  359. case 15:
  360. fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
  361. break;
  362. case 16:
  363. fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
  364. break;
  365. case 24:
  366. fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
  367. break;
  368. case 32:
  369. fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
  370. break;
  371. }
  372. fbuf.fmt.bytesperline = buffer->bytesperline;
  373. err = drv(file, VIDIOC_S_FBUF, &fbuf);
  374. if (err < 0)
  375. dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n", err);
  376. return err;
  377. }
  378. static noinline int v4l1_compat_get_win_cap_dimensions(
  379. struct video_window *win,
  380. struct file *file,
  381. v4l2_kioctl drv)
  382. {
  383. int err;
  384. struct v4l2_format *fmt;
  385. fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
  386. if (!fmt) {
  387. err = -ENOMEM;
  388. return err;
  389. }
  390. memset(win, 0, sizeof(*win));
  391. fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
  392. err = drv(file, VIDIOC_G_FMT, fmt);
  393. if (err < 0)
  394. dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n", err);
  395. if (err == 0) {
  396. win->x = fmt->fmt.win.w.left;
  397. win->y = fmt->fmt.win.w.top;
  398. win->width = fmt->fmt.win.w.width;
  399. win->height = fmt->fmt.win.w.height;
  400. win->chromakey = fmt->fmt.win.chromakey;
  401. win->clips = NULL;
  402. win->clipcount = 0;
  403. goto done;
  404. }
  405. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  406. err = drv(file, VIDIOC_G_FMT, fmt);
  407. if (err < 0) {
  408. dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n", err);
  409. goto done;
  410. }
  411. win->x = 0;
  412. win->y = 0;
  413. win->width = fmt->fmt.pix.width;
  414. win->height = fmt->fmt.pix.height;
  415. win->chromakey = 0;
  416. win->clips = NULL;
  417. win->clipcount = 0;
  418. done:
  419. kfree(fmt);
  420. return err;
  421. }
  422. static noinline int v4l1_compat_set_win_cap_dimensions(
  423. struct video_window *win,
  424. struct file *file,
  425. v4l2_kioctl drv)
  426. {
  427. int err, err1, err2;
  428. struct v4l2_format *fmt;
  429. fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
  430. if (!fmt) {
  431. err = -ENOMEM;
  432. return err;
  433. }
  434. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  435. drv(file, VIDIOC_STREAMOFF, &fmt->type);
  436. err1 = drv(file, VIDIOC_G_FMT, fmt);
  437. if (err1 < 0)
  438. dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n", err1);
  439. if (err1 == 0) {
  440. fmt->fmt.pix.width = win->width;
  441. fmt->fmt.pix.height = win->height;
  442. fmt->fmt.pix.field = V4L2_FIELD_ANY;
  443. fmt->fmt.pix.bytesperline = 0;
  444. err = drv(file, VIDIOC_S_FMT, fmt);
  445. if (err < 0)
  446. dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
  447. err);
  448. win->width = fmt->fmt.pix.width;
  449. win->height = fmt->fmt.pix.height;
  450. }
  451. memset(fmt, 0, sizeof(*fmt));
  452. fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
  453. fmt->fmt.win.w.left = win->x;
  454. fmt->fmt.win.w.top = win->y;
  455. fmt->fmt.win.w.width = win->width;
  456. fmt->fmt.win.w.height = win->height;
  457. fmt->fmt.win.chromakey = win->chromakey;
  458. fmt->fmt.win.clips = (void __user *)win->clips;
  459. fmt->fmt.win.clipcount = win->clipcount;
  460. err2 = drv(file, VIDIOC_S_FMT, fmt);
  461. if (err2 < 0)
  462. dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n", err2);
  463. if (err1 != 0 && err2 != 0)
  464. err = err1;
  465. else
  466. err = 0;
  467. kfree(fmt);
  468. return err;
  469. }
  470. static noinline int v4l1_compat_turn_preview_on_off(
  471. int *on,
  472. struct file *file,
  473. v4l2_kioctl drv)
  474. {
  475. int err;
  476. enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  477. if (0 == *on) {
  478. /* dirty hack time. But v4l1 has no STREAMOFF
  479. * equivalent in the API, and this one at
  480. * least comes close ... */
  481. drv(file, VIDIOC_STREAMOFF, &captype);
  482. }
  483. err = drv(file, VIDIOC_OVERLAY, on);
  484. if (err < 0)
  485. dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n", err);
  486. return err;
  487. }
  488. static noinline int v4l1_compat_get_input_info(
  489. struct video_channel *chan,
  490. struct file *file,
  491. v4l2_kioctl drv)
  492. {
  493. int err;
  494. struct v4l2_input input2;
  495. v4l2_std_id sid;
  496. memset(&input2, 0, sizeof(input2));
  497. input2.index = chan->channel;
  498. err = drv(file, VIDIOC_ENUMINPUT, &input2);
  499. if (err < 0) {
  500. dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
  501. "channel=%d err=%d\n", chan->channel, err);
  502. goto done;
  503. }
  504. chan->channel = input2.index;
  505. memcpy(chan->name, input2.name,
  506. min(sizeof(chan->name), sizeof(input2.name)));
  507. chan->name[sizeof(chan->name) - 1] = 0;
  508. chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
  509. chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
  510. switch (input2.type) {
  511. case V4L2_INPUT_TYPE_TUNER:
  512. chan->type = VIDEO_TYPE_TV;
  513. break;
  514. default:
  515. case V4L2_INPUT_TYPE_CAMERA:
  516. chan->type = VIDEO_TYPE_CAMERA;
  517. break;
  518. }
  519. chan->norm = 0;
  520. err = drv(file, VIDIOC_G_STD, &sid);
  521. if (err < 0)
  522. dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n", err);
  523. if (err == 0) {
  524. if (sid & V4L2_STD_PAL)
  525. chan->norm = VIDEO_MODE_PAL;
  526. if (sid & V4L2_STD_NTSC)
  527. chan->norm = VIDEO_MODE_NTSC;
  528. if (sid & V4L2_STD_SECAM)
  529. chan->norm = VIDEO_MODE_SECAM;
  530. }
  531. done:
  532. return err;
  533. }
  534. static noinline int v4l1_compat_set_input(
  535. struct video_channel *chan,
  536. struct file *file,
  537. v4l2_kioctl drv)
  538. {
  539. int err;
  540. v4l2_std_id sid = 0;
  541. err = drv(file, VIDIOC_S_INPUT, &chan->channel);
  542. if (err < 0)
  543. dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n", err);
  544. switch (chan->norm) {
  545. case VIDEO_MODE_PAL:
  546. sid = V4L2_STD_PAL;
  547. break;
  548. case VIDEO_MODE_NTSC:
  549. sid = V4L2_STD_NTSC;
  550. break;
  551. case VIDEO_MODE_SECAM:
  552. sid = V4L2_STD_SECAM;
  553. break;
  554. }
  555. if (0 != sid) {
  556. err = drv(file, VIDIOC_S_STD, &sid);
  557. if (err < 0)
  558. dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n", err);
  559. }
  560. return err;
  561. }
  562. static noinline int v4l1_compat_get_picture(
  563. struct video_picture *pict,
  564. struct file *file,
  565. v4l2_kioctl drv)
  566. {
  567. int err;
  568. struct v4l2_format *fmt;
  569. fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
  570. if (!fmt) {
  571. err = -ENOMEM;
  572. return err;
  573. }
  574. pict->brightness = get_v4l_control(file,
  575. V4L2_CID_BRIGHTNESS, drv);
  576. pict->hue = get_v4l_control(file,
  577. V4L2_CID_HUE, drv);
  578. pict->contrast = get_v4l_control(file,
  579. V4L2_CID_CONTRAST, drv);
  580. pict->colour = get_v4l_control(file,
  581. V4L2_CID_SATURATION, drv);
  582. pict->whiteness = get_v4l_control(file,
  583. V4L2_CID_WHITENESS, drv);
  584. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  585. err = drv(file, VIDIOC_G_FMT, fmt);
  586. if (err < 0) {
  587. dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n", err);
  588. goto done;
  589. }
  590. pict->depth = ((fmt->fmt.pix.bytesperline << 3)
  591. + (fmt->fmt.pix.width - 1))
  592. / fmt->fmt.pix.width;
  593. pict->palette = pixelformat_to_palette(
  594. fmt->fmt.pix.pixelformat);
  595. done:
  596. kfree(fmt);
  597. return err;
  598. }
  599. static noinline int v4l1_compat_set_picture(
  600. struct video_picture *pict,
  601. struct file *file,
  602. v4l2_kioctl drv)
  603. {
  604. int err;
  605. struct v4l2_framebuffer fbuf;
  606. int mem_err = 0, ovl_err = 0;
  607. struct v4l2_format *fmt;
  608. fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
  609. if (!fmt) {
  610. err = -ENOMEM;
  611. return err;
  612. }
  613. memset(&fbuf, 0, sizeof(fbuf));
  614. set_v4l_control(file,
  615. V4L2_CID_BRIGHTNESS, pict->brightness, drv);
  616. set_v4l_control(file,
  617. V4L2_CID_HUE, pict->hue, drv);
  618. set_v4l_control(file,
  619. V4L2_CID_CONTRAST, pict->contrast, drv);
  620. set_v4l_control(file,
  621. V4L2_CID_SATURATION, pict->colour, drv);
  622. set_v4l_control(file,
  623. V4L2_CID_WHITENESS, pict->whiteness, drv);
  624. /*
  625. * V4L1 uses this ioctl to set both memory capture and overlay
  626. * pixel format, while V4L2 has two different ioctls for this.
  627. * Some cards may not support one or the other, and may support
  628. * different pixel formats for memory vs overlay.
  629. */
  630. fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  631. err = drv(file, VIDIOC_G_FMT, fmt);
  632. /* If VIDIOC_G_FMT failed, then the driver likely doesn't
  633. support memory capture. Trying to set the memory capture
  634. parameters would be pointless. */
  635. if (err < 0) {
  636. dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n", err);
  637. mem_err = -1000; /* didn't even try */
  638. } else if (fmt->fmt.pix.pixelformat !=
  639. palette_to_pixelformat(pict->palette)) {
  640. fmt->fmt.pix.pixelformat = palette_to_pixelformat(
  641. pict->palette);
  642. mem_err = drv(file, VIDIOC_S_FMT, fmt);
  643. if (mem_err < 0)
  644. dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
  645. mem_err);
  646. }
  647. err = drv(file, VIDIOC_G_FBUF, &fbuf);
  648. /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
  649. support overlay. Trying to set the overlay parameters
  650. would be quite pointless. */
  651. if (err < 0) {
  652. dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n", err);
  653. ovl_err = -1000; /* didn't even try */
  654. } else if (fbuf.fmt.pixelformat !=
  655. palette_to_pixelformat(pict->palette)) {
  656. fbuf.fmt.pixelformat = palette_to_pixelformat(
  657. pict->palette);
  658. ovl_err = drv(file, VIDIOC_S_FBUF, &fbuf);
  659. if (ovl_err < 0)
  660. dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
  661. ovl_err);
  662. }
  663. if (ovl_err < 0 && mem_err < 0) {
  664. /* ioctl failed, couldn't set either parameter */
  665. if (mem_err != -1000)
  666. err = mem_err;
  667. else if (ovl_err == -EPERM)
  668. err = 0;
  669. else
  670. err = ovl_err;
  671. } else
  672. err = 0;
  673. kfree(fmt);
  674. return err;
  675. }
  676. static noinline int v4l1_compat_get_tuner(
  677. struct video_tuner *tun,
  678. struct file *file,
  679. v4l2_kioctl drv)
  680. {
  681. int err, i;
  682. struct v4l2_tuner tun2;
  683. struct v4l2_standard std2;
  684. v4l2_std_id sid;
  685. memset(&tun2, 0, sizeof(tun2));
  686. err = drv(file, VIDIOC_G_TUNER, &tun2);
  687. if (err < 0) {
  688. dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n", err);
  689. goto done;
  690. }
  691. memcpy(tun->name, tun2.name,
  692. min(sizeof(tun->name), sizeof(tun2.name)));
  693. tun->name[sizeof(tun->name) - 1] = 0;
  694. tun->rangelow = tun2.rangelow;
  695. tun->rangehigh = tun2.rangehigh;
  696. tun->flags = 0;
  697. tun->mode = VIDEO_MODE_AUTO;
  698. for (i = 0; i < 64; i++) {
  699. memset(&std2, 0, sizeof(std2));
  700. std2.index = i;
  701. if (0 != drv(file, VIDIOC_ENUMSTD, &std2))
  702. break;
  703. if (std2.id & V4L2_STD_PAL)
  704. tun->flags |= VIDEO_TUNER_PAL;
  705. if (std2.id & V4L2_STD_NTSC)
  706. tun->flags |= VIDEO_TUNER_NTSC;
  707. if (std2.id & V4L2_STD_SECAM)
  708. tun->flags |= VIDEO_TUNER_SECAM;
  709. }
  710. err = drv(file, VIDIOC_G_STD, &sid);
  711. if (err < 0)
  712. dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n", err);
  713. if (err == 0) {
  714. if (sid & V4L2_STD_PAL)
  715. tun->mode = VIDEO_MODE_PAL;
  716. if (sid & V4L2_STD_NTSC)
  717. tun->mode = VIDEO_MODE_NTSC;
  718. if (sid & V4L2_STD_SECAM)
  719. tun->mode = VIDEO_MODE_SECAM;
  720. }
  721. if (tun2.capability & V4L2_TUNER_CAP_LOW)
  722. tun->flags |= VIDEO_TUNER_LOW;
  723. if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
  724. tun->flags |= VIDEO_TUNER_STEREO_ON;
  725. tun->signal = tun2.signal;
  726. done:
  727. return err;
  728. }
  729. static noinline int v4l1_compat_select_tuner(
  730. struct video_tuner *tun,
  731. struct file *file,
  732. v4l2_kioctl drv)
  733. {
  734. int err;
  735. struct v4l2_tuner t;/*84 bytes on x86_64*/
  736. memset(&t, 0, sizeof(t));
  737. t.index = tun->tuner;
  738. err = drv(file, VIDIOC_S_INPUT, &t);
  739. if (err < 0)
  740. dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n", err);
  741. return err;
  742. }
  743. static noinline int v4l1_compat_get_frequency(
  744. unsigned long *freq,
  745. struct file *file,
  746. v4l2_kioctl drv)
  747. {
  748. int err;
  749. struct v4l2_frequency freq2;
  750. memset(&freq2, 0, sizeof(freq2));
  751. freq2.tuner = 0;
  752. err = drv(file, VIDIOC_G_FREQUENCY, &freq2);
  753. if (err < 0)
  754. dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n", err);
  755. if (0 == err)
  756. *freq = freq2.frequency;
  757. return err;
  758. }
  759. static noinline int v4l1_compat_set_frequency(
  760. unsigned long *freq,
  761. struct file *file,
  762. v4l2_kioctl drv)
  763. {
  764. int err;
  765. struct v4l2_frequency freq2;
  766. memset(&freq2, 0, sizeof(freq2));
  767. drv(file, VIDIOC_G_FREQUENCY, &freq2);
  768. freq2.frequency = *freq;
  769. err = drv(file, VIDIOC_S_FREQUENCY, &freq2);
  770. if (err < 0)
  771. dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n", err);
  772. return err;
  773. }
  774. static noinline int v4l1_compat_get_audio(
  775. struct video_audio *aud,
  776. struct file *file,
  777. v4l2_kioctl drv)
  778. {
  779. int err, 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: %d\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: %d\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 int v4l1_compat_set_audio(
  843. struct video_audio *aud,
  844. struct file *file,
  845. v4l2_kioctl drv)
  846. {
  847. int 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: %d\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: %d\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: %d\n", err);
  888. }
  889. err = 0;
  890. done:
  891. return err;
  892. }
  893. static noinline int v4l1_compat_capture_frame(
  894. struct video_mmap *mm,
  895. struct file *file,
  896. v4l2_kioctl drv)
  897. {
  898. int 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: %d\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: %d\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: %d\n", err);
  936. goto done;
  937. }
  938. err = drv(file, VIDIOC_QBUF, &buf);
  939. if (err < 0) {
  940. dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n", err);
  941. goto done;
  942. }
  943. err = drv(file, VIDIOC_STREAMON, &captype);
  944. if (err < 0)
  945. dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n", err);
  946. done:
  947. kfree(fmt);
  948. return err;
  949. }
  950. static noinline int v4l1_compat_sync(
  951. int *i,
  952. struct file *file,
  953. v4l2_kioctl drv)
  954. {
  955. int 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: %d\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: %d\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: %d\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: %d\n", err);
  998. } while (err == 0 && buf.index != *i);
  999. done:
  1000. return err;
  1001. }
  1002. static noinline int v4l1_compat_get_vbi_format(
  1003. struct vbi_format *fmt,
  1004. struct file *file,
  1005. v4l2_kioctl drv)
  1006. {
  1007. int 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: %d\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 int v4l1_compat_set_vbi_format(
  1038. struct vbi_format *fmt,
  1039. struct file *file,
  1040. v4l2_kioctl drv)
  1041. {
  1042. int 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: %d\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: %d\n", err);
  1081. done:
  1082. kfree(fmt2);
  1083. return err;
  1084. }
  1085. /*
  1086. * This function is exported.
  1087. */
  1088. int
  1089. v4l_compat_translate_ioctl(struct file *file,
  1090. int cmd,
  1091. void *arg,
  1092. v4l2_kioctl drv)
  1093. {
  1094. int 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. */