mantis_dvb.c 9.6 KB

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