cx231xx-video.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399
  1. /*
  2. cx231xx-video.c - driver for Conexant Cx23100/101/102
  3. USB video capture devices
  4. Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
  5. Based on em28xx driver
  6. Based on cx23885 driver
  7. Based on cx88 driver
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/list.h>
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/bitmap.h>
  25. #include <linux/usb.h>
  26. #include <linux/i2c.h>
  27. #include <linux/mm.h>
  28. #include <linux/mutex.h>
  29. #include <linux/slab.h>
  30. #include <media/v4l2-common.h>
  31. #include <media/v4l2-ioctl.h>
  32. #include <media/v4l2-event.h>
  33. #include <media/v4l2-chip-ident.h>
  34. #include <media/msp3400.h>
  35. #include <media/tuner.h>
  36. #include "dvb_frontend.h"
  37. #include "cx231xx.h"
  38. #include "cx231xx-vbi.h"
  39. #define CX231XX_VERSION "0.0.2"
  40. #define DRIVER_AUTHOR "Srinivasa Deevi <srinivasa.deevi@conexant.com>"
  41. #define DRIVER_DESC "Conexant cx231xx based USB video device driver"
  42. #define cx231xx_videodbg(fmt, arg...) do {\
  43. if (video_debug) \
  44. printk(KERN_INFO "%s %s :"fmt, \
  45. dev->name, __func__ , ##arg); } while (0)
  46. static unsigned int isoc_debug;
  47. module_param(isoc_debug, int, 0644);
  48. MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]");
  49. #define cx231xx_isocdbg(fmt, arg...) \
  50. do {\
  51. if (isoc_debug) { \
  52. printk(KERN_INFO "%s %s :"fmt, \
  53. dev->name, __func__ , ##arg); \
  54. } \
  55. } while (0)
  56. MODULE_AUTHOR(DRIVER_AUTHOR);
  57. MODULE_DESCRIPTION(DRIVER_DESC);
  58. MODULE_LICENSE("GPL");
  59. MODULE_VERSION(CX231XX_VERSION);
  60. static unsigned int card[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET };
  61. static unsigned int video_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET };
  62. static unsigned int vbi_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET };
  63. static unsigned int radio_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET };
  64. module_param_array(card, int, NULL, 0444);
  65. module_param_array(video_nr, int, NULL, 0444);
  66. module_param_array(vbi_nr, int, NULL, 0444);
  67. module_param_array(radio_nr, int, NULL, 0444);
  68. MODULE_PARM_DESC(card, "card type");
  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 cx231xx_fmt format[] = {
  77. {
  78. .name = "16bpp YUY2, 4:2:2, packed",
  79. .fourcc = V4L2_PIX_FMT_YUYV,
  80. .depth = 16,
  81. .reg = 0,
  82. },
  83. };
  84. /* ------------------------------------------------------------------
  85. Video buffer and parser functions
  86. ------------------------------------------------------------------*/
  87. /*
  88. * Announces that a buffer were filled and request the next
  89. */
  90. static inline void buffer_filled(struct cx231xx *dev,
  91. struct cx231xx_dmaqueue *dma_q,
  92. struct cx231xx_buffer *buf)
  93. {
  94. /* Advice that buffer was filled */
  95. cx231xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
  96. buf->vb.state = VIDEOBUF_DONE;
  97. buf->vb.field_count++;
  98. v4l2_get_timestamp(&buf->vb.ts);
  99. if (dev->USE_ISO)
  100. dev->video_mode.isoc_ctl.buf = NULL;
  101. else
  102. dev->video_mode.bulk_ctl.buf = NULL;
  103. list_del(&buf->vb.queue);
  104. wake_up(&buf->vb.done);
  105. }
  106. static inline void print_err_status(struct cx231xx *dev, int packet, int status)
  107. {
  108. char *errmsg = "Unknown";
  109. switch (status) {
  110. case -ENOENT:
  111. errmsg = "unlinked synchronuously";
  112. break;
  113. case -ECONNRESET:
  114. errmsg = "unlinked asynchronuously";
  115. break;
  116. case -ENOSR:
  117. errmsg = "Buffer error (overrun)";
  118. break;
  119. case -EPIPE:
  120. errmsg = "Stalled (device not responding)";
  121. break;
  122. case -EOVERFLOW:
  123. errmsg = "Babble (bad cable?)";
  124. break;
  125. case -EPROTO:
  126. errmsg = "Bit-stuff error (bad cable?)";
  127. break;
  128. case -EILSEQ:
  129. errmsg = "CRC/Timeout (could be anything)";
  130. break;
  131. case -ETIME:
  132. errmsg = "Device does not respond";
  133. break;
  134. }
  135. if (packet < 0) {
  136. cx231xx_isocdbg("URB status %d [%s].\n", status, errmsg);
  137. } else {
  138. cx231xx_isocdbg("URB packet %d, status %d [%s].\n",
  139. packet, status, errmsg);
  140. }
  141. }
  142. /*
  143. * video-buf generic routine to get the next available buffer
  144. */
  145. static inline void get_next_buf(struct cx231xx_dmaqueue *dma_q,
  146. struct cx231xx_buffer **buf)
  147. {
  148. struct cx231xx_video_mode *vmode =
  149. container_of(dma_q, struct cx231xx_video_mode, vidq);
  150. struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode);
  151. char *outp;
  152. if (list_empty(&dma_q->active)) {
  153. cx231xx_isocdbg("No active queue to serve\n");
  154. if (dev->USE_ISO)
  155. dev->video_mode.isoc_ctl.buf = NULL;
  156. else
  157. dev->video_mode.bulk_ctl.buf = NULL;
  158. *buf = NULL;
  159. return;
  160. }
  161. /* Get the next buffer */
  162. *buf = list_entry(dma_q->active.next, struct cx231xx_buffer, vb.queue);
  163. /* Cleans up buffer - Useful for testing for frame/URB loss */
  164. outp = videobuf_to_vmalloc(&(*buf)->vb);
  165. memset(outp, 0, (*buf)->vb.size);
  166. if (dev->USE_ISO)
  167. dev->video_mode.isoc_ctl.buf = *buf;
  168. else
  169. dev->video_mode.bulk_ctl.buf = *buf;
  170. return;
  171. }
  172. /*
  173. * Controls the isoc copy of each urb packet
  174. */
  175. static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
  176. {
  177. struct cx231xx_dmaqueue *dma_q = urb->context;
  178. int i, rc = 1;
  179. unsigned char *p_buffer;
  180. u32 bytes_parsed = 0, buffer_size = 0;
  181. u8 sav_eav = 0;
  182. if (!dev)
  183. return 0;
  184. if (dev->state & DEV_DISCONNECTED)
  185. return 0;
  186. if (urb->status < 0) {
  187. print_err_status(dev, -1, urb->status);
  188. if (urb->status == -ENOENT)
  189. return 0;
  190. }
  191. for (i = 0; i < urb->number_of_packets; i++) {
  192. int status = urb->iso_frame_desc[i].status;
  193. if (status < 0) {
  194. print_err_status(dev, i, status);
  195. if (urb->iso_frame_desc[i].status != -EPROTO)
  196. continue;
  197. }
  198. if (urb->iso_frame_desc[i].actual_length <= 0) {
  199. /* cx231xx_isocdbg("packet %d is empty",i); - spammy */
  200. continue;
  201. }
  202. if (urb->iso_frame_desc[i].actual_length >
  203. dev->video_mode.max_pkt_size) {
  204. cx231xx_isocdbg("packet bigger than packet size");
  205. continue;
  206. }
  207. /* get buffer pointer and length */
  208. p_buffer = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
  209. buffer_size = urb->iso_frame_desc[i].actual_length;
  210. bytes_parsed = 0;
  211. if (dma_q->is_partial_line) {
  212. /* Handle the case of a partial line */
  213. sav_eav = dma_q->last_sav;
  214. } else {
  215. /* Check for a SAV/EAV overlapping
  216. the buffer boundary */
  217. sav_eav =
  218. cx231xx_find_boundary_SAV_EAV(p_buffer,
  219. dma_q->partial_buf,
  220. &bytes_parsed);
  221. }
  222. sav_eav &= 0xF0;
  223. /* Get the first line if we have some portion of an SAV/EAV from
  224. the last buffer or a partial line */
  225. if (sav_eav) {
  226. bytes_parsed += cx231xx_get_video_line(dev, dma_q,
  227. sav_eav, /* SAV/EAV */
  228. p_buffer + bytes_parsed, /* p_buffer */
  229. buffer_size - bytes_parsed);/* buf size */
  230. }
  231. /* Now parse data that is completely in this buffer */
  232. /* dma_q->is_partial_line = 0; */
  233. while (bytes_parsed < buffer_size) {
  234. u32 bytes_used = 0;
  235. sav_eav = cx231xx_find_next_SAV_EAV(
  236. p_buffer + bytes_parsed, /* p_buffer */
  237. buffer_size - bytes_parsed, /* buf size */
  238. &bytes_used);/* bytes used to get SAV/EAV */
  239. bytes_parsed += bytes_used;
  240. sav_eav &= 0xF0;
  241. if (sav_eav && (bytes_parsed < buffer_size)) {
  242. bytes_parsed += cx231xx_get_video_line(dev,
  243. dma_q, sav_eav, /* SAV/EAV */
  244. p_buffer + bytes_parsed,/* p_buffer */
  245. buffer_size - bytes_parsed);/*buf size*/
  246. }
  247. }
  248. /* Save the last four bytes of the buffer so we can check the
  249. buffer boundary condition next time */
  250. memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4);
  251. bytes_parsed = 0;
  252. }
  253. return rc;
  254. }
  255. static inline int cx231xx_bulk_copy(struct cx231xx *dev, struct urb *urb)
  256. {
  257. struct cx231xx_dmaqueue *dma_q = urb->context;
  258. int rc = 1;
  259. unsigned char *p_buffer;
  260. u32 bytes_parsed = 0, buffer_size = 0;
  261. u8 sav_eav = 0;
  262. if (!dev)
  263. return 0;
  264. if (dev->state & DEV_DISCONNECTED)
  265. return 0;
  266. if (urb->status < 0) {
  267. print_err_status(dev, -1, urb->status);
  268. if (urb->status == -ENOENT)
  269. return 0;
  270. }
  271. if (1) {
  272. /* get buffer pointer and length */
  273. p_buffer = urb->transfer_buffer;
  274. buffer_size = urb->actual_length;
  275. bytes_parsed = 0;
  276. if (dma_q->is_partial_line) {
  277. /* Handle the case of a partial line */
  278. sav_eav = dma_q->last_sav;
  279. } else {
  280. /* Check for a SAV/EAV overlapping
  281. the buffer boundary */
  282. sav_eav =
  283. cx231xx_find_boundary_SAV_EAV(p_buffer,
  284. dma_q->partial_buf,
  285. &bytes_parsed);
  286. }
  287. sav_eav &= 0xF0;
  288. /* Get the first line if we have some portion of an SAV/EAV from
  289. the last buffer or a partial line */
  290. if (sav_eav) {
  291. bytes_parsed += cx231xx_get_video_line(dev, dma_q,
  292. sav_eav, /* SAV/EAV */
  293. p_buffer + bytes_parsed, /* p_buffer */
  294. buffer_size - bytes_parsed);/* buf size */
  295. }
  296. /* Now parse data that is completely in this buffer */
  297. /* dma_q->is_partial_line = 0; */
  298. while (bytes_parsed < buffer_size) {
  299. u32 bytes_used = 0;
  300. sav_eav = cx231xx_find_next_SAV_EAV(
  301. p_buffer + bytes_parsed, /* p_buffer */
  302. buffer_size - bytes_parsed, /* buf size */
  303. &bytes_used);/* bytes used to get SAV/EAV */
  304. bytes_parsed += bytes_used;
  305. sav_eav &= 0xF0;
  306. if (sav_eav && (bytes_parsed < buffer_size)) {
  307. bytes_parsed += cx231xx_get_video_line(dev,
  308. dma_q, sav_eav, /* SAV/EAV */
  309. p_buffer + bytes_parsed,/* p_buffer */
  310. buffer_size - bytes_parsed);/*buf size*/
  311. }
  312. }
  313. /* Save the last four bytes of the buffer so we can check the
  314. buffer boundary condition next time */
  315. memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4);
  316. bytes_parsed = 0;
  317. }
  318. return rc;
  319. }
  320. u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf,
  321. u32 *p_bytes_used)
  322. {
  323. u32 bytes_used;
  324. u8 boundary_bytes[8];
  325. u8 sav_eav = 0;
  326. *p_bytes_used = 0;
  327. /* Create an array of the last 4 bytes of the last buffer and the first
  328. 4 bytes of the current buffer. */
  329. memcpy(boundary_bytes, partial_buf, 4);
  330. memcpy(boundary_bytes + 4, p_buffer, 4);
  331. /* Check for the SAV/EAV in the boundary buffer */
  332. sav_eav = cx231xx_find_next_SAV_EAV((u8 *)&boundary_bytes, 8,
  333. &bytes_used);
  334. if (sav_eav) {
  335. /* found a boundary SAV/EAV. Updates the bytes used to reflect
  336. only those used in the new buffer */
  337. *p_bytes_used = bytes_used - 4;
  338. }
  339. return sav_eav;
  340. }
  341. u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size, u32 *p_bytes_used)
  342. {
  343. u32 i;
  344. u8 sav_eav = 0;
  345. /*
  346. * Don't search if the buffer size is less than 4. It causes a page
  347. * fault since buffer_size - 4 evaluates to a large number in that
  348. * case.
  349. */
  350. if (buffer_size < 4) {
  351. *p_bytes_used = buffer_size;
  352. return 0;
  353. }
  354. for (i = 0; i < (buffer_size - 3); i++) {
  355. if ((p_buffer[i] == 0xFF) &&
  356. (p_buffer[i + 1] == 0x00) && (p_buffer[i + 2] == 0x00)) {
  357. *p_bytes_used = i + 4;
  358. sav_eav = p_buffer[i + 3];
  359. return sav_eav;
  360. }
  361. }
  362. *p_bytes_used = buffer_size;
  363. return 0;
  364. }
  365. u32 cx231xx_get_video_line(struct cx231xx *dev,
  366. struct cx231xx_dmaqueue *dma_q, u8 sav_eav,
  367. u8 *p_buffer, u32 buffer_size)
  368. {
  369. u32 bytes_copied = 0;
  370. int current_field = -1;
  371. switch (sav_eav) {
  372. case SAV_ACTIVE_VIDEO_FIELD1:
  373. /* looking for skipped line which occurred in PAL 720x480 mode.
  374. In this case, there will be no active data contained
  375. between the SAV and EAV */
  376. if ((buffer_size > 3) && (p_buffer[0] == 0xFF) &&
  377. (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) &&
  378. ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) ||
  379. (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) ||
  380. (p_buffer[3] == EAV_VBLANK_FIELD1) ||
  381. (p_buffer[3] == EAV_VBLANK_FIELD2)))
  382. return bytes_copied;
  383. current_field = 1;
  384. break;
  385. case SAV_ACTIVE_VIDEO_FIELD2:
  386. /* looking for skipped line which occurred in PAL 720x480 mode.
  387. In this case, there will be no active data contained between
  388. the SAV and EAV */
  389. if ((buffer_size > 3) && (p_buffer[0] == 0xFF) &&
  390. (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) &&
  391. ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) ||
  392. (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) ||
  393. (p_buffer[3] == EAV_VBLANK_FIELD1) ||
  394. (p_buffer[3] == EAV_VBLANK_FIELD2)))
  395. return bytes_copied;
  396. current_field = 2;
  397. break;
  398. }
  399. dma_q->last_sav = sav_eav;
  400. bytes_copied = cx231xx_copy_video_line(dev, dma_q, p_buffer,
  401. buffer_size, current_field);
  402. return bytes_copied;
  403. }
  404. u32 cx231xx_copy_video_line(struct cx231xx *dev,
  405. struct cx231xx_dmaqueue *dma_q, u8 *p_line,
  406. u32 length, int field_number)
  407. {
  408. u32 bytes_to_copy;
  409. struct cx231xx_buffer *buf;
  410. u32 _line_size = dev->width * 2;
  411. if (dma_q->current_field != field_number)
  412. cx231xx_reset_video_buffer(dev, dma_q);
  413. /* get the buffer pointer */
  414. if (dev->USE_ISO)
  415. buf = dev->video_mode.isoc_ctl.buf;
  416. else
  417. buf = dev->video_mode.bulk_ctl.buf;
  418. /* Remember the field number for next time */
  419. dma_q->current_field = field_number;
  420. bytes_to_copy = dma_q->bytes_left_in_line;
  421. if (bytes_to_copy > length)
  422. bytes_to_copy = length;
  423. if (dma_q->lines_completed >= dma_q->lines_per_field) {
  424. dma_q->bytes_left_in_line -= bytes_to_copy;
  425. dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0) ?
  426. 0 : 1;
  427. return 0;
  428. }
  429. dma_q->is_partial_line = 1;
  430. /* If we don't have a buffer, just return the number of bytes we would
  431. have copied if we had a buffer. */
  432. if (!buf) {
  433. dma_q->bytes_left_in_line -= bytes_to_copy;
  434. dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0)
  435. ? 0 : 1;
  436. return bytes_to_copy;
  437. }
  438. /* copy the data to video buffer */
  439. cx231xx_do_copy(dev, dma_q, p_line, bytes_to_copy);
  440. dma_q->pos += bytes_to_copy;
  441. dma_q->bytes_left_in_line -= bytes_to_copy;
  442. if (dma_q->bytes_left_in_line == 0) {
  443. dma_q->bytes_left_in_line = _line_size;
  444. dma_q->lines_completed++;
  445. dma_q->is_partial_line = 0;
  446. if (cx231xx_is_buffer_done(dev, dma_q) && buf) {
  447. buffer_filled(dev, dma_q, buf);
  448. dma_q->pos = 0;
  449. buf = NULL;
  450. dma_q->lines_completed = 0;
  451. }
  452. }
  453. return bytes_to_copy;
  454. }
  455. void cx231xx_reset_video_buffer(struct cx231xx *dev,
  456. struct cx231xx_dmaqueue *dma_q)
  457. {
  458. struct cx231xx_buffer *buf;
  459. /* handle the switch from field 1 to field 2 */
  460. if (dma_q->current_field == 1) {
  461. if (dma_q->lines_completed >= dma_q->lines_per_field)
  462. dma_q->field1_done = 1;
  463. else
  464. dma_q->field1_done = 0;
  465. }
  466. if (dev->USE_ISO)
  467. buf = dev->video_mode.isoc_ctl.buf;
  468. else
  469. buf = dev->video_mode.bulk_ctl.buf;
  470. if (buf == NULL) {
  471. /* first try to get the buffer */
  472. get_next_buf(dma_q, &buf);
  473. dma_q->pos = 0;
  474. dma_q->field1_done = 0;
  475. dma_q->current_field = -1;
  476. }
  477. /* reset the counters */
  478. dma_q->bytes_left_in_line = dev->width << 1;
  479. dma_q->lines_completed = 0;
  480. }
  481. int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
  482. u8 *p_buffer, u32 bytes_to_copy)
  483. {
  484. u8 *p_out_buffer = NULL;
  485. u32 current_line_bytes_copied = 0;
  486. struct cx231xx_buffer *buf;
  487. u32 _line_size = dev->width << 1;
  488. void *startwrite;
  489. int offset, lencopy;
  490. if (dev->USE_ISO)
  491. buf = dev->video_mode.isoc_ctl.buf;
  492. else
  493. buf = dev->video_mode.bulk_ctl.buf;
  494. if (buf == NULL)
  495. return -1;
  496. p_out_buffer = videobuf_to_vmalloc(&buf->vb);
  497. current_line_bytes_copied = _line_size - dma_q->bytes_left_in_line;
  498. /* Offset field 2 one line from the top of the buffer */
  499. offset = (dma_q->current_field == 1) ? 0 : _line_size;
  500. /* Offset for field 2 */
  501. startwrite = p_out_buffer + offset;
  502. /* lines already completed in the current field */
  503. startwrite += (dma_q->lines_completed * _line_size * 2);
  504. /* bytes already completed in the current line */
  505. startwrite += current_line_bytes_copied;
  506. lencopy = dma_q->bytes_left_in_line > bytes_to_copy ?
  507. bytes_to_copy : dma_q->bytes_left_in_line;
  508. if ((u8 *)(startwrite + lencopy) > (u8 *)(p_out_buffer + buf->vb.size))
  509. return 0;
  510. /* The below copies the UYVY data straight into video buffer */
  511. cx231xx_swab((u16 *) p_buffer, (u16 *) startwrite, (u16) lencopy);
  512. return 0;
  513. }
  514. void cx231xx_swab(u16 *from, u16 *to, u16 len)
  515. {
  516. u16 i;
  517. if (len <= 0)
  518. return;
  519. for (i = 0; i < len / 2; i++)
  520. to[i] = (from[i] << 8) | (from[i] >> 8);
  521. }
  522. u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q)
  523. {
  524. u8 buffer_complete = 0;
  525. /* Dual field stream */
  526. buffer_complete = ((dma_q->current_field == 2) &&
  527. (dma_q->lines_completed >= dma_q->lines_per_field) &&
  528. dma_q->field1_done);
  529. return buffer_complete;
  530. }
  531. /* ------------------------------------------------------------------
  532. Videobuf operations
  533. ------------------------------------------------------------------*/
  534. static int
  535. buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
  536. {
  537. struct cx231xx_fh *fh = vq->priv_data;
  538. struct cx231xx *dev = fh->dev;
  539. *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)>>3;
  540. if (0 == *count)
  541. *count = CX231XX_DEF_BUF;
  542. if (*count < CX231XX_MIN_BUF)
  543. *count = CX231XX_MIN_BUF;
  544. return 0;
  545. }
  546. /* This is called *without* dev->slock held; please keep it that way */
  547. static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf)
  548. {
  549. struct cx231xx_fh *fh = vq->priv_data;
  550. struct cx231xx *dev = fh->dev;
  551. unsigned long flags = 0;
  552. if (in_interrupt())
  553. BUG();
  554. /* We used to wait for the buffer to finish here, but this didn't work
  555. because, as we were keeping the state as VIDEOBUF_QUEUED,
  556. videobuf_queue_cancel marked it as finished for us.
  557. (Also, it could wedge forever if the hardware was misconfigured.)
  558. This should be safe; by the time we get here, the buffer isn't
  559. queued anymore. If we ever start marking the buffers as
  560. VIDEOBUF_ACTIVE, it won't be, though.
  561. */
  562. spin_lock_irqsave(&dev->video_mode.slock, flags);
  563. if (dev->USE_ISO) {
  564. if (dev->video_mode.isoc_ctl.buf == buf)
  565. dev->video_mode.isoc_ctl.buf = NULL;
  566. } else {
  567. if (dev->video_mode.bulk_ctl.buf == buf)
  568. dev->video_mode.bulk_ctl.buf = NULL;
  569. }
  570. spin_unlock_irqrestore(&dev->video_mode.slock, flags);
  571. videobuf_vmalloc_free(&buf->vb);
  572. buf->vb.state = VIDEOBUF_NEEDS_INIT;
  573. }
  574. static int
  575. buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
  576. enum v4l2_field field)
  577. {
  578. struct cx231xx_fh *fh = vq->priv_data;
  579. struct cx231xx_buffer *buf =
  580. container_of(vb, struct cx231xx_buffer, vb);
  581. struct cx231xx *dev = fh->dev;
  582. int rc = 0, urb_init = 0;
  583. /* The only currently supported format is 16 bits/pixel */
  584. buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth
  585. + 7) >> 3;
  586. if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
  587. return -EINVAL;
  588. buf->vb.width = dev->width;
  589. buf->vb.height = dev->height;
  590. buf->vb.field = field;
  591. if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
  592. rc = videobuf_iolock(vq, &buf->vb, NULL);
  593. if (rc < 0)
  594. goto fail;
  595. }
  596. if (dev->USE_ISO) {
  597. if (!dev->video_mode.isoc_ctl.num_bufs)
  598. urb_init = 1;
  599. } else {
  600. if (!dev->video_mode.bulk_ctl.num_bufs)
  601. urb_init = 1;
  602. }
  603. /*cx231xx_info("urb_init=%d dev->video_mode.max_pkt_size=%d\n",
  604. urb_init, dev->video_mode.max_pkt_size);*/
  605. if (urb_init) {
  606. dev->mode_tv = 0;
  607. if (dev->USE_ISO)
  608. rc = cx231xx_init_isoc(dev, CX231XX_NUM_PACKETS,
  609. CX231XX_NUM_BUFS,
  610. dev->video_mode.max_pkt_size,
  611. cx231xx_isoc_copy);
  612. else
  613. rc = cx231xx_init_bulk(dev, CX231XX_NUM_PACKETS,
  614. CX231XX_NUM_BUFS,
  615. dev->video_mode.max_pkt_size,
  616. cx231xx_bulk_copy);
  617. if (rc < 0)
  618. goto fail;
  619. }
  620. buf->vb.state = VIDEOBUF_PREPARED;
  621. return 0;
  622. fail:
  623. free_buffer(vq, buf);
  624. return rc;
  625. }
  626. static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
  627. {
  628. struct cx231xx_buffer *buf =
  629. container_of(vb, struct cx231xx_buffer, vb);
  630. struct cx231xx_fh *fh = vq->priv_data;
  631. struct cx231xx *dev = fh->dev;
  632. struct cx231xx_dmaqueue *vidq = &dev->video_mode.vidq;
  633. buf->vb.state = VIDEOBUF_QUEUED;
  634. list_add_tail(&buf->vb.queue, &vidq->active);
  635. }
  636. static void buffer_release(struct videobuf_queue *vq,
  637. struct videobuf_buffer *vb)
  638. {
  639. struct cx231xx_buffer *buf =
  640. container_of(vb, struct cx231xx_buffer, vb);
  641. struct cx231xx_fh *fh = vq->priv_data;
  642. struct cx231xx *dev = (struct cx231xx *)fh->dev;
  643. cx231xx_isocdbg("cx231xx: called buffer_release\n");
  644. free_buffer(vq, buf);
  645. }
  646. static struct videobuf_queue_ops cx231xx_video_qops = {
  647. .buf_setup = buffer_setup,
  648. .buf_prepare = buffer_prepare,
  649. .buf_queue = buffer_queue,
  650. .buf_release = buffer_release,
  651. };
  652. /********************* v4l2 interface **************************************/
  653. void video_mux(struct cx231xx *dev, int index)
  654. {
  655. dev->video_input = index;
  656. dev->ctl_ainput = INPUT(index)->amux;
  657. cx231xx_set_video_input_mux(dev, index);
  658. cx25840_call(dev, video, s_routing, INPUT(index)->vmux, 0, 0);
  659. cx231xx_set_audio_input(dev, dev->ctl_ainput);
  660. cx231xx_info("video_mux : %d\n", index);
  661. /* do mode control overrides if required */
  662. cx231xx_do_mode_ctrl_overrides(dev);
  663. }
  664. /* Usage lock check functions */
  665. static int res_get(struct cx231xx_fh *fh)
  666. {
  667. struct cx231xx *dev = fh->dev;
  668. int rc = 0;
  669. /* This instance already has stream_on */
  670. if (fh->stream_on)
  671. return rc;
  672. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  673. if (dev->stream_on)
  674. return -EBUSY;
  675. dev->stream_on = 1;
  676. } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
  677. if (dev->vbi_stream_on)
  678. return -EBUSY;
  679. dev->vbi_stream_on = 1;
  680. } else
  681. return -EINVAL;
  682. fh->stream_on = 1;
  683. return rc;
  684. }
  685. static int res_check(struct cx231xx_fh *fh)
  686. {
  687. return fh->stream_on;
  688. }
  689. static void res_free(struct cx231xx_fh *fh)
  690. {
  691. struct cx231xx *dev = fh->dev;
  692. fh->stream_on = 0;
  693. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  694. dev->stream_on = 0;
  695. if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
  696. dev->vbi_stream_on = 0;
  697. }
  698. static int check_dev(struct cx231xx *dev)
  699. {
  700. if (dev->state & DEV_DISCONNECTED) {
  701. cx231xx_errdev("v4l2 ioctl: device not present\n");
  702. return -ENODEV;
  703. }
  704. return 0;
  705. }
  706. /* ------------------------------------------------------------------
  707. IOCTL vidioc handling
  708. ------------------------------------------------------------------*/
  709. static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  710. struct v4l2_format *f)
  711. {
  712. struct cx231xx_fh *fh = priv;
  713. struct cx231xx *dev = fh->dev;
  714. f->fmt.pix.width = dev->width;
  715. f->fmt.pix.height = dev->height;
  716. f->fmt.pix.pixelformat = dev->format->fourcc;
  717. f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
  718. f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
  719. f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  720. f->fmt.pix.field = V4L2_FIELD_INTERLACED;
  721. f->fmt.pix.priv = 0;
  722. return 0;
  723. }
  724. static struct cx231xx_fmt *format_by_fourcc(unsigned int fourcc)
  725. {
  726. unsigned int i;
  727. for (i = 0; i < ARRAY_SIZE(format); i++)
  728. if (format[i].fourcc == fourcc)
  729. return &format[i];
  730. return NULL;
  731. }
  732. static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  733. struct v4l2_format *f)
  734. {
  735. struct cx231xx_fh *fh = priv;
  736. struct cx231xx *dev = fh->dev;
  737. unsigned int width = f->fmt.pix.width;
  738. unsigned int height = f->fmt.pix.height;
  739. unsigned int maxw = norm_maxw(dev);
  740. unsigned int maxh = norm_maxh(dev);
  741. struct cx231xx_fmt *fmt;
  742. fmt = format_by_fourcc(f->fmt.pix.pixelformat);
  743. if (!fmt) {
  744. cx231xx_videodbg("Fourcc format (%08x) invalid.\n",
  745. f->fmt.pix.pixelformat);
  746. return -EINVAL;
  747. }
  748. /* width must even because of the YUYV format
  749. height must be even because of interlacing */
  750. v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh, 1, 0);
  751. f->fmt.pix.width = width;
  752. f->fmt.pix.height = height;
  753. f->fmt.pix.pixelformat = fmt->fourcc;
  754. f->fmt.pix.bytesperline = (width * fmt->depth + 7) >> 3;
  755. f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height;
  756. f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  757. f->fmt.pix.field = V4L2_FIELD_INTERLACED;
  758. f->fmt.pix.priv = 0;
  759. return 0;
  760. }
  761. static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  762. struct v4l2_format *f)
  763. {
  764. struct cx231xx_fh *fh = priv;
  765. struct cx231xx *dev = fh->dev;
  766. int rc;
  767. struct cx231xx_fmt *fmt;
  768. struct v4l2_mbus_framefmt mbus_fmt;
  769. rc = check_dev(dev);
  770. if (rc < 0)
  771. return rc;
  772. vidioc_try_fmt_vid_cap(file, priv, f);
  773. fmt = format_by_fourcc(f->fmt.pix.pixelformat);
  774. if (!fmt)
  775. return -EINVAL;
  776. if (videobuf_queue_is_busy(&fh->vb_vidq)) {
  777. cx231xx_errdev("%s queue busy\n", __func__);
  778. return -EBUSY;
  779. }
  780. if (dev->stream_on && !fh->stream_on) {
  781. cx231xx_errdev("%s device in use by another fh\n", __func__);
  782. return -EBUSY;
  783. }
  784. /* set new image size */
  785. dev->width = f->fmt.pix.width;
  786. dev->height = f->fmt.pix.height;
  787. dev->format = fmt;
  788. v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED);
  789. call_all(dev, video, s_mbus_fmt, &mbus_fmt);
  790. v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt);
  791. return rc;
  792. }
  793. static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
  794. {
  795. struct cx231xx_fh *fh = priv;
  796. struct cx231xx *dev = fh->dev;
  797. *id = dev->norm;
  798. return 0;
  799. }
  800. static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
  801. {
  802. struct cx231xx_fh *fh = priv;
  803. struct cx231xx *dev = fh->dev;
  804. struct v4l2_mbus_framefmt mbus_fmt;
  805. struct v4l2_format f;
  806. int rc;
  807. rc = check_dev(dev);
  808. if (rc < 0)
  809. return rc;
  810. cx231xx_info("vidioc_s_std : 0x%x\n", (unsigned int)*norm);
  811. dev->norm = *norm;
  812. /* Adjusts width/height, if needed */
  813. f.fmt.pix.width = dev->width;
  814. f.fmt.pix.height = dev->height;
  815. vidioc_try_fmt_vid_cap(file, priv, &f);
  816. call_all(dev, core, s_std, dev->norm);
  817. /* We need to reset basic properties in the decoder related to
  818. resolution (since a standard change effects things like the number
  819. of lines in VACT, etc) */
  820. v4l2_fill_mbus_format(&mbus_fmt, &f.fmt.pix, V4L2_MBUS_FMT_FIXED);
  821. call_all(dev, video, s_mbus_fmt, &mbus_fmt);
  822. v4l2_fill_pix_format(&f.fmt.pix, &mbus_fmt);
  823. /* set new image size */
  824. dev->width = f.fmt.pix.width;
  825. dev->height = f.fmt.pix.height;
  826. /* do mode control overrides */
  827. cx231xx_do_mode_ctrl_overrides(dev);
  828. return 0;
  829. }
  830. static const char *iname[] = {
  831. [CX231XX_VMUX_COMPOSITE1] = "Composite1",
  832. [CX231XX_VMUX_SVIDEO] = "S-Video",
  833. [CX231XX_VMUX_TELEVISION] = "Television",
  834. [CX231XX_VMUX_CABLE] = "Cable TV",
  835. [CX231XX_VMUX_DVB] = "DVB",
  836. [CX231XX_VMUX_DEBUG] = "for debug only",
  837. };
  838. static int vidioc_enum_input(struct file *file, void *priv,
  839. struct v4l2_input *i)
  840. {
  841. struct cx231xx_fh *fh = priv;
  842. struct cx231xx *dev = fh->dev;
  843. u32 gen_stat;
  844. unsigned int ret, n;
  845. n = i->index;
  846. if (n >= MAX_CX231XX_INPUT)
  847. return -EINVAL;
  848. if (0 == INPUT(n)->type)
  849. return -EINVAL;
  850. i->index = n;
  851. i->type = V4L2_INPUT_TYPE_CAMERA;
  852. strcpy(i->name, iname[INPUT(n)->type]);
  853. if ((CX231XX_VMUX_TELEVISION == INPUT(n)->type) ||
  854. (CX231XX_VMUX_CABLE == INPUT(n)->type))
  855. i->type = V4L2_INPUT_TYPE_TUNER;
  856. i->std = dev->vdev->tvnorms;
  857. /* If they are asking about the active input, read signal status */
  858. if (n == dev->video_input) {
  859. ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
  860. GEN_STAT, 2, &gen_stat, 4);
  861. if (ret > 0) {
  862. if ((gen_stat & FLD_VPRES) == 0x00)
  863. i->status |= V4L2_IN_ST_NO_SIGNAL;
  864. if ((gen_stat & FLD_HLOCK) == 0x00)
  865. i->status |= V4L2_IN_ST_NO_H_LOCK;
  866. }
  867. }
  868. return 0;
  869. }
  870. static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  871. {
  872. struct cx231xx_fh *fh = priv;
  873. struct cx231xx *dev = fh->dev;
  874. *i = dev->video_input;
  875. return 0;
  876. }
  877. static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  878. {
  879. struct cx231xx_fh *fh = priv;
  880. struct cx231xx *dev = fh->dev;
  881. int rc;
  882. dev->mode_tv = 0;
  883. rc = check_dev(dev);
  884. if (rc < 0)
  885. return rc;
  886. if (i >= MAX_CX231XX_INPUT)
  887. return -EINVAL;
  888. if (0 == INPUT(i)->type)
  889. return -EINVAL;
  890. video_mux(dev, i);
  891. if (INPUT(i)->type == CX231XX_VMUX_TELEVISION ||
  892. INPUT(i)->type == CX231XX_VMUX_CABLE) {
  893. /* There's a tuner, so reset the standard and put it on the
  894. last known frequency (since it was probably powered down
  895. until now */
  896. call_all(dev, core, s_std, dev->norm);
  897. }
  898. return 0;
  899. }
  900. static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
  901. {
  902. struct cx231xx_fh *fh = priv;
  903. struct cx231xx *dev = fh->dev;
  904. int rc;
  905. rc = check_dev(dev);
  906. if (rc < 0)
  907. return rc;
  908. if (0 != t->index)
  909. return -EINVAL;
  910. strcpy(t->name, "Tuner");
  911. t->type = V4L2_TUNER_ANALOG_TV;
  912. t->capability = V4L2_TUNER_CAP_NORM;
  913. t->rangehigh = 0xffffffffUL;
  914. t->signal = 0xffff; /* LOCKED */
  915. call_all(dev, tuner, g_tuner, t);
  916. return 0;
  917. }
  918. static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
  919. {
  920. struct cx231xx_fh *fh = priv;
  921. struct cx231xx *dev = fh->dev;
  922. int rc;
  923. rc = check_dev(dev);
  924. if (rc < 0)
  925. return rc;
  926. if (0 != t->index)
  927. return -EINVAL;
  928. #if 0
  929. call_all(dev, tuner, s_tuner, t);
  930. #endif
  931. return 0;
  932. }
  933. static int vidioc_g_frequency(struct file *file, void *priv,
  934. struct v4l2_frequency *f)
  935. {
  936. struct cx231xx_fh *fh = priv;
  937. struct cx231xx *dev = fh->dev;
  938. if (f->tuner)
  939. return -EINVAL;
  940. f->frequency = dev->ctl_freq;
  941. return 0;
  942. }
  943. static int vidioc_s_frequency(struct file *file, void *priv,
  944. struct v4l2_frequency *f)
  945. {
  946. struct cx231xx_fh *fh = priv;
  947. struct cx231xx *dev = fh->dev;
  948. int rc;
  949. u32 if_frequency = 5400000;
  950. cx231xx_info("Enter vidioc_s_frequency()f->frequency=%d;f->type=%d\n",
  951. f->frequency, f->type);
  952. /*cx231xx_info("f->type: 1-radio 2-analogTV 3-digitalTV\n");*/
  953. rc = check_dev(dev);
  954. if (rc < 0)
  955. return rc;
  956. if (0 != f->tuner)
  957. return -EINVAL;
  958. /* set pre channel change settings in DIF first */
  959. rc = cx231xx_tuner_pre_channel_change(dev);
  960. call_all(dev, tuner, s_frequency, f);
  961. call_all(dev, tuner, g_frequency, f);
  962. dev->ctl_freq = f->frequency;
  963. /* set post channel change settings in DIF first */
  964. rc = cx231xx_tuner_post_channel_change(dev);
  965. if (dev->tuner_type == TUNER_NXP_TDA18271) {
  966. if (dev->norm & (V4L2_STD_MN | V4L2_STD_NTSC_443))
  967. if_frequency = 5400000; /*5.4MHz */
  968. else if (dev->norm & V4L2_STD_B)
  969. if_frequency = 6000000; /*6.0MHz */
  970. else if (dev->norm & (V4L2_STD_PAL_DK | V4L2_STD_SECAM_DK))
  971. if_frequency = 6900000; /*6.9MHz */
  972. else if (dev->norm & V4L2_STD_GH)
  973. if_frequency = 7100000; /*7.1MHz */
  974. else if (dev->norm & V4L2_STD_PAL_I)
  975. if_frequency = 7250000; /*7.25MHz */
  976. else if (dev->norm & V4L2_STD_SECAM_L)
  977. if_frequency = 6900000; /*6.9MHz */
  978. else if (dev->norm & V4L2_STD_SECAM_LC)
  979. if_frequency = 1250000; /*1.25MHz */
  980. cx231xx_info("if_frequency is set to %d\n", if_frequency);
  981. cx231xx_set_Colibri_For_LowIF(dev, if_frequency, 1, 1);
  982. update_HH_register_after_set_DIF(dev);
  983. }
  984. cx231xx_info("Set New FREQUENCY to %d\n", f->frequency);
  985. return rc;
  986. }
  987. static int vidioc_g_chip_ident(struct file *file, void *fh,
  988. struct v4l2_dbg_chip_ident *chip)
  989. {
  990. chip->ident = V4L2_IDENT_NONE;
  991. chip->revision = 0;
  992. if (chip->match.type == V4L2_CHIP_MATCH_HOST) {
  993. if (v4l2_chip_match_host(&chip->match))
  994. chip->ident = V4L2_IDENT_CX23100;
  995. return 0;
  996. }
  997. return -EINVAL;
  998. }
  999. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1000. /*
  1001. -R, --list-registers=type=<host/i2cdrv/i2caddr>,
  1002. chip=<chip>[,min=<addr>,max=<addr>]
  1003. dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER]
  1004. -r, --set-register=type=<host/i2cdrv/i2caddr>,
  1005. chip=<chip>,reg=<addr>,val=<val>
  1006. set the register [VIDIOC_DBG_S_REGISTER]
  1007. if type == host, then <chip> is the hosts chip ID (default 0)
  1008. if type == i2cdrv (default), then <chip> is the I2C driver name or ID
  1009. if type == i2caddr, then <chip> is the 7-bit I2C address
  1010. */
  1011. static int vidioc_g_register(struct file *file, void *priv,
  1012. struct v4l2_dbg_register *reg)
  1013. {
  1014. struct cx231xx_fh *fh = priv;
  1015. struct cx231xx *dev = fh->dev;
  1016. int ret = 0;
  1017. u8 value[4] = { 0, 0, 0, 0 };
  1018. u32 data = 0;
  1019. switch (reg->match.type) {
  1020. case V4L2_CHIP_MATCH_HOST:
  1021. switch (reg->match.addr) {
  1022. case 0: /* Cx231xx - internal registers */
  1023. ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
  1024. (u16)reg->reg, value, 4);
  1025. reg->val = value[0] | value[1] << 8 |
  1026. value[2] << 16 | value[3] << 24;
  1027. break;
  1028. case 1: /* AFE - read byte */
  1029. ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
  1030. (u16)reg->reg, 2, &data, 1);
  1031. reg->val = le32_to_cpu(data & 0xff);
  1032. break;
  1033. case 14: /* AFE - read dword */
  1034. ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
  1035. (u16)reg->reg, 2, &data, 4);
  1036. reg->val = le32_to_cpu(data);
  1037. break;
  1038. case 2: /* Video Block - read byte */
  1039. ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
  1040. (u16)reg->reg, 2, &data, 1);
  1041. reg->val = le32_to_cpu(data & 0xff);
  1042. break;
  1043. case 24: /* Video Block - read dword */
  1044. ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
  1045. (u16)reg->reg, 2, &data, 4);
  1046. reg->val = le32_to_cpu(data);
  1047. break;
  1048. case 3: /* I2S block - read byte */
  1049. ret = cx231xx_read_i2c_data(dev,
  1050. I2S_BLK_DEVICE_ADDRESS,
  1051. (u16)reg->reg, 1,
  1052. &data, 1);
  1053. reg->val = le32_to_cpu(data & 0xff);
  1054. break;
  1055. case 34: /* I2S Block - read dword */
  1056. ret =
  1057. cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
  1058. (u16)reg->reg, 1, &data, 4);
  1059. reg->val = le32_to_cpu(data);
  1060. break;
  1061. }
  1062. return ret < 0 ? ret : 0;
  1063. case V4L2_CHIP_MATCH_I2C_DRIVER:
  1064. call_all(dev, core, g_register, reg);
  1065. return 0;
  1066. case V4L2_CHIP_MATCH_I2C_ADDR:/*for register debug*/
  1067. switch (reg->match.addr) {
  1068. case 0: /* Cx231xx - internal registers */
  1069. ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
  1070. (u16)reg->reg, value, 4);
  1071. reg->val = value[0] | value[1] << 8 |
  1072. value[2] << 16 | value[3] << 24;
  1073. break;
  1074. case 0x600:/* AFE - read byte */
  1075. ret = cx231xx_read_i2c_master(dev, AFE_DEVICE_ADDRESS,
  1076. (u16)reg->reg, 2,
  1077. &data, 1 , 0);
  1078. reg->val = le32_to_cpu(data & 0xff);
  1079. break;
  1080. case 0x880:/* Video Block - read byte */
  1081. if (reg->reg < 0x0b) {
  1082. ret = cx231xx_read_i2c_master(dev,
  1083. VID_BLK_I2C_ADDRESS,
  1084. (u16)reg->reg, 2,
  1085. &data, 1 , 0);
  1086. reg->val = le32_to_cpu(data & 0xff);
  1087. } else {
  1088. ret = cx231xx_read_i2c_master(dev,
  1089. VID_BLK_I2C_ADDRESS,
  1090. (u16)reg->reg, 2,
  1091. &data, 4 , 0);
  1092. reg->val = le32_to_cpu(data);
  1093. }
  1094. break;
  1095. case 0x980:
  1096. ret = cx231xx_read_i2c_master(dev,
  1097. I2S_BLK_DEVICE_ADDRESS,
  1098. (u16)reg->reg, 1,
  1099. &data, 1 , 0);
  1100. reg->val = le32_to_cpu(data & 0xff);
  1101. break;
  1102. case 0x400:
  1103. ret =
  1104. cx231xx_read_i2c_master(dev, 0x40,
  1105. (u16)reg->reg, 1,
  1106. &data, 1 , 0);
  1107. reg->val = le32_to_cpu(data & 0xff);
  1108. break;
  1109. case 0xc01:
  1110. ret =
  1111. cx231xx_read_i2c_master(dev, 0xc0,
  1112. (u16)reg->reg, 2,
  1113. &data, 38, 1);
  1114. reg->val = le32_to_cpu(data);
  1115. break;
  1116. case 0x022:
  1117. ret =
  1118. cx231xx_read_i2c_master(dev, 0x02,
  1119. (u16)reg->reg, 1,
  1120. &data, 1, 2);
  1121. reg->val = le32_to_cpu(data & 0xff);
  1122. break;
  1123. case 0x322:
  1124. ret = cx231xx_read_i2c_master(dev,
  1125. 0x32,
  1126. (u16)reg->reg, 1,
  1127. &data, 4 , 2);
  1128. reg->val = le32_to_cpu(data);
  1129. break;
  1130. case 0x342:
  1131. ret = cx231xx_read_i2c_master(dev,
  1132. 0x34,
  1133. (u16)reg->reg, 1,
  1134. &data, 4 , 2);
  1135. reg->val = le32_to_cpu(data);
  1136. break;
  1137. default:
  1138. cx231xx_info("no match device address!!\n");
  1139. break;
  1140. }
  1141. return ret < 0 ? ret : 0;
  1142. /*return -EINVAL;*/
  1143. default:
  1144. if (!v4l2_chip_match_host(&reg->match))
  1145. return -EINVAL;
  1146. }
  1147. call_all(dev, core, g_register, reg);
  1148. return ret;
  1149. }
  1150. static int vidioc_s_register(struct file *file, void *priv,
  1151. struct v4l2_dbg_register *reg)
  1152. {
  1153. struct cx231xx_fh *fh = priv;
  1154. struct cx231xx *dev = fh->dev;
  1155. int ret = 0;
  1156. __le64 buf;
  1157. u32 value;
  1158. u8 data[4] = { 0, 0, 0, 0 };
  1159. buf = cpu_to_le64(reg->val);
  1160. switch (reg->match.type) {
  1161. case V4L2_CHIP_MATCH_HOST:
  1162. {
  1163. value = (u32) buf & 0xffffffff;
  1164. switch (reg->match.addr) {
  1165. case 0: /* cx231xx internal registers */
  1166. data[0] = (u8) value;
  1167. data[1] = (u8) (value >> 8);
  1168. data[2] = (u8) (value >> 16);
  1169. data[3] = (u8) (value >> 24);
  1170. ret = cx231xx_write_ctrl_reg(dev,
  1171. VRT_SET_REGISTER,
  1172. (u16)reg->reg, data,
  1173. 4);
  1174. break;
  1175. case 1: /* AFE - read byte */
  1176. ret = cx231xx_write_i2c_data(dev,
  1177. AFE_DEVICE_ADDRESS,
  1178. (u16)reg->reg, 2,
  1179. value, 1);
  1180. break;
  1181. case 14: /* AFE - read dword */
  1182. ret = cx231xx_write_i2c_data(dev,
  1183. AFE_DEVICE_ADDRESS,
  1184. (u16)reg->reg, 2,
  1185. value, 4);
  1186. break;
  1187. case 2: /* Video Block - read byte */
  1188. ret =
  1189. cx231xx_write_i2c_data(dev,
  1190. VID_BLK_I2C_ADDRESS,
  1191. (u16)reg->reg, 2,
  1192. value, 1);
  1193. break;
  1194. case 24: /* Video Block - read dword */
  1195. ret =
  1196. cx231xx_write_i2c_data(dev,
  1197. VID_BLK_I2C_ADDRESS,
  1198. (u16)reg->reg, 2,
  1199. value, 4);
  1200. break;
  1201. case 3: /* I2S block - read byte */
  1202. ret =
  1203. cx231xx_write_i2c_data(dev,
  1204. I2S_BLK_DEVICE_ADDRESS,
  1205. (u16)reg->reg, 1,
  1206. value, 1);
  1207. break;
  1208. case 34: /* I2S block - read dword */
  1209. ret =
  1210. cx231xx_write_i2c_data(dev,
  1211. I2S_BLK_DEVICE_ADDRESS,
  1212. (u16)reg->reg, 1,
  1213. value, 4);
  1214. break;
  1215. }
  1216. }
  1217. return ret < 0 ? ret : 0;
  1218. case V4L2_CHIP_MATCH_I2C_ADDR:
  1219. {
  1220. value = (u32) buf & 0xffffffff;
  1221. switch (reg->match.addr) {
  1222. case 0:/*cx231xx internal registers*/
  1223. data[0] = (u8) value;
  1224. data[1] = (u8) (value >> 8);
  1225. data[2] = (u8) (value >> 16);
  1226. data[3] = (u8) (value >> 24);
  1227. ret = cx231xx_write_ctrl_reg(dev,
  1228. VRT_SET_REGISTER,
  1229. (u16)reg->reg, data,
  1230. 4);
  1231. break;
  1232. case 0x600:/* AFE - read byte */
  1233. ret = cx231xx_write_i2c_master(dev,
  1234. AFE_DEVICE_ADDRESS,
  1235. (u16)reg->reg, 2,
  1236. value, 1 , 0);
  1237. break;
  1238. case 0x880:/* Video Block - read byte */
  1239. if (reg->reg < 0x0b)
  1240. cx231xx_write_i2c_master(dev,
  1241. VID_BLK_I2C_ADDRESS,
  1242. (u16)reg->reg, 2,
  1243. value, 1, 0);
  1244. else
  1245. cx231xx_write_i2c_master(dev,
  1246. VID_BLK_I2C_ADDRESS,
  1247. (u16)reg->reg, 2,
  1248. value, 4, 0);
  1249. break;
  1250. case 0x980:
  1251. ret =
  1252. cx231xx_write_i2c_master(dev,
  1253. I2S_BLK_DEVICE_ADDRESS,
  1254. (u16)reg->reg, 1,
  1255. value, 1, 0);
  1256. break;
  1257. case 0x400:
  1258. ret =
  1259. cx231xx_write_i2c_master(dev,
  1260. 0x40,
  1261. (u16)reg->reg, 1,
  1262. value, 1, 0);
  1263. break;
  1264. case 0xc01:
  1265. ret =
  1266. cx231xx_write_i2c_master(dev,
  1267. 0xc0,
  1268. (u16)reg->reg, 1,
  1269. value, 1, 1);
  1270. break;
  1271. case 0x022:
  1272. ret =
  1273. cx231xx_write_i2c_master(dev,
  1274. 0x02,
  1275. (u16)reg->reg, 1,
  1276. value, 1, 2);
  1277. break;
  1278. case 0x322:
  1279. ret =
  1280. cx231xx_write_i2c_master(dev,
  1281. 0x32,
  1282. (u16)reg->reg, 1,
  1283. value, 4, 2);
  1284. break;
  1285. case 0x342:
  1286. ret =
  1287. cx231xx_write_i2c_master(dev,
  1288. 0x34,
  1289. (u16)reg->reg, 1,
  1290. value, 4, 2);
  1291. break;
  1292. default:
  1293. cx231xx_info("no match device address, "
  1294. "the value is %x\n", reg->match.addr);
  1295. break;
  1296. }
  1297. }
  1298. default:
  1299. break;
  1300. }
  1301. call_all(dev, core, s_register, reg);
  1302. return ret;
  1303. }
  1304. #endif
  1305. static int vidioc_cropcap(struct file *file, void *priv,
  1306. struct v4l2_cropcap *cc)
  1307. {
  1308. struct cx231xx_fh *fh = priv;
  1309. struct cx231xx *dev = fh->dev;
  1310. if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1311. return -EINVAL;
  1312. cc->bounds.left = 0;
  1313. cc->bounds.top = 0;
  1314. cc->bounds.width = dev->width;
  1315. cc->bounds.height = dev->height;
  1316. cc->defrect = cc->bounds;
  1317. cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
  1318. cc->pixelaspect.denominator = 59;
  1319. return 0;
  1320. }
  1321. static int vidioc_streamon(struct file *file, void *priv,
  1322. enum v4l2_buf_type type)
  1323. {
  1324. struct cx231xx_fh *fh = priv;
  1325. struct cx231xx *dev = fh->dev;
  1326. int rc;
  1327. rc = check_dev(dev);
  1328. if (rc < 0)
  1329. return rc;
  1330. rc = res_get(fh);
  1331. if (likely(rc >= 0))
  1332. rc = videobuf_streamon(&fh->vb_vidq);
  1333. call_all(dev, video, s_stream, 1);
  1334. return rc;
  1335. }
  1336. static int vidioc_streamoff(struct file *file, void *priv,
  1337. enum v4l2_buf_type type)
  1338. {
  1339. struct cx231xx_fh *fh = priv;
  1340. struct cx231xx *dev = fh->dev;
  1341. int rc;
  1342. rc = check_dev(dev);
  1343. if (rc < 0)
  1344. return rc;
  1345. if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
  1346. (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
  1347. return -EINVAL;
  1348. if (type != fh->type)
  1349. return -EINVAL;
  1350. cx25840_call(dev, video, s_stream, 0);
  1351. videobuf_streamoff(&fh->vb_vidq);
  1352. res_free(fh);
  1353. return 0;
  1354. }
  1355. static int vidioc_querycap(struct file *file, void *priv,
  1356. struct v4l2_capability *cap)
  1357. {
  1358. struct video_device *vdev = video_devdata(file);
  1359. struct cx231xx_fh *fh = priv;
  1360. struct cx231xx *dev = fh->dev;
  1361. strlcpy(cap->driver, "cx231xx", sizeof(cap->driver));
  1362. strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
  1363. usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
  1364. if (vdev->vfl_type == VFL_TYPE_RADIO)
  1365. cap->device_caps = V4L2_CAP_RADIO;
  1366. else {
  1367. cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
  1368. if (vdev->vfl_type == VFL_TYPE_VBI)
  1369. cap->device_caps |= V4L2_CAP_VBI_CAPTURE;
  1370. else
  1371. cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
  1372. }
  1373. if (dev->tuner_type != TUNER_ABSENT)
  1374. cap->device_caps |= V4L2_CAP_TUNER;
  1375. cap->capabilities = cap->device_caps | V4L2_CAP_READWRITE |
  1376. V4L2_CAP_VBI_CAPTURE | V4L2_CAP_VIDEO_CAPTURE |
  1377. V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS;
  1378. if (dev->radio_dev)
  1379. cap->capabilities |= V4L2_CAP_RADIO;
  1380. return 0;
  1381. }
  1382. static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  1383. struct v4l2_fmtdesc *f)
  1384. {
  1385. if (unlikely(f->index >= ARRAY_SIZE(format)))
  1386. return -EINVAL;
  1387. strlcpy(f->description, format[f->index].name, sizeof(f->description));
  1388. f->pixelformat = format[f->index].fourcc;
  1389. return 0;
  1390. }
  1391. /* RAW VBI ioctls */
  1392. static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
  1393. struct v4l2_format *f)
  1394. {
  1395. struct cx231xx_fh *fh = priv;
  1396. struct cx231xx *dev = fh->dev;
  1397. f->fmt.vbi.sampling_rate = 6750000 * 4;
  1398. f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
  1399. f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
  1400. f->fmt.vbi.offset = 0;
  1401. f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ?
  1402. PAL_VBI_START_LINE : NTSC_VBI_START_LINE;
  1403. f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ?
  1404. PAL_VBI_LINES : NTSC_VBI_LINES;
  1405. f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ?
  1406. PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263;
  1407. f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
  1408. memset(f->fmt.vbi.reserved, 0, sizeof(f->fmt.vbi.reserved));
  1409. return 0;
  1410. }
  1411. static int vidioc_try_fmt_vbi_cap(struct file *file, void *priv,
  1412. struct v4l2_format *f)
  1413. {
  1414. struct cx231xx_fh *fh = priv;
  1415. struct cx231xx *dev = fh->dev;
  1416. f->fmt.vbi.sampling_rate = 6750000 * 4;
  1417. f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
  1418. f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
  1419. f->fmt.vbi.offset = 0;
  1420. f->fmt.vbi.flags = 0;
  1421. f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ?
  1422. PAL_VBI_START_LINE : NTSC_VBI_START_LINE;
  1423. f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ?
  1424. PAL_VBI_LINES : NTSC_VBI_LINES;
  1425. f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ?
  1426. PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263;
  1427. f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
  1428. memset(f->fmt.vbi.reserved, 0, sizeof(f->fmt.vbi.reserved));
  1429. return 0;
  1430. }
  1431. static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
  1432. struct v4l2_format *f)
  1433. {
  1434. struct cx231xx_fh *fh = priv;
  1435. struct cx231xx *dev = fh->dev;
  1436. if (dev->vbi_stream_on && !fh->stream_on) {
  1437. cx231xx_errdev("%s device in use by another fh\n", __func__);
  1438. return -EBUSY;
  1439. }
  1440. return vidioc_try_fmt_vbi_cap(file, priv, f);
  1441. }
  1442. static int vidioc_reqbufs(struct file *file, void *priv,
  1443. struct v4l2_requestbuffers *rb)
  1444. {
  1445. struct cx231xx_fh *fh = priv;
  1446. struct cx231xx *dev = fh->dev;
  1447. int rc;
  1448. rc = check_dev(dev);
  1449. if (rc < 0)
  1450. return rc;
  1451. return videobuf_reqbufs(&fh->vb_vidq, rb);
  1452. }
  1453. static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *b)
  1454. {
  1455. struct cx231xx_fh *fh = priv;
  1456. struct cx231xx *dev = fh->dev;
  1457. int rc;
  1458. rc = check_dev(dev);
  1459. if (rc < 0)
  1460. return rc;
  1461. return videobuf_querybuf(&fh->vb_vidq, b);
  1462. }
  1463. static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  1464. {
  1465. struct cx231xx_fh *fh = priv;
  1466. struct cx231xx *dev = fh->dev;
  1467. int rc;
  1468. rc = check_dev(dev);
  1469. if (rc < 0)
  1470. return rc;
  1471. return videobuf_qbuf(&fh->vb_vidq, b);
  1472. }
  1473. static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  1474. {
  1475. struct cx231xx_fh *fh = priv;
  1476. struct cx231xx *dev = fh->dev;
  1477. int rc;
  1478. rc = check_dev(dev);
  1479. if (rc < 0)
  1480. return rc;
  1481. return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
  1482. }
  1483. /* ----------------------------------------------------------- */
  1484. /* RADIO ESPECIFIC IOCTLS */
  1485. /* ----------------------------------------------------------- */
  1486. static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
  1487. {
  1488. struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
  1489. if (t->index)
  1490. return -EINVAL;
  1491. strcpy(t->name, "Radio");
  1492. call_all(dev, tuner, g_tuner, t);
  1493. return 0;
  1494. }
  1495. static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
  1496. {
  1497. struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
  1498. if (0 != t->index)
  1499. return -EINVAL;
  1500. call_all(dev, tuner, s_tuner, t);
  1501. return 0;
  1502. }
  1503. /*
  1504. * cx231xx_v4l2_open()
  1505. * inits the device and starts isoc transfer
  1506. */
  1507. static int cx231xx_v4l2_open(struct file *filp)
  1508. {
  1509. int errCode = 0, radio = 0;
  1510. struct video_device *vdev = video_devdata(filp);
  1511. struct cx231xx *dev = video_drvdata(filp);
  1512. struct cx231xx_fh *fh;
  1513. enum v4l2_buf_type fh_type = 0;
  1514. switch (vdev->vfl_type) {
  1515. case VFL_TYPE_GRABBER:
  1516. fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1517. break;
  1518. case VFL_TYPE_VBI:
  1519. fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
  1520. break;
  1521. case VFL_TYPE_RADIO:
  1522. radio = 1;
  1523. break;
  1524. }
  1525. cx231xx_videodbg("open dev=%s type=%s users=%d\n",
  1526. video_device_node_name(vdev), v4l2_type_names[fh_type],
  1527. dev->users);
  1528. #if 0
  1529. errCode = cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
  1530. if (errCode < 0) {
  1531. cx231xx_errdev
  1532. ("Device locked on digital mode. Can't open analog\n");
  1533. return -EBUSY;
  1534. }
  1535. #endif
  1536. fh = kzalloc(sizeof(struct cx231xx_fh), GFP_KERNEL);
  1537. if (!fh) {
  1538. cx231xx_errdev("cx231xx-video.c: Out of memory?!\n");
  1539. return -ENOMEM;
  1540. }
  1541. if (mutex_lock_interruptible(&dev->lock)) {
  1542. kfree(fh);
  1543. return -ERESTARTSYS;
  1544. }
  1545. fh->dev = dev;
  1546. fh->radio = radio;
  1547. fh->type = fh_type;
  1548. filp->private_data = fh;
  1549. v4l2_fh_init(&fh->fh, vdev);
  1550. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
  1551. dev->width = norm_maxw(dev);
  1552. dev->height = norm_maxh(dev);
  1553. /* Power up in Analog TV mode */
  1554. if (dev->board.external_av)
  1555. cx231xx_set_power_mode(dev,
  1556. POLARIS_AVMODE_ENXTERNAL_AV);
  1557. else
  1558. cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV);
  1559. #if 0
  1560. cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
  1561. #endif
  1562. /* set video alternate setting */
  1563. cx231xx_set_video_alternate(dev);
  1564. /* Needed, since GPIO might have disabled power of
  1565. some i2c device */
  1566. cx231xx_config_i2c(dev);
  1567. /* device needs to be initialized before isoc transfer */
  1568. dev->video_input = dev->video_input > 2 ? 2 : dev->video_input;
  1569. }
  1570. if (fh->radio) {
  1571. cx231xx_videodbg("video_open: setting radio device\n");
  1572. /* cx231xx_start_radio(dev); */
  1573. call_all(dev, tuner, s_radio);
  1574. }
  1575. dev->users++;
  1576. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1577. videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops,
  1578. NULL, &dev->video_mode.slock,
  1579. fh->type, V4L2_FIELD_INTERLACED,
  1580. sizeof(struct cx231xx_buffer),
  1581. fh, &dev->lock);
  1582. if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
  1583. /* Set the required alternate setting VBI interface works in
  1584. Bulk mode only */
  1585. cx231xx_set_alt_setting(dev, INDEX_VANC, 0);
  1586. videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops,
  1587. NULL, &dev->vbi_mode.slock,
  1588. fh->type, V4L2_FIELD_SEQ_TB,
  1589. sizeof(struct cx231xx_buffer),
  1590. fh, &dev->lock);
  1591. }
  1592. mutex_unlock(&dev->lock);
  1593. v4l2_fh_add(&fh->fh);
  1594. return errCode;
  1595. }
  1596. /*
  1597. * cx231xx_realease_resources()
  1598. * unregisters the v4l2,i2c and usb devices
  1599. * called when the device gets disconected or at module unload
  1600. */
  1601. void cx231xx_release_analog_resources(struct cx231xx *dev)
  1602. {
  1603. /*FIXME: I2C IR should be disconnected */
  1604. if (dev->radio_dev) {
  1605. if (video_is_registered(dev->radio_dev))
  1606. video_unregister_device(dev->radio_dev);
  1607. else
  1608. video_device_release(dev->radio_dev);
  1609. dev->radio_dev = NULL;
  1610. }
  1611. if (dev->vbi_dev) {
  1612. cx231xx_info("V4L2 device %s deregistered\n",
  1613. video_device_node_name(dev->vbi_dev));
  1614. if (video_is_registered(dev->vbi_dev))
  1615. video_unregister_device(dev->vbi_dev);
  1616. else
  1617. video_device_release(dev->vbi_dev);
  1618. dev->vbi_dev = NULL;
  1619. }
  1620. if (dev->vdev) {
  1621. cx231xx_info("V4L2 device %s deregistered\n",
  1622. video_device_node_name(dev->vdev));
  1623. if (dev->board.has_417)
  1624. cx231xx_417_unregister(dev);
  1625. if (video_is_registered(dev->vdev))
  1626. video_unregister_device(dev->vdev);
  1627. else
  1628. video_device_release(dev->vdev);
  1629. dev->vdev = NULL;
  1630. }
  1631. v4l2_ctrl_handler_free(&dev->ctrl_handler);
  1632. v4l2_ctrl_handler_free(&dev->radio_ctrl_handler);
  1633. }
  1634. /*
  1635. * cx231xx_close()
  1636. * stops streaming and deallocates all resources allocated by the v4l2
  1637. * calls and ioctls
  1638. */
  1639. static int cx231xx_close(struct file *filp)
  1640. {
  1641. struct cx231xx_fh *fh = filp->private_data;
  1642. struct cx231xx *dev = fh->dev;
  1643. cx231xx_videodbg("users=%d\n", dev->users);
  1644. cx231xx_videodbg("users=%d\n", dev->users);
  1645. if (res_check(fh))
  1646. res_free(fh);
  1647. /*
  1648. * To workaround error number=-71 on EP0 for VideoGrabber,
  1649. * need exclude following.
  1650. * FIXME: It is probably safe to remove most of these, as we're
  1651. * now avoiding the alternate setting for INDEX_VANC
  1652. */
  1653. if (!dev->board.no_alt_vanc)
  1654. if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
  1655. videobuf_stop(&fh->vb_vidq);
  1656. videobuf_mmap_free(&fh->vb_vidq);
  1657. /* the device is already disconnect,
  1658. free the remaining resources */
  1659. if (dev->state & DEV_DISCONNECTED) {
  1660. if (atomic_read(&dev->devlist_count) > 0) {
  1661. cx231xx_release_resources(dev);
  1662. fh->dev = NULL;
  1663. return 0;
  1664. }
  1665. return 0;
  1666. }
  1667. /* do this before setting alternate! */
  1668. cx231xx_uninit_vbi_isoc(dev);
  1669. /* set alternate 0 */
  1670. if (!dev->vbi_or_sliced_cc_mode)
  1671. cx231xx_set_alt_setting(dev, INDEX_VANC, 0);
  1672. else
  1673. cx231xx_set_alt_setting(dev, INDEX_HANC, 0);
  1674. v4l2_fh_del(&fh->fh);
  1675. v4l2_fh_exit(&fh->fh);
  1676. kfree(fh);
  1677. dev->users--;
  1678. wake_up_interruptible_nr(&dev->open, 1);
  1679. return 0;
  1680. }
  1681. v4l2_fh_del(&fh->fh);
  1682. dev->users--;
  1683. if (!dev->users) {
  1684. videobuf_stop(&fh->vb_vidq);
  1685. videobuf_mmap_free(&fh->vb_vidq);
  1686. /* the device is already disconnect,
  1687. free the remaining resources */
  1688. if (dev->state & DEV_DISCONNECTED) {
  1689. cx231xx_release_resources(dev);
  1690. fh->dev = NULL;
  1691. return 0;
  1692. }
  1693. /* Save some power by putting tuner to sleep */
  1694. call_all(dev, core, s_power, 0);
  1695. /* do this before setting alternate! */
  1696. if (dev->USE_ISO)
  1697. cx231xx_uninit_isoc(dev);
  1698. else
  1699. cx231xx_uninit_bulk(dev);
  1700. cx231xx_set_mode(dev, CX231XX_SUSPEND);
  1701. /* set alternate 0 */
  1702. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0);
  1703. }
  1704. v4l2_fh_exit(&fh->fh);
  1705. kfree(fh);
  1706. wake_up_interruptible_nr(&dev->open, 1);
  1707. return 0;
  1708. }
  1709. static int cx231xx_v4l2_close(struct file *filp)
  1710. {
  1711. struct cx231xx_fh *fh = filp->private_data;
  1712. struct cx231xx *dev = fh->dev;
  1713. int rc;
  1714. mutex_lock(&dev->lock);
  1715. rc = cx231xx_close(filp);
  1716. mutex_unlock(&dev->lock);
  1717. return rc;
  1718. }
  1719. /*
  1720. * cx231xx_v4l2_read()
  1721. * will allocate buffers when called for the first time
  1722. */
  1723. static ssize_t
  1724. cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
  1725. loff_t *pos)
  1726. {
  1727. struct cx231xx_fh *fh = filp->private_data;
  1728. struct cx231xx *dev = fh->dev;
  1729. int rc;
  1730. rc = check_dev(dev);
  1731. if (rc < 0)
  1732. return rc;
  1733. if ((fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ||
  1734. (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)) {
  1735. rc = res_get(fh);
  1736. if (unlikely(rc < 0))
  1737. return rc;
  1738. if (mutex_lock_interruptible(&dev->lock))
  1739. return -ERESTARTSYS;
  1740. rc = videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
  1741. filp->f_flags & O_NONBLOCK);
  1742. mutex_unlock(&dev->lock);
  1743. return rc;
  1744. }
  1745. return 0;
  1746. }
  1747. /*
  1748. * cx231xx_v4l2_poll()
  1749. * will allocate buffers when called for the first time
  1750. */
  1751. static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table *wait)
  1752. {
  1753. unsigned long req_events = poll_requested_events(wait);
  1754. struct cx231xx_fh *fh = filp->private_data;
  1755. struct cx231xx *dev = fh->dev;
  1756. unsigned res = 0;
  1757. int rc;
  1758. rc = check_dev(dev);
  1759. if (rc < 0)
  1760. return POLLERR;
  1761. rc = res_get(fh);
  1762. if (unlikely(rc < 0))
  1763. return POLLERR;
  1764. if (v4l2_event_pending(&fh->fh))
  1765. res |= POLLPRI;
  1766. else
  1767. poll_wait(filp, &fh->fh.wait, wait);
  1768. if (!(req_events & (POLLIN | POLLRDNORM)))
  1769. return res;
  1770. if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) ||
  1771. (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) {
  1772. mutex_lock(&dev->lock);
  1773. res |= videobuf_poll_stream(filp, &fh->vb_vidq, wait);
  1774. mutex_unlock(&dev->lock);
  1775. return res;
  1776. }
  1777. return res | POLLERR;
  1778. }
  1779. /*
  1780. * cx231xx_v4l2_mmap()
  1781. */
  1782. static int cx231xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
  1783. {
  1784. struct cx231xx_fh *fh = filp->private_data;
  1785. struct cx231xx *dev = fh->dev;
  1786. int rc;
  1787. rc = check_dev(dev);
  1788. if (rc < 0)
  1789. return rc;
  1790. rc = res_get(fh);
  1791. if (unlikely(rc < 0))
  1792. return rc;
  1793. if (mutex_lock_interruptible(&dev->lock))
  1794. return -ERESTARTSYS;
  1795. rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
  1796. mutex_unlock(&dev->lock);
  1797. cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
  1798. (unsigned long)vma->vm_start,
  1799. (unsigned long)vma->vm_end -
  1800. (unsigned long)vma->vm_start, rc);
  1801. return rc;
  1802. }
  1803. static const struct v4l2_file_operations cx231xx_v4l_fops = {
  1804. .owner = THIS_MODULE,
  1805. .open = cx231xx_v4l2_open,
  1806. .release = cx231xx_v4l2_close,
  1807. .read = cx231xx_v4l2_read,
  1808. .poll = cx231xx_v4l2_poll,
  1809. .mmap = cx231xx_v4l2_mmap,
  1810. .unlocked_ioctl = video_ioctl2,
  1811. };
  1812. static const struct v4l2_ioctl_ops video_ioctl_ops = {
  1813. .vidioc_querycap = vidioc_querycap,
  1814. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  1815. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  1816. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  1817. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  1818. .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
  1819. .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap,
  1820. .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
  1821. .vidioc_cropcap = vidioc_cropcap,
  1822. .vidioc_reqbufs = vidioc_reqbufs,
  1823. .vidioc_querybuf = vidioc_querybuf,
  1824. .vidioc_qbuf = vidioc_qbuf,
  1825. .vidioc_dqbuf = vidioc_dqbuf,
  1826. .vidioc_s_std = vidioc_s_std,
  1827. .vidioc_g_std = vidioc_g_std,
  1828. .vidioc_enum_input = vidioc_enum_input,
  1829. .vidioc_g_input = vidioc_g_input,
  1830. .vidioc_s_input = vidioc_s_input,
  1831. .vidioc_streamon = vidioc_streamon,
  1832. .vidioc_streamoff = vidioc_streamoff,
  1833. .vidioc_g_tuner = vidioc_g_tuner,
  1834. .vidioc_s_tuner = vidioc_s_tuner,
  1835. .vidioc_g_frequency = vidioc_g_frequency,
  1836. .vidioc_s_frequency = vidioc_s_frequency,
  1837. .vidioc_g_chip_ident = vidioc_g_chip_ident,
  1838. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1839. .vidioc_g_register = vidioc_g_register,
  1840. .vidioc_s_register = vidioc_s_register,
  1841. #endif
  1842. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  1843. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  1844. };
  1845. static struct video_device cx231xx_vbi_template;
  1846. static const struct video_device cx231xx_video_template = {
  1847. .fops = &cx231xx_v4l_fops,
  1848. .release = video_device_release,
  1849. .ioctl_ops = &video_ioctl_ops,
  1850. .tvnorms = V4L2_STD_ALL,
  1851. };
  1852. static const struct v4l2_file_operations radio_fops = {
  1853. .owner = THIS_MODULE,
  1854. .open = cx231xx_v4l2_open,
  1855. .release = cx231xx_v4l2_close,
  1856. .poll = v4l2_ctrl_poll,
  1857. .ioctl = video_ioctl2,
  1858. };
  1859. static const struct v4l2_ioctl_ops radio_ioctl_ops = {
  1860. .vidioc_querycap = vidioc_querycap,
  1861. .vidioc_g_tuner = radio_g_tuner,
  1862. .vidioc_s_tuner = radio_s_tuner,
  1863. .vidioc_g_frequency = vidioc_g_frequency,
  1864. .vidioc_s_frequency = vidioc_s_frequency,
  1865. .vidioc_g_chip_ident = vidioc_g_chip_ident,
  1866. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1867. .vidioc_g_register = vidioc_g_register,
  1868. .vidioc_s_register = vidioc_s_register,
  1869. #endif
  1870. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  1871. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  1872. };
  1873. static struct video_device cx231xx_radio_template = {
  1874. .name = "cx231xx-radio",
  1875. .fops = &radio_fops,
  1876. .ioctl_ops = &radio_ioctl_ops,
  1877. };
  1878. /******************************** usb interface ******************************/
  1879. static struct video_device *cx231xx_vdev_init(struct cx231xx *dev,
  1880. const struct video_device
  1881. *template, const char *type_name)
  1882. {
  1883. struct video_device *vfd;
  1884. vfd = video_device_alloc();
  1885. if (NULL == vfd)
  1886. return NULL;
  1887. *vfd = *template;
  1888. vfd->v4l2_dev = &dev->v4l2_dev;
  1889. vfd->release = video_device_release;
  1890. vfd->debug = video_debug;
  1891. vfd->lock = &dev->lock;
  1892. set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  1893. snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
  1894. video_set_drvdata(vfd, dev);
  1895. if (dev->tuner_type == TUNER_ABSENT) {
  1896. v4l2_disable_ioctl(vfd, VIDIOC_G_FREQUENCY);
  1897. v4l2_disable_ioctl(vfd, VIDIOC_S_FREQUENCY);
  1898. v4l2_disable_ioctl(vfd, VIDIOC_G_TUNER);
  1899. v4l2_disable_ioctl(vfd, VIDIOC_S_TUNER);
  1900. }
  1901. return vfd;
  1902. }
  1903. int cx231xx_register_analog_devices(struct cx231xx *dev)
  1904. {
  1905. int ret;
  1906. cx231xx_info("%s: v4l2 driver version %s\n",
  1907. dev->name, CX231XX_VERSION);
  1908. /* set default norm */
  1909. dev->norm = V4L2_STD_PAL;
  1910. dev->width = norm_maxw(dev);
  1911. dev->height = norm_maxh(dev);
  1912. dev->interlaced = 0;
  1913. /* Analog specific initialization */
  1914. dev->format = &format[0];
  1915. /* Set the initial input */
  1916. video_mux(dev, dev->video_input);
  1917. v4l2_ctrl_handler_init(&dev->ctrl_handler, 10);
  1918. v4l2_ctrl_handler_init(&dev->radio_ctrl_handler, 5);
  1919. if (dev->sd_cx25840) {
  1920. v4l2_ctrl_add_handler(&dev->ctrl_handler,
  1921. dev->sd_cx25840->ctrl_handler, NULL);
  1922. v4l2_ctrl_add_handler(&dev->radio_ctrl_handler,
  1923. dev->sd_cx25840->ctrl_handler,
  1924. v4l2_ctrl_radio_filter);
  1925. }
  1926. if (dev->ctrl_handler.error)
  1927. return dev->ctrl_handler.error;
  1928. if (dev->radio_ctrl_handler.error)
  1929. return dev->radio_ctrl_handler.error;
  1930. /* enable vbi capturing */
  1931. /* write code here... */
  1932. /* allocate and fill video video_device struct */
  1933. dev->vdev = cx231xx_vdev_init(dev, &cx231xx_video_template, "video");
  1934. if (!dev->vdev) {
  1935. cx231xx_errdev("cannot allocate video_device.\n");
  1936. return -ENODEV;
  1937. }
  1938. dev->vdev->ctrl_handler = &dev->ctrl_handler;
  1939. /* register v4l2 video video_device */
  1940. ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
  1941. video_nr[dev->devno]);
  1942. if (ret) {
  1943. cx231xx_errdev("unable to register video device (error=%i).\n",
  1944. ret);
  1945. return ret;
  1946. }
  1947. cx231xx_info("%s/0: registered device %s [v4l2]\n",
  1948. dev->name, video_device_node_name(dev->vdev));
  1949. /* Initialize VBI template */
  1950. cx231xx_vbi_template = cx231xx_video_template;
  1951. strcpy(cx231xx_vbi_template.name, "cx231xx-vbi");
  1952. /* Allocate and fill vbi video_device struct */
  1953. dev->vbi_dev = cx231xx_vdev_init(dev, &cx231xx_vbi_template, "vbi");
  1954. if (!dev->vbi_dev) {
  1955. cx231xx_errdev("cannot allocate video_device.\n");
  1956. return -ENODEV;
  1957. }
  1958. dev->vbi_dev->ctrl_handler = &dev->ctrl_handler;
  1959. /* register v4l2 vbi video_device */
  1960. ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
  1961. vbi_nr[dev->devno]);
  1962. if (ret < 0) {
  1963. cx231xx_errdev("unable to register vbi device\n");
  1964. return ret;
  1965. }
  1966. cx231xx_info("%s/0: registered device %s\n",
  1967. dev->name, video_device_node_name(dev->vbi_dev));
  1968. if (cx231xx_boards[dev->model].radio.type == CX231XX_RADIO) {
  1969. dev->radio_dev = cx231xx_vdev_init(dev, &cx231xx_radio_template,
  1970. "radio");
  1971. if (!dev->radio_dev) {
  1972. cx231xx_errdev("cannot allocate video_device.\n");
  1973. return -ENODEV;
  1974. }
  1975. dev->radio_dev->ctrl_handler = &dev->radio_ctrl_handler;
  1976. ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
  1977. radio_nr[dev->devno]);
  1978. if (ret < 0) {
  1979. cx231xx_errdev("can't register radio device\n");
  1980. return ret;
  1981. }
  1982. cx231xx_info("Registered radio device as %s\n",
  1983. video_device_node_name(dev->radio_dev));
  1984. }
  1985. cx231xx_info("V4L2 device registered as %s and %s\n",
  1986. video_device_node_name(dev->vdev),
  1987. video_device_node_name(dev->vbi_dev));
  1988. return 0;
  1989. }