1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Zoran zr36057/zr36067 PCI controller driver, for the
4 * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
5 * Media Labs LML33/LML33R10.
7 * This part handles card-specific data and detection
9 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
12 #include <linux/delay.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
17 #include <linux/i2c.h>
18 #include <linux/i2c-algo-bit.h>
19 #include <linux/videodev2.h>
20 #include <linux/spinlock.h>
22 #include <linux/pci.h>
23 #include <linux/interrupt.h>
25 #include <media/v4l2-common.h>
26 #include <media/i2c/bt819.h>
28 #include "videocodec.h"
30 #include "zoran_card.h"
31 #include "zoran_device.h"
36 extern const struct zoran_format zoran_formats
[];
38 static int card
[BUZ_MAX
] = { [0 ... (BUZ_MAX
- 1)] = -1 };
39 module_param_array(card
, int, NULL
, 0444);
40 MODULE_PARM_DESC(card
, "Card type");
42 /* Default input and video norm at startup of the driver. */
44 static unsigned int default_input
; /* default 0 = Composite, 1 = S-Video */
45 module_param(default_input
, uint
, 0444);
46 MODULE_PARM_DESC(default_input
,
47 "Default input (0=Composite, 1=S-Video, 2=Internal)");
49 static int default_mux
= 1; /* 6 Eyes input selection */
50 module_param(default_mux
, int, 0644);
51 MODULE_PARM_DESC(default_mux
,
52 "Default 6 Eyes mux setting (Input selection)");
54 static int default_norm
; /* default 0 = PAL, 1 = NTSC 2 = SECAM */
55 module_param(default_norm
, int, 0444);
56 MODULE_PARM_DESC(default_norm
, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
58 /* /dev/videoN, -1 for autodetect */
59 static int video_nr
[BUZ_MAX
] = { [0 ... (BUZ_MAX
- 1)] = -1 };
60 module_param_array(video_nr
, int, NULL
, 0444);
61 MODULE_PARM_DESC(video_nr
, "Video device number (-1=Auto)");
63 /* 1=Pass through TV signal when device is not used */
64 /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */
66 module_param(pass_through
, int, 0644);
67 MODULE_PARM_DESC(pass_through
,
68 "Pass TV signal through to TV-out when idling");
70 int zr36067_debug
= 1;
71 module_param_named(debug
, zr36067_debug
, int, 0644);
72 MODULE_PARM_DESC(debug
, "Debug level (0-5)");
74 #define ZORAN_VERSION "0.10.1"
76 MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
77 MODULE_AUTHOR("Serguei Miridonov");
78 MODULE_LICENSE("GPL");
79 MODULE_VERSION(ZORAN_VERSION
);
81 #define ZR_DEVICE(subven, subdev, data) { \
82 .vendor = PCI_VENDOR_ID_ZORAN, .device = PCI_DEVICE_ID_ZORAN_36057, \
83 .subvendor = (subven), .subdevice = (subdev), .driver_data = (data) }
85 static const struct pci_device_id zr36067_pci_tbl
[] = {
86 ZR_DEVICE(PCI_VENDOR_ID_MIRO
, PCI_DEVICE_ID_MIRO_DC10PLUS
, DC10_PLUS
),
87 ZR_DEVICE(PCI_VENDOR_ID_MIRO
, PCI_DEVICE_ID_MIRO_DC30PLUS
, DC30_PLUS
),
88 ZR_DEVICE(PCI_VENDOR_ID_ELECTRONICDESIGNGMBH
, PCI_DEVICE_ID_LML_33R10
, LML33R10
),
89 ZR_DEVICE(PCI_VENDOR_ID_IOMEGA
, PCI_DEVICE_ID_IOMEGA_BUZ
, BUZ
),
90 ZR_DEVICE(PCI_ANY_ID
, PCI_ANY_ID
, NUM_CARDS
),
93 MODULE_DEVICE_TABLE(pci
, zr36067_pci_tbl
);
95 static unsigned int zoran_num
; /* number of cards found */
97 /* videocodec bus functions ZR36060 */
98 static u32
zr36060_read(struct videocodec
*codec
, u16 reg
)
100 struct zoran
*zr
= (struct zoran
*)codec
->master_data
->data
;
103 if (post_office_wait(zr
) || post_office_write(zr
, 0, 1, reg
>> 8) ||
104 post_office_write(zr
, 0, 2, reg
& 0xff))
107 data
= post_office_read(zr
, 0, 3) & 0xff;
111 static void zr36060_write(struct videocodec
*codec
, u16 reg
, u32 val
)
113 struct zoran
*zr
= (struct zoran
*)codec
->master_data
->data
;
115 if (post_office_wait(zr
) || post_office_write(zr
, 0, 1, reg
>> 8) ||
116 post_office_write(zr
, 0, 2, reg
& 0xff))
119 post_office_write(zr
, 0, 3, val
& 0xff);
122 /* videocodec bus functions ZR36050 */
123 static u32
zr36050_read(struct videocodec
*codec
, u16 reg
)
125 struct zoran
*zr
= (struct zoran
*)codec
->master_data
->data
;
128 if (post_office_wait(zr
) || post_office_write(zr
, 1, 0, reg
>> 2)) // reg. HIGHBYTES
131 data
= post_office_read(zr
, 0, reg
& 0x03) & 0xff; // reg. LOWBYTES + read
135 static void zr36050_write(struct videocodec
*codec
, u16 reg
, u32 val
)
137 struct zoran
*zr
= (struct zoran
*)codec
->master_data
->data
;
139 if (post_office_wait(zr
) || post_office_write(zr
, 1, 0, reg
>> 2)) // reg. HIGHBYTES
142 post_office_write(zr
, 0, reg
& 0x03, val
& 0xff); // reg. LOWBYTES + wr. data
145 /* videocodec bus functions ZR36016 */
146 static u32
zr36016_read(struct videocodec
*codec
, u16 reg
)
148 struct zoran
*zr
= (struct zoran
*)codec
->master_data
->data
;
151 if (post_office_wait(zr
))
154 data
= post_office_read(zr
, 2, reg
& 0x03) & 0xff; // read
158 /* hack for in zoran_device.c */
159 void zr36016_write(struct videocodec
*codec
, u16 reg
, u32 val
)
161 struct zoran
*zr
= (struct zoran
*)codec
->master_data
->data
;
163 if (post_office_wait(zr
))
166 post_office_write(zr
, 2, reg
& 0x03, val
& 0x0ff); // wr. data
170 * Board specific information
173 static void dc10_init(struct zoran
*zr
)
175 /* Pixel clock selection */
178 /* Enable the video bus sync signals */
182 static void dc10plus_init(struct zoran
*zr
)
186 static void buz_init(struct zoran
*zr
)
188 /* some stuff from Iomega */
189 pci_write_config_dword(zr
->pci_dev
, 0xfc, 0x90680f15);
190 pci_write_config_dword(zr
->pci_dev
, 0x0c, 0x00012020);
191 pci_write_config_dword(zr
->pci_dev
, 0xe8, 0xc0200000);
194 static void lml33_init(struct zoran
*zr
)
196 GPIO(zr
, 2, 1); // Set Composite input/output
199 static void avs6eyes_init(struct zoran
*zr
)
201 // AverMedia 6-Eyes original driver by Christer Weinigel
203 // Lifted straight from Christer's old driver and
204 // modified slightly by Martin Samuelsson.
206 int mux
= default_mux
; /* 1 = BT866, 7 = VID1 */
208 GPIO(zr
, 4, 1); /* Bt866 SLEEP on */
211 GPIO(zr
, 0, 1); /* ZR36060 /RESET on */
212 GPIO(zr
, 1, 0); /* ZR36060 /SLEEP on */
213 GPIO(zr
, 2, mux
& 1); /* MUX S0 */
214 GPIO(zr
, 3, 0); /* /FRAME on */
215 GPIO(zr
, 4, 0); /* Bt866 SLEEP off */
216 GPIO(zr
, 5, mux
& 2); /* MUX S1 */
217 GPIO(zr
, 6, 0); /* ? */
218 GPIO(zr
, 7, mux
& 4); /* MUX S2 */
221 static const char *codecid_to_modulename(u16 codecid
)
223 const char *name
= NULL
;
226 case CODEC_TYPE_ZR36060
:
229 case CODEC_TYPE_ZR36050
:
232 case CODEC_TYPE_ZR36016
:
240 static int codec_init(struct zoran
*zr
, u16 codecid
)
243 case CODEC_TYPE_ZR36060
:
244 #ifdef CONFIG_VIDEO_ZORAN_ZR36060
245 return zr36060_init_module();
247 pci_err(zr
->pci_dev
, "ZR36060 support is not enabled\n");
251 case CODEC_TYPE_ZR36050
:
252 #ifdef CONFIG_VIDEO_ZORAN_DC30
253 return zr36050_init_module();
255 pci_err(zr
->pci_dev
, "ZR36050 support is not enabled\n");
259 case CODEC_TYPE_ZR36016
:
260 #ifdef CONFIG_VIDEO_ZORAN_DC30
261 return zr36016_init_module();
263 pci_err(zr
->pci_dev
, "ZR36016 support is not enabled\n");
269 pci_err(zr
->pci_dev
, "unknown codec id %x\n", codecid
);
273 static void codec_exit(struct zoran
*zr
, u16 codecid
)
276 case CODEC_TYPE_ZR36060
:
277 #ifdef CONFIG_VIDEO_ZORAN_ZR36060
278 zr36060_cleanup_module();
281 case CODEC_TYPE_ZR36050
:
282 #ifdef CONFIG_VIDEO_ZORAN_DC30
283 zr36050_cleanup_module();
286 case CODEC_TYPE_ZR36016
:
287 #ifdef CONFIG_VIDEO_ZORAN_DC30
288 zr36016_cleanup_module();
294 static int videocodec_init(struct zoran
*zr
)
296 const char *codec_name
, *vfe_name
;
299 codec_name
= codecid_to_modulename(zr
->card
.video_codec
);
301 result
= codec_init(zr
, zr
->card
.video_codec
);
303 pci_err(zr
->pci_dev
, "failed to load video codec %s: %d\n",
308 vfe_name
= codecid_to_modulename(zr
->card
.video_vfe
);
310 result
= codec_init(zr
, zr
->card
.video_vfe
);
312 pci_err(zr
->pci_dev
, "failed to load video vfe %s: %d\n",
315 codec_exit(zr
, zr
->card
.video_codec
);
322 static void videocodec_exit(struct zoran
*zr
)
324 if (zr
->card
.video_codec
!= CODEC_TYPE_NONE
)
325 codec_exit(zr
, zr
->card
.video_codec
);
326 if (zr
->card
.video_vfe
!= CODEC_TYPE_NONE
)
327 codec_exit(zr
, zr
->card
.video_vfe
);
330 static const struct tvnorm f50sqpixel
= { 944, 768, 83, 880, 625, 576, 16 };
331 static const struct tvnorm f60sqpixel
= { 780, 640, 51, 716, 525, 480, 12 };
332 static const struct tvnorm f50ccir601
= { 864, 720, 75, 804, 625, 576, 18 };
333 static const struct tvnorm f60ccir601
= { 858, 720, 57, 788, 525, 480, 16 };
335 static const struct tvnorm f50ccir601_lml33
= { 864, 720, 75 + 34, 804, 625, 576, 18 };
336 static const struct tvnorm f60ccir601_lml33
= { 858, 720, 57 + 34, 788, 525, 480, 16 };
338 /* The DC10 (57/16/50) uses VActive as HSync, so h_start must be 0 */
339 static const struct tvnorm f50sqpixel_dc10
= { 944, 768, 0, 880, 625, 576, 0 };
340 static const struct tvnorm f60sqpixel_dc10
= { 780, 640, 0, 716, 525, 480, 12 };
343 * FIXME: I cannot swap U and V in saa7114, so i do one pixel left shift in zoran (75 -> 74)
344 * (Maxim Yevtyushkin <max@linuxmedialabs.com>)
346 static const struct tvnorm f50ccir601_lm33r10
= { 864, 720, 74 + 54, 804, 625, 576, 18 };
347 static const struct tvnorm f60ccir601_lm33r10
= { 858, 720, 56 + 54, 788, 525, 480, 16 };
350 * FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I copy Maxim's left
351 * shift hack for the 6 Eyes.
353 * Christer's driver used the unshifted norms, though...
356 static const struct tvnorm f50ccir601_avs6eyes
= { 864, 720, 74, 804, 625, 576, 18 };
357 static const struct tvnorm f60ccir601_avs6eyes
= { 858, 720, 56, 788, 525, 480, 16 };
359 static const unsigned short vpx3220_addrs
[] = { 0x43, 0x47, I2C_CLIENT_END
};
360 static const unsigned short saa7110_addrs
[] = { 0x4e, 0x4f, I2C_CLIENT_END
};
361 static const unsigned short saa7111_addrs
[] = { 0x25, 0x24, I2C_CLIENT_END
};
362 static const unsigned short saa7114_addrs
[] = { 0x21, 0x20, I2C_CLIENT_END
};
363 static const unsigned short adv717x_addrs
[] = { 0x6a, 0x6b, 0x2a, 0x2b, I2C_CLIENT_END
};
364 static const unsigned short ks0127_addrs
[] = { 0x6c, 0x6d, I2C_CLIENT_END
};
365 static const unsigned short saa7185_addrs
[] = { 0x44, I2C_CLIENT_END
};
366 static const unsigned short bt819_addrs
[] = { 0x45, I2C_CLIENT_END
};
367 static const unsigned short bt856_addrs
[] = { 0x44, I2C_CLIENT_END
};
368 static const unsigned short bt866_addrs
[] = { 0x44, I2C_CLIENT_END
};
370 static struct card_info zoran_cards
[NUM_CARDS
] = {
374 .i2c_decoder
= "vpx3220a",
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 .addrs_decoder
= saa7110_addrs
,
405 .i2c_encoder
= "adv7175",
406 .addrs_encoder
= adv717x_addrs
,
407 .video_codec
= CODEC_TYPE_ZR36060
,
413 { 5, "Internal/comp" }
415 .norms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
420 .jpeg_int
= ZR36057_ISR_GIRQ0
,
421 .vsync_int
= ZR36057_ISR_GIRQ1
,
422 .gpio
= { 3, 0, 6, 1, 2, -1, 4, 5 },
423 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
425 .vfe_pol
= { 1, 1, 1, 1, 0, 0, 0, 0 },
426 .gws_not_connected
= 0,
428 .init
= &dc10plus_init
,
432 .i2c_decoder
= "saa7110",
433 .addrs_decoder
= saa7110_addrs
,
434 .i2c_encoder
= "adv7175",
435 .addrs_encoder
= adv717x_addrs
,
436 .video_codec
= CODEC_TYPE_ZR36060
,
442 { 5, "Internal/comp" }
444 .norms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
450 .jpeg_int
= ZR36057_ISR_GIRQ0
,
451 .vsync_int
= ZR36057_ISR_GIRQ1
,
452 .gpio
= { 3, 0, 6, 1, 2, -1, 4, 5 },
453 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
455 .vfe_pol
= { 1, 1, 1, 1, 0, 0, 0, 0 },
456 .gws_not_connected
= 0,
458 .init
= &dc10plus_init
,
462 .i2c_decoder
= "vpx3220a",
463 .addrs_decoder
= vpx3220_addrs
,
464 .i2c_encoder
= "adv7175",
465 .addrs_encoder
= adv717x_addrs
,
466 .video_codec
= CODEC_TYPE_ZR36050
,
467 .video_vfe
= CODEC_TYPE_ZR36016
,
473 { 0, "Internal/comp" }
475 .norms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
482 .vsync_int
= ZR36057_ISR_GIRQ1
,
483 .gpio
= { 2, 1, -1, 3, 7, 0, 4, 5 },
484 .gpio_pol
= { 0, 0, 0, 1, 0, 0, 0, 0 },
486 .vfe_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
487 .gws_not_connected
= 0,
493 .i2c_decoder
= "vpx3220a",
494 .addrs_decoder
= vpx3220_addrs
,
495 .i2c_encoder
= "adv7175",
496 .addrs_encoder
= adv717x_addrs
,
497 .video_codec
= CODEC_TYPE_ZR36050
,
498 .video_vfe
= CODEC_TYPE_ZR36016
,
504 { 0, "Internal/comp" }
506 .norms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
513 .vsync_int
= ZR36057_ISR_GIRQ1
,
514 .gpio
= { 2, 1, -1, 3, 7, 0, 4, 5 },
515 .gpio_pol
= { 0, 0, 0, 1, 0, 0, 0, 0 },
517 .vfe_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
518 .gws_not_connected
= 0,
524 .i2c_decoder
= "bt819a",
525 .addrs_decoder
= bt819_addrs
,
526 .i2c_encoder
= "bt856",
527 .addrs_encoder
= bt856_addrs
,
528 .video_codec
= CODEC_TYPE_ZR36060
,
535 .norms
= V4L2_STD_NTSC
| V4L2_STD_PAL
,
541 .jpeg_int
= ZR36057_ISR_GIRQ1
,
542 .vsync_int
= ZR36057_ISR_GIRQ0
,
543 .gpio
= { 1, -1, 3, 5, 7, -1, -1, -1 },
544 .gpio_pol
= { 0, 0, 0, 0, 1, 0, 0, 0 },
546 .vfe_pol
= { 1, 1, 0, 0, 0, 1, 0, 0 },
547 .gws_not_connected
= 1,
553 .i2c_decoder
= "saa7114",
554 .addrs_decoder
= saa7114_addrs
,
555 .i2c_encoder
= "adv7170",
556 .addrs_encoder
= adv717x_addrs
,
557 .video_codec
= CODEC_TYPE_ZR36060
,
564 .norms
= V4L2_STD_NTSC
| V4L2_STD_PAL
,
570 .jpeg_int
= ZR36057_ISR_GIRQ1
,
571 .vsync_int
= ZR36057_ISR_GIRQ0
,
572 .gpio
= { 1, -1, 3, 5, 7, -1, -1, -1 },
573 .gpio_pol
= { 0, 0, 0, 0, 1, 0, 0, 0 },
575 .vfe_pol
= { 1, 1, 0, 0, 0, 1, 0, 0 },
576 .gws_not_connected
= 1,
582 .i2c_decoder
= "saa7111",
583 .addrs_decoder
= saa7111_addrs
,
584 .i2c_encoder
= "saa7185",
585 .addrs_encoder
= saa7185_addrs
,
586 .video_codec
= CODEC_TYPE_ZR36060
,
593 .norms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
599 .jpeg_int
= ZR36057_ISR_GIRQ1
,
600 .vsync_int
= ZR36057_ISR_GIRQ0
,
601 .gpio
= { 1, -1, 3, -1, -1, -1, -1, -1 },
602 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 },
604 .vfe_pol
= { 1, 1, 0, 0, 0, 1, 0, 0 },
605 .gws_not_connected
= 1,
612 * AverMedia chose not to brand the 6-Eyes. Thus it can't be
613 * autodetected, and requires card=x.
615 .i2c_decoder
= "ks0127",
616 .addrs_decoder
= ks0127_addrs
,
617 .i2c_encoder
= "bt866",
618 .addrs_encoder
= bt866_addrs
,
619 .video_codec
= CODEC_TYPE_ZR36060
,
623 { 0, "Composite 1" },
624 { 1, "Composite 2" },
625 { 2, "Composite 3" },
626 { 4, "Composite 4" },
627 { 5, "Composite 5" },
628 { 6, "Composite 6" },
634 .norms
= V4L2_STD_NTSC
| V4L2_STD_PAL
,
636 &f50ccir601_avs6eyes
,
637 &f60ccir601_avs6eyes
,
640 .jpeg_int
= ZR36057_ISR_GIRQ1
,
641 .vsync_int
= ZR36057_ISR_GIRQ0
,
642 .gpio
= { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
643 .gpio_pol
= { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
644 .gpcs
= { 3, 1 }, // Validity unknown /Sam
645 .vfe_pol
= { 1, 0, 0, 0, 0, 1, 0, 0 }, // Validity unknown /Sam
646 .gws_not_connected
= 1,
648 .init
= &avs6eyes_init
,
656 /* software I2C functions */
657 static int zoran_i2c_getsda(void *data
)
659 struct zoran
*zr
= (struct zoran
*)data
;
661 return (btread(ZR36057_I2CBR
) >> 1) & 1;
664 static int zoran_i2c_getscl(void *data
)
666 struct zoran
*zr
= (struct zoran
*)data
;
668 return btread(ZR36057_I2CBR
) & 1;
671 static void zoran_i2c_setsda(void *data
, int state
)
673 struct zoran
*zr
= (struct zoran
*)data
;
679 btwrite(zr
->i2cbr
, ZR36057_I2CBR
);
682 static void zoran_i2c_setscl(void *data
, int state
)
684 struct zoran
*zr
= (struct zoran
*)data
;
690 btwrite(zr
->i2cbr
, ZR36057_I2CBR
);
693 static const struct i2c_algo_bit_data zoran_i2c_bit_data_template
= {
694 .setsda
= zoran_i2c_setsda
,
695 .setscl
= zoran_i2c_setscl
,
696 .getsda
= zoran_i2c_getsda
,
697 .getscl
= zoran_i2c_getscl
,
702 static int zoran_register_i2c(struct zoran
*zr
)
704 zr
->i2c_algo
= zoran_i2c_bit_data_template
;
705 zr
->i2c_algo
.data
= zr
;
706 strscpy(zr
->i2c_adapter
.name
, ZR_DEVNAME(zr
),
707 sizeof(zr
->i2c_adapter
.name
));
708 i2c_set_adapdata(&zr
->i2c_adapter
, &zr
->v4l2_dev
);
709 zr
->i2c_adapter
.algo_data
= &zr
->i2c_algo
;
710 zr
->i2c_adapter
.dev
.parent
= &zr
->pci_dev
->dev
;
711 return i2c_bit_add_bus(&zr
->i2c_adapter
);
714 static void zoran_unregister_i2c(struct zoran
*zr
)
716 i2c_del_adapter(&zr
->i2c_adapter
);
719 /* Check a zoran_params struct for correctness, insert default params */
720 int zoran_check_jpg_settings(struct zoran
*zr
,
721 struct zoran_jpg_settings
*settings
, int try)
723 int err
= 0, err0
= 0;
725 pci_dbg(zr
->pci_dev
, "%s - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
726 __func__
, settings
->decimation
, settings
->hor_dcm
,
727 settings
->ver_dcm
, settings
->tmp_dcm
);
728 pci_dbg(zr
->pci_dev
, "%s - x: %d, y: %d, w: %d, y: %d\n", __func__
,
729 settings
->img_x
, settings
->img_y
,
730 settings
->img_width
, settings
->img_height
);
731 /* Check decimation, set default values for decimation = 1, 2, 4 */
732 switch (settings
->decimation
) {
735 settings
->hor_dcm
= 1;
736 settings
->ver_dcm
= 1;
737 settings
->tmp_dcm
= 1;
738 settings
->field_per_buff
= 2;
741 settings
->img_width
= BUZ_MAX_WIDTH
;
742 settings
->img_height
= BUZ_MAX_HEIGHT
/ 2;
746 settings
->hor_dcm
= 2;
747 settings
->ver_dcm
= 1;
748 settings
->tmp_dcm
= 2;
749 settings
->field_per_buff
= 1;
750 settings
->img_x
= (BUZ_MAX_WIDTH
== 720) ? 8 : 0;
752 settings
->img_width
=
753 (BUZ_MAX_WIDTH
== 720) ? 704 : BUZ_MAX_WIDTH
;
754 settings
->img_height
= BUZ_MAX_HEIGHT
/ 2;
758 if (zr
->card
.type
== DC10_NEW
) {
760 "%s - HDec by 4 is not supported on the DC10\n",
766 settings
->hor_dcm
= 4;
767 settings
->ver_dcm
= 2;
768 settings
->tmp_dcm
= 2;
769 settings
->field_per_buff
= 1;
770 settings
->img_x
= (BUZ_MAX_WIDTH
== 720) ? 8 : 0;
772 settings
->img_width
=
773 (BUZ_MAX_WIDTH
== 720) ? 704 : BUZ_MAX_WIDTH
;
774 settings
->img_height
= BUZ_MAX_HEIGHT
/ 2;
778 /* We have to check the data the user has set */
780 if (settings
->hor_dcm
!= 1 && settings
->hor_dcm
!= 2 &&
781 (zr
->card
.type
== DC10_NEW
|| settings
->hor_dcm
!= 4)) {
782 settings
->hor_dcm
= clamp(settings
->hor_dcm
, 1, 2);
785 if (settings
->ver_dcm
!= 1 && settings
->ver_dcm
!= 2) {
786 settings
->ver_dcm
= clamp(settings
->ver_dcm
, 1, 2);
789 if (settings
->tmp_dcm
!= 1 && settings
->tmp_dcm
!= 2) {
790 settings
->tmp_dcm
= clamp(settings
->tmp_dcm
, 1, 2);
793 if (settings
->field_per_buff
!= 1 &&
794 settings
->field_per_buff
!= 2) {
795 settings
->field_per_buff
= clamp(settings
->field_per_buff
, 1, 2);
798 if (settings
->img_x
< 0) {
802 if (settings
->img_y
< 0) {
806 if (settings
->img_width
< 0 || settings
->img_width
> BUZ_MAX_WIDTH
) {
807 settings
->img_width
= clamp(settings
->img_width
, 0, (int)BUZ_MAX_WIDTH
);
810 if (settings
->img_height
< 0 || settings
->img_height
> BUZ_MAX_HEIGHT
/ 2) {
811 settings
->img_height
= clamp(settings
->img_height
, 0, BUZ_MAX_HEIGHT
/ 2);
814 if (settings
->img_x
+ settings
->img_width
> BUZ_MAX_WIDTH
) {
815 settings
->img_x
= BUZ_MAX_WIDTH
- settings
->img_width
;
818 if (settings
->img_y
+ settings
->img_height
> BUZ_MAX_HEIGHT
/ 2) {
819 settings
->img_y
= BUZ_MAX_HEIGHT
/ 2 - settings
->img_height
;
822 if (settings
->img_width
% (16 * settings
->hor_dcm
) != 0) {
823 settings
->img_width
-= settings
->img_width
% (16 * settings
->hor_dcm
);
824 if (settings
->img_width
== 0)
825 settings
->img_width
= 16 * settings
->hor_dcm
;
828 if (settings
->img_height
% (8 * settings
->ver_dcm
) != 0) {
829 settings
->img_height
-= settings
->img_height
% (8 * settings
->ver_dcm
);
830 if (settings
->img_height
== 0)
831 settings
->img_height
= 8 * settings
->ver_dcm
;
836 pci_err(zr
->pci_dev
, "%s - error in params for decimation = 0\n", __func__
);
841 pci_err(zr
->pci_dev
, "%s - decimation = %d, must be 0, 1, 2 or 4\n",
842 __func__
, settings
->decimation
);
847 if (settings
->jpg_comp
.quality
> 100)
848 settings
->jpg_comp
.quality
= 100;
849 if (settings
->jpg_comp
.quality
< 5)
850 settings
->jpg_comp
.quality
= 5;
851 if (settings
->jpg_comp
.APPn
< 0)
852 settings
->jpg_comp
.APPn
= 0;
853 if (settings
->jpg_comp
.APPn
> 15)
854 settings
->jpg_comp
.APPn
= 15;
855 if (settings
->jpg_comp
.APP_len
< 0)
856 settings
->jpg_comp
.APP_len
= 0;
857 if (settings
->jpg_comp
.APP_len
> 60)
858 settings
->jpg_comp
.APP_len
= 60;
859 if (settings
->jpg_comp
.COM_len
< 0)
860 settings
->jpg_comp
.COM_len
= 0;
861 if (settings
->jpg_comp
.COM_len
> 60)
862 settings
->jpg_comp
.COM_len
= 60;
868 static int zoran_init_video_device(struct zoran
*zr
, struct video_device
*video_dev
, int dir
)
872 /* Now add the template and register the device unit. */
873 *video_dev
= zoran_template
;
874 video_dev
->v4l2_dev
= &zr
->v4l2_dev
;
875 video_dev
->lock
= &zr
->lock
;
876 video_dev
->device_caps
= V4L2_CAP_STREAMING
| dir
;
878 strscpy(video_dev
->name
, ZR_DEVNAME(zr
), sizeof(video_dev
->name
));
879 video_dev
->vfl_dir
= VFL_DIR_RX
;
880 zoran_queue_init(zr
, &zr
->vq
, V4L2_BUF_TYPE_VIDEO_CAPTURE
);
882 err
= video_register_device(video_dev
, VFL_TYPE_VIDEO
, video_nr
[zr
->id
]);
885 video_set_drvdata(video_dev
, zr
);
889 static void zoran_exit_video_devices(struct zoran
*zr
)
891 video_unregister_device(zr
->video_dev
);
892 kfree(zr
->video_dev
);
895 static int zoran_init_video_devices(struct zoran
*zr
)
899 zr
->video_dev
= video_device_alloc();
903 err
= zoran_init_video_device(zr
, zr
->video_dev
, V4L2_CAP_VIDEO_CAPTURE
);
905 kfree(zr
->video_dev
);
910 * v4l2_device_unregister() will care about removing zr->encoder/zr->decoder
911 * via v4l2_i2c_subdev_unregister()
913 static int zoran_i2c_init(struct zoran
*zr
)
917 pci_info(zr
->pci_dev
, "Initializing i2c bus...\n");
919 err
= zoran_register_i2c(zr
);
921 pci_err(zr
->pci_dev
, "%s - cannot initialize i2c bus\n", __func__
);
925 zr
->decoder
= v4l2_i2c_new_subdev(&zr
->v4l2_dev
, &zr
->i2c_adapter
,
926 zr
->card
.i2c_decoder
, 0,
927 zr
->card
.addrs_decoder
);
929 pci_err(zr
->pci_dev
, "Fail to get decoder %s\n", zr
->card
.i2c_decoder
);
934 if (zr
->card
.i2c_encoder
) {
935 zr
->encoder
= v4l2_i2c_new_subdev(&zr
->v4l2_dev
, &zr
->i2c_adapter
,
936 zr
->card
.i2c_encoder
, 0,
937 zr
->card
.addrs_encoder
);
939 pci_err(zr
->pci_dev
, "Fail to get encoder %s\n", zr
->card
.i2c_encoder
);
947 zoran_unregister_i2c(zr
);
951 static void zoran_i2c_exit(struct zoran
*zr
)
953 zoran_unregister_i2c(zr
);
956 void zoran_open_init_params(struct zoran
*zr
)
960 zr
->v4l_settings
.width
= 192;
961 zr
->v4l_settings
.height
= 144;
962 zr
->v4l_settings
.format
= &zoran_formats
[7]; /* YUY2 - YUV-4:2:2 packed */
963 zr
->v4l_settings
.bytesperline
= zr
->v4l_settings
.width
*
964 ((zr
->v4l_settings
.format
->depth
+ 7) / 8);
966 /* Set necessary params and call zoran_check_jpg_settings to set the defaults */
967 zr
->jpg_settings
.decimation
= 1;
968 zr
->jpg_settings
.jpg_comp
.quality
= 50; /* default compression factor 8 */
969 if (zr
->card
.type
!= BUZ
)
970 zr
->jpg_settings
.odd_even
= 1;
972 zr
->jpg_settings
.odd_even
= 0;
973 zr
->jpg_settings
.jpg_comp
.APPn
= 0;
974 zr
->jpg_settings
.jpg_comp
.APP_len
= 0; /* No APPn marker */
975 memset(zr
->jpg_settings
.jpg_comp
.APP_data
, 0,
976 sizeof(zr
->jpg_settings
.jpg_comp
.APP_data
));
977 zr
->jpg_settings
.jpg_comp
.COM_len
= 0; /* No COM marker */
978 memset(zr
->jpg_settings
.jpg_comp
.COM_data
, 0,
979 sizeof(zr
->jpg_settings
.jpg_comp
.COM_data
));
980 zr
->jpg_settings
.jpg_comp
.jpeg_markers
=
981 V4L2_JPEG_MARKER_DHT
| V4L2_JPEG_MARKER_DQT
;
982 i
= zoran_check_jpg_settings(zr
, &zr
->jpg_settings
, 0);
984 pci_err(zr
->pci_dev
, "%s internal error\n", __func__
);
986 zr
->buffer_size
= zr
->v4l_settings
.bytesperline
* zr
->v4l_settings
.height
;
988 clear_interrupt_counters(zr
);
991 static int zr36057_init(struct zoran
*zr
)
995 pci_info(zr
->pci_dev
, "initializing card[%d]\n", zr
->id
);
997 /* Avoid nonsense settings from user for default input/norm */
998 if (default_norm
< 0 || default_norm
> 2)
1000 if (default_norm
== 0) {
1001 zr
->norm
= V4L2_STD_PAL
;
1002 zr
->timing
= zr
->card
.tvn
[ZR_NORM_PAL
];
1003 } else if (default_norm
== 1) {
1004 zr
->norm
= V4L2_STD_NTSC
;
1005 zr
->timing
= zr
->card
.tvn
[ZR_NORM_NTSC
];
1007 zr
->norm
= V4L2_STD_SECAM
;
1008 zr
->timing
= zr
->card
.tvn
[ZR_NORM_SECAM
];
1011 pci_warn(zr
->pci_dev
,
1012 "%s - default TV standard not supported by hardware. PAL will be used.\n",
1014 zr
->norm
= V4L2_STD_PAL
;
1015 zr
->timing
= zr
->card
.tvn
[ZR_NORM_PAL
];
1018 if (default_input
> zr
->card
.inputs
- 1) {
1019 pci_warn(zr
->pci_dev
, "default_input value %d out of range (0-%d)\n",
1020 default_input
, zr
->card
.inputs
- 1);
1023 zr
->input
= default_input
;
1025 /* default setup (will be repeated at every open) */
1026 zoran_open_init_params(zr
);
1028 /* allocate memory *before* doing anything to the hardware in case allocation fails */
1029 zr
->stat_com
= dma_alloc_coherent(&zr
->pci_dev
->dev
,
1030 BUZ_NUM_STAT_COM
* sizeof(u32
),
1031 &zr
->p_sc
, GFP_KERNEL
);
1035 for (j
= 0; j
< BUZ_NUM_STAT_COM
; j
++)
1036 zr
->stat_com
[j
] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
1038 zr
->stat_comb
= dma_alloc_coherent(&zr
->pci_dev
->dev
,
1039 BUZ_NUM_STAT_COM
* sizeof(u32
) * 2,
1040 &zr
->p_scb
, GFP_KERNEL
);
1041 if (!zr
->stat_comb
) {
1046 err
= zoran_init_video_devices(zr
);
1050 zoran_init_hardware(zr
);
1051 if (!pass_through
) {
1052 decoder_call(zr
, video
, s_stream
, 0);
1053 encoder_call(zr
, video
, s_routing
, 2, 0, 0);
1056 zr
->initialized
= 1;
1060 dma_free_coherent(&zr
->pci_dev
->dev
, BUZ_NUM_STAT_COM
* sizeof(u32
) * 2,
1061 zr
->stat_comb
, zr
->p_scb
);
1063 dma_free_coherent(&zr
->pci_dev
->dev
, BUZ_NUM_STAT_COM
* sizeof(u32
),
1064 zr
->stat_com
, zr
->p_sc
);
1068 static void zoran_remove(struct pci_dev
*pdev
)
1070 struct v4l2_device
*v4l2_dev
= dev_get_drvdata(&pdev
->dev
);
1071 struct zoran
*zr
= to_zoran(v4l2_dev
);
1073 if (!zr
->initialized
)
1076 debugfs_remove_recursive(zr
->dbgfs_dir
);
1078 zoran_queue_exit(zr
);
1080 /* unregister videocodec bus */
1082 videocodec_detach(zr
->codec
);
1084 videocodec_detach(zr
->vfe
);
1085 videocodec_exit(zr
);
1087 /* unregister i2c bus */
1089 /* disable PCI bus-mastering */
1090 zoran_set_pci_master(zr
, 0);
1091 /* put chip into reset */
1092 btwrite(0, ZR36057_SPGPPCR
);
1093 pci_free_irq(zr
->pci_dev
, 0, zr
);
1094 /* unmap and free memory */
1095 dma_free_coherent(&zr
->pci_dev
->dev
, BUZ_NUM_STAT_COM
* sizeof(u32
),
1096 zr
->stat_com
, zr
->p_sc
);
1097 dma_free_coherent(&zr
->pci_dev
->dev
, BUZ_NUM_STAT_COM
* sizeof(u32
) * 2,
1098 zr
->stat_comb
, zr
->p_scb
);
1099 pci_release_regions(pdev
);
1100 pci_disable_device(zr
->pci_dev
);
1101 zoran_exit_video_devices(zr
);
1103 v4l2_ctrl_handler_free(&zr
->hdl
);
1104 v4l2_device_unregister(&zr
->v4l2_dev
);
1107 void zoran_vdev_release(struct video_device
*vdev
)
1112 static struct videocodec_master
*zoran_setup_videocodec(struct zoran
*zr
,
1115 struct videocodec_master
*m
= NULL
;
1117 m
= devm_kmalloc(&zr
->pci_dev
->dev
, sizeof(*m
), GFP_KERNEL
);
1122 * magic and type are unused for master struct. Makes sense only at codec structs.
1123 * In the past, .type were initialized to the old V4L1 .hardware value,
1124 * as VID_HARDWARE_ZR36067
1129 m
->flags
= CODEC_FLAG_ENCODER
| CODEC_FLAG_DECODER
;
1130 strscpy(m
->name
, ZR_DEVNAME(zr
), sizeof(m
->name
));
1134 case CODEC_TYPE_ZR36060
:
1135 m
->readreg
= zr36060_read
;
1136 m
->writereg
= zr36060_write
;
1137 m
->flags
|= CODEC_FLAG_JPEG
| CODEC_FLAG_VFE
;
1139 case CODEC_TYPE_ZR36050
:
1140 m
->readreg
= zr36050_read
;
1141 m
->writereg
= zr36050_write
;
1142 m
->flags
|= CODEC_FLAG_JPEG
;
1144 case CODEC_TYPE_ZR36016
:
1145 m
->readreg
= zr36016_read
;
1146 m
->writereg
= zr36016_write
;
1147 m
->flags
|= CODEC_FLAG_VFE
;
1154 static void zoran_subdev_notify(struct v4l2_subdev
*sd
, unsigned int cmd
, void *arg
)
1156 struct zoran
*zr
= to_zoran(sd
->v4l2_dev
);
1159 * Bt819 needs to reset its FIFO buffer using #FRST pin and
1160 * LML33 card uses GPIO(7) for that.
1162 if (cmd
== BT819_FIFO_RESET_LOW
)
1164 else if (cmd
== BT819_FIFO_RESET_HIGH
)
1168 static int zoran_video_set_ctrl(struct v4l2_ctrl
*ctrl
)
1170 struct zoran
*zr
= container_of(ctrl
->handler
, struct zoran
, hdl
);
1173 case V4L2_CID_JPEG_COMPRESSION_QUALITY
:
1174 zr
->jpg_settings
.jpg_comp
.quality
= ctrl
->val
;
1175 return zoran_check_jpg_settings(zr
, &zr
->jpg_settings
, 0);
1183 static const struct v4l2_ctrl_ops zoran_video_ctrl_ops
= {
1184 .s_ctrl
= zoran_video_set_ctrl
,
1187 static int zoran_debugfs_show(struct seq_file
*seq
, void *v
)
1189 struct zoran
*zr
= seq
->private;
1191 seq_printf(seq
, "Running mode %x\n", zr
->running
);
1192 seq_printf(seq
, "Codec mode %x\n", zr
->codec_mode
);
1193 seq_printf(seq
, "Norm %llx\n", zr
->norm
);
1194 seq_printf(seq
, "Input %d\n", zr
->input
);
1195 seq_printf(seq
, "Buffersize %d\n", zr
->buffer_size
);
1197 seq_printf(seq
, "V4L width %dx%d\n", zr
->v4l_settings
.width
, zr
->v4l_settings
.height
);
1198 seq_printf(seq
, "V4L bytesperline %d\n", zr
->v4l_settings
.bytesperline
);
1200 seq_printf(seq
, "JPG decimation %u\n", zr
->jpg_settings
.decimation
);
1201 seq_printf(seq
, "JPG hor_dcm %u\n", zr
->jpg_settings
.hor_dcm
);
1202 seq_printf(seq
, "JPG ver_dcm %u\n", zr
->jpg_settings
.ver_dcm
);
1203 seq_printf(seq
, "JPG tmp_dcm %u\n", zr
->jpg_settings
.tmp_dcm
);
1204 seq_printf(seq
, "JPG odd_even %u\n", zr
->jpg_settings
.odd_even
);
1205 seq_printf(seq
, "JPG crop %dx%d %d %d\n",
1206 zr
->jpg_settings
.img_x
,
1207 zr
->jpg_settings
.img_y
,
1208 zr
->jpg_settings
.img_width
,
1209 zr
->jpg_settings
.img_height
);
1211 seq_printf(seq
, "Prepared %u\n", zr
->prepared
);
1212 seq_printf(seq
, "Queued %u\n", zr
->queued
);
1214 videocodec_debugfs_show(seq
);
1218 DEFINE_SHOW_ATTRIBUTE(zoran_debugfs
);
1221 * Scan for a Buz card (actually for the PCI controller ZR36057),
1222 * request the irq and map the io memory
1224 static int zoran_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1226 unsigned char latency
, need_latency
;
1229 struct videocodec_master
*master_vfe
= NULL
;
1230 struct videocodec_master
*master_codec
= NULL
;
1235 pci_info(pdev
, "Zoran MJPEG board driver version %s\n", ZORAN_VERSION
);
1237 /* some mainboards might not do PCI-PCI data transfer well */
1238 if (pci_pci_problems
& (PCIPCI_FAIL
| PCIAGP_FAIL
| PCIPCI_ALIMAGIK
))
1239 pci_warn(pdev
, "%s: chipset does not support reliable PCI-PCI DMA\n",
1242 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
1245 err
= vb2_dma_contig_set_max_seg_size(&pdev
->dev
, U32_MAX
);
1250 if (nr
>= BUZ_MAX
) {
1251 pci_err(pdev
, "driver limited to %d card(s) maximum\n", BUZ_MAX
);
1255 zr
= devm_kzalloc(&pdev
->dev
, sizeof(*zr
), GFP_KERNEL
);
1259 zr
->v4l2_dev
.notify
= zoran_subdev_notify
;
1260 if (v4l2_device_register(&pdev
->dev
, &zr
->v4l2_dev
))
1264 snprintf(ZR_DEVNAME(zr
), sizeof(ZR_DEVNAME(zr
)), "MJPEG[%u]", zr
->id
);
1265 if (v4l2_ctrl_handler_init(&zr
->hdl
, 10))
1267 zr
->v4l2_dev
.ctrl_handler
= &zr
->hdl
;
1268 v4l2_ctrl_new_std(&zr
->hdl
, &zoran_video_ctrl_ops
,
1269 V4L2_CID_JPEG_COMPRESSION_QUALITY
, 0,
1271 spin_lock_init(&zr
->spinlock
);
1272 mutex_init(&zr
->lock
);
1273 if (pci_enable_device(pdev
))
1275 zr
->revision
= zr
->pci_dev
->revision
;
1277 pci_info(zr
->pci_dev
, "Zoran ZR360%c7 (rev %d), irq: %d, memory: 0x%08llx\n",
1278 zr
->revision
< 2 ? '5' : '6', zr
->revision
,
1279 zr
->pci_dev
->irq
, (uint64_t)pci_resource_start(zr
->pci_dev
, 0));
1280 if (zr
->revision
>= 2)
1281 pci_info(zr
->pci_dev
, "Subsystem vendor=0x%04x id=0x%04x\n",
1282 zr
->pci_dev
->subsystem_vendor
, zr
->pci_dev
->subsystem_device
);
1284 /* Use auto-detected card type? */
1285 if (card
[nr
] == -1) {
1286 if (zr
->revision
< 2) {
1287 pci_err(pdev
, "No card type specified, please use the card=X module parameter\n");
1288 pci_err(pdev
, "It is not possible to auto-detect ZR36057 based cards\n");
1292 card_num
= ent
->driver_data
;
1293 if (card_num
>= NUM_CARDS
) {
1294 pci_err(pdev
, "Unknown card, try specifying card=X module parameter\n");
1297 pci_info(zr
->pci_dev
, "%s() - card %s detected\n", __func__
,
1298 zoran_cards
[card_num
].name
);
1300 card_num
= card
[nr
];
1301 if (card_num
>= NUM_CARDS
|| card_num
< 0) {
1302 pci_err(pdev
, "User specified card type %d out of range (0 .. %d)\n",
1303 card_num
, NUM_CARDS
- 1);
1309 * even though we make this a non pointer and thus
1310 * theoretically allow for making changes to this struct
1311 * on a per-individual card basis at runtime, this is
1312 * strongly discouraged. This structure is intended to
1313 * keep general card information, no settings or anything
1315 zr
->card
= zoran_cards
[card_num
];
1316 snprintf(ZR_DEVNAME(zr
), sizeof(ZR_DEVNAME(zr
)), "%s[%u]",
1317 zr
->card
.name
, zr
->id
);
1319 err
= pci_request_regions(pdev
, ZR_DEVNAME(zr
));
1323 zr
->zr36057_mem
= devm_ioremap(&pdev
->dev
, pci_resource_start(pdev
, 0),
1324 pci_resource_len(pdev
, 0));
1325 if (!zr
->zr36057_mem
) {
1326 pci_err(pdev
, "%s() - ioremap failed\n", __func__
);
1327 goto zr_pci_release
;
1330 result
= pci_request_irq(pdev
, 0, zoran_irq
, NULL
, zr
, ZR_DEVNAME(zr
));
1332 if (result
== -EINVAL
) {
1333 pci_err(pdev
, "%s - bad IRQ number or handler\n", __func__
);
1334 } else if (result
== -EBUSY
) {
1335 pci_err(pdev
, "%s - IRQ %d busy, change your PnP config in BIOS\n",
1336 __func__
, zr
->pci_dev
->irq
);
1338 pci_err(pdev
, "%s - cannot assign IRQ, error code %d\n", __func__
, result
);
1340 goto zr_pci_release
;
1343 /* set PCI latency timer */
1344 pci_read_config_byte(zr
->pci_dev
, PCI_LATENCY_TIMER
,
1346 need_latency
= zr
->revision
> 1 ? 32 : 48;
1347 if (latency
!= need_latency
) {
1348 pci_info(zr
->pci_dev
, "Changing PCI latency from %d to %d\n",
1349 latency
, need_latency
);
1350 pci_write_config_byte(zr
->pci_dev
, PCI_LATENCY_TIMER
, need_latency
);
1353 zr36057_restart(zr
);
1355 err
= zoran_i2c_init(zr
);
1359 pci_info(zr
->pci_dev
, "Initializing videocodec bus...\n");
1360 err
= videocodec_init(zr
);
1364 /* reset JPEG codec */
1365 jpeg_codec_sleep(zr
, 1);
1366 jpeg_codec_reset(zr
);
1367 /* video bus enabled */
1368 /* display codec revision */
1369 if (zr
->card
.video_codec
!= 0) {
1370 master_codec
= zoran_setup_videocodec(zr
, zr
->card
.video_codec
);
1372 goto zr_unreg_videocodec
;
1373 zr
->codec
= videocodec_attach(master_codec
);
1375 pci_err(pdev
, "%s - no codec found\n", __func__
);
1376 goto zr_unreg_videocodec
;
1378 if (zr
->codec
->type
!= zr
->card
.video_codec
) {
1379 pci_err(pdev
, "%s - wrong codec\n", __func__
);
1380 goto zr_unreg_videocodec
;
1383 if (zr
->card
.video_vfe
!= 0) {
1384 master_vfe
= zoran_setup_videocodec(zr
, zr
->card
.video_vfe
);
1386 goto zr_detach_codec
;
1387 zr
->vfe
= videocodec_attach(master_vfe
);
1389 pci_err(pdev
, "%s - no VFE found\n", __func__
);
1390 goto zr_detach_codec
;
1392 if (zr
->vfe
->type
!= zr
->card
.video_vfe
) {
1393 pci_err(pdev
, "%s = wrong VFE\n", __func__
);
1398 /* take care of Natoma chipset and a revision 1 zr36057 */
1399 if ((pci_pci_problems
& PCIPCI_NATOMA
) && zr
->revision
<= 1)
1400 pci_info(zr
->pci_dev
, "ZR36057/Natoma bug, max. buffer size is 128K\n");
1402 if (zr36057_init(zr
) < 0)
1405 zr
->map_mode
= ZORAN_MAP_MODE_RAW
;
1407 zr
->dbgfs_dir
= debugfs_create_dir(ZR_DEVNAME(zr
), NULL
);
1408 debugfs_create_file("debug", 0444, zr
->dbgfs_dir
, zr
,
1409 &zoran_debugfs_fops
);
1413 videocodec_detach(zr
->vfe
);
1415 videocodec_detach(zr
->codec
);
1416 zr_unreg_videocodec
:
1417 videocodec_exit(zr
);
1421 btwrite(0, ZR36057_SPGPPCR
);
1422 pci_free_irq(zr
->pci_dev
, 0, zr
);
1424 pci_release_regions(pdev
);
1426 v4l2_ctrl_handler_free(&zr
->hdl
);
1427 v4l2_device_unregister(&zr
->v4l2_dev
);
1433 static struct pci_driver zoran_driver
= {
1435 .id_table
= zr36067_pci_tbl
,
1436 .probe
= zoran_probe
,
1437 .remove
= zoran_remove
,
1440 module_pci_driver(zoran_driver
);