em28xx-video.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881
  1. /*
  2. em2820-video.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
  3. Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
  4. Ludovico Cavedon <cavedon@sssup.it>
  5. Mauro Carvalho Chehab <mchehab@brturbo.com.br>
  6. Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/init.h>
  20. #include <linux/list.h>
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/usb.h>
  24. #include <linux/i2c.h>
  25. #include <linux/video_decoder.h>
  26. #include "em2820.h"
  27. #include <media/tuner.h>
  28. #define DRIVER_AUTHOR "Markus Rechberger <mrechberger@gmail.com>, " \
  29. "Ludovico Cavedon <cavedon@sssup.it>, " \
  30. "Mauro Carvalho Chehab <mchehab@brturbo.com.br>"
  31. #define DRIVER_NAME "em2820"
  32. #define DRIVER_DESC "Empia em2820 based USB video device driver"
  33. #define EM2820_VERSION_CODE KERNEL_VERSION(0, 0, 1)
  34. #define em2820_videodbg(fmt, arg...) do {\
  35. if (video_debug) \
  36. printk(KERN_INFO "%s %s :"fmt, \
  37. dev->name, __FUNCTION__ , ##arg); } while (0)
  38. MODULE_AUTHOR(DRIVER_AUTHOR);
  39. MODULE_DESCRIPTION(DRIVER_DESC);
  40. MODULE_LICENSE("GPL");
  41. static LIST_HEAD(em2820_devlist);
  42. static unsigned int card[] = {[0 ... (EM2820_MAXBOARDS - 1)] = UNSET };
  43. module_param_array(card, int, NULL, 0444);
  44. MODULE_PARM_DESC(card,"card type");
  45. static int tuner = -1;
  46. module_param(tuner, int, 0444);
  47. MODULE_PARM_DESC(tuner, "tuner type");
  48. static unsigned int video_debug = 0;
  49. module_param(video_debug,int,0644);
  50. MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
  51. /* supported tv norms */
  52. static struct em2820_tvnorm tvnorms[] = {
  53. {
  54. .name = "PAL",
  55. .id = V4L2_STD_PAL,
  56. .mode = VIDEO_MODE_PAL,
  57. }, {
  58. .name = "NTSC",
  59. .id = V4L2_STD_NTSC,
  60. .mode = VIDEO_MODE_NTSC,
  61. }, {
  62. .name = "SECAM",
  63. .id = V4L2_STD_SECAM,
  64. .mode = VIDEO_MODE_SECAM,
  65. }, {
  66. .name = "PAL-M",
  67. .id = V4L2_STD_PAL_M,
  68. .mode = VIDEO_MODE_PAL,
  69. }
  70. };
  71. #define TVNORMS ARRAY_SIZE(tvnorms)
  72. /* supported controls */
  73. static struct v4l2_queryctrl em2820_qctrl[] = {
  74. {
  75. .id = V4L2_CID_BRIGHTNESS,
  76. .type = V4L2_CTRL_TYPE_INTEGER,
  77. .name = "Brightness",
  78. .minimum = -128,
  79. .maximum = 127,
  80. .step = 1,
  81. .default_value = 0,
  82. .flags = 0,
  83. },{
  84. .id = V4L2_CID_CONTRAST,
  85. .type = V4L2_CTRL_TYPE_INTEGER,
  86. .name = "Contrast",
  87. .minimum = 0x0,
  88. .maximum = 0x1f,
  89. .step = 0x1,
  90. .default_value = 0x10,
  91. .flags = 0,
  92. },{
  93. .id = V4L2_CID_SATURATION,
  94. .type = V4L2_CTRL_TYPE_INTEGER,
  95. .name = "Saturation",
  96. .minimum = 0x0,
  97. .maximum = 0x1f,
  98. .step = 0x1,
  99. .default_value = 0x10,
  100. .flags = 0,
  101. },{
  102. .id = V4L2_CID_AUDIO_VOLUME,
  103. .type = V4L2_CTRL_TYPE_INTEGER,
  104. .name = "Volume",
  105. .minimum = 0x0,
  106. .maximum = 0x1f,
  107. .step = 0x1,
  108. .default_value = 0x1f,
  109. .flags = 0,
  110. },{
  111. .id = V4L2_CID_AUDIO_MUTE,
  112. .type = V4L2_CTRL_TYPE_BOOLEAN,
  113. .name = "Mute",
  114. .minimum = 0,
  115. .maximum = 1,
  116. .step = 1,
  117. .default_value = 1,
  118. .flags = 0,
  119. },{
  120. .id = V4L2_CID_RED_BALANCE,
  121. .type = V4L2_CTRL_TYPE_INTEGER,
  122. .name = "Red chroma balance",
  123. .minimum = -128,
  124. .maximum = 127,
  125. .step = 1,
  126. .default_value = 0,
  127. .flags = 0,
  128. },{
  129. .id = V4L2_CID_BLUE_BALANCE,
  130. .type = V4L2_CTRL_TYPE_INTEGER,
  131. .name = "Blue chroma balance",
  132. .minimum = -128,
  133. .maximum = 127,
  134. .step = 1,
  135. .default_value = 0,
  136. .flags = 0,
  137. },{
  138. .id = V4L2_CID_GAMMA,
  139. .type = V4L2_CTRL_TYPE_INTEGER,
  140. .name = "Gamma",
  141. .minimum = 0x0,
  142. .maximum = 0x3f,
  143. .step = 0x1,
  144. .default_value = 0x20,
  145. .flags = 0,
  146. }
  147. };
  148. static struct usb_driver em2820_usb_driver;
  149. static DECLARE_MUTEX(em2820_sysfs_lock);
  150. static DECLARE_RWSEM(em2820_disconnect);
  151. /********************* v4l2 interface ******************************************/
  152. static inline unsigned long kvirt_to_pa(unsigned long adr)
  153. {
  154. unsigned long kva, ret;
  155. kva = (unsigned long)page_address(vmalloc_to_page((void *)adr));
  156. kva |= adr & (PAGE_SIZE - 1);
  157. ret = __pa(kva);
  158. return ret;
  159. }
  160. /*
  161. * em2820_config()
  162. * inits registers with sane defaults
  163. */
  164. static int em2820_config(struct em2820 *dev)
  165. {
  166. /* Sets I2C speed to 100 KHz */
  167. em2820_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
  168. /* enable vbi capturing */
  169. em2820_audio_usb_mute(dev, 1);
  170. dev->mute = 1; /* maybe not the right place... */
  171. dev->volume = 0x1f;
  172. em2820_audio_analog_set(dev);
  173. em2820_audio_analog_setup(dev);
  174. em2820_outfmt_set_yuv422(dev);
  175. em2820_colorlevels_set_default(dev);
  176. em2820_compression_disable(dev);
  177. return 0;
  178. }
  179. /*
  180. * em2820_config_i2c()
  181. * configure i2c attached devices
  182. */
  183. void em2820_config_i2c(struct em2820 *dev)
  184. {
  185. struct v4l2_frequency f;
  186. struct video_decoder_init em2820_vdi = {.data = NULL };
  187. /* configure decoder */
  188. em2820_i2c_call_clients(dev, DECODER_INIT, &em2820_vdi);
  189. em2820_i2c_call_clients(dev, DECODER_SET_INPUT, &dev->ctl_input);
  190. /* em2820_i2c_call_clients(dev,DECODER_SET_PICTURE, &dev->vpic); */
  191. /* em2820_i2c_call_clients(dev,DECODER_SET_NORM,&dev->tvnorm->id); */
  192. /* em2820_i2c_call_clients(dev,DECODER_ENABLE_OUTPUT,&output); */
  193. /* em2820_i2c_call_clients(dev,DECODER_DUMP, NULL); */
  194. /* configure tuner */
  195. f.tuner = 0;
  196. f.type = V4L2_TUNER_ANALOG_TV;
  197. f.frequency = 9076; /* FIXME:remove magic number */
  198. dev->ctl_freq = f.frequency;
  199. em2820_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
  200. /* configure tda9887 */
  201. /* em2820_i2c_call_clients(dev,VIDIOC_S_STD,&dev->tvnorm->id); */
  202. }
  203. /*
  204. * em2820_empty_framequeues()
  205. * prepare queues for incoming and outgoing frames
  206. */
  207. static void em2820_empty_framequeues(struct em2820 *dev)
  208. {
  209. u32 i;
  210. INIT_LIST_HEAD(&dev->inqueue);
  211. INIT_LIST_HEAD(&dev->outqueue);
  212. for (i = 0; i < EM2820_NUM_FRAMES; i++) {
  213. dev->frame[i].state = F_UNUSED;
  214. dev->frame[i].buf.bytesused = 0;
  215. }
  216. }
  217. /*
  218. * em2820_v4l2_open()
  219. * inits the device and starts isoc transfer
  220. */
  221. static int em2820_v4l2_open(struct inode *inode, struct file *filp)
  222. {
  223. int minor = iminor(inode);
  224. int errCode = 0;
  225. struct em2820 *h,*dev = NULL;
  226. struct list_head *list;
  227. list_for_each(list,&em2820_devlist) {
  228. h = list_entry(list, struct em2820, devlist);
  229. if (h->vdev->minor == minor) {
  230. dev = h;
  231. }
  232. }
  233. filp->private_data=dev;
  234. em2820_videodbg("users=%d", dev->users);
  235. if (!down_read_trylock(&em2820_disconnect))
  236. return -ERESTARTSYS;
  237. if (dev->users) {
  238. em2820_warn("this driver can be opened only once\n");
  239. up_read(&em2820_disconnect);
  240. return -EBUSY;
  241. }
  242. /* if(dev->vbi_dev->minor == minor){
  243. dev->type=V4L2_BUF_TYPE_VBI_CAPTURE;
  244. }*/
  245. if (dev->vdev->minor == minor) {
  246. dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  247. }
  248. init_MUTEX(&dev->fileop_lock); /* to 1 == available */
  249. spin_lock_init(&dev->queue_lock);
  250. init_waitqueue_head(&dev->wait_frame);
  251. init_waitqueue_head(&dev->wait_stream);
  252. down(&dev->lock);
  253. em2820_set_alternate(dev);
  254. dev->width = norm_maxw(dev);
  255. dev->height = norm_maxh(dev);
  256. dev->frame_size = dev->width * dev->height * 2;
  257. dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
  258. dev->bytesperline = dev->width * 2;
  259. dev->hscale = 0;
  260. dev->vscale = 0;
  261. em2820_capture_start(dev, 1);
  262. em2820_resolution_set(dev);
  263. /* start the transfer */
  264. errCode = em2820_init_isoc(dev);
  265. if (errCode)
  266. goto err;
  267. dev->users++;
  268. filp->private_data = dev;
  269. dev->io = IO_NONE;
  270. dev->stream = STREAM_OFF;
  271. dev->num_frames = 0;
  272. /* prepare queues */
  273. em2820_empty_framequeues(dev);
  274. dev->state |= DEV_INITIALIZED;
  275. err:
  276. up(&dev->lock);
  277. up_read(&em2820_disconnect);
  278. return errCode;
  279. }
  280. /*
  281. * em2820_realease_resources()
  282. * unregisters the v4l2,i2c and usb devices
  283. * called when the device gets disconected or at module unload
  284. */
  285. static void em2820_release_resources(struct em2820 *dev)
  286. {
  287. down(&em2820_sysfs_lock);
  288. em2820_info("V4L2 device /dev/video%d deregistered\n",
  289. dev->vdev->minor);
  290. list_del(&dev->devlist);
  291. video_unregister_device(dev->vdev);
  292. /* video_unregister_device(dev->vbi_dev); */
  293. em2820_i2c_unregister(dev);
  294. usb_put_dev(dev->udev);
  295. up(&em2820_sysfs_lock);
  296. }
  297. /*
  298. * em2820_v4l2_close()
  299. * stops streaming and deallocates all resources allocated by the v4l2 calls and ioctls
  300. */
  301. static int em2820_v4l2_close(struct inode *inode, struct file *filp)
  302. {
  303. int errCode;
  304. struct em2820 *dev=filp->private_data;
  305. em2820_videodbg("users=%d", dev->users);
  306. down(&dev->lock);
  307. em2820_uninit_isoc(dev);
  308. em2820_release_buffers(dev);
  309. /* the device is already disconnect, free the remaining resources */
  310. if (dev->state & DEV_DISCONNECTED) {
  311. em2820_release_resources(dev);
  312. up(&dev->lock);
  313. kfree(dev);
  314. return 0;
  315. }
  316. /* set alternate 0 */
  317. dev->alt = 0;
  318. em2820_videodbg("setting alternate 0");
  319. errCode = usb_set_interface(dev->udev, 0, 0);
  320. if (errCode < 0) {
  321. em2820_errdev ("cannot change alternate number to 0 (error=%i)\n",
  322. errCode);
  323. }
  324. dev->users--;
  325. wake_up_interruptible_nr(&dev->open, 1);
  326. up(&dev->lock);
  327. return 0;
  328. }
  329. /*
  330. * em2820_v4l2_read()
  331. * will allocate buffers when called for the first time
  332. */
  333. static ssize_t
  334. em2820_v4l2_read(struct file *filp, char __user * buf, size_t count,
  335. loff_t * f_pos)
  336. {
  337. struct em2820_frame_t *f, *i;
  338. unsigned long lock_flags;
  339. int ret = 0;
  340. struct em2820 *dev = filp->private_data;
  341. if (down_interruptible(&dev->fileop_lock))
  342. return -ERESTARTSYS;
  343. if (dev->state & DEV_DISCONNECTED) {
  344. em2820_videodbg("device not present");
  345. up(&dev->fileop_lock);
  346. return -ENODEV;
  347. }
  348. if (dev->state & DEV_MISCONFIGURED) {
  349. em2820_videodbg("device misconfigured; close and open it again");
  350. up(&dev->fileop_lock);
  351. return -EIO;
  352. }
  353. if (dev->io == IO_MMAP) {
  354. em2820_videodbg ("IO method is set to mmap; close and open"
  355. " the device again to choose the read method");
  356. up(&dev->fileop_lock);
  357. return -EINVAL;
  358. }
  359. if (dev->io == IO_NONE) {
  360. if (!em2820_request_buffers(dev, EM2820_NUM_READ_FRAMES)) {
  361. em2820_errdev("read failed, not enough memory\n");
  362. up(&dev->fileop_lock);
  363. return -ENOMEM;
  364. }
  365. dev->io = IO_READ;
  366. dev->stream = STREAM_ON;
  367. em2820_queue_unusedframes(dev);
  368. }
  369. if (!count) {
  370. up(&dev->fileop_lock);
  371. return 0;
  372. }
  373. if (list_empty(&dev->outqueue)) {
  374. if (filp->f_flags & O_NONBLOCK) {
  375. up(&dev->fileop_lock);
  376. return -EAGAIN;
  377. }
  378. ret = wait_event_interruptible
  379. (dev->wait_frame,
  380. (!list_empty(&dev->outqueue)) ||
  381. (dev->state & DEV_DISCONNECTED));
  382. if (ret) {
  383. up(&dev->fileop_lock);
  384. return ret;
  385. }
  386. if (dev->state & DEV_DISCONNECTED) {
  387. up(&dev->fileop_lock);
  388. return -ENODEV;
  389. }
  390. }
  391. f = list_entry(dev->outqueue.prev, struct em2820_frame_t, frame);
  392. spin_lock_irqsave(&dev->queue_lock, lock_flags);
  393. list_for_each_entry(i, &dev->outqueue, frame)
  394. i->state = F_UNUSED;
  395. INIT_LIST_HEAD(&dev->outqueue);
  396. spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
  397. em2820_queue_unusedframes(dev);
  398. if (count > f->buf.length)
  399. count = f->buf.length;
  400. if (copy_to_user(buf, f->bufmem, count)) {
  401. up(&dev->fileop_lock);
  402. return -EFAULT;
  403. }
  404. *f_pos += count;
  405. up(&dev->fileop_lock);
  406. return count;
  407. }
  408. /*
  409. * em2820_v4l2_poll()
  410. * will allocate buffers when called for the first time
  411. */
  412. static unsigned int em2820_v4l2_poll(struct file *filp, poll_table * wait)
  413. {
  414. unsigned int mask = 0;
  415. struct em2820 *dev = filp->private_data;
  416. if (down_interruptible(&dev->fileop_lock))
  417. return POLLERR;
  418. if (dev->state & DEV_DISCONNECTED) {
  419. em2820_videodbg("device not present");
  420. } else if (dev->state & DEV_MISCONFIGURED) {
  421. em2820_videodbg("device is misconfigured; close and open it again");
  422. } else {
  423. if (dev->io == IO_NONE) {
  424. if (!em2820_request_buffers
  425. (dev, EM2820_NUM_READ_FRAMES)) {
  426. em2820_warn
  427. ("poll() failed, not enough memory\n");
  428. } else {
  429. dev->io = IO_READ;
  430. dev->stream = STREAM_ON;
  431. }
  432. }
  433. if (dev->io == IO_READ) {
  434. em2820_queue_unusedframes(dev);
  435. poll_wait(filp, &dev->wait_frame, wait);
  436. if (!list_empty(&dev->outqueue))
  437. mask |= POLLIN | POLLRDNORM;
  438. up(&dev->fileop_lock);
  439. return mask;
  440. }
  441. }
  442. up(&dev->fileop_lock);
  443. return POLLERR;
  444. }
  445. /*
  446. * em2820_vm_open()
  447. */
  448. static void em2820_vm_open(struct vm_area_struct *vma)
  449. {
  450. struct em2820_frame_t *f = vma->vm_private_data;
  451. f->vma_use_count++;
  452. }
  453. /*
  454. * em2820_vm_close()
  455. */
  456. static void em2820_vm_close(struct vm_area_struct *vma)
  457. {
  458. /* NOTE: buffers are not freed here */
  459. struct em2820_frame_t *f = vma->vm_private_data;
  460. f->vma_use_count--;
  461. }
  462. static struct vm_operations_struct em2820_vm_ops = {
  463. .open = em2820_vm_open,
  464. .close = em2820_vm_close,
  465. };
  466. /*
  467. * em2820_v4l2_mmap()
  468. */
  469. static int em2820_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
  470. {
  471. unsigned long size = vma->vm_end - vma->vm_start,
  472. start = vma->vm_start, pos, page;
  473. u32 i;
  474. struct em2820 *dev = filp->private_data;
  475. if (down_interruptible(&dev->fileop_lock))
  476. return -ERESTARTSYS;
  477. if (dev->state & DEV_DISCONNECTED) {
  478. em2820_videodbg("mmap: device not present");
  479. up(&dev->fileop_lock);
  480. return -ENODEV;
  481. }
  482. if (dev->state & DEV_MISCONFIGURED) {
  483. em2820_videodbg ("mmap: Device is misconfigured; close and "
  484. "open it again");
  485. up(&dev->fileop_lock);
  486. return -EIO;
  487. }
  488. if (dev->io != IO_MMAP || !(vma->vm_flags & VM_WRITE) ||
  489. size != PAGE_ALIGN(dev->frame[0].buf.length)) {
  490. up(&dev->fileop_lock);
  491. return -EINVAL;
  492. }
  493. for (i = 0; i < dev->num_frames; i++) {
  494. if ((dev->frame[i].buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
  495. break;
  496. }
  497. if (i == dev->num_frames) {
  498. em2820_videodbg("mmap: user supplied mapping address is out of range");
  499. up(&dev->fileop_lock);
  500. return -EINVAL;
  501. }
  502. /* VM_IO is eventually going to replace PageReserved altogether */
  503. vma->vm_flags |= VM_IO;
  504. vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */
  505. pos = (unsigned long)dev->frame[i].bufmem;
  506. while (size > 0) { /* size is page-aligned */
  507. page = vmalloc_to_pfn((void *)pos);
  508. if (remap_pfn_range(vma, start, page, PAGE_SIZE,
  509. vma->vm_page_prot)) {
  510. em2820_videodbg("mmap: rename page map failed");
  511. up(&dev->fileop_lock);
  512. return -EAGAIN;
  513. }
  514. start += PAGE_SIZE;
  515. pos += PAGE_SIZE;
  516. size -= PAGE_SIZE;
  517. }
  518. vma->vm_ops = &em2820_vm_ops;
  519. vma->vm_private_data = &dev->frame[i];
  520. em2820_vm_open(vma);
  521. up(&dev->fileop_lock);
  522. return 0;
  523. }
  524. /*
  525. * em2820_get_ctrl()
  526. * return the current saturation, brightness or contrast, mute state
  527. */
  528. static int em2820_get_ctrl(struct em2820 *dev, struct v4l2_control *ctrl)
  529. {
  530. s32 tmp;
  531. switch (ctrl->id) {
  532. case V4L2_CID_AUDIO_MUTE:
  533. ctrl->value = dev->mute;
  534. return 0;
  535. case V4L2_CID_AUDIO_VOLUME:
  536. ctrl->value = dev->volume;
  537. return 0;
  538. case V4L2_CID_BRIGHTNESS:
  539. if ((tmp = em2820_brightness_get(dev)) < 0)
  540. return -EIO;
  541. ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */
  542. return 0;
  543. case V4L2_CID_CONTRAST:
  544. if ((ctrl->value = em2820_contrast_get(dev)) < 0)
  545. return -EIO;
  546. return 0;
  547. case V4L2_CID_SATURATION:
  548. if ((ctrl->value = em2820_saturation_get(dev)) < 0)
  549. return -EIO;
  550. return 0;
  551. case V4L2_CID_RED_BALANCE:
  552. if ((tmp = em2820_v_balance_get(dev)) < 0)
  553. return -EIO;
  554. ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */
  555. return 0;
  556. case V4L2_CID_BLUE_BALANCE:
  557. if ((tmp = em2820_u_balance_get(dev)) < 0)
  558. return -EIO;
  559. ctrl->value = (s32) ((s8) tmp); /* FIXME: clenaer way to extend sign? */
  560. return 0;
  561. case V4L2_CID_GAMMA:
  562. if ((ctrl->value = em2820_gamma_get(dev)) < 0)
  563. return -EIO;
  564. return 0;
  565. default:
  566. return -EINVAL;
  567. }
  568. }
  569. /*
  570. * em2820_set_ctrl()
  571. * mute or set new saturation, brightness or contrast
  572. */
  573. static int em2820_set_ctrl(struct em2820 *dev, const struct v4l2_control *ctrl)
  574. {
  575. switch (ctrl->id) {
  576. case V4L2_CID_AUDIO_MUTE:
  577. if (ctrl->value != dev->mute) {
  578. dev->mute = ctrl->value;
  579. em2820_audio_usb_mute(dev, ctrl->value);
  580. return em2820_audio_analog_set(dev);
  581. }
  582. return 0;
  583. case V4L2_CID_AUDIO_VOLUME:
  584. dev->volume = ctrl->value;
  585. return em2820_audio_analog_set(dev);
  586. case V4L2_CID_BRIGHTNESS:
  587. return em2820_brightness_set(dev, ctrl->value);
  588. case V4L2_CID_CONTRAST:
  589. return em2820_contrast_set(dev, ctrl->value);
  590. case V4L2_CID_SATURATION:
  591. return em2820_saturation_set(dev, ctrl->value);
  592. case V4L2_CID_RED_BALANCE:
  593. return em2820_v_balance_set(dev, ctrl->value);
  594. case V4L2_CID_BLUE_BALANCE:
  595. return em2820_u_balance_set(dev, ctrl->value);
  596. case V4L2_CID_GAMMA:
  597. return em2820_gamma_set(dev, ctrl->value);
  598. default:
  599. return -EINVAL;
  600. }
  601. }
  602. /*
  603. * em2820_stream_interrupt()
  604. * stops streaming
  605. */
  606. static int em2820_stream_interrupt(struct em2820 *dev)
  607. {
  608. int ret = 0;
  609. /* stop reading from the device */
  610. dev->stream = STREAM_INTERRUPT;
  611. ret = wait_event_timeout(dev->wait_stream,
  612. (dev->stream == STREAM_OFF) ||
  613. (dev->state & DEV_DISCONNECTED),
  614. EM2820_URB_TIMEOUT);
  615. if (dev->state & DEV_DISCONNECTED)
  616. return -ENODEV;
  617. else if (ret) {
  618. dev->state |= DEV_MISCONFIGURED;
  619. em2820_videodbg("device is misconfigured; close and "
  620. "open /dev/video%d again", dev->vdev->minor);
  621. return ret;
  622. }
  623. return 0;
  624. }
  625. static int em2820_set_norm(struct em2820 *dev, int width, int height)
  626. {
  627. unsigned int hscale, vscale;
  628. unsigned int maxh, maxw;
  629. maxw = norm_maxw(dev);
  630. maxh = norm_maxh(dev);
  631. /* width must even because of the YUYV format */
  632. /* height must be even because of interlacing */
  633. height &= 0xfffe;
  634. width &= 0xfffe;
  635. if (height < 32)
  636. height = 32;
  637. if (height > maxh)
  638. height = maxh;
  639. if (width < 48)
  640. width = 48;
  641. if (width > maxw)
  642. width = maxw;
  643. if ((hscale = (((unsigned long)maxw) << 12) / width - 4096L) >= 0x4000)
  644. hscale = 0x3fff;
  645. width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
  646. if ((vscale = (((unsigned long)maxh) << 12) / height - 4096L) >= 0x4000)
  647. vscale = 0x3fff;
  648. height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
  649. /* set new image size */
  650. dev->width = width;
  651. dev->height = height;
  652. dev->frame_size = dev->width * dev->height * 2;
  653. dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
  654. dev->bytesperline = dev->width * 2;
  655. dev->hscale = hscale;
  656. dev->vscale = vscale;
  657. em2820_resolution_set(dev);
  658. return 0;
  659. }
  660. static void video_mux(struct em2820 *dev, int index)
  661. {
  662. int input, ainput;
  663. input = INPUT(index)->vmux;
  664. dev->ctl_input = index;
  665. em2820_i2c_call_clients(dev, DECODER_SET_INPUT, &input);
  666. dev->ctl_ainput = INPUT(index)->amux;
  667. switch (dev->ctl_ainput) {
  668. case 0:
  669. ainput = EM2820_AUDIO_SRC_TUNER;
  670. break;
  671. default:
  672. ainput = EM2820_AUDIO_SRC_LINE;
  673. }
  674. em2820_audio_source(dev, ainput);
  675. }
  676. /*
  677. * em2820_v4l2_do_ioctl()
  678. * This function is _not_ called directly, but from
  679. * em2820_v4l2_ioctl. Userspace
  680. * copying is done already, arg is a kernel pointer.
  681. */
  682. static int em2820_do_ioctl(struct inode *inode, struct file *filp,
  683. struct em2820 *dev, unsigned int cmd, void *arg,
  684. v4l2_kioctl driver_ioctl)
  685. {
  686. int ret;
  687. switch (cmd) {
  688. /* ---------- tv norms ---------- */
  689. case VIDIOC_ENUMSTD:
  690. {
  691. struct v4l2_standard *e = arg;
  692. unsigned int i;
  693. i = e->index;
  694. if (i >= TVNORMS)
  695. return -EINVAL;
  696. ret = v4l2_video_std_construct(e, tvnorms[e->index].id,
  697. tvnorms[e->index].name);
  698. e->index = i;
  699. if (ret < 0)
  700. return ret;
  701. return 0;
  702. }
  703. case VIDIOC_G_STD:
  704. {
  705. v4l2_std_id *id = arg;
  706. *id = dev->tvnorm->id;
  707. return 0;
  708. }
  709. case VIDIOC_S_STD:
  710. {
  711. v4l2_std_id *id = arg;
  712. unsigned int i;
  713. for (i = 0; i < TVNORMS; i++)
  714. if (*id == tvnorms[i].id)
  715. break;
  716. if (i == TVNORMS)
  717. for (i = 0; i < TVNORMS; i++)
  718. if (*id & tvnorms[i].id)
  719. break;
  720. if (i == TVNORMS)
  721. return -EINVAL;
  722. down(&dev->lock);
  723. dev->tvnorm = &tvnorms[i];
  724. em2820_set_norm(dev, dev->width, dev->height);
  725. /*
  726. dev->width=norm_maxw(dev);
  727. dev->height=norm_maxh(dev);
  728. dev->frame_size=dev->width*dev->height*2;
  729. dev->field_size=dev->frame_size>>1;
  730. dev->bytesperline=dev->width*2;
  731. dev->hscale=0;
  732. dev->vscale=0;
  733. em2820_resolution_set(dev);
  734. */
  735. /*
  736. em2820_uninit_isoc(dev);
  737. em2820_set_alternate(dev);
  738. em2820_capture_start(dev, 1);
  739. em2820_resolution_set(dev);
  740. em2820_init_isoc(dev);
  741. */
  742. em2820_i2c_call_clients(dev, DECODER_SET_NORM,
  743. &tvnorms[i].mode);
  744. em2820_i2c_call_clients(dev, VIDIOC_S_STD,
  745. &dev->tvnorm->id);
  746. up(&dev->lock);
  747. return 0;
  748. }
  749. /* ------ input switching ---------- */
  750. case VIDIOC_ENUMINPUT:
  751. {
  752. struct v4l2_input *i = arg;
  753. unsigned int n;
  754. static const char *iname[] = {
  755. [EM2820_VMUX_COMPOSITE1] = "Composite1",
  756. [EM2820_VMUX_COMPOSITE2] = "Composite2",
  757. [EM2820_VMUX_COMPOSITE3] = "Composite3",
  758. [EM2820_VMUX_COMPOSITE4] = "Composite4",
  759. [EM2820_VMUX_SVIDEO] = "S-Video",
  760. [EM2820_VMUX_TELEVISION] = "Television",
  761. [EM2820_VMUX_CABLE] = "Cable TV",
  762. [EM2820_VMUX_DVB] = "DVB",
  763. [EM2820_VMUX_DEBUG] = "for debug only",
  764. };
  765. n = i->index;
  766. if (n >= MAX_EM2820_INPUT)
  767. return -EINVAL;
  768. if (0 == INPUT(n)->type)
  769. return -EINVAL;
  770. memset(i, 0, sizeof(*i));
  771. i->index = n;
  772. i->type = V4L2_INPUT_TYPE_CAMERA;
  773. strcpy(i->name, iname[INPUT(n)->type]);
  774. if ((EM2820_VMUX_TELEVISION == INPUT(n)->type) ||
  775. (EM2820_VMUX_CABLE == INPUT(n)->type))
  776. i->type = V4L2_INPUT_TYPE_TUNER;
  777. for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
  778. i->std |= tvnorms[n].id;
  779. return 0;
  780. }
  781. case VIDIOC_G_INPUT:
  782. {
  783. int *i = arg;
  784. *i = dev->ctl_input;
  785. return 0;
  786. }
  787. case VIDIOC_S_INPUT:
  788. {
  789. int *index = arg;
  790. if (*index >= MAX_EM2820_INPUT)
  791. return -EINVAL;
  792. if (0 == INPUT(*index)->type)
  793. return -EINVAL;
  794. down(&dev->lock);
  795. video_mux(dev, *index);
  796. up(&dev->lock);
  797. return 0;
  798. }
  799. case VIDIOC_G_AUDIO:
  800. {
  801. struct v4l2_audio *a = arg;
  802. unsigned int index = a->index;
  803. if (a->index > 1)
  804. return -EINVAL;
  805. memset(a, 0, sizeof(*a));
  806. index = dev->ctl_ainput;
  807. if (index == 0) {
  808. strcpy(a->name, "Television");
  809. } else {
  810. strcpy(a->name, "Line In");
  811. }
  812. a->capability = V4L2_AUDCAP_STEREO;
  813. a->index = index;
  814. return 0;
  815. }
  816. case VIDIOC_S_AUDIO:
  817. {
  818. struct v4l2_audio *a = arg;
  819. if (a->index != dev->ctl_ainput)
  820. return -EINVAL;
  821. return 0;
  822. }
  823. /* --- controls ---------------------------------------------- */
  824. case VIDIOC_QUERYCTRL:
  825. {
  826. struct v4l2_queryctrl *qc = arg;
  827. u8 i, n;
  828. n = sizeof(em2820_qctrl) / sizeof(em2820_qctrl[0]);
  829. for (i = 0; i < n; i++)
  830. if (qc->id && qc->id == em2820_qctrl[i].id) {
  831. memcpy(qc, &(em2820_qctrl[i]),
  832. sizeof(*qc));
  833. return 0;
  834. }
  835. return -EINVAL;
  836. }
  837. case VIDIOC_G_CTRL:
  838. {
  839. struct v4l2_control *ctrl = arg;
  840. return em2820_get_ctrl(dev, ctrl);
  841. }
  842. case VIDIOC_S_CTRL_OLD: /* ??? */
  843. case VIDIOC_S_CTRL:
  844. {
  845. struct v4l2_control *ctrl = arg;
  846. u8 i, n;
  847. n = sizeof(em2820_qctrl) / sizeof(em2820_qctrl[0]);
  848. for (i = 0; i < n; i++)
  849. if (ctrl->id == em2820_qctrl[i].id) {
  850. if (ctrl->value <
  851. em2820_qctrl[i].minimum
  852. || ctrl->value >
  853. em2820_qctrl[i].maximum)
  854. return -ERANGE;
  855. return em2820_set_ctrl(dev, ctrl);
  856. }
  857. return -EINVAL;
  858. }
  859. /* --- tuner ioctls ------------------------------------------ */
  860. case VIDIOC_G_TUNER:
  861. {
  862. struct v4l2_tuner *t = arg;
  863. int status = 0;
  864. if (0 != t->index)
  865. return -EINVAL;
  866. memset(t, 0, sizeof(*t));
  867. strcpy(t->name, "Tuner");
  868. t->type = V4L2_TUNER_ANALOG_TV;
  869. t->capability = V4L2_TUNER_CAP_NORM;
  870. t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
  871. /* t->signal = 0xffff;*/
  872. /* em2820_i2c_call_clients(dev,VIDIOC_G_TUNER,t);*/
  873. /* No way to get signal strength? */
  874. down(&dev->lock);
  875. em2820_i2c_call_clients(dev, DECODER_GET_STATUS,
  876. &status);
  877. up(&dev->lock);
  878. t->signal =
  879. (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
  880. em2820_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x", t->signal,
  881. t->afc);
  882. return 0;
  883. }
  884. case VIDIOC_S_TUNER:
  885. {
  886. struct v4l2_tuner *t = arg;
  887. int status = 0;
  888. if (0 != t->index)
  889. return -EINVAL;
  890. memset(t, 0, sizeof(*t));
  891. strcpy(t->name, "Tuner");
  892. t->type = V4L2_TUNER_ANALOG_TV;
  893. t->capability = V4L2_TUNER_CAP_NORM;
  894. t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
  895. /* t->signal = 0xffff; */
  896. /* No way to get signal strength? */
  897. down(&dev->lock);
  898. em2820_i2c_call_clients(dev, DECODER_GET_STATUS,
  899. &status);
  900. up(&dev->lock);
  901. t->signal =
  902. (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
  903. em2820_videodbg("VIDIO_S_TUNER: signal=%x, afc=%x\n",
  904. t->signal, t->afc);
  905. return 0;
  906. }
  907. case VIDIOC_G_FREQUENCY:
  908. {
  909. struct v4l2_frequency *f = arg;
  910. memset(f, 0, sizeof(*f));
  911. f->type = V4L2_TUNER_ANALOG_TV;
  912. f->frequency = dev->ctl_freq;
  913. return 0;
  914. }
  915. case VIDIOC_S_FREQUENCY:
  916. {
  917. struct v4l2_frequency *f = arg;
  918. if (0 != f->tuner)
  919. return -EINVAL;
  920. if (V4L2_TUNER_ANALOG_TV != f->type)
  921. return -EINVAL;
  922. down(&dev->lock);
  923. dev->ctl_freq = f->frequency;
  924. em2820_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
  925. up(&dev->lock);
  926. return 0;
  927. }
  928. case VIDIOC_CROPCAP:
  929. {
  930. struct v4l2_cropcap *cc = arg;
  931. if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  932. return -EINVAL;
  933. cc->bounds.left = 0;
  934. cc->bounds.top = 0;
  935. cc->bounds.width = dev->width;
  936. cc->bounds.height = dev->height;
  937. cc->defrect = cc->bounds;
  938. cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
  939. cc->pixelaspect.denominator = 59;
  940. return 0;
  941. }
  942. case VIDIOC_STREAMON:
  943. {
  944. int *type = arg;
  945. if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
  946. || dev->io != IO_MMAP)
  947. return -EINVAL;
  948. if (list_empty(&dev->inqueue))
  949. return -EINVAL;
  950. dev->stream = STREAM_ON; /* FIXME: Start video capture here? */
  951. em2820_videodbg("VIDIOC_STREAMON: starting stream");
  952. return 0;
  953. }
  954. case VIDIOC_STREAMOFF:
  955. {
  956. int *type = arg;
  957. int ret;
  958. if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
  959. || dev->io != IO_MMAP)
  960. return -EINVAL;
  961. if (dev->stream == STREAM_ON) {
  962. em2820_videodbg ("VIDIOC_STREAMOFF: interrupting stream");
  963. if ((ret = em2820_stream_interrupt(dev)))
  964. return ret;
  965. }
  966. em2820_empty_framequeues(dev);
  967. return 0;
  968. }
  969. default:
  970. return v4l_compat_translate_ioctl(inode, filp, cmd, arg,
  971. driver_ioctl);
  972. }
  973. return 0;
  974. }
  975. /*
  976. * em2820_v4l2_do_ioctl()
  977. * This function is _not_ called directly, but from
  978. * em2820_v4l2_ioctl. Userspace
  979. * copying is done already, arg is a kernel pointer.
  980. */
  981. static int em2820_video_do_ioctl(struct inode *inode, struct file *filp,
  982. unsigned int cmd, void *arg)
  983. {
  984. struct em2820 *dev = filp->private_data;
  985. if (!dev)
  986. return -ENODEV;
  987. if (video_debug > 1)
  988. em2820_print_ioctl(dev->name,cmd);
  989. switch (cmd) {
  990. /* --- capabilities ------------------------------------------ */
  991. case VIDIOC_QUERYCAP:
  992. {
  993. struct v4l2_capability *cap = arg;
  994. memset(cap, 0, sizeof(*cap));
  995. strlcpy(cap->driver, "em2820", sizeof(cap->driver));
  996. strlcpy(cap->card, em2820_boards[dev->model].name,
  997. sizeof(cap->card));
  998. strlcpy(cap->bus_info, dev->udev->dev.bus_id,
  999. sizeof(cap->bus_info));
  1000. cap->version = EM2820_VERSION_CODE;
  1001. cap->capabilities =
  1002. V4L2_CAP_VIDEO_CAPTURE |
  1003. V4L2_CAP_AUDIO |
  1004. V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
  1005. if (dev->has_tuner)
  1006. cap->capabilities |= V4L2_CAP_TUNER;
  1007. return 0;
  1008. }
  1009. /* --- capture ioctls ---------------------------------------- */
  1010. case VIDIOC_ENUM_FMT:
  1011. {
  1012. struct v4l2_fmtdesc *fmtd = arg;
  1013. if (fmtd->index != 0)
  1014. return -EINVAL;
  1015. memset(fmtd, 0, sizeof(*fmtd));
  1016. fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1017. strcpy(fmtd->description, "Packed YUY2");
  1018. fmtd->pixelformat = V4L2_PIX_FMT_YUYV;
  1019. memset(fmtd->reserved, 0, sizeof(fmtd->reserved));
  1020. return 0;
  1021. }
  1022. case VIDIOC_G_FMT:
  1023. {
  1024. struct v4l2_format *format = arg;
  1025. em2820_videodbg("VIDIOC_G_FMT: type=%s",
  1026. format->type ==
  1027. V4L2_BUF_TYPE_VIDEO_CAPTURE ?
  1028. "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type ==
  1029. V4L2_BUF_TYPE_VBI_CAPTURE ?
  1030. "V4L2_BUF_TYPE_VBI_CAPTURE " :
  1031. "not supported");
  1032. if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1033. return -EINVAL;
  1034. format->fmt.pix.width = dev->width;
  1035. format->fmt.pix.height = dev->height;
  1036. format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
  1037. format->fmt.pix.bytesperline = dev->bytesperline;
  1038. format->fmt.pix.sizeimage = dev->frame_size;
  1039. format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  1040. format->fmt.pix.field = dev->interlaced ? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
  1041. em2820_videodbg("VIDIOC_G_FMT: %dx%d", dev->width,
  1042. dev->height);
  1043. return 0;
  1044. }
  1045. case VIDIOC_TRY_FMT:
  1046. case VIDIOC_S_FMT:
  1047. {
  1048. struct v4l2_format *format = arg;
  1049. u32 i;
  1050. int ret = 0;
  1051. int width = format->fmt.pix.width;
  1052. int height = format->fmt.pix.height;
  1053. unsigned int hscale, vscale;
  1054. unsigned int maxh, maxw;
  1055. maxw = norm_maxw(dev);
  1056. maxh = norm_maxh(dev);
  1057. /* int both_fields; */
  1058. em2820_videodbg("%s: type=%s",
  1059. cmd ==
  1060. VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :
  1061. "VIDIOC_S_FMT",
  1062. format->type ==
  1063. V4L2_BUF_TYPE_VIDEO_CAPTURE ?
  1064. "V4L2_BUF_TYPE_VIDEO_CAPTURE" : format->type ==
  1065. V4L2_BUF_TYPE_VBI_CAPTURE ?
  1066. "V4L2_BUF_TYPE_VBI_CAPTURE " :
  1067. "not supported");
  1068. if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1069. return -EINVAL;
  1070. em2820_videodbg("%s: requested %dx%d",
  1071. cmd ==
  1072. VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :
  1073. "VIDIOC_S_FMT", format->fmt.pix.width,
  1074. format->fmt.pix.height);
  1075. /* FIXME: Move some code away from here */
  1076. /* width must even because of the YUYV format */
  1077. /* height must be even because of interlacing */
  1078. height &= 0xfffe;
  1079. width &= 0xfffe;
  1080. if (height < 32)
  1081. height = 32;
  1082. if (height > maxh)
  1083. height = maxh;
  1084. if (width < 48)
  1085. width = 48;
  1086. if (width > maxw)
  1087. width = maxw;
  1088. /* FIXME*/
  1089. if(dev->is_em2800){
  1090. /* we only know how to scale to 50% */
  1091. if(height % (maxh / 2))
  1092. height=maxh;
  1093. if(width % (maxw / 2))
  1094. width=maxw;
  1095. /* larger resoltion don't seem to work either */
  1096. if(width == maxw && height == maxh)
  1097. width /= 2;
  1098. }
  1099. if ((hscale =
  1100. (((unsigned long)maxw) << 12) / width - 4096L) >=
  1101. 0x4000)
  1102. hscale = 0x3fff;
  1103. width =
  1104. (((unsigned long)maxw) << 12) / (hscale + 4096L);
  1105. if ((vscale =
  1106. (((unsigned long)maxh) << 12) / height - 4096L) >=
  1107. 0x4000)
  1108. vscale = 0x3fff;
  1109. height =
  1110. (((unsigned long)maxh) << 12) / (vscale + 4096L);
  1111. format->fmt.pix.width = width;
  1112. format->fmt.pix.height = height;
  1113. format->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
  1114. format->fmt.pix.bytesperline = width * 2;
  1115. format->fmt.pix.sizeimage = width * 2 * height;
  1116. format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  1117. format->fmt.pix.field = V4L2_FIELD_INTERLACED;
  1118. em2820_videodbg("%s: returned %dx%d (%d, %d)",
  1119. cmd ==
  1120. VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" :
  1121. "VIDIOC_S_FMT", format->fmt.pix.width,
  1122. format->fmt.pix.height, hscale, vscale);
  1123. if (cmd == VIDIOC_TRY_FMT)
  1124. return 0;
  1125. for (i = 0; i < dev->num_frames; i++)
  1126. if (dev->frame[i].vma_use_count) {
  1127. em2820_videodbg("VIDIOC_S_FMT failed. "
  1128. "Unmap the buffers first.");
  1129. return -EINVAL;
  1130. }
  1131. /* stop io in case it is already in progress */
  1132. if (dev->stream == STREAM_ON) {
  1133. em2820_videodbg("VIDIOC_SET_FMT: interupting stream");
  1134. if ((ret = em2820_stream_interrupt(dev)))
  1135. return ret;
  1136. }
  1137. em2820_release_buffers(dev);
  1138. dev->io = IO_NONE;
  1139. /* set new image size */
  1140. dev->width = width;
  1141. dev->height = height;
  1142. dev->frame_size = dev->width * dev->height * 2;
  1143. dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
  1144. dev->bytesperline = dev->width * 2;
  1145. dev->hscale = hscale;
  1146. dev->vscale = vscale;
  1147. /* dev->both_fileds = both_fileds; */
  1148. em2820_uninit_isoc(dev);
  1149. em2820_set_alternate(dev);
  1150. em2820_capture_start(dev, 1);
  1151. em2820_resolution_set(dev);
  1152. em2820_init_isoc(dev);
  1153. return 0;
  1154. }
  1155. /* --- streaming capture ------------------------------------- */
  1156. case VIDIOC_REQBUFS:
  1157. {
  1158. struct v4l2_requestbuffers *rb = arg;
  1159. u32 i;
  1160. int ret;
  1161. if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  1162. rb->memory != V4L2_MEMORY_MMAP)
  1163. return -EINVAL;
  1164. if (dev->io == IO_READ) {
  1165. em2820_videodbg ("method is set to read;"
  1166. " close and open the device again to"
  1167. " choose the mmap I/O method");
  1168. return -EINVAL;
  1169. }
  1170. for (i = 0; i < dev->num_frames; i++)
  1171. if (dev->frame[i].vma_use_count) {
  1172. em2820_videodbg ("VIDIOC_REQBUFS failed; previous buffers are still mapped");
  1173. return -EINVAL;
  1174. }
  1175. if (dev->stream == STREAM_ON) {
  1176. em2820_videodbg("VIDIOC_REQBUFS: interrupting stream");
  1177. if ((ret = em2820_stream_interrupt(dev)))
  1178. return ret;
  1179. }
  1180. em2820_empty_framequeues(dev);
  1181. em2820_release_buffers(dev);
  1182. if (rb->count)
  1183. rb->count =
  1184. em2820_request_buffers(dev, rb->count);
  1185. dev->frame_current = NULL;
  1186. em2820_videodbg ("VIDIOC_REQBUFS: setting io method to mmap: num bufs %i",
  1187. rb->count);
  1188. dev->io = rb->count ? IO_MMAP : IO_NONE;
  1189. return 0;
  1190. }
  1191. case VIDIOC_QUERYBUF:
  1192. {
  1193. struct v4l2_buffer *b = arg;
  1194. if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  1195. b->index >= dev->num_frames || dev->io != IO_MMAP)
  1196. return -EINVAL;
  1197. memcpy(b, &dev->frame[b->index].buf, sizeof(*b));
  1198. if (dev->frame[b->index].vma_use_count) {
  1199. b->flags |= V4L2_BUF_FLAG_MAPPED;
  1200. }
  1201. if (dev->frame[b->index].state == F_DONE)
  1202. b->flags |= V4L2_BUF_FLAG_DONE;
  1203. else if (dev->frame[b->index].state != F_UNUSED)
  1204. b->flags |= V4L2_BUF_FLAG_QUEUED;
  1205. return 0;
  1206. }
  1207. case VIDIOC_QBUF:
  1208. {
  1209. struct v4l2_buffer *b = arg;
  1210. unsigned long lock_flags;
  1211. if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
  1212. b->index >= dev->num_frames || dev->io != IO_MMAP) {
  1213. return -EINVAL;
  1214. }
  1215. if (dev->frame[b->index].state != F_UNUSED) {
  1216. return -EAGAIN;
  1217. }
  1218. dev->frame[b->index].state = F_QUEUED;
  1219. /* add frame to fifo */
  1220. spin_lock_irqsave(&dev->queue_lock, lock_flags);
  1221. list_add_tail(&dev->frame[b->index].frame,
  1222. &dev->inqueue);
  1223. spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
  1224. return 0;
  1225. }
  1226. case VIDIOC_DQBUF:
  1227. {
  1228. struct v4l2_buffer *b = arg;
  1229. struct em2820_frame_t *f;
  1230. unsigned long lock_flags;
  1231. int ret = 0;
  1232. if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE
  1233. || dev->io != IO_MMAP)
  1234. return -EINVAL;
  1235. if (list_empty(&dev->outqueue)) {
  1236. if (dev->stream == STREAM_OFF)
  1237. return -EINVAL;
  1238. if (filp->f_flags & O_NONBLOCK)
  1239. return -EAGAIN;
  1240. ret = wait_event_interruptible
  1241. (dev->wait_frame,
  1242. (!list_empty(&dev->outqueue)) ||
  1243. (dev->state & DEV_DISCONNECTED));
  1244. if (ret)
  1245. return ret;
  1246. if (dev->state & DEV_DISCONNECTED)
  1247. return -ENODEV;
  1248. }
  1249. spin_lock_irqsave(&dev->queue_lock, lock_flags);
  1250. f = list_entry(dev->outqueue.next,
  1251. struct em2820_frame_t, frame);
  1252. list_del(dev->outqueue.next);
  1253. spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
  1254. f->state = F_UNUSED;
  1255. memcpy(b, &f->buf, sizeof(*b));
  1256. if (f->vma_use_count)
  1257. b->flags |= V4L2_BUF_FLAG_MAPPED;
  1258. return 0;
  1259. }
  1260. default:
  1261. return em2820_do_ioctl(inode, filp, dev, cmd, arg,
  1262. em2820_video_do_ioctl);
  1263. }
  1264. return 0;
  1265. }
  1266. /*
  1267. * em2820_v4l2_ioctl()
  1268. * handle v4l2 ioctl the main action happens in em2820_v4l2_do_ioctl()
  1269. */
  1270. static int em2820_v4l2_ioctl(struct inode *inode, struct file *filp,
  1271. unsigned int cmd, unsigned long arg)
  1272. {
  1273. int ret = 0;
  1274. struct em2820 *dev = filp->private_data;
  1275. if (down_interruptible(&dev->fileop_lock))
  1276. return -ERESTARTSYS;
  1277. if (dev->state & DEV_DISCONNECTED) {
  1278. em2820_errdev("v4l2 ioctl: device not present\n");
  1279. up(&dev->fileop_lock);
  1280. return -ENODEV;
  1281. }
  1282. if (dev->state & DEV_MISCONFIGURED) {
  1283. em2820_errdev
  1284. ("v4l2 ioctl: device is misconfigured; close and open it again\n");
  1285. up(&dev->fileop_lock);
  1286. return -EIO;
  1287. }
  1288. ret = video_usercopy(inode, filp, cmd, arg, em2820_video_do_ioctl);
  1289. up(&dev->fileop_lock);
  1290. return ret;
  1291. }
  1292. static struct file_operations em2820_v4l_fops = {
  1293. .owner = THIS_MODULE,
  1294. .open = em2820_v4l2_open,
  1295. .release = em2820_v4l2_close,
  1296. .ioctl = em2820_v4l2_ioctl,
  1297. .read = em2820_v4l2_read,
  1298. .poll = em2820_v4l2_poll,
  1299. .mmap = em2820_v4l2_mmap,
  1300. .llseek = no_llseek,
  1301. };
  1302. /******************************** usb interface *****************************************/
  1303. /*
  1304. * em2820_init_dev()
  1305. * allocates and inits the device structs, registers i2c bus and v4l device
  1306. */
  1307. static int em2820_init_dev(struct em2820 **devhandle, struct usb_device *udev,
  1308. int minor, int model)
  1309. {
  1310. struct em2820 *dev = *devhandle;
  1311. int retval = -ENOMEM;
  1312. int errCode, i;
  1313. unsigned int maxh, maxw;
  1314. struct usb_interface *uif;
  1315. dev->udev = udev;
  1316. dev->model = model;
  1317. init_MUTEX(&dev->lock);
  1318. init_waitqueue_head(&dev->open);
  1319. dev->em2820_write_regs = em2820_write_regs;
  1320. dev->em2820_read_reg = em2820_read_reg;
  1321. dev->em2820_read_reg_req_len = em2820_read_reg_req_len;
  1322. dev->em2820_write_regs_req = em2820_write_regs_req;
  1323. dev->em2820_read_reg_req = em2820_read_reg_req;
  1324. dev->is_em2800 = em2820_boards[model].is_em2800;
  1325. dev->has_tuner = em2820_boards[model].has_tuner;
  1326. dev->has_msp34xx = em2820_boards[model].has_msp34xx;
  1327. dev->tda9887_conf = em2820_boards[model].tda9887_conf;
  1328. dev->decoder = em2820_boards[model].decoder;
  1329. if (tuner >= 0)
  1330. dev->tuner_type = tuner;
  1331. else
  1332. dev->tuner_type = em2820_boards[model].tuner_type;
  1333. dev->video_inputs = em2820_boards[model].vchannels;
  1334. for (i = 0; i < TVNORMS; i++)
  1335. if (em2820_boards[model].norm == tvnorms[i].mode)
  1336. break;
  1337. if (i == TVNORMS)
  1338. i = 0;
  1339. dev->tvnorm = &tvnorms[i]; /* set default norm */
  1340. em2820_videodbg("tvnorm=%s\n", dev->tvnorm->name);
  1341. maxw = norm_maxw(dev);
  1342. maxh = norm_maxh(dev);
  1343. /* set default image size */
  1344. dev->width = maxw;
  1345. dev->height = maxh;
  1346. dev->interlaced = EM2820_INTERLACED_DEFAULT;
  1347. dev->field_size = dev->width * dev->height;
  1348. dev->frame_size =
  1349. dev->interlaced ? dev->field_size << 1 : dev->field_size;
  1350. dev->bytesperline = dev->width * 2;
  1351. dev->hscale = 0;
  1352. dev->vscale = 0;
  1353. dev->ctl_input = 2;
  1354. /* setup video picture settings for saa7113h */
  1355. memset(&dev->vpic, 0, sizeof(dev->vpic));
  1356. dev->vpic.colour = 128 << 8;
  1357. dev->vpic.hue = 128 << 8;
  1358. dev->vpic.brightness = 128 << 8;
  1359. dev->vpic.contrast = 192 << 8;
  1360. dev->vpic.whiteness = 128 << 8; /* This one isn't used */
  1361. dev->vpic.depth = 16;
  1362. dev->vpic.palette = VIDEO_PALETTE_YUV422;
  1363. /* compute alternate max packet sizes */
  1364. uif = dev->udev->actconfig->interface[0];
  1365. dev->alt_max_pkt_size[0] = 0;
  1366. for (i = 1; i <= EM2820_MAX_ALT && i < uif->num_altsetting ; i++) {
  1367. u16 tmp =
  1368. le16_to_cpu(uif->altsetting[i].endpoint[1].desc.
  1369. wMaxPacketSize);
  1370. dev->alt_max_pkt_size[i] =
  1371. (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
  1372. }
  1373. #ifdef CONFIG_MODULES
  1374. /* request some modules */
  1375. if (dev->decoder == EM2820_SAA7113)
  1376. request_module("saa7113");
  1377. if (dev->decoder == EM2820_SAA7114)
  1378. request_module("saa7114");
  1379. if (dev->decoder == EM2820_TVP5150)
  1380. request_module("tvp5150");
  1381. if (dev->has_tuner)
  1382. request_module("tuner");
  1383. if (dev->tda9887_conf)
  1384. request_module("tda9887");
  1385. #endif
  1386. errCode = em2820_config(dev);
  1387. if (errCode) {
  1388. em2820_errdev("error configuring device\n");
  1389. kfree(dev);
  1390. return -ENOMEM;
  1391. }
  1392. down(&dev->lock);
  1393. /* register i2c bus */
  1394. em2820_i2c_register(dev);
  1395. /* Do board specific init and eeprom reading */
  1396. em2820_card_setup(dev);
  1397. /* configure the device */
  1398. em2820_config_i2c(dev);
  1399. up(&dev->lock);
  1400. errCode = em2820_config(dev);
  1401. #ifdef CONFIG_MODULES
  1402. if (dev->has_msp34xx)
  1403. request_module("msp3400");
  1404. #endif
  1405. /* allocate and fill v4l2 device struct */
  1406. dev->vdev = video_device_alloc();
  1407. if (NULL == dev->vdev) {
  1408. em2820_errdev("cannot allocate video_device.\n");
  1409. kfree(dev);
  1410. return -ENOMEM;
  1411. }
  1412. dev->vdev->type = VID_TYPE_CAPTURE;
  1413. if (dev->has_tuner)
  1414. dev->vdev->type |= VID_TYPE_TUNER;
  1415. dev->vdev->hardware = 0;
  1416. dev->vdev->fops = &em2820_v4l_fops;
  1417. dev->vdev->minor = -1;
  1418. dev->vdev->dev = &dev->udev->dev;
  1419. dev->vdev->release = video_device_release;
  1420. snprintf(dev->vdev->name, sizeof(dev->vdev->name), "%s",
  1421. "em2820 video");
  1422. list_add_tail(&dev->devlist,&em2820_devlist);
  1423. /* register v4l2 device */
  1424. down(&dev->lock);
  1425. if ((retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1))) {
  1426. em2820_errdev("unable to register video device (error=%i).\n",
  1427. retval);
  1428. up(&dev->lock);
  1429. list_del(&dev->devlist);
  1430. video_device_release(dev->vdev);
  1431. kfree(dev);
  1432. return -ENODEV;
  1433. }
  1434. if (dev->has_msp34xx) {
  1435. /* Send a reset to other chips via gpio */
  1436. em2820_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
  1437. udelay(2500);
  1438. em2820_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
  1439. udelay(2500);
  1440. }
  1441. video_mux(dev, 0);
  1442. up(&dev->lock);
  1443. em2820_info("V4L2 device registered as /dev/video%d\n",
  1444. dev->vdev->minor);
  1445. return 0;
  1446. }
  1447. /*
  1448. * em2820_usb_probe()
  1449. * checks for supported devices
  1450. */
  1451. static int em2820_usb_probe(struct usb_interface *interface,
  1452. const struct usb_device_id *id)
  1453. {
  1454. const struct usb_endpoint_descriptor *endpoint;
  1455. struct usb_device *udev;
  1456. struct em2820 *dev = NULL;
  1457. int retval = -ENODEV;
  1458. int model,i,nr,ifnum;
  1459. udev = usb_get_dev(interface_to_usbdev(interface));
  1460. ifnum = interface->altsetting[0].desc.bInterfaceNumber;
  1461. em2820_err(DRIVER_NAME " new device (%04x:%04x): interface %i, class %i\n",
  1462. udev->descriptor.idVendor,udev->descriptor.idProduct,
  1463. ifnum,
  1464. interface->altsetting[0].desc.bInterfaceClass);
  1465. /* Don't register audio interfaces */
  1466. if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO)
  1467. return -ENODEV;
  1468. endpoint = &interface->cur_altsetting->endpoint[1].desc;
  1469. /* check if the the device has the iso in endpoint at the correct place */
  1470. if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
  1471. USB_ENDPOINT_XFER_ISOC) {
  1472. em2820_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n");
  1473. return -ENODEV;
  1474. }
  1475. if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
  1476. em2820_err(DRIVER_NAME " probing error: endpoint is ISO OUT endpoint!\n");
  1477. return -ENODEV;
  1478. }
  1479. model=id->driver_info;
  1480. nr=interface->minor;
  1481. if (nr>EM2820_MAXBOARDS) {
  1482. printk ("em2820: Supports only %i em28xx boards.\n",EM2820_MAXBOARDS);
  1483. return -ENOMEM;
  1484. }
  1485. /* allocate memory for our device state and initialize it */
  1486. dev = kmalloc(sizeof(*dev), GFP_KERNEL);
  1487. if (dev == NULL) {
  1488. em2820_err(DRIVER_NAME ": out of memory!\n");
  1489. return -ENOMEM;
  1490. }
  1491. memset(dev, 0, sizeof(*dev));
  1492. snprintf(dev->name, 29, "em2820 #%d", nr);
  1493. if ((card[nr]>=0)&&(card[nr]<em2820_bcount))
  1494. model=card[nr];
  1495. if ((model==EM2800_BOARD_UNKNOWN)||(model==EM2820_BOARD_UNKNOWN)) {
  1496. printk( "%s: Your board has no eeprom inside it and thus can't\n"
  1497. "%s: be autodetected. Please pass card=<n> insmod option to\n"
  1498. "%s: workaround that. Redirect complaints to the vendor of\n"
  1499. "%s: the TV card. Best regards,\n"
  1500. "%s: -- tux\n",
  1501. dev->name,dev->name,dev->name,dev->name,dev->name);
  1502. printk("%s: Here is a list of valid choices for the card=<n> insmod option:\n",
  1503. dev->name);
  1504. for (i = 0; i < em2820_bcount; i++) {
  1505. printk("%s: card=%d -> %s\n",
  1506. dev->name, i, em2820_boards[i].name);
  1507. }
  1508. }
  1509. /* allocate device struct */
  1510. retval = em2820_init_dev(&dev, udev, nr, model);
  1511. if (retval)
  1512. return retval;
  1513. em2820_info("Found %s\n", em2820_boards[model].name);
  1514. /* save our data pointer in this interface device */
  1515. usb_set_intfdata(interface, dev);
  1516. return 0;
  1517. }
  1518. /*
  1519. * em2820_usb_disconnect()
  1520. * called when the device gets diconencted
  1521. * video device will be unregistered on v4l2_close in case it is still open
  1522. */
  1523. static void em2820_usb_disconnect(struct usb_interface *interface)
  1524. {
  1525. struct em2820 *dev = usb_get_intfdata(interface);
  1526. usb_set_intfdata(interface, NULL);
  1527. if (!dev)
  1528. return;
  1529. down_write(&em2820_disconnect);
  1530. down(&dev->lock);
  1531. em2820_info("disconnecting %s\n", dev->vdev->name);
  1532. wake_up_interruptible_all(&dev->open);
  1533. if (dev->users) {
  1534. em2820_warn
  1535. ("device /dev/video%d is open! Deregistration and memory "
  1536. "deallocation are deferred on close.\n", dev->vdev->minor);
  1537. dev->state |= DEV_MISCONFIGURED;
  1538. em2820_uninit_isoc(dev);
  1539. dev->state |= DEV_DISCONNECTED;
  1540. wake_up_interruptible(&dev->wait_frame);
  1541. wake_up_interruptible(&dev->wait_stream);
  1542. } else {
  1543. dev->state |= DEV_DISCONNECTED;
  1544. em2820_release_resources(dev);
  1545. }
  1546. up(&dev->lock);
  1547. if (!dev->users)
  1548. kfree(dev);
  1549. up_write(&em2820_disconnect);
  1550. }
  1551. static struct usb_driver em2820_usb_driver = {
  1552. .owner = THIS_MODULE,
  1553. .name = "em2820",
  1554. .probe = em2820_usb_probe,
  1555. .disconnect = em2820_usb_disconnect,
  1556. .id_table = em2820_id_table,
  1557. };
  1558. static int __init em2820_module_init(void)
  1559. {
  1560. int result;
  1561. printk(KERN_INFO DRIVER_NAME " v4l2 driver version %d.%d.%d loaded\n",
  1562. (EM2820_VERSION_CODE >> 16) & 0xff,
  1563. (EM2820_VERSION_CODE >> 8) & 0xff, EM2820_VERSION_CODE & 0xff);
  1564. #ifdef SNAPSHOT
  1565. printk(KERN_INFO DRIVER_NAME " snapshot date %04d-%02d-%02d\n",
  1566. SNAPSHOT / 10000, (SNAPSHOT / 100) % 100, SNAPSHOT % 100);
  1567. #endif
  1568. /* register this driver with the USB subsystem */
  1569. result = usb_register(&em2820_usb_driver);
  1570. if (result)
  1571. em2820_err(DRIVER_NAME
  1572. " usb_register failed. Error number %d.\n", result);
  1573. return result;
  1574. }
  1575. static void __exit em2820_module_exit(void)
  1576. {
  1577. /* deregister this driver with the USB subsystem */
  1578. usb_deregister(&em2820_usb_driver);
  1579. }
  1580. module_init(em2820_module_init);
  1581. module_exit(em2820_module_exit);