mantis_cards.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. Mantis PCI bridge driver
  4. Copyright (C) Manu Abraham ([email protected])
  5. */
  6. #include <linux/module.h>
  7. #include <linux/kernel.h>
  8. #include <linux/pci.h>
  9. #include <linux/slab.h>
  10. #include <asm/irq.h>
  11. #include <linux/interrupt.h>
  12. #include <media/rc-map.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 "mantis_vp1033.h"
  20. #include "mantis_vp1034.h"
  21. #include "mantis_vp1041.h"
  22. #include "mantis_vp2033.h"
  23. #include "mantis_vp2040.h"
  24. #include "mantis_vp3030.h"
  25. #include "mantis_dma.h"
  26. #include "mantis_ca.h"
  27. #include "mantis_dvb.h"
  28. #include "mantis_uart.h"
  29. #include "mantis_ioc.h"
  30. #include "mantis_pci.h"
  31. #include "mantis_i2c.h"
  32. #include "mantis_reg.h"
  33. #include "mantis_input.h"
  34. static unsigned int verbose;
  35. module_param(verbose, int, 0644);
  36. MODULE_PARM_DESC(verbose, "verbose startup messages, default is 0 (no)");
  37. static int devs;
  38. #define DRIVER_NAME "Mantis"
  39. static char *label[10] = {
  40. "DMA",
  41. "IRQ-0",
  42. "IRQ-1",
  43. "OCERR",
  44. "PABRT",
  45. "RIPRR",
  46. "PPERR",
  47. "FTRGT",
  48. "RISCI",
  49. "RACK"
  50. };
  51. static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
  52. {
  53. u32 stat = 0, mask = 0;
  54. u32 rst_stat = 0, rst_mask = 0;
  55. struct mantis_pci *mantis;
  56. struct mantis_ca *ca;
  57. mantis = (struct mantis_pci *) dev_id;
  58. if (unlikely(!mantis))
  59. return IRQ_NONE;
  60. ca = mantis->mantis_ca;
  61. stat = mmread(MANTIS_INT_STAT);
  62. mask = mmread(MANTIS_INT_MASK);
  63. if (!(stat & mask))
  64. return IRQ_NONE;
  65. rst_mask = MANTIS_GPIF_WRACK |
  66. MANTIS_GPIF_OTHERR |
  67. MANTIS_SBUF_WSTO |
  68. MANTIS_GPIF_EXTIRQ;
  69. rst_stat = mmread(MANTIS_GPIF_STATUS);
  70. rst_stat &= rst_mask;
  71. mmwrite(rst_stat, MANTIS_GPIF_STATUS);
  72. mantis->mantis_int_stat = stat;
  73. mantis->mantis_int_mask = mask;
  74. dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask);
  75. if (stat & MANTIS_INT_RISCEN) {
  76. dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]);
  77. }
  78. if (stat & MANTIS_INT_IRQ0) {
  79. dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]);
  80. mantis->gpif_status = rst_stat;
  81. wake_up(&ca->hif_write_wq);
  82. schedule_work(&ca->hif_evm_work);
  83. }
  84. if (stat & MANTIS_INT_IRQ1) {
  85. dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
  86. spin_lock(&mantis->intmask_lock);
  87. mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1,
  88. MANTIS_INT_MASK);
  89. spin_unlock(&mantis->intmask_lock);
  90. schedule_work(&mantis->uart_work);
  91. }
  92. if (stat & MANTIS_INT_OCERR) {
  93. dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);
  94. }
  95. if (stat & MANTIS_INT_PABORT) {
  96. dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);
  97. }
  98. if (stat & MANTIS_INT_RIPERR) {
  99. dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);
  100. }
  101. if (stat & MANTIS_INT_PPERR) {
  102. dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);
  103. }
  104. if (stat & MANTIS_INT_FTRGT) {
  105. dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);
  106. }
  107. if (stat & MANTIS_INT_RISCI) {
  108. dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
  109. mantis->busy_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
  110. tasklet_schedule(&mantis->tasklet);
  111. }
  112. if (stat & MANTIS_INT_I2CDONE) {
  113. dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);
  114. wake_up(&mantis->i2c_wq);
  115. }
  116. mmwrite(stat, MANTIS_INT_STAT);
  117. stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |
  118. MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |
  119. MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |
  120. MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
  121. MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |
  122. MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |
  123. MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |
  124. MANTIS_INT_PABORT | MANTIS_INT_RIPERR |
  125. MANTIS_INT_PPERR | MANTIS_INT_FTRGT |
  126. MANTIS_INT_RISCI);
  127. if (stat)
  128. dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);
  129. dprintk(MANTIS_DEBUG, 0, "\n");
  130. return IRQ_HANDLED;
  131. }
  132. static int mantis_pci_probe(struct pci_dev *pdev,
  133. const struct pci_device_id *pci_id)
  134. {
  135. struct mantis_pci_drvdata *drvdata;
  136. struct mantis_pci *mantis;
  137. struct mantis_hwconfig *config;
  138. int err;
  139. mantis = kzalloc(sizeof(*mantis), GFP_KERNEL);
  140. if (!mantis)
  141. return -ENOMEM;
  142. drvdata = (void *)pci_id->driver_data;
  143. mantis->num = devs;
  144. mantis->verbose = verbose;
  145. mantis->pdev = pdev;
  146. config = drvdata->hwconfig;
  147. config->irq_handler = &mantis_irq_handler;
  148. mantis->hwconfig = config;
  149. mantis->rc_map_name = drvdata->rc_map_name;
  150. spin_lock_init(&mantis->intmask_lock);
  151. err = mantis_pci_init(mantis);
  152. if (err) {
  153. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
  154. goto err_free_mantis;
  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 err_pci_exit;
  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 err_pci_exit;
  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 err_i2c_exit;
  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 err_i2c_exit;
  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 err_dma_exit;
  180. }
  181. err = mantis_input_init(mantis);
  182. if (err < 0) {
  183. dprintk(MANTIS_ERROR, 1,
  184. "ERROR: Mantis DVB initialization failed <%d>", err);
  185. goto err_dvb_exit;
  186. }
  187. err = mantis_uart_init(mantis);
  188. if (err < 0) {
  189. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
  190. goto err_input_exit;
  191. }
  192. devs++;
  193. return 0;
  194. err_input_exit:
  195. mantis_input_exit(mantis);
  196. err_dvb_exit:
  197. mantis_dvb_exit(mantis);
  198. err_dma_exit:
  199. mantis_dma_exit(mantis);
  200. err_i2c_exit:
  201. mantis_i2c_exit(mantis);
  202. err_pci_exit:
  203. mantis_pci_exit(mantis);
  204. err_free_mantis:
  205. kfree(mantis);
  206. return err;
  207. }
  208. static void mantis_pci_remove(struct pci_dev *pdev)
  209. {
  210. struct mantis_pci *mantis = pci_get_drvdata(pdev);
  211. if (mantis) {
  212. mantis_uart_exit(mantis);
  213. mantis_input_exit(mantis);
  214. mantis_dvb_exit(mantis);
  215. mantis_dma_exit(mantis);
  216. mantis_i2c_exit(mantis);
  217. mantis_pci_exit(mantis);
  218. kfree(mantis);
  219. }
  220. return;
  221. }
  222. static const struct pci_device_id mantis_pci_table[] = {
  223. MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config,
  224. RC_MAP_TECHNISAT_TS35),
  225. MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config,
  226. NULL),
  227. MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config,
  228. NULL),
  229. MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2040_config,
  230. RC_MAP_TERRATEC_CINERGY_C_PCI),
  231. MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config,
  232. RC_MAP_TERRATEC_CINERGY_S2_HD),
  233. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config,
  234. NULL),
  235. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config,
  236. NULL),
  237. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config,
  238. RC_MAP_TWINHAN_DTV_CAB_CI),
  239. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config,
  240. RC_MAP_TWINHAN_DTV_CAB_CI),
  241. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config,
  242. NULL),
  243. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config,
  244. NULL),
  245. { }
  246. };
  247. MODULE_DEVICE_TABLE(pci, mantis_pci_table);
  248. static struct pci_driver mantis_pci_driver = {
  249. .name = DRIVER_NAME,
  250. .id_table = mantis_pci_table,
  251. .probe = mantis_pci_probe,
  252. .remove = mantis_pci_remove,
  253. };
  254. module_pci_driver(mantis_pci_driver);
  255. MODULE_DESCRIPTION("MANTIS driver");
  256. MODULE_AUTHOR("Manu Abraham");
  257. MODULE_LICENSE("GPL");