- patches.suse/slab-handle-memoryless-nodes-v2a.patch: Refresh.
[linux-flexiantxendom0-3.2.10.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 "stv0299.h"
52 #include "z0194a.h"
53 #include "stv0288.h"
54 #include "stb6000.h"
55 #include "cx24116.h"
56 #include "stv0900.h"
57 #include "stb6100.h"
58 #include "stb6100_proc.h"
59
60 MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
61 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
62 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
63 MODULE_LICENSE("GPL");
64
65 static unsigned int debug;
66 module_param(debug, int, 0644);
67 MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
68
69 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
70
71 #define dprintk(level,fmt, arg...)      if (debug >= level) \
72         printk(KERN_DEBUG "%s/2-dvb: " fmt, core->name, ## arg)
73
74 /* ------------------------------------------------------------------ */
75
76 static int dvb_buf_setup(struct videobuf_queue *q,
77                          unsigned int *count, unsigned int *size)
78 {
79         struct cx8802_dev *dev = q->priv_data;
80
81         dev->ts_packet_size  = 188 * 4;
82         dev->ts_packet_count = 32;
83
84         *size  = dev->ts_packet_size * dev->ts_packet_count;
85         *count = 32;
86         return 0;
87 }
88
89 static int dvb_buf_prepare(struct videobuf_queue *q,
90                            struct videobuf_buffer *vb, enum v4l2_field field)
91 {
92         struct cx8802_dev *dev = q->priv_data;
93         return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field);
94 }
95
96 static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
97 {
98         struct cx8802_dev *dev = q->priv_data;
99         cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
100 }
101
102 static void dvb_buf_release(struct videobuf_queue *q,
103                             struct videobuf_buffer *vb)
104 {
105         cx88_free_buffer(q, (struct cx88_buffer*)vb);
106 }
107
108 static struct videobuf_queue_ops dvb_qops = {
109         .buf_setup    = dvb_buf_setup,
110         .buf_prepare  = dvb_buf_prepare,
111         .buf_queue    = dvb_buf_queue,
112         .buf_release  = dvb_buf_release,
113 };
114
115 /* ------------------------------------------------------------------ */
116
117 static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire)
118 {
119         struct cx8802_dev *dev= fe->dvb->priv;
120         struct cx8802_driver *drv = NULL;
121         int ret = 0;
122         int fe_id;
123
124         fe_id = videobuf_dvb_find_frontend(&dev->frontends, fe);
125         if (!fe_id) {
126                 printk(KERN_ERR "%s() No frontend found\n", __func__);
127                 return -EINVAL;
128         }
129
130         drv = cx8802_get_driver(dev, CX88_MPEG_DVB);
131         if (drv) {
132                 if (acquire){
133                         dev->frontends.active_fe_id = fe_id;
134                         ret = drv->request_acquire(drv);
135                 } else {
136                         ret = drv->request_release(drv);
137                         dev->frontends.active_fe_id = 0;
138                 }
139         }
140
141         return ret;
142 }
143
144 static void cx88_dvb_gate_ctrl(struct cx88_core  *core, int open)
145 {
146         struct videobuf_dvb_frontends *f;
147         struct videobuf_dvb_frontend *fe;
148
149         if (!core->dvbdev)
150                 return;
151
152         f = &core->dvbdev->frontends;
153
154         if (!f)
155                 return;
156
157         if (f->gate <= 1) /* undefined or fe0 */
158                 fe = videobuf_dvb_get_frontend(f, 1);
159         else
160                 fe = videobuf_dvb_get_frontend(f, f->gate);
161
162         if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl)
163                 fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open);
164 }
165
166 /* ------------------------------------------------------------------ */
167
168 static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
169 {
170         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x39 };
171         static u8 reset []         = { RESET,      0x80 };
172         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
173         static u8 agc_cfg []       = { AGC_TARGET, 0x24, 0x20 };
174         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
175         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
176
177         mt352_write(fe, clock_config,   sizeof(clock_config));
178         udelay(200);
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         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
184         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
185         return 0;
186 }
187
188 static int dvico_dual_demod_init(struct dvb_frontend *fe)
189 {
190         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x38 };
191         static u8 reset []         = { RESET,      0x80 };
192         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
193         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0x20 };
194         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
195         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
196
197         mt352_write(fe, clock_config,   sizeof(clock_config));
198         udelay(200);
199         mt352_write(fe, reset,          sizeof(reset));
200         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
201
202         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
203         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
204         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
205
206         return 0;
207 }
208
209 static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
210 {
211         static u8 clock_config []  = { 0x89, 0x38, 0x39 };
212         static u8 reset []         = { 0x50, 0x80 };
213         static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
214         static u8 agc_cfg []       = { 0x67, 0x10, 0x23, 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 dvico_fusionhdtv = {
233         .demod_address = 0x0f,
234         .demod_init    = dvico_fusionhdtv_demod_init,
235 };
236
237 static struct mt352_config dntv_live_dvbt_config = {
238         .demod_address = 0x0f,
239         .demod_init    = dntv_live_dvbt_demod_init,
240 };
241
242 static struct mt352_config dvico_fusionhdtv_dual = {
243         .demod_address = 0x0f,
244         .demod_init    = dvico_dual_demod_init,
245 };
246
247 static struct zl10353_config cx88_terratec_cinergy_ht_pci_mkii_config = {
248         .demod_address = (0x1e >> 1),
249         .no_tuner      = 1,
250         .if2           = 45600,
251 };
252
253 #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))
254 static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe)
255 {
256         static u8 clock_config []  = { 0x89, 0x38, 0x38 };
257         static u8 reset []         = { 0x50, 0x80 };
258         static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
259         static u8 agc_cfg []       = { 0x67, 0x10, 0x20, 0x00, 0xFF, 0xFF,
260                                        0x00, 0xFF, 0x00, 0x40, 0x40 };
261         static u8 dntv_extra[]     = { 0xB5, 0x7A };
262         static u8 capt_range_cfg[] = { 0x75, 0x32 };
263
264         mt352_write(fe, clock_config,   sizeof(clock_config));
265         udelay(2000);
266         mt352_write(fe, reset,          sizeof(reset));
267         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
268
269         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
270         udelay(2000);
271         mt352_write(fe, dntv_extra,     sizeof(dntv_extra));
272         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
273
274         return 0;
275 }
276
277 static struct mt352_config dntv_live_dvbt_pro_config = {
278         .demod_address = 0x0f,
279         .no_tuner      = 1,
280         .demod_init    = dntv_live_dvbt_pro_demod_init,
281 };
282 #endif
283
284 static struct zl10353_config dvico_fusionhdtv_hybrid = {
285         .demod_address = 0x0f,
286         .no_tuner      = 1,
287 };
288
289 static struct zl10353_config dvico_fusionhdtv_xc3028 = {
290         .demod_address = 0x0f,
291         .if2           = 45600,
292         .no_tuner      = 1,
293 };
294
295 static struct mt352_config dvico_fusionhdtv_mt352_xc3028 = {
296         .demod_address = 0x0f,
297         .if2 = 4560,
298         .no_tuner = 1,
299         .demod_init = dvico_fusionhdtv_demod_init,
300 };
301
302 static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
303         .demod_address = 0x0f,
304 };
305
306 static struct cx22702_config connexant_refboard_config = {
307         .demod_address = 0x43,
308         .output_mode   = CX22702_SERIAL_OUTPUT,
309 };
310
311 static struct cx22702_config hauppauge_hvr_config = {
312         .demod_address = 0x63,
313         .output_mode   = CX22702_SERIAL_OUTPUT,
314 };
315
316 static int or51132_set_ts_param(struct dvb_frontend* fe, int is_punctured)
317 {
318         struct cx8802_dev *dev= fe->dvb->priv;
319         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
320         return 0;
321 }
322
323 static struct or51132_config pchdtv_hd3000 = {
324         .demod_address = 0x15,
325         .set_ts_params = or51132_set_ts_param,
326 };
327
328 static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
329 {
330         struct cx8802_dev *dev= fe->dvb->priv;
331         struct cx88_core *core = dev->core;
332
333         dprintk(1, "%s: index = %d\n", __func__, index);
334         if (index == 0)
335                 cx_clear(MO_GP0_IO, 8);
336         else
337                 cx_set(MO_GP0_IO, 8);
338         return 0;
339 }
340
341 static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
342 {
343         struct cx8802_dev *dev= fe->dvb->priv;
344         if (is_punctured)
345                 dev->ts_gen_cntrl |= 0x04;
346         else
347                 dev->ts_gen_cntrl &= ~0x04;
348         return 0;
349 }
350
351 static struct lgdt330x_config fusionhdtv_3_gold = {
352         .demod_address = 0x0e,
353         .demod_chip    = LGDT3302,
354         .serial_mpeg   = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
355         .set_ts_params = lgdt330x_set_ts_param,
356 };
357
358 static struct lgdt330x_config fusionhdtv_5_gold = {
359         .demod_address = 0x0e,
360         .demod_chip    = LGDT3303,
361         .serial_mpeg   = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
362         .set_ts_params = lgdt330x_set_ts_param,
363 };
364
365 static struct lgdt330x_config pchdtv_hd5500 = {
366         .demod_address = 0x59,
367         .demod_chip    = LGDT3303,
368         .serial_mpeg   = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
369         .set_ts_params = lgdt330x_set_ts_param,
370 };
371
372 static int nxt200x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
373 {
374         struct cx8802_dev *dev= fe->dvb->priv;
375         dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
376         return 0;
377 }
378
379 static struct nxt200x_config ati_hdtvwonder = {
380         .demod_address = 0x0a,
381         .set_ts_params = nxt200x_set_ts_param,
382 };
383
384 static int cx24123_set_ts_param(struct dvb_frontend* fe,
385         int is_punctured)
386 {
387         struct cx8802_dev *dev= fe->dvb->priv;
388         dev->ts_gen_cntrl = 0x02;
389         return 0;
390 }
391
392 static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
393                                        fe_sec_voltage_t voltage)
394 {
395         struct cx8802_dev *dev= fe->dvb->priv;
396         struct cx88_core *core = dev->core;
397
398         if (voltage == SEC_VOLTAGE_OFF)
399                 cx_write(MO_GP0_IO, 0x000006fb);
400         else
401                 cx_write(MO_GP0_IO, 0x000006f9);
402
403         if (core->prev_set_voltage)
404                 return core->prev_set_voltage(fe, voltage);
405         return 0;
406 }
407
408 static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
409                                       fe_sec_voltage_t voltage)
410 {
411         struct cx8802_dev *dev= fe->dvb->priv;
412         struct cx88_core *core = dev->core;
413
414         if (voltage == SEC_VOLTAGE_OFF) {
415                 dprintk(1,"LNB Voltage OFF\n");
416                 cx_write(MO_GP0_IO, 0x0000efff);
417         }
418
419         if (core->prev_set_voltage)
420                 return core->prev_set_voltage(fe, voltage);
421         return 0;
422 }
423
424 static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,
425                                       fe_sec_voltage_t voltage)
426 {
427         struct cx8802_dev *dev= fe->dvb->priv;
428         struct cx88_core *core = dev->core;
429
430         cx_set(MO_GP0_IO, 0x6040);
431         switch (voltage) {
432                 case SEC_VOLTAGE_13:
433                         cx_clear(MO_GP0_IO, 0x20);
434                         break;
435                 case SEC_VOLTAGE_18:
436                         cx_set(MO_GP0_IO, 0x20);
437                         break;
438                 case SEC_VOLTAGE_OFF:
439                         cx_clear(MO_GP0_IO, 0x20);
440                         break;
441         }
442
443         if (core->prev_set_voltage)
444                 return core->prev_set_voltage(fe, voltage);
445         return 0;
446 }
447
448 static struct cx24123_config geniatech_dvbs_config = {
449         .demod_address = 0x55,
450         .set_ts_params = cx24123_set_ts_param,
451 };
452
453 static struct cx24123_config hauppauge_novas_config = {
454         .demod_address = 0x55,
455         .set_ts_params = cx24123_set_ts_param,
456 };
457
458 static struct cx24123_config kworld_dvbs_100_config = {
459         .demod_address = 0x15,
460         .set_ts_params = cx24123_set_ts_param,
461         .lnb_polarity  = 1,
462 };
463
464 static struct s5h1409_config pinnacle_pctv_hd_800i_config = {
465         .demod_address = 0x32 >> 1,
466         .output_mode   = S5H1409_PARALLEL_OUTPUT,
467         .gpio          = S5H1409_GPIO_ON,
468         .qam_if        = 44000,
469         .inversion     = S5H1409_INVERSION_OFF,
470         .status_mode   = S5H1409_DEMODLOCKING,
471         .mpeg_timing   = S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
472 };
473
474 static struct s5h1409_config dvico_hdtv5_pci_nano_config = {
475         .demod_address = 0x32 >> 1,
476         .output_mode   = S5H1409_SERIAL_OUTPUT,
477         .gpio          = S5H1409_GPIO_OFF,
478         .inversion     = S5H1409_INVERSION_OFF,
479         .status_mode   = S5H1409_DEMODLOCKING,
480         .mpeg_timing   = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
481 };
482
483 static struct s5h1409_config kworld_atsc_120_config = {
484         .demod_address = 0x32 >> 1,
485         .output_mode   = S5H1409_SERIAL_OUTPUT,
486         .gpio          = S5H1409_GPIO_OFF,
487         .inversion     = S5H1409_INVERSION_OFF,
488         .status_mode   = S5H1409_DEMODLOCKING,
489         .mpeg_timing   = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
490 };
491
492 static struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = {
493         .i2c_address    = 0x64,
494         .if_khz         = 5380,
495 };
496
497 static struct zl10353_config cx88_pinnacle_hybrid_pctv = {
498         .demod_address = (0x1e >> 1),
499         .no_tuner      = 1,
500         .if2           = 45600,
501 };
502
503 static struct zl10353_config cx88_geniatech_x8000_mt = {
504         .demod_address = (0x1e >> 1),
505         .no_tuner = 1,
506         .disable_i2c_gate_ctrl = 1,
507 };
508
509 static struct s5h1411_config dvico_fusionhdtv7_config = {
510         .output_mode   = S5H1411_SERIAL_OUTPUT,
511         .gpio          = S5H1411_GPIO_ON,
512         .mpeg_timing   = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
513         .qam_if        = S5H1411_IF_44000,
514         .vsb_if        = S5H1411_IF_44000,
515         .inversion     = S5H1411_INVERSION_OFF,
516         .status_mode   = S5H1411_DEMODLOCKING
517 };
518
519 static struct xc5000_config dvico_fusionhdtv7_tuner_config = {
520         .i2c_address    = 0xc2 >> 1,
521         .if_khz         = 5380,
522 };
523
524 static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
525 {
526         struct dvb_frontend *fe;
527         struct videobuf_dvb_frontend *fe0 = NULL;
528         struct xc2028_ctrl ctl;
529         struct xc2028_config cfg = {
530                 .i2c_adap  = &dev->core->i2c_adap,
531                 .i2c_addr  = addr,
532                 .ctrl      = &ctl,
533         };
534
535         /* Get the first frontend */
536         fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
537         if (!fe0)
538                 return -EINVAL;
539
540         if (!fe0->dvb.frontend) {
541                 printk(KERN_ERR "%s/2: dvb frontend not attached. "
542                                 "Can't attach xc3028\n",
543                        dev->core->name);
544                 return -EINVAL;
545         }
546
547         /*
548          * Some xc3028 devices may be hidden by an I2C gate. This is known
549          * to happen with some s5h1409-based devices.
550          * Now that I2C gate is open, sets up xc3028 configuration
551          */
552         cx88_setup_xc3028(dev->core, &ctl);
553
554         fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
555         if (!fe) {
556                 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
557                        dev->core->name);
558                 dvb_frontend_detach(fe0->dvb.frontend);
559                 dvb_unregister_frontend(fe0->dvb.frontend);
560                 fe0->dvb.frontend = NULL;
561                 return -EINVAL;
562         }
563
564         printk(KERN_INFO "%s/2: xc3028 attached\n",
565                dev->core->name);
566
567         return 0;
568 }
569
570 static int cx24116_set_ts_param(struct dvb_frontend *fe,
571         int is_punctured)
572 {
573         struct cx8802_dev *dev = fe->dvb->priv;
574         dev->ts_gen_cntrl = 0x2;
575
576         return 0;
577 }
578
579 static int stv0900_set_ts_param(struct dvb_frontend *fe,
580         int is_punctured)
581 {
582         struct cx8802_dev *dev = fe->dvb->priv;
583         dev->ts_gen_cntrl = 0;
584
585         return 0;
586 }
587
588 static int cx24116_reset_device(struct dvb_frontend *fe)
589 {
590         struct cx8802_dev *dev = fe->dvb->priv;
591         struct cx88_core *core = dev->core;
592
593         /* Reset the part */
594         /* Put the cx24116 into reset */
595         cx_write(MO_SRST_IO, 0);
596         msleep(10);
597         /* Take the cx24116 out of reset */
598         cx_write(MO_SRST_IO, 1);
599         msleep(10);
600
601         return 0;
602 }
603
604 static struct cx24116_config hauppauge_hvr4000_config = {
605         .demod_address          = 0x05,
606         .set_ts_params          = cx24116_set_ts_param,
607         .reset_device           = cx24116_reset_device,
608 };
609
610 static struct cx24116_config tevii_s460_config = {
611         .demod_address = 0x55,
612         .set_ts_params = cx24116_set_ts_param,
613         .reset_device  = cx24116_reset_device,
614 };
615
616 static struct stv0900_config prof_7301_stv0900_config = {
617         .demod_address = 0x6a,
618 /*      demod_mode = 0,*/
619         .xtal = 27000000,
620         .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
621         .diseqc_mode = 2,/* 2/3 PWM */
622         .tun1_maddress = 0,/* 0x60 */
623         .tun1_adc = 0,/* 2 Vpp */
624         .path1_mode = 3,
625         .set_ts_params = stv0900_set_ts_param,
626 };
627
628 static struct stb6100_config prof_7301_stb6100_config = {
629         .tuner_address = 0x60,
630         .refclock = 27000000,
631 };
632
633 static struct stv0299_config tevii_tuner_sharp_config = {
634         .demod_address = 0x68,
635         .inittab = sharp_z0194a_inittab,
636         .mclk = 88000000UL,
637         .invert = 1,
638         .skip_reinit = 0,
639         .lock_output = 1,
640         .volt13_op0_op1 = STV0299_VOLT13_OP1,
641         .min_delay_ms = 100,
642         .set_symbol_rate = sharp_z0194a_set_symbol_rate,
643         .set_ts_params = cx24116_set_ts_param,
644 };
645
646 static struct stv0288_config tevii_tuner_earda_config = {
647         .demod_address = 0x68,
648         .min_delay_ms = 100,
649         .set_ts_params = cx24116_set_ts_param,
650 };
651
652 static int cx8802_alloc_frontends(struct cx8802_dev *dev)
653 {
654         struct cx88_core *core = dev->core;
655         struct videobuf_dvb_frontend *fe = NULL;
656         int i;
657
658         mutex_init(&dev->frontends.lock);
659         INIT_LIST_HEAD(&dev->frontends.felist);
660
661         if (!core->board.num_frontends)
662                 return -ENODEV;
663
664         printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
665                          core->board.num_frontends);
666         for (i = 1; i <= core->board.num_frontends; i++) {
667                 fe = videobuf_dvb_alloc_frontend(&dev->frontends, i);
668                 if (!fe) {
669                         printk(KERN_ERR "%s() failed to alloc\n", __func__);
670                         videobuf_dvb_dealloc_frontends(&dev->frontends);
671                         return -ENOMEM;
672                 }
673         }
674         return 0;
675 }
676
677 static int dvb_register(struct cx8802_dev *dev)
678 {
679         struct cx88_core *core = dev->core;
680         struct videobuf_dvb_frontend *fe0, *fe1 = NULL;
681         int mfe_shared = 0; /* bus not shared by default */
682
683         if (0 != core->i2c_rc) {
684                 printk(KERN_ERR "%s/2: no i2c-bus available, cannot attach dvb drivers\n", core->name);
685                 goto frontend_detach;
686         }
687
688         /* Get the first frontend */
689         fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
690         if (!fe0)
691                 goto frontend_detach;
692
693         /* multi-frontend gate control is undefined or defaults to fe0 */
694         dev->frontends.gate = 0;
695
696         /* Sets the gate control callback to be used by i2c command calls */
697         core->gate_ctrl = cx88_dvb_gate_ctrl;
698
699         /* init frontend(s) */
700         switch (core->boardnr) {
701         case CX88_BOARD_HAUPPAUGE_DVB_T1:
702                 fe0->dvb.frontend = dvb_attach(cx22702_attach,
703                                                &connexant_refboard_config,
704                                                &core->i2c_adap);
705                 if (fe0->dvb.frontend != NULL) {
706                         if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
707                                         0x61, &core->i2c_adap,
708                                         DVB_PLL_THOMSON_DTT759X))
709                                 goto frontend_detach;
710                 }
711                 break;
712         case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
713         case CX88_BOARD_CONEXANT_DVB_T1:
714         case CX88_BOARD_KWORLD_DVB_T_CX22702:
715         case CX88_BOARD_WINFAST_DTV1000:
716                 fe0->dvb.frontend = dvb_attach(cx22702_attach,
717                                                &connexant_refboard_config,
718                                                &core->i2c_adap);
719                 if (fe0->dvb.frontend != NULL) {
720                         if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
721                                         0x60, &core->i2c_adap,
722                                         DVB_PLL_THOMSON_DTT7579))
723                                 goto frontend_detach;
724                 }
725                 break;
726         case CX88_BOARD_WINFAST_DTV2000H:
727         case CX88_BOARD_WINFAST_DTV2000H_J:
728         case CX88_BOARD_HAUPPAUGE_HVR1100:
729         case CX88_BOARD_HAUPPAUGE_HVR1100LP:
730         case CX88_BOARD_HAUPPAUGE_HVR1300:
731                 fe0->dvb.frontend = dvb_attach(cx22702_attach,
732                                                &hauppauge_hvr_config,
733                                                &core->i2c_adap);
734                 if (fe0->dvb.frontend != NULL) {
735                         if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
736                                    &core->i2c_adap, 0x61,
737                                    TUNER_PHILIPS_FMD1216ME_MK3))
738                                 goto frontend_detach;
739                 }
740                 break;
741         case CX88_BOARD_HAUPPAUGE_HVR3000:
742                 /* MFE frontend 1 */
743                 mfe_shared = 1;
744                 dev->frontends.gate = 2;
745                 /* DVB-S init */
746                 fe0->dvb.frontend = dvb_attach(cx24123_attach,
747                                         &hauppauge_novas_config,
748                                         &dev->core->i2c_adap);
749                 if (fe0->dvb.frontend) {
750                         if (!dvb_attach(isl6421_attach,
751                                         fe0->dvb.frontend,
752                                         &dev->core->i2c_adap,
753                                         0x08, ISL6421_DCL, 0x00))
754                                 goto frontend_detach;
755                 }
756                 /* MFE frontend 2 */
757                 fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2);
758                 if (!fe1)
759                         goto frontend_detach;
760                 /* DVB-T init */
761                 fe1->dvb.frontend = dvb_attach(cx22702_attach,
762                                         &hauppauge_hvr_config,
763                                         &dev->core->i2c_adap);
764                 if (fe1->dvb.frontend) {
765                         fe1->dvb.frontend->id = 1;
766                         if (!dvb_attach(simple_tuner_attach,
767                                         fe1->dvb.frontend,
768                                         &dev->core->i2c_adap,
769                                         0x61, TUNER_PHILIPS_FMD1216ME_MK3))
770                                 goto frontend_detach;
771                 }
772                 break;
773         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
774                 fe0->dvb.frontend = dvb_attach(mt352_attach,
775                                                &dvico_fusionhdtv,
776                                                &core->i2c_adap);
777                 if (fe0->dvb.frontend != NULL) {
778                         if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
779                                         0x60, NULL, DVB_PLL_THOMSON_DTT7579))
780                                 goto frontend_detach;
781                         break;
782                 }
783                 /* ZL10353 replaces MT352 on later cards */
784                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
785                                                &dvico_fusionhdtv_plus_v1_1,
786                                                &core->i2c_adap);
787                 if (fe0->dvb.frontend != NULL) {
788                         if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
789                                         0x60, NULL, DVB_PLL_THOMSON_DTT7579))
790                                 goto frontend_detach;
791                 }
792                 break;
793         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
794                 /* The tin box says DEE1601, but it seems to be DTT7579
795                  * compatible, with a slightly different MT352 AGC gain. */
796                 fe0->dvb.frontend = dvb_attach(mt352_attach,
797                                                &dvico_fusionhdtv_dual,
798                                                &core->i2c_adap);
799                 if (fe0->dvb.frontend != NULL) {
800                         if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
801                                         0x61, NULL, DVB_PLL_THOMSON_DTT7579))
802                                 goto frontend_detach;
803                         break;
804                 }
805                 /* ZL10353 replaces MT352 on later cards */
806                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
807                                                &dvico_fusionhdtv_plus_v1_1,
808                                                &core->i2c_adap);
809                 if (fe0->dvb.frontend != NULL) {
810                         if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
811                                         0x61, NULL, DVB_PLL_THOMSON_DTT7579))
812                                 goto frontend_detach;
813                 }
814                 break;
815         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
816                 fe0->dvb.frontend = dvb_attach(mt352_attach,
817                                                &dvico_fusionhdtv,
818                                                &core->i2c_adap);
819                 if (fe0->dvb.frontend != NULL) {
820                         if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
821                                         0x61, NULL, DVB_PLL_LG_Z201))
822                                 goto frontend_detach;
823                 }
824                 break;
825         case CX88_BOARD_KWORLD_DVB_T:
826         case CX88_BOARD_DNTV_LIVE_DVB_T:
827         case CX88_BOARD_ADSTECH_DVB_T_PCI:
828                 fe0->dvb.frontend = dvb_attach(mt352_attach,
829                                                &dntv_live_dvbt_config,
830                                                &core->i2c_adap);
831                 if (fe0->dvb.frontend != NULL) {
832                         if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
833                                         0x61, NULL, DVB_PLL_UNKNOWN_1))
834                                 goto frontend_detach;
835                 }
836                 break;
837         case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
838 #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))
839                 /* MT352 is on a secondary I2C bus made from some GPIO lines */
840                 fe0->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
841                                                &dev->vp3054->adap);
842                 if (fe0->dvb.frontend != NULL) {
843                         if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
844                                         &core->i2c_adap, 0x61,
845                                         TUNER_PHILIPS_FMD1216ME_MK3))
846                                 goto frontend_detach;
847                 }
848 #else
849                 printk(KERN_ERR "%s/2: built without vp3054 support\n",
850                                 core->name);
851 #endif
852                 break;
853         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
854                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
855                                                &dvico_fusionhdtv_hybrid,
856                                                &core->i2c_adap);
857                 if (fe0->dvb.frontend != NULL) {
858                         if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
859                                    &core->i2c_adap, 0x61,
860                                    TUNER_THOMSON_FE6600))
861                                 goto frontend_detach;
862                 }
863                 break;
864         case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
865                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
866                                                &dvico_fusionhdtv_xc3028,
867                                                &core->i2c_adap);
868                 if (fe0->dvb.frontend == NULL)
869                         fe0->dvb.frontend = dvb_attach(mt352_attach,
870                                                 &dvico_fusionhdtv_mt352_xc3028,
871                                                 &core->i2c_adap);
872                 /*
873                  * On this board, the demod provides the I2C bus pullup.
874                  * We must not permit gate_ctrl to be performed, or
875                  * the xc3028 cannot communicate on the bus.
876                  */
877                 if (fe0->dvb.frontend)
878                         fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
879                 if (attach_xc3028(0x61, dev) < 0)
880                         goto frontend_detach;
881                 break;
882         case CX88_BOARD_PCHDTV_HD3000:
883                 fe0->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000,
884                                                &core->i2c_adap);
885                 if (fe0->dvb.frontend != NULL) {
886                         if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
887                                         &core->i2c_adap, 0x61,
888                                         TUNER_THOMSON_DTT761X))
889                                 goto frontend_detach;
890                 }
891                 break;
892         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
893                 dev->ts_gen_cntrl = 0x08;
894
895                 /* Do a hardware reset of chip before using it. */
896                 cx_clear(MO_GP0_IO, 1);
897                 mdelay(100);
898                 cx_set(MO_GP0_IO, 1);
899                 mdelay(200);
900
901                 /* Select RF connector callback */
902                 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
903                 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
904                                                &fusionhdtv_3_gold,
905                                                &core->i2c_adap);
906                 if (fe0->dvb.frontend != NULL) {
907                         if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
908                                         &core->i2c_adap, 0x61,
909                                         TUNER_MICROTUNE_4042FI5))
910                                 goto frontend_detach;
911                 }
912                 break;
913         case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
914                 dev->ts_gen_cntrl = 0x08;
915
916                 /* Do a hardware reset of chip before using it. */
917                 cx_clear(MO_GP0_IO, 1);
918                 mdelay(100);
919                 cx_set(MO_GP0_IO, 9);
920                 mdelay(200);
921                 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
922                                                &fusionhdtv_3_gold,
923                                                &core->i2c_adap);
924                 if (fe0->dvb.frontend != NULL) {
925                         if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
926                                         &core->i2c_adap, 0x61,
927                                         TUNER_THOMSON_DTT761X))
928                                 goto frontend_detach;
929                 }
930                 break;
931         case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
932                 dev->ts_gen_cntrl = 0x08;
933
934                 /* Do a hardware reset of chip before using it. */
935                 cx_clear(MO_GP0_IO, 1);
936                 mdelay(100);
937                 cx_set(MO_GP0_IO, 1);
938                 mdelay(200);
939                 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
940                                                &fusionhdtv_5_gold,
941                                                &core->i2c_adap);
942                 if (fe0->dvb.frontend != NULL) {
943                         if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
944                                         &core->i2c_adap, 0x61,
945                                         TUNER_LG_TDVS_H06XF))
946                                 goto frontend_detach;
947                         if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,
948                                    &core->i2c_adap, 0x43))
949                                 goto frontend_detach;
950                 }
951                 break;
952         case CX88_BOARD_PCHDTV_HD5500:
953                 dev->ts_gen_cntrl = 0x08;
954
955                 /* Do a hardware reset of chip before using it. */
956                 cx_clear(MO_GP0_IO, 1);
957                 mdelay(100);
958                 cx_set(MO_GP0_IO, 1);
959                 mdelay(200);
960                 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
961                                                &pchdtv_hd5500,
962                                                &core->i2c_adap);
963                 if (fe0->dvb.frontend != NULL) {
964                         if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
965                                         &core->i2c_adap, 0x61,
966                                         TUNER_LG_TDVS_H06XF))
967                                 goto frontend_detach;
968                         if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,
969                                    &core->i2c_adap, 0x43))
970                                 goto frontend_detach;
971                 }
972                 break;
973         case CX88_BOARD_ATI_HDTVWONDER:
974                 fe0->dvb.frontend = dvb_attach(nxt200x_attach,
975                                                &ati_hdtvwonder,
976                                                &core->i2c_adap);
977                 if (fe0->dvb.frontend != NULL) {
978                         if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
979                                         &core->i2c_adap, 0x61,
980                                         TUNER_PHILIPS_TUV1236D))
981                                 goto frontend_detach;
982                 }
983                 break;
984         case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
985         case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
986                 fe0->dvb.frontend = dvb_attach(cx24123_attach,
987                                                &hauppauge_novas_config,
988                                                &core->i2c_adap);
989                 if (fe0->dvb.frontend) {
990                         if (!dvb_attach(isl6421_attach, fe0->dvb.frontend,
991                                         &core->i2c_adap, 0x08, ISL6421_DCL, 0x00))
992                                 goto frontend_detach;
993                 }
994                 break;
995         case CX88_BOARD_KWORLD_DVBS_100:
996                 fe0->dvb.frontend = dvb_attach(cx24123_attach,
997                                                &kworld_dvbs_100_config,
998                                                &core->i2c_adap);
999                 if (fe0->dvb.frontend) {
1000                         core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
1001                         fe0->dvb.frontend->ops.set_voltage = kworld_dvbs_100_set_voltage;
1002                 }
1003                 break;
1004         case CX88_BOARD_GENIATECH_DVBS:
1005                 fe0->dvb.frontend = dvb_attach(cx24123_attach,
1006                                                &geniatech_dvbs_config,
1007                                                &core->i2c_adap);
1008                 if (fe0->dvb.frontend) {
1009                         core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
1010                         fe0->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;
1011                 }
1012                 break;
1013         case CX88_BOARD_PINNACLE_PCTV_HD_800i:
1014                 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1015                                                &pinnacle_pctv_hd_800i_config,
1016                                                &core->i2c_adap);
1017                 if (fe0->dvb.frontend != NULL) {
1018                         if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,
1019                                         &core->i2c_adap,
1020                                         &pinnacle_pctv_hd_800i_tuner_config))
1021                                 goto frontend_detach;
1022                 }
1023                 break;
1024         case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
1025                 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1026                                                 &dvico_hdtv5_pci_nano_config,
1027                                                 &core->i2c_adap);
1028                 if (fe0->dvb.frontend != NULL) {
1029                         struct dvb_frontend *fe;
1030                         struct xc2028_config cfg = {
1031                                 .i2c_adap  = &core->i2c_adap,
1032                                 .i2c_addr  = 0x61,
1033                         };
1034                         static struct xc2028_ctrl ctl = {
1035                                 .fname       = XC2028_DEFAULT_FIRMWARE,
1036                                 .max_len     = 64,
1037                                 .scode_table = XC3028_FE_OREN538,
1038                         };
1039
1040                         fe = dvb_attach(xc2028_attach,
1041                                         fe0->dvb.frontend, &cfg);
1042                         if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
1043                                 fe->ops.tuner_ops.set_config(fe, &ctl);
1044                 }
1045                 break;
1046          case CX88_BOARD_PINNACLE_HYBRID_PCTV:
1047         case CX88_BOARD_WINFAST_DTV1800H:
1048                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1049                                                &cx88_pinnacle_hybrid_pctv,
1050                                                &core->i2c_adap);
1051                 if (fe0->dvb.frontend) {
1052                         fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1053                         if (attach_xc3028(0x61, dev) < 0)
1054                                 goto frontend_detach;
1055                 }
1056                 break;
1057          case CX88_BOARD_GENIATECH_X8000_MT:
1058                 dev->ts_gen_cntrl = 0x00;
1059
1060                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1061                                                &cx88_geniatech_x8000_mt,
1062                                                &core->i2c_adap);
1063                 if (attach_xc3028(0x61, dev) < 0)
1064                         goto frontend_detach;
1065                 break;
1066          case CX88_BOARD_KWORLD_ATSC_120:
1067                 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
1068                                                &kworld_atsc_120_config,
1069                                                &core->i2c_adap);
1070                 if (attach_xc3028(0x61, dev) < 0)
1071                         goto frontend_detach;
1072                 break;
1073         case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
1074                 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1075                                                &dvico_fusionhdtv7_config,
1076                                                &core->i2c_adap);
1077                 if (fe0->dvb.frontend != NULL) {
1078                         if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,
1079                                         &core->i2c_adap,
1080                                         &dvico_fusionhdtv7_tuner_config))
1081                                 goto frontend_detach;
1082                 }
1083                 break;
1084         case CX88_BOARD_HAUPPAUGE_HVR4000:
1085                 /* MFE frontend 1 */
1086                 mfe_shared = 1;
1087                 dev->frontends.gate = 2;
1088                 /* DVB-S/S2 Init */
1089                 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1090                                         &hauppauge_hvr4000_config,
1091                                         &dev->core->i2c_adap);
1092                 if (fe0->dvb.frontend) {
1093                         if (!dvb_attach(isl6421_attach,
1094                                         fe0->dvb.frontend,
1095                                         &dev->core->i2c_adap,
1096                                         0x08, ISL6421_DCL, 0x00))
1097                                 goto frontend_detach;
1098                 }
1099                 /* MFE frontend 2 */
1100                 fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2);
1101                 if (!fe1)
1102                         goto frontend_detach;
1103                 /* DVB-T Init */
1104                 fe1->dvb.frontend = dvb_attach(cx22702_attach,
1105                                         &hauppauge_hvr_config,
1106                                         &dev->core->i2c_adap);
1107                 if (fe1->dvb.frontend) {
1108                         fe1->dvb.frontend->id = 1;
1109                         if (!dvb_attach(simple_tuner_attach,
1110                                         fe1->dvb.frontend,
1111                                         &dev->core->i2c_adap,
1112                                         0x61, TUNER_PHILIPS_FMD1216ME_MK3))
1113                                 goto frontend_detach;
1114                 }
1115                 break;
1116         case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
1117                 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1118                                         &hauppauge_hvr4000_config,
1119                                         &dev->core->i2c_adap);
1120                 if (fe0->dvb.frontend) {
1121                         if (!dvb_attach(isl6421_attach,
1122                                         fe0->dvb.frontend,
1123                                         &dev->core->i2c_adap,
1124                                         0x08, ISL6421_DCL, 0x00))
1125                                 goto frontend_detach;
1126                 }
1127                 break;
1128         case CX88_BOARD_PROF_6200:
1129         case CX88_BOARD_TBS_8910:
1130         case CX88_BOARD_TEVII_S420:
1131                 fe0->dvb.frontend = dvb_attach(stv0299_attach,
1132                                                 &tevii_tuner_sharp_config,
1133                                                 &core->i2c_adap);
1134                 if (fe0->dvb.frontend != NULL) {
1135                         if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
1136                                         &core->i2c_adap, DVB_PLL_OPERA1))
1137                                 goto frontend_detach;
1138                         core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
1139                         fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
1140
1141                 } else {
1142                         fe0->dvb.frontend = dvb_attach(stv0288_attach,
1143                                                             &tevii_tuner_earda_config,
1144                                                             &core->i2c_adap);
1145                                 if (fe0->dvb.frontend != NULL) {
1146                                         if (!dvb_attach(stb6000_attach, fe0->dvb.frontend, 0x61,
1147                                                 &core->i2c_adap))
1148                                         goto frontend_detach;
1149                                 core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
1150                                 fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
1151                         }
1152                 }
1153                 break;
1154         case CX88_BOARD_TEVII_S460:
1155                 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1156                                                &tevii_s460_config,
1157                                                &core->i2c_adap);
1158                 if (fe0->dvb.frontend != NULL)
1159                         fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
1160                 break;
1161         case CX88_BOARD_OMICOM_SS4_PCI:
1162         case CX88_BOARD_TBS_8920:
1163         case CX88_BOARD_PROF_7300:
1164         case CX88_BOARD_SATTRADE_ST4200:
1165                 fe0->dvb.frontend = dvb_attach(cx24116_attach,
1166                                                &hauppauge_hvr4000_config,
1167                                                &core->i2c_adap);
1168                 if (fe0->dvb.frontend != NULL)
1169                         fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
1170                 break;
1171         case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII:
1172                 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1173                                                &cx88_terratec_cinergy_ht_pci_mkii_config,
1174                                                &core->i2c_adap);
1175                 if (fe0->dvb.frontend) {
1176                         fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1177                         if (attach_xc3028(0x61, dev) < 0)
1178                                 goto frontend_detach;
1179                 }
1180                 break;
1181         case CX88_BOARD_PROF_7301:{
1182                 struct dvb_tuner_ops *tuner_ops = NULL;
1183
1184                 fe0->dvb.frontend = dvb_attach(stv0900_attach,
1185                                                 &prof_7301_stv0900_config,
1186                                                 &core->i2c_adap, 0);
1187                 if (fe0->dvb.frontend != NULL) {
1188                         if (!dvb_attach(stb6100_attach, fe0->dvb.frontend,
1189                                         &prof_7301_stb6100_config,
1190                                         &core->i2c_adap))
1191                                 goto frontend_detach;
1192
1193                         tuner_ops = &fe0->dvb.frontend->ops.tuner_ops;
1194                         tuner_ops->set_frequency = stb6100_set_freq;
1195                         tuner_ops->get_frequency = stb6100_get_freq;
1196                         tuner_ops->set_bandwidth = stb6100_set_bandw;
1197                         tuner_ops->get_bandwidth = stb6100_get_bandw;
1198
1199                         core->prev_set_voltage =
1200                                         fe0->dvb.frontend->ops.set_voltage;
1201                         fe0->dvb.frontend->ops.set_voltage =
1202                                         tevii_dvbs_set_voltage;
1203                 }
1204                 break;
1205                 }
1206         default:
1207                 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
1208                        core->name);
1209                 break;
1210         }
1211
1212         if ( (NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend) ) {
1213                 printk(KERN_ERR
1214                        "%s/2: frontend initialization failed\n",
1215                        core->name);
1216                 goto frontend_detach;
1217         }
1218         /* define general-purpose callback pointer */
1219         fe0->dvb.frontend->callback = cx88_tuner_callback;
1220
1221         /* Ensure all frontends negotiate bus access */
1222         fe0->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
1223         if (fe1)
1224                 fe1->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
1225
1226         /* Put the analog decoder in standby to keep it quiet */
1227         call_all(core, core, s_power, 0);
1228
1229         /* register everything */
1230         return videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
1231                                          &dev->pci->dev, adapter_nr, mfe_shared, NULL);
1232
1233 frontend_detach:
1234         core->gate_ctrl = NULL;
1235         videobuf_dvb_dealloc_frontends(&dev->frontends);
1236         return -EINVAL;
1237 }
1238
1239 /* ----------------------------------------------------------- */
1240
1241 /* CX8802 MPEG -> mini driver - We have been given the hardware */
1242 static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)
1243 {
1244         struct cx88_core *core = drv->core;
1245         int err = 0;
1246         dprintk( 1, "%s\n", __func__);
1247
1248         switch (core->boardnr) {
1249         case CX88_BOARD_HAUPPAUGE_HVR1300:
1250                 /* We arrive here with either the cx23416 or the cx22702
1251                  * on the bus. Take the bus from the cx23416 and enable the
1252                  * cx22702 demod
1253                  */
1254                 /* Toggle reset on cx22702 leaving i2c active */
1255                 cx_set(MO_GP0_IO, 0x00000080);
1256                 udelay(1000);
1257                 cx_clear(MO_GP0_IO, 0x00000080);
1258                 udelay(50);
1259                 cx_set(MO_GP0_IO, 0x00000080);
1260                 udelay(1000);
1261                 /* enable the cx22702 pins */
1262                 cx_clear(MO_GP0_IO, 0x00000004);
1263                 udelay(1000);
1264                 break;
1265
1266         case CX88_BOARD_HAUPPAUGE_HVR3000:
1267         case CX88_BOARD_HAUPPAUGE_HVR4000:
1268                 /* Toggle reset on cx22702 leaving i2c active */
1269                 cx_set(MO_GP0_IO, 0x00000080);
1270                 udelay(1000);
1271                 cx_clear(MO_GP0_IO, 0x00000080);
1272                 udelay(50);
1273                 cx_set(MO_GP0_IO, 0x00000080);
1274                 udelay(1000);
1275                 switch (core->dvbdev->frontends.active_fe_id) {
1276                 case 1: /* DVB-S/S2 Enabled */
1277                         /* tri-state the cx22702 pins */
1278                         cx_set(MO_GP0_IO, 0x00000004);
1279                         /* Take the cx24116/cx24123 out of reset */
1280                         cx_write(MO_SRST_IO, 1);
1281                         core->dvbdev->ts_gen_cntrl = 0x02; /* Parallel IO */
1282                         break;
1283                 case 2: /* DVB-T Enabled */
1284                         /* Put the cx24116/cx24123 into reset */
1285                         cx_write(MO_SRST_IO, 0);
1286                         /* enable the cx22702 pins */
1287                         cx_clear(MO_GP0_IO, 0x00000004);
1288                         core->dvbdev->ts_gen_cntrl = 0x0c; /* Serial IO */
1289                         break;
1290                 }
1291                 udelay(1000);
1292                 break;
1293
1294         default:
1295                 err = -ENODEV;
1296         }
1297         return err;
1298 }
1299
1300 /* CX8802 MPEG -> mini driver - We no longer have the hardware */
1301 static int cx8802_dvb_advise_release(struct cx8802_driver *drv)
1302 {
1303         struct cx88_core *core = drv->core;
1304         int err = 0;
1305         dprintk( 1, "%s\n", __func__);
1306
1307         switch (core->boardnr) {
1308         case CX88_BOARD_HAUPPAUGE_HVR1300:
1309                 /* Do Nothing, leave the cx22702 on the bus. */
1310                 break;
1311         case CX88_BOARD_HAUPPAUGE_HVR3000:
1312         case CX88_BOARD_HAUPPAUGE_HVR4000:
1313                 break;
1314         default:
1315                 err = -ENODEV;
1316         }
1317         return err;
1318 }
1319
1320 static int cx8802_dvb_probe(struct cx8802_driver *drv)
1321 {
1322         struct cx88_core *core = drv->core;
1323         struct cx8802_dev *dev = drv->core->dvbdev;
1324         int err;
1325         struct videobuf_dvb_frontend *fe;
1326         int i;
1327
1328         dprintk( 1, "%s\n", __func__);
1329         dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
1330                 core->boardnr,
1331                 core->name,
1332                 core->pci_bus,
1333                 core->pci_slot);
1334
1335         err = -ENODEV;
1336         if (!(core->board.mpeg & CX88_MPEG_DVB))
1337                 goto fail_core;
1338
1339         /* If vp3054 isn't enabled, a stub will just return 0 */
1340         err = vp3054_i2c_probe(dev);
1341         if (0 != err)
1342                 goto fail_core;
1343
1344         /* dvb stuff */
1345         printk(KERN_INFO "%s/2: cx2388x based DVB/ATSC card\n", core->name);
1346         dev->ts_gen_cntrl = 0x0c;
1347
1348         err = cx8802_alloc_frontends(dev);
1349         if (err)
1350                 goto fail_core;
1351
1352         err = -ENODEV;
1353         for (i = 1; i <= core->board.num_frontends; i++) {
1354                 fe = videobuf_dvb_get_frontend(&core->dvbdev->frontends, i);
1355                 if (fe == NULL) {
1356                         printk(KERN_ERR "%s() failed to get frontend(%d)\n",
1357                                         __func__, i);
1358                         goto fail_probe;
1359                 }
1360                 videobuf_queue_sg_init(&fe->dvb.dvbq, &dvb_qops,
1361                                     &dev->pci->dev, &dev->slock,
1362                                     V4L2_BUF_TYPE_VIDEO_CAPTURE,
1363                                     V4L2_FIELD_TOP,
1364                                     sizeof(struct cx88_buffer),
1365                                     dev);
1366                 /* init struct videobuf_dvb */
1367                 fe->dvb.name = dev->core->name;
1368         }
1369
1370         err = dvb_register(dev);
1371         if (err)
1372                 /* frontends/adapter de-allocated in dvb_register */
1373                 printk(KERN_ERR "%s/2: dvb_register failed (err = %d)\n",
1374                        core->name, err);
1375         return err;
1376 fail_probe:
1377         videobuf_dvb_dealloc_frontends(&core->dvbdev->frontends);
1378 fail_core:
1379         return err;
1380 }
1381
1382 static int cx8802_dvb_remove(struct cx8802_driver *drv)
1383 {
1384         struct cx88_core *core = drv->core;
1385         struct cx8802_dev *dev = drv->core->dvbdev;
1386
1387         dprintk( 1, "%s\n", __func__);
1388
1389         videobuf_dvb_unregister_bus(&dev->frontends);
1390
1391         vp3054_i2c_remove(dev);
1392
1393         core->gate_ctrl = NULL;
1394
1395         return 0;
1396 }
1397
1398 static struct cx8802_driver cx8802_dvb_driver = {
1399         .type_id        = CX88_MPEG_DVB,
1400         .hw_access      = CX8802_DRVCTL_SHARED,
1401         .probe          = cx8802_dvb_probe,
1402         .remove         = cx8802_dvb_remove,
1403         .advise_acquire = cx8802_dvb_advise_acquire,
1404         .advise_release = cx8802_dvb_advise_release,
1405 };
1406
1407 static int __init dvb_init(void)
1408 {
1409         printk(KERN_INFO "cx88/2: cx2388x dvb driver version %d.%d.%d loaded\n",
1410                (CX88_VERSION_CODE >> 16) & 0xff,
1411                (CX88_VERSION_CODE >>  8) & 0xff,
1412                CX88_VERSION_CODE & 0xff);
1413 #ifdef SNAPSHOT
1414         printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
1415                SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
1416 #endif
1417         return cx8802_register_driver(&cx8802_dvb_driver);
1418 }
1419
1420 static void __exit dvb_fini(void)
1421 {
1422         cx8802_unregister_driver(&cx8802_dvb_driver);
1423 }
1424
1425 module_init(dvb_init);
1426 module_exit(dvb_fini);
1427
1428 /*
1429  * Local variables:
1430  * c-basic-offset: 8
1431  * compile-command: "make DVB=1"
1432  * End:
1433  */