uio_cif.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 __devinit 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. pci_set_drvdata(dev, NULL);
  91. iounmap(info->mem[0].internal_addr);
  92. kfree (info);
  93. }
  94. static struct pci_device_id hilscher_pci_ids[] __devinitdata = {
  95. {
  96. .vendor = PCI_VENDOR_ID_PLX,
  97. .device = PCI_DEVICE_ID_PLX_9030,
  98. .subvendor = PCI_SUBVENDOR_ID_PEP,
  99. .subdevice = CIF_SUBDEVICE_PROFIBUS,
  100. },
  101. {
  102. .vendor = PCI_VENDOR_ID_PLX,
  103. .device = PCI_DEVICE_ID_PLX_9030,
  104. .subvendor = PCI_SUBVENDOR_ID_PEP,
  105. .subdevice = CIF_SUBDEVICE_DEVICENET,
  106. },
  107. { 0, }
  108. };
  109. static struct pci_driver hilscher_pci_driver = {
  110. .name = "hilscher",
  111. .id_table = hilscher_pci_ids,
  112. .probe = hilscher_pci_probe,
  113. .remove = hilscher_pci_remove,
  114. };
  115. static int __init hilscher_init_module(void)
  116. {
  117. return pci_register_driver(&hilscher_pci_driver);
  118. }
  119. static void __exit hilscher_exit_module(void)
  120. {
  121. pci_unregister_driver(&hilscher_pci_driver);
  122. }
  123. module_init(hilscher_init_module);
  124. module_exit(hilscher_exit_module);
  125. MODULE_DEVICE_TABLE(pci, hilscher_pci_ids);
  126. MODULE_LICENSE("GPL v2");
  127. MODULE_AUTHOR("Hans J. Koch, Benedikt Spranger");