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