hopper_cards.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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;
  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. 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. spin_lock(&mantis->intmask_lock);
  92. mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1,
  93. MANTIS_INT_MASK);
  94. spin_unlock(&mantis->intmask_lock);
  95. schedule_work(&mantis->uart_work);
  96. }
  97. if (stat & MANTIS_INT_OCERR) {
  98. dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);
  99. }
  100. if (stat & MANTIS_INT_PABORT) {
  101. dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);
  102. }
  103. if (stat & MANTIS_INT_RIPERR) {
  104. dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);
  105. }
  106. if (stat & MANTIS_INT_PPERR) {
  107. dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);
  108. }
  109. if (stat & MANTIS_INT_FTRGT) {
  110. dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);
  111. }
  112. if (stat & MANTIS_INT_RISCI) {
  113. dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
  114. mantis->busy_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
  115. tasklet_schedule(&mantis->tasklet);
  116. }
  117. if (stat & MANTIS_INT_I2CDONE) {
  118. dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);
  119. wake_up(&mantis->i2c_wq);
  120. }
  121. mmwrite(stat, MANTIS_INT_STAT);
  122. stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |
  123. MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |
  124. MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |
  125. MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
  126. MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |
  127. MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |
  128. MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |
  129. MANTIS_INT_PABORT | MANTIS_INT_RIPERR |
  130. MANTIS_INT_PPERR | MANTIS_INT_FTRGT |
  131. MANTIS_INT_RISCI);
  132. if (stat)
  133. dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);
  134. dprintk(MANTIS_DEBUG, 0, "\n");
  135. return IRQ_HANDLED;
  136. }
  137. static int hopper_pci_probe(struct pci_dev *pdev,
  138. const struct pci_device_id *pci_id)
  139. {
  140. struct mantis_pci_drvdata *drvdata;
  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. drvdata = (void *)pci_id->driver_data;
  151. mantis->num = devs;
  152. mantis->verbose = verbose;
  153. mantis->pdev = pdev;
  154. config = drvdata->hwconfig;
  155. config->irq_handler = &hopper_irq_handler;
  156. mantis->hwconfig = config;
  157. mantis->rc_map_name = drvdata->rc_map_name;
  158. spin_lock_init(&mantis->intmask_lock);
  159. err = mantis_pci_init(mantis);
  160. if (err) {
  161. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
  162. goto fail1;
  163. }
  164. err = mantis_stream_control(mantis, STREAM_TO_HIF);
  165. if (err < 0) {
  166. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
  167. goto fail1;
  168. }
  169. err = mantis_i2c_init(mantis);
  170. if (err < 0) {
  171. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
  172. goto fail2;
  173. }
  174. err = mantis_get_mac(mantis);
  175. if (err < 0) {
  176. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
  177. goto fail2;
  178. }
  179. err = mantis_dma_init(mantis);
  180. if (err < 0) {
  181. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
  182. goto fail3;
  183. }
  184. err = mantis_dvb_init(mantis);
  185. if (err < 0) {
  186. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
  187. goto fail4;
  188. }
  189. devs++;
  190. return err;
  191. fail4:
  192. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
  193. mantis_dma_exit(mantis);
  194. fail3:
  195. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
  196. mantis_i2c_exit(mantis);
  197. fail2:
  198. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
  199. mantis_pci_exit(mantis);
  200. fail1:
  201. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
  202. kfree(mantis);
  203. fail0:
  204. return err;
  205. }
  206. static void hopper_pci_remove(struct pci_dev *pdev)
  207. {
  208. struct mantis_pci *mantis = pci_get_drvdata(pdev);
  209. if (mantis) {
  210. mantis_dvb_exit(mantis);
  211. mantis_dma_exit(mantis);
  212. mantis_i2c_exit(mantis);
  213. mantis_pci_exit(mantis);
  214. kfree(mantis);
  215. }
  216. return;
  217. }
  218. static struct pci_device_id hopper_pci_table[] = {
  219. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config,
  220. NULL),
  221. { }
  222. };
  223. MODULE_DEVICE_TABLE(pci, hopper_pci_table);
  224. static struct pci_driver hopper_pci_driver = {
  225. .name = DRIVER_NAME,
  226. .id_table = hopper_pci_table,
  227. .probe = hopper_pci_probe,
  228. .remove = hopper_pci_remove,
  229. };
  230. module_pci_driver(hopper_pci_driver);
  231. MODULE_DESCRIPTION("HOPPER driver");
  232. MODULE_AUTHOR("Manu Abraham");
  233. MODULE_LICENSE("GPL");