V4L/DVB (4944): Cx88: Convert DViCO FusionHDTV Hybrid to use dvb_pll_attach
[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 #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 "lgh06xf.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, 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 struct zl10353_config dvico_fusionhdtv_hybrid = {
272         .demod_address = 0x0f,
273         .no_tuner      = 1,
274 };
275
276 static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
277         .demod_address = 0x0f,
278 };
279
280 static struct cx22702_config connexant_refboard_config = {
281         .demod_address = 0x43,
282         .output_mode   = CX22702_SERIAL_OUTPUT,
283 };
284
285 static struct cx22702_config hauppauge_novat_config = {
286         .demod_address = 0x43,
287         .output_mode   = CX22702_SERIAL_OUTPUT,
288 };
289 static struct cx22702_config hauppauge_hvr1100_config = {
290         .demod_address = 0x63,
291         .output_mode   = CX22702_SERIAL_OUTPUT,
292 };
293 static struct cx22702_config hauppauge_hvr3000_config = {
294         .demod_address = 0x63,
295         .output_mode   = CX22702_SERIAL_OUTPUT,
296 };
297
298 static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe,
299         int acquire)
300 {
301         struct cx8802_dev *dev= fe->dvb->priv;
302         struct cx8802_driver *drv = NULL;
303         int ret = 0;
304
305         drv = cx8802_get_driver(dev, CX88_MPEG_DVB);
306         if (drv) {
307                 if(acquire)
308                         ret = drv->request_acquire(drv);
309                 else
310                         ret = drv->request_release(drv);
311         }
312
313         return ret;
314 }
315
316 static struct cx22702_config hauppauge_hvr1300_config = {
317         .demod_address = 0x63,
318         .output_mode   = CX22702_SERIAL_OUTPUT,
319 };
320
321 static int or51132_set_ts_param(struct dvb_frontend* fe,
322                                 int is_punctured)
323 {
324         struct cx8802_dev *dev= fe->dvb->priv;
325         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
326         return 0;
327 }
328
329 static struct or51132_config pchdtv_hd3000 = {
330         .demod_address = 0x15,
331         .set_ts_params = or51132_set_ts_param,
332 };
333
334 static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
335 {
336         struct cx8802_dev *dev= fe->dvb->priv;
337         struct cx88_core *core = dev->core;
338
339         dprintk(1, "%s: index = %d\n", __FUNCTION__, index);
340         if (index == 0)
341                 cx_clear(MO_GP0_IO, 8);
342         else
343                 cx_set(MO_GP0_IO, 8);
344         return 0;
345 }
346
347 static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
348 {
349         struct cx8802_dev *dev= fe->dvb->priv;
350         if (is_punctured)
351                 dev->ts_gen_cntrl |= 0x04;
352         else
353                 dev->ts_gen_cntrl &= ~0x04;
354         return 0;
355 }
356
357 static struct lgdt330x_config fusionhdtv_3_gold = {
358         .demod_address = 0x0e,
359         .demod_chip    = LGDT3302,
360         .serial_mpeg   = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
361         .set_ts_params = lgdt330x_set_ts_param,
362 };
363
364 static struct lgdt330x_config fusionhdtv_5_gold = {
365         .demod_address = 0x0e,
366         .demod_chip    = LGDT3303,
367         .serial_mpeg   = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
368         .set_ts_params = lgdt330x_set_ts_param,
369 };
370
371 static struct lgdt330x_config pchdtv_hd5500 = {
372         .demod_address = 0x59,
373         .demod_chip    = LGDT3303,
374         .serial_mpeg   = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
375         .set_ts_params = lgdt330x_set_ts_param,
376 };
377
378 static int nxt200x_set_ts_param(struct dvb_frontend* fe,
379                                 int is_punctured)
380 {
381         struct cx8802_dev *dev= fe->dvb->priv;
382         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
383         return 0;
384 }
385
386 static int nxt200x_set_pll_input(u8* buf, int input)
387 {
388         if (input)
389                 buf[3] |= 0x08;
390         else
391                 buf[3] &= ~0x08;
392         return 0;
393 }
394
395 static struct nxt200x_config ati_hdtvwonder = {
396         .demod_address = 0x0a,
397         .set_pll_input = nxt200x_set_pll_input,
398         .set_ts_params = nxt200x_set_ts_param,
399 };
400
401 static int cx24123_set_ts_param(struct dvb_frontend* fe,
402         int is_punctured)
403 {
404         struct cx8802_dev *dev= fe->dvb->priv;
405         dev->ts_gen_cntrl = 0x02;
406         return 0;
407 }
408
409 static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
410                                        fe_sec_voltage_t voltage)
411 {
412         struct cx8802_dev *dev= fe->dvb->priv;
413         struct cx88_core *core = dev->core;
414
415         if (voltage == SEC_VOLTAGE_OFF) {
416                 cx_write(MO_GP0_IO, 0x000006fb);
417         } else {
418                 cx_write(MO_GP0_IO, 0x000006f9);
419         }
420
421         if (core->prev_set_voltage)
422                 return core->prev_set_voltage(fe, voltage);
423         return 0;
424 }
425
426 static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
427                                       fe_sec_voltage_t voltage)
428 {
429         struct cx8802_dev *dev= fe->dvb->priv;
430         struct cx88_core *core = dev->core;
431
432         if (voltage == SEC_VOLTAGE_OFF) {
433                 dprintk(1,"LNB Voltage OFF\n");
434                 cx_write(MO_GP0_IO, 0x0000efff);
435         }
436
437         if (core->prev_set_voltage)
438                 return core->prev_set_voltage(fe, voltage);
439         return 0;
440 }
441
442 static struct cx24123_config geniatech_dvbs_config = {
443         .demod_address = 0x55,
444         .set_ts_params = cx24123_set_ts_param,
445 };
446
447 static struct cx24123_config hauppauge_novas_config = {
448         .demod_address = 0x55,
449         .set_ts_params = cx24123_set_ts_param,
450 };
451
452 static struct cx24123_config kworld_dvbs_100_config = {
453         .demod_address = 0x15,
454         .set_ts_params = cx24123_set_ts_param,
455         .lnb_polarity  = 1,
456 };
457
458 static int dvb_register(struct cx8802_dev *dev)
459 {
460         /* init struct videobuf_dvb */
461         dev->dvb.name = dev->core->name;
462         dev->ts_gen_cntrl = 0x0c;
463
464         /* init frontend */
465         switch (dev->core->board) {
466         case CX88_BOARD_HAUPPAUGE_DVB_T1:
467                 dev->dvb.frontend = dvb_attach(cx22702_attach,
468                                                &hauppauge_novat_config,
469                                                &dev->core->i2c_adap);
470                 if (dev->dvb.frontend != NULL) {
471                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
472                                    &dev->core->i2c_adap,
473                                    &dvb_pll_thomson_dtt759x);
474                 }
475                 break;
476         case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
477         case CX88_BOARD_CONEXANT_DVB_T1:
478         case CX88_BOARD_KWORLD_DVB_T_CX22702:
479         case CX88_BOARD_WINFAST_DTV1000:
480                 dev->dvb.frontend = dvb_attach(cx22702_attach,
481                                                &connexant_refboard_config,
482                                                &dev->core->i2c_adap);
483                 if (dev->dvb.frontend != NULL) {
484                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
485                                    &dev->core->i2c_adap,
486                                    &dvb_pll_thomson_dtt7579);
487                 }
488                 break;
489         case CX88_BOARD_WINFAST_DTV2000H:
490         case CX88_BOARD_HAUPPAUGE_HVR1100:
491         case CX88_BOARD_HAUPPAUGE_HVR1100LP:
492                 dev->dvb.frontend = dvb_attach(cx22702_attach,
493                                                &hauppauge_hvr1100_config,
494                                                &dev->core->i2c_adap);
495                 if (dev->dvb.frontend != NULL) {
496                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
497                                    &dev->core->i2c_adap,
498                                    &dvb_pll_fmd1216me);
499                 }
500                 break;
501         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
502                 dev->dvb.frontend = dvb_attach(mt352_attach,
503                                                &dvico_fusionhdtv,
504                                                &dev->core->i2c_adap);
505                 if (dev->dvb.frontend != NULL) {
506                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
507                                    NULL, &dvb_pll_thomson_dtt7579);
508                         break;
509                 }
510                 /* ZL10353 replaces MT352 on later cards */
511                 dev->dvb.frontend = dvb_attach(zl10353_attach,
512                                                &dvico_fusionhdtv_plus_v1_1,
513                                                &dev->core->i2c_adap);
514                 if (dev->dvb.frontend != NULL) {
515                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
516                                    NULL, &dvb_pll_thomson_dtt7579);
517                 }
518                 break;
519         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
520                 /* The tin box says DEE1601, but it seems to be DTT7579
521                  * compatible, with a slightly different MT352 AGC gain. */
522                 dev->dvb.frontend = dvb_attach(mt352_attach,
523                                                &dvico_fusionhdtv_dual,
524                                                &dev->core->i2c_adap);
525                 if (dev->dvb.frontend != NULL) {
526                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
527                                    NULL, &dvb_pll_thomson_dtt7579);
528                         break;
529                 }
530                 /* ZL10353 replaces MT352 on later cards */
531                 dev->dvb.frontend = dvb_attach(zl10353_attach,
532                                                &dvico_fusionhdtv_plus_v1_1,
533                                                &dev->core->i2c_adap);
534                 if (dev->dvb.frontend != NULL) {
535                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
536                                    NULL, &dvb_pll_thomson_dtt7579);
537                 }
538                 break;
539         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
540                 dev->dvb.frontend = dvb_attach(mt352_attach,
541                                                &dvico_fusionhdtv,
542                                                &dev->core->i2c_adap);
543                 if (dev->dvb.frontend != NULL) {
544                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
545                                    NULL, &dvb_pll_lg_z201);
546                 }
547                 break;
548         case CX88_BOARD_KWORLD_DVB_T:
549         case CX88_BOARD_DNTV_LIVE_DVB_T:
550         case CX88_BOARD_ADSTECH_DVB_T_PCI:
551                 dev->dvb.frontend = dvb_attach(mt352_attach,
552                                                &dntv_live_dvbt_config,
553                                                &dev->core->i2c_adap);
554                 if (dev->dvb.frontend != NULL) {
555                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
556                                    NULL, &dvb_pll_unknown_1);
557                 }
558                 break;
559         case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
560 #ifdef HAVE_VP3054_I2C
561                 dev->core->pll_addr = 0x61;
562                 dev->core->pll_desc = &dvb_pll_fmd1216me;
563                 dev->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
564                         &((struct vp3054_i2c_state *)dev->card_priv)->adap);
565                 if (dev->dvb.frontend != NULL) {
566                         dev->dvb.frontend->ops.tuner_ops.set_params = dntv_live_dvbt_pro_tuner_set_params;
567                 }
568 #else
569                 printk("%s: built without vp3054 support\n", dev->core->name);
570 #endif
571                 break;
572         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
573                 dev->dvb.frontend = dvb_attach(zl10353_attach,
574                                                &dvico_fusionhdtv_hybrid,
575                                                &dev->core->i2c_adap);
576                 if (dev->dvb.frontend != NULL) {
577                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
578                                    &dev->core->i2c_adap,
579                                    &dvb_pll_thomson_fe6600);
580                 }
581                 break;
582         case CX88_BOARD_PCHDTV_HD3000:
583                 dev->dvb.frontend = dvb_attach(or51132_attach,
584                                                &pchdtv_hd3000,
585                                                &dev->core->i2c_adap);
586                 if (dev->dvb.frontend != NULL) {
587                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
588                                    &dev->core->i2c_adap,
589                                    &dvb_pll_thomson_dtt761x);
590                 }
591                 break;
592         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
593                 dev->ts_gen_cntrl = 0x08;
594                 {
595                 /* Do a hardware reset of chip before using it. */
596                 struct cx88_core *core = dev->core;
597
598                 cx_clear(MO_GP0_IO, 1);
599                 mdelay(100);
600                 cx_set(MO_GP0_IO, 1);
601                 mdelay(200);
602
603                 /* Select RF connector callback */
604                 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
605                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
606                                                &fusionhdtv_3_gold,
607                                                &dev->core->i2c_adap);
608                 if (dev->dvb.frontend != NULL) {
609                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
610                                    &dev->core->i2c_adap,
611                                    &dvb_pll_microtune_4042);
612                 }
613                 }
614                 break;
615         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
616                 dev->ts_gen_cntrl = 0x08;
617                 {
618                 /* Do a hardware reset of chip before using it. */
619                 struct cx88_core *core = dev->core;
620
621                 cx_clear(MO_GP0_IO, 1);
622                 mdelay(100);
623                 cx_set(MO_GP0_IO, 9);
624                 mdelay(200);
625                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
626                                                &fusionhdtv_3_gold,
627                                                &dev->core->i2c_adap);
628                 if (dev->dvb.frontend != NULL) {
629                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
630                                    &dev->core->i2c_adap,
631                                    &dvb_pll_thomson_dtt761x);
632                 }
633                 }
634                 break;
635         case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
636                 dev->ts_gen_cntrl = 0x08;
637                 {
638                 /* Do a hardware reset of chip before using it. */
639                 struct cx88_core *core = dev->core;
640
641                 cx_clear(MO_GP0_IO, 1);
642                 mdelay(100);
643                 cx_set(MO_GP0_IO, 1);
644                 mdelay(200);
645                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
646                                                &fusionhdtv_5_gold,
647                                                &dev->core->i2c_adap);
648                 if (dev->dvb.frontend != NULL) {
649                         dvb_attach(lgh06xf_attach, dev->dvb.frontend,
650                                    &dev->core->i2c_adap);
651                 }
652                 }
653                 break;
654         case CX88_BOARD_PCHDTV_HD5500:
655                 dev->ts_gen_cntrl = 0x08;
656                 {
657                 /* Do a hardware reset of chip before using it. */
658                 struct cx88_core *core = dev->core;
659
660                 cx_clear(MO_GP0_IO, 1);
661                 mdelay(100);
662                 cx_set(MO_GP0_IO, 1);
663                 mdelay(200);
664                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
665                                                &pchdtv_hd5500,
666                                                &dev->core->i2c_adap);
667                 if (dev->dvb.frontend != NULL) {
668                         dvb_attach(lgh06xf_attach, dev->dvb.frontend,
669                                    &dev->core->i2c_adap);
670                 }
671                 }
672                 break;
673         case CX88_BOARD_ATI_HDTVWONDER:
674                 dev->dvb.frontend = dvb_attach(nxt200x_attach,
675                                                &ati_hdtvwonder,
676                                                &dev->core->i2c_adap);
677                 if (dev->dvb.frontend != NULL) {
678                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
679                                    NULL, &dvb_pll_tuv1236d);
680                 }
681                 break;
682         case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
683         case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
684                 dev->dvb.frontend = dvb_attach(cx24123_attach,
685                                                &hauppauge_novas_config,
686                                                &dev->core->i2c_adap);
687                 if (dev->dvb.frontend) {
688                         dvb_attach(isl6421_attach, dev->dvb.frontend,
689                                    &dev->core->i2c_adap, 0x08, 0x00, 0x00);
690                 }
691                 break;
692         case CX88_BOARD_KWORLD_DVBS_100:
693                 dev->dvb.frontend = dvb_attach(cx24123_attach,
694                                                &kworld_dvbs_100_config,
695                                                &dev->core->i2c_adap);
696                 if (dev->dvb.frontend) {
697                         dev->core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
698                         dev->dvb.frontend->ops.set_voltage = kworld_dvbs_100_set_voltage;
699                 }
700                 break;
701         case CX88_BOARD_GENIATECH_DVBS:
702                 dev->dvb.frontend = dvb_attach(cx24123_attach,
703                                                &geniatech_dvbs_config,
704                                                &dev->core->i2c_adap);
705                 if (dev->dvb.frontend) {
706                         dev->core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
707                         dev->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;
708                 }
709                 break;
710         case CX88_BOARD_HAUPPAUGE_HVR1300:
711                 dev->dvb.frontend = dvb_attach(cx22702_attach,
712                                                &hauppauge_hvr1300_config,
713                                                &dev->core->i2c_adap);
714                 if (dev->dvb.frontend != NULL) {
715                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
716                                    &dev->core->i2c_adap,
717                                    &dvb_pll_fmd1216me);
718                 }
719                 break;
720         case CX88_BOARD_HAUPPAUGE_HVR3000:
721                 dev->dvb.frontend = dvb_attach(cx22702_attach,
722                                                &hauppauge_hvr3000_config,
723                                                &dev->core->i2c_adap);
724                 if (dev->dvb.frontend != NULL) {
725                         dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
726                                    &dev->core->i2c_adap,
727                                    &dvb_pll_fmd1216me);
728                 }
729                 break;
730         default:
731                 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
732                        dev->core->name);
733                 break;
734         }
735         if (NULL == dev->dvb.frontend) {
736                 printk("%s: frontend initialization failed\n",dev->core->name);
737                 return -1;
738         }
739
740         if (dev->core->pll_desc) {
741                 dev->dvb.frontend->ops.info.frequency_min = dev->core->pll_desc->min;
742                 dev->dvb.frontend->ops.info.frequency_max = dev->core->pll_desc->max;
743         }
744         /* Ensure all frontends negotiate bus access */
745         dev->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
746
747         /* Put the analog decoder in standby to keep it quiet */
748         cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
749
750         /* register everything */
751         return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev);
752 }
753
754 /* ----------------------------------------------------------- */
755
756 /* CX8802 MPEG -> mini driver - We have been given the hardware */
757 static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)
758 {
759         struct cx88_core *core = drv->core;
760         int err = 0;
761         dprintk( 1, "%s\n", __FUNCTION__);
762
763         switch (core->board) {
764         case CX88_BOARD_HAUPPAUGE_HVR1300:
765                 /* We arrive here with either the cx23416 or the cx22702
766                  * on the bus. Take the bus from the cx23416 and enable the
767                  * cx22702 demod
768                  */
769                 cx_set(MO_GP0_IO,   0x00000080); /* cx22702 out of reset and enable */
770                 cx_clear(MO_GP0_IO, 0x00000004);
771                 udelay(1000);
772                 break;
773         default:
774                 err = -ENODEV;
775         }
776         return err;
777 }
778
779 /* CX8802 MPEG -> mini driver - We no longer have the hardware */
780 static int cx8802_dvb_advise_release(struct cx8802_driver *drv)
781 {
782         struct cx88_core *core = drv->core;
783         int err = 0;
784         dprintk( 1, "%s\n", __FUNCTION__);
785
786         switch (core->board) {
787         case CX88_BOARD_HAUPPAUGE_HVR1300:
788                 /* Do Nothing, leave the cx22702 on the bus. */
789                 break;
790         default:
791                 err = -ENODEV;
792         }
793         return err;
794 }
795
796 static int cx8802_dvb_probe(struct cx8802_driver *drv)
797 {
798         struct cx88_core *core = drv->core;
799         struct cx8802_dev *dev = drv->core->dvbdev;
800         int err;
801
802         dprintk( 1, "%s\n", __FUNCTION__);
803         dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
804                 core->board,
805                 core->name,
806                 core->pci_bus,
807                 core->pci_slot);
808
809         err = -ENODEV;
810         if (!(cx88_boards[core->board].mpeg & CX88_MPEG_DVB))
811                 goto fail_core;
812
813 #ifdef HAVE_VP3054_I2C
814         err = vp3054_i2c_probe(dev);
815         if (0 != err)
816                 goto fail_core;
817 #endif
818
819         /* dvb stuff */
820         printk("%s/2: cx2388x based dvb card\n", core->name);
821         videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops,
822                             dev->pci, &dev->slock,
823                             V4L2_BUF_TYPE_VIDEO_CAPTURE,
824                             V4L2_FIELD_TOP,
825                             sizeof(struct cx88_buffer),
826                             dev);
827         err = dvb_register(dev);
828         if (err != 0)
829                 printk("%s dvb_register failed err = %d\n", __FUNCTION__, err);
830
831  fail_core:
832         return err;
833 }
834
835 static int cx8802_dvb_remove(struct cx8802_driver *drv)
836 {
837         struct cx8802_dev *dev = drv->core->dvbdev;
838
839         /* dvb */
840         videobuf_dvb_unregister(&dev->dvb);
841
842 #ifdef HAVE_VP3054_I2C
843         vp3054_i2c_remove(dev);
844 #endif
845
846         return 0;
847 }
848
849 static struct cx8802_driver cx8802_dvb_driver = {
850         .type_id        = CX88_MPEG_DVB,
851         .hw_access      = CX8802_DRVCTL_SHARED,
852         .probe          = cx8802_dvb_probe,
853         .remove         = cx8802_dvb_remove,
854         .advise_acquire = cx8802_dvb_advise_acquire,
855         .advise_release = cx8802_dvb_advise_release,
856 };
857
858 static int dvb_init(void)
859 {
860         printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n",
861                (CX88_VERSION_CODE >> 16) & 0xff,
862                (CX88_VERSION_CODE >>  8) & 0xff,
863                CX88_VERSION_CODE & 0xff);
864 #ifdef SNAPSHOT
865         printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
866                SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
867 #endif
868         return cx8802_register_driver(&cx8802_dvb_driver);
869 }
870
871 static void dvb_fini(void)
872 {
873         cx8802_unregister_driver(&cx8802_dvb_driver);
874 }
875
876 module_init(dvb_init);
877 module_exit(dvb_fini);
878
879 /*
880  * Local variables:
881  * c-basic-offset: 8
882  * compile-command: "make DVB=1"
883  * End:
884  */