From: Frank Mori Hess Date: Sat, 12 Mar 2005 13:31:39 +0000 (+0000) Subject: patch from Ian Abbott : X-Git-Tag: r0_7_70~18 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b15596ff7c423baf37a81901cd2e748c1623062f;p=comedi.git patch from Ian Abbott : 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. --- diff --git a/comedi/drivers/amplc_pci224.c b/comedi/drivers/amplc_pci224.c index 3557294b..8b15c339 100644 --- a/comedi/drivers/amplc_pci224.c +++ b/comedi/drivers/amplc_pci224.c @@ -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); } }