]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/unican.c
LinCAN PCI cards support updated to support PCI devices reference counting.
[lincan.git] / lincan / src / unican.c
index 2ec2aaaa9c11fb74fb4daa2c01d66b59d60c5668..10cc185dc4a49f6756bce104e610690edcfa1ec6 100644 (file)
@@ -970,19 +970,20 @@ int unican_pci_init_hw_data(struct candevice_t *candev)
 {
        struct pci_dev *pcidev = NULL;
 
-       do {
-               pcidev = pci_find_device(UNICAN_PCI_VENDOR, UNICAN_PCI_ID, pcidev);
-               if(pcidev == NULL) return -ENODEV;
-       } while(can_check_dev_taken(pcidev));
-       
+       pcidev = can_pci_get_next_untaken_device(UNICAN_PCI_VENDOR, UNICAN_PCI_ID);
+       if(pcidev == NULL)
+               return -ENODEV;
+
        if (pci_enable_device (pcidev)){
                printk(KERN_CRIT "Setup of Unican PCI failed\n");
+               can_pci_dev_put(pcidev);
                return -EIO;
        }
        candev->sysdevptr.pcidev=pcidev;
        
        if(!(pci_resource_flags(pcidev,0)&IORESOURCE_MEM)){
                printk(KERN_CRIT "Unican PCI region 0 is not MEM\n");
+               can_pci_dev_put(pcidev);
                return -EIO;
        }
        candev->io_addr=pci_resource_start(pcidev,0);
@@ -998,6 +999,11 @@ int unican_pci_init_hw_data(struct candevice_t *candev)
        return 0;
 }
 
+void unican_pci_done_hw_data(struct candevice_t *candev)
+{
+       struct pci_dev *pcidev = candev->sysdevptr.pcidev;
+       can_pci_dev_put(pcidev);
+}
 
 int unican_pci_init_chip_data(struct candevice_t *candev, int chipnr)
 {
@@ -1014,6 +1020,7 @@ int unican_pci_register(struct hwspecops_t *hwspecops)
        hwspecops->release_io = unican_pci_release_io;
        hwspecops->reset = unican_reset;
        hwspecops->init_hw_data = unican_pci_init_hw_data;
+       hwspecops->done_hw_data = unican_pci_done_hw_data;
        hwspecops->init_chip_data = unican_pci_init_chip_data;
        hwspecops->init_obj_data = unican_init_obj_data;
        hwspecops->write_register = NULL;