diff -uprNX dontdiff 2.6-zoran-inc/drivers/media/video/zr36120-driver.c 2.6-zoran/drivers/media/video/zr36120-driver.c
--- 2.6-zoran-inc/drivers/media/video/zr36120-driver.c	2004-07-14 15:09:00.000000000 -0300
+++ 2.6-zoran/drivers/media/video/zr36120-driver.c	2004-07-14 16:08:18.000000000 -0300
@@ -1994,86 +1994,120 @@ static struct video_device vbi_template=
 	.minor		= -1,
 };
 
-/*
- *      Scan for a Zoran chip, request the irq and map the io memory
- */
+static int init_zr36120(struct zr36120 *ztv);
 static
-int __init find_zr36120(void)
+int __devinit zr36120_probe(struct pci_dev *dev,
+			    const struct pci_device_id *pci_id)
 {
-	int result;
-	struct zr36120 *ztv;
-	struct pci_dev *dev = NULL;
-	unsigned char revision;
-	int zr36120_num=0;
+	struct zr36120	*ztv;
+	int		retval;
+	u8		revision;
+
+	if (zr36120_ncards == ZR36120_MAX) {
+		printk(KERN_INFO "%s: maximum number of cards reached\n",
+			zr36120_name);
+		retval = -ENOMEM;
+		goto exit;
+	}
 
-	while ((dev = pci_find_device(PCI_VENDOR_ID_ZORAN,PCI_DEVICE_ID_ZORAN_36120, dev)))
-	{
-		/* Ok, a ZR36120/ZR36125 found! */
-		ztv = &zr36120_cards[zr36120_num];
-		ztv->dev = dev;
-
-		if (pci_enable_device(dev))
-			return -EIO;
-
-		pci_read_config_byte(dev, PCI_CLASS_REVISION, &revision);
-		printk(KERN_INFO "%s: Zoran %x (rev %d) ",
-			zr36120_name, dev->device, revision);
-		printk("bus: %d, devfn: %d, irq: %d, ",
-			dev->bus->number, dev->devfn, dev->irq);
-		printk("memory: 0x%08lx.\n", ztv->zr36120_adr);
-
-		DEBUG(printk(KERN_DEBUG "%s: mapped-memory at 0x%p\n",
-			zr36120_name, ztv->zr36120_mem));
-
-		result = request_irq(dev->irq, zr36120_irq,
-			SA_SHIRQ|SA_INTERRUPT, zr36120_name, (void *)ztv);
-		if (result==-EINVAL)
-		{
-			iounmap(ztv->zr36120_mem);
-			printk(KERN_ERR "%s: Bad irq number or handler\n",
-				zr36120_name);
-			return -EINVAL;
-		}
-		if (result==-EBUSY)
-			printk(KERN_ERR "%s: IRQ %d busy, change your PnP "
-					"config in BIOS\n", zr36120_name,
-					dev->irq);
-		if (result < 0) {
-			iounmap(ztv->zr36120_mem);
-			return result;
-		}
-		/* Enable bus-mastering */
-		pci_set_master(dev);
+	ztv = &(zr36120_cards[zr36120_ncards]);
+
+	ztv->dev = dev;
 
-		zr36120_num++;
+	if (pci_enable_device(dev)) {
+		retval = -EIO;
+		goto exit;
 	}
-	if(zr36120_num)
-		printk(KERN_INFO "%s: %d Zoran card(s) found.\n", zr36120_name,
-				zr36120_num);
-	return zr36120_num;
+
+	pci_read_config_byte(dev, PCI_CLASS_REVISION, &revision);
+	ztv->zr36120_adr = dev->resource[0].start;
+	printk(KERN_INFO "%s: Zoran %x (rev %d) ",
+		zr36120_name, dev->device, revision);
+	printk("bus: %d, devfn: %d, irq: %d, ",
+		dev->bus->number, dev->devfn, dev->irq);
+	printk("memory: 0x%08lx.\n", ztv->zr36120_adr);
+
+	ztv->zr36120_mem = ioremap(ztv->zr36120_adr, 0x1000);
+	if (ztv->zr36120_mem == NULL) {
+		printk(KERN_WARNING "%s: couldn't map bus memory\n",
+			zr36120_name);
+		retval = -EIO;
+		goto exit;
+	}
+
+	DEBUG(printk(KERN_DEBUG "%s: mapped-memory at 0x%p\n",
+		zr36120_name, ztv->zr36120_mem));
+
+	retval = request_irq(dev->irq, zr36120_irq,
+		SA_SHIRQ|SA_INTERRUPT, zr36120_name, (void *)ztv);
+	if (retval == -EINVAL)
+	{
+		printk(KERN_ERR "%s: Bad irq number or handler\n",
+			zr36120_name);
+		retval = -EINVAL;
+		goto unmap;
+	}
+	if (retval == -EBUSY) {
+		printk(KERN_ERR "%s: IRQ %d busy, change your PnP "
+				"config in BIOS\n", zr36120_name,
+				dev->irq);
+		goto unmap;
+	}
+
+	/* Enable bus-mastering */
+	pci_set_master(dev);
+
+	if (init_zr36120(ztv) < 0) {
+		retval = -EIO;
+		goto free_irq;
+	} 
+
+	pci_set_drvdata(dev, ztv);
+	zr36120_ncards++;
+	retval = 0;
+
+exit:
+	return retval;
+
+free_irq:
+	free_irq(dev->irq, ztv);
+
+unmap:
+	iounmap(ztv->zr36120_mem);
+
+	goto exit;
 }
 
 static
-int __init init_zr36120(int card)
+int __init init_zr36120(struct zr36120 *ztv)
 {
-	struct zr36120 *ztv = &zr36120_cards[card];
-	int	i;
+	int	i,
+		card = zr36120_ncards,
+		retval = 0;
 	void *alloc_mem1, *alloc_mem2; 
 
 	/* if the given cardtype valid? */
-	if (cardtype[card]>=NRTVCARDS) {
+	if (cardtype[card] >= NRTVCARDS) {
 		printk(KERN_INFO "%s: invalid cardtype(%d) detected\n",
 						zr36120_name, cardtype[card]);
-		return -1;
+		retval = -EINVAL;
+		goto exit;
+	}
+
+	alloc_mem1 = kmalloc(sizeof(struct video_device), GFP_KERNEL);
+	if (alloc_mem1 == NULL) {
+		printk(KERN_ERR "%s: failed to kmalloc data for video_device "
+				"entries\n", zr36120_name);
+		retval = -ENOMEM;
+		goto exit;
 	}
 
-	if (!(alloc_mem1 = kmalloc(sizeof(struct video_device), GFP_KERNEL)) ||
-	    !(alloc_mem2 = kmalloc(sizeof(struct video_device), GFP_KERNEL))) {
+	alloc_mem2 = kmalloc(sizeof(struct video_device), GFP_KERNEL);
+	if (alloc_mem2 == NULL) {
 		printk(KERN_ERR "%s: failed to kmalloc data for video_device "
 				"entries\n", zr36120_name);
-		if (alloc_mem1)
-			kfree(alloc_mem1);
-		return -1;
+		retval = -ENOMEM;
+		goto free_mem1;
 	}
 
 	/* reset the zoran */
@@ -2165,9 +2199,8 @@ int __init init_zr36120(int card)
 	strcpy(ztv->video_dev->name, ztv->i2c_adapter.name);
 	ztv->video_dev->priv = ztv;
 	if (video_register_device(ztv->video_dev, VFL_TYPE_GRABBER, video_nr) < 0) {
-		kfree(alloc_mem1);
-		kfree(alloc_mem2);
-		return -1;
+		retval = -EBUSY;
+		goto free_mem2;
 	}
 
 	ztv->vbi_dev = alloc_mem2;
@@ -2175,10 +2208,8 @@ int __init init_zr36120(int card)
 	strcpy(ztv->vbi_dev->name, ztv->i2c_adapter.name);
 	ztv->vbi_dev->priv = ztv;
 	if (video_register_device(ztv->vbi_dev, VFL_TYPE_VBI, vbi_nr) < 0) {
-		video_unregister_device(ztv->video_dev);
-		kfree(alloc_mem1);
-		kfree(alloc_mem2);
-		return -1;
+		retval = -EBUSY;
+		goto free_video_dev;
 	}
 	ztv->i2cbr = 0;
 	zr36120_i2c_load(ztv);
@@ -2188,67 +2219,75 @@ int __init init_zr36120(int card)
 		ZR36120_ICR);
 
 	printk(KERN_INFO "%s: installed %s\n",ztv->i2c_adapter.name,ztv->card->name);
-	return 0;
+
+exit:
+	return retval;
+
+free_video_dev:
+	video_unregister_device(ztv->video_dev);
+free_mem2:
+	kfree(alloc_mem2);
+free_mem1:
+	kfree(alloc_mem1);
+	goto exit;
 }
 
 static
-void release_zr36120(int max)
+void __devexit zr36120_remove(struct pci_dev *pci_dev)
 {
-	struct zr36120 *ztv;
-	int i;
+	struct zr36120 *ztv = pci_get_drvdata(pci_dev);
 
-	for (i=0;i<max; i++) 
-	{
-		ztv = &zr36120_cards[i];
+	/* turn off all capturing, DMA and IRQs */
+	/* reset the zoran */
+	zrand(~ZR36120_PCI_SOFTRESET, ZR36120_PCI);
+	udelay(10);
+	zror(ZR36120_PCI_SOFTRESET, ZR36120_PCI);
+	udelay(10);
 
-		/* turn off all capturing, DMA and IRQs */
-		/* reset the zoran */
-		zrand(~ZR36120_PCI_SOFTRESET, ZR36120_PCI);
-		udelay(10);
-		zror(ZR36120_PCI_SOFTRESET, ZR36120_PCI);
-		udelay(10);
-
-		/* first disable interrupts before unmapping the memory! */
-		zrwrite(0, ZR36120_ICR);
-		zrwrite(0xffffffffUL, ZR36120_ISR);
-
-		/* free it */
-		free_irq(ztv->dev->irq,ztv);
- 
-		zr36120_i2c_unload(ztv);
-
-		/* unmap and free memory */
-		if (ztv->zr36120_mem)
-			iounmap(ztv->zr36120_mem);
+	/* first disable interrupts before unmapping the memory! */
+	zrwrite(0, ZR36120_ICR);
+	zrwrite(0xffffffffUL, ZR36120_ISR);
 
-		video_unregister_device(ztv->video_dev);
-		video_unregister_device(ztv->vbi_dev);
-	}
+	/* free it */
+	free_irq(ztv->dev->irq, ztv);
+
+	zr36120_i2c_unload(ztv);
+
+	/* unmap and free memory */
+	if (ztv->zr36120_mem)
+		iounmap(ztv->zr36120_mem);
+
+	video_unregister_device(ztv->video_dev);
+	video_unregister_device(ztv->vbi_dev);
 }
 
+static struct  pci_driver zr36120_pci_driver = {
+	.name = "zr36120",
+	.id_table = zr36120_pci_tbl,
+	.probe = zr36120_probe,
+	.remove = zr36120_remove,
+};
+
 void __exit zr36120_exit(void)
 {
-	release_zr36120(zr36120_ncards);
+	pci_unregister_driver(&zr36120_pci_driver);
 }
 
 int __init zr36120_init(void)
 {
-	int	card;
- 
 	handle_chipset();
-	zr36120_ncards = find_zr36120();
-	if (zr36120_ncards<0)
-		/* no cards found, no need for a driver */
-		return -EIO;
-
-	/* initialize Zorans */
-	for (card = 0; card < zr36120_ncards; card++) {
-		if (init_zr36120(card)<0) {
-			/* only release the zorans we have registered */
-			release_zr36120(card);
-			return -EIO;
-		} 
+
+	if (pci_module_init(&zr36120_pci_driver) == -ENODEV) {
+		printk(KERN_INFO "%s: no cards found\n", zr36120_name);
+		return -ENODEV;
 	}
+
+	if (zr36120_ncards) {
+		printk(KERN_INFO "%s: %d Zoran card(s) found.\n", zr36120_name,
+				zr36120_ncards);
+	}
+	
+
 	return 0;
 }
 
