uio_cif.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * UIO Hilscher CIF card driver
  3. *
  4. * (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
  5. * Original code (C) 2005 Benedikt Spranger <b.spranger@linutronix.de>
  6. *
  7. * Licensed under GPL version 2 only.
  8. *
  9. */
  10. #include <linux/device.h>
  11. #include <linux/module.h>
  12. #include <linux/pci.h>
  13. #include <linux/slab.h>
  14. #include <linux/uio_driver.h>
  15. #include <asm/io.h>
  16. #define PLX9030_INTCSR 0x4C
  17. #define INTSCR_INT1_ENABLE 0x01
  18. #define INTSCR_INT1_STATUS 0x04
  19. #define INT1_ENABLED_AND_ACTIVE (INTSCR_INT1_ENABLE | INTSCR_INT1_STATUS)
  20. #define PCI_SUBVENDOR_ID_PEP 0x1518
  21. #define CIF_SUBDEVICE_PROFIBUS 0x430
  22. #define CIF_SUBDEVICE_DEVICENET 0x432
  23. static irqreturn_t hilscher_handler(int irq, struct uio_info *dev_info)
  24. {
  25. void __iomem *plx_intscr = dev_info->mem[0].internal_addr
  26. + PLX9030_INTCSR;
  27. if ((ioread8(plx_intscr) & INT1_ENABLED_AND_ACTIVE)
  28. != INT1_ENABLED_AND_ACTIVE)
  29. return IRQ_NONE;
  30. /* Disable interrupt */
  31. iowrite8(ioread8(plx_intscr) & ~INTSCR_INT1_ENABLE, plx_intscr);
  32. return IRQ_HANDLED;
  33. }
  34. static int hilscher_pci_probe(struct pci_dev *dev,
  35. const struct pci_device_id *id)
  36. {
  37. struct uio_info *info;
  38. info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
  39. if (!info)
  40. return -ENOMEM;
  41. if (pci_enable_device(dev))
  42. goto out_free;
  43. if (pci_request_regions(dev, "hilscher"))
  44. goto out_disable;
  45. info->mem[0].addr = pci_resource_start(dev, 0);
  46. if (!info->mem[0].addr)
  47. goto out_release;
  48. info->mem[0].internal_addr = pci_ioremap_bar(dev, 0);
  49. if (!info->mem[0].internal_addr)
  50. goto out_release;
  51. info->mem[0].size = pci_resource_len(dev, 0);
  52. info->mem[0].memtype = UIO_MEM_PHYS;
  53. info->mem[1].addr = pci_resource_start(dev, 2);
  54. info->mem[1].size = pci_resource_len(dev, 2);
  55. info->mem[1].memtype = UIO_MEM_PHYS;
  56. switch (id->subdevice) {
  57. case CIF_SUBDEVICE_PROFIBUS:
  58. info->name = "CIF_Profibus";
  59. break;
  60. case CIF_SUBDEVICE_DEVICENET:
  61. info->name = "CIF_Devicenet";
  62. break;
  63. default:
  64. info->name = "CIF_???";
  65. }
  66. info->version = "0.0.1";
  67. info->irq = dev->irq;
  68. info->irq_flags = IRQF_SHARED;
  69. info->handler = hilscher_handler;
  70. if (uio_register_device(&dev->dev, info))
  71. goto out_unmap;
  72. pci_set_drvdata(dev, info);
  73. return 0;
  74. out_unmap:
  75. iounmap(info->mem[0].internal_addr);
  76. out_release:
  77. pci_release_regions(dev);
  78. out_disable:
  79. pci_disable_device(dev);
  80. out_free:
  81. kfree (info);
  82. return -ENODEV;
  83. }
  84. static void hilscher_pci_remove(struct pci_dev *dev)
  85. {
  86. struct uio_info *info = pci_get_drvdata(dev);
  87. uio_unregister_device(info);
  88. pci_release_regions(dev);
  89. pci_disable_device(dev);
  90. iounmap(info->mem[0].internal_addr);
  91. kfree (info);
  92. }
  93. static struct pci_device_id hilscher_pci_ids[] = {
  94. {
  95. .vendor = PCI_VENDOR_ID_PLX,
  96. .device = PCI_DEVICE_ID_PLX_9030,
  97. .subvendor = PCI_SUBVENDOR_ID_PEP,
  98. .subdevice = CIF_SUBDEVICE_PROFIBUS,
  99. },
  100. {
  101. .vendor = PCI_VENDOR_ID_PLX,
  102. .device = PCI_DEVICE_ID_PLX_9030,
  103. .subvendor = PCI_SUBVENDOR_ID_PEP,
  104. .subdevice = CIF_SUBDEVICE_DEVICENET,
  105. },
  106. { 0, }
  107. };
  108. static struct pci_driver hilscher_pci_driver = {
  109. .name = "hilscher",
  110. .id_table = hilscher_pci_ids,
  111. .probe = hilscher_pci_probe,
  112. .remove = hilscher_pci_remove,
  113. };
  114. module_pci_driver(hilscher_pci_driver);
  115. MODULE_DEVICE_TABLE(pci, hilscher_pci_ids);
  116. MODULE_LICENSE("GPL v2");
  117. MODULE_AUTHOR("Hans J. Koch, Benedikt Spranger");