diff options
author | H Hartley Sweeten <hartleys@visionengravers.com> | 2012-07-18 22:03:25 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-07-19 19:51:39 -0400 |
commit | b92169fd857421825e16f68d178c48f8727e75cc (patch) | |
tree | f70ae08b2fda77122bfe611e6e66421d8b2cc368 | |
parent | bdc1afa388b89285d68de2ae423dd0d25cfc1d62 (diff) |
staging: comedi: me_daq: factor out the "find pci device" code
Factor the "find pci device" code out of the attach function.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/comedi/drivers/me_daq.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c index 1803d66cbf7d..dc0fbbd895ff 100644 --- a/drivers/staging/comedi/drivers/me_daq.c +++ b/drivers/staging/comedi/drivers/me_daq.c | |||
@@ -610,23 +610,11 @@ static int me_reset(struct comedi_device *dev) | |||
610 | return 0; | 610 | return 0; |
611 | } | 611 | } |
612 | 612 | ||
613 | static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it) | 613 | static struct pci_dev *me_find_pci_dev(struct comedi_device *dev, |
614 | struct comedi_devconfig *it) | ||
614 | { | 615 | { |
615 | struct pci_dev *pci_device = NULL; | 616 | struct pci_dev *pci_device = NULL; |
616 | struct comedi_subdevice *subdevice; | 617 | int i; |
617 | struct me_board *board; | ||
618 | resource_size_t plx_regbase_tmp; | ||
619 | unsigned long plx_regbase_size_tmp; | ||
620 | resource_size_t me_regbase_tmp; | ||
621 | unsigned long me_regbase_size_tmp; | ||
622 | resource_size_t swap_regbase_tmp; | ||
623 | unsigned long swap_regbase_size_tmp; | ||
624 | resource_size_t regbase_tmp; | ||
625 | int result, error, i; | ||
626 | |||
627 | /* Allocate private memory */ | ||
628 | if (alloc_private(dev, sizeof(struct me_private_data)) < 0) | ||
629 | return -ENOMEM; | ||
630 | 618 | ||
631 | /* Probe the device to determine what device in the series it is. */ | 619 | /* Probe the device to determine what device in the series it is. */ |
632 | for_each_pci_dev(pci_device) { | 620 | for_each_pci_dev(pci_device) { |
@@ -652,9 +640,6 @@ static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it) | |||
652 | } | 640 | } |
653 | 641 | ||
654 | dev->board_ptr = me_boards + i; | 642 | dev->board_ptr = me_boards + i; |
655 | board = | ||
656 | (struct me_board *)dev->board_ptr; | ||
657 | dev_private->pci_device = pci_device; | ||
658 | goto found; | 643 | goto found; |
659 | } | 644 | } |
660 | } | 645 | } |
@@ -664,12 +649,38 @@ static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it) | |||
664 | printk(KERN_ERR | 649 | printk(KERN_ERR |
665 | "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n", | 650 | "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n", |
666 | dev->minor, it->options[0], it->options[1]); | 651 | dev->minor, it->options[0], it->options[1]); |
667 | return -EIO; | 652 | return NULL; |
668 | 653 | ||
669 | found: | 654 | found: |
670 | printk(KERN_INFO "comedi%d: found %s at PCI bus %d, slot %d\n", | 655 | printk(KERN_INFO "comedi%d: found %s at PCI bus %d, slot %d\n", |
671 | dev->minor, me_boards[i].name, | 656 | dev->minor, me_boards[i].name, |
672 | pci_device->bus->number, PCI_SLOT(pci_device->devfn)); | 657 | pci_device->bus->number, PCI_SLOT(pci_device->devfn)); |
658 | return pci_device; | ||
659 | } | ||
660 | |||
661 | static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it) | ||
662 | { | ||
663 | struct pci_dev *pci_device; | ||
664 | struct comedi_subdevice *subdevice; | ||
665 | struct me_board *board; | ||
666 | resource_size_t plx_regbase_tmp; | ||
667 | unsigned long plx_regbase_size_tmp; | ||
668 | resource_size_t me_regbase_tmp; | ||
669 | unsigned long me_regbase_size_tmp; | ||
670 | resource_size_t swap_regbase_tmp; | ||
671 | unsigned long swap_regbase_size_tmp; | ||
672 | resource_size_t regbase_tmp; | ||
673 | int result, error; | ||
674 | |||
675 | /* Allocate private memory */ | ||
676 | if (alloc_private(dev, sizeof(struct me_private_data)) < 0) | ||
677 | return -ENOMEM; | ||
678 | |||
679 | pci_device = me_find_pci_dev(dev, it); | ||
680 | if (!pci_device) | ||
681 | return -EIO; | ||
682 | dev_private->pci_device = pci_device; | ||
683 | board = (struct me_board *)dev->board_ptr; | ||
673 | 684 | ||
674 | /* Enable PCI device and request PCI regions */ | 685 | /* Enable PCI device and request PCI regions */ |
675 | if (comedi_pci_enable(pci_device, ME_DRIVER_NAME) < 0) { | 686 | if (comedi_pci_enable(pci_device, ME_DRIVER_NAME) < 0) { |