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
8 static void flexcop_rcv_data_ctrl(struct flexcop_device
*fc
, int onoff
)
10 flexcop_set_ibi_value(ctrl_208
, Rcv_Data_sig
, onoff
);
11 deb_ts("rcv_data is now: '%s'\n", onoff
? "on" : "off");
14 void flexcop_smc_ctrl(struct flexcop_device
*fc
, int onoff
)
16 flexcop_set_ibi_value(ctrl_208
, SMC_Enable_sig
, onoff
);
19 static void flexcop_null_filter_ctrl(struct flexcop_device
*fc
, int onoff
)
21 flexcop_set_ibi_value(ctrl_208
, Null_filter_sig
, onoff
);
24 void flexcop_set_mac_filter(struct flexcop_device
*fc
, u8 mac
[6])
26 flexcop_ibi_value v418
, v41c
;
27 v41c
= fc
->read_ibi_reg(fc
, mac_address_41c
);
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];
36 fc
->write_ibi_reg(fc
, mac_address_418
, v418
);
37 fc
->write_ibi_reg(fc
, mac_address_41c
, v41c
);
40 void flexcop_mac_filter_ctrl(struct flexcop_device
*fc
, int onoff
)
42 flexcop_set_ibi_value(ctrl_208
, MAC_filter_Mode_sig
, onoff
);
45 static void flexcop_pid_group_filter(struct flexcop_device
*fc
,
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
;
52 fc
->write_ibi_reg(fc
, pid_filter_30c
, v30c
);
55 static void flexcop_pid_group_filter_ctrl(struct flexcop_device
*fc
, int onoff
)
57 flexcop_set_ibi_value(ctrl_208
, Mask_filter_sig
, onoff
);
60 /* this fancy define reduces the code size of the quite similar PID controlling of
64 #define pid_ctrl(vregname,field,enablefield,trans_field,transval) \
65 flexcop_ibi_value vpid = fc->read_ibi_reg(fc, vregname), \
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);
73 static void flexcop_pid_Stream1_PID_ctrl(struct flexcop_device
*fc
,
76 pid_ctrl(pid_filter_300
, Stream1_PID
, Stream1_filter_sig
,
80 static void flexcop_pid_Stream2_PID_ctrl(struct flexcop_device
*fc
,
83 pid_ctrl(pid_filter_300
, Stream2_PID
, Stream2_filter_sig
,
87 static void flexcop_pid_PCR_PID_ctrl(struct flexcop_device
*fc
,
90 pid_ctrl(pid_filter_304
, PCR_PID
, PCR_filter_sig
, PCR_trans
, 0);
93 static void flexcop_pid_PMT_PID_ctrl(struct flexcop_device
*fc
,
96 pid_ctrl(pid_filter_304
, PMT_PID
, PMT_filter_sig
, PMT_trans
, 0);
99 static void flexcop_pid_EMM_PID_ctrl(struct flexcop_device
*fc
,
102 pid_ctrl(pid_filter_308
, EMM_PID
, EMM_filter_sig
, EMM_trans
, 0);
105 static void flexcop_pid_ECM_PID_ctrl(struct flexcop_device
*fc
,
108 pid_ctrl(pid_filter_308
, ECM_PID
, ECM_filter_sig
, ECM_trans
, 0);
111 static void flexcop_pid_control(struct flexcop_device
*fc
,
112 int index
, u16 pid
, int onoff
)
117 deb_ts("setting pid: %5d %04x at index %d '%s'\n",
118 pid
, pid
, index
, onoff
? "on" : "off");
120 /* First 6 can be buggy - skip over them if option set */
121 if (fc
->skip_6_hw_pid_filter
)
124 /* We could use bit magic here to reduce source code size.
125 * I decided against it, but to use the real register names */
128 flexcop_pid_Stream1_PID_ctrl(fc
, pid
, onoff
);
131 flexcop_pid_Stream2_PID_ctrl(fc
, pid
, onoff
);
134 flexcop_pid_PCR_PID_ctrl(fc
, pid
, onoff
);
137 flexcop_pid_PMT_PID_ctrl(fc
, pid
, onoff
);
140 flexcop_pid_EMM_PID_ctrl(fc
, pid
, onoff
);
143 flexcop_pid_ECM_PID_ctrl(fc
, pid
, onoff
);
146 if (fc
->has_32_hw_pid_filter
&& index
< 38) {
147 flexcop_ibi_value vpid
, vid
;
150 vid
= fc
->read_ibi_reg(fc
, index_reg_310
);
151 vid
.index_reg_310
.index_reg
= index
- 6;
152 fc
->write_ibi_reg(fc
, index_reg_310
, vid
);
154 vpid
= fc
->read_ibi_reg(fc
, pid_n_reg_314
);
155 vpid
.pid_n_reg_314
.PID
= onoff
? pid
: 0x1fff;
156 vpid
.pid_n_reg_314
.PID_enable_bit
= onoff
;
157 fc
->write_ibi_reg(fc
, pid_n_reg_314
, vpid
);
163 static int flexcop_toggle_fullts_streaming(struct flexcop_device
*fc
, int onoff
)
165 if (fc
->fullts_streaming_state
!= onoff
) {
166 deb_ts("%s full TS transfer\n",onoff
? "enabling" : "disabling");
167 flexcop_pid_group_filter(fc
, 0, 0x1fe0 * (!onoff
));
168 flexcop_pid_group_filter_ctrl(fc
, onoff
);
169 fc
->fullts_streaming_state
= onoff
;
174 int flexcop_pid_feed_control(struct flexcop_device
*fc
,
175 struct dvb_demux_feed
*dvbdmxfeed
, int onoff
)
177 int max_pid_filter
= 6;
179 max_pid_filter
-= 6 * fc
->skip_6_hw_pid_filter
;
180 max_pid_filter
+= 32 * fc
->has_32_hw_pid_filter
;
182 fc
->feedcount
+= onoff
? 1 : -1; /* the number of PIDs/Feed currently requested */
183 if (dvbdmxfeed
->index
>= max_pid_filter
)
184 fc
->extra_feedcount
+= onoff
? 1 : -1;
186 /* toggle complete-TS-streaming when:
187 * - pid_filtering is not enabled and it is the first or last feed requested
188 * - pid_filtering is enabled,
189 * - but the number of requested feeds is exceeded
190 * - or the requested pid is 0x2000 */
192 if (!fc
->pid_filtering
&& fc
->feedcount
== onoff
)
193 flexcop_toggle_fullts_streaming(fc
, onoff
);
195 if (fc
->pid_filtering
) {
196 flexcop_pid_control \
197 (fc
, dvbdmxfeed
->index
, dvbdmxfeed
->pid
, onoff
);
199 if (fc
->extra_feedcount
> 0)
200 flexcop_toggle_fullts_streaming(fc
, 1);
201 else if (dvbdmxfeed
->pid
== 0x2000)
202 flexcop_toggle_fullts_streaming(fc
, onoff
);
204 flexcop_toggle_fullts_streaming(fc
, 0);
207 /* if it was the first or last feed request change the stream-status */
208 if (fc
->feedcount
== onoff
) {
209 flexcop_rcv_data_ctrl(fc
, onoff
);
210 if (fc
->stream_control
) /* device specific stream control */
211 fc
->stream_control(fc
, onoff
);
213 /* feeding stopped -> reset the flexcop filter*/
215 flexcop_reset_block_300(fc
);
216 flexcop_hw_filter_init(fc
);
221 EXPORT_SYMBOL(flexcop_pid_feed_control
);
223 void flexcop_hw_filter_init(struct flexcop_device
*fc
)
227 int max_pid_filter
= 6;
229 max_pid_filter
-= 6 * fc
->skip_6_hw_pid_filter
;
230 max_pid_filter
+= 32 * fc
->has_32_hw_pid_filter
;
232 for (i
= 0; i
< max_pid_filter
; i
++)
233 flexcop_pid_control(fc
, i
, 0x1fff, 0);
235 flexcop_pid_group_filter(fc
, 0, 0x1fe0);
236 flexcop_pid_group_filter_ctrl(fc
, 0);
238 v
= fc
->read_ibi_reg(fc
, pid_filter_308
);
239 v
.pid_filter_308
.EMM_filter_4
= 1;
240 v
.pid_filter_308
.EMM_filter_6
= 0;
241 fc
->write_ibi_reg(fc
, pid_filter_308
, v
);
243 flexcop_null_filter_ctrl(fc
, 1);