diff options
Diffstat (limited to 'drivers/media/video/zoran/zoran_card.c')
-rw-r--r-- | drivers/media/video/zoran/zoran_card.c | 620 |
1 files changed, 300 insertions, 320 deletions
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c index 05f39195372..5d2f090aa0f 100644 --- a/drivers/media/video/zoran/zoran_card.c +++ b/drivers/media/video/zoran/zoran_card.c | |||
@@ -61,17 +61,17 @@ | |||
61 | 61 | ||
62 | extern const struct zoran_format zoran_formats[]; | 62 | extern const struct zoran_format zoran_formats[]; |
63 | 63 | ||
64 | static int card[BUZ_MAX] = { -1, -1, -1, -1 }; | 64 | static int card[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 }; |
65 | module_param_array(card, int, NULL, 0444); | 65 | module_param_array(card, int, NULL, 0444); |
66 | MODULE_PARM_DESC(card, "The type of card"); | 66 | MODULE_PARM_DESC(card, "Card type"); |
67 | 67 | ||
68 | static int encoder[BUZ_MAX] = { -1, -1, -1, -1 }; | 68 | static int encoder[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 }; |
69 | module_param_array(encoder, int, NULL, 0444); | 69 | module_param_array(encoder, int, NULL, 0444); |
70 | MODULE_PARM_DESC(encoder, "i2c TV encoder"); | 70 | MODULE_PARM_DESC(encoder, "Video encoder chip"); |
71 | 71 | ||
72 | static int decoder[BUZ_MAX] = { -1, -1, -1, -1 }; | 72 | static int decoder[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 }; |
73 | module_param_array(decoder, int, NULL, 0444); | 73 | module_param_array(decoder, int, NULL, 0444); |
74 | MODULE_PARM_DESC(decoder, "i2c TV decoder"); | 74 | MODULE_PARM_DESC(decoder, "Video decoder chip"); |
75 | 75 | ||
76 | /* | 76 | /* |
77 | The video mem address of the video card. | 77 | The video mem address of the video card. |
@@ -104,9 +104,9 @@ module_param(default_norm, int, 0444); | |||
104 | MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)"); | 104 | MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)"); |
105 | 105 | ||
106 | /* /dev/videoN, -1 for autodetect */ | 106 | /* /dev/videoN, -1 for autodetect */ |
107 | static int video_nr[BUZ_MAX] = {-1, -1, -1, -1}; | 107 | static int video_nr[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 }; |
108 | module_param_array(video_nr, int, NULL, 0444); | 108 | module_param_array(video_nr, int, NULL, 0444); |
109 | MODULE_PARM_DESC(video_nr, "video device number (-1=Auto)"); | 109 | MODULE_PARM_DESC(video_nr, "Video device number (-1=Auto)"); |
110 | 110 | ||
111 | /* | 111 | /* |
112 | Number and size of grab buffers for Video 4 Linux | 112 | Number and size of grab buffers for Video 4 Linux |
@@ -153,9 +153,21 @@ MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver"); | |||
153 | MODULE_AUTHOR("Serguei Miridonov"); | 153 | MODULE_AUTHOR("Serguei Miridonov"); |
154 | MODULE_LICENSE("GPL"); | 154 | MODULE_LICENSE("GPL"); |
155 | 155 | ||
156 | #define ZR_DEVICE(subven, subdev, data) { \ | ||
157 | .vendor = PCI_VENDOR_ID_ZORAN, .device = PCI_DEVICE_ID_ZORAN_36057, \ | ||
158 | .subvendor = (subven), .subdevice = (subdev), .driver_data = (data) } | ||
159 | |||
160 | static struct pci_device_id zr36067_pci_tbl[] = { | ||
161 | ZR_DEVICE(PCI_VENDOR_ID_MIRO, PCI_DEVICE_ID_MIRO_DC10PLUS, DC10plus), | ||
162 | ZR_DEVICE(PCI_VENDOR_ID_MIRO, PCI_DEVICE_ID_MIRO_DC30PLUS, DC30plus), | ||
163 | ZR_DEVICE(PCI_VENDOR_ID_ELECTRONICDESIGNGMBH, PCI_DEVICE_ID_LML_33R10, LML33R10), | ||
164 | ZR_DEVICE(PCI_VENDOR_ID_IOMEGA, PCI_DEVICE_ID_IOMEGA_BUZ, BUZ), | ||
165 | ZR_DEVICE(PCI_ANY_ID, PCI_ANY_ID, NUM_CARDS), | ||
166 | {0} | ||
167 | }; | ||
168 | MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl); | ||
156 | 169 | ||
157 | int zoran_num; /* number of Buzs in use */ | 170 | static unsigned int zoran_num; /* number of cards found */ |
158 | struct zoran *zoran[BUZ_MAX]; | ||
159 | 171 | ||
160 | /* videocodec bus functions ZR36060 */ | 172 | /* videocodec bus functions ZR36060 */ |
161 | static u32 | 173 | static u32 |
@@ -472,8 +484,6 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
472 | }, { | 484 | }, { |
473 | .type = DC10plus, | 485 | .type = DC10plus, |
474 | .name = "DC10plus", | 486 | .name = "DC10plus", |
475 | .vendor_id = PCI_VENDOR_ID_MIRO, | ||
476 | .device_id = PCI_DEVICE_ID_MIRO_DC10PLUS, | ||
477 | .i2c_decoder = I2C_DRIVERID_SAA7110, | 487 | .i2c_decoder = I2C_DRIVERID_SAA7110, |
478 | .i2c_encoder = I2C_DRIVERID_ADV7175, | 488 | .i2c_encoder = I2C_DRIVERID_ADV7175, |
479 | .video_codec = CODEC_TYPE_ZR36060, | 489 | .video_codec = CODEC_TYPE_ZR36060, |
@@ -531,8 +541,6 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
531 | }, { | 541 | }, { |
532 | .type = DC30plus, | 542 | .type = DC30plus, |
533 | .name = "DC30plus", | 543 | .name = "DC30plus", |
534 | .vendor_id = PCI_VENDOR_ID_MIRO, | ||
535 | .device_id = PCI_DEVICE_ID_MIRO_DC30PLUS, | ||
536 | .i2c_decoder = I2C_DRIVERID_VPX3220, | 544 | .i2c_decoder = I2C_DRIVERID_VPX3220, |
537 | .i2c_encoder = I2C_DRIVERID_ADV7175, | 545 | .i2c_encoder = I2C_DRIVERID_ADV7175, |
538 | .video_codec = CODEC_TYPE_ZR36050, | 546 | .video_codec = CODEC_TYPE_ZR36050, |
@@ -589,8 +597,6 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
589 | }, { | 597 | }, { |
590 | .type = LML33R10, | 598 | .type = LML33R10, |
591 | .name = "LML33R10", | 599 | .name = "LML33R10", |
592 | .vendor_id = PCI_VENDOR_ID_ELECTRONICDESIGNGMBH, | ||
593 | .device_id = PCI_DEVICE_ID_LML_33R10, | ||
594 | .i2c_decoder = I2C_DRIVERID_SAA7114, | 600 | .i2c_decoder = I2C_DRIVERID_SAA7114, |
595 | .i2c_encoder = I2C_DRIVERID_ADV7170, | 601 | .i2c_encoder = I2C_DRIVERID_ADV7170, |
596 | .video_codec = CODEC_TYPE_ZR36060, | 602 | .video_codec = CODEC_TYPE_ZR36060, |
@@ -618,8 +624,6 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
618 | }, { | 624 | }, { |
619 | .type = BUZ, | 625 | .type = BUZ, |
620 | .name = "Buz", | 626 | .name = "Buz", |
621 | .vendor_id = PCI_VENDOR_ID_IOMEGA, | ||
622 | .device_id = PCI_DEVICE_ID_IOMEGA_BUZ, | ||
623 | .i2c_decoder = I2C_DRIVERID_SAA7111A, | 627 | .i2c_decoder = I2C_DRIVERID_SAA7111A, |
624 | .i2c_encoder = I2C_DRIVERID_SAA7185B, | 628 | .i2c_encoder = I2C_DRIVERID_SAA7185B, |
625 | .video_codec = CODEC_TYPE_ZR36060, | 629 | .video_codec = CODEC_TYPE_ZR36060, |
@@ -649,8 +653,6 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
649 | .name = "6-Eyes", | 653 | .name = "6-Eyes", |
650 | /* AverMedia chose not to brand the 6-Eyes. Thus it | 654 | /* AverMedia chose not to brand the 6-Eyes. Thus it |
651 | can't be autodetected, and requires card=x. */ | 655 | can't be autodetected, and requires card=x. */ |
652 | .vendor_id = -1, | ||
653 | .device_id = -1, | ||
654 | .i2c_decoder = I2C_DRIVERID_KS0127, | 656 | .i2c_decoder = I2C_DRIVERID_KS0127, |
655 | .i2c_encoder = I2C_DRIVERID_BT866, | 657 | .i2c_encoder = I2C_DRIVERID_BT866, |
656 | .video_codec = CODEC_TYPE_ZR36060, | 658 | .video_codec = CODEC_TYPE_ZR36060, |
@@ -1138,7 +1140,8 @@ zr36057_init (struct zoran *zr) | |||
1138 | strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); | 1140 | strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); |
1139 | err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]); | 1141 | err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]); |
1140 | if (err < 0) | 1142 | if (err < 0) |
1141 | goto exit_unregister; | 1143 | goto exit_free; |
1144 | video_set_drvdata(zr->video_dev, zr); | ||
1142 | 1145 | ||
1143 | zoran_init_hardware(zr); | 1146 | zoran_init_hardware(zr); |
1144 | if (zr36067_debug > 2) | 1147 | if (zr36067_debug > 2) |
@@ -1153,19 +1156,19 @@ zr36057_init (struct zoran *zr) | |||
1153 | zr->initialized = 1; | 1156 | zr->initialized = 1; |
1154 | return 0; | 1157 | return 0; |
1155 | 1158 | ||
1156 | exit_unregister: | ||
1157 | zoran_unregister_i2c(zr); | ||
1158 | exit_free: | 1159 | exit_free: |
1159 | kfree(zr->stat_com); | 1160 | kfree(zr->stat_com); |
1160 | kfree(zr->video_dev); | 1161 | kfree(zr->video_dev); |
1161 | return err; | 1162 | return err; |
1162 | } | 1163 | } |
1163 | 1164 | ||
1164 | static void | 1165 | static void __devexit zoran_remove(struct pci_dev *pdev) |
1165 | zoran_release (struct zoran *zr) | ||
1166 | { | 1166 | { |
1167 | struct zoran *zr = pci_get_drvdata(pdev); | ||
1168 | |||
1167 | if (!zr->initialized) | 1169 | if (!zr->initialized) |
1168 | goto exit_free; | 1170 | goto exit_free; |
1171 | |||
1169 | /* unregister videocodec bus */ | 1172 | /* unregister videocodec bus */ |
1170 | if (zr->codec) { | 1173 | if (zr->codec) { |
1171 | struct videocodec_master *master = zr->codec->master_data; | 1174 | struct videocodec_master *master = zr->codec->master_data; |
@@ -1194,6 +1197,7 @@ zoran_release (struct zoran *zr) | |||
1194 | pci_disable_device(zr->pci_dev); | 1197 | pci_disable_device(zr->pci_dev); |
1195 | video_unregister_device(zr->video_dev); | 1198 | video_unregister_device(zr->video_dev); |
1196 | exit_free: | 1199 | exit_free: |
1200 | pci_set_drvdata(pdev, NULL); | ||
1197 | kfree(zr); | 1201 | kfree(zr); |
1198 | } | 1202 | } |
1199 | 1203 | ||
@@ -1256,338 +1260,329 @@ zoran_setup_videocodec (struct zoran *zr, | |||
1256 | * Scan for a Buz card (actually for the PCI controller ZR36057), | 1260 | * Scan for a Buz card (actually for the PCI controller ZR36057), |
1257 | * request the irq and map the io memory | 1261 | * request the irq and map the io memory |
1258 | */ | 1262 | */ |
1259 | static int __devinit | 1263 | static int __devinit zoran_probe(struct pci_dev *pdev, |
1260 | find_zr36057 (void) | 1264 | const struct pci_device_id *ent) |
1261 | { | 1265 | { |
1262 | unsigned char latency, need_latency; | 1266 | unsigned char latency, need_latency; |
1263 | struct zoran *zr; | 1267 | struct zoran *zr; |
1264 | struct pci_dev *dev = NULL; | ||
1265 | int result; | 1268 | int result; |
1266 | struct videocodec_master *master_vfe = NULL; | 1269 | struct videocodec_master *master_vfe = NULL; |
1267 | struct videocodec_master *master_codec = NULL; | 1270 | struct videocodec_master *master_codec = NULL; |
1268 | int card_num; | 1271 | int card_num; |
1269 | char *i2c_enc_name, *i2c_dec_name, *codec_name, *vfe_name; | 1272 | char *i2c_enc_name, *i2c_dec_name, *codec_name, *vfe_name; |
1273 | unsigned int nr; | ||
1270 | 1274 | ||
1271 | zoran_num = 0; | ||
1272 | while (zoran_num < BUZ_MAX && | ||
1273 | (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) { | ||
1274 | card_num = card[zoran_num]; | ||
1275 | zr = kzalloc(sizeof(struct zoran), GFP_KERNEL); | ||
1276 | if (!zr) { | ||
1277 | dprintk(1, | ||
1278 | KERN_ERR | ||
1279 | "%s: find_zr36057() - kzalloc failed\n", | ||
1280 | ZORAN_NAME); | ||
1281 | continue; | ||
1282 | } | ||
1283 | zr->pci_dev = dev; | ||
1284 | //zr->zr36057_mem = NULL; | ||
1285 | zr->id = zoran_num; | ||
1286 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); | ||
1287 | spin_lock_init(&zr->spinlock); | ||
1288 | mutex_init(&zr->resource_lock); | ||
1289 | if (pci_enable_device(dev)) | ||
1290 | goto zr_free_mem; | ||
1291 | zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0); | ||
1292 | pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, | ||
1293 | &zr->revision); | ||
1294 | if (zr->revision < 2) { | ||
1295 | dprintk(1, | ||
1296 | KERN_INFO | ||
1297 | "%s: Zoran ZR36057 (rev %d) irq: %d, memory: 0x%08x.\n", | ||
1298 | ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq, | ||
1299 | zr->zr36057_adr); | ||
1300 | 1275 | ||
1301 | if (card_num == -1) { | 1276 | nr = zoran_num++; |
1302 | dprintk(1, | 1277 | if (nr >= BUZ_MAX) { |
1303 | KERN_ERR | 1278 | dprintk(1, |
1304 | "%s: find_zr36057() - no card specified, please use the card=X insmod option\n", | 1279 | KERN_ERR |
1305 | ZR_DEVNAME(zr)); | 1280 | "%s: driver limited to %d card(s) maximum\n", |
1306 | goto zr_free_mem; | 1281 | ZORAN_NAME, BUZ_MAX); |
1307 | } | 1282 | return -ENOENT; |
1308 | } else { | 1283 | } |
1309 | int i; | ||
1310 | unsigned short ss_vendor, ss_device; | ||
1311 | 1284 | ||
1312 | ss_vendor = zr->pci_dev->subsystem_vendor; | 1285 | zr = kzalloc(sizeof(struct zoran), GFP_KERNEL); |
1313 | ss_device = zr->pci_dev->subsystem_device; | 1286 | if (!zr) { |
1287 | dprintk(1, | ||
1288 | KERN_ERR | ||
1289 | "%s: find_zr36057() - kzalloc failed\n", | ||
1290 | ZORAN_NAME); | ||
1291 | return -ENOMEM; | ||
1292 | } | ||
1293 | zr->pci_dev = pdev; | ||
1294 | zr->id = nr; | ||
1295 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); | ||
1296 | spin_lock_init(&zr->spinlock); | ||
1297 | mutex_init(&zr->resource_lock); | ||
1298 | if (pci_enable_device(pdev)) | ||
1299 | goto zr_free_mem; | ||
1300 | pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision); | ||
1301 | |||
1302 | dprintk(1, | ||
1303 | KERN_INFO | ||
1304 | "%s: Zoran ZR360%c7 (rev %d), irq: %d, memory: 0x%08llx\n", | ||
1305 | ZR_DEVNAME(zr), zr->revision < 2 ? '5' : '6', zr->revision, | ||
1306 | zr->pci_dev->irq, (uint64_t)pci_resource_start(zr->pci_dev, 0)); | ||
1307 | if (zr->revision >= 2) { | ||
1308 | dprintk(1, | ||
1309 | KERN_INFO | ||
1310 | "%s: Subsystem vendor=0x%04x id=0x%04x\n", | ||
1311 | ZR_DEVNAME(zr), zr->pci_dev->subsystem_vendor, | ||
1312 | zr->pci_dev->subsystem_device); | ||
1313 | } | ||
1314 | |||
1315 | /* Use auto-detected card type? */ | ||
1316 | if (card[nr] == -1) { | ||
1317 | if (zr->revision < 2) { | ||
1314 | dprintk(1, | 1318 | dprintk(1, |
1315 | KERN_INFO | 1319 | KERN_ERR |
1316 | "%s: Zoran ZR36067 (rev %d) irq: %d, memory: 0x%08x\n", | 1320 | "%s: No card type specified, please use the card=X module parameter\n", |
1317 | ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq, | 1321 | ZR_DEVNAME(zr)); |
1318 | zr->zr36057_adr); | ||
1319 | dprintk(1, | 1322 | dprintk(1, |
1320 | KERN_INFO | ||
1321 | "%s: subsystem vendor=0x%04x id=0x%04x\n", | ||
1322 | ZR_DEVNAME(zr), ss_vendor, ss_device); | ||
1323 | if (card_num == -1) { | ||
1324 | dprintk(3, | ||
1325 | KERN_DEBUG | ||
1326 | "%s: find_zr36057() - trying to autodetect card type\n", | ||
1327 | ZR_DEVNAME(zr)); | ||
1328 | for (i=0;i<NUM_CARDS;i++) { | ||
1329 | if (ss_vendor == zoran_cards[i].vendor_id && | ||
1330 | ss_device == zoran_cards[i].device_id) { | ||
1331 | dprintk(3, | ||
1332 | KERN_DEBUG | ||
1333 | "%s: find_zr36057() - card %s detected\n", | ||
1334 | ZR_DEVNAME(zr), | ||
1335 | zoran_cards[i].name); | ||
1336 | card_num = i; | ||
1337 | break; | ||
1338 | } | ||
1339 | } | ||
1340 | if (i == NUM_CARDS) { | ||
1341 | dprintk(1, | ||
1342 | KERN_ERR | ||
1343 | "%s: find_zr36057() - unknown card\n", | ||
1344 | ZR_DEVNAME(zr)); | ||
1345 | goto zr_free_mem; | ||
1346 | } | ||
1347 | } | ||
1348 | } | ||
1349 | |||
1350 | if (card_num < 0 || card_num >= NUM_CARDS) { | ||
1351 | dprintk(2, | ||
1352 | KERN_ERR | 1323 | KERN_ERR |
1353 | "%s: find_zr36057() - invalid cardnum %d\n", | 1324 | "%s: It is not possible to auto-detect ZR36057 based cards\n", |
1354 | ZR_DEVNAME(zr), card_num); | 1325 | ZR_DEVNAME(zr)); |
1355 | goto zr_free_mem; | 1326 | goto zr_free_mem; |
1356 | } | 1327 | } |
1357 | 1328 | ||
1358 | /* even though we make this a non pointer and thus | 1329 | card_num = ent->driver_data; |
1359 | * theoretically allow for making changes to this struct | 1330 | if (card_num >= NUM_CARDS) { |
1360 | * on a per-individual card basis at runtime, this is | ||
1361 | * strongly discouraged. This structure is intended to | ||
1362 | * keep general card information, no settings or anything */ | ||
1363 | zr->card = zoran_cards[card_num]; | ||
1364 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), | ||
1365 | "%s[%u]", zr->card.name, zr->id); | ||
1366 | |||
1367 | zr->zr36057_mem = ioremap_nocache(zr->zr36057_adr, 0x1000); | ||
1368 | if (!zr->zr36057_mem) { | ||
1369 | dprintk(1, | 1331 | dprintk(1, |
1370 | KERN_ERR | 1332 | KERN_ERR |
1371 | "%s: find_zr36057() - ioremap failed\n", | 1333 | "%s: Unknown card, try specifying card=X module parameter\n", |
1372 | ZR_DEVNAME(zr)); | 1334 | ZR_DEVNAME(zr)); |
1373 | goto zr_free_mem; | 1335 | goto zr_free_mem; |
1374 | } | 1336 | } |
1375 | 1337 | dprintk(3, | |
1376 | result = request_irq(zr->pci_dev->irq, | 1338 | KERN_DEBUG |
1377 | zoran_irq, | 1339 | "%s: %s() - card %s detected\n", |
1378 | IRQF_SHARED | IRQF_DISABLED, | 1340 | ZR_DEVNAME(zr), __func__, zoran_cards[card_num].name); |
1379 | ZR_DEVNAME(zr), | 1341 | } else { |
1380 | (void *) zr); | 1342 | card_num = card[nr]; |
1381 | if (result < 0) { | 1343 | if (card_num >= NUM_CARDS || card_num < 0) { |
1382 | if (result == -EINVAL) { | 1344 | dprintk(1, |
1383 | dprintk(1, | 1345 | KERN_ERR |
1384 | KERN_ERR | 1346 | "%s: User specified card type %d out of range (0 .. %d)\n", |
1385 | "%s: find_zr36057() - bad irq number or handler\n", | 1347 | ZR_DEVNAME(zr), card_num, NUM_CARDS - 1); |
1386 | ZR_DEVNAME(zr)); | 1348 | goto zr_free_mem; |
1387 | } else if (result == -EBUSY) { | ||
1388 | dprintk(1, | ||
1389 | KERN_ERR | ||
1390 | "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n", | ||
1391 | ZR_DEVNAME(zr), zr->pci_dev->irq); | ||
1392 | } else { | ||
1393 | dprintk(1, | ||
1394 | KERN_ERR | ||
1395 | "%s: find_zr36057() - can't assign irq, error code %d\n", | ||
1396 | ZR_DEVNAME(zr), result); | ||
1397 | } | ||
1398 | goto zr_unmap; | ||
1399 | } | ||
1400 | |||
1401 | /* set PCI latency timer */ | ||
1402 | pci_read_config_byte(zr->pci_dev, PCI_LATENCY_TIMER, | ||
1403 | &latency); | ||
1404 | need_latency = zr->revision > 1 ? 32 : 48; | ||
1405 | if (latency != need_latency) { | ||
1406 | dprintk(2, | ||
1407 | KERN_INFO | ||
1408 | "%s: Changing PCI latency from %d to %d.\n", | ||
1409 | ZR_DEVNAME(zr), latency, need_latency); | ||
1410 | pci_write_config_byte(zr->pci_dev, | ||
1411 | PCI_LATENCY_TIMER, | ||
1412 | need_latency); | ||
1413 | } | 1349 | } |
1350 | } | ||
1414 | 1351 | ||
1415 | zr36057_restart(zr); | 1352 | /* even though we make this a non pointer and thus |
1416 | /* i2c */ | 1353 | * theoretically allow for making changes to this struct |
1417 | dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n", | 1354 | * on a per-individual card basis at runtime, this is |
1418 | ZR_DEVNAME(zr)); | 1355 | * strongly discouraged. This structure is intended to |
1356 | * keep general card information, no settings or anything */ | ||
1357 | zr->card = zoran_cards[card_num]; | ||
1358 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), | ||
1359 | "%s[%u]", zr->card.name, zr->id); | ||
1360 | |||
1361 | zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0); | ||
1362 | if (!zr->zr36057_mem) { | ||
1363 | dprintk(1, | ||
1364 | KERN_ERR | ||
1365 | "%s: %s() - ioremap failed\n", | ||
1366 | ZR_DEVNAME(zr), __func__); | ||
1367 | goto zr_free_mem; | ||
1368 | } | ||
1419 | 1369 | ||
1420 | /* i2c decoder */ | 1370 | result = request_irq(zr->pci_dev->irq, zoran_irq, |
1421 | if (decoder[zr->id] != -1) { | 1371 | IRQF_SHARED | IRQF_DISABLED, ZR_DEVNAME(zr), zr); |
1422 | i2c_dec_name = i2cid_to_modulename(decoder[zr->id]); | 1372 | if (result < 0) { |
1423 | zr->card.i2c_decoder = decoder[zr->id]; | 1373 | if (result == -EINVAL) { |
1424 | } else if (zr->card.i2c_decoder != 0) { | 1374 | dprintk(1, |
1425 | i2c_dec_name = | 1375 | KERN_ERR |
1426 | i2cid_to_modulename(zr->card.i2c_decoder); | 1376 | "%s: find_zr36057() - bad irq number or handler\n", |
1377 | ZR_DEVNAME(zr)); | ||
1378 | } else if (result == -EBUSY) { | ||
1379 | dprintk(1, | ||
1380 | KERN_ERR | ||
1381 | "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n", | ||
1382 | ZR_DEVNAME(zr), zr->pci_dev->irq); | ||
1427 | } else { | 1383 | } else { |
1428 | i2c_dec_name = NULL; | 1384 | dprintk(1, |
1385 | KERN_ERR | ||
1386 | "%s: find_zr36057() - can't assign irq, error code %d\n", | ||
1387 | ZR_DEVNAME(zr), result); | ||
1429 | } | 1388 | } |
1389 | goto zr_unmap; | ||
1390 | } | ||
1430 | 1391 | ||
1431 | if (i2c_dec_name) { | 1392 | /* set PCI latency timer */ |
1432 | if ((result = request_module(i2c_dec_name)) < 0) { | 1393 | pci_read_config_byte(zr->pci_dev, PCI_LATENCY_TIMER, |
1433 | dprintk(1, | 1394 | &latency); |
1434 | KERN_ERR | 1395 | need_latency = zr->revision > 1 ? 32 : 48; |
1435 | "%s: failed to load module %s: %d\n", | 1396 | if (latency != need_latency) { |
1436 | ZR_DEVNAME(zr), i2c_dec_name, result); | 1397 | dprintk(2, |
1437 | } | 1398 | KERN_INFO |
1438 | } | 1399 | "%s: Changing PCI latency from %d to %d\n", |
1400 | ZR_DEVNAME(zr), latency, need_latency); | ||
1401 | pci_write_config_byte(zr->pci_dev, PCI_LATENCY_TIMER, | ||
1402 | need_latency); | ||
1403 | } | ||
1439 | 1404 | ||
1440 | /* i2c encoder */ | 1405 | zr36057_restart(zr); |
1441 | if (encoder[zr->id] != -1) { | 1406 | /* i2c */ |
1442 | i2c_enc_name = i2cid_to_modulename(encoder[zr->id]); | 1407 | dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n", |
1443 | zr->card.i2c_encoder = encoder[zr->id]; | 1408 | ZR_DEVNAME(zr)); |
1444 | } else if (zr->card.i2c_encoder != 0) { | 1409 | |
1445 | i2c_enc_name = | 1410 | /* i2c decoder */ |
1446 | i2cid_to_modulename(zr->card.i2c_encoder); | 1411 | if (decoder[zr->id] != -1) { |
1447 | } else { | 1412 | i2c_dec_name = i2cid_to_modulename(decoder[zr->id]); |
1448 | i2c_enc_name = NULL; | 1413 | zr->card.i2c_decoder = decoder[zr->id]; |
1449 | } | 1414 | } else if (zr->card.i2c_decoder != 0) { |
1415 | i2c_dec_name = i2cid_to_modulename(zr->card.i2c_decoder); | ||
1416 | } else { | ||
1417 | i2c_dec_name = NULL; | ||
1418 | } | ||
1450 | 1419 | ||
1451 | if (i2c_enc_name) { | 1420 | if (i2c_dec_name) { |
1452 | if ((result = request_module(i2c_enc_name)) < 0) { | 1421 | result = request_module(i2c_dec_name); |
1453 | dprintk(1, | 1422 | if (result < 0) { |
1454 | KERN_ERR | 1423 | dprintk(1, |
1455 | "%s: failed to load module %s: %d\n", | 1424 | KERN_ERR |
1456 | ZR_DEVNAME(zr), i2c_enc_name, result); | 1425 | "%s: failed to load module %s: %d\n", |
1457 | } | 1426 | ZR_DEVNAME(zr), i2c_dec_name, result); |
1458 | } | 1427 | } |
1428 | } | ||
1429 | |||
1430 | /* i2c encoder */ | ||
1431 | if (encoder[zr->id] != -1) { | ||
1432 | i2c_enc_name = i2cid_to_modulename(encoder[zr->id]); | ||
1433 | zr->card.i2c_encoder = encoder[zr->id]; | ||
1434 | } else if (zr->card.i2c_encoder != 0) { | ||
1435 | i2c_enc_name = i2cid_to_modulename(zr->card.i2c_encoder); | ||
1436 | } else { | ||
1437 | i2c_enc_name = NULL; | ||
1438 | } | ||
1459 | 1439 | ||
1460 | if (zoran_register_i2c(zr) < 0) { | 1440 | if (i2c_enc_name) { |
1441 | result = request_module(i2c_enc_name); | ||
1442 | if (result < 0) { | ||
1461 | dprintk(1, | 1443 | dprintk(1, |
1462 | KERN_ERR | 1444 | KERN_ERR |
1463 | "%s: find_zr36057() - can't initialize i2c bus\n", | 1445 | "%s: failed to load module %s: %d\n", |
1464 | ZR_DEVNAME(zr)); | 1446 | ZR_DEVNAME(zr), i2c_enc_name, result); |
1465 | goto zr_free_irq; | ||
1466 | } | 1447 | } |
1448 | } | ||
1467 | 1449 | ||
1468 | dprintk(2, | 1450 | if (zoran_register_i2c(zr) < 0) { |
1469 | KERN_INFO "%s: Initializing videocodec bus...\n", | 1451 | dprintk(1, |
1452 | KERN_ERR | ||
1453 | "%s: find_zr36057() - can't initialize i2c bus\n", | ||
1470 | ZR_DEVNAME(zr)); | 1454 | ZR_DEVNAME(zr)); |
1455 | goto zr_free_irq; | ||
1456 | } | ||
1471 | 1457 | ||
1472 | if (zr->card.video_codec != 0 && | 1458 | dprintk(2, |
1473 | (codec_name = | 1459 | KERN_INFO "%s: Initializing videocodec bus...\n", |
1474 | codecid_to_modulename(zr->card.video_codec)) != NULL) { | 1460 | ZR_DEVNAME(zr)); |
1475 | if ((result = request_module(codec_name)) < 0) { | 1461 | |
1462 | if (zr->card.video_codec) { | ||
1463 | codec_name = codecid_to_modulename(zr->card.video_codec); | ||
1464 | if (codec_name) { | ||
1465 | result = request_module(codec_name); | ||
1466 | if (result) { | ||
1476 | dprintk(1, | 1467 | dprintk(1, |
1477 | KERN_ERR | 1468 | KERN_ERR |
1478 | "%s: failed to load modules %s: %d\n", | 1469 | "%s: failed to load modules %s: %d\n", |
1479 | ZR_DEVNAME(zr), codec_name, result); | 1470 | ZR_DEVNAME(zr), codec_name, result); |
1480 | } | 1471 | } |
1481 | } | 1472 | } |
1482 | if (zr->card.video_vfe != 0 && | 1473 | } |
1483 | (vfe_name = | 1474 | if (zr->card.video_vfe) { |
1484 | codecid_to_modulename(zr->card.video_vfe)) != NULL) { | 1475 | vfe_name = codecid_to_modulename(zr->card.video_vfe); |
1485 | if ((result = request_module(vfe_name)) < 0) { | 1476 | if (vfe_name) { |
1477 | result = request_module(vfe_name); | ||
1478 | if (result < 0) { | ||
1486 | dprintk(1, | 1479 | dprintk(1, |
1487 | KERN_ERR | 1480 | KERN_ERR |
1488 | "%s: failed to load modules %s: %d\n", | 1481 | "%s: failed to load modules %s: %d\n", |
1489 | ZR_DEVNAME(zr), vfe_name, result); | 1482 | ZR_DEVNAME(zr), vfe_name, result); |
1490 | } | 1483 | } |
1491 | } | 1484 | } |
1485 | } | ||
1492 | 1486 | ||
1493 | /* reset JPEG codec */ | 1487 | /* reset JPEG codec */ |
1494 | jpeg_codec_sleep(zr, 1); | 1488 | jpeg_codec_sleep(zr, 1); |
1495 | jpeg_codec_reset(zr); | 1489 | jpeg_codec_reset(zr); |
1496 | /* video bus enabled */ | 1490 | /* video bus enabled */ |
1497 | /* display codec revision */ | 1491 | /* display codec revision */ |
1498 | if (zr->card.video_codec != 0) { | 1492 | if (zr->card.video_codec != 0) { |
1499 | master_codec = zoran_setup_videocodec(zr, | 1493 | master_codec = zoran_setup_videocodec(zr, zr->card.video_codec); |
1500 | zr->card.video_codec); | 1494 | if (!master_codec) |
1501 | if (!master_codec) | 1495 | goto zr_unreg_i2c; |
1502 | goto zr_unreg_i2c; | 1496 | zr->codec = videocodec_attach(master_codec); |
1503 | zr->codec = videocodec_attach(master_codec); | 1497 | if (!zr->codec) { |
1504 | if (!zr->codec) { | 1498 | dprintk(1, |
1505 | dprintk(1, | 1499 | KERN_ERR |
1506 | KERN_ERR | 1500 | "%s: find_zr36057() - no codec found\n", |
1507 | "%s: find_zr36057() - no codec found\n", | 1501 | ZR_DEVNAME(zr)); |
1508 | ZR_DEVNAME(zr)); | 1502 | goto zr_free_codec; |
1509 | goto zr_free_codec; | ||
1510 | } | ||
1511 | if (zr->codec->type != zr->card.video_codec) { | ||
1512 | dprintk(1, | ||
1513 | KERN_ERR | ||
1514 | "%s: find_zr36057() - wrong codec\n", | ||
1515 | ZR_DEVNAME(zr)); | ||
1516 | goto zr_detach_codec; | ||
1517 | } | ||
1518 | } | 1503 | } |
1519 | if (zr->card.video_vfe != 0) { | 1504 | if (zr->codec->type != zr->card.video_codec) { |
1520 | master_vfe = zoran_setup_videocodec(zr, | 1505 | dprintk(1, |
1521 | zr->card.video_vfe); | 1506 | KERN_ERR |
1522 | if (!master_vfe) | 1507 | "%s: find_zr36057() - wrong codec\n", |
1523 | goto zr_detach_codec; | 1508 | ZR_DEVNAME(zr)); |
1524 | zr->vfe = videocodec_attach(master_vfe); | 1509 | goto zr_detach_codec; |
1525 | if (!zr->vfe) { | 1510 | } |
1526 | dprintk(1, | 1511 | } |
1527 | KERN_ERR | 1512 | if (zr->card.video_vfe != 0) { |
1528 | "%s: find_zr36057() - no VFE found\n", | 1513 | master_vfe = zoran_setup_videocodec(zr, zr->card.video_vfe); |
1529 | ZR_DEVNAME(zr)); | 1514 | if (!master_vfe) |
1530 | goto zr_free_vfe; | 1515 | goto zr_detach_codec; |
1531 | } | 1516 | zr->vfe = videocodec_attach(master_vfe); |
1532 | if (zr->vfe->type != zr->card.video_vfe) { | 1517 | if (!zr->vfe) { |
1533 | dprintk(1, | 1518 | dprintk(1, |
1534 | KERN_ERR | 1519 | KERN_ERR |
1535 | "%s: find_zr36057() = wrong VFE\n", | 1520 | "%s: find_zr36057() - no VFE found\n", |
1536 | ZR_DEVNAME(zr)); | 1521 | ZR_DEVNAME(zr)); |
1537 | goto zr_detach_vfe; | 1522 | goto zr_free_vfe; |
1538 | } | 1523 | } |
1524 | if (zr->vfe->type != zr->card.video_vfe) { | ||
1525 | dprintk(1, | ||
1526 | KERN_ERR | ||
1527 | "%s: find_zr36057() = wrong VFE\n", | ||
1528 | ZR_DEVNAME(zr)); | ||
1529 | goto zr_detach_vfe; | ||
1539 | } | 1530 | } |
1540 | /* Success so keep the pci_dev referenced */ | ||
1541 | pci_dev_get(zr->pci_dev); | ||
1542 | zoran[zoran_num++] = zr; | ||
1543 | continue; | ||
1544 | |||
1545 | // Init errors | ||
1546 | zr_detach_vfe: | ||
1547 | videocodec_detach(zr->vfe); | ||
1548 | zr_free_vfe: | ||
1549 | kfree(master_vfe); | ||
1550 | zr_detach_codec: | ||
1551 | videocodec_detach(zr->codec); | ||
1552 | zr_free_codec: | ||
1553 | kfree(master_codec); | ||
1554 | zr_unreg_i2c: | ||
1555 | zoran_unregister_i2c(zr); | ||
1556 | zr_free_irq: | ||
1557 | btwrite(0, ZR36057_SPGPPCR); | ||
1558 | free_irq(zr->pci_dev->irq, zr); | ||
1559 | zr_unmap: | ||
1560 | iounmap(zr->zr36057_mem); | ||
1561 | zr_free_mem: | ||
1562 | kfree(zr); | ||
1563 | continue; | ||
1564 | } | 1531 | } |
1565 | if (dev) /* Clean up ref count on early exit */ | ||
1566 | pci_dev_put(dev); | ||
1567 | 1532 | ||
1568 | if (zoran_num == 0) { | 1533 | /* take care of Natoma chipset and a revision 1 zr36057 */ |
1569 | dprintk(1, KERN_INFO "No known MJPEG cards found.\n"); | 1534 | if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { |
1535 | zr->jpg_buffers.need_contiguous = 1; | ||
1536 | dprintk(1, | ||
1537 | KERN_INFO | ||
1538 | "%s: ZR36057/Natoma bug, max. buffer size is 128K\n", | ||
1539 | ZR_DEVNAME(zr)); | ||
1570 | } | 1540 | } |
1571 | return zoran_num; | 1541 | |
1542 | if (zr36057_init(zr) < 0) | ||
1543 | goto zr_detach_vfe; | ||
1544 | |||
1545 | zoran_proc_init(zr); | ||
1546 | |||
1547 | pci_set_drvdata(pdev, zr); | ||
1548 | |||
1549 | return 0; | ||
1550 | |||
1551 | zr_detach_vfe: | ||
1552 | videocodec_detach(zr->vfe); | ||
1553 | zr_free_vfe: | ||
1554 | kfree(master_vfe); | ||
1555 | zr_detach_codec: | ||
1556 | videocodec_detach(zr->codec); | ||
1557 | zr_free_codec: | ||
1558 | kfree(master_codec); | ||
1559 | zr_unreg_i2c: | ||
1560 | zoran_unregister_i2c(zr); | ||
1561 | zr_free_irq: | ||
1562 | btwrite(0, ZR36057_SPGPPCR); | ||
1563 | free_irq(zr->pci_dev->irq, zr); | ||
1564 | zr_unmap: | ||
1565 | iounmap(zr->zr36057_mem); | ||
1566 | zr_free_mem: | ||
1567 | kfree(zr); | ||
1568 | |||
1569 | return -ENODEV; | ||
1572 | } | 1570 | } |
1573 | 1571 | ||
1574 | static int __init | 1572 | static struct pci_driver zoran_driver = { |
1575 | init_dc10_cards (void) | 1573 | .name = "zr36067", |
1574 | .id_table = zr36067_pci_tbl, | ||
1575 | .probe = zoran_probe, | ||
1576 | .remove = zoran_remove, | ||
1577 | }; | ||
1578 | |||
1579 | static int __init zoran_init(void) | ||
1576 | { | 1580 | { |
1577 | int i; | 1581 | int res; |
1578 | 1582 | ||
1579 | memset(zoran, 0, sizeof(zoran)); | ||
1580 | printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n", | 1583 | printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n", |
1581 | MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION); | 1584 | MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION); |
1582 | 1585 | ||
1583 | /* Look for cards */ | ||
1584 | if (find_zr36057() < 0) { | ||
1585 | return -EIO; | ||
1586 | } | ||
1587 | if (zoran_num == 0) | ||
1588 | return -ENODEV; | ||
1589 | dprintk(1, KERN_INFO "%s: %d card(s) found\n", ZORAN_NAME, | ||
1590 | zoran_num); | ||
1591 | /* check the parameters we have been given, adjust if necessary */ | 1586 | /* check the parameters we have been given, adjust if necessary */ |
1592 | if (v4l_nbufs < 2) | 1587 | if (v4l_nbufs < 2) |
1593 | v4l_nbufs = 2; | 1588 | v4l_nbufs = 2; |
@@ -1629,37 +1624,22 @@ init_dc10_cards (void) | |||
1629 | ZORAN_NAME); | 1624 | ZORAN_NAME); |
1630 | } | 1625 | } |
1631 | 1626 | ||
1632 | /* take care of Natoma chipset and a revision 1 zr36057 */ | 1627 | res = pci_register_driver(&zoran_driver); |
1633 | for (i = 0; i < zoran_num; i++) { | 1628 | if (res) { |
1634 | struct zoran *zr = zoran[i]; | 1629 | dprintk(1, |
1635 | 1630 | KERN_ERR | |
1636 | if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { | 1631 | "%s: Unable to register ZR36057 driver\n", |
1637 | zr->jpg_buffers.need_contiguous = 1; | 1632 | ZORAN_NAME); |
1638 | dprintk(1, | 1633 | return res; |
1639 | KERN_INFO | ||
1640 | "%s: ZR36057/Natoma bug, max. buffer size is 128K\n", | ||
1641 | ZR_DEVNAME(zr)); | ||
1642 | } | ||
1643 | |||
1644 | if (zr36057_init(zr) < 0) { | ||
1645 | for (i = 0; i < zoran_num; i++) | ||
1646 | zoran_release(zoran[i]); | ||
1647 | return -EIO; | ||
1648 | } | ||
1649 | zoran_proc_init(zr); | ||
1650 | } | 1634 | } |
1651 | 1635 | ||
1652 | return 0; | 1636 | return 0; |
1653 | } | 1637 | } |
1654 | 1638 | ||
1655 | static void __exit | 1639 | static void __exit zoran_exit(void) |
1656 | unload_dc10_cards (void) | ||
1657 | { | 1640 | { |
1658 | int i; | 1641 | pci_unregister_driver(&zoran_driver); |
1659 | |||
1660 | for (i = 0; i < zoran_num; i++) | ||
1661 | zoran_release(zoran[i]); | ||
1662 | } | 1642 | } |
1663 | 1643 | ||
1664 | module_init(init_dc10_cards); | 1644 | module_init(zoran_init); |
1665 | module_exit(unload_dc10_cards); | 1645 | module_exit(zoran_exit); |