diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/media/dvb/bt8xx/dvb-bt8xx.c |
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/media/dvb/bt8xx/dvb-bt8xx.c')
-rw-r--r-- | drivers/media/dvb/bt8xx/dvb-bt8xx.c | 797 |
1 files changed, 797 insertions, 0 deletions
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c new file mode 100644 index 00000000000..b735397f59a --- /dev/null +++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c | |||
@@ -0,0 +1,797 @@ | |||
1 | /* | ||
2 | * Bt8xx based DVB adapter driver | ||
3 | * | ||
4 | * Copyright (C) 2002,2003 Florian Schirmer <jolt@tuxbox.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <linux/bitops.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/moduleparam.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/device.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/i2c.h> | ||
30 | |||
31 | #include "dmxdev.h" | ||
32 | #include "dvbdev.h" | ||
33 | #include "dvb_demux.h" | ||
34 | #include "dvb_frontend.h" | ||
35 | |||
36 | #include "dvb-bt8xx.h" | ||
37 | |||
38 | #include "bt878.h" | ||
39 | |||
40 | static int debug; | ||
41 | |||
42 | module_param(debug, int, 0644); | ||
43 | MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); | ||
44 | |||
45 | #define dprintk( args... ) \ | ||
46 | do { \ | ||
47 | if (debug) printk(KERN_DEBUG args); \ | ||
48 | } while (0) | ||
49 | |||
50 | static void dvb_bt8xx_task(unsigned long data) | ||
51 | { | ||
52 | struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *)data; | ||
53 | |||
54 | //printk("%d ", card->bt->finished_block); | ||
55 | |||
56 | while (card->bt->last_block != card->bt->finished_block) { | ||
57 | (card->bt->TS_Size ? dvb_dmx_swfilter_204 : dvb_dmx_swfilter) | ||
58 | (&card->demux, | ||
59 | &card->bt->buf_cpu[card->bt->last_block * | ||
60 | card->bt->block_bytes], | ||
61 | card->bt->block_bytes); | ||
62 | card->bt->last_block = (card->bt->last_block + 1) % | ||
63 | card->bt->block_count; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | static int dvb_bt8xx_start_feed(struct dvb_demux_feed *dvbdmxfeed) | ||
68 | { | ||
69 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; | ||
70 | struct dvb_bt8xx_card *card = dvbdmx->priv; | ||
71 | int rc; | ||
72 | |||
73 | dprintk("dvb_bt8xx: start_feed\n"); | ||
74 | |||
75 | if (!dvbdmx->dmx.frontend) | ||
76 | return -EINVAL; | ||
77 | |||
78 | down(&card->lock); | ||
79 | card->nfeeds++; | ||
80 | rc = card->nfeeds; | ||
81 | if (card->nfeeds == 1) | ||
82 | bt878_start(card->bt, card->gpio_mode, | ||
83 | card->op_sync_orin, card->irq_err_ignore); | ||
84 | up(&card->lock); | ||
85 | return rc; | ||
86 | } | ||
87 | |||
88 | static int dvb_bt8xx_stop_feed(struct dvb_demux_feed *dvbdmxfeed) | ||
89 | { | ||
90 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; | ||
91 | struct dvb_bt8xx_card *card = dvbdmx->priv; | ||
92 | |||
93 | dprintk("dvb_bt8xx: stop_feed\n"); | ||
94 | |||
95 | if (!dvbdmx->dmx.frontend) | ||
96 | return -EINVAL; | ||
97 | |||
98 | down(&card->lock); | ||
99 | card->nfeeds--; | ||
100 | if (card->nfeeds == 0) | ||
101 | bt878_stop(card->bt); | ||
102 | up(&card->lock); | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static int is_pci_slot_eq(struct pci_dev* adev, struct pci_dev* bdev) | ||
108 | { | ||
109 | if ((adev->subsystem_vendor == bdev->subsystem_vendor) && | ||
110 | (adev->subsystem_device == bdev->subsystem_device) && | ||
111 | (adev->bus->number == bdev->bus->number) && | ||
112 | (PCI_SLOT(adev->devfn) == PCI_SLOT(bdev->devfn))) | ||
113 | return 1; | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | static struct bt878 __init *dvb_bt8xx_878_match(unsigned int bttv_nr, struct pci_dev* bttv_pci_dev) | ||
118 | { | ||
119 | unsigned int card_nr; | ||
120 | |||
121 | /* Hmm, n squared. Hope n is small */ | ||
122 | for (card_nr = 0; card_nr < bt878_num; card_nr++) { | ||
123 | if (is_pci_slot_eq(bt878[card_nr].dev, bttv_pci_dev)) | ||
124 | return &bt878[card_nr]; | ||
125 | } | ||
126 | return NULL; | ||
127 | } | ||
128 | |||
129 | |||
130 | static int thomson_dtt7579_demod_init(struct dvb_frontend* fe) | ||
131 | { | ||
132 | static u8 mt352_clock_config [] = { 0x89, 0x38, 0x38 }; | ||
133 | static u8 mt352_reset [] = { 0x50, 0x80 }; | ||
134 | static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 }; | ||
135 | static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0x20 }; | ||
136 | static u8 mt352_gpp_ctl_cfg [] = { 0x8C, 0x33 }; | ||
137 | static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; | ||
138 | |||
139 | mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); | ||
140 | udelay(2000); | ||
141 | mt352_write(fe, mt352_reset, sizeof(mt352_reset)); | ||
142 | mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); | ||
143 | |||
144 | mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg)); | ||
145 | mt352_write(fe, mt352_gpp_ctl_cfg, sizeof(mt352_gpp_ctl_cfg)); | ||
146 | mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg)); | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static int thomson_dtt7579_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf) | ||
152 | { | ||
153 | u32 div; | ||
154 | unsigned char bs = 0; | ||
155 | unsigned char cp = 0; | ||
156 | |||
157 | #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */ | ||
158 | div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; | ||
159 | |||
160 | if (params->frequency < 542000000) cp = 0xb4; | ||
161 | else if (params->frequency < 771000000) cp = 0xbc; | ||
162 | else cp = 0xf4; | ||
163 | |||
164 | if (params->frequency == 0) bs = 0x03; | ||
165 | else if (params->frequency < 443250000) bs = 0x02; | ||
166 | else bs = 0x08; | ||
167 | |||
168 | pllbuf[0] = 0xc0; // Note: non-linux standard PLL i2c address | ||
169 | pllbuf[1] = div >> 8; | ||
170 | pllbuf[2] = div & 0xff; | ||
171 | pllbuf[3] = cp; | ||
172 | pllbuf[4] = bs; | ||
173 | |||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | static struct mt352_config thomson_dtt7579_config = { | ||
178 | |||
179 | .demod_address = 0x0f, | ||
180 | .demod_init = thomson_dtt7579_demod_init, | ||
181 | .pll_set = thomson_dtt7579_pll_set, | ||
182 | }; | ||
183 | |||
184 | static int cx24108_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) | ||
185 | { | ||
186 | u32 freq = params->frequency; | ||
187 | |||
188 | int i, a, n, pump; | ||
189 | u32 band, pll; | ||
190 | |||
191 | |||
192 | u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000, | ||
193 | 1576000,1718000,1856000,2036000,2150000}; | ||
194 | u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000, | ||
195 | 0x00102000,0x00104000,0x00108000,0x00110000, | ||
196 | 0x00120000,0x00140000}; | ||
197 | |||
198 | #define XTAL 1011100 /* Hz, really 1.0111 MHz and a /10 prescaler */ | ||
199 | printk("cx24108 debug: entering SetTunerFreq, freq=%d\n",freq); | ||
200 | |||
201 | /* This is really the bit driving the tuner chip cx24108 */ | ||
202 | |||
203 | if(freq<950000) freq=950000; /* kHz */ | ||
204 | if(freq>2150000) freq=2150000; /* satellite IF is 950..2150MHz */ | ||
205 | |||
206 | /* decide which VCO to use for the input frequency */ | ||
207 | for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++); | ||
208 | printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq); | ||
209 | band=bandsel[i]; | ||
210 | /* the gain values must be set by SetSymbolrate */ | ||
211 | /* compute the pll divider needed, from Conexant data sheet, | ||
212 | resolved for (n*32+a), remember f(vco) is f(receive) *2 or *4, | ||
213 | depending on the divider bit. It is set to /4 on the 2 lowest | ||
214 | bands */ | ||
215 | n=((i<=2?2:1)*freq*10L)/(XTAL/100); | ||
216 | a=n%32; n/=32; if(a==0) n--; | ||
217 | pump=(freq<(osci[i-1]+osci[i])/2); | ||
218 | pll=0xf8000000| | ||
219 | ((pump?1:2)<<(14+11))| | ||
220 | ((n&0x1ff)<<(5+11))| | ||
221 | ((a&0x1f)<<11); | ||
222 | /* everything is shifted left 11 bits to left-align the bits in the | ||
223 | 32bit word. Output to the tuner goes MSB-aligned, after all */ | ||
224 | printk("cx24108 debug: pump=%d, n=%d, a=%d\n",pump,n,a); | ||
225 | cx24110_pll_write(fe,band); | ||
226 | /* set vga and vca to their widest-band settings, as a precaution. | ||
227 | SetSymbolrate might not be called to set this up */ | ||
228 | cx24110_pll_write(fe,0x500c0000); | ||
229 | cx24110_pll_write(fe,0x83f1f800); | ||
230 | cx24110_pll_write(fe,pll); | ||
231 | /* writereg(client,0x56,0x7f);*/ | ||
232 | |||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | static int pinnsat_pll_init(struct dvb_frontend* fe) | ||
237 | { | ||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | |||
242 | static struct cx24110_config pctvsat_config = { | ||
243 | |||
244 | .demod_address = 0x55, | ||
245 | .pll_init = pinnsat_pll_init, | ||
246 | .pll_set = cx24108_pll_set, | ||
247 | }; | ||
248 | |||
249 | |||
250 | static int microtune_mt7202dtf_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) | ||
251 | { | ||
252 | struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv; | ||
253 | u8 cfg, cpump, band_select; | ||
254 | u8 data[4]; | ||
255 | u32 div; | ||
256 | struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = data, .len = sizeof(data) }; | ||
257 | |||
258 | div = (36000000 + params->frequency + 83333) / 166666; | ||
259 | cfg = 0x88; | ||
260 | |||
261 | if (params->frequency < 175000000) cpump = 2; | ||
262 | else if (params->frequency < 390000000) cpump = 1; | ||
263 | else if (params->frequency < 470000000) cpump = 2; | ||
264 | else if (params->frequency < 750000000) cpump = 2; | ||
265 | else cpump = 3; | ||
266 | |||
267 | if (params->frequency < 175000000) band_select = 0x0e; | ||
268 | else if (params->frequency < 470000000) band_select = 0x05; | ||
269 | else band_select = 0x03; | ||
270 | |||
271 | data[0] = (div >> 8) & 0x7f; | ||
272 | data[1] = div & 0xff; | ||
273 | data[2] = ((div >> 10) & 0x60) | cfg; | ||
274 | data[3] = cpump | band_select; | ||
275 | |||
276 | i2c_transfer(card->i2c_adapter, &msg, 1); | ||
277 | return (div * 166666 - 36000000); | ||
278 | } | ||
279 | |||
280 | static int microtune_mt7202dtf_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) | ||
281 | { | ||
282 | struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv; | ||
283 | |||
284 | return request_firmware(fw, name, &bt->bt->dev->dev); | ||
285 | } | ||
286 | |||
287 | static struct sp887x_config microtune_mt7202dtf_config = { | ||
288 | |||
289 | .demod_address = 0x70, | ||
290 | .pll_set = microtune_mt7202dtf_pll_set, | ||
291 | .request_firmware = microtune_mt7202dtf_request_firmware, | ||
292 | }; | ||
293 | |||
294 | |||
295 | |||
296 | static int advbt771_samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe) | ||
297 | { | ||
298 | static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d }; | ||
299 | static u8 mt352_reset [] = { 0x50, 0x80 }; | ||
300 | static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 }; | ||
301 | static u8 mt352_agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF, | ||
302 | 0x00, 0xFF, 0x00, 0x40, 0x40 }; | ||
303 | static u8 mt352_av771_extra[] = { 0xB5, 0x7A }; | ||
304 | static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; | ||
305 | |||
306 | |||
307 | mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); | ||
308 | udelay(2000); | ||
309 | mt352_write(fe, mt352_reset, sizeof(mt352_reset)); | ||
310 | mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); | ||
311 | |||
312 | mt352_write(fe, mt352_agc_cfg,sizeof(mt352_agc_cfg)); | ||
313 | udelay(2000); | ||
314 | mt352_write(fe, mt352_av771_extra,sizeof(mt352_av771_extra)); | ||
315 | mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg)); | ||
316 | |||
317 | return 0; | ||
318 | } | ||
319 | |||
320 | static int advbt771_samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf) | ||
321 | { | ||
322 | u32 div; | ||
323 | unsigned char bs = 0; | ||
324 | unsigned char cp = 0; | ||
325 | |||
326 | #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */ | ||
327 | div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; | ||
328 | |||
329 | if (params->frequency < 150000000) cp = 0xB4; | ||
330 | else if (params->frequency < 173000000) cp = 0xBC; | ||
331 | else if (params->frequency < 250000000) cp = 0xB4; | ||
332 | else if (params->frequency < 400000000) cp = 0xBC; | ||
333 | else if (params->frequency < 420000000) cp = 0xF4; | ||
334 | else if (params->frequency < 470000000) cp = 0xFC; | ||
335 | else if (params->frequency < 600000000) cp = 0xBC; | ||
336 | else if (params->frequency < 730000000) cp = 0xF4; | ||
337 | else cp = 0xFC; | ||
338 | |||
339 | if (params->frequency < 150000000) bs = 0x01; | ||
340 | else if (params->frequency < 173000000) bs = 0x01; | ||
341 | else if (params->frequency < 250000000) bs = 0x02; | ||
342 | else if (params->frequency < 400000000) bs = 0x02; | ||
343 | else if (params->frequency < 420000000) bs = 0x02; | ||
344 | else if (params->frequency < 470000000) bs = 0x02; | ||
345 | else if (params->frequency < 600000000) bs = 0x08; | ||
346 | else if (params->frequency < 730000000) bs = 0x08; | ||
347 | else bs = 0x08; | ||
348 | |||
349 | pllbuf[0] = 0xc2; // Note: non-linux standard PLL i2c address | ||
350 | pllbuf[1] = div >> 8; | ||
351 | pllbuf[2] = div & 0xff; | ||
352 | pllbuf[3] = cp; | ||
353 | pllbuf[4] = bs; | ||
354 | |||
355 | return 0; | ||
356 | } | ||
357 | |||
358 | static struct mt352_config advbt771_samsung_tdtc9251dh0_config = { | ||
359 | |||
360 | .demod_address = 0x0f, | ||
361 | .demod_init = advbt771_samsung_tdtc9251dh0_demod_init, | ||
362 | .pll_set = advbt771_samsung_tdtc9251dh0_pll_set, | ||
363 | }; | ||
364 | |||
365 | |||
366 | static struct dst_config dst_config = { | ||
367 | |||
368 | .demod_address = 0x55, | ||
369 | }; | ||
370 | |||
371 | |||
372 | static int or51211_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) | ||
373 | { | ||
374 | struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv; | ||
375 | |||
376 | return request_firmware(fw, name, &bt->bt->dev->dev); | ||
377 | } | ||
378 | |||
379 | static void or51211_setmode(struct dvb_frontend * fe, int mode) | ||
380 | { | ||
381 | struct dvb_bt8xx_card *bt = fe->dvb->priv; | ||
382 | bttv_write_gpio(bt->bttv_nr, 0x0002, mode); /* Reset */ | ||
383 | msleep(20); | ||
384 | } | ||
385 | |||
386 | static void or51211_reset(struct dvb_frontend * fe) | ||
387 | { | ||
388 | struct dvb_bt8xx_card *bt = fe->dvb->priv; | ||
389 | |||
390 | /* RESET DEVICE | ||
391 | * reset is controled by GPIO-0 | ||
392 | * when set to 0 causes reset and when to 1 for normal op | ||
393 | * must remain reset for 128 clock cycles on a 50Mhz clock | ||
394 | * also PRM1 PRM2 & PRM4 are controled by GPIO-1,GPIO-2 & GPIO-4 | ||
395 | * We assume that the reset has be held low long enough or we | ||
396 | * have been reset by a power on. When the driver is unloaded | ||
397 | * reset set to 0 so if reloaded we have been reset. | ||
398 | */ | ||
399 | /* reset & PRM1,2&4 are outputs */ | ||
400 | int ret = bttv_gpio_enable(bt->bttv_nr, 0x001F, 0x001F); | ||
401 | if (ret != 0) { | ||
402 | printk(KERN_WARNING "or51211: Init Error - Can't Reset DVR " | ||
403 | "(%i)\n", ret); | ||
404 | } | ||
405 | bttv_write_gpio(bt->bttv_nr, 0x001F, 0x0000); /* Reset */ | ||
406 | msleep(20); | ||
407 | /* Now set for normal operation */ | ||
408 | bttv_write_gpio(bt->bttv_nr, 0x0001F, 0x0001); | ||
409 | /* wait for operation to begin */ | ||
410 | msleep(500); | ||
411 | } | ||
412 | |||
413 | static void or51211_sleep(struct dvb_frontend * fe) | ||
414 | { | ||
415 | struct dvb_bt8xx_card *bt = fe->dvb->priv; | ||
416 | bttv_write_gpio(bt->bttv_nr, 0x0001, 0x0000); | ||
417 | } | ||
418 | |||
419 | static struct or51211_config or51211_config = { | ||
420 | |||
421 | .demod_address = 0x15, | ||
422 | .request_firmware = or51211_request_firmware, | ||
423 | .setmode = or51211_setmode, | ||
424 | .reset = or51211_reset, | ||
425 | .sleep = or51211_sleep, | ||
426 | }; | ||
427 | |||
428 | |||
429 | static int vp3021_alps_tded4_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) | ||
430 | { | ||
431 | struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv; | ||
432 | u8 buf[4]; | ||
433 | u32 div; | ||
434 | struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf) }; | ||
435 | |||
436 | div = (params->frequency + 36166667) / 166667; | ||
437 | |||
438 | buf[0] = (div >> 8) & 0x7F; | ||
439 | buf[1] = div & 0xFF; | ||
440 | buf[2] = 0x85; | ||
441 | if ((params->frequency >= 47000000) && (params->frequency < 153000000)) | ||
442 | buf[3] = 0x01; | ||
443 | else if ((params->frequency >= 153000000) && (params->frequency < 430000000)) | ||
444 | buf[3] = 0x02; | ||
445 | else if ((params->frequency >= 430000000) && (params->frequency < 824000000)) | ||
446 | buf[3] = 0x0C; | ||
447 | else if ((params->frequency >= 824000000) && (params->frequency < 863000000)) | ||
448 | buf[3] = 0x8C; | ||
449 | else | ||
450 | return -EINVAL; | ||
451 | |||
452 | i2c_transfer(card->i2c_adapter, &msg, 1); | ||
453 | return 0; | ||
454 | } | ||
455 | |||
456 | static struct nxt6000_config vp3021_alps_tded4_config = { | ||
457 | |||
458 | .demod_address = 0x0a, | ||
459 | .clock_inversion = 1, | ||
460 | .pll_set = vp3021_alps_tded4_pll_set, | ||
461 | }; | ||
462 | |||
463 | |||
464 | static void frontend_init(struct dvb_bt8xx_card *card, u32 type) | ||
465 | { | ||
466 | switch(type) { | ||
467 | #ifdef BTTV_DVICO_DVBT_LITE | ||
468 | case BTTV_DVICO_DVBT_LITE: | ||
469 | card->fe = mt352_attach(&thomson_dtt7579_config, card->i2c_adapter); | ||
470 | if (card->fe != NULL) { | ||
471 | card->fe->ops->info.frequency_min = 174000000; | ||
472 | card->fe->ops->info.frequency_max = 862000000; | ||
473 | break; | ||
474 | } | ||
475 | break; | ||
476 | #endif | ||
477 | |||
478 | #ifdef BTTV_TWINHAN_VP3021 | ||
479 | case BTTV_TWINHAN_VP3021: | ||
480 | #else | ||
481 | case BTTV_NEBULA_DIGITV: | ||
482 | #endif | ||
483 | card->fe = nxt6000_attach(&vp3021_alps_tded4_config, card->i2c_adapter); | ||
484 | if (card->fe != NULL) { | ||
485 | break; | ||
486 | } | ||
487 | break; | ||
488 | |||
489 | case BTTV_AVDVBT_761: | ||
490 | card->fe = sp887x_attach(µtune_mt7202dtf_config, card->i2c_adapter); | ||
491 | if (card->fe != NULL) { | ||
492 | break; | ||
493 | } | ||
494 | break; | ||
495 | |||
496 | case BTTV_AVDVBT_771: | ||
497 | card->fe = mt352_attach(&advbt771_samsung_tdtc9251dh0_config, card->i2c_adapter); | ||
498 | if (card->fe != NULL) { | ||
499 | card->fe->ops->info.frequency_min = 174000000; | ||
500 | card->fe->ops->info.frequency_max = 862000000; | ||
501 | break; | ||
502 | } | ||
503 | break; | ||
504 | |||
505 | case BTTV_TWINHAN_DST: | ||
506 | card->fe = dst_attach(&dst_config, card->i2c_adapter, card->bt); | ||
507 | if (card->fe != NULL) { | ||
508 | break; | ||
509 | } | ||
510 | break; | ||
511 | |||
512 | case BTTV_PINNACLESAT: | ||
513 | card->fe = cx24110_attach(&pctvsat_config, card->i2c_adapter); | ||
514 | if (card->fe != NULL) { | ||
515 | break; | ||
516 | } | ||
517 | break; | ||
518 | |||
519 | case BTTV_PC_HDTV: | ||
520 | card->fe = or51211_attach(&or51211_config, card->i2c_adapter); | ||
521 | if (card->fe != NULL) { | ||
522 | break; | ||
523 | } | ||
524 | break; | ||
525 | } | ||
526 | |||
527 | if (card->fe == NULL) { | ||
528 | printk("dvb-bt8xx: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", | ||
529 | card->bt->dev->vendor, | ||
530 | card->bt->dev->device, | ||
531 | card->bt->dev->subsystem_vendor, | ||
532 | card->bt->dev->subsystem_device); | ||
533 | } else { | ||
534 | if (dvb_register_frontend(card->dvb_adapter, card->fe)) { | ||
535 | printk("dvb-bt8xx: Frontend registration failed!\n"); | ||
536 | if (card->fe->ops->release) | ||
537 | card->fe->ops->release(card->fe); | ||
538 | card->fe = NULL; | ||
539 | } | ||
540 | } | ||
541 | } | ||
542 | |||
543 | static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type) | ||
544 | { | ||
545 | int result; | ||
546 | |||
547 | if ((result = dvb_register_adapter(&card->dvb_adapter, card->card_name, | ||
548 | THIS_MODULE)) < 0) { | ||
549 | printk("dvb_bt8xx: dvb_register_adapter failed (errno = %d)\n", result); | ||
550 | return result; | ||
551 | |||
552 | } | ||
553 | card->dvb_adapter->priv = card; | ||
554 | |||
555 | card->bt->adapter = card->i2c_adapter; | ||
556 | |||
557 | memset(&card->demux, 0, sizeof(struct dvb_demux)); | ||
558 | |||
559 | card->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING; | ||
560 | |||
561 | card->demux.priv = card; | ||
562 | card->demux.filternum = 256; | ||
563 | card->demux.feednum = 256; | ||
564 | card->demux.start_feed = dvb_bt8xx_start_feed; | ||
565 | card->demux.stop_feed = dvb_bt8xx_stop_feed; | ||
566 | card->demux.write_to_decoder = NULL; | ||
567 | |||
568 | if ((result = dvb_dmx_init(&card->demux)) < 0) { | ||
569 | printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result); | ||
570 | |||
571 | dvb_unregister_adapter(card->dvb_adapter); | ||
572 | return result; | ||
573 | } | ||
574 | |||
575 | card->dmxdev.filternum = 256; | ||
576 | card->dmxdev.demux = &card->demux.dmx; | ||
577 | card->dmxdev.capabilities = 0; | ||
578 | |||
579 | if ((result = dvb_dmxdev_init(&card->dmxdev, card->dvb_adapter)) < 0) { | ||
580 | printk("dvb_bt8xx: dvb_dmxdev_init failed (errno = %d)\n", result); | ||
581 | |||
582 | dvb_dmx_release(&card->demux); | ||
583 | dvb_unregister_adapter(card->dvb_adapter); | ||
584 | return result; | ||
585 | } | ||
586 | |||
587 | card->fe_hw.source = DMX_FRONTEND_0; | ||
588 | |||
589 | if ((result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_hw)) < 0) { | ||
590 | printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result); | ||
591 | |||
592 | dvb_dmxdev_release(&card->dmxdev); | ||
593 | dvb_dmx_release(&card->demux); | ||
594 | dvb_unregister_adapter(card->dvb_adapter); | ||
595 | return result; | ||
596 | } | ||
597 | |||
598 | card->fe_mem.source = DMX_MEMORY_FE; | ||
599 | |||
600 | if ((result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_mem)) < 0) { | ||
601 | printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result); | ||
602 | |||
603 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); | ||
604 | dvb_dmxdev_release(&card->dmxdev); | ||
605 | dvb_dmx_release(&card->demux); | ||
606 | dvb_unregister_adapter(card->dvb_adapter); | ||
607 | return result; | ||
608 | } | ||
609 | |||
610 | if ((result = card->demux.dmx.connect_frontend(&card->demux.dmx, &card->fe_hw)) < 0) { | ||
611 | printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result); | ||
612 | |||
613 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem); | ||
614 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); | ||
615 | dvb_dmxdev_release(&card->dmxdev); | ||
616 | dvb_dmx_release(&card->demux); | ||
617 | dvb_unregister_adapter(card->dvb_adapter); | ||
618 | return result; | ||
619 | } | ||
620 | |||
621 | dvb_net_init(card->dvb_adapter, &card->dvbnet, &card->demux.dmx); | ||
622 | |||
623 | tasklet_init(&card->bt->tasklet, dvb_bt8xx_task, (unsigned long) card); | ||
624 | |||
625 | frontend_init(card, type); | ||
626 | |||
627 | return 0; | ||
628 | } | ||
629 | |||
630 | static int dvb_bt8xx_probe(struct device *dev) | ||
631 | { | ||
632 | struct bttv_sub_device *sub = to_bttv_sub_dev(dev); | ||
633 | struct dvb_bt8xx_card *card; | ||
634 | struct pci_dev* bttv_pci_dev; | ||
635 | int ret; | ||
636 | |||
637 | if (!(card = kmalloc(sizeof(struct dvb_bt8xx_card), GFP_KERNEL))) | ||
638 | return -ENOMEM; | ||
639 | |||
640 | memset(card, 0, sizeof(*card)); | ||
641 | init_MUTEX(&card->lock); | ||
642 | card->bttv_nr = sub->core->nr; | ||
643 | strncpy(card->card_name, sub->core->name, sizeof(sub->core->name)); | ||
644 | card->i2c_adapter = &sub->core->i2c_adap; | ||
645 | |||
646 | switch(sub->core->type) | ||
647 | { | ||
648 | case BTTV_PINNACLESAT: | ||
649 | card->gpio_mode = 0x0400c060; | ||
650 | /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR, | ||
651 | BT878_DA_IOM=1,BT878_DA_APP to enable serial highspeed mode. */ | ||
652 | card->op_sync_orin = 0; | ||
653 | card->irq_err_ignore = 0; | ||
654 | break; | ||
655 | |||
656 | #ifdef BTTV_DVICO_DVBT_LITE | ||
657 | case BTTV_DVICO_DVBT_LITE: | ||
658 | #endif | ||
659 | card->gpio_mode = 0x0400C060; | ||
660 | card->op_sync_orin = 0; | ||
661 | card->irq_err_ignore = 0; | ||
662 | /* 26, 15, 14, 6, 5 | ||
663 | * A_PWRDN DA_DPM DA_SBR DA_IOM_DA | ||
664 | * DA_APP(parallel) */ | ||
665 | break; | ||
666 | |||
667 | #ifdef BTTV_TWINHAN_VP3021 | ||
668 | case BTTV_TWINHAN_VP3021: | ||
669 | #else | ||
670 | case BTTV_NEBULA_DIGITV: | ||
671 | #endif | ||
672 | case BTTV_AVDVBT_761: | ||
673 | card->gpio_mode = (1 << 26) | (1 << 14) | (1 << 5); | ||
674 | card->op_sync_orin = 0; | ||
675 | card->irq_err_ignore = 0; | ||
676 | /* A_PWRDN DA_SBR DA_APP (high speed serial) */ | ||
677 | break; | ||
678 | |||
679 | case BTTV_AVDVBT_771: //case 0x07711461: | ||
680 | card->gpio_mode = 0x0400402B; | ||
681 | card->op_sync_orin = BT878_RISC_SYNC_MASK; | ||
682 | card->irq_err_ignore = 0; | ||
683 | /* A_PWRDN DA_SBR DA_APP[0] PKTP=10 RISC_ENABLE FIFO_ENABLE*/ | ||
684 | break; | ||
685 | |||
686 | case BTTV_TWINHAN_DST: | ||
687 | card->gpio_mode = 0x2204f2c; | ||
688 | card->op_sync_orin = BT878_RISC_SYNC_MASK; | ||
689 | card->irq_err_ignore = BT878_APABORT | BT878_ARIPERR | | ||
690 | BT878_APPERR | BT878_AFBUS; | ||
691 | /* 25,21,14,11,10,9,8,3,2 then | ||
692 | * 0x33 = 5,4,1,0 | ||
693 | * A_SEL=SML, DA_MLB, DA_SBR, | ||
694 | * DA_SDR=f, fifo trigger = 32 DWORDS | ||
695 | * IOM = 0 == audio A/D | ||
696 | * DPM = 0 == digital audio mode | ||
697 | * == async data parallel port | ||
698 | * then 0x33 (13 is set by start_capture) | ||
699 | * DA_APP = async data parallel port, | ||
700 | * ACAP_EN = 1, | ||
701 | * RISC+FIFO ENABLE */ | ||
702 | break; | ||
703 | |||
704 | case BTTV_PC_HDTV: | ||
705 | card->gpio_mode = 0x0100EC7B; | ||
706 | card->op_sync_orin = 0; | ||
707 | card->irq_err_ignore = 0; | ||
708 | break; | ||
709 | |||
710 | default: | ||
711 | printk(KERN_WARNING "dvb_bt8xx: Unknown bttv card type: %d.\n", | ||
712 | sub->core->type); | ||
713 | kfree(card); | ||
714 | return -ENODEV; | ||
715 | } | ||
716 | |||
717 | dprintk("dvb_bt8xx: identified card%d as %s\n", card->bttv_nr, card->card_name); | ||
718 | |||
719 | if (!(bttv_pci_dev = bttv_get_pcidev(card->bttv_nr))) { | ||
720 | printk("dvb_bt8xx: no pci device for card %d\n", card->bttv_nr); | ||
721 | kfree(card); | ||
722 | return -EFAULT; | ||
723 | } | ||
724 | |||
725 | if (!(card->bt = dvb_bt8xx_878_match(card->bttv_nr, bttv_pci_dev))) { | ||
726 | printk("dvb_bt8xx: unable to determine DMA core of card %d,\n", | ||
727 | card->bttv_nr); | ||
728 | printk("dvb_bt8xx: if you have the ALSA bt87x audio driver " | ||
729 | "installed, try removing it.\n"); | ||
730 | |||
731 | kfree(card); | ||
732 | return -EFAULT; | ||
733 | |||
734 | } | ||
735 | |||
736 | init_MUTEX(&card->bt->gpio_lock); | ||
737 | card->bt->bttv_nr = sub->core->nr; | ||
738 | |||
739 | if ( (ret = dvb_bt8xx_load_card(card, sub->core->type)) ) { | ||
740 | kfree(card); | ||
741 | return ret; | ||
742 | } | ||
743 | |||
744 | dev_set_drvdata(dev, card); | ||
745 | return 0; | ||
746 | } | ||
747 | |||
748 | static int dvb_bt8xx_remove(struct device *dev) | ||
749 | { | ||
750 | struct dvb_bt8xx_card *card = dev_get_drvdata(dev); | ||
751 | |||
752 | dprintk("dvb_bt8xx: unloading card%d\n", card->bttv_nr); | ||
753 | |||
754 | bt878_stop(card->bt); | ||
755 | tasklet_kill(&card->bt->tasklet); | ||
756 | dvb_net_release(&card->dvbnet); | ||
757 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem); | ||
758 | card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); | ||
759 | dvb_dmxdev_release(&card->dmxdev); | ||
760 | dvb_dmx_release(&card->demux); | ||
761 | if (card->fe) dvb_unregister_frontend(card->fe); | ||
762 | dvb_unregister_adapter(card->dvb_adapter); | ||
763 | |||
764 | kfree(card); | ||
765 | |||
766 | return 0; | ||
767 | } | ||
768 | |||
769 | static struct bttv_sub_driver driver = { | ||
770 | .drv = { | ||
771 | .name = "dvb-bt8xx", | ||
772 | .probe = dvb_bt8xx_probe, | ||
773 | .remove = dvb_bt8xx_remove, | ||
774 | /* FIXME: | ||
775 | * .shutdown = dvb_bt8xx_shutdown, | ||
776 | * .suspend = dvb_bt8xx_suspend, | ||
777 | * .resume = dvb_bt8xx_resume, | ||
778 | */ | ||
779 | }, | ||
780 | }; | ||
781 | |||
782 | static int __init dvb_bt8xx_init(void) | ||
783 | { | ||
784 | return bttv_sub_register(&driver, "dvb"); | ||
785 | } | ||
786 | |||
787 | static void __exit dvb_bt8xx_exit(void) | ||
788 | { | ||
789 | bttv_sub_unregister(&driver); | ||
790 | } | ||
791 | |||
792 | module_init(dvb_bt8xx_init); | ||
793 | module_exit(dvb_bt8xx_exit); | ||
794 | |||
795 | MODULE_DESCRIPTION("Bt8xx based DVB adapter driver"); | ||
796 | MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>"); | ||
797 | MODULE_LICENSE("GPL"); | ||