em28xx-video.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457
  1. /*
  2. em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB
  3. video capture devices
  4. Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
  5. Markus Rechberger <mrechberger@gmail.com>
  6. Mauro Carvalho Chehab <mchehab@infradead.org>
  7. Sascha Sommer <saschasommer@freenet.de>
  8. Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
  9. Some parts based on SN9C10x PC Camera Controllers GPL driver made
  10. by Luca Risolia <luca.risolia@studio.unibo.it>
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <linux/init.h>
  24. #include <linux/list.h>
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/bitmap.h>
  28. #include <linux/usb.h>
  29. #include <linux/i2c.h>
  30. #include <linux/mm.h>
  31. #include <linux/mutex.h>
  32. #include <linux/slab.h>
  33. #include "em28xx.h"
  34. #include <media/v4l2-common.h>
  35. #include <media/v4l2-ioctl.h>
  36. #include <media/v4l2-chip-ident.h>
  37. #include <media/msp3400.h>
  38. #include <media/tuner.h>
  39. #define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \
  40. "Markus Rechberger <mrechberger@gmail.com>, " \
  41. "Mauro Carvalho Chehab <mchehab@infradead.org>, " \
  42. "Sascha Sommer <saschasommer@freenet.de>"
  43. #define DRIVER_DESC "Empia em28xx based USB video device driver"
  44. #define EM28XX_VERSION "0.1.3"
  45. #define em28xx_videodbg(fmt, arg...) do {\
  46. if (video_debug) \
  47. printk(KERN_INFO "%s %s :"fmt, \
  48. dev->name, __func__ , ##arg); } while (0)
  49. static unsigned int isoc_debug;
  50. module_param(isoc_debug, int, 0644);
  51. MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]");
  52. #define em28xx_isocdbg(fmt, arg...) \
  53. do {\
  54. if (isoc_debug) { \
  55. printk(KERN_INFO "%s %s :"fmt, \
  56. dev->name, __func__ , ##arg); \
  57. } \
  58. } while (0)
  59. MODULE_AUTHOR(DRIVER_AUTHOR);
  60. MODULE_DESCRIPTION(DRIVER_DESC);
  61. MODULE_LICENSE("GPL");
  62. MODULE_VERSION(EM28XX_VERSION);
  63. static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
  64. static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
  65. static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
  66. module_param_array(video_nr, int, NULL, 0444);
  67. module_param_array(vbi_nr, int, NULL, 0444);
  68. module_param_array(radio_nr, int, NULL, 0444);
  69. MODULE_PARM_DESC(video_nr, "video device numbers");
  70. MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
  71. MODULE_PARM_DESC(radio_nr, "radio device numbers");
  72. static unsigned int video_debug;
  73. module_param(video_debug, int, 0644);
  74. MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
  75. /* supported video standards */
  76. static struct em28xx_fmt format[] = {
  77. {
  78. .name = "16 bpp YUY2, 4:2:2, packed",
  79. .fourcc = V4L2_PIX_FMT_YUYV,
  80. .depth = 16,
  81. .reg = EM28XX_OUTFMT_YUV422_Y0UY1V,
  82. }, {
  83. .name = "16 bpp RGB 565, LE",
  84. .fourcc = V4L2_PIX_FMT_RGB565,
  85. .depth = 16,
  86. .reg = EM28XX_OUTFMT_RGB_16_656,
  87. }, {
  88. .name = "8 bpp Bayer BGBG..GRGR",
  89. .fourcc = V4L2_PIX_FMT_SBGGR8,
  90. .depth = 8,
  91. .reg = EM28XX_OUTFMT_RGB_8_BGBG,
  92. }, {
  93. .name = "8 bpp Bayer GRGR..BGBG",
  94. .fourcc = V4L2_PIX_FMT_SGRBG8,
  95. .depth = 8,
  96. .reg = EM28XX_OUTFMT_RGB_8_GRGR,
  97. }, {
  98. .name = "8 bpp Bayer GBGB..RGRG",
  99. .fourcc = V4L2_PIX_FMT_SGBRG8,
  100. .depth = 8,
  101. .reg = EM28XX_OUTFMT_RGB_8_GBGB,
  102. }, {
  103. .name = "12 bpp YUV411",
  104. .fourcc = V4L2_PIX_FMT_YUV411P,
  105. .depth = 12,
  106. .reg = EM28XX_OUTFMT_YUV411,
  107. },
  108. };
  109. /* supported controls */
  110. /* Common to all boards */
  111. static struct v4l2_queryctrl ac97_qctrl[] = {
  112. {
  113. .id = V4L2_CID_AUDIO_VOLUME,
  114. .type = V4L2_CTRL_TYPE_INTEGER,
  115. .name = "Volume",
  116. .minimum = 0x0,
  117. .maximum = 0x1f,
  118. .step = 0x1,
  119. .default_value = 0x1f,
  120. .flags = V4L2_CTRL_FLAG_SLIDER,
  121. }, {
  122. .id = V4L2_CID_AUDIO_MUTE,
  123. .type = V4L2_CTRL_TYPE_BOOLEAN,
  124. .name = "Mute",
  125. .minimum = 0,
  126. .maximum = 1,
  127. .step = 1,
  128. .default_value = 1,
  129. .flags = 0,
  130. }
  131. };
  132. /* ------------------------------------------------------------------
  133. DMA and thread functions
  134. ------------------------------------------------------------------*/
  135. /*
  136. * Finish the current buffer
  137. */
  138. static inline void finish_buffer(struct em28xx *dev,
  139. struct em28xx_buffer *buf)
  140. {
  141. em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
  142. buf->vb.state = VIDEOBUF_DONE;
  143. buf->vb.field_count++;
  144. v4l2_get_timestamp(&buf->vb.ts);
  145. list_del(&buf->vb.queue);
  146. wake_up(&buf->vb.done);
  147. }
  148. /*
  149. * Identify the buffer header type and properly handles
  150. */
  151. static void em28xx_copy_video(struct em28xx *dev,
  152. struct em28xx_buffer *buf,
  153. unsigned char *p,
  154. unsigned char *outp, unsigned long len)
  155. {
  156. void *fieldstart, *startwrite, *startread;
  157. int linesdone, currlinedone, offset, lencopy, remain;
  158. int bytesperline = dev->width << 1;
  159. if (buf->pos + len > buf->vb.size)
  160. len = buf->vb.size - buf->pos;
  161. startread = p;
  162. remain = len;
  163. if (dev->progressive || buf->top_field)
  164. fieldstart = outp;
  165. else /* interlaced mode, even nr. of lines */
  166. fieldstart = outp + bytesperline;
  167. linesdone = buf->pos / bytesperline;
  168. currlinedone = buf->pos % bytesperline;
  169. if (dev->progressive)
  170. offset = linesdone * bytesperline + currlinedone;
  171. else
  172. offset = linesdone * bytesperline * 2 + currlinedone;
  173. startwrite = fieldstart + offset;
  174. lencopy = bytesperline - currlinedone;
  175. lencopy = lencopy > remain ? remain : lencopy;
  176. if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
  177. em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
  178. ((char *)startwrite + lencopy) -
  179. ((char *)outp + buf->vb.size));
  180. remain = (char *)outp + buf->vb.size - (char *)startwrite;
  181. lencopy = remain;
  182. }
  183. if (lencopy <= 0)
  184. return;
  185. memcpy(startwrite, startread, lencopy);
  186. remain -= lencopy;
  187. while (remain > 0) {
  188. if (dev->progressive)
  189. startwrite += lencopy;
  190. else
  191. startwrite += lencopy + bytesperline;
  192. startread += lencopy;
  193. if (bytesperline > remain)
  194. lencopy = remain;
  195. else
  196. lencopy = bytesperline;
  197. if ((char *)startwrite + lencopy > (char *)outp +
  198. buf->vb.size) {
  199. em28xx_isocdbg("Overflow of %zi bytes past buffer end"
  200. "(2)\n",
  201. ((char *)startwrite + lencopy) -
  202. ((char *)outp + buf->vb.size));
  203. lencopy = remain = (char *)outp + buf->vb.size -
  204. (char *)startwrite;
  205. }
  206. if (lencopy <= 0)
  207. break;
  208. memcpy(startwrite, startread, lencopy);
  209. remain -= lencopy;
  210. }
  211. buf->pos += len;
  212. }
  213. static void em28xx_copy_vbi(struct em28xx *dev,
  214. struct em28xx_buffer *buf,
  215. unsigned char *p,
  216. unsigned char *outp, unsigned long len)
  217. {
  218. void *startwrite, *startread;
  219. int offset;
  220. int bytesperline;
  221. if (dev == NULL) {
  222. em28xx_isocdbg("dev is null\n");
  223. return;
  224. }
  225. bytesperline = dev->vbi_width;
  226. if (buf == NULL) {
  227. return;
  228. }
  229. if (p == NULL) {
  230. em28xx_isocdbg("p is null\n");
  231. return;
  232. }
  233. if (outp == NULL) {
  234. em28xx_isocdbg("outp is null\n");
  235. return;
  236. }
  237. if (buf->pos + len > buf->vb.size)
  238. len = buf->vb.size - buf->pos;
  239. startread = p;
  240. startwrite = outp + buf->pos;
  241. offset = buf->pos;
  242. /* Make sure the bottom field populates the second half of the frame */
  243. if (buf->top_field == 0) {
  244. startwrite += bytesperline * dev->vbi_height;
  245. offset += bytesperline * dev->vbi_height;
  246. }
  247. memcpy(startwrite, startread, len);
  248. buf->pos += len;
  249. }
  250. static inline void print_err_status(struct em28xx *dev,
  251. int packet, int status)
  252. {
  253. char *errmsg = "Unknown";
  254. switch (status) {
  255. case -ENOENT:
  256. errmsg = "unlinked synchronuously";
  257. break;
  258. case -ECONNRESET:
  259. errmsg = "unlinked asynchronuously";
  260. break;
  261. case -ENOSR:
  262. errmsg = "Buffer error (overrun)";
  263. break;
  264. case -EPIPE:
  265. errmsg = "Stalled (device not responding)";
  266. break;
  267. case -EOVERFLOW:
  268. errmsg = "Babble (bad cable?)";
  269. break;
  270. case -EPROTO:
  271. errmsg = "Bit-stuff error (bad cable?)";
  272. break;
  273. case -EILSEQ:
  274. errmsg = "CRC/Timeout (could be anything)";
  275. break;
  276. case -ETIME:
  277. errmsg = "Device does not respond";
  278. break;
  279. }
  280. if (packet < 0) {
  281. em28xx_isocdbg("URB status %d [%s].\n", status, errmsg);
  282. } else {
  283. em28xx_isocdbg("URB packet %d, status %d [%s].\n",
  284. packet, status, errmsg);
  285. }
  286. }
  287. /*
  288. * get the next available buffer from dma queue
  289. */
  290. static inline struct em28xx_buffer *get_next_buf(struct em28xx *dev,
  291. struct em28xx_dmaqueue *dma_q)
  292. {
  293. struct em28xx_buffer *buf;
  294. char *outp;
  295. if (list_empty(&dma_q->active)) {
  296. em28xx_isocdbg("No active queue to serve\n");
  297. return NULL;
  298. }
  299. /* Get the next buffer */
  300. buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
  301. /* Cleans up buffer - Useful for testing for frame/URB loss */
  302. outp = videobuf_to_vmalloc(&buf->vb);
  303. memset(outp, 0, buf->vb.size);
  304. buf->pos = 0;
  305. return buf;
  306. }
  307. /* Processes and copies the URB data content (video and VBI data) */
  308. static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb)
  309. {
  310. struct em28xx_buffer *buf, *vbi_buf;
  311. struct em28xx_dmaqueue *dma_q = &dev->vidq;
  312. struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq;
  313. int xfer_bulk, num_packets, i, rc = 1;
  314. unsigned int actual_length, len = 0;
  315. unsigned char *p, *outp = NULL, *vbioutp = NULL;
  316. if (!dev)
  317. return 0;
  318. if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
  319. return 0;
  320. if (urb->status < 0)
  321. print_err_status(dev, -1, urb->status);
  322. xfer_bulk = usb_pipebulk(urb->pipe);
  323. buf = dev->usb_ctl.vid_buf;
  324. if (buf != NULL)
  325. outp = videobuf_to_vmalloc(&buf->vb);
  326. vbi_buf = dev->usb_ctl.vbi_buf;
  327. if (vbi_buf != NULL)
  328. vbioutp = videobuf_to_vmalloc(&vbi_buf->vb);
  329. if (xfer_bulk) /* bulk */
  330. num_packets = 1;
  331. else /* isoc */
  332. num_packets = urb->number_of_packets;
  333. for (i = 0; i < num_packets; i++) {
  334. if (xfer_bulk) { /* bulk */
  335. actual_length = urb->actual_length;
  336. p = urb->transfer_buffer;
  337. } else { /* isoc */
  338. if (urb->iso_frame_desc[i].status < 0) {
  339. print_err_status(dev, i,
  340. urb->iso_frame_desc[i].status);
  341. if (urb->iso_frame_desc[i].status != -EPROTO)
  342. continue;
  343. }
  344. actual_length = urb->iso_frame_desc[i].actual_length;
  345. if (actual_length > dev->max_pkt_size) {
  346. em28xx_isocdbg("packet bigger than packet size");
  347. continue;
  348. }
  349. p = urb->transfer_buffer +
  350. urb->iso_frame_desc[i].offset;
  351. }
  352. if (actual_length == 0) {
  353. /* NOTE: happens very often with isoc transfers */
  354. /* em28xx_usbdbg("packet %d is empty",i); - spammy */
  355. continue;
  356. }
  357. /* capture type 0 = vbi start
  358. capture type 1 = video start
  359. capture type 2 = video in progress */
  360. len = actual_length;
  361. if (len >= 4) {
  362. /* NOTE: headers are always 4 bytes and
  363. * never split across packets */
  364. if (p[0] == 0x33 && p[1] == 0x95) {
  365. dev->capture_type = 0;
  366. dev->vbi_read = 0;
  367. em28xx_isocdbg("VBI START HEADER!!!\n");
  368. dev->top_field = !(p[2] & 1);
  369. p += 4;
  370. len -= 4;
  371. } else if (p[0] == 0x88 && p[1] == 0x88 &&
  372. p[2] == 0x88 && p[3] == 0x88) {
  373. /* continuation */
  374. p += 4;
  375. len -= 4;
  376. } else if (p[0] == 0x22 && p[1] == 0x5a) {
  377. /* start video */
  378. dev->capture_type = 1;
  379. dev->top_field = !(p[2] & 1);
  380. p += 4;
  381. len -= 4;
  382. }
  383. }
  384. /* NOTE: with bulk transfers, intermediate data packets
  385. * have no continuation header */
  386. if (dev->capture_type == 0) {
  387. int vbi_size = dev->vbi_width * dev->vbi_height;
  388. if (dev->vbi_read >= vbi_size) {
  389. /* We've already read all the VBI data, so
  390. treat the rest as video */
  391. em28xx_isocdbg("dev->vbi_read > vbi_size\n");
  392. } else if ((dev->vbi_read + len) < vbi_size) {
  393. /* This entire frame is VBI data */
  394. if (dev->vbi_read == 0 && dev->top_field) {
  395. /* Brand new frame */
  396. if (vbi_buf != NULL)
  397. finish_buffer(dev, vbi_buf);
  398. vbi_buf = get_next_buf(dev, vbi_dma_q);
  399. dev->usb_ctl.vbi_buf = vbi_buf;
  400. if (vbi_buf == NULL)
  401. vbioutp = NULL;
  402. else
  403. vbioutp = videobuf_to_vmalloc(
  404. &vbi_buf->vb);
  405. }
  406. if (dev->vbi_read == 0) {
  407. if (vbi_buf != NULL) {
  408. vbi_buf->top_field
  409. = dev->top_field;
  410. vbi_buf->pos = 0;
  411. }
  412. }
  413. dev->vbi_read += len;
  414. em28xx_copy_vbi(dev, vbi_buf, p, vbioutp, len);
  415. } else {
  416. /* Some of this frame is VBI data and some is
  417. video data */
  418. int vbi_data_len = vbi_size - dev->vbi_read;
  419. dev->vbi_read += vbi_data_len;
  420. em28xx_copy_vbi(dev, vbi_buf, p, vbioutp,
  421. vbi_data_len);
  422. dev->capture_type = 1;
  423. p += vbi_data_len;
  424. len -= vbi_data_len;
  425. }
  426. }
  427. if (dev->capture_type == 1) {
  428. dev->capture_type = 2;
  429. if (dev->progressive || dev->top_field) {
  430. if (buf != NULL)
  431. finish_buffer(dev, buf);
  432. buf = get_next_buf(dev, dma_q);
  433. dev->usb_ctl.vid_buf = buf;
  434. if (buf == NULL)
  435. outp = NULL;
  436. else
  437. outp = videobuf_to_vmalloc(&buf->vb);
  438. }
  439. if (buf != NULL) {
  440. buf->top_field = dev->top_field;
  441. buf->pos = 0;
  442. }
  443. }
  444. if (buf != NULL && dev->capture_type == 2 && len > 0)
  445. em28xx_copy_video(dev, buf, p, outp, len);
  446. }
  447. return rc;
  448. }
  449. /* ------------------------------------------------------------------
  450. Videobuf operations
  451. ------------------------------------------------------------------*/
  452. static int
  453. buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
  454. {
  455. struct em28xx_fh *fh = vq->priv_data;
  456. struct em28xx *dev = fh->dev;
  457. struct v4l2_frequency f;
  458. *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)
  459. >> 3;
  460. if (0 == *count)
  461. *count = EM28XX_DEF_BUF;
  462. if (*count < EM28XX_MIN_BUF)
  463. *count = EM28XX_MIN_BUF;
  464. /* Ask tuner to go to analog or radio mode */
  465. memset(&f, 0, sizeof(f));
  466. f.frequency = dev->ctl_freq;
  467. f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  468. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
  469. return 0;
  470. }
  471. /* This is called *without* dev->slock held; please keep it that way */
  472. static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf)
  473. {
  474. struct em28xx_fh *fh = vq->priv_data;
  475. struct em28xx *dev = fh->dev;
  476. unsigned long flags = 0;
  477. if (in_interrupt())
  478. BUG();
  479. /* We used to wait for the buffer to finish here, but this didn't work
  480. because, as we were keeping the state as VIDEOBUF_QUEUED,
  481. videobuf_queue_cancel marked it as finished for us.
  482. (Also, it could wedge forever if the hardware was misconfigured.)
  483. This should be safe; by the time we get here, the buffer isn't
  484. queued anymore. If we ever start marking the buffers as
  485. VIDEOBUF_ACTIVE, it won't be, though.
  486. */
  487. spin_lock_irqsave(&dev->slock, flags);
  488. if (dev->usb_ctl.vid_buf == buf)
  489. dev->usb_ctl.vid_buf = NULL;
  490. spin_unlock_irqrestore(&dev->slock, flags);
  491. videobuf_vmalloc_free(&buf->vb);
  492. buf->vb.state = VIDEOBUF_NEEDS_INIT;
  493. }
  494. static int
  495. buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
  496. enum v4l2_field field)
  497. {
  498. struct em28xx_fh *fh = vq->priv_data;
  499. struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
  500. struct em28xx *dev = fh->dev;
  501. int rc = 0, urb_init = 0;
  502. buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth
  503. + 7) >> 3;
  504. if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
  505. return -EINVAL;
  506. buf->vb.width = dev->width;
  507. buf->vb.height = dev->height;
  508. buf->vb.field = field;
  509. if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
  510. rc = videobuf_iolock(vq, &buf->vb, NULL);
  511. if (rc < 0)
  512. goto fail;
  513. }
  514. if (!dev->usb_ctl.analog_bufs.num_bufs)
  515. urb_init = 1;
  516. if (urb_init) {
  517. dev->capture_type = -1;
  518. rc = em28xx_init_usb_xfer(dev, EM28XX_ANALOG_MODE,
  519. dev->analog_xfer_bulk,
  520. EM28XX_NUM_BUFS,
  521. dev->max_pkt_size,
  522. dev->packet_multiplier,
  523. em28xx_urb_data_copy);
  524. if (rc < 0)
  525. goto fail;
  526. }
  527. buf->vb.state = VIDEOBUF_PREPARED;
  528. return 0;
  529. fail:
  530. free_buffer(vq, buf);
  531. return rc;
  532. }
  533. static void
  534. buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
  535. {
  536. struct em28xx_buffer *buf = container_of(vb,
  537. struct em28xx_buffer,
  538. vb);
  539. struct em28xx_fh *fh = vq->priv_data;
  540. struct em28xx *dev = fh->dev;
  541. struct em28xx_dmaqueue *vidq = &dev->vidq;
  542. buf->vb.state = VIDEOBUF_QUEUED;
  543. list_add_tail(&buf->vb.queue, &vidq->active);
  544. }
  545. static void buffer_release(struct videobuf_queue *vq,
  546. struct videobuf_buffer *vb)
  547. {
  548. struct em28xx_buffer *buf = container_of(vb,
  549. struct em28xx_buffer,
  550. vb);
  551. struct em28xx_fh *fh = vq->priv_data;
  552. struct em28xx *dev = (struct em28xx *)fh->dev;
  553. em28xx_isocdbg("em28xx: called buffer_release\n");
  554. free_buffer(vq, buf);
  555. }
  556. static struct videobuf_queue_ops em28xx_video_qops = {
  557. .buf_setup = buffer_setup,
  558. .buf_prepare = buffer_prepare,
  559. .buf_queue = buffer_queue,
  560. .buf_release = buffer_release,
  561. };
  562. /********************* v4l2 interface **************************************/
  563. static void video_mux(struct em28xx *dev, int index)
  564. {
  565. dev->ctl_input = index;
  566. dev->ctl_ainput = INPUT(index)->amux;
  567. dev->ctl_aoutput = INPUT(index)->aout;
  568. if (!dev->ctl_aoutput)
  569. dev->ctl_aoutput = EM28XX_AOUT_MASTER;
  570. v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing,
  571. INPUT(index)->vmux, 0, 0);
  572. if (dev->board.has_msp34xx) {
  573. if (dev->i2s_speed) {
  574. v4l2_device_call_all(&dev->v4l2_dev, 0, audio,
  575. s_i2s_clock_freq, dev->i2s_speed);
  576. }
  577. /* Note: this is msp3400 specific */
  578. v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
  579. dev->ctl_ainput, MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
  580. }
  581. if (dev->board.adecoder != EM28XX_NOADECODER) {
  582. v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing,
  583. dev->ctl_ainput, dev->ctl_aoutput, 0);
  584. }
  585. em28xx_audio_analog_set(dev);
  586. }
  587. /* Usage lock check functions */
  588. static int res_get(struct em28xx_fh *fh, unsigned int bit)
  589. {
  590. struct em28xx *dev = fh->dev;
  591. if (fh->resources & bit)
  592. /* have it already allocated */
  593. return 1;
  594. /* is it free? */
  595. if (dev->resources & bit) {
  596. /* no, someone else uses it */
  597. return 0;
  598. }
  599. /* it's free, grab it */
  600. fh->resources |= bit;
  601. dev->resources |= bit;
  602. em28xx_videodbg("res: get %d\n", bit);
  603. return 1;
  604. }
  605. static int res_check(struct em28xx_fh *fh, unsigned int bit)
  606. {
  607. return fh->resources & bit;
  608. }
  609. static int res_locked(struct em28xx *dev, unsigned int bit)
  610. {
  611. return dev->resources & bit;
  612. }
  613. static void res_free(struct em28xx_fh *fh, unsigned int bits)
  614. {
  615. struct em28xx *dev = fh->dev;
  616. BUG_ON((fh->resources & bits) != bits);
  617. fh->resources &= ~bits;
  618. dev->resources &= ~bits;
  619. em28xx_videodbg("res: put %d\n", bits);
  620. }
  621. static int get_ressource(struct em28xx_fh *fh)
  622. {
  623. switch (fh->type) {
  624. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  625. return EM28XX_RESOURCE_VIDEO;
  626. case V4L2_BUF_TYPE_VBI_CAPTURE:
  627. return EM28XX_RESOURCE_VBI;
  628. default:
  629. BUG();
  630. return 0;
  631. }
  632. }
  633. /*
  634. * ac97_queryctrl()
  635. * return the ac97 supported controls
  636. */
  637. static int ac97_queryctrl(struct v4l2_queryctrl *qc)
  638. {
  639. int i;
  640. for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
  641. if (qc->id && qc->id == ac97_qctrl[i].id) {
  642. memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
  643. return 0;
  644. }
  645. }
  646. /* Control is not ac97 related */
  647. return 1;
  648. }
  649. /*
  650. * ac97_get_ctrl()
  651. * return the current values for ac97 mute and volume
  652. */
  653. static int ac97_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
  654. {
  655. switch (ctrl->id) {
  656. case V4L2_CID_AUDIO_MUTE:
  657. ctrl->value = dev->mute;
  658. return 0;
  659. case V4L2_CID_AUDIO_VOLUME:
  660. ctrl->value = dev->volume;
  661. return 0;
  662. default:
  663. /* Control is not ac97 related */
  664. return 1;
  665. }
  666. }
  667. /*
  668. * ac97_set_ctrl()
  669. * set values for ac97 mute and volume
  670. */
  671. static int ac97_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
  672. {
  673. int i;
  674. for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++)
  675. if (ctrl->id == ac97_qctrl[i].id)
  676. goto handle;
  677. /* Announce that hasn't handle it */
  678. return 1;
  679. handle:
  680. if (ctrl->value < ac97_qctrl[i].minimum ||
  681. ctrl->value > ac97_qctrl[i].maximum)
  682. return -ERANGE;
  683. switch (ctrl->id) {
  684. case V4L2_CID_AUDIO_MUTE:
  685. dev->mute = ctrl->value;
  686. break;
  687. case V4L2_CID_AUDIO_VOLUME:
  688. dev->volume = ctrl->value;
  689. break;
  690. }
  691. return em28xx_audio_analog_set(dev);
  692. }
  693. static int check_dev(struct em28xx *dev)
  694. {
  695. if (dev->state & DEV_DISCONNECTED) {
  696. em28xx_errdev("v4l2 ioctl: device not present\n");
  697. return -ENODEV;
  698. }
  699. if (dev->state & DEV_MISCONFIGURED) {
  700. em28xx_errdev("v4l2 ioctl: device is misconfigured; "
  701. "close and open it again\n");
  702. return -EIO;
  703. }
  704. return 0;
  705. }
  706. static void get_scale(struct em28xx *dev,
  707. unsigned int width, unsigned int height,
  708. unsigned int *hscale, unsigned int *vscale)
  709. {
  710. unsigned int maxw = norm_maxw(dev);
  711. unsigned int maxh = norm_maxh(dev);
  712. *hscale = (((unsigned long)maxw) << 12) / width - 4096L;
  713. if (*hscale >= 0x4000)
  714. *hscale = 0x3fff;
  715. *vscale = (((unsigned long)maxh) << 12) / height - 4096L;
  716. if (*vscale >= 0x4000)
  717. *vscale = 0x3fff;
  718. }
  719. /* ------------------------------------------------------------------
  720. IOCTL vidioc handling
  721. ------------------------------------------------------------------*/
  722. static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  723. struct v4l2_format *f)
  724. {
  725. struct em28xx_fh *fh = priv;
  726. struct em28xx *dev = fh->dev;
  727. f->fmt.pix.width = dev->width;
  728. f->fmt.pix.height = dev->height;
  729. f->fmt.pix.pixelformat = dev->format->fourcc;
  730. f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
  731. f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
  732. f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  733. /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
  734. if (dev->progressive)
  735. f->fmt.pix.field = V4L2_FIELD_NONE;
  736. else
  737. f->fmt.pix.field = dev->interlaced ?
  738. V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
  739. return 0;
  740. }
  741. static struct em28xx_fmt *format_by_fourcc(unsigned int fourcc)
  742. {
  743. unsigned int i;
  744. for (i = 0; i < ARRAY_SIZE(format); i++)
  745. if (format[i].fourcc == fourcc)
  746. return &format[i];
  747. return NULL;
  748. }
  749. static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  750. struct v4l2_format *f)
  751. {
  752. struct em28xx_fh *fh = priv;
  753. struct em28xx *dev = fh->dev;
  754. unsigned int width = f->fmt.pix.width;
  755. unsigned int height = f->fmt.pix.height;
  756. unsigned int maxw = norm_maxw(dev);
  757. unsigned int maxh = norm_maxh(dev);
  758. unsigned int hscale, vscale;
  759. struct em28xx_fmt *fmt;
  760. fmt = format_by_fourcc(f->fmt.pix.pixelformat);
  761. if (!fmt) {
  762. em28xx_videodbg("Fourcc format (%08x) invalid.\n",
  763. f->fmt.pix.pixelformat);
  764. return -EINVAL;
  765. }
  766. if (dev->board.is_em2800) {
  767. /* the em2800 can only scale down to 50% */
  768. height = height > (3 * maxh / 4) ? maxh : maxh / 2;
  769. width = width > (3 * maxw / 4) ? maxw : maxw / 2;
  770. /* MaxPacketSize for em2800 is too small to capture at full resolution
  771. * use half of maxw as the scaler can only scale to 50% */
  772. if (width == maxw && height == maxh)
  773. width /= 2;
  774. } else {
  775. /* width must even because of the YUYV format
  776. height must be even because of interlacing */
  777. v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh,
  778. 1, 0);
  779. }
  780. get_scale(dev, width, height, &hscale, &vscale);
  781. width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
  782. height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
  783. f->fmt.pix.width = width;
  784. f->fmt.pix.height = height;
  785. f->fmt.pix.pixelformat = fmt->fourcc;
  786. f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3;
  787. f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height;
  788. f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  789. if (dev->progressive)
  790. f->fmt.pix.field = V4L2_FIELD_NONE;
  791. else
  792. f->fmt.pix.field = dev->interlaced ?
  793. V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP;
  794. return 0;
  795. }
  796. static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
  797. unsigned width, unsigned height)
  798. {
  799. struct em28xx_fmt *fmt;
  800. fmt = format_by_fourcc(fourcc);
  801. if (!fmt)
  802. return -EINVAL;
  803. dev->format = fmt;
  804. dev->width = width;
  805. dev->height = height;
  806. /* set new image size */
  807. get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
  808. em28xx_set_alternate(dev);
  809. em28xx_resolution_set(dev);
  810. return 0;
  811. }
  812. static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  813. struct v4l2_format *f)
  814. {
  815. struct em28xx_fh *fh = priv;
  816. struct em28xx *dev = fh->dev;
  817. int rc;
  818. rc = check_dev(dev);
  819. if (rc < 0)
  820. return rc;
  821. vidioc_try_fmt_vid_cap(file, priv, f);
  822. if (videobuf_queue_is_busy(&fh->vb_vidq)) {
  823. em28xx_errdev("%s queue busy\n", __func__);
  824. return -EBUSY;
  825. }
  826. return em28xx_set_video_format(dev, f->fmt.pix.pixelformat,
  827. f->fmt.pix.width, f->fmt.pix.height);
  828. }
  829. static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
  830. {
  831. struct em28xx_fh *fh = priv;
  832. struct em28xx *dev = fh->dev;
  833. int rc;
  834. rc = check_dev(dev);
  835. if (rc < 0)
  836. return rc;
  837. *norm = dev->norm;
  838. return 0;
  839. }
  840. static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *norm)
  841. {
  842. struct em28xx_fh *fh = priv;
  843. struct em28xx *dev = fh->dev;
  844. int rc;
  845. rc = check_dev(dev);
  846. if (rc < 0)
  847. return rc;
  848. v4l2_device_call_all(&dev->v4l2_dev, 0, video, querystd, norm);
  849. return 0;
  850. }
  851. static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
  852. {
  853. struct em28xx_fh *fh = priv;
  854. struct em28xx *dev = fh->dev;
  855. struct v4l2_format f;
  856. int rc;
  857. rc = check_dev(dev);
  858. if (rc < 0)
  859. return rc;
  860. dev->norm = *norm;
  861. /* Adjusts width/height, if needed */
  862. f.fmt.pix.width = dev->width;
  863. f.fmt.pix.height = dev->height;
  864. vidioc_try_fmt_vid_cap(file, priv, &f);
  865. /* set new image size */
  866. dev->width = f.fmt.pix.width;
  867. dev->height = f.fmt.pix.height;
  868. get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
  869. em28xx_resolution_set(dev);
  870. v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
  871. return 0;
  872. }
  873. static int vidioc_g_parm(struct file *file, void *priv,
  874. struct v4l2_streamparm *p)
  875. {
  876. struct em28xx_fh *fh = priv;
  877. struct em28xx *dev = fh->dev;
  878. int rc = 0;
  879. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  880. return -EINVAL;
  881. if (dev->board.is_webcam)
  882. rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0,
  883. video, g_parm, p);
  884. else
  885. v4l2_video_std_frame_period(dev->norm,
  886. &p->parm.capture.timeperframe);
  887. return rc;
  888. }
  889. static int vidioc_s_parm(struct file *file, void *priv,
  890. struct v4l2_streamparm *p)
  891. {
  892. struct em28xx_fh *fh = priv;
  893. struct em28xx *dev = fh->dev;
  894. if (!dev->board.is_webcam)
  895. return -EINVAL;
  896. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  897. return -EINVAL;
  898. return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p);
  899. }
  900. static const char *iname[] = {
  901. [EM28XX_VMUX_COMPOSITE1] = "Composite1",
  902. [EM28XX_VMUX_COMPOSITE2] = "Composite2",
  903. [EM28XX_VMUX_COMPOSITE3] = "Composite3",
  904. [EM28XX_VMUX_COMPOSITE4] = "Composite4",
  905. [EM28XX_VMUX_SVIDEO] = "S-Video",
  906. [EM28XX_VMUX_TELEVISION] = "Television",
  907. [EM28XX_VMUX_CABLE] = "Cable TV",
  908. [EM28XX_VMUX_DVB] = "DVB",
  909. [EM28XX_VMUX_DEBUG] = "for debug only",
  910. };
  911. static int vidioc_enum_input(struct file *file, void *priv,
  912. struct v4l2_input *i)
  913. {
  914. struct em28xx_fh *fh = priv;
  915. struct em28xx *dev = fh->dev;
  916. unsigned int n;
  917. n = i->index;
  918. if (n >= MAX_EM28XX_INPUT)
  919. return -EINVAL;
  920. if (0 == INPUT(n)->type)
  921. return -EINVAL;
  922. i->index = n;
  923. i->type = V4L2_INPUT_TYPE_CAMERA;
  924. strcpy(i->name, iname[INPUT(n)->type]);
  925. if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) ||
  926. (EM28XX_VMUX_CABLE == INPUT(n)->type))
  927. i->type = V4L2_INPUT_TYPE_TUNER;
  928. i->std = dev->vdev->tvnorms;
  929. return 0;
  930. }
  931. static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  932. {
  933. struct em28xx_fh *fh = priv;
  934. struct em28xx *dev = fh->dev;
  935. *i = dev->ctl_input;
  936. return 0;
  937. }
  938. static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  939. {
  940. struct em28xx_fh *fh = priv;
  941. struct em28xx *dev = fh->dev;
  942. int rc;
  943. rc = check_dev(dev);
  944. if (rc < 0)
  945. return rc;
  946. if (i >= MAX_EM28XX_INPUT)
  947. return -EINVAL;
  948. if (0 == INPUT(i)->type)
  949. return -EINVAL;
  950. video_mux(dev, i);
  951. return 0;
  952. }
  953. static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
  954. {
  955. struct em28xx_fh *fh = priv;
  956. struct em28xx *dev = fh->dev;
  957. if (!dev->audio_mode.has_audio)
  958. return -EINVAL;
  959. switch (a->index) {
  960. case EM28XX_AMUX_VIDEO:
  961. strcpy(a->name, "Television");
  962. break;
  963. case EM28XX_AMUX_LINE_IN:
  964. strcpy(a->name, "Line In");
  965. break;
  966. case EM28XX_AMUX_VIDEO2:
  967. strcpy(a->name, "Television alt");
  968. break;
  969. case EM28XX_AMUX_PHONE:
  970. strcpy(a->name, "Phone");
  971. break;
  972. case EM28XX_AMUX_MIC:
  973. strcpy(a->name, "Mic");
  974. break;
  975. case EM28XX_AMUX_CD:
  976. strcpy(a->name, "CD");
  977. break;
  978. case EM28XX_AMUX_AUX:
  979. strcpy(a->name, "Aux");
  980. break;
  981. case EM28XX_AMUX_PCM_OUT:
  982. strcpy(a->name, "PCM");
  983. break;
  984. default:
  985. return -EINVAL;
  986. }
  987. a->index = dev->ctl_ainput;
  988. a->capability = V4L2_AUDCAP_STEREO;
  989. return 0;
  990. }
  991. static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *a)
  992. {
  993. struct em28xx_fh *fh = priv;
  994. struct em28xx *dev = fh->dev;
  995. if (!dev->audio_mode.has_audio)
  996. return -EINVAL;
  997. if (a->index >= MAX_EM28XX_INPUT)
  998. return -EINVAL;
  999. if (0 == INPUT(a->index)->type)
  1000. return -EINVAL;
  1001. dev->ctl_ainput = INPUT(a->index)->amux;
  1002. dev->ctl_aoutput = INPUT(a->index)->aout;
  1003. if (!dev->ctl_aoutput)
  1004. dev->ctl_aoutput = EM28XX_AOUT_MASTER;
  1005. return 0;
  1006. }
  1007. static int vidioc_queryctrl(struct file *file, void *priv,
  1008. struct v4l2_queryctrl *qc)
  1009. {
  1010. struct em28xx_fh *fh = priv;
  1011. struct em28xx *dev = fh->dev;
  1012. int id = qc->id;
  1013. int rc;
  1014. rc = check_dev(dev);
  1015. if (rc < 0)
  1016. return rc;
  1017. memset(qc, 0, sizeof(*qc));
  1018. qc->id = id;
  1019. /* enumerate AC97 controls */
  1020. if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
  1021. rc = ac97_queryctrl(qc);
  1022. if (!rc)
  1023. return 0;
  1024. }
  1025. /* enumerate V4L2 device controls */
  1026. v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
  1027. if (qc->type)
  1028. return 0;
  1029. else
  1030. return -EINVAL;
  1031. }
  1032. /*
  1033. * FIXME: This is an indirect way to check if a control exists at a
  1034. * subdev. Instead of that hack, maybe the better would be to change all
  1035. * subdevs to return -ENOIOCTLCMD, if an ioctl is not supported.
  1036. */
  1037. static int check_subdev_ctrl(struct em28xx *dev, int id)
  1038. {
  1039. struct v4l2_queryctrl qc;
  1040. memset(&qc, 0, sizeof(qc));
  1041. qc.id = id;
  1042. /* enumerate V4L2 device controls */
  1043. v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, &qc);
  1044. if (qc.type)
  1045. return 0;
  1046. else
  1047. return -EINVAL;
  1048. }
  1049. static int vidioc_g_ctrl(struct file *file, void *priv,
  1050. struct v4l2_control *ctrl)
  1051. {
  1052. struct em28xx_fh *fh = priv;
  1053. struct em28xx *dev = fh->dev;
  1054. int rc;
  1055. rc = check_dev(dev);
  1056. if (rc < 0)
  1057. return rc;
  1058. rc = 0;
  1059. /* Set an AC97 control */
  1060. if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
  1061. rc = ac97_get_ctrl(dev, ctrl);
  1062. else
  1063. rc = 1;
  1064. /* It were not an AC97 control. Sends it to the v4l2 dev interface */
  1065. if (rc == 1) {
  1066. if (check_subdev_ctrl(dev, ctrl->id))
  1067. return -EINVAL;
  1068. v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
  1069. rc = 0;
  1070. }
  1071. return rc;
  1072. }
  1073. static int vidioc_s_ctrl(struct file *file, void *priv,
  1074. struct v4l2_control *ctrl)
  1075. {
  1076. struct em28xx_fh *fh = priv;
  1077. struct em28xx *dev = fh->dev;
  1078. int rc;
  1079. rc = check_dev(dev);
  1080. if (rc < 0)
  1081. return rc;
  1082. /* Set an AC97 control */
  1083. if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
  1084. rc = ac97_set_ctrl(dev, ctrl);
  1085. else
  1086. rc = 1;
  1087. /* It isn't an AC97 control. Sends it to the v4l2 dev interface */
  1088. if (rc == 1) {
  1089. rc = check_subdev_ctrl(dev, ctrl->id);
  1090. if (!rc)
  1091. v4l2_device_call_all(&dev->v4l2_dev, 0,
  1092. core, s_ctrl, ctrl);
  1093. /*
  1094. * In the case of non-AC97 volume controls, we still need
  1095. * to do some setups at em28xx, in order to mute/unmute
  1096. * and to adjust audio volume. However, the value ranges
  1097. * should be checked by the corresponding V4L subdriver.
  1098. */
  1099. switch (ctrl->id) {
  1100. case V4L2_CID_AUDIO_MUTE:
  1101. dev->mute = ctrl->value;
  1102. rc = em28xx_audio_analog_set(dev);
  1103. break;
  1104. case V4L2_CID_AUDIO_VOLUME:
  1105. dev->volume = ctrl->value;
  1106. rc = em28xx_audio_analog_set(dev);
  1107. }
  1108. }
  1109. return (rc < 0) ? rc : 0;
  1110. }
  1111. static int vidioc_g_tuner(struct file *file, void *priv,
  1112. struct v4l2_tuner *t)
  1113. {
  1114. struct em28xx_fh *fh = priv;
  1115. struct em28xx *dev = fh->dev;
  1116. int rc;
  1117. rc = check_dev(dev);
  1118. if (rc < 0)
  1119. return rc;
  1120. if (0 != t->index)
  1121. return -EINVAL;
  1122. strcpy(t->name, "Tuner");
  1123. t->type = V4L2_TUNER_ANALOG_TV;
  1124. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
  1125. return 0;
  1126. }
  1127. static int vidioc_s_tuner(struct file *file, void *priv,
  1128. struct v4l2_tuner *t)
  1129. {
  1130. struct em28xx_fh *fh = priv;
  1131. struct em28xx *dev = fh->dev;
  1132. int rc;
  1133. rc = check_dev(dev);
  1134. if (rc < 0)
  1135. return rc;
  1136. if (0 != t->index)
  1137. return -EINVAL;
  1138. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
  1139. return 0;
  1140. }
  1141. static int vidioc_g_frequency(struct file *file, void *priv,
  1142. struct v4l2_frequency *f)
  1143. {
  1144. struct em28xx_fh *fh = priv;
  1145. struct em28xx *dev = fh->dev;
  1146. f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1147. f->frequency = dev->ctl_freq;
  1148. return 0;
  1149. }
  1150. static int vidioc_s_frequency(struct file *file, void *priv,
  1151. struct v4l2_frequency *f)
  1152. {
  1153. struct em28xx_fh *fh = priv;
  1154. struct em28xx *dev = fh->dev;
  1155. int rc;
  1156. rc = check_dev(dev);
  1157. if (rc < 0)
  1158. return rc;
  1159. if (0 != f->tuner)
  1160. return -EINVAL;
  1161. if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
  1162. return -EINVAL;
  1163. if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
  1164. return -EINVAL;
  1165. dev->ctl_freq = f->frequency;
  1166. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
  1167. return 0;
  1168. }
  1169. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1170. static int em28xx_reg_len(int reg)
  1171. {
  1172. switch (reg) {
  1173. case EM28XX_R40_AC97LSB:
  1174. case EM28XX_R30_HSCALELOW:
  1175. case EM28XX_R32_VSCALELOW:
  1176. return 2;
  1177. default:
  1178. return 1;
  1179. }
  1180. }
  1181. static int vidioc_g_chip_ident(struct file *file, void *priv,
  1182. struct v4l2_dbg_chip_ident *chip)
  1183. {
  1184. struct em28xx_fh *fh = priv;
  1185. struct em28xx *dev = fh->dev;
  1186. chip->ident = V4L2_IDENT_NONE;
  1187. chip->revision = 0;
  1188. v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
  1189. return 0;
  1190. }
  1191. static int vidioc_g_register(struct file *file, void *priv,
  1192. struct v4l2_dbg_register *reg)
  1193. {
  1194. struct em28xx_fh *fh = priv;
  1195. struct em28xx *dev = fh->dev;
  1196. int ret;
  1197. switch (reg->match.type) {
  1198. case V4L2_CHIP_MATCH_AC97:
  1199. ret = em28xx_read_ac97(dev, reg->reg);
  1200. if (ret < 0)
  1201. return ret;
  1202. reg->val = ret;
  1203. reg->size = 1;
  1204. return 0;
  1205. case V4L2_CHIP_MATCH_I2C_DRIVER:
  1206. v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
  1207. return 0;
  1208. case V4L2_CHIP_MATCH_I2C_ADDR:
  1209. /* TODO: is this correct? */
  1210. v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
  1211. return 0;
  1212. default:
  1213. if (!v4l2_chip_match_host(&reg->match))
  1214. return -EINVAL;
  1215. }
  1216. /* Match host */
  1217. reg->size = em28xx_reg_len(reg->reg);
  1218. if (reg->size == 1) {
  1219. ret = em28xx_read_reg(dev, reg->reg);
  1220. if (ret < 0)
  1221. return ret;
  1222. reg->val = ret;
  1223. } else {
  1224. __le16 val = 0;
  1225. ret = em28xx_read_reg_req_len(dev, USB_REQ_GET_STATUS,
  1226. reg->reg, (char *)&val, 2);
  1227. if (ret < 0)
  1228. return ret;
  1229. reg->val = le16_to_cpu(val);
  1230. }
  1231. return 0;
  1232. }
  1233. static int vidioc_s_register(struct file *file, void *priv,
  1234. struct v4l2_dbg_register *reg)
  1235. {
  1236. struct em28xx_fh *fh = priv;
  1237. struct em28xx *dev = fh->dev;
  1238. __le16 buf;
  1239. switch (reg->match.type) {
  1240. case V4L2_CHIP_MATCH_AC97:
  1241. return em28xx_write_ac97(dev, reg->reg, reg->val);
  1242. case V4L2_CHIP_MATCH_I2C_DRIVER:
  1243. v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
  1244. return 0;
  1245. case V4L2_CHIP_MATCH_I2C_ADDR:
  1246. /* TODO: is this correct? */
  1247. v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
  1248. return 0;
  1249. default:
  1250. if (!v4l2_chip_match_host(&reg->match))
  1251. return -EINVAL;
  1252. }
  1253. /* Match host */
  1254. buf = cpu_to_le16(reg->val);
  1255. return em28xx_write_regs(dev, reg->reg, (char *)&buf,
  1256. em28xx_reg_len(reg->reg));
  1257. }
  1258. #endif
  1259. static int vidioc_cropcap(struct file *file, void *priv,
  1260. struct v4l2_cropcap *cc)
  1261. {
  1262. struct em28xx_fh *fh = priv;
  1263. struct em28xx *dev = fh->dev;
  1264. if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1265. return -EINVAL;
  1266. cc->bounds.left = 0;
  1267. cc->bounds.top = 0;
  1268. cc->bounds.width = dev->width;
  1269. cc->bounds.height = dev->height;
  1270. cc->defrect = cc->bounds;
  1271. cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
  1272. cc->pixelaspect.denominator = 59;
  1273. return 0;
  1274. }
  1275. static int vidioc_streamon(struct file *file, void *priv,
  1276. enum v4l2_buf_type type)
  1277. {
  1278. struct em28xx_fh *fh = priv;
  1279. struct em28xx *dev = fh->dev;
  1280. int rc = -EINVAL;
  1281. rc = check_dev(dev);
  1282. if (rc < 0)
  1283. return rc;
  1284. if (unlikely(type != fh->type))
  1285. return -EINVAL;
  1286. em28xx_videodbg("vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n",
  1287. fh, type, fh->resources, dev->resources);
  1288. if (unlikely(!res_get(fh, get_ressource(fh))))
  1289. return -EBUSY;
  1290. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1291. rc = videobuf_streamon(&fh->vb_vidq);
  1292. else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
  1293. rc = videobuf_streamon(&fh->vb_vbiq);
  1294. return rc;
  1295. }
  1296. static int vidioc_streamoff(struct file *file, void *priv,
  1297. enum v4l2_buf_type type)
  1298. {
  1299. struct em28xx_fh *fh = priv;
  1300. struct em28xx *dev = fh->dev;
  1301. int rc;
  1302. rc = check_dev(dev);
  1303. if (rc < 0)
  1304. return rc;
  1305. if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
  1306. fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)
  1307. return -EINVAL;
  1308. if (type != fh->type)
  1309. return -EINVAL;
  1310. em28xx_videodbg("vidioc_streamoff fh=%p t=%d fh->res=%d dev->res=%d\n",
  1311. fh, type, fh->resources, dev->resources);
  1312. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  1313. if (res_check(fh, EM28XX_RESOURCE_VIDEO)) {
  1314. videobuf_streamoff(&fh->vb_vidq);
  1315. res_free(fh, EM28XX_RESOURCE_VIDEO);
  1316. }
  1317. } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
  1318. if (res_check(fh, EM28XX_RESOURCE_VBI)) {
  1319. videobuf_streamoff(&fh->vb_vbiq);
  1320. res_free(fh, EM28XX_RESOURCE_VBI);
  1321. }
  1322. }
  1323. return 0;
  1324. }
  1325. static int vidioc_querycap(struct file *file, void *priv,
  1326. struct v4l2_capability *cap)
  1327. {
  1328. struct em28xx_fh *fh = priv;
  1329. struct em28xx *dev = fh->dev;
  1330. strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
  1331. strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
  1332. usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
  1333. cap->capabilities =
  1334. V4L2_CAP_SLICED_VBI_CAPTURE |
  1335. V4L2_CAP_VIDEO_CAPTURE |
  1336. V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
  1337. if (dev->vbi_dev)
  1338. cap->capabilities |= V4L2_CAP_VBI_CAPTURE;
  1339. if (dev->audio_mode.has_audio)
  1340. cap->capabilities |= V4L2_CAP_AUDIO;
  1341. if (dev->tuner_type != TUNER_ABSENT)
  1342. cap->capabilities |= V4L2_CAP_TUNER;
  1343. return 0;
  1344. }
  1345. static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  1346. struct v4l2_fmtdesc *f)
  1347. {
  1348. if (unlikely(f->index >= ARRAY_SIZE(format)))
  1349. return -EINVAL;
  1350. strlcpy(f->description, format[f->index].name, sizeof(f->description));
  1351. f->pixelformat = format[f->index].fourcc;
  1352. return 0;
  1353. }
  1354. static int vidioc_enum_framesizes(struct file *file, void *priv,
  1355. struct v4l2_frmsizeenum *fsize)
  1356. {
  1357. struct em28xx_fh *fh = priv;
  1358. struct em28xx *dev = fh->dev;
  1359. struct em28xx_fmt *fmt;
  1360. unsigned int maxw = norm_maxw(dev);
  1361. unsigned int maxh = norm_maxh(dev);
  1362. fmt = format_by_fourcc(fsize->pixel_format);
  1363. if (!fmt) {
  1364. em28xx_videodbg("Fourcc format (%08x) invalid.\n",
  1365. fsize->pixel_format);
  1366. return -EINVAL;
  1367. }
  1368. if (dev->board.is_em2800) {
  1369. if (fsize->index > 1)
  1370. return -EINVAL;
  1371. fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  1372. fsize->discrete.width = maxw / (1 + fsize->index);
  1373. fsize->discrete.height = maxh / (1 + fsize->index);
  1374. return 0;
  1375. }
  1376. if (fsize->index != 0)
  1377. return -EINVAL;
  1378. /* Report a continuous range */
  1379. fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  1380. fsize->stepwise.min_width = 48;
  1381. fsize->stepwise.min_height = 32;
  1382. fsize->stepwise.max_width = maxw;
  1383. fsize->stepwise.max_height = maxh;
  1384. fsize->stepwise.step_width = 1;
  1385. fsize->stepwise.step_height = 1;
  1386. return 0;
  1387. }
  1388. /* Sliced VBI ioctls */
  1389. static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
  1390. struct v4l2_format *f)
  1391. {
  1392. struct em28xx_fh *fh = priv;
  1393. struct em28xx *dev = fh->dev;
  1394. int rc;
  1395. rc = check_dev(dev);
  1396. if (rc < 0)
  1397. return rc;
  1398. f->fmt.sliced.service_set = 0;
  1399. v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
  1400. if (f->fmt.sliced.service_set == 0)
  1401. rc = -EINVAL;
  1402. return rc;
  1403. }
  1404. static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
  1405. struct v4l2_format *f)
  1406. {
  1407. struct em28xx_fh *fh = priv;
  1408. struct em28xx *dev = fh->dev;
  1409. int rc;
  1410. rc = check_dev(dev);
  1411. if (rc < 0)
  1412. return rc;
  1413. v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
  1414. if (f->fmt.sliced.service_set == 0)
  1415. return -EINVAL;
  1416. return 0;
  1417. }
  1418. /* RAW VBI ioctls */
  1419. static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
  1420. struct v4l2_format *format)
  1421. {
  1422. struct em28xx_fh *fh = priv;
  1423. struct em28xx *dev = fh->dev;
  1424. format->fmt.vbi.samples_per_line = dev->vbi_width;
  1425. format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
  1426. format->fmt.vbi.offset = 0;
  1427. format->fmt.vbi.flags = 0;
  1428. format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
  1429. format->fmt.vbi.count[0] = dev->vbi_height;
  1430. format->fmt.vbi.count[1] = dev->vbi_height;
  1431. /* Varies by video standard (NTSC, PAL, etc.) */
  1432. if (dev->norm & V4L2_STD_525_60) {
  1433. /* NTSC */
  1434. format->fmt.vbi.start[0] = 10;
  1435. format->fmt.vbi.start[1] = 273;
  1436. } else if (dev->norm & V4L2_STD_625_50) {
  1437. /* PAL */
  1438. format->fmt.vbi.start[0] = 6;
  1439. format->fmt.vbi.start[1] = 318;
  1440. }
  1441. return 0;
  1442. }
  1443. static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
  1444. struct v4l2_format *format)
  1445. {
  1446. struct em28xx_fh *fh = priv;
  1447. struct em28xx *dev = fh->dev;
  1448. format->fmt.vbi.samples_per_line = dev->vbi_width;
  1449. format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
  1450. format->fmt.vbi.offset = 0;
  1451. format->fmt.vbi.flags = 0;
  1452. format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
  1453. format->fmt.vbi.count[0] = dev->vbi_height;
  1454. format->fmt.vbi.count[1] = dev->vbi_height;
  1455. /* Varies by video standard (NTSC, PAL, etc.) */
  1456. if (dev->norm & V4L2_STD_525_60) {
  1457. /* NTSC */
  1458. format->fmt.vbi.start[0] = 10;
  1459. format->fmt.vbi.start[1] = 273;
  1460. } else if (dev->norm & V4L2_STD_625_50) {
  1461. /* PAL */
  1462. format->fmt.vbi.start[0] = 6;
  1463. format->fmt.vbi.start[1] = 318;
  1464. }
  1465. return 0;
  1466. }
  1467. static int vidioc_reqbufs(struct file *file, void *priv,
  1468. struct v4l2_requestbuffers *rb)
  1469. {
  1470. struct em28xx_fh *fh = priv;
  1471. struct em28xx *dev = fh->dev;
  1472. int rc;
  1473. rc = check_dev(dev);
  1474. if (rc < 0)
  1475. return rc;
  1476. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1477. return videobuf_reqbufs(&fh->vb_vidq, rb);
  1478. else
  1479. return videobuf_reqbufs(&fh->vb_vbiq, rb);
  1480. }
  1481. static int vidioc_querybuf(struct file *file, void *priv,
  1482. struct v4l2_buffer *b)
  1483. {
  1484. struct em28xx_fh *fh = priv;
  1485. struct em28xx *dev = fh->dev;
  1486. int rc;
  1487. rc = check_dev(dev);
  1488. if (rc < 0)
  1489. return rc;
  1490. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1491. return videobuf_querybuf(&fh->vb_vidq, b);
  1492. else {
  1493. /* FIXME: I'm not sure yet whether this is a bug in zvbi or
  1494. the videobuf framework, but we probably shouldn't be
  1495. returning a buffer larger than that which was asked for.
  1496. At a minimum, it causes a crash in zvbi since it does
  1497. a memcpy based on the source buffer length */
  1498. int result = videobuf_querybuf(&fh->vb_vbiq, b);
  1499. b->length = dev->vbi_width * dev->vbi_height * 2;
  1500. return result;
  1501. }
  1502. }
  1503. static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  1504. {
  1505. struct em28xx_fh *fh = priv;
  1506. struct em28xx *dev = fh->dev;
  1507. int rc;
  1508. rc = check_dev(dev);
  1509. if (rc < 0)
  1510. return rc;
  1511. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1512. return videobuf_qbuf(&fh->vb_vidq, b);
  1513. else
  1514. return videobuf_qbuf(&fh->vb_vbiq, b);
  1515. }
  1516. static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  1517. {
  1518. struct em28xx_fh *fh = priv;
  1519. struct em28xx *dev = fh->dev;
  1520. int rc;
  1521. rc = check_dev(dev);
  1522. if (rc < 0)
  1523. return rc;
  1524. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1525. return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags &
  1526. O_NONBLOCK);
  1527. else
  1528. return videobuf_dqbuf(&fh->vb_vbiq, b, file->f_flags &
  1529. O_NONBLOCK);
  1530. }
  1531. /* ----------------------------------------------------------- */
  1532. /* RADIO ESPECIFIC IOCTLS */
  1533. /* ----------------------------------------------------------- */
  1534. static int radio_querycap(struct file *file, void *priv,
  1535. struct v4l2_capability *cap)
  1536. {
  1537. struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
  1538. strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
  1539. strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
  1540. usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
  1541. cap->capabilities = V4L2_CAP_TUNER;
  1542. return 0;
  1543. }
  1544. static int radio_g_tuner(struct file *file, void *priv,
  1545. struct v4l2_tuner *t)
  1546. {
  1547. struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
  1548. if (unlikely(t->index > 0))
  1549. return -EINVAL;
  1550. strcpy(t->name, "Radio");
  1551. t->type = V4L2_TUNER_RADIO;
  1552. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
  1553. return 0;
  1554. }
  1555. static int radio_enum_input(struct file *file, void *priv,
  1556. struct v4l2_input *i)
  1557. {
  1558. if (i->index != 0)
  1559. return -EINVAL;
  1560. strcpy(i->name, "Radio");
  1561. i->type = V4L2_INPUT_TYPE_TUNER;
  1562. return 0;
  1563. }
  1564. static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
  1565. {
  1566. if (unlikely(a->index))
  1567. return -EINVAL;
  1568. strcpy(a->name, "Radio");
  1569. return 0;
  1570. }
  1571. static int radio_s_tuner(struct file *file, void *priv,
  1572. struct v4l2_tuner *t)
  1573. {
  1574. struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
  1575. if (0 != t->index)
  1576. return -EINVAL;
  1577. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
  1578. return 0;
  1579. }
  1580. static int radio_s_audio(struct file *file, void *fh,
  1581. const struct v4l2_audio *a)
  1582. {
  1583. return 0;
  1584. }
  1585. static int radio_s_input(struct file *file, void *fh, unsigned int i)
  1586. {
  1587. return 0;
  1588. }
  1589. static int radio_queryctrl(struct file *file, void *priv,
  1590. struct v4l2_queryctrl *qc)
  1591. {
  1592. int i;
  1593. if (qc->id < V4L2_CID_BASE ||
  1594. qc->id >= V4L2_CID_LASTP1)
  1595. return -EINVAL;
  1596. for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
  1597. if (qc->id && qc->id == ac97_qctrl[i].id) {
  1598. memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
  1599. return 0;
  1600. }
  1601. }
  1602. return -EINVAL;
  1603. }
  1604. /*
  1605. * em28xx_v4l2_open()
  1606. * inits the device and starts isoc transfer
  1607. */
  1608. static int em28xx_v4l2_open(struct file *filp)
  1609. {
  1610. int errCode = 0, radio = 0;
  1611. struct video_device *vdev = video_devdata(filp);
  1612. struct em28xx *dev = video_drvdata(filp);
  1613. enum v4l2_buf_type fh_type = 0;
  1614. struct em28xx_fh *fh;
  1615. enum v4l2_field field;
  1616. switch (vdev->vfl_type) {
  1617. case VFL_TYPE_GRABBER:
  1618. fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1619. break;
  1620. case VFL_TYPE_VBI:
  1621. fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
  1622. break;
  1623. case VFL_TYPE_RADIO:
  1624. radio = 1;
  1625. break;
  1626. }
  1627. em28xx_videodbg("open dev=%s type=%s users=%d\n",
  1628. video_device_node_name(vdev), v4l2_type_names[fh_type],
  1629. dev->users);
  1630. if (mutex_lock_interruptible(&dev->lock))
  1631. return -ERESTARTSYS;
  1632. fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
  1633. if (!fh) {
  1634. em28xx_errdev("em28xx-video.c: Out of memory?!\n");
  1635. mutex_unlock(&dev->lock);
  1636. return -ENOMEM;
  1637. }
  1638. fh->dev = dev;
  1639. fh->radio = radio;
  1640. fh->type = fh_type;
  1641. filp->private_data = fh;
  1642. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
  1643. em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
  1644. em28xx_set_alternate(dev);
  1645. em28xx_resolution_set(dev);
  1646. /* Needed, since GPIO might have disabled power of
  1647. some i2c device
  1648. */
  1649. em28xx_wake_i2c(dev);
  1650. }
  1651. if (fh->radio) {
  1652. em28xx_videodbg("video_open: setting radio device\n");
  1653. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
  1654. }
  1655. dev->users++;
  1656. if (dev->progressive)
  1657. field = V4L2_FIELD_NONE;
  1658. else
  1659. field = V4L2_FIELD_INTERLACED;
  1660. videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops,
  1661. NULL, &dev->slock,
  1662. V4L2_BUF_TYPE_VIDEO_CAPTURE, field,
  1663. sizeof(struct em28xx_buffer), fh, &dev->lock);
  1664. videobuf_queue_vmalloc_init(&fh->vb_vbiq, &em28xx_vbi_qops,
  1665. NULL, &dev->slock,
  1666. V4L2_BUF_TYPE_VBI_CAPTURE,
  1667. V4L2_FIELD_SEQ_TB,
  1668. sizeof(struct em28xx_buffer), fh, &dev->lock);
  1669. mutex_unlock(&dev->lock);
  1670. return errCode;
  1671. }
  1672. /*
  1673. * em28xx_realease_resources()
  1674. * unregisters the v4l2,i2c and usb devices
  1675. * called when the device gets disconected or at module unload
  1676. */
  1677. void em28xx_release_analog_resources(struct em28xx *dev)
  1678. {
  1679. /*FIXME: I2C IR should be disconnected */
  1680. if (dev->radio_dev) {
  1681. if (video_is_registered(dev->radio_dev))
  1682. video_unregister_device(dev->radio_dev);
  1683. else
  1684. video_device_release(dev->radio_dev);
  1685. dev->radio_dev = NULL;
  1686. }
  1687. if (dev->vbi_dev) {
  1688. em28xx_info("V4L2 device %s deregistered\n",
  1689. video_device_node_name(dev->vbi_dev));
  1690. if (video_is_registered(dev->vbi_dev))
  1691. video_unregister_device(dev->vbi_dev);
  1692. else
  1693. video_device_release(dev->vbi_dev);
  1694. dev->vbi_dev = NULL;
  1695. }
  1696. if (dev->vdev) {
  1697. em28xx_info("V4L2 device %s deregistered\n",
  1698. video_device_node_name(dev->vdev));
  1699. if (video_is_registered(dev->vdev))
  1700. video_unregister_device(dev->vdev);
  1701. else
  1702. video_device_release(dev->vdev);
  1703. dev->vdev = NULL;
  1704. }
  1705. }
  1706. /*
  1707. * em28xx_v4l2_close()
  1708. * stops streaming and deallocates all resources allocated by the v4l2
  1709. * calls and ioctls
  1710. */
  1711. static int em28xx_v4l2_close(struct file *filp)
  1712. {
  1713. struct em28xx_fh *fh = filp->private_data;
  1714. struct em28xx *dev = fh->dev;
  1715. int errCode;
  1716. em28xx_videodbg("users=%d\n", dev->users);
  1717. mutex_lock(&dev->lock);
  1718. if (res_check(fh, EM28XX_RESOURCE_VIDEO)) {
  1719. videobuf_stop(&fh->vb_vidq);
  1720. res_free(fh, EM28XX_RESOURCE_VIDEO);
  1721. }
  1722. if (res_check(fh, EM28XX_RESOURCE_VBI)) {
  1723. videobuf_stop(&fh->vb_vbiq);
  1724. res_free(fh, EM28XX_RESOURCE_VBI);
  1725. }
  1726. if (dev->users == 1) {
  1727. /* the device is already disconnect,
  1728. free the remaining resources */
  1729. if (dev->state & DEV_DISCONNECTED) {
  1730. em28xx_release_resources(dev);
  1731. kfree(dev->alt_max_pkt_size_isoc);
  1732. mutex_unlock(&dev->lock);
  1733. kfree(dev);
  1734. kfree(fh);
  1735. return 0;
  1736. }
  1737. /* Save some power by putting tuner to sleep */
  1738. v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
  1739. /* do this before setting alternate! */
  1740. em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE);
  1741. em28xx_set_mode(dev, EM28XX_SUSPEND);
  1742. /* set alternate 0 */
  1743. dev->alt = 0;
  1744. em28xx_videodbg("setting alternate 0\n");
  1745. errCode = usb_set_interface(dev->udev, 0, 0);
  1746. if (errCode < 0) {
  1747. em28xx_errdev("cannot change alternate number to "
  1748. "0 (error=%i)\n", errCode);
  1749. }
  1750. }
  1751. videobuf_mmap_free(&fh->vb_vidq);
  1752. videobuf_mmap_free(&fh->vb_vbiq);
  1753. kfree(fh);
  1754. dev->users--;
  1755. mutex_unlock(&dev->lock);
  1756. return 0;
  1757. }
  1758. /*
  1759. * em28xx_v4l2_read()
  1760. * will allocate buffers when called for the first time
  1761. */
  1762. static ssize_t
  1763. em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
  1764. loff_t *pos)
  1765. {
  1766. struct em28xx_fh *fh = filp->private_data;
  1767. struct em28xx *dev = fh->dev;
  1768. int rc;
  1769. rc = check_dev(dev);
  1770. if (rc < 0)
  1771. return rc;
  1772. if (mutex_lock_interruptible(&dev->lock))
  1773. return -ERESTARTSYS;
  1774. /* FIXME: read() is not prepared to allow changing the video
  1775. resolution while streaming. Seems a bug at em28xx_set_fmt
  1776. */
  1777. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  1778. if (res_locked(dev, EM28XX_RESOURCE_VIDEO))
  1779. rc = -EBUSY;
  1780. else
  1781. rc = videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
  1782. filp->f_flags & O_NONBLOCK);
  1783. } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
  1784. if (!res_get(fh, EM28XX_RESOURCE_VBI))
  1785. rc = -EBUSY;
  1786. else
  1787. rc = videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0,
  1788. filp->f_flags & O_NONBLOCK);
  1789. }
  1790. mutex_unlock(&dev->lock);
  1791. return rc;
  1792. }
  1793. /*
  1794. * em28xx_poll()
  1795. * will allocate buffers when called for the first time
  1796. */
  1797. static unsigned int em28xx_poll(struct file *filp, poll_table *wait)
  1798. {
  1799. struct em28xx_fh *fh = filp->private_data;
  1800. struct em28xx *dev = fh->dev;
  1801. int rc;
  1802. rc = check_dev(dev);
  1803. if (rc < 0)
  1804. return rc;
  1805. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  1806. if (!res_get(fh, EM28XX_RESOURCE_VIDEO))
  1807. return POLLERR;
  1808. return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
  1809. } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
  1810. if (!res_get(fh, EM28XX_RESOURCE_VBI))
  1811. return POLLERR;
  1812. return videobuf_poll_stream(filp, &fh->vb_vbiq, wait);
  1813. } else {
  1814. return POLLERR;
  1815. }
  1816. }
  1817. static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
  1818. {
  1819. struct em28xx_fh *fh = filp->private_data;
  1820. struct em28xx *dev = fh->dev;
  1821. unsigned int res;
  1822. mutex_lock(&dev->lock);
  1823. res = em28xx_poll(filp, wait);
  1824. mutex_unlock(&dev->lock);
  1825. return res;
  1826. }
  1827. /*
  1828. * em28xx_v4l2_mmap()
  1829. */
  1830. static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
  1831. {
  1832. struct em28xx_fh *fh = filp->private_data;
  1833. struct em28xx *dev = fh->dev;
  1834. int rc;
  1835. rc = check_dev(dev);
  1836. if (rc < 0)
  1837. return rc;
  1838. if (mutex_lock_interruptible(&dev->lock))
  1839. return -ERESTARTSYS;
  1840. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1841. rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
  1842. else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
  1843. rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma);
  1844. mutex_unlock(&dev->lock);
  1845. em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
  1846. (unsigned long)vma->vm_start,
  1847. (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
  1848. rc);
  1849. return rc;
  1850. }
  1851. static const struct v4l2_file_operations em28xx_v4l_fops = {
  1852. .owner = THIS_MODULE,
  1853. .open = em28xx_v4l2_open,
  1854. .release = em28xx_v4l2_close,
  1855. .read = em28xx_v4l2_read,
  1856. .poll = em28xx_v4l2_poll,
  1857. .mmap = em28xx_v4l2_mmap,
  1858. .unlocked_ioctl = video_ioctl2,
  1859. };
  1860. static const struct v4l2_ioctl_ops video_ioctl_ops = {
  1861. .vidioc_querycap = vidioc_querycap,
  1862. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  1863. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  1864. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  1865. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  1866. .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
  1867. .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
  1868. .vidioc_enum_framesizes = vidioc_enum_framesizes,
  1869. .vidioc_g_audio = vidioc_g_audio,
  1870. .vidioc_s_audio = vidioc_s_audio,
  1871. .vidioc_cropcap = vidioc_cropcap,
  1872. .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
  1873. .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
  1874. .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
  1875. .vidioc_reqbufs = vidioc_reqbufs,
  1876. .vidioc_querybuf = vidioc_querybuf,
  1877. .vidioc_qbuf = vidioc_qbuf,
  1878. .vidioc_dqbuf = vidioc_dqbuf,
  1879. .vidioc_g_std = vidioc_g_std,
  1880. .vidioc_querystd = vidioc_querystd,
  1881. .vidioc_s_std = vidioc_s_std,
  1882. .vidioc_g_parm = vidioc_g_parm,
  1883. .vidioc_s_parm = vidioc_s_parm,
  1884. .vidioc_enum_input = vidioc_enum_input,
  1885. .vidioc_g_input = vidioc_g_input,
  1886. .vidioc_s_input = vidioc_s_input,
  1887. .vidioc_queryctrl = vidioc_queryctrl,
  1888. .vidioc_g_ctrl = vidioc_g_ctrl,
  1889. .vidioc_s_ctrl = vidioc_s_ctrl,
  1890. .vidioc_streamon = vidioc_streamon,
  1891. .vidioc_streamoff = vidioc_streamoff,
  1892. .vidioc_g_tuner = vidioc_g_tuner,
  1893. .vidioc_s_tuner = vidioc_s_tuner,
  1894. .vidioc_g_frequency = vidioc_g_frequency,
  1895. .vidioc_s_frequency = vidioc_s_frequency,
  1896. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1897. .vidioc_g_register = vidioc_g_register,
  1898. .vidioc_s_register = vidioc_s_register,
  1899. .vidioc_g_chip_ident = vidioc_g_chip_ident,
  1900. #endif
  1901. };
  1902. static const struct video_device em28xx_video_template = {
  1903. .fops = &em28xx_v4l_fops,
  1904. .release = video_device_release,
  1905. .ioctl_ops = &video_ioctl_ops,
  1906. .tvnorms = V4L2_STD_ALL,
  1907. .current_norm = V4L2_STD_PAL,
  1908. };
  1909. static const struct v4l2_file_operations radio_fops = {
  1910. .owner = THIS_MODULE,
  1911. .open = em28xx_v4l2_open,
  1912. .release = em28xx_v4l2_close,
  1913. .unlocked_ioctl = video_ioctl2,
  1914. };
  1915. static const struct v4l2_ioctl_ops radio_ioctl_ops = {
  1916. .vidioc_querycap = radio_querycap,
  1917. .vidioc_g_tuner = radio_g_tuner,
  1918. .vidioc_enum_input = radio_enum_input,
  1919. .vidioc_g_audio = radio_g_audio,
  1920. .vidioc_s_tuner = radio_s_tuner,
  1921. .vidioc_s_audio = radio_s_audio,
  1922. .vidioc_s_input = radio_s_input,
  1923. .vidioc_queryctrl = radio_queryctrl,
  1924. .vidioc_g_ctrl = vidioc_g_ctrl,
  1925. .vidioc_s_ctrl = vidioc_s_ctrl,
  1926. .vidioc_g_frequency = vidioc_g_frequency,
  1927. .vidioc_s_frequency = vidioc_s_frequency,
  1928. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1929. .vidioc_g_register = vidioc_g_register,
  1930. .vidioc_s_register = vidioc_s_register,
  1931. #endif
  1932. };
  1933. static struct video_device em28xx_radio_template = {
  1934. .name = "em28xx-radio",
  1935. .fops = &radio_fops,
  1936. .ioctl_ops = &radio_ioctl_ops,
  1937. };
  1938. /******************************** usb interface ******************************/
  1939. static struct video_device *em28xx_vdev_init(struct em28xx *dev,
  1940. const struct video_device *template,
  1941. const char *type_name)
  1942. {
  1943. struct video_device *vfd;
  1944. vfd = video_device_alloc();
  1945. if (NULL == vfd)
  1946. return NULL;
  1947. *vfd = *template;
  1948. vfd->v4l2_dev = &dev->v4l2_dev;
  1949. vfd->release = video_device_release;
  1950. vfd->debug = video_debug;
  1951. vfd->lock = &dev->lock;
  1952. snprintf(vfd->name, sizeof(vfd->name), "%s %s",
  1953. dev->name, type_name);
  1954. video_set_drvdata(vfd, dev);
  1955. return vfd;
  1956. }
  1957. int em28xx_register_analog_devices(struct em28xx *dev)
  1958. {
  1959. u8 val;
  1960. int ret;
  1961. unsigned int maxw;
  1962. printk(KERN_INFO "%s: v4l2 driver version %s\n",
  1963. dev->name, EM28XX_VERSION);
  1964. /* set default norm */
  1965. dev->norm = em28xx_video_template.current_norm;
  1966. v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
  1967. dev->interlaced = EM28XX_INTERLACED_DEFAULT;
  1968. /* Analog specific initialization */
  1969. dev->format = &format[0];
  1970. maxw = norm_maxw(dev);
  1971. /* MaxPacketSize for em2800 is too small to capture at full resolution
  1972. * use half of maxw as the scaler can only scale to 50% */
  1973. if (dev->board.is_em2800)
  1974. maxw /= 2;
  1975. em28xx_set_video_format(dev, format[0].fourcc,
  1976. maxw, norm_maxh(dev));
  1977. video_mux(dev, 0);
  1978. /* Audio defaults */
  1979. dev->mute = 1;
  1980. dev->volume = 0x1f;
  1981. /* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */
  1982. val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK);
  1983. em28xx_write_reg(dev, EM28XX_R0F_XCLK,
  1984. (EM28XX_XCLK_AUDIO_UNMUTE | val));
  1985. em28xx_set_outfmt(dev);
  1986. em28xx_colorlevels_set_default(dev);
  1987. em28xx_compression_disable(dev);
  1988. /* allocate and fill video video_device struct */
  1989. dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video");
  1990. if (!dev->vdev) {
  1991. em28xx_errdev("cannot allocate video_device.\n");
  1992. return -ENODEV;
  1993. }
  1994. /* register v4l2 video video_device */
  1995. ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
  1996. video_nr[dev->devno]);
  1997. if (ret) {
  1998. em28xx_errdev("unable to register video device (error=%i).\n",
  1999. ret);
  2000. return ret;
  2001. }
  2002. /* Allocate and fill vbi video_device struct */
  2003. if (em28xx_vbi_supported(dev) == 1) {
  2004. dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template,
  2005. "vbi");
  2006. /* register v4l2 vbi video_device */
  2007. ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
  2008. vbi_nr[dev->devno]);
  2009. if (ret < 0) {
  2010. em28xx_errdev("unable to register vbi device\n");
  2011. return ret;
  2012. }
  2013. }
  2014. if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
  2015. dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template,
  2016. "radio");
  2017. if (!dev->radio_dev) {
  2018. em28xx_errdev("cannot allocate video_device.\n");
  2019. return -ENODEV;
  2020. }
  2021. ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
  2022. radio_nr[dev->devno]);
  2023. if (ret < 0) {
  2024. em28xx_errdev("can't register radio device\n");
  2025. return ret;
  2026. }
  2027. em28xx_info("Registered radio device as %s\n",
  2028. video_device_node_name(dev->radio_dev));
  2029. }
  2030. em28xx_info("V4L2 video device registered as %s\n",
  2031. video_device_node_name(dev->vdev));
  2032. if (dev->vbi_dev)
  2033. em28xx_info("V4L2 VBI device registered as %s\n",
  2034. video_device_node_name(dev->vbi_dev));
  2035. return 0;
  2036. }