mantis_cards.c 8.1 KB

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