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 <media/dmxdev.h>
  24. #include <media/dvbdev.h>
  25. #include <media/dvb_demux.h>
  26. #include <media/dvb_frontend.h>
  27. #include <media/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)) {
  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;
  144. mantis = kzalloc(sizeof(*mantis), GFP_KERNEL);
  145. if (!mantis) {
  146. err = -ENOMEM;
  147. goto fail0;
  148. }
  149. drvdata = (void *)pci_id->driver_data;
  150. mantis->num = devs;
  151. mantis->verbose = verbose;
  152. mantis->pdev = pdev;
  153. config = drvdata->hwconfig;
  154. config->irq_handler = &hopper_irq_handler;
  155. mantis->hwconfig = config;
  156. mantis->rc_map_name = drvdata->rc_map_name;
  157. spin_lock_init(&mantis->intmask_lock);
  158. err = mantis_pci_init(mantis);
  159. if (err) {
  160. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
  161. goto fail1;
  162. }
  163. err = mantis_stream_control(mantis, STREAM_TO_HIF);
  164. if (err < 0) {
  165. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
  166. goto fail1;
  167. }
  168. err = mantis_i2c_init(mantis);
  169. if (err < 0) {
  170. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
  171. goto fail2;
  172. }
  173. err = mantis_get_mac(mantis);
  174. if (err < 0) {
  175. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
  176. goto fail2;
  177. }
  178. err = mantis_dma_init(mantis);
  179. if (err < 0) {
  180. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
  181. goto fail3;
  182. }
  183. err = mantis_dvb_init(mantis);
  184. if (err < 0) {
  185. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
  186. goto fail4;
  187. }
  188. devs++;
  189. return err;
  190. fail4:
  191. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
  192. mantis_dma_exit(mantis);
  193. fail3:
  194. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
  195. mantis_i2c_exit(mantis);
  196. fail2:
  197. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
  198. mantis_pci_exit(mantis);
  199. fail1:
  200. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
  201. kfree(mantis);
  202. fail0:
  203. return err;
  204. }
  205. static void hopper_pci_remove(struct pci_dev *pdev)
  206. {
  207. struct mantis_pci *mantis = pci_get_drvdata(pdev);
  208. if (mantis) {
  209. mantis_dvb_exit(mantis);
  210. mantis_dma_exit(mantis);
  211. mantis_i2c_exit(mantis);
  212. mantis_pci_exit(mantis);
  213. kfree(mantis);
  214. }
  215. return;
  216. }
  217. static const struct pci_device_id hopper_pci_table[] = {
  218. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config,
  219. NULL),
  220. { }
  221. };
  222. MODULE_DEVICE_TABLE(pci, hopper_pci_table);
  223. static struct pci_driver hopper_pci_driver = {
  224. .name = DRIVER_NAME,
  225. .id_table = hopper_pci_table,
  226. .probe = hopper_pci_probe,
  227. .remove = hopper_pci_remove,
  228. };
  229. module_pci_driver(hopper_pci_driver);
  230. MODULE_DESCRIPTION("HOPPER driver");
  231. MODULE_AUTHOR("Manu Abraham");
  232. MODULE_LICENSE("GPL");