mantis_cards.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #include <linux/module.h>
  2. #include <linux/moduleparam.h>
  3. #include <linux/kernel.h>
  4. #include <linux/pci.h>
  5. #include <asm/irq.h>
  6. #include <linux/interrupt.h>
  7. #include "dmxdev.h"
  8. #include "dvbdev.h"
  9. #include "dvb_demux.h"
  10. #include "dvb_frontend.h"
  11. #include "dvb_net.h"
  12. #include "mantis_common.h"
  13. #include "mantis_vp1033.h"
  14. #include "mantis_vp1034.h"
  15. #include "mantis_vp1041.h"
  16. #include "mantis_vp2033.h"
  17. #include "mantis_vp2040.h"
  18. #include "mantis_vp3030.h"
  19. #include "mantis_dma.h"
  20. #include "mantis_ca.h"
  21. #include "mantis_dvb.h"
  22. #include "mantis_uart.h"
  23. #include "mantis_ioc.h"
  24. #include "mantis_pci.h"
  25. #include "mantis_i2c.h"
  26. #include "mantis_reg.h"
  27. static unsigned int verbose;
  28. module_param(verbose, int, 0644);
  29. MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
  30. static int devs;
  31. #define DRIVER_NAME "Mantis"
  32. static char *label[10] = {
  33. "DMA",
  34. "IRQ-0",
  35. "IRQ-1",
  36. "OCERR",
  37. "PABRT",
  38. "RIPRR",
  39. "PPERR",
  40. "FTRGT",
  41. "RISCI",
  42. "RACK"
  43. };
  44. static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
  45. {
  46. u32 stat = 0, mask = 0, lstat = 0, mstat = 0;
  47. u32 rst_stat = 0, rst_mask = 0;
  48. struct mantis_pci *mantis;
  49. struct mantis_ca *ca;
  50. mantis = (struct mantis_pci *) dev_id;
  51. if (unlikely(mantis == NULL)) {
  52. dprintk(MANTIS_ERROR, 1, "Mantis == NULL");
  53. return IRQ_NONE;
  54. }
  55. ca = mantis->mantis_ca;
  56. stat = mmread(MANTIS_INT_STAT);
  57. mask = mmread(MANTIS_INT_MASK);
  58. mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;
  59. if (!(stat & mask))
  60. return IRQ_NONE;
  61. rst_mask = MANTIS_GPIF_WRACK |
  62. MANTIS_GPIF_OTHERR |
  63. MANTIS_SBUF_WSTO |
  64. MANTIS_GPIF_EXTIRQ;
  65. rst_stat = mmread(MANTIS_GPIF_STATUS);
  66. rst_stat &= rst_mask;
  67. mmwrite(rst_stat, MANTIS_GPIF_STATUS);
  68. mantis->mantis_int_stat = stat;
  69. mantis->mantis_int_mask = mask;
  70. dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask);
  71. if (stat & MANTIS_INT_RISCEN) {
  72. dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]);
  73. }
  74. if (stat & MANTIS_INT_IRQ0) {
  75. dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]);
  76. mantis->gpif_status = rst_stat;
  77. wake_up(&ca->hif_write_wq);
  78. schedule_work(&ca->hif_evm_work);
  79. }
  80. if (stat & MANTIS_INT_IRQ1) {
  81. dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
  82. schedule_work(&mantis->uart_work);
  83. }
  84. if (stat & MANTIS_INT_OCERR) {
  85. dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);
  86. }
  87. if (stat & MANTIS_INT_PABORT) {
  88. dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);
  89. }
  90. if (stat & MANTIS_INT_RIPERR) {
  91. dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);
  92. }
  93. if (stat & MANTIS_INT_PPERR) {
  94. dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);
  95. }
  96. if (stat & MANTIS_INT_FTRGT) {
  97. dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);
  98. }
  99. if (stat & MANTIS_INT_RISCI) {
  100. dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
  101. mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
  102. tasklet_schedule(&mantis->tasklet);
  103. }
  104. if (stat & MANTIS_INT_I2CDONE) {
  105. dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);
  106. wake_up(&mantis->i2c_wq);
  107. }
  108. mmwrite(stat, MANTIS_INT_STAT);
  109. stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |
  110. MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |
  111. MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |
  112. MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
  113. MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |
  114. MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |
  115. MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |
  116. MANTIS_INT_PABORT | MANTIS_INT_RIPERR |
  117. MANTIS_INT_PPERR | MANTIS_INT_FTRGT |
  118. MANTIS_INT_RISCI);
  119. if (stat)
  120. dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);
  121. dprintk(MANTIS_DEBUG, 0, "\n");
  122. return IRQ_HANDLED;
  123. }
  124. static int __devinit mantis_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
  125. {
  126. struct mantis_pci *mantis;
  127. struct mantis_hwconfig *config;
  128. int err = 0;
  129. mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL);
  130. if (mantis == NULL) {
  131. printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
  132. err = -ENOMEM;
  133. goto fail0;
  134. }
  135. mantis->num = devs;
  136. mantis->verbose = verbose;
  137. mantis->pdev = pdev;
  138. config = (struct mantis_hwconfig *) pci_id->driver_data;
  139. config->irq_handler = &mantis_irq_handler;
  140. mantis->hwconfig = config;
  141. err = mantis_pci_init(mantis);
  142. if (err) {
  143. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
  144. goto fail1;
  145. }
  146. err = mantis_stream_control(mantis, STREAM_TO_HIF);
  147. if (err < 0) {
  148. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
  149. goto fail1;
  150. }
  151. err = mantis_i2c_init(mantis);
  152. if (err < 0) {
  153. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
  154. goto fail2;
  155. }
  156. err = mantis_get_mac(mantis);
  157. if (err < 0) {
  158. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
  159. goto fail2;
  160. }
  161. err = mantis_dma_init(mantis);
  162. if (err < 0) {
  163. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
  164. goto fail3;
  165. }
  166. err = mantis_dvb_init(mantis);
  167. if (err < 0) {
  168. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
  169. goto fail4;
  170. }
  171. err = mantis_uart_init(mantis);
  172. if (err < 0) {
  173. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
  174. goto fail6;
  175. }
  176. devs++;
  177. return err;
  178. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err);
  179. mantis_uart_exit(mantis);
  180. fail6:
  181. fail4:
  182. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
  183. mantis_dma_exit(mantis);
  184. fail3:
  185. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
  186. mantis_i2c_exit(mantis);
  187. fail2:
  188. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
  189. mantis_pci_exit(mantis);
  190. fail1:
  191. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
  192. kfree(mantis);
  193. fail0:
  194. return err;
  195. }
  196. static void __devexit mantis_pci_remove(struct pci_dev *pdev)
  197. {
  198. struct mantis_pci *mantis = pci_get_drvdata(pdev);
  199. if (mantis) {
  200. mantis_uart_exit(mantis);
  201. mantis_dvb_exit(mantis);
  202. mantis_dma_exit(mantis);
  203. mantis_i2c_exit(mantis);
  204. mantis_pci_exit(mantis);
  205. kfree(mantis);
  206. }
  207. return;
  208. }
  209. static struct pci_device_id mantis_pci_table[] = {
  210. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config),
  211. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config),
  212. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config),
  213. MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config),
  214. MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config),
  215. MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config),
  216. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config),
  217. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config),
  218. MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config),
  219. MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2033_config),
  220. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config),
  221. { }
  222. };
  223. static struct pci_driver mantis_pci_driver = {
  224. .name = DRIVER_NAME,
  225. .id_table = mantis_pci_table,
  226. .probe = mantis_pci_probe,
  227. .remove = mantis_pci_remove,
  228. };
  229. static int __devinit mantis_init(void)
  230. {
  231. return pci_register_driver(&mantis_pci_driver);
  232. }
  233. static void __devexit mantis_exit(void)
  234. {
  235. return pci_unregister_driver(&mantis_pci_driver);
  236. }
  237. module_init(mantis_init);
  238. module_exit(mantis_exit);
  239. MODULE_DESCRIPTION("MANTIS driver");
  240. MODULE_AUTHOR("Manu Abraham");
  241. MODULE_LICENSE("GPL");