2 * Zoran zr36057/zr36067 PCI controller driver, for the
3 * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
4 * Media Labs LML33/LML33R10.
6 * This part handles card-specific data and detection
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
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>
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.
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.
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.
30 #include <linux/delay.h>
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>
38 #include <linux/proc_fs.h>
39 #include <linux/i2c.h>
40 #include <linux/i2c-algo-bit.h>
41 #include <linux/videodev2.h>
42 #include <linux/spinlock.h>
43 #include <linux/sem.h>
44 #include <linux/kmod.h>
45 #include <linux/wait.h>
47 #include <linux/pci.h>
48 #include <linux/interrupt.h>
49 #include <linux/mutex.h>
51 #include <media/v4l2-common.h>
52 #include <media/bt819.h>
54 #include "videocodec.h"
56 #include "zoran_card.h"
57 #include "zoran_device.h"
58 #include "zoran_procfs.h"
60 extern const struct zoran_format zoran_formats
[];
62 static int card
[BUZ_MAX
] = { [0 ... (BUZ_MAX
-1)] = -1 };
63 module_param_array(card
, int, NULL
, 0444);
64 MODULE_PARM_DESC(card
, "Card type");
66 static int encoder
[BUZ_MAX
] = { [0 ... (BUZ_MAX
-1)] = -1 };
67 module_param_array(encoder
, int, NULL
, 0444);
68 MODULE_PARM_DESC(encoder
, "Video encoder chip");
70 static int decoder
[BUZ_MAX
] = { [0 ... (BUZ_MAX
-1)] = -1 };
71 module_param_array(decoder
, int, NULL
, 0444);
72 MODULE_PARM_DESC(decoder
, "Video decoder chip");
75 The video mem address of the video card.
76 The driver has a little database for some videocards
77 to determine it from there. If your video card is not in there
78 you have either to give it to the driver as a parameter
79 or set in in a VIDIOCSFBUF ioctl
82 static unsigned long vidmem
; /* default = 0 - Video memory base address */
83 module_param(vidmem
, ulong
, 0444);
84 MODULE_PARM_DESC(vidmem
, "Default video memory base address");
87 Default input and video norm at startup of the driver.
90 static unsigned int default_input
; /* default 0 = Composite, 1 = S-Video */
91 module_param(default_input
, uint
, 0444);
92 MODULE_PARM_DESC(default_input
,
93 "Default input (0=Composite, 1=S-Video, 2=Internal)");
95 static int default_mux
= 1; /* 6 Eyes input selection */
96 module_param(default_mux
, int, 0644);
97 MODULE_PARM_DESC(default_mux
,
98 "Default 6 Eyes mux setting (Input selection)");
100 static int default_norm
; /* default 0 = PAL, 1 = NTSC 2 = SECAM */
101 module_param(default_norm
, int, 0444);
102 MODULE_PARM_DESC(default_norm
, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
104 /* /dev/videoN, -1 for autodetect */
105 static int video_nr
[BUZ_MAX
] = { [0 ... (BUZ_MAX
-1)] = -1 };
106 module_param_array(video_nr
, int, NULL
, 0444);
107 MODULE_PARM_DESC(video_nr
, "Video device number (-1=Auto)");
110 int v4l_bufsize
= 864; /* Everybody should be able to work with this setting */
111 module_param(v4l_nbufs
, int, 0644);
112 MODULE_PARM_DESC(v4l_nbufs
, "Maximum number of V4L buffers to use");
113 module_param(v4l_bufsize
, int, 0644);
114 MODULE_PARM_DESC(v4l_bufsize
, "Maximum size per V4L buffer (in kB)");
117 int jpg_bufsize
= 512; /* max size for 100% quality full-PAL frame */
118 module_param(jpg_nbufs
, int, 0644);
119 MODULE_PARM_DESC(jpg_nbufs
, "Maximum number of JPG buffers to use");
120 module_param(jpg_bufsize
, int, 0644);
121 MODULE_PARM_DESC(jpg_bufsize
, "Maximum size per JPG buffer (in kB)");
123 int pass_through
= 0; /* 1=Pass through TV signal when device is not used */
124 /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */
125 module_param(pass_through
, int, 0644);
126 MODULE_PARM_DESC(pass_through
,
127 "Pass TV signal through to TV-out when idling");
129 int zr36067_debug
= 1;
130 module_param_named(debug
, zr36067_debug
, int, 0644);
131 MODULE_PARM_DESC(debug
, "Debug level (0-5)");
133 MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
134 MODULE_AUTHOR("Serguei Miridonov");
135 MODULE_LICENSE("GPL");
137 #define ZR_DEVICE(subven, subdev, data) { \
138 .vendor = PCI_VENDOR_ID_ZORAN, .device = PCI_DEVICE_ID_ZORAN_36057, \
139 .subvendor = (subven), .subdevice = (subdev), .driver_data = (data) }
141 static struct pci_device_id zr36067_pci_tbl
[] = {
142 ZR_DEVICE(PCI_VENDOR_ID_MIRO
, PCI_DEVICE_ID_MIRO_DC10PLUS
, DC10plus
),
143 ZR_DEVICE(PCI_VENDOR_ID_MIRO
, PCI_DEVICE_ID_MIRO_DC30PLUS
, DC30plus
),
144 ZR_DEVICE(PCI_VENDOR_ID_ELECTRONICDESIGNGMBH
, PCI_DEVICE_ID_LML_33R10
, LML33R10
),
145 ZR_DEVICE(PCI_VENDOR_ID_IOMEGA
, PCI_DEVICE_ID_IOMEGA_BUZ
, BUZ
),
146 ZR_DEVICE(PCI_ANY_ID
, PCI_ANY_ID
, NUM_CARDS
),
149 MODULE_DEVICE_TABLE(pci
, zr36067_pci_tbl
);
151 static unsigned int zoran_num
; /* number of cards found */
153 /* videocodec bus functions ZR36060 */
155 zr36060_read (struct videocodec
*codec
,
158 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
161 if (post_office_wait(zr
)
162 || post_office_write(zr
, 0, 1, reg
>> 8)
163 || post_office_write(zr
, 0, 2, reg
& 0xff)) {
167 data
= post_office_read(zr
, 0, 3) & 0xff;
172 zr36060_write (struct videocodec
*codec
,
176 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
178 if (post_office_wait(zr
)
179 || post_office_write(zr
, 0, 1, reg
>> 8)
180 || post_office_write(zr
, 0, 2, reg
& 0xff)) {
184 post_office_write(zr
, 0, 3, val
& 0xff);
187 /* videocodec bus functions ZR36050 */
189 zr36050_read (struct videocodec
*codec
,
192 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
195 if (post_office_wait(zr
)
196 || post_office_write(zr
, 1, 0, reg
>> 2)) { // reg. HIGHBYTES
200 data
= post_office_read(zr
, 0, reg
& 0x03) & 0xff; // reg. LOWBYTES + read
205 zr36050_write (struct videocodec
*codec
,
209 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
211 if (post_office_wait(zr
)
212 || post_office_write(zr
, 1, 0, reg
>> 2)) { // reg. HIGHBYTES
216 post_office_write(zr
, 0, reg
& 0x03, val
& 0xff); // reg. LOWBYTES + wr. data
219 /* videocodec bus functions ZR36016 */
221 zr36016_read (struct videocodec
*codec
,
224 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
227 if (post_office_wait(zr
)) {
231 data
= post_office_read(zr
, 2, reg
& 0x03) & 0xff; // read
235 /* hack for in zoran_device.c */
237 zr36016_write (struct videocodec
*codec
,
241 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
243 if (post_office_wait(zr
)) {
247 post_office_write(zr
, 2, reg
& 0x03, val
& 0x0ff); // wr. data
251 * Board specific information
255 dc10_init (struct zoran
*zr
)
257 dprintk(3, KERN_DEBUG
"%s: %s\n", ZR_DEVNAME(zr
), __func__
);
259 /* Pixel clock selection */
262 /* Enable the video bus sync signals */
267 dc10plus_init (struct zoran
*zr
)
269 dprintk(3, KERN_DEBUG
"%s: %s\n", ZR_DEVNAME(zr
), __func__
);
273 buz_init (struct zoran
*zr
)
275 dprintk(3, KERN_DEBUG
"%s: %s\n", ZR_DEVNAME(zr
), __func__
);
277 /* some stuff from Iomega */
278 pci_write_config_dword(zr
->pci_dev
, 0xfc, 0x90680f15);
279 pci_write_config_dword(zr
->pci_dev
, 0x0c, 0x00012020);
280 pci_write_config_dword(zr
->pci_dev
, 0xe8, 0xc0200000);
284 lml33_init (struct zoran
*zr
)
286 dprintk(3, KERN_DEBUG
"%s: %s\n", ZR_DEVNAME(zr
), __func__
);
288 GPIO(zr
, 2, 1); // Set Composite input/output
292 avs6eyes_init (struct zoran
*zr
)
294 // AverMedia 6-Eyes original driver by Christer Weinigel
296 // Lifted straight from Christer's old driver and
297 // modified slightly by Martin Samuelsson.
299 int mux
= default_mux
; /* 1 = BT866, 7 = VID1 */
301 GPIO(zr
, 4, 1); /* Bt866 SLEEP on */
304 GPIO(zr
, 0, 1); /* ZR36060 /RESET on */
305 GPIO(zr
, 1, 0); /* ZR36060 /SLEEP on */
306 GPIO(zr
, 2, mux
& 1); /* MUX S0 */
307 GPIO(zr
, 3, 0); /* /FRAME on */
308 GPIO(zr
, 4, 0); /* Bt866 SLEEP off */
309 GPIO(zr
, 5, mux
& 2); /* MUX S1 */
310 GPIO(zr
, 6, 0); /* ? */
311 GPIO(zr
, 7, mux
& 4); /* MUX S2 */
316 codecid_to_modulename (u16 codecid
)
321 case CODEC_TYPE_ZR36060
:
324 case CODEC_TYPE_ZR36050
:
327 case CODEC_TYPE_ZR36016
:
336 // u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
339 static struct tvnorm f50sqpixel
= { 944, 768, 83, 880, 625, 576, 16 };
340 static struct tvnorm f60sqpixel
= { 780, 640, 51, 716, 525, 480, 12 };
341 static struct tvnorm f50ccir601
= { 864, 720, 75, 804, 625, 576, 18 };
342 static struct tvnorm f60ccir601
= { 858, 720, 57, 788, 525, 480, 16 };
344 static struct tvnorm f50ccir601_lml33
= { 864, 720, 75+34, 804, 625, 576, 18 };
345 static struct tvnorm f60ccir601_lml33
= { 858, 720, 57+34, 788, 525, 480, 16 };
347 /* The DC10 (57/16/50) uses VActive as HSync, so HStart must be 0 */
348 static struct tvnorm f50sqpixel_dc10
= { 944, 768, 0, 880, 625, 576, 0 };
349 static struct tvnorm f60sqpixel_dc10
= { 780, 640, 0, 716, 525, 480, 12 };
351 /* FIXME: I cannot swap U and V in saa7114, so i do one
352 * pixel left shift in zoran (75 -> 74)
353 * (Maxim Yevtyushkin <max@linuxmedialabs.com>) */
354 static struct tvnorm f50ccir601_lm33r10
= { 864, 720, 74+54, 804, 625, 576, 18 };
355 static struct tvnorm f60ccir601_lm33r10
= { 858, 720, 56+54, 788, 525, 480, 16 };
357 /* FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I
358 * copy Maxim's left shift hack for the 6 Eyes.
360 * Christer's driver used the unshifted norms, though...
362 static struct tvnorm f50ccir601_avs6eyes
= { 864, 720, 74, 804, 625, 576, 18 };
363 static struct tvnorm f60ccir601_avs6eyes
= { 858, 720, 56, 788, 525, 480, 16 };
365 static const unsigned short vpx3220_addrs
[] = { 0x43, 0x47, I2C_CLIENT_END
};
366 static const unsigned short saa7110_addrs
[] = { 0x4e, 0x4f, I2C_CLIENT_END
};
367 static const unsigned short saa7111_addrs
[] = { 0x25, 0x24, I2C_CLIENT_END
};
368 static const unsigned short saa7114_addrs
[] = { 0x21, 0x20, I2C_CLIENT_END
};
369 static const unsigned short adv717x_addrs
[] = { 0x6a, 0x6b, 0x2a, 0x2b, I2C_CLIENT_END
};
370 static const unsigned short ks0127_addrs
[] = { 0x6c, 0x6d, I2C_CLIENT_END
};
371 static const unsigned short saa7185_addrs
[] = { 0x44, I2C_CLIENT_END
};
372 static const unsigned short bt819_addrs
[] = { 0x45, I2C_CLIENT_END
};
373 static const unsigned short bt856_addrs
[] = { 0x44, I2C_CLIENT_END
};
374 static const unsigned short bt866_addrs
[] = { 0x44, I2C_CLIENT_END
};
376 static struct card_info zoran_cards
[NUM_CARDS
] __devinitdata
= {
380 .i2c_decoder
= "vpx3220a",
381 .mod_decoder
= "vpx3220",
382 .addrs_decoder
= vpx3220_addrs
,
383 .video_codec
= CODEC_TYPE_ZR36050
,
384 .video_vfe
= CODEC_TYPE_ZR36016
,
390 { 0, "Internal/comp" }
392 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
399 .vsync_int
= ZR36057_ISR_GIRQ1
,
400 .gpio
= { 2, 1, -1, 3, 7, 0, 4, 5 },
401 .gpio_pol
= { 0, 0, 0, 1, 0, 0, 0, 0 },
403 .vfe_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
404 .gws_not_connected
= 0,
410 .i2c_decoder
= "saa7110",
411 .mod_decoder
= "saa7110",
412 .addrs_decoder
= saa7110_addrs
,
413 .i2c_encoder
= "adv7175",
414 .mod_encoder
= "adv7175",
415 .addrs_encoder
= adv717x_addrs
,
416 .video_codec
= CODEC_TYPE_ZR36060
,
422 { 5, "Internal/comp" }
424 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
429 .jpeg_int
= ZR36057_ISR_GIRQ0
,
430 .vsync_int
= ZR36057_ISR_GIRQ1
,
431 .gpio
= { 3, 0, 6, 1, 2, -1, 4, 5 },
432 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
434 .vfe_pol
= { 1, 1, 1, 1, 0, 0, 0, 0 },
435 .gws_not_connected
= 0,
437 .init
= &dc10plus_init
,
441 .i2c_decoder
= "saa7110",
442 .mod_decoder
= "saa7110",
443 .addrs_decoder
= saa7110_addrs
,
444 .i2c_encoder
= "adv7175",
445 .mod_encoder
= "adv7175",
446 .addrs_encoder
= adv717x_addrs
,
447 .video_codec
= CODEC_TYPE_ZR36060
,
453 { 5, "Internal/comp" }
455 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
461 .jpeg_int
= ZR36057_ISR_GIRQ0
,
462 .vsync_int
= ZR36057_ISR_GIRQ1
,
463 .gpio
= { 3, 0, 6, 1, 2, -1, 4, 5 },
464 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
466 .vfe_pol
= { 1, 1, 1, 1, 0, 0, 0, 0 },
467 .gws_not_connected
= 0,
469 .init
= &dc10plus_init
,
473 .i2c_decoder
= "vpx3220a",
474 .mod_decoder
= "vpx3220",
475 .addrs_decoder
= vpx3220_addrs
,
476 .i2c_encoder
= "adv7175",
477 .mod_encoder
= "adv7175",
478 .addrs_encoder
= adv717x_addrs
,
479 .video_codec
= CODEC_TYPE_ZR36050
,
480 .video_vfe
= CODEC_TYPE_ZR36016
,
486 { 0, "Internal/comp" }
488 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
495 .vsync_int
= ZR36057_ISR_GIRQ1
,
496 .gpio
= { 2, 1, -1, 3, 7, 0, 4, 5 },
497 .gpio_pol
= { 0, 0, 0, 1, 0, 0, 0, 0 },
499 .vfe_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
500 .gws_not_connected
= 0,
506 .i2c_decoder
= "vpx3220a",
507 .mod_decoder
= "vpx3220",
508 .addrs_decoder
= vpx3220_addrs
,
509 .i2c_encoder
= "adv7175",
510 .mod_encoder
= "adv7175",
511 .addrs_encoder
= adv717x_addrs
,
512 .video_codec
= CODEC_TYPE_ZR36050
,
513 .video_vfe
= CODEC_TYPE_ZR36016
,
519 { 0, "Internal/comp" }
521 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
528 .vsync_int
= ZR36057_ISR_GIRQ1
,
529 .gpio
= { 2, 1, -1, 3, 7, 0, 4, 5 },
530 .gpio_pol
= { 0, 0, 0, 1, 0, 0, 0, 0 },
532 .vfe_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
533 .gws_not_connected
= 0,
539 .i2c_decoder
= "bt819a",
540 .mod_decoder
= "bt819",
541 .addrs_decoder
= bt819_addrs
,
542 .i2c_encoder
= "bt856",
543 .mod_encoder
= "bt856",
544 .addrs_encoder
= bt856_addrs
,
545 .video_codec
= CODEC_TYPE_ZR36060
,
552 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
,
558 .jpeg_int
= ZR36057_ISR_GIRQ1
,
559 .vsync_int
= ZR36057_ISR_GIRQ0
,
560 .gpio
= { 1, -1, 3, 5, 7, -1, -1, -1 },
561 .gpio_pol
= { 0, 0, 0, 0, 1, 0, 0, 0 },
563 .vfe_pol
= { 1, 1, 0, 0, 0, 1, 0, 0 },
564 .gws_not_connected
= 1,
570 .i2c_decoder
= "saa7114",
571 .mod_decoder
= "saa7115",
572 .addrs_decoder
= saa7114_addrs
,
573 .i2c_encoder
= "adv7170",
574 .mod_encoder
= "adv7170",
575 .addrs_encoder
= adv717x_addrs
,
576 .video_codec
= CODEC_TYPE_ZR36060
,
583 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
,
589 .jpeg_int
= ZR36057_ISR_GIRQ1
,
590 .vsync_int
= ZR36057_ISR_GIRQ0
,
591 .gpio
= { 1, -1, 3, 5, 7, -1, -1, -1 },
592 .gpio_pol
= { 0, 0, 0, 0, 1, 0, 0, 0 },
594 .vfe_pol
= { 1, 1, 0, 0, 0, 1, 0, 0 },
595 .gws_not_connected
= 1,
601 .i2c_decoder
= "saa7111",
602 .mod_decoder
= "saa7115",
603 .addrs_decoder
= saa7111_addrs
,
604 .i2c_encoder
= "saa7185",
605 .mod_encoder
= "saa7185",
606 .addrs_encoder
= saa7185_addrs
,
607 .video_codec
= CODEC_TYPE_ZR36060
,
614 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
620 .jpeg_int
= ZR36057_ISR_GIRQ1
,
621 .vsync_int
= ZR36057_ISR_GIRQ0
,
622 .gpio
= { 1, -1, 3, -1, -1, -1, -1, -1 },
623 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
625 .vfe_pol
= { 1, 1, 0, 0, 0, 1, 0, 0 },
626 .gws_not_connected
= 1,
632 /* AverMedia chose not to brand the 6-Eyes. Thus it
633 can't be autodetected, and requires card=x. */
634 .i2c_decoder
= "ks0127",
635 .mod_decoder
= "ks0127",
636 .addrs_decoder
= ks0127_addrs
,
637 .i2c_encoder
= "bt866",
638 .mod_encoder
= "bt866",
639 .addrs_encoder
= bt866_addrs
,
640 .video_codec
= CODEC_TYPE_ZR36060
,
644 { 0, "Composite 1" },
645 { 1, "Composite 2" },
646 { 2, "Composite 3" },
647 { 4, "Composite 4" },
648 { 5, "Composite 5" },
649 { 6, "Composite 6" },
655 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
,
657 &f50ccir601_avs6eyes
,
658 &f60ccir601_avs6eyes
,
661 .jpeg_int
= ZR36057_ISR_GIRQ1
,
662 .vsync_int
= ZR36057_ISR_GIRQ0
,
663 .gpio
= { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
664 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
665 .gpcs
= { 3, 1 }, // Validity unknown /Sam
666 .vfe_pol
= { 1, 0, 0, 0, 0, 1, 0, 0 }, // Validity unknown /Sam
667 .gws_not_connected
= 1,
669 .init
= &avs6eyes_init
,
677 /* software I2C functions */
679 zoran_i2c_getsda (void *data
)
681 struct zoran
*zr
= (struct zoran
*) data
;
683 return (btread(ZR36057_I2CBR
) >> 1) & 1;
687 zoran_i2c_getscl (void *data
)
689 struct zoran
*zr
= (struct zoran
*) data
;
691 return btread(ZR36057_I2CBR
) & 1;
695 zoran_i2c_setsda (void *data
,
698 struct zoran
*zr
= (struct zoran
*) data
;
704 btwrite(zr
->i2cbr
, ZR36057_I2CBR
);
708 zoran_i2c_setscl (void *data
,
711 struct zoran
*zr
= (struct zoran
*) data
;
717 btwrite(zr
->i2cbr
, ZR36057_I2CBR
);
720 static const struct i2c_algo_bit_data zoran_i2c_bit_data_template
= {
721 .setsda
= zoran_i2c_setsda
,
722 .setscl
= zoran_i2c_setscl
,
723 .getsda
= zoran_i2c_getsda
,
724 .getscl
= zoran_i2c_getscl
,
730 zoran_register_i2c (struct zoran
*zr
)
732 memcpy(&zr
->i2c_algo
, &zoran_i2c_bit_data_template
,
733 sizeof(struct i2c_algo_bit_data
));
734 zr
->i2c_algo
.data
= zr
;
735 strlcpy(zr
->i2c_adapter
.name
, ZR_DEVNAME(zr
),
736 sizeof(zr
->i2c_adapter
.name
));
737 i2c_set_adapdata(&zr
->i2c_adapter
, &zr
->v4l2_dev
);
738 zr
->i2c_adapter
.algo_data
= &zr
->i2c_algo
;
739 zr
->i2c_adapter
.dev
.parent
= &zr
->pci_dev
->dev
;
740 return i2c_bit_add_bus(&zr
->i2c_adapter
);
744 zoran_unregister_i2c (struct zoran
*zr
)
746 i2c_del_adapter(&zr
->i2c_adapter
);
749 /* Check a zoran_params struct for correctness, insert default params */
752 zoran_check_jpg_settings (struct zoran
*zr
,
753 struct zoran_jpg_settings
*settings
,
756 int err
= 0, err0
= 0;
760 "%s: %s - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
761 ZR_DEVNAME(zr
), __func__
, settings
->decimation
, settings
->HorDcm
,
762 settings
->VerDcm
, settings
->TmpDcm
);
765 "%s: %s - x: %d, y: %d, w: %d, y: %d\n",
766 ZR_DEVNAME(zr
), __func__
, settings
->img_x
, settings
->img_y
,
767 settings
->img_width
, settings
->img_height
);
768 /* Check decimation, set default values for decimation = 1, 2, 4 */
769 switch (settings
->decimation
) {
772 settings
->HorDcm
= 1;
773 settings
->VerDcm
= 1;
774 settings
->TmpDcm
= 1;
775 settings
->field_per_buff
= 2;
778 settings
->img_width
= BUZ_MAX_WIDTH
;
779 settings
->img_height
= BUZ_MAX_HEIGHT
/ 2;
783 settings
->HorDcm
= 2;
784 settings
->VerDcm
= 1;
785 settings
->TmpDcm
= 2;
786 settings
->field_per_buff
= 1;
787 settings
->img_x
= (BUZ_MAX_WIDTH
== 720) ? 8 : 0;
789 settings
->img_width
=
790 (BUZ_MAX_WIDTH
== 720) ? 704 : BUZ_MAX_WIDTH
;
791 settings
->img_height
= BUZ_MAX_HEIGHT
/ 2;
795 if (zr
->card
.type
== DC10_new
) {
798 "%s: %s - HDec by 4 is not supported on the DC10\n",
799 ZR_DEVNAME(zr
), __func__
);
804 settings
->HorDcm
= 4;
805 settings
->VerDcm
= 2;
806 settings
->TmpDcm
= 2;
807 settings
->field_per_buff
= 1;
808 settings
->img_x
= (BUZ_MAX_WIDTH
== 720) ? 8 : 0;
810 settings
->img_width
=
811 (BUZ_MAX_WIDTH
== 720) ? 704 : BUZ_MAX_WIDTH
;
812 settings
->img_height
= BUZ_MAX_HEIGHT
/ 2;
816 /* We have to check the data the user has set */
818 if (settings
->HorDcm
!= 1 && settings
->HorDcm
!= 2 &&
819 (zr
->card
.type
== DC10_new
|| settings
->HorDcm
!= 4)) {
820 settings
->HorDcm
= clamp(settings
->HorDcm
, 1, 2);
823 if (settings
->VerDcm
!= 1 && settings
->VerDcm
!= 2) {
824 settings
->VerDcm
= clamp(settings
->VerDcm
, 1, 2);
827 if (settings
->TmpDcm
!= 1 && settings
->TmpDcm
!= 2) {
828 settings
->TmpDcm
= clamp(settings
->TmpDcm
, 1, 2);
831 if (settings
->field_per_buff
!= 1 &&
832 settings
->field_per_buff
!= 2) {
833 settings
->field_per_buff
= clamp(settings
->field_per_buff
, 1, 2);
836 if (settings
->img_x
< 0) {
840 if (settings
->img_y
< 0) {
844 if (settings
->img_width
< 0 || settings
->img_width
> BUZ_MAX_WIDTH
) {
845 settings
->img_width
= clamp(settings
->img_width
, 0, (int)BUZ_MAX_WIDTH
);
848 if (settings
->img_height
< 0 || settings
->img_height
> BUZ_MAX_HEIGHT
/ 2) {
849 settings
->img_height
= clamp(settings
->img_height
, 0, BUZ_MAX_HEIGHT
/ 2);
852 if (settings
->img_x
+ settings
->img_width
> BUZ_MAX_WIDTH
) {
853 settings
->img_x
= BUZ_MAX_WIDTH
- settings
->img_width
;
856 if (settings
->img_y
+ settings
->img_height
> BUZ_MAX_HEIGHT
/ 2) {
857 settings
->img_y
= BUZ_MAX_HEIGHT
/ 2 - settings
->img_height
;
860 if (settings
->img_width
% (16 * settings
->HorDcm
) != 0) {
861 settings
->img_width
-= settings
->img_width
% (16 * settings
->HorDcm
);
862 if (settings
->img_width
== 0)
863 settings
->img_width
= 16 * settings
->HorDcm
;
866 if (settings
->img_height
% (8 * settings
->VerDcm
) != 0) {
867 settings
->img_height
-= settings
->img_height
% (8 * settings
->VerDcm
);
868 if (settings
->img_height
== 0)
869 settings
->img_height
= 8 * settings
->VerDcm
;
876 "%s: %s - error in params for decimation = 0\n",
877 ZR_DEVNAME(zr
), __func__
);
884 "%s: %s - decimation = %d, must be 0, 1, 2 or 4\n",
885 ZR_DEVNAME(zr
), __func__
, settings
->decimation
);
890 if (settings
->jpg_comp
.quality
> 100)
891 settings
->jpg_comp
.quality
= 100;
892 if (settings
->jpg_comp
.quality
< 5)
893 settings
->jpg_comp
.quality
= 5;
894 if (settings
->jpg_comp
.APPn
< 0)
895 settings
->jpg_comp
.APPn
= 0;
896 if (settings
->jpg_comp
.APPn
> 15)
897 settings
->jpg_comp
.APPn
= 15;
898 if (settings
->jpg_comp
.APP_len
< 0)
899 settings
->jpg_comp
.APP_len
= 0;
900 if (settings
->jpg_comp
.APP_len
> 60)
901 settings
->jpg_comp
.APP_len
= 60;
902 if (settings
->jpg_comp
.COM_len
< 0)
903 settings
->jpg_comp
.COM_len
= 0;
904 if (settings
->jpg_comp
.COM_len
> 60)
905 settings
->jpg_comp
.COM_len
= 60;
912 zoran_open_init_params (struct zoran
*zr
)
916 /* User must explicitly set a window */
917 zr
->overlay_settings
.is_set
= 0;
918 zr
->overlay_mask
= NULL
;
919 zr
->overlay_active
= ZORAN_FREE
;
921 zr
->v4l_memgrab_active
= 0;
922 zr
->v4l_overlay_active
= 0;
923 zr
->v4l_grab_frame
= NO_GRAB_ACTIVE
;
924 zr
->v4l_grab_seq
= 0;
925 zr
->v4l_settings
.width
= 192;
926 zr
->v4l_settings
.height
= 144;
927 zr
->v4l_settings
.format
= &zoran_formats
[7]; /* YUY2 - YUV-4:2:2 packed */
928 zr
->v4l_settings
.bytesperline
=
929 zr
->v4l_settings
.width
*
930 ((zr
->v4l_settings
.format
->depth
+ 7) / 8);
932 /* DMA ring stuff for V4L */
933 zr
->v4l_pend_tail
= 0;
934 zr
->v4l_pend_head
= 0;
935 zr
->v4l_sync_tail
= 0;
936 zr
->v4l_buffers
.active
= ZORAN_FREE
;
937 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
938 zr
->v4l_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
940 zr
->v4l_buffers
.allocated
= 0;
942 for (i
= 0; i
< BUZ_MAX_FRAME
; i
++) {
943 zr
->jpg_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
945 zr
->jpg_buffers
.active
= ZORAN_FREE
;
946 zr
->jpg_buffers
.allocated
= 0;
947 /* Set necessary params and call zoran_check_jpg_settings to set the defaults */
948 zr
->jpg_settings
.decimation
= 1;
949 zr
->jpg_settings
.jpg_comp
.quality
= 50; /* default compression factor 8 */
950 if (zr
->card
.type
!= BUZ
)
951 zr
->jpg_settings
.odd_even
= 1;
953 zr
->jpg_settings
.odd_even
= 0;
954 zr
->jpg_settings
.jpg_comp
.APPn
= 0;
955 zr
->jpg_settings
.jpg_comp
.APP_len
= 0; /* No APPn marker */
956 memset(zr
->jpg_settings
.jpg_comp
.APP_data
, 0,
957 sizeof(zr
->jpg_settings
.jpg_comp
.APP_data
));
958 zr
->jpg_settings
.jpg_comp
.COM_len
= 0; /* No COM marker */
959 memset(zr
->jpg_settings
.jpg_comp
.COM_data
, 0,
960 sizeof(zr
->jpg_settings
.jpg_comp
.COM_data
));
961 zr
->jpg_settings
.jpg_comp
.jpeg_markers
=
962 JPEG_MARKER_DHT
| JPEG_MARKER_DQT
;
963 i
= zoran_check_jpg_settings(zr
, &zr
->jpg_settings
, 0);
965 dprintk(1, KERN_ERR
"%s: %s internal error\n",
966 ZR_DEVNAME(zr
), __func__
);
968 clear_interrupt_counters(zr
);
972 static void __devinit
973 test_interrupts (struct zoran
*zr
)
978 clear_interrupt_counters(zr
);
981 icr
= btread(ZR36057_ICR
);
982 btwrite(0x78000000 | ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
983 prepare_to_wait(&zr
->test_q
, &wait
, TASK_INTERRUPTIBLE
);
984 timeout
= schedule_timeout(HZ
);
985 finish_wait(&zr
->test_q
, &wait
);
986 btwrite(0, ZR36057_ICR
);
987 btwrite(0x78000000, ZR36057_ISR
);
989 dprintk(5, KERN_INFO
"%s: Testing interrupts...\n", ZR_DEVNAME(zr
));
991 dprintk(1, ": time spent: %d\n", 1 * HZ
- timeout
);
993 if (zr36067_debug
> 1)
994 print_interrupts(zr
);
995 btwrite(icr
, ZR36057_ICR
);
999 zr36057_init (struct zoran
*zr
)
1005 "%s: %s - initializing card[%d], zr=%p\n",
1006 ZR_DEVNAME(zr
), __func__
, zr
->id
, zr
);
1008 /* default setup of all parameters which will persist between opens */
1011 init_waitqueue_head(&zr
->v4l_capq
);
1012 init_waitqueue_head(&zr
->jpg_capq
);
1013 init_waitqueue_head(&zr
->test_q
);
1014 zr
->jpg_buffers
.allocated
= 0;
1015 zr
->v4l_buffers
.allocated
= 0;
1017 zr
->vbuf_base
= (void *) vidmem
;
1019 zr
->vbuf_height
= 0;
1021 zr
->vbuf_bytesperline
= 0;
1023 /* Avoid nonsense settings from user for default input/norm */
1024 if (default_norm
< 0 || default_norm
> 2)
1026 if (default_norm
== 0) {
1027 zr
->norm
= V4L2_STD_PAL
;
1028 zr
->timing
= zr
->card
.tvn
[0];
1029 } else if (default_norm
== 1) {
1030 zr
->norm
= V4L2_STD_NTSC
;
1031 zr
->timing
= zr
->card
.tvn
[1];
1033 zr
->norm
= V4L2_STD_SECAM
;
1034 zr
->timing
= zr
->card
.tvn
[2];
1036 if (zr
->timing
== NULL
) {
1039 "%s: %s - default TV standard not supported by hardware. PAL will be used.\n",
1040 ZR_DEVNAME(zr
), __func__
);
1041 zr
->norm
= V4L2_STD_PAL
;
1042 zr
->timing
= zr
->card
.tvn
[0];
1045 if (default_input
> zr
->card
.inputs
-1) {
1048 "%s: default_input value %d out of range (0-%d)\n",
1049 ZR_DEVNAME(zr
), default_input
, zr
->card
.inputs
-1);
1052 zr
->input
= default_input
;
1054 /* default setup (will be repeated at every open) */
1055 zoran_open_init_params(zr
);
1057 /* allocate memory *before* doing anything to the hardware
1058 * in case allocation fails */
1059 zr
->stat_com
= kzalloc(BUZ_NUM_STAT_COM
* 4, GFP_KERNEL
);
1060 zr
->video_dev
= kmalloc(sizeof(struct video_device
), GFP_KERNEL
);
1061 if (!zr
->stat_com
|| !zr
->video_dev
) {
1064 "%s: %s - kmalloc (STAT_COM) failed\n",
1065 ZR_DEVNAME(zr
), __func__
);
1069 for (j
= 0; j
< BUZ_NUM_STAT_COM
; j
++) {
1070 zr
->stat_com
[j
] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
1074 * Now add the template and register the device unit.
1076 memcpy(zr
->video_dev
, &zoran_template
, sizeof(zoran_template
));
1077 zr
->video_dev
->parent
= &zr
->pci_dev
->dev
;
1078 strcpy(zr
->video_dev
->name
, ZR_DEVNAME(zr
));
1079 err
= video_register_device(zr
->video_dev
, VFL_TYPE_GRABBER
, video_nr
[zr
->id
]);
1082 video_set_drvdata(zr
->video_dev
, zr
);
1084 zoran_init_hardware(zr
);
1085 if (zr36067_debug
> 2)
1086 detect_guest_activity(zr
);
1087 test_interrupts(zr
);
1088 if (!pass_through
) {
1089 decoder_call(zr
, video
, s_stream
, 0);
1090 encoder_call(zr
, video
, s_routing
, 2, 0, 0);
1093 zr
->zoran_proc
= NULL
;
1094 zr
->initialized
= 1;
1098 kfree(zr
->stat_com
);
1099 kfree(zr
->video_dev
);
1103 static void __devexit
zoran_remove(struct pci_dev
*pdev
)
1105 struct v4l2_device
*v4l2_dev
= dev_get_drvdata(&pdev
->dev
);
1106 struct zoran
*zr
= to_zoran(v4l2_dev
);
1108 if (!zr
->initialized
)
1111 /* unregister videocodec bus */
1113 struct videocodec_master
*master
= zr
->codec
->master_data
;
1115 videocodec_detach(zr
->codec
);
1119 struct videocodec_master
*master
= zr
->vfe
->master_data
;
1121 videocodec_detach(zr
->vfe
);
1125 /* unregister i2c bus */
1126 zoran_unregister_i2c(zr
);
1127 /* disable PCI bus-mastering */
1128 zoran_set_pci_master(zr
, 0);
1129 /* put chip into reset */
1130 btwrite(0, ZR36057_SPGPPCR
);
1131 free_irq(zr
->pci_dev
->irq
, zr
);
1132 /* unmap and free memory */
1133 kfree(zr
->stat_com
);
1134 zoran_proc_cleanup(zr
);
1135 iounmap(zr
->zr36057_mem
);
1136 pci_disable_device(zr
->pci_dev
);
1137 video_unregister_device(zr
->video_dev
);
1139 v4l2_device_unregister(&zr
->v4l2_dev
);
1144 zoran_vdev_release (struct video_device
*vdev
)
1149 static struct videocodec_master
* __devinit
1150 zoran_setup_videocodec (struct zoran
*zr
,
1153 struct videocodec_master
*m
= NULL
;
1155 m
= kmalloc(sizeof(struct videocodec_master
), GFP_KERNEL
);
1157 dprintk(1, KERN_ERR
"%s: %s - no memory\n",
1158 ZR_DEVNAME(zr
), __func__
);
1162 /* magic and type are unused for master struct. Makes sense only at
1164 In the past, .type were initialized to the old V4L1 .hardware
1165 value, as VID_HARDWARE_ZR36067
1170 m
->flags
= CODEC_FLAG_ENCODER
| CODEC_FLAG_DECODER
;
1171 strlcpy(m
->name
, ZR_DEVNAME(zr
), sizeof(m
->name
));
1176 case CODEC_TYPE_ZR36060
:
1177 m
->readreg
= zr36060_read
;
1178 m
->writereg
= zr36060_write
;
1179 m
->flags
|= CODEC_FLAG_JPEG
| CODEC_FLAG_VFE
;
1181 case CODEC_TYPE_ZR36050
:
1182 m
->readreg
= zr36050_read
;
1183 m
->writereg
= zr36050_write
;
1184 m
->flags
|= CODEC_FLAG_JPEG
;
1186 case CODEC_TYPE_ZR36016
:
1187 m
->readreg
= zr36016_read
;
1188 m
->writereg
= zr36016_write
;
1189 m
->flags
|= CODEC_FLAG_VFE
;
1196 static void zoran_subdev_notify(struct v4l2_subdev
*sd
, unsigned int cmd
, void *arg
)
1198 struct zoran
*zr
= to_zoran(sd
->v4l2_dev
);
1200 /* Bt819 needs to reset its FIFO buffer using #FRST pin and
1201 LML33 card uses GPIO(7) for that. */
1202 if (cmd
== BT819_FIFO_RESET_LOW
)
1204 else if (cmd
== BT819_FIFO_RESET_HIGH
)
1209 * Scan for a Buz card (actually for the PCI controller ZR36057),
1210 * request the irq and map the io memory
1212 static int __devinit
zoran_probe(struct pci_dev
*pdev
,
1213 const struct pci_device_id
*ent
)
1215 unsigned char latency
, need_latency
;
1218 struct videocodec_master
*master_vfe
= NULL
;
1219 struct videocodec_master
*master_codec
= NULL
;
1221 char *codec_name
, *vfe_name
;
1226 if (nr
>= BUZ_MAX
) {
1227 dprintk(1, KERN_ERR
"%s: driver limited to %d card(s) maximum\n",
1228 ZORAN_NAME
, BUZ_MAX
);
1232 zr
= kzalloc(sizeof(struct zoran
), GFP_KERNEL
);
1234 dprintk(1, KERN_ERR
"%s: %s - kzalloc failed\n",
1235 ZORAN_NAME
, __func__
);
1238 zr
->v4l2_dev
.notify
= zoran_subdev_notify
;
1239 if (v4l2_device_register(&pdev
->dev
, &zr
->v4l2_dev
))
1243 snprintf(ZR_DEVNAME(zr
), sizeof(ZR_DEVNAME(zr
)), "MJPEG[%u]", zr
->id
);
1244 spin_lock_init(&zr
->spinlock
);
1245 mutex_init(&zr
->resource_lock
);
1246 if (pci_enable_device(pdev
))
1248 pci_read_config_byte(zr
->pci_dev
, PCI_CLASS_REVISION
, &zr
->revision
);
1252 "%s: Zoran ZR360%c7 (rev %d), irq: %d, memory: 0x%08llx\n",
1253 ZR_DEVNAME(zr
), zr
->revision
< 2 ? '5' : '6', zr
->revision
,
1254 zr
->pci_dev
->irq
, (uint64_t)pci_resource_start(zr
->pci_dev
, 0));
1255 if (zr
->revision
>= 2) {
1258 "%s: Subsystem vendor=0x%04x id=0x%04x\n",
1259 ZR_DEVNAME(zr
), zr
->pci_dev
->subsystem_vendor
,
1260 zr
->pci_dev
->subsystem_device
);
1263 /* Use auto-detected card type? */
1264 if (card
[nr
] == -1) {
1265 if (zr
->revision
< 2) {
1268 "%s: No card type specified, please use the card=X module parameter\n",
1272 "%s: It is not possible to auto-detect ZR36057 based cards\n",
1277 card_num
= ent
->driver_data
;
1278 if (card_num
>= NUM_CARDS
) {
1281 "%s: Unknown card, try specifying card=X module parameter\n",
1287 "%s: %s() - card %s detected\n",
1288 ZR_DEVNAME(zr
), __func__
, zoran_cards
[card_num
].name
);
1290 card_num
= card
[nr
];
1291 if (card_num
>= NUM_CARDS
|| card_num
< 0) {
1294 "%s: User specified card type %d out of range (0 .. %d)\n",
1295 ZR_DEVNAME(zr
), card_num
, NUM_CARDS
- 1);
1300 /* even though we make this a non pointer and thus
1301 * theoretically allow for making changes to this struct
1302 * on a per-individual card basis at runtime, this is
1303 * strongly discouraged. This structure is intended to
1304 * keep general card information, no settings or anything */
1305 zr
->card
= zoran_cards
[card_num
];
1306 snprintf(ZR_DEVNAME(zr
), sizeof(ZR_DEVNAME(zr
)),
1307 "%s[%u]", zr
->card
.name
, zr
->id
);
1309 zr
->zr36057_mem
= pci_ioremap_bar(zr
->pci_dev
, 0);
1310 if (!zr
->zr36057_mem
) {
1311 dprintk(1, KERN_ERR
"%s: %s() - ioremap failed\n",
1312 ZR_DEVNAME(zr
), __func__
);
1316 result
= request_irq(zr
->pci_dev
->irq
, zoran_irq
,
1317 IRQF_SHARED
| IRQF_DISABLED
, ZR_DEVNAME(zr
), zr
);
1319 if (result
== -EINVAL
) {
1322 "%s: %s - bad irq number or handler\n",
1323 ZR_DEVNAME(zr
), __func__
);
1324 } else if (result
== -EBUSY
) {
1327 "%s: %s - IRQ %d busy, change your PnP config in BIOS\n",
1328 ZR_DEVNAME(zr
), __func__
, zr
->pci_dev
->irq
);
1332 "%s: %s - can't assign irq, error code %d\n",
1333 ZR_DEVNAME(zr
), __func__
, result
);
1338 /* set PCI latency timer */
1339 pci_read_config_byte(zr
->pci_dev
, PCI_LATENCY_TIMER
,
1341 need_latency
= zr
->revision
> 1 ? 32 : 48;
1342 if (latency
!= need_latency
) {
1343 dprintk(2, KERN_INFO
"%s: Changing PCI latency from %d to %d\n",
1344 ZR_DEVNAME(zr
), latency
, need_latency
);
1345 pci_write_config_byte(zr
->pci_dev
, PCI_LATENCY_TIMER
,
1349 zr36057_restart(zr
);
1351 dprintk(2, KERN_INFO
"%s: Initializing i2c bus...\n",
1354 if (zoran_register_i2c(zr
) < 0) {
1355 dprintk(1, KERN_ERR
"%s: %s - can't initialize i2c bus\n",
1356 ZR_DEVNAME(zr
), __func__
);
1360 zr
->decoder
= v4l2_i2c_new_subdev(&zr
->v4l2_dev
,
1361 &zr
->i2c_adapter
, zr
->card
.mod_decoder
, zr
->card
.i2c_decoder
,
1362 0, zr
->card
.addrs_decoder
);
1364 if (zr
->card
.mod_encoder
)
1365 zr
->encoder
= v4l2_i2c_new_subdev(&zr
->v4l2_dev
,
1367 zr
->card
.mod_encoder
, zr
->card
.i2c_encoder
,
1368 0, zr
->card
.addrs_encoder
);
1371 KERN_INFO
"%s: Initializing videocodec bus...\n",
1374 if (zr
->card
.video_codec
) {
1375 codec_name
= codecid_to_modulename(zr
->card
.video_codec
);
1377 result
= request_module(codec_name
);
1381 "%s: failed to load modules %s: %d\n",
1382 ZR_DEVNAME(zr
), codec_name
, result
);
1386 if (zr
->card
.video_vfe
) {
1387 vfe_name
= codecid_to_modulename(zr
->card
.video_vfe
);
1389 result
= request_module(vfe_name
);
1393 "%s: failed to load modules %s: %d\n",
1394 ZR_DEVNAME(zr
), vfe_name
, result
);
1399 /* reset JPEG codec */
1400 jpeg_codec_sleep(zr
, 1);
1401 jpeg_codec_reset(zr
);
1402 /* video bus enabled */
1403 /* display codec revision */
1404 if (zr
->card
.video_codec
!= 0) {
1405 master_codec
= zoran_setup_videocodec(zr
, zr
->card
.video_codec
);
1408 zr
->codec
= videocodec_attach(master_codec
);
1410 dprintk(1, KERN_ERR
"%s: %s - no codec found\n",
1411 ZR_DEVNAME(zr
), __func__
);
1414 if (zr
->codec
->type
!= zr
->card
.video_codec
) {
1415 dprintk(1, KERN_ERR
"%s: %s - wrong codec\n",
1416 ZR_DEVNAME(zr
), __func__
);
1417 goto zr_detach_codec
;
1420 if (zr
->card
.video_vfe
!= 0) {
1421 master_vfe
= zoran_setup_videocodec(zr
, zr
->card
.video_vfe
);
1423 goto zr_detach_codec
;
1424 zr
->vfe
= videocodec_attach(master_vfe
);
1426 dprintk(1, KERN_ERR
"%s: %s - no VFE found\n",
1427 ZR_DEVNAME(zr
), __func__
);
1430 if (zr
->vfe
->type
!= zr
->card
.video_vfe
) {
1431 dprintk(1, KERN_ERR
"%s: %s = wrong VFE\n",
1432 ZR_DEVNAME(zr
), __func__
);
1437 /* take care of Natoma chipset and a revision 1 zr36057 */
1438 if ((pci_pci_problems
& PCIPCI_NATOMA
) && zr
->revision
<= 1) {
1439 zr
->jpg_buffers
.need_contiguous
= 1;
1440 dprintk(1, KERN_INFO
1441 "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
1445 if (zr36057_init(zr
) < 0)
1448 zoran_proc_init(zr
);
1453 videocodec_detach(zr
->vfe
);
1457 videocodec_detach(zr
->codec
);
1459 kfree(master_codec
);
1461 zoran_unregister_i2c(zr
);
1463 btwrite(0, ZR36057_SPGPPCR
);
1464 free_irq(zr
->pci_dev
->irq
, zr
);
1466 iounmap(zr
->zr36057_mem
);
1468 v4l2_device_unregister(&zr
->v4l2_dev
);
1475 static struct pci_driver zoran_driver
= {
1477 .id_table
= zr36067_pci_tbl
,
1478 .probe
= zoran_probe
,
1479 .remove
= __devexit_p(zoran_remove
),
1482 static int __init
zoran_init(void)
1486 printk(KERN_INFO
"Zoran MJPEG board driver version %d.%d.%d\n",
1487 MAJOR_VERSION
, MINOR_VERSION
, RELEASE_VERSION
);
1489 /* check the parameters we have been given, adjust if necessary */
1492 if (v4l_nbufs
> VIDEO_MAX_FRAME
)
1493 v4l_nbufs
= VIDEO_MAX_FRAME
;
1494 /* The user specfies the in KB, we want them in byte
1495 * (and page aligned) */
1496 v4l_bufsize
= PAGE_ALIGN(v4l_bufsize
* 1024);
1497 if (v4l_bufsize
< 32768)
1498 v4l_bufsize
= 32768;
1499 /* 2 MB is arbitrary but sufficient for the maximum possible images */
1500 if (v4l_bufsize
> 2048 * 1024)
1501 v4l_bufsize
= 2048 * 1024;
1504 if (jpg_nbufs
> BUZ_MAX_FRAME
)
1505 jpg_nbufs
= BUZ_MAX_FRAME
;
1506 jpg_bufsize
= PAGE_ALIGN(jpg_bufsize
* 1024);
1507 if (jpg_bufsize
< 8192)
1509 if (jpg_bufsize
> (512 * 1024))
1510 jpg_bufsize
= 512 * 1024;
1511 /* Use parameter for vidmem or try to find a video card */
1515 "%s: Using supplied video memory base address @ 0x%lx\n",
1516 ZORAN_NAME
, vidmem
);
1519 /* some mainboards might not do PCI-PCI data transfer well */
1520 if (pci_pci_problems
& (PCIPCI_FAIL
|PCIAGP_FAIL
|PCIPCI_ALIMAGIK
)) {
1523 "%s: chipset does not support reliable PCI-PCI DMA\n",
1527 res
= pci_register_driver(&zoran_driver
);
1531 "%s: Unable to register ZR36057 driver\n",
1539 static void __exit
zoran_exit(void)
1541 pci_unregister_driver(&zoran_driver
);
1544 module_init(zoran_init
);
1545 module_exit(zoran_exit
);