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>
37 #include <linux/slab.h>
39 #include <linux/proc_fs.h>
40 #include <linux/i2c.h>
41 #include <linux/i2c-algo-bit.h>
42 #include <linux/videodev2.h>
43 #include <linux/spinlock.h>
44 #include <linux/sem.h>
45 #include <linux/kmod.h>
46 #include <linux/wait.h>
48 #include <linux/pci.h>
49 #include <linux/interrupt.h>
50 #include <linux/mutex.h>
52 #include <media/v4l2-common.h>
53 #include <media/bt819.h>
55 #include "videocodec.h"
57 #include "zoran_card.h"
58 #include "zoran_device.h"
59 #include "zoran_procfs.h"
61 extern const struct zoran_format zoran_formats
[];
63 static int card
[BUZ_MAX
] = { [0 ... (BUZ_MAX
-1)] = -1 };
64 module_param_array(card
, int, NULL
, 0444);
65 MODULE_PARM_DESC(card
, "Card type");
67 static int encoder
[BUZ_MAX
] = { [0 ... (BUZ_MAX
-1)] = -1 };
68 module_param_array(encoder
, int, NULL
, 0444);
69 MODULE_PARM_DESC(encoder
, "Video encoder chip");
71 static int decoder
[BUZ_MAX
] = { [0 ... (BUZ_MAX
-1)] = -1 };
72 module_param_array(decoder
, int, NULL
, 0444);
73 MODULE_PARM_DESC(decoder
, "Video decoder chip");
76 The video mem address of the video card.
77 The driver has a little database for some videocards
78 to determine it from there. If your video card is not in there
79 you have either to give it to the driver as a parameter
80 or set in in a VIDIOCSFBUF ioctl
83 static unsigned long vidmem
; /* default = 0 - Video memory base address */
84 module_param(vidmem
, ulong
, 0444);
85 MODULE_PARM_DESC(vidmem
, "Default video memory base address");
88 Default input and video norm at startup of the driver.
91 static unsigned int default_input
; /* default 0 = Composite, 1 = S-Video */
92 module_param(default_input
, uint
, 0444);
93 MODULE_PARM_DESC(default_input
,
94 "Default input (0=Composite, 1=S-Video, 2=Internal)");
96 static int default_mux
= 1; /* 6 Eyes input selection */
97 module_param(default_mux
, int, 0644);
98 MODULE_PARM_DESC(default_mux
,
99 "Default 6 Eyes mux setting (Input selection)");
101 static int default_norm
; /* default 0 = PAL, 1 = NTSC 2 = SECAM */
102 module_param(default_norm
, int, 0444);
103 MODULE_PARM_DESC(default_norm
, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
105 /* /dev/videoN, -1 for autodetect */
106 static int video_nr
[BUZ_MAX
] = { [0 ... (BUZ_MAX
-1)] = -1 };
107 module_param_array(video_nr
, int, NULL
, 0444);
108 MODULE_PARM_DESC(video_nr
, "Video device number (-1=Auto)");
111 int v4l_bufsize
= 864; /* Everybody should be able to work with this setting */
112 module_param(v4l_nbufs
, int, 0644);
113 MODULE_PARM_DESC(v4l_nbufs
, "Maximum number of V4L buffers to use");
114 module_param(v4l_bufsize
, int, 0644);
115 MODULE_PARM_DESC(v4l_bufsize
, "Maximum size per V4L buffer (in kB)");
118 int jpg_bufsize
= 512; /* max size for 100% quality full-PAL frame */
119 module_param(jpg_nbufs
, int, 0644);
120 MODULE_PARM_DESC(jpg_nbufs
, "Maximum number of JPG buffers to use");
121 module_param(jpg_bufsize
, int, 0644);
122 MODULE_PARM_DESC(jpg_bufsize
, "Maximum size per JPG buffer (in kB)");
124 int pass_through
= 0; /* 1=Pass through TV signal when device is not used */
125 /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */
126 module_param(pass_through
, int, 0644);
127 MODULE_PARM_DESC(pass_through
,
128 "Pass TV signal through to TV-out when idling");
130 int zr36067_debug
= 1;
131 module_param_named(debug
, zr36067_debug
, int, 0644);
132 MODULE_PARM_DESC(debug
, "Debug level (0-5)");
134 MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
135 MODULE_AUTHOR("Serguei Miridonov");
136 MODULE_LICENSE("GPL");
138 #define ZR_DEVICE(subven, subdev, data) { \
139 .vendor = PCI_VENDOR_ID_ZORAN, .device = PCI_DEVICE_ID_ZORAN_36057, \
140 .subvendor = (subven), .subdevice = (subdev), .driver_data = (data) }
142 static struct pci_device_id zr36067_pci_tbl
[] = {
143 ZR_DEVICE(PCI_VENDOR_ID_MIRO
, PCI_DEVICE_ID_MIRO_DC10PLUS
, DC10plus
),
144 ZR_DEVICE(PCI_VENDOR_ID_MIRO
, PCI_DEVICE_ID_MIRO_DC30PLUS
, DC30plus
),
145 ZR_DEVICE(PCI_VENDOR_ID_ELECTRONICDESIGNGMBH
, PCI_DEVICE_ID_LML_33R10
, LML33R10
),
146 ZR_DEVICE(PCI_VENDOR_ID_IOMEGA
, PCI_DEVICE_ID_IOMEGA_BUZ
, BUZ
),
147 ZR_DEVICE(PCI_ANY_ID
, PCI_ANY_ID
, NUM_CARDS
),
150 MODULE_DEVICE_TABLE(pci
, zr36067_pci_tbl
);
152 static unsigned int zoran_num
; /* number of cards found */
154 /* videocodec bus functions ZR36060 */
156 zr36060_read (struct videocodec
*codec
,
159 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
162 if (post_office_wait(zr
)
163 || post_office_write(zr
, 0, 1, reg
>> 8)
164 || post_office_write(zr
, 0, 2, reg
& 0xff)) {
168 data
= post_office_read(zr
, 0, 3) & 0xff;
173 zr36060_write (struct videocodec
*codec
,
177 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
179 if (post_office_wait(zr
)
180 || post_office_write(zr
, 0, 1, reg
>> 8)
181 || post_office_write(zr
, 0, 2, reg
& 0xff)) {
185 post_office_write(zr
, 0, 3, val
& 0xff);
188 /* videocodec bus functions ZR36050 */
190 zr36050_read (struct videocodec
*codec
,
193 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
196 if (post_office_wait(zr
)
197 || post_office_write(zr
, 1, 0, reg
>> 2)) { // reg. HIGHBYTES
201 data
= post_office_read(zr
, 0, reg
& 0x03) & 0xff; // reg. LOWBYTES + read
206 zr36050_write (struct videocodec
*codec
,
210 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
212 if (post_office_wait(zr
)
213 || post_office_write(zr
, 1, 0, reg
>> 2)) { // reg. HIGHBYTES
217 post_office_write(zr
, 0, reg
& 0x03, val
& 0xff); // reg. LOWBYTES + wr. data
220 /* videocodec bus functions ZR36016 */
222 zr36016_read (struct videocodec
*codec
,
225 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
228 if (post_office_wait(zr
)) {
232 data
= post_office_read(zr
, 2, reg
& 0x03) & 0xff; // read
236 /* hack for in zoran_device.c */
238 zr36016_write (struct videocodec
*codec
,
242 struct zoran
*zr
= (struct zoran
*) codec
->master_data
->data
;
244 if (post_office_wait(zr
)) {
248 post_office_write(zr
, 2, reg
& 0x03, val
& 0x0ff); // wr. data
252 * Board specific information
256 dc10_init (struct zoran
*zr
)
258 dprintk(3, KERN_DEBUG
"%s: %s\n", ZR_DEVNAME(zr
), __func__
);
260 /* Pixel clock selection */
263 /* Enable the video bus sync signals */
268 dc10plus_init (struct zoran
*zr
)
270 dprintk(3, KERN_DEBUG
"%s: %s\n", ZR_DEVNAME(zr
), __func__
);
274 buz_init (struct zoran
*zr
)
276 dprintk(3, KERN_DEBUG
"%s: %s\n", ZR_DEVNAME(zr
), __func__
);
278 /* some stuff from Iomega */
279 pci_write_config_dword(zr
->pci_dev
, 0xfc, 0x90680f15);
280 pci_write_config_dword(zr
->pci_dev
, 0x0c, 0x00012020);
281 pci_write_config_dword(zr
->pci_dev
, 0xe8, 0xc0200000);
285 lml33_init (struct zoran
*zr
)
287 dprintk(3, KERN_DEBUG
"%s: %s\n", ZR_DEVNAME(zr
), __func__
);
289 GPIO(zr
, 2, 1); // Set Composite input/output
293 avs6eyes_init (struct zoran
*zr
)
295 // AverMedia 6-Eyes original driver by Christer Weinigel
297 // Lifted straight from Christer's old driver and
298 // modified slightly by Martin Samuelsson.
300 int mux
= default_mux
; /* 1 = BT866, 7 = VID1 */
302 GPIO(zr
, 4, 1); /* Bt866 SLEEP on */
305 GPIO(zr
, 0, 1); /* ZR36060 /RESET on */
306 GPIO(zr
, 1, 0); /* ZR36060 /SLEEP on */
307 GPIO(zr
, 2, mux
& 1); /* MUX S0 */
308 GPIO(zr
, 3, 0); /* /FRAME on */
309 GPIO(zr
, 4, 0); /* Bt866 SLEEP off */
310 GPIO(zr
, 5, mux
& 2); /* MUX S1 */
311 GPIO(zr
, 6, 0); /* ? */
312 GPIO(zr
, 7, mux
& 4); /* MUX S2 */
317 codecid_to_modulename (u16 codecid
)
322 case CODEC_TYPE_ZR36060
:
325 case CODEC_TYPE_ZR36050
:
328 case CODEC_TYPE_ZR36016
:
337 // u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
340 static struct tvnorm f50sqpixel
= { 944, 768, 83, 880, 625, 576, 16 };
341 static struct tvnorm f60sqpixel
= { 780, 640, 51, 716, 525, 480, 12 };
342 static struct tvnorm f50ccir601
= { 864, 720, 75, 804, 625, 576, 18 };
343 static struct tvnorm f60ccir601
= { 858, 720, 57, 788, 525, 480, 16 };
345 static struct tvnorm f50ccir601_lml33
= { 864, 720, 75+34, 804, 625, 576, 18 };
346 static struct tvnorm f60ccir601_lml33
= { 858, 720, 57+34, 788, 525, 480, 16 };
348 /* The DC10 (57/16/50) uses VActive as HSync, so HStart must be 0 */
349 static struct tvnorm f50sqpixel_dc10
= { 944, 768, 0, 880, 625, 576, 0 };
350 static struct tvnorm f60sqpixel_dc10
= { 780, 640, 0, 716, 525, 480, 12 };
352 static struct tvnorm f50ccir601_lm33r10
= { 864, 720, 74+54, 804, 625, 576, 18 };
353 static struct tvnorm f60ccir601_lm33r10
= { 858, 720, 56+54, 788, 525, 480, 16 };
355 static struct tvnorm f50ccir601_avs6eyes
= { 864, 720, 74, 804, 625, 576, 18 };
356 static struct tvnorm f60ccir601_avs6eyes
= { 858, 720, 56, 788, 525, 480, 16 };
358 static const unsigned short vpx3220_addrs
[] = { 0x43, 0x47, I2C_CLIENT_END
};
359 static const unsigned short saa7110_addrs
[] = { 0x4e, 0x4f, I2C_CLIENT_END
};
360 static const unsigned short saa7111_addrs
[] = { 0x25, 0x24, I2C_CLIENT_END
};
361 static const unsigned short saa7114_addrs
[] = { 0x21, 0x20, I2C_CLIENT_END
};
362 static const unsigned short adv717x_addrs
[] = { 0x6a, 0x6b, 0x2a, 0x2b, I2C_CLIENT_END
};
363 static const unsigned short ks0127_addrs
[] = { 0x6c, 0x6d, I2C_CLIENT_END
};
364 static const unsigned short saa7185_addrs
[] = { 0x44, I2C_CLIENT_END
};
365 static const unsigned short bt819_addrs
[] = { 0x45, I2C_CLIENT_END
};
366 static const unsigned short bt856_addrs
[] = { 0x44, I2C_CLIENT_END
};
367 static const unsigned short bt866_addrs
[] = { 0x44, I2C_CLIENT_END
};
369 static struct card_info zoran_cards
[NUM_CARDS
] __devinitdata
= {
373 .i2c_decoder
= "vpx3220a",
374 .mod_decoder
= "vpx3220",
375 .addrs_decoder
= vpx3220_addrs
,
376 .video_codec
= CODEC_TYPE_ZR36050
,
377 .video_vfe
= CODEC_TYPE_ZR36016
,
383 { 0, "Internal/comp" }
385 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
392 .vsync_int
= ZR36057_ISR_GIRQ1
,
393 .gpio
= { 2, 1, -1, 3, 7, 0, 4, 5 },
394 .gpio_pol
= { 0, 0, 0, 1, 0, 0, 0, 0 },
396 .vfe_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
397 .gws_not_connected
= 0,
403 .i2c_decoder
= "saa7110",
404 .mod_decoder
= "saa7110",
405 .addrs_decoder
= saa7110_addrs
,
406 .i2c_encoder
= "adv7175",
407 .mod_encoder
= "adv7175",
408 .addrs_encoder
= adv717x_addrs
,
409 .video_codec
= CODEC_TYPE_ZR36060
,
415 { 5, "Internal/comp" }
417 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
422 .jpeg_int
= ZR36057_ISR_GIRQ0
,
423 .vsync_int
= ZR36057_ISR_GIRQ1
,
424 .gpio
= { 3, 0, 6, 1, 2, -1, 4, 5 },
425 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
427 .vfe_pol
= { 1, 1, 1, 1, 0, 0, 0, 0 },
428 .gws_not_connected
= 0,
430 .init
= &dc10plus_init
,
434 .i2c_decoder
= "saa7110",
435 .mod_decoder
= "saa7110",
436 .addrs_decoder
= saa7110_addrs
,
437 .i2c_encoder
= "adv7175",
438 .mod_encoder
= "adv7175",
439 .addrs_encoder
= adv717x_addrs
,
440 .video_codec
= CODEC_TYPE_ZR36060
,
446 { 5, "Internal/comp" }
448 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
454 .jpeg_int
= ZR36057_ISR_GIRQ0
,
455 .vsync_int
= ZR36057_ISR_GIRQ1
,
456 .gpio
= { 3, 0, 6, 1, 2, -1, 4, 5 },
457 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
459 .vfe_pol
= { 1, 1, 1, 1, 0, 0, 0, 0 },
460 .gws_not_connected
= 0,
462 .init
= &dc10plus_init
,
466 .i2c_decoder
= "vpx3220a",
467 .mod_decoder
= "vpx3220",
468 .addrs_decoder
= vpx3220_addrs
,
469 .i2c_encoder
= "adv7175",
470 .mod_encoder
= "adv7175",
471 .addrs_encoder
= adv717x_addrs
,
472 .video_codec
= CODEC_TYPE_ZR36050
,
473 .video_vfe
= CODEC_TYPE_ZR36016
,
479 { 0, "Internal/comp" }
481 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
488 .vsync_int
= ZR36057_ISR_GIRQ1
,
489 .gpio
= { 2, 1, -1, 3, 7, 0, 4, 5 },
490 .gpio_pol
= { 0, 0, 0, 1, 0, 0, 0, 0 },
492 .vfe_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
493 .gws_not_connected
= 0,
499 .i2c_decoder
= "vpx3220a",
500 .mod_decoder
= "vpx3220",
501 .addrs_decoder
= vpx3220_addrs
,
502 .i2c_encoder
= "adv7175",
503 .mod_encoder
= "adv7175",
504 .addrs_encoder
= adv717x_addrs
,
505 .video_codec
= CODEC_TYPE_ZR36050
,
506 .video_vfe
= CODEC_TYPE_ZR36016
,
512 { 0, "Internal/comp" }
514 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
521 .vsync_int
= ZR36057_ISR_GIRQ1
,
522 .gpio
= { 2, 1, -1, 3, 7, 0, 4, 5 },
523 .gpio_pol
= { 0, 0, 0, 1, 0, 0, 0, 0 },
525 .vfe_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
526 .gws_not_connected
= 0,
532 .i2c_decoder
= "bt819a",
533 .mod_decoder
= "bt819",
534 .addrs_decoder
= bt819_addrs
,
535 .i2c_encoder
= "bt856",
536 .mod_encoder
= "bt856",
537 .addrs_encoder
= bt856_addrs
,
538 .video_codec
= CODEC_TYPE_ZR36060
,
545 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
,
551 .jpeg_int
= ZR36057_ISR_GIRQ1
,
552 .vsync_int
= ZR36057_ISR_GIRQ0
,
553 .gpio
= { 1, -1, 3, 5, 7, -1, -1, -1 },
554 .gpio_pol
= { 0, 0, 0, 0, 1, 0, 0, 0 },
556 .vfe_pol
= { 1, 1, 0, 0, 0, 1, 0, 0 },
557 .gws_not_connected
= 1,
563 .i2c_decoder
= "saa7114",
564 .mod_decoder
= "saa7115",
565 .addrs_decoder
= saa7114_addrs
,
566 .i2c_encoder
= "adv7170",
567 .mod_encoder
= "adv7170",
568 .addrs_encoder
= adv717x_addrs
,
569 .video_codec
= CODEC_TYPE_ZR36060
,
576 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
,
582 .jpeg_int
= ZR36057_ISR_GIRQ1
,
583 .vsync_int
= ZR36057_ISR_GIRQ0
,
584 .gpio
= { 1, -1, 3, 5, 7, -1, -1, -1 },
585 .gpio_pol
= { 0, 0, 0, 0, 1, 0, 0, 0 },
587 .vfe_pol
= { 1, 1, 0, 0, 0, 1, 0, 0 },
588 .gws_not_connected
= 1,
594 .i2c_decoder
= "saa7111",
595 .mod_decoder
= "saa7115",
596 .addrs_decoder
= saa7111_addrs
,
597 .i2c_encoder
= "saa7185",
598 .mod_encoder
= "saa7185",
599 .addrs_encoder
= saa7185_addrs
,
600 .video_codec
= CODEC_TYPE_ZR36060
,
607 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
|V4L2_STD_SECAM
,
613 .jpeg_int
= ZR36057_ISR_GIRQ1
,
614 .vsync_int
= ZR36057_ISR_GIRQ0
,
615 .gpio
= { 1, -1, 3, -1, -1, -1, -1, -1 },
616 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
618 .vfe_pol
= { 1, 1, 0, 0, 0, 1, 0, 0 },
619 .gws_not_connected
= 1,
625 /* AverMedia chose not to brand the 6-Eyes. Thus it
626 can't be autodetected, and requires card=x. */
627 .i2c_decoder
= "ks0127",
628 .mod_decoder
= "ks0127",
629 .addrs_decoder
= ks0127_addrs
,
630 .i2c_encoder
= "bt866",
631 .mod_encoder
= "bt866",
632 .addrs_encoder
= bt866_addrs
,
633 .video_codec
= CODEC_TYPE_ZR36060
,
637 { 0, "Composite 1" },
638 { 1, "Composite 2" },
639 { 2, "Composite 3" },
640 { 4, "Composite 4" },
641 { 5, "Composite 5" },
642 { 6, "Composite 6" },
648 .norms
= V4L2_STD_NTSC
|V4L2_STD_PAL
,
650 &f50ccir601_avs6eyes
,
651 &f60ccir601_avs6eyes
,
654 .jpeg_int
= ZR36057_ISR_GIRQ1
,
655 .vsync_int
= ZR36057_ISR_GIRQ0
,
656 .gpio
= { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
657 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
658 .gpcs
= { 3, 1 }, // Validity unknown /Sam
659 .vfe_pol
= { 1, 0, 0, 0, 0, 1, 0, 0 }, // Validity unknown /Sam
660 .gws_not_connected
= 1,
662 .init
= &avs6eyes_init
,
670 /* software I2C functions */
672 zoran_i2c_getsda (void *data
)
674 struct zoran
*zr
= (struct zoran
*) data
;
676 return (btread(ZR36057_I2CBR
) >> 1) & 1;
680 zoran_i2c_getscl (void *data
)
682 struct zoran
*zr
= (struct zoran
*) data
;
684 return btread(ZR36057_I2CBR
) & 1;
688 zoran_i2c_setsda (void *data
,
691 struct zoran
*zr
= (struct zoran
*) data
;
697 btwrite(zr
->i2cbr
, ZR36057_I2CBR
);
701 zoran_i2c_setscl (void *data
,
704 struct zoran
*zr
= (struct zoran
*) data
;
710 btwrite(zr
->i2cbr
, ZR36057_I2CBR
);
713 static const struct i2c_algo_bit_data zoran_i2c_bit_data_template
= {
714 .setsda
= zoran_i2c_setsda
,
715 .setscl
= zoran_i2c_setscl
,
716 .getsda
= zoran_i2c_getsda
,
717 .getscl
= zoran_i2c_getscl
,
723 zoran_register_i2c (struct zoran
*zr
)
725 memcpy(&zr
->i2c_algo
, &zoran_i2c_bit_data_template
,
726 sizeof(struct i2c_algo_bit_data
));
727 zr
->i2c_algo
.data
= zr
;
728 strlcpy(zr
->i2c_adapter
.name
, ZR_DEVNAME(zr
),
729 sizeof(zr
->i2c_adapter
.name
));
730 i2c_set_adapdata(&zr
->i2c_adapter
, &zr
->v4l2_dev
);
731 zr
->i2c_adapter
.algo_data
= &zr
->i2c_algo
;
732 zr
->i2c_adapter
.dev
.parent
= &zr
->pci_dev
->dev
;
733 return i2c_bit_add_bus(&zr
->i2c_adapter
);
737 zoran_unregister_i2c (struct zoran
*zr
)
739 i2c_del_adapter(&zr
->i2c_adapter
);
742 /* Check a zoran_params struct for correctness, insert default params */
745 zoran_check_jpg_settings (struct zoran
*zr
,
746 struct zoran_jpg_settings
*settings
,
749 int err
= 0, err0
= 0;
753 "%s: %s - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
754 ZR_DEVNAME(zr
), __func__
, settings
->decimation
, settings
->HorDcm
,
755 settings
->VerDcm
, settings
->TmpDcm
);
758 "%s: %s - x: %d, y: %d, w: %d, y: %d\n",
759 ZR_DEVNAME(zr
), __func__
, settings
->img_x
, settings
->img_y
,
760 settings
->img_width
, settings
->img_height
);
761 /* Check decimation, set default values for decimation = 1, 2, 4 */
762 switch (settings
->decimation
) {
765 settings
->HorDcm
= 1;
766 settings
->VerDcm
= 1;
767 settings
->TmpDcm
= 1;
768 settings
->field_per_buff
= 2;
771 settings
->img_width
= BUZ_MAX_WIDTH
;
772 settings
->img_height
= BUZ_MAX_HEIGHT
/ 2;
776 settings
->HorDcm
= 2;
777 settings
->VerDcm
= 1;
778 settings
->TmpDcm
= 2;
779 settings
->field_per_buff
= 1;
780 settings
->img_x
= (BUZ_MAX_WIDTH
== 720) ? 8 : 0;
782 settings
->img_width
=
783 (BUZ_MAX_WIDTH
== 720) ? 704 : BUZ_MAX_WIDTH
;
784 settings
->img_height
= BUZ_MAX_HEIGHT
/ 2;
788 if (zr
->card
.type
== DC10_new
) {
791 "%s: %s - HDec by 4 is not supported on the DC10\n",
792 ZR_DEVNAME(zr
), __func__
);
797 settings
->HorDcm
= 4;
798 settings
->VerDcm
= 2;
799 settings
->TmpDcm
= 2;
800 settings
->field_per_buff
= 1;
801 settings
->img_x
= (BUZ_MAX_WIDTH
== 720) ? 8 : 0;
803 settings
->img_width
=
804 (BUZ_MAX_WIDTH
== 720) ? 704 : BUZ_MAX_WIDTH
;
805 settings
->img_height
= BUZ_MAX_HEIGHT
/ 2;
809 /* We have to check the data the user has set */
811 if (settings
->HorDcm
!= 1 && settings
->HorDcm
!= 2 &&
812 (zr
->card
.type
== DC10_new
|| settings
->HorDcm
!= 4)) {
813 settings
->HorDcm
= clamp(settings
->HorDcm
, 1, 2);
816 if (settings
->VerDcm
!= 1 && settings
->VerDcm
!= 2) {
817 settings
->VerDcm
= clamp(settings
->VerDcm
, 1, 2);
820 if (settings
->TmpDcm
!= 1 && settings
->TmpDcm
!= 2) {
821 settings
->TmpDcm
= clamp(settings
->TmpDcm
, 1, 2);
824 if (settings
->field_per_buff
!= 1 &&
825 settings
->field_per_buff
!= 2) {
826 settings
->field_per_buff
= clamp(settings
->field_per_buff
, 1, 2);
829 if (settings
->img_x
< 0) {
833 if (settings
->img_y
< 0) {
837 if (settings
->img_width
< 0 || settings
->img_width
> BUZ_MAX_WIDTH
) {
838 settings
->img_width
= clamp(settings
->img_width
, 0, (int)BUZ_MAX_WIDTH
);
841 if (settings
->img_height
< 0 || settings
->img_height
> BUZ_MAX_HEIGHT
/ 2) {
842 settings
->img_height
= clamp(settings
->img_height
, 0, BUZ_MAX_HEIGHT
/ 2);
845 if (settings
->img_x
+ settings
->img_width
> BUZ_MAX_WIDTH
) {
846 settings
->img_x
= BUZ_MAX_WIDTH
- settings
->img_width
;
849 if (settings
->img_y
+ settings
->img_height
> BUZ_MAX_HEIGHT
/ 2) {
850 settings
->img_y
= BUZ_MAX_HEIGHT
/ 2 - settings
->img_height
;
853 if (settings
->img_width
% (16 * settings
->HorDcm
) != 0) {
854 settings
->img_width
-= settings
->img_width
% (16 * settings
->HorDcm
);
855 if (settings
->img_width
== 0)
856 settings
->img_width
= 16 * settings
->HorDcm
;
859 if (settings
->img_height
% (8 * settings
->VerDcm
) != 0) {
860 settings
->img_height
-= settings
->img_height
% (8 * settings
->VerDcm
);
861 if (settings
->img_height
== 0)
862 settings
->img_height
= 8 * settings
->VerDcm
;
869 "%s: %s - error in params for decimation = 0\n",
870 ZR_DEVNAME(zr
), __func__
);
877 "%s: %s - decimation = %d, must be 0, 1, 2 or 4\n",
878 ZR_DEVNAME(zr
), __func__
, settings
->decimation
);
883 if (settings
->jpg_comp
.quality
> 100)
884 settings
->jpg_comp
.quality
= 100;
885 if (settings
->jpg_comp
.quality
< 5)
886 settings
->jpg_comp
.quality
= 5;
887 if (settings
->jpg_comp
.APPn
< 0)
888 settings
->jpg_comp
.APPn
= 0;
889 if (settings
->jpg_comp
.APPn
> 15)
890 settings
->jpg_comp
.APPn
= 15;
891 if (settings
->jpg_comp
.APP_len
< 0)
892 settings
->jpg_comp
.APP_len
= 0;
893 if (settings
->jpg_comp
.APP_len
> 60)
894 settings
->jpg_comp
.APP_len
= 60;
895 if (settings
->jpg_comp
.COM_len
< 0)
896 settings
->jpg_comp
.COM_len
= 0;
897 if (settings
->jpg_comp
.COM_len
> 60)
898 settings
->jpg_comp
.COM_len
= 60;
905 zoran_open_init_params (struct zoran
*zr
)
909 /* User must explicitly set a window */
910 zr
->overlay_settings
.is_set
= 0;
911 zr
->overlay_mask
= NULL
;
912 zr
->overlay_active
= ZORAN_FREE
;
914 zr
->v4l_memgrab_active
= 0;
915 zr
->v4l_overlay_active
= 0;
916 zr
->v4l_grab_frame
= NO_GRAB_ACTIVE
;
917 zr
->v4l_grab_seq
= 0;
918 zr
->v4l_settings
.width
= 192;
919 zr
->v4l_settings
.height
= 144;
920 zr
->v4l_settings
.format
= &zoran_formats
[7]; /* YUY2 - YUV-4:2:2 packed */
921 zr
->v4l_settings
.bytesperline
=
922 zr
->v4l_settings
.width
*
923 ((zr
->v4l_settings
.format
->depth
+ 7) / 8);
925 /* DMA ring stuff for V4L */
926 zr
->v4l_pend_tail
= 0;
927 zr
->v4l_pend_head
= 0;
928 zr
->v4l_sync_tail
= 0;
929 zr
->v4l_buffers
.active
= ZORAN_FREE
;
930 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
931 zr
->v4l_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
933 zr
->v4l_buffers
.allocated
= 0;
935 for (i
= 0; i
< BUZ_MAX_FRAME
; i
++) {
936 zr
->jpg_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
938 zr
->jpg_buffers
.active
= ZORAN_FREE
;
939 zr
->jpg_buffers
.allocated
= 0;
940 /* Set necessary params and call zoran_check_jpg_settings to set the defaults */
941 zr
->jpg_settings
.decimation
= 1;
942 zr
->jpg_settings
.jpg_comp
.quality
= 50; /* default compression factor 8 */
943 if (zr
->card
.type
!= BUZ
)
944 zr
->jpg_settings
.odd_even
= 1;
946 zr
->jpg_settings
.odd_even
= 0;
947 zr
->jpg_settings
.jpg_comp
.APPn
= 0;
948 zr
->jpg_settings
.jpg_comp
.APP_len
= 0; /* No APPn marker */
949 memset(zr
->jpg_settings
.jpg_comp
.APP_data
, 0,
950 sizeof(zr
->jpg_settings
.jpg_comp
.APP_data
));
951 zr
->jpg_settings
.jpg_comp
.COM_len
= 0; /* No COM marker */
952 memset(zr
->jpg_settings
.jpg_comp
.COM_data
, 0,
953 sizeof(zr
->jpg_settings
.jpg_comp
.COM_data
));
954 zr
->jpg_settings
.jpg_comp
.jpeg_markers
=
955 JPEG_MARKER_DHT
| JPEG_MARKER_DQT
;
956 i
= zoran_check_jpg_settings(zr
, &zr
->jpg_settings
, 0);
958 dprintk(1, KERN_ERR
"%s: %s internal error\n",
959 ZR_DEVNAME(zr
), __func__
);
961 clear_interrupt_counters(zr
);
965 static void __devinit
966 test_interrupts (struct zoran
*zr
)
971 clear_interrupt_counters(zr
);
974 icr
= btread(ZR36057_ICR
);
975 btwrite(0x78000000 | ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
976 prepare_to_wait(&zr
->test_q
, &wait
, TASK_INTERRUPTIBLE
);
977 timeout
= schedule_timeout(HZ
);
978 finish_wait(&zr
->test_q
, &wait
);
979 btwrite(0, ZR36057_ICR
);
980 btwrite(0x78000000, ZR36057_ISR
);
982 dprintk(5, KERN_INFO
"%s: Testing interrupts...\n", ZR_DEVNAME(zr
));
984 dprintk(1, ": time spent: %d\n", 1 * HZ
- timeout
);
986 if (zr36067_debug
> 1)
987 print_interrupts(zr
);
988 btwrite(icr
, ZR36057_ICR
);
992 zr36057_init (struct zoran
*zr
)
998 "%s: %s - initializing card[%d], zr=%p\n",
999 ZR_DEVNAME(zr
), __func__
, zr
->id
, zr
);
1001 /* default setup of all parameters which will persist between opens */
1004 init_waitqueue_head(&zr
->v4l_capq
);
1005 init_waitqueue_head(&zr
->jpg_capq
);
1006 init_waitqueue_head(&zr
->test_q
);
1007 zr
->jpg_buffers
.allocated
= 0;
1008 zr
->v4l_buffers
.allocated
= 0;
1010 zr
->vbuf_base
= (void *) vidmem
;
1012 zr
->vbuf_height
= 0;
1014 zr
->vbuf_bytesperline
= 0;
1016 /* Avoid nonsense settings from user for default input/norm */
1017 if (default_norm
< 0 || default_norm
> 2)
1019 if (default_norm
== 0) {
1020 zr
->norm
= V4L2_STD_PAL
;
1021 zr
->timing
= zr
->card
.tvn
[0];
1022 } else if (default_norm
== 1) {
1023 zr
->norm
= V4L2_STD_NTSC
;
1024 zr
->timing
= zr
->card
.tvn
[1];
1026 zr
->norm
= V4L2_STD_SECAM
;
1027 zr
->timing
= zr
->card
.tvn
[2];
1029 if (zr
->timing
== NULL
) {
1032 "%s: %s - default TV standard not supported by hardware. PAL will be used.\n",
1033 ZR_DEVNAME(zr
), __func__
);
1034 zr
->norm
= V4L2_STD_PAL
;
1035 zr
->timing
= zr
->card
.tvn
[0];
1038 if (default_input
> zr
->card
.inputs
-1) {
1041 "%s: default_input value %d out of range (0-%d)\n",
1042 ZR_DEVNAME(zr
), default_input
, zr
->card
.inputs
-1);
1045 zr
->input
= default_input
;
1047 /* default setup (will be repeated at every open) */
1048 zoran_open_init_params(zr
);
1050 /* allocate memory *before* doing anything to the hardware
1051 * in case allocation fails */
1052 zr
->stat_com
= kzalloc(BUZ_NUM_STAT_COM
* 4, GFP_KERNEL
);
1053 zr
->video_dev
= kmalloc(sizeof(struct video_device
), GFP_KERNEL
);
1054 if (!zr
->stat_com
|| !zr
->video_dev
) {
1057 "%s: %s - kmalloc (STAT_COM) failed\n",
1058 ZR_DEVNAME(zr
), __func__
);
1062 for (j
= 0; j
< BUZ_NUM_STAT_COM
; j
++) {
1063 zr
->stat_com
[j
] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
1067 * Now add the template and register the device unit.
1069 memcpy(zr
->video_dev
, &zoran_template
, sizeof(zoran_template
));
1070 zr
->video_dev
->parent
= &zr
->pci_dev
->dev
;
1071 strcpy(zr
->video_dev
->name
, ZR_DEVNAME(zr
));
1072 err
= video_register_device(zr
->video_dev
, VFL_TYPE_GRABBER
, video_nr
[zr
->id
]);
1075 video_set_drvdata(zr
->video_dev
, zr
);
1077 zoran_init_hardware(zr
);
1078 if (zr36067_debug
> 2)
1079 detect_guest_activity(zr
);
1080 test_interrupts(zr
);
1081 if (!pass_through
) {
1082 decoder_call(zr
, video
, s_stream
, 0);
1083 encoder_call(zr
, video
, s_routing
, 2, 0, 0);
1086 zr
->zoran_proc
= NULL
;
1087 zr
->initialized
= 1;
1091 kfree(zr
->stat_com
);
1092 kfree(zr
->video_dev
);
1096 static void __devexit
zoran_remove(struct pci_dev
*pdev
)
1098 struct v4l2_device
*v4l2_dev
= dev_get_drvdata(&pdev
->dev
);
1099 struct zoran
*zr
= to_zoran(v4l2_dev
);
1101 if (!zr
->initialized
)
1104 /* unregister videocodec bus */
1106 struct videocodec_master
*master
= zr
->codec
->master_data
;
1108 videocodec_detach(zr
->codec
);
1112 struct videocodec_master
*master
= zr
->vfe
->master_data
;
1114 videocodec_detach(zr
->vfe
);
1118 /* unregister i2c bus */
1119 zoran_unregister_i2c(zr
);
1120 /* disable PCI bus-mastering */
1121 zoran_set_pci_master(zr
, 0);
1122 /* put chip into reset */
1123 btwrite(0, ZR36057_SPGPPCR
);
1124 free_irq(zr
->pci_dev
->irq
, zr
);
1125 /* unmap and free memory */
1126 kfree(zr
->stat_com
);
1127 zoran_proc_cleanup(zr
);
1128 iounmap(zr
->zr36057_mem
);
1129 pci_disable_device(zr
->pci_dev
);
1130 video_unregister_device(zr
->video_dev
);
1132 v4l2_device_unregister(&zr
->v4l2_dev
);
1137 zoran_vdev_release (struct video_device
*vdev
)
1142 static struct videocodec_master
* __devinit
1143 zoran_setup_videocodec (struct zoran
*zr
,
1146 struct videocodec_master
*m
= NULL
;
1148 m
= kmalloc(sizeof(struct videocodec_master
), GFP_KERNEL
);
1150 dprintk(1, KERN_ERR
"%s: %s - no memory\n",
1151 ZR_DEVNAME(zr
), __func__
);
1155 /* magic and type are unused for master struct. Makes sense only at
1157 In the past, .type were initialized to the old V4L1 .hardware
1158 value, as VID_HARDWARE_ZR36067
1163 m
->flags
= CODEC_FLAG_ENCODER
| CODEC_FLAG_DECODER
;
1164 strlcpy(m
->name
, ZR_DEVNAME(zr
), sizeof(m
->name
));
1169 case CODEC_TYPE_ZR36060
:
1170 m
->readreg
= zr36060_read
;
1171 m
->writereg
= zr36060_write
;
1172 m
->flags
|= CODEC_FLAG_JPEG
| CODEC_FLAG_VFE
;
1174 case CODEC_TYPE_ZR36050
:
1175 m
->readreg
= zr36050_read
;
1176 m
->writereg
= zr36050_write
;
1177 m
->flags
|= CODEC_FLAG_JPEG
;
1179 case CODEC_TYPE_ZR36016
:
1180 m
->readreg
= zr36016_read
;
1181 m
->writereg
= zr36016_write
;
1182 m
->flags
|= CODEC_FLAG_VFE
;
1189 static void zoran_subdev_notify(struct v4l2_subdev
*sd
, unsigned int cmd
, void *arg
)
1191 struct zoran
*zr
= to_zoran(sd
->v4l2_dev
);
1193 /* Bt819 needs to reset its FIFO buffer using #FRST pin and
1194 LML33 card uses GPIO(7) for that. */
1195 if (cmd
== BT819_FIFO_RESET_LOW
)
1197 else if (cmd
== BT819_FIFO_RESET_HIGH
)
1202 * Scan for a Buz card (actually for the PCI controller ZR36057),
1203 * request the irq and map the io memory
1205 static int __devinit
zoran_probe(struct pci_dev
*pdev
,
1206 const struct pci_device_id
*ent
)
1208 unsigned char latency
, need_latency
;
1211 struct videocodec_master
*master_vfe
= NULL
;
1212 struct videocodec_master
*master_codec
= NULL
;
1214 char *codec_name
, *vfe_name
;
1219 if (nr
>= BUZ_MAX
) {
1220 dprintk(1, KERN_ERR
"%s: driver limited to %d card(s) maximum\n",
1221 ZORAN_NAME
, BUZ_MAX
);
1225 zr
= kzalloc(sizeof(struct zoran
), GFP_KERNEL
);
1227 dprintk(1, KERN_ERR
"%s: %s - kzalloc failed\n",
1228 ZORAN_NAME
, __func__
);
1231 zr
->v4l2_dev
.notify
= zoran_subdev_notify
;
1232 if (v4l2_device_register(&pdev
->dev
, &zr
->v4l2_dev
))
1236 snprintf(ZR_DEVNAME(zr
), sizeof(ZR_DEVNAME(zr
)), "MJPEG[%u]", zr
->id
);
1237 spin_lock_init(&zr
->spinlock
);
1238 mutex_init(&zr
->resource_lock
);
1239 if (pci_enable_device(pdev
))
1241 pci_read_config_byte(zr
->pci_dev
, PCI_CLASS_REVISION
, &zr
->revision
);
1245 "%s: Zoran ZR360%c7 (rev %d), irq: %d, memory: 0x%08llx\n",
1246 ZR_DEVNAME(zr
), zr
->revision
< 2 ? '5' : '6', zr
->revision
,
1247 zr
->pci_dev
->irq
, (uint64_t)pci_resource_start(zr
->pci_dev
, 0));
1248 if (zr
->revision
>= 2) {
1251 "%s: Subsystem vendor=0x%04x id=0x%04x\n",
1252 ZR_DEVNAME(zr
), zr
->pci_dev
->subsystem_vendor
,
1253 zr
->pci_dev
->subsystem_device
);
1256 /* Use auto-detected card type? */
1257 if (card
[nr
] == -1) {
1258 if (zr
->revision
< 2) {
1261 "%s: No card type specified, please use the card=X module parameter\n",
1265 "%s: It is not possible to auto-detect ZR36057 based cards\n",
1270 card_num
= ent
->driver_data
;
1271 if (card_num
>= NUM_CARDS
) {
1274 "%s: Unknown card, try specifying card=X module parameter\n",
1280 "%s: %s() - card %s detected\n",
1281 ZR_DEVNAME(zr
), __func__
, zoran_cards
[card_num
].name
);
1283 card_num
= card
[nr
];
1284 if (card_num
>= NUM_CARDS
|| card_num
< 0) {
1287 "%s: User specified card type %d out of range (0 .. %d)\n",
1288 ZR_DEVNAME(zr
), card_num
, NUM_CARDS
- 1);
1293 /* even though we make this a non pointer and thus
1294 * theoretically allow for making changes to this struct
1295 * on a per-individual card basis at runtime, this is
1296 * strongly discouraged. This structure is intended to
1297 * keep general card information, no settings or anything */
1298 zr
->card
= zoran_cards
[card_num
];
1299 snprintf(ZR_DEVNAME(zr
), sizeof(ZR_DEVNAME(zr
)),
1300 "%s[%u]", zr
->card
.name
, zr
->id
);
1302 zr
->zr36057_mem
= pci_ioremap_bar(zr
->pci_dev
, 0);
1303 if (!zr
->zr36057_mem
) {
1304 dprintk(1, KERN_ERR
"%s: %s() - ioremap failed\n",
1305 ZR_DEVNAME(zr
), __func__
);
1309 result
= request_irq(zr
->pci_dev
->irq
, zoran_irq
,
1310 IRQF_SHARED
| IRQF_DISABLED
, ZR_DEVNAME(zr
), zr
);
1312 if (result
== -EINVAL
) {
1315 "%s: %s - bad irq number or handler\n",
1316 ZR_DEVNAME(zr
), __func__
);
1317 } else if (result
== -EBUSY
) {
1320 "%s: %s - IRQ %d busy, change your PnP config in BIOS\n",
1321 ZR_DEVNAME(zr
), __func__
, zr
->pci_dev
->irq
);
1325 "%s: %s - can't assign irq, error code %d\n",
1326 ZR_DEVNAME(zr
), __func__
, result
);
1331 /* set PCI latency timer */
1332 pci_read_config_byte(zr
->pci_dev
, PCI_LATENCY_TIMER
,
1334 need_latency
= zr
->revision
> 1 ? 32 : 48;
1335 if (latency
!= need_latency
) {
1336 dprintk(2, KERN_INFO
"%s: Changing PCI latency from %d to %d\n",
1337 ZR_DEVNAME(zr
), latency
, need_latency
);
1338 pci_write_config_byte(zr
->pci_dev
, PCI_LATENCY_TIMER
,
1342 zr36057_restart(zr
);
1344 dprintk(2, KERN_INFO
"%s: Initializing i2c bus...\n",
1347 if (zoran_register_i2c(zr
) < 0) {
1348 dprintk(1, KERN_ERR
"%s: %s - can't initialize i2c bus\n",
1349 ZR_DEVNAME(zr
), __func__
);
1353 zr
->decoder
= v4l2_i2c_new_subdev(&zr
->v4l2_dev
,
1354 &zr
->i2c_adapter
, zr
->card
.mod_decoder
, zr
->card
.i2c_decoder
,
1355 0, zr
->card
.addrs_decoder
);
1357 if (zr
->card
.mod_encoder
)
1358 zr
->encoder
= v4l2_i2c_new_subdev(&zr
->v4l2_dev
,
1360 zr
->card
.mod_encoder
, zr
->card
.i2c_encoder
,
1361 0, zr
->card
.addrs_encoder
);
1364 KERN_INFO
"%s: Initializing videocodec bus...\n",
1367 if (zr
->card
.video_codec
) {
1368 codec_name
= codecid_to_modulename(zr
->card
.video_codec
);
1370 result
= request_module(codec_name
);
1374 "%s: failed to load modules %s: %d\n",
1375 ZR_DEVNAME(zr
), codec_name
, result
);
1379 if (zr
->card
.video_vfe
) {
1380 vfe_name
= codecid_to_modulename(zr
->card
.video_vfe
);
1382 result
= request_module(vfe_name
);
1386 "%s: failed to load modules %s: %d\n",
1387 ZR_DEVNAME(zr
), vfe_name
, result
);
1392 /* reset JPEG codec */
1393 jpeg_codec_sleep(zr
, 1);
1394 jpeg_codec_reset(zr
);
1395 /* video bus enabled */
1396 /* display codec revision */
1397 if (zr
->card
.video_codec
!= 0) {
1398 master_codec
= zoran_setup_videocodec(zr
, zr
->card
.video_codec
);
1401 zr
->codec
= videocodec_attach(master_codec
);
1403 dprintk(1, KERN_ERR
"%s: %s - no codec found\n",
1404 ZR_DEVNAME(zr
), __func__
);
1407 if (zr
->codec
->type
!= zr
->card
.video_codec
) {
1408 dprintk(1, KERN_ERR
"%s: %s - wrong codec\n",
1409 ZR_DEVNAME(zr
), __func__
);
1410 goto zr_detach_codec
;
1413 if (zr
->card
.video_vfe
!= 0) {
1414 master_vfe
= zoran_setup_videocodec(zr
, zr
->card
.video_vfe
);
1416 goto zr_detach_codec
;
1417 zr
->vfe
= videocodec_attach(master_vfe
);
1419 dprintk(1, KERN_ERR
"%s: %s - no VFE found\n",
1420 ZR_DEVNAME(zr
), __func__
);
1423 if (zr
->vfe
->type
!= zr
->card
.video_vfe
) {
1424 dprintk(1, KERN_ERR
"%s: %s = wrong VFE\n",
1425 ZR_DEVNAME(zr
), __func__
);
1430 /* take care of Natoma chipset and a revision 1 zr36057 */
1431 if ((pci_pci_problems
& PCIPCI_NATOMA
) && zr
->revision
<= 1) {
1432 zr
->jpg_buffers
.need_contiguous
= 1;
1433 dprintk(1, KERN_INFO
1434 "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
1438 if (zr36057_init(zr
) < 0)
1441 zoran_proc_init(zr
);
1446 videocodec_detach(zr
->vfe
);
1450 videocodec_detach(zr
->codec
);
1452 kfree(master_codec
);
1454 zoran_unregister_i2c(zr
);
1456 btwrite(0, ZR36057_SPGPPCR
);
1457 free_irq(zr
->pci_dev
->irq
, zr
);
1459 iounmap(zr
->zr36057_mem
);
1461 v4l2_device_unregister(&zr
->v4l2_dev
);
1468 static struct pci_driver zoran_driver
= {
1470 .id_table
= zr36067_pci_tbl
,
1471 .probe
= zoran_probe
,
1472 .remove
= __devexit_p(zoran_remove
),
1475 static int __init
zoran_init(void)
1479 printk(KERN_INFO
"Zoran MJPEG board driver version %d.%d.%d\n",
1480 MAJOR_VERSION
, MINOR_VERSION
, RELEASE_VERSION
);
1482 /* check the parameters we have been given, adjust if necessary */
1485 if (v4l_nbufs
> VIDEO_MAX_FRAME
)
1486 v4l_nbufs
= VIDEO_MAX_FRAME
;
1487 /* The user specfies the in KB, we want them in byte
1488 * (and page aligned) */
1489 v4l_bufsize
= PAGE_ALIGN(v4l_bufsize
* 1024);
1490 if (v4l_bufsize
< 32768)
1491 v4l_bufsize
= 32768;
1492 /* 2 MB is arbitrary but sufficient for the maximum possible images */
1493 if (v4l_bufsize
> 2048 * 1024)
1494 v4l_bufsize
= 2048 * 1024;
1497 if (jpg_nbufs
> BUZ_MAX_FRAME
)
1498 jpg_nbufs
= BUZ_MAX_FRAME
;
1499 jpg_bufsize
= PAGE_ALIGN(jpg_bufsize
* 1024);
1500 if (jpg_bufsize
< 8192)
1502 if (jpg_bufsize
> (512 * 1024))
1503 jpg_bufsize
= 512 * 1024;
1504 /* Use parameter for vidmem or try to find a video card */
1508 "%s: Using supplied video memory base address @ 0x%lx\n",
1509 ZORAN_NAME
, vidmem
);
1512 /* some mainboards might not do PCI-PCI data transfer well */
1513 if (pci_pci_problems
& (PCIPCI_FAIL
|PCIAGP_FAIL
|PCIPCI_ALIMAGIK
)) {
1516 "%s: chipset does not support reliable PCI-PCI DMA\n",
1520 res
= pci_register_driver(&zoran_driver
);
1524 "%s: Unable to register ZR36057 driver\n",
1532 static void __exit
zoran_exit(void)
1534 pci_unregister_driver(&zoran_driver
);
1537 module_init(zoran_init
);
1538 module_exit(zoran_exit
);