mantis_dvb.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. Mantis PCI bridge driver
  3. Copyright (C) 2005, 2006 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/bitops.h>
  17. #include "mantis_common.h"
  18. #include "mantis_core.h"
  19. #include "dmxdev.h"
  20. #include "dvbdev.h"
  21. #include "dvb_demux.h"
  22. #include "dvb_frontend.h"
  23. #include "mantis_vp1033.h"
  24. #include "mantis_vp1034.h"
  25. #include "mantis_vp2033.h"
  26. #include "mantis_vp2040.h"
  27. #include "mantis_vp3030.h"
  28. /* Tuner power supply control */
  29. void mantis_fe_powerup(struct mantis_pci *mantis)
  30. {
  31. dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Power ON");
  32. gpio_set_bits(mantis, 0x0c, 1);
  33. msleep_interruptible(100);
  34. gpio_set_bits(mantis, 0x0c, 1);
  35. msleep_interruptible(100);
  36. }
  37. void mantis_fe_powerdown(struct mantis_pci *mantis)
  38. {
  39. dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Power OFF");
  40. gpio_set_bits(mantis, 0x0c, 0);
  41. }
  42. static int mantis_fe_reset(struct dvb_frontend *fe)
  43. {
  44. struct mantis_pci *mantis = fe->dvb->priv;
  45. dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Reset");
  46. gpio_set_bits(mantis, 13, 0);
  47. msleep_interruptible(100);
  48. gpio_set_bits(mantis, 13, 0);
  49. msleep_interruptible(100);
  50. gpio_set_bits(mantis, 13, 1);
  51. msleep_interruptible(100);
  52. gpio_set_bits(mantis, 13, 1);
  53. return 0;
  54. }
  55. static int mantis_frontend_reset(struct mantis_pci *mantis)
  56. {
  57. dprintk(verbose, MANTIS_DEBUG, 1, "Frontend Reset");
  58. gpio_set_bits(mantis, 13, 0);
  59. msleep_interruptible(100);
  60. gpio_set_bits(mantis, 13, 0);
  61. msleep_interruptible(100);
  62. gpio_set_bits(mantis, 13, 1);
  63. msleep_interruptible(100);
  64. gpio_set_bits(mantis, 13, 1);
  65. return 0;
  66. }
  67. static int mantis_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
  68. {
  69. struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
  70. struct mantis_pci *mantis = dvbdmx->priv;
  71. dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB Start feed");
  72. if (!dvbdmx->dmx.frontend) {
  73. dprintk(verbose, MANTIS_DEBUG, 1, "no frontend ?");
  74. return -EINVAL;
  75. }
  76. mantis->feeds++;
  77. dprintk(verbose, MANTIS_DEBUG, 1,
  78. "mantis start feed, feeds=%d",
  79. mantis->feeds);
  80. if (mantis->feeds == 1) {
  81. dprintk(verbose, MANTIS_DEBUG, 1, "mantis start feed & dma");
  82. printk("mantis start feed & dma\n");
  83. mantis_dma_start(mantis);
  84. }
  85. return mantis->feeds;
  86. }
  87. static int mantis_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
  88. {
  89. struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
  90. struct mantis_pci *mantis = dvbdmx->priv;
  91. dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB Stop feed");
  92. if (!dvbdmx->dmx.frontend) {
  93. dprintk(verbose, MANTIS_DEBUG, 1, "no frontend ?");
  94. return -EINVAL;
  95. }
  96. mantis->feeds--;
  97. if (mantis->feeds == 0) {
  98. dprintk(verbose, MANTIS_DEBUG, 1, "mantis stop feed and dma");
  99. printk("mantis stop feed and dma\n");
  100. mantis_dma_stop(mantis);
  101. }
  102. return 0;
  103. }
  104. int __devinit mantis_dvb_init(struct mantis_pci *mantis)
  105. {
  106. int result;
  107. dprintk(verbose, MANTIS_DEBUG, 1, "dvb_register_adapter");
  108. if (dvb_register_adapter(&mantis->dvb_adapter,
  109. "Mantis dvb adapter", THIS_MODULE,
  110. &mantis->pdev->dev) < 0) {
  111. dprintk(verbose, MANTIS_ERROR, 1, "Error registering adapter");
  112. return -ENODEV;
  113. }
  114. mantis->dvb_adapter.priv = mantis;
  115. mantis->demux.dmx.capabilities = DMX_TS_FILTERING |
  116. DMX_SECTION_FILTERING |
  117. DMX_MEMORY_BASED_FILTERING;
  118. mantis->demux.priv = mantis;
  119. mantis->demux.filternum = 256;
  120. mantis->demux.feednum = 256;
  121. mantis->demux.start_feed = mantis_dvb_start_feed;
  122. mantis->demux.stop_feed = mantis_dvb_stop_feed;
  123. mantis->demux.write_to_decoder = NULL;
  124. dprintk(verbose, MANTIS_DEBUG, 1, "dvb_dmx_init");
  125. if ((result = dvb_dmx_init(&mantis->demux)) < 0) {
  126. dprintk(verbose, MANTIS_ERROR, 1,
  127. "dvb_dmx_init failed, ERROR=%d", result);
  128. goto err0;
  129. }
  130. mantis->dmxdev.filternum = 256;
  131. mantis->dmxdev.demux = &mantis->demux.dmx;
  132. mantis->dmxdev.capabilities = 0;
  133. dprintk(verbose, MANTIS_DEBUG, 1, "dvb_dmxdev_init");
  134. if ((result = dvb_dmxdev_init(&mantis->dmxdev,
  135. &mantis->dvb_adapter)) < 0) {
  136. dprintk(verbose, MANTIS_ERROR, 1,
  137. "dvb_dmxdev_init failed, ERROR=%d", result);
  138. goto err1;
  139. }
  140. mantis->fe_hw.source = DMX_FRONTEND_0;
  141. if ((result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx,
  142. &mantis->fe_hw)) < 0) {
  143. dprintk(verbose, MANTIS_ERROR, 1,
  144. "dvb_dmx_init failed, ERROR=%d", result);
  145. goto err2;
  146. }
  147. mantis->fe_mem.source = DMX_MEMORY_FE;
  148. if ((result = mantis->demux.dmx.add_frontend(&mantis->demux.dmx,
  149. &mantis->fe_mem)) < 0) {
  150. dprintk(verbose, MANTIS_ERROR, 1,
  151. "dvb_dmx_init failed, ERROR=%d", result);
  152. goto err3;
  153. }
  154. if ((result = mantis->demux.dmx.connect_frontend(&mantis->demux.dmx,
  155. &mantis->fe_hw)) < 0) {
  156. dprintk(verbose, MANTIS_ERROR, 1,
  157. "dvb_dmx_init failed, ERROR=%d", result);
  158. goto err4;
  159. }
  160. dvb_net_init(&mantis->dvb_adapter, &mantis->dvbnet, &mantis->demux.dmx);
  161. tasklet_init(&mantis->tasklet, mantis_dma_xfer, (unsigned long) mantis);
  162. mantis_frontend_init(mantis);
  163. return 0;
  164. /* Error conditions .. */
  165. err4:
  166. mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_mem);
  167. err3:
  168. mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_hw);
  169. err2:
  170. dvb_dmxdev_release(&mantis->dmxdev);
  171. err1:
  172. dvb_dmx_release(&mantis->demux);
  173. err0:
  174. dvb_unregister_adapter(&mantis->dvb_adapter);
  175. return result;
  176. }
  177. int __devinit mantis_frontend_init(struct mantis_pci *mantis)
  178. {
  179. dprintk(verbose, MANTIS_DEBUG, 1, "Mantis frontend Init");
  180. mantis_fe_powerup(mantis);
  181. mantis_frontend_reset(mantis);
  182. dprintk(verbose, MANTIS_DEBUG, 1, "Device ID=%02x", mantis->subsystem_device);
  183. switch (mantis->subsystem_device) {
  184. case MANTIS_VP_1033_DVB_S: // VP-1033
  185. dprintk(verbose, MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)");
  186. mantis->fe = stv0299_attach(&lgtdqcs001f_config,
  187. &mantis->adapter);
  188. if (mantis->fe) {
  189. mantis->fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set;
  190. dprintk(verbose, MANTIS_ERROR, 1,
  191. "found STV0299 DVB-S frontend @ 0x%02x",
  192. lgtdqcs001f_config.demod_address);
  193. dprintk(verbose, MANTIS_ERROR, 1,
  194. "Mantis DVB-S STV0299 frontend attach success");
  195. }
  196. break;
  197. case MANTIS_VP_1034_DVB_S: // VP-1034
  198. dprintk(verbose, MANTIS_ERROR, 1, "Probing for MB86A16 (DVB-S/DSS)");
  199. mantis->fe = mb86a16_attach(&vp1034_config, &mantis->adapter);
  200. if (mantis->fe) {
  201. dprintk(verbose, MANTIS_ERROR, 1,
  202. "found MB86A16 DVB-S/DSS frontend @0x%02x",
  203. vp1034_config.demod_address);
  204. }
  205. break;
  206. case MANTIS_VP_2033_DVB_C: // VP-2033
  207. dprintk(verbose, MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
  208. mantis->fe = tda10021_attach(&philips_cu1216_config, &mantis->adapter, read_pwm(mantis));
  209. if (mantis->fe) {
  210. mantis->fe->ops.tuner_ops.set_params = philips_cu1216_tuner_set;
  211. dprintk(verbose, MANTIS_ERROR, 1,
  212. "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
  213. philips_cu1216_config.demod_address);
  214. dprintk(verbose, MANTIS_ERROR, 1,
  215. "Mantis DVB-C Philips CU1216 frontend attach success");
  216. }
  217. break;
  218. case TERRATEC_CINERGY_C_PCI:
  219. dprintk(verbose, MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
  220. mantis->fe = tda10023_attach(&tda10023_cu1216_config, &mantis->adapter, read_pwm(mantis));
  221. if (mantis->fe) {
  222. mantis->fe->ops.tuner_ops.set_params = philips_cu1216_tuner_set;
  223. dprintk(verbose, MANTIS_ERROR, 1,
  224. "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
  225. philips_cu1216_config.demod_address);
  226. dprintk(verbose, MANTIS_ERROR, 1,
  227. "Mantis DVB-C Philips CU1216 frontend attach success");
  228. }
  229. break;
  230. default:
  231. dprintk(verbose, MANTIS_DEBUG, 1, "Unknown frontend:[0x%02x]",
  232. mantis->sub_device_id);
  233. return -ENODEV;
  234. }
  235. if (mantis->fe == NULL) {
  236. dprintk(verbose, MANTIS_ERROR, 1, "!!! NO Frontends found !!!");
  237. return -ENODEV;
  238. } else {
  239. if (dvb_register_frontend(&mantis->dvb_adapter, mantis->fe)) {
  240. dprintk(verbose, MANTIS_ERROR, 1,
  241. "ERROR: Frontend registration failed");
  242. if (mantis->fe->ops.release)
  243. mantis->fe->ops.release(mantis->fe);
  244. mantis->fe = NULL;
  245. return -ENODEV;
  246. }
  247. }
  248. return 0;
  249. }
  250. int __devexit mantis_dvb_exit(struct mantis_pci *mantis)
  251. {
  252. tasklet_kill(&mantis->tasklet);
  253. dvb_net_release(&mantis->dvbnet);
  254. mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_mem);
  255. mantis->demux.dmx.remove_frontend(&mantis->demux.dmx, &mantis->fe_hw);
  256. dvb_dmxdev_release(&mantis->dmxdev);
  257. dvb_dmx_release(&mantis->demux);
  258. if (mantis->fe)
  259. dvb_unregister_frontend(mantis->fe);
  260. dprintk(verbose, MANTIS_DEBUG, 1, "dvb_unregister_adapter");
  261. dvb_unregister_adapter(&mantis->dvb_adapter);
  262. return 0;
  263. }