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