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@posteo.de>
5 * based on skystar2-driver Copyright (C) 2003 Vadim Catana, skystar@moldova.cc
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)
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
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.
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.
32 #define DRIVER_NAME "B2C2 FlexcopII/II(b)/III digital TV receiver chip"
33 #define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@posteo.de"
35 #ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
38 #define DEBSTATUS " (debugging is not enabled)"
41 int b2c2_flexcop_debug
;
42 EXPORT_SYMBOL_GPL(b2c2_flexcop_debug
);
43 module_param_named(debug
, b2c2_flexcop_debug
, int, 0644);
44 MODULE_PARM_DESC(debug
,
45 "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg,64=i2cdump (|-able))."
49 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
51 /* global zero for ibi values */
52 flexcop_ibi_value ibi_zero
;
54 static int flexcop_dvb_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
56 struct flexcop_device
*fc
= dvbdmxfeed
->demux
->priv
;
57 return flexcop_pid_feed_control(fc
, dvbdmxfeed
, 1);
60 static int flexcop_dvb_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
62 struct flexcop_device
*fc
= dvbdmxfeed
->demux
->priv
;
63 return flexcop_pid_feed_control(fc
, dvbdmxfeed
, 0);
66 static int flexcop_dvb_init(struct flexcop_device
*fc
)
68 int ret
= dvb_register_adapter(&fc
->dvb_adapter
,
69 "FlexCop Digital TV device", fc
->owner
,
72 err("error registering DVB adapter");
75 fc
->dvb_adapter
.priv
= fc
;
77 fc
->demux
.dmx
.capabilities
= (DMX_TS_FILTERING
| DMX_SECTION_FILTERING
78 | DMX_MEMORY_BASED_FILTERING
);
80 fc
->demux
.filternum
= fc
->demux
.feednum
= FC_MAX_FEED
;
81 fc
->demux
.start_feed
= flexcop_dvb_start_feed
;
82 fc
->demux
.stop_feed
= flexcop_dvb_stop_feed
;
83 fc
->demux
.write_to_decoder
= NULL
;
85 ret
= dvb_dmx_init(&fc
->demux
);
87 err("dvb_dmx failed: error %d", ret
);
91 fc
->hw_frontend
.source
= DMX_FRONTEND_0
;
93 fc
->dmxdev
.filternum
= fc
->demux
.feednum
;
94 fc
->dmxdev
.demux
= &fc
->demux
.dmx
;
95 fc
->dmxdev
.capabilities
= 0;
96 ret
= dvb_dmxdev_init(&fc
->dmxdev
, &fc
->dvb_adapter
);
98 err("dvb_dmxdev_init failed: error %d", ret
);
102 ret
= fc
->demux
.dmx
.add_frontend(&fc
->demux
.dmx
, &fc
->hw_frontend
);
104 err("adding hw_frontend to dmx failed: error %d", ret
);
105 goto err_dmx_add_hw_frontend
;
108 fc
->mem_frontend
.source
= DMX_MEMORY_FE
;
109 ret
= fc
->demux
.dmx
.add_frontend(&fc
->demux
.dmx
, &fc
->mem_frontend
);
111 err("adding mem_frontend to dmx failed: error %d", ret
);
112 goto err_dmx_add_mem_frontend
;
115 ret
= fc
->demux
.dmx
.connect_frontend(&fc
->demux
.dmx
, &fc
->hw_frontend
);
117 err("connect frontend failed: error %d", ret
);
118 goto err_connect_frontend
;
121 ret
= dvb_net_init(&fc
->dvb_adapter
, &fc
->dvbnet
, &fc
->demux
.dmx
);
123 err("dvb_net_init failed: error %d", ret
);
127 fc
->init_state
|= FC_STATE_DVB_INIT
;
131 fc
->demux
.dmx
.disconnect_frontend(&fc
->demux
.dmx
);
132 err_connect_frontend
:
133 fc
->demux
.dmx
.remove_frontend(&fc
->demux
.dmx
, &fc
->mem_frontend
);
134 err_dmx_add_mem_frontend
:
135 fc
->demux
.dmx
.remove_frontend(&fc
->demux
.dmx
, &fc
->hw_frontend
);
136 err_dmx_add_hw_frontend
:
137 dvb_dmxdev_release(&fc
->dmxdev
);
139 dvb_dmx_release(&fc
->demux
);
141 dvb_unregister_adapter(&fc
->dvb_adapter
);
145 static void flexcop_dvb_exit(struct flexcop_device
*fc
)
147 if (fc
->init_state
& FC_STATE_DVB_INIT
) {
148 dvb_net_release(&fc
->dvbnet
);
150 fc
->demux
.dmx
.close(&fc
->demux
.dmx
);
151 fc
->demux
.dmx
.remove_frontend(&fc
->demux
.dmx
,
153 fc
->demux
.dmx
.remove_frontend(&fc
->demux
.dmx
,
155 dvb_dmxdev_release(&fc
->dmxdev
);
156 dvb_dmx_release(&fc
->demux
);
157 dvb_unregister_adapter(&fc
->dvb_adapter
);
158 deb_info("deinitialized dvb stuff\n");
160 fc
->init_state
&= ~FC_STATE_DVB_INIT
;
163 /* these methods are necessary to achieve the long-term-goal of hiding the
164 * struct flexcop_device from the bus-parts */
165 void flexcop_pass_dmx_data(struct flexcop_device
*fc
, u8
*buf
, u32 len
)
167 dvb_dmx_swfilter(&fc
->demux
, buf
, len
);
169 EXPORT_SYMBOL(flexcop_pass_dmx_data
);
171 void flexcop_pass_dmx_packets(struct flexcop_device
*fc
, u8
*buf
, u32 no
)
173 dvb_dmx_swfilter_packets(&fc
->demux
, buf
, no
);
175 EXPORT_SYMBOL(flexcop_pass_dmx_packets
);
177 static void flexcop_reset(struct flexcop_device
*fc
)
179 flexcop_ibi_value v210
, v204
;
181 /* reset the flexcop itself */
182 fc
->write_ibi_reg(fc
,ctrl_208
,ibi_zero
);
185 v210
.sw_reset_210
.reset_block_000
= 1;
186 v210
.sw_reset_210
.reset_block_100
= 1;
187 v210
.sw_reset_210
.reset_block_200
= 1;
188 v210
.sw_reset_210
.reset_block_300
= 1;
189 v210
.sw_reset_210
.reset_block_400
= 1;
190 v210
.sw_reset_210
.reset_block_500
= 1;
191 v210
.sw_reset_210
.reset_block_600
= 1;
192 v210
.sw_reset_210
.reset_block_700
= 1;
193 v210
.sw_reset_210
.Block_reset_enable
= 0xb2;
194 v210
.sw_reset_210
.Special_controls
= 0xc259;
195 fc
->write_ibi_reg(fc
,sw_reset_210
,v210
);
198 /* reset the periphical devices */
200 v204
= fc
->read_ibi_reg(fc
,misc_204
);
201 v204
.misc_204
.Per_reset_sig
= 0;
202 fc
->write_ibi_reg(fc
,misc_204
,v204
);
204 v204
.misc_204
.Per_reset_sig
= 1;
205 fc
->write_ibi_reg(fc
,misc_204
,v204
);
208 void flexcop_reset_block_300(struct flexcop_device
*fc
)
210 flexcop_ibi_value v208_save
= fc
->read_ibi_reg(fc
, ctrl_208
),
211 v210
= fc
->read_ibi_reg(fc
, sw_reset_210
);
213 deb_rdump("208: %08x, 210: %08x\n", v208_save
.raw
, v210
.raw
);
214 fc
->write_ibi_reg(fc
,ctrl_208
,ibi_zero
);
216 v210
.sw_reset_210
.reset_block_300
= 1;
217 v210
.sw_reset_210
.Block_reset_enable
= 0xb2;
219 fc
->write_ibi_reg(fc
,sw_reset_210
,v210
);
220 fc
->write_ibi_reg(fc
,ctrl_208
,v208_save
);
223 struct flexcop_device
*flexcop_device_kmalloc(size_t bus_specific_len
)
226 struct flexcop_device
*fc
= kzalloc(sizeof(struct flexcop_device
),
233 bus
= kzalloc(bus_specific_len
, GFP_KERNEL
);
240 fc
->bus_specific
= bus
;
244 EXPORT_SYMBOL(flexcop_device_kmalloc
);
246 void flexcop_device_kfree(struct flexcop_device
*fc
)
248 kfree(fc
->bus_specific
);
251 EXPORT_SYMBOL(flexcop_device_kfree
);
253 int flexcop_device_initialize(struct flexcop_device
*fc
)
259 flexcop_determine_revision(fc
);
260 flexcop_sram_init(fc
);
261 flexcop_hw_filter_init(fc
);
262 flexcop_smc_ctrl(fc
, 0);
264 ret
= flexcop_dvb_init(fc
);
268 /* i2c has to be done before doing EEProm stuff -
269 * because the EEProm is accessed via i2c */
270 ret
= flexcop_i2c_init(fc
);
274 /* do the MAC address reading after initializing the dvb_adapter */
275 if (fc
->get_mac_addr(fc
, 0) == 0) {
276 u8
*b
= fc
->dvb_adapter
.proposed_mac
;
277 info("MAC address = %pM", b
);
278 flexcop_set_mac_filter(fc
,b
);
279 flexcop_mac_filter_ctrl(fc
,1);
281 warn("reading of MAC address failed.\n");
283 ret
= flexcop_frontend_init(fc
);
287 flexcop_device_name(fc
,"initialization of","complete");
291 flexcop_device_exit(fc
);
294 EXPORT_SYMBOL(flexcop_device_initialize
);
296 void flexcop_device_exit(struct flexcop_device
*fc
)
298 flexcop_frontend_exit(fc
);
299 flexcop_i2c_exit(fc
);
300 flexcop_dvb_exit(fc
);
302 EXPORT_SYMBOL(flexcop_device_exit
);
304 static int flexcop_module_init(void)
306 info(DRIVER_NAME
" loaded successfully");
310 static void flexcop_module_cleanup(void)
312 info(DRIVER_NAME
" unloaded successfully");
315 module_init(flexcop_module_init
);
316 module_exit(flexcop_module_cleanup
);
318 MODULE_AUTHOR(DRIVER_AUTHOR
);
319 MODULE_DESCRIPTION(DRIVER_NAME
);
320 MODULE_LICENSE("GPL");