aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/b2c2/flexcop.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/b2c2/flexcop.c')
-rw-r--r--drivers/media/dvb/b2c2/flexcop.c288
1 files changed, 288 insertions, 0 deletions
diff --git a/drivers/media/dvb/b2c2/flexcop.c b/drivers/media/dvb/b2c2/flexcop.c
new file mode 100644
index 000000000000..1998267207fb
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop.c
@@ -0,0 +1,288 @@
1/*
2 * flexcop.c - driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * Copyright (C) 2004-5 Patrick Boettcher <patrick.boettcher@desy.de>
5 *
6 * based on the skystar2-driver
7 * Copyright (C) 2003 Vadim Catana, skystar@moldova.cc
8 *
9 * Acknowledgements:
10 * John Jurrius from BBTI, Inc. for extensive support with
11 * code examples and data books
12 *
13 * Bjarne Steinsbo, bjarne at steinsbo.com (some ideas for rewriting)
14 *
15 * Contributions to the skystar2-driver have been done by
16 * Vincenzo Di Massa, hawk.it at tiscalinet.it (several DiSEqC fixes)
17 * Roberto Ragusa, r.ragusa at libero.it (polishing, restyling the code)
18 * Niklas Peinecke, peinecke at gdv.uni-hannover.de (hardware pid/mac filtering)
19 *
20 *
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public License
23 * as published by the Free Software Foundation; either version 2.1
24 * of the License, or (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 */
35
36#include "flexcop.h"
37
38#define DRIVER_NAME "B2C2 FlexcopII/II(b)/III digital TV receiver chip"
39#define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de"
40
41#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
42#define DEBSTATUS ""
43#else
44#define DEBSTATUS " (debugging is not enabled)"
45#endif
46
47int b2c2_flexcop_debug;
48module_param_named(debug, b2c2_flexcop_debug, int, 0644);
49MODULE_PARM_DESC(debug, "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram (|-able))." DEBSTATUS);
50#undef DEBSTATUS
51
52/* global zero for ibi values */
53flexcop_ibi_value ibi_zero;
54
55static int flexcop_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
56{
57 struct flexcop_device *fc = dvbdmxfeed->demux->priv;
58 return flexcop_pid_feed_control(fc,dvbdmxfeed,1);
59}
60
61static int flexcop_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
62{
63 struct flexcop_device *fc = dvbdmxfeed->demux->priv;
64 return flexcop_pid_feed_control(fc,dvbdmxfeed,0);
65}
66
67static int flexcop_dvb_init(struct flexcop_device *fc)
68{
69 int ret;
70 if ((ret = dvb_register_adapter(&fc->dvb_adapter,"FlexCop Digital TV device",THIS_MODULE)) < 0) {
71 err("error registering DVB adapter");
72 return ret;
73 }
74 fc->dvb_adapter.priv = fc;
75
76 fc->demux.dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
77 fc->demux.priv = fc;
78
79 fc->demux.filternum = fc->demux.feednum = FC_MAX_FEED;
80
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;
84
85 if ((ret = dvb_dmx_init(&fc->demux)) < 0) {
86 err("dvb_dmx failed: error %d",ret);
87 goto err_dmx;
88 }
89
90 fc->hw_frontend.source = DMX_FRONTEND_0;
91
92 fc->dmxdev.filternum = fc->demux.feednum;
93 fc->dmxdev.demux = &fc->demux.dmx;
94 fc->dmxdev.capabilities = 0;
95 if ((ret = dvb_dmxdev_init(&fc->dmxdev, &fc->dvb_adapter)) < 0) {
96 err("dvb_dmxdev_init failed: error %d",ret);
97 goto err_dmx_dev;
98 }
99
100 if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) {
101 err("adding hw_frontend to dmx failed: error %d",ret);
102 goto err_dmx_add_hw_frontend;
103 }
104
105 fc->mem_frontend.source = DMX_MEMORY_FE;
106 if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->mem_frontend)) < 0) {
107 err("adding mem_frontend to dmx failed: error %d",ret);
108 goto err_dmx_add_mem_frontend;
109 }
110
111 if ((ret = fc->demux.dmx.connect_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) {
112 err("connect frontend failed: error %d",ret);
113 goto err_connect_frontend;
114 }
115
116 dvb_net_init(&fc->dvb_adapter, &fc->dvbnet, &fc->demux.dmx);
117
118 fc->init_state |= FC_STATE_DVB_INIT;
119 goto success;
120
121err_connect_frontend:
122 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->mem_frontend);
123err_dmx_add_mem_frontend:
124 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->hw_frontend);
125err_dmx_add_hw_frontend:
126 dvb_dmxdev_release(&fc->dmxdev);
127err_dmx_dev:
128 dvb_dmx_release(&fc->demux);
129err_dmx:
130 dvb_unregister_adapter(&fc->dvb_adapter);
131 return ret;
132
133success:
134 return 0;
135}
136
137static void flexcop_dvb_exit(struct flexcop_device *fc)
138{
139 if (fc->init_state & FC_STATE_DVB_INIT) {
140 dvb_net_release(&fc->dvbnet);
141
142 fc->demux.dmx.close(&fc->demux.dmx);
143 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->mem_frontend);
144 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->hw_frontend);
145 dvb_dmxdev_release(&fc->dmxdev);
146 dvb_dmx_release(&fc->demux);
147 dvb_unregister_adapter(&fc->dvb_adapter);
148
149 deb_info("deinitialized dvb stuff\n");
150 }
151 fc->init_state &= ~FC_STATE_DVB_INIT;
152}
153
154/* these methods are necessary to achieve the long-term-goal of hiding the
155 * struct flexcop_device from the bus-parts */
156void flexcop_pass_dmx_data(struct flexcop_device *fc, u8 *buf, u32 len)
157{
158 dvb_dmx_swfilter(&fc->demux, buf, len);
159}
160EXPORT_SYMBOL(flexcop_pass_dmx_data);
161
162void flexcop_pass_dmx_packets(struct flexcop_device *fc, u8 *buf, u32 no)
163{
164 dvb_dmx_swfilter_packets(&fc->demux, buf, no);
165}
166EXPORT_SYMBOL(flexcop_pass_dmx_packets);
167
168static void flexcop_reset(struct flexcop_device *fc)
169{
170 flexcop_ibi_value v210,v204;
171
172/* reset the flexcop itself */
173 fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
174
175 v210.raw = 0;
176 v210.sw_reset_210.reset_blocks = 0xff;
177 v210.sw_reset_210.Block_reset_enable = 0xb2;
178 fc->write_ibi_reg(fc,sw_reset_210,v210);
179
180/* reset the periphical devices */
181
182 v204 = fc->read_ibi_reg(fc,misc_204);
183 v204.misc_204.Per_reset_sig = 0;
184 fc->write_ibi_reg(fc,misc_204,v204);
185 v204.misc_204.Per_reset_sig = 1;
186 fc->write_ibi_reg(fc,misc_204,v204);
187
188/* v208.raw = 0;
189 v208.ctrl_208.Null_filter_sig = 1;
190 fc->write_ibi_reg(fc,ctrl_208,v208);*/
191}
192
193struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len)
194{
195 void *bus;
196 struct flexcop_device *fc = kmalloc(sizeof(struct flexcop_device), GFP_KERNEL);
197 if (!fc) {
198 err("no memory");
199 return NULL;
200 }
201 memset(fc, 0, sizeof(struct flexcop_device));
202
203 bus = kmalloc(bus_specific_len, GFP_KERNEL);
204 if (!bus) {
205 err("no memory");
206 kfree(fc);
207 return NULL;
208 }
209 memset(bus, 0, bus_specific_len);
210
211 fc->bus_specific = bus;
212
213 return fc;
214}
215EXPORT_SYMBOL(flexcop_device_kmalloc);
216
217void flexcop_device_kfree(struct flexcop_device *fc)
218{
219 kfree(fc->bus_specific);
220 kfree(fc);
221}
222EXPORT_SYMBOL(flexcop_device_kfree);
223
224int flexcop_device_initialize(struct flexcop_device *fc)
225{
226 int ret;
227 ibi_zero.raw = 0;
228
229 flexcop_reset(fc);
230 flexcop_determine_revision(fc);
231 flexcop_sram_init(fc);
232 flexcop_hw_filter_init(fc);
233
234 flexcop_smc_ctrl(fc, 0);
235
236 if (fc->get_mac_addr(fc, 0) == 0) {
237 u8 *b = fc->mac_address;
238 info("MAC address = %02x:%02x:%02x:%02x:%02x:%02x", b[0],b[1],b[2],b[3],b[4],b[5]);
239 flexcop_set_mac_filter(fc,fc->mac_address);
240 flexcop_mac_filter_ctrl(fc,1);
241 } else
242 warn("reading of MAC address failed.\n");
243
244 if ((ret = flexcop_dvb_init(fc)))
245 goto error;
246
247 if ((ret = flexcop_i2c_init(fc)))
248 goto error;
249
250 if ((ret = flexcop_frontend_init(fc)))
251 goto error;
252
253 flexcop_device_name(fc,"initialization of","complete");
254
255 ret = 0;
256 goto success;
257error:
258 flexcop_device_exit(fc);
259success:
260 return ret;
261}
262EXPORT_SYMBOL(flexcop_device_initialize);
263
264void flexcop_device_exit(struct flexcop_device *fc)
265{
266 flexcop_frontend_exit(fc);
267 flexcop_i2c_exit(fc);
268 flexcop_dvb_exit(fc);
269}
270EXPORT_SYMBOL(flexcop_device_exit);
271
272static int flexcop_module_init(void)
273{
274 info(DRIVER_NAME " loaded successfully");
275 return 0;
276}
277
278static void flexcop_module_cleanup(void)
279{
280 info(DRIVER_NAME " unloaded successfully");
281}
282
283module_init(flexcop_module_init);
284module_exit(flexcop_module_cleanup);
285
286MODULE_AUTHOR(DRIVER_AUTHOR);
287MODULE_DESCRIPTION(DRIVER_NAME);
288MODULE_LICENSE("GPL");