mantis_cards.c 7.8 KB

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