ivtv-driver.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  1. /*
  2. ivtv driver initialization and card probing
  3. Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
  4. Copyright (C) 2004 Chris Kennedy <c@groovy.org>
  5. Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. /* Main Driver file for the ivtv project:
  19. * Driver for the Conexant CX23415/CX23416 chip.
  20. * Author: Kevin Thayer (nufan_wfk at yahoo.com)
  21. * License: GPL
  22. * http://www.ivtvdriver.org
  23. *
  24. * -----
  25. * MPG600/MPG160 support by T.Adachi <tadachi@tadachi-net.com>
  26. * and Takeru KOMORIYA<komoriya@paken.org>
  27. *
  28. * AVerMedia M179 GPIO info by Chris Pinkham <cpinkham@bc2va.org>
  29. * using information provided by Jiun-Kuei Jung @ AVerMedia.
  30. *
  31. * Kurouto Sikou CX23416GYC-STVLP tested by K.Ohta <alpha292@bremen.or.jp>
  32. * using information from T.Adachi,Takeru KOMORIYA and others :-)
  33. *
  34. * Nagase TRANSGEAR 5000TV, Aopen VA2000MAX-STN6 and I/O data GV-MVP/RX
  35. * version by T.Adachi. Special thanks Mr.Suzuki
  36. */
  37. #include "ivtv-driver.h"
  38. #include "ivtv-version.h"
  39. #include "ivtv-fileops.h"
  40. #include "ivtv-i2c.h"
  41. #include "ivtv-firmware.h"
  42. #include "ivtv-queue.h"
  43. #include "ivtv-udma.h"
  44. #include "ivtv-irq.h"
  45. #include "ivtv-mailbox.h"
  46. #include "ivtv-streams.h"
  47. #include "ivtv-ioctl.h"
  48. #include "ivtv-cards.h"
  49. #include "ivtv-vbi.h"
  50. #include "ivtv-routing.h"
  51. #include "ivtv-controls.h"
  52. #include "ivtv-gpio.h"
  53. #include <linux/dma-mapping.h>
  54. #include <media/tveeprom.h>
  55. #include <media/saa7115.h>
  56. #include "tuner-xc2028.h"
  57. /* If you have already X v4l cards, then set this to X. This way
  58. the device numbers stay matched. Example: you have a WinTV card
  59. without radio and a PVR-350 with. Normally this would give a
  60. video1 device together with a radio0 device for the PVR. By
  61. setting this to 1 you ensure that radio0 is now also radio1. */
  62. int ivtv_first_minor;
  63. /* Callback for registering extensions */
  64. int (*ivtv_ext_init)(struct ivtv *);
  65. EXPORT_SYMBOL(ivtv_ext_init);
  66. /* add your revision and whatnot here */
  67. static struct pci_device_id ivtv_pci_tbl[] = {
  68. {PCI_VENDOR_ID_ICOMP, PCI_DEVICE_ID_IVTV15,
  69. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  70. {PCI_VENDOR_ID_ICOMP, PCI_DEVICE_ID_IVTV16,
  71. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  72. {0,}
  73. };
  74. MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
  75. /* ivtv instance counter */
  76. static atomic_t ivtv_instance = ATOMIC_INIT(0);
  77. /* Parameter declarations */
  78. static int cardtype[IVTV_MAX_CARDS];
  79. static int tuner[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
  80. -1, -1, -1, -1, -1, -1, -1, -1,
  81. -1, -1, -1, -1, -1, -1, -1, -1,
  82. -1, -1, -1, -1, -1, -1, -1, -1 };
  83. static int radio[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
  84. -1, -1, -1, -1, -1, -1, -1, -1,
  85. -1, -1, -1, -1, -1, -1, -1, -1,
  86. -1, -1, -1, -1, -1, -1, -1, -1 };
  87. static int i2c_clock_period[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
  88. -1, -1, -1, -1, -1, -1, -1, -1,
  89. -1, -1, -1, -1, -1, -1, -1, -1,
  90. -1, -1, -1, -1, -1, -1, -1, -1 };
  91. static unsigned int cardtype_c = 1;
  92. static unsigned int tuner_c = 1;
  93. static int radio_c = 1;
  94. static unsigned int i2c_clock_period_c = 1;
  95. static char pal[] = "---";
  96. static char secam[] = "--";
  97. static char ntsc[] = "-";
  98. /* Buffers */
  99. /* DMA Buffers, Default size in MB allocated */
  100. #define IVTV_DEFAULT_ENC_MPG_BUFFERS 4
  101. #define IVTV_DEFAULT_ENC_YUV_BUFFERS 2
  102. #define IVTV_DEFAULT_ENC_VBI_BUFFERS 1
  103. /* Exception: size in kB for this stream (MB is overkill) */
  104. #define IVTV_DEFAULT_ENC_PCM_BUFFERS 320
  105. #define IVTV_DEFAULT_DEC_MPG_BUFFERS 1
  106. #define IVTV_DEFAULT_DEC_YUV_BUFFERS 1
  107. /* Exception: size in kB for this stream (MB is way overkill) */
  108. #define IVTV_DEFAULT_DEC_VBI_BUFFERS 64
  109. static int enc_mpg_buffers = IVTV_DEFAULT_ENC_MPG_BUFFERS;
  110. static int enc_yuv_buffers = IVTV_DEFAULT_ENC_YUV_BUFFERS;
  111. static int enc_vbi_buffers = IVTV_DEFAULT_ENC_VBI_BUFFERS;
  112. static int enc_pcm_buffers = IVTV_DEFAULT_ENC_PCM_BUFFERS;
  113. static int dec_mpg_buffers = IVTV_DEFAULT_DEC_MPG_BUFFERS;
  114. static int dec_yuv_buffers = IVTV_DEFAULT_DEC_YUV_BUFFERS;
  115. static int dec_vbi_buffers = IVTV_DEFAULT_DEC_VBI_BUFFERS;
  116. static int ivtv_yuv_mode;
  117. static int ivtv_yuv_threshold = -1;
  118. static int ivtv_pci_latency = 1;
  119. int ivtv_debug;
  120. #ifdef CONFIG_VIDEO_ADV_DEBUG
  121. int ivtv_fw_debug;
  122. #endif
  123. static int tunertype = -1;
  124. static int newi2c = -1;
  125. module_param_array(tuner, int, &tuner_c, 0644);
  126. module_param_array(radio, int, &radio_c, 0644);
  127. module_param_array(cardtype, int, &cardtype_c, 0644);
  128. module_param_string(pal, pal, sizeof(pal), 0644);
  129. module_param_string(secam, secam, sizeof(secam), 0644);
  130. module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);
  131. module_param_named(debug,ivtv_debug, int, 0644);
  132. #ifdef CONFIG_VIDEO_ADV_DEBUG
  133. module_param_named(fw_debug, ivtv_fw_debug, int, 0644);
  134. #endif
  135. module_param(ivtv_pci_latency, int, 0644);
  136. module_param(ivtv_yuv_mode, int, 0644);
  137. module_param(ivtv_yuv_threshold, int, 0644);
  138. module_param(ivtv_first_minor, int, 0644);
  139. module_param(enc_mpg_buffers, int, 0644);
  140. module_param(enc_yuv_buffers, int, 0644);
  141. module_param(enc_vbi_buffers, int, 0644);
  142. module_param(enc_pcm_buffers, int, 0644);
  143. module_param(dec_mpg_buffers, int, 0644);
  144. module_param(dec_yuv_buffers, int, 0644);
  145. module_param(dec_vbi_buffers, int, 0644);
  146. module_param(tunertype, int, 0644);
  147. module_param(newi2c, int, 0644);
  148. module_param_array(i2c_clock_period, int, &i2c_clock_period_c, 0644);
  149. MODULE_PARM_DESC(tuner, "Tuner type selection,\n"
  150. "\t\t\tsee tuner.h for values");
  151. MODULE_PARM_DESC(radio,
  152. "Enable or disable the radio. Use only if autodetection\n"
  153. "\t\t\tfails. 0 = disable, 1 = enable");
  154. MODULE_PARM_DESC(cardtype,
  155. "Only use this option if your card is not detected properly.\n"
  156. "\t\tSpecify card type:\n"
  157. "\t\t\t 1 = WinTV PVR 250\n"
  158. "\t\t\t 2 = WinTV PVR 350\n"
  159. "\t\t\t 3 = WinTV PVR-150 or PVR-500\n"
  160. "\t\t\t 4 = AVerMedia M179\n"
  161. "\t\t\t 5 = YUAN MPG600/Kuroutoshikou iTVC16-STVLP\n"
  162. "\t\t\t 6 = YUAN MPG160/Kuroutoshikou iTVC15-STVLP\n"
  163. "\t\t\t 7 = YUAN PG600/DIAMONDMM PVR-550 (CX Falcon 2)\n"
  164. "\t\t\t 8 = Adaptec AVC-2410\n"
  165. "\t\t\t 9 = Adaptec AVC-2010\n"
  166. "\t\t\t10 = NAGASE TRANSGEAR 5000TV\n"
  167. "\t\t\t11 = AOpen VA2000MAX-STN6\n"
  168. "\t\t\t12 = YUAN MPG600GR/Kuroutoshikou CX23416GYC-STVLP\n"
  169. "\t\t\t13 = I/O Data GV-MVP/RX\n"
  170. "\t\t\t14 = I/O Data GV-MVP/RX2E\n"
  171. "\t\t\t15 = GOTVIEW PCI DVD\n"
  172. "\t\t\t16 = GOTVIEW PCI DVD2 Deluxe\n"
  173. "\t\t\t17 = Yuan MPC622\n"
  174. "\t\t\t18 = Digital Cowboy DCT-MTVP1\n"
  175. "\t\t\t19 = Yuan PG600V2/GotView PCI DVD Lite\n"
  176. "\t\t\t20 = Club3D ZAP-TV1x01\n"
  177. "\t\t\t21 = AverTV MCE 116 Plus\n"
  178. "\t\t\t22 = ASUS Falcon2\n"
  179. "\t\t\t23 = AverMedia PVR-150 Plus\n"
  180. "\t\t\t24 = AverMedia EZMaker PCI Deluxe\n"
  181. "\t\t\t25 = AverMedia M104 (not yet working)\n"
  182. "\t\t\t26 = Buffalo PC-MV5L/PCI\n"
  183. "\t\t\t27 = AVerMedia UltraTV 1500 MCE\n"
  184. "\t\t\t28 = Sony VAIO Giga Pocket (ENX Kikyou)\n"
  185. "\t\t\t 0 = Autodetect (default)\n"
  186. "\t\t\t-1 = Ignore this card\n\t\t");
  187. MODULE_PARM_DESC(pal, "Set PAL standard: BGH, DK, I, M, N, Nc, 60");
  188. MODULE_PARM_DESC(secam, "Set SECAM standard: BGH, DK, L, LC");
  189. MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J (Japan), K (South Korea)");
  190. MODULE_PARM_DESC(tunertype,
  191. "Specify tuner type:\n"
  192. "\t\t\t 0 = tuner for PAL-B/G/H/D/K/I, SECAM-B/G/H/D/K/L/Lc\n"
  193. "\t\t\t 1 = tuner for NTSC-M/J/K, PAL-M/N/Nc\n"
  194. "\t\t\t-1 = Autodetect (default)\n");
  195. MODULE_PARM_DESC(debug,
  196. "Debug level (bitmask). Default: 0\n"
  197. "\t\t\t 1/0x0001: warning\n"
  198. "\t\t\t 2/0x0002: info\n"
  199. "\t\t\t 4/0x0004: mailbox\n"
  200. "\t\t\t 8/0x0008: ioctl\n"
  201. "\t\t\t 16/0x0010: file\n"
  202. "\t\t\t 32/0x0020: dma\n"
  203. "\t\t\t 64/0x0040: irq\n"
  204. "\t\t\t 128/0x0080: decoder\n"
  205. "\t\t\t 256/0x0100: yuv\n"
  206. "\t\t\t 512/0x0200: i2c\n"
  207. "\t\t\t1024/0x0400: high volume\n");
  208. #ifdef CONFIG_VIDEO_ADV_DEBUG
  209. MODULE_PARM_DESC(fw_debug,
  210. "Enable code for debugging firmware problems. Default: 0\n");
  211. #endif
  212. MODULE_PARM_DESC(ivtv_pci_latency,
  213. "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n"
  214. "\t\t\tDefault: Yes");
  215. MODULE_PARM_DESC(ivtv_yuv_mode,
  216. "Specify the yuv playback mode:\n"
  217. "\t\t\t0 = interlaced\n\t\t\t1 = progressive\n\t\t\t2 = auto\n"
  218. "\t\t\tDefault: 0 (interlaced)");
  219. MODULE_PARM_DESC(ivtv_yuv_threshold,
  220. "If ivtv_yuv_mode is 2 (auto) then playback content as\n\t\tprogressive if src height <= ivtv_yuvthreshold\n"
  221. "\t\t\tDefault: 480");
  222. MODULE_PARM_DESC(enc_mpg_buffers,
  223. "Encoder MPG Buffers (in MB)\n"
  224. "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_MPG_BUFFERS));
  225. MODULE_PARM_DESC(enc_yuv_buffers,
  226. "Encoder YUV Buffers (in MB)\n"
  227. "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_YUV_BUFFERS));
  228. MODULE_PARM_DESC(enc_vbi_buffers,
  229. "Encoder VBI Buffers (in MB)\n"
  230. "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_VBI_BUFFERS));
  231. MODULE_PARM_DESC(enc_pcm_buffers,
  232. "Encoder PCM buffers (in kB)\n"
  233. "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_PCM_BUFFERS));
  234. MODULE_PARM_DESC(dec_mpg_buffers,
  235. "Decoder MPG buffers (in MB)\n"
  236. "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_MPG_BUFFERS));
  237. MODULE_PARM_DESC(dec_yuv_buffers,
  238. "Decoder YUV buffers (in MB)\n"
  239. "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_YUV_BUFFERS));
  240. MODULE_PARM_DESC(dec_vbi_buffers,
  241. "Decoder VBI buffers (in kB)\n"
  242. "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_VBI_BUFFERS));
  243. MODULE_PARM_DESC(newi2c,
  244. "Use new I2C implementation\n"
  245. "\t\t\t-1 is autodetect, 0 is off, 1 is on\n"
  246. "\t\t\tDefault is autodetect");
  247. MODULE_PARM_DESC(i2c_clock_period,
  248. "Period of SCL for the I2C bus controlled by the CX23415/6\n"
  249. "\t\t\tMin: 10 usec (100 kHz), Max: 4500 usec (222 Hz)\n"
  250. "\t\t\tDefault: " __stringify(IVTV_DEFAULT_I2C_CLOCK_PERIOD));
  251. MODULE_PARM_DESC(ivtv_first_minor, "Set device node number assigned to first card");
  252. MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil");
  253. MODULE_DESCRIPTION("CX23415/CX23416 driver");
  254. MODULE_SUPPORTED_DEVICE
  255. ("CX23415/CX23416 MPEG2 encoder (WinTV PVR-150/250/350/500,\n"
  256. "\t\t\tYuan MPG series and similar)");
  257. MODULE_LICENSE("GPL");
  258. MODULE_VERSION(IVTV_VERSION);
  259. #if defined(CONFIG_MODULES) && defined(MODULE)
  260. static void request_module_async(struct work_struct *work)
  261. {
  262. struct ivtv *dev = container_of(work, struct ivtv, request_module_wk);
  263. /* Make sure ivtv-alsa module is loaded */
  264. request_module("ivtv-alsa");
  265. /* Initialize ivtv-alsa for this instance of the cx18 device */
  266. if (ivtv_ext_init != NULL)
  267. ivtv_ext_init(dev);
  268. }
  269. static void request_modules(struct ivtv *dev)
  270. {
  271. INIT_WORK(&dev->request_module_wk, request_module_async);
  272. schedule_work(&dev->request_module_wk);
  273. }
  274. static void flush_request_modules(struct ivtv *dev)
  275. {
  276. flush_work(&dev->request_module_wk);
  277. }
  278. #else
  279. #define request_modules(dev)
  280. #define flush_request_modules(dev)
  281. #endif /* CONFIG_MODULES */
  282. void ivtv_clear_irq_mask(struct ivtv *itv, u32 mask)
  283. {
  284. itv->irqmask &= ~mask;
  285. write_reg_sync(itv->irqmask, IVTV_REG_IRQMASK);
  286. }
  287. void ivtv_set_irq_mask(struct ivtv *itv, u32 mask)
  288. {
  289. itv->irqmask |= mask;
  290. write_reg_sync(itv->irqmask, IVTV_REG_IRQMASK);
  291. }
  292. int ivtv_set_output_mode(struct ivtv *itv, int mode)
  293. {
  294. int old_mode;
  295. spin_lock(&itv->lock);
  296. old_mode = itv->output_mode;
  297. if (old_mode == 0)
  298. itv->output_mode = old_mode = mode;
  299. spin_unlock(&itv->lock);
  300. return old_mode;
  301. }
  302. struct ivtv_stream *ivtv_get_output_stream(struct ivtv *itv)
  303. {
  304. switch (itv->output_mode) {
  305. case OUT_MPG:
  306. return &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
  307. case OUT_YUV:
  308. return &itv->streams[IVTV_DEC_STREAM_TYPE_YUV];
  309. default:
  310. return NULL;
  311. }
  312. }
  313. int ivtv_waitq(wait_queue_head_t *waitq)
  314. {
  315. DEFINE_WAIT(wait);
  316. prepare_to_wait(waitq, &wait, TASK_INTERRUPTIBLE);
  317. schedule();
  318. finish_wait(waitq, &wait);
  319. return signal_pending(current) ? -EINTR : 0;
  320. }
  321. /* Generic utility functions */
  322. int ivtv_msleep_timeout(unsigned int msecs, int intr)
  323. {
  324. int timeout = msecs_to_jiffies(msecs);
  325. do {
  326. set_current_state(intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
  327. timeout = schedule_timeout(timeout);
  328. if (intr) {
  329. int ret = signal_pending(current);
  330. if (ret)
  331. return ret;
  332. }
  333. } while (timeout);
  334. return 0;
  335. }
  336. /* Release ioremapped memory */
  337. static void ivtv_iounmap(struct ivtv *itv)
  338. {
  339. if (itv == NULL)
  340. return;
  341. /* Release registers memory */
  342. if (itv->reg_mem != NULL) {
  343. IVTV_DEBUG_INFO("releasing reg_mem\n");
  344. iounmap(itv->reg_mem);
  345. itv->reg_mem = NULL;
  346. }
  347. /* Release io memory */
  348. if (itv->has_cx23415 && itv->dec_mem != NULL) {
  349. IVTV_DEBUG_INFO("releasing dec_mem\n");
  350. iounmap(itv->dec_mem);
  351. }
  352. itv->dec_mem = NULL;
  353. /* Release io memory */
  354. if (itv->enc_mem != NULL) {
  355. IVTV_DEBUG_INFO("releasing enc_mem\n");
  356. iounmap(itv->enc_mem);
  357. itv->enc_mem = NULL;
  358. }
  359. }
  360. /* Hauppauge card? get values from tveeprom */
  361. void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv)
  362. {
  363. u8 eedata[256];
  364. itv->i2c_client.addr = 0xA0 >> 1;
  365. tveeprom_read(&itv->i2c_client, eedata, sizeof(eedata));
  366. tveeprom_hauppauge_analog(&itv->i2c_client, tv, eedata);
  367. }
  368. static void ivtv_process_eeprom(struct ivtv *itv)
  369. {
  370. struct tveeprom tv;
  371. int pci_slot = PCI_SLOT(itv->pdev->devfn);
  372. ivtv_read_eeprom(itv, &tv);
  373. /* Many thanks to Steven Toth from Hauppauge for providing the
  374. model numbers */
  375. switch (tv.model) {
  376. /* In a few cases the PCI subsystem IDs do not correctly
  377. identify the card. A better method is to check the
  378. model number from the eeprom instead. */
  379. case 30012 ... 30039: /* Low profile PVR250 */
  380. case 32000 ... 32999:
  381. case 48000 ... 48099: /* 48??? range are PVR250s with a cx23415 */
  382. case 48400 ... 48599:
  383. itv->card = ivtv_get_card(IVTV_CARD_PVR_250);
  384. break;
  385. case 48100 ... 48399:
  386. case 48600 ... 48999:
  387. itv->card = ivtv_get_card(IVTV_CARD_PVR_350);
  388. break;
  389. case 23000 ... 23999: /* PVR500 */
  390. case 25000 ... 25999: /* Low profile PVR150 */
  391. case 26000 ... 26999: /* Regular PVR150 */
  392. itv->card = ivtv_get_card(IVTV_CARD_PVR_150);
  393. break;
  394. case 0:
  395. IVTV_ERR("Invalid EEPROM\n");
  396. return;
  397. default:
  398. IVTV_ERR("Unknown model %d, defaulting to PVR-150\n", tv.model);
  399. itv->card = ivtv_get_card(IVTV_CARD_PVR_150);
  400. break;
  401. }
  402. switch (tv.model) {
  403. /* Old style PVR350 (with an saa7114) uses this input for
  404. the tuner. */
  405. case 48254:
  406. itv->card = ivtv_get_card(IVTV_CARD_PVR_350_V1);
  407. break;
  408. default:
  409. break;
  410. }
  411. itv->v4l2_cap = itv->card->v4l2_capabilities;
  412. itv->card_name = itv->card->name;
  413. itv->card_i2c = itv->card->i2c;
  414. /* If this is a PVR500 then it should be possible to detect whether it is the
  415. first or second unit by looking at the subsystem device ID: is bit 4 is
  416. set, then it is the second unit (according to info from Hauppauge).
  417. However, while this works for most cards, I have seen a few PVR500 cards
  418. where both units have the same subsystem ID.
  419. So instead I look at the reported 'PCI slot' (which is the slot on the PVR500
  420. PCI bridge) and if it is 8, then it is assumed to be the first unit, otherwise
  421. it is the second unit. It is possible that it is a different slot when ivtv is
  422. used in Xen, in that case I ignore this card here. The worst that can happen
  423. is that the card presents itself with a non-working radio device.
  424. This detection is needed since the eeprom reports incorrectly that a radio is
  425. present on the second unit. */
  426. if (tv.model / 1000 == 23) {
  427. static const struct ivtv_card_tuner_i2c ivtv_i2c_radio = {
  428. .radio = { 0x60, I2C_CLIENT_END },
  429. .demod = { 0x43, I2C_CLIENT_END },
  430. .tv = { 0x61, I2C_CLIENT_END },
  431. };
  432. itv->card_name = "WinTV PVR 500";
  433. itv->card_i2c = &ivtv_i2c_radio;
  434. if (pci_slot == 8 || pci_slot == 9) {
  435. int is_first = (pci_slot & 1) == 0;
  436. itv->card_name = is_first ? "WinTV PVR 500 (unit #1)" :
  437. "WinTV PVR 500 (unit #2)";
  438. if (!is_first) {
  439. IVTV_INFO("Correcting tveeprom data: no radio present on second unit\n");
  440. tv.has_radio = 0;
  441. }
  442. }
  443. }
  444. IVTV_INFO("Autodetected %s\n", itv->card_name);
  445. switch (tv.tuner_hauppauge_model) {
  446. case 85:
  447. case 99:
  448. case 112:
  449. itv->pvr150_workaround = 1;
  450. break;
  451. default:
  452. break;
  453. }
  454. if (tv.tuner_type == TUNER_ABSENT)
  455. IVTV_ERR("tveeprom cannot autodetect tuner!\n");
  456. if (itv->options.tuner == -1)
  457. itv->options.tuner = tv.tuner_type;
  458. if (itv->options.radio == -1)
  459. itv->options.radio = (tv.has_radio != 0);
  460. /* only enable newi2c if an IR blaster is present */
  461. if (itv->options.newi2c == -1 && tv.has_ir) {
  462. itv->options.newi2c = (tv.has_ir & 4) ? 1 : 0;
  463. if (itv->options.newi2c) {
  464. IVTV_INFO("Reopen i2c bus for IR-blaster support\n");
  465. exit_ivtv_i2c(itv);
  466. init_ivtv_i2c(itv);
  467. }
  468. }
  469. if (itv->std != 0)
  470. /* user specified tuner standard */
  471. return;
  472. /* autodetect tuner standard */
  473. if (tv.tuner_formats & V4L2_STD_PAL) {
  474. IVTV_DEBUG_INFO("PAL tuner detected\n");
  475. itv->std |= V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
  476. } else if (tv.tuner_formats & V4L2_STD_NTSC) {
  477. IVTV_DEBUG_INFO("NTSC tuner detected\n");
  478. itv->std |= V4L2_STD_NTSC_M;
  479. } else if (tv.tuner_formats & V4L2_STD_SECAM) {
  480. IVTV_DEBUG_INFO("SECAM tuner detected\n");
  481. itv->std |= V4L2_STD_SECAM_L;
  482. } else {
  483. IVTV_INFO("No tuner detected, default to NTSC-M\n");
  484. itv->std |= V4L2_STD_NTSC_M;
  485. }
  486. }
  487. static v4l2_std_id ivtv_parse_std(struct ivtv *itv)
  488. {
  489. switch (pal[0]) {
  490. case '6':
  491. tunertype = 0;
  492. return V4L2_STD_PAL_60;
  493. case 'b':
  494. case 'B':
  495. case 'g':
  496. case 'G':
  497. case 'h':
  498. case 'H':
  499. tunertype = 0;
  500. return V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
  501. case 'n':
  502. case 'N':
  503. tunertype = 1;
  504. if (pal[1] == 'c' || pal[1] == 'C')
  505. return V4L2_STD_PAL_Nc;
  506. return V4L2_STD_PAL_N;
  507. case 'i':
  508. case 'I':
  509. tunertype = 0;
  510. return V4L2_STD_PAL_I;
  511. case 'd':
  512. case 'D':
  513. case 'k':
  514. case 'K':
  515. tunertype = 0;
  516. return V4L2_STD_PAL_DK;
  517. case 'M':
  518. case 'm':
  519. tunertype = 1;
  520. return V4L2_STD_PAL_M;
  521. case '-':
  522. break;
  523. default:
  524. IVTV_WARN("pal= argument not recognised\n");
  525. return 0;
  526. }
  527. switch (secam[0]) {
  528. case 'b':
  529. case 'B':
  530. case 'g':
  531. case 'G':
  532. case 'h':
  533. case 'H':
  534. tunertype = 0;
  535. return V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H;
  536. case 'd':
  537. case 'D':
  538. case 'k':
  539. case 'K':
  540. tunertype = 0;
  541. return V4L2_STD_SECAM_DK;
  542. case 'l':
  543. case 'L':
  544. tunertype = 0;
  545. if (secam[1] == 'C' || secam[1] == 'c')
  546. return V4L2_STD_SECAM_LC;
  547. return V4L2_STD_SECAM_L;
  548. case '-':
  549. break;
  550. default:
  551. IVTV_WARN("secam= argument not recognised\n");
  552. return 0;
  553. }
  554. switch (ntsc[0]) {
  555. case 'm':
  556. case 'M':
  557. tunertype = 1;
  558. return V4L2_STD_NTSC_M;
  559. case 'j':
  560. case 'J':
  561. tunertype = 1;
  562. return V4L2_STD_NTSC_M_JP;
  563. case 'k':
  564. case 'K':
  565. tunertype = 1;
  566. return V4L2_STD_NTSC_M_KR;
  567. case '-':
  568. break;
  569. default:
  570. IVTV_WARN("ntsc= argument not recognised\n");
  571. return 0;
  572. }
  573. /* no match found */
  574. return 0;
  575. }
  576. static void ivtv_process_options(struct ivtv *itv)
  577. {
  578. const char *chipname;
  579. int i, j;
  580. itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers * 1024;
  581. itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers * 1024;
  582. itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers * 1024;
  583. itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers;
  584. itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_MPG] = dec_mpg_buffers * 1024;
  585. itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_YUV] = dec_yuv_buffers * 1024;
  586. itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_VBI] = dec_vbi_buffers;
  587. itv->options.cardtype = cardtype[itv->instance];
  588. itv->options.tuner = tuner[itv->instance];
  589. itv->options.radio = radio[itv->instance];
  590. itv->options.i2c_clock_period = i2c_clock_period[itv->instance];
  591. if (itv->options.i2c_clock_period == -1)
  592. itv->options.i2c_clock_period = IVTV_DEFAULT_I2C_CLOCK_PERIOD;
  593. else if (itv->options.i2c_clock_period < 10)
  594. itv->options.i2c_clock_period = 10;
  595. else if (itv->options.i2c_clock_period > 4500)
  596. itv->options.i2c_clock_period = 4500;
  597. itv->options.newi2c = newi2c;
  598. if (tunertype < -1 || tunertype > 1) {
  599. IVTV_WARN("Invalid tunertype argument, will autodetect instead\n");
  600. tunertype = -1;
  601. }
  602. itv->std = ivtv_parse_std(itv);
  603. if (itv->std == 0 && tunertype >= 0)
  604. itv->std = tunertype ? V4L2_STD_MN : (V4L2_STD_ALL & ~V4L2_STD_MN);
  605. itv->has_cx23415 = (itv->pdev->device == PCI_DEVICE_ID_IVTV15);
  606. chipname = itv->has_cx23415 ? "cx23415" : "cx23416";
  607. if (itv->options.cardtype == -1) {
  608. IVTV_INFO("Ignore card (detected %s based chip)\n", chipname);
  609. return;
  610. }
  611. if ((itv->card = ivtv_get_card(itv->options.cardtype - 1))) {
  612. IVTV_INFO("User specified %s card (detected %s based chip)\n",
  613. itv->card->name, chipname);
  614. } else if (itv->options.cardtype != 0) {
  615. IVTV_ERR("Unknown user specified type, trying to autodetect card\n");
  616. }
  617. if (itv->card == NULL) {
  618. if (itv->pdev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE ||
  619. itv->pdev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE_ALT1 ||
  620. itv->pdev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE_ALT2) {
  621. itv->card = ivtv_get_card(itv->has_cx23415 ? IVTV_CARD_PVR_350 : IVTV_CARD_PVR_150);
  622. IVTV_INFO("Autodetected Hauppauge card (%s based)\n",
  623. chipname);
  624. }
  625. }
  626. if (itv->card == NULL) {
  627. for (i = 0; (itv->card = ivtv_get_card(i)); i++) {
  628. if (itv->card->pci_list == NULL)
  629. continue;
  630. for (j = 0; itv->card->pci_list[j].device; j++) {
  631. if (itv->pdev->device !=
  632. itv->card->pci_list[j].device)
  633. continue;
  634. if (itv->pdev->subsystem_vendor !=
  635. itv->card->pci_list[j].subsystem_vendor)
  636. continue;
  637. if (itv->pdev->subsystem_device !=
  638. itv->card->pci_list[j].subsystem_device)
  639. continue;
  640. IVTV_INFO("Autodetected %s card (%s based)\n",
  641. itv->card->name, chipname);
  642. goto done;
  643. }
  644. }
  645. }
  646. done:
  647. if (itv->card == NULL) {
  648. itv->card = ivtv_get_card(IVTV_CARD_PVR_150);
  649. IVTV_ERR("Unknown card: vendor/device: [%04x:%04x]\n",
  650. itv->pdev->vendor, itv->pdev->device);
  651. IVTV_ERR(" subsystem vendor/device: [%04x:%04x]\n",
  652. itv->pdev->subsystem_vendor, itv->pdev->subsystem_device);
  653. IVTV_ERR(" %s based\n", chipname);
  654. IVTV_ERR("Defaulting to %s card\n", itv->card->name);
  655. IVTV_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n");
  656. IVTV_ERR("card you have to the ivtv-devel mailinglist (www.ivtvdriver.org)\n");
  657. IVTV_ERR("Prefix your subject line with [UNKNOWN IVTV CARD].\n");
  658. }
  659. itv->v4l2_cap = itv->card->v4l2_capabilities;
  660. itv->card_name = itv->card->name;
  661. itv->card_i2c = itv->card->i2c;
  662. }
  663. /* Precondition: the ivtv structure has been memset to 0. Only
  664. the dev and num fields have been filled in.
  665. No assumptions on the card type may be made here (see ivtv_init_struct2
  666. for that).
  667. */
  668. static int ivtv_init_struct1(struct ivtv *itv)
  669. {
  670. struct sched_param param = { .sched_priority = 99 };
  671. itv->base_addr = pci_resource_start(itv->pdev, 0);
  672. itv->enc_mbox.max_mbox = 2; /* the encoder has 3 mailboxes (0-2) */
  673. itv->dec_mbox.max_mbox = 1; /* the decoder has 2 mailboxes (0-1) */
  674. mutex_init(&itv->serialize_lock);
  675. mutex_init(&itv->i2c_bus_lock);
  676. mutex_init(&itv->udma.lock);
  677. spin_lock_init(&itv->lock);
  678. spin_lock_init(&itv->dma_reg_lock);
  679. init_kthread_worker(&itv->irq_worker);
  680. itv->irq_worker_task = kthread_run(kthread_worker_fn, &itv->irq_worker,
  681. "%s", itv->v4l2_dev.name);
  682. if (IS_ERR(itv->irq_worker_task)) {
  683. IVTV_ERR("Could not create ivtv task\n");
  684. return -1;
  685. }
  686. /* must use the FIFO scheduler as it is realtime sensitive */
  687. sched_setscheduler(itv->irq_worker_task, SCHED_FIFO, &param);
  688. init_kthread_work(&itv->irq_work, ivtv_irq_work_handler);
  689. /* Initial settings */
  690. itv->cxhdl.port = CX2341X_PORT_MEMORY;
  691. itv->cxhdl.capabilities = CX2341X_CAP_HAS_SLICED_VBI;
  692. init_waitqueue_head(&itv->eos_waitq);
  693. init_waitqueue_head(&itv->event_waitq);
  694. init_waitqueue_head(&itv->vsync_waitq);
  695. init_waitqueue_head(&itv->dma_waitq);
  696. init_timer(&itv->dma_timer);
  697. itv->dma_timer.function = ivtv_unfinished_dma;
  698. itv->dma_timer.data = (unsigned long)itv;
  699. itv->cur_dma_stream = -1;
  700. itv->cur_pio_stream = -1;
  701. /* Ctrls */
  702. itv->speed = 1000;
  703. /* VBI */
  704. itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
  705. itv->vbi.sliced_in = &itv->vbi.in.fmt.sliced;
  706. /* Init the sg table for osd/yuv output */
  707. sg_init_table(itv->udma.SGlist, IVTV_DMA_SG_OSD_ENT);
  708. /* OSD */
  709. itv->osd_global_alpha_state = 1;
  710. itv->osd_global_alpha = 255;
  711. /* YUV */
  712. atomic_set(&itv->yuv_info.next_dma_frame, -1);
  713. itv->yuv_info.lace_mode = ivtv_yuv_mode;
  714. itv->yuv_info.lace_threshold = ivtv_yuv_threshold;
  715. itv->yuv_info.max_frames_buffered = 3;
  716. itv->yuv_info.track_osd = 1;
  717. return 0;
  718. }
  719. /* Second initialization part. Here the card type has been
  720. autodetected. */
  721. static void ivtv_init_struct2(struct ivtv *itv)
  722. {
  723. int i;
  724. for (i = 0; i < IVTV_CARD_MAX_VIDEO_INPUTS; i++)
  725. if (itv->card->video_inputs[i].video_type == 0)
  726. break;
  727. itv->nof_inputs = i;
  728. for (i = 0; i < IVTV_CARD_MAX_AUDIO_INPUTS; i++)
  729. if (itv->card->audio_inputs[i].audio_type == 0)
  730. break;
  731. itv->nof_audio_inputs = i;
  732. if (itv->card->hw_all & IVTV_HW_CX25840) {
  733. itv->vbi.sliced_size = 288; /* multiple of 16, real size = 284 */
  734. } else {
  735. itv->vbi.sliced_size = 64; /* multiple of 16, real size = 52 */
  736. }
  737. /* Find tuner input */
  738. for (i = 0; i < itv->nof_inputs; i++) {
  739. if (itv->card->video_inputs[i].video_type ==
  740. IVTV_CARD_INPUT_VID_TUNER)
  741. break;
  742. }
  743. if (i == itv->nof_inputs)
  744. i = 0;
  745. itv->active_input = i;
  746. itv->audio_input = itv->card->video_inputs[i].audio_index;
  747. }
  748. static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *pdev,
  749. const struct pci_device_id *pci_id)
  750. {
  751. u16 cmd;
  752. unsigned char pci_latency;
  753. IVTV_DEBUG_INFO("Enabling pci device\n");
  754. if (pci_enable_device(pdev)) {
  755. IVTV_ERR("Can't enable device!\n");
  756. return -EIO;
  757. }
  758. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  759. IVTV_ERR("No suitable DMA available.\n");
  760. return -EIO;
  761. }
  762. if (!request_mem_region(itv->base_addr, IVTV_ENCODER_SIZE, "ivtv encoder")) {
  763. IVTV_ERR("Cannot request encoder memory region.\n");
  764. return -EIO;
  765. }
  766. if (!request_mem_region(itv->base_addr + IVTV_REG_OFFSET,
  767. IVTV_REG_SIZE, "ivtv registers")) {
  768. IVTV_ERR("Cannot request register memory region.\n");
  769. release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
  770. return -EIO;
  771. }
  772. if (itv->has_cx23415 &&
  773. !request_mem_region(itv->base_addr + IVTV_DECODER_OFFSET,
  774. IVTV_DECODER_SIZE, "ivtv decoder")) {
  775. IVTV_ERR("Cannot request decoder memory region.\n");
  776. release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
  777. release_mem_region(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
  778. return -EIO;
  779. }
  780. /* Check for bus mastering */
  781. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  782. if (!(cmd & PCI_COMMAND_MASTER)) {
  783. IVTV_DEBUG_INFO("Attempting to enable Bus Mastering\n");
  784. pci_set_master(pdev);
  785. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  786. if (!(cmd & PCI_COMMAND_MASTER)) {
  787. IVTV_ERR("Bus Mastering is not enabled\n");
  788. return -ENXIO;
  789. }
  790. }
  791. IVTV_DEBUG_INFO("Bus Mastering Enabled.\n");
  792. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
  793. if (pci_latency < 64 && ivtv_pci_latency) {
  794. IVTV_INFO("Unreasonably low latency timer, "
  795. "setting to 64 (was %d)\n", pci_latency);
  796. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 64);
  797. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
  798. }
  799. /* This config space value relates to DMA latencies. The
  800. default value 0x8080 is too low however and will lead
  801. to DMA errors. 0xffff is the max value which solves
  802. these problems. */
  803. pci_write_config_dword(pdev, 0x40, 0xffff);
  804. IVTV_DEBUG_INFO("%d (rev %d) at %02x:%02x.%x, "
  805. "irq: %d, latency: %d, memory: 0x%llx\n",
  806. pdev->device, pdev->revision, pdev->bus->number,
  807. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
  808. pdev->irq, pci_latency, (u64)itv->base_addr);
  809. return 0;
  810. }
  811. static void ivtv_load_and_init_modules(struct ivtv *itv)
  812. {
  813. u32 hw = itv->card->hw_all;
  814. unsigned i;
  815. /* check which i2c devices are actually found */
  816. for (i = 0; i < 32; i++) {
  817. u32 device = 1 << i;
  818. if (!(device & hw))
  819. continue;
  820. if (device == IVTV_HW_GPIO || device == IVTV_HW_TVEEPROM) {
  821. /* GPIO and TVEEPROM do not use i2c probing */
  822. itv->hw_flags |= device;
  823. continue;
  824. }
  825. if (ivtv_i2c_register(itv, i) == 0)
  826. itv->hw_flags |= device;
  827. }
  828. /* probe for legacy IR controllers that aren't in card definitions */
  829. if ((itv->hw_flags & IVTV_HW_IR_ANY) == 0)
  830. ivtv_i2c_new_ir_legacy(itv);
  831. if (itv->card->hw_all & IVTV_HW_CX25840)
  832. itv->sd_video = ivtv_find_hw(itv, IVTV_HW_CX25840);
  833. else if (itv->card->hw_all & IVTV_HW_SAA717X)
  834. itv->sd_video = ivtv_find_hw(itv, IVTV_HW_SAA717X);
  835. else if (itv->card->hw_all & IVTV_HW_SAA7114)
  836. itv->sd_video = ivtv_find_hw(itv, IVTV_HW_SAA7114);
  837. else
  838. itv->sd_video = ivtv_find_hw(itv, IVTV_HW_SAA7115);
  839. itv->sd_audio = ivtv_find_hw(itv, itv->card->hw_audio_ctrl);
  840. itv->sd_muxer = ivtv_find_hw(itv, itv->card->hw_muxer);
  841. hw = itv->hw_flags;
  842. if (itv->card->type == IVTV_CARD_CX23416GYC) {
  843. /* Several variations of this card exist, detect which card
  844. type should be used. */
  845. if ((hw & (IVTV_HW_UPD64031A | IVTV_HW_UPD6408X)) == 0)
  846. itv->card = ivtv_get_card(IVTV_CARD_CX23416GYC_NOGRYCS);
  847. else if ((hw & IVTV_HW_UPD64031A) == 0)
  848. itv->card = ivtv_get_card(IVTV_CARD_CX23416GYC_NOGR);
  849. }
  850. else if (itv->card->type == IVTV_CARD_GV_MVPRX ||
  851. itv->card->type == IVTV_CARD_GV_MVPRX2E) {
  852. /* The crystal frequency of GVMVPRX is 24.576MHz */
  853. v4l2_subdev_call(itv->sd_video, video, s_crystal_freq,
  854. SAA7115_FREQ_24_576_MHZ, SAA7115_FREQ_FL_UCGC);
  855. }
  856. if (hw & IVTV_HW_CX25840) {
  857. itv->vbi.raw_decoder_line_size = 1444;
  858. itv->vbi.raw_decoder_sav_odd_field = 0x20;
  859. itv->vbi.raw_decoder_sav_even_field = 0x60;
  860. itv->vbi.sliced_decoder_line_size = 272;
  861. itv->vbi.sliced_decoder_sav_odd_field = 0xB0;
  862. itv->vbi.sliced_decoder_sav_even_field = 0xF0;
  863. }
  864. if (hw & IVTV_HW_SAA711X) {
  865. /* determine the exact saa711x model */
  866. itv->hw_flags &= ~IVTV_HW_SAA711X;
  867. if (strstr(itv->sd_video->name, "saa7114")) {
  868. itv->hw_flags |= IVTV_HW_SAA7114;
  869. /* VBI is not yet supported by the saa7114 driver. */
  870. itv->v4l2_cap &= ~(V4L2_CAP_SLICED_VBI_CAPTURE|V4L2_CAP_VBI_CAPTURE);
  871. } else {
  872. itv->hw_flags |= IVTV_HW_SAA7115;
  873. }
  874. itv->vbi.raw_decoder_line_size = 1443;
  875. itv->vbi.raw_decoder_sav_odd_field = 0x25;
  876. itv->vbi.raw_decoder_sav_even_field = 0x62;
  877. itv->vbi.sliced_decoder_line_size = 51;
  878. itv->vbi.sliced_decoder_sav_odd_field = 0xAB;
  879. itv->vbi.sliced_decoder_sav_even_field = 0xEC;
  880. }
  881. if (hw & IVTV_HW_SAA717X) {
  882. itv->vbi.raw_decoder_line_size = 1443;
  883. itv->vbi.raw_decoder_sav_odd_field = 0x25;
  884. itv->vbi.raw_decoder_sav_even_field = 0x62;
  885. itv->vbi.sliced_decoder_line_size = 51;
  886. itv->vbi.sliced_decoder_sav_odd_field = 0xAB;
  887. itv->vbi.sliced_decoder_sav_even_field = 0xEC;
  888. }
  889. }
  890. static int ivtv_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
  891. {
  892. int retval = 0;
  893. int vbi_buf_size;
  894. struct ivtv *itv;
  895. itv = kzalloc(sizeof(struct ivtv), GFP_ATOMIC);
  896. if (itv == NULL)
  897. return -ENOMEM;
  898. itv->pdev = pdev;
  899. itv->instance = v4l2_device_set_name(&itv->v4l2_dev, "ivtv",
  900. &ivtv_instance);
  901. retval = v4l2_device_register(&pdev->dev, &itv->v4l2_dev);
  902. if (retval) {
  903. kfree(itv);
  904. return retval;
  905. }
  906. IVTV_INFO("Initializing card %d\n", itv->instance);
  907. ivtv_process_options(itv);
  908. if (itv->options.cardtype == -1) {
  909. retval = -ENODEV;
  910. goto err;
  911. }
  912. if (ivtv_init_struct1(itv)) {
  913. retval = -ENOMEM;
  914. goto err;
  915. }
  916. retval = cx2341x_handler_init(&itv->cxhdl, 50);
  917. if (retval)
  918. goto err;
  919. itv->v4l2_dev.ctrl_handler = &itv->cxhdl.hdl;
  920. itv->cxhdl.ops = &ivtv_cxhdl_ops;
  921. itv->cxhdl.priv = itv;
  922. itv->cxhdl.func = ivtv_api_func;
  923. IVTV_DEBUG_INFO("base addr: 0x%llx\n", (u64)itv->base_addr);
  924. /* PCI Device Setup */
  925. retval = ivtv_setup_pci(itv, pdev, pci_id);
  926. if (retval == -EIO)
  927. goto free_worker;
  928. if (retval == -ENXIO)
  929. goto free_mem;
  930. /* map io memory */
  931. IVTV_DEBUG_INFO("attempting ioremap at 0x%llx len 0x%08x\n",
  932. (u64)itv->base_addr + IVTV_ENCODER_OFFSET, IVTV_ENCODER_SIZE);
  933. itv->enc_mem = ioremap_nocache(itv->base_addr + IVTV_ENCODER_OFFSET,
  934. IVTV_ENCODER_SIZE);
  935. if (!itv->enc_mem) {
  936. IVTV_ERR("ioremap failed. Can't get a window into CX23415/6 "
  937. "encoder memory\n");
  938. IVTV_ERR("Each capture card with a CX23415/6 needs 8 MB of "
  939. "vmalloc address space for this window\n");
  940. IVTV_ERR("Check the output of 'grep Vmalloc /proc/meminfo'\n");
  941. IVTV_ERR("Use the vmalloc= kernel command line option to set "
  942. "VmallocTotal to a larger value\n");
  943. retval = -ENOMEM;
  944. goto free_mem;
  945. }
  946. if (itv->has_cx23415) {
  947. IVTV_DEBUG_INFO("attempting ioremap at 0x%llx len 0x%08x\n",
  948. (u64)itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE);
  949. itv->dec_mem = ioremap_nocache(itv->base_addr + IVTV_DECODER_OFFSET,
  950. IVTV_DECODER_SIZE);
  951. if (!itv->dec_mem) {
  952. IVTV_ERR("ioremap failed. Can't get a window into "
  953. "CX23415 decoder memory\n");
  954. IVTV_ERR("Each capture card with a CX23415 needs 8 MB "
  955. "of vmalloc address space for this window\n");
  956. IVTV_ERR("Check the output of 'grep Vmalloc "
  957. "/proc/meminfo'\n");
  958. IVTV_ERR("Use the vmalloc= kernel command line option "
  959. "to set VmallocTotal to a larger value\n");
  960. retval = -ENOMEM;
  961. goto free_mem;
  962. }
  963. }
  964. else {
  965. itv->dec_mem = itv->enc_mem;
  966. }
  967. /* map registers memory */
  968. IVTV_DEBUG_INFO("attempting ioremap at 0x%llx len 0x%08x\n",
  969. (u64)itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
  970. itv->reg_mem =
  971. ioremap_nocache(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
  972. if (!itv->reg_mem) {
  973. IVTV_ERR("ioremap failed. Can't get a window into CX23415/6 "
  974. "register space\n");
  975. IVTV_ERR("Each capture card with a CX23415/6 needs 64 kB of "
  976. "vmalloc address space for this window\n");
  977. IVTV_ERR("Check the output of 'grep Vmalloc /proc/meminfo'\n");
  978. IVTV_ERR("Use the vmalloc= kernel command line option to set "
  979. "VmallocTotal to a larger value\n");
  980. retval = -ENOMEM;
  981. goto free_io;
  982. }
  983. retval = ivtv_gpio_init(itv);
  984. if (retval)
  985. goto free_io;
  986. /* active i2c */
  987. IVTV_DEBUG_INFO("activating i2c...\n");
  988. if (init_ivtv_i2c(itv)) {
  989. IVTV_ERR("Could not initialize i2c\n");
  990. goto free_io;
  991. }
  992. if (itv->card->hw_all & IVTV_HW_TVEEPROM) {
  993. /* Based on the model number the cardtype may be changed.
  994. The PCI IDs are not always reliable. */
  995. ivtv_process_eeprom(itv);
  996. }
  997. if (itv->card->comment)
  998. IVTV_INFO("%s", itv->card->comment);
  999. if (itv->card->v4l2_capabilities == 0) {
  1000. /* card was detected but is not supported */
  1001. retval = -ENODEV;
  1002. goto free_i2c;
  1003. }
  1004. if (itv->std == 0) {
  1005. itv->std = V4L2_STD_NTSC_M;
  1006. }
  1007. if (itv->options.tuner == -1) {
  1008. int i;
  1009. for (i = 0; i < IVTV_CARD_MAX_TUNERS; i++) {
  1010. if ((itv->std & itv->card->tuners[i].std) == 0)
  1011. continue;
  1012. itv->options.tuner = itv->card->tuners[i].tuner;
  1013. break;
  1014. }
  1015. }
  1016. /* if no tuner was found, then pick the first tuner in the card list */
  1017. if (itv->options.tuner == -1 && itv->card->tuners[0].std) {
  1018. itv->std = itv->card->tuners[0].std;
  1019. if (itv->std & V4L2_STD_PAL)
  1020. itv->std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
  1021. else if (itv->std & V4L2_STD_NTSC)
  1022. itv->std = V4L2_STD_NTSC_M;
  1023. else if (itv->std & V4L2_STD_SECAM)
  1024. itv->std = V4L2_STD_SECAM_L;
  1025. itv->options.tuner = itv->card->tuners[0].tuner;
  1026. }
  1027. if (itv->options.radio == -1)
  1028. itv->options.radio = (itv->card->radio_input.audio_type != 0);
  1029. /* The card is now fully identified, continue with card-specific
  1030. initialization. */
  1031. ivtv_init_struct2(itv);
  1032. ivtv_load_and_init_modules(itv);
  1033. if (itv->std & V4L2_STD_525_60) {
  1034. itv->is_60hz = 1;
  1035. itv->is_out_60hz = 1;
  1036. } else {
  1037. itv->is_50hz = 1;
  1038. itv->is_out_50hz = 1;
  1039. }
  1040. itv->yuv_info.osd_full_w = 720;
  1041. itv->yuv_info.osd_full_h = itv->is_out_50hz ? 576 : 480;
  1042. itv->yuv_info.v4l2_src_w = itv->yuv_info.osd_full_w;
  1043. itv->yuv_info.v4l2_src_h = itv->yuv_info.osd_full_h;
  1044. cx2341x_handler_set_50hz(&itv->cxhdl, itv->is_50hz);
  1045. itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_MPG] = 0x08000;
  1046. itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_PCM] = 0x01200;
  1047. itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_MPG] = 0x10000;
  1048. itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_YUV] = 0x10000;
  1049. itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_YUV] = 0x08000;
  1050. /* Setup VBI Raw Size. Should be big enough to hold PAL.
  1051. It is possible to switch between PAL and NTSC, so we need to
  1052. take the largest size here. */
  1053. /* 1456 is multiple of 16, real size = 1444 */
  1054. itv->vbi.raw_size = 1456;
  1055. /* We use a buffer size of 1/2 of the total size needed for a
  1056. frame. This is actually very useful, since we now receive
  1057. a field at a time and that makes 'compressing' the raw data
  1058. down to size by stripping off the SAV codes a lot easier.
  1059. Note: having two different buffer sizes prevents standard
  1060. switching on the fly. We need to find a better solution... */
  1061. vbi_buf_size = itv->vbi.raw_size * (itv->is_60hz ? 24 : 36) / 2;
  1062. itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_VBI] = vbi_buf_size;
  1063. itv->stream_buf_size[IVTV_DEC_STREAM_TYPE_VBI] = sizeof(struct v4l2_sliced_vbi_data) * 36;
  1064. if (itv->options.radio > 0)
  1065. itv->v4l2_cap |= V4L2_CAP_RADIO;
  1066. if (itv->options.tuner > -1) {
  1067. struct tuner_setup setup;
  1068. setup.addr = ADDR_UNSET;
  1069. setup.type = itv->options.tuner;
  1070. setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
  1071. if (itv->options.radio > 0)
  1072. setup.mode_mask |= T_RADIO;
  1073. setup.tuner_callback = (setup.type == TUNER_XC2028) ?
  1074. ivtv_reset_tuner_gpio : NULL;
  1075. ivtv_call_all(itv, tuner, s_type_addr, &setup);
  1076. if (setup.type == TUNER_XC2028) {
  1077. static struct xc2028_ctrl ctrl = {
  1078. .fname = XC2028_DEFAULT_FIRMWARE,
  1079. .max_len = 64,
  1080. };
  1081. struct v4l2_priv_tun_config cfg = {
  1082. .tuner = itv->options.tuner,
  1083. .priv = &ctrl,
  1084. };
  1085. ivtv_call_all(itv, tuner, s_config, &cfg);
  1086. }
  1087. }
  1088. /* The tuner is fixed to the standard. The other inputs (e.g. S-Video)
  1089. are not. */
  1090. itv->tuner_std = itv->std;
  1091. if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
  1092. struct v4l2_ctrl_handler *hdl = itv->v4l2_dev.ctrl_handler;
  1093. itv->ctrl_pts = v4l2_ctrl_new_std(hdl, &ivtv_hdl_out_ops,
  1094. V4L2_CID_MPEG_VIDEO_DEC_PTS, 0, 0, 0, 0);
  1095. itv->ctrl_frame = v4l2_ctrl_new_std(hdl, &ivtv_hdl_out_ops,
  1096. V4L2_CID_MPEG_VIDEO_DEC_FRAME, 0, 0, 0, 0);
  1097. /* Note: V4L2_MPEG_AUDIO_DEC_PLAYBACK_AUTO is not supported,
  1098. mask that menu item. */
  1099. itv->ctrl_audio_playback =
  1100. v4l2_ctrl_new_std_menu(hdl, &ivtv_hdl_out_ops,
  1101. V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK,
  1102. V4L2_MPEG_AUDIO_DEC_PLAYBACK_SWAPPED_STEREO,
  1103. 1 << V4L2_MPEG_AUDIO_DEC_PLAYBACK_AUTO,
  1104. V4L2_MPEG_AUDIO_DEC_PLAYBACK_STEREO);
  1105. itv->ctrl_audio_multilingual_playback =
  1106. v4l2_ctrl_new_std_menu(hdl, &ivtv_hdl_out_ops,
  1107. V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK,
  1108. V4L2_MPEG_AUDIO_DEC_PLAYBACK_SWAPPED_STEREO,
  1109. 1 << V4L2_MPEG_AUDIO_DEC_PLAYBACK_AUTO,
  1110. V4L2_MPEG_AUDIO_DEC_PLAYBACK_LEFT);
  1111. if (hdl->error) {
  1112. retval = hdl->error;
  1113. goto free_i2c;
  1114. }
  1115. v4l2_ctrl_cluster(2, &itv->ctrl_pts);
  1116. v4l2_ctrl_cluster(2, &itv->ctrl_audio_playback);
  1117. ivtv_call_all(itv, video, s_std_output, itv->std);
  1118. /* Turn off the output signal. The mpeg decoder is not yet
  1119. active so without this you would get a green image until the
  1120. mpeg decoder becomes active. */
  1121. ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 0);
  1122. }
  1123. /* clear interrupt mask, effectively disabling interrupts */
  1124. ivtv_set_irq_mask(itv, 0xffffffff);
  1125. /* Register IRQ */
  1126. retval = request_irq(itv->pdev->irq, ivtv_irq_handler,
  1127. IRQF_SHARED, itv->v4l2_dev.name, (void *)itv);
  1128. if (retval) {
  1129. IVTV_ERR("Failed to register irq %d\n", retval);
  1130. goto free_i2c;
  1131. }
  1132. retval = ivtv_streams_setup(itv);
  1133. if (retval) {
  1134. IVTV_ERR("Error %d setting up streams\n", retval);
  1135. goto free_irq;
  1136. }
  1137. retval = ivtv_streams_register(itv);
  1138. if (retval) {
  1139. IVTV_ERR("Error %d registering devices\n", retval);
  1140. goto free_streams;
  1141. }
  1142. IVTV_INFO("Initialized card: %s\n", itv->card_name);
  1143. /* Load ivtv submodules (ivtv-alsa) */
  1144. request_modules(itv);
  1145. return 0;
  1146. free_streams:
  1147. ivtv_streams_cleanup(itv);
  1148. free_irq:
  1149. free_irq(itv->pdev->irq, (void *)itv);
  1150. free_i2c:
  1151. v4l2_ctrl_handler_free(&itv->cxhdl.hdl);
  1152. exit_ivtv_i2c(itv);
  1153. free_io:
  1154. ivtv_iounmap(itv);
  1155. free_mem:
  1156. release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
  1157. release_mem_region(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
  1158. if (itv->has_cx23415)
  1159. release_mem_region(itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE);
  1160. free_worker:
  1161. kthread_stop(itv->irq_worker_task);
  1162. err:
  1163. if (retval == 0)
  1164. retval = -ENODEV;
  1165. IVTV_ERR("Error %d on initialization\n", retval);
  1166. v4l2_device_unregister(&itv->v4l2_dev);
  1167. kfree(itv);
  1168. return retval;
  1169. }
  1170. int ivtv_init_on_first_open(struct ivtv *itv)
  1171. {
  1172. struct v4l2_frequency vf;
  1173. /* Needed to call ioctls later */
  1174. struct ivtv_open_id fh;
  1175. int fw_retry_count = 3;
  1176. int video_input;
  1177. fh.itv = itv;
  1178. fh.type = IVTV_ENC_STREAM_TYPE_MPG;
  1179. if (test_bit(IVTV_F_I_FAILED, &itv->i_flags))
  1180. return -ENXIO;
  1181. if (test_and_set_bit(IVTV_F_I_INITED, &itv->i_flags))
  1182. return 0;
  1183. while (--fw_retry_count > 0) {
  1184. /* load firmware */
  1185. if (ivtv_firmware_init(itv) == 0)
  1186. break;
  1187. if (fw_retry_count > 1)
  1188. IVTV_WARN("Retry loading firmware\n");
  1189. }
  1190. if (fw_retry_count == 0) {
  1191. set_bit(IVTV_F_I_FAILED, &itv->i_flags);
  1192. return -ENXIO;
  1193. }
  1194. /* Try and get firmware versions */
  1195. IVTV_DEBUG_INFO("Getting firmware version..\n");
  1196. ivtv_firmware_versions(itv);
  1197. if (itv->card->hw_all & IVTV_HW_CX25840)
  1198. v4l2_subdev_call(itv->sd_video, core, load_fw);
  1199. vf.tuner = 0;
  1200. vf.type = V4L2_TUNER_ANALOG_TV;
  1201. vf.frequency = 6400; /* the tuner 'baseline' frequency */
  1202. /* Set initial frequency. For PAL/SECAM broadcasts no
  1203. 'default' channel exists AFAIK. */
  1204. if (itv->std == V4L2_STD_NTSC_M_JP) {
  1205. vf.frequency = 1460; /* ch. 1 91250*16/1000 */
  1206. }
  1207. else if (itv->std & V4L2_STD_NTSC_M) {
  1208. vf.frequency = 1076; /* ch. 4 67250*16/1000 */
  1209. }
  1210. video_input = itv->active_input;
  1211. itv->active_input++; /* Force update of input */
  1212. ivtv_s_input(NULL, &fh, video_input);
  1213. /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code
  1214. in one place. */
  1215. itv->std++; /* Force full standard initialization */
  1216. itv->std_out = itv->std;
  1217. ivtv_s_frequency(NULL, &fh, &vf);
  1218. if (itv->card->v4l2_capabilities & V4L2_CAP_VIDEO_OUTPUT) {
  1219. /* Turn on the TV-out: ivtv_init_mpeg_decoder() initializes
  1220. the mpeg decoder so now the saa7127 receives a proper
  1221. signal. */
  1222. ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 1);
  1223. ivtv_init_mpeg_decoder(itv);
  1224. }
  1225. /* On a cx23416 this seems to be able to enable DMA to the chip? */
  1226. if (!itv->has_cx23415)
  1227. write_reg_sync(0x03, IVTV_REG_DMACONTROL);
  1228. ivtv_s_std_enc(itv, itv->tuner_std);
  1229. /* Default interrupts enabled. For the PVR350 this includes the
  1230. decoder VSYNC interrupt, which is always on. It is not only used
  1231. during decoding but also by the OSD.
  1232. Some old PVR250 cards had a cx23415, so testing for that is too
  1233. general. Instead test if the card has video output capability. */
  1234. if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
  1235. ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT | IVTV_IRQ_DEC_VSYNC);
  1236. ivtv_set_osd_alpha(itv);
  1237. ivtv_s_std_dec(itv, itv->tuner_std);
  1238. } else {
  1239. ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT);
  1240. }
  1241. /* Setup initial controls */
  1242. cx2341x_handler_setup(&itv->cxhdl);
  1243. return 0;
  1244. }
  1245. static void ivtv_remove(struct pci_dev *pdev)
  1246. {
  1247. struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
  1248. struct ivtv *itv = to_ivtv(v4l2_dev);
  1249. int i;
  1250. IVTV_DEBUG_INFO("Removing card\n");
  1251. flush_request_modules(itv);
  1252. if (test_bit(IVTV_F_I_INITED, &itv->i_flags)) {
  1253. /* Stop all captures */
  1254. IVTV_DEBUG_INFO("Stopping all streams\n");
  1255. if (atomic_read(&itv->capturing) > 0)
  1256. ivtv_stop_all_captures(itv);
  1257. /* Stop all decoding */
  1258. IVTV_DEBUG_INFO("Stopping decoding\n");
  1259. /* Turn off the TV-out */
  1260. if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)
  1261. ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 0);
  1262. if (atomic_read(&itv->decoding) > 0) {
  1263. int type;
  1264. if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags))
  1265. type = IVTV_DEC_STREAM_TYPE_YUV;
  1266. else
  1267. type = IVTV_DEC_STREAM_TYPE_MPG;
  1268. ivtv_stop_v4l2_decode_stream(&itv->streams[type],
  1269. V4L2_DEC_CMD_STOP_TO_BLACK | V4L2_DEC_CMD_STOP_IMMEDIATELY, 0);
  1270. }
  1271. ivtv_halt_firmware(itv);
  1272. }
  1273. /* Interrupts */
  1274. ivtv_set_irq_mask(itv, 0xffffffff);
  1275. del_timer_sync(&itv->dma_timer);
  1276. /* Kill irq worker */
  1277. flush_kthread_worker(&itv->irq_worker);
  1278. kthread_stop(itv->irq_worker_task);
  1279. ivtv_streams_cleanup(itv);
  1280. ivtv_udma_free(itv);
  1281. v4l2_ctrl_handler_free(&itv->cxhdl.hdl);
  1282. exit_ivtv_i2c(itv);
  1283. free_irq(itv->pdev->irq, (void *)itv);
  1284. ivtv_iounmap(itv);
  1285. release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
  1286. release_mem_region(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
  1287. if (itv->has_cx23415)
  1288. release_mem_region(itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE);
  1289. pci_disable_device(itv->pdev);
  1290. for (i = 0; i < IVTV_VBI_FRAMES; i++)
  1291. kfree(itv->vbi.sliced_mpeg_data[i]);
  1292. printk(KERN_INFO "ivtv: Removed %s\n", itv->card_name);
  1293. v4l2_device_unregister(&itv->v4l2_dev);
  1294. kfree(itv);
  1295. }
  1296. /* define a pci_driver for card detection */
  1297. static struct pci_driver ivtv_pci_driver = {
  1298. .name = "ivtv",
  1299. .id_table = ivtv_pci_tbl,
  1300. .probe = ivtv_probe,
  1301. .remove = ivtv_remove,
  1302. };
  1303. static int __init module_start(void)
  1304. {
  1305. printk(KERN_INFO "ivtv: Start initialization, version %s\n", IVTV_VERSION);
  1306. /* Validate parameters */
  1307. if (ivtv_first_minor < 0 || ivtv_first_minor >= IVTV_MAX_CARDS) {
  1308. printk(KERN_ERR "ivtv: Exiting, ivtv_first_minor must be between 0 and %d\n",
  1309. IVTV_MAX_CARDS - 1);
  1310. return -1;
  1311. }
  1312. if (ivtv_debug < 0 || ivtv_debug > 2047) {
  1313. ivtv_debug = 0;
  1314. printk(KERN_INFO "ivtv: Debug value must be >= 0 and <= 2047\n");
  1315. }
  1316. if (pci_register_driver(&ivtv_pci_driver)) {
  1317. printk(KERN_ERR "ivtv: Error detecting PCI card\n");
  1318. return -ENODEV;
  1319. }
  1320. printk(KERN_INFO "ivtv: End initialization\n");
  1321. return 0;
  1322. }
  1323. static void __exit module_cleanup(void)
  1324. {
  1325. pci_unregister_driver(&ivtv_pci_driver);
  1326. }
  1327. /* Note: These symbols are exported because they are used by the ivtvfb
  1328. framebuffer module and an infrared module for the IR-blaster. */
  1329. EXPORT_SYMBOL(ivtv_set_irq_mask);
  1330. EXPORT_SYMBOL(ivtv_api);
  1331. EXPORT_SYMBOL(ivtv_vapi);
  1332. EXPORT_SYMBOL(ivtv_vapi_result);
  1333. EXPORT_SYMBOL(ivtv_clear_irq_mask);
  1334. EXPORT_SYMBOL(ivtv_debug);
  1335. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1336. EXPORT_SYMBOL(ivtv_fw_debug);
  1337. #endif
  1338. EXPORT_SYMBOL(ivtv_reset_ir_gpio);
  1339. EXPORT_SYMBOL(ivtv_udma_setup);
  1340. EXPORT_SYMBOL(ivtv_udma_unmap);
  1341. EXPORT_SYMBOL(ivtv_udma_alloc);
  1342. EXPORT_SYMBOL(ivtv_udma_prepare);
  1343. EXPORT_SYMBOL(ivtv_init_on_first_open);
  1344. EXPORT_SYMBOL(ivtv_firmware_check);
  1345. module_init(module_start);
  1346. module_exit(module_cleanup);