zoran_card.c 41 KB

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