uio_netx.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * UIO driver for Hilscher NetX based fieldbus cards (cifX, comX).
  3. * See http://www.hilscher.com for details.
  4. *
  5. * (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
  6. * (C) 2008 Manuel Traut <manut@linutronix.de>
  7. *
  8. * Licensed under GPL version 2 only.
  9. *
  10. */
  11. #include <linux/device.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include <linux/slab.h>
  16. #include <linux/uio_driver.h>
  17. #define PCI_VENDOR_ID_HILSCHER 0x15CF
  18. #define PCI_DEVICE_ID_HILSCHER_NETX 0x0000
  19. #define PCI_DEVICE_ID_HILSCHER_NETPLC 0x0010
  20. #define PCI_SUBDEVICE_ID_NETPLC_RAM 0x0000
  21. #define PCI_SUBDEVICE_ID_NETPLC_FLASH 0x0001
  22. #define PCI_SUBDEVICE_ID_NXSB_PCA 0x3235
  23. #define PCI_SUBDEVICE_ID_NXPCA 0x3335
  24. #define DPM_HOST_INT_EN0 0xfff0
  25. #define DPM_HOST_INT_STAT0 0xffe0
  26. #define DPM_HOST_INT_MASK 0xe600ffff
  27. #define DPM_HOST_INT_GLOBAL_EN 0x80000000
  28. static irqreturn_t netx_handler(int irq, struct uio_info *dev_info)
  29. {
  30. void __iomem *int_enable_reg = dev_info->mem[0].internal_addr
  31. + DPM_HOST_INT_EN0;
  32. void __iomem *int_status_reg = dev_info->mem[0].internal_addr
  33. + DPM_HOST_INT_STAT0;
  34. /* Is one of our interrupts enabled and active ? */
  35. if (!(ioread32(int_enable_reg) & ioread32(int_status_reg)
  36. & DPM_HOST_INT_MASK))
  37. return IRQ_NONE;
  38. /* Disable interrupt */
  39. iowrite32(ioread32(int_enable_reg) & ~DPM_HOST_INT_GLOBAL_EN,
  40. int_enable_reg);
  41. return IRQ_HANDLED;
  42. }
  43. static int netx_pci_probe(struct pci_dev *dev,
  44. const struct pci_device_id *id)
  45. {
  46. struct uio_info *info;
  47. int bar;
  48. info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
  49. if (!info)
  50. return -ENOMEM;
  51. if (pci_enable_device(dev))
  52. goto out_free;
  53. if (pci_request_regions(dev, "netx"))
  54. goto out_disable;
  55. switch (id->device) {
  56. case PCI_DEVICE_ID_HILSCHER_NETX:
  57. bar = 0;
  58. info->name = "netx";
  59. break;
  60. case PCI_DEVICE_ID_HILSCHER_NETPLC:
  61. bar = 0;
  62. info->name = "netplc";
  63. break;
  64. default:
  65. bar = 2;
  66. info->name = "netx_plx";
  67. }
  68. /* BAR0 or 2 points to the card's dual port memory */
  69. info->mem[0].addr = pci_resource_start(dev, bar);
  70. if (!info->mem[0].addr)
  71. goto out_release;
  72. info->mem[0].internal_addr = ioremap(pci_resource_start(dev, bar),
  73. pci_resource_len(dev, bar));
  74. if (!info->mem[0].internal_addr)
  75. goto out_release;
  76. info->mem[0].size = pci_resource_len(dev, bar);
  77. info->mem[0].memtype = UIO_MEM_PHYS;
  78. info->irq = dev->irq;
  79. info->irq_flags = IRQF_SHARED;
  80. info->handler = netx_handler;
  81. info->version = "0.0.1";
  82. /* Make sure all interrupts are disabled */
  83. iowrite32(0, info->mem[0].internal_addr + DPM_HOST_INT_EN0);
  84. if (uio_register_device(&dev->dev, info))
  85. goto out_unmap;
  86. pci_set_drvdata(dev, info);
  87. dev_info(&dev->dev, "Found %s card, registered UIO device.\n",
  88. info->name);
  89. return 0;
  90. out_unmap:
  91. iounmap(info->mem[0].internal_addr);
  92. out_release:
  93. pci_release_regions(dev);
  94. out_disable:
  95. pci_disable_device(dev);
  96. out_free:
  97. kfree(info);
  98. return -ENODEV;
  99. }
  100. static void netx_pci_remove(struct pci_dev *dev)
  101. {
  102. struct uio_info *info = pci_get_drvdata(dev);
  103. /* Disable all interrupts */
  104. iowrite32(0, info->mem[0].internal_addr + DPM_HOST_INT_EN0);
  105. uio_unregister_device(info);
  106. pci_release_regions(dev);
  107. pci_disable_device(dev);
  108. iounmap(info->mem[0].internal_addr);
  109. kfree(info);
  110. }
  111. static struct pci_device_id netx_pci_ids[] = {
  112. {
  113. .vendor = PCI_VENDOR_ID_HILSCHER,
  114. .device = PCI_DEVICE_ID_HILSCHER_NETX,
  115. .subvendor = 0,
  116. .subdevice = 0,
  117. },
  118. {
  119. .vendor = PCI_VENDOR_ID_HILSCHER,
  120. .device = PCI_DEVICE_ID_HILSCHER_NETPLC,
  121. .subvendor = PCI_VENDOR_ID_HILSCHER,
  122. .subdevice = PCI_SUBDEVICE_ID_NETPLC_RAM,
  123. },
  124. {
  125. .vendor = PCI_VENDOR_ID_HILSCHER,
  126. .device = PCI_DEVICE_ID_HILSCHER_NETPLC,
  127. .subvendor = PCI_VENDOR_ID_HILSCHER,
  128. .subdevice = PCI_SUBDEVICE_ID_NETPLC_FLASH,
  129. },
  130. {
  131. .vendor = PCI_VENDOR_ID_PLX,
  132. .device = PCI_DEVICE_ID_PLX_9030,
  133. .subvendor = PCI_VENDOR_ID_PLX,
  134. .subdevice = PCI_SUBDEVICE_ID_NXSB_PCA,
  135. },
  136. {
  137. .vendor = PCI_VENDOR_ID_PLX,
  138. .device = PCI_DEVICE_ID_PLX_9030,
  139. .subvendor = PCI_VENDOR_ID_PLX,
  140. .subdevice = PCI_SUBDEVICE_ID_NXPCA,
  141. },
  142. { 0, }
  143. };
  144. static struct pci_driver netx_pci_driver = {
  145. .name = "netx",
  146. .id_table = netx_pci_ids,
  147. .probe = netx_pci_probe,
  148. .remove = netx_pci_remove,
  149. };
  150. module_pci_driver(netx_pci_driver);
  151. MODULE_DEVICE_TABLE(pci, netx_pci_ids);
  152. MODULE_LICENSE("GPL v2");
  153. MODULE_AUTHOR("Hans J. Koch, Manuel Traut");