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