mantis_dvb.c 8.3 KB

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