flexcop.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. ret = dvb_dmx_init(&fc->demux);
  79. if (ret < 0) {
  80. err("dvb_dmx failed: error %d", ret);
  81. goto err_dmx;
  82. }
  83. fc->hw_frontend.source = DMX_FRONTEND_0;
  84. fc->dmxdev.filternum = fc->demux.feednum;
  85. fc->dmxdev.demux = &fc->demux.dmx;
  86. fc->dmxdev.capabilities = 0;
  87. ret = dvb_dmxdev_init(&fc->dmxdev, &fc->dvb_adapter);
  88. if (ret < 0) {
  89. err("dvb_dmxdev_init failed: error %d", ret);
  90. goto err_dmx_dev;
  91. }
  92. ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->hw_frontend);
  93. if (ret < 0) {
  94. err("adding hw_frontend to dmx failed: error %d", ret);
  95. goto err_dmx_add_hw_frontend;
  96. }
  97. fc->mem_frontend.source = DMX_MEMORY_FE;
  98. ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->mem_frontend);
  99. if (ret < 0) {
  100. err("adding mem_frontend to dmx failed: error %d", ret);
  101. goto err_dmx_add_mem_frontend;
  102. }
  103. ret = fc->demux.dmx.connect_frontend(&fc->demux.dmx, &fc->hw_frontend);
  104. if (ret < 0) {
  105. err("connect frontend failed: error %d", ret);
  106. goto err_connect_frontend;
  107. }
  108. ret = dvb_net_init(&fc->dvb_adapter, &fc->dvbnet, &fc->demux.dmx);
  109. if (ret < 0) {
  110. err("dvb_net_init failed: error %d", ret);
  111. goto err_net;
  112. }
  113. fc->init_state |= FC_STATE_DVB_INIT;
  114. return 0;
  115. err_net:
  116. fc->demux.dmx.disconnect_frontend(&fc->demux.dmx);
  117. err_connect_frontend:
  118. fc->demux.dmx.remove_frontend(&fc->demux.dmx, &fc->mem_frontend);
  119. err_dmx_add_mem_frontend:
  120. fc->demux.dmx.remove_frontend(&fc->demux.dmx, &fc->hw_frontend);
  121. err_dmx_add_hw_frontend:
  122. dvb_dmxdev_release(&fc->dmxdev);
  123. err_dmx_dev:
  124. dvb_dmx_release(&fc->demux);
  125. err_dmx:
  126. dvb_unregister_adapter(&fc->dvb_adapter);
  127. return ret;
  128. }
  129. static void flexcop_dvb_exit(struct flexcop_device *fc)
  130. {
  131. if (fc->init_state & FC_STATE_DVB_INIT) {
  132. dvb_net_release(&fc->dvbnet);
  133. fc->demux.dmx.close(&fc->demux.dmx);
  134. fc->demux.dmx.remove_frontend(&fc->demux.dmx,
  135. &fc->mem_frontend);
  136. fc->demux.dmx.remove_frontend(&fc->demux.dmx,
  137. &fc->hw_frontend);
  138. dvb_dmxdev_release(&fc->dmxdev);
  139. dvb_dmx_release(&fc->demux);
  140. dvb_unregister_adapter(&fc->dvb_adapter);
  141. deb_info("deinitialized dvb stuff\n");
  142. }
  143. fc->init_state &= ~FC_STATE_DVB_INIT;
  144. }
  145. /* these methods are necessary to achieve the long-term-goal of hiding the
  146. * struct flexcop_device from the bus-parts */
  147. void flexcop_pass_dmx_data(struct flexcop_device *fc, u8 *buf, u32 len)
  148. {
  149. dvb_dmx_swfilter(&fc->demux, buf, len);
  150. }
  151. EXPORT_SYMBOL(flexcop_pass_dmx_data);
  152. void flexcop_pass_dmx_packets(struct flexcop_device *fc, u8 *buf, u32 no)
  153. {
  154. dvb_dmx_swfilter_packets(&fc->demux, buf, no);
  155. }
  156. EXPORT_SYMBOL(flexcop_pass_dmx_packets);
  157. static void flexcop_reset(struct flexcop_device *fc)
  158. {
  159. flexcop_ibi_value v210, v204;
  160. /* reset the flexcop itself */
  161. fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
  162. v210.raw = 0;
  163. v210.sw_reset_210.reset_block_000 = 1;
  164. v210.sw_reset_210.reset_block_100 = 1;
  165. v210.sw_reset_210.reset_block_200 = 1;
  166. v210.sw_reset_210.reset_block_300 = 1;
  167. v210.sw_reset_210.reset_block_400 = 1;
  168. v210.sw_reset_210.reset_block_500 = 1;
  169. v210.sw_reset_210.reset_block_600 = 1;
  170. v210.sw_reset_210.reset_block_700 = 1;
  171. v210.sw_reset_210.Block_reset_enable = 0xb2;
  172. v210.sw_reset_210.Special_controls = 0xc259;
  173. fc->write_ibi_reg(fc,sw_reset_210,v210);
  174. msleep(1);
  175. /* reset the periphical devices */
  176. v204 = fc->read_ibi_reg(fc,misc_204);
  177. v204.misc_204.Per_reset_sig = 0;
  178. fc->write_ibi_reg(fc,misc_204,v204);
  179. msleep(1);
  180. v204.misc_204.Per_reset_sig = 1;
  181. fc->write_ibi_reg(fc,misc_204,v204);
  182. }
  183. void flexcop_reset_block_300(struct flexcop_device *fc)
  184. {
  185. flexcop_ibi_value v208_save = fc->read_ibi_reg(fc, ctrl_208),
  186. v210 = fc->read_ibi_reg(fc, sw_reset_210);
  187. deb_rdump("208: %08x, 210: %08x\n", v208_save.raw, v210.raw);
  188. fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
  189. v210.sw_reset_210.reset_block_300 = 1;
  190. v210.sw_reset_210.Block_reset_enable = 0xb2;
  191. fc->write_ibi_reg(fc,sw_reset_210,v210);
  192. fc->write_ibi_reg(fc,ctrl_208,v208_save);
  193. }
  194. struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len)
  195. {
  196. void *bus;
  197. struct flexcop_device *fc = kzalloc(sizeof(struct flexcop_device),
  198. GFP_KERNEL);
  199. if (!fc) {
  200. err("no memory");
  201. return NULL;
  202. }
  203. bus = kzalloc(bus_specific_len, GFP_KERNEL);
  204. if (!bus) {
  205. err("no memory");
  206. kfree(fc);
  207. return NULL;
  208. }
  209. fc->bus_specific = bus;
  210. return fc;
  211. }
  212. EXPORT_SYMBOL(flexcop_device_kmalloc);
  213. void flexcop_device_kfree(struct flexcop_device *fc)
  214. {
  215. kfree(fc->bus_specific);
  216. kfree(fc);
  217. }
  218. EXPORT_SYMBOL(flexcop_device_kfree);
  219. int flexcop_device_initialize(struct flexcop_device *fc)
  220. {
  221. int ret;
  222. ibi_zero.raw = 0;
  223. flexcop_reset(fc);
  224. flexcop_determine_revision(fc);
  225. flexcop_sram_init(fc);
  226. flexcop_hw_filter_init(fc);
  227. flexcop_smc_ctrl(fc, 0);
  228. ret = flexcop_dvb_init(fc);
  229. if (ret)
  230. goto error;
  231. /* i2c has to be done before doing EEProm stuff -
  232. * because the EEProm is accessed via i2c */
  233. ret = flexcop_i2c_init(fc);
  234. if (ret)
  235. goto error;
  236. /* do the MAC address reading after initializing the dvb_adapter */
  237. if (fc->get_mac_addr(fc, 0) == 0) {
  238. u8 *b = fc->dvb_adapter.proposed_mac;
  239. info("MAC address = %pM", b);
  240. flexcop_set_mac_filter(fc,b);
  241. flexcop_mac_filter_ctrl(fc,1);
  242. } else
  243. warn("reading of MAC address failed.\n");
  244. ret = flexcop_frontend_init(fc);
  245. if (ret)
  246. goto error;
  247. flexcop_device_name(fc,"initialization of","complete");
  248. return 0;
  249. error:
  250. flexcop_device_exit(fc);
  251. return ret;
  252. }
  253. EXPORT_SYMBOL(flexcop_device_initialize);
  254. void flexcop_device_exit(struct flexcop_device *fc)
  255. {
  256. flexcop_frontend_exit(fc);
  257. flexcop_i2c_exit(fc);
  258. flexcop_dvb_exit(fc);
  259. }
  260. EXPORT_SYMBOL(flexcop_device_exit);
  261. static int flexcop_module_init(void)
  262. {
  263. info(DRIVER_NAME " loaded successfully");
  264. return 0;
  265. }
  266. static void flexcop_module_cleanup(void)
  267. {
  268. info(DRIVER_NAME " unloaded successfully");
  269. }
  270. module_init(flexcop_module_init);
  271. module_exit(flexcop_module_cleanup);
  272. MODULE_AUTHOR(DRIVER_AUTHOR);
  273. MODULE_DESCRIPTION(DRIVER_NAME);
  274. MODULE_LICENSE("GPL");