v4l1-compat.c 32 KB

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