mantis_cards.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 "dmxdev.h"
  25. #include "dvbdev.h"
  26. #include "dvb_demux.h"
  27. #include "dvb_frontend.h"
  28. #include "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 = 0;
  152. mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL);
  153. if (mantis == NULL) {
  154. printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
  155. return -ENOMEM;
  156. }
  157. drvdata = (void *)pci_id->driver_data;
  158. mantis->num = devs;
  159. mantis->verbose = verbose;
  160. mantis->pdev = pdev;
  161. config = drvdata->hwconfig;
  162. config->irq_handler = &mantis_irq_handler;
  163. mantis->hwconfig = config;
  164. mantis->rc_map_name = drvdata->rc_map_name;
  165. spin_lock_init(&mantis->intmask_lock);
  166. err = mantis_pci_init(mantis);
  167. if (err) {
  168. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
  169. goto err_free_mantis;
  170. }
  171. err = mantis_stream_control(mantis, STREAM_TO_HIF);
  172. if (err < 0) {
  173. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
  174. goto err_pci_exit;
  175. }
  176. err = mantis_i2c_init(mantis);
  177. if (err < 0) {
  178. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
  179. goto err_pci_exit;
  180. }
  181. err = mantis_get_mac(mantis);
  182. if (err < 0) {
  183. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
  184. goto err_i2c_exit;
  185. }
  186. err = mantis_dma_init(mantis);
  187. if (err < 0) {
  188. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
  189. goto err_i2c_exit;
  190. }
  191. err = mantis_dvb_init(mantis);
  192. if (err < 0) {
  193. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
  194. goto err_dma_exit;
  195. }
  196. err = mantis_input_init(mantis);
  197. if (err < 0) {
  198. dprintk(MANTIS_ERROR, 1,
  199. "ERROR: Mantis DVB initialization failed <%d>", err);
  200. goto err_dvb_exit;
  201. }
  202. err = mantis_uart_init(mantis);
  203. if (err < 0) {
  204. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
  205. goto err_input_exit;
  206. }
  207. devs++;
  208. return 0;
  209. err_input_exit:
  210. mantis_input_exit(mantis);
  211. err_dvb_exit:
  212. mantis_dvb_exit(mantis);
  213. err_dma_exit:
  214. mantis_dma_exit(mantis);
  215. err_i2c_exit:
  216. mantis_i2c_exit(mantis);
  217. err_pci_exit:
  218. mantis_pci_exit(mantis);
  219. err_free_mantis:
  220. kfree(mantis);
  221. return err;
  222. }
  223. static void mantis_pci_remove(struct pci_dev *pdev)
  224. {
  225. struct mantis_pci *mantis = pci_get_drvdata(pdev);
  226. if (mantis) {
  227. mantis_uart_exit(mantis);
  228. mantis_input_exit(mantis);
  229. mantis_dvb_exit(mantis);
  230. mantis_dma_exit(mantis);
  231. mantis_i2c_exit(mantis);
  232. mantis_pci_exit(mantis);
  233. kfree(mantis);
  234. }
  235. return;
  236. }
  237. static struct pci_device_id mantis_pci_table[] = {
  238. MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config,
  239. RC_MAP_TECHNISAT_TS35),
  240. MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config,
  241. NULL),
  242. MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config,
  243. NULL),
  244. MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2040_config,
  245. RC_MAP_TERRATEC_CINERGY_C_PCI),
  246. MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config,
  247. RC_MAP_TERRATEC_CINERGY_S2_HD),
  248. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config,
  249. NULL),
  250. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config,
  251. NULL),
  252. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config,
  253. RC_MAP_TWINHAN_DTV_CAB_CI),
  254. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config,
  255. RC_MAP_TWINHAN_DTV_CAB_CI),
  256. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config,
  257. NULL),
  258. MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config,
  259. NULL),
  260. { }
  261. };
  262. MODULE_DEVICE_TABLE(pci, mantis_pci_table);
  263. static struct pci_driver mantis_pci_driver = {
  264. .name = DRIVER_NAME,
  265. .id_table = mantis_pci_table,
  266. .probe = mantis_pci_probe,
  267. .remove = mantis_pci_remove,
  268. };
  269. module_pci_driver(mantis_pci_driver);
  270. MODULE_DESCRIPTION("MANTIS driver");
  271. MODULE_AUTHOR("Manu Abraham");
  272. MODULE_LICENSE("GPL");