V4L/DVB (9019): Added support for Omicom SS4 DVB-S/S2 card
[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 #include "cx88-vp3054-i2c.h"
39 #include "zl10353.h"
40 #include "cx22702.h"
41 #include "or51132.h"
42 #include "lgdt330x.h"
43 #include "s5h1409.h"
44 #include "xc5000.h"
45 #include "nxt200x.h"
46 #include "cx24123.h"
47 #include "isl6421.h"
48 #include "tuner-simple.h"
49 #include "tda9887.h"
50 #include "s5h1411.h"
51 #include "cx24116.h"
52
53 MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
54 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
55 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
56 MODULE_LICENSE("GPL");
57
58 static unsigned int debug;
59 module_param(debug, int, 0644);
60 MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
61
62 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
63
64 #define dprintk(level,fmt, arg...)      if (debug >= level) \
65         printk(KERN_DEBUG "%s/2-dvb: " fmt, core->name, ## arg)
66
67 /* ------------------------------------------------------------------ */
68
69 static int dvb_buf_setup(struct videobuf_queue *q,
70                          unsigned int *count, unsigned int *size)
71 {
72         struct cx8802_dev *dev = q->priv_data;
73
74         dev->ts_packet_size  = 188 * 4;
75         dev->ts_packet_count = 32;
76
77         *size  = dev->ts_packet_size * dev->ts_packet_count;
78         *count = 32;
79         return 0;
80 }
81
82 static int dvb_buf_prepare(struct videobuf_queue *q,
83                            struct videobuf_buffer *vb, enum v4l2_field field)
84 {
85         struct cx8802_dev *dev = q->priv_data;
86         return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field);
87 }
88
89 static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
90 {
91         struct cx8802_dev *dev = q->priv_data;
92         cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
93 }
94
95 static void dvb_buf_release(struct videobuf_queue *q,
96                             struct videobuf_buffer *vb)
97 {
98         cx88_free_buffer(q, (struct cx88_buffer*)vb);
99 }
100
101 static struct videobuf_queue_ops dvb_qops = {
102         .buf_setup    = dvb_buf_setup,
103         .buf_prepare  = dvb_buf_prepare,
104         .buf_queue    = dvb_buf_queue,
105         .buf_release  = dvb_buf_release,
106 };
107
108 /* ------------------------------------------------------------------ */
109
110 static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire)
111 {
112         struct cx8802_dev *dev= fe->dvb->priv;
113         struct cx8802_driver *drv = NULL;
114         int ret = 0;
115
116         drv = cx8802_get_driver(dev, CX88_MPEG_DVB);
117         if (drv) {
118                 if (acquire)
119                         ret = drv->request_acquire(drv);
120                 else
121                         ret = drv->request_release(drv);
122         }
123
124         return ret;
125 }
126
127 /* ------------------------------------------------------------------ */
128
129 static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
130 {
131         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x39 };
132         static u8 reset []         = { RESET,      0x80 };
133         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
134         static u8 agc_cfg []       = { AGC_TARGET, 0x24, 0x20 };
135         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
136         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
137
138         mt352_write(fe, clock_config,   sizeof(clock_config));
139         udelay(200);
140         mt352_write(fe, reset,          sizeof(reset));
141         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
142
143         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
144         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
145         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
146         return 0;
147 }
148
149 static int dvico_dual_demod_init(struct dvb_frontend *fe)
150 {
151         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x38 };
152         static u8 reset []         = { RESET,      0x80 };
153         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
154         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0x20 };
155         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
156         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
157
158         mt352_write(fe, clock_config,   sizeof(clock_config));
159         udelay(200);
160         mt352_write(fe, reset,          sizeof(reset));
161         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
162
163         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
164         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
165         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
166
167         return 0;
168 }
169
170 static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
171 {
172         static u8 clock_config []  = { 0x89, 0x38, 0x39 };
173         static u8 reset []         = { 0x50, 0x80 };
174         static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
175         static u8 agc_cfg []       = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
176                                        0x00, 0xFF, 0x00, 0x40, 0x40 };
177         static u8 dntv_extra[]     = { 0xB5, 0x7A };
178         static u8 capt_range_cfg[] = { 0x75, 0x32 };
179
180         mt352_write(fe, clock_config,   sizeof(clock_config));
181         udelay(2000);
182         mt352_write(fe, reset,          sizeof(reset));
183         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
184
185         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
186         udelay(2000);
187         mt352_write(fe, dntv_extra,     sizeof(dntv_extra));
188         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
189
190         return 0;
191 }
192
193 static struct mt352_config dvico_fusionhdtv = {
194         .demod_address = 0x0f,
195         .demod_init    = dvico_fusionhdtv_demod_init,
196 };
197
198 static struct mt352_config dntv_live_dvbt_config = {
199         .demod_address = 0x0f,
200         .demod_init    = dntv_live_dvbt_demod_init,
201 };
202
203 static struct mt352_config dvico_fusionhdtv_dual = {
204         .demod_address = 0x0f,
205         .demod_init    = dvico_dual_demod_init,
206 };
207
208 #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))
209 static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe)
210 {
211         static u8 clock_config []  = { 0x89, 0x38, 0x38 };
212         static u8 reset []         = { 0x50, 0x80 };
213         static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
214         static u8 agc_cfg []       = { 0x67, 0x10, 0x20, 0x00, 0xFF, 0xFF,
215                                        0x00, 0xFF, 0x00, 0x40, 0x40 };
216         static u8 dntv_extra[]     = { 0xB5, 0x7A };
217         static u8 capt_range_cfg[] = { 0x75, 0x32 };
218
219         mt352_write(fe, clock_config,   sizeof(clock_config));
220         udelay(2000);
221         mt352_write(fe, reset,          sizeof(reset));
222         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
223
224         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
225         udelay(2000);
226         mt352_write(fe, dntv_extra,     sizeof(dntv_extra));
227         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
228
229         return 0;
230 }
231
232 static struct mt352_config dntv_live_dvbt_pro_config = {
233         .demod_address = 0x0f,
234         .no_tuner      = 1,
235         .demod_init    = dntv_live_dvbt_pro_demod_init,
236 };
237 #endif
238
239 static struct zl10353_config dvico_fusionhdtv_hybrid = {
240         .demod_address = 0x0f,
241         .no_tuner      = 1,
242 };
243
244 static struct zl10353_config dvico_fusionhdtv_xc3028 = {
245         .demod_address = 0x0f,
246         .if2           = 45600,
247         .no_tuner      = 1,
248 };
249
250 static struct mt352_config dvico_fusionhdtv_mt352_xc3028 = {
251         .demod_address = 0x0f,
252         .if2 = 4560,
253         .no_tuner = 1,
254         .demod_init = dvico_fusionhdtv_demod_init,
255 };
256
257 static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
258         .demod_address = 0x0f,
259 };
260
261 static struct cx22702_config connexant_refboard_config = {
262         .demod_address = 0x43,
263         .output_mode   = CX22702_SERIAL_OUTPUT,
264 };
265
266 static struct cx22702_config hauppauge_hvr_config = {
267         .demod_address = 0x63,
268         .output_mode   = CX22702_SERIAL_OUTPUT,
269 };
270
271 static int or51132_set_ts_param(struct dvb_frontend* fe, int is_punctured)
272 {
273         struct cx8802_dev *dev= fe->dvb->priv;
274         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
275         return 0;
276 }
277
278 static struct or51132_config pchdtv_hd3000 = {
279         .demod_address = 0x15,
280         .set_ts_params = or51132_set_ts_param,
281 };
282
283 static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
284 {
285         struct cx8802_dev *dev= fe->dvb->priv;
286         struct cx88_core *core = dev->core;
287
288         dprintk(1, "%s: index = %d\n", __func__, index);
289         if (index == 0)
290                 cx_clear(MO_GP0_IO, 8);
291         else
292                 cx_set(MO_GP0_IO, 8);
293         return 0;
294 }
295
296 static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
297 {
298         struct cx8802_dev *dev= fe->dvb->priv;
299         if (is_punctured)
300                 dev->ts_gen_cntrl |= 0x04;
301         else
302                 dev->ts_gen_cntrl &= ~0x04;
303         return 0;
304 }
305
306 static struct lgdt330x_config fusionhdtv_3_gold = {
307         .demod_address = 0x0e,
308         .demod_chip    = LGDT3302,
309         .serial_mpeg   = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
310         .set_ts_params = lgdt330x_set_ts_param,
311 };
312
313 static struct lgdt330x_config fusionhdtv_5_gold = {
314         .demod_address = 0x0e,
315         .demod_chip    = LGDT3303,
316         .serial_mpeg   = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
317         .set_ts_params = lgdt330x_set_ts_param,
318 };
319
320 static struct lgdt330x_config pchdtv_hd5500 = {
321         .demod_address = 0x59,
322         .demod_chip    = LGDT3303,
323         .serial_mpeg   = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
324         .set_ts_params = lgdt330x_set_ts_param,
325 };
326
327 static int nxt200x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
328 {
329         struct cx8802_dev *dev= fe->dvb->priv;
330         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
331         return 0;
332 }
333
334 static struct nxt200x_config ati_hdtvwonder = {
335         .demod_address = 0x0a,
336         .set_ts_params = nxt200x_set_ts_param,
337 };
338
339 static int cx24123_set_ts_param(struct dvb_frontend* fe,
340         int is_punctured)
341 {
342         struct cx8802_dev *dev= fe->dvb->priv;
343         dev->ts_gen_cntrl = 0x02;
344         return 0;
345 }
346
347 static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
348                                        fe_sec_voltage_t voltage)
349 {
350         struct cx8802_dev *dev= fe->dvb->priv;
351         struct cx88_core *core = dev->core;
352
353         if (voltage == SEC_VOLTAGE_OFF)
354                 cx_write(MO_GP0_IO, 0x000006fb);
355         else
356                 cx_write(MO_GP0_IO, 0x000006f9);
357
358         if (core->prev_set_voltage)
359                 return core->prev_set_voltage(fe, voltage);
360         return 0;
361 }
362
363 static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
364                                       fe_sec_voltage_t voltage)
365 {
366         struct cx8802_dev *dev= fe->dvb->priv;
367         struct cx88_core *core = dev->core;
368
369         if (voltage == SEC_VOLTAGE_OFF) {
370                 dprintk(1,"LNB Voltage OFF\n");
371                 cx_write(MO_GP0_IO, 0x0000efff);
372         }
373
374         if (core->prev_set_voltage)
375                 return core->prev_set_voltage(fe, voltage);
376         return 0;
377 }
378
379 static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,
380                                       fe_sec_voltage_t voltage)
381 {
382         struct cx8802_dev *dev= fe->dvb->priv;
383         struct cx88_core *core = dev->core;
384
385         switch (voltage) {
386                 case SEC_VOLTAGE_13:
387                         printk("LNB Voltage SEC_VOLTAGE_13\n");
388                         cx_write(MO_GP0_IO, 0x00006040);
389                         break;
390                 case SEC_VOLTAGE_18:
391                         printk("LNB Voltage SEC_VOLTAGE_18\n");
392                         cx_write(MO_GP0_IO, 0x00006060);
393                         break;
394                 case SEC_VOLTAGE_OFF:
395                         printk("LNB Voltage SEC_VOLTAGE_off\n");
396                         break;
397         }
398
399         if (core->prev_set_voltage)
400                 return core->prev_set_voltage(fe, voltage);
401         return 0;
402 }
403
404 static int cx88_pci_nano_callback(void *ptr, int command, int arg)
405 {
406         struct cx88_core *core = ptr;
407
408         switch (command) {
409         case XC2028_TUNER_RESET:
410                 /* Send the tuner in then out of reset */
411                 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __func__, arg);
412
413                 switch (core->boardnr) {
414                 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
415                         /* GPIO-4 xc3028 tuner */
416
417                         cx_set(MO_GP0_IO, 0x00001000);
418                         cx_clear(MO_GP0_IO, 0x00000010);
419                         msleep(100);
420                         cx_set(MO_GP0_IO, 0x00000010);
421                         msleep(100);
422                         break;
423                 }
424
425                 break;
426         case XC2028_RESET_CLK:
427                 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __func__, arg);
428                 break;
429         default:
430                 dprintk(1, "%s: unknown command %d, arg %d\n", __func__,
431                         command, arg);
432                 return -EINVAL;
433         }
434
435         return 0;
436 }
437
438 static struct cx24123_config geniatech_dvbs_config = {
439         .demod_address = 0x55,
440         .set_ts_params = cx24123_set_ts_param,
441 };
442
443 static struct cx24123_config hauppauge_novas_config = {
444         .demod_address = 0x55,
445         .set_ts_params = cx24123_set_ts_param,
446 };
447
448 static struct cx24123_config kworld_dvbs_100_config = {
449         .demod_address = 0x15,
450         .set_ts_params = cx24123_set_ts_param,
451         .lnb_polarity  = 1,
452 };
453
454 static struct s5h1409_config pinnacle_pctv_hd_800i_config = {
455         .demod_address = 0x32 >> 1,
456         .output_mode   = S5H1409_PARALLEL_OUTPUT,
457         .gpio          = S5H1409_GPIO_ON,
458         .qam_if        = 44000,
459         .inversion     = S5H1409_INVERSION_OFF,
460         .status_mode   = S5H1409_DEMODLOCKING,
461         .mpeg_timing   = S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
462 };
463
464 static struct s5h1409_config dvico_hdtv5_pci_nano_config = {
465         .demod_address = 0x32 >> 1,
466         .output_mode   = S5H1409_SERIAL_OUTPUT,
467         .gpio          = S5H1409_GPIO_OFF,
468         .inversion     = S5H1409_INVERSION_OFF,
469         .status_mode   = S5H1409_DEMODLOCKING,
470         .mpeg_timing   = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
471 };
472
473 static struct s5h1409_config kworld_atsc_120_config = {
474         .demod_address = 0x32 >> 1,
475         .output_mode   = S5H1409_SERIAL_OUTPUT,
476         .gpio          = S5H1409_GPIO_OFF,
477         .inversion     = S5H1409_INVERSION_OFF,
478         .status_mode   = S5H1409_DEMODLOCKING,
479         .mpeg_timing   = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
480 };
481
482 static struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = {
483         .i2c_address    = 0x64,
484         .if_khz         = 5380,
485         .tuner_callback = cx88_tuner_callback,
486 };
487
488 static struct zl10353_config cx88_geniatech_x8000_mt = {
489        .demod_address = (0x1e >> 1),
490        .no_tuner = 1,
491 };
492
493 static struct s5h1411_config dvico_fusionhdtv7_config = {
494         .output_mode   = S5H1411_SERIAL_OUTPUT,
495         .gpio          = S5H1411_GPIO_ON,
496         .mpeg_timing   = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
497         .qam_if        = S5H1411_IF_44000,
498         .vsb_if        = S5H1411_IF_44000,
499         .inversion     = S5H1411_INVERSION_OFF,
500         .status_mode   = S5H1411_DEMODLOCKING
501 };
502
503 static struct xc5000_config dvico_fusionhdtv7_tuner_config = {
504         .i2c_address    = 0xc2 >> 1,
505         .if_khz         = 5380,
506         .tuner_callback = cx88_tuner_callback,
507 };
508
509 static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
510 {
511         struct dvb_frontend *fe;
512         struct xc2028_ctrl ctl;
513         struct xc2028_config cfg = {
514                 .i2c_adap  = &dev->core->i2c_adap,
515                 .i2c_addr  = addr,
516                 .ctrl      = &ctl,
517                 .callback  = cx88_tuner_callback,
518         };
519
520         if (!dev->dvb.frontend) {
521                 printk(KERN_ERR "%s/2: dvb frontend not attached. "
522                                 "Can't attach xc3028\n",
523                        dev->core->name);
524                 return -EINVAL;
525         }
526
527         /*
528          * Some xc3028 devices may be hidden by an I2C gate. This is known
529          * to happen with some s5h1409-based devices.
530          * Now that I2C gate is open, sets up xc3028 configuration
531          */
532         cx88_setup_xc3028(dev->core, &ctl);
533
534         fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
535         if (!fe) {
536                 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
537                        dev->core->name);
538                 return -EINVAL;
539         }
540
541         printk(KERN_INFO "%s/2: xc3028 attached\n",
542                dev->core->name);
543
544         return 0;
545 }
546
547 static int cx24116_set_ts_param(struct dvb_frontend *fe,
548         int is_punctured)
549 {
550         struct cx8802_dev *dev = fe->dvb->priv;
551         dev->ts_gen_cntrl = 0x2;
552
553         return 0;
554 }
555
556 static int cx24116_reset_device(struct dvb_frontend *fe)
557 {
558         struct cx8802_dev *dev = fe->dvb->priv;
559         struct cx88_core *core = dev->core;
560
561         /* Reset the part */
562         cx_write(MO_SRST_IO, 0);
563         msleep(10);
564         cx_write(MO_SRST_IO, 1);
565         msleep(10);
566
567         return 0;
568 }
569
570 static struct cx24116_config hauppauge_hvr4000_config = {
571         .demod_address          = 0x05,
572         .set_ts_params          = cx24116_set_ts_param,
573         .reset_device           = cx24116_reset_device,
574 };
575
576 static struct cx24116_config tevii_s460_config = {
577         .demod_address = 0x55,
578         .set_ts_params = cx24116_set_ts_param,
579         .reset_device  = cx24116_reset_device,
580 };
581
582 static int dvb_register(struct cx8802_dev *dev)
583 {
584         struct cx88_core *core = dev->core;
585
586         /* init struct videobuf_dvb */
587         dev->dvb.name = core->name;
588         dev->ts_gen_cntrl = 0x0c;
589
590         /* init frontend */
591         switch (core->boardnr) {
592         case CX88_BOARD_HAUPPAUGE_DVB_T1:
593                 dev->dvb.frontend = dvb_attach(cx22702_attach,
594                                                &connexant_refboard_config,
595                                                &core->i2c_adap);
596                 if (dev->dvb.frontend != NULL) {
597                         if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend,
598                                         0x61, &core->i2c_adap,
599                                         DVB_PLL_THOMSON_DTT759X))
600                                 goto frontend_detach;
601                 }
602                 break;
603         case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
604         case CX88_BOARD_CONEXANT_DVB_T1:
605         case CX88_BOARD_KWORLD_DVB_T_CX22702:
606         case CX88_BOARD_WINFAST_DTV1000:
607                 dev->dvb.frontend = dvb_attach(cx22702_attach,
608                                                &connexant_refboard_config,
609                                                &core->i2c_adap);
610                 if (dev->dvb.frontend != NULL) {
611                         if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend,
612                                         0x60, &core->i2c_adap,
613                                         DVB_PLL_THOMSON_DTT7579))
614                                 goto frontend_detach;
615                 }
616                 break;
617         case CX88_BOARD_WINFAST_DTV2000H:
618         case CX88_BOARD_HAUPPAUGE_HVR1100:
619         case CX88_BOARD_HAUPPAUGE_HVR1100LP:
620         case CX88_BOARD_HAUPPAUGE_HVR1300:
621         case CX88_BOARD_HAUPPAUGE_HVR3000:
622                 dev->dvb.frontend = dvb_attach(cx22702_attach,
623                                                &hauppauge_hvr_config,
624                                                &core->i2c_adap);
625                 if (dev->dvb.frontend != NULL) {
626                         if (!dvb_attach(simple_tuner_attach, dev->dvb.frontend,
627                                    &core->i2c_adap, 0x61,
628                                    TUNER_PHILIPS_FMD1216ME_MK3))
629                                 goto frontend_detach;
630                 }
631                 break;
632         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
633                 dev->dvb.frontend = dvb_attach(mt352_attach,
634                                                &dvico_fusionhdtv,
635                                                &core->i2c_adap);
636                 if (dev->dvb.frontend != NULL) {
637                         if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend,
638                                         0x60, NULL, DVB_PLL_THOMSON_DTT7579))
639                                 goto frontend_detach;
640                         break;
641                 }
642                 /* ZL10353 replaces MT352 on later cards */
643                 dev->dvb.frontend = dvb_attach(zl10353_attach,
644                                                &dvico_fusionhdtv_plus_v1_1,
645                                                &core->i2c_adap);
646                 if (dev->dvb.frontend != NULL) {
647                         if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend,
648                                         0x60, NULL, DVB_PLL_THOMSON_DTT7579))
649                                 goto frontend_detach;
650                 }
651                 break;
652         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
653                 /* The tin box says DEE1601, but it seems to be DTT7579
654                  * compatible, with a slightly different MT352 AGC gain. */
655                 dev->dvb.frontend = dvb_attach(mt352_attach,
656                                                &dvico_fusionhdtv_dual,
657                                                &core->i2c_adap);
658                 if (dev->dvb.frontend != NULL) {
659                         if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend,
660                                         0x61, NULL, DVB_PLL_THOMSON_DTT7579))
661                                 goto frontend_detach;
662                         break;
663                 }
664                 /* ZL10353 replaces MT352 on later cards */
665                 dev->dvb.frontend = dvb_attach(zl10353_attach,
666                                                &dvico_fusionhdtv_plus_v1_1,
667                                                &core->i2c_adap);
668                 if (dev->dvb.frontend != NULL) {
669                         if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend,
670                                         0x61, NULL, DVB_PLL_THOMSON_DTT7579))
671                                 goto frontend_detach;
672                 }
673                 break;
674         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
675                 dev->dvb.frontend = dvb_attach(mt352_attach,
676                                                &dvico_fusionhdtv,
677                                                &core->i2c_adap);
678                 if (dev->dvb.frontend != NULL) {
679                         if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend,
680                                         0x61, NULL, DVB_PLL_LG_Z201))
681                                 goto frontend_detach;
682                 }
683                 break;
684         case CX88_BOARD_KWORLD_DVB_T:
685         case CX88_BOARD_DNTV_LIVE_DVB_T:
686         case CX88_BOARD_ADSTECH_DVB_T_PCI:
687                 dev->dvb.frontend = dvb_attach(mt352_attach,
688                                                &dntv_live_dvbt_config,
689                                                &core->i2c_adap);
690                 if (dev->dvb.frontend != NULL) {
691                         if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend,
692                                         0x61, NULL, DVB_PLL_UNKNOWN_1))
693                                 goto frontend_detach;
694                 }
695                 break;
696         case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
697 #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))
698                 /* MT352 is on a secondary I2C bus made from some GPIO lines */
699                 dev->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
700                                                &dev->vp3054->adap);
701                 if (dev->dvb.frontend != NULL) {
702                         if (!dvb_attach(simple_tuner_attach, dev->dvb.frontend,
703                                         &core->i2c_adap, 0x61,
704                                         TUNER_PHILIPS_FMD1216ME_MK3))
705                                 goto frontend_detach;
706                 }
707 #else
708                 printk(KERN_ERR "%s/2: built without vp3054 support\n",
709                                 core->name);
710 #endif
711                 break;
712         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
713                 dev->dvb.frontend = dvb_attach(zl10353_attach,
714                                                &dvico_fusionhdtv_hybrid,
715                                                &core->i2c_adap);
716                 if (dev->dvb.frontend != NULL) {
717                         if (!dvb_attach(simple_tuner_attach, dev->dvb.frontend,
718                                    &core->i2c_adap, 0x61,
719                                    TUNER_THOMSON_FE6600))
720                                 goto frontend_detach;
721                 }
722                 break;
723         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
724                 dev->dvb.frontend = dvb_attach(zl10353_attach,
725                                                &dvico_fusionhdtv_xc3028,
726                                                &core->i2c_adap);
727                 if (dev->dvb.frontend == NULL)
728                         dev->dvb.frontend = dvb_attach(mt352_attach,
729                                                 &dvico_fusionhdtv_mt352_xc3028,
730                                                 &core->i2c_adap);
731                 /*
732                  * On this board, the demod provides the I2C bus pullup.
733                  * We must not permit gate_ctrl to be performed, or
734                  * the xc3028 cannot communicate on the bus.
735                  */
736                 if (dev->dvb.frontend)
737                         dev->dvb.frontend->ops.i2c_gate_ctrl = NULL;
738                 if (attach_xc3028(0x61, dev) < 0)
739                         return -EINVAL;
740                 break;
741         case CX88_BOARD_PCHDTV_HD3000:
742                 dev->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000,
743                                                &core->i2c_adap);
744                 if (dev->dvb.frontend != NULL) {
745                         if (!dvb_attach(simple_tuner_attach, dev->dvb.frontend,
746                                         &core->i2c_adap, 0x61,
747                                         TUNER_THOMSON_DTT761X))
748                                 goto frontend_detach;
749                 }
750                 break;
751         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
752                 dev->ts_gen_cntrl = 0x08;
753
754                 /* Do a hardware reset of chip before using it. */
755                 cx_clear(MO_GP0_IO, 1);
756                 mdelay(100);
757                 cx_set(MO_GP0_IO, 1);
758                 mdelay(200);
759
760                 /* Select RF connector callback */
761                 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
762                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
763                                                &fusionhdtv_3_gold,
764                                                &core->i2c_adap);
765                 if (dev->dvb.frontend != NULL) {
766                         if (!dvb_attach(simple_tuner_attach, dev->dvb.frontend,
767                                         &core->i2c_adap, 0x61,
768                                         TUNER_MICROTUNE_4042FI5))
769                                 goto frontend_detach;
770                 }
771                 break;
772         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
773                 dev->ts_gen_cntrl = 0x08;
774
775                 /* Do a hardware reset of chip before using it. */
776                 cx_clear(MO_GP0_IO, 1);
777                 mdelay(100);
778                 cx_set(MO_GP0_IO, 9);
779                 mdelay(200);
780                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
781                                                &fusionhdtv_3_gold,
782                                                &core->i2c_adap);
783                 if (dev->dvb.frontend != NULL) {
784                         if (!dvb_attach(simple_tuner_attach, dev->dvb.frontend,
785                                         &core->i2c_adap, 0x61,
786                                         TUNER_THOMSON_DTT761X))
787                                 goto frontend_detach;
788                 }
789                 break;
790         case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
791                 dev->ts_gen_cntrl = 0x08;
792
793                 /* Do a hardware reset of chip before using it. */
794                 cx_clear(MO_GP0_IO, 1);
795                 mdelay(100);
796                 cx_set(MO_GP0_IO, 1);
797                 mdelay(200);
798                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
799                                                &fusionhdtv_5_gold,
800                                                &core->i2c_adap);
801                 if (dev->dvb.frontend != NULL) {
802                         if (!dvb_attach(simple_tuner_attach, dev->dvb.frontend,
803                                         &core->i2c_adap, 0x61,
804                                         TUNER_LG_TDVS_H06XF))
805                                 goto frontend_detach;
806                         if (!dvb_attach(tda9887_attach, dev->dvb.frontend,
807                                    &core->i2c_adap, 0x43))
808                                 goto frontend_detach;
809                 }
810                 break;
811         case CX88_BOARD_PCHDTV_HD5500:
812                 dev->ts_gen_cntrl = 0x08;
813
814                 /* Do a hardware reset of chip before using it. */
815                 cx_clear(MO_GP0_IO, 1);
816                 mdelay(100);
817                 cx_set(MO_GP0_IO, 1);
818                 mdelay(200);
819                 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
820                                                &pchdtv_hd5500,
821                                                &core->i2c_adap);
822                 if (dev->dvb.frontend != NULL) {
823                         if (!dvb_attach(simple_tuner_attach, dev->dvb.frontend,
824                                         &core->i2c_adap, 0x61,
825                                         TUNER_LG_TDVS_H06XF))
826                                 goto frontend_detach;
827                         if (!dvb_attach(tda9887_attach, dev->dvb.frontend,
828                                    &core->i2c_adap, 0x43))
829                                 goto frontend_detach;
830                 }
831                 break;
832         case CX88_BOARD_ATI_HDTVWONDER:
833                 dev->dvb.frontend = dvb_attach(nxt200x_attach,
834                                                &ati_hdtvwonder,
835                                                &core->i2c_adap);
836                 if (dev->dvb.frontend != NULL) {
837                         if (!dvb_attach(simple_tuner_attach, dev->dvb.frontend,
838                                         &core->i2c_adap, 0x61,
839                                         TUNER_PHILIPS_TUV1236D))
840                                 goto frontend_detach;
841                 }
842                 break;
843         case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
844         case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
845                 dev->dvb.frontend = dvb_attach(cx24123_attach,
846                                                &hauppauge_novas_config,
847                                                &core->i2c_adap);
848                 if (dev->dvb.frontend) {
849                         if (!dvb_attach(isl6421_attach, dev->dvb.frontend,
850                                         &core->i2c_adap, 0x08, ISL6421_DCL, 0x00))
851                                 goto frontend_detach;
852                 }
853                 break;
854         case CX88_BOARD_KWORLD_DVBS_100:
855                 dev->dvb.frontend = dvb_attach(cx24123_attach,
856                                                &kworld_dvbs_100_config,
857                                                &core->i2c_adap);
858                 if (dev->dvb.frontend) {
859                         core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
860                         dev->dvb.frontend->ops.set_voltage = kworld_dvbs_100_set_voltage;
861                 }
862                 break;
863         case CX88_BOARD_GENIATECH_DVBS:
864                 dev->dvb.frontend = dvb_attach(cx24123_attach,
865                                                &geniatech_dvbs_config,
866                                                &core->i2c_adap);
867                 if (dev->dvb.frontend) {
868                         core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
869                         dev->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;
870                 }
871                 break;
872         case CX88_BOARD_PINNACLE_PCTV_HD_800i:
873                 dev->dvb.frontend = dvb_attach(s5h1409_attach,
874                                                &pinnacle_pctv_hd_800i_config,
875                                                &core->i2c_adap);
876                 if (dev->dvb.frontend != NULL) {
877                         if (!dvb_attach(xc5000_attach, dev->dvb.frontend,
878                                         &core->i2c_adap,
879                                         &pinnacle_pctv_hd_800i_tuner_config))
880                                 goto frontend_detach;
881                 }
882                 break;
883         case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
884                 dev->dvb.frontend = dvb_attach(s5h1409_attach,
885                                                 &dvico_hdtv5_pci_nano_config,
886                                                 &core->i2c_adap);
887                 if (dev->dvb.frontend != NULL) {
888                         struct dvb_frontend *fe;
889                         struct xc2028_config cfg = {
890                                 .i2c_adap  = &core->i2c_adap,
891                                 .i2c_addr  = 0x61,
892                                 .callback  = cx88_pci_nano_callback,
893                         };
894                         static struct xc2028_ctrl ctl = {
895                                 .fname       = XC2028_DEFAULT_FIRMWARE,
896                                 .max_len     = 64,
897                                 .scode_table = XC3028_FE_OREN538,
898                         };
899
900                         fe = dvb_attach(xc2028_attach,
901                                         dev->dvb.frontend, &cfg);
902                         if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
903                                 fe->ops.tuner_ops.set_config(fe, &ctl);
904                 }
905                 break;
906          case CX88_BOARD_PINNACLE_HYBRID_PCTV:
907                 dev->dvb.frontend = dvb_attach(zl10353_attach,
908                                                &cx88_geniatech_x8000_mt,
909                                                &core->i2c_adap);
910                 if (attach_xc3028(0x61, dev) < 0)
911                         goto frontend_detach;
912                 break;
913          case CX88_BOARD_GENIATECH_X8000_MT:
914                 dev->ts_gen_cntrl = 0x00;
915
916                 dev->dvb.frontend = dvb_attach(zl10353_attach,
917                                                &cx88_geniatech_x8000_mt,
918                                                &core->i2c_adap);
919                 if (attach_xc3028(0x61, dev) < 0)
920                         goto frontend_detach;
921                 break;
922          case CX88_BOARD_KWORLD_ATSC_120:
923                 dev->dvb.frontend = dvb_attach(s5h1409_attach,
924                                                &kworld_atsc_120_config,
925                                                &core->i2c_adap);
926                 if (attach_xc3028(0x61, dev) < 0)
927                         goto frontend_detach;
928                 break;
929         case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
930                 dev->dvb.frontend = dvb_attach(s5h1411_attach,
931                                                &dvico_fusionhdtv7_config,
932                                                &core->i2c_adap);
933                 if (dev->dvb.frontend != NULL) {
934                         if (!dvb_attach(xc5000_attach, dev->dvb.frontend,
935                                         &core->i2c_adap,
936                                         &dvico_fusionhdtv7_tuner_config))
937                                 goto frontend_detach;
938                 }
939                 break;
940         case CX88_BOARD_HAUPPAUGE_HVR4000:
941         case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
942                 /* Support for DVB-S only, not DVB-T support */
943                 dev->dvb.frontend = dvb_attach(cx24116_attach,
944                         &hauppauge_hvr4000_config,
945                         &dev->core->i2c_adap);
946                 if (dev->dvb.frontend) {
947                         dvb_attach(isl6421_attach, dev->dvb.frontend,
948                                 &dev->core->i2c_adap,
949                                 0x08, ISL6421_DCL, 0x00);
950                 }
951                 break;
952         case CX88_BOARD_TEVII_S460:
953                 dev->dvb.frontend = dvb_attach(cx24116_attach,
954                                                &tevii_s460_config,
955                                                &core->i2c_adap);
956                 if (dev->dvb.frontend != NULL) {
957                         core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
958                         dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
959                 }
960                 break;
961         case CX88_BOARD_OMICOM_SS4_PCI:
962                 dev->dvb.frontend = dvb_attach(cx24116_attach,
963                                                &hauppauge_hvr4000_config,
964                                                &core->i2c_adap);
965                 if (dev->dvb.frontend != NULL) {
966                         core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
967                         dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
968                 }
969                 break;
970         default:
971                 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
972                        core->name);
973                 break;
974         }
975         if (NULL == dev->dvb.frontend) {
976                 printk(KERN_ERR
977                        "%s/2: frontend initialization failed\n",
978                        core->name);
979                 return -EINVAL;
980         }
981
982         /* Ensure all frontends negotiate bus access */
983         dev->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
984
985         /* Put the analog decoder in standby to keep it quiet */
986         cx88_call_i2c_clients(core, TUNER_SET_STANDBY, NULL);
987
988         /* register everything */
989         return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev,
990                                      &dev->pci->dev, adapter_nr);
991
992 frontend_detach:
993         if (dev->dvb.frontend) {
994                 dvb_frontend_detach(dev->dvb.frontend);
995                 dev->dvb.frontend = NULL;
996         }
997         return -EINVAL;
998 }
999
1000 /* ----------------------------------------------------------- */
1001
1002 /* CX8802 MPEG -> mini driver - We have been given the hardware */
1003 static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)
1004 {
1005         struct cx88_core *core = drv->core;
1006         int err = 0;
1007         dprintk( 1, "%s\n", __func__);
1008
1009         switch (core->boardnr) {
1010         case CX88_BOARD_HAUPPAUGE_HVR1300:
1011                 /* We arrive here with either the cx23416 or the cx22702
1012                  * on the bus. Take the bus from the cx23416 and enable the
1013                  * cx22702 demod
1014                  */
1015                 cx_set(MO_GP0_IO,   0x00000080); /* cx22702 out of reset and enable */
1016                 cx_clear(MO_GP0_IO, 0x00000004);
1017                 udelay(1000);
1018                 break;
1019         default:
1020                 err = -ENODEV;
1021         }
1022         return err;
1023 }
1024
1025 /* CX8802 MPEG -> mini driver - We no longer have the hardware */
1026 static int cx8802_dvb_advise_release(struct cx8802_driver *drv)
1027 {
1028         struct cx88_core *core = drv->core;
1029         int err = 0;
1030         dprintk( 1, "%s\n", __func__);
1031
1032         switch (core->boardnr) {
1033         case CX88_BOARD_HAUPPAUGE_HVR1300:
1034                 /* Do Nothing, leave the cx22702 on the bus. */
1035                 break;
1036         default:
1037                 err = -ENODEV;
1038         }
1039         return err;
1040 }
1041
1042 static int cx8802_dvb_probe(struct cx8802_driver *drv)
1043 {
1044         struct cx88_core *core = drv->core;
1045         struct cx8802_dev *dev = drv->core->dvbdev;
1046         int err;
1047
1048         dprintk( 1, "%s\n", __func__);
1049         dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
1050                 core->boardnr,
1051                 core->name,
1052                 core->pci_bus,
1053                 core->pci_slot);
1054
1055         err = -ENODEV;
1056         if (!(core->board.mpeg & CX88_MPEG_DVB))
1057                 goto fail_core;
1058
1059         /* If vp3054 isn't enabled, a stub will just return 0 */
1060         err = vp3054_i2c_probe(dev);
1061         if (0 != err)
1062                 goto fail_core;
1063
1064         /* dvb stuff */
1065         printk(KERN_INFO "%s/2: cx2388x based DVB/ATSC card\n", core->name);
1066         videobuf_queue_sg_init(&dev->dvb.dvbq, &dvb_qops,
1067                             &dev->pci->dev, &dev->slock,
1068                             V4L2_BUF_TYPE_VIDEO_CAPTURE,
1069                             V4L2_FIELD_TOP,
1070                             sizeof(struct cx88_buffer),
1071                             dev);
1072         err = dvb_register(dev);
1073         if (err != 0)
1074                 printk(KERN_ERR "%s/2: dvb_register failed (err = %d)\n",
1075                        core->name, err);
1076
1077  fail_core:
1078         return err;
1079 }
1080
1081 static int cx8802_dvb_remove(struct cx8802_driver *drv)
1082 {
1083         struct cx8802_dev *dev = drv->core->dvbdev;
1084
1085         /* dvb */
1086         if (dev->dvb.frontend)
1087                 videobuf_dvb_unregister(&dev->dvb);
1088
1089         vp3054_i2c_remove(dev);
1090
1091         return 0;
1092 }
1093
1094 static struct cx8802_driver cx8802_dvb_driver = {
1095         .type_id        = CX88_MPEG_DVB,
1096         .hw_access      = CX8802_DRVCTL_SHARED,
1097         .probe          = cx8802_dvb_probe,
1098         .remove         = cx8802_dvb_remove,
1099         .advise_acquire = cx8802_dvb_advise_acquire,
1100         .advise_release = cx8802_dvb_advise_release,
1101 };
1102
1103 static int dvb_init(void)
1104 {
1105         printk(KERN_INFO "cx88/2: cx2388x dvb driver version %d.%d.%d loaded\n",
1106                (CX88_VERSION_CODE >> 16) & 0xff,
1107                (CX88_VERSION_CODE >>  8) & 0xff,
1108                CX88_VERSION_CODE & 0xff);
1109 #ifdef SNAPSHOT
1110         printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
1111                SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
1112 #endif
1113         return cx8802_register_driver(&cx8802_dvb_driver);
1114 }
1115
1116 static void dvb_fini(void)
1117 {
1118         cx8802_unregister_driver(&cx8802_dvb_driver);
1119 }
1120
1121 module_init(dvb_init);
1122 module_exit(dvb_fini);
1123
1124 /*
1125  * Local variables:
1126  * c-basic-offset: 8
1127  * compile-command: "make DVB=1"
1128  * End:
1129  */