mantis_pci.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 "mantis_common.h"
  37. #include "mantis_reg.h"
  38. #include "mantis_pci.h"
  39. #define DRIVER_NAME "Mantis Core"
  40. int __devinit mantis_pci_init(struct mantis_pci *mantis)
  41. {
  42. u8 revision, latency;
  43. struct mantis_hwconfig *config = mantis->hwconfig;
  44. struct pci_dev *pdev = mantis->pdev;
  45. int err, ret = 0;
  46. dprintk(MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",
  47. config->model_name,
  48. config->dev_type,
  49. mantis->pdev->bus->number,
  50. PCI_SLOT(mantis->pdev->devfn),
  51. PCI_FUNC(mantis->pdev->devfn));
  52. err = pci_enable_device(pdev);
  53. if (err != 0) {
  54. ret = -ENODEV;
  55. dprintk(MANTIS_ERROR, 1, "ERROR: PCI enable failed <%i>", err);
  56. goto fail0;
  57. }
  58. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  59. if (err != 0) {
  60. dprintk(MANTIS_ERROR, 1, "ERROR: Unable to obtain 32 bit DMA <%i>", err);
  61. ret = -ENOMEM;
  62. goto fail1;
  63. }
  64. pci_set_master(pdev);
  65. if (!request_mem_region(pci_resource_start(pdev, 0),
  66. pci_resource_len(pdev, 0),
  67. DRIVER_NAME)) {
  68. dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 Request failed !");
  69. ret = -ENODEV;
  70. goto fail1;
  71. }
  72. mantis->mmio = ioremap(pci_resource_start(pdev, 0),
  73. pci_resource_len(pdev, 0));
  74. if (!mantis->mmio) {
  75. dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 remap failed !");
  76. ret = -ENODEV;
  77. goto fail2;
  78. }
  79. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
  80. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  81. mantis->latency = latency;
  82. mantis->revision = revision;
  83. dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ",
  84. mantis->revision,
  85. mantis->pdev->subsystem_vendor,
  86. mantis->pdev->subsystem_device);
  87. dprintk(MANTIS_ERROR, 0,
  88. "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
  89. mantis->pdev->irq,
  90. mantis->latency,
  91. mantis->mantis_addr,
  92. mantis->mmio);
  93. err = request_irq(pdev->irq,
  94. config->irq_handler,
  95. IRQF_SHARED,
  96. DRIVER_NAME,
  97. mantis);
  98. if (err != 0) {
  99. dprintk(MANTIS_ERROR, 1, "ERROR: IRQ registration failed ! <%d>", err);
  100. ret = -ENODEV;
  101. goto fail3;
  102. }
  103. pci_set_drvdata(pdev, mantis);
  104. return ret;
  105. /* Error conditions */
  106. fail3:
  107. dprintk(MANTIS_ERROR, 1, "ERROR: <%d> I/O unmap", ret);
  108. if (mantis->mmio)
  109. iounmap(mantis->mmio);
  110. fail2:
  111. dprintk(MANTIS_ERROR, 1, "ERROR: <%d> releasing regions", ret);
  112. release_mem_region(pci_resource_start(pdev, 0),
  113. pci_resource_len(pdev, 0));
  114. fail1:
  115. dprintk(MANTIS_ERROR, 1, "ERROR: <%d> disabling device", ret);
  116. pci_disable_device(pdev);
  117. fail0:
  118. dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret);
  119. pci_set_drvdata(pdev, NULL);
  120. return ret;
  121. }
  122. EXPORT_SYMBOL_GPL(mantis_pci_init);
  123. void mantis_pci_exit(struct mantis_pci *mantis)
  124. {
  125. struct pci_dev *pdev = mantis->pdev;
  126. dprintk(MANTIS_NOTICE, 1, " mem: 0x%p", mantis->mmio);
  127. free_irq(pdev->irq, mantis);
  128. if (mantis->mmio) {
  129. iounmap(mantis->mmio);
  130. release_mem_region(pci_resource_start(pdev, 0),
  131. pci_resource_len(pdev, 0));
  132. }
  133. pci_disable_device(pdev);
  134. pci_set_drvdata(pdev, NULL);
  135. }
  136. EXPORT_SYMBOL_GPL(mantis_pci_exit);
  137. MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");
  138. MODULE_AUTHOR("Manu Abraham");
  139. MODULE_LICENSE("GPL");