mantis_pci.c 4.1 KB

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