3 * device driver for Conexant 2388x based TV cards
4 * MPEG Transport Stream (DVB) routines
6 * (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
7 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
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.
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.
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.
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/device.h>
28 #include <linux/kthread.h>
29 #include <linux/file.h>
30 #include <linux/suspend.h>
37 # include "mt352_priv.h"
38 # ifdef HAVE_VP3054_I2C
39 # include "cx88-vp3054-i2c.h"
49 # include "lgdt330x.h"
58 MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
59 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
60 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
61 MODULE_LICENSE("GPL");
63 static unsigned int debug = 0;
64 module_param(debug, int, 0644);
65 MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
67 #define dprintk(level,fmt, arg...) if (debug >= level) \
68 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg)
70 /* ------------------------------------------------------------------ */
72 static int dvb_buf_setup(struct videobuf_queue *q,
73 unsigned int *count, unsigned int *size)
75 struct cx8802_dev *dev = q->priv_data;
77 dev->ts_packet_size = 188 * 4;
78 dev->ts_packet_count = 32;
80 *size = dev->ts_packet_size * dev->ts_packet_count;
85 static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
86 enum v4l2_field field)
88 struct cx8802_dev *dev = q->priv_data;
89 return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb,field);
92 static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
94 struct cx8802_dev *dev = q->priv_data;
95 cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
98 static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
100 struct cx8802_dev *dev = q->priv_data;
101 cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb);
104 static struct videobuf_queue_ops dvb_qops = {
105 .buf_setup = dvb_buf_setup,
106 .buf_prepare = dvb_buf_prepare,
107 .buf_queue = dvb_buf_queue,
108 .buf_release = dvb_buf_release,
111 /* ------------------------------------------------------------------ */
114 static int generic_mt352_demod_init(struct dvb_frontend* fe)
116 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
117 static u8 reset [] = { RESET, 0x80 };
118 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
119 static u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };
120 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
121 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
123 mt352_write(fe, clock_config, sizeof(clock_config));
125 mt352_write(fe, reset, sizeof(reset));
126 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
128 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
129 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
130 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
134 static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
136 static u8 clock_config [] = { 0x89, 0x38, 0x39 };
137 static u8 reset [] = { 0x50, 0x80 };
138 static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
139 static u8 agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
140 0x00, 0xFF, 0x00, 0x40, 0x40 };
141 static u8 dntv_extra[] = { 0xB5, 0x7A };
142 static u8 capt_range_cfg[] = { 0x75, 0x32 };
144 mt352_write(fe, clock_config, sizeof(clock_config));
146 mt352_write(fe, reset, sizeof(reset));
147 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
149 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
151 mt352_write(fe, dntv_extra, sizeof(dntv_extra));
152 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
157 static int mt352_pll_set(struct dvb_frontend* fe,
158 struct dvb_frontend_parameters* params,
161 struct cx8802_dev *dev= fe->dvb->priv;
163 pllbuf[0] = dev->core->pll_addr << 1;
164 dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
166 params->u.ofdm.bandwidth);
170 static struct mt352_config dvico_fusionhdtv = {
171 .demod_address = 0x0F,
172 .demod_init = generic_mt352_demod_init,
173 .pll_set = mt352_pll_set,
176 static struct mt352_config dntv_live_dvbt_config = {
177 .demod_address = 0x0f,
178 .demod_init = dntv_live_dvbt_demod_init,
179 .pll_set = mt352_pll_set,
182 #ifdef HAVE_VP3054_I2C
183 static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
185 struct cx8802_dev *dev= fe->dvb->priv;
187 /* this message is to set up ATC and ALC */
188 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
190 { .addr = dev->core->pll_addr, .flags = 0,
191 .buf = fmd1216_init, .len = sizeof(fmd1216_init) };
194 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
204 static int dntv_live_dvbt_pro_pll_set(struct dvb_frontend* fe,
205 struct dvb_frontend_parameters* params,
208 struct cx8802_dev *dev= fe->dvb->priv;
210 { .addr = dev->core->pll_addr, .flags = 0,
211 .buf = pllbuf+1, .len = 4 };
214 /* Switch PLL to DVB mode */
215 err = philips_fmd1216_pll_init(fe);
220 pllbuf[0] = dev->core->pll_addr << 1;
221 dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
223 params->u.ofdm.bandwidth);
224 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
225 printk(KERN_WARNING "cx88-dvb: %s error "
226 "(addr %02x <- %02x, err = %i)\n",
227 __FUNCTION__, pllbuf[0], pllbuf[1], err);
237 static struct mt352_config dntv_live_dvbt_pro_config = {
238 .demod_address = 0x0f,
240 .demod_init = generic_mt352_demod_init,
241 .pll_set = dntv_live_dvbt_pro_pll_set,
247 static struct cx22702_config connexant_refboard_config = {
248 .demod_address = 0x43,
249 .output_mode = CX22702_SERIAL_OUTPUT,
251 .pll_desc = &dvb_pll_thomson_dtt7579,
254 static struct cx22702_config hauppauge_novat_config = {
255 .demod_address = 0x43,
256 .output_mode = CX22702_SERIAL_OUTPUT,
258 .pll_desc = &dvb_pll_thomson_dtt759x,
260 static struct cx22702_config hauppauge_hvr1100_config = {
261 .demod_address = 0x63,
262 .output_mode = CX22702_SERIAL_OUTPUT,
264 .pll_desc = &dvb_pll_fmd1216me,
269 static int or51132_set_ts_param(struct dvb_frontend* fe,
272 struct cx8802_dev *dev= fe->dvb->priv;
273 dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
277 static struct or51132_config pchdtv_hd3000 = {
278 .demod_address = 0x15,
280 .pll_desc = &dvb_pll_thomson_dtt7610,
281 .set_ts_params = or51132_set_ts_param,
286 static int lgdt330x_pll_set(struct dvb_frontend* fe,
287 struct dvb_frontend_parameters* params)
289 /* FIXME make this routine use the tuner-simple code.
290 * It could probably be shared with a number of ATSC
291 * frontends. Many share the same tuner with analog TV. */
293 struct cx8802_dev *dev= fe->dvb->priv;
294 struct cx88_core *core = dev->core;
297 { .addr = dev->core->pll_addr, .flags = 0, .buf = buf, .len = 4 };
300 /* Put the analog decoder in standby to keep it quiet */
301 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
303 dvb_pll_configure(core->pll_desc, buf, params->frequency, 0);
304 dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",
305 __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]);
306 if ((err = i2c_transfer(&core->i2c_adap, &msg, 1)) != 1) {
307 printk(KERN_WARNING "cx88-dvb: %s error "
308 "(addr %02x <- %02x, err = %i)\n",
309 __FUNCTION__, buf[0], buf[1], err);
315 if (core->tuner_type == TUNER_LG_TDVS_H062F) {
316 /* Set the Auxiliary Byte. */
320 i2c_transfer(&core->i2c_adap, &msg, 1);
325 static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
327 struct cx8802_dev *dev= fe->dvb->priv;
328 struct cx88_core *core = dev->core;
330 dprintk(1, "%s: index = %d\n", __FUNCTION__, index);
332 cx_clear(MO_GP0_IO, 8);
334 cx_set(MO_GP0_IO, 8);
338 static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
340 struct cx8802_dev *dev= fe->dvb->priv;
342 dev->ts_gen_cntrl |= 0x04;
344 dev->ts_gen_cntrl &= ~0x04;
348 static struct lgdt330x_config fusionhdtv_3_gold = {
349 .demod_address = 0x0e,
350 .demod_chip = LGDT3302,
351 .serial_mpeg = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
352 .pll_set = lgdt330x_pll_set,
353 .set_ts_params = lgdt330x_set_ts_param,
356 static struct lgdt330x_config fusionhdtv_5_gold = {
357 .demod_address = 0x0e,
358 .demod_chip = LGDT3303,
359 .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
360 .pll_set = lgdt330x_pll_set,
361 .set_ts_params = lgdt330x_set_ts_param,
366 static int nxt200x_set_ts_param(struct dvb_frontend* fe,
369 struct cx8802_dev *dev= fe->dvb->priv;
370 dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
374 static int nxt200x_set_pll_input(u8* buf, int input)
383 static struct nxt200x_config ati_hdtvwonder = {
384 .demod_address = 0x0a,
386 .pll_desc = &dvb_pll_tuv1236d,
387 .set_pll_input = nxt200x_set_pll_input,
388 .set_ts_params = nxt200x_set_ts_param,
393 static int cx24123_set_ts_param(struct dvb_frontend* fe,
396 struct cx8802_dev *dev= fe->dvb->priv;
397 dev->ts_gen_cntrl = 0x2;
401 static void cx24123_enable_lnb_voltage(struct dvb_frontend* fe, int on)
403 struct cx8802_dev *dev= fe->dvb->priv;
404 struct cx88_core *core = dev->core;
407 cx_write(MO_GP0_IO, 0x000006f9);
409 cx_write(MO_GP0_IO, 0x000006fB);
412 static struct cx24123_config hauppauge_novas_config = {
413 .demod_address = 0x55,
415 .set_ts_params = cx24123_set_ts_param,
418 static struct cx24123_config kworld_dvbs_100_config = {
419 .demod_address = 0x15,
421 .set_ts_params = cx24123_set_ts_param,
422 .enable_lnb_voltage = cx24123_enable_lnb_voltage,
426 static int dvb_register(struct cx8802_dev *dev)
428 /* init struct videobuf_dvb */
429 dev->dvb.name = dev->core->name;
430 dev->ts_gen_cntrl = 0x0c;
433 switch (dev->core->board) {
435 case CX88_BOARD_HAUPPAUGE_DVB_T1:
436 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
437 &dev->core->i2c_adap);
439 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
440 case CX88_BOARD_CONEXANT_DVB_T1:
441 case CX88_BOARD_WINFAST_DTV1000:
442 dev->dvb.frontend = cx22702_attach(&connexant_refboard_config,
443 &dev->core->i2c_adap);
445 case CX88_BOARD_HAUPPAUGE_HVR1100:
446 case CX88_BOARD_HAUPPAUGE_HVR1100LP:
447 dev->dvb.frontend = cx22702_attach(&hauppauge_hvr1100_config,
448 &dev->core->i2c_adap);
452 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
453 dev->core->pll_addr = 0x61;
454 dev->core->pll_desc = &dvb_pll_lg_z201;
455 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
456 &dev->core->i2c_adap);
458 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
459 dev->core->pll_addr = 0x60;
460 dev->core->pll_desc = &dvb_pll_thomson_dtt7579;
461 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
462 &dev->core->i2c_adap);
464 case CX88_BOARD_KWORLD_DVB_T:
465 case CX88_BOARD_DNTV_LIVE_DVB_T:
466 case CX88_BOARD_ADSTECH_DVB_T_PCI:
467 dev->core->pll_addr = 0x61;
468 dev->core->pll_desc = &dvb_pll_unknown_1;
469 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config,
470 &dev->core->i2c_adap);
472 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
473 #ifdef HAVE_VP3054_I2C
474 dev->core->pll_addr = 0x61;
475 dev->core->pll_desc = &dvb_pll_fmd1216me;
476 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_pro_config,
477 &((struct vp3054_i2c_state *)dev->card_priv)->adap);
479 printk("%s: built without vp3054 support\n", dev->core->name);
484 case CX88_BOARD_PCHDTV_HD3000:
485 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
486 &dev->core->i2c_adap);
490 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
491 dev->ts_gen_cntrl = 0x08;
493 /* Do a hardware reset of chip before using it. */
494 struct cx88_core *core = dev->core;
496 cx_clear(MO_GP0_IO, 1);
498 cx_set(MO_GP0_IO, 1);
501 /* Select RF connector callback */
502 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
503 dev->core->pll_addr = 0x61;
504 dev->core->pll_desc = &dvb_pll_microtune_4042;
505 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold,
506 &dev->core->i2c_adap);
509 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
510 dev->ts_gen_cntrl = 0x08;
512 /* Do a hardware reset of chip before using it. */
513 struct cx88_core *core = dev->core;
515 cx_clear(MO_GP0_IO, 1);
517 cx_set(MO_GP0_IO, 9);
519 dev->core->pll_addr = 0x61;
520 dev->core->pll_desc = &dvb_pll_thomson_dtt761x;
521 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold,
522 &dev->core->i2c_adap);
525 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
526 dev->ts_gen_cntrl = 0x08;
528 /* Do a hardware reset of chip before using it. */
529 struct cx88_core *core = dev->core;
531 cx_clear(MO_GP0_IO, 1);
533 cx_set(MO_GP0_IO, 1);
535 dev->core->pll_addr = 0x61;
536 dev->core->pll_desc = &dvb_pll_tdvs_tua6034;
537 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_5_gold,
538 &dev->core->i2c_adap);
543 case CX88_BOARD_ATI_HDTVWONDER:
544 dev->dvb.frontend = nxt200x_attach(&ati_hdtvwonder,
545 &dev->core->i2c_adap);
549 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
550 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
551 dev->dvb.frontend = cx24123_attach(&hauppauge_novas_config,
552 &dev->core->i2c_adap);
554 case CX88_BOARD_KWORLD_DVBS_100:
555 dev->dvb.frontend = cx24123_attach(&kworld_dvbs_100_config,
556 &dev->core->i2c_adap);
560 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
564 if (NULL == dev->dvb.frontend) {
565 printk("%s: frontend initialization failed\n",dev->core->name);
569 if (dev->core->pll_desc) {
570 dev->dvb.frontend->ops->info.frequency_min = dev->core->pll_desc->min;
571 dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max;
574 /* Put the analog decoder in standby to keep it quiet */
575 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
577 /* register everything */
578 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
581 /* ----------------------------------------------------------- */
583 static int __devinit dvb_probe(struct pci_dev *pci_dev,
584 const struct pci_device_id *pci_id)
586 struct cx8802_dev *dev;
587 struct cx88_core *core;
591 core = cx88_core_get(pci_dev);
596 if (!cx88_boards[core->board].dvb)
600 dev = kmalloc(sizeof(*dev),GFP_KERNEL);
603 memset(dev,0,sizeof(*dev));
607 err = cx8802_init_common(dev);
611 #ifdef HAVE_VP3054_I2C
612 err = vp3054_i2c_probe(dev);
618 printk("%s/2: cx2388x based dvb card\n", core->name);
619 videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops,
620 dev->pci, &dev->slock,
621 V4L2_BUF_TYPE_VIDEO_CAPTURE,
623 sizeof(struct cx88_buffer),
625 err = dvb_register(dev);
629 /* Maintain a reference to cx88-video can query the 8802 device. */
634 cx8802_fini_common(dev);
638 cx88_core_put(core,pci_dev);
642 static void __devexit dvb_remove(struct pci_dev *pci_dev)
644 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
646 /* Destroy any 8802 reference. */
647 dev->core->dvbdev = NULL;
650 videobuf_dvb_unregister(&dev->dvb);
652 #ifdef HAVE_VP3054_I2C
653 vp3054_i2c_remove(dev);
657 cx8802_fini_common(dev);
658 cx88_core_put(dev->core,dev->pci);
662 static struct pci_device_id cx8802_pci_tbl[] = {
666 .subvendor = PCI_ANY_ID,
667 .subdevice = PCI_ANY_ID,
669 /* --- end of list --- */
672 MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
674 static struct pci_driver dvb_pci_driver = {
676 .id_table = cx8802_pci_tbl,
678 .remove = __devexit_p(dvb_remove),
679 .suspend = cx8802_suspend_common,
680 .resume = cx8802_resume_common,
683 static int dvb_init(void)
685 printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n",
686 (CX88_VERSION_CODE >> 16) & 0xff,
687 (CX88_VERSION_CODE >> 8) & 0xff,
688 CX88_VERSION_CODE & 0xff);
690 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
691 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
693 return pci_register_driver(&dvb_pci_driver);
696 static void dvb_fini(void)
698 pci_unregister_driver(&dvb_pci_driver);
701 module_init(dvb_init);
702 module_exit(dvb_fini);
707 * compile-command: "make DVB=1"