patch from Ian Abbott <abbotti@mev.co.uk>:
authorFrank Mori Hess <fmhess@speakeasy.net>
Mon, 19 Jun 2006 01:12:37 +0000 (01:12 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Mon, 19 Jun 2006 01:12:37 +0000 (01:12 +0000)
I have a patch that changes the adl_pci9118 and adv_pci1710 drivers.  It
mimics their old behaviour of searching for an unused card, rather than
using the first card it finds.  I didn't need to change the cb_pcidas
driver after all as it wasn't using the amcc_s5933 driver, only some
macros from amcc_s5933.h.

The patch also removes the amcc_s5933 module from the Makefile.am and
Kbuild files and removes the function declarations, etc., from the
amcc_s5933.h file.

comedi/drivers/Kbuild
comedi/drivers/Makefile.am
comedi/drivers/adl_pci9118.c
comedi/drivers/adv_pci1710.c
comedi/drivers/amcc_s5933.h

index e3f25dcfa5b13c8ed2e01fefaa307d78ff2f4f3b..2dcb48c1160a51df77ff57c5386eb84d64d99711 100644 (file)
@@ -18,7 +18,6 @@ obj-$(CONFIG_COMEDI_USB_MODULES) += usbduxfast.o
 obj-$(CONFIG_COMEDI_USB_MODULES) += dt9812.o
 
 obj-m += 8255.o
-obj-m += amcc_s5933.o
 obj-m += comedi_fc.o
 obj-m += das08.o
 obj-m += mite.o
index 82909dbdcb0f90ae049a5fa9ff25a65da227d91c..51c1d5a47c9e0a6b7a11a0f47276dcd21cd17489 100644 (file)
@@ -5,7 +5,6 @@ AM_CFLAGS = $(COMEDI_CFLAGS) $(LINUX_CFLAGS) $(RTAI_CFLAGS) $(RTLINUX_CFLAGS)
 LINK = $(top_builddir)/modtool --link -o $@ \
        -i ../.mods/comedi.o.symvers \
        -i .mods/8255.o.symvers \
-       -i .mods/amcc_s5933.o.symvers \
        -i .mods/comedi_fc.o.symvers \
        -i .mods/das08.o.symvers \
        -i .mods/mite.o.symvers \
@@ -13,8 +12,6 @@ LINK = $(top_builddir)/modtool --link -o $@ \
 
 8255_ko_LINK = $(top_builddir)/modtool --link -o $@ \
        -i ../.mods/comedi.o.symvers
-amcc_s5933_ko_LINK = $(top_builddir)/modtool --link -o $@ \
-       -i ../.mods/comedi.o.symvers
 comedi_fc_ko_LINK = $(top_builddir)/modtool --link -o $@ \
        -i ../.mods/comedi.o.symvers
 das08_ko_LINK = $(top_builddir)/modtool --link -o $@ \
@@ -25,7 +22,6 @@ ni_labpc_ko_LINK = $(top_builddir)/modtool --link -o $@ \
        -i ../.mods/comedi.o.symvers
 
 8255_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB
-amcc_s5933_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB
 comedi_fc_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB
 das08_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB
 mite_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB
@@ -86,7 +82,6 @@ module_PROGRAMS =
 else !CONFIG_KBUILD
 module_PROGRAMS = \
  8255.ko \
- amcc_s5933.ko \
  comedi_fc.ko \
  das08.ko \
  mite.ko \
@@ -179,7 +174,6 @@ adl_pci8164_ko_SOURCES = adl_pci8164.c
 adl_pci9111_ko_SOURCES = adl_pci9111.c
 adl_pci9118_ko_SOURCES = adl_pci9118.c
 adv_pci1710_ko_SOURCES = adv_pci1710.c
-amcc_s5933_ko_SOURCES = amcc_s5933.c
 adv_pci_dio_ko_SOURCES = adv_pci_dio.c
 amplc_pci224_ko_SOURCES = amplc_pci224.c
 amplc_pci230_ko_SOURCES = amplc_pci230.c
index c80e0010c708691f2e48fc46eb5ff43895085a54..e52e45863b89bfa12a0bdea543420123ba085b7a 100644 (file)
@@ -63,6 +63,7 @@ Configuration options:
 
 */
 #include <linux/comedidev.h>
+#include <linux/pci.h>
 
 #include <linux/delay.h>
 
@@ -180,8 +181,6 @@ static comedi_lrange range_pci9118hg={ 8, {
 static int pci9118_attach(comedi_device *dev,comedi_devconfig *it);
 static int pci9118_detach(comedi_device *dev);
 
-static unsigned short pci_list_builded=0;      /*>0 list of cards is known */
-
 typedef struct {
        char            *name;          // driver name
        int             vendor_id;      // PCI vendor a device ID of card
@@ -243,7 +242,6 @@ COMEDI_INITCLEANUP(driver_pci9118);
 
 typedef struct{
        int                     iobase_a;       // base+size for AMCC chip
-       struct pcilst_struct    *amcc;          // ptr too AMCC data
        unsigned int            master;         // master capable
        struct pci_dev          *pcidev;                // ptr to actual pcidev
        unsigned int            usemux;         // we want to use external multiplexor!
@@ -1670,53 +1668,84 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it)
 {
        comedi_subdevice *s;
        int ret,pages,i;
-       unsigned short io_addr[5],master,irq,m;
+       unsigned short master,irq;
         unsigned int iobase_a,iobase_9;
-       struct pcilst_struct *card=NULL;
+       struct pci_dev *pcidev;
+       int opt_bus, opt_slot;
+       const char *errstr;
        unsigned char pci_bus,pci_slot,pci_func;
        u16 u16w;
        
-       if (pci_list_builded++ == 0) {
-               pci_card_list_init(PCI_VENDOR_ID_AMCC,0);
-       }
-
        rt_printk("comedi%d: adl_pci9118: board=%s",dev->minor,this_board->name);
 
+       opt_bus = it->options[0];
+       opt_slot = it->options[1];
        if (it->options[3]&1) {
                master=0; // user don't want use bus master
        } else {
                master=1;
        }
 
-       /* this call pci_enable_device(), pci_request_regions(),
-        * and pci_set_master() */
-       if ((card=select_and_alloc_pci_card(PCI_VENDOR_ID_AMCC, this_board->device_id, it->options[0], it->options[1], master))==NULL) 
-               return -EIO;
-       
-       if ((pci_card_data(card,&pci_bus,&pci_slot,&pci_func,
-                           &io_addr[0],&irq,&m))<0) {
-               pci_card_free(card);
-               rt_printk(" - Can't get AMCC data!\n");
+       if((ret=alloc_private(dev,sizeof(pci9118_private)))<0) {
+               rt_printk(" - Allocation failed!\n");
+               return -ENOMEM;
+       }
+
+       /* Look for matching PCI device */
+       errstr = "not found!";
+       pcidev = NULL;
+       while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_AMCC,
+                                       this_board->device_id, pcidev))) {
+               /* Found matching vendor/device. */
+               if (opt_bus || opt_slot) {
+                       /* Check bus/slot. */
+                       if (opt_bus != pcidev->bus->number
+                                       || opt_slot != PCI_SLOT(pcidev->devfn))
+                               continue;       /* no match */
+               }
+               /*
+                * 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!";
+                       continue;
+               }
+               break;
+       }
+
+       if (!pcidev) {
+               if (opt_bus || opt_slot) {
+                       rt_printk(" - Card at b:s %d:%d %s\n",
+                                       opt_bus, opt_slot, errstr);
+               } else {
+                       rt_printk(" - Card %s\n", errstr);
+               }
                return -EIO;
        }
 
-       iobase_a=io_addr[0];
-       iobase_9=io_addr[2];
+       if (master) {
+               pci_set_master(pcidev);
+       }
+
+       pci_bus = pcidev->bus->number;
+       pci_slot = PCI_SLOT(pcidev->devfn);
+       pci_func = PCI_FUNC(pcidev->devfn);
+       irq = pcidev->irq;
+       iobase_a = pci_resource_start(pcidev, 0);
+       iobase_9 = pci_resource_start(pcidev, 2);
 
        rt_printk(", b:s:f=%d:%d:%d, io=0x%4x, 0x%4x",pci_bus,pci_slot,pci_func,iobase_9,iobase_a);
        
         dev->iobase=iobase_9;
        dev->board_name = this_board->name;
 
-       
-       if((ret=alloc_private(dev,sizeof(pci9118_private)))<0) {
-               pci_card_free(card);
-               rt_printk(" - Allocation failed!\n");
-               return -ENOMEM;
-       }
 
-       devpriv->amcc=card;
-       devpriv->pcidev=card->pcidev;
+       devpriv->pcidev=pcidev;
        devpriv->iobase_a=iobase_a;
        
        if (it->options[3]&2) irq=0; // user don't want use IRQ
@@ -1862,15 +1891,17 @@ static int pci9118_detach(comedi_device *dev)
        if (dev->private) {
                if (devpriv->valid) pci9118_reset(dev);
                if(dev->irq) comedi_free_irq(dev->irq,dev);
-               if (devpriv->amcc) pci_card_free(devpriv->amcc);
+               if (devpriv->pcidev) {
+                       if (dev->iobase) {
+                               pci_release_regions(devpriv->pcidev);
+                               pci_disable_device(devpriv->pcidev);
+                       }
+                       pci_dev_put(devpriv->pcidev);
+               }
                if (devpriv->dmabuf_virt[0]) free_pages((unsigned long)devpriv->dmabuf_virt[0],devpriv->dmabuf_pages[0]);
                if (devpriv->dmabuf_virt[1]) free_pages((unsigned long)devpriv->dmabuf_virt[1],devpriv->dmabuf_pages[1]);
        }
 
-       if (--pci_list_builded == 0) {
-               pci_card_list_cleanup(PCI_VENDOR_ID_AMCC);
-       }
-
        return 0;
 }
 
index ca3d77e1024569678a707a5645d50e52d521115a..2ee39c2764a95adcc488ad88df8942b623def861 100644 (file)
@@ -182,8 +182,6 @@ static comedi_lrange range_pci171x_da={ 2, {
 static int pci1710_attach(comedi_device *dev,comedi_devconfig *it);
 static int pci1710_detach(comedi_device *dev);
 
-static unsigned short  pci_list_builded=0;     /*>0 list of card is known */
-
 typedef struct {
        char            *name;          // driver name
        int             device_id;
@@ -262,7 +260,7 @@ static comedi_driver driver_pci1710={
 };
 
 typedef struct{
-       struct pcilst_struct    *amcc;          // ptr to AMCC data
+       struct pci_dev          *pcidev;        // ptr to PCI device
        char                    valid;          // card is usable
        char                    neverending_ai; // we do unlimited AI
        unsigned int            CntrlReg;       // Control register
@@ -1223,49 +1221,72 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it)
 {
        comedi_subdevice *s;
        int ret,subdev,n_subdevices;
-       unsigned short io_addr[5],master,irq;
-       struct pcilst_struct *card=NULL;
+       unsigned short irq;
         unsigned int iobase;
+       struct pci_dev *pcidev;
+       int opt_bus, opt_slot;
+       const char *errstr;
        unsigned char pci_bus,pci_slot,pci_func;
 
-       if (pci_list_builded++ == 0) {
-               pci_card_list_init(PCI_VENDOR_ID_ADVANTECH,
-#ifdef PCI171X_EXTDEBUG
-                                                   1
-#else
-                                                   0
-#endif
-               );
-       }
-
        rt_printk("comedi%d: adv_pci1710: board=%s",dev->minor,this_board->name);
 
-       /* this call pci_enable_device() and pci_request_regions() */
-       if ((card=select_and_alloc_pci_card(PCI_VENDOR_ID_ADVANTECH, this_board->device_id, it->options[0], it->options[1], 0))==NULL)
-               return -EIO;
+       opt_bus = it->options[0];
+       opt_slot = it->options[1];
+
+       if((ret=alloc_private(dev,sizeof(pci1710_private)))<0) {
+               rt_printk(" - Allocation failed!\n");
+               return -ENOMEM;
+       }
+
+       /* Look for matching PCI device */
+       errstr = "not found!";
+       pcidev = NULL;
+       while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_ADVANTECH,
+                                       this_board->device_id, pcidev))) {
+               /* Found matching vendor/device. */
+               if (opt_bus || opt_slot) {
+                       /* Check bus/slot. */
+                       if (opt_bus != pcidev->bus->number
+                                       || opt_slot != PCI_SLOT(pcidev->devfn))
+                               continue;       /* no match */
+               }
+               /*
+                * 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!";
+                       continue;
+               }
+               break;
+       }
 
-       if ((pci_card_data(card,&pci_bus,&pci_slot,&pci_func,
-                           &io_addr[0],&irq,&master))<0) {
-               pci_card_free(card);
-               rt_printk(" - Can't get configuration data!\n");
+       if (!pcidev) {
+               if (opt_bus || opt_slot) {
+                       rt_printk(" - Card at b:s %d:%d %s\n",
+                                       opt_bus, opt_slot, errstr);
+               } else {
+                       rt_printk(" - Card %s\n", errstr);
+               }
                return -EIO;
        }
 
-       iobase=io_addr[2];
+       pci_bus = pcidev->bus->number;
+       pci_slot = PCI_SLOT(pcidev->devfn);
+       pci_func = PCI_FUNC(pcidev->devfn);
+       irq = pcidev->irq;
+       iobase = pci_resource_start(pcidev, 2);
 
        rt_printk(", b:s:f=%d:%d:%d, io=0x%4x",pci_bus,pci_slot,pci_func,iobase);
 
         dev->iobase=iobase;
 
        dev->board_name = this_board->name;
-
-       if((ret=alloc_private(dev,sizeof(pci1710_private)))<0) {
-               pci_card_free(card);
-               rt_printk(" - Allocation failed!\n");
-               return -ENOMEM;
-       }
-
-       devpriv->amcc = card;
+       devpriv->pcidev = pcidev;
 
         n_subdevices = 0;
        if (this_board->n_aichan) n_subdevices++;
@@ -1397,11 +1418,13 @@ static int pci1710_detach(comedi_device *dev)
        if (dev->private) {
                if (devpriv->valid) pci1710_reset(dev);
                if (dev->irq) comedi_free_irq(dev->irq,dev);
-               if (devpriv->amcc) pci_card_free(devpriv->amcc);
-       }
-
-       if (--pci_list_builded == 0) {
-               pci_card_list_cleanup(PCI_VENDOR_ID_ADVANTECH);
+               if (devpriv->pcidev) {
+                       if (dev->iobase) {
+                               pci_release_regions(devpriv->pcidev);
+                               pci_disable_device(devpriv->pcidev);
+                       }
+                       pci_dev_put(devpriv->pcidev);
+               }
        }
 
 
index c28f34018857f5556f8e9e428549180dd365b52f..86b211a9f0bb367c68f46bf5b09f5e7dd0bd396f 100644 (file)
@@ -15,9 +15,6 @@
 #ifndef _AMCC_S5933_H_
 #define _AMCC_S5933_H_
 
-#include <linux/comedidev.h>
-#include <linux/pci.h>
-
 
 /****************************************************************************/
 /* AMCC Operation Register Offsets - PCI                                    */
 #define TARGET_ABORT_INT       0x00200000L
 #define BUS_MASTER_INT         0x00200000L
 
-/****************************************************************************/
-
-struct pcilst_struct{
-       struct          pcilst_struct *next;
-       int             used;
-       struct pci_dev  *pcidev;
-       unsigned short  vendor;
-       unsigned short  device;
-       unsigned int    master;
-       unsigned char   pci_bus;
-       unsigned char   pci_slot;
-       unsigned char   pci_func;
-       unsigned int    io_addr[5];
-       unsigned int    irq;
-};
-
-struct pcilst_struct *amcc_devices;    // ptr to root list of all amcc devices
-
-/****************************************************************************/
-
-void pci_card_list_init(unsigned short pci_vendor, char display);
-void pci_card_list_cleanup(unsigned short pci_vendor);
-struct pcilst_struct *find_free_pci_card_by_device(unsigned short vendor_id, unsigned short device_id);
-int find_free_pci_card_by_position(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, struct pcilst_struct **card);
-struct pcilst_struct *select_and_alloc_pci_card(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, char master);
-
-//int pci_card_alloc(struct pcilst_struct *amcc);
-int pci_card_free(struct pcilst_struct *amcc);
-void pci_card_list_display(void);
-int pci_card_data(struct pcilst_struct *amcc,
-       unsigned char *pci_bus, unsigned char *pci_slot, unsigned char *pci_func,
-       unsigned short *io_addr, unsigned short *irq, unsigned short *master);
-
-/****************************************************************************/
-
 #endif