hopper_cards.c 6.1 KB

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