hopper_cards.c 6.1 KB

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