flexcop-hw-filter.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
  3. * flexcop-hw-filter.c - pid and mac address filtering and control functions
  4. * see flexcop.c for copyright information
  5. */
  6. #include "flexcop.h"
  7. static void flexcop_rcv_data_ctrl(struct flexcop_device *fc, int onoff)
  8. {
  9. flexcop_set_ibi_value(ctrl_208, Rcv_Data_sig, onoff);
  10. deb_ts("rcv_data is now: '%s'\n", onoff ? "on" : "off");
  11. }
  12. void flexcop_smc_ctrl(struct flexcop_device *fc, int onoff)
  13. {
  14. flexcop_set_ibi_value(ctrl_208, SMC_Enable_sig, onoff);
  15. }
  16. static void flexcop_null_filter_ctrl(struct flexcop_device *fc, int onoff)
  17. {
  18. flexcop_set_ibi_value(ctrl_208, Null_filter_sig, onoff);
  19. }
  20. void flexcop_set_mac_filter(struct flexcop_device *fc, u8 mac[6])
  21. {
  22. flexcop_ibi_value v418, v41c;
  23. v41c = fc->read_ibi_reg(fc, mac_address_41c);
  24. v418.mac_address_418.MAC1 = mac[0];
  25. v418.mac_address_418.MAC2 = mac[1];
  26. v418.mac_address_418.MAC3 = mac[2];
  27. v418.mac_address_418.MAC6 = mac[3];
  28. v41c.mac_address_41c.MAC7 = mac[4];
  29. v41c.mac_address_41c.MAC8 = mac[5];
  30. fc->write_ibi_reg(fc, mac_address_418, v418);
  31. fc->write_ibi_reg(fc, mac_address_41c, v41c);
  32. }
  33. void flexcop_mac_filter_ctrl(struct flexcop_device *fc, int onoff)
  34. {
  35. flexcop_set_ibi_value(ctrl_208, MAC_filter_Mode_sig, onoff);
  36. }
  37. static void flexcop_pid_group_filter(struct flexcop_device *fc,
  38. u16 pid, u16 mask)
  39. {
  40. /* index_reg_310.extra_index_reg need to 0 or 7 to work */
  41. flexcop_ibi_value v30c;
  42. v30c.pid_filter_30c_ext_ind_0_7.Group_PID = pid;
  43. v30c.pid_filter_30c_ext_ind_0_7.Group_mask = mask;
  44. fc->write_ibi_reg(fc, pid_filter_30c, v30c);
  45. }
  46. static void flexcop_pid_group_filter_ctrl(struct flexcop_device *fc, int onoff)
  47. {
  48. flexcop_set_ibi_value(ctrl_208, Mask_filter_sig, onoff);
  49. }
  50. /* this fancy define reduces the code size of the quite similar PID controlling of
  51. * the first 6 PIDs
  52. */
  53. #define pid_ctrl(vregname,field,enablefield,trans_field,transval) \
  54. flexcop_ibi_value vpid = fc->read_ibi_reg(fc, vregname), \
  55. v208 = fc->read_ibi_reg(fc, ctrl_208); \
  56. vpid.vregname.field = onoff ? pid : 0x1fff; \
  57. vpid.vregname.trans_field = transval; \
  58. v208.ctrl_208.enablefield = onoff; \
  59. fc->write_ibi_reg(fc, vregname, vpid); \
  60. fc->write_ibi_reg(fc, ctrl_208, v208);
  61. static void flexcop_pid_Stream1_PID_ctrl(struct flexcop_device *fc,
  62. u16 pid, int onoff)
  63. {
  64. pid_ctrl(pid_filter_300, Stream1_PID, Stream1_filter_sig,
  65. Stream1_trans, 0);
  66. }
  67. static void flexcop_pid_Stream2_PID_ctrl(struct flexcop_device *fc,
  68. u16 pid, int onoff)
  69. {
  70. pid_ctrl(pid_filter_300, Stream2_PID, Stream2_filter_sig,
  71. Stream2_trans, 0);
  72. }
  73. static void flexcop_pid_PCR_PID_ctrl(struct flexcop_device *fc,
  74. u16 pid, int onoff)
  75. {
  76. pid_ctrl(pid_filter_304, PCR_PID, PCR_filter_sig, PCR_trans, 0);
  77. }
  78. static void flexcop_pid_PMT_PID_ctrl(struct flexcop_device *fc,
  79. u16 pid, int onoff)
  80. {
  81. pid_ctrl(pid_filter_304, PMT_PID, PMT_filter_sig, PMT_trans, 0);
  82. }
  83. static void flexcop_pid_EMM_PID_ctrl(struct flexcop_device *fc,
  84. u16 pid, int onoff)
  85. {
  86. pid_ctrl(pid_filter_308, EMM_PID, EMM_filter_sig, EMM_trans, 0);
  87. }
  88. static void flexcop_pid_ECM_PID_ctrl(struct flexcop_device *fc,
  89. u16 pid, int onoff)
  90. {
  91. pid_ctrl(pid_filter_308, ECM_PID, ECM_filter_sig, ECM_trans, 0);
  92. }
  93. static void flexcop_pid_control(struct flexcop_device *fc,
  94. int index, u16 pid, int onoff)
  95. {
  96. if (pid == 0x2000)
  97. return;
  98. deb_ts("setting pid: %5d %04x at index %d '%s'\n",
  99. pid, pid, index, onoff ? "on" : "off");
  100. /* First 6 can be buggy - skip over them if option set */
  101. if (fc->skip_6_hw_pid_filter)
  102. index += 6;
  103. /* We could use bit magic here to reduce source code size.
  104. * I decided against it, but to use the real register names */
  105. switch (index) {
  106. case 0:
  107. flexcop_pid_Stream1_PID_ctrl(fc, pid, onoff);
  108. break;
  109. case 1:
  110. flexcop_pid_Stream2_PID_ctrl(fc, pid, onoff);
  111. break;
  112. case 2:
  113. flexcop_pid_PCR_PID_ctrl(fc, pid, onoff);
  114. break;
  115. case 3:
  116. flexcop_pid_PMT_PID_ctrl(fc, pid, onoff);
  117. break;
  118. case 4:
  119. flexcop_pid_EMM_PID_ctrl(fc, pid, onoff);
  120. break;
  121. case 5:
  122. flexcop_pid_ECM_PID_ctrl(fc, pid, onoff);
  123. break;
  124. default:
  125. if (fc->has_32_hw_pid_filter && index < 38) {
  126. flexcop_ibi_value vpid, vid;
  127. /* set the index */
  128. vid = fc->read_ibi_reg(fc, index_reg_310);
  129. vid.index_reg_310.index_reg = index - 6;
  130. fc->write_ibi_reg(fc, index_reg_310, vid);
  131. vpid = fc->read_ibi_reg(fc, pid_n_reg_314);
  132. vpid.pid_n_reg_314.PID = onoff ? pid : 0x1fff;
  133. vpid.pid_n_reg_314.PID_enable_bit = onoff;
  134. fc->write_ibi_reg(fc, pid_n_reg_314, vpid);
  135. }
  136. break;
  137. }
  138. }
  139. static int flexcop_toggle_fullts_streaming(struct flexcop_device *fc, int onoff)
  140. {
  141. if (fc->fullts_streaming_state != onoff) {
  142. deb_ts("%s full TS transfer\n",onoff ? "enabling" : "disabling");
  143. flexcop_pid_group_filter(fc, 0, 0x1fe0 * (!onoff));
  144. flexcop_pid_group_filter_ctrl(fc, onoff);
  145. fc->fullts_streaming_state = onoff;
  146. }
  147. return 0;
  148. }
  149. int flexcop_pid_feed_control(struct flexcop_device *fc,
  150. struct dvb_demux_feed *dvbdmxfeed, int onoff)
  151. {
  152. int max_pid_filter = 6;
  153. max_pid_filter -= 6 * fc->skip_6_hw_pid_filter;
  154. max_pid_filter += 32 * fc->has_32_hw_pid_filter;
  155. fc->feedcount += onoff ? 1 : -1; /* the number of PIDs/Feed currently requested */
  156. if (dvbdmxfeed->index >= max_pid_filter)
  157. fc->extra_feedcount += onoff ? 1 : -1;
  158. /* toggle complete-TS-streaming when:
  159. * - pid_filtering is not enabled and it is the first or last feed requested
  160. * - pid_filtering is enabled,
  161. * - but the number of requested feeds is exceeded
  162. * - or the requested pid is 0x2000 */
  163. if (!fc->pid_filtering && fc->feedcount == onoff)
  164. flexcop_toggle_fullts_streaming(fc, onoff);
  165. if (fc->pid_filtering) {
  166. flexcop_pid_control \
  167. (fc, dvbdmxfeed->index, dvbdmxfeed->pid, onoff);
  168. if (fc->extra_feedcount > 0)
  169. flexcop_toggle_fullts_streaming(fc, 1);
  170. else if (dvbdmxfeed->pid == 0x2000)
  171. flexcop_toggle_fullts_streaming(fc, onoff);
  172. else
  173. flexcop_toggle_fullts_streaming(fc, 0);
  174. }
  175. /* if it was the first or last feed request change the stream-status */
  176. if (fc->feedcount == onoff) {
  177. flexcop_rcv_data_ctrl(fc, onoff);
  178. if (fc->stream_control) /* device specific stream control */
  179. fc->stream_control(fc, onoff);
  180. /* feeding stopped -> reset the flexcop filter*/
  181. if (onoff == 0) {
  182. flexcop_reset_block_300(fc);
  183. flexcop_hw_filter_init(fc);
  184. }
  185. }
  186. return 0;
  187. }
  188. EXPORT_SYMBOL(flexcop_pid_feed_control);
  189. void flexcop_hw_filter_init(struct flexcop_device *fc)
  190. {
  191. int i;
  192. flexcop_ibi_value v;
  193. int max_pid_filter = 6;
  194. max_pid_filter -= 6 * fc->skip_6_hw_pid_filter;
  195. max_pid_filter += 32 * fc->has_32_hw_pid_filter;
  196. for (i = 0; i < max_pid_filter; i++)
  197. flexcop_pid_control(fc, i, 0x1fff, 0);
  198. flexcop_pid_group_filter(fc, 0, 0x1fe0);
  199. flexcop_pid_group_filter_ctrl(fc, 0);
  200. v = fc->read_ibi_reg(fc, pid_filter_308);
  201. v.pid_filter_308.EMM_filter_4 = 1;
  202. v.pid_filter_308.EMM_filter_6 = 0;
  203. fc->write_ibi_reg(fc, pid_filter_308, v);
  204. flexcop_null_filter_ctrl(fc, 1);
  205. }