v4l1-compat.c 32 KB

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