em28xx-video.c 60 KB

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