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