32 #include <linux/types.h>
33 #include <linux/kernel.h>
34 #include <linux/module.h>
37 #include <linux/slab.h>
40 #include <linux/i2c.h>
42 #include <linux/videodev2.h>
44 #include <linux/sem.h>
46 #include <linux/wait.h>
48 #include <linux/pci.h>
75 static unsigned long vidmem;
83 static unsigned int default_input;
86 "Default input (0=Composite, 1=S-Video, 2=Internal)");
88 static int default_mux = 1;
91 "Default 6 Eyes mux setting (Input selection)");
93 static int default_norm;
120 "Pass TV signal through to TV-out when idling");
126 #define ZORAN_VERSION "0.10.1"
133 #define ZR_DEVICE(subven, subdev, data) { \
134 .vendor = PCI_VENDOR_ID_ZORAN, .device = PCI_DEVICE_ID_ZORAN_36057, \
135 .subvendor = (subven), .subdevice = (subdev), .driver_data = (data) }
147 static unsigned int zoran_num;
251 dc10_init (
struct zoran *zr)
263 dc10plus_init (
struct zoran *zr)
269 buz_init (
struct zoran *zr)
274 pci_write_config_dword(zr->
pci_dev, 0xfc, 0x90680f15);
275 pci_write_config_dword(zr->
pci_dev, 0x0c, 0x00012020);
276 pci_write_config_dword(zr->
pci_dev, 0xe8, 0xc0200000);
280 lml33_init (
struct zoran *zr)
288 avs6eyes_init (
struct zoran *zr)
295 int mux = default_mux;
302 GPIO(zr, 2, mux & 1);
305 GPIO(zr, 5, mux & 2);
307 GPIO(zr, 7, mux & 4);
312 codecid_to_modulename (
u16 codecid)
335 static struct tvnorm f50sqpixel = { 944, 768, 83, 880, 625, 576, 16 };
336 static struct tvnorm f60sqpixel = { 780, 640, 51, 716, 525, 480, 12 };
337 static struct tvnorm f50ccir601 = { 864, 720, 75, 804, 625, 576, 18 };
338 static struct tvnorm f60ccir601 = { 858, 720, 57, 788, 525, 480, 16 };
340 static struct tvnorm f50ccir601_lml33 = { 864, 720, 75+34, 804, 625, 576, 18 };
341 static struct tvnorm f60ccir601_lml33 = { 858, 720, 57+34, 788, 525, 480, 16 };
344 static struct tvnorm f50sqpixel_dc10 = { 944, 768, 0, 880, 625, 576, 0 };
345 static struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 };
350 static struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74+54, 804, 625, 576, 18 };
351 static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 };
358 static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
359 static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
361 static const unsigned short vpx3220_addrs[] = { 0x43, 0x47,
I2C_CLIENT_END };
362 static const unsigned short saa7110_addrs[] = { 0x4e, 0x4f,
I2C_CLIENT_END };
363 static const unsigned short saa7111_addrs[] = { 0x25, 0x24,
I2C_CLIENT_END };
364 static const unsigned short saa7114_addrs[] = { 0x21, 0x20,
I2C_CLIENT_END };
365 static const unsigned short adv717x_addrs[] = { 0x6a, 0x6b, 0x2a, 0x2b,
I2C_CLIENT_END };
366 static const unsigned short ks0127_addrs[] = { 0x6c, 0x6d,
I2C_CLIENT_END };
367 static const unsigned short saa7185_addrs[] = { 0x44,
I2C_CLIENT_END };
368 static const unsigned short bt819_addrs[] = { 0x45,
I2C_CLIENT_END };
369 static const unsigned short bt856_addrs[] = { 0x44,
I2C_CLIENT_END };
370 static const unsigned short bt866_addrs[] = { 0x44,
I2C_CLIENT_END };
376 .i2c_decoder =
"vpx3220a",
377 .addrs_decoder = vpx3220_addrs,
385 { 0,
"Internal/comp" }
395 .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
396 .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
398 .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
399 .gws_not_connected = 0,
405 .i2c_decoder =
"saa7110",
406 .addrs_decoder = saa7110_addrs,
407 .i2c_encoder =
"adv7175",
408 .addrs_encoder = adv717x_addrs,
415 { 5,
"Internal/comp" }
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 .addrs_decoder = saa7110_addrs,
436 .i2c_encoder =
"adv7175",
437 .addrs_encoder = adv717x_addrs,
444 { 5,
"Internal/comp" }
454 .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
455 .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
457 .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
458 .gws_not_connected = 0,
460 .init = &dc10plus_init,
464 .i2c_decoder =
"vpx3220a",
465 .addrs_decoder = vpx3220_addrs,
466 .i2c_encoder =
"adv7175",
467 .addrs_encoder = adv717x_addrs,
475 { 0,
"Internal/comp" }
485 .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
486 .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
488 .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
489 .gws_not_connected = 0,
495 .i2c_decoder =
"vpx3220a",
496 .addrs_decoder = vpx3220_addrs,
497 .i2c_encoder =
"adv7175",
498 .addrs_encoder = adv717x_addrs,
506 { 0,
"Internal/comp" }
516 .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
517 .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
519 .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
520 .gws_not_connected = 0,
526 .i2c_decoder =
"bt819a",
527 .addrs_decoder = bt819_addrs,
528 .i2c_encoder =
"bt856",
529 .addrs_encoder = bt856_addrs,
545 .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
546 .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
548 .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
549 .gws_not_connected = 1,
555 .i2c_decoder =
"saa7114",
556 .addrs_decoder = saa7114_addrs,
557 .i2c_encoder =
"adv7170",
558 .addrs_encoder = adv717x_addrs,
574 .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
575 .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
577 .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
578 .gws_not_connected = 1,
584 .i2c_decoder =
"saa7111",
585 .addrs_decoder = saa7111_addrs,
586 .i2c_encoder =
"saa7185",
587 .addrs_encoder = saa7185_addrs,
603 .gpio = { 1, -1, 3, -1, -1, -1, -1, -1 },
604 .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
606 .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
607 .gws_not_connected = 1,
615 .i2c_decoder =
"ks0127",
616 .addrs_decoder = ks0127_addrs,
617 .i2c_encoder =
"bt866",
618 .addrs_encoder = bt866_addrs,
623 { 0,
"Composite 1" },
624 { 1,
"Composite 2" },
625 { 2,
"Composite 3" },
626 { 4,
"Composite 4" },
627 { 5,
"Composite 5" },
628 { 6,
"Composite 6" },
636 &f50ccir601_avs6eyes,
637 &f60ccir601_avs6eyes,
642 .gpio = { 1, 0, 3, -1, -1, -1, -1, -1 },
643 .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
645 .vfe_pol = { 1, 0, 0, 0, 0, 1, 0, 0 },
646 .gws_not_connected = 1,
648 .init = &avs6eyes_init,
658 zoran_i2c_getsda (
void *
data)
666 zoran_i2c_getscl (
void *data)
674 zoran_i2c_setsda (
void *data,
687 zoran_i2c_setscl (
void *data,
700 .setsda = zoran_i2c_setsda,
701 .setscl = zoran_i2c_setscl,
702 .getsda = zoran_i2c_getsda,
703 .getscl = zoran_i2c_getscl,
709 zoran_register_i2c (
struct zoran *zr)
723 zoran_unregister_i2c (
struct zoran *zr)
735 int err = 0, err0 = 0;
739 "%s: %s - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
744 "%s: %s - x: %d, y: %d, w: %d, y: %d\n",
777 "%s: %s - HDec by 4 is not supported on the DC10\n",
815 if (settings->
img_x < 0) {
819 if (settings->
img_y < 0) {
855 "%s: %s - error in params for decimation = 0\n",
863 "%s: %s - decimation = %d, must be 0, 1, 2 or 4\n",
869 if (settings->
jpg_comp.quality > 100)
879 if (settings->
jpg_comp.APP_len > 60)
883 if (settings->
jpg_comp.COM_len > 60)
952 test_interrupts (
struct zoran *zr)
970 dprintk(1,
": time spent: %d\n", 1 *
HZ - timeout);
972 if (zr36067_debug > 1)
978 zr36057_init (
struct zoran *zr)
984 "%s: %s - initializing card[%d], zr=%p\n",
1003 if (default_norm < 0 || default_norm > 2)
1005 if (default_norm == 0) {
1008 }
else if (default_norm == 1) {
1018 "%s: %s - default TV standard not supported by hardware. PAL will be used.\n",
1024 if (default_input > zr->
card.inputs-1) {
1027 "%s: default_input value %d out of range (0-%d)\n",
1031 zr->
input = default_input;
1043 "%s: %s - kmalloc (STAT_COM) failed\n",
1068 if (zr36067_debug > 2)
1070 test_interrupts(zr);
1071 if (!pass_through) {
1089 struct zoran *zr = to_zoran(v4l2_dev);
1109 zoran_unregister_i2c(zr);
1133 zoran_setup_videocodec (
struct zoran *zr,
1198 unsigned char latency, need_latency;
1204 char *codec_name, *vfe_name;
1221 zr->
v4l2_dev.notify = zoran_subdev_notify;
1236 "%s: Zoran ZR360%c7 (rev %d), irq: %d, memory: 0x%08llx\n",
1242 "%s: Subsystem vendor=0x%04x id=0x%04x\n",
1244 zr->
pci_dev->subsystem_device);
1248 if (
card[nr] == -1) {
1252 "%s: No card type specified, please use the card=X module parameter\n",
1256 "%s: It is not possible to auto-detect ZR36057 based cards\n",
1265 "%s: Unknown card, try specifying card=X module parameter\n",
1271 "%s: %s() - card %s detected\n",
1272 ZR_DEVNAME(zr), __func__, zoran_cards[card_num].name);
1275 if (card_num >=
NUM_CARDS || card_num < 0) {
1278 "%s: User specified card type %d out of range (0 .. %d)\n",
1289 zr->
card = zoran_cards[card_num];
1291 "%s[%u]", zr->
card.name, zr->
id);
1306 "%s: %s - bad irq number or handler\n",
1308 }
else if (result == -
EBUSY) {
1311 "%s: %s - IRQ %d busy, change your PnP config in BIOS\n",
1316 "%s: %s - can't assign irq, error code %d\n",
1325 need_latency = zr->
revision > 1 ? 32 : 48;
1326 if (latency != need_latency) {
1338 if (zoran_register_i2c(zr) < 0) {
1346 0, zr->
card.addrs_decoder);
1348 if (zr->
card.i2c_encoder)
1351 0, zr->
card.addrs_encoder);
1354 KERN_INFO "%s: Initializing videocodec bus...\n",
1357 if (zr->
card.video_codec) {
1358 codec_name = codecid_to_modulename(zr->
card.video_codec);
1360 result = request_module(codec_name);
1364 "%s: failed to load modules %s: %d\n",
1369 if (zr->
card.video_vfe) {
1370 vfe_name = codecid_to_modulename(zr->
card.video_vfe);
1372 result = request_module(vfe_name);
1376 "%s: failed to load modules %s: %d\n",
1387 if (zr->
card.video_codec != 0) {
1388 master_codec = zoran_setup_videocodec(zr, zr->
card.video_codec);
1397 if (zr->
codec->type != zr->
card.video_codec) {
1400 goto zr_detach_codec;
1403 if (zr->
card.video_vfe != 0) {
1404 master_vfe = zoran_setup_videocodec(zr, zr->
card.video_vfe);
1406 goto zr_detach_codec;
1413 if (zr->
vfe->type != zr->
card.video_vfe) {
1424 "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
1428 if (zr36057_init(zr) < 0)
1442 kfree(master_codec);
1444 zoran_unregister_i2c(zr);
1460 .id_table = zr36067_pci_tbl,
1461 .probe = zoran_probe,
1465 static int __init zoran_init(
void)
1479 v4l_bufsize =
PAGE_ALIGN(v4l_bufsize * 1024);
1480 if (v4l_bufsize < 32768)
1481 v4l_bufsize = 32768;
1483 if (v4l_bufsize > 2048 * 1024)
1484 v4l_bufsize = 2048 * 1024;
1489 jpg_bufsize =
PAGE_ALIGN(jpg_bufsize * 1024);
1490 if (jpg_bufsize < 8192)
1492 if (jpg_bufsize > (512 * 1024))
1493 jpg_bufsize = 512 * 1024;
1498 "%s: Using supplied video memory base address @ 0x%lx\n",
1506 "%s: chipset does not support reliable PCI-PCI DMA\n",
1510 res = pci_register_driver(&zoran_driver);
1514 "%s: Unable to register ZR36057 driver\n",
1522 static void __exit zoran_exit(
void)