zoran_card.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  1. /*
  2. * Zoran zr36057/zr36067 PCI controller driver, for the
  3. * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
  4. * Media Labs LML33/LML33R10.
  5. *
  6. * This part handles card-specific data and detection
  7. *
  8. * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
  9. *
  10. * Currently maintained by:
  11. * Ronald Bultje <rbultje@ronald.bitfreak.net>
  12. * Laurent Pinchart <laurent.pinchart@skynet.be>
  13. * Mailinglist <mjpeg-users@lists.sf.net>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. */
  29. #include <linux/delay.h>
  30. #include <linux/types.h>
  31. #include <linux/kernel.h>
  32. #include <linux/module.h>
  33. #include <linux/init.h>
  34. #include <linux/vmalloc.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/i2c.h>
  37. #include <linux/i2c-algo-bit.h>
  38. #include <linux/videodev.h>
  39. #include <media/v4l2-common.h>
  40. #include <linux/spinlock.h>
  41. #include <linux/sem.h>
  42. #include <linux/kmod.h>
  43. #include <linux/wait.h>
  44. #include <linux/pci.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/video_decoder.h>
  47. #include <linux/video_encoder.h>
  48. #include <linux/mutex.h>
  49. #include <asm/io.h>
  50. #include "videocodec.h"
  51. #include "zoran.h"
  52. #include "zoran_card.h"
  53. #include "zoran_device.h"
  54. #include "zoran_procfs.h"
  55. extern const struct zoran_format zoran_formats[];
  56. static int card[BUZ_MAX] = { -1, -1, -1, -1 };
  57. module_param_array(card, int, NULL, 0444);
  58. MODULE_PARM_DESC(card, "The type of card");
  59. static int encoder[BUZ_MAX] = { -1, -1, -1, -1 };
  60. module_param_array(encoder, int, NULL, 0444);
  61. MODULE_PARM_DESC(encoder, "i2c TV encoder");
  62. static int decoder[BUZ_MAX] = { -1, -1, -1, -1 };
  63. module_param_array(decoder, int, NULL, 0444);
  64. MODULE_PARM_DESC(decoder, "i2c TV decoder");
  65. /*
  66. The video mem address of the video card.
  67. The driver has a little database for some videocards
  68. to determine it from there. If your video card is not in there
  69. you have either to give it to the driver as a parameter
  70. or set in in a VIDIOCSFBUF ioctl
  71. */
  72. static unsigned long vidmem; /* default = 0 - Video memory base address */
  73. module_param(vidmem, ulong, 0444);
  74. MODULE_PARM_DESC(vidmem, "Default video memory base address");
  75. /*
  76. Default input and video norm at startup of the driver.
  77. */
  78. static unsigned int default_input; /* default 0 = Composite, 1 = S-Video */
  79. module_param(default_input, uint, 0444);
  80. MODULE_PARM_DESC(default_input,
  81. "Default input (0=Composite, 1=S-Video, 2=Internal)");
  82. static int default_mux = 1; /* 6 Eyes input selection */
  83. module_param(default_mux, int, 0644);
  84. MODULE_PARM_DESC(default_mux,
  85. "Default 6 Eyes mux setting (Input selection)");
  86. static int default_norm; /* default 0 = PAL, 1 = NTSC 2 = SECAM */
  87. module_param(default_norm, int, 0444);
  88. MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
  89. /* /dev/videoN, -1 for autodetect */
  90. static int video_nr[BUZ_MAX] = {-1, -1, -1, -1};
  91. module_param_array(video_nr, int, NULL, 0444);
  92. MODULE_PARM_DESC(video_nr, "video device number (-1=Auto)");
  93. /*
  94. Number and size of grab buffers for Video 4 Linux
  95. The vast majority of applications should not need more than 2,
  96. the very popular BTTV driver actually does ONLY have 2.
  97. Time sensitive applications might need more, the maximum
  98. is VIDEO_MAX_FRAME (defined in <linux/videodev.h>).
  99. The size is set so that the maximum possible request
  100. can be satisfied. Decrease it, if bigphys_area alloc'd
  101. memory is low. If you don't have the bigphys_area patch,
  102. set it to 128 KB. Will you allow only to grab small
  103. images with V4L, but that's better than nothing.
  104. v4l_bufsize has to be given in KB !
  105. */
  106. int v4l_nbufs = 2;
  107. int v4l_bufsize = 128; /* Everybody should be able to work with this setting */
  108. module_param(v4l_nbufs, int, 0644);
  109. MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use");
  110. module_param(v4l_bufsize, int, 0644);
  111. MODULE_PARM_DESC(v4l_bufsize, "Maximum size per V4L buffer (in kB)");
  112. int jpg_nbufs = 32;
  113. int jpg_bufsize = 512; /* max size for 100% quality full-PAL frame */
  114. module_param(jpg_nbufs, int, 0644);
  115. MODULE_PARM_DESC(jpg_nbufs, "Maximum number of JPG buffers to use");
  116. module_param(jpg_bufsize, int, 0644);
  117. MODULE_PARM_DESC(jpg_bufsize, "Maximum size per JPG buffer (in kB)");
  118. int pass_through = 0; /* 1=Pass through TV signal when device is not used */
  119. /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */
  120. module_param(pass_through, int, 0644);
  121. MODULE_PARM_DESC(pass_through,
  122. "Pass TV signal through to TV-out when idling");
  123. int zr36067_debug = 1;
  124. module_param_named(debug, zr36067_debug, int, 0644);
  125. MODULE_PARM_DESC(debug, "Debug level (0-5)");
  126. MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
  127. MODULE_AUTHOR("Serguei Miridonov");
  128. MODULE_LICENSE("GPL");
  129. #if (defined(CONFIG_VIDEO_ZORAN_MODULE) && defined(MODULE))
  130. static struct pci_device_id zr36067_pci_tbl[] = {
  131. {PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057,
  132. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  133. {0}
  134. };
  135. MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
  136. #endif
  137. int zoran_num; /* number of Buzs in use */
  138. struct zoran *zoran[BUZ_MAX];
  139. /* videocodec bus functions ZR36060 */
  140. static u32
  141. zr36060_read (struct videocodec *codec,
  142. u16 reg)
  143. {
  144. struct zoran *zr = (struct zoran *) codec->master_data->data;
  145. __u32 data;
  146. if (post_office_wait(zr)
  147. || post_office_write(zr, 0, 1, reg >> 8)
  148. || post_office_write(zr, 0, 2, reg & 0xff)) {
  149. return -1;
  150. }
  151. data = post_office_read(zr, 0, 3) & 0xff;
  152. return data;
  153. }
  154. static void
  155. zr36060_write (struct videocodec *codec,
  156. u16 reg,
  157. u32 val)
  158. {
  159. struct zoran *zr = (struct zoran *) codec->master_data->data;
  160. if (post_office_wait(zr)
  161. || post_office_write(zr, 0, 1, reg >> 8)
  162. || post_office_write(zr, 0, 2, reg & 0xff)) {
  163. return;
  164. }
  165. post_office_write(zr, 0, 3, val & 0xff);
  166. }
  167. /* videocodec bus functions ZR36050 */
  168. static u32
  169. zr36050_read (struct videocodec *codec,
  170. u16 reg)
  171. {
  172. struct zoran *zr = (struct zoran *) codec->master_data->data;
  173. __u32 data;
  174. if (post_office_wait(zr)
  175. || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
  176. return -1;
  177. }
  178. data = post_office_read(zr, 0, reg & 0x03) & 0xff; // reg. LOWBYTES + read
  179. return data;
  180. }
  181. static void
  182. zr36050_write (struct videocodec *codec,
  183. u16 reg,
  184. u32 val)
  185. {
  186. struct zoran *zr = (struct zoran *) codec->master_data->data;
  187. if (post_office_wait(zr)
  188. || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
  189. return;
  190. }
  191. post_office_write(zr, 0, reg & 0x03, val & 0xff); // reg. LOWBYTES + wr. data
  192. }
  193. /* videocodec bus functions ZR36016 */
  194. static u32
  195. zr36016_read (struct videocodec *codec,
  196. u16 reg)
  197. {
  198. struct zoran *zr = (struct zoran *) codec->master_data->data;
  199. __u32 data;
  200. if (post_office_wait(zr)) {
  201. return -1;
  202. }
  203. data = post_office_read(zr, 2, reg & 0x03) & 0xff; // read
  204. return data;
  205. }
  206. /* hack for in zoran_device.c */
  207. void
  208. zr36016_write (struct videocodec *codec,
  209. u16 reg,
  210. u32 val)
  211. {
  212. struct zoran *zr = (struct zoran *) codec->master_data->data;
  213. if (post_office_wait(zr)) {
  214. return;
  215. }
  216. post_office_write(zr, 2, reg & 0x03, val & 0x0ff); // wr. data
  217. }
  218. /*
  219. * Board specific information
  220. */
  221. static void
  222. dc10_init (struct zoran *zr)
  223. {
  224. dprintk(3, KERN_DEBUG "%s: dc10_init()\n", ZR_DEVNAME(zr));
  225. /* Pixel clock selection */
  226. GPIO(zr, 4, 0);
  227. GPIO(zr, 5, 1);
  228. /* Enable the video bus sync signals */
  229. GPIO(zr, 7, 0);
  230. }
  231. static void
  232. dc10plus_init (struct zoran *zr)
  233. {
  234. dprintk(3, KERN_DEBUG "%s: dc10plus_init()\n", ZR_DEVNAME(zr));
  235. }
  236. static void
  237. buz_init (struct zoran *zr)
  238. {
  239. dprintk(3, KERN_DEBUG "%s: buz_init()\n", ZR_DEVNAME(zr));
  240. /* some stuff from Iomega */
  241. pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15);
  242. pci_write_config_dword(zr->pci_dev, 0x0c, 0x00012020);
  243. pci_write_config_dword(zr->pci_dev, 0xe8, 0xc0200000);
  244. }
  245. static void
  246. lml33_init (struct zoran *zr)
  247. {
  248. dprintk(3, KERN_DEBUG "%s: lml33_init()\n", ZR_DEVNAME(zr));
  249. GPIO(zr, 2, 1); // Set Composite input/output
  250. }
  251. static void
  252. avs6eyes_init (struct zoran *zr)
  253. {
  254. // AverMedia 6-Eyes original driver by Christer Weinigel
  255. // Lifted straight from Christer's old driver and
  256. // modified slightly by Martin Samuelsson.
  257. int mux = default_mux; /* 1 = BT866, 7 = VID1 */
  258. GPIO(zr, 4, 1); /* Bt866 SLEEP on */
  259. udelay(2);
  260. GPIO(zr, 0, 1); /* ZR36060 /RESET on */
  261. GPIO(zr, 1, 0); /* ZR36060 /SLEEP on */
  262. GPIO(zr, 2, mux & 1); /* MUX S0 */
  263. GPIO(zr, 3, 0); /* /FRAME on */
  264. GPIO(zr, 4, 0); /* Bt866 SLEEP off */
  265. GPIO(zr, 5, mux & 2); /* MUX S1 */
  266. GPIO(zr, 6, 0); /* ? */
  267. GPIO(zr, 7, mux & 4); /* MUX S2 */
  268. }
  269. static char *
  270. i2cid_to_modulename (u16 i2c_id)
  271. {
  272. char *name = NULL;
  273. switch (i2c_id) {
  274. case I2C_DRIVERID_SAA7110:
  275. name = "saa7110";
  276. break;
  277. case I2C_DRIVERID_SAA7111A:
  278. name = "saa7111";
  279. break;
  280. case I2C_DRIVERID_SAA7114:
  281. name = "saa7114";
  282. break;
  283. case I2C_DRIVERID_SAA7185B:
  284. name = "saa7185";
  285. break;
  286. case I2C_DRIVERID_ADV7170:
  287. name = "adv7170";
  288. break;
  289. case I2C_DRIVERID_ADV7175:
  290. name = "adv7175";
  291. break;
  292. case I2C_DRIVERID_BT819:
  293. name = "bt819";
  294. break;
  295. case I2C_DRIVERID_BT856:
  296. name = "bt856";
  297. break;
  298. case I2C_DRIVERID_BT866:
  299. name = "bt866";
  300. break;
  301. case I2C_DRIVERID_VPX3220:
  302. name = "vpx3220";
  303. break;
  304. case I2C_DRIVERID_KS0127:
  305. name = "ks0127";
  306. break;
  307. }
  308. return name;
  309. }
  310. static char *
  311. codecid_to_modulename (u16 codecid)
  312. {
  313. char *name = NULL;
  314. switch (codecid) {
  315. case CODEC_TYPE_ZR36060:
  316. name = "zr36060";
  317. break;
  318. case CODEC_TYPE_ZR36050:
  319. name = "zr36050";
  320. break;
  321. case CODEC_TYPE_ZR36016:
  322. name = "zr36016";
  323. break;
  324. }
  325. return name;
  326. }
  327. // struct tvnorm {
  328. // u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
  329. // };
  330. static struct tvnorm f50sqpixel = { 944, 768, 83, 880, 625, 576, 16 };
  331. static struct tvnorm f60sqpixel = { 780, 640, 51, 716, 525, 480, 12 };
  332. static struct tvnorm f50ccir601 = { 864, 720, 75, 804, 625, 576, 18 };
  333. static struct tvnorm f60ccir601 = { 858, 720, 57, 788, 525, 480, 16 };
  334. static struct tvnorm f50ccir601_lml33 = { 864, 720, 75+34, 804, 625, 576, 18 };
  335. static struct tvnorm f60ccir601_lml33 = { 858, 720, 57+34, 788, 525, 480, 16 };
  336. /* The DC10 (57/16/50) uses VActive as HSync, so HStart must be 0 */
  337. static struct tvnorm f50sqpixel_dc10 = { 944, 768, 0, 880, 625, 576, 0 };
  338. static struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 };
  339. /* FIXME: I cannot swap U and V in saa7114, so i do one
  340. * pixel left shift in zoran (75 -> 74)
  341. * (Maxim Yevtyushkin <max@linuxmedialabs.com>) */
  342. static struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74+54, 804, 625, 576, 18 };
  343. static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 };
  344. /* FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I
  345. * copy Maxim's left shift hack for the 6 Eyes.
  346. *
  347. * Christer's driver used the unshifted norms, though...
  348. * /Sam */
  349. static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
  350. static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
  351. static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
  352. {
  353. .type = DC10_old,
  354. .name = "DC10(old)",
  355. .i2c_decoder = I2C_DRIVERID_VPX3220,
  356. .video_codec = CODEC_TYPE_ZR36050,
  357. .video_vfe = CODEC_TYPE_ZR36016,
  358. .inputs = 3,
  359. .input = {
  360. { 1, "Composite" },
  361. { 2, "S-Video" },
  362. { 0, "Internal/comp" }
  363. },
  364. .norms = 3,
  365. .tvn = {
  366. &f50sqpixel_dc10,
  367. &f60sqpixel_dc10,
  368. &f50sqpixel_dc10
  369. },
  370. .jpeg_int = 0,
  371. .vsync_int = ZR36057_ISR_GIRQ1,
  372. .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
  373. .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
  374. .gpcs = { -1, 0 },
  375. .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  376. .gws_not_connected = 0,
  377. .input_mux = 0,
  378. .init = &dc10_init,
  379. }, {
  380. .type = DC10_new,
  381. .name = "DC10(new)",
  382. .i2c_decoder = I2C_DRIVERID_SAA7110,
  383. .i2c_encoder = I2C_DRIVERID_ADV7175,
  384. .video_codec = CODEC_TYPE_ZR36060,
  385. .inputs = 3,
  386. .input = {
  387. { 0, "Composite" },
  388. { 7, "S-Video" },
  389. { 5, "Internal/comp" }
  390. },
  391. .norms = 3,
  392. .tvn = {
  393. &f50sqpixel,
  394. &f60sqpixel,
  395. &f50sqpixel},
  396. .jpeg_int = ZR36057_ISR_GIRQ0,
  397. .vsync_int = ZR36057_ISR_GIRQ1,
  398. .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
  399. .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  400. .gpcs = { -1, 1},
  401. .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
  402. .gws_not_connected = 0,
  403. .input_mux = 0,
  404. .init = &dc10plus_init,
  405. }, {
  406. .type = DC10plus,
  407. .name = "DC10plus",
  408. .vendor_id = PCI_VENDOR_ID_MIRO,
  409. .device_id = PCI_DEVICE_ID_MIRO_DC10PLUS,
  410. .i2c_decoder = I2C_DRIVERID_SAA7110,
  411. .i2c_encoder = I2C_DRIVERID_ADV7175,
  412. .video_codec = CODEC_TYPE_ZR36060,
  413. .inputs = 3,
  414. .input = {
  415. { 0, "Composite" },
  416. { 7, "S-Video" },
  417. { 5, "Internal/comp" }
  418. },
  419. .norms = 3,
  420. .tvn = {
  421. &f50sqpixel,
  422. &f60sqpixel,
  423. &f50sqpixel
  424. },
  425. .jpeg_int = ZR36057_ISR_GIRQ0,
  426. .vsync_int = ZR36057_ISR_GIRQ1,
  427. .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
  428. .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  429. .gpcs = { -1, 1 },
  430. .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
  431. .gws_not_connected = 0,
  432. .input_mux = 0,
  433. .init = &dc10plus_init,
  434. }, {
  435. .type = DC30,
  436. .name = "DC30",
  437. .i2c_decoder = I2C_DRIVERID_VPX3220,
  438. .i2c_encoder = I2C_DRIVERID_ADV7175,
  439. .video_codec = CODEC_TYPE_ZR36050,
  440. .video_vfe = CODEC_TYPE_ZR36016,
  441. .inputs = 3,
  442. .input = {
  443. { 1, "Composite" },
  444. { 2, "S-Video" },
  445. { 0, "Internal/comp" }
  446. },
  447. .norms = 3,
  448. .tvn = {
  449. &f50sqpixel_dc10,
  450. &f60sqpixel_dc10,
  451. &f50sqpixel_dc10
  452. },
  453. .jpeg_int = 0,
  454. .vsync_int = ZR36057_ISR_GIRQ1,
  455. .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
  456. .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
  457. .gpcs = { -1, 0 },
  458. .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  459. .gws_not_connected = 0,
  460. .input_mux = 0,
  461. .init = &dc10_init,
  462. }, {
  463. .type = DC30plus,
  464. .name = "DC30plus",
  465. .vendor_id = PCI_VENDOR_ID_MIRO,
  466. .device_id = PCI_DEVICE_ID_MIRO_DC30PLUS,
  467. .i2c_decoder = I2C_DRIVERID_VPX3220,
  468. .i2c_encoder = I2C_DRIVERID_ADV7175,
  469. .video_codec = CODEC_TYPE_ZR36050,
  470. .video_vfe = CODEC_TYPE_ZR36016,
  471. .inputs = 3,
  472. .input = {
  473. { 1, "Composite" },
  474. { 2, "S-Video" },
  475. { 0, "Internal/comp" }
  476. },
  477. .norms = 3,
  478. .tvn = {
  479. &f50sqpixel_dc10,
  480. &f60sqpixel_dc10,
  481. &f50sqpixel_dc10
  482. },
  483. .jpeg_int = 0,
  484. .vsync_int = ZR36057_ISR_GIRQ1,
  485. .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
  486. .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
  487. .gpcs = { -1, 0 },
  488. .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  489. .gws_not_connected = 0,
  490. .input_mux = 0,
  491. .init = &dc10_init,
  492. }, {
  493. .type = LML33,
  494. .name = "LML33",
  495. .i2c_decoder = I2C_DRIVERID_BT819,
  496. .i2c_encoder = I2C_DRIVERID_BT856,
  497. .video_codec = CODEC_TYPE_ZR36060,
  498. .inputs = 2,
  499. .input = {
  500. { 0, "Composite" },
  501. { 7, "S-Video" }
  502. },
  503. .norms = 2,
  504. .tvn = {
  505. &f50ccir601_lml33,
  506. &f60ccir601_lml33,
  507. NULL
  508. },
  509. .jpeg_int = ZR36057_ISR_GIRQ1,
  510. .vsync_int = ZR36057_ISR_GIRQ0,
  511. .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
  512. .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
  513. .gpcs = { 3, 1 },
  514. .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
  515. .gws_not_connected = 1,
  516. .input_mux = 0,
  517. .init = &lml33_init,
  518. }, {
  519. .type = LML33R10,
  520. .name = "LML33R10",
  521. .vendor_id = PCI_VENDOR_ID_ELECTRONICDESIGNGMBH,
  522. .device_id = PCI_DEVICE_ID_LML_33R10,
  523. .i2c_decoder = I2C_DRIVERID_SAA7114,
  524. .i2c_encoder = I2C_DRIVERID_ADV7170,
  525. .video_codec = CODEC_TYPE_ZR36060,
  526. .inputs = 2,
  527. .input = {
  528. { 0, "Composite" },
  529. { 7, "S-Video" }
  530. },
  531. .norms = 2,
  532. .tvn = {
  533. &f50ccir601_lm33r10,
  534. &f60ccir601_lm33r10,
  535. NULL
  536. },
  537. .jpeg_int = ZR36057_ISR_GIRQ1,
  538. .vsync_int = ZR36057_ISR_GIRQ0,
  539. .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
  540. .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
  541. .gpcs = { 3, 1 },
  542. .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
  543. .gws_not_connected = 1,
  544. .input_mux = 0,
  545. .init = &lml33_init,
  546. }, {
  547. .type = BUZ,
  548. .name = "Buz",
  549. .vendor_id = PCI_VENDOR_ID_IOMEGA,
  550. .device_id = PCI_DEVICE_ID_IOMEGA_BUZ,
  551. .i2c_decoder = I2C_DRIVERID_SAA7111A,
  552. .i2c_encoder = I2C_DRIVERID_SAA7185B,
  553. .video_codec = CODEC_TYPE_ZR36060,
  554. .inputs = 2,
  555. .input = {
  556. { 3, "Composite" },
  557. { 7, "S-Video" }
  558. },
  559. .norms = 3,
  560. .tvn = {
  561. &f50ccir601,
  562. &f60ccir601,
  563. &f50ccir601
  564. },
  565. .jpeg_int = ZR36057_ISR_GIRQ1,
  566. .vsync_int = ZR36057_ISR_GIRQ0,
  567. .gpio = { 1, -1, 3, -1, -1, -1, -1, -1 },
  568. .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  569. .gpcs = { 3, 1 },
  570. .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
  571. .gws_not_connected = 1,
  572. .input_mux = 0,
  573. .init = &buz_init,
  574. }, {
  575. .type = AVS6EYES,
  576. .name = "6-Eyes",
  577. /* AverMedia chose not to brand the 6-Eyes. Thus it
  578. can't be autodetected, and requires card=x. */
  579. .vendor_id = -1,
  580. .device_id = -1,
  581. .i2c_decoder = I2C_DRIVERID_KS0127,
  582. .i2c_encoder = I2C_DRIVERID_BT866,
  583. .video_codec = CODEC_TYPE_ZR36060,
  584. .inputs = 10,
  585. .input = {
  586. { 0, "Composite 1" },
  587. { 1, "Composite 2" },
  588. { 2, "Composite 3" },
  589. { 4, "Composite 4" },
  590. { 5, "Composite 5" },
  591. { 6, "Composite 6" },
  592. { 8, "S-Video 1" },
  593. { 9, "S-Video 2" },
  594. {10, "S-Video 3" },
  595. {15, "YCbCr" }
  596. },
  597. .norms = 2,
  598. .tvn = {
  599. &f50ccir601_avs6eyes,
  600. &f60ccir601_avs6eyes,
  601. NULL
  602. },
  603. .jpeg_int = ZR36057_ISR_GIRQ1,
  604. .vsync_int = ZR36057_ISR_GIRQ0,
  605. .gpio = { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
  606. .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
  607. .gpcs = { 3, 1 }, // Validity unknown /Sam
  608. .vfe_pol = { 1, 0, 0, 0, 0, 1, 0, 0 }, // Validity unknown /Sam
  609. .gws_not_connected = 1,
  610. .input_mux = 1,
  611. .init = &avs6eyes_init,
  612. }
  613. };
  614. /*
  615. * I2C functions
  616. */
  617. /* software I2C functions */
  618. static int
  619. zoran_i2c_getsda (void *data)
  620. {
  621. struct zoran *zr = (struct zoran *) data;
  622. return (btread(ZR36057_I2CBR) >> 1) & 1;
  623. }
  624. static int
  625. zoran_i2c_getscl (void *data)
  626. {
  627. struct zoran *zr = (struct zoran *) data;
  628. return btread(ZR36057_I2CBR) & 1;
  629. }
  630. static void
  631. zoran_i2c_setsda (void *data,
  632. int state)
  633. {
  634. struct zoran *zr = (struct zoran *) data;
  635. if (state)
  636. zr->i2cbr |= 2;
  637. else
  638. zr->i2cbr &= ~2;
  639. btwrite(zr->i2cbr, ZR36057_I2CBR);
  640. }
  641. static void
  642. zoran_i2c_setscl (void *data,
  643. int state)
  644. {
  645. struct zoran *zr = (struct zoran *) data;
  646. if (state)
  647. zr->i2cbr |= 1;
  648. else
  649. zr->i2cbr &= ~1;
  650. btwrite(zr->i2cbr, ZR36057_I2CBR);
  651. }
  652. static int
  653. zoran_i2c_client_register (struct i2c_client *client)
  654. {
  655. struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter);
  656. int res = 0;
  657. dprintk(2,
  658. KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n",
  659. ZR_DEVNAME(zr), client->driver->id);
  660. mutex_lock(&zr->resource_lock);
  661. if (zr->user > 0) {
  662. /* we're already busy, so we keep a reference to
  663. * them... Could do a lot of stuff here, but this
  664. * is easiest. (Did I ever mention I'm a lazy ass?)
  665. */
  666. res = -EBUSY;
  667. goto clientreg_unlock_and_return;
  668. }
  669. if (client->driver->id == zr->card.i2c_decoder)
  670. zr->decoder = client;
  671. else if (client->driver->id == zr->card.i2c_encoder)
  672. zr->encoder = client;
  673. else {
  674. res = -ENODEV;
  675. goto clientreg_unlock_and_return;
  676. }
  677. clientreg_unlock_and_return:
  678. mutex_unlock(&zr->resource_lock);
  679. return res;
  680. }
  681. static int
  682. zoran_i2c_client_unregister (struct i2c_client *client)
  683. {
  684. struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter);
  685. int res = 0;
  686. dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr));
  687. mutex_lock(&zr->resource_lock);
  688. if (zr->user > 0) {
  689. res = -EBUSY;
  690. goto clientunreg_unlock_and_return;
  691. }
  692. /* try to locate it */
  693. if (client == zr->encoder) {
  694. zr->encoder = NULL;
  695. } else if (client == zr->decoder) {
  696. zr->decoder = NULL;
  697. snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id);
  698. }
  699. clientunreg_unlock_and_return:
  700. mutex_unlock(&zr->resource_lock);
  701. return res;
  702. }
  703. static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
  704. .setsda = zoran_i2c_setsda,
  705. .setscl = zoran_i2c_setscl,
  706. .getsda = zoran_i2c_getsda,
  707. .getscl = zoran_i2c_getscl,
  708. .udelay = 10,
  709. .timeout = 100,
  710. };
  711. static int
  712. zoran_register_i2c (struct zoran *zr)
  713. {
  714. memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template,
  715. sizeof(struct i2c_algo_bit_data));
  716. zr->i2c_algo.data = zr;
  717. zr->i2c_adapter.class = I2C_CLASS_TV_ANALOG;
  718. zr->i2c_adapter.id = I2C_HW_B_ZR36067;
  719. zr->i2c_adapter.client_register = zoran_i2c_client_register;
  720. zr->i2c_adapter.client_unregister = zoran_i2c_client_unregister;
  721. strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr),
  722. sizeof(zr->i2c_adapter.name));
  723. i2c_set_adapdata(&zr->i2c_adapter, zr);
  724. zr->i2c_adapter.algo_data = &zr->i2c_algo;
  725. zr->i2c_adapter.dev.parent = &zr->pci_dev->dev;
  726. return i2c_bit_add_bus(&zr->i2c_adapter);
  727. }
  728. static void
  729. zoran_unregister_i2c (struct zoran *zr)
  730. {
  731. i2c_del_adapter(&zr->i2c_adapter);
  732. }
  733. /* Check a zoran_params struct for correctness, insert default params */
  734. int
  735. zoran_check_jpg_settings (struct zoran *zr,
  736. struct zoran_jpg_settings *settings)
  737. {
  738. int err = 0, err0 = 0;
  739. dprintk(4,
  740. KERN_DEBUG
  741. "%s: check_jpg_settings() - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
  742. ZR_DEVNAME(zr), settings->decimation, settings->HorDcm,
  743. settings->VerDcm, settings->TmpDcm);
  744. dprintk(4,
  745. KERN_DEBUG
  746. "%s: check_jpg_settings() - x: %d, y: %d, w: %d, y: %d\n",
  747. ZR_DEVNAME(zr), settings->img_x, settings->img_y,
  748. settings->img_width, settings->img_height);
  749. /* Check decimation, set default values for decimation = 1, 2, 4 */
  750. switch (settings->decimation) {
  751. case 1:
  752. settings->HorDcm = 1;
  753. settings->VerDcm = 1;
  754. settings->TmpDcm = 1;
  755. settings->field_per_buff = 2;
  756. settings->img_x = 0;
  757. settings->img_y = 0;
  758. settings->img_width = BUZ_MAX_WIDTH;
  759. settings->img_height = BUZ_MAX_HEIGHT / 2;
  760. break;
  761. case 2:
  762. settings->HorDcm = 2;
  763. settings->VerDcm = 1;
  764. settings->TmpDcm = 2;
  765. settings->field_per_buff = 1;
  766. settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
  767. settings->img_y = 0;
  768. settings->img_width =
  769. (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
  770. settings->img_height = BUZ_MAX_HEIGHT / 2;
  771. break;
  772. case 4:
  773. if (zr->card.type == DC10_new) {
  774. dprintk(1,
  775. KERN_DEBUG
  776. "%s: check_jpg_settings() - HDec by 4 is not supported on the DC10\n",
  777. ZR_DEVNAME(zr));
  778. err0++;
  779. break;
  780. }
  781. settings->HorDcm = 4;
  782. settings->VerDcm = 2;
  783. settings->TmpDcm = 2;
  784. settings->field_per_buff = 1;
  785. settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
  786. settings->img_y = 0;
  787. settings->img_width =
  788. (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
  789. settings->img_height = BUZ_MAX_HEIGHT / 2;
  790. break;
  791. case 0:
  792. /* We have to check the data the user has set */
  793. if (settings->HorDcm != 1 && settings->HorDcm != 2 &&
  794. (zr->card.type == DC10_new || settings->HorDcm != 4))
  795. err0++;
  796. if (settings->VerDcm != 1 && settings->VerDcm != 2)
  797. err0++;
  798. if (settings->TmpDcm != 1 && settings->TmpDcm != 2)
  799. err0++;
  800. if (settings->field_per_buff != 1 &&
  801. settings->field_per_buff != 2)
  802. err0++;
  803. if (settings->img_x < 0)
  804. err0++;
  805. if (settings->img_y < 0)
  806. err0++;
  807. if (settings->img_width < 0)
  808. err0++;
  809. if (settings->img_height < 0)
  810. err0++;
  811. if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH)
  812. err0++;
  813. if (settings->img_y + settings->img_height >
  814. BUZ_MAX_HEIGHT / 2)
  815. err0++;
  816. if (settings->HorDcm && settings->VerDcm) {
  817. if (settings->img_width %
  818. (16 * settings->HorDcm) != 0)
  819. err0++;
  820. if (settings->img_height %
  821. (8 * settings->VerDcm) != 0)
  822. err0++;
  823. }
  824. if (err0) {
  825. dprintk(1,
  826. KERN_ERR
  827. "%s: check_jpg_settings() - error in params for decimation = 0\n",
  828. ZR_DEVNAME(zr));
  829. err++;
  830. }
  831. break;
  832. default:
  833. dprintk(1,
  834. KERN_ERR
  835. "%s: check_jpg_settings() - decimation = %d, must be 0, 1, 2 or 4\n",
  836. ZR_DEVNAME(zr), settings->decimation);
  837. err++;
  838. break;
  839. }
  840. if (settings->jpg_comp.quality > 100)
  841. settings->jpg_comp.quality = 100;
  842. if (settings->jpg_comp.quality < 5)
  843. settings->jpg_comp.quality = 5;
  844. if (settings->jpg_comp.APPn < 0)
  845. settings->jpg_comp.APPn = 0;
  846. if (settings->jpg_comp.APPn > 15)
  847. settings->jpg_comp.APPn = 15;
  848. if (settings->jpg_comp.APP_len < 0)
  849. settings->jpg_comp.APP_len = 0;
  850. if (settings->jpg_comp.APP_len > 60)
  851. settings->jpg_comp.APP_len = 60;
  852. if (settings->jpg_comp.COM_len < 0)
  853. settings->jpg_comp.COM_len = 0;
  854. if (settings->jpg_comp.COM_len > 60)
  855. settings->jpg_comp.COM_len = 60;
  856. if (err)
  857. return -EINVAL;
  858. return 0;
  859. }
  860. void
  861. zoran_open_init_params (struct zoran *zr)
  862. {
  863. int i;
  864. /* User must explicitly set a window */
  865. zr->overlay_settings.is_set = 0;
  866. zr->overlay_mask = NULL;
  867. zr->overlay_active = ZORAN_FREE;
  868. zr->v4l_memgrab_active = 0;
  869. zr->v4l_overlay_active = 0;
  870. zr->v4l_grab_frame = NO_GRAB_ACTIVE;
  871. zr->v4l_grab_seq = 0;
  872. zr->v4l_settings.width = 192;
  873. zr->v4l_settings.height = 144;
  874. zr->v4l_settings.format = &zoran_formats[7]; /* YUY2 - YUV-4:2:2 packed */
  875. zr->v4l_settings.bytesperline =
  876. zr->v4l_settings.width *
  877. ((zr->v4l_settings.format->depth + 7) / 8);
  878. /* DMA ring stuff for V4L */
  879. zr->v4l_pend_tail = 0;
  880. zr->v4l_pend_head = 0;
  881. zr->v4l_sync_tail = 0;
  882. zr->v4l_buffers.active = ZORAN_FREE;
  883. for (i = 0; i < VIDEO_MAX_FRAME; i++) {
  884. zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
  885. }
  886. zr->v4l_buffers.allocated = 0;
  887. for (i = 0; i < BUZ_MAX_FRAME; i++) {
  888. zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
  889. }
  890. zr->jpg_buffers.active = ZORAN_FREE;
  891. zr->jpg_buffers.allocated = 0;
  892. /* Set necessary params and call zoran_check_jpg_settings to set the defaults */
  893. zr->jpg_settings.decimation = 1;
  894. zr->jpg_settings.jpg_comp.quality = 50; /* default compression factor 8 */
  895. if (zr->card.type != BUZ)
  896. zr->jpg_settings.odd_even = 1;
  897. else
  898. zr->jpg_settings.odd_even = 0;
  899. zr->jpg_settings.jpg_comp.APPn = 0;
  900. zr->jpg_settings.jpg_comp.APP_len = 0; /* No APPn marker */
  901. memset(zr->jpg_settings.jpg_comp.APP_data, 0,
  902. sizeof(zr->jpg_settings.jpg_comp.APP_data));
  903. zr->jpg_settings.jpg_comp.COM_len = 0; /* No COM marker */
  904. memset(zr->jpg_settings.jpg_comp.COM_data, 0,
  905. sizeof(zr->jpg_settings.jpg_comp.COM_data));
  906. zr->jpg_settings.jpg_comp.jpeg_markers =
  907. JPEG_MARKER_DHT | JPEG_MARKER_DQT;
  908. i = zoran_check_jpg_settings(zr, &zr->jpg_settings);
  909. if (i)
  910. dprintk(1,
  911. KERN_ERR
  912. "%s: zoran_open_init_params() internal error\n",
  913. ZR_DEVNAME(zr));
  914. clear_interrupt_counters(zr);
  915. zr->testing = 0;
  916. }
  917. static void __devinit
  918. test_interrupts (struct zoran *zr)
  919. {
  920. DEFINE_WAIT(wait);
  921. int timeout, icr;
  922. clear_interrupt_counters(zr);
  923. zr->testing = 1;
  924. icr = btread(ZR36057_ICR);
  925. btwrite(0x78000000 | ZR36057_ICR_IntPinEn, ZR36057_ICR);
  926. prepare_to_wait(&zr->test_q, &wait, TASK_INTERRUPTIBLE);
  927. timeout = schedule_timeout(HZ);
  928. finish_wait(&zr->test_q, &wait);
  929. btwrite(0, ZR36057_ICR);
  930. btwrite(0x78000000, ZR36057_ISR);
  931. zr->testing = 0;
  932. dprintk(5, KERN_INFO "%s: Testing interrupts...\n", ZR_DEVNAME(zr));
  933. if (timeout) {
  934. dprintk(1, ": time spent: %d\n", 1 * HZ - timeout);
  935. }
  936. if (zr36067_debug > 1)
  937. print_interrupts(zr);
  938. btwrite(icr, ZR36057_ICR);
  939. }
  940. static int __devinit
  941. zr36057_init (struct zoran *zr)
  942. {
  943. int j, err;
  944. int two = 2;
  945. int zero = 0;
  946. dprintk(1,
  947. KERN_INFO
  948. "%s: zr36057_init() - initializing card[%d], zr=%p\n",
  949. ZR_DEVNAME(zr), zr->id, zr);
  950. /* default setup of all parameters which will persist between opens */
  951. zr->user = 0;
  952. init_waitqueue_head(&zr->v4l_capq);
  953. init_waitqueue_head(&zr->jpg_capq);
  954. init_waitqueue_head(&zr->test_q);
  955. zr->jpg_buffers.allocated = 0;
  956. zr->v4l_buffers.allocated = 0;
  957. zr->buffer.base = (void *) vidmem;
  958. zr->buffer.width = 0;
  959. zr->buffer.height = 0;
  960. zr->buffer.depth = 0;
  961. zr->buffer.bytesperline = 0;
  962. /* Avoid nonsense settings from user for default input/norm */
  963. if (default_norm < VIDEO_MODE_PAL &&
  964. default_norm > VIDEO_MODE_SECAM)
  965. default_norm = VIDEO_MODE_PAL;
  966. zr->norm = default_norm;
  967. if (!(zr->timing = zr->card.tvn[zr->norm])) {
  968. dprintk(1,
  969. KERN_WARNING
  970. "%s: zr36057_init() - default TV standard not supported by hardware. PAL will be used.\n",
  971. ZR_DEVNAME(zr));
  972. zr->norm = VIDEO_MODE_PAL;
  973. zr->timing = zr->card.tvn[zr->norm];
  974. }
  975. if (default_input > zr->card.inputs-1) {
  976. dprintk(1,
  977. KERN_WARNING
  978. "%s: default_input value %d out of range (0-%d)\n",
  979. ZR_DEVNAME(zr), default_input, zr->card.inputs-1);
  980. default_input = 0;
  981. }
  982. zr->input = default_input;
  983. /* Should the following be reset at every open ? */
  984. zr->hue = 32768;
  985. zr->contrast = 32768;
  986. zr->saturation = 32768;
  987. zr->brightness = 32768;
  988. /* default setup (will be repeated at every open) */
  989. zoran_open_init_params(zr);
  990. /* allocate memory *before* doing anything to the hardware
  991. * in case allocation fails */
  992. zr->stat_com = kzalloc(BUZ_NUM_STAT_COM * 4, GFP_KERNEL);
  993. zr->video_dev = kmalloc(sizeof(struct video_device), GFP_KERNEL);
  994. if (!zr->stat_com || !zr->video_dev) {
  995. dprintk(1,
  996. KERN_ERR
  997. "%s: zr36057_init() - kmalloc (STAT_COM) failed\n",
  998. ZR_DEVNAME(zr));
  999. err = -ENOMEM;
  1000. goto exit_free;
  1001. }
  1002. for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
  1003. zr->stat_com[j] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
  1004. }
  1005. /*
  1006. * Now add the template and register the device unit.
  1007. */
  1008. memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
  1009. strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
  1010. err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
  1011. if (err < 0)
  1012. goto exit_unregister;
  1013. zoran_init_hardware(zr);
  1014. if (zr36067_debug > 2)
  1015. detect_guest_activity(zr);
  1016. test_interrupts(zr);
  1017. if (!pass_through) {
  1018. decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
  1019. encoder_command(zr, ENCODER_SET_INPUT, &two);
  1020. }
  1021. zr->zoran_proc = NULL;
  1022. zr->initialized = 1;
  1023. return 0;
  1024. exit_unregister:
  1025. zoran_unregister_i2c(zr);
  1026. exit_free:
  1027. kfree(zr->stat_com);
  1028. kfree(zr->video_dev);
  1029. return err;
  1030. }
  1031. static void
  1032. zoran_release (struct zoran *zr)
  1033. {
  1034. if (!zr->initialized)
  1035. goto exit_free;
  1036. /* unregister videocodec bus */
  1037. if (zr->codec) {
  1038. struct videocodec_master *master = zr->codec->master_data;
  1039. videocodec_detach(zr->codec);
  1040. kfree(master);
  1041. }
  1042. if (zr->vfe) {
  1043. struct videocodec_master *master = zr->vfe->master_data;
  1044. videocodec_detach(zr->vfe);
  1045. kfree(master);
  1046. }
  1047. /* unregister i2c bus */
  1048. zoran_unregister_i2c(zr);
  1049. /* disable PCI bus-mastering */
  1050. zoran_set_pci_master(zr, 0);
  1051. /* put chip into reset */
  1052. btwrite(0, ZR36057_SPGPPCR);
  1053. free_irq(zr->pci_dev->irq, zr);
  1054. /* unmap and free memory */
  1055. kfree(zr->stat_com);
  1056. zoran_proc_cleanup(zr);
  1057. iounmap(zr->zr36057_mem);
  1058. pci_disable_device(zr->pci_dev);
  1059. video_unregister_device(zr->video_dev);
  1060. exit_free:
  1061. kfree(zr);
  1062. }
  1063. void
  1064. zoran_vdev_release (struct video_device *vdev)
  1065. {
  1066. kfree(vdev);
  1067. }
  1068. static struct videocodec_master * __devinit
  1069. zoran_setup_videocodec (struct zoran *zr,
  1070. int type)
  1071. {
  1072. struct videocodec_master *m = NULL;
  1073. m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL);
  1074. if (!m) {
  1075. dprintk(1,
  1076. KERN_ERR
  1077. "%s: zoran_setup_videocodec() - no memory\n",
  1078. ZR_DEVNAME(zr));
  1079. return m;
  1080. }
  1081. /* magic and type are unused for master struct. Makes sense only at
  1082. codec structs.
  1083. In the past, .type were initialized to the old V4L1 .hardware
  1084. value, as VID_HARDWARE_ZR36067
  1085. */
  1086. m->magic = 0L;
  1087. m->type = 0;
  1088. m->flags = CODEC_FLAG_ENCODER | CODEC_FLAG_DECODER;
  1089. strncpy(m->name, ZR_DEVNAME(zr), sizeof(m->name));
  1090. m->data = zr;
  1091. switch (type)
  1092. {
  1093. case CODEC_TYPE_ZR36060:
  1094. m->readreg = zr36060_read;
  1095. m->writereg = zr36060_write;
  1096. m->flags |= CODEC_FLAG_JPEG | CODEC_FLAG_VFE;
  1097. break;
  1098. case CODEC_TYPE_ZR36050:
  1099. m->readreg = zr36050_read;
  1100. m->writereg = zr36050_write;
  1101. m->flags |= CODEC_FLAG_JPEG;
  1102. break;
  1103. case CODEC_TYPE_ZR36016:
  1104. m->readreg = zr36016_read;
  1105. m->writereg = zr36016_write;
  1106. m->flags |= CODEC_FLAG_VFE;
  1107. break;
  1108. }
  1109. return m;
  1110. }
  1111. /*
  1112. * Scan for a Buz card (actually for the PCI controller ZR36057),
  1113. * request the irq and map the io memory
  1114. */
  1115. static int __devinit
  1116. find_zr36057 (void)
  1117. {
  1118. unsigned char latency, need_latency;
  1119. struct zoran *zr;
  1120. struct pci_dev *dev = NULL;
  1121. int result;
  1122. struct videocodec_master *master_vfe = NULL;
  1123. struct videocodec_master *master_codec = NULL;
  1124. int card_num;
  1125. char *i2c_enc_name, *i2c_dec_name, *codec_name, *vfe_name;
  1126. zoran_num = 0;
  1127. while (zoran_num < BUZ_MAX &&
  1128. (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) {
  1129. card_num = card[zoran_num];
  1130. zr = kzalloc(sizeof(struct zoran), GFP_KERNEL);
  1131. if (!zr) {
  1132. dprintk(1,
  1133. KERN_ERR
  1134. "%s: find_zr36057() - kzalloc failed\n",
  1135. ZORAN_NAME);
  1136. continue;
  1137. }
  1138. zr->pci_dev = dev;
  1139. //zr->zr36057_mem = NULL;
  1140. zr->id = zoran_num;
  1141. snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
  1142. spin_lock_init(&zr->spinlock);
  1143. mutex_init(&zr->resource_lock);
  1144. if (pci_enable_device(dev))
  1145. goto zr_free_mem;
  1146. zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0);
  1147. pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION,
  1148. &zr->revision);
  1149. if (zr->revision < 2) {
  1150. dprintk(1,
  1151. KERN_INFO
  1152. "%s: Zoran ZR36057 (rev %d) irq: %d, memory: 0x%08x.\n",
  1153. ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
  1154. zr->zr36057_adr);
  1155. if (card_num == -1) {
  1156. dprintk(1,
  1157. KERN_ERR
  1158. "%s: find_zr36057() - no card specified, please use the card=X insmod option\n",
  1159. ZR_DEVNAME(zr));
  1160. goto zr_free_mem;
  1161. }
  1162. } else {
  1163. int i;
  1164. unsigned short ss_vendor, ss_device;
  1165. ss_vendor = zr->pci_dev->subsystem_vendor;
  1166. ss_device = zr->pci_dev->subsystem_device;
  1167. dprintk(1,
  1168. KERN_INFO
  1169. "%s: Zoran ZR36067 (rev %d) irq: %d, memory: 0x%08x\n",
  1170. ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
  1171. zr->zr36057_adr);
  1172. dprintk(1,
  1173. KERN_INFO
  1174. "%s: subsystem vendor=0x%04x id=0x%04x\n",
  1175. ZR_DEVNAME(zr), ss_vendor, ss_device);
  1176. if (card_num == -1) {
  1177. dprintk(3,
  1178. KERN_DEBUG
  1179. "%s: find_zr36057() - trying to autodetect card type\n",
  1180. ZR_DEVNAME(zr));
  1181. for (i=0;i<NUM_CARDS;i++) {
  1182. if (ss_vendor == zoran_cards[i].vendor_id &&
  1183. ss_device == zoran_cards[i].device_id) {
  1184. dprintk(3,
  1185. KERN_DEBUG
  1186. "%s: find_zr36057() - card %s detected\n",
  1187. ZR_DEVNAME(zr),
  1188. zoran_cards[i].name);
  1189. card_num = i;
  1190. break;
  1191. }
  1192. }
  1193. if (i == NUM_CARDS) {
  1194. dprintk(1,
  1195. KERN_ERR
  1196. "%s: find_zr36057() - unknown card\n",
  1197. ZR_DEVNAME(zr));
  1198. goto zr_free_mem;
  1199. }
  1200. }
  1201. }
  1202. if (card_num < 0 || card_num >= NUM_CARDS) {
  1203. dprintk(2,
  1204. KERN_ERR
  1205. "%s: find_zr36057() - invalid cardnum %d\n",
  1206. ZR_DEVNAME(zr), card_num);
  1207. goto zr_free_mem;
  1208. }
  1209. /* even though we make this a non pointer and thus
  1210. * theoretically allow for making changes to this struct
  1211. * on a per-individual card basis at runtime, this is
  1212. * strongly discouraged. This structure is intended to
  1213. * keep general card information, no settings or anything */
  1214. zr->card = zoran_cards[card_num];
  1215. snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)),
  1216. "%s[%u]", zr->card.name, zr->id);
  1217. zr->zr36057_mem = ioremap_nocache(zr->zr36057_adr, 0x1000);
  1218. if (!zr->zr36057_mem) {
  1219. dprintk(1,
  1220. KERN_ERR
  1221. "%s: find_zr36057() - ioremap failed\n",
  1222. ZR_DEVNAME(zr));
  1223. goto zr_free_mem;
  1224. }
  1225. result = request_irq(zr->pci_dev->irq,
  1226. zoran_irq,
  1227. IRQF_SHARED | IRQF_DISABLED,
  1228. ZR_DEVNAME(zr),
  1229. (void *) zr);
  1230. if (result < 0) {
  1231. if (result == -EINVAL) {
  1232. dprintk(1,
  1233. KERN_ERR
  1234. "%s: find_zr36057() - bad irq number or handler\n",
  1235. ZR_DEVNAME(zr));
  1236. } else if (result == -EBUSY) {
  1237. dprintk(1,
  1238. KERN_ERR
  1239. "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n",
  1240. ZR_DEVNAME(zr), zr->pci_dev->irq);
  1241. } else {
  1242. dprintk(1,
  1243. KERN_ERR
  1244. "%s: find_zr36057() - can't assign irq, error code %d\n",
  1245. ZR_DEVNAME(zr), result);
  1246. }
  1247. goto zr_unmap;
  1248. }
  1249. /* set PCI latency timer */
  1250. pci_read_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
  1251. &latency);
  1252. need_latency = zr->revision > 1 ? 32 : 48;
  1253. if (latency != need_latency) {
  1254. dprintk(2,
  1255. KERN_INFO
  1256. "%s: Changing PCI latency from %d to %d.\n",
  1257. ZR_DEVNAME(zr), latency, need_latency);
  1258. pci_write_config_byte(zr->pci_dev,
  1259. PCI_LATENCY_TIMER,
  1260. need_latency);
  1261. }
  1262. zr36057_restart(zr);
  1263. /* i2c */
  1264. dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n",
  1265. ZR_DEVNAME(zr));
  1266. /* i2c decoder */
  1267. if (decoder[zr->id] != -1) {
  1268. i2c_dec_name = i2cid_to_modulename(decoder[zr->id]);
  1269. zr->card.i2c_decoder = decoder[zr->id];
  1270. } else if (zr->card.i2c_decoder != 0) {
  1271. i2c_dec_name =
  1272. i2cid_to_modulename(zr->card.i2c_decoder);
  1273. } else {
  1274. i2c_dec_name = NULL;
  1275. }
  1276. if (i2c_dec_name) {
  1277. if ((result = request_module(i2c_dec_name)) < 0) {
  1278. dprintk(1,
  1279. KERN_ERR
  1280. "%s: failed to load module %s: %d\n",
  1281. ZR_DEVNAME(zr), i2c_dec_name, result);
  1282. }
  1283. }
  1284. /* i2c encoder */
  1285. if (encoder[zr->id] != -1) {
  1286. i2c_enc_name = i2cid_to_modulename(encoder[zr->id]);
  1287. zr->card.i2c_encoder = encoder[zr->id];
  1288. } else if (zr->card.i2c_encoder != 0) {
  1289. i2c_enc_name =
  1290. i2cid_to_modulename(zr->card.i2c_encoder);
  1291. } else {
  1292. i2c_enc_name = NULL;
  1293. }
  1294. if (i2c_enc_name) {
  1295. if ((result = request_module(i2c_enc_name)) < 0) {
  1296. dprintk(1,
  1297. KERN_ERR
  1298. "%s: failed to load module %s: %d\n",
  1299. ZR_DEVNAME(zr), i2c_enc_name, result);
  1300. }
  1301. }
  1302. if (zoran_register_i2c(zr) < 0) {
  1303. dprintk(1,
  1304. KERN_ERR
  1305. "%s: find_zr36057() - can't initialize i2c bus\n",
  1306. ZR_DEVNAME(zr));
  1307. goto zr_free_irq;
  1308. }
  1309. dprintk(2,
  1310. KERN_INFO "%s: Initializing videocodec bus...\n",
  1311. ZR_DEVNAME(zr));
  1312. if (zr->card.video_codec != 0 &&
  1313. (codec_name =
  1314. codecid_to_modulename(zr->card.video_codec)) != NULL) {
  1315. if ((result = request_module(codec_name)) < 0) {
  1316. dprintk(1,
  1317. KERN_ERR
  1318. "%s: failed to load modules %s: %d\n",
  1319. ZR_DEVNAME(zr), codec_name, result);
  1320. }
  1321. }
  1322. if (zr->card.video_vfe != 0 &&
  1323. (vfe_name =
  1324. codecid_to_modulename(zr->card.video_vfe)) != NULL) {
  1325. if ((result = request_module(vfe_name)) < 0) {
  1326. dprintk(1,
  1327. KERN_ERR
  1328. "%s: failed to load modules %s: %d\n",
  1329. ZR_DEVNAME(zr), vfe_name, result);
  1330. }
  1331. }
  1332. /* reset JPEG codec */
  1333. jpeg_codec_sleep(zr, 1);
  1334. jpeg_codec_reset(zr);
  1335. /* video bus enabled */
  1336. /* display codec revision */
  1337. if (zr->card.video_codec != 0) {
  1338. master_codec = zoran_setup_videocodec(zr,
  1339. zr->card.video_codec);
  1340. if (!master_codec)
  1341. goto zr_unreg_i2c;
  1342. zr->codec = videocodec_attach(master_codec);
  1343. if (!zr->codec) {
  1344. dprintk(1,
  1345. KERN_ERR
  1346. "%s: find_zr36057() - no codec found\n",
  1347. ZR_DEVNAME(zr));
  1348. goto zr_free_codec;
  1349. }
  1350. if (zr->codec->type != zr->card.video_codec) {
  1351. dprintk(1,
  1352. KERN_ERR
  1353. "%s: find_zr36057() - wrong codec\n",
  1354. ZR_DEVNAME(zr));
  1355. goto zr_detach_codec;
  1356. }
  1357. }
  1358. if (zr->card.video_vfe != 0) {
  1359. master_vfe = zoran_setup_videocodec(zr,
  1360. zr->card.video_vfe);
  1361. if (!master_vfe)
  1362. goto zr_detach_codec;
  1363. zr->vfe = videocodec_attach(master_vfe);
  1364. if (!zr->vfe) {
  1365. dprintk(1,
  1366. KERN_ERR
  1367. "%s: find_zr36057() - no VFE found\n",
  1368. ZR_DEVNAME(zr));
  1369. goto zr_free_vfe;
  1370. }
  1371. if (zr->vfe->type != zr->card.video_vfe) {
  1372. dprintk(1,
  1373. KERN_ERR
  1374. "%s: find_zr36057() = wrong VFE\n",
  1375. ZR_DEVNAME(zr));
  1376. goto zr_detach_vfe;
  1377. }
  1378. }
  1379. /* Success so keep the pci_dev referenced */
  1380. pci_dev_get(zr->pci_dev);
  1381. zoran[zoran_num++] = zr;
  1382. continue;
  1383. // Init errors
  1384. zr_detach_vfe:
  1385. videocodec_detach(zr->vfe);
  1386. zr_free_vfe:
  1387. kfree(master_vfe);
  1388. zr_detach_codec:
  1389. videocodec_detach(zr->codec);
  1390. zr_free_codec:
  1391. kfree(master_codec);
  1392. zr_unreg_i2c:
  1393. zoran_unregister_i2c(zr);
  1394. zr_free_irq:
  1395. btwrite(0, ZR36057_SPGPPCR);
  1396. free_irq(zr->pci_dev->irq, zr);
  1397. zr_unmap:
  1398. iounmap(zr->zr36057_mem);
  1399. zr_free_mem:
  1400. kfree(zr);
  1401. continue;
  1402. }
  1403. if (dev) /* Clean up ref count on early exit */
  1404. pci_dev_put(dev);
  1405. if (zoran_num == 0) {
  1406. dprintk(1, KERN_INFO "No known MJPEG cards found.\n");
  1407. }
  1408. return zoran_num;
  1409. }
  1410. static int __init
  1411. init_dc10_cards (void)
  1412. {
  1413. int i;
  1414. memset(zoran, 0, sizeof(zoran));
  1415. printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n",
  1416. MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION);
  1417. /* Look for cards */
  1418. if (find_zr36057() < 0) {
  1419. return -EIO;
  1420. }
  1421. if (zoran_num == 0)
  1422. return -ENODEV;
  1423. dprintk(1, KERN_INFO "%s: %d card(s) found\n", ZORAN_NAME,
  1424. zoran_num);
  1425. /* check the parameters we have been given, adjust if necessary */
  1426. if (v4l_nbufs < 2)
  1427. v4l_nbufs = 2;
  1428. if (v4l_nbufs > VIDEO_MAX_FRAME)
  1429. v4l_nbufs = VIDEO_MAX_FRAME;
  1430. /* The user specfies the in KB, we want them in byte
  1431. * (and page aligned) */
  1432. v4l_bufsize = PAGE_ALIGN(v4l_bufsize * 1024);
  1433. if (v4l_bufsize < 32768)
  1434. v4l_bufsize = 32768;
  1435. /* 2 MB is arbitrary but sufficient for the maximum possible images */
  1436. if (v4l_bufsize > 2048 * 1024)
  1437. v4l_bufsize = 2048 * 1024;
  1438. if (jpg_nbufs < 4)
  1439. jpg_nbufs = 4;
  1440. if (jpg_nbufs > BUZ_MAX_FRAME)
  1441. jpg_nbufs = BUZ_MAX_FRAME;
  1442. jpg_bufsize = PAGE_ALIGN(jpg_bufsize * 1024);
  1443. if (jpg_bufsize < 8192)
  1444. jpg_bufsize = 8192;
  1445. if (jpg_bufsize > (512 * 1024))
  1446. jpg_bufsize = 512 * 1024;
  1447. /* Use parameter for vidmem or try to find a video card */
  1448. if (vidmem) {
  1449. dprintk(1,
  1450. KERN_INFO
  1451. "%s: Using supplied video memory base address @ 0x%lx\n",
  1452. ZORAN_NAME, vidmem);
  1453. }
  1454. /* random nonsense */
  1455. dprintk(6, KERN_DEBUG "Jotti is een held!\n");
  1456. /* some mainboards might not do PCI-PCI data transfer well */
  1457. if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) {
  1458. dprintk(1,
  1459. KERN_WARNING
  1460. "%s: chipset does not support reliable PCI-PCI DMA\n",
  1461. ZORAN_NAME);
  1462. }
  1463. /* take care of Natoma chipset and a revision 1 zr36057 */
  1464. for (i = 0; i < zoran_num; i++) {
  1465. struct zoran *zr = zoran[i];
  1466. if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
  1467. zr->jpg_buffers.need_contiguous = 1;
  1468. dprintk(1,
  1469. KERN_INFO
  1470. "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
  1471. ZR_DEVNAME(zr));
  1472. }
  1473. if (zr36057_init(zr) < 0) {
  1474. for (i = 0; i < zoran_num; i++)
  1475. zoran_release(zoran[i]);
  1476. return -EIO;
  1477. }
  1478. zoran_proc_init(zr);
  1479. }
  1480. return 0;
  1481. }
  1482. static void __exit
  1483. unload_dc10_cards (void)
  1484. {
  1485. int i;
  1486. for (i = 0; i < zoran_num; i++)
  1487. zoran_release(zoran[i]);
  1488. }
  1489. module_init(init_dc10_cards);
  1490. module_exit(unload_dc10_cards);