v4l1-compat.c 27 KB

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