aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2012-09-19 19:21:49 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-21 12:24:17 -0400
commit94174847ea41b1c2a44d997f2850530fb33f41cd (patch)
treea3f9d40980fcd0f142f0727658966de0b3cb04ee
parent1e12ca3407850641fc72adb620eee8a8e6dd8c90 (diff)
staging: comedi: me_daq: use attach_pci callback
Convert this PCI driver to use the comedi PCI auto config attach mechanism by adding an 'attach_pci' callback function. Since the driver does not require any external configuration options. and the legacy 'attach' callback is now optional, remove it. Also, make the boardinfo 'name' unique for the different board types. Use this name when requesting the PCI resources. Change the printk at the end of the attach into a dev_info. 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.c88
1 files changed, 32 insertions, 56 deletions
diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c
index eeb493d12a05..2ce0b14af589 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -50,8 +50,6 @@ Configuration options:
50 50
51#define ME2600_FIRMWARE "me2600_firmware.bin" 51#define ME2600_FIRMWARE "me2600_firmware.bin"
52 52
53#define ME_DRIVER_NAME "me_daq"
54
55#define PCI_VENDOR_ID_MEILHAUS 0x1402 53#define PCI_VENDOR_ID_MEILHAUS 0x1402
56#define ME2000_DEVICE_ID 0x2000 54#define ME2000_DEVICE_ID 0x2000
57#define ME2600_DEVICE_ID 0x2600 55#define ME2600_DEVICE_ID 0x2600
@@ -192,8 +190,7 @@ struct me_board {
192 190
193static const struct me_board me_boards[] = { 191static const struct me_board me_boards[] = {
194 { 192 {
195 /* -- ME-2600i -- */ 193 .name = "me-2600i",
196 .name = ME_DRIVER_NAME,
197 .device_id = ME2600_DEVICE_ID, 194 .device_id = ME2600_DEVICE_ID,
198 /* Analog Output */ 195 /* Analog Output */
199 .ao_channel_nbr = 4, 196 .ao_channel_nbr = 4,
@@ -208,8 +205,7 @@ static const struct me_board me_boards[] = {
208 .dio_channel_nbr = 32, 205 .dio_channel_nbr = 32,
209 }, 206 },
210 { 207 {
211 /* -- ME-2000i -- */ 208 .name = "me-2000i",
212 .name = ME_DRIVER_NAME,
213 .device_id = ME2000_DEVICE_ID, 209 .device_id = ME2000_DEVICE_ID,
214 /* Analog Output */ 210 /* Analog Output */
215 .ao_channel_nbr = 0, 211 .ao_channel_nbr = 0,
@@ -617,44 +613,24 @@ static int me_reset(struct comedi_device *dev)
617 return 0; 613 return 0;
618} 614}
619 615
620static struct pci_dev *me_find_pci_dev(struct comedi_device *dev, 616static const void *me_find_boardinfo(struct comedi_device *dev,
621 struct comedi_devconfig *it) 617 struct pci_dev *pcidev)
622{ 618{
623 const struct me_board *board; 619 const struct me_board *board;
624 struct pci_dev *pcidev = NULL;
625 int bus = it->options[0];
626 int slot = it->options[1];
627 int i; 620 int i;
628 621
629 for_each_pci_dev(pcidev) { 622 for (i = 0; i < ARRAY_SIZE(me_boards); i++) {
630 if (bus || slot) { 623 board = &me_boards[i];
631 if (pcidev->bus->number != bus || 624 if (board->device_id == pcidev->device)
632 PCI_SLOT(pcidev->devfn) != slot) 625 return board;
633 continue;
634 }
635 if (pcidev->vendor != PCI_VENDOR_ID_MEILHAUS)
636 continue;
637
638 for (i = 0; i < ARRAY_SIZE(me_boards); i++) {
639 board = &me_boards[i];
640 if (board->device_id != pcidev->device)
641 continue;
642
643 dev->board_ptr = board;
644 return pcidev;
645 }
646 } 626 }
647 dev_err(dev->class_dev,
648 "No supported board found! (req. bus %d, slot %d)\n",
649 bus, slot);
650 return NULL; 627 return NULL;
651} 628}
652 629
653static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it) 630static int me_attach_pci(struct comedi_device *dev, struct pci_dev *pcidev)
654{ 631{
655 struct pci_dev *pci_device; 632 const struct me_board *board;
656 struct comedi_subdevice *s; 633 struct comedi_subdevice *s;
657 struct me_board *board;
658 resource_size_t plx_regbase_tmp; 634 resource_size_t plx_regbase_tmp;
659 unsigned long plx_regbase_size_tmp; 635 unsigned long plx_regbase_size_tmp;
660 resource_size_t me_regbase_tmp; 636 resource_size_t me_regbase_tmp;
@@ -664,29 +640,28 @@ static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)
664 resource_size_t regbase_tmp; 640 resource_size_t regbase_tmp;
665 int result, error; 641 int result, error;
666 642
643 comedi_set_hw_dev(dev, &pcidev->dev);
644
645 board = me_find_boardinfo(dev, pcidev);
646 if (!board)
647 return -ENODEV;
648 dev->board_ptr = board;
649 dev->board_name = board->name;
650
667 /* Allocate private memory */ 651 /* Allocate private memory */
668 if (alloc_private(dev, sizeof(struct me_private_data)) < 0) 652 if (alloc_private(dev, sizeof(struct me_private_data)) < 0)
669 return -ENOMEM; 653 return -ENOMEM;
670 654
671 pci_device = me_find_pci_dev(dev, it);
672 if (!pci_device)
673 return -EIO;
674 comedi_set_hw_dev(dev, &pci_device->dev);
675 board = (struct me_board *)dev->board_ptr;
676
677 /* Enable PCI device and request PCI regions */ 655 /* Enable PCI device and request PCI regions */
678 if (comedi_pci_enable(pci_device, ME_DRIVER_NAME) < 0) { 656 if (comedi_pci_enable(pcidev, dev->board_name) < 0) {
679 printk(KERN_ERR "comedi%d: Failed to enable PCI device and " 657 printk(KERN_ERR "comedi%d: Failed to enable PCI device and "
680 "request regions\n", dev->minor); 658 "request regions\n", dev->minor);
681 return -EIO; 659 return -EIO;
682 } 660 }
683 661
684 /* Set data in device structure */
685 dev->board_name = board->name;
686
687 /* Read PLX register base address [PCI_BASE_ADDRESS #0]. */ 662 /* Read PLX register base address [PCI_BASE_ADDRESS #0]. */
688 plx_regbase_tmp = pci_resource_start(pci_device, 0); 663 plx_regbase_tmp = pci_resource_start(pcidev, 0);
689 plx_regbase_size_tmp = pci_resource_len(pci_device, 0); 664 plx_regbase_size_tmp = pci_resource_len(pcidev, 0);
690 dev_private->plx_regbase = 665 dev_private->plx_regbase =
691 ioremap(plx_regbase_tmp, plx_regbase_size_tmp); 666 ioremap(plx_regbase_tmp, plx_regbase_size_tmp);
692 dev_private->plx_regbase_size = plx_regbase_size_tmp; 667 dev_private->plx_regbase_size = plx_regbase_size_tmp;
@@ -697,8 +672,8 @@ static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)
697 672
698 /* Read Swap base address [PCI_BASE_ADDRESS #5]. */ 673 /* Read Swap base address [PCI_BASE_ADDRESS #5]. */
699 674
700 swap_regbase_tmp = pci_resource_start(pci_device, 5); 675 swap_regbase_tmp = pci_resource_start(pcidev, 5);
701 swap_regbase_size_tmp = pci_resource_len(pci_device, 5); 676 swap_regbase_size_tmp = pci_resource_len(pcidev, 5);
702 677
703 if (!swap_regbase_tmp) 678 if (!swap_regbase_tmp)
704 printk(KERN_ERR "comedi%d: Swap not present\n", dev->minor); 679 printk(KERN_ERR "comedi%d: Swap not present\n", dev->minor);
@@ -712,20 +687,20 @@ static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)
712 plx_regbase_tmp = swap_regbase_tmp; 687 plx_regbase_tmp = swap_regbase_tmp;
713 swap_regbase_tmp = regbase_tmp; 688 swap_regbase_tmp = regbase_tmp;
714 689
715 result = pci_write_config_dword(pci_device, 690 result = pci_write_config_dword(pcidev,
716 PCI_BASE_ADDRESS_0, 691 PCI_BASE_ADDRESS_0,
717 plx_regbase_tmp); 692 plx_regbase_tmp);
718 if (result != PCIBIOS_SUCCESSFUL) 693 if (result != PCIBIOS_SUCCESSFUL)
719 return -EIO; 694 return -EIO;
720 695
721 result = pci_write_config_dword(pci_device, 696 result = pci_write_config_dword(pcidev,
722 PCI_BASE_ADDRESS_5, 697 PCI_BASE_ADDRESS_5,
723 swap_regbase_tmp); 698 swap_regbase_tmp);
724 if (result != PCIBIOS_SUCCESSFUL) 699 if (result != PCIBIOS_SUCCESSFUL)
725 return -EIO; 700 return -EIO;
726 } else { 701 } else {
727 plx_regbase_tmp -= 0x80; 702 plx_regbase_tmp -= 0x80;
728 result = pci_write_config_dword(pci_device, 703 result = pci_write_config_dword(pcidev,
729 PCI_BASE_ADDRESS_0, 704 PCI_BASE_ADDRESS_0,
730 plx_regbase_tmp); 705 plx_regbase_tmp);
731 if (result != PCIBIOS_SUCCESSFUL) 706 if (result != PCIBIOS_SUCCESSFUL)
@@ -736,8 +711,8 @@ static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)
736 711
737 /* Read Meilhaus register base address [PCI_BASE_ADDRESS #2]. */ 712 /* Read Meilhaus register base address [PCI_BASE_ADDRESS #2]. */
738 713
739 me_regbase_tmp = pci_resource_start(pci_device, 2); 714 me_regbase_tmp = pci_resource_start(pcidev, 2);
740 me_regbase_size_tmp = pci_resource_len(pci_device, 2); 715 me_regbase_size_tmp = pci_resource_len(pcidev, 2);
741 dev_private->me_regbase_size = me_regbase_size_tmp; 716 dev_private->me_regbase_size = me_regbase_size_tmp;
742 dev_private->me_regbase = ioremap(me_regbase_tmp, me_regbase_size_tmp); 717 dev_private->me_regbase = ioremap(me_regbase_tmp, me_regbase_size_tmp);
743 if (!dev_private->me_regbase) { 718 if (!dev_private->me_regbase) {
@@ -791,8 +766,9 @@ static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)
791 s->insn_config = me_dio_insn_config; 766 s->insn_config = me_dio_insn_config;
792 s->io_bits = 0; 767 s->io_bits = 0;
793 768
794 printk(KERN_INFO "comedi%d: " ME_DRIVER_NAME " attached.\n", 769 dev_info(dev->class_dev, "%s: %s attached\n",
795 dev->minor); 770 dev->driver->driver_name, dev->board_name);
771
796 return 0; 772 return 0;
797} 773}
798 774
@@ -818,7 +794,7 @@ static void me_detach(struct comedi_device *dev)
818static struct comedi_driver me_daq_driver = { 794static struct comedi_driver me_daq_driver = {
819 .driver_name = "me_daq", 795 .driver_name = "me_daq",
820 .module = THIS_MODULE, 796 .module = THIS_MODULE,
821 .attach = me_attach, 797 .attach_pci = me_attach_pci,
822 .detach = me_detach, 798 .detach = me_detach,
823}; 799};
824 800