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