zoran_card.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579
  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] = { [0 ... (BUZ_MAX-1)] = -1 };
  57. module_param_array(card, int, NULL, 0444);
  58. MODULE_PARM_DESC(card, "Card type");
  59. static int encoder[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 };
  60. module_param_array(encoder, int, NULL, 0444);
  61. MODULE_PARM_DESC(encoder, "Video encoder chip");
  62. static int decoder[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 };
  63. module_param_array(decoder, int, NULL, 0444);
  64. MODULE_PARM_DESC(decoder, "Video decoder chip");
  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] = { [0 ... (BUZ_MAX-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 = 4;
  107. int v4l_bufsize = 810; /* 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. #define ZR_DEVICE(subven, subdev, data) { \
  130. .vendor = PCI_VENDOR_ID_ZORAN, .device = PCI_DEVICE_ID_ZORAN_36057, \
  131. .subvendor = (subven), .subdevice = (subdev), .driver_data = (data) }
  132. static struct pci_device_id zr36067_pci_tbl[] = {
  133. ZR_DEVICE(PCI_VENDOR_ID_MIRO, PCI_DEVICE_ID_MIRO_DC10PLUS, DC10plus),
  134. ZR_DEVICE(PCI_VENDOR_ID_MIRO, PCI_DEVICE_ID_MIRO_DC30PLUS, DC30plus),
  135. ZR_DEVICE(PCI_VENDOR_ID_ELECTRONICDESIGNGMBH, PCI_DEVICE_ID_LML_33R10, LML33R10),
  136. ZR_DEVICE(PCI_VENDOR_ID_IOMEGA, PCI_DEVICE_ID_IOMEGA_BUZ, BUZ),
  137. ZR_DEVICE(PCI_ANY_ID, PCI_ANY_ID, NUM_CARDS),
  138. {0}
  139. };
  140. MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
  141. static unsigned int zoran_num; /* number of cards found */
  142. /* videocodec bus functions ZR36060 */
  143. static u32
  144. zr36060_read (struct videocodec *codec,
  145. u16 reg)
  146. {
  147. struct zoran *zr = (struct zoran *) codec->master_data->data;
  148. __u32 data;
  149. if (post_office_wait(zr)
  150. || post_office_write(zr, 0, 1, reg >> 8)
  151. || post_office_write(zr, 0, 2, reg & 0xff)) {
  152. return -1;
  153. }
  154. data = post_office_read(zr, 0, 3) & 0xff;
  155. return data;
  156. }
  157. static void
  158. zr36060_write (struct videocodec *codec,
  159. u16 reg,
  160. u32 val)
  161. {
  162. struct zoran *zr = (struct zoran *) codec->master_data->data;
  163. if (post_office_wait(zr)
  164. || post_office_write(zr, 0, 1, reg >> 8)
  165. || post_office_write(zr, 0, 2, reg & 0xff)) {
  166. return;
  167. }
  168. post_office_write(zr, 0, 3, val & 0xff);
  169. }
  170. /* videocodec bus functions ZR36050 */
  171. static u32
  172. zr36050_read (struct videocodec *codec,
  173. u16 reg)
  174. {
  175. struct zoran *zr = (struct zoran *) codec->master_data->data;
  176. __u32 data;
  177. if (post_office_wait(zr)
  178. || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
  179. return -1;
  180. }
  181. data = post_office_read(zr, 0, reg & 0x03) & 0xff; // reg. LOWBYTES + read
  182. return data;
  183. }
  184. static void
  185. zr36050_write (struct videocodec *codec,
  186. u16 reg,
  187. u32 val)
  188. {
  189. struct zoran *zr = (struct zoran *) codec->master_data->data;
  190. if (post_office_wait(zr)
  191. || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
  192. return;
  193. }
  194. post_office_write(zr, 0, reg & 0x03, val & 0xff); // reg. LOWBYTES + wr. data
  195. }
  196. /* videocodec bus functions ZR36016 */
  197. static u32
  198. zr36016_read (struct videocodec *codec,
  199. u16 reg)
  200. {
  201. struct zoran *zr = (struct zoran *) codec->master_data->data;
  202. __u32 data;
  203. if (post_office_wait(zr)) {
  204. return -1;
  205. }
  206. data = post_office_read(zr, 2, reg & 0x03) & 0xff; // read
  207. return data;
  208. }
  209. /* hack for in zoran_device.c */
  210. void
  211. zr36016_write (struct videocodec *codec,
  212. u16 reg,
  213. u32 val)
  214. {
  215. struct zoran *zr = (struct zoran *) codec->master_data->data;
  216. if (post_office_wait(zr)) {
  217. return;
  218. }
  219. post_office_write(zr, 2, reg & 0x03, val & 0x0ff); // wr. data
  220. }
  221. /*
  222. * Board specific information
  223. */
  224. static void
  225. dc10_init (struct zoran *zr)
  226. {
  227. dprintk(3, KERN_DEBUG "%s: dc10_init()\n", ZR_DEVNAME(zr));
  228. /* Pixel clock selection */
  229. GPIO(zr, 4, 0);
  230. GPIO(zr, 5, 1);
  231. /* Enable the video bus sync signals */
  232. GPIO(zr, 7, 0);
  233. }
  234. static void
  235. dc10plus_init (struct zoran *zr)
  236. {
  237. dprintk(3, KERN_DEBUG "%s: dc10plus_init()\n", ZR_DEVNAME(zr));
  238. }
  239. static void
  240. buz_init (struct zoran *zr)
  241. {
  242. dprintk(3, KERN_DEBUG "%s: buz_init()\n", ZR_DEVNAME(zr));
  243. /* some stuff from Iomega */
  244. pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15);
  245. pci_write_config_dword(zr->pci_dev, 0x0c, 0x00012020);
  246. pci_write_config_dword(zr->pci_dev, 0xe8, 0xc0200000);
  247. }
  248. static void
  249. lml33_init (struct zoran *zr)
  250. {
  251. dprintk(3, KERN_DEBUG "%s: lml33_init()\n", ZR_DEVNAME(zr));
  252. GPIO(zr, 2, 1); // Set Composite input/output
  253. }
  254. static void
  255. avs6eyes_init (struct zoran *zr)
  256. {
  257. // AverMedia 6-Eyes original driver by Christer Weinigel
  258. // Lifted straight from Christer's old driver and
  259. // modified slightly by Martin Samuelsson.
  260. int mux = default_mux; /* 1 = BT866, 7 = VID1 */
  261. GPIO(zr, 4, 1); /* Bt866 SLEEP on */
  262. udelay(2);
  263. GPIO(zr, 0, 1); /* ZR36060 /RESET on */
  264. GPIO(zr, 1, 0); /* ZR36060 /SLEEP on */
  265. GPIO(zr, 2, mux & 1); /* MUX S0 */
  266. GPIO(zr, 3, 0); /* /FRAME on */
  267. GPIO(zr, 4, 0); /* Bt866 SLEEP off */
  268. GPIO(zr, 5, mux & 2); /* MUX S1 */
  269. GPIO(zr, 6, 0); /* ? */
  270. GPIO(zr, 7, mux & 4); /* MUX S2 */
  271. }
  272. static char *
  273. codecid_to_modulename (u16 codecid)
  274. {
  275. char *name = NULL;
  276. switch (codecid) {
  277. case CODEC_TYPE_ZR36060:
  278. name = "zr36060";
  279. break;
  280. case CODEC_TYPE_ZR36050:
  281. name = "zr36050";
  282. break;
  283. case CODEC_TYPE_ZR36016:
  284. name = "zr36016";
  285. break;
  286. }
  287. return name;
  288. }
  289. // struct tvnorm {
  290. // u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
  291. // };
  292. static struct tvnorm f50sqpixel = { 944, 768, 83, 880, 625, 576, 16 };
  293. static struct tvnorm f60sqpixel = { 780, 640, 51, 716, 525, 480, 12 };
  294. static struct tvnorm f50ccir601 = { 864, 720, 75, 804, 625, 576, 18 };
  295. static struct tvnorm f60ccir601 = { 858, 720, 57, 788, 525, 480, 16 };
  296. static struct tvnorm f50ccir601_lml33 = { 864, 720, 75+34, 804, 625, 576, 18 };
  297. static struct tvnorm f60ccir601_lml33 = { 858, 720, 57+34, 788, 525, 480, 16 };
  298. /* The DC10 (57/16/50) uses VActive as HSync, so HStart must be 0 */
  299. static struct tvnorm f50sqpixel_dc10 = { 944, 768, 0, 880, 625, 576, 0 };
  300. static struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 };
  301. /* FIXME: I cannot swap U and V in saa7114, so i do one
  302. * pixel left shift in zoran (75 -> 74)
  303. * (Maxim Yevtyushkin <max@linuxmedialabs.com>) */
  304. static struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74+54, 804, 625, 576, 18 };
  305. static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 };
  306. /* FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I
  307. * copy Maxim's left shift hack for the 6 Eyes.
  308. *
  309. * Christer's driver used the unshifted norms, though...
  310. * /Sam */
  311. static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
  312. static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
  313. static const unsigned short vpx3220_addrs[] = { 0x43, 0x47, I2C_CLIENT_END };
  314. static const unsigned short saa7110_addrs[] = { 0x4e, 0x4f, I2C_CLIENT_END };
  315. static const unsigned short saa7111_addrs[] = { 0x25, 0x24, I2C_CLIENT_END };
  316. static const unsigned short saa7114_addrs[] = { 0x21, 0x20, I2C_CLIENT_END };
  317. static const unsigned short adv717x_addrs[] = { 0x6a, 0x6b, 0x2a, 0x2b, I2C_CLIENT_END };
  318. static const unsigned short ks0127_addrs[] = { 0x6c, 0x6d, I2C_CLIENT_END };
  319. static const unsigned short saa7185_addrs[] = { 0x44, I2C_CLIENT_END };
  320. static const unsigned short bt819_addrs[] = { 0x45, I2C_CLIENT_END };
  321. static const unsigned short bt856_addrs[] = { 0x44, I2C_CLIENT_END };
  322. static const unsigned short bt866_addrs[] = { 0x44, I2C_CLIENT_END };
  323. static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
  324. {
  325. .type = DC10_old,
  326. .name = "DC10(old)",
  327. .i2c_decoder = "vpx3220a",
  328. .mod_decoder = "vpx3220",
  329. .addrs_decoder = vpx3220_addrs,
  330. .video_codec = CODEC_TYPE_ZR36050,
  331. .video_vfe = CODEC_TYPE_ZR36016,
  332. .inputs = 3,
  333. .input = {
  334. { 1, "Composite" },
  335. { 2, "S-Video" },
  336. { 0, "Internal/comp" }
  337. },
  338. .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
  339. .tvn = {
  340. &f50sqpixel_dc10,
  341. &f60sqpixel_dc10,
  342. &f50sqpixel_dc10
  343. },
  344. .jpeg_int = 0,
  345. .vsync_int = ZR36057_ISR_GIRQ1,
  346. .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
  347. .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
  348. .gpcs = { -1, 0 },
  349. .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  350. .gws_not_connected = 0,
  351. .input_mux = 0,
  352. .init = &dc10_init,
  353. }, {
  354. .type = DC10_new,
  355. .name = "DC10(new)",
  356. .i2c_decoder = "saa7110",
  357. .mod_decoder = "saa7110",
  358. .addrs_decoder = saa7110_addrs,
  359. .i2c_encoder = "adv7175",
  360. .mod_encoder = "adv7175",
  361. .addrs_encoder = adv717x_addrs,
  362. .video_codec = CODEC_TYPE_ZR36060,
  363. .inputs = 3,
  364. .input = {
  365. { 0, "Composite" },
  366. { 7, "S-Video" },
  367. { 5, "Internal/comp" }
  368. },
  369. .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
  370. .tvn = {
  371. &f50sqpixel,
  372. &f60sqpixel,
  373. &f50sqpixel},
  374. .jpeg_int = ZR36057_ISR_GIRQ0,
  375. .vsync_int = ZR36057_ISR_GIRQ1,
  376. .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
  377. .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  378. .gpcs = { -1, 1},
  379. .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
  380. .gws_not_connected = 0,
  381. .input_mux = 0,
  382. .init = &dc10plus_init,
  383. }, {
  384. .type = DC10plus,
  385. .name = "DC10plus",
  386. .i2c_decoder = "saa7110",
  387. .mod_decoder = "saa7110",
  388. .addrs_decoder = saa7110_addrs,
  389. .i2c_encoder = "adv7175",
  390. .mod_encoder = "adv7175",
  391. .addrs_encoder = adv717x_addrs,
  392. .video_codec = CODEC_TYPE_ZR36060,
  393. .inputs = 3,
  394. .input = {
  395. { 0, "Composite" },
  396. { 7, "S-Video" },
  397. { 5, "Internal/comp" }
  398. },
  399. .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
  400. .tvn = {
  401. &f50sqpixel,
  402. &f60sqpixel,
  403. &f50sqpixel
  404. },
  405. .jpeg_int = ZR36057_ISR_GIRQ0,
  406. .vsync_int = ZR36057_ISR_GIRQ1,
  407. .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
  408. .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  409. .gpcs = { -1, 1 },
  410. .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
  411. .gws_not_connected = 0,
  412. .input_mux = 0,
  413. .init = &dc10plus_init,
  414. }, {
  415. .type = DC30,
  416. .name = "DC30",
  417. .i2c_decoder = "vpx3220a",
  418. .mod_decoder = "vpx3220",
  419. .addrs_decoder = vpx3220_addrs,
  420. .i2c_encoder = "adv7175",
  421. .mod_encoder = "adv7175",
  422. .addrs_encoder = adv717x_addrs,
  423. .video_codec = CODEC_TYPE_ZR36050,
  424. .video_vfe = CODEC_TYPE_ZR36016,
  425. .inputs = 3,
  426. .input = {
  427. { 1, "Composite" },
  428. { 2, "S-Video" },
  429. { 0, "Internal/comp" }
  430. },
  431. .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
  432. .tvn = {
  433. &f50sqpixel_dc10,
  434. &f60sqpixel_dc10,
  435. &f50sqpixel_dc10
  436. },
  437. .jpeg_int = 0,
  438. .vsync_int = ZR36057_ISR_GIRQ1,
  439. .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
  440. .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
  441. .gpcs = { -1, 0 },
  442. .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  443. .gws_not_connected = 0,
  444. .input_mux = 0,
  445. .init = &dc10_init,
  446. }, {
  447. .type = DC30plus,
  448. .name = "DC30plus",
  449. .i2c_decoder = "vpx3220a",
  450. .mod_decoder = "vpx3220",
  451. .addrs_decoder = vpx3220_addrs,
  452. .i2c_encoder = "adv7175",
  453. .mod_encoder = "adv7175",
  454. .addrs_encoder = adv717x_addrs,
  455. .video_codec = CODEC_TYPE_ZR36050,
  456. .video_vfe = CODEC_TYPE_ZR36016,
  457. .inputs = 3,
  458. .input = {
  459. { 1, "Composite" },
  460. { 2, "S-Video" },
  461. { 0, "Internal/comp" }
  462. },
  463. .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
  464. .tvn = {
  465. &f50sqpixel_dc10,
  466. &f60sqpixel_dc10,
  467. &f50sqpixel_dc10
  468. },
  469. .jpeg_int = 0,
  470. .vsync_int = ZR36057_ISR_GIRQ1,
  471. .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
  472. .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
  473. .gpcs = { -1, 0 },
  474. .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  475. .gws_not_connected = 0,
  476. .input_mux = 0,
  477. .init = &dc10_init,
  478. }, {
  479. .type = LML33,
  480. .name = "LML33",
  481. .i2c_decoder = "bt819a",
  482. .mod_decoder = "bt819",
  483. .addrs_decoder = bt819_addrs,
  484. .i2c_encoder = "bt856",
  485. .mod_encoder = "bt856",
  486. .addrs_encoder = bt856_addrs,
  487. .video_codec = CODEC_TYPE_ZR36060,
  488. .inputs = 2,
  489. .input = {
  490. { 0, "Composite" },
  491. { 7, "S-Video" }
  492. },
  493. .norms = V4L2_STD_NTSC|V4L2_STD_PAL,
  494. .tvn = {
  495. &f50ccir601_lml33,
  496. &f60ccir601_lml33,
  497. NULL
  498. },
  499. .jpeg_int = ZR36057_ISR_GIRQ1,
  500. .vsync_int = ZR36057_ISR_GIRQ0,
  501. .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
  502. .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
  503. .gpcs = { 3, 1 },
  504. .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
  505. .gws_not_connected = 1,
  506. .input_mux = 0,
  507. .init = &lml33_init,
  508. }, {
  509. .type = LML33R10,
  510. .name = "LML33R10",
  511. .i2c_decoder = "saa7114",
  512. .mod_decoder = "saa7115",
  513. .addrs_decoder = saa7114_addrs,
  514. .i2c_encoder = "adv7170",
  515. .mod_encoder = "adv7170",
  516. .addrs_encoder = adv717x_addrs,
  517. .video_codec = CODEC_TYPE_ZR36060,
  518. .inputs = 2,
  519. .input = {
  520. { 0, "Composite" },
  521. { 7, "S-Video" }
  522. },
  523. .norms = V4L2_STD_NTSC|V4L2_STD_PAL,
  524. .tvn = {
  525. &f50ccir601_lm33r10,
  526. &f60ccir601_lm33r10,
  527. NULL
  528. },
  529. .jpeg_int = ZR36057_ISR_GIRQ1,
  530. .vsync_int = ZR36057_ISR_GIRQ0,
  531. .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
  532. .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
  533. .gpcs = { 3, 1 },
  534. .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
  535. .gws_not_connected = 1,
  536. .input_mux = 0,
  537. .init = &lml33_init,
  538. }, {
  539. .type = BUZ,
  540. .name = "Buz",
  541. .i2c_decoder = "saa7111",
  542. .mod_decoder = "saa7115",
  543. .addrs_decoder = saa7111_addrs,
  544. .i2c_encoder = "saa7185",
  545. .mod_encoder = "saa7185",
  546. .addrs_encoder = saa7185_addrs,
  547. .video_codec = CODEC_TYPE_ZR36060,
  548. .inputs = 2,
  549. .input = {
  550. { 3, "Composite" },
  551. { 7, "S-Video" }
  552. },
  553. .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
  554. .tvn = {
  555. &f50ccir601,
  556. &f60ccir601,
  557. &f50ccir601
  558. },
  559. .jpeg_int = ZR36057_ISR_GIRQ1,
  560. .vsync_int = ZR36057_ISR_GIRQ0,
  561. .gpio = { 1, -1, 3, -1, -1, -1, -1, -1 },
  562. .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
  563. .gpcs = { 3, 1 },
  564. .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
  565. .gws_not_connected = 1,
  566. .input_mux = 0,
  567. .init = &buz_init,
  568. }, {
  569. .type = AVS6EYES,
  570. .name = "6-Eyes",
  571. /* AverMedia chose not to brand the 6-Eyes. Thus it
  572. can't be autodetected, and requires card=x. */
  573. .i2c_decoder = "ks0127",
  574. .mod_decoder = "ks0127",
  575. .addrs_decoder = ks0127_addrs,
  576. .i2c_encoder = "bt866",
  577. .mod_encoder = "bt866",
  578. .addrs_encoder = bt866_addrs,
  579. .video_codec = CODEC_TYPE_ZR36060,
  580. .inputs = 10,
  581. .input = {
  582. { 0, "Composite 1" },
  583. { 1, "Composite 2" },
  584. { 2, "Composite 3" },
  585. { 4, "Composite 4" },
  586. { 5, "Composite 5" },
  587. { 6, "Composite 6" },
  588. { 8, "S-Video 1" },
  589. { 9, "S-Video 2" },
  590. {10, "S-Video 3" },
  591. {15, "YCbCr" }
  592. },
  593. .norms = V4L2_STD_NTSC|V4L2_STD_PAL,
  594. .tvn = {
  595. &f50ccir601_avs6eyes,
  596. &f60ccir601_avs6eyes,
  597. NULL
  598. },
  599. .jpeg_int = ZR36057_ISR_GIRQ1,
  600. .vsync_int = ZR36057_ISR_GIRQ0,
  601. .gpio = { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
  602. .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
  603. .gpcs = { 3, 1 }, // Validity unknown /Sam
  604. .vfe_pol = { 1, 0, 0, 0, 0, 1, 0, 0 }, // Validity unknown /Sam
  605. .gws_not_connected = 1,
  606. .input_mux = 1,
  607. .init = &avs6eyes_init,
  608. }
  609. };
  610. /*
  611. * I2C functions
  612. */
  613. /* software I2C functions */
  614. static int
  615. zoran_i2c_getsda (void *data)
  616. {
  617. struct zoran *zr = (struct zoran *) data;
  618. return (btread(ZR36057_I2CBR) >> 1) & 1;
  619. }
  620. static int
  621. zoran_i2c_getscl (void *data)
  622. {
  623. struct zoran *zr = (struct zoran *) data;
  624. return btread(ZR36057_I2CBR) & 1;
  625. }
  626. static void
  627. zoran_i2c_setsda (void *data,
  628. int state)
  629. {
  630. struct zoran *zr = (struct zoran *) data;
  631. if (state)
  632. zr->i2cbr |= 2;
  633. else
  634. zr->i2cbr &= ~2;
  635. btwrite(zr->i2cbr, ZR36057_I2CBR);
  636. }
  637. static void
  638. zoran_i2c_setscl (void *data,
  639. int state)
  640. {
  641. struct zoran *zr = (struct zoran *) data;
  642. if (state)
  643. zr->i2cbr |= 1;
  644. else
  645. zr->i2cbr &= ~1;
  646. btwrite(zr->i2cbr, ZR36057_I2CBR);
  647. }
  648. static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
  649. .setsda = zoran_i2c_setsda,
  650. .setscl = zoran_i2c_setscl,
  651. .getsda = zoran_i2c_getsda,
  652. .getscl = zoran_i2c_getscl,
  653. .udelay = 10,
  654. .timeout = 100,
  655. };
  656. static int
  657. zoran_register_i2c (struct zoran *zr)
  658. {
  659. memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template,
  660. sizeof(struct i2c_algo_bit_data));
  661. zr->i2c_algo.data = zr;
  662. zr->i2c_adapter.id = I2C_HW_B_ZR36067;
  663. strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr),
  664. sizeof(zr->i2c_adapter.name));
  665. i2c_set_adapdata(&zr->i2c_adapter, &zr->v4l2_dev);
  666. zr->i2c_adapter.algo_data = &zr->i2c_algo;
  667. zr->i2c_adapter.dev.parent = &zr->pci_dev->dev;
  668. return i2c_bit_add_bus(&zr->i2c_adapter);
  669. }
  670. static void
  671. zoran_unregister_i2c (struct zoran *zr)
  672. {
  673. i2c_del_adapter(&zr->i2c_adapter);
  674. }
  675. /* Check a zoran_params struct for correctness, insert default params */
  676. int
  677. zoran_check_jpg_settings (struct zoran *zr,
  678. struct zoran_jpg_settings *settings,
  679. int try)
  680. {
  681. int err = 0, err0 = 0;
  682. dprintk(4,
  683. KERN_DEBUG
  684. "%s: check_jpg_settings() - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
  685. ZR_DEVNAME(zr), settings->decimation, settings->HorDcm,
  686. settings->VerDcm, settings->TmpDcm);
  687. dprintk(4,
  688. KERN_DEBUG
  689. "%s: check_jpg_settings() - x: %d, y: %d, w: %d, y: %d\n",
  690. ZR_DEVNAME(zr), settings->img_x, settings->img_y,
  691. settings->img_width, settings->img_height);
  692. /* Check decimation, set default values for decimation = 1, 2, 4 */
  693. switch (settings->decimation) {
  694. case 1:
  695. settings->HorDcm = 1;
  696. settings->VerDcm = 1;
  697. settings->TmpDcm = 1;
  698. settings->field_per_buff = 2;
  699. settings->img_x = 0;
  700. settings->img_y = 0;
  701. settings->img_width = BUZ_MAX_WIDTH;
  702. settings->img_height = BUZ_MAX_HEIGHT / 2;
  703. break;
  704. case 2:
  705. settings->HorDcm = 2;
  706. settings->VerDcm = 1;
  707. settings->TmpDcm = 2;
  708. settings->field_per_buff = 1;
  709. settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
  710. settings->img_y = 0;
  711. settings->img_width =
  712. (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
  713. settings->img_height = BUZ_MAX_HEIGHT / 2;
  714. break;
  715. case 4:
  716. if (zr->card.type == DC10_new) {
  717. dprintk(1,
  718. KERN_DEBUG
  719. "%s: check_jpg_settings() - HDec by 4 is not supported on the DC10\n",
  720. ZR_DEVNAME(zr));
  721. err0++;
  722. break;
  723. }
  724. settings->HorDcm = 4;
  725. settings->VerDcm = 2;
  726. settings->TmpDcm = 2;
  727. settings->field_per_buff = 1;
  728. settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
  729. settings->img_y = 0;
  730. settings->img_width =
  731. (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
  732. settings->img_height = BUZ_MAX_HEIGHT / 2;
  733. break;
  734. case 0:
  735. /* We have to check the data the user has set */
  736. if (settings->HorDcm != 1 && settings->HorDcm != 2 &&
  737. (zr->card.type == DC10_new || settings->HorDcm != 4)) {
  738. settings->HorDcm = clamp(settings->HorDcm, 1, 2);
  739. err0++;
  740. }
  741. if (settings->VerDcm != 1 && settings->VerDcm != 2) {
  742. settings->VerDcm = clamp(settings->VerDcm, 1, 2);
  743. err0++;
  744. }
  745. if (settings->TmpDcm != 1 && settings->TmpDcm != 2) {
  746. settings->TmpDcm = clamp(settings->TmpDcm, 1, 2);
  747. err0++;
  748. }
  749. if (settings->field_per_buff != 1 &&
  750. settings->field_per_buff != 2) {
  751. settings->field_per_buff = clamp(settings->field_per_buff, 1, 2);
  752. err0++;
  753. }
  754. if (settings->img_x < 0) {
  755. settings->img_x = 0;
  756. err0++;
  757. }
  758. if (settings->img_y < 0) {
  759. settings->img_y = 0;
  760. err0++;
  761. }
  762. if (settings->img_width < 0 || settings->img_width > BUZ_MAX_WIDTH) {
  763. settings->img_width = clamp(settings->img_width, 0, (int)BUZ_MAX_WIDTH);
  764. err0++;
  765. }
  766. if (settings->img_height < 0 || settings->img_height > BUZ_MAX_HEIGHT / 2) {
  767. settings->img_height = clamp(settings->img_height, 0, BUZ_MAX_HEIGHT / 2);
  768. err0++;
  769. }
  770. if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) {
  771. settings->img_x = BUZ_MAX_WIDTH - settings->img_width;
  772. err0++;
  773. }
  774. if (settings->img_y + settings->img_height > BUZ_MAX_HEIGHT / 2) {
  775. settings->img_y = BUZ_MAX_HEIGHT / 2 - settings->img_height;
  776. err0++;
  777. }
  778. if (settings->img_width % (16 * settings->HorDcm) != 0) {
  779. settings->img_width -= settings->img_width % (16 * settings->HorDcm);
  780. if (settings->img_width == 0)
  781. settings->img_width = 16 * settings->HorDcm;
  782. err0++;
  783. }
  784. if (settings->img_height % (8 * settings->VerDcm) != 0) {
  785. settings->img_height -= settings->img_height % (8 * settings->VerDcm);
  786. if (settings->img_height == 0)
  787. settings->img_height = 8 * settings->VerDcm;
  788. err0++;
  789. }
  790. if (!try && err0) {
  791. dprintk(1,
  792. KERN_ERR
  793. "%s: check_jpg_settings() - error in params for decimation = 0\n",
  794. ZR_DEVNAME(zr));
  795. err++;
  796. }
  797. break;
  798. default:
  799. dprintk(1,
  800. KERN_ERR
  801. "%s: check_jpg_settings() - decimation = %d, must be 0, 1, 2 or 4\n",
  802. ZR_DEVNAME(zr), settings->decimation);
  803. err++;
  804. break;
  805. }
  806. if (settings->jpg_comp.quality > 100)
  807. settings->jpg_comp.quality = 100;
  808. if (settings->jpg_comp.quality < 5)
  809. settings->jpg_comp.quality = 5;
  810. if (settings->jpg_comp.APPn < 0)
  811. settings->jpg_comp.APPn = 0;
  812. if (settings->jpg_comp.APPn > 15)
  813. settings->jpg_comp.APPn = 15;
  814. if (settings->jpg_comp.APP_len < 0)
  815. settings->jpg_comp.APP_len = 0;
  816. if (settings->jpg_comp.APP_len > 60)
  817. settings->jpg_comp.APP_len = 60;
  818. if (settings->jpg_comp.COM_len < 0)
  819. settings->jpg_comp.COM_len = 0;
  820. if (settings->jpg_comp.COM_len > 60)
  821. settings->jpg_comp.COM_len = 60;
  822. if (err)
  823. return -EINVAL;
  824. return 0;
  825. }
  826. void
  827. zoran_open_init_params (struct zoran *zr)
  828. {
  829. int i;
  830. /* User must explicitly set a window */
  831. zr->overlay_settings.is_set = 0;
  832. zr->overlay_mask = NULL;
  833. zr->overlay_active = ZORAN_FREE;
  834. zr->v4l_memgrab_active = 0;
  835. zr->v4l_overlay_active = 0;
  836. zr->v4l_grab_frame = NO_GRAB_ACTIVE;
  837. zr->v4l_grab_seq = 0;
  838. zr->v4l_settings.width = 192;
  839. zr->v4l_settings.height = 144;
  840. zr->v4l_settings.format = &zoran_formats[7]; /* YUY2 - YUV-4:2:2 packed */
  841. zr->v4l_settings.bytesperline =
  842. zr->v4l_settings.width *
  843. ((zr->v4l_settings.format->depth + 7) / 8);
  844. /* DMA ring stuff for V4L */
  845. zr->v4l_pend_tail = 0;
  846. zr->v4l_pend_head = 0;
  847. zr->v4l_sync_tail = 0;
  848. zr->v4l_buffers.active = ZORAN_FREE;
  849. for (i = 0; i < VIDEO_MAX_FRAME; i++) {
  850. zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
  851. }
  852. zr->v4l_buffers.allocated = 0;
  853. for (i = 0; i < BUZ_MAX_FRAME; i++) {
  854. zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
  855. }
  856. zr->jpg_buffers.active = ZORAN_FREE;
  857. zr->jpg_buffers.allocated = 0;
  858. /* Set necessary params and call zoran_check_jpg_settings to set the defaults */
  859. zr->jpg_settings.decimation = 1;
  860. zr->jpg_settings.jpg_comp.quality = 50; /* default compression factor 8 */
  861. if (zr->card.type != BUZ)
  862. zr->jpg_settings.odd_even = 1;
  863. else
  864. zr->jpg_settings.odd_even = 0;
  865. zr->jpg_settings.jpg_comp.APPn = 0;
  866. zr->jpg_settings.jpg_comp.APP_len = 0; /* No APPn marker */
  867. memset(zr->jpg_settings.jpg_comp.APP_data, 0,
  868. sizeof(zr->jpg_settings.jpg_comp.APP_data));
  869. zr->jpg_settings.jpg_comp.COM_len = 0; /* No COM marker */
  870. memset(zr->jpg_settings.jpg_comp.COM_data, 0,
  871. sizeof(zr->jpg_settings.jpg_comp.COM_data));
  872. zr->jpg_settings.jpg_comp.jpeg_markers =
  873. JPEG_MARKER_DHT | JPEG_MARKER_DQT;
  874. i = zoran_check_jpg_settings(zr, &zr->jpg_settings, 0);
  875. if (i)
  876. dprintk(1,
  877. KERN_ERR
  878. "%s: zoran_open_init_params() internal error\n",
  879. ZR_DEVNAME(zr));
  880. clear_interrupt_counters(zr);
  881. zr->testing = 0;
  882. }
  883. static void __devinit
  884. test_interrupts (struct zoran *zr)
  885. {
  886. DEFINE_WAIT(wait);
  887. int timeout, icr;
  888. clear_interrupt_counters(zr);
  889. zr->testing = 1;
  890. icr = btread(ZR36057_ICR);
  891. btwrite(0x78000000 | ZR36057_ICR_IntPinEn, ZR36057_ICR);
  892. prepare_to_wait(&zr->test_q, &wait, TASK_INTERRUPTIBLE);
  893. timeout = schedule_timeout(HZ);
  894. finish_wait(&zr->test_q, &wait);
  895. btwrite(0, ZR36057_ICR);
  896. btwrite(0x78000000, ZR36057_ISR);
  897. zr->testing = 0;
  898. dprintk(5, KERN_INFO "%s: Testing interrupts...\n", ZR_DEVNAME(zr));
  899. if (timeout) {
  900. dprintk(1, ": time spent: %d\n", 1 * HZ - timeout);
  901. }
  902. if (zr36067_debug > 1)
  903. print_interrupts(zr);
  904. btwrite(icr, ZR36057_ICR);
  905. }
  906. static int __devinit
  907. zr36057_init (struct zoran *zr)
  908. {
  909. int j, err;
  910. dprintk(1,
  911. KERN_INFO
  912. "%s: zr36057_init() - initializing card[%d], zr=%p\n",
  913. ZR_DEVNAME(zr), zr->id, zr);
  914. /* default setup of all parameters which will persist between opens */
  915. zr->user = 0;
  916. init_waitqueue_head(&zr->v4l_capq);
  917. init_waitqueue_head(&zr->jpg_capq);
  918. init_waitqueue_head(&zr->test_q);
  919. zr->jpg_buffers.allocated = 0;
  920. zr->v4l_buffers.allocated = 0;
  921. zr->buffer.base = (void *) vidmem;
  922. zr->buffer.width = 0;
  923. zr->buffer.height = 0;
  924. zr->buffer.depth = 0;
  925. zr->buffer.bytesperline = 0;
  926. /* Avoid nonsense settings from user for default input/norm */
  927. if (default_norm < VIDEO_MODE_PAL &&
  928. default_norm > VIDEO_MODE_SECAM)
  929. default_norm = VIDEO_MODE_PAL;
  930. if (default_norm == VIDEO_MODE_PAL) {
  931. zr->norm = V4L2_STD_PAL;
  932. zr->timing = zr->card.tvn[0];
  933. } else if (default_norm == VIDEO_MODE_NTSC) {
  934. zr->norm = V4L2_STD_NTSC;
  935. zr->timing = zr->card.tvn[1];
  936. } else {
  937. zr->norm = V4L2_STD_SECAM;
  938. zr->timing = zr->card.tvn[2];
  939. }
  940. if (zr->timing == NULL) {
  941. dprintk(1,
  942. KERN_WARNING
  943. "%s: zr36057_init() - default TV standard not supported by hardware. PAL will be used.\n",
  944. ZR_DEVNAME(zr));
  945. zr->norm = V4L2_STD_PAL;
  946. zr->timing = zr->card.tvn[0];
  947. }
  948. if (default_input > zr->card.inputs-1) {
  949. dprintk(1,
  950. KERN_WARNING
  951. "%s: default_input value %d out of range (0-%d)\n",
  952. ZR_DEVNAME(zr), default_input, zr->card.inputs-1);
  953. default_input = 0;
  954. }
  955. zr->input = default_input;
  956. /* default setup (will be repeated at every open) */
  957. zoran_open_init_params(zr);
  958. /* allocate memory *before* doing anything to the hardware
  959. * in case allocation fails */
  960. zr->stat_com = kzalloc(BUZ_NUM_STAT_COM * 4, GFP_KERNEL);
  961. zr->video_dev = kmalloc(sizeof(struct video_device), GFP_KERNEL);
  962. if (!zr->stat_com || !zr->video_dev) {
  963. dprintk(1,
  964. KERN_ERR
  965. "%s: zr36057_init() - kmalloc (STAT_COM) failed\n",
  966. ZR_DEVNAME(zr));
  967. err = -ENOMEM;
  968. goto exit_free;
  969. }
  970. for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
  971. zr->stat_com[j] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
  972. }
  973. /*
  974. * Now add the template and register the device unit.
  975. */
  976. memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
  977. zr->video_dev->parent = &zr->pci_dev->dev;
  978. strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
  979. err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
  980. if (err < 0)
  981. goto exit_free;
  982. video_set_drvdata(zr->video_dev, zr);
  983. zoran_init_hardware(zr);
  984. if (zr36067_debug > 2)
  985. detect_guest_activity(zr);
  986. test_interrupts(zr);
  987. if (!pass_through) {
  988. struct v4l2_routing route = { 2, 0 };
  989. decoder_call(zr, video, s_stream, 0);
  990. encoder_call(zr, video, s_routing, &route);
  991. }
  992. zr->zoran_proc = NULL;
  993. zr->initialized = 1;
  994. return 0;
  995. exit_free:
  996. kfree(zr->stat_com);
  997. kfree(zr->video_dev);
  998. return err;
  999. }
  1000. static void __devexit zoran_remove(struct pci_dev *pdev)
  1001. {
  1002. struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
  1003. struct zoran *zr = to_zoran(v4l2_dev);
  1004. if (!zr->initialized)
  1005. goto exit_free;
  1006. /* unregister videocodec bus */
  1007. if (zr->codec) {
  1008. struct videocodec_master *master = zr->codec->master_data;
  1009. videocodec_detach(zr->codec);
  1010. kfree(master);
  1011. }
  1012. if (zr->vfe) {
  1013. struct videocodec_master *master = zr->vfe->master_data;
  1014. videocodec_detach(zr->vfe);
  1015. kfree(master);
  1016. }
  1017. /* unregister i2c bus */
  1018. zoran_unregister_i2c(zr);
  1019. /* disable PCI bus-mastering */
  1020. zoran_set_pci_master(zr, 0);
  1021. /* put chip into reset */
  1022. btwrite(0, ZR36057_SPGPPCR);
  1023. free_irq(zr->pci_dev->irq, zr);
  1024. /* unmap and free memory */
  1025. kfree(zr->stat_com);
  1026. zoran_proc_cleanup(zr);
  1027. iounmap(zr->zr36057_mem);
  1028. pci_disable_device(zr->pci_dev);
  1029. video_unregister_device(zr->video_dev);
  1030. exit_free:
  1031. v4l2_device_unregister(&zr->v4l2_dev);
  1032. kfree(zr);
  1033. }
  1034. void
  1035. zoran_vdev_release (struct video_device *vdev)
  1036. {
  1037. kfree(vdev);
  1038. }
  1039. static struct videocodec_master * __devinit
  1040. zoran_setup_videocodec (struct zoran *zr,
  1041. int type)
  1042. {
  1043. struct videocodec_master *m = NULL;
  1044. m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL);
  1045. if (!m) {
  1046. dprintk(1,
  1047. KERN_ERR
  1048. "%s: zoran_setup_videocodec() - no memory\n",
  1049. ZR_DEVNAME(zr));
  1050. return m;
  1051. }
  1052. /* magic and type are unused for master struct. Makes sense only at
  1053. codec structs.
  1054. In the past, .type were initialized to the old V4L1 .hardware
  1055. value, as VID_HARDWARE_ZR36067
  1056. */
  1057. m->magic = 0L;
  1058. m->type = 0;
  1059. m->flags = CODEC_FLAG_ENCODER | CODEC_FLAG_DECODER;
  1060. strncpy(m->name, ZR_DEVNAME(zr), sizeof(m->name));
  1061. m->data = zr;
  1062. switch (type)
  1063. {
  1064. case CODEC_TYPE_ZR36060:
  1065. m->readreg = zr36060_read;
  1066. m->writereg = zr36060_write;
  1067. m->flags |= CODEC_FLAG_JPEG | CODEC_FLAG_VFE;
  1068. break;
  1069. case CODEC_TYPE_ZR36050:
  1070. m->readreg = zr36050_read;
  1071. m->writereg = zr36050_write;
  1072. m->flags |= CODEC_FLAG_JPEG;
  1073. break;
  1074. case CODEC_TYPE_ZR36016:
  1075. m->readreg = zr36016_read;
  1076. m->writereg = zr36016_write;
  1077. m->flags |= CODEC_FLAG_VFE;
  1078. break;
  1079. }
  1080. return m;
  1081. }
  1082. /*
  1083. * Scan for a Buz card (actually for the PCI controller ZR36057),
  1084. * request the irq and map the io memory
  1085. */
  1086. static int __devinit zoran_probe(struct pci_dev *pdev,
  1087. const struct pci_device_id *ent)
  1088. {
  1089. unsigned char latency, need_latency;
  1090. struct zoran *zr;
  1091. int result;
  1092. struct videocodec_master *master_vfe = NULL;
  1093. struct videocodec_master *master_codec = NULL;
  1094. int card_num;
  1095. char *codec_name, *vfe_name;
  1096. unsigned int nr;
  1097. nr = zoran_num++;
  1098. if (nr >= BUZ_MAX) {
  1099. dprintk(1,
  1100. KERN_ERR
  1101. "%s: driver limited to %d card(s) maximum\n",
  1102. ZORAN_NAME, BUZ_MAX);
  1103. return -ENOENT;
  1104. }
  1105. zr = kzalloc(sizeof(struct zoran), GFP_KERNEL);
  1106. if (!zr) {
  1107. dprintk(1,
  1108. KERN_ERR
  1109. "%s: find_zr36057() - kzalloc failed\n",
  1110. ZORAN_NAME);
  1111. return -ENOMEM;
  1112. }
  1113. if (v4l2_device_register(&pdev->dev, &zr->v4l2_dev))
  1114. goto zr_free_mem;
  1115. zr->pci_dev = pdev;
  1116. zr->id = nr;
  1117. snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
  1118. spin_lock_init(&zr->spinlock);
  1119. mutex_init(&zr->resource_lock);
  1120. if (pci_enable_device(pdev))
  1121. goto zr_unreg;
  1122. pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision);
  1123. dprintk(1,
  1124. KERN_INFO
  1125. "%s: Zoran ZR360%c7 (rev %d), irq: %d, memory: 0x%08llx\n",
  1126. ZR_DEVNAME(zr), zr->revision < 2 ? '5' : '6', zr->revision,
  1127. zr->pci_dev->irq, (uint64_t)pci_resource_start(zr->pci_dev, 0));
  1128. if (zr->revision >= 2) {
  1129. dprintk(1,
  1130. KERN_INFO
  1131. "%s: Subsystem vendor=0x%04x id=0x%04x\n",
  1132. ZR_DEVNAME(zr), zr->pci_dev->subsystem_vendor,
  1133. zr->pci_dev->subsystem_device);
  1134. }
  1135. /* Use auto-detected card type? */
  1136. if (card[nr] == -1) {
  1137. if (zr->revision < 2) {
  1138. dprintk(1,
  1139. KERN_ERR
  1140. "%s: No card type specified, please use the card=X module parameter\n",
  1141. ZR_DEVNAME(zr));
  1142. dprintk(1,
  1143. KERN_ERR
  1144. "%s: It is not possible to auto-detect ZR36057 based cards\n",
  1145. ZR_DEVNAME(zr));
  1146. goto zr_unreg;
  1147. }
  1148. card_num = ent->driver_data;
  1149. if (card_num >= NUM_CARDS) {
  1150. dprintk(1,
  1151. KERN_ERR
  1152. "%s: Unknown card, try specifying card=X module parameter\n",
  1153. ZR_DEVNAME(zr));
  1154. goto zr_unreg;
  1155. }
  1156. dprintk(3,
  1157. KERN_DEBUG
  1158. "%s: %s() - card %s detected\n",
  1159. ZR_DEVNAME(zr), __func__, zoran_cards[card_num].name);
  1160. } else {
  1161. card_num = card[nr];
  1162. if (card_num >= NUM_CARDS || card_num < 0) {
  1163. dprintk(1,
  1164. KERN_ERR
  1165. "%s: User specified card type %d out of range (0 .. %d)\n",
  1166. ZR_DEVNAME(zr), card_num, NUM_CARDS - 1);
  1167. goto zr_unreg;
  1168. }
  1169. }
  1170. /* even though we make this a non pointer and thus
  1171. * theoretically allow for making changes to this struct
  1172. * on a per-individual card basis at runtime, this is
  1173. * strongly discouraged. This structure is intended to
  1174. * keep general card information, no settings or anything */
  1175. zr->card = zoran_cards[card_num];
  1176. snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)),
  1177. "%s[%u]", zr->card.name, zr->id);
  1178. zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0);
  1179. if (!zr->zr36057_mem) {
  1180. dprintk(1,
  1181. KERN_ERR
  1182. "%s: %s() - ioremap failed\n",
  1183. ZR_DEVNAME(zr), __func__);
  1184. goto zr_unreg;
  1185. }
  1186. result = request_irq(zr->pci_dev->irq, zoran_irq,
  1187. IRQF_SHARED | IRQF_DISABLED, ZR_DEVNAME(zr), zr);
  1188. if (result < 0) {
  1189. if (result == -EINVAL) {
  1190. dprintk(1,
  1191. KERN_ERR
  1192. "%s: find_zr36057() - bad irq number or handler\n",
  1193. ZR_DEVNAME(zr));
  1194. } else if (result == -EBUSY) {
  1195. dprintk(1,
  1196. KERN_ERR
  1197. "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n",
  1198. ZR_DEVNAME(zr), zr->pci_dev->irq);
  1199. } else {
  1200. dprintk(1,
  1201. KERN_ERR
  1202. "%s: find_zr36057() - can't assign irq, error code %d\n",
  1203. ZR_DEVNAME(zr), result);
  1204. }
  1205. goto zr_unmap;
  1206. }
  1207. /* set PCI latency timer */
  1208. pci_read_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
  1209. &latency);
  1210. need_latency = zr->revision > 1 ? 32 : 48;
  1211. if (latency != need_latency) {
  1212. dprintk(2,
  1213. KERN_INFO
  1214. "%s: Changing PCI latency from %d to %d\n",
  1215. ZR_DEVNAME(zr), latency, need_latency);
  1216. pci_write_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
  1217. need_latency);
  1218. }
  1219. zr36057_restart(zr);
  1220. /* i2c */
  1221. dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n",
  1222. ZR_DEVNAME(zr));
  1223. if (zoran_register_i2c(zr) < 0) {
  1224. dprintk(1,
  1225. KERN_ERR
  1226. "%s: find_zr36057() - can't initialize i2c bus\n",
  1227. ZR_DEVNAME(zr));
  1228. goto zr_free_irq;
  1229. }
  1230. zr->decoder = v4l2_i2c_new_probed_subdev(&zr->i2c_adapter,
  1231. zr->card.mod_decoder, zr->card.i2c_decoder, zr->card.addrs_decoder);
  1232. if (zr->card.mod_encoder)
  1233. zr->encoder = v4l2_i2c_new_probed_subdev(&zr->i2c_adapter,
  1234. zr->card.mod_encoder, zr->card.i2c_encoder,
  1235. zr->card.addrs_encoder);
  1236. dprintk(2,
  1237. KERN_INFO "%s: Initializing videocodec bus...\n",
  1238. ZR_DEVNAME(zr));
  1239. if (zr->card.video_codec) {
  1240. codec_name = codecid_to_modulename(zr->card.video_codec);
  1241. if (codec_name) {
  1242. result = request_module(codec_name);
  1243. if (result) {
  1244. dprintk(1,
  1245. KERN_ERR
  1246. "%s: failed to load modules %s: %d\n",
  1247. ZR_DEVNAME(zr), codec_name, result);
  1248. }
  1249. }
  1250. }
  1251. if (zr->card.video_vfe) {
  1252. vfe_name = codecid_to_modulename(zr->card.video_vfe);
  1253. if (vfe_name) {
  1254. result = request_module(vfe_name);
  1255. if (result < 0) {
  1256. dprintk(1,
  1257. KERN_ERR
  1258. "%s: failed to load modules %s: %d\n",
  1259. ZR_DEVNAME(zr), vfe_name, result);
  1260. }
  1261. }
  1262. }
  1263. /* reset JPEG codec */
  1264. jpeg_codec_sleep(zr, 1);
  1265. jpeg_codec_reset(zr);
  1266. /* video bus enabled */
  1267. /* display codec revision */
  1268. if (zr->card.video_codec != 0) {
  1269. master_codec = zoran_setup_videocodec(zr, zr->card.video_codec);
  1270. if (!master_codec)
  1271. goto zr_unreg_i2c;
  1272. zr->codec = videocodec_attach(master_codec);
  1273. if (!zr->codec) {
  1274. dprintk(1,
  1275. KERN_ERR
  1276. "%s: find_zr36057() - no codec found\n",
  1277. ZR_DEVNAME(zr));
  1278. goto zr_free_codec;
  1279. }
  1280. if (zr->codec->type != zr->card.video_codec) {
  1281. dprintk(1,
  1282. KERN_ERR
  1283. "%s: find_zr36057() - wrong codec\n",
  1284. ZR_DEVNAME(zr));
  1285. goto zr_detach_codec;
  1286. }
  1287. }
  1288. if (zr->card.video_vfe != 0) {
  1289. master_vfe = zoran_setup_videocodec(zr, zr->card.video_vfe);
  1290. if (!master_vfe)
  1291. goto zr_detach_codec;
  1292. zr->vfe = videocodec_attach(master_vfe);
  1293. if (!zr->vfe) {
  1294. dprintk(1,
  1295. KERN_ERR
  1296. "%s: find_zr36057() - no VFE found\n",
  1297. ZR_DEVNAME(zr));
  1298. goto zr_free_vfe;
  1299. }
  1300. if (zr->vfe->type != zr->card.video_vfe) {
  1301. dprintk(1,
  1302. KERN_ERR
  1303. "%s: find_zr36057() = wrong VFE\n",
  1304. ZR_DEVNAME(zr));
  1305. goto zr_detach_vfe;
  1306. }
  1307. }
  1308. /* take care of Natoma chipset and a revision 1 zr36057 */
  1309. if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
  1310. zr->jpg_buffers.need_contiguous = 1;
  1311. dprintk(1,
  1312. KERN_INFO
  1313. "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
  1314. ZR_DEVNAME(zr));
  1315. }
  1316. if (zr36057_init(zr) < 0)
  1317. goto zr_detach_vfe;
  1318. zoran_proc_init(zr);
  1319. return 0;
  1320. zr_detach_vfe:
  1321. videocodec_detach(zr->vfe);
  1322. zr_free_vfe:
  1323. kfree(master_vfe);
  1324. zr_detach_codec:
  1325. videocodec_detach(zr->codec);
  1326. zr_free_codec:
  1327. kfree(master_codec);
  1328. zr_unreg_i2c:
  1329. zoran_unregister_i2c(zr);
  1330. zr_free_irq:
  1331. btwrite(0, ZR36057_SPGPPCR);
  1332. free_irq(zr->pci_dev->irq, zr);
  1333. zr_unmap:
  1334. iounmap(zr->zr36057_mem);
  1335. zr_unreg:
  1336. v4l2_device_unregister(&zr->v4l2_dev);
  1337. zr_free_mem:
  1338. kfree(zr);
  1339. return -ENODEV;
  1340. }
  1341. static struct pci_driver zoran_driver = {
  1342. .name = "zr36067",
  1343. .id_table = zr36067_pci_tbl,
  1344. .probe = zoran_probe,
  1345. .remove = zoran_remove,
  1346. };
  1347. static int __init zoran_init(void)
  1348. {
  1349. int res;
  1350. printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n",
  1351. MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION);
  1352. /* check the parameters we have been given, adjust if necessary */
  1353. if (v4l_nbufs < 2)
  1354. v4l_nbufs = 2;
  1355. if (v4l_nbufs > VIDEO_MAX_FRAME)
  1356. v4l_nbufs = VIDEO_MAX_FRAME;
  1357. /* The user specfies the in KB, we want them in byte
  1358. * (and page aligned) */
  1359. v4l_bufsize = PAGE_ALIGN(v4l_bufsize * 1024);
  1360. if (v4l_bufsize < 32768)
  1361. v4l_bufsize = 32768;
  1362. /* 2 MB is arbitrary but sufficient for the maximum possible images */
  1363. if (v4l_bufsize > 2048 * 1024)
  1364. v4l_bufsize = 2048 * 1024;
  1365. if (jpg_nbufs < 4)
  1366. jpg_nbufs = 4;
  1367. if (jpg_nbufs > BUZ_MAX_FRAME)
  1368. jpg_nbufs = BUZ_MAX_FRAME;
  1369. jpg_bufsize = PAGE_ALIGN(jpg_bufsize * 1024);
  1370. if (jpg_bufsize < 8192)
  1371. jpg_bufsize = 8192;
  1372. if (jpg_bufsize > (512 * 1024))
  1373. jpg_bufsize = 512 * 1024;
  1374. /* Use parameter for vidmem or try to find a video card */
  1375. if (vidmem) {
  1376. dprintk(1,
  1377. KERN_INFO
  1378. "%s: Using supplied video memory base address @ 0x%lx\n",
  1379. ZORAN_NAME, vidmem);
  1380. }
  1381. /* random nonsense */
  1382. dprintk(6, KERN_DEBUG "Jotti is een held!\n");
  1383. /* some mainboards might not do PCI-PCI data transfer well */
  1384. if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) {
  1385. dprintk(1,
  1386. KERN_WARNING
  1387. "%s: chipset does not support reliable PCI-PCI DMA\n",
  1388. ZORAN_NAME);
  1389. }
  1390. res = pci_register_driver(&zoran_driver);
  1391. if (res) {
  1392. dprintk(1,
  1393. KERN_ERR
  1394. "%s: Unable to register ZR36057 driver\n",
  1395. ZORAN_NAME);
  1396. return res;
  1397. }
  1398. return 0;
  1399. }
  1400. static void __exit zoran_exit(void)
  1401. {
  1402. pci_unregister_driver(&zoran_driver);
  1403. }
  1404. module_init(zoran_init);
  1405. module_exit(zoran_exit);