hopper_cards.c 6.8 KB

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