V4L/DVB (3220): Add support for VP-3054 HDTV board
[linux-2.6.git] / drivers / media / video / cx88 / cx88-dvb.c
1 /*
2  *
3  * device driver for Conexant 2388x based TV cards
4  * MPEG Transport Stream (DVB) routines
5  *
6  * (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
7  * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/device.h>
27 #include <linux/fs.h>
28 #include <linux/kthread.h>
29 #include <linux/file.h>
30 #include <linux/suspend.h>
31
32 #include "cx88.h"
33 #include "dvb-pll.h"
34
35 #ifdef HAVE_MT352
36 # include "mt352.h"
37 # include "mt352_priv.h"
38 # ifdef HAVE_VP3054_I2C
39 #  include "cx88-vp3054-i2c.h"
40 # endif
41 #endif
42 #ifdef HAVE_CX22702
43 # include "cx22702.h"
44 #endif
45 #ifdef HAVE_OR51132
46 # include "or51132.h"
47 #endif
48 #ifdef HAVE_LGDT330X
49 # include "lgdt330x.h"
50 #endif
51 #ifdef HAVE_NXT200X
52 # include "nxt200x.h"
53 #endif
54 #ifdef HAVE_CX24123
55 # include "cx24123.h"
56 #endif
57
58 MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
59 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
60 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
61 MODULE_LICENSE("GPL");
62
63 static unsigned int debug = 0;
64 module_param(debug, int, 0644);
65 MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
66
67 #define dprintk(level,fmt, arg...)      if (debug >= level) \
68         printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg)
69
70 /* ------------------------------------------------------------------ */
71
72 static int dvb_buf_setup(struct videobuf_queue *q,
73                          unsigned int *count, unsigned int *size)
74 {
75         struct cx8802_dev *dev = q->priv_data;
76
77         dev->ts_packet_size  = 188 * 4;
78         dev->ts_packet_count = 32;
79
80         *size  = dev->ts_packet_size * dev->ts_packet_count;
81         *count = 32;
82         return 0;
83 }
84
85 static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
86                            enum v4l2_field field)
87 {
88         struct cx8802_dev *dev = q->priv_data;
89         return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb,field);
90 }
91
92 static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
93 {
94         struct cx8802_dev *dev = q->priv_data;
95         cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
96 }
97
98 static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
99 {
100         struct cx8802_dev *dev = q->priv_data;
101         cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb);
102 }
103
104 static struct videobuf_queue_ops dvb_qops = {
105         .buf_setup    = dvb_buf_setup,
106         .buf_prepare  = dvb_buf_prepare,
107         .buf_queue    = dvb_buf_queue,
108         .buf_release  = dvb_buf_release,
109 };
110
111 /* ------------------------------------------------------------------ */
112
113 #ifdef HAVE_MT352
114 static int generic_mt352_demod_init(struct dvb_frontend* fe)
115 {
116         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x39 };
117         static u8 reset []         = { RESET,      0x80 };
118         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
119         static u8 agc_cfg []       = { AGC_TARGET, 0x24, 0x20 };
120         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
121         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
122
123         mt352_write(fe, clock_config,   sizeof(clock_config));
124         udelay(200);
125         mt352_write(fe, reset,          sizeof(reset));
126         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
127
128         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
129         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
130         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
131         return 0;
132 }
133
134 static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
135 {
136         static u8 clock_config []  = { 0x89, 0x38, 0x39 };
137         static u8 reset []         = { 0x50, 0x80 };
138         static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
139         static u8 agc_cfg []       = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
140                                        0x00, 0xFF, 0x00, 0x40, 0x40 };
141         static u8 dntv_extra[]     = { 0xB5, 0x7A };
142         static u8 capt_range_cfg[] = { 0x75, 0x32 };
143
144         mt352_write(fe, clock_config,   sizeof(clock_config));
145         udelay(2000);
146         mt352_write(fe, reset,          sizeof(reset));
147         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
148
149         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
150         udelay(2000);
151         mt352_write(fe, dntv_extra,     sizeof(dntv_extra));
152         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
153
154         return 0;
155 }
156
157 static int mt352_pll_set(struct dvb_frontend* fe,
158                          struct dvb_frontend_parameters* params,
159                          u8* pllbuf)
160 {
161         struct cx8802_dev *dev= fe->dvb->priv;
162
163         pllbuf[0] = dev->core->pll_addr << 1;
164         dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
165                           params->frequency,
166                           params->u.ofdm.bandwidth);
167         return 0;
168 }
169
170 static struct mt352_config dvico_fusionhdtv = {
171         .demod_address = 0x0F,
172         .demod_init    = generic_mt352_demod_init,
173         .pll_set       = mt352_pll_set,
174 };
175
176 static struct mt352_config dntv_live_dvbt_config = {
177         .demod_address = 0x0f,
178         .demod_init    = dntv_live_dvbt_demod_init,
179         .pll_set       = mt352_pll_set,
180 };
181
182 #ifdef HAVE_VP3054_I2C
183 static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
184 {
185         struct cx8802_dev *dev= fe->dvb->priv;
186
187         /* this message is to set up ATC and ALC */
188         static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
189         struct i2c_msg msg =
190                 { .addr = dev->core->pll_addr, .flags = 0,
191                   .buf = fmd1216_init, .len = sizeof(fmd1216_init) };
192         int err;
193
194         if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
195                 if (err < 0)
196                         return err;
197                 else
198                         return -EREMOTEIO;
199         }
200
201         return 0;
202 }
203
204 static int dntv_live_dvbt_pro_pll_set(struct dvb_frontend* fe,
205                                       struct dvb_frontend_parameters* params,
206                                       u8* pllbuf)
207 {
208         struct cx8802_dev *dev= fe->dvb->priv;
209         struct i2c_msg msg =
210                 { .addr = dev->core->pll_addr, .flags = 0,
211                   .buf = pllbuf+1, .len = 4 };
212         int err;
213
214         /* Switch PLL to DVB mode */
215         err = philips_fmd1216_pll_init(fe);
216         if (err)
217                 return err;
218
219         /* Tune PLL */
220         pllbuf[0] = dev->core->pll_addr << 1;
221         dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
222                           params->frequency,
223                           params->u.ofdm.bandwidth);
224         if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
225                 printk(KERN_WARNING "cx88-dvb: %s error "
226                            "(addr %02x <- %02x, err = %i)\n",
227                            __FUNCTION__, pllbuf[0], pllbuf[1], err);
228                 if (err < 0)
229                         return err;
230                 else
231                         return -EREMOTEIO;
232         }
233
234         return 0;
235 }
236
237 static struct mt352_config dntv_live_dvbt_pro_config = {
238         .demod_address = 0x0f,
239         .no_tuner      = 1,
240         .demod_init    = generic_mt352_demod_init,
241         .pll_set       = dntv_live_dvbt_pro_pll_set,
242 };
243 #endif
244 #endif
245
246 #ifdef HAVE_CX22702
247 static struct cx22702_config connexant_refboard_config = {
248         .demod_address = 0x43,
249         .output_mode   = CX22702_SERIAL_OUTPUT,
250         .pll_address   = 0x60,
251         .pll_desc      = &dvb_pll_thomson_dtt7579,
252 };
253
254 static struct cx22702_config hauppauge_novat_config = {
255         .demod_address = 0x43,
256         .output_mode   = CX22702_SERIAL_OUTPUT,
257         .pll_address   = 0x61,
258         .pll_desc      = &dvb_pll_thomson_dtt759x,
259 };
260 static struct cx22702_config hauppauge_hvr1100_config = {
261         .demod_address = 0x63,
262         .output_mode   = CX22702_SERIAL_OUTPUT,
263         .pll_address   = 0x61,
264         .pll_desc      = &dvb_pll_fmd1216me,
265 };
266 #endif
267
268 #ifdef HAVE_OR51132
269 static int or51132_set_ts_param(struct dvb_frontend* fe,
270                                 int is_punctured)
271 {
272         struct cx8802_dev *dev= fe->dvb->priv;
273         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
274         return 0;
275 }
276
277 static struct or51132_config pchdtv_hd3000 = {
278         .demod_address    = 0x15,
279         .pll_address      = 0x61,
280         .pll_desc         = &dvb_pll_thomson_dtt7610,
281         .set_ts_params    = or51132_set_ts_param,
282 };
283 #endif
284
285 #ifdef HAVE_LGDT330X
286 static int lgdt330x_pll_set(struct dvb_frontend* fe,
287                             struct dvb_frontend_parameters* params)
288 {
289         /* FIXME make this routine use the tuner-simple code.
290          * It could probably be shared with a number of ATSC
291          * frontends. Many share the same tuner with analog TV. */
292
293         struct cx8802_dev *dev= fe->dvb->priv;
294         struct cx88_core *core = dev->core;
295         u8 buf[4];
296         struct i2c_msg msg =
297                 { .addr = dev->core->pll_addr, .flags = 0, .buf = buf, .len = 4 };
298         int err;
299
300         /* Put the analog decoder in standby to keep it quiet */
301         cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
302
303         dvb_pll_configure(core->pll_desc, buf, params->frequency, 0);
304         dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",
305                         __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]);
306         if ((err = i2c_transfer(&core->i2c_adap, &msg, 1)) != 1) {
307                 printk(KERN_WARNING "cx88-dvb: %s error "
308                            "(addr %02x <- %02x, err = %i)\n",
309                            __FUNCTION__, buf[0], buf[1], err);
310                 if (err < 0)
311                         return err;
312                 else
313                         return -EREMOTEIO;
314         }
315         if (core->tuner_type == TUNER_LG_TDVS_H062F) {
316                 /* Set the Auxiliary Byte. */
317                 buf[2] &= ~0x20;
318                 buf[2] |= 0x18;
319                 buf[3] = 0x50;
320                 i2c_transfer(&core->i2c_adap, &msg, 1);
321         }
322         return 0;
323 }
324
325 static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
326 {
327         struct cx8802_dev *dev= fe->dvb->priv;
328         struct cx88_core *core = dev->core;
329
330         dprintk(1, "%s: index = %d\n", __FUNCTION__, index);
331         if (index == 0)
332                 cx_clear(MO_GP0_IO, 8);
333         else
334                 cx_set(MO_GP0_IO, 8);
335         return 0;
336 }
337
338 static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
339 {
340         struct cx8802_dev *dev= fe->dvb->priv;
341         if (is_punctured)
342                 dev->ts_gen_cntrl |= 0x04;
343         else
344                 dev->ts_gen_cntrl &= ~0x04;
345         return 0;
346 }
347
348 static struct lgdt330x_config fusionhdtv_3_gold = {
349         .demod_address    = 0x0e,
350         .demod_chip       = LGDT3302,
351         .serial_mpeg      = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
352         .pll_set          = lgdt330x_pll_set,
353         .set_ts_params    = lgdt330x_set_ts_param,
354 };
355
356 static struct lgdt330x_config fusionhdtv_5_gold = {
357         .demod_address    = 0x0e,
358         .demod_chip       = LGDT3303,
359         .serial_mpeg      = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
360         .pll_set          = lgdt330x_pll_set,
361         .set_ts_params    = lgdt330x_set_ts_param,
362 };
363 #endif
364
365 #ifdef HAVE_NXT200X
366 static int nxt200x_set_ts_param(struct dvb_frontend* fe,
367                                 int is_punctured)
368 {
369         struct cx8802_dev *dev= fe->dvb->priv;
370         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
371         return 0;
372 }
373
374 static int nxt200x_set_pll_input(u8* buf, int input)
375 {
376         if (input)
377                 buf[3] |= 0x08;
378         else
379                 buf[3] &= ~0x08;
380         return 0;
381 }
382
383 static struct nxt200x_config ati_hdtvwonder = {
384         .demod_address    = 0x0a,
385         .pll_address      = 0x61,
386         .pll_desc         = &dvb_pll_tuv1236d,
387         .set_pll_input    = nxt200x_set_pll_input,
388         .set_ts_params    = nxt200x_set_ts_param,
389 };
390 #endif
391
392 #ifdef HAVE_CX24123
393 static int cx24123_set_ts_param(struct dvb_frontend* fe,
394         int is_punctured)
395 {
396         struct cx8802_dev *dev= fe->dvb->priv;
397         dev->ts_gen_cntrl = 0x2;
398         return 0;
399 }
400
401 static void cx24123_enable_lnb_voltage(struct dvb_frontend* fe, int on)
402 {
403         struct cx8802_dev *dev= fe->dvb->priv;
404         struct cx88_core *core = dev->core;
405
406         if (on)
407                 cx_write(MO_GP0_IO, 0x000006f9);
408         else
409                 cx_write(MO_GP0_IO, 0x000006fB);
410 }
411
412 static struct cx24123_config hauppauge_novas_config = {
413         .demod_address          = 0x55,
414         .use_isl6421            = 1,
415         .set_ts_params          = cx24123_set_ts_param,
416 };
417
418 static struct cx24123_config kworld_dvbs_100_config = {
419         .demod_address          = 0x15,
420         .use_isl6421            = 0,
421         .set_ts_params          = cx24123_set_ts_param,
422         .enable_lnb_voltage     = cx24123_enable_lnb_voltage,
423 };
424 #endif
425
426 static int dvb_register(struct cx8802_dev *dev)
427 {
428         /* init struct videobuf_dvb */
429         dev->dvb.name = dev->core->name;
430         dev->ts_gen_cntrl = 0x0c;
431
432         /* init frontend */
433         switch (dev->core->board) {
434 #ifdef HAVE_CX22702
435         case CX88_BOARD_HAUPPAUGE_DVB_T1:
436                 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
437                                                    &dev->core->i2c_adap);
438                 break;
439         case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
440         case CX88_BOARD_CONEXANT_DVB_T1:
441         case CX88_BOARD_WINFAST_DTV1000:
442                 dev->dvb.frontend = cx22702_attach(&connexant_refboard_config,
443                                                    &dev->core->i2c_adap);
444                 break;
445         case CX88_BOARD_HAUPPAUGE_HVR1100:
446         case CX88_BOARD_HAUPPAUGE_HVR1100LP:
447                 dev->dvb.frontend = cx22702_attach(&hauppauge_hvr1100_config,
448                                                    &dev->core->i2c_adap);
449                 break;
450 #endif
451 #ifdef HAVE_MT352
452         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
453                 dev->core->pll_addr = 0x61;
454                 dev->core->pll_desc = &dvb_pll_lg_z201;
455                 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
456                                                  &dev->core->i2c_adap);
457                 break;
458         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
459                 dev->core->pll_addr = 0x60;
460                 dev->core->pll_desc = &dvb_pll_thomson_dtt7579;
461                 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
462                                                  &dev->core->i2c_adap);
463                 break;
464         case CX88_BOARD_KWORLD_DVB_T:
465         case CX88_BOARD_DNTV_LIVE_DVB_T:
466         case CX88_BOARD_ADSTECH_DVB_T_PCI:
467                 dev->core->pll_addr = 0x61;
468                 dev->core->pll_desc = &dvb_pll_unknown_1;
469                 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config,
470                                                  &dev->core->i2c_adap);
471                 break;
472         case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
473 #ifdef HAVE_VP3054_I2C
474                 dev->core->pll_addr = 0x61;
475                 dev->core->pll_desc = &dvb_pll_fmd1216me;
476                 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_pro_config,
477                         &((struct vp3054_i2c_state *)dev->card_priv)->adap);
478 #else
479                 printk("%s: built without vp3054 support\n", dev->core->name);
480 #endif
481                 break;
482 #endif
483 #ifdef HAVE_OR51132
484         case CX88_BOARD_PCHDTV_HD3000:
485                 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
486                                                  &dev->core->i2c_adap);
487                 break;
488 #endif
489 #ifdef HAVE_LGDT330X
490         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
491                 dev->ts_gen_cntrl = 0x08;
492                 {
493                 /* Do a hardware reset of chip before using it. */
494                 struct cx88_core *core = dev->core;
495
496                 cx_clear(MO_GP0_IO, 1);
497                 mdelay(100);
498                 cx_set(MO_GP0_IO, 1);
499                 mdelay(200);
500
501                 /* Select RF connector callback */
502                 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
503                 dev->core->pll_addr = 0x61;
504                 dev->core->pll_desc = &dvb_pll_microtune_4042;
505                 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold,
506                                                     &dev->core->i2c_adap);
507                 }
508                 break;
509         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
510                 dev->ts_gen_cntrl = 0x08;
511                 {
512                 /* Do a hardware reset of chip before using it. */
513                 struct cx88_core *core = dev->core;
514
515                 cx_clear(MO_GP0_IO, 1);
516                 mdelay(100);
517                 cx_set(MO_GP0_IO, 9);
518                 mdelay(200);
519                 dev->core->pll_addr = 0x61;
520                 dev->core->pll_desc = &dvb_pll_thomson_dtt761x;
521                 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold,
522                                                     &dev->core->i2c_adap);
523                 }
524                 break;
525         case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
526                 dev->ts_gen_cntrl = 0x08;
527                 {
528                 /* Do a hardware reset of chip before using it. */
529                 struct cx88_core *core = dev->core;
530
531                 cx_clear(MO_GP0_IO, 1);
532                 mdelay(100);
533                 cx_set(MO_GP0_IO, 1);
534                 mdelay(200);
535                 dev->core->pll_addr = 0x61;
536                 dev->core->pll_desc = &dvb_pll_tdvs_tua6034;
537                 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_5_gold,
538                                                     &dev->core->i2c_adap);
539                 }
540                 break;
541 #endif
542 #ifdef HAVE_NXT200X
543         case CX88_BOARD_ATI_HDTVWONDER:
544                 dev->dvb.frontend = nxt200x_attach(&ati_hdtvwonder,
545                                                  &dev->core->i2c_adap);
546                 break;
547 #endif
548 #ifdef HAVE_CX24123
549         case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
550         case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
551                 dev->dvb.frontend = cx24123_attach(&hauppauge_novas_config,
552                         &dev->core->i2c_adap);
553                 break;
554         case CX88_BOARD_KWORLD_DVBS_100:
555                 dev->dvb.frontend = cx24123_attach(&kworld_dvbs_100_config,
556                         &dev->core->i2c_adap);
557                 break;
558 #endif
559         default:
560                 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
561                        dev->core->name);
562                 break;
563         }
564         if (NULL == dev->dvb.frontend) {
565                 printk("%s: frontend initialization failed\n",dev->core->name);
566                 return -1;
567         }
568
569         if (dev->core->pll_desc) {
570                 dev->dvb.frontend->ops->info.frequency_min = dev->core->pll_desc->min;
571                 dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max;
572         }
573
574         /* Put the analog decoder in standby to keep it quiet */
575         cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
576
577         /* register everything */
578         return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
579 }
580
581 /* ----------------------------------------------------------- */
582
583 static int __devinit dvb_probe(struct pci_dev *pci_dev,
584                                const struct pci_device_id *pci_id)
585 {
586         struct cx8802_dev *dev;
587         struct cx88_core  *core;
588         int err;
589
590         /* general setup */
591         core = cx88_core_get(pci_dev);
592         if (NULL == core)
593                 return -EINVAL;
594
595         err = -ENODEV;
596         if (!cx88_boards[core->board].dvb)
597                 goto fail_core;
598
599         err = -ENOMEM;
600         dev = kmalloc(sizeof(*dev),GFP_KERNEL);
601         if (NULL == dev)
602                 goto fail_core;
603         memset(dev,0,sizeof(*dev));
604         dev->pci = pci_dev;
605         dev->core = core;
606
607         err = cx8802_init_common(dev);
608         if (0 != err)
609                 goto fail_free;
610
611 #ifdef HAVE_VP3054_I2C
612         err = vp3054_i2c_probe(dev);
613         if (0 != err)
614                 goto fail_free;
615 #endif
616
617         /* dvb stuff */
618         printk("%s/2: cx2388x based dvb card\n", core->name);
619         videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops,
620                             dev->pci, &dev->slock,
621                             V4L2_BUF_TYPE_VIDEO_CAPTURE,
622                             V4L2_FIELD_TOP,
623                             sizeof(struct cx88_buffer),
624                             dev);
625         err = dvb_register(dev);
626         if (0 != err)
627                 goto fail_fini;
628
629         /* Maintain a reference to cx88-video can query the 8802 device. */
630         core->dvbdev = dev;
631         return 0;
632
633  fail_fini:
634         cx8802_fini_common(dev);
635  fail_free:
636         kfree(dev);
637  fail_core:
638         cx88_core_put(core,pci_dev);
639         return err;
640 }
641
642 static void __devexit dvb_remove(struct pci_dev *pci_dev)
643 {
644         struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
645
646         /* Destroy any 8802 reference. */
647         dev->core->dvbdev = NULL;
648
649         /* dvb */
650         videobuf_dvb_unregister(&dev->dvb);
651
652 #ifdef HAVE_VP3054_I2C
653         vp3054_i2c_remove(dev);
654 #endif
655
656         /* common */
657         cx8802_fini_common(dev);
658         cx88_core_put(dev->core,dev->pci);
659         kfree(dev);
660 }
661
662 static struct pci_device_id cx8802_pci_tbl[] = {
663         {
664                 .vendor       = 0x14f1,
665                 .device       = 0x8802,
666                 .subvendor    = PCI_ANY_ID,
667                 .subdevice    = PCI_ANY_ID,
668         },{
669                 /* --- end of list --- */
670         }
671 };
672 MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
673
674 static struct pci_driver dvb_pci_driver = {
675         .name     = "cx88-dvb",
676         .id_table = cx8802_pci_tbl,
677         .probe    = dvb_probe,
678         .remove   = __devexit_p(dvb_remove),
679         .suspend  = cx8802_suspend_common,
680         .resume   = cx8802_resume_common,
681 };
682
683 static int dvb_init(void)
684 {
685         printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n",
686                (CX88_VERSION_CODE >> 16) & 0xff,
687                (CX88_VERSION_CODE >>  8) & 0xff,
688                CX88_VERSION_CODE & 0xff);
689 #ifdef SNAPSHOT
690         printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
691                SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
692 #endif
693         return pci_register_driver(&dvb_pci_driver);
694 }
695
696 static void dvb_fini(void)
697 {
698         pci_unregister_driver(&dvb_pci_driver);
699 }
700
701 module_init(dvb_init);
702 module_exit(dvb_fini);
703
704 /*
705  * Local variables:
706  * c-basic-offset: 8
707  * compile-command: "make DVB=1"
708  * End:
709  */