aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
authorTrent Piepho <xyzzy@speakeasy.org>2009-01-11 10:02:54 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-01-29 05:35:37 -0500
commit66aa66ea31371daad562bf22ff245caf707d5d40 (patch)
treee8246e33f329444cacb771979a0994a2ace50307 /drivers/media/video
parentf90c3c0bdd7a3f16eecf1b077f5e031c44ddb605 (diff)
V4L/DVB (10212): Convert to be a pci driver
This is a really old and crufty driver that wasn't using the long established pci driver framework. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Acked-by: Jean Delvare <khali@linux-fr.org> [mchehab@redhat.com: Cleaned up a few CodingStyle issues] Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/zoran/zoran_card.c596
-rw-r--r--drivers/media/video/zoran/zoran_card.h2
-rw-r--r--drivers/media/video/zoran/zoran_driver.c2
3 files changed, 296 insertions, 304 deletions
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c
index 4e8ecf356ad0..e987d53c2943 100644
--- a/drivers/media/video/zoran/zoran_card.c
+++ b/drivers/media/video/zoran/zoran_card.c
@@ -153,16 +153,13 @@ MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
153MODULE_AUTHOR("Serguei Miridonov"); 153MODULE_AUTHOR("Serguei Miridonov");
154MODULE_LICENSE("GPL"); 154MODULE_LICENSE("GPL");
155 155
156#if (defined(CONFIG_VIDEO_ZORAN_MODULE) && defined(MODULE))
157static struct pci_device_id zr36067_pci_tbl[] = { 156static struct pci_device_id zr36067_pci_tbl[] = {
158 {PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, 157 { PCI_DEVICE(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057), },
159 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
160 {0} 158 {0}
161}; 159};
162MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl); 160MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
163#endif
164 161
165int zoran_num; /* number of Buzs in use */ 162atomic_t zoran_num = ATOMIC_INIT(0); /* number of Buzs in use */
166struct zoran *zoran[BUZ_MAX]; 163struct zoran *zoran[BUZ_MAX];
167 164
168/* videocodec bus functions ZR36060 */ 165/* videocodec bus functions ZR36060 */
@@ -1146,7 +1143,7 @@ zr36057_init (struct zoran *zr)
1146 strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); 1143 strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
1147 err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]); 1144 err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
1148 if (err < 0) 1145 if (err < 0)
1149 goto exit_unregister; 1146 goto exit_free;
1150 1147
1151 zoran_init_hardware(zr); 1148 zoran_init_hardware(zr);
1152 if (zr36067_debug > 2) 1149 if (zr36067_debug > 2)
@@ -1161,19 +1158,19 @@ zr36057_init (struct zoran *zr)
1161 zr->initialized = 1; 1158 zr->initialized = 1;
1162 return 0; 1159 return 0;
1163 1160
1164exit_unregister:
1165 zoran_unregister_i2c(zr);
1166exit_free: 1161exit_free:
1167 kfree(zr->stat_com); 1162 kfree(zr->stat_com);
1168 kfree(zr->video_dev); 1163 kfree(zr->video_dev);
1169 return err; 1164 return err;
1170} 1165}
1171 1166
1172static void 1167static void __devexit zoran_remove(struct pci_dev *pdev)
1173zoran_release (struct zoran *zr)
1174{ 1168{
1169 struct zoran *zr = pci_get_drvdata(pdev);
1170
1175 if (!zr->initialized) 1171 if (!zr->initialized)
1176 goto exit_free; 1172 goto exit_free;
1173
1177 /* unregister videocodec bus */ 1174 /* unregister videocodec bus */
1178 if (zr->codec) { 1175 if (zr->codec) {
1179 struct videocodec_master *master = zr->codec->master_data; 1176 struct videocodec_master *master = zr->codec->master_data;
@@ -1202,6 +1199,7 @@ zoran_release (struct zoran *zr)
1202 pci_disable_device(zr->pci_dev); 1199 pci_disable_device(zr->pci_dev);
1203 video_unregister_device(zr->video_dev); 1200 video_unregister_device(zr->video_dev);
1204exit_free: 1201exit_free:
1202 pci_set_drvdata(pdev, NULL);
1205 kfree(zr); 1203 kfree(zr);
1206} 1204}
1207 1205
@@ -1264,338 +1262,347 @@ zoran_setup_videocodec (struct zoran *zr,
1264 * Scan for a Buz card (actually for the PCI controller ZR36057), 1262 * Scan for a Buz card (actually for the PCI controller ZR36057),
1265 * request the irq and map the io memory 1263 * request the irq and map the io memory
1266 */ 1264 */
1267static int __devinit 1265static int __devinit zoran_probe(struct pci_dev *pdev,
1268find_zr36057 (void) 1266 const struct pci_device_id *ent)
1269{ 1267{
1270 unsigned char latency, need_latency; 1268 unsigned char latency, need_latency;
1271 struct zoran *zr; 1269 struct zoran *zr;
1272 struct pci_dev *dev = NULL;
1273 int result; 1270 int result;
1274 struct videocodec_master *master_vfe = NULL; 1271 struct videocodec_master *master_vfe = NULL;
1275 struct videocodec_master *master_codec = NULL; 1272 struct videocodec_master *master_codec = NULL;
1276 int card_num; 1273 int card_num;
1277 char *i2c_enc_name, *i2c_dec_name, *codec_name, *vfe_name; 1274 char *i2c_enc_name, *i2c_dec_name, *codec_name, *vfe_name;
1275 unsigned int nr;
1278 1276
1279 zoran_num = 0;
1280 while (zoran_num < BUZ_MAX &&
1281 (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) {
1282 card_num = card[zoran_num];
1283 zr = kzalloc(sizeof(struct zoran), GFP_KERNEL);
1284 if (!zr) {
1285 dprintk(1,
1286 KERN_ERR
1287 "%s: find_zr36057() - kzalloc failed\n",
1288 ZORAN_NAME);
1289 continue;
1290 }
1291 zr->pci_dev = dev;
1292 //zr->zr36057_mem = NULL;
1293 zr->id = zoran_num;
1294 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
1295 spin_lock_init(&zr->spinlock);
1296 mutex_init(&zr->resource_lock);
1297 if (pci_enable_device(dev))
1298 goto zr_free_mem;
1299 zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0);
1300 pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION,
1301 &zr->revision);
1302 if (zr->revision < 2) {
1303 dprintk(1,
1304 KERN_INFO
1305 "%s: Zoran ZR36057 (rev %d) irq: %d, memory: 0x%08x.\n",
1306 ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
1307 zr->zr36057_adr);
1308 1277
1309 if (card_num == -1) { 1278 nr = atomic_inc_return(&zoran_num) - 1;
1310 dprintk(1, 1279 if (nr >= BUZ_MAX) {
1311 KERN_ERR 1280 dprintk(1,
1312 "%s: find_zr36057() - no card specified, please use the card=X insmod option\n", 1281 KERN_ERR
1313 ZR_DEVNAME(zr)); 1282 "%s: driver limited to %d card(s) maximum\n",
1314 goto zr_free_mem; 1283 ZORAN_NAME, BUZ_MAX);
1315 } 1284 return -ENOENT;
1316 } else { 1285 }
1317 int i;
1318 unsigned short ss_vendor, ss_device;
1319
1320 ss_vendor = zr->pci_dev->subsystem_vendor;
1321 ss_device = zr->pci_dev->subsystem_device;
1322 dprintk(1,
1323 KERN_INFO
1324 "%s: Zoran ZR36067 (rev %d) irq: %d, memory: 0x%08x\n",
1325 ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
1326 zr->zr36057_adr);
1327 dprintk(1,
1328 KERN_INFO
1329 "%s: subsystem vendor=0x%04x id=0x%04x\n",
1330 ZR_DEVNAME(zr), ss_vendor, ss_device);
1331 if (card_num == -1) {
1332 dprintk(3,
1333 KERN_DEBUG
1334 "%s: find_zr36057() - trying to autodetect card type\n",
1335 ZR_DEVNAME(zr));
1336 for (i=0;i<NUM_CARDS;i++) {
1337 if (ss_vendor == zoran_cards[i].vendor_id &&
1338 ss_device == zoran_cards[i].device_id) {
1339 dprintk(3,
1340 KERN_DEBUG
1341 "%s: find_zr36057() - card %s detected\n",
1342 ZR_DEVNAME(zr),
1343 zoran_cards[i].name);
1344 card_num = i;
1345 break;
1346 }
1347 }
1348 if (i == NUM_CARDS) {
1349 dprintk(1,
1350 KERN_ERR
1351 "%s: find_zr36057() - unknown card\n",
1352 ZR_DEVNAME(zr));
1353 goto zr_free_mem;
1354 }
1355 }
1356 }
1357 1286
1358 if (card_num < 0 || card_num >= NUM_CARDS) { 1287 card_num = card[nr];
1359 dprintk(2, 1288 zr = kzalloc(sizeof(struct zoran), GFP_KERNEL);
1360 KERN_ERR 1289 if (!zr) {
1361 "%s: find_zr36057() - invalid cardnum %d\n", 1290 dprintk(1,
1362 ZR_DEVNAME(zr), card_num); 1291 KERN_ERR
1363 goto zr_free_mem; 1292 "%s: find_zr36057() - kzalloc failed\n",
1364 } 1293 ZORAN_NAME);
1294 /* The entry in zoran[] gets leaked */
1295 return -ENOMEM;
1296 }
1297 zr->pci_dev = pdev;
1298 zr->id = nr;
1299 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
1300 spin_lock_init(&zr->spinlock);
1301 mutex_init(&zr->resource_lock);
1302 if (pci_enable_device(pdev))
1303 goto zr_free_mem;
1304 zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0);
1305 pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision);
1306 if (zr->revision < 2) {
1307 dprintk(1,
1308 KERN_INFO
1309 "%s: Zoran ZR36057 (rev %d) irq: %d, memory: 0x%08x.\n",
1310 ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
1311 zr->zr36057_adr);
1365 1312
1366 /* even though we make this a non pointer and thus 1313 if (card_num == -1) {
1367 * theoretically allow for making changes to this struct
1368 * on a per-individual card basis at runtime, this is
1369 * strongly discouraged. This structure is intended to
1370 * keep general card information, no settings or anything */
1371 zr->card = zoran_cards[card_num];
1372 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)),
1373 "%s[%u]", zr->card.name, zr->id);
1374
1375 zr->zr36057_mem = ioremap_nocache(zr->zr36057_adr, 0x1000);
1376 if (!zr->zr36057_mem) {
1377 dprintk(1, 1314 dprintk(1,
1378 KERN_ERR 1315 KERN_ERR
1379 "%s: find_zr36057() - ioremap failed\n", 1316 "%s: find_zr36057() - no card specified, please use the card=X insmod option\n",
1380 ZR_DEVNAME(zr)); 1317 ZR_DEVNAME(zr));
1381 goto zr_free_mem; 1318 goto zr_free_mem;
1382 } 1319 }
1320 } else {
1321 int i;
1322 unsigned short ss_vendor, ss_device;
1383 1323
1384 result = request_irq(zr->pci_dev->irq, 1324 ss_vendor = zr->pci_dev->subsystem_vendor;
1385 zoran_irq, 1325 ss_device = zr->pci_dev->subsystem_device;
1386 IRQF_SHARED | IRQF_DISABLED, 1326 dprintk(1,
1387 ZR_DEVNAME(zr), 1327 KERN_INFO
1388 (void *) zr); 1328 "%s: Zoran ZR36067 (rev %d) irq: %d, memory: 0x%08x\n",
1389 if (result < 0) { 1329 ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
1390 if (result == -EINVAL) { 1330 zr->zr36057_adr);
1331 dprintk(1,
1332 KERN_INFO
1333 "%s: subsystem vendor=0x%04x id=0x%04x\n",
1334 ZR_DEVNAME(zr), ss_vendor, ss_device);
1335 if (card_num == -1) {
1336 dprintk(3,
1337 KERN_DEBUG
1338 "%s: find_zr36057() - trying to autodetect card type\n",
1339 ZR_DEVNAME(zr));
1340 for (i = 0; i < NUM_CARDS; i++) {
1341 if (ss_vendor == zoran_cards[i].vendor_id &&
1342 ss_device == zoran_cards[i].device_id) {
1343 dprintk(3,
1344 KERN_DEBUG
1345 "%s: find_zr36057() - card %s detected\n",
1346 ZR_DEVNAME(zr),
1347 zoran_cards[i].name);
1348 card_num = i;
1349 break;
1350 }
1351 }
1352 if (i == NUM_CARDS) {
1391 dprintk(1, 1353 dprintk(1,
1392 KERN_ERR 1354 KERN_ERR
1393 "%s: find_zr36057() - bad irq number or handler\n", 1355 "%s: find_zr36057() - unknown card\n",
1394 ZR_DEVNAME(zr)); 1356 ZR_DEVNAME(zr));
1395 } else if (result == -EBUSY) { 1357 goto zr_free_mem;
1396 dprintk(1,
1397 KERN_ERR
1398 "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n",
1399 ZR_DEVNAME(zr), zr->pci_dev->irq);
1400 } else {
1401 dprintk(1,
1402 KERN_ERR
1403 "%s: find_zr36057() - can't assign irq, error code %d\n",
1404 ZR_DEVNAME(zr), result);
1405 } 1358 }
1406 goto zr_unmap;
1407 } 1359 }
1360 }
1408 1361
1409 /* set PCI latency timer */ 1362 if (card_num < 0 || card_num >= NUM_CARDS) {
1410 pci_read_config_byte(zr->pci_dev, PCI_LATENCY_TIMER, 1363 dprintk(2,
1411 &latency); 1364 KERN_ERR
1412 need_latency = zr->revision > 1 ? 32 : 48; 1365 "%s: find_zr36057() - invalid cardnum %d\n",
1413 if (latency != need_latency) { 1366 ZR_DEVNAME(zr), card_num);
1414 dprintk(2, 1367 goto zr_free_mem;
1415 KERN_INFO 1368 }
1416 "%s: Changing PCI latency from %d to %d.\n",
1417 ZR_DEVNAME(zr), latency, need_latency);
1418 pci_write_config_byte(zr->pci_dev,
1419 PCI_LATENCY_TIMER,
1420 need_latency);
1421 }
1422 1369
1423 zr36057_restart(zr); 1370 /* even though we make this a non pointer and thus
1424 /* i2c */ 1371 * theoretically allow for making changes to this struct
1425 dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n", 1372 * on a per-individual card basis at runtime, this is
1373 * strongly discouraged. This structure is intended to
1374 * keep general card information, no settings or anything */
1375 zr->card = zoran_cards[card_num];
1376 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)),
1377 "%s[%u]", zr->card.name, zr->id);
1378
1379 zr->zr36057_mem = ioremap_nocache(zr->zr36057_adr, 0x1000);
1380 if (!zr->zr36057_mem) {
1381 dprintk(1,
1382 KERN_ERR
1383 "%s: find_zr36057() - ioremap failed\n",
1426 ZR_DEVNAME(zr)); 1384 ZR_DEVNAME(zr));
1385 goto zr_free_mem;
1386 }
1427 1387
1428 /* i2c decoder */ 1388 result = request_irq(zr->pci_dev->irq, zoran_irq,
1429 if (decoder[zr->id] != -1) { 1389 IRQF_SHARED | IRQF_DISABLED, ZR_DEVNAME(zr), zr);
1430 i2c_dec_name = i2cid_to_modulename(decoder[zr->id]); 1390 if (result < 0) {
1431 zr->card.i2c_decoder = decoder[zr->id]; 1391 if (result == -EINVAL) {
1432 } else if (zr->card.i2c_decoder != 0) { 1392 dprintk(1,
1433 i2c_dec_name = 1393 KERN_ERR
1434 i2cid_to_modulename(zr->card.i2c_decoder); 1394 "%s: find_zr36057() - bad irq number or handler\n",
1395 ZR_DEVNAME(zr));
1396 } else if (result == -EBUSY) {
1397 dprintk(1,
1398 KERN_ERR
1399 "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n",
1400 ZR_DEVNAME(zr), zr->pci_dev->irq);
1435 } else { 1401 } else {
1436 i2c_dec_name = NULL; 1402 dprintk(1,
1403 KERN_ERR
1404 "%s: find_zr36057() - can't assign irq, error code %d\n",
1405 ZR_DEVNAME(zr), result);
1437 } 1406 }
1407 goto zr_unmap;
1408 }
1438 1409
1439 if (i2c_dec_name) { 1410 /* set PCI latency timer */
1440 if ((result = request_module(i2c_dec_name)) < 0) { 1411 pci_read_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
1441 dprintk(1, 1412 &latency);
1442 KERN_ERR 1413 need_latency = zr->revision > 1 ? 32 : 48;
1443 "%s: failed to load module %s: %d\n", 1414 if (latency != need_latency) {
1444 ZR_DEVNAME(zr), i2c_dec_name, result); 1415 dprintk(2,
1445 } 1416 KERN_INFO
1446 } 1417 "%s: Changing PCI latency from %d to %d\n",
1418 ZR_DEVNAME(zr), latency, need_latency);
1419 pci_write_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
1420 need_latency);
1421 }
1447 1422
1448 /* i2c encoder */ 1423 zr36057_restart(zr);
1449 if (encoder[zr->id] != -1) { 1424 /* i2c */
1450 i2c_enc_name = i2cid_to_modulename(encoder[zr->id]); 1425 dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n",
1451 zr->card.i2c_encoder = encoder[zr->id]; 1426 ZR_DEVNAME(zr));
1452 } else if (zr->card.i2c_encoder != 0) { 1427
1453 i2c_enc_name = 1428 /* i2c decoder */
1454 i2cid_to_modulename(zr->card.i2c_encoder); 1429 if (decoder[zr->id] != -1) {
1455 } else { 1430 i2c_dec_name = i2cid_to_modulename(decoder[zr->id]);
1456 i2c_enc_name = NULL; 1431 zr->card.i2c_decoder = decoder[zr->id];
1457 } 1432 } else if (zr->card.i2c_decoder != 0) {
1433 i2c_dec_name = i2cid_to_modulename(zr->card.i2c_decoder);
1434 } else {
1435 i2c_dec_name = NULL;
1436 }
1458 1437
1459 if (i2c_enc_name) { 1438 if (i2c_dec_name) {
1460 if ((result = request_module(i2c_enc_name)) < 0) { 1439 result = request_module(i2c_dec_name);
1461 dprintk(1, 1440 if (result < 0) {
1462 KERN_ERR 1441 dprintk(1,
1463 "%s: failed to load module %s: %d\n", 1442 KERN_ERR
1464 ZR_DEVNAME(zr), i2c_enc_name, result); 1443 "%s: failed to load module %s: %d\n",
1465 } 1444 ZR_DEVNAME(zr), i2c_dec_name, result);
1466 } 1445 }
1446 }
1467 1447
1468 if (zoran_register_i2c(zr) < 0) { 1448 /* i2c encoder */
1449 if (encoder[zr->id] != -1) {
1450 i2c_enc_name = i2cid_to_modulename(encoder[zr->id]);
1451 zr->card.i2c_encoder = encoder[zr->id];
1452 } else if (zr->card.i2c_encoder != 0) {
1453 i2c_enc_name = i2cid_to_modulename(zr->card.i2c_encoder);
1454 } else {
1455 i2c_enc_name = NULL;
1456 }
1457
1458 if (i2c_enc_name) {
1459 result = request_module(i2c_enc_name);
1460 if (result < 0) {
1469 dprintk(1, 1461 dprintk(1,
1470 KERN_ERR 1462 KERN_ERR
1471 "%s: find_zr36057() - can't initialize i2c bus\n", 1463 "%s: failed to load module %s: %d\n",
1472 ZR_DEVNAME(zr)); 1464 ZR_DEVNAME(zr), i2c_enc_name, result);
1473 goto zr_free_irq;
1474 } 1465 }
1466 }
1475 1467
1476 dprintk(2, 1468 if (zoran_register_i2c(zr) < 0) {
1477 KERN_INFO "%s: Initializing videocodec bus...\n", 1469 dprintk(1,
1470 KERN_ERR
1471 "%s: find_zr36057() - can't initialize i2c bus\n",
1478 ZR_DEVNAME(zr)); 1472 ZR_DEVNAME(zr));
1473 goto zr_free_irq;
1474 }
1479 1475
1480 if (zr->card.video_codec != 0 && 1476 dprintk(2,
1481 (codec_name = 1477 KERN_INFO "%s: Initializing videocodec bus...\n",
1482 codecid_to_modulename(zr->card.video_codec)) != NULL) { 1478 ZR_DEVNAME(zr));
1483 if ((result = request_module(codec_name)) < 0) { 1479
1480 if (zr->card.video_codec) {
1481 codec_name = codecid_to_modulename(zr->card.video_codec);
1482 if (codec_name) {
1483 result = request_module(codec_name);
1484 if (result) {
1484 dprintk(1, 1485 dprintk(1,
1485 KERN_ERR 1486 KERN_ERR
1486 "%s: failed to load modules %s: %d\n", 1487 "%s: failed to load modules %s: %d\n",
1487 ZR_DEVNAME(zr), codec_name, result); 1488 ZR_DEVNAME(zr), codec_name, result);
1488 } 1489 }
1489 } 1490 }
1490 if (zr->card.video_vfe != 0 && 1491 }
1491 (vfe_name = 1492 if (zr->card.video_vfe) {
1492 codecid_to_modulename(zr->card.video_vfe)) != NULL) { 1493 vfe_name = codecid_to_modulename(zr->card.video_vfe);
1493 if ((result = request_module(vfe_name)) < 0) { 1494 if (vfe_name) {
1495 result = request_module(vfe_name);
1496 if (result < 0) {
1494 dprintk(1, 1497 dprintk(1,
1495 KERN_ERR 1498 KERN_ERR
1496 "%s: failed to load modules %s: %d\n", 1499 "%s: failed to load modules %s: %d\n",
1497 ZR_DEVNAME(zr), vfe_name, result); 1500 ZR_DEVNAME(zr), vfe_name, result);
1498 } 1501 }
1499 } 1502 }
1503 }
1500 1504
1501 /* reset JPEG codec */ 1505 /* reset JPEG codec */
1502 jpeg_codec_sleep(zr, 1); 1506 jpeg_codec_sleep(zr, 1);
1503 jpeg_codec_reset(zr); 1507 jpeg_codec_reset(zr);
1504 /* video bus enabled */ 1508 /* video bus enabled */
1505 /* display codec revision */ 1509 /* display codec revision */
1506 if (zr->card.video_codec != 0) { 1510 if (zr->card.video_codec != 0) {
1507 master_codec = zoran_setup_videocodec(zr, 1511 master_codec = zoran_setup_videocodec(zr, zr->card.video_codec);
1508 zr->card.video_codec); 1512 if (!master_codec)
1509 if (!master_codec) 1513 goto zr_unreg_i2c;
1510 goto zr_unreg_i2c; 1514 zr->codec = videocodec_attach(master_codec);
1511 zr->codec = videocodec_attach(master_codec); 1515 if (!zr->codec) {
1512 if (!zr->codec) { 1516 dprintk(1,
1513 dprintk(1, 1517 KERN_ERR
1514 KERN_ERR 1518 "%s: find_zr36057() - no codec found\n",
1515 "%s: find_zr36057() - no codec found\n", 1519 ZR_DEVNAME(zr));
1516 ZR_DEVNAME(zr)); 1520 goto zr_free_codec;
1517 goto zr_free_codec;
1518 }
1519 if (zr->codec->type != zr->card.video_codec) {
1520 dprintk(1,
1521 KERN_ERR
1522 "%s: find_zr36057() - wrong codec\n",
1523 ZR_DEVNAME(zr));
1524 goto zr_detach_codec;
1525 }
1526 } 1521 }
1527 if (zr->card.video_vfe != 0) { 1522 if (zr->codec->type != zr->card.video_codec) {
1528 master_vfe = zoran_setup_videocodec(zr, 1523 dprintk(1,
1529 zr->card.video_vfe); 1524 KERN_ERR
1530 if (!master_vfe) 1525 "%s: find_zr36057() - wrong codec\n",
1531 goto zr_detach_codec; 1526 ZR_DEVNAME(zr));
1532 zr->vfe = videocodec_attach(master_vfe); 1527 goto zr_detach_codec;
1533 if (!zr->vfe) {
1534 dprintk(1,
1535 KERN_ERR
1536 "%s: find_zr36057() - no VFE found\n",
1537 ZR_DEVNAME(zr));
1538 goto zr_free_vfe;
1539 }
1540 if (zr->vfe->type != zr->card.video_vfe) {
1541 dprintk(1,
1542 KERN_ERR
1543 "%s: find_zr36057() = wrong VFE\n",
1544 ZR_DEVNAME(zr));
1545 goto zr_detach_vfe;
1546 }
1547 } 1528 }
1548 /* Success so keep the pci_dev referenced */
1549 pci_dev_get(zr->pci_dev);
1550 zoran[zoran_num++] = zr;
1551 continue;
1552
1553 // Init errors
1554 zr_detach_vfe:
1555 videocodec_detach(zr->vfe);
1556 zr_free_vfe:
1557 kfree(master_vfe);
1558 zr_detach_codec:
1559 videocodec_detach(zr->codec);
1560 zr_free_codec:
1561 kfree(master_codec);
1562 zr_unreg_i2c:
1563 zoran_unregister_i2c(zr);
1564 zr_free_irq:
1565 btwrite(0, ZR36057_SPGPPCR);
1566 free_irq(zr->pci_dev->irq, zr);
1567 zr_unmap:
1568 iounmap(zr->zr36057_mem);
1569 zr_free_mem:
1570 kfree(zr);
1571 continue;
1572 } 1529 }
1573 if (dev) /* Clean up ref count on early exit */ 1530 if (zr->card.video_vfe != 0) {
1574 pci_dev_put(dev); 1531 master_vfe = zoran_setup_videocodec(zr, zr->card.video_vfe);
1532 if (!master_vfe)
1533 goto zr_detach_codec;
1534 zr->vfe = videocodec_attach(master_vfe);
1535 if (!zr->vfe) {
1536 dprintk(1,
1537 KERN_ERR
1538 "%s: find_zr36057() - no VFE found\n",
1539 ZR_DEVNAME(zr));
1540 goto zr_free_vfe;
1541 }
1542 if (zr->vfe->type != zr->card.video_vfe) {
1543 dprintk(1,
1544 KERN_ERR
1545 "%s: find_zr36057() = wrong VFE\n",
1546 ZR_DEVNAME(zr));
1547 goto zr_detach_vfe;
1548 }
1549 }
1550 zoran[nr] = zr;
1575 1551
1576 if (zoran_num == 0) { 1552 /* take care of Natoma chipset and a revision 1 zr36057 */
1577 dprintk(1, KERN_INFO "No known MJPEG cards found.\n"); 1553 if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
1554 zr->jpg_buffers.need_contiguous = 1;
1555 dprintk(1,
1556 KERN_INFO
1557 "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
1558 ZR_DEVNAME(zr));
1578 } 1559 }
1579 return zoran_num; 1560
1561 if (zr36057_init(zr) < 0)
1562 goto zr_detach_vfe;
1563
1564 zoran_proc_init(zr);
1565
1566 pci_set_drvdata(pdev, zr);
1567
1568 return 0;
1569
1570zr_detach_vfe:
1571 videocodec_detach(zr->vfe);
1572zr_free_vfe:
1573 kfree(master_vfe);
1574zr_detach_codec:
1575 videocodec_detach(zr->codec);
1576zr_free_codec:
1577 kfree(master_codec);
1578zr_unreg_i2c:
1579 zoran_unregister_i2c(zr);
1580zr_free_irq:
1581 btwrite(0, ZR36057_SPGPPCR);
1582 free_irq(zr->pci_dev->irq, zr);
1583zr_unmap:
1584 iounmap(zr->zr36057_mem);
1585zr_free_mem:
1586 kfree(zr);
1587
1588 return -ENODEV;
1580} 1589}
1581 1590
1582static int __init 1591static struct pci_driver zoran_driver = {
1583init_dc10_cards (void) 1592 .name = "zr36067",
1593 .id_table = zr36067_pci_tbl,
1594 .probe = zoran_probe,
1595 .remove = zoran_remove,
1596};
1597
1598static int __init zoran_init(void)
1584{ 1599{
1585 int i; 1600 int res;
1586 1601
1587 memset(zoran, 0, sizeof(zoran)); 1602 memset(zoran, 0, sizeof(zoran));
1588 printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n", 1603 printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n",
1589 MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION); 1604 MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION);
1590 1605
1591 /* Look for cards */
1592 if (find_zr36057() < 0) {
1593 return -EIO;
1594 }
1595 if (zoran_num == 0)
1596 return -ENODEV;
1597 dprintk(1, KERN_INFO "%s: %d card(s) found\n", ZORAN_NAME,
1598 zoran_num);
1599 /* check the parameters we have been given, adjust if necessary */ 1606 /* check the parameters we have been given, adjust if necessary */
1600 if (v4l_nbufs < 2) 1607 if (v4l_nbufs < 2)
1601 v4l_nbufs = 2; 1608 v4l_nbufs = 2;
@@ -1637,37 +1644,22 @@ init_dc10_cards (void)
1637 ZORAN_NAME); 1644 ZORAN_NAME);
1638 } 1645 }
1639 1646
1640 /* take care of Natoma chipset and a revision 1 zr36057 */ 1647 res = pci_register_driver(&zoran_driver);
1641 for (i = 0; i < zoran_num; i++) { 1648 if (res) {
1642 struct zoran *zr = zoran[i]; 1649 dprintk(1,
1643 1650 KERN_ERR
1644 if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { 1651 "%s: Unable to register ZR36057 driver\n",
1645 zr->jpg_buffers.need_contiguous = 1; 1652 ZORAN_NAME);
1646 dprintk(1, 1653 return res;
1647 KERN_INFO
1648 "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
1649 ZR_DEVNAME(zr));
1650 }
1651
1652 if (zr36057_init(zr) < 0) {
1653 for (i = 0; i < zoran_num; i++)
1654 zoran_release(zoran[i]);
1655 return -EIO;
1656 }
1657 zoran_proc_init(zr);
1658 } 1654 }
1659 1655
1660 return 0; 1656 return 0;
1661} 1657}
1662 1658
1663static void __exit 1659static void __exit zoran_exit(void)
1664unload_dc10_cards (void)
1665{ 1660{
1666 int i; 1661 pci_unregister_driver(&zoran_driver);
1667
1668 for (i = 0; i < zoran_num; i++)
1669 zoran_release(zoran[i]);
1670} 1662}
1671 1663
1672module_init(init_dc10_cards); 1664module_init(zoran_init);
1673module_exit(unload_dc10_cards); 1665module_exit(zoran_exit);
diff --git a/drivers/media/video/zoran/zoran_card.h b/drivers/media/video/zoran/zoran_card.h
index e4dc9d29b404..c989448a77de 100644
--- a/drivers/media/video/zoran/zoran_card.h
+++ b/drivers/media/video/zoran/zoran_card.h
@@ -40,7 +40,7 @@ extern int zr36067_debug;
40 40
41/* Anybody who uses more than four? */ 41/* Anybody who uses more than four? */
42#define BUZ_MAX 4 42#define BUZ_MAX 4
43extern int zoran_num; 43extern atomic_t zoran_num;
44extern struct zoran *zoran[BUZ_MAX]; 44extern struct zoran *zoran[BUZ_MAX];
45 45
46extern struct video_device zoran_template; 46extern struct video_device zoran_template;
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
index b58b9dda715c..5e667fd72725 100644
--- a/drivers/media/video/zoran/zoran_driver.c
+++ b/drivers/media/video/zoran/zoran_driver.c
@@ -1206,7 +1206,7 @@ zoran_open(struct file *file)
1206 1206
1207 lock_kernel(); 1207 lock_kernel();
1208 /* find the device */ 1208 /* find the device */
1209 for (i = 0; i < zoran_num; i++) { 1209 for (i = 0; i < atomic_read(&zoran_num); i++) {
1210 if (zoran[i]->video_dev->minor == minor) { 1210 if (zoran[i]->video_dev->minor == minor) {
1211 zr = zoran[i]; 1211 zr = zoran[i];
1212 break; 1212 break;