[PATCH] dvb: fix sparse warnings
[linux-2.6] / drivers / media / video / saa7134 / saa7134-dvb.c
1 /*
2  *
3  * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
4  *
5  *  Extended 3 / 2005 by Hartmut Hackmann to support various
6  *  cards with the tda10046 DVB-T channel decoder
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <linux/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/delay.h>
29 #include <linux/kthread.h>
30 #include <linux/suspend.h>
31
32
33 #include "saa7134-reg.h"
34 #include "saa7134.h"
35
36 #ifdef HAVE_MT352
37 # include "mt352.h"
38 # include "mt352_priv.h" /* FIXME */
39 #endif
40 #ifdef HAVE_TDA1004X
41 # include "tda1004x.h"
42 #endif
43
44 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
45 MODULE_LICENSE("GPL");
46
47 static unsigned int antenna_pwr = 0;
48
49 module_param(antenna_pwr, int, 0444);
50 MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
51
52 /* ------------------------------------------------------------------ */
53
54 #ifdef HAVE_MT352
55 static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
56 {
57         u32 ok;
58
59         if (!on) {
60                 saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));
61                 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
62                 return 0;
63         }
64
65         saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));
66         saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));
67         udelay(10);
68
69         saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 28));
70         saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
71         udelay(10);
72         saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 28));
73         udelay(10);
74         ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
75         printk("%s: %s %s\n", dev->name, __FUNCTION__,
76                ok ? "on" : "off");
77
78         if (!ok)
79                 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));
80         return ok;
81 }
82
83 static int mt352_pinnacle_init(struct dvb_frontend* fe)
84 {
85         static u8 clock_config []  = { CLOCK_CTL,  0x3d, 0x28 };
86         static u8 reset []         = { RESET,      0x80 };
87         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
88         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };
89         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
90         static u8 fsm_ctl_cfg[]    = { 0x7b,       0x04 };
91         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x0f };
92         static u8 scan_ctl_cfg []  = { SCAN_CTL,   0x0d };
93         static u8 irq_cfg []       = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
94         struct saa7134_dev *dev= fe->dvb->priv;
95
96         printk("%s: %s called\n",dev->name,__FUNCTION__);
97
98         mt352_write(fe, clock_config,   sizeof(clock_config));
99         udelay(200);
100         mt352_write(fe, reset,          sizeof(reset));
101         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
102         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
103         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
104         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
105
106         mt352_write(fe, fsm_ctl_cfg,    sizeof(fsm_ctl_cfg));
107         mt352_write(fe, scan_ctl_cfg,   sizeof(scan_ctl_cfg));
108         mt352_write(fe, irq_cfg,        sizeof(irq_cfg));
109         return 0;
110 }
111
112 static int mt352_pinnacle_pll_set(struct dvb_frontend* fe,
113                                   struct dvb_frontend_parameters* params,
114                                   u8* pllbuf)
115 {
116         static int on  = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
117         static int off = TDA9887_PRESENT | TDA9887_PORT2_ACTIVE;
118         struct saa7134_dev *dev = fe->dvb->priv;
119         struct v4l2_frequency f;
120
121         /* set frequency (mt2050) */
122         f.tuner     = 0;
123         f.type      = V4L2_TUNER_DIGITAL_TV;
124         f.frequency = params->frequency / 1000 * 16 / 1000;
125         saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
126         saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
127         saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&off);
128
129         pinnacle_antenna_pwr(dev, antenna_pwr);
130
131         /* mt352 setup */
132         mt352_pinnacle_init(fe);
133         pllbuf[0] = 0xc2;
134         pllbuf[1] = 0x00;
135         pllbuf[2] = 0x00;
136         pllbuf[3] = 0x80;
137         pllbuf[4] = 0x00;
138         return 0;
139 }
140
141 static struct mt352_config pinnacle_300i = {
142         .demod_address = 0x3c >> 1,
143         .adc_clock     = 20333,
144         .if2           = 36150,
145         .no_tuner      = 1,
146         .demod_init    = mt352_pinnacle_init,
147         .pll_set       = mt352_pinnacle_pll_set,
148 };
149 #endif
150
151 /* ------------------------------------------------------------------ */
152
153 #ifdef HAVE_TDA1004X
154 static int philips_tu1216_pll_init(struct dvb_frontend *fe)
155 {
156         struct saa7134_dev *dev = fe->dvb->priv;
157         static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
158         struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
159
160         /* setup PLL configuration */
161         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
162                 return -EIO;
163         msleep(1);
164
165         return 0;
166 }
167
168 static int philips_tu1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
169 {
170         struct saa7134_dev *dev = fe->dvb->priv;
171         u8 tuner_buf[4];
172         struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,.len =
173                         sizeof(tuner_buf) };
174         int tuner_frequency = 0;
175         u8 band, cp, filter;
176
177         /* determine charge pump */
178         tuner_frequency = params->frequency + 36166000;
179         if (tuner_frequency < 87000000)
180                 return -EINVAL;
181         else if (tuner_frequency < 130000000)
182                 cp = 3;
183         else if (tuner_frequency < 160000000)
184                 cp = 5;
185         else if (tuner_frequency < 200000000)
186                 cp = 6;
187         else if (tuner_frequency < 290000000)
188                 cp = 3;
189         else if (tuner_frequency < 420000000)
190                 cp = 5;
191         else if (tuner_frequency < 480000000)
192                 cp = 6;
193         else if (tuner_frequency < 620000000)
194                 cp = 3;
195         else if (tuner_frequency < 830000000)
196                 cp = 5;
197         else if (tuner_frequency < 895000000)
198                 cp = 7;
199         else
200                 return -EINVAL;
201
202         /* determine band */
203         if (params->frequency < 49000000)
204                 return -EINVAL;
205         else if (params->frequency < 161000000)
206                 band = 1;
207         else if (params->frequency < 444000000)
208                 band = 2;
209         else if (params->frequency < 861000000)
210                 band = 4;
211         else
212                 return -EINVAL;
213
214         /* setup PLL filter */
215         switch (params->u.ofdm.bandwidth) {
216         case BANDWIDTH_6_MHZ:
217                 filter = 0;
218                 break;
219
220         case BANDWIDTH_7_MHZ:
221                 filter = 0;
222                 break;
223
224         case BANDWIDTH_8_MHZ:
225                 filter = 1;
226                 break;
227
228         default:
229                 return -EINVAL;
230         }
231
232         /* calculate divisor
233          * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
234          */
235         tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
236
237         /* setup tuner buffer */
238         tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
239         tuner_buf[1] = tuner_frequency & 0xff;
240         tuner_buf[2] = 0xca;
241         tuner_buf[3] = (cp << 5) | (filter << 3) | band;
242
243         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
244                 return -EIO;
245
246         msleep(1);
247         return 0;
248 }
249
250 static int philips_tu1216_request_firmware(struct dvb_frontend *fe,
251                                            const struct firmware **fw, char *name)
252 {
253         struct saa7134_dev *dev = fe->dvb->priv;
254         return request_firmware(fw, name, &dev->pci->dev);
255 }
256
257 static struct tda1004x_config philips_tu1216_config = {
258
259         .demod_address = 0x8,
260         .invert        = 1,
261         .invert_oclk   = 1,
262         .xtal_freq     = TDA10046_XTAL_4M,
263         .agc_config    = TDA10046_AGC_DEFAULT,
264         .if_freq       = TDA10046_FREQ_3617,
265         .pll_init      = philips_tu1216_pll_init,
266         .pll_set       = philips_tu1216_pll_set,
267         .pll_sleep     = NULL,
268         .request_firmware = philips_tu1216_request_firmware,
269 };
270
271 /* ------------------------------------------------------------------ */
272
273
274 static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
275 {
276         struct saa7134_dev *dev = fe->dvb->priv;
277         /* this message is to set up ATC and ALC */
278         static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
279         struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
280
281         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
282                 return -EIO;
283         msleep(1);
284
285         return 0;
286 }
287
288 static void philips_fmd1216_analog(struct dvb_frontend *fe)
289 {
290         struct saa7134_dev *dev = fe->dvb->priv;
291         /* this message actually turns the tuner back to analog mode */
292         static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
293         struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
294
295         i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
296         msleep(1);
297         fmd1216_init[2] = 0x86;
298         fmd1216_init[3] = 0x54;
299         i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
300         msleep(1);
301 }
302
303 static int philips_fmd1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
304 {
305         struct saa7134_dev *dev = fe->dvb->priv;
306         u8 tuner_buf[4];
307         struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = tuner_buf,.len =
308                         sizeof(tuner_buf) };
309         int tuner_frequency = 0;
310         int divider = 0;
311         u8 band, mode, cp;
312
313         /* determine charge pump */
314         tuner_frequency = params->frequency + 36130000;
315         if (tuner_frequency < 87000000)
316                 return -EINVAL;
317         /* low band */
318         else if (tuner_frequency < 180000000) {
319                 band = 1;
320                 mode = 7;
321                 cp   = 0;
322         } else if (tuner_frequency < 195000000) {
323                 band = 1;
324                 mode = 6;
325                 cp   = 1;
326         /* mid band     */
327         } else if (tuner_frequency < 366000000) {
328                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
329                         band = 10;
330                 } else {
331                         band = 2;
332                 }
333                 mode = 7;
334                 cp   = 0;
335         } else if (tuner_frequency < 478000000) {
336                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
337                         band = 10;
338                 } else {
339                         band = 2;
340                 }
341                 mode = 6;
342                 cp   = 1;
343         /* high band */
344         } else if (tuner_frequency < 662000000) {
345                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
346                         band = 12;
347                 } else {
348                         band = 4;
349                 }
350                 mode = 7;
351                 cp   = 0;
352         } else if (tuner_frequency < 840000000) {
353                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
354                         band = 12;
355                 } else {
356                         band = 4;
357                 }
358                 mode = 6;
359                 cp   = 1;
360         } else {
361                 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
362                         band = 12;
363                 } else {
364                         band = 4;
365                 }
366                 mode = 7;
367                 cp   = 1;
368
369         }
370         /* calculate divisor */
371         /* ((36166000 + Finput) / 166666) rounded! */
372         divider = (tuner_frequency + 83333) / 166667;
373
374         /* setup tuner buffer */
375         tuner_buf[0] = (divider >> 8) & 0x7f;
376         tuner_buf[1] = divider & 0xff;
377         tuner_buf[2] = 0x80 | (cp << 6) | (mode  << 3) | 4;
378         tuner_buf[3] = 0x40 | band;
379
380         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
381                 return -EIO;
382         return 0;
383 }
384
385 #ifdef HAVE_TDA1004X
386 static struct tda1004x_config medion_cardbus = {
387         .demod_address = 0x08,
388         .invert        = 1,
389         .invert_oclk   = 0,
390         .xtal_freq     = TDA10046_XTAL_16M,
391         .agc_config    = TDA10046_AGC_IFO_AUTO_NEG,
392         .if_freq       = TDA10046_FREQ_3613,
393         .pll_init      = philips_fmd1216_pll_init,
394         .pll_set       = philips_fmd1216_pll_set,
395         .pll_sleep         = philips_fmd1216_analog,
396         .request_firmware = NULL,
397 };
398 #endif
399
400 /* ------------------------------------------------------------------ */
401
402 struct tda827x_data {
403         u32 lomax;
404         u8  spd;
405         u8  bs;
406         u8  bp;
407         u8  cp;
408         u8  gc3;
409         u8 div1p5;
410 };
411
412 static struct tda827x_data tda827x_dvbt[] = {
413         { .lomax =  62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
414         { .lomax =  66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
415         { .lomax =  76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
416         { .lomax =  84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
417         { .lomax =  93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
418         { .lomax =  98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
419         { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
420         { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
421         { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
422         { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
423         { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
424         { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
425         { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
426         { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
427         { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
428         { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
429         { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
430         { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
431         { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
432         { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
433         { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
434         { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
435         { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
436         { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
437         { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
438         { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
439         { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
440         { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
441         { .lomax =         0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
442 };
443
444 static int philips_tda827x_pll_init(struct dvb_frontend *fe)
445 {
446         return 0;
447 }
448
449 static int philips_tda827x_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
450 {
451         struct saa7134_dev *dev = fe->dvb->priv;
452         u8 tuner_buf[14];
453
454         struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,
455                                         .len = sizeof(tuner_buf) };
456         int i, tuner_freq, if_freq;
457         u32 N;
458         switch (params->u.ofdm.bandwidth) {
459         case BANDWIDTH_6_MHZ:
460                 if_freq = 4000000;
461                 break;
462         case BANDWIDTH_7_MHZ:
463                 if_freq = 4500000;
464                 break;
465         default:                   /* 8 MHz or Auto */
466                 if_freq = 5000000;
467                 break;
468         }
469         tuner_freq = params->frequency + if_freq;
470
471         i = 0;
472         while (tda827x_dvbt[i].lomax < tuner_freq) {
473                 if(tda827x_dvbt[i + 1].lomax == 0)
474                         break;
475                 i++;
476         }
477
478         N = ((tuner_freq + 125000) / 250000) << (tda827x_dvbt[i].spd + 2);
479         tuner_buf[0] = 0;
480         tuner_buf[1] = (N>>8) | 0x40;
481         tuner_buf[2] = N & 0xff;
482         tuner_buf[3] = 0;
483         tuner_buf[4] = 0x52;
484         tuner_buf[5] = (tda827x_dvbt[i].spd << 6) + (tda827x_dvbt[i].div1p5 << 5) +
485                                    (tda827x_dvbt[i].bs << 3) + tda827x_dvbt[i].bp;
486         tuner_buf[6] = (tda827x_dvbt[i].gc3 << 4) + 0x8f;
487         tuner_buf[7] = 0xbf;
488         tuner_buf[8] = 0x2a;
489         tuner_buf[9] = 0x05;
490         tuner_buf[10] = 0xff;
491         tuner_buf[11] = 0x00;
492         tuner_buf[12] = 0x00;
493         tuner_buf[13] = 0x40;
494
495         tuner_msg.len = 14;
496         if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
497                 return -EIO;
498
499         msleep(500);
500         /* correct CP value */
501         tuner_buf[0] = 0x30;
502         tuner_buf[1] = 0x50 + tda827x_dvbt[i].cp;
503         tuner_msg.len = 2;
504         i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
505
506         return 0;
507 }
508
509 static void philips_tda827x_pll_sleep(struct dvb_frontend *fe)
510 {
511         struct saa7134_dev *dev = fe->dvb->priv;
512         static u8 tda827x_sleep[] = { 0x30, 0xd0};
513         struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tda827x_sleep,
514                                     .len = sizeof(tda827x_sleep) };
515         i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
516 }
517
518 static struct tda1004x_config tda827x_lifeview_config = {
519         .demod_address = 0x08,
520         .invert        = 1,
521         .invert_oclk   = 0,
522         .xtal_freq     = TDA10046_XTAL_16M,
523         .agc_config    = TDA10046_AGC_TDA827X,
524         .if_freq       = TDA10046_FREQ_045,
525         .pll_init      = philips_tda827x_pll_init,
526         .pll_set       = philips_tda827x_pll_set,
527         .pll_sleep         = philips_tda827x_pll_sleep,
528         .request_firmware = NULL,
529 };
530 #endif
531
532 /* ------------------------------------------------------------------ */
533
534 static int dvb_init(struct saa7134_dev *dev)
535 {
536         /* init struct videobuf_dvb */
537         dev->ts.nr_bufs    = 32;
538         dev->ts.nr_packets = 32*4;
539         dev->dvb.name = dev->name;
540         videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
541                             dev->pci, &dev->slock,
542                             V4L2_BUF_TYPE_VIDEO_CAPTURE,
543                             V4L2_FIELD_ALTERNATE,
544                             sizeof(struct saa7134_buf),
545                             dev);
546
547         switch (dev->board) {
548 #ifdef HAVE_MT352
549         case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
550                 printk("%s: pinnacle 300i dvb setup\n",dev->name);
551                 dev->dvb.frontend = mt352_attach(&pinnacle_300i,
552                                                  &dev->i2c_adap);
553                 break;
554 #endif
555 #ifdef HAVE_TDA1004X
556         case SAA7134_BOARD_MD7134:
557                 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
558                                                     &dev->i2c_adap);
559                 break;
560         case SAA7134_BOARD_PHILIPS_TOUGH:
561                 dev->dvb.frontend = tda10046_attach(&philips_tu1216_config,
562                                                     &dev->i2c_adap);
563                 break;
564         case SAA7134_BOARD_FLYDVBTDUO:
565                 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
566                                                     &dev->i2c_adap);
567                 break;
568         case SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS:
569                 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
570                                                     &dev->i2c_adap);
571                 break;
572 #endif
573         default:
574                 printk("%s: Huh? unknown DVB card?\n",dev->name);
575                 break;
576         }
577
578         if (NULL == dev->dvb.frontend) {
579                 printk("%s: frontend initialization failed\n",dev->name);
580                 return -1;
581         }
582
583         /* register everything else */
584         return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
585 }
586
587 static int dvb_fini(struct saa7134_dev *dev)
588 {
589         static int on  = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
590
591         switch (dev->board) {
592         case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
593                 /* otherwise we don't detect the tuner on next insmod */
594                 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
595                 break;
596         };
597         videobuf_dvb_unregister(&dev->dvb);
598         return 0;
599 }
600
601 static struct saa7134_mpeg_ops dvb_ops = {
602         .type          = SAA7134_MPEG_DVB,
603         .init          = dvb_init,
604         .fini          = dvb_fini,
605 };
606
607 static int __init dvb_register(void)
608 {
609         return saa7134_ts_register(&dvb_ops);
610 }
611
612 static void __exit dvb_unregister(void)
613 {
614         saa7134_ts_unregister(&dvb_ops);
615 }
616
617 module_init(dvb_register);
618 module_exit(dvb_unregister);
619
620 /* ------------------------------------------------------------------ */
621 /*
622  * Local variables:
623  * c-basic-offset: 8
624  * End:
625  */