usbvision-video.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845
  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)
  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. .tvnorms = USBVISION_NORMS,
  1131. .current_norm = V4L2_STD_PAL
  1132. };
  1133. // Radio template
  1134. static const struct v4l2_file_operations usbvision_radio_fops = {
  1135. .owner = THIS_MODULE,
  1136. .open = usbvision_radio_open,
  1137. .release = usbvision_radio_close,
  1138. .ioctl = video_ioctl2,
  1139. };
  1140. static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = {
  1141. .vidioc_querycap = vidioc_querycap,
  1142. .vidioc_enum_input = vidioc_enum_input,
  1143. .vidioc_g_input = vidioc_g_input,
  1144. .vidioc_s_input = vidioc_s_input,
  1145. .vidioc_queryctrl = vidioc_queryctrl,
  1146. .vidioc_g_audio = vidioc_g_audio,
  1147. .vidioc_s_audio = vidioc_s_audio,
  1148. .vidioc_g_ctrl = vidioc_g_ctrl,
  1149. .vidioc_s_ctrl = vidioc_s_ctrl,
  1150. .vidioc_g_tuner = vidioc_g_tuner,
  1151. .vidioc_s_tuner = vidioc_s_tuner,
  1152. .vidioc_g_frequency = vidioc_g_frequency,
  1153. .vidioc_s_frequency = vidioc_s_frequency,
  1154. };
  1155. static struct video_device usbvision_radio_template = {
  1156. .fops = &usbvision_radio_fops,
  1157. .name = "usbvision-radio",
  1158. .release = video_device_release,
  1159. .ioctl_ops = &usbvision_radio_ioctl_ops,
  1160. .tvnorms = USBVISION_NORMS,
  1161. .current_norm = V4L2_STD_PAL
  1162. };
  1163. // vbi template
  1164. static const struct v4l2_file_operations usbvision_vbi_fops = {
  1165. .owner = THIS_MODULE,
  1166. .open = usbvision_vbi_open,
  1167. .release = usbvision_vbi_close,
  1168. .ioctl = usbvision_vbi_ioctl,
  1169. };
  1170. static struct video_device usbvision_vbi_template=
  1171. {
  1172. .fops = &usbvision_vbi_fops,
  1173. .release = video_device_release,
  1174. .name = "usbvision-vbi",
  1175. };
  1176. static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
  1177. struct video_device *vdev_template,
  1178. char *name)
  1179. {
  1180. struct usb_device *usb_dev = usbvision->dev;
  1181. struct video_device *vdev;
  1182. if (usb_dev == NULL) {
  1183. dev_err(&usbvision->dev->dev,
  1184. "%s: usbvision->dev is not set\n", __func__);
  1185. return NULL;
  1186. }
  1187. vdev = video_device_alloc();
  1188. if (NULL == vdev) {
  1189. return NULL;
  1190. }
  1191. *vdev = *vdev_template;
  1192. vdev->v4l2_dev = &usbvision->v4l2_dev;
  1193. snprintf(vdev->name, sizeof(vdev->name), "%s", name);
  1194. video_set_drvdata(vdev, usbvision);
  1195. return vdev;
  1196. }
  1197. // unregister video4linux devices
  1198. static void usbvision_unregister_video(struct usb_usbvision *usbvision)
  1199. {
  1200. // vbi Device:
  1201. if (usbvision->vbi) {
  1202. PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
  1203. video_device_node_name(usbvision->vbi));
  1204. if (video_is_registered(usbvision->vbi)) {
  1205. video_unregister_device(usbvision->vbi);
  1206. } else {
  1207. video_device_release(usbvision->vbi);
  1208. }
  1209. usbvision->vbi = NULL;
  1210. }
  1211. // Radio Device:
  1212. if (usbvision->rdev) {
  1213. PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
  1214. video_device_node_name(usbvision->rdev));
  1215. if (video_is_registered(usbvision->rdev)) {
  1216. video_unregister_device(usbvision->rdev);
  1217. } else {
  1218. video_device_release(usbvision->rdev);
  1219. }
  1220. usbvision->rdev = NULL;
  1221. }
  1222. // Video Device:
  1223. if (usbvision->vdev) {
  1224. PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
  1225. video_device_node_name(usbvision->vdev));
  1226. if (video_is_registered(usbvision->vdev)) {
  1227. video_unregister_device(usbvision->vdev);
  1228. } else {
  1229. video_device_release(usbvision->vdev);
  1230. }
  1231. usbvision->vdev = NULL;
  1232. }
  1233. }
  1234. // register video4linux devices
  1235. static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
  1236. {
  1237. // Video Device:
  1238. usbvision->vdev = usbvision_vdev_init(usbvision,
  1239. &usbvision_video_template,
  1240. "USBVision Video");
  1241. if (usbvision->vdev == NULL) {
  1242. goto err_exit;
  1243. }
  1244. if (video_register_device(usbvision->vdev,
  1245. VFL_TYPE_GRABBER,
  1246. video_nr)<0) {
  1247. goto err_exit;
  1248. }
  1249. printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n",
  1250. usbvision->nr, video_device_node_name(usbvision->vdev));
  1251. // Radio Device:
  1252. if (usbvision_device_data[usbvision->DevModel].Radio) {
  1253. // usbvision has radio
  1254. usbvision->rdev = usbvision_vdev_init(usbvision,
  1255. &usbvision_radio_template,
  1256. "USBVision Radio");
  1257. if (usbvision->rdev == NULL) {
  1258. goto err_exit;
  1259. }
  1260. if (video_register_device(usbvision->rdev,
  1261. VFL_TYPE_RADIO,
  1262. radio_nr)<0) {
  1263. goto err_exit;
  1264. }
  1265. printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
  1266. usbvision->nr, video_device_node_name(usbvision->rdev));
  1267. }
  1268. // vbi Device:
  1269. if (usbvision_device_data[usbvision->DevModel].vbi) {
  1270. usbvision->vbi = usbvision_vdev_init(usbvision,
  1271. &usbvision_vbi_template,
  1272. "USBVision VBI");
  1273. if (usbvision->vdev == NULL) {
  1274. goto err_exit;
  1275. }
  1276. if (video_register_device(usbvision->vbi,
  1277. VFL_TYPE_VBI,
  1278. vbi_nr)<0) {
  1279. goto err_exit;
  1280. }
  1281. printk(KERN_INFO "USBVision[%d]: registered USBVision VBI device %s [v4l2] (Not Working Yet!)\n",
  1282. usbvision->nr, video_device_node_name(usbvision->vbi));
  1283. }
  1284. // all done
  1285. return 0;
  1286. err_exit:
  1287. dev_err(&usbvision->dev->dev,
  1288. "USBVision[%d]: video_register_device() failed\n",
  1289. usbvision->nr);
  1290. usbvision_unregister_video(usbvision);
  1291. return -1;
  1292. }
  1293. /*
  1294. * usbvision_alloc()
  1295. *
  1296. * This code allocates the struct usb_usbvision.
  1297. * It is filled with default values.
  1298. *
  1299. * Returns NULL on error, a pointer to usb_usbvision else.
  1300. *
  1301. */
  1302. static struct usb_usbvision *usbvision_alloc(struct usb_device *dev,
  1303. struct usb_interface *intf)
  1304. {
  1305. struct usb_usbvision *usbvision;
  1306. usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL);
  1307. if (usbvision == NULL)
  1308. return NULL;
  1309. usbvision->dev = dev;
  1310. if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev))
  1311. goto err_free;
  1312. mutex_init(&usbvision->lock); /* available */
  1313. // prepare control urb for control messages during interrupts
  1314. usbvision->ctrlUrb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
  1315. if (usbvision->ctrlUrb == NULL)
  1316. goto err_unreg;
  1317. init_waitqueue_head(&usbvision->ctrlUrb_wq);
  1318. usbvision_init_powerOffTimer(usbvision);
  1319. return usbvision;
  1320. err_unreg:
  1321. v4l2_device_unregister(&usbvision->v4l2_dev);
  1322. err_free:
  1323. kfree(usbvision);
  1324. return NULL;
  1325. }
  1326. /*
  1327. * usbvision_release()
  1328. *
  1329. * This code does final release of struct usb_usbvision. This happens
  1330. * after the device is disconnected -and- all clients closed their files.
  1331. *
  1332. */
  1333. static void usbvision_release(struct usb_usbvision *usbvision)
  1334. {
  1335. PDEBUG(DBG_PROBE, "");
  1336. mutex_lock(&usbvision->lock);
  1337. usbvision_reset_powerOffTimer(usbvision);
  1338. usbvision->initialized = 0;
  1339. mutex_unlock(&usbvision->lock);
  1340. usbvision_remove_sysfs(usbvision->vdev);
  1341. usbvision_unregister_video(usbvision);
  1342. if (usbvision->ctrlUrb) {
  1343. usb_free_urb(usbvision->ctrlUrb);
  1344. }
  1345. v4l2_device_unregister(&usbvision->v4l2_dev);
  1346. kfree(usbvision);
  1347. PDEBUG(DBG_PROBE, "success");
  1348. }
  1349. /*********************** usb interface **********************************/
  1350. static void usbvision_configure_video(struct usb_usbvision *usbvision)
  1351. {
  1352. int model;
  1353. if (usbvision == NULL)
  1354. return;
  1355. model = usbvision->DevModel;
  1356. usbvision->palette = usbvision_v4l2_format[2]; // V4L2_PIX_FMT_RGB24;
  1357. if (usbvision_device_data[usbvision->DevModel].Vin_Reg2_override) {
  1358. usbvision->Vin_Reg2_Preset =
  1359. usbvision_device_data[usbvision->DevModel].Vin_Reg2;
  1360. } else {
  1361. usbvision->Vin_Reg2_Preset = 0;
  1362. }
  1363. usbvision->tvnormId = usbvision_device_data[model].VideoNorm;
  1364. usbvision->video_inputs = usbvision_device_data[model].VideoChannels;
  1365. usbvision->ctl_input = 0;
  1366. /* This should be here to make i2c clients to be able to register */
  1367. /* first switch off audio */
  1368. usbvision_audio_off(usbvision);
  1369. if (!PowerOnAtOpen) {
  1370. /* and then power up the noisy tuner */
  1371. usbvision_power_on(usbvision);
  1372. usbvision_i2c_register(usbvision);
  1373. }
  1374. }
  1375. /*
  1376. * usbvision_probe()
  1377. *
  1378. * This procedure queries device descriptor and accepts the interface
  1379. * if it looks like USBVISION video device
  1380. *
  1381. */
  1382. static int __devinit usbvision_probe(struct usb_interface *intf,
  1383. const struct usb_device_id *devid)
  1384. {
  1385. struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf));
  1386. struct usb_interface *uif;
  1387. __u8 ifnum = intf->altsetting->desc.bInterfaceNumber;
  1388. const struct usb_host_interface *interface;
  1389. struct usb_usbvision *usbvision = NULL;
  1390. const struct usb_endpoint_descriptor *endpoint;
  1391. int model,i;
  1392. PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u",
  1393. dev->descriptor.idVendor,
  1394. dev->descriptor.idProduct, ifnum);
  1395. model = devid->driver_info;
  1396. if ( (model<0) || (model>=usbvision_device_data_size) ) {
  1397. PDEBUG(DBG_PROBE, "model out of bounds %d",model);
  1398. return -ENODEV;
  1399. }
  1400. printk(KERN_INFO "%s: %s found\n", __func__,
  1401. usbvision_device_data[model].ModelString);
  1402. if (usbvision_device_data[model].Interface >= 0) {
  1403. interface = &dev->actconfig->interface[usbvision_device_data[model].Interface]->altsetting[0];
  1404. } else {
  1405. interface = &dev->actconfig->interface[ifnum]->altsetting[0];
  1406. }
  1407. endpoint = &interface->endpoint[1].desc;
  1408. if (!usb_endpoint_xfer_isoc(endpoint)) {
  1409. dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n",
  1410. __func__, ifnum);
  1411. dev_err(&intf->dev, "%s: Endpoint attributes %d",
  1412. __func__, endpoint->bmAttributes);
  1413. return -ENODEV;
  1414. }
  1415. if (usb_endpoint_dir_out(endpoint)) {
  1416. dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n",
  1417. __func__, ifnum);
  1418. return -ENODEV;
  1419. }
  1420. usbvision = usbvision_alloc(dev, intf);
  1421. if (usbvision == NULL) {
  1422. dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__);
  1423. return -ENOMEM;
  1424. }
  1425. if (dev->descriptor.bNumConfigurations > 1) {
  1426. usbvision->bridgeType = BRIDGE_NT1004;
  1427. } else if (model == DAZZLE_DVC_90_REV_1_SECAM) {
  1428. usbvision->bridgeType = BRIDGE_NT1005;
  1429. } else {
  1430. usbvision->bridgeType = BRIDGE_NT1003;
  1431. }
  1432. PDEBUG(DBG_PROBE, "bridgeType %d", usbvision->bridgeType);
  1433. mutex_lock(&usbvision->lock);
  1434. /* compute alternate max packet sizes */
  1435. uif = dev->actconfig->interface[0];
  1436. usbvision->num_alt=uif->num_altsetting;
  1437. PDEBUG(DBG_PROBE, "Alternate settings: %i",usbvision->num_alt);
  1438. usbvision->alt_max_pkt_size = kmalloc(32*
  1439. usbvision->num_alt,GFP_KERNEL);
  1440. if (usbvision->alt_max_pkt_size == NULL) {
  1441. dev_err(&intf->dev, "usbvision: out of memory!\n");
  1442. mutex_unlock(&usbvision->lock);
  1443. return -ENOMEM;
  1444. }
  1445. for (i = 0; i < usbvision->num_alt ; i++) {
  1446. u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc.
  1447. wMaxPacketSize);
  1448. usbvision->alt_max_pkt_size[i] =
  1449. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1450. PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i",i,
  1451. usbvision->alt_max_pkt_size[i]);
  1452. }
  1453. usbvision->nr = usbvision_nr++;
  1454. usbvision->have_tuner = usbvision_device_data[model].Tuner;
  1455. if (usbvision->have_tuner) {
  1456. usbvision->tuner_type = usbvision_device_data[model].TunerType;
  1457. }
  1458. usbvision->DevModel = model;
  1459. usbvision->remove_pending = 0;
  1460. usbvision->iface = ifnum;
  1461. usbvision->ifaceAlt = 0;
  1462. usbvision->video_endp = endpoint->bEndpointAddress;
  1463. usbvision->isocPacketSize = 0;
  1464. usbvision->usb_bandwidth = 0;
  1465. usbvision->user = 0;
  1466. usbvision->streaming = Stream_Off;
  1467. usbvision_register_video(usbvision);
  1468. usbvision_configure_video(usbvision);
  1469. mutex_unlock(&usbvision->lock);
  1470. usb_set_intfdata (intf, usbvision);
  1471. usbvision_create_sysfs(usbvision->vdev);
  1472. PDEBUG(DBG_PROBE, "success");
  1473. return 0;
  1474. }
  1475. /*
  1476. * usbvision_disconnect()
  1477. *
  1478. * This procedure stops all driver activity, deallocates interface-private
  1479. * structure (pointed by 'ptr') and after that driver should be removable
  1480. * with no ill consequences.
  1481. *
  1482. */
  1483. static void __devexit usbvision_disconnect(struct usb_interface *intf)
  1484. {
  1485. struct usb_usbvision *usbvision = usb_get_intfdata(intf);
  1486. PDEBUG(DBG_PROBE, "");
  1487. if (usbvision == NULL) {
  1488. dev_err(&usbvision->dev->dev,
  1489. "%s: usb_get_intfdata() failed\n", __func__);
  1490. return;
  1491. }
  1492. usb_set_intfdata (intf, NULL);
  1493. mutex_lock(&usbvision->lock);
  1494. // At this time we ask to cancel outstanding URBs
  1495. usbvision_stop_isoc(usbvision);
  1496. v4l2_device_disconnect(&usbvision->v4l2_dev);
  1497. if (usbvision->power) {
  1498. usbvision_i2c_unregister(usbvision);
  1499. usbvision_power_off(usbvision);
  1500. }
  1501. usbvision->remove_pending = 1; // Now all ISO data will be ignored
  1502. usb_put_dev(usbvision->dev);
  1503. usbvision->dev = NULL; // USB device is no more
  1504. mutex_unlock(&usbvision->lock);
  1505. if (usbvision->user) {
  1506. printk(KERN_INFO "%s: In use, disconnect pending\n",
  1507. __func__);
  1508. wake_up_interruptible(&usbvision->wait_frame);
  1509. wake_up_interruptible(&usbvision->wait_stream);
  1510. } else {
  1511. usbvision_release(usbvision);
  1512. }
  1513. PDEBUG(DBG_PROBE, "success");
  1514. }
  1515. static struct usb_driver usbvision_driver = {
  1516. .name = "usbvision",
  1517. .id_table = usbvision_table,
  1518. .probe = usbvision_probe,
  1519. .disconnect = __devexit_p(usbvision_disconnect),
  1520. };
  1521. /*
  1522. * usbvision_init()
  1523. *
  1524. * This code is run to initialize the driver.
  1525. *
  1526. */
  1527. static int __init usbvision_init(void)
  1528. {
  1529. int errCode;
  1530. PDEBUG(DBG_PROBE, "");
  1531. PDEBUG(DBG_IO, "IO debugging is enabled [video]");
  1532. PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]");
  1533. PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]");
  1534. /* disable planar mode support unless compression enabled */
  1535. if (isocMode != ISOC_MODE_COMPRESS ) {
  1536. // FIXME : not the right way to set supported flag
  1537. usbvision_v4l2_format[6].supported = 0; // V4L2_PIX_FMT_YVU420
  1538. usbvision_v4l2_format[7].supported = 0; // V4L2_PIX_FMT_YUV422P
  1539. }
  1540. errCode = usb_register(&usbvision_driver);
  1541. if (errCode == 0) {
  1542. printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n");
  1543. PDEBUG(DBG_PROBE, "success");
  1544. }
  1545. return errCode;
  1546. }
  1547. static void __exit usbvision_exit(void)
  1548. {
  1549. PDEBUG(DBG_PROBE, "");
  1550. usb_deregister(&usbvision_driver);
  1551. PDEBUG(DBG_PROBE, "success");
  1552. }
  1553. module_init(usbvision_init);
  1554. module_exit(usbvision_exit);
  1555. /*
  1556. * Overrides for Emacs so that we follow Linus's tabbing style.
  1557. * ---------------------------------------------------------------------------
  1558. * Local variables:
  1559. * c-basic-offset: 8
  1560. * End:
  1561. */