/* * pci.c */ #include "hrt.h" #include "pci.h" #include #define hrt_pci_printk printk("hrt_pci: "); printk static int hrt_use_pci = 1; hrt_parm(hrt_use_pci, "i", int, 0); void hrt_pci_remove(struct pci_dev *pci_dev); int hrt_pci_probe(struct pci_dev *dev, const struct pci_device_id *pci_id); static struct pci_device_id hrt_pci_tbl[] __devinitdata = { {HRT_VENDOR_ID, HRT_DEVICE_ID_GRAY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {0,} }; MODULE_DEVICE_TABLE(pci, hrt_pci_tbl); static struct pci_driver hrt_pci_driver = { .name = "hrt", .id_table = hrt_pci_tbl, .probe = hrt_pci_probe, .remove = hrt_pci_remove, }; int hrt_pci_available; /** * hrt_addresses - a list of possible jumper-selected addresses * jumper A on = plug and play address (above one MB address) * jumper A off = hardwired to 0xdc000 or 0xd4000 * jumper B on = address 0xd4000 (ignored if jumper A is on) * jumper B off = address 0xdc000 (ignored if jumper A is on) */ const unsigned long hrt_addresses[] = { 0xd4000, 0xdc000 }; /* * functions */ int hrt_pci_manual_find_dev() { int i; hrt_pci_available = 0; /* init all the devices found in the system */ for (i = 0; i < ARRAY_SIZE(hrt_addresses); i++) { if (hrt_num_devices >= HRT_MAX_DEVICES) { hrt_printk("More than %d HRT devices\n", HRT_MAX_DEVICES); return -ENOMEM; } hrt_devices[hrt_num_devices].pci_dev = 0; if (!hrt_dev_init(&hrt_devices[hrt_num_devices], hrt_num_devices, hrt_addresses[i])) hrt_num_devices++; } if (hrt_num_devices == 0) { hrt_printk("No HRT cards detected.\n"); return -ENODEV; } else hrt_printk("Number of HRT devices found: %d\n", hrt_num_devices); return 0; } int hrt_pci_init() { hrt_pci_printk("entering hrt_pci_init()\n"); hrt_static_dev_init(); if (hrt_use_pci) { hrt_pci_available = !pci_module_init(&hrt_pci_driver); if (hrt_pci_available != 0) { hrt_pci_printk("pci was found\n"); } else { hrt_pci_printk("pci was not found\n"); } } else hrt_pci_available = 0; /* * this is so that when the card is configured as a low * address we will manually detect it as a isa dev although * pci_module_init will still succed in hotplug situations * and on the 2.6 kernel */ if (0 == pci_find_device(HRT_VENDOR_ID, HRT_DEVICE_ID_GRAY, 0)) hrt_pci_available = 0; if (!hrt_pci_available) { /* pci wasnt found so try manually to find the device */ hrt_printk("PCI wasnt found so trying to find device manually\n"); hrt_pci_available = 0; return hrt_pci_manual_find_dev(); } return !hrt_pci_available; } void hrt_pci_cleanup() { hrt_pci_printk("entering hrt_pci_cleanup()\n"); if (hrt_pci_available) pci_unregister_driver(&hrt_pci_driver); } /* */ int hrt_pci_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) { hrt_dev_t* d = &hrt_devices[hrt_num_devices]; hrt_pci_printk("entering hrt_pci_probe(..)\n"); if (hrt_num_devices >= HRT_MAX_DEVICES) { hrt_pci_printk("no more free hrt_dev devices\n"); return -ENOMEM; } /* do some probing */ if (pci_enable_device(dev)) { hrt_pci_printk("pci_enable_device failed :(\n"); return -EIO; } if (!hrt_dev_init(d, hrt_num_devices, pci_resource_start(dev, 0))) { hrt_pci_printk("found hrt device at 0x%lx\n", pci_resource_start(dev, 0)); /* device has been found so set data */ d->pci_dev = dev; return 0; } else return -ENODEV; } void hrt_pci_remove(struct pci_dev *pci_dev) { hrt_pci_printk("entering hrt_pci_remove()\n"); }