mantis_pci.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. Mantis PCI bridge driver
  3. Copyright (C) Manu Abraham (abraham.manu@gmail.com)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/moduleparam.h>
  18. #include <linux/kernel.h>
  19. #include <asm/io.h>
  20. #include <asm/pgtable.h>
  21. #include <asm/page.h>
  22. #include <linux/kmod.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/init.h>
  25. #include <linux/device.h>
  26. #include <linux/pci.h>
  27. #include <asm/irq.h>
  28. #include <linux/signal.h>
  29. #include <linux/sched.h>
  30. #include <linux/interrupt.h>
  31. #include "dmxdev.h"
  32. #include "dvbdev.h"
  33. #include "dvb_demux.h"
  34. #include "dvb_frontend.h"
  35. #include "dvb_net.h"
  36. #include <asm/irq.h>
  37. #include <linux/signal.h>
  38. #include <linux/sched.h>
  39. #include <linux/interrupt.h>
  40. #include "mantis_common.h"
  41. #include "mantis_reg.h"
  42. #include "mantis_pci.h"
  43. #define DRIVER_NAME "Mantis Core"
  44. int __devinit mantis_pci_init(struct mantis_pci *mantis)
  45. {
  46. u8 revision, latency;
  47. struct mantis_hwconfig *config = mantis->hwconfig;
  48. struct pci_dev *pdev = mantis->pdev;
  49. int err, ret = 0;
  50. dprintk(MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",
  51. config->model_name,
  52. config->dev_type,
  53. mantis->pdev->bus->number,
  54. PCI_SLOT(mantis->pdev->devfn),
  55. PCI_FUNC(mantis->pdev->devfn));
  56. err = pci_enable_device(pdev);
  57. if (err != 0) {
  58. ret = -ENODEV;
  59. dprintk(MANTIS_ERROR, 1, "ERROR: PCI enable failed <%i>", err);
  60. goto fail0;
  61. }
  62. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  63. if (err != 0) {
  64. dprintk(MANTIS_ERROR, 1, "ERROR: Unable to obtain 32 bit DMA <%i>", err);
  65. ret = -ENOMEM;
  66. goto fail1;
  67. }
  68. pci_set_master(pdev);
  69. if (!request_mem_region(pci_resource_start(pdev, 0),
  70. pci_resource_len(pdev, 0),
  71. DRIVER_NAME)) {
  72. dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 Request failed !");
  73. ret = -ENODEV;
  74. goto fail1;
  75. }
  76. mantis->mmio = ioremap(pci_resource_start(pdev, 0),
  77. pci_resource_len(pdev, 0));
  78. if (!mantis->mmio) {
  79. dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 remap failed !");
  80. ret = -ENODEV;
  81. goto fail2;
  82. }
  83. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
  84. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  85. mantis->latency = latency;
  86. mantis->revision = revision;
  87. dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ",
  88. mantis->revision,
  89. mantis->pdev->subsystem_vendor,
  90. mantis->pdev->subsystem_device);
  91. dprintk(MANTIS_ERROR, 0,
  92. "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
  93. mantis->pdev->irq,
  94. mantis->latency,
  95. mantis->mantis_addr,
  96. mantis->mmio);
  97. err = request_irq(pdev->irq,
  98. config->irq_handler,
  99. IRQF_SHARED,
  100. DRIVER_NAME,
  101. mantis);
  102. if (err != 0) {
  103. dprintk(MANTIS_ERROR, 1, "ERROR: IRQ registration failed ! <%d>", err);
  104. ret = -ENODEV;
  105. goto fail3;
  106. }
  107. pci_set_drvdata(pdev, mantis);
  108. return ret;
  109. /* Error conditions */
  110. fail3:
  111. dprintk(MANTIS_ERROR, 1, "ERROR: <%d> I/O unmap", ret);
  112. if (mantis->mmio)
  113. iounmap(mantis->mmio);
  114. fail2:
  115. dprintk(MANTIS_ERROR, 1, "ERROR: <%d> releasing regions", ret);
  116. release_mem_region(pci_resource_start(pdev, 0),
  117. pci_resource_len(pdev, 0));
  118. fail1:
  119. dprintk(MANTIS_ERROR, 1, "ERROR: <%d> disabling device", ret);
  120. pci_disable_device(pdev);
  121. fail0:
  122. dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret);
  123. pci_set_drvdata(pdev, NULL);
  124. return ret;
  125. }
  126. EXPORT_SYMBOL_GPL(mantis_pci_init);
  127. void __devexit mantis_pci_exit(struct mantis_pci *mantis)
  128. {
  129. struct pci_dev *pdev = mantis->pdev;
  130. dprintk(MANTIS_NOTICE, 1, " mem: 0x%p", mantis->mmio);
  131. free_irq(pdev->irq, mantis);
  132. if (mantis->mmio) {
  133. iounmap(mantis->mmio);
  134. release_mem_region(pci_resource_start(pdev, 0),
  135. pci_resource_len(pdev, 0));
  136. }
  137. pci_disable_device(pdev);
  138. pci_set_drvdata(pdev, NULL);
  139. }
  140. EXPORT_SYMBOL_GPL(mantis_pci_exit);
  141. MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");
  142. MODULE_AUTHOR("Manu Abraham");
  143. MODULE_LICENSE("GPL");