hopper_cards.c 6.8 KB

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