Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial
[linux-2.6] / 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 #include <media/v4l2-common.h>
35
36 #include "mt352.h"
37 #include "mt352_priv.h"
38 #ifdef HAVE_VP3054_I2C
39 # include "cx88-vp3054-i2c.h"
40 #endif
41 #include "zl10353.h"
42 #include "cx22702.h"
43 #include "or51132.h"
44 #include "lgdt330x.h"
45 #include "lg_h06xf.h"
46 #include "nxt200x.h"
47 #include "cx24123.h"
48 #include "isl6421.h"
49
50 MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
51 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
52 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
53 MODULE_LICENSE("GPL");
54
55 static unsigned int debug = 0;
56 module_param(debug, int, 0644);
57 MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
58
59 #define dprintk(level,fmt, arg...)      if (debug >= level) \
60         printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg)
61
62 /* ------------------------------------------------------------------ */
63
64 static int dvb_buf_setup(struct videobuf_queue *q,
65                          unsigned int *count, unsigned int *size)
66 {
67         struct cx8802_dev *dev = q->priv_data;
68
69         dev->ts_packet_size  = 188 * 4;
70         dev->ts_packet_count = 32;
71
72         *size  = dev->ts_packet_size * dev->ts_packet_count;
73         *count = 32;
74         return 0;
75 }
76
77 static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
78                            enum v4l2_field field)
79 {
80         struct cx8802_dev *dev = q->priv_data;
81         return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field);
82 }
83
84 static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
85 {
86         struct cx8802_dev *dev = q->priv_data;
87         cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
88 }
89
90 static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
91 {
92         cx88_free_buffer(q, (struct cx88_buffer*)vb);
93 }
94
95 static struct videobuf_queue_ops dvb_qops = {
96         .buf_setup    = dvb_buf_setup,
97         .buf_prepare  = dvb_buf_prepare,
98         .buf_queue    = dvb_buf_queue,
99         .buf_release  = dvb_buf_release,
100 };
101
102 /* ------------------------------------------------------------------ */
103 static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
104 {
105         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x39 };
106         static u8 reset []         = { RESET,      0x80 };
107         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
108         static u8 agc_cfg []       = { AGC_TARGET, 0x24, 0x20 };
109         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
110         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
111
112         mt352_write(fe, clock_config,   sizeof(clock_config));
113         udelay(200);
114         mt352_write(fe, reset,          sizeof(reset));
115         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
116
117         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
118         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
119         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
120         return 0;
121 }
122
123 static int dvico_dual_demod_init(struct dvb_frontend *fe)
124 {
125         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x38 };
126         static u8 reset []         = { RESET,      0x80 };
127         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
128         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0x20 };
129         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
130         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
131
132         mt352_write(fe, clock_config,   sizeof(clock_config));
133         udelay(200);
134         mt352_write(fe, reset,          sizeof(reset));
135         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
136
137         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
138         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
139         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
140
141         return 0;
142 }
143
144 static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
145 {
146         static u8 clock_config []  = { 0x89, 0x38, 0x39 };
147         static u8 reset []         = { 0x50, 0x80 };
148         static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
149         static u8 agc_cfg []       = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
150                                        0x00, 0xFF, 0x00, 0x40, 0x40 };
151         static u8 dntv_extra[]     = { 0xB5, 0x7A };
152         static u8 capt_range_cfg[] = { 0x75, 0x32 };
153
154         mt352_write(fe, clock_config,   sizeof(clock_config));
155         udelay(2000);
156         mt352_write(fe, reset,          sizeof(reset));
157         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
158
159         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
160         udelay(2000);
161         mt352_write(fe, dntv_extra,     sizeof(dntv_extra));
162         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
163
164         return 0;
165 }
166
167 static struct mt352_config dvico_fusionhdtv = {
168         .demod_address = 0x0f,
169         .demod_init    = dvico_fusionhdtv_demod_init,
170 };
171
172 static struct mt352_config dntv_live_dvbt_config = {
173         .demod_address = 0x0f,
174         .demod_init    = dntv_live_dvbt_demod_init,
175 };
176
177 static struct mt352_config dvico_fusionhdtv_dual = {
178         .demod_address = 0x0f,
179         .demod_init    = dvico_dual_demod_init,
180 };
181
182 #ifdef HAVE_VP3054_I2C
183 static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe)
184 {
185         static u8 clock_config []  = { 0x89, 0x38, 0x38 };
186         static u8 reset []         = { 0x50, 0x80 };
187         static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
188         static u8 agc_cfg []       = { 0x67, 0x10, 0x20, 0x00, 0xFF, 0xFF,
189                                        0x00, 0xFF, 0x00, 0x40, 0x40 };
190         static u8 dntv_extra[]     = { 0xB5, 0x7A };
191         static u8 capt_range_cfg[] = { 0x75, 0x32 };
192
193         mt352_write(fe, clock_config,   sizeof(clock_config));
194         udelay(2000);
195         mt352_write(fe, reset,          sizeof(reset));
196         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
197
198         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
199         udelay(2000);
200         mt352_write(fe, dntv_extra,     sizeof(dntv_extra));
201         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
202
203         return 0;
204 }
205
206 static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
207 {
208         struct cx8802_dev *dev= fe->dvb->priv;
209
210         /* this message is to set up ATC and ALC */
211         static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
212         struct i2c_msg msg =
213                 { .addr = dev->core->pll_addr, .flags = 0,
214                   .buf = fmd1216_init, .len = sizeof(fmd1216_init) };
215         int err;
216
217         if (fe->ops.i2c_gate_ctrl)
218                 fe->ops.i2c_gate_ctrl(fe, 1);
219         if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
220                 if (err < 0)
221                         return err;
222                 else
223                         return -EREMOTEIO;
224         }
225
226         return 0;
227 }
228
229 static int dntv_live_dvbt_pro_tuner_set_params(struct dvb_frontend* fe,
230                                                struct dvb_frontend_parameters* params)
231 {
232         struct cx8802_dev *dev= fe->dvb->priv;
233         u8 buf[4];
234         struct i2c_msg msg =
235                 { .addr = dev->core->pll_addr, .flags = 0,
236                   .buf = buf, .len = 4 };
237         int err;
238
239         /* Switch PLL to DVB mode */
240         err = philips_fmd1216_pll_init(fe);
241         if (err)
242                 return err;
243
244         /* Tune PLL */
245         dvb_pll_configure(dev->core->pll_desc, buf,
246                           params->frequency,
247                           params->u.ofdm.bandwidth);
248         if (fe->ops.i2c_gate_ctrl)
249                 fe->ops.i2c_gate_ctrl(fe, 1);
250         if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
251
252                 printk(KERN_WARNING "cx88-dvb: %s error "
253                        "(addr %02x <- %02x, err = %i)\n",
254                        __FUNCTION__, dev->core->pll_addr, buf[0], err);
255                 if (err < 0)
256                         return err;
257                 else
258                         return -EREMOTEIO;
259         }
260
261         return 0;
262 }
263
264 static struct mt352_config dntv_live_dvbt_pro_config = {
265         .demod_address = 0x0f,
266         .no_tuner      = 1,
267         .demod_init    = dntv_live_dvbt_pro_demod_init,
268 };
269 #endif
270
271 static int dvico_hybrid_tuner_set_params(struct dvb_frontend *fe,
272                                          struct dvb_frontend_parameters *params)
273 {
274         u8 pllbuf[4];
275         struct cx8802_dev *dev= fe->dvb->priv;
276         struct i2c_msg msg =
277                 { .addr = dev->core->pll_addr, .flags = 0,
278                   .buf = pllbuf, .len = 4 };
279         int err;
280
281         dvb_pll_configure(dev->core->pll_desc, pllbuf,
282                           params->frequency,
283                           params->u.ofdm.bandwidth);
284
285         if (fe->ops.i2c_gate_ctrl)
286                 fe->ops.i2c_gate_ctrl(fe, 1);
287         if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
288                 printk(KERN_WARNING "cx88-dvb: %s error "
289                        "(addr %02x <- %02x, err = %i)\n",
290                        __FUNCTION__, pllbuf[0], pllbuf[1], err);
291                 if (err < 0)
292                         return err;
293                 else
294                         return -EREMOTEIO;
295         }
296
297         return 0;
298 }
299
300 static struct zl10353_config dvico_fusionhdtv_hybrid = {
301         .demod_address = 0x0f,
302         .no_tuner      = 1,
303 };
304
305 static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
306         .demod_address = 0x0f,
307 };
308
309 static struct cx22702_config connexant_refboard_config = {
310         .demod_address = 0x43,
311         .output_mode   = CX22702_SERIAL_OUTPUT,
312 };
313
314 static struct cx22702_config hauppauge_novat_config = {
315         .demod_address = 0x43,
316         .output_mode   = CX22702_SERIAL_OUTPUT,
317 };
318 static struct cx22702_config hauppauge_hvr1100_config = {
319         .demod_address = 0x63,
320         .output_mode   = CX22702_SERIAL_OUTPUT,
321 };
322 static struct cx22702_config hauppauge_hvr1300_config = {
323         .demod_address = 0x63,
324         .output_mode   = CX22702_SERIAL_OUTPUT,
325 };
326
327 static int or51132_set_ts_param(struct dvb_frontend* fe,
328                                 int is_punctured)
329 {
330         struct cx8802_dev *dev= fe->dvb->priv;
331         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
332         return 0;
333 }
334
335 static struct or51132_config pchdtv_hd3000 = {
336         .demod_address = 0x15,
337         .set_ts_params = or51132_set_ts_param,
338 };
339
340 static int lgdt3302_tuner_set_params(struct dvb_frontend* fe,
341                                      struct dvb_frontend_parameters* params)
342 {
343         /* FIXME make this routine use the tuner-simple code.
344          * It could probably be shared with a number of ATSC
345          * frontends. Many share the same tuner with analog TV. */
346
347         struct cx8802_dev *dev= fe->dvb->priv;
348         struct cx88_core *core = dev->core;
349         u8 buf[4];
350         struct i2c_msg msg =
351                 { .addr = dev->core->pll_addr, .flags = 0, .buf = buf, .len = 4 };
352         int err;
353
354         dvb_pll_configure(core->pll_desc, buf, params->frequency, 0);
355         dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",
356                 __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]);
357
358         if (fe->ops.i2c_gate_ctrl)
359                 fe->ops.i2c_gate_ctrl(fe, 1);
360         if ((err = i2c_transfer(&core->i2c_adap, &msg, 1)) != 1) {
361                 printk(KERN_WARNING "cx88-dvb: %s error "
362                        "(addr %02x <- %02x, err = %i)\n",
363                        __FUNCTION__, buf[0], buf[1], err);
364                 if (err < 0)
365                         return err;
366                 else
367                         return -EREMOTEIO;
368         }
369         return 0;
370 }
371
372 static int lgdt3303_tuner_set_params(struct dvb_frontend* fe,
373                                      struct dvb_frontend_parameters* params)
374 {
375         struct cx8802_dev *dev= fe->dvb->priv;
376         struct cx88_core *core = dev->core;
377
378         /* Put the analog decoder in standby to keep it quiet */
379         cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
380
381         return lg_h06xf_pll_set(fe, &core->i2c_adap, params);
382 }
383
384 static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
385 {
386         struct cx8802_dev *dev= fe->dvb->priv;
387         struct cx88_core *core = dev->core;
388
389         dprintk(1, "%s: index = %d\n", __FUNCTION__, index);
390         if (index == 0)
391                 cx_clear(MO_GP0_IO, 8);
392         else
393                 cx_set(MO_GP0_IO, 8);
394         return 0;
395 }
396
397 static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
398 {
399         struct cx8802_dev *dev= fe->dvb->priv;
400         if (is_punctured)
401                 dev->ts_gen_cntrl |= 0x04;
402         else
403                 dev->ts_gen_cntrl &= ~0x04;
404         return 0;
405 }
406
407 static struct lgdt330x_config fusionhdtv_3_gold = {
408         .demod_address = 0x0e,
409         .demod_chip    = LGDT3302,
410         .serial_mpeg   = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
411         .set_ts_params = lgdt330x_set_ts_param,
412 };
413
414 static struct lgdt330x_config fusionhdtv_5_gold = {
415         .demod_address = 0x0e,
416         .demod_chip    = LGDT3303,
417         .serial_mpeg   = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
418         .set_ts_params = lgdt330x_set_ts_param,
419 };
420
421 static struct lgdt330x_config pchdtv_hd5500 = {
422         .demod_address = 0x59,
423         .demod_chip    = LGDT3303,
424         .serial_mpeg   = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
425         .set_ts_params = lgdt330x_set_ts_param,
426 };
427
428 static int nxt200x_set_ts_param(struct dvb_frontend* fe,
429                                 int is_punctured)
430 {
431         struct cx8802_dev *dev= fe->dvb->priv;
432         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
433         return 0;
434 }
435
436 static int nxt200x_set_pll_input(u8* buf, int input)
437 {
438         if (input)
439                 buf[3] |= 0x08;
440         else
441                 buf[3] &= ~0x08;
442         return 0;
443 }
444
445 static struct nxt200x_config ati_hdtvwonder = {
446         .demod_address = 0x0a,
447         .set_pll_input = nxt200x_set_pll_input,
448         .set_ts_params = nxt200x_set_ts_param,
449 };
450
451 static int cx24123_set_ts_param(struct dvb_frontend* fe,
452         int is_punctured)
453 {
454         struct cx8802_dev *dev= fe->dvb->priv;
455         dev->ts_gen_cntrl = 0x02;
456         return 0;
457 }
458
459 static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
460                                        fe_sec_voltage_t voltage)
461 {
462         struct cx8802_dev *dev= fe->dvb->priv;
463         struct cx88_core *core = dev->core;
464
465         if (voltage == SEC_VOLTAGE_OFF) {
466                 cx_write(MO_GP0_IO, 0x000006fb);
467         } else {
468                 cx_write(MO_GP0_IO, 0x000006f9);
469         }
470
471         if (core->prev_set_voltage)
472                 return core->prev_set_voltage(fe, voltage);
473         return 0;
474 }
475
476 static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
477                                       fe_sec_voltage_t voltage)
478 {
479         struct cx8802_dev *dev= fe->dvb->priv;
480         struct cx88_core *core = dev->core;
481
482         if (voltage == SEC_VOLTAGE_OFF) {
483                 dprintk(1,"LNB Voltage OFF\n");
484                 cx_write(MO_GP0_IO, 0x0000efff);
485         }
486
487         if (core->prev_set_voltage)
488                 return core->prev_set_voltage(fe, voltage);
489         return 0;
490 }
491
492 static struct cx24123_config geniatech_dvbs_config = {
493         .demod_address = 0x55,
494         .set_ts_params = cx24123_set_ts_param,
495 };
496
497 static struct cx24123_config hauppauge_novas_config = {
498         .demod_address = 0x55,
499         .set_ts_params = cx24123_set_ts_param,
500 };
501
502 static struct cx24123_config kworld_dvbs_100_config = {
503         .demod_address = 0x15,
504         .set_ts_params = cx24123_set_ts_param,
505         .lnb_polarity  = 1,
506 };
507
508 static int dvb_register(struct cx8802_dev *dev)
509 {
510         /* init struct videobuf_dvb */
511         dev->dvb.name = dev->core->name;
512         dev->ts_gen_cntrl = 0x0c;
513
514         /* init frontend */
515         switch (dev->core->board) {
516         case CX88_BOARD_HAUPPAUGE_DVB_T1:
517                 dev->dvb.frontend = dvb_attach(cx22702_attach,
518                                                &hauppauge_novat_config,
519                                                &dev->core->i2c_adap);
520                 if (dev->dvb.frontend != NULL) {
521                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
522                                    &dev->core->i2c_adap,
523                                    &dvb_pll_thomson_dtt759x);
524                 }
525                 break;
526         case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
527         case CX88_BOARD_CONEXANT_DVB_T1:
528         case CX88_BOARD_KWORLD_DVB_T_CX22702:
529         case CX88_BOARD_WINFAST_DTV1000:
530                 dev->dvb.frontend = dvb_attach(cx22702_attach,
531                                                &connexant_refboard_config,
532                                                &dev->core->i2c_adap);
533                 if (dev->dvb.frontend != NULL) {
534                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
535                                    &dev->core->i2c_adap,
536                                    &dvb_pll_thomson_dtt7579);
537                 }
538                 break;
539         case CX88_BOARD_WINFAST_DTV2000H:
540         case CX88_BOARD_HAUPPAUGE_HVR1100:
541         case CX88_BOARD_HAUPPAUGE_HVR1100LP:
542                 dev->dvb.frontend = dvb_attach(cx22702_attach,
543                                                &hauppauge_hvr1100_config,
544                                                &dev->core->i2c_adap);
545                 if (dev->dvb.frontend != NULL) {
546                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
547                                    &dev->core->i2c_adap,
548                                    &dvb_pll_fmd1216me);
549                 }
550                 break;
551         case CX88_BOARD_HAUPPAUGE_HVR1300:
552                 dev->dvb.frontend = dvb_attach(cx22702_attach,
553                                                &hauppauge_hvr1300_config,
554                                                &dev->core->i2c_adap);
555                 if (dev->dvb.frontend != NULL) {
556                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
557                                    &dev->core->i2c_adap,
558                                    &dvb_pll_fmd1216me);
559                 }
560                 break;
561         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
562                 dev->dvb.frontend = dvb_attach(mt352_attach,
563                                                &dvico_fusionhdtv,
564                                                &dev->core->i2c_adap);
565                 if (dev->dvb.frontend != NULL) {
566                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
567                                    NULL, &dvb_pll_thomson_dtt7579);
568                         break;
569                 }
570                 /* ZL10353 replaces MT352 on later cards */
571                 dev->dvb.frontend = dvb_attach(zl10353_attach,
572                                                &dvico_fusionhdtv_plus_v1_1,
573                                                &dev->core->i2c_adap);
574                 if (dev->dvb.frontend != NULL) {
575                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
576                                    NULL, &dvb_pll_thomson_dtt7579);
577                 }
578                 break;
579         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
580                 /* The tin box says DEE1601, but it seems to be DTT7579
581                  * compatible, with a slightly different MT352 AGC gain. */
582                 dev->dvb.frontend = dvb_attach(mt352_attach,
583                                                &dvico_fusionhdtv_dual,
584                                                &dev->core->i2c_adap);
585                 if (dev->dvb.frontend != NULL) {
586                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
587                                    NULL, &dvb_pll_thomson_dtt7579);
588                         break;
589                 }
590                 /* ZL10353 replaces MT352 on later cards */
591                 dev->dvb.frontend = dvb_attach(zl10353_attach,
592                                                &dvico_fusionhdtv_plus_v1_1,
593                                                &dev->core->i2c_adap);
594                 if (dev->dvb.frontend != NULL) {
595                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
596                                    NULL, &dvb_pll_thomson_dtt7579);
597                 }
598                 break;
599         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
600                 dev->dvb.frontend = dvb_attach(mt352_attach,
601                                                &dvico_fusionhdtv,
602                                                &dev->core->i2c_adap);
603                 if (dev->dvb.frontend != NULL) {
604                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
605                                    NULL, &dvb_pll_lg_z201);
606                 }
607                 break;
608         case CX88_BOARD_KWORLD_DVB_T:
609         case CX88_BOARD_DNTV_LIVE_DVB_T:
610         case CX88_BOARD_ADSTECH_DVB_T_PCI:
611                 dev->dvb.frontend = dvb_attach(mt352_attach,
612                                                &dntv_live_dvbt_config,
613                                                &dev->core->i2c_adap);
614                 if (dev->dvb.frontend != NULL) {
615                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
616                                    NULL, &dvb_pll_unknown_1);
617                 }
618                 break;
619         case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
620 #ifdef HAVE_VP3054_I2C
621                 dev->core->pll_addr = 0x61;
622                 dev->core->pll_desc = &dvb_pll_fmd1216me;
623                 dev->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
624                         &((struct vp3054_i2c_state *)dev->card_priv)->adap);
625                 if (dev->dvb.frontend != NULL) {
626                         dev->dvb.frontend->ops.tuner_ops.set_params = dntv_live_dvbt_pro_tuner_set_params;
627                 }
628 #else
629                 printk("%s: built without vp3054 support\n", dev->core->name);
630 #endif
631                 break;
632         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
633                 dev->core->pll_addr = 0x61;
634                 dev->core->pll_desc = &dvb_pll_thomson_fe6600;
635                 dev->dvb.frontend = dvb_attach(zl10353_attach,
636                                                &dvico_fusionhdtv_hybrid,
637                                                &dev->core->i2c_adap);
638                 if (dev->dvb.frontend != NULL) {
639                         dev->dvb.frontend->ops.tuner_ops.set_params = dvico_hybrid_tuner_set_params;
640                 }
641                 break;
642         case CX88_BOARD_PCHDTV_HD3000:
643                 dev->dvb.frontend = dvb_attach(or51132_attach,
644                                                &pchdtv_hd3000,
645                                                &dev->core->i2c_adap);
646                 if (dev->dvb.frontend != NULL) {
647                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
648                                    &dev->core->i2c_adap,
649                                    &dvb_pll_thomson_dtt761x);
650                 }
651                 break;
652         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
653                 dev->ts_gen_cntrl = 0x08;
654                 {
655                 /* Do a hardware reset of chip before using it. */
656                 struct cx88_core *core = dev->core;
657
658                 cx_clear(MO_GP0_IO, 1);
659                 mdelay(100);
660                 cx_set(MO_GP0_IO, 1);
661                 mdelay(200);
662
663                 /* Select RF connector callback */
664                 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
665                 dev->core->pll_addr = 0x61;
666                 dev->core->pll_desc = &dvb_pll_microtune_4042;
667                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
668                                                &fusionhdtv_3_gold,
669                                                &dev->core->i2c_adap);
670                 if (dev->dvb.frontend != NULL) {
671                         dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3302_tuner_set_params;
672                 }
673                 }
674                 break;
675         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
676                 dev->ts_gen_cntrl = 0x08;
677                 {
678                 /* Do a hardware reset of chip before using it. */
679                 struct cx88_core *core = dev->core;
680
681                 cx_clear(MO_GP0_IO, 1);
682                 mdelay(100);
683                 cx_set(MO_GP0_IO, 9);
684                 mdelay(200);
685                 dev->core->pll_addr = 0x61;
686                 dev->core->pll_desc = &dvb_pll_thomson_dtt761x;
687                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
688                                                &fusionhdtv_3_gold,
689                                                &dev->core->i2c_adap);
690                 if (dev->dvb.frontend != NULL) {
691                         dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3302_tuner_set_params;
692                 }
693                 }
694                 break;
695         case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
696                 dev->ts_gen_cntrl = 0x08;
697                 {
698                 /* Do a hardware reset of chip before using it. */
699                 struct cx88_core *core = dev->core;
700
701                 cx_clear(MO_GP0_IO, 1);
702                 mdelay(100);
703                 cx_set(MO_GP0_IO, 1);
704                 mdelay(200);
705                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
706                                                &fusionhdtv_5_gold,
707                                                &dev->core->i2c_adap);
708                 if (dev->dvb.frontend != NULL) {
709                         dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3303_tuner_set_params;
710                 }
711                 }
712                 break;
713         case CX88_BOARD_PCHDTV_HD5500:
714                 dev->ts_gen_cntrl = 0x08;
715                 {
716                 /* Do a hardware reset of chip before using it. */
717                 struct cx88_core *core = dev->core;
718
719                 cx_clear(MO_GP0_IO, 1);
720                 mdelay(100);
721                 cx_set(MO_GP0_IO, 1);
722                 mdelay(200);
723                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
724                                                &pchdtv_hd5500,
725                                                &dev->core->i2c_adap);
726                 if (dev->dvb.frontend != NULL) {
727                         dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3303_tuner_set_params;
728                 }
729                 }
730                 break;
731         case CX88_BOARD_ATI_HDTVWONDER:
732                 dev->dvb.frontend = dvb_attach(nxt200x_attach,
733                                                &ati_hdtvwonder,
734                                                &dev->core->i2c_adap);
735                 if (dev->dvb.frontend != NULL) {
736                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
737                                    NULL, &dvb_pll_tuv1236d);
738                 }
739                 break;
740         case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
741         case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
742                 dev->dvb.frontend = dvb_attach(cx24123_attach,
743                                                &hauppauge_novas_config,
744                                                &dev->core->i2c_adap);
745                 if (dev->dvb.frontend) {
746                         dvb_attach(isl6421_attach, dev->dvb.frontend,
747                                    &dev->core->i2c_adap, 0x08, 0x00, 0x00);
748                 }
749                 break;
750         case CX88_BOARD_KWORLD_DVBS_100:
751                 dev->dvb.frontend = dvb_attach(cx24123_attach,
752                                                &kworld_dvbs_100_config,
753                                                &dev->core->i2c_adap);
754                 if (dev->dvb.frontend) {
755                         dev->core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
756                         dev->dvb.frontend->ops.set_voltage = kworld_dvbs_100_set_voltage;
757                 }
758                 break;
759         case CX88_BOARD_GENIATECH_DVBS:
760                 dev->dvb.frontend = dvb_attach(cx24123_attach,
761                                                &geniatech_dvbs_config,
762                                                &dev->core->i2c_adap);
763                 if (dev->dvb.frontend) {
764                         dev->core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
765                         dev->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;
766                 }
767                 break;
768         default:
769                 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
770                        dev->core->name);
771                 break;
772         }
773         if (NULL == dev->dvb.frontend) {
774                 printk("%s: frontend initialization failed\n",dev->core->name);
775                 return -1;
776         }
777
778         if (dev->core->pll_desc) {
779                 dev->dvb.frontend->ops.info.frequency_min = dev->core->pll_desc->min;
780                 dev->dvb.frontend->ops.info.frequency_max = dev->core->pll_desc->max;
781         }
782
783         /* Put the analog decoder in standby to keep it quiet */
784         cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
785
786         /* register everything */
787         return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
788 }
789
790 /* ----------------------------------------------------------- */
791
792 static int __devinit dvb_probe(struct pci_dev *pci_dev,
793                                const struct pci_device_id *pci_id)
794 {
795         struct cx8802_dev *dev;
796         struct cx88_core  *core;
797         int err;
798
799         /* general setup */
800         core = cx88_core_get(pci_dev);
801         if (NULL == core)
802                 return -EINVAL;
803
804         err = -ENODEV;
805         if (!(cx88_boards[core->board].mpeg & CX88_MPEG_DVB))
806                 goto fail_core;
807
808         err = -ENOMEM;
809         dev = kzalloc(sizeof(*dev),GFP_KERNEL);
810         if (NULL == dev)
811                 goto fail_core;
812         dev->pci = pci_dev;
813         dev->core = core;
814
815         err = cx8802_init_common(dev);
816         if (0 != err)
817                 goto fail_free;
818
819 #ifdef HAVE_VP3054_I2C
820         err = vp3054_i2c_probe(dev);
821         if (0 != err)
822                 goto fail_free;
823 #endif
824
825         /* dvb stuff */
826         printk("%s/2: cx2388x based dvb card\n", core->name);
827         videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops,
828                             dev->pci, &dev->slock,
829                             V4L2_BUF_TYPE_VIDEO_CAPTURE,
830                             V4L2_FIELD_TOP,
831                             sizeof(struct cx88_buffer),
832                             dev);
833         err = dvb_register(dev);
834         if (0 != err)
835                 goto fail_fini;
836
837         /* Maintain a reference to cx88-video can query the 8802 device. */
838         core->dvbdev = dev;
839         return 0;
840
841  fail_fini:
842         cx8802_fini_common(dev);
843  fail_free:
844         kfree(dev);
845  fail_core:
846         cx88_core_put(core,pci_dev);
847         return err;
848 }
849
850 static void __devexit dvb_remove(struct pci_dev *pci_dev)
851 {
852         struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
853
854         /* Destroy any 8802 reference. */
855         dev->core->dvbdev = NULL;
856
857         /* dvb */
858         videobuf_dvb_unregister(&dev->dvb);
859
860 #ifdef HAVE_VP3054_I2C
861         vp3054_i2c_remove(dev);
862 #endif
863
864         /* common */
865         cx8802_fini_common(dev);
866         cx88_core_put(dev->core,dev->pci);
867         kfree(dev);
868 }
869
870 static struct pci_device_id cx8802_pci_tbl[] = {
871         {
872                 .vendor       = 0x14f1,
873                 .device       = 0x8802,
874                 .subvendor    = PCI_ANY_ID,
875                 .subdevice    = PCI_ANY_ID,
876         },{
877                 /* --- end of list --- */
878         }
879 };
880 MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
881
882 static struct pci_driver dvb_pci_driver = {
883         .name     = "cx88-dvb",
884         .id_table = cx8802_pci_tbl,
885         .probe    = dvb_probe,
886         .remove   = __devexit_p(dvb_remove),
887 #ifdef CONFIG_PM
888         .suspend  = cx8802_suspend_common,
889         .resume   = cx8802_resume_common,
890 #endif
891 };
892
893 static int dvb_init(void)
894 {
895         printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n",
896                (CX88_VERSION_CODE >> 16) & 0xff,
897                (CX88_VERSION_CODE >>  8) & 0xff,
898                CX88_VERSION_CODE & 0xff);
899 #ifdef SNAPSHOT
900         printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
901                SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
902 #endif
903         return pci_register_driver(&dvb_pci_driver);
904 }
905
906 static void dvb_fini(void)
907 {
908         pci_unregister_driver(&dvb_pci_driver);
909 }
910
911 module_init(dvb_init);
912 module_exit(dvb_fini);
913
914 /*
915  * Local variables:
916  * c-basic-offset: 8
917  * compile-command: "make DVB=1"
918  * End:
919  */