14 #include <linux/module.h>
15 #include <linux/slab.h>
18 static u16 tpci200_status_timeout[] = {
25 static u16 tpci200_status_error[] = {
42 if (tpci200 ==
NULL) {
49 "Slot [%d:%d] doesn't exist! Last tpci200 slot is %d.\n",
63 spin_unlock_irqrestore(&tpci200->
regs_lock, flags);
72 spin_unlock_irqrestore(&tpci200->
regs_lock, flags);
96 tpci200->
slots[
i].io_phys.size = 0;
98 tpci200->
slots[
i].id_phys.size = 0;
100 tpci200->
slots[
i].int_phys.size = 0;
102 tpci200->
slots[
i].mem_phys.size = 0;
106 static void tpci200_enable_irq(
struct tpci200_board *tpci200,
109 tpci200_set_mask(tpci200,
110 &tpci200->
info->interface_regs->control[islot],
114 static void tpci200_disable_irq(
struct tpci200_board *tpci200,
117 tpci200_clear_mask(tpci200,
118 &tpci200->
info->interface_regs->control[islot],
136 struct slot_irq *slot_irq;
142 status_reg =
ioread16(&tpci200->
info->interface_regs->status);
154 ret = tpci200_slot_irq(slot_irq);
157 "No registered ISR for slot [%d:%d]!. IRQ will be disabled.\n",
159 tpci200_disable_irq(tpci200, i);
169 struct slot_irq *slot_irq;
172 tpci200 = check_slot(dev);
184 tpci200_disable_irq(tpci200, dev->
slot);
185 slot_irq = tpci200->
slots[dev->
slot].irq;
194 static int tpci200_request_irq(
struct ipack_device *dev,
198 struct slot_irq *slot_irq;
201 tpci200 = check_slot(dev);
210 "Slot [%d:%d] IRQ already registered !\n", dev->
bus_nr,
216 slot_irq = kzalloc(
sizeof(
struct slot_irq),
GFP_KERNEL);
217 if (slot_irq ==
NULL) {
219 "Slot [%d:%d] unable to allocate memory for IRQ !\n",
236 tpci200_enable_irq(tpci200, dev->
slot);
247 unsigned long ioidint_base;
249 unsigned short slot_ctrl;
256 "Carrier IP interface registers");
259 "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 2 !",
260 tpci200->
info->pdev->bus->number,
261 tpci200->
info->pdev->devfn);
262 goto out_disable_pci;
268 "Carrier IO ID INT space");
271 "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 3 !",
272 tpci200->
info->pdev->bus->number,
273 tpci200->
info->pdev->devfn);
274 goto out_release_ip_space;
279 "Carrier MEM space");
282 "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 4!",
283 tpci200->
info->pdev->bus->number,
284 tpci200->
info->pdev->devfn);
285 goto out_release_ioid_int_space;
289 tpci200->
info->interface_regs =
293 tpci200->
info->ioidint_space =
297 tpci200->
info->mem8_space =
322 tpci200->
slots[
i].io_phys.address =
327 tpci200->
slots[
i].id_phys.address =
332 tpci200->
slots[
i].int_phys.address =
337 tpci200->
slots[
i].mem_phys.address =
341 writew(slot_ctrl, &tpci200->
info->interface_regs->control[i]);
346 KBUILD_MODNAME, (
void *) tpci200);
349 "(bn 0x%X, sn 0x%X) unable to register IRQ !",
350 tpci200->
info->pdev->bus->number,
351 tpci200->
info->pdev->devfn);
352 goto out_release_ioid_int_space;
357 out_release_ioid_int_space:
359 out_release_ip_space:
366 static int tpci200_slot_unmap_space(
struct ipack_device *dev,
int space)
371 tpci200 = check_slot(dev);
382 "Slot [%d:%d] IO space not mapped !\n",
391 "Slot [%d:%d] ID space not mapped !\n",
400 "Slot [%d:%d] INT space not mapped !\n",
409 "Slot [%d:%d] MEM space not mapped !\n",
417 "Slot [%d:%d] space number %d doesn't exist !\n",
426 virt_addr_space->
size = 0;
432 static int tpci200_slot_map_space(
struct ipack_device *dev,
436 unsigned int size_to_map;
441 tpci200 = check_slot(dev);
452 "Slot [%d:%d] IO space already mapped !\n",
459 phys_address = tpci200->
slots[dev->
slot].io_phys.address;
460 size_to_map = tpci200->
slots[dev->
slot].io_phys.size;
465 "Slot [%d:%d] ID space already mapped !\n",
472 phys_address = tpci200->
slots[dev->
slot].id_phys.address;
473 size_to_map = tpci200->
slots[dev->
slot].id_phys.size;
478 "Slot [%d:%d] INT space already mapped !\n",
485 phys_address = tpci200->
slots[dev->
slot].int_phys.address;
486 size_to_map = tpci200->
slots[dev->
slot].int_phys.size;
491 "Slot [%d:%d] MEM space already mapped !\n",
498 if (memory_size > tpci200->
slots[dev->
slot].mem_phys.size) {
500 "Slot [%d:%d] request is 0x%X memory, only 0x%X available !\n",
502 tpci200->
slots[dev->
slot].mem_phys.size);
507 phys_address = tpci200->
slots[dev->
slot].mem_phys.address;
511 dev_err(&dev->
dev,
"Slot [%d:%d] space %d doesn't exist !\n",
517 virt_addr_space->
size = size_to_map;
526 static int tpci200_get_clockrate(
struct ipack_device *dev)
534 addr = &tpci200->
info->interface_regs->control[dev->
slot];
538 static int tpci200_set_clockrate(
struct ipack_device *dev,
int mherz)
546 addr = &tpci200->
info->interface_regs->control[dev->
slot];
570 addr = &tpci200->
info->interface_regs->status;
571 mask = tpci200_status_error[dev->
slot];
572 return (
ioread16(addr) & mask) ? 1 : 0;
575 static int tpci200_get_timeout(
struct ipack_device *dev)
584 addr = &tpci200->
info->interface_regs->status;
585 mask = tpci200_status_timeout[dev->
slot];
587 return (
ioread16(addr) & mask) ? 1 : 0;
590 static int tpci200_reset_timeout(
struct ipack_device *dev)
599 addr = &tpci200->
info->interface_regs->status;
600 mask = tpci200_status_timeout[dev->
slot];
608 tpci200_unregister(tpci200);
613 .map_space = tpci200_slot_map_space,
614 .unmap_space = tpci200_slot_unmap_space,
615 .request_irq = tpci200_request_irq,
616 .free_irq = tpci200_free_irq,
617 .get_clockrate = tpci200_get_clockrate,
618 .set_clockrate = tpci200_set_clockrate,
619 .get_error = tpci200_get_error,
620 .get_timeout = tpci200_get_timeout,
621 .reset_timeout = tpci200_reset_timeout,
628 tpci200->
slots = kzalloc(
633 res = tpci200_register(tpci200);
644 static int tpci200_pci_probe(
struct pci_dev *pdev,
656 if (!tpci200->
info) {
665 KBUILD_MODNAME
" Configuration Memory");
667 dev_err(&pdev->
dev,
"Failed to allocate PCI Configuration Memory");
669 goto out_err_pci_request;
674 if (!tpci200->
info->cfg_regs) {
675 dev_err(&pdev->
dev,
"Failed to map PCI Configuration Memory");
677 goto out_err_ioremap;
692 tpci200->
info->pdev = pdev;
696 ret = tpci200_install(tpci200);
698 dev_err(&pdev->
dev,
"error during tpci200 install\n");
700 goto out_err_install;
707 if (!tpci200->
info->ipack_bus) {
709 "error registering the carrier on ipack driver\n");
711 goto out_err_bus_register;
715 tpci200->
number = tpci200->
info->ipack_bus->bus_nr;
722 out_err_bus_register:
723 tpci200_uninstall(tpci200);
736 static void __tpci200_pci_remove(
struct tpci200_board *tpci200)
739 tpci200_uninstall(tpci200);
749 __tpci200_pci_remove(tpci200);
762 .id_table = tpci200_idtable,
763 .probe = tpci200_pci_probe,
767 static int __init tpci200_drvr_init_module(
void)
769 return pci_register_driver(&tpci200_pci_drv);
772 static void __exit tpci200_drvr_exit_module(
void)