flexcop.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
  3. * flexcop.c - main module part
  4. * Copyright (C) 2004-9 Patrick Boettcher <patrick.boettcher@desy.de>
  5. * based on skystar2-driver Copyright (C) 2003 Vadim Catana, skystar@moldova.cc
  6. *
  7. * Acknowledgements:
  8. * John Jurrius from BBTI, Inc. for extensive support
  9. * with code examples and data books
  10. * Bjarne Steinsbo, bjarne at steinsbo.com (some ideas for rewriting)
  11. *
  12. * Contributions to the skystar2-driver have been done by
  13. * Vincenzo Di Massa, hawk.it at tiscalinet.it (several DiSEqC fixes)
  14. * Roberto Ragusa, r.ragusa at libero.it (polishing, restyling the code)
  15. * Uwe Bugla, uwe.bugla at gmx.de (doing tests, restyling code, writing docu)
  16. * Niklas Peinecke, peinecke at gdv.uni-hannover.de (hardware pid/mac
  17. * filtering)
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU Lesser General Public License
  21. * as published by the Free Software Foundation; either version 2.1
  22. * of the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Lesser General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  32. */
  33. #include "flexcop.h"
  34. #define DRIVER_NAME "B2C2 FlexcopII/II(b)/III digital TV receiver chip"
  35. #define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de"
  36. #ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
  37. #define DEBSTATUS ""
  38. #else
  39. #define DEBSTATUS " (debugging is not enabled)"
  40. #endif
  41. int b2c2_flexcop_debug;
  42. module_param_named(debug, b2c2_flexcop_debug, int, 0644);
  43. MODULE_PARM_DESC(debug,
  44. "set debug level (1=info,2=tuner,4=i2c,8=ts,"
  45. "16=sram,32=reg (|-able))."
  46. DEBSTATUS);
  47. #undef DEBSTATUS
  48. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  49. /* global zero for ibi values */
  50. flexcop_ibi_value ibi_zero;
  51. static int flexcop_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
  52. {
  53. struct flexcop_device *fc = dvbdmxfeed->demux->priv;
  54. return flexcop_pid_feed_control(fc, dvbdmxfeed, 1);
  55. }
  56. static int flexcop_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
  57. {
  58. struct flexcop_device *fc = dvbdmxfeed->demux->priv;
  59. return flexcop_pid_feed_control(fc, dvbdmxfeed, 0);
  60. }
  61. static int flexcop_dvb_init(struct flexcop_device *fc)
  62. {
  63. int ret = dvb_register_adapter(&fc->dvb_adapter,
  64. "FlexCop Digital TV device", fc->owner,
  65. fc->dev, adapter_nr);
  66. if (ret < 0) {
  67. err("error registering DVB adapter");
  68. return ret;
  69. }
  70. fc->dvb_adapter.priv = fc;
  71. fc->demux.dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING
  72. | DMX_MEMORY_BASED_FILTERING);
  73. fc->demux.priv = fc;
  74. fc->demux.filternum = fc->demux.feednum = FC_MAX_FEED;
  75. fc->demux.start_feed = flexcop_dvb_start_feed;
  76. fc->demux.stop_feed = flexcop_dvb_stop_feed;
  77. fc->demux.write_to_decoder = NULL;
  78. if ((ret = dvb_dmx_init(&fc->demux)) < 0) {
  79. err("dvb_dmx failed: error %d", ret);
  80. goto err_dmx;
  81. }
  82. fc->hw_frontend.source = DMX_FRONTEND_0;
  83. fc->dmxdev.filternum = fc->demux.feednum;
  84. fc->dmxdev.demux = &fc->demux.dmx;
  85. fc->dmxdev.capabilities = 0;
  86. if ((ret = dvb_dmxdev_init(&fc->dmxdev, &fc->dvb_adapter)) < 0) {
  87. err("dvb_dmxdev_init failed: error %d", ret);
  88. goto err_dmx_dev;
  89. }
  90. if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) {
  91. err("adding hw_frontend to dmx failed: error %d", ret);
  92. goto err_dmx_add_hw_frontend;
  93. }
  94. fc->mem_frontend.source = DMX_MEMORY_FE;
  95. if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->mem_frontend)) < 0) {
  96. err("adding mem_frontend to dmx failed: error %d", ret);
  97. goto err_dmx_add_mem_frontend;
  98. }
  99. if ((ret = fc->demux.dmx.connect_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) {
  100. err("connect frontend failed: error %d", ret);
  101. goto err_connect_frontend;
  102. }
  103. dvb_net_init(&fc->dvb_adapter, &fc->dvbnet, &fc->demux.dmx);
  104. fc->init_state |= FC_STATE_DVB_INIT;
  105. return 0;
  106. err_connect_frontend:
  107. fc->demux.dmx.remove_frontend(&fc->demux.dmx, &fc->mem_frontend);
  108. err_dmx_add_mem_frontend:
  109. fc->demux.dmx.remove_frontend(&fc->demux.dmx, &fc->hw_frontend);
  110. err_dmx_add_hw_frontend:
  111. dvb_dmxdev_release(&fc->dmxdev);
  112. err_dmx_dev:
  113. dvb_dmx_release(&fc->demux);
  114. err_dmx:
  115. dvb_unregister_adapter(&fc->dvb_adapter);
  116. return ret;
  117. }
  118. static void flexcop_dvb_exit(struct flexcop_device *fc)
  119. {
  120. if (fc->init_state & FC_STATE_DVB_INIT) {
  121. dvb_net_release(&fc->dvbnet);
  122. fc->demux.dmx.close(&fc->demux.dmx);
  123. fc->demux.dmx.remove_frontend(&fc->demux.dmx,
  124. &fc->mem_frontend);
  125. fc->demux.dmx.remove_frontend(&fc->demux.dmx,
  126. &fc->hw_frontend);
  127. dvb_dmxdev_release(&fc->dmxdev);
  128. dvb_dmx_release(&fc->demux);
  129. dvb_unregister_adapter(&fc->dvb_adapter);
  130. deb_info("deinitialized dvb stuff\n");
  131. }
  132. fc->init_state &= ~FC_STATE_DVB_INIT;
  133. }
  134. /* these methods are necessary to achieve the long-term-goal of hiding the
  135. * struct flexcop_device from the bus-parts */
  136. void flexcop_pass_dmx_data(struct flexcop_device *fc, u8 *buf, u32 len)
  137. {
  138. dvb_dmx_swfilter(&fc->demux, buf, len);
  139. }
  140. EXPORT_SYMBOL(flexcop_pass_dmx_data);
  141. void flexcop_pass_dmx_packets(struct flexcop_device *fc, u8 *buf, u32 no)
  142. {
  143. dvb_dmx_swfilter_packets(&fc->demux, buf, no);
  144. }
  145. EXPORT_SYMBOL(flexcop_pass_dmx_packets);
  146. static void flexcop_reset(struct flexcop_device *fc)
  147. {
  148. flexcop_ibi_value v210, v204;
  149. /* reset the flexcop itself */
  150. fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
  151. v210.raw = 0;
  152. v210.sw_reset_210.reset_block_000 = 1;
  153. v210.sw_reset_210.reset_block_100 = 1;
  154. v210.sw_reset_210.reset_block_200 = 1;
  155. v210.sw_reset_210.reset_block_300 = 1;
  156. v210.sw_reset_210.reset_block_400 = 1;
  157. v210.sw_reset_210.reset_block_500 = 1;
  158. v210.sw_reset_210.reset_block_600 = 1;
  159. v210.sw_reset_210.reset_block_700 = 1;
  160. v210.sw_reset_210.Block_reset_enable = 0xb2;
  161. v210.sw_reset_210.Special_controls = 0xc259;
  162. fc->write_ibi_reg(fc,sw_reset_210,v210);
  163. msleep(1);
  164. /* reset the periphical devices */
  165. v204 = fc->read_ibi_reg(fc,misc_204);
  166. v204.misc_204.Per_reset_sig = 0;
  167. fc->write_ibi_reg(fc,misc_204,v204);
  168. msleep(1);
  169. v204.misc_204.Per_reset_sig = 1;
  170. fc->write_ibi_reg(fc,misc_204,v204);
  171. }
  172. void flexcop_reset_block_300(struct flexcop_device *fc)
  173. {
  174. flexcop_ibi_value v208_save = fc->read_ibi_reg(fc, ctrl_208),
  175. v210 = fc->read_ibi_reg(fc, sw_reset_210);
  176. deb_rdump("208: %08x, 210: %08x\n", v208_save.raw, v210.raw);
  177. fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
  178. v210.sw_reset_210.reset_block_300 = 1;
  179. v210.sw_reset_210.Block_reset_enable = 0xb2;
  180. fc->write_ibi_reg(fc,sw_reset_210,v210);
  181. fc->write_ibi_reg(fc,ctrl_208,v208_save);
  182. }
  183. struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len)
  184. {
  185. void *bus;
  186. struct flexcop_device *fc = kzalloc(sizeof(struct flexcop_device),
  187. GFP_KERNEL);
  188. if (!fc) {
  189. err("no memory");
  190. return NULL;
  191. }
  192. bus = kzalloc(bus_specific_len, GFP_KERNEL);
  193. if (!bus) {
  194. err("no memory");
  195. kfree(fc);
  196. return NULL;
  197. }
  198. fc->bus_specific = bus;
  199. return fc;
  200. }
  201. EXPORT_SYMBOL(flexcop_device_kmalloc);
  202. void flexcop_device_kfree(struct flexcop_device *fc)
  203. {
  204. kfree(fc->bus_specific);
  205. kfree(fc);
  206. }
  207. EXPORT_SYMBOL(flexcop_device_kfree);
  208. int flexcop_device_initialize(struct flexcop_device *fc)
  209. {
  210. int ret;
  211. ibi_zero.raw = 0;
  212. flexcop_reset(fc);
  213. flexcop_determine_revision(fc);
  214. flexcop_sram_init(fc);
  215. flexcop_hw_filter_init(fc);
  216. flexcop_smc_ctrl(fc, 0);
  217. if ((ret = flexcop_dvb_init(fc)))
  218. goto error;
  219. /* i2c has to be done before doing EEProm stuff -
  220. * because the EEProm is accessed via i2c */
  221. ret = flexcop_i2c_init(fc);
  222. if (ret)
  223. goto error;
  224. /* do the MAC address reading after initializing the dvb_adapter */
  225. if (fc->get_mac_addr(fc, 0) == 0) {
  226. u8 *b = fc->dvb_adapter.proposed_mac;
  227. info("MAC address = %pM", b);
  228. flexcop_set_mac_filter(fc,b);
  229. flexcop_mac_filter_ctrl(fc,1);
  230. } else
  231. warn("reading of MAC address failed.\n");
  232. if ((ret = flexcop_frontend_init(fc)))
  233. goto error;
  234. flexcop_device_name(fc,"initialization of","complete");
  235. return 0;
  236. error:
  237. flexcop_device_exit(fc);
  238. return ret;
  239. }
  240. EXPORT_SYMBOL(flexcop_device_initialize);
  241. void flexcop_device_exit(struct flexcop_device *fc)
  242. {
  243. flexcop_frontend_exit(fc);
  244. flexcop_i2c_exit(fc);
  245. flexcop_dvb_exit(fc);
  246. }
  247. EXPORT_SYMBOL(flexcop_device_exit);
  248. static int flexcop_module_init(void)
  249. {
  250. info(DRIVER_NAME " loaded successfully");
  251. return 0;
  252. }
  253. static void flexcop_module_cleanup(void)
  254. {
  255. info(DRIVER_NAME " unloaded successfully");
  256. }
  257. module_init(flexcop_module_init);
  258. module_exit(flexcop_module_cleanup);
  259. MODULE_AUTHOR(DRIVER_AUTHOR);
  260. MODULE_DESCRIPTION(DRIVER_NAME);
  261. MODULE_LICENSE("GPL");