[PATCH] crc16: remove w1 specific comments.
[linux-2.6/verdex.git] / drivers / media / dvb / bt8xx / dvb-bt8xx.c
blobc5c7672cd53819f9a3ab1fa391dcf039b73f9301
1 /*
2 * Bt8xx based DVB adapter driver
4 * Copyright (C) 2002,2003 Florian Schirmer <jolt@tuxbox.org>
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.
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.
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.
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>
31 #include "dmxdev.h"
32 #include "dvbdev.h"
33 #include "dvb_demux.h"
34 #include "dvb_frontend.h"
35 #include "dvb-bt8xx.h"
36 #include "bt878.h"
38 static int debug;
40 module_param(debug, int, 0644);
41 MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
43 #define dprintk( args... ) \
44 do \
45 if (debug) printk(KERN_DEBUG args); \
46 while (0)
48 #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
50 static void dvb_bt8xx_task(unsigned long data)
52 struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *)data;
54 //printk("%d ", card->bt->finished_block);
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;
67 static int dvb_bt8xx_start_feed(struct dvb_demux_feed *dvbdmxfeed)
69 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
70 struct dvb_bt8xx_card *card = dvbdmx->priv;
71 int rc;
73 dprintk("dvb_bt8xx: start_feed\n");
75 if (!dvbdmx->dmx.frontend)
76 return -EINVAL;
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;
88 static int dvb_bt8xx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
90 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
91 struct dvb_bt8xx_card *card = dvbdmx->priv;
93 dprintk("dvb_bt8xx: stop_feed\n");
95 if (!dvbdmx->dmx.frontend)
96 return -EINVAL;
98 down(&card->lock);
99 card->nfeeds--;
100 if (card->nfeeds == 0)
101 bt878_stop(card->bt);
102 up(&card->lock);
104 return 0;
107 static int is_pci_slot_eq(struct pci_dev* adev, struct pci_dev* bdev)
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;
117 static struct bt878 __init *dvb_bt8xx_878_match(unsigned int bttv_nr, struct pci_dev* bttv_pci_dev)
119 unsigned int card_nr;
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 return NULL;
128 static int thomson_dtt7579_demod_init(struct dvb_frontend* fe)
130 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x38 };
131 static u8 mt352_reset [] = { 0x50, 0x80 };
132 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
133 static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0x20 };
134 static u8 mt352_gpp_ctl_cfg [] = { 0x8C, 0x33 };
135 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
137 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
138 udelay(2000);
139 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
140 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
142 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
143 mt352_write(fe, mt352_gpp_ctl_cfg, sizeof(mt352_gpp_ctl_cfg));
144 mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
146 return 0;
149 static int thomson_dtt7579_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf)
151 u32 div;
152 unsigned char bs = 0;
153 unsigned char cp = 0;
155 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
157 if (params->frequency < 542000000)
158 cp = 0xb4;
159 else if (params->frequency < 771000000)
160 cp = 0xbc;
161 else
162 cp = 0xf4;
164 if (params->frequency == 0)
165 bs = 0x03;
166 else if (params->frequency < 443250000)
167 bs = 0x02;
168 else
169 bs = 0x08;
171 pllbuf[0] = 0xc0; // Note: non-linux standard PLL i2c address
172 pllbuf[1] = div >> 8;
173 pllbuf[2] = div & 0xff;
174 pllbuf[3] = cp;
175 pllbuf[4] = bs;
177 return 0;
180 static struct mt352_config thomson_dtt7579_config = {
181 .demod_address = 0x0f,
182 .demod_init = thomson_dtt7579_demod_init,
183 .pll_set = thomson_dtt7579_pll_set,
186 static int cx24108_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
188 u32 freq = params->frequency;
190 int i, a, n, pump;
191 u32 band, pll;
193 u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000,
194 1576000,1718000,1856000,2036000,2150000};
195 u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000,
196 0x00102000,0x00104000,0x00108000,0x00110000,
197 0x00120000,0x00140000};
199 #define XTAL 1011100 /* Hz, really 1.0111 MHz and a /10 prescaler */
200 printk("cx24108 debug: entering SetTunerFreq, freq=%d\n",freq);
202 /* This is really the bit driving the tuner chip cx24108 */
204 if (freq<950000)
205 freq = 950000; /* kHz */
206 else if (freq>2150000)
207 freq = 2150000; /* satellite IF is 950..2150MHz */
209 /* decide which VCO to use for the input frequency */
210 for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++);
211 printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq);
212 band=bandsel[i];
213 /* the gain values must be set by SetSymbolrate */
214 /* compute the pll divider needed, from Conexant data sheet,
215 resolved for (n*32+a), remember f(vco) is f(receive) *2 or *4,
216 depending on the divider bit. It is set to /4 on the 2 lowest
217 bands */
218 n=((i<=2?2:1)*freq*10L)/(XTAL/100);
219 a=n%32; n/=32; if(a==0) n--;
220 pump=(freq<(osci[i-1]+osci[i])/2);
221 pll=0xf8000000|
222 ((pump?1:2)<<(14+11))|
223 ((n&0x1ff)<<(5+11))|
224 ((a&0x1f)<<11);
225 /* everything is shifted left 11 bits to left-align the bits in the
226 32bit word. Output to the tuner goes MSB-aligned, after all */
227 printk("cx24108 debug: pump=%d, n=%d, a=%d\n",pump,n,a);
228 cx24110_pll_write(fe,band);
229 /* set vga and vca to their widest-band settings, as a precaution.
230 SetSymbolrate might not be called to set this up */
231 cx24110_pll_write(fe,0x500c0000);
232 cx24110_pll_write(fe,0x83f1f800);
233 cx24110_pll_write(fe,pll);
234 //writereg(client,0x56,0x7f);
236 return 0;
239 static int pinnsat_pll_init(struct dvb_frontend* fe)
241 return 0;
244 static struct cx24110_config pctvsat_config = {
245 .demod_address = 0x55,
246 .pll_init = pinnsat_pll_init,
247 .pll_set = cx24108_pll_set,
250 static int microtune_mt7202dtf_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
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) };
258 div = (36000000 + params->frequency + 83333) / 166666;
259 cfg = 0x88;
261 if (params->frequency < 175000000)
262 cpump = 2;
263 else if (params->frequency < 390000000)
264 cpump = 1;
265 else if (params->frequency < 470000000)
266 cpump = 2;
267 else if (params->frequency < 750000000)
268 cpump = 2;
269 else
270 cpump = 3;
272 if (params->frequency < 175000000)
273 band_select = 0x0e;
274 else if (params->frequency < 470000000)
275 band_select = 0x05;
276 else
277 band_select = 0x03;
279 data[0] = (div >> 8) & 0x7f;
280 data[1] = div & 0xff;
281 data[2] = ((div >> 10) & 0x60) | cfg;
282 data[3] = cpump | band_select;
284 i2c_transfer(card->i2c_adapter, &msg, 1);
285 return (div * 166666 - 36000000);
288 static int microtune_mt7202dtf_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
290 struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv;
292 return request_firmware(fw, name, &bt->bt->dev->dev);
295 static struct sp887x_config microtune_mt7202dtf_config = {
296 .demod_address = 0x70,
297 .pll_set = microtune_mt7202dtf_pll_set,
298 .request_firmware = microtune_mt7202dtf_request_firmware,
301 static int advbt771_samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe)
303 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d };
304 static u8 mt352_reset [] = { 0x50, 0x80 };
305 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
306 static u8 mt352_agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
307 0x00, 0xFF, 0x00, 0x40, 0x40 };
308 static u8 mt352_av771_extra[] = { 0xB5, 0x7A };
309 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
311 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
312 udelay(2000);
313 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
314 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
316 mt352_write(fe, mt352_agc_cfg,sizeof(mt352_agc_cfg));
317 udelay(2000);
318 mt352_write(fe, mt352_av771_extra,sizeof(mt352_av771_extra));
319 mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
321 return 0;
324 static int advbt771_samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf)
326 u32 div;
327 unsigned char bs = 0;
328 unsigned char cp = 0;
330 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
332 if (params->frequency < 150000000)
333 cp = 0xB4;
334 else if (params->frequency < 173000000)
335 cp = 0xBC;
336 else if (params->frequency < 250000000)
337 cp = 0xB4;
338 else if (params->frequency < 400000000)
339 cp = 0xBC;
340 else if (params->frequency < 420000000)
341 cp = 0xF4;
342 else if (params->frequency < 470000000)
343 cp = 0xFC;
344 else if (params->frequency < 600000000)
345 cp = 0xBC;
346 else if (params->frequency < 730000000)
347 cp = 0xF4;
348 else
349 cp = 0xFC;
351 if (params->frequency < 150000000)
352 bs = 0x01;
353 else if (params->frequency < 173000000)
354 bs = 0x01;
355 else if (params->frequency < 250000000)
356 bs = 0x02;
357 else if (params->frequency < 400000000)
358 bs = 0x02;
359 else if (params->frequency < 420000000)
360 bs = 0x02;
361 else if (params->frequency < 470000000)
362 bs = 0x02;
363 else if (params->frequency < 600000000)
364 bs = 0x08;
365 else if (params->frequency < 730000000)
366 bs = 0x08;
367 else
368 bs = 0x08;
370 pllbuf[0] = 0xc2; // Note: non-linux standard PLL i2c address
371 pllbuf[1] = div >> 8;
372 pllbuf[2] = div & 0xff;
373 pllbuf[3] = cp;
374 pllbuf[4] = bs;
376 return 0;
379 static struct mt352_config advbt771_samsung_tdtc9251dh0_config = {
380 .demod_address = 0x0f,
381 .demod_init = advbt771_samsung_tdtc9251dh0_demod_init,
382 .pll_set = advbt771_samsung_tdtc9251dh0_pll_set,
385 static struct dst_config dst_config = {
386 .demod_address = 0x55,
389 static int or51211_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
391 struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv;
393 return request_firmware(fw, name, &bt->bt->dev->dev);
396 static void or51211_setmode(struct dvb_frontend * fe, int mode)
398 struct dvb_bt8xx_card *bt = fe->dvb->priv;
399 bttv_write_gpio(bt->bttv_nr, 0x0002, mode); /* Reset */
400 msleep(20);
403 static void or51211_reset(struct dvb_frontend * fe)
405 struct dvb_bt8xx_card *bt = fe->dvb->priv;
407 /* RESET DEVICE
408 * reset is controled by GPIO-0
409 * when set to 0 causes reset and when to 1 for normal op
410 * must remain reset for 128 clock cycles on a 50Mhz clock
411 * also PRM1 PRM2 & PRM4 are controled by GPIO-1,GPIO-2 & GPIO-4
412 * We assume that the reset has be held low long enough or we
413 * have been reset by a power on. When the driver is unloaded
414 * reset set to 0 so if reloaded we have been reset.
416 /* reset & PRM1,2&4 are outputs */
417 int ret = bttv_gpio_enable(bt->bttv_nr, 0x001F, 0x001F);
418 if (ret != 0)
419 printk(KERN_WARNING "or51211: Init Error - Can't Reset DVR (%i)\n", ret);
420 bttv_write_gpio(bt->bttv_nr, 0x001F, 0x0000); /* Reset */
421 msleep(20);
422 /* Now set for normal operation */
423 bttv_write_gpio(bt->bttv_nr, 0x0001F, 0x0001);
424 /* wait for operation to begin */
425 msleep(500);
428 static void or51211_sleep(struct dvb_frontend * fe)
430 struct dvb_bt8xx_card *bt = fe->dvb->priv;
431 bttv_write_gpio(bt->bttv_nr, 0x0001, 0x0000);
434 static struct or51211_config or51211_config = {
435 .demod_address = 0x15,
436 .request_firmware = or51211_request_firmware,
437 .setmode = or51211_setmode,
438 .reset = or51211_reset,
439 .sleep = or51211_sleep,
442 static int vp3021_alps_tded4_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
444 struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv;
445 u8 buf[4];
446 u32 div;
447 struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf) };
449 div = (params->frequency + 36166667) / 166667;
451 buf[0] = (div >> 8) & 0x7F;
452 buf[1] = div & 0xFF;
453 buf[2] = 0x85;
454 if ((params->frequency >= 47000000) && (params->frequency < 153000000))
455 buf[3] = 0x01;
456 else if ((params->frequency >= 153000000) && (params->frequency < 430000000))
457 buf[3] = 0x02;
458 else if ((params->frequency >= 430000000) && (params->frequency < 824000000))
459 buf[3] = 0x0C;
460 else if ((params->frequency >= 824000000) && (params->frequency < 863000000))
461 buf[3] = 0x8C;
462 else
463 return -EINVAL;
465 i2c_transfer(card->i2c_adapter, &msg, 1);
466 return 0;
469 static struct nxt6000_config vp3021_alps_tded4_config = {
470 .demod_address = 0x0a,
471 .clock_inversion = 1,
472 .pll_set = vp3021_alps_tded4_pll_set,
475 static int digitv_alps_tded4_demod_init(struct dvb_frontend* fe)
477 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d };
478 static u8 mt352_reset [] = { 0x50, 0x80 };
479 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
480 static u8 mt352_agc_cfg [] = { 0x67, 0x20, 0xa0 };
481 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
483 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
484 udelay(2000);
485 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
486 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
487 mt352_write(fe, mt352_agc_cfg,sizeof(mt352_agc_cfg));
488 mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
490 return 0;
493 static int digitv_alps_tded4_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf)
495 u32 div;
496 struct dvb_ofdm_parameters *op = &params->u.ofdm;
498 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
500 pllbuf[0] = 0xc2;
501 pllbuf[1] = (div >> 8) & 0x7F;
502 pllbuf[2] = div & 0xFF;
503 pllbuf[3] = 0x85;
505 dprintk("frequency %u, div %u\n", params->frequency, div);
507 if (params->frequency < 470000000)
508 pllbuf[4] = 0x02;
509 else if (params->frequency > 823000000)
510 pllbuf[4] = 0x88;
511 else
512 pllbuf[4] = 0x08;
514 if (op->bandwidth == 8)
515 pllbuf[4] |= 0x04;
517 return 0;
520 static void digitv_alps_tded4_reset(struct dvb_bt8xx_card *bt)
523 * Reset the frontend, must be called before trying
524 * to initialise the MT352 or mt352_attach
525 * will fail.
527 * Presumably not required for the NXT6000 frontend.
531 int ret = bttv_gpio_enable(bt->bttv_nr, 0x08, 0x08);
532 if (ret != 0)
533 printk(KERN_WARNING "digitv_alps_tded4: Init Error - Can't Reset DVR (%i)\n", ret);
535 /* Pulse the reset line */
536 bttv_write_gpio(bt->bttv_nr, 0x08, 0x08); /* High */
537 bttv_write_gpio(bt->bttv_nr, 0x08, 0x00); /* Low */
538 msleep(100);
540 bttv_write_gpio(bt->bttv_nr, 0x08, 0x08); /* High */
543 static struct mt352_config digitv_alps_tded4_config = {
544 .demod_address = 0x0a,
545 .demod_init = digitv_alps_tded4_demod_init,
546 .pll_set = digitv_alps_tded4_pll_set,
549 static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
551 int ret;
552 struct dst_state* state = NULL;
554 switch(type) {
555 #ifdef BTTV_DVICO_DVBT_LITE
556 case BTTV_DVICO_DVBT_LITE:
557 card->fe = mt352_attach(&thomson_dtt7579_config, card->i2c_adapter);
558 if (card->fe != NULL) {
559 card->fe->ops->info.frequency_min = 174000000;
560 card->fe->ops->info.frequency_max = 862000000;
562 break;
563 #endif
565 #ifdef BTTV_TWINHAN_VP3021
566 case BTTV_TWINHAN_VP3021:
567 #else
568 case BTTV_NEBULA_DIGITV:
569 #endif
571 * It is possible to determine the correct frontend using the I2C bus (see the Nebula SDK);
572 * this would be a cleaner solution than trying each frontend in turn.
575 /* Old Nebula (marked (c)2003 on high profile pci card) has nxt6000 demod */
576 card->fe = nxt6000_attach(&vp3021_alps_tded4_config, card->i2c_adapter);
577 if (card->fe != NULL) {
578 dprintk ("dvb_bt8xx: an nxt6000 was detected on your digitv card\n");
579 break;
582 /* New Nebula (marked (c)2005 on low profile pci card) has mt352 demod */
583 digitv_alps_tded4_reset(card);
584 card->fe = mt352_attach(&digitv_alps_tded4_config, card->i2c_adapter);
586 if (card->fe != NULL)
587 dprintk ("dvb_bt8xx: an mt352 was detected on your digitv card\n");
588 break;
590 case BTTV_AVDVBT_761:
591 card->fe = sp887x_attach(&microtune_mt7202dtf_config, card->i2c_adapter);
592 break;
594 case BTTV_AVDVBT_771:
595 card->fe = mt352_attach(&advbt771_samsung_tdtc9251dh0_config, card->i2c_adapter);
596 if (card->fe != NULL) {
597 card->fe->ops->info.frequency_min = 174000000;
598 card->fe->ops->info.frequency_max = 862000000;
600 break;
602 case BTTV_TWINHAN_DST:
603 /* DST is not a frontend driver !!! */
604 state = (struct dst_state *) kmalloc(sizeof (struct dst_state), GFP_KERNEL);
605 /* Setup the Card */
606 state->config = &dst_config;
607 state->i2c = card->i2c_adapter;
608 state->bt = card->bt;
610 /* DST is not a frontend, attaching the ASIC */
611 if ((dst_attach(state, &card->dvb_adapter)) == NULL) {
612 printk("%s: Could not find a Twinhan DST.\n", __FUNCTION__);
613 break;
615 card->fe = &state->frontend;
617 /* Attach other DST peripherals if any */
618 /* Conditional Access device */
619 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
620 ret = dst_ca_attach(state, &card->dvb_adapter);
621 break;
623 case BTTV_PINNACLESAT:
624 card->fe = cx24110_attach(&pctvsat_config, card->i2c_adapter);
625 break;
627 case BTTV_PC_HDTV:
628 card->fe = or51211_attach(&or51211_config, card->i2c_adapter);
629 break;
632 if (card->fe == NULL)
633 printk("dvb-bt8xx: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
634 card->bt->dev->vendor,
635 card->bt->dev->device,
636 card->bt->dev->subsystem_vendor,
637 card->bt->dev->subsystem_device);
638 else
639 if (dvb_register_frontend(&card->dvb_adapter, card->fe)) {
640 printk("dvb-bt8xx: Frontend registration failed!\n");
641 if (card->fe->ops->release)
642 card->fe->ops->release(card->fe);
643 card->fe = NULL;
647 static int __init dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
649 int result;
651 if ((result = dvb_register_adapter(&card->dvb_adapter, card->card_name, THIS_MODULE)) < 0) {
652 printk("dvb_bt8xx: dvb_register_adapter failed (errno = %d)\n", result);
653 return result;
655 card->dvb_adapter.priv = card;
657 card->bt->adapter = card->i2c_adapter;
659 memset(&card->demux, 0, sizeof(struct dvb_demux));
661 card->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING;
663 card->demux.priv = card;
664 card->demux.filternum = 256;
665 card->demux.feednum = 256;
666 card->demux.start_feed = dvb_bt8xx_start_feed;
667 card->demux.stop_feed = dvb_bt8xx_stop_feed;
668 card->demux.write_to_decoder = NULL;
670 if ((result = dvb_dmx_init(&card->demux)) < 0) {
671 printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result);
673 dvb_unregister_adapter(&card->dvb_adapter);
674 return result;
677 card->dmxdev.filternum = 256;
678 card->dmxdev.demux = &card->demux.dmx;
679 card->dmxdev.capabilities = 0;
681 if ((result = dvb_dmxdev_init(&card->dmxdev, &card->dvb_adapter)) < 0) {
682 printk("dvb_bt8xx: dvb_dmxdev_init failed (errno = %d)\n", result);
684 dvb_dmx_release(&card->demux);
685 dvb_unregister_adapter(&card->dvb_adapter);
686 return result;
689 card->fe_hw.source = DMX_FRONTEND_0;
691 if ((result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_hw)) < 0) {
692 printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result);
694 dvb_dmxdev_release(&card->dmxdev);
695 dvb_dmx_release(&card->demux);
696 dvb_unregister_adapter(&card->dvb_adapter);
697 return result;
700 card->fe_mem.source = DMX_MEMORY_FE;
702 if ((result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_mem)) < 0) {
703 printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result);
705 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
706 dvb_dmxdev_release(&card->dmxdev);
707 dvb_dmx_release(&card->demux);
708 dvb_unregister_adapter(&card->dvb_adapter);
709 return result;
712 if ((result = card->demux.dmx.connect_frontend(&card->demux.dmx, &card->fe_hw)) < 0) {
713 printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result);
715 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem);
716 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
717 dvb_dmxdev_release(&card->dmxdev);
718 dvb_dmx_release(&card->demux);
719 dvb_unregister_adapter(&card->dvb_adapter);
720 return result;
723 dvb_net_init(&card->dvb_adapter, &card->dvbnet, &card->demux.dmx);
725 tasklet_init(&card->bt->tasklet, dvb_bt8xx_task, (unsigned long) card);
727 frontend_init(card, type);
729 return 0;
732 static int dvb_bt8xx_probe(struct device *dev)
734 struct bttv_sub_device *sub = to_bttv_sub_dev(dev);
735 struct dvb_bt8xx_card *card;
736 struct pci_dev* bttv_pci_dev;
737 int ret;
739 if (!(card = kmalloc(sizeof(struct dvb_bt8xx_card), GFP_KERNEL)))
740 return -ENOMEM;
742 memset(card, 0, sizeof(*card));
743 init_MUTEX(&card->lock);
744 card->bttv_nr = sub->core->nr;
745 strncpy(card->card_name, sub->core->name, sizeof(sub->core->name));
746 card->i2c_adapter = &sub->core->i2c_adap;
748 switch(sub->core->type) {
749 case BTTV_PINNACLESAT:
750 card->gpio_mode = 0x0400c060;
751 /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR,
752 BT878_DA_IOM=1,BT878_DA_APP to enable serial highspeed mode. */
753 card->op_sync_orin = 0;
754 card->irq_err_ignore = 0;
755 break;
757 #ifdef BTTV_DVICO_DVBT_LITE
758 case BTTV_DVICO_DVBT_LITE:
759 #endif
760 card->gpio_mode = 0x0400C060;
761 card->op_sync_orin = 0;
762 card->irq_err_ignore = 0;
763 /* 26, 15, 14, 6, 5
764 * A_PWRDN DA_DPM DA_SBR DA_IOM_DA
765 * DA_APP(parallel) */
766 break;
768 #ifdef BTTV_TWINHAN_VP3021
769 case BTTV_TWINHAN_VP3021:
770 #else
771 case BTTV_NEBULA_DIGITV:
772 #endif
773 case BTTV_AVDVBT_761:
774 card->gpio_mode = (1 << 26) | (1 << 14) | (1 << 5);
775 card->op_sync_orin = 0;
776 card->irq_err_ignore = 0;
777 /* A_PWRDN DA_SBR DA_APP (high speed serial) */
778 break;
780 case BTTV_AVDVBT_771: //case 0x07711461:
781 card->gpio_mode = 0x0400402B;
782 card->op_sync_orin = BT878_RISC_SYNC_MASK;
783 card->irq_err_ignore = 0;
784 /* A_PWRDN DA_SBR DA_APP[0] PKTP=10 RISC_ENABLE FIFO_ENABLE*/
785 break;
787 case BTTV_TWINHAN_DST:
788 card->gpio_mode = 0x2204f2c;
789 card->op_sync_orin = BT878_RISC_SYNC_MASK;
790 card->irq_err_ignore = BT878_APABORT | BT878_ARIPERR |
791 BT878_APPERR | BT878_AFBUS;
792 /* 25,21,14,11,10,9,8,3,2 then
793 * 0x33 = 5,4,1,0
794 * A_SEL=SML, DA_MLB, DA_SBR,
795 * DA_SDR=f, fifo trigger = 32 DWORDS
796 * IOM = 0 == audio A/D
797 * DPM = 0 == digital audio mode
798 * == async data parallel port
799 * then 0x33 (13 is set by start_capture)
800 * DA_APP = async data parallel port,
801 * ACAP_EN = 1,
802 * RISC+FIFO ENABLE */
803 break;
805 case BTTV_PC_HDTV:
806 card->gpio_mode = 0x0100EC7B;
807 card->op_sync_orin = 0;
808 card->irq_err_ignore = 0;
809 break;
811 default:
812 printk(KERN_WARNING "dvb_bt8xx: Unknown bttv card type: %d.\n",
813 sub->core->type);
814 kfree(card);
815 return -ENODEV;
818 dprintk("dvb_bt8xx: identified card%d as %s\n", card->bttv_nr, card->card_name);
820 if (!(bttv_pci_dev = bttv_get_pcidev(card->bttv_nr))) {
821 printk("dvb_bt8xx: no pci device for card %d\n", card->bttv_nr);
822 kfree(card);
823 return -EFAULT;
826 if (!(card->bt = dvb_bt8xx_878_match(card->bttv_nr, bttv_pci_dev))) {
827 printk("dvb_bt8xx: unable to determine DMA core of card %d,\n",
828 card->bttv_nr);
829 printk("dvb_bt8xx: if you have the ALSA bt87x audio driver "
830 "installed, try removing it.\n");
832 kfree(card);
833 return -EFAULT;
836 init_MUTEX(&card->bt->gpio_lock);
837 card->bt->bttv_nr = sub->core->nr;
839 if ( (ret = dvb_bt8xx_load_card(card, sub->core->type)) ) {
840 kfree(card);
841 return ret;
844 dev_set_drvdata(dev, card);
845 return 0;
848 static int dvb_bt8xx_remove(struct device *dev)
850 struct dvb_bt8xx_card *card = dev_get_drvdata(dev);
852 dprintk("dvb_bt8xx: unloading card%d\n", card->bttv_nr);
854 bt878_stop(card->bt);
855 tasklet_kill(&card->bt->tasklet);
856 dvb_net_release(&card->dvbnet);
857 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem);
858 card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
859 dvb_dmxdev_release(&card->dmxdev);
860 dvb_dmx_release(&card->demux);
861 if (card->fe)
862 dvb_unregister_frontend(card->fe);
863 dvb_unregister_adapter(&card->dvb_adapter);
865 kfree(card);
867 return 0;
870 static struct bttv_sub_driver driver = {
871 .drv = {
872 .name = "dvb-bt8xx",
873 .probe = dvb_bt8xx_probe,
874 .remove = dvb_bt8xx_remove,
875 /* FIXME:
876 * .shutdown = dvb_bt8xx_shutdown,
877 * .suspend = dvb_bt8xx_suspend,
878 * .resume = dvb_bt8xx_resume,
883 static int __init dvb_bt8xx_init(void)
885 return bttv_sub_register(&driver, "dvb");
888 static void __exit dvb_bt8xx_exit(void)
890 bttv_sub_unregister(&driver);
893 module_init(dvb_bt8xx_init);
894 module_exit(dvb_bt8xx_exit);
896 MODULE_DESCRIPTION("Bt8xx based DVB adapter driver");
897 MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>");
898 MODULE_LICENSE("GPL");