cx231xx-video.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395
  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 (type != fh->type)
  1346. return -EINVAL;
  1347. cx25840_call(dev, video, s_stream, 0);
  1348. videobuf_streamoff(&fh->vb_vidq);
  1349. res_free(fh);
  1350. return 0;
  1351. }
  1352. static int vidioc_querycap(struct file *file, void *priv,
  1353. struct v4l2_capability *cap)
  1354. {
  1355. struct video_device *vdev = video_devdata(file);
  1356. struct cx231xx_fh *fh = priv;
  1357. struct cx231xx *dev = fh->dev;
  1358. strlcpy(cap->driver, "cx231xx", sizeof(cap->driver));
  1359. strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
  1360. usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
  1361. if (vdev->vfl_type == VFL_TYPE_RADIO)
  1362. cap->device_caps = V4L2_CAP_RADIO;
  1363. else {
  1364. cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
  1365. if (vdev->vfl_type == VFL_TYPE_VBI)
  1366. cap->device_caps |= V4L2_CAP_VBI_CAPTURE;
  1367. else
  1368. cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
  1369. }
  1370. if (dev->tuner_type != TUNER_ABSENT)
  1371. cap->device_caps |= V4L2_CAP_TUNER;
  1372. cap->capabilities = cap->device_caps | V4L2_CAP_READWRITE |
  1373. V4L2_CAP_VBI_CAPTURE | V4L2_CAP_VIDEO_CAPTURE |
  1374. V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS;
  1375. if (dev->radio_dev)
  1376. cap->capabilities |= V4L2_CAP_RADIO;
  1377. return 0;
  1378. }
  1379. static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  1380. struct v4l2_fmtdesc *f)
  1381. {
  1382. if (unlikely(f->index >= ARRAY_SIZE(format)))
  1383. return -EINVAL;
  1384. strlcpy(f->description, format[f->index].name, sizeof(f->description));
  1385. f->pixelformat = format[f->index].fourcc;
  1386. return 0;
  1387. }
  1388. /* RAW VBI ioctls */
  1389. static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
  1390. struct v4l2_format *f)
  1391. {
  1392. struct cx231xx_fh *fh = priv;
  1393. struct cx231xx *dev = fh->dev;
  1394. f->fmt.vbi.sampling_rate = 6750000 * 4;
  1395. f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
  1396. f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
  1397. f->fmt.vbi.offset = 0;
  1398. f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ?
  1399. PAL_VBI_START_LINE : NTSC_VBI_START_LINE;
  1400. f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ?
  1401. PAL_VBI_LINES : NTSC_VBI_LINES;
  1402. f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ?
  1403. PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263;
  1404. f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
  1405. memset(f->fmt.vbi.reserved, 0, sizeof(f->fmt.vbi.reserved));
  1406. return 0;
  1407. }
  1408. static int vidioc_try_fmt_vbi_cap(struct file *file, void *priv,
  1409. struct v4l2_format *f)
  1410. {
  1411. struct cx231xx_fh *fh = priv;
  1412. struct cx231xx *dev = fh->dev;
  1413. f->fmt.vbi.sampling_rate = 6750000 * 4;
  1414. f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
  1415. f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
  1416. f->fmt.vbi.offset = 0;
  1417. f->fmt.vbi.flags = 0;
  1418. f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ?
  1419. PAL_VBI_START_LINE : NTSC_VBI_START_LINE;
  1420. f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ?
  1421. PAL_VBI_LINES : NTSC_VBI_LINES;
  1422. f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ?
  1423. PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263;
  1424. f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
  1425. memset(f->fmt.vbi.reserved, 0, sizeof(f->fmt.vbi.reserved));
  1426. return 0;
  1427. }
  1428. static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
  1429. struct v4l2_format *f)
  1430. {
  1431. struct cx231xx_fh *fh = priv;
  1432. struct cx231xx *dev = fh->dev;
  1433. if (dev->vbi_stream_on && !fh->stream_on) {
  1434. cx231xx_errdev("%s device in use by another fh\n", __func__);
  1435. return -EBUSY;
  1436. }
  1437. return vidioc_try_fmt_vbi_cap(file, priv, f);
  1438. }
  1439. static int vidioc_reqbufs(struct file *file, void *priv,
  1440. struct v4l2_requestbuffers *rb)
  1441. {
  1442. struct cx231xx_fh *fh = priv;
  1443. struct cx231xx *dev = fh->dev;
  1444. int rc;
  1445. rc = check_dev(dev);
  1446. if (rc < 0)
  1447. return rc;
  1448. return videobuf_reqbufs(&fh->vb_vidq, rb);
  1449. }
  1450. static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *b)
  1451. {
  1452. struct cx231xx_fh *fh = priv;
  1453. struct cx231xx *dev = fh->dev;
  1454. int rc;
  1455. rc = check_dev(dev);
  1456. if (rc < 0)
  1457. return rc;
  1458. return videobuf_querybuf(&fh->vb_vidq, b);
  1459. }
  1460. static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  1461. {
  1462. struct cx231xx_fh *fh = priv;
  1463. struct cx231xx *dev = fh->dev;
  1464. int rc;
  1465. rc = check_dev(dev);
  1466. if (rc < 0)
  1467. return rc;
  1468. return videobuf_qbuf(&fh->vb_vidq, b);
  1469. }
  1470. static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
  1471. {
  1472. struct cx231xx_fh *fh = priv;
  1473. struct cx231xx *dev = fh->dev;
  1474. int rc;
  1475. rc = check_dev(dev);
  1476. if (rc < 0)
  1477. return rc;
  1478. return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
  1479. }
  1480. /* ----------------------------------------------------------- */
  1481. /* RADIO ESPECIFIC IOCTLS */
  1482. /* ----------------------------------------------------------- */
  1483. static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
  1484. {
  1485. struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
  1486. if (t->index)
  1487. return -EINVAL;
  1488. strcpy(t->name, "Radio");
  1489. call_all(dev, tuner, g_tuner, t);
  1490. return 0;
  1491. }
  1492. static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
  1493. {
  1494. struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
  1495. if (0 != t->index)
  1496. return -EINVAL;
  1497. call_all(dev, tuner, s_tuner, t);
  1498. return 0;
  1499. }
  1500. /*
  1501. * cx231xx_v4l2_open()
  1502. * inits the device and starts isoc transfer
  1503. */
  1504. static int cx231xx_v4l2_open(struct file *filp)
  1505. {
  1506. int errCode = 0, radio = 0;
  1507. struct video_device *vdev = video_devdata(filp);
  1508. struct cx231xx *dev = video_drvdata(filp);
  1509. struct cx231xx_fh *fh;
  1510. enum v4l2_buf_type fh_type = 0;
  1511. switch (vdev->vfl_type) {
  1512. case VFL_TYPE_GRABBER:
  1513. fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1514. break;
  1515. case VFL_TYPE_VBI:
  1516. fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
  1517. break;
  1518. case VFL_TYPE_RADIO:
  1519. radio = 1;
  1520. break;
  1521. }
  1522. cx231xx_videodbg("open dev=%s type=%s users=%d\n",
  1523. video_device_node_name(vdev), v4l2_type_names[fh_type],
  1524. dev->users);
  1525. #if 0
  1526. errCode = cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
  1527. if (errCode < 0) {
  1528. cx231xx_errdev
  1529. ("Device locked on digital mode. Can't open analog\n");
  1530. return -EBUSY;
  1531. }
  1532. #endif
  1533. fh = kzalloc(sizeof(struct cx231xx_fh), GFP_KERNEL);
  1534. if (!fh) {
  1535. cx231xx_errdev("cx231xx-video.c: Out of memory?!\n");
  1536. return -ENOMEM;
  1537. }
  1538. if (mutex_lock_interruptible(&dev->lock)) {
  1539. kfree(fh);
  1540. return -ERESTARTSYS;
  1541. }
  1542. fh->dev = dev;
  1543. fh->type = fh_type;
  1544. filp->private_data = fh;
  1545. v4l2_fh_init(&fh->fh, vdev);
  1546. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
  1547. dev->width = norm_maxw(dev);
  1548. dev->height = norm_maxh(dev);
  1549. /* Power up in Analog TV mode */
  1550. if (dev->board.external_av)
  1551. cx231xx_set_power_mode(dev,
  1552. POLARIS_AVMODE_ENXTERNAL_AV);
  1553. else
  1554. cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV);
  1555. #if 0
  1556. cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
  1557. #endif
  1558. /* set video alternate setting */
  1559. cx231xx_set_video_alternate(dev);
  1560. /* Needed, since GPIO might have disabled power of
  1561. some i2c device */
  1562. cx231xx_config_i2c(dev);
  1563. /* device needs to be initialized before isoc transfer */
  1564. dev->video_input = dev->video_input > 2 ? 2 : dev->video_input;
  1565. }
  1566. if (radio) {
  1567. cx231xx_videodbg("video_open: setting radio device\n");
  1568. /* cx231xx_start_radio(dev); */
  1569. call_all(dev, tuner, s_radio);
  1570. }
  1571. dev->users++;
  1572. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1573. videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops,
  1574. NULL, &dev->video_mode.slock,
  1575. fh->type, V4L2_FIELD_INTERLACED,
  1576. sizeof(struct cx231xx_buffer),
  1577. fh, &dev->lock);
  1578. if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
  1579. /* Set the required alternate setting VBI interface works in
  1580. Bulk mode only */
  1581. cx231xx_set_alt_setting(dev, INDEX_VANC, 0);
  1582. videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops,
  1583. NULL, &dev->vbi_mode.slock,
  1584. fh->type, V4L2_FIELD_SEQ_TB,
  1585. sizeof(struct cx231xx_buffer),
  1586. fh, &dev->lock);
  1587. }
  1588. mutex_unlock(&dev->lock);
  1589. v4l2_fh_add(&fh->fh);
  1590. return errCode;
  1591. }
  1592. /*
  1593. * cx231xx_realease_resources()
  1594. * unregisters the v4l2,i2c and usb devices
  1595. * called when the device gets disconected or at module unload
  1596. */
  1597. void cx231xx_release_analog_resources(struct cx231xx *dev)
  1598. {
  1599. /*FIXME: I2C IR should be disconnected */
  1600. if (dev->radio_dev) {
  1601. if (video_is_registered(dev->radio_dev))
  1602. video_unregister_device(dev->radio_dev);
  1603. else
  1604. video_device_release(dev->radio_dev);
  1605. dev->radio_dev = NULL;
  1606. }
  1607. if (dev->vbi_dev) {
  1608. cx231xx_info("V4L2 device %s deregistered\n",
  1609. video_device_node_name(dev->vbi_dev));
  1610. if (video_is_registered(dev->vbi_dev))
  1611. video_unregister_device(dev->vbi_dev);
  1612. else
  1613. video_device_release(dev->vbi_dev);
  1614. dev->vbi_dev = NULL;
  1615. }
  1616. if (dev->vdev) {
  1617. cx231xx_info("V4L2 device %s deregistered\n",
  1618. video_device_node_name(dev->vdev));
  1619. if (dev->board.has_417)
  1620. cx231xx_417_unregister(dev);
  1621. if (video_is_registered(dev->vdev))
  1622. video_unregister_device(dev->vdev);
  1623. else
  1624. video_device_release(dev->vdev);
  1625. dev->vdev = NULL;
  1626. }
  1627. v4l2_ctrl_handler_free(&dev->ctrl_handler);
  1628. v4l2_ctrl_handler_free(&dev->radio_ctrl_handler);
  1629. }
  1630. /*
  1631. * cx231xx_close()
  1632. * stops streaming and deallocates all resources allocated by the v4l2
  1633. * calls and ioctls
  1634. */
  1635. static int cx231xx_close(struct file *filp)
  1636. {
  1637. struct cx231xx_fh *fh = filp->private_data;
  1638. struct cx231xx *dev = fh->dev;
  1639. cx231xx_videodbg("users=%d\n", dev->users);
  1640. cx231xx_videodbg("users=%d\n", dev->users);
  1641. if (res_check(fh))
  1642. res_free(fh);
  1643. /*
  1644. * To workaround error number=-71 on EP0 for VideoGrabber,
  1645. * need exclude following.
  1646. * FIXME: It is probably safe to remove most of these, as we're
  1647. * now avoiding the alternate setting for INDEX_VANC
  1648. */
  1649. if (!dev->board.no_alt_vanc)
  1650. if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
  1651. videobuf_stop(&fh->vb_vidq);
  1652. videobuf_mmap_free(&fh->vb_vidq);
  1653. /* the device is already disconnect,
  1654. free the remaining resources */
  1655. if (dev->state & DEV_DISCONNECTED) {
  1656. if (atomic_read(&dev->devlist_count) > 0) {
  1657. cx231xx_release_resources(dev);
  1658. fh->dev = NULL;
  1659. return 0;
  1660. }
  1661. return 0;
  1662. }
  1663. /* do this before setting alternate! */
  1664. cx231xx_uninit_vbi_isoc(dev);
  1665. /* set alternate 0 */
  1666. if (!dev->vbi_or_sliced_cc_mode)
  1667. cx231xx_set_alt_setting(dev, INDEX_VANC, 0);
  1668. else
  1669. cx231xx_set_alt_setting(dev, INDEX_HANC, 0);
  1670. v4l2_fh_del(&fh->fh);
  1671. v4l2_fh_exit(&fh->fh);
  1672. kfree(fh);
  1673. dev->users--;
  1674. wake_up_interruptible_nr(&dev->open, 1);
  1675. return 0;
  1676. }
  1677. v4l2_fh_del(&fh->fh);
  1678. dev->users--;
  1679. if (!dev->users) {
  1680. videobuf_stop(&fh->vb_vidq);
  1681. videobuf_mmap_free(&fh->vb_vidq);
  1682. /* the device is already disconnect,
  1683. free the remaining resources */
  1684. if (dev->state & DEV_DISCONNECTED) {
  1685. cx231xx_release_resources(dev);
  1686. fh->dev = NULL;
  1687. return 0;
  1688. }
  1689. /* Save some power by putting tuner to sleep */
  1690. call_all(dev, core, s_power, 0);
  1691. /* do this before setting alternate! */
  1692. if (dev->USE_ISO)
  1693. cx231xx_uninit_isoc(dev);
  1694. else
  1695. cx231xx_uninit_bulk(dev);
  1696. cx231xx_set_mode(dev, CX231XX_SUSPEND);
  1697. /* set alternate 0 */
  1698. cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0);
  1699. }
  1700. v4l2_fh_exit(&fh->fh);
  1701. kfree(fh);
  1702. wake_up_interruptible_nr(&dev->open, 1);
  1703. return 0;
  1704. }
  1705. static int cx231xx_v4l2_close(struct file *filp)
  1706. {
  1707. struct cx231xx_fh *fh = filp->private_data;
  1708. struct cx231xx *dev = fh->dev;
  1709. int rc;
  1710. mutex_lock(&dev->lock);
  1711. rc = cx231xx_close(filp);
  1712. mutex_unlock(&dev->lock);
  1713. return rc;
  1714. }
  1715. /*
  1716. * cx231xx_v4l2_read()
  1717. * will allocate buffers when called for the first time
  1718. */
  1719. static ssize_t
  1720. cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
  1721. loff_t *pos)
  1722. {
  1723. struct cx231xx_fh *fh = filp->private_data;
  1724. struct cx231xx *dev = fh->dev;
  1725. int rc;
  1726. rc = check_dev(dev);
  1727. if (rc < 0)
  1728. return rc;
  1729. if ((fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ||
  1730. (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)) {
  1731. rc = res_get(fh);
  1732. if (unlikely(rc < 0))
  1733. return rc;
  1734. if (mutex_lock_interruptible(&dev->lock))
  1735. return -ERESTARTSYS;
  1736. rc = videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
  1737. filp->f_flags & O_NONBLOCK);
  1738. mutex_unlock(&dev->lock);
  1739. return rc;
  1740. }
  1741. return 0;
  1742. }
  1743. /*
  1744. * cx231xx_v4l2_poll()
  1745. * will allocate buffers when called for the first time
  1746. */
  1747. static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table *wait)
  1748. {
  1749. unsigned long req_events = poll_requested_events(wait);
  1750. struct cx231xx_fh *fh = filp->private_data;
  1751. struct cx231xx *dev = fh->dev;
  1752. unsigned res = 0;
  1753. int rc;
  1754. rc = check_dev(dev);
  1755. if (rc < 0)
  1756. return POLLERR;
  1757. rc = res_get(fh);
  1758. if (unlikely(rc < 0))
  1759. return POLLERR;
  1760. if (v4l2_event_pending(&fh->fh))
  1761. res |= POLLPRI;
  1762. else
  1763. poll_wait(filp, &fh->fh.wait, wait);
  1764. if (!(req_events & (POLLIN | POLLRDNORM)))
  1765. return res;
  1766. if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) ||
  1767. (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) {
  1768. mutex_lock(&dev->lock);
  1769. res |= videobuf_poll_stream(filp, &fh->vb_vidq, wait);
  1770. mutex_unlock(&dev->lock);
  1771. return res;
  1772. }
  1773. return res | POLLERR;
  1774. }
  1775. /*
  1776. * cx231xx_v4l2_mmap()
  1777. */
  1778. static int cx231xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
  1779. {
  1780. struct cx231xx_fh *fh = filp->private_data;
  1781. struct cx231xx *dev = fh->dev;
  1782. int rc;
  1783. rc = check_dev(dev);
  1784. if (rc < 0)
  1785. return rc;
  1786. rc = res_get(fh);
  1787. if (unlikely(rc < 0))
  1788. return rc;
  1789. if (mutex_lock_interruptible(&dev->lock))
  1790. return -ERESTARTSYS;
  1791. rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
  1792. mutex_unlock(&dev->lock);
  1793. cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
  1794. (unsigned long)vma->vm_start,
  1795. (unsigned long)vma->vm_end -
  1796. (unsigned long)vma->vm_start, rc);
  1797. return rc;
  1798. }
  1799. static const struct v4l2_file_operations cx231xx_v4l_fops = {
  1800. .owner = THIS_MODULE,
  1801. .open = cx231xx_v4l2_open,
  1802. .release = cx231xx_v4l2_close,
  1803. .read = cx231xx_v4l2_read,
  1804. .poll = cx231xx_v4l2_poll,
  1805. .mmap = cx231xx_v4l2_mmap,
  1806. .unlocked_ioctl = video_ioctl2,
  1807. };
  1808. static const struct v4l2_ioctl_ops video_ioctl_ops = {
  1809. .vidioc_querycap = vidioc_querycap,
  1810. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  1811. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  1812. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  1813. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  1814. .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
  1815. .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap,
  1816. .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
  1817. .vidioc_cropcap = vidioc_cropcap,
  1818. .vidioc_reqbufs = vidioc_reqbufs,
  1819. .vidioc_querybuf = vidioc_querybuf,
  1820. .vidioc_qbuf = vidioc_qbuf,
  1821. .vidioc_dqbuf = vidioc_dqbuf,
  1822. .vidioc_s_std = vidioc_s_std,
  1823. .vidioc_g_std = vidioc_g_std,
  1824. .vidioc_enum_input = vidioc_enum_input,
  1825. .vidioc_g_input = vidioc_g_input,
  1826. .vidioc_s_input = vidioc_s_input,
  1827. .vidioc_streamon = vidioc_streamon,
  1828. .vidioc_streamoff = vidioc_streamoff,
  1829. .vidioc_g_tuner = vidioc_g_tuner,
  1830. .vidioc_s_tuner = vidioc_s_tuner,
  1831. .vidioc_g_frequency = vidioc_g_frequency,
  1832. .vidioc_s_frequency = vidioc_s_frequency,
  1833. .vidioc_g_chip_ident = vidioc_g_chip_ident,
  1834. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1835. .vidioc_g_register = vidioc_g_register,
  1836. .vidioc_s_register = vidioc_s_register,
  1837. #endif
  1838. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  1839. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  1840. };
  1841. static struct video_device cx231xx_vbi_template;
  1842. static const struct video_device cx231xx_video_template = {
  1843. .fops = &cx231xx_v4l_fops,
  1844. .release = video_device_release,
  1845. .ioctl_ops = &video_ioctl_ops,
  1846. .tvnorms = V4L2_STD_ALL,
  1847. };
  1848. static const struct v4l2_file_operations radio_fops = {
  1849. .owner = THIS_MODULE,
  1850. .open = cx231xx_v4l2_open,
  1851. .release = cx231xx_v4l2_close,
  1852. .poll = v4l2_ctrl_poll,
  1853. .unlocked_ioctl = video_ioctl2,
  1854. };
  1855. static const struct v4l2_ioctl_ops radio_ioctl_ops = {
  1856. .vidioc_querycap = vidioc_querycap,
  1857. .vidioc_g_tuner = radio_g_tuner,
  1858. .vidioc_s_tuner = radio_s_tuner,
  1859. .vidioc_g_frequency = vidioc_g_frequency,
  1860. .vidioc_s_frequency = vidioc_s_frequency,
  1861. .vidioc_g_chip_ident = vidioc_g_chip_ident,
  1862. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1863. .vidioc_g_register = vidioc_g_register,
  1864. .vidioc_s_register = vidioc_s_register,
  1865. #endif
  1866. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  1867. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  1868. };
  1869. static struct video_device cx231xx_radio_template = {
  1870. .name = "cx231xx-radio",
  1871. .fops = &radio_fops,
  1872. .ioctl_ops = &radio_ioctl_ops,
  1873. };
  1874. /******************************** usb interface ******************************/
  1875. static struct video_device *cx231xx_vdev_init(struct cx231xx *dev,
  1876. const struct video_device
  1877. *template, const char *type_name)
  1878. {
  1879. struct video_device *vfd;
  1880. vfd = video_device_alloc();
  1881. if (NULL == vfd)
  1882. return NULL;
  1883. *vfd = *template;
  1884. vfd->v4l2_dev = &dev->v4l2_dev;
  1885. vfd->release = video_device_release;
  1886. vfd->debug = video_debug;
  1887. vfd->lock = &dev->lock;
  1888. set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  1889. snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
  1890. video_set_drvdata(vfd, dev);
  1891. if (dev->tuner_type == TUNER_ABSENT) {
  1892. v4l2_disable_ioctl(vfd, VIDIOC_G_FREQUENCY);
  1893. v4l2_disable_ioctl(vfd, VIDIOC_S_FREQUENCY);
  1894. v4l2_disable_ioctl(vfd, VIDIOC_G_TUNER);
  1895. v4l2_disable_ioctl(vfd, VIDIOC_S_TUNER);
  1896. }
  1897. return vfd;
  1898. }
  1899. int cx231xx_register_analog_devices(struct cx231xx *dev)
  1900. {
  1901. int ret;
  1902. cx231xx_info("%s: v4l2 driver version %s\n",
  1903. dev->name, CX231XX_VERSION);
  1904. /* set default norm */
  1905. dev->norm = V4L2_STD_PAL;
  1906. dev->width = norm_maxw(dev);
  1907. dev->height = norm_maxh(dev);
  1908. dev->interlaced = 0;
  1909. /* Analog specific initialization */
  1910. dev->format = &format[0];
  1911. /* Set the initial input */
  1912. video_mux(dev, dev->video_input);
  1913. v4l2_ctrl_handler_init(&dev->ctrl_handler, 10);
  1914. v4l2_ctrl_handler_init(&dev->radio_ctrl_handler, 5);
  1915. if (dev->sd_cx25840) {
  1916. v4l2_ctrl_add_handler(&dev->ctrl_handler,
  1917. dev->sd_cx25840->ctrl_handler, NULL);
  1918. v4l2_ctrl_add_handler(&dev->radio_ctrl_handler,
  1919. dev->sd_cx25840->ctrl_handler,
  1920. v4l2_ctrl_radio_filter);
  1921. }
  1922. if (dev->ctrl_handler.error)
  1923. return dev->ctrl_handler.error;
  1924. if (dev->radio_ctrl_handler.error)
  1925. return dev->radio_ctrl_handler.error;
  1926. /* enable vbi capturing */
  1927. /* write code here... */
  1928. /* allocate and fill video video_device struct */
  1929. dev->vdev = cx231xx_vdev_init(dev, &cx231xx_video_template, "video");
  1930. if (!dev->vdev) {
  1931. cx231xx_errdev("cannot allocate video_device.\n");
  1932. return -ENODEV;
  1933. }
  1934. dev->vdev->ctrl_handler = &dev->ctrl_handler;
  1935. /* register v4l2 video video_device */
  1936. ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
  1937. video_nr[dev->devno]);
  1938. if (ret) {
  1939. cx231xx_errdev("unable to register video device (error=%i).\n",
  1940. ret);
  1941. return ret;
  1942. }
  1943. cx231xx_info("%s/0: registered device %s [v4l2]\n",
  1944. dev->name, video_device_node_name(dev->vdev));
  1945. /* Initialize VBI template */
  1946. cx231xx_vbi_template = cx231xx_video_template;
  1947. strcpy(cx231xx_vbi_template.name, "cx231xx-vbi");
  1948. /* Allocate and fill vbi video_device struct */
  1949. dev->vbi_dev = cx231xx_vdev_init(dev, &cx231xx_vbi_template, "vbi");
  1950. if (!dev->vbi_dev) {
  1951. cx231xx_errdev("cannot allocate video_device.\n");
  1952. return -ENODEV;
  1953. }
  1954. dev->vbi_dev->ctrl_handler = &dev->ctrl_handler;
  1955. /* register v4l2 vbi video_device */
  1956. ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
  1957. vbi_nr[dev->devno]);
  1958. if (ret < 0) {
  1959. cx231xx_errdev("unable to register vbi device\n");
  1960. return ret;
  1961. }
  1962. cx231xx_info("%s/0: registered device %s\n",
  1963. dev->name, video_device_node_name(dev->vbi_dev));
  1964. if (cx231xx_boards[dev->model].radio.type == CX231XX_RADIO) {
  1965. dev->radio_dev = cx231xx_vdev_init(dev, &cx231xx_radio_template,
  1966. "radio");
  1967. if (!dev->radio_dev) {
  1968. cx231xx_errdev("cannot allocate video_device.\n");
  1969. return -ENODEV;
  1970. }
  1971. dev->radio_dev->ctrl_handler = &dev->radio_ctrl_handler;
  1972. ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
  1973. radio_nr[dev->devno]);
  1974. if (ret < 0) {
  1975. cx231xx_errdev("can't register radio device\n");
  1976. return ret;
  1977. }
  1978. cx231xx_info("Registered radio device as %s\n",
  1979. video_device_node_name(dev->radio_dev));
  1980. }
  1981. cx231xx_info("V4L2 device registered as %s and %s\n",
  1982. video_device_node_name(dev->vdev),
  1983. video_device_node_name(dev->vbi_dev));
  1984. return 0;
  1985. }