em28xx-video.c 60 KB

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