mantis_dvb.c 9.4 KB

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