patch from Ian Abbott <abbotti@mev.co.uk>:
authorFrank Mori Hess <fmhess@speakeasy.net>
Sat, 12 Mar 2005 13:31:39 +0000 (13:31 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Sat, 12 Mar 2005 13:31:39 +0000 (13:31 +0000)
Here's a change to my new amplc_pci224 driver to use pci_request_regions
instead of check_region/request_region, as suggested by Frank.

comedi/drivers/amplc_pci224.c

index 3557294bbca93e9a3b781e4a19aa97b36ddb0306..8b15c339d8a58eff6de868322d428a9719e88fa0 100644 (file)
@@ -1313,22 +1313,6 @@ pci224_find_pci(comedi_device *dev, int bus, int slot,
        return -EIO;
 }
 
-/*
- * This function checks and requests an I/O region, reporting an error
- * if there is a conflict.
- */
-static int
-pci224_request_region(unsigned minor, unsigned long from, unsigned long extent)
-{
-       if (check_region(from, extent) < 0) {
-               printk(KERN_ERR "comedi%d: I/O port conflict (%#lx,%lu)!\n",
-                               minor, from, extent);
-               return -EIO;
-       }
-       request_region(from, extent, DRIVER_NAME);
-       return 0;
-}
-
 /*
  * Attach is called by the Comedi core to configure the driver
  * for a particular board.  If you specified a board_name array
@@ -1340,7 +1324,7 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it)
 {
        comedi_subdevice *s;
        struct pci_dev *pci_dev;
-       int iobase1 = 0, iobase2 = 0,  irq = 0;
+       int irq;
        int bus = 0, slot = 0;
        unsigned n;
        int ret;
@@ -1360,13 +1344,17 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it)
                pci_dev_put(pci_dev);
                return ret;
        }
-       iobase1 = pci_resource_start(pci_dev, 2);
-       iobase2 = pci_resource_start(pci_dev, 3);
-       irq = pci_dev->irq;
+       if (pci_request_regions(pci_dev, DRIVER_NAME)) {
+               printk(KERN_ERR "comedi%d: error! cannot allocate PCI regions!\n",
+                               dev->minor);
+               pci_dev_put(pci_dev);
+               return -EIO;
+       }
 
        if ((ret=alloc_private(dev,sizeof(pci224_private))) < 0) {
                printk(KERN_ERR "comedi%d: error! out of memory!\n",
                                dev->minor);
+               pci_release_regions(pci_dev);
                pci_dev_put(pci_dev);
                return ret; 
        }
@@ -1374,6 +1362,10 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it)
        devpriv->pci_dev = pci_dev;
        spin_lock_init(&devpriv->ao_spinlock);
 
+       devpriv->iobase1 = pci_resource_start(pci_dev, 2);
+       dev->iobase = pci_resource_start(pci_dev, 3);
+       irq = pci_dev->irq;
+
        /* Allocate readback buffer for AO channels. */
        devpriv->ao_readback = kmalloc(sizeof(devpriv->ao_readback[0]) *
                        thisboard->ao_chans, GFP_KERNEL);
@@ -1395,20 +1387,6 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it)
                return -ENOMEM;
        }
 
-       /* Reserve I/O space 1. */
-       ret = pci224_request_region(dev->minor, iobase1, PCI224_IO1_SIZE);
-       if (ret < 0) {
-               return ret;
-       }
-       devpriv->iobase1 = iobase1;
-
-       /* Reserve I/O space 2. */
-       ret = pci224_request_region(dev->minor, iobase2, PCI224_IO2_SIZE);
-       if (ret < 0) {
-               return ret;
-       }
-       dev->iobase = iobase2;
-
        /* Disable interrupt sources. */
        devpriv->intsce = 0;
        outb(0, devpriv->iobase1 + PCI224_INT_SCE);
@@ -1555,13 +1533,7 @@ pci224_detach(comedi_device *dev)
                         kfree(s->range_table_list);
                 }
         }
-       if (dev->iobase) {
-               release_region(dev->iobase, PCI224_IO2_SIZE);
-       }
        if (devpriv) {
-               if (devpriv->iobase1) {
-                       release_region(devpriv->iobase1, PCI224_IO1_SIZE);
-               }
                if (devpriv->ao_readback) {
                        kfree(devpriv->ao_readback);
                }
@@ -1572,6 +1544,7 @@ pci224_detach(comedi_device *dev)
                        kfree(devpriv->ao_scan_order);
                }
                if (devpriv->pci_dev) {
+                       pci_release_regions(devpriv->pci_dev);
                        pci_dev_put(devpriv->pci_dev);
                }
        }