New wrapper functions in comedi/drivers/comedi_pci.h:
authorIan Abbott <abbotti@mev.co.uk>
Thu, 1 Nov 2007 15:39:26 +0000 (15:39 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Thu, 1 Nov 2007 15:39:26 +0000 (15:39 +0000)
comedi_pci_enable() combines pci_enable_device() and pci_request_regions().
comedi_pci_disable() combines pci_release_regions() and pci_disable_device().
Does the right thing for reference-counted PCI enables in 2.6.20 onwards.

34 files changed:
comedi/drivers/Makefile.am
comedi/drivers/adl_pci6208.c
comedi/drivers/adl_pci7296.c
comedi/drivers/adl_pci7432.c
comedi/drivers/adl_pci8164.c
comedi/drivers/adl_pci9111.c
comedi/drivers/adl_pci9118.c
comedi/drivers/adv_pci1710.c
comedi/drivers/adv_pci_dio.c
comedi/drivers/amplc_dio200.c
comedi/drivers/amplc_pc236.c
comedi/drivers/amplc_pc263.c
comedi/drivers/amplc_pci224.c
comedi/drivers/amplc_pci230.c
comedi/drivers/cb_pcidas.c
comedi/drivers/cb_pcidas64.c
comedi/drivers/cb_pcidda.c
comedi/drivers/cb_pcidio.c
comedi/drivers/cb_pcimdas.c
comedi/drivers/cb_pcimdda.c
comedi/drivers/comedi_pci.h [new file with mode: 0644]
comedi/drivers/contec_pci_dio.c
comedi/drivers/daqboard2000.c
comedi/drivers/das08.c
comedi/drivers/dt3000.c
comedi/drivers/gsc_hpdi.c
comedi/drivers/icp_multi.h
comedi/drivers/jr3_pci.c
comedi/drivers/ke_counter.c
comedi/drivers/me4000.c
comedi/drivers/me_daq.c
comedi/drivers/mite.c
comedi/drivers/rtd520.c
comedi/drivers/s626.c

index 1588d0f367bb39a66e3cecfe60246001eb7a2b58..83a7bb55dc75826cc8b4e4f9827d311fa64c30a4 100644 (file)
@@ -39,6 +39,7 @@ EXTRA_DIST = \
  am9513.h \
  amcc_s5933.h \
  comedi_fc.h \
+ comedi_pci.h \
  das08.h \
  dt9812.h \
  icp_multi.h \
index b1b21714499ad99b15ca9f191e253b7496e8fb13..19a62aa8a26a1ab69445e30843d46111c836ad16 100644 (file)
@@ -52,7 +52,7 @@ References:
  * options that are used with comedi_config.
  */
 #include <linux/comedidev.h>
-#include <linux/pci.h> /* for PCI devices */
+#include "comedi_pci.h"
 
 #define PCI6208_DRIVER_NAME    "adl_pci6208"
 
@@ -207,8 +207,7 @@ static int pci6208_detach(comedi_device *dev)
        
        if(devpriv && devpriv->pci_dev){
                if(dev->iobase) {
-                       pci_release_regions(devpriv->pci_dev);
-                       pci_disable_device(devpriv->pci_dev);
+                       comedi_pci_disable(devpriv->pci_dev);
                }
                pci_dev_put(devpriv->pci_dev);
        }
@@ -363,9 +362,9 @@ pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr, int dev_m
 {
        unsigned long io_base, io_range, lcr_io_base, lcr_io_range;
 
-       // Enable PCI device
-       if (pci_enable_device(pci_dev) < 0) {
-               printk("comedi%d: Failed to enable PCI device\n", dev_minor);
+       // Enable PCI device and request regions
+       if (comedi_pci_enable(pci_dev, PCI6208_DRIVER_NAME) < 0) {
+               printk("comedi%d: Failed to enable PCI device and request regions\n", dev_minor);
                return -EIO;
        }
        
@@ -387,12 +386,6 @@ pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr, int dev_m
                io_base,
                io_range);
        
-       // Allocate IO ressources         
-       if (pci_request_regions(pci_dev, PCI6208_DRIVER_NAME) < 0) {
-               printk("comedi%d: I/O port conflict\n",dev_minor);
-               return -EIO;
-       }
-       
        *io_base_ptr = io_base;
        //devpriv->io_range = io_range;
        //devpriv->is_valid=0;
index fcd60c3cd22d787e940b643bb75df8540c0af15f..f136acda4e4739ef46b16a8291a81faaeec53506 100644 (file)
@@ -33,8 +33,8 @@ Configuration Options:
 
 #include <linux/comedidev.h>
 #include <linux/kernel.h>
-#include <linux/pci.h>
 
+#include "comedi_pci.h"
 #include "8255.h"
 // #include "8253.h"
 
@@ -109,12 +109,9 @@ static int adl_pci7296_attach(comedi_device *dev,comedi_devconfig *it)
                if ( pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
                     pcidev->device == PCI_DEVICE_ID_PCI7296 ) {
                        devpriv->pci_dev = pcidev;
-                       if (pci_enable_device(pcidev) < 0) {
-                               printk("comedi%d: Failed to enable PCI device\n", dev->minor);
-                               return -EIO;
-                       }
-                       if (pci_request_regions(pcidev, "adl_pci7296") < 0) {
-                               printk("comedi%d: I/O port conflict\n", dev->minor);
+                       if (comedi_pci_enable(pcidev, "adl_pci7296") < 0) {
+                               printk("comedi%d: Failed to enable PCI device and request regions\n",
+                                               dev->minor);
                                return -EIO;
                        }
 
@@ -152,8 +149,7 @@ static int adl_pci7296_detach(comedi_device *dev)
 
        if (devpriv && devpriv->pci_dev) {
                if (dev->iobase) {
-                       pci_release_regions(devpriv->pci_dev);
-                       pci_disable_device(devpriv->pci_dev);
+                       comedi_pci_disable(devpriv->pci_dev);
                }
                pci_dev_put(devpriv->pci_dev);
        }
index 592c42117cd7f2083a4a775a50e0ec9750efdd60..c6a4c227d5f9c171ca818140e6a41c2067f2351d 100644 (file)
@@ -32,7 +32,7 @@ Configuration Options:
 
 #include <linux/comedidev.h>
 #include <linux/kernel.h>
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 #define PCI7432_DI      0x00
 #define PCI7432_DO         0x00
@@ -109,12 +109,8 @@ static int adl_pci7432_attach(comedi_device *dev,comedi_devconfig *it)
                if ( pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
                     pcidev->device == PCI_DEVICE_ID_PCI7432 ) {
                        devpriv->pci_dev = pcidev;
-                       if (pci_enable_device(pcidev) < 0) {
-                               printk("comedi%d: Failed to enable PCI device\n", dev->minor);
-                               return -EIO;
-                       }
-                       if (pci_request_regions(pcidev, "adl_pci7432") < 0) {
-                               printk("comedi%d: I/O port conflict\n", dev->minor);
+                       if (comedi_pci_enable(pcidev, "adl_pci7432") < 0) {
+                               printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor);
                                return -EIO;
                        }
                        dev->iobase = pci_resource_start ( pcidev, 2 );
@@ -158,8 +154,7 @@ static int adl_pci7432_detach(comedi_device *dev)
 
        if (devpriv && devpriv->pci_dev) {
                if (dev->iobase) {
-                       pci_release_regions(devpriv->pci_dev);
-                       pci_disable_device(devpriv->pci_dev);
+                       comedi_pci_disable(devpriv->pci_dev);
                }
                pci_dev_put(devpriv->pci_dev);
        }
index c1c36666192a59088e473920cb1cdefdd12eda36..391e2298088b40ab6accee6edbed9cf6245571ae 100644 (file)
@@ -31,9 +31,9 @@ Configuration Options:
 */
 
 #include <linux/comedidev.h>
-#include <linux/pci.h>
 #include <linux/delay.h>
 #include "comedi_fc.h"
+#include "comedi_pci.h"
 #include "8253.h"
 
 #define PCI8164_AXIS_X  0x00
@@ -127,12 +127,8 @@ static int adl_pci8164_attach(comedi_device *dev,comedi_devconfig *it)
                if ( pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
                     pcidev->device == PCI_DEVICE_ID_PCI8164 ) {
                        devpriv->pci_dev = pcidev;
-                       if (pci_enable_device(pcidev) < 0) {
-                               printk("comedi%d: Failed to enable PCI device\n", dev->minor);
-                               return -EIO;
-                       }
-                       if (pci_request_regions(pcidev, "adl_pci8164") < 0) {
-                               printk("comedi%d: I/O port conflict\n", dev->minor);
+                       if (comedi_pci_enable(pcidev, "adl_pci8164") < 0) {
+                               printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor);
                                return -EIO;
                        }
                        dev->iobase = pci_resource_start ( pcidev, 2 );
@@ -196,8 +192,7 @@ static int adl_pci8164_detach(comedi_device *dev)
 
        if (devpriv && devpriv->pci_dev) {
                if (dev->iobase) {
-                       pci_release_regions(devpriv->pci_dev);
-                       pci_disable_device(devpriv->pci_dev);
+                       comedi_pci_disable(devpriv->pci_dev);
                }
                pci_dev_put(devpriv->pci_dev);
        }
index 575b92075c8ee70714d64cb404863ecdd054a3c6..f76b058972293240a2cea36aed015c0677a30f01 100644 (file)
@@ -77,9 +77,9 @@ TODO:
 #include <linux/comedidev.h>
 
 #include <linux/delay.h>
-#include <linux/pci.h>
 
 #include "8253.h"
+#include "comedi_pci.h"
 #include "comedi_fc.h"
 
 #define PCI9111_DRIVER_NAME    "adl_pci9111"
@@ -1350,10 +1350,10 @@ found:
                lcr_io_base,
                lcr_io_range);
 
-       // Enable PCI device
-       if(pci_enable_device (pci_device) < 0)
+       // Enable PCI device and request regions
+       if(comedi_pci_enable (pci_device, PCI9111_DRIVER_NAME) < 0)
        {
-               printk("comedi%d: Failed to enable PCI device\n", dev->minor);
+               printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor);
                return -EIO;
        }
 
@@ -1367,13 +1367,6 @@ found:
                io_base,
                io_range);
 
-       // Allocate IO ressources
-       if(pci_request_regions(pci_device, PCI9111_DRIVER_NAME))
-       {
-               printk("comedi%d: I/O port conflict\n",dev->minor);
-               return -EIO;
-       }
-
        dev->iobase=io_base;
        dev->board_name = board->name;
        dev_private->io_range = io_range;
@@ -1487,8 +1480,7 @@ static int pci9111_detach(comedi_device *dev)
        {
                if(dev->iobase)
                {
-                       pci_release_regions(dev_private->pci_device);
-                       pci_disable_device(dev_private->pci_device);
+                       comedi_pci_disable(dev_private->pci_device);
                }
                pci_dev_put(dev_private->pci_device);
        }
index f2b56880ad9ac05147c760057903e9cbb0a92803..582df2a2d9cd6ffaefb2fc4f6166663e51f5d0a5 100644 (file)
@@ -63,12 +63,12 @@ Configuration options:
 
 */
 #include <linux/comedidev.h>
-#include <linux/pci.h>
 
 #include <linux/delay.h>
 
 #include "amcc_s5933.h"
 #include "8253.h"
+#include "comedi_pci.h"
 #include "comedi_fc.h"
 
 /* paranoid checks are broken */
@@ -1711,12 +1711,8 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it)
                 * Look for device that isn't in use.
                 * Enable PCI device and request regions.
                 */
-               if (pci_enable_device(pcidev)) {
-                       errstr = "failed to enable PCI device!";
-                       continue;
-               }
-               if (pci_request_regions(pcidev, "adl_pci9118")) {
-                       errstr = "in use or I/O port conflict!";
+               if (comedi_pci_enable(pcidev, "adl_pci9118")) {
+                       errstr = "failed to enable PCI device and request regions!";
                        continue;
                }
                break;
@@ -1898,8 +1894,7 @@ static int pci9118_detach(comedi_device *dev)
                if(dev->irq) comedi_free_irq(dev->irq,dev);
                if (devpriv->pcidev) {
                        if (dev->iobase) {
-                               pci_release_regions(devpriv->pcidev);
-                               pci_disable_device(devpriv->pcidev);
+                               comedi_pci_disable(devpriv->pcidev);
                        }
                        pci_dev_put(devpriv->pcidev);
                }
index 5e7e1c13669c120e7682798fe06eb4aca4882d1a..b23404e4bca9f7bb7964d918b7f5ce4075165c64 100644 (file)
@@ -43,7 +43,7 @@ Configuration options:
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 #include "8253.h"
 #include "amcc_s5933.h"
@@ -1256,12 +1256,8 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it)
                 * Look for device that isn't in use.
                 * Enable PCI device and request regions.
                 */
-               if (pci_enable_device(pcidev)) {
-                       errstr = "failed to enable PCI device!";
-                       continue;
-               }
-               if (pci_request_regions(pcidev, "adl_pci9118")) {
-                       errstr = "in use or I/O port conflict!";
+               if (comedi_pci_enable(pcidev, "adv_pci1710")) {
+                       errstr = "failed to enable PCI device and request regions!";
                        continue;
                }
                break;
@@ -1423,8 +1419,7 @@ static int pci1710_detach(comedi_device *dev)
                if (dev->irq) comedi_free_irq(dev->irq,dev);
                if (devpriv->pcidev) {
                        if (dev->iobase) {
-                               pci_release_regions(devpriv->pcidev);
-                               pci_disable_device(devpriv->pcidev);
+                               comedi_pci_disable(devpriv->pcidev);
                        }
                        pci_dev_put(devpriv->pcidev);
                }
index 3951d1dcd2ed590af6bbffd52f8a384301425423..858937a310a9fdb2a80d70e5182505520d5bfe8d 100644 (file)
@@ -30,9 +30,9 @@ Configuration options:
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
 #include <linux/delay.h>
 
+#include "comedi_pci.h"
 #include "8255.h"
 
 #undef PCI_DIO_EXTDEBUG        /* if defined, enable extensive debug logging */
@@ -908,12 +908,8 @@ static int pci_dio_attach(comedi_device *dev, comedi_devconfig *it)
                return -EIO;
        }
 
-       if (pci_enable_device(pcidev)) {
-               rt_printk(", Error: Can't enable PCI device!\n");
-               return -EIO;
-       }
-       if (pci_request_regions(pcidev, driver_pci_dio.driver_name)) {
-               rt_printk(", Error: Can't allocate PCI device!\n");
+       if (comedi_pci_enable(pcidev, driver_pci_dio.driver_name)) {
+               rt_printk(", Error: Can't enable PCI device and request regions!\n");
                return -EIO;
        }
        iobase=pci_resource_start(pcidev, this_board->main_pci_region);
@@ -1027,8 +1023,7 @@ static int pci_dio_detach(comedi_device *dev)
 
                if (devpriv->pcidev) {
                        if (dev->iobase) {
-                               pci_release_regions(devpriv->pcidev);
-                               pci_disable_device(devpriv->pcidev);
+                               comedi_pci_disable(devpriv->pcidev);
                        }
                        pci_dev_put(devpriv->pcidev);
                }
index e3770ff7e867f6a40f7ea70753d12f16af39a443..588a14a98b5e39a68455622a42d8b51b09f092e2 100644 (file)
@@ -210,7 +210,7 @@ order they appear in the channel list.
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 #include "8255.h"
 #include "8253.h"
@@ -1251,20 +1251,14 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it)
 
        /* Enable device and reserve I/O spaces. */
        if (pci_dev) {
-               ret = pci_enable_device(pci_dev);
+               ret = comedi_pci_enable(pci_dev, DIO200_DRIVER_NAME);
                if (ret < 0) {
-                       printk(KERN_ERR "comedi%d: error! cannot enable PCI device!\n",
+                       printk(KERN_ERR "comedi%d: error! cannot enable PCI device and request regions!\n",
                                        dev->minor);
                        return ret;
                }
                iobase = pci_resource_start(pci_dev, 2);
                irq = pci_dev->irq;
-               ret = pci_request_regions(pci_dev, DIO200_DRIVER_NAME);
-               if (ret < 0) {
-                       printk(KERN_ERR "comedi%d: I/O port conflict (PCI)!\n",
-                                       dev->minor);
-                       return ret;
-               }
        } else {
                ret = dio200_request_region(dev->minor, iobase, DIO200_IO_SIZE);
                if (ret < 0) {
@@ -1399,8 +1393,7 @@ dio200_detach(comedi_device *dev)
                if (devpriv->pci_dev) {
                        if(dev->iobase)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                } else if (dev->iobase) {
index 0814cc431351148bce0db7ea1f74c4486ca6e7a1..dc76272653c38d352ff5350dc807290686c08282 100644 (file)
@@ -54,7 +54,7 @@ unused.
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 #include "8255.h"
 #include "plx9052.h"
@@ -266,12 +266,8 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it)
 
        /* Enable device and reserve I/O spaces. */
        if (pci_dev) {
-               if ((ret=pci_enable_device(pci_dev)) < 0) {
-                       printk("error enabling PCI device!\n");
-                       return ret;
-               }
-               if ((ret=pci_request_regions(pci_dev, PC236_DRIVER_NAME)) < 0) {
-                       printk("I/O port conflict (PCI)!\n");
+               if ((ret=comedi_pci_enable(pci_dev, PC236_DRIVER_NAME)) < 0) {
+                       printk("error enabling PCI device and requesting regions!\n");
                        return ret;
                }
                devpriv->lcr_iobase = pci_resource_start(pci_dev, 1);
@@ -359,8 +355,7 @@ static int pc236_detach(comedi_device *dev)
                if (devpriv->pci_dev) {
                        if(dev->iobase)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                } else if (dev->iobase) {
index 48fc83bd77b69a67d73df7569142c9fd024a27bf..ab85aa881af8da0496d729f9c0542e1de899d00a 100644 (file)
@@ -46,7 +46,7 @@ The state of the outputs can be read.
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 #define PC263_DRIVER_NAME      "amplc_pc263"
 
@@ -221,12 +221,8 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it)
 
        /* Enable device and reserve I/O spaces. */
        if (pci_dev) {
-               if ((ret=pci_enable_device(pci_dev)) < 0) {
-                       printk("error enabling PCI device!\n");
-                       return ret;
-               }
-               if ((ret=pci_request_regions(pci_dev, PC263_DRIVER_NAME)) < 0) {
-                       printk("I/O port conflict (PCI)!\n");
+               if ((ret=comedi_pci_enable(pci_dev, PC263_DRIVER_NAME)) < 0) {
+                       printk("error enabling PCI device and requesting regions!\n");
                        return ret;
                }
                iobase = pci_resource_start(pci_dev, 2);
@@ -289,8 +285,7 @@ static int pc263_detach(comedi_device *dev)
                if (devpriv->pci_dev) {
                        if(dev->iobase)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                } else if (dev->iobase) {
index 530b42cd58039d6d2386e77b10bb2dc374c8f757..4b5548d9ea87e0914b9e6a053e2c35562444ce8b 100644 (file)
@@ -104,7 +104,7 @@ Caveats:
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 #include "comedi_fc.h"
 #include "8253.h"
@@ -1343,16 +1343,11 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it)
                return ret;
        devpriv->pci_dev = pci_dev;
 
-       if ((ret=pci_enable_device(pci_dev)) < 0) {
-               printk(KERN_ERR "comedi%d: error! cannot enable PCI device!\n",
+       if ((ret=comedi_pci_enable(pci_dev, DRIVER_NAME)) < 0) {
+               printk(KERN_ERR "comedi%d: error! cannot enable PCI device and request regions!\n",
                                dev->minor);
                return ret;
        }
-       if (pci_request_regions(pci_dev, DRIVER_NAME)) {
-               printk(KERN_ERR "comedi%d: error! cannot allocate PCI regions!\n",
-                               dev->minor);
-               return -EIO;
-       }
        spin_lock_init(&devpriv->ao_spinlock);
 
        devpriv->iobase1 = pci_resource_start(pci_dev, 2);
@@ -1539,8 +1534,7 @@ pci224_detach(comedi_device *dev)
                if (devpriv->pci_dev) {
                        if(dev->iobase)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                }
index adaebd6d3222b9261feef086163146b76ac69630..2ca26dd0c3eac93ed73ee6213a581d473812d201 100644 (file)
@@ -42,8 +42,8 @@ extra triggered scan functionality, interrupt bug-fix added by Steve Sharples
 #include <linux/comedidev.h>
 
 #include <linux/delay.h>
-#include <linux/pci.h>
 
+#include "comedi_pci.h"
 #include "8253.h"
 #include "8255.h"
 
@@ -453,20 +453,16 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it)
  */
        dev->board_name = thisboard->name;
 
-       /* Read base addresses of the PCI230's two I/O regions from PCI configuration register. */
-       if(pci_enable_device(pci_dev)<0){
+       /* Enable PCI device and reserve I/O spaces. */
+       if(comedi_pci_enable(pci_dev, "amplc_pci230")<0){
+               printk("comedi%d: failed to enable PCI device and request regions\n",dev->minor);
                return -EIO;
        }
 
+       /* Read base addresses of the PCI230's two I/O regions from PCI configuration register. */
        pci_iobase = pci_resource_start(pci_dev, 2);
        iobase = pci_resource_start(pci_dev, 3);
 
-       /* Reserve I/O spaces. */
-       if(pci_request_regions(pci_dev,"amplc_pci230")<0){
-               printk("comedi%d: I/O space conflict\n",dev->minor);
-               return -EIO;
-       }
-
        printk("comedi%d: %s I/O region 1 0x%04lx I/O region 2 0x%04lx\n",
                        dev->minor, dev->board_name, pci_iobase, iobase);
 
@@ -606,8 +602,7 @@ static int pci230_detach(comedi_device *dev)
                if(devpriv->pci_dev){
                        if(dev->iobase)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                }
index 9f9e83e9e4ca3a8d773f60fec6dd78827a76423e..cae0fe09c10ceb0c8e1fc1e321ddb05a51c1c665 100644 (file)
@@ -63,11 +63,11 @@ analog triggering on 1602 series
 
 #include <linux/comedidev.h>
 #include <linux/delay.h>
-#include <linux/pci.h>
 
 #include "8253.h"
 #include "8255.h"
 #include "amcc_s5933.h"
+#include "comedi_pci.h"
 #include "comedi_fc.h"
 
 #undef CB_PCIDAS_DEBUG // disable debugging code
@@ -561,14 +561,9 @@ found:
        /*
         * Enable PCI device and reserve I/O ports.
         */
-       if(pci_enable_device(pcidev))
+       if(comedi_pci_enable(pcidev, "cb_pcidas"))
        {
-               printk(" Failed to enable PCI device\n");
-               return -EIO;
-       }
-       if(pci_request_regions(pcidev, "cb_pcidas"))
-       {
-               printk(" I/O port conflict\n");
+               printk(" Failed to enable PCI device and request regions\n");
                return -EIO;
        }
        /*
@@ -745,8 +740,7 @@ static int cb_pcidas_detach(comedi_device *dev)
        {
                if(devpriv->s5933_config)
                {
-                       pci_release_regions(devpriv->pci_dev);
-                       pci_disable_device(devpriv->pci_dev);
+                       comedi_pci_disable(devpriv->pci_dev);
                }
                pci_dev_put(devpriv->pci_dev);
        }
index 1271614cc8b49f6b9663b99d210f2dd37a32dc54..96f07bdd8a9b85021aa9ff6b44ca87d5416337d5 100644 (file)
@@ -85,9 +85,9 @@ TODO:
 
 #include <linux/comedidev.h>
 #include <linux/delay.h>
-#include <linux/pci.h>
 #include <asm/system.h>
 
+#include "comedi_pci.h"
 #include "8253.h"
 #include "8255.h"
 #include "plx9080.h"
@@ -1695,15 +1695,9 @@ static int attach(comedi_device *dev, comedi_devconfig *it)
        printk("Found %s on bus %i, slot %i\n", board(dev)->name,
                pcidev->bus->number, PCI_SLOT(pcidev->devfn));
 
-       if( pci_enable_device( pcidev ) )
+       if( comedi_pci_enable( pcidev, driver_cb_pcidas.driver_name ) )
        {
-               printk(KERN_WARNING " failed to enable PCI device\n");
-               return -EIO;
-       }
-       if( pci_request_regions( pcidev, driver_cb_pcidas.driver_name ) )
-       {
-               /* Couldn't allocate io space */
-               printk(KERN_WARNING " failed to allocate io memory\n");
+               printk(KERN_WARNING " failed to enable PCI device and request regions\n");
                return -EIO;
        }
        pci_set_master( pcidev );
@@ -1820,8 +1814,7 @@ static int detach(comedi_device *dev)
                                        priv(dev)->ao_dma_desc, priv(dev)->ao_dma_desc_bus_addr );
                        if(priv(dev)->main_phys_iobase)
                        {
-                               pci_release_regions(priv(dev)->hw_dev);
-                               pci_disable_device(priv(dev)->hw_dev);
+                               comedi_pci_disable(priv(dev)->hw_dev);
                        }
                        pci_dev_put(priv(dev)->hw_dev);
                }
index b31bc277898a46a997c51c2e27dd01a2416cf5c3..2b16a28ea5fce5913e8179cd87b3a970a76c32ac 100644 (file)
@@ -47,8 +47,8 @@ Please report sucess/failure with other different cards to
 */
 
 #include <linux/comedidev.h>
-#include <linux/pci.h>
 
+#include "comedi_pci.h"
 #include "8255.h"
 
 #define PCI_VENDOR_ID_CB       0x1307  // PCI vendor number of ComputerBoards
@@ -310,23 +310,17 @@ found:
        printk("Found %s at requested position\n",thisboard->name);
 
        /*
-        * Initialize devpriv->control_status and devpriv->adc_fifo to point to
-        * their base address.
+        * Enable PCI device and request regions.
         */
-       if(pci_enable_device(pcidev))
+       if (comedi_pci_enable(pcidev, thisboard->name))
        {
-               printk("cb_pcidda: failed to enable PCI device\n");
+               printk("cb_pcidda: failed to enable PCI device and request regions\n");
                return -EIO;
        }
 
 /*
  * Allocate the I/O ports.
  */
-       if (pci_request_regions(pcidev, thisboard->name))
-       {
-               printk("cb_pcidda: I/O port conflict\n");
-               return -EIO;
-       }
        devpriv->digitalio = pci_resource_start(devpriv->pci_dev, DIGITALIO_BADRINDEX);
        devpriv->dac = pci_resource_start(devpriv->pci_dev, DAC_BADRINDEX);
 
@@ -402,8 +396,7 @@ static int cb_pcidda_detach(comedi_device *dev)
                {
                        if(devpriv->dac)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                }
index f5d881cd3fef4d7a7efcf417195cfd2e33717eef..53ccf7d92ed112b3cdd92776cabe4c4b44426de0 100644 (file)
@@ -41,7 +41,7 @@ Passing a zero for an option is the same as leaving it unspecified.
 
 /*------------------------------ HEADER FILES ---------------------------------*/
 #include <linux/comedidev.h>
-#include <linux/pci.h> /* for PCI devices */
+#include "comedi_pci.h"
 #include "8255.h"
 
 
@@ -245,12 +245,8 @@ found:
        devpriv->pci_dev = pcidev;
        printk("Found %s on bus %i, slot %i\n", thisboard->name,
                devpriv->pci_dev->bus->number, PCI_SLOT(devpriv->pci_dev->devfn));
-       if(pci_enable_device(pcidev)) {
-               printk("cb_pcidio: failed to enable PCI device\n");
-               return -EIO;
-       }
-       if(pci_request_regions(pcidev, thisboard->name)) {
-               printk("cb_pcidio: I/O port conflict\n");
+       if(comedi_pci_enable(pcidev, thisboard->name)) {
+               printk("cb_pcidio: failed to enable PCI device and request regions\n");
                return -EIO;
        }
        devpriv->dio_reg_base
@@ -288,8 +284,7 @@ static int pcidio_detach(comedi_device *dev)
        if(devpriv) {
                if(devpriv->pci_dev) {
                        if(devpriv->dio_reg_base) {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                }
index ee7ac4e269d2fd1ebf9b2a405704a41cf7d01754..39bba14f82761583e789f19f038f8b68ca84d7cf 100644 (file)
@@ -42,9 +42,9 @@ See http://www.measurementcomputing.com/PDFManuals/pcim-das1602_16.pdf for more
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
 #include <linux/delay.h>
 
+#include "comedi_pci.h"
 #include "plx9052.h"
 #include "8255.h"
 
@@ -260,14 +260,9 @@ found:
                                "PLEASE REPORT USAGE TO <mocelet@sucs.org>\n");
        };
 
-       if(pci_enable_device(pcidev))
+       if(comedi_pci_enable(pcidev, "cb_pcimdas"))
        {
-               printk(" Failed to enable PCI device\n");
-               return -EIO;
-       }
-       if(pci_request_regions(pcidev, "cb_pcimdas"))
-       {
-               printk(" I/O port conflict\n");
+               printk(" Failed to enable PCI device and request regions\n");
                return -EIO;
        }
 
@@ -371,8 +366,7 @@ static int cb_pcimdas_detach(comedi_device *dev)
                {
                        if(devpriv->BADR0)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                }
index 044a42214b35dea809ffa5d7bc63974e27de3b16..635a8bd29f8c8cbeefa65b3da4f01ff979b7eb32 100644 (file)
@@ -87,7 +87,7 @@ Configuration Options:
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 #include "8255.h"
 
@@ -344,8 +344,7 @@ static int detach(comedi_device *dev)
                if (devpriv->pci_dev) {
                        if(devpriv->registers)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                }
@@ -467,14 +466,9 @@ static int probe(comedi_device *dev, const comedi_devconfig *it)
 
                        devpriv->pci_dev = pcidev;
                        dev->board_ptr = boards + index;
-                       if (pci_enable_device(pcidev))
+                       if (comedi_pci_enable(pcidev, thisboard->name))
                        {
-                               printk("cb_pcimdda: Failed to enable PCI device\n");
-                               return -EIO;
-                       }
-                       if (pci_request_regions(pcidev, thisboard->name))
-                       {
-                               printk("cb_pcimdda: I/O port conflict\n");
+                               printk("cb_pcimdda: Failed to enable PCI device and request regions\n");
                                return -EIO;
                        }
                        registers = pci_resource_start(devpriv->pci_dev, REGS_BADRINDEX);
diff --git a/comedi/drivers/comedi_pci.h b/comedi/drivers/comedi_pci.h
new file mode 100644 (file)
index 0000000..1407878
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+    comedi/drivers/comedi_pci.h
+    Various PCI functions for drivers.
+
+    Copyright (C) 2007 MEV Ltd. <http://www.mev.co.uk/>
+
+    COMEDI - Linux Control and Measurement Device Interface
+    Copyright (C) 2000 David A. Schleef <ds@schleef.org>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef _COMEDI_PCI_H_
+#define _COMEDI_PCI_H_
+
+#include <linux/version.h>
+#include <linux/pci.h>
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
+#define PCI_ENABLE_IS_REFCOUNTED
+#endif
+
+/*
+ * Enables PCI device without requesting regions.  Just a simple wrapper
+ * for pci_enable_device().
+ */
+static inline int comedi_pci_enable_no_regions(struct pci_dev *pdev)
+{
+       return pci_enable_device(pdev);
+}
+
+/*
+ * Called to disable PCI device if PCI device has been enabled, but
+ * PCI regions have not been reserved.
+ *
+ * It only disables the PCI device if the kernel supports reference
+ * counting of PCI enables, otherwise it might stop the device working
+ * in another driver instance.
+ */
+static inline void comedi_pci_disable_no_regions(struct pci_dev *pdev)
+{
+#ifdef PCI_ENABLE_IS_REFCOUNTED
+       pci_disable_device(pdev);
+#endif
+}
+
+/*
+ * Enable the PCI device and request the regions.
+ */
+static inline int comedi_pci_enable(struct pci_dev *pdev, const char *res_name)
+{
+       int rc;
+
+       rc = pci_enable_device(pdev);
+       if (rc < 0) {
+               return rc;
+       }
+       rc = pci_request_regions(pdev, res_name);
+       if (rc < 0) {
+               comedi_pci_disable_no_regions(pdev);
+       }
+       return rc;
+}
+
+/*
+ * Release the regions and disable the PCI device.
+ *
+ * This must be matched with a previous successful call to comedi_pci_enable().
+ */
+static inline void comedi_pci_disable(struct pci_dev *pdev)
+{
+       pci_release_regions(pdev);
+       pci_disable_device(pdev);
+}
+
+#endif
index 5b182f4e4b95755db4c402fcab9957b1b9afeca5..138cf85e78c6010f02f3fd0ffbd6f843cb7726b5 100644 (file)
@@ -36,7 +36,7 @@ Configuration Options:
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 typedef enum contec_model {
        PIO1616L        =0,
@@ -124,12 +124,8 @@ static int contec_attach(comedi_device *dev,comedi_devconfig *it)
                                }
                        }
                        devpriv->pci_dev = pcidev;
-                       if (pci_enable_device(pcidev)) {
-                               printk("error enabling PCI device!\n");
-                               return -EIO;
-                       }
-                       if (pci_request_regions(pcidev, "contec_pci_dio")) {
-                               printk("I/O port conflict!\n");
+                       if (comedi_pci_enable(pcidev, "contec_pci_dio")) {
+                               printk("error enabling PCI device and request regions!\n");
                                return -EIO;
                        }
                        dev->iobase = pci_resource_start ( pcidev, 0 );
@@ -173,8 +169,7 @@ static int contec_detach(comedi_device *dev)
        if (devpriv && devpriv->pci_dev) {
                if(dev->iobase)
                {
-                       pci_release_regions(devpriv->pci_dev);
-                       pci_disable_device(devpriv->pci_dev);
+                       comedi_pci_disable(devpriv->pci_dev);
                }
                pci_dev_put(devpriv->pci_dev);
        }
index 7ef41a3535b342b59573bf259772224845874aad..550b597a4f0df19167d211dd5110229afcc14056 100644 (file)
@@ -115,8 +115,8 @@ Configuration options:
 #include <linux/comedidev.h>
 
 #include <linux/delay.h>
-#include <linux/pci.h>
 
+#include "comedi_pci.h"
 #include "8255.h"
 
 #define DAQBOARD2000_SUBSYSTEM_IDS2    0x00021616 /* Daqboard/2000 - 2 Dacs */
@@ -719,10 +719,8 @@ static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it)
        }
 
 
-       if((result = pci_enable_device(card))<0){
-               return -EIO;
-       }
-       if((result = pci_request_regions(card, "daqboard2000")) < 0) {
+       if((result = comedi_pci_enable(card, "daqboard2000")) < 0) {
+               printk(" failed to enable PCI device and request regions\n");
                return -EIO;    
        }
        devpriv->got_regions = 1;
@@ -814,8 +812,7 @@ static int daqboard2000_detach(comedi_device * dev)
                {
                        if(devpriv->got_regions)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                }
index f8495212fee17c609062dd323a383477ef29e086..9623127ce209b3b186b7d057e2b7a1ee7b6471cf 100644 (file)
@@ -56,8 +56,8 @@ driver.
 #include <linux/comedidev.h>
 
 #include <linux/delay.h>
-#include <linux/pci.h>
 
+#include "comedi_pci.h"
 #include "8255.h"
 #include "das08.h"
 
@@ -956,14 +956,9 @@ static int das08_attach(comedi_device *dev,comedi_devconfig *it)
                        return -EIO;
                }
                devpriv->pdev = pdev;
-               // enable PCI device
-               if(pci_enable_device(pdev)){
-                       printk(" Error enabling PCI device\n");
-                       return -EIO;
-               }
-               // reserve I/O spaces
-               if(pci_request_regions(pdev, "das08")){
-                       printk(" I/O port conflict\n");
+               // enable PCI device and reserve I/O spaces
+               if(comedi_pci_enable(pdev, "das08")){
+                       printk(" Error enabling PCI device and requesting regions\n");
                        return -EIO;
                }
                // read base addresses
@@ -1008,8 +1003,7 @@ int das08_common_detach(comedi_device *dev)
                if(devpriv->pdev){
                        if(devpriv->pci_iobase)
                        {
-                               pci_release_regions(devpriv->pdev);
-                               pci_disable_device(devpriv->pdev);
+                               comedi_pci_disable(devpriv->pdev);
                        }
                        pci_dev_put(devpriv->pdev);
                }
index aab9e58e7393b28452a3edeb4a865a5e95fdd261..78f14d714c6d21b689645f22a609e8910940d658 100644 (file)
@@ -53,10 +53,9 @@ AO commands are not supported.
 #define DEBUG 1
 
 #include <linux/comedidev.h>
-
 #include <linux/delay.h>
-#include <linux/pci.h>
 
+#include "comedi_pci.h"
 
 #define PCI_VENDOR_ID_DT       0x1116
 
@@ -869,8 +868,7 @@ static int dt3000_detach(comedi_device *dev)
                {
                        if(devpriv->phys_addr)
                        {
-                               pci_release_regions(devpriv->pci_dev);
-                               pci_disable_device(devpriv->pci_dev);
+                               comedi_pci_disable(devpriv->pci_dev);
                        }
                        pci_dev_put(devpriv->pci_dev);
                }
@@ -908,10 +906,7 @@ static int setup_pci(comedi_device *dev)
        resource_size_t addr;
        int ret;
 
-       ret = pci_enable_device(devpriv->pci_dev);
-       if(ret<0)return ret;
-
-       ret = pci_request_regions(devpriv->pci_dev, "dt3000");
+       ret = comedi_pci_enable(devpriv->pci_dev, "dt3000");
        if(ret<0)return ret;
 
        addr=pci_resource_start(devpriv->pci_dev,0);
index d26a8339b7024b6b26bfeb9a264772f5513fe216..4af15bb777696043da568232096489a7acd28d72 100644 (file)
@@ -47,8 +47,8 @@ support could be added to this driver.
 
 #include <linux/comedidev.h>
 #include <linux/delay.h>
-#include <linux/pci.h>
 
+#include "comedi_pci.h"
 #include "plx9080.h"
 #include "comedi_fc.h"
 
@@ -577,15 +577,9 @@ static int hpdi_attach(comedi_device *dev, comedi_devconfig *it)
        printk("gsc_hpdi: found %s on bus %i, slot %i\n", board( dev )->name,
                pcidev->bus->number, PCI_SLOT(pcidev->devfn));
 
-       if( pci_enable_device( pcidev ) )
+       if( comedi_pci_enable( pcidev, driver_hpdi.driver_name ) )
        {
-               printk(KERN_WARNING " failed enable PCI device\n");
-               return -EIO;
-       }
-       if( pci_request_regions( pcidev, driver_hpdi.driver_name ) )
-       {
-               /* Couldn't allocate io space */
-               printk(KERN_WARNING " failed to allocate io memory\n");
+               printk(KERN_WARNING " failed enable PCI device and request regions\n");
                return -EIO;
        }
        pci_set_master( pcidev );
@@ -684,8 +678,7 @@ static int hpdi_detach(comedi_device *dev)
                                NUM_DMA_DESCRIPTORS, priv(dev)->dma_desc, priv(dev)->dma_desc_phys_addr );
                        if(priv(dev)->hpdi_phys_iobase)
                        {
-                               pci_release_regions( priv(dev)->hw_dev );
-                               pci_disable_device( priv(dev)->hw_dev );
+                               comedi_pci_disable( priv(dev)->hw_dev );
                        }
                        pci_dev_put(priv(dev)->hw_dev);
                }
index 5ab59b04c3f4063033f9220a5cf3d3bae807278f..769b0d2a2f80d06844372e07b55dee855b02a024 100644 (file)
@@ -11,7 +11,7 @@
 #define _ICP_MULTI_H_
 
 #include <linux/comedidev.h>
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 
 
@@ -162,19 +162,14 @@ static int pci_card_alloc(struct pcilst_struct *inova)
        }
 
        if (inova->used) return 1;
-       if(pci_enable_device(inova->pcidev)) {
-               rt_printk(" - Can't enable PCI device!\n");
+       if (comedi_pci_enable(inova->pcidev, "icp_multi")) {
+               rt_printk(" - Can't enable PCI device and request regions!\n");
                return -1;
        }
        /* Resources will be accurate now. */
        for (i=0;i<5;i++)
                inova->io_addr[i]=pci_resource_start(inova->pcidev, i);
        inova->irq=inova->pcidev->irq;
-       /* Request regions on behalf of client. */
-       if (pci_request_regions(inova->pcidev, "icp_multi")) {
-               rt_printk(" - I/O port conflict!\n");
-               return -1;
-       }
        inova->used=1;
        return 0;
 }
@@ -187,8 +182,7 @@ static int pci_card_free(struct pcilst_struct *inova)
 
        if (!inova->used) return 1;
        inova->used=0;
-       pci_release_regions(inova->pcidev);
-       pci_disable_device(inova->pcidev);
+       comedi_pci_disable(inova->pcidev);
        return 0;
 }
 
index d392917df3cb3ce0f0913cdce936fd12a33b0bd2..497b74dd323e8627234aae2af5a07acc717252a4 100644 (file)
@@ -43,10 +43,10 @@ Devices: [JR3] PCI force sensor board (jr3_pci)
 #include <linux/comedidev.h>
 
 #include <linux/delay.h>
-#include <linux/pci.h>
 #include <linux/ctype.h>
 #include <linux/firmware.h>
 #include <linux/firmware.h>
+#include "comedi_pci.h"
 #include "jr3_pci.h"
 
 /* Hotplug firmware loading stuff */
@@ -131,6 +131,7 @@ MODULE_DEVICE_TABLE(pci, jr3_pci_pci_table);
 
 typedef struct {
   struct pci_dev *pci_dev;
+  int pci_enabled;
   volatile jr3_t *iobase;
   int n_channels;
   struct timer_list timer;
@@ -756,12 +757,10 @@ static int jr3_pci_attach(comedi_device *dev, comedi_devconfig *it)
     devpriv->pci_dev = card;
     dev->board_name = "jr3_pci";
   }
-  if((result = pci_enable_device(card))<0){
-    return -EIO;
-  }
-  if((result = pci_request_regions(card, "jr3_pci")) < 0) {
+  if((result = comedi_pci_enable(card, "jr3_pci")) < 0) {
     return -EIO;       
   }
+  devpriv->pci_enabled = 1;
   devpriv->iobase = ioremap(pci_resource_start(card,0), sizeof(jr3_t));
   result = alloc_subdevices(dev, devpriv->n_channels);
   if(result < 0) goto out;
@@ -867,9 +866,9 @@ static int jr3_pci_detach(comedi_device * dev)
 
     if(devpriv->iobase) {
       iounmap((void*)devpriv->iobase);
-
-      pci_release_regions(devpriv->pci_dev);
-      pci_disable_device(devpriv->pci_dev);
+    }
+    if(devpriv->pci_enabled) {
+      comedi_pci_disable(devpriv->pci_dev);
     }
 
     if (devpriv->pci_dev) {
index 6a0ee63d0c191fdb78247d50bd1a562852f395e1..3f2d2942eac99ca395ecc5d3c0b40f24114f3464 100644 (file)
@@ -34,7 +34,7 @@ Kolter Electronic PCI Counter Card.
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 #define CNT_DRIVER_NAME         "ke_counter"
 #define PCI_VENDOR_ID_KOLTER    0x1001
@@ -192,15 +192,11 @@ found:
   devpriv->pcidev = pci_device;
   dev->board_name = board->name;
 
-  /* enable PCI device */
-  if((error = pci_enable_device(pci_device)) < 0)
-  {
-    return error;
-  }
-
-  /* request PCI regions */
-  if((error = pci_request_regions(pci_device, CNT_DRIVER_NAME)) < 0)
+  /* enable PCI device and request regions */
+  if((error = comedi_pci_enable(pci_device, CNT_DRIVER_NAME)) < 0)
   {
+    printk("comedi%d: failed to enable PCI device and request regions!\n",
+      dev->minor);
     return error;
   }
 
@@ -244,8 +240,7 @@ static int cnt_detach(comedi_device *dev)
        {
                if(dev->iobase)
                {
-                       pci_release_regions(devpriv->pcidev);
-                       pci_disable_device(devpriv->pcidev);
+                       comedi_pci_disable(devpriv->pcidev);
                }
                pci_dev_put(devpriv->pcidev);
        }
index aa586436b8d3c820597ff44ef44a446d8cc10b9a..7553b2d8fc3e3ef8a1b9bacb90cafcb79b31c1fe 100644 (file)
@@ -53,11 +53,11 @@ broken.
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
 #include <linux/delay.h>
 #include <linux/list.h>
 #include <linux/spinlock.h>
 
+#include "comedi_pci.h"
 #include "me4000.h"
 #if 0
 /* file removed due to GPL incompatibility */
@@ -442,19 +442,13 @@ found:
     /* Set data in device structure */
     dev->board_name = board->name;
 
-    /* Enable PCI device */
-    result = pci_enable_device(pci_device);
+    /* Enable PCI device and request regions */
+    result = comedi_pci_enable(pci_device, dev->board_name);
     if(result){
-               printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot enable PCI device\n", dev->minor);
+               printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot enable PCI device and request I/O regions\n", dev->minor);
                return result;
     }
 
-    /* Request the PCI register regions */
-    result = pci_request_regions(pci_device, dev->board_name);
-    if (result < 0){
-               printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot request I/O regions\n", dev->minor);
-               return result;
-    }
     /* Get the PCI base registers */
     result = get_registers(dev, pci_device);
     if(result){
@@ -853,8 +847,7 @@ static int me4000_detach(comedi_device *dev){
                        reset_board(dev);
                        if(info->plx_regbase)
                        {
-                               pci_release_regions(info->pci_dev_p);
-                               pci_disable_device(info->pci_dev_p);
+                               comedi_pci_disable(info->pci_dev_p);
                        }
                        pci_dev_put(info->pci_dev_p);
                }
index b5963bd608ee1f297375fd7763b471bbeed71990..82fdd9c8088efc2c73928e42a92511635ff3785d 100644 (file)
@@ -52,7 +52,7 @@ from http://www.comedi.org
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
+#include "comedi_pci.h"
 
 //#include "me2600_fw.h"
 
@@ -736,17 +736,10 @@ found:
          dev->minor, me_boards[i].name,
          pci_device->bus->number, PCI_SLOT(pci_device->devfn));
 
-  // Enable PCI device
-  if(pci_enable_device(pci_device) < 0)
+  // Enable PCI device and request PCI regions
+  if(comedi_pci_enable(pci_device, ME_DRIVER_NAME) < 0)
   {
-    printk("comedi%d: Failed to enable PCI device\n", dev->minor);
-    return -EIO;
-  }
-
-  // Request PCI regions
-  if(pci_request_regions(pci_device, ME_DRIVER_NAME) < 0)
-  {
-    printk("comedi%d: I/O memory conflict\n", dev->minor);
+    printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor);
     return -EIO;
   }
 
@@ -899,8 +892,7 @@ static int me_detach(comedi_device *dev)
                {
                        if(dev_private->plx_regbase_size)
                        {
-                               pci_release_regions(dev_private->pci_device);
-                               pci_disable_device(dev_private->pci_device);
+                               comedi_pci_disable(dev_private->pci_device);
                        }
                        pci_dev_put(dev_private->pci_device);
                }
index acdd0d35f7231abe4777a1a316d459b17862c8e5..0cee3743efa214ff5dd2f38572db4de6a09290e0 100644 (file)
@@ -53,9 +53,9 @@
 #include "mite.h"
 
 #include "comedi_fc.h"
+#include "comedi_pci.h"
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>
 #include <asm/system.h>
 
 
@@ -118,15 +118,11 @@ int mite_setup2(struct mite_struct *mite, unsigned use_iodwbsr_1)
        u32 csigr_bits;
        unsigned unknown_dma_burst_bits;
 
-       if(pci_enable_device(mite->pcidev)){
-               printk("error enabling mite\n");
+       if(comedi_pci_enable( mite->pcidev, "mite" ) ) {
+               printk("error enabling mite and requesting io regions\n");
                return -EIO;
        }
        pci_set_master(mite->pcidev);
-       if( pci_request_regions( mite->pcidev, "mite" ) ) {
-               printk("failed to request mite io regions\n");
-               return -EIO;
-       };
 
        addr = pci_resource_start(mite->pcidev, 0);
        mite->mite_phys_addr = addr;
@@ -220,8 +216,7 @@ void mite_unsetup(struct mite_struct *mite)
                mite->daq_io_addr=NULL;
        }
        if( mite->mite_phys_addr ){
-               pci_release_regions( mite->pcidev );
-               pci_disable_device( mite->pcidev );
+               comedi_pci_disable( mite->pcidev );
                mite->mite_phys_addr = 0;
        }
 
index 7fd11aeae83d5042c42e7feddcb5d328a9ed2626..1684fe6efd787aad52ec5a0c1c0a14ea9fff4f87 100644 (file)
@@ -102,9 +102,9 @@ Configuration options:
 */
 
 #include <linux/comedidev.h>
-
 #include <linux/delay.h>
-#include <linux/pci.h>
+
+#include "comedi_pci.h"
 
 
 
@@ -804,10 +804,8 @@ static int rtd_attach (
        }
     dev->board_name = thisboard->name;
 
-       if((ret=pci_enable_device(pcidev))<0){
-               return ret;
-       }
-       if((ret=pci_request_regions(pcidev, "rtd520"))<0){
+       if((ret=comedi_pci_enable(pcidev, "rtd520"))<0){
+               printk("Failed to enable PCI device and request regions.\n");
                return ret;
        }
        devpriv->got_regions = 1;
@@ -1156,8 +1154,7 @@ static int rtd_detach (
        if (devpriv->pci_dev) {
                if(devpriv->got_regions)
                {
-                       pci_release_regions(devpriv->pci_dev);
-                       pci_disable_device(devpriv->pci_dev);
+                       comedi_pci_disable(devpriv->pci_dev);
                }
                pci_dev_put(devpriv->pci_dev);
        }
index 31a37348d434acc4833a88a2d7fd72f503fd69bb..e8d2dc8941ff68c7f7afde8833a12f8c722dec45 100644 (file)
@@ -67,7 +67,7 @@ Status: experimental
 
 #include <linux/comedidev.h>
 
-#include <linux/pci.h> /* for PCI devices */
+#include "comedi_pci.h"
 
 #include "comedi_fc.h"
 #include "s626.h"
@@ -495,13 +495,8 @@ static int s626_attach(comedi_device *dev,comedi_devconfig *it)
     return -ENODEV;
   }
 
-  if((result = pci_enable_device(pdev))<0){
-    printk("s626_attach: pci_enable_device fails\n");
-    return -ENODEV;
-  }
-
-  if((result = pci_request_regions(pdev, "s626"))<0){
-    printk("s626_attach: pci_request_regions fails\n");
+  if((result = comedi_pci_enable(pdev, "s626"))<0){
+    printk("s626_attach: comedi_pci_enable fails\n");
     return -ENODEV;
   }
   devpriv->got_regions = 1;
@@ -1231,8 +1226,7 @@ static int s626_detach(comedi_device *dev)
                if(devpriv->pdev){
                        if(devpriv->got_regions)
                        {
-                               pci_release_regions(devpriv->pdev);
-                               pci_disable_device(devpriv->pdev);
+                               comedi_pci_disable(devpriv->pdev);
                        }
                        pci_dev_put(devpriv->pdev);
                }