usbvision-video.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  1. /*
  2. * USB USBVISION Video device driver 0.9.10
  3. *
  4. *
  5. *
  6. * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
  7. *
  8. * This module is part of usbvision driver project.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. * Let's call the version 0.... until compression decoding is completely
  25. * implemented.
  26. *
  27. * This driver is written by Jose Ignacio Gijon and Joerg Heckenbach.
  28. * It was based on USB CPiA driver written by Peter Pregler,
  29. * Scott J. Bertin and Johannes Erdfelt
  30. * Ideas are taken from bttv driver by Ralph Metzler, Marcus Metzler &
  31. * Gerd Knorr and zoran 36120/36125 driver by Pauline Middelink
  32. * Updates to driver completed by Dwaine P. Garden
  33. *
  34. *
  35. * TODO:
  36. * - use submit_urb for all setup packets
  37. * - Fix memory settings for nt1004. It is 4 times as big as the
  38. * nt1003 memory.
  39. * - Add audio on endpoint 3 for nt1004 chip.
  40. * Seems impossible, needs a codec interface. Which one?
  41. * - Clean up the driver.
  42. * - optimization for performance.
  43. * - Add Videotext capability (VBI). Working on it.....
  44. * - Check audio for other devices
  45. *
  46. */
  47. #include <linux/version.h>
  48. #include <linux/kernel.h>
  49. #include <linux/list.h>
  50. #include <linux/timer.h>
  51. #include <linux/slab.h>
  52. #include <linux/smp_lock.h>
  53. #include <linux/mm.h>
  54. #include <linux/highmem.h>
  55. #include <linux/vmalloc.h>
  56. #include <linux/module.h>
  57. #include <linux/init.h>
  58. #include <linux/spinlock.h>
  59. #include <asm/io.h>
  60. #include <linux/videodev2.h>
  61. #include <linux/i2c.h>
  62. #include <media/saa7115.h>
  63. #include <media/v4l2-common.h>
  64. #include <media/v4l2-ioctl.h>
  65. #include <media/tuner.h>
  66. #include <linux/workqueue.h>
  67. #include "usbvision.h"
  68. #include "usbvision-cards.h"
  69. #define DRIVER_AUTHOR "Joerg Heckenbach <joerg@heckenbach-aw.de>,\
  70. Dwaine Garden <DwaineGarden@rogers.com>"
  71. #define DRIVER_NAME "usbvision"
  72. #define DRIVER_ALIAS "USBVision"
  73. #define DRIVER_DESC "USBVision USB Video Device Driver for Linux"
  74. #define DRIVER_LICENSE "GPL"
  75. #define USBVISION_DRIVER_VERSION_MAJOR 0
  76. #define USBVISION_DRIVER_VERSION_MINOR 9
  77. #define USBVISION_DRIVER_VERSION_PATCHLEVEL 10
  78. #define USBVISION_DRIVER_VERSION KERNEL_VERSION(USBVISION_DRIVER_VERSION_MAJOR,\
  79. USBVISION_DRIVER_VERSION_MINOR,\
  80. USBVISION_DRIVER_VERSION_PATCHLEVEL)
  81. #define USBVISION_VERSION_STRING __stringify(USBVISION_DRIVER_VERSION_MAJOR)\
  82. "." __stringify(USBVISION_DRIVER_VERSION_MINOR)\
  83. "." __stringify(USBVISION_DRIVER_VERSION_PATCHLEVEL)
  84. #define ENABLE_HEXDUMP 0 /* Enable if you need it */
  85. #ifdef USBVISION_DEBUG
  86. #define PDEBUG(level, fmt, args...) { \
  87. if (video_debug & (level)) \
  88. printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
  89. __func__, __LINE__ , ## args); \
  90. }
  91. #else
  92. #define PDEBUG(level, fmt, args...) do {} while(0)
  93. #endif
  94. #define DBG_IO 1<<1
  95. #define DBG_PROBE 1<<2
  96. #define DBG_MMAP 1<<3
  97. //String operations
  98. #define rmspace(str) while(*str==' ') str++;
  99. #define goto2next(str) while(*str!=' ') str++; while(*str==' ') str++;
  100. /* sequential number of usbvision device */
  101. static int usbvision_nr;
  102. static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
  103. { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" },
  104. { 1, 2, 16, V4L2_PIX_FMT_RGB565 , "RGB565" },
  105. { 1, 3, 24, V4L2_PIX_FMT_RGB24 , "RGB24" },
  106. { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" },
  107. { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" },
  108. { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" },
  109. { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, // 1.5 !
  110. { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" }
  111. };
  112. /* Function prototypes */
  113. static void usbvision_release(struct usb_usbvision *usbvision);
  114. /* Default initialization of device driver parameters */
  115. /* Set the default format for ISOC endpoint */
  116. static int isocMode = ISOC_MODE_COMPRESS;
  117. /* Set the default Debug Mode of the device driver */
  118. static int video_debug;
  119. /* Set the default device to power on at startup */
  120. static int PowerOnAtOpen = 1;
  121. /* Sequential Number of Video Device */
  122. static int video_nr = -1;
  123. /* Sequential Number of Radio Device */
  124. static int radio_nr = -1;
  125. /* Sequential Number of VBI Device */
  126. static int vbi_nr = -1;
  127. /* Grab parameters for the device driver */
  128. /* Showing parameters under SYSFS */
  129. module_param(isocMode, int, 0444);
  130. module_param(video_debug, int, 0444);
  131. module_param(PowerOnAtOpen, int, 0444);
  132. module_param(video_nr, int, 0444);
  133. module_param(radio_nr, int, 0444);
  134. module_param(vbi_nr, int, 0444);
  135. MODULE_PARM_DESC(isocMode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)");
  136. MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)");
  137. MODULE_PARM_DESC(PowerOnAtOpen, " Set the default device to power on when device is opened. Default: 1 (On)");
  138. MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)");
  139. MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
  140. MODULE_PARM_DESC(vbi_nr, "Set vbi device number (/dev/vbiX). Default: -1 (autodetect)");
  141. // Misc stuff
  142. MODULE_AUTHOR(DRIVER_AUTHOR);
  143. MODULE_DESCRIPTION(DRIVER_DESC);
  144. MODULE_LICENSE(DRIVER_LICENSE);
  145. MODULE_VERSION(USBVISION_VERSION_STRING);
  146. MODULE_ALIAS(DRIVER_ALIAS);
  147. /*****************************************************************************/
  148. /* SYSFS Code - Copied from the stv680.c usb module. */
  149. /* Device information is located at /sys/class/video4linux/video0 */
  150. /* Device parameters information is located at /sys/module/usbvision */
  151. /* Device USB Information is located at */
  152. /* /sys/bus/usb/drivers/USBVision Video Grabber */
  153. /*****************************************************************************/
  154. #define YES_NO(x) ((x) ? "Yes" : "No")
  155. static inline struct usb_usbvision *cd_to_usbvision(struct device *cd)
  156. {
  157. struct video_device *vdev =
  158. container_of(cd, struct video_device, dev);
  159. return video_get_drvdata(vdev);
  160. }
  161. static ssize_t show_version(struct device *cd,
  162. struct device_attribute *attr, char *buf)
  163. {
  164. return sprintf(buf, "%s\n", USBVISION_VERSION_STRING);
  165. }
  166. static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
  167. static ssize_t show_model(struct device *cd,
  168. struct device_attribute *attr, char *buf)
  169. {
  170. struct video_device *vdev =
  171. container_of(cd, struct video_device, dev);
  172. struct usb_usbvision *usbvision = video_get_drvdata(vdev);
  173. return sprintf(buf, "%s\n",
  174. usbvision_device_data[usbvision->DevModel].ModelString);
  175. }
  176. static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
  177. static ssize_t show_hue(struct device *cd,
  178. struct device_attribute *attr, char *buf)
  179. {
  180. struct video_device *vdev =
  181. container_of(cd, struct video_device, dev);
  182. struct usb_usbvision *usbvision = video_get_drvdata(vdev);
  183. struct v4l2_control ctrl;
  184. ctrl.id = V4L2_CID_HUE;
  185. ctrl.value = 0;
  186. if(usbvision->user)
  187. call_all(usbvision, core, g_ctrl, &ctrl);
  188. return sprintf(buf, "%d\n", ctrl.value);
  189. }
  190. static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
  191. static ssize_t show_contrast(struct device *cd,
  192. struct device_attribute *attr, char *buf)
  193. {
  194. struct video_device *vdev =
  195. container_of(cd, struct video_device, dev);
  196. struct usb_usbvision *usbvision = video_get_drvdata(vdev);
  197. struct v4l2_control ctrl;
  198. ctrl.id = V4L2_CID_CONTRAST;
  199. ctrl.value = 0;
  200. if(usbvision->user)
  201. call_all(usbvision, core, g_ctrl, &ctrl);
  202. return sprintf(buf, "%d\n", ctrl.value);
  203. }
  204. static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
  205. static ssize_t show_brightness(struct device *cd,
  206. struct device_attribute *attr, char *buf)
  207. {
  208. struct video_device *vdev =
  209. container_of(cd, struct video_device, dev);
  210. struct usb_usbvision *usbvision = video_get_drvdata(vdev);
  211. struct v4l2_control ctrl;
  212. ctrl.id = V4L2_CID_BRIGHTNESS;
  213. ctrl.value = 0;
  214. if(usbvision->user)
  215. call_all(usbvision, core, g_ctrl, &ctrl);
  216. return sprintf(buf, "%d\n", ctrl.value);
  217. }
  218. static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
  219. static ssize_t show_saturation(struct device *cd,
  220. struct device_attribute *attr, char *buf)
  221. {
  222. struct video_device *vdev =
  223. container_of(cd, struct video_device, dev);
  224. struct usb_usbvision *usbvision = video_get_drvdata(vdev);
  225. struct v4l2_control ctrl;
  226. ctrl.id = V4L2_CID_SATURATION;
  227. ctrl.value = 0;
  228. if(usbvision->user)
  229. call_all(usbvision, core, g_ctrl, &ctrl);
  230. return sprintf(buf, "%d\n", ctrl.value);
  231. }
  232. static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
  233. static ssize_t show_streaming(struct device *cd,
  234. struct device_attribute *attr, char *buf)
  235. {
  236. struct video_device *vdev =
  237. container_of(cd, struct video_device, dev);
  238. struct usb_usbvision *usbvision = video_get_drvdata(vdev);
  239. return sprintf(buf, "%s\n",
  240. YES_NO(usbvision->streaming==Stream_On?1:0));
  241. }
  242. static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
  243. static ssize_t show_compression(struct device *cd,
  244. struct device_attribute *attr, char *buf)
  245. {
  246. struct video_device *vdev =
  247. container_of(cd, struct video_device, dev);
  248. struct usb_usbvision *usbvision = video_get_drvdata(vdev);
  249. return sprintf(buf, "%s\n",
  250. YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS));
  251. }
  252. static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
  253. static ssize_t show_device_bridge(struct device *cd,
  254. struct device_attribute *attr, char *buf)
  255. {
  256. struct video_device *vdev =
  257. container_of(cd, struct video_device, dev);
  258. struct usb_usbvision *usbvision = video_get_drvdata(vdev);
  259. return sprintf(buf, "%d\n", usbvision->bridgeType);
  260. }
  261. static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
  262. static void usbvision_create_sysfs(struct video_device *vdev)
  263. {
  264. int res;
  265. if (!vdev)
  266. return;
  267. do {
  268. res = device_create_file(&vdev->dev, &dev_attr_version);
  269. if (res<0)
  270. break;
  271. res = device_create_file(&vdev->dev, &dev_attr_model);
  272. if (res<0)
  273. break;
  274. res = device_create_file(&vdev->dev, &dev_attr_hue);
  275. if (res<0)
  276. break;
  277. res = device_create_file(&vdev->dev, &dev_attr_contrast);
  278. if (res<0)
  279. break;
  280. res = device_create_file(&vdev->dev, &dev_attr_brightness);
  281. if (res<0)
  282. break;
  283. res = device_create_file(&vdev->dev, &dev_attr_saturation);
  284. if (res<0)
  285. break;
  286. res = device_create_file(&vdev->dev, &dev_attr_streaming);
  287. if (res<0)
  288. break;
  289. res = device_create_file(&vdev->dev, &dev_attr_compression);
  290. if (res<0)
  291. break;
  292. res = device_create_file(&vdev->dev, &dev_attr_bridge);
  293. if (res>=0)
  294. return;
  295. } while (0);
  296. dev_err(&vdev->dev, "%s error: %d\n", __func__, res);
  297. }
  298. static void usbvision_remove_sysfs(struct video_device *vdev)
  299. {
  300. if (vdev) {
  301. device_remove_file(&vdev->dev, &dev_attr_version);
  302. device_remove_file(&vdev->dev, &dev_attr_model);
  303. device_remove_file(&vdev->dev, &dev_attr_hue);
  304. device_remove_file(&vdev->dev, &dev_attr_contrast);
  305. device_remove_file(&vdev->dev, &dev_attr_brightness);
  306. device_remove_file(&vdev->dev, &dev_attr_saturation);
  307. device_remove_file(&vdev->dev, &dev_attr_streaming);
  308. device_remove_file(&vdev->dev, &dev_attr_compression);
  309. device_remove_file(&vdev->dev, &dev_attr_bridge);
  310. }
  311. }
  312. /*
  313. * usbvision_open()
  314. *
  315. * This is part of Video 4 Linux API. The driver can be opened by one
  316. * client only (checks internal counter 'usbvision->user'). The procedure
  317. * then allocates buffers needed for video processing.
  318. *
  319. */
  320. static int usbvision_v4l2_open(struct file *file)
  321. {
  322. struct usb_usbvision *usbvision = video_drvdata(file);
  323. int errCode = 0;
  324. PDEBUG(DBG_IO, "open");
  325. lock_kernel();
  326. usbvision_reset_powerOffTimer(usbvision);
  327. if (usbvision->user)
  328. errCode = -EBUSY;
  329. else {
  330. /* Allocate memory for the scratch ring buffer */
  331. errCode = usbvision_scratch_alloc(usbvision);
  332. if (isocMode==ISOC_MODE_COMPRESS) {
  333. /* Allocate intermediate decompression buffers
  334. only if needed */
  335. errCode = usbvision_decompress_alloc(usbvision);
  336. }
  337. if (errCode) {
  338. /* Deallocate all buffers if trouble */
  339. usbvision_scratch_free(usbvision);
  340. usbvision_decompress_free(usbvision);
  341. }
  342. }
  343. /* If so far no errors then we shall start the camera */
  344. if (!errCode) {
  345. mutex_lock(&usbvision->lock);
  346. if (usbvision->power == 0) {
  347. usbvision_power_on(usbvision);
  348. usbvision_i2c_register(usbvision);
  349. }
  350. /* Send init sequence only once, it's large! */
  351. if (!usbvision->initialized) {
  352. int setup_ok = 0;
  353. setup_ok = usbvision_setup(usbvision,isocMode);
  354. if (setup_ok)
  355. usbvision->initialized = 1;
  356. else
  357. errCode = -EBUSY;
  358. }
  359. if (!errCode) {
  360. usbvision_begin_streaming(usbvision);
  361. errCode = usbvision_init_isoc(usbvision);
  362. /* device must be initialized before isoc transfer */
  363. usbvision_muxsel(usbvision,0);
  364. usbvision->user++;
  365. } else {
  366. if (PowerOnAtOpen) {
  367. usbvision_i2c_unregister(usbvision);
  368. usbvision_power_off(usbvision);
  369. usbvision->initialized = 0;
  370. }
  371. }
  372. mutex_unlock(&usbvision->lock);
  373. }
  374. /* prepare queues */
  375. usbvision_empty_framequeues(usbvision);
  376. PDEBUG(DBG_IO, "success");
  377. unlock_kernel();
  378. return errCode;
  379. }
  380. /*
  381. * usbvision_v4l2_close()
  382. *
  383. * This is part of Video 4 Linux API. The procedure
  384. * stops streaming and deallocates all buffers that were earlier
  385. * allocated in usbvision_v4l2_open().
  386. *
  387. */
  388. static int usbvision_v4l2_close(struct file *file)
  389. {
  390. struct usb_usbvision *usbvision = video_drvdata(file);
  391. PDEBUG(DBG_IO, "close");
  392. mutex_lock(&usbvision->lock);
  393. usbvision_audio_off(usbvision);
  394. usbvision_restart_isoc(usbvision);
  395. usbvision_stop_isoc(usbvision);
  396. usbvision_decompress_free(usbvision);
  397. usbvision_frames_free(usbvision);
  398. usbvision_empty_framequeues(usbvision);
  399. usbvision_scratch_free(usbvision);
  400. usbvision->user--;
  401. if (PowerOnAtOpen) {
  402. /* power off in a little while
  403. to avoid off/on every close/open short sequences */
  404. usbvision_set_powerOffTimer(usbvision);
  405. usbvision->initialized = 0;
  406. }
  407. mutex_unlock(&usbvision->lock);
  408. if (usbvision->remove_pending) {
  409. printk(KERN_INFO "%s: Final disconnect\n", __func__);
  410. usbvision_release(usbvision);
  411. }
  412. PDEBUG(DBG_IO, "success");
  413. return 0;
  414. }
  415. /*
  416. * usbvision_ioctl()
  417. *
  418. * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
  419. *
  420. */
  421. #ifdef CONFIG_VIDEO_ADV_DEBUG
  422. static int vidioc_g_register (struct file *file, void *priv,
  423. struct v4l2_dbg_register *reg)
  424. {
  425. struct usb_usbvision *usbvision = video_drvdata(file);
  426. int errCode;
  427. if (!v4l2_chip_match_host(&reg->match))
  428. return -EINVAL;
  429. /* NT100x has a 8-bit register space */
  430. errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
  431. if (errCode < 0) {
  432. dev_err(&usbvision->vdev->dev,
  433. "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n",
  434. __func__, errCode);
  435. return errCode;
  436. }
  437. reg->val = errCode;
  438. reg->size = 1;
  439. return 0;
  440. }
  441. static int vidioc_s_register (struct file *file, void *priv,
  442. struct v4l2_dbg_register *reg)
  443. {
  444. struct usb_usbvision *usbvision = video_drvdata(file);
  445. int errCode;
  446. if (!v4l2_chip_match_host(&reg->match))
  447. return -EINVAL;
  448. /* NT100x has a 8-bit register space */
  449. errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val);
  450. if (errCode < 0) {
  451. dev_err(&usbvision->vdev->dev,
  452. "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n",
  453. __func__, errCode);
  454. return errCode;
  455. }
  456. return 0;
  457. }
  458. #endif
  459. static int vidioc_querycap (struct file *file, void *priv,
  460. struct v4l2_capability *vc)
  461. {
  462. struct usb_usbvision *usbvision = video_drvdata(file);
  463. strlcpy(vc->driver, "USBVision", sizeof(vc->driver));
  464. strlcpy(vc->card,
  465. usbvision_device_data[usbvision->DevModel].ModelString,
  466. sizeof(vc->card));
  467. usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info));
  468. vc->version = USBVISION_DRIVER_VERSION;
  469. vc->capabilities = V4L2_CAP_VIDEO_CAPTURE |
  470. V4L2_CAP_AUDIO |
  471. V4L2_CAP_READWRITE |
  472. V4L2_CAP_STREAMING |
  473. (usbvision->have_tuner ? V4L2_CAP_TUNER : 0);
  474. return 0;
  475. }
  476. static int vidioc_enum_input (struct file *file, void *priv,
  477. struct v4l2_input *vi)
  478. {
  479. struct usb_usbvision *usbvision = video_drvdata(file);
  480. int chan;
  481. if (vi->index >= usbvision->video_inputs)
  482. return -EINVAL;
  483. if (usbvision->have_tuner) {
  484. chan = vi->index;
  485. } else {
  486. chan = vi->index + 1; /*skip Television string*/
  487. }
  488. /* Determine the requested input characteristics
  489. specific for each usbvision card model */
  490. switch(chan) {
  491. case 0:
  492. if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
  493. strcpy(vi->name, "White Video Input");
  494. } else {
  495. strcpy(vi->name, "Television");
  496. vi->type = V4L2_INPUT_TYPE_TUNER;
  497. vi->audioset = 1;
  498. vi->tuner = chan;
  499. vi->std = USBVISION_NORMS;
  500. }
  501. break;
  502. case 1:
  503. vi->type = V4L2_INPUT_TYPE_CAMERA;
  504. if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
  505. strcpy(vi->name, "Green Video Input");
  506. } else {
  507. strcpy(vi->name, "Composite Video Input");
  508. }
  509. vi->std = V4L2_STD_PAL;
  510. break;
  511. case 2:
  512. vi->type = V4L2_INPUT_TYPE_CAMERA;
  513. if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
  514. strcpy(vi->name, "Yellow Video Input");
  515. } else {
  516. strcpy(vi->name, "S-Video Input");
  517. }
  518. vi->std = V4L2_STD_PAL;
  519. break;
  520. case 3:
  521. vi->type = V4L2_INPUT_TYPE_CAMERA;
  522. strcpy(vi->name, "Red Video Input");
  523. vi->std = V4L2_STD_PAL;
  524. break;
  525. }
  526. return 0;
  527. }
  528. static int vidioc_g_input (struct file *file, void *priv, unsigned int *input)
  529. {
  530. struct usb_usbvision *usbvision = video_drvdata(file);
  531. *input = usbvision->ctl_input;
  532. return 0;
  533. }
  534. static int vidioc_s_input (struct file *file, void *priv, unsigned int input)
  535. {
  536. struct usb_usbvision *usbvision = video_drvdata(file);
  537. if ((input >= usbvision->video_inputs) || (input < 0) )
  538. return -EINVAL;
  539. mutex_lock(&usbvision->lock);
  540. usbvision_muxsel(usbvision, input);
  541. usbvision_set_input(usbvision);
  542. usbvision_set_output(usbvision,
  543. usbvision->curwidth,
  544. usbvision->curheight);
  545. mutex_unlock(&usbvision->lock);
  546. return 0;
  547. }
  548. static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id)
  549. {
  550. struct usb_usbvision *usbvision = video_drvdata(file);
  551. usbvision->tvnormId=*id;
  552. mutex_lock(&usbvision->lock);
  553. call_all(usbvision, core, s_std, usbvision->tvnormId);
  554. mutex_unlock(&usbvision->lock);
  555. /* propagate the change to the decoder */
  556. usbvision_muxsel(usbvision, usbvision->ctl_input);
  557. return 0;
  558. }
  559. static int vidioc_g_tuner (struct file *file, void *priv,
  560. struct v4l2_tuner *vt)
  561. {
  562. struct usb_usbvision *usbvision = video_drvdata(file);
  563. if (!usbvision->have_tuner || vt->index) // Only tuner 0
  564. return -EINVAL;
  565. if(usbvision->radio) {
  566. strcpy(vt->name, "Radio");
  567. vt->type = V4L2_TUNER_RADIO;
  568. } else {
  569. strcpy(vt->name, "Television");
  570. }
  571. /* Let clients fill in the remainder of this struct */
  572. call_all(usbvision, tuner, g_tuner, vt);
  573. return 0;
  574. }
  575. static int vidioc_s_tuner (struct file *file, void *priv,
  576. struct v4l2_tuner *vt)
  577. {
  578. struct usb_usbvision *usbvision = video_drvdata(file);
  579. // Only no or one tuner for now
  580. if (!usbvision->have_tuner || vt->index)
  581. return -EINVAL;
  582. /* let clients handle this */
  583. call_all(usbvision, tuner, s_tuner, vt);
  584. return 0;
  585. }
  586. static int vidioc_g_frequency (struct file *file, void *priv,
  587. struct v4l2_frequency *freq)
  588. {
  589. struct usb_usbvision *usbvision = video_drvdata(file);
  590. freq->tuner = 0; // Only one tuner
  591. if(usbvision->radio) {
  592. freq->type = V4L2_TUNER_RADIO;
  593. } else {
  594. freq->type = V4L2_TUNER_ANALOG_TV;
  595. }
  596. freq->frequency = usbvision->freq;
  597. return 0;
  598. }
  599. static int vidioc_s_frequency (struct file *file, void *priv,
  600. struct v4l2_frequency *freq)
  601. {
  602. struct usb_usbvision *usbvision = video_drvdata(file);
  603. // Only no or one tuner for now
  604. if (!usbvision->have_tuner || freq->tuner)
  605. return -EINVAL;
  606. usbvision->freq = freq->frequency;
  607. call_all(usbvision, tuner, s_frequency, freq);
  608. return 0;
  609. }
  610. static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
  611. {
  612. struct usb_usbvision *usbvision = video_drvdata(file);
  613. if(usbvision->radio) {
  614. strcpy(a->name,"Radio");
  615. } else {
  616. strcpy(a->name, "TV");
  617. }
  618. return 0;
  619. }
  620. static int vidioc_s_audio (struct file *file, void *fh,
  621. struct v4l2_audio *a)
  622. {
  623. if(a->index) {
  624. return -EINVAL;
  625. }
  626. return 0;
  627. }
  628. static int vidioc_queryctrl (struct file *file, void *priv,
  629. struct v4l2_queryctrl *ctrl)
  630. {
  631. struct usb_usbvision *usbvision = video_drvdata(file);
  632. call_all(usbvision, core, queryctrl, ctrl);
  633. if (!ctrl->type)
  634. return -EINVAL;
  635. return 0;
  636. }
  637. static int vidioc_g_ctrl (struct file *file, void *priv,
  638. struct v4l2_control *ctrl)
  639. {
  640. struct usb_usbvision *usbvision = video_drvdata(file);
  641. call_all(usbvision, core, g_ctrl, ctrl);
  642. return 0;
  643. }
  644. static int vidioc_s_ctrl (struct file *file, void *priv,
  645. struct v4l2_control *ctrl)
  646. {
  647. struct usb_usbvision *usbvision = video_drvdata(file);
  648. call_all(usbvision, core, s_ctrl, ctrl);
  649. return 0;
  650. }
  651. static int vidioc_reqbufs (struct file *file,
  652. void *priv, struct v4l2_requestbuffers *vr)
  653. {
  654. struct usb_usbvision *usbvision = video_drvdata(file);
  655. int ret;
  656. RESTRICT_TO_RANGE(vr->count,1,USBVISION_NUMFRAMES);
  657. /* Check input validity:
  658. the user must do a VIDEO CAPTURE and MMAP method. */
  659. if (vr->memory != V4L2_MEMORY_MMAP)
  660. return -EINVAL;
  661. if(usbvision->streaming == Stream_On) {
  662. if ((ret = usbvision_stream_interrupt(usbvision)))
  663. return ret;
  664. }
  665. usbvision_frames_free(usbvision);
  666. usbvision_empty_framequeues(usbvision);
  667. vr->count = usbvision_frames_alloc(usbvision,vr->count);
  668. usbvision->curFrame = NULL;
  669. return 0;
  670. }
  671. static int vidioc_querybuf (struct file *file,
  672. void *priv, struct v4l2_buffer *vb)
  673. {
  674. struct usb_usbvision *usbvision = video_drvdata(file);
  675. struct usbvision_frame *frame;
  676. /* FIXME : must control
  677. that buffers are mapped (VIDIOC_REQBUFS has been called) */
  678. if(vb->index>=usbvision->num_frames) {
  679. return -EINVAL;
  680. }
  681. /* Updating the corresponding frame state */
  682. vb->flags = 0;
  683. frame = &usbvision->frame[vb->index];
  684. if(frame->grabstate >= FrameState_Ready)
  685. vb->flags |= V4L2_BUF_FLAG_QUEUED;
  686. if(frame->grabstate >= FrameState_Done)
  687. vb->flags |= V4L2_BUF_FLAG_DONE;
  688. if(frame->grabstate == FrameState_Unused)
  689. vb->flags |= V4L2_BUF_FLAG_MAPPED;
  690. vb->memory = V4L2_MEMORY_MMAP;
  691. vb->m.offset = vb->index*PAGE_ALIGN(usbvision->max_frame_size);
  692. vb->memory = V4L2_MEMORY_MMAP;
  693. vb->field = V4L2_FIELD_NONE;
  694. vb->length = usbvision->curwidth*
  695. usbvision->curheight*
  696. usbvision->palette.bytes_per_pixel;
  697. vb->timestamp = usbvision->frame[vb->index].timestamp;
  698. vb->sequence = usbvision->frame[vb->index].sequence;
  699. return 0;
  700. }
  701. static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
  702. {
  703. struct usb_usbvision *usbvision = video_drvdata(file);
  704. struct usbvision_frame *frame;
  705. unsigned long lock_flags;
  706. /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */
  707. if(vb->index>=usbvision->num_frames) {
  708. return -EINVAL;
  709. }
  710. frame = &usbvision->frame[vb->index];
  711. if (frame->grabstate != FrameState_Unused) {
  712. return -EAGAIN;
  713. }
  714. /* Mark it as ready and enqueue frame */
  715. frame->grabstate = FrameState_Ready;
  716. frame->scanstate = ScanState_Scanning;
  717. frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */
  718. vb->flags &= ~V4L2_BUF_FLAG_DONE;
  719. /* set v4l2_format index */
  720. frame->v4l2_format = usbvision->palette;
  721. spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
  722. list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue);
  723. spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
  724. return 0;
  725. }
  726. static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
  727. {
  728. struct usb_usbvision *usbvision = video_drvdata(file);
  729. int ret;
  730. struct usbvision_frame *f;
  731. unsigned long lock_flags;
  732. if (list_empty(&(usbvision->outqueue))) {
  733. if (usbvision->streaming == Stream_Idle)
  734. return -EINVAL;
  735. ret = wait_event_interruptible
  736. (usbvision->wait_frame,
  737. !list_empty(&(usbvision->outqueue)));
  738. if (ret)
  739. return ret;
  740. }
  741. spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
  742. f = list_entry(usbvision->outqueue.next,
  743. struct usbvision_frame, frame);
  744. list_del(usbvision->outqueue.next);
  745. spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
  746. f->grabstate = FrameState_Unused;
  747. vb->memory = V4L2_MEMORY_MMAP;
  748. vb->flags = V4L2_BUF_FLAG_MAPPED |
  749. V4L2_BUF_FLAG_QUEUED |
  750. V4L2_BUF_FLAG_DONE;
  751. vb->index = f->index;
  752. vb->sequence = f->sequence;
  753. vb->timestamp = f->timestamp;
  754. vb->field = V4L2_FIELD_NONE;
  755. vb->bytesused = f->scanlength;
  756. return 0;
  757. }
  758. static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
  759. {
  760. struct usb_usbvision *usbvision = video_drvdata(file);
  761. usbvision->streaming = Stream_On;
  762. call_all(usbvision, video, s_stream, 1);
  763. return 0;
  764. }
  765. static int vidioc_streamoff(struct file *file,
  766. void *priv, enum v4l2_buf_type type)
  767. {
  768. struct usb_usbvision *usbvision = video_drvdata(file);
  769. if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  770. return -EINVAL;
  771. if(usbvision->streaming == Stream_On) {
  772. usbvision_stream_interrupt(usbvision);
  773. /* Stop all video streamings */
  774. call_all(usbvision, video, s_stream, 0);
  775. }
  776. usbvision_empty_framequeues(usbvision);
  777. return 0;
  778. }
  779. static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
  780. struct v4l2_fmtdesc *vfd)
  781. {
  782. if(vfd->index>=USBVISION_SUPPORTED_PALETTES-1) {
  783. return -EINVAL;
  784. }
  785. strcpy(vfd->description,usbvision_v4l2_format[vfd->index].desc);
  786. vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
  787. return 0;
  788. }
  789. static int vidioc_g_fmt_vid_cap (struct file *file, void *priv,
  790. struct v4l2_format *vf)
  791. {
  792. struct usb_usbvision *usbvision = video_drvdata(file);
  793. vf->fmt.pix.width = usbvision->curwidth;
  794. vf->fmt.pix.height = usbvision->curheight;
  795. vf->fmt.pix.pixelformat = usbvision->palette.format;
  796. vf->fmt.pix.bytesperline =
  797. usbvision->curwidth*usbvision->palette.bytes_per_pixel;
  798. vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*usbvision->curheight;
  799. vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  800. vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */
  801. return 0;
  802. }
  803. static int vidioc_try_fmt_vid_cap (struct file *file, void *priv,
  804. struct v4l2_format *vf)
  805. {
  806. struct usb_usbvision *usbvision = video_drvdata(file);
  807. int formatIdx;
  808. /* Find requested format in available ones */
  809. for(formatIdx=0;formatIdx<USBVISION_SUPPORTED_PALETTES;formatIdx++) {
  810. if(vf->fmt.pix.pixelformat ==
  811. usbvision_v4l2_format[formatIdx].format) {
  812. usbvision->palette = usbvision_v4l2_format[formatIdx];
  813. break;
  814. }
  815. }
  816. /* robustness */
  817. if(formatIdx == USBVISION_SUPPORTED_PALETTES) {
  818. return -EINVAL;
  819. }
  820. RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
  821. RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
  822. vf->fmt.pix.bytesperline = vf->fmt.pix.width*
  823. usbvision->palette.bytes_per_pixel;
  824. vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
  825. return 0;
  826. }
  827. static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  828. struct v4l2_format *vf)
  829. {
  830. struct usb_usbvision *usbvision = video_drvdata(file);
  831. int ret;
  832. if( 0 != (ret=vidioc_try_fmt_vid_cap (file, priv, vf)) ) {
  833. return ret;
  834. }
  835. /* stop io in case it is already in progress */
  836. if(usbvision->streaming == Stream_On) {
  837. if ((ret = usbvision_stream_interrupt(usbvision)))
  838. return ret;
  839. }
  840. usbvision_frames_free(usbvision);
  841. usbvision_empty_framequeues(usbvision);
  842. usbvision->curFrame = NULL;
  843. /* by now we are committed to the new data... */
  844. mutex_lock(&usbvision->lock);
  845. usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
  846. mutex_unlock(&usbvision->lock);
  847. return 0;
  848. }
  849. static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
  850. size_t count, loff_t *ppos)
  851. {
  852. struct usb_usbvision *usbvision = video_drvdata(file);
  853. int noblock = file->f_flags & O_NONBLOCK;
  854. unsigned long lock_flags;
  855. int ret,i;
  856. struct usbvision_frame *frame;
  857. PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__,
  858. (unsigned long)count, noblock);
  859. if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL))
  860. return -EFAULT;
  861. /* This entry point is compatible with the mmap routines
  862. so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF
  863. to get frames or call read on the device. */
  864. if(!usbvision->num_frames) {
  865. /* First, allocate some frames to work with
  866. if this has not been done with VIDIOC_REQBUF */
  867. usbvision_frames_free(usbvision);
  868. usbvision_empty_framequeues(usbvision);
  869. usbvision_frames_alloc(usbvision,USBVISION_NUMFRAMES);
  870. }
  871. if(usbvision->streaming != Stream_On) {
  872. /* no stream is running, make it running ! */
  873. usbvision->streaming = Stream_On;
  874. call_all(usbvision, video, s_stream, 1);
  875. }
  876. /* Then, enqueue as many frames as possible
  877. (like a user of VIDIOC_QBUF would do) */
  878. for(i=0;i<usbvision->num_frames;i++) {
  879. frame = &usbvision->frame[i];
  880. if(frame->grabstate == FrameState_Unused) {
  881. /* Mark it as ready and enqueue frame */
  882. frame->grabstate = FrameState_Ready;
  883. frame->scanstate = ScanState_Scanning;
  884. /* Accumulated in usbvision_parse_data() */
  885. frame->scanlength = 0;
  886. /* set v4l2_format index */
  887. frame->v4l2_format = usbvision->palette;
  888. spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
  889. list_add_tail(&frame->frame, &usbvision->inqueue);
  890. spin_unlock_irqrestore(&usbvision->queue_lock,
  891. lock_flags);
  892. }
  893. }
  894. /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */
  895. if (list_empty(&(usbvision->outqueue))) {
  896. if(noblock)
  897. return -EAGAIN;
  898. ret = wait_event_interruptible
  899. (usbvision->wait_frame,
  900. !list_empty(&(usbvision->outqueue)));
  901. if (ret)
  902. return ret;
  903. }
  904. spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
  905. frame = list_entry(usbvision->outqueue.next,
  906. struct usbvision_frame, frame);
  907. list_del(usbvision->outqueue.next);
  908. spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
  909. /* An error returns an empty frame */
  910. if (frame->grabstate == FrameState_Error) {
  911. frame->bytes_read = 0;
  912. return 0;
  913. }
  914. PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld",
  915. __func__,
  916. frame->index, frame->bytes_read, frame->scanlength);
  917. /* copy bytes to user space; we allow for partials reads */
  918. if ((count + frame->bytes_read) > (unsigned long)frame->scanlength)
  919. count = frame->scanlength - frame->bytes_read;
  920. if (copy_to_user(buf, frame->data + frame->bytes_read, count)) {
  921. return -EFAULT;
  922. }
  923. frame->bytes_read += count;
  924. PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld",
  925. __func__,
  926. (unsigned long)count, frame->bytes_read);
  927. /* For now, forget the frame if it has not been read in one shot. */
  928. /* if (frame->bytes_read >= frame->scanlength) {// All data has been read */
  929. frame->bytes_read = 0;
  930. /* Mark it as available to be used again. */
  931. frame->grabstate = FrameState_Unused;
  932. /* } */
  933. return count;
  934. }
  935. static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
  936. {
  937. unsigned long size = vma->vm_end - vma->vm_start,
  938. start = vma->vm_start;
  939. void *pos;
  940. u32 i;
  941. struct usb_usbvision *usbvision = video_drvdata(file);
  942. PDEBUG(DBG_MMAP, "mmap");
  943. mutex_lock(&usbvision->lock);
  944. if (!USBVISION_IS_OPERATIONAL(usbvision)) {
  945. mutex_unlock(&usbvision->lock);
  946. return -EFAULT;
  947. }
  948. if (!(vma->vm_flags & VM_WRITE) ||
  949. size != PAGE_ALIGN(usbvision->max_frame_size)) {
  950. mutex_unlock(&usbvision->lock);
  951. return -EINVAL;
  952. }
  953. for (i = 0; i < usbvision->num_frames; i++) {
  954. if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) ==
  955. vma->vm_pgoff)
  956. break;
  957. }
  958. if (i == usbvision->num_frames) {
  959. PDEBUG(DBG_MMAP,
  960. "mmap: user supplied mapping address is out of range");
  961. mutex_unlock(&usbvision->lock);
  962. return -EINVAL;
  963. }
  964. /* VM_IO is eventually going to replace PageReserved altogether */
  965. vma->vm_flags |= VM_IO;
  966. vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */
  967. pos = usbvision->frame[i].data;
  968. while (size > 0) {
  969. if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
  970. PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed");
  971. mutex_unlock(&usbvision->lock);
  972. return -EAGAIN;
  973. }
  974. start += PAGE_SIZE;
  975. pos += PAGE_SIZE;
  976. size -= PAGE_SIZE;
  977. }
  978. mutex_unlock(&usbvision->lock);
  979. return 0;
  980. }
  981. /*
  982. * Here comes the stuff for radio on usbvision based devices
  983. *
  984. */
  985. static int usbvision_radio_open(struct file *file)
  986. {
  987. struct usb_usbvision *usbvision = video_drvdata(file);
  988. int errCode = 0;
  989. PDEBUG(DBG_IO, "%s:", __func__);
  990. mutex_lock(&usbvision->lock);
  991. if (usbvision->user) {
  992. dev_err(&usbvision->rdev->dev,
  993. "%s: Someone tried to open an already opened USBVision Radio!\n",
  994. __func__);
  995. errCode = -EBUSY;
  996. }
  997. else {
  998. if(PowerOnAtOpen) {
  999. usbvision_reset_powerOffTimer(usbvision);
  1000. if (usbvision->power == 0) {
  1001. usbvision_power_on(usbvision);
  1002. usbvision_i2c_register(usbvision);
  1003. }
  1004. }
  1005. /* Alternate interface 1 is is the biggest frame size */
  1006. errCode = usbvision_set_alternate(usbvision);
  1007. if (errCode < 0) {
  1008. usbvision->last_error = errCode;
  1009. errCode = -EBUSY;
  1010. goto out;
  1011. }
  1012. // If so far no errors then we shall start the radio
  1013. usbvision->radio = 1;
  1014. call_all(usbvision, tuner, s_radio);
  1015. usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO);
  1016. usbvision->user++;
  1017. }
  1018. if (errCode) {
  1019. if (PowerOnAtOpen) {
  1020. usbvision_i2c_unregister(usbvision);
  1021. usbvision_power_off(usbvision);
  1022. usbvision->initialized = 0;
  1023. }
  1024. }
  1025. out:
  1026. mutex_unlock(&usbvision->lock);
  1027. return errCode;
  1028. }
  1029. static int usbvision_radio_close(struct file *file)
  1030. {
  1031. struct usb_usbvision *usbvision = video_drvdata(file);
  1032. int errCode = 0;
  1033. PDEBUG(DBG_IO, "");
  1034. mutex_lock(&usbvision->lock);
  1035. /* Set packet size to 0 */
  1036. usbvision->ifaceAlt=0;
  1037. errCode = usb_set_interface(usbvision->dev, usbvision->iface,
  1038. usbvision->ifaceAlt);
  1039. usbvision_audio_off(usbvision);
  1040. usbvision->radio=0;
  1041. usbvision->user--;
  1042. if (PowerOnAtOpen) {
  1043. usbvision_set_powerOffTimer(usbvision);
  1044. usbvision->initialized = 0;
  1045. }
  1046. mutex_unlock(&usbvision->lock);
  1047. if (usbvision->remove_pending) {
  1048. printk(KERN_INFO "%s: Final disconnect\n", __func__);
  1049. usbvision_release(usbvision);
  1050. }
  1051. PDEBUG(DBG_IO, "success");
  1052. return errCode;
  1053. }
  1054. /*
  1055. * Here comes the stuff for vbi on usbvision based devices
  1056. *
  1057. */
  1058. static int usbvision_vbi_open(struct file *file)
  1059. {
  1060. /* TODO */
  1061. return -ENODEV;
  1062. }
  1063. static int usbvision_vbi_close(struct file *file)
  1064. {
  1065. /* TODO */
  1066. return -ENODEV;
  1067. }
  1068. static long usbvision_do_vbi_ioctl(struct file *file,
  1069. unsigned int cmd, void *arg)
  1070. {
  1071. /* TODO */
  1072. return -ENOIOCTLCMD;
  1073. }
  1074. static long usbvision_vbi_ioctl(struct file *file,
  1075. unsigned int cmd, unsigned long arg)
  1076. {
  1077. return video_usercopy(file, cmd, arg, usbvision_do_vbi_ioctl);
  1078. }
  1079. //
  1080. // Video registration stuff
  1081. //
  1082. // Video template
  1083. static const struct v4l2_file_operations usbvision_fops = {
  1084. .owner = THIS_MODULE,
  1085. .open = usbvision_v4l2_open,
  1086. .release = usbvision_v4l2_close,
  1087. .read = usbvision_v4l2_read,
  1088. .mmap = usbvision_v4l2_mmap,
  1089. .ioctl = video_ioctl2,
  1090. /* .poll = video_poll, */
  1091. };
  1092. static const struct v4l2_ioctl_ops usbvision_ioctl_ops = {
  1093. .vidioc_querycap = vidioc_querycap,
  1094. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  1095. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  1096. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  1097. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  1098. .vidioc_reqbufs = vidioc_reqbufs,
  1099. .vidioc_querybuf = vidioc_querybuf,
  1100. .vidioc_qbuf = vidioc_qbuf,
  1101. .vidioc_dqbuf = vidioc_dqbuf,
  1102. .vidioc_s_std = vidioc_s_std,
  1103. .vidioc_enum_input = vidioc_enum_input,
  1104. .vidioc_g_input = vidioc_g_input,
  1105. .vidioc_s_input = vidioc_s_input,
  1106. .vidioc_queryctrl = vidioc_queryctrl,
  1107. .vidioc_g_audio = vidioc_g_audio,
  1108. .vidioc_s_audio = vidioc_s_audio,
  1109. .vidioc_g_ctrl = vidioc_g_ctrl,
  1110. .vidioc_s_ctrl = vidioc_s_ctrl,
  1111. .vidioc_streamon = vidioc_streamon,
  1112. .vidioc_streamoff = vidioc_streamoff,
  1113. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  1114. /* .vidiocgmbuf = vidiocgmbuf, */
  1115. #endif
  1116. .vidioc_g_tuner = vidioc_g_tuner,
  1117. .vidioc_s_tuner = vidioc_s_tuner,
  1118. .vidioc_g_frequency = vidioc_g_frequency,
  1119. .vidioc_s_frequency = vidioc_s_frequency,
  1120. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1121. .vidioc_g_register = vidioc_g_register,
  1122. .vidioc_s_register = vidioc_s_register,
  1123. #endif
  1124. };
  1125. static struct video_device usbvision_video_template = {
  1126. .fops = &usbvision_fops,
  1127. .ioctl_ops = &usbvision_ioctl_ops,
  1128. .name = "usbvision-video",
  1129. .release = video_device_release,
  1130. .minor = -1,
  1131. .tvnorms = USBVISION_NORMS,
  1132. .current_norm = V4L2_STD_PAL
  1133. };
  1134. // Radio template
  1135. static const struct v4l2_file_operations usbvision_radio_fops = {
  1136. .owner = THIS_MODULE,
  1137. .open = usbvision_radio_open,
  1138. .release = usbvision_radio_close,
  1139. .ioctl = video_ioctl2,
  1140. };
  1141. static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = {
  1142. .vidioc_querycap = vidioc_querycap,
  1143. .vidioc_enum_input = vidioc_enum_input,
  1144. .vidioc_g_input = vidioc_g_input,
  1145. .vidioc_s_input = vidioc_s_input,
  1146. .vidioc_queryctrl = vidioc_queryctrl,
  1147. .vidioc_g_audio = vidioc_g_audio,
  1148. .vidioc_s_audio = vidioc_s_audio,
  1149. .vidioc_g_ctrl = vidioc_g_ctrl,
  1150. .vidioc_s_ctrl = vidioc_s_ctrl,
  1151. .vidioc_g_tuner = vidioc_g_tuner,
  1152. .vidioc_s_tuner = vidioc_s_tuner,
  1153. .vidioc_g_frequency = vidioc_g_frequency,
  1154. .vidioc_s_frequency = vidioc_s_frequency,
  1155. };
  1156. static struct video_device usbvision_radio_template = {
  1157. .fops = &usbvision_radio_fops,
  1158. .name = "usbvision-radio",
  1159. .release = video_device_release,
  1160. .minor = -1,
  1161. .ioctl_ops = &usbvision_radio_ioctl_ops,
  1162. .tvnorms = USBVISION_NORMS,
  1163. .current_norm = V4L2_STD_PAL
  1164. };
  1165. // vbi template
  1166. static const struct v4l2_file_operations usbvision_vbi_fops = {
  1167. .owner = THIS_MODULE,
  1168. .open = usbvision_vbi_open,
  1169. .release = usbvision_vbi_close,
  1170. .ioctl = usbvision_vbi_ioctl,
  1171. };
  1172. static struct video_device usbvision_vbi_template=
  1173. {
  1174. .fops = &usbvision_vbi_fops,
  1175. .release = video_device_release,
  1176. .name = "usbvision-vbi",
  1177. .minor = -1,
  1178. };
  1179. static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
  1180. struct video_device *vdev_template,
  1181. char *name)
  1182. {
  1183. struct usb_device *usb_dev = usbvision->dev;
  1184. struct video_device *vdev;
  1185. if (usb_dev == NULL) {
  1186. dev_err(&usbvision->dev->dev,
  1187. "%s: usbvision->dev is not set\n", __func__);
  1188. return NULL;
  1189. }
  1190. vdev = video_device_alloc();
  1191. if (NULL == vdev) {
  1192. return NULL;
  1193. }
  1194. *vdev = *vdev_template;
  1195. // vdev->minor = -1;
  1196. vdev->v4l2_dev = &usbvision->v4l2_dev;
  1197. snprintf(vdev->name, sizeof(vdev->name), "%s", name);
  1198. video_set_drvdata(vdev, usbvision);
  1199. return vdev;
  1200. }
  1201. // unregister video4linux devices
  1202. static void usbvision_unregister_video(struct usb_usbvision *usbvision)
  1203. {
  1204. // vbi Device:
  1205. if (usbvision->vbi) {
  1206. PDEBUG(DBG_PROBE, "unregister /dev/vbi%d [v4l2]",
  1207. usbvision->vbi->num);
  1208. if (usbvision->vbi->minor != -1) {
  1209. video_unregister_device(usbvision->vbi);
  1210. } else {
  1211. video_device_release(usbvision->vbi);
  1212. }
  1213. usbvision->vbi = NULL;
  1214. }
  1215. // Radio Device:
  1216. if (usbvision->rdev) {
  1217. PDEBUG(DBG_PROBE, "unregister /dev/radio%d [v4l2]",
  1218. usbvision->rdev->num);
  1219. if (usbvision->rdev->minor != -1) {
  1220. video_unregister_device(usbvision->rdev);
  1221. } else {
  1222. video_device_release(usbvision->rdev);
  1223. }
  1224. usbvision->rdev = NULL;
  1225. }
  1226. // Video Device:
  1227. if (usbvision->vdev) {
  1228. PDEBUG(DBG_PROBE, "unregister /dev/video%d [v4l2]",
  1229. usbvision->vdev->num);
  1230. if (usbvision->vdev->minor != -1) {
  1231. video_unregister_device(usbvision->vdev);
  1232. } else {
  1233. video_device_release(usbvision->vdev);
  1234. }
  1235. usbvision->vdev = NULL;
  1236. }
  1237. }
  1238. // register video4linux devices
  1239. static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
  1240. {
  1241. // Video Device:
  1242. usbvision->vdev = usbvision_vdev_init(usbvision,
  1243. &usbvision_video_template,
  1244. "USBVision Video");
  1245. if (usbvision->vdev == NULL) {
  1246. goto err_exit;
  1247. }
  1248. if (video_register_device(usbvision->vdev,
  1249. VFL_TYPE_GRABBER,
  1250. video_nr)<0) {
  1251. goto err_exit;
  1252. }
  1253. printk(KERN_INFO "USBVision[%d]: registered USBVision Video device /dev/video%d [v4l2]\n",
  1254. usbvision->nr, usbvision->vdev->num);
  1255. // Radio Device:
  1256. if (usbvision_device_data[usbvision->DevModel].Radio) {
  1257. // usbvision has radio
  1258. usbvision->rdev = usbvision_vdev_init(usbvision,
  1259. &usbvision_radio_template,
  1260. "USBVision Radio");
  1261. if (usbvision->rdev == NULL) {
  1262. goto err_exit;
  1263. }
  1264. if (video_register_device(usbvision->rdev,
  1265. VFL_TYPE_RADIO,
  1266. radio_nr)<0) {
  1267. goto err_exit;
  1268. }
  1269. printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device /dev/radio%d [v4l2]\n",
  1270. usbvision->nr, usbvision->rdev->num);
  1271. }
  1272. // vbi Device:
  1273. if (usbvision_device_data[usbvision->DevModel].vbi) {
  1274. usbvision->vbi = usbvision_vdev_init(usbvision,
  1275. &usbvision_vbi_template,
  1276. "USBVision VBI");
  1277. if (usbvision->vdev == NULL) {
  1278. goto err_exit;
  1279. }
  1280. if (video_register_device(usbvision->vbi,
  1281. VFL_TYPE_VBI,
  1282. vbi_nr)<0) {
  1283. goto err_exit;
  1284. }
  1285. printk(KERN_INFO "USBVision[%d]: registered USBVision VBI device /dev/vbi%d [v4l2] (Not Working Yet!)\n",
  1286. usbvision->nr, usbvision->vbi->num);
  1287. }
  1288. // all done
  1289. return 0;
  1290. err_exit:
  1291. dev_err(&usbvision->dev->dev,
  1292. "USBVision[%d]: video_register_device() failed\n",
  1293. usbvision->nr);
  1294. usbvision_unregister_video(usbvision);
  1295. return -1;
  1296. }
  1297. /*
  1298. * usbvision_alloc()
  1299. *
  1300. * This code allocates the struct usb_usbvision.
  1301. * It is filled with default values.
  1302. *
  1303. * Returns NULL on error, a pointer to usb_usbvision else.
  1304. *
  1305. */
  1306. static struct usb_usbvision *usbvision_alloc(struct usb_device *dev,
  1307. struct usb_interface *intf)
  1308. {
  1309. struct usb_usbvision *usbvision;
  1310. usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL);
  1311. if (usbvision == NULL)
  1312. return NULL;
  1313. usbvision->dev = dev;
  1314. if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev))
  1315. goto err_free;
  1316. mutex_init(&usbvision->lock); /* available */
  1317. // prepare control urb for control messages during interrupts
  1318. usbvision->ctrlUrb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
  1319. if (usbvision->ctrlUrb == NULL)
  1320. goto err_unreg;
  1321. init_waitqueue_head(&usbvision->ctrlUrb_wq);
  1322. usbvision_init_powerOffTimer(usbvision);
  1323. return usbvision;
  1324. err_unreg:
  1325. v4l2_device_unregister(&usbvision->v4l2_dev);
  1326. err_free:
  1327. kfree(usbvision);
  1328. return NULL;
  1329. }
  1330. /*
  1331. * usbvision_release()
  1332. *
  1333. * This code does final release of struct usb_usbvision. This happens
  1334. * after the device is disconnected -and- all clients closed their files.
  1335. *
  1336. */
  1337. static void usbvision_release(struct usb_usbvision *usbvision)
  1338. {
  1339. PDEBUG(DBG_PROBE, "");
  1340. mutex_lock(&usbvision->lock);
  1341. usbvision_reset_powerOffTimer(usbvision);
  1342. usbvision->initialized = 0;
  1343. mutex_unlock(&usbvision->lock);
  1344. usbvision_remove_sysfs(usbvision->vdev);
  1345. usbvision_unregister_video(usbvision);
  1346. if (usbvision->ctrlUrb) {
  1347. usb_free_urb(usbvision->ctrlUrb);
  1348. }
  1349. v4l2_device_unregister(&usbvision->v4l2_dev);
  1350. kfree(usbvision);
  1351. PDEBUG(DBG_PROBE, "success");
  1352. }
  1353. /*********************** usb interface **********************************/
  1354. static void usbvision_configure_video(struct usb_usbvision *usbvision)
  1355. {
  1356. int model;
  1357. if (usbvision == NULL)
  1358. return;
  1359. model = usbvision->DevModel;
  1360. usbvision->palette = usbvision_v4l2_format[2]; // V4L2_PIX_FMT_RGB24;
  1361. if (usbvision_device_data[usbvision->DevModel].Vin_Reg2_override) {
  1362. usbvision->Vin_Reg2_Preset =
  1363. usbvision_device_data[usbvision->DevModel].Vin_Reg2;
  1364. } else {
  1365. usbvision->Vin_Reg2_Preset = 0;
  1366. }
  1367. usbvision->tvnormId = usbvision_device_data[model].VideoNorm;
  1368. usbvision->video_inputs = usbvision_device_data[model].VideoChannels;
  1369. usbvision->ctl_input = 0;
  1370. /* This should be here to make i2c clients to be able to register */
  1371. /* first switch off audio */
  1372. usbvision_audio_off(usbvision);
  1373. if (!PowerOnAtOpen) {
  1374. /* and then power up the noisy tuner */
  1375. usbvision_power_on(usbvision);
  1376. usbvision_i2c_register(usbvision);
  1377. }
  1378. }
  1379. /*
  1380. * usbvision_probe()
  1381. *
  1382. * This procedure queries device descriptor and accepts the interface
  1383. * if it looks like USBVISION video device
  1384. *
  1385. */
  1386. static int __devinit usbvision_probe(struct usb_interface *intf,
  1387. const struct usb_device_id *devid)
  1388. {
  1389. struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf));
  1390. struct usb_interface *uif;
  1391. __u8 ifnum = intf->altsetting->desc.bInterfaceNumber;
  1392. const struct usb_host_interface *interface;
  1393. struct usb_usbvision *usbvision = NULL;
  1394. const struct usb_endpoint_descriptor *endpoint;
  1395. int model,i;
  1396. PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u",
  1397. dev->descriptor.idVendor,
  1398. dev->descriptor.idProduct, ifnum);
  1399. model = devid->driver_info;
  1400. if ( (model<0) || (model>=usbvision_device_data_size) ) {
  1401. PDEBUG(DBG_PROBE, "model out of bounds %d",model);
  1402. return -ENODEV;
  1403. }
  1404. printk(KERN_INFO "%s: %s found\n", __func__,
  1405. usbvision_device_data[model].ModelString);
  1406. if (usbvision_device_data[model].Interface >= 0) {
  1407. interface = &dev->actconfig->interface[usbvision_device_data[model].Interface]->altsetting[0];
  1408. } else {
  1409. interface = &dev->actconfig->interface[ifnum]->altsetting[0];
  1410. }
  1411. endpoint = &interface->endpoint[1].desc;
  1412. if (!usb_endpoint_xfer_isoc(endpoint)) {
  1413. dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n",
  1414. __func__, ifnum);
  1415. dev_err(&intf->dev, "%s: Endpoint attributes %d",
  1416. __func__, endpoint->bmAttributes);
  1417. return -ENODEV;
  1418. }
  1419. if (usb_endpoint_dir_out(endpoint)) {
  1420. dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n",
  1421. __func__, ifnum);
  1422. return -ENODEV;
  1423. }
  1424. usbvision = usbvision_alloc(dev, intf);
  1425. if (usbvision == NULL) {
  1426. dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__);
  1427. return -ENOMEM;
  1428. }
  1429. if (dev->descriptor.bNumConfigurations > 1) {
  1430. usbvision->bridgeType = BRIDGE_NT1004;
  1431. } else if (model == DAZZLE_DVC_90_REV_1_SECAM) {
  1432. usbvision->bridgeType = BRIDGE_NT1005;
  1433. } else {
  1434. usbvision->bridgeType = BRIDGE_NT1003;
  1435. }
  1436. PDEBUG(DBG_PROBE, "bridgeType %d", usbvision->bridgeType);
  1437. mutex_lock(&usbvision->lock);
  1438. /* compute alternate max packet sizes */
  1439. uif = dev->actconfig->interface[0];
  1440. usbvision->num_alt=uif->num_altsetting;
  1441. PDEBUG(DBG_PROBE, "Alternate settings: %i",usbvision->num_alt);
  1442. usbvision->alt_max_pkt_size = kmalloc(32*
  1443. usbvision->num_alt,GFP_KERNEL);
  1444. if (usbvision->alt_max_pkt_size == NULL) {
  1445. dev_err(&intf->dev, "usbvision: out of memory!\n");
  1446. mutex_unlock(&usbvision->lock);
  1447. return -ENOMEM;
  1448. }
  1449. for (i = 0; i < usbvision->num_alt ; i++) {
  1450. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc.
  1451. wMaxPacketSize);
  1452. usbvision->alt_max_pkt_size[i] =
  1453. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1454. PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i",i,
  1455. usbvision->alt_max_pkt_size[i]);
  1456. }
  1457. usbvision->nr = usbvision_nr++;
  1458. usbvision->have_tuner = usbvision_device_data[model].Tuner;
  1459. if (usbvision->have_tuner) {
  1460. usbvision->tuner_type = usbvision_device_data[model].TunerType;
  1461. }
  1462. usbvision->DevModel = model;
  1463. usbvision->remove_pending = 0;
  1464. usbvision->iface = ifnum;
  1465. usbvision->ifaceAlt = 0;
  1466. usbvision->video_endp = endpoint->bEndpointAddress;
  1467. usbvision->isocPacketSize = 0;
  1468. usbvision->usb_bandwidth = 0;
  1469. usbvision->user = 0;
  1470. usbvision->streaming = Stream_Off;
  1471. usbvision_register_video(usbvision);
  1472. usbvision_configure_video(usbvision);
  1473. mutex_unlock(&usbvision->lock);
  1474. usb_set_intfdata (intf, usbvision);
  1475. usbvision_create_sysfs(usbvision->vdev);
  1476. PDEBUG(DBG_PROBE, "success");
  1477. return 0;
  1478. }
  1479. /*
  1480. * usbvision_disconnect()
  1481. *
  1482. * This procedure stops all driver activity, deallocates interface-private
  1483. * structure (pointed by 'ptr') and after that driver should be removable
  1484. * with no ill consequences.
  1485. *
  1486. */
  1487. static void __devexit usbvision_disconnect(struct usb_interface *intf)
  1488. {
  1489. struct usb_usbvision *usbvision = usb_get_intfdata(intf);
  1490. PDEBUG(DBG_PROBE, "");
  1491. if (usbvision == NULL) {
  1492. dev_err(&usbvision->dev->dev,
  1493. "%s: usb_get_intfdata() failed\n", __func__);
  1494. return;
  1495. }
  1496. usb_set_intfdata (intf, NULL);
  1497. mutex_lock(&usbvision->lock);
  1498. // At this time we ask to cancel outstanding URBs
  1499. usbvision_stop_isoc(usbvision);
  1500. v4l2_device_disconnect(&usbvision->v4l2_dev);
  1501. if (usbvision->power) {
  1502. usbvision_i2c_unregister(usbvision);
  1503. usbvision_power_off(usbvision);
  1504. }
  1505. usbvision->remove_pending = 1; // Now all ISO data will be ignored
  1506. usb_put_dev(usbvision->dev);
  1507. usbvision->dev = NULL; // USB device is no more
  1508. mutex_unlock(&usbvision->lock);
  1509. if (usbvision->user) {
  1510. printk(KERN_INFO "%s: In use, disconnect pending\n",
  1511. __func__);
  1512. wake_up_interruptible(&usbvision->wait_frame);
  1513. wake_up_interruptible(&usbvision->wait_stream);
  1514. } else {
  1515. usbvision_release(usbvision);
  1516. }
  1517. PDEBUG(DBG_PROBE, "success");
  1518. }
  1519. static struct usb_driver usbvision_driver = {
  1520. .name = "usbvision",
  1521. .id_table = usbvision_table,
  1522. .probe = usbvision_probe,
  1523. .disconnect = __devexit_p(usbvision_disconnect),
  1524. };
  1525. /*
  1526. * usbvision_init()
  1527. *
  1528. * This code is run to initialize the driver.
  1529. *
  1530. */
  1531. static int __init usbvision_init(void)
  1532. {
  1533. int errCode;
  1534. PDEBUG(DBG_PROBE, "");
  1535. PDEBUG(DBG_IO, "IO debugging is enabled [video]");
  1536. PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]");
  1537. PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]");
  1538. /* disable planar mode support unless compression enabled */
  1539. if (isocMode != ISOC_MODE_COMPRESS ) {
  1540. // FIXME : not the right way to set supported flag
  1541. usbvision_v4l2_format[6].supported = 0; // V4L2_PIX_FMT_YVU420
  1542. usbvision_v4l2_format[7].supported = 0; // V4L2_PIX_FMT_YUV422P
  1543. }
  1544. errCode = usb_register(&usbvision_driver);
  1545. if (errCode == 0) {
  1546. printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n");
  1547. PDEBUG(DBG_PROBE, "success");
  1548. }
  1549. return errCode;
  1550. }
  1551. static void __exit usbvision_exit(void)
  1552. {
  1553. PDEBUG(DBG_PROBE, "");
  1554. usb_deregister(&usbvision_driver);
  1555. PDEBUG(DBG_PROBE, "success");
  1556. }
  1557. module_init(usbvision_init);
  1558. module_exit(usbvision_exit);
  1559. /*
  1560. * Overrides for Emacs so that we follow Linus's tabbing style.
  1561. * ---------------------------------------------------------------------------
  1562. * Local variables:
  1563. * c-basic-offset: 8
  1564. * End:
  1565. */