3 * device driver for Conexant 2388x based TV cards
4 * MPEG Transport Stream (DVB) routines
6 * (c) 2004 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>
38 # include "mt352_priv.h"
47 # include "lgdt330x.h"
50 MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
51 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
52 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
53 MODULE_LICENSE("GPL");
55 static unsigned int debug
= 0;
56 module_param(debug
, int, 0644);
57 MODULE_PARM_DESC(debug
,"enable debug messages [dvb]");
59 #define dprintk(level,fmt, arg...) if (debug >= level) \
60 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg)
62 /* ------------------------------------------------------------------ */
64 static int dvb_buf_setup(struct videobuf_queue
*q
,
65 unsigned int *count
, unsigned int *size
)
67 struct cx8802_dev
*dev
= q
->priv_data
;
69 dev
->ts_packet_size
= 188 * 4;
70 dev
->ts_packet_count
= 32;
72 *size
= dev
->ts_packet_size
* dev
->ts_packet_count
;
77 static int dvb_buf_prepare(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
,
78 enum v4l2_field field
)
80 struct cx8802_dev
*dev
= q
->priv_data
;
81 return cx8802_buf_prepare(dev
, (struct cx88_buffer
*)vb
,field
);
84 static void dvb_buf_queue(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
86 struct cx8802_dev
*dev
= q
->priv_data
;
87 cx8802_buf_queue(dev
, (struct cx88_buffer
*)vb
);
90 static void dvb_buf_release(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
92 struct cx8802_dev
*dev
= q
->priv_data
;
93 cx88_free_buffer(dev
->pci
, (struct cx88_buffer
*)vb
);
96 static struct videobuf_queue_ops dvb_qops
= {
97 .buf_setup
= dvb_buf_setup
,
98 .buf_prepare
= dvb_buf_prepare
,
99 .buf_queue
= dvb_buf_queue
,
100 .buf_release
= dvb_buf_release
,
103 /* ------------------------------------------------------------------ */
106 static int dvico_fusionhdtv_demod_init(struct dvb_frontend
* fe
)
108 static u8 clock_config
[] = { CLOCK_CTL
, 0x38, 0x39 };
109 static u8 reset
[] = { RESET
, 0x80 };
110 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
111 static u8 agc_cfg
[] = { AGC_TARGET
, 0x24, 0x20 };
112 static u8 gpp_ctl_cfg
[] = { GPP_CTL
, 0x33 };
113 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x32 };
115 mt352_write(fe
, clock_config
, sizeof(clock_config
));
117 mt352_write(fe
, reset
, sizeof(reset
));
118 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
120 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
121 mt352_write(fe
, gpp_ctl_cfg
, sizeof(gpp_ctl_cfg
));
122 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
126 static int dntv_live_dvbt_demod_init(struct dvb_frontend
* fe
)
128 static u8 clock_config
[] = { 0x89, 0x38, 0x39 };
129 static u8 reset
[] = { 0x50, 0x80 };
130 static u8 adc_ctl_1_cfg
[] = { 0x8E, 0x40 };
131 static u8 agc_cfg
[] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
132 0x00, 0xFF, 0x00, 0x40, 0x40 };
133 static u8 dntv_extra
[] = { 0xB5, 0x7A };
134 static u8 capt_range_cfg
[] = { 0x75, 0x32 };
136 mt352_write(fe
, clock_config
, sizeof(clock_config
));
138 mt352_write(fe
, reset
, sizeof(reset
));
139 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
141 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
143 mt352_write(fe
, dntv_extra
, sizeof(dntv_extra
));
144 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
149 static int mt352_pll_set(struct dvb_frontend
* fe
,
150 struct dvb_frontend_parameters
* params
,
153 struct cx8802_dev
*dev
= fe
->dvb
->priv
;
155 pllbuf
[0] = dev
->core
->pll_addr
<< 1;
156 dvb_pll_configure(dev
->core
->pll_desc
, pllbuf
+1,
158 params
->u
.ofdm
.bandwidth
);
162 static struct mt352_config dvico_fusionhdtv
= {
163 .demod_address
= 0x0F,
164 .demod_init
= dvico_fusionhdtv_demod_init
,
165 .pll_set
= mt352_pll_set
,
168 static struct mt352_config dntv_live_dvbt_config
= {
169 .demod_address
= 0x0f,
170 .demod_init
= dntv_live_dvbt_demod_init
,
171 .pll_set
= mt352_pll_set
,
176 static struct cx22702_config connexant_refboard_config
= {
177 .demod_address
= 0x43,
178 .output_mode
= CX22702_SERIAL_OUTPUT
,
180 .pll_desc
= &dvb_pll_thomson_dtt7579
,
183 static struct cx22702_config hauppauge_novat_config
= {
184 .demod_address
= 0x43,
185 .output_mode
= CX22702_SERIAL_OUTPUT
,
187 .pll_desc
= &dvb_pll_thomson_dtt759x
,
192 static int or51132_set_ts_param(struct dvb_frontend
* fe
,
195 struct cx8802_dev
*dev
= fe
->dvb
->priv
;
196 dev
->ts_gen_cntrl
= is_punctured
? 0x04 : 0x00;
200 static struct or51132_config pchdtv_hd3000
= {
201 .demod_address
= 0x15,
203 .pll_desc
= &dvb_pll_thomson_dtt7610
,
204 .set_ts_params
= or51132_set_ts_param
,
209 static int lgdt330x_pll_set(struct dvb_frontend
* fe
,
210 struct dvb_frontend_parameters
* params
)
212 /* FIXME make this routine use the tuner-simple code.
213 * It could probably be shared with a number of ATSC
214 * frontends. Many share the same tuner with analog TV. */
216 struct cx8802_dev
*dev
= fe
->dvb
->priv
;
217 struct cx88_core
*core
= dev
->core
;
220 { .addr
= dev
->core
->pll_addr
, .flags
= 0, .buf
= buf
, .len
= 4 };
223 /* Put the analog decoder in standby to keep it quiet */
224 cx88_call_i2c_clients (dev
->core
, TUNER_SET_STANDBY
, NULL
);
226 dvb_pll_configure(core
->pll_desc
, buf
, params
->frequency
, 0);
227 dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",
228 __FUNCTION__
, msg
.addr
, buf
[0],buf
[1],buf
[2],buf
[3]);
229 if ((err
= i2c_transfer(&core
->i2c_adap
, &msg
, 1)) != 1) {
230 printk(KERN_WARNING
"cx88-dvb: %s error "
231 "(addr %02x <- %02x, err = %i)\n",
232 __FUNCTION__
, buf
[0], buf
[1], err
);
238 if (core
->tuner_type
== TUNER_LG_TDVS_H062F
) {
239 /* Set the Auxiliary Byte. */
243 i2c_transfer(&core
->i2c_adap
, &msg
, 1);
248 static int lgdt330x_pll_rf_set(struct dvb_frontend
* fe
, int index
)
250 struct cx8802_dev
*dev
= fe
->dvb
->priv
;
251 struct cx88_core
*core
= dev
->core
;
253 dprintk(1, "%s: index = %d\n", __FUNCTION__
, index
);
255 cx_clear(MO_GP0_IO
, 8);
257 cx_set(MO_GP0_IO
, 8);
261 static int lgdt330x_set_ts_param(struct dvb_frontend
* fe
, int is_punctured
)
263 struct cx8802_dev
*dev
= fe
->dvb
->priv
;
265 dev
->ts_gen_cntrl
|= 0x04;
267 dev
->ts_gen_cntrl
&= ~0x04;
271 static struct lgdt330x_config fusionhdtv_3_gold
= {
272 .demod_address
= 0x0e,
273 .demod_chip
= LGDT3302
,
274 .serial_mpeg
= 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
275 .pll_set
= lgdt330x_pll_set
,
276 .set_ts_params
= lgdt330x_set_ts_param
,
279 static struct lgdt330x_config fusionhdtv_5_gold
= {
280 .demod_address
= 0x0e,
281 .demod_chip
= LGDT3303
,
282 .serial_mpeg
= 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
283 .pll_set
= lgdt330x_pll_set
,
284 .set_ts_params
= lgdt330x_set_ts_param
,
288 static int dvb_register(struct cx8802_dev
*dev
)
290 /* init struct videobuf_dvb */
291 dev
->dvb
.name
= dev
->core
->name
;
292 dev
->ts_gen_cntrl
= 0x0c;
295 switch (dev
->core
->board
) {
297 case CX88_BOARD_HAUPPAUGE_DVB_T1
:
298 dev
->dvb
.frontend
= cx22702_attach(&hauppauge_novat_config
,
299 &dev
->core
->i2c_adap
);
301 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1
:
302 case CX88_BOARD_CONEXANT_DVB_T1
:
303 dev
->dvb
.frontend
= cx22702_attach(&connexant_refboard_config
,
304 &dev
->core
->i2c_adap
);
308 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1
:
309 dev
->core
->pll_addr
= 0x61;
310 dev
->core
->pll_desc
= &dvb_pll_lg_z201
;
311 dev
->dvb
.frontend
= mt352_attach(&dvico_fusionhdtv
,
312 &dev
->core
->i2c_adap
);
314 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS
:
315 dev
->core
->pll_addr
= 0x60;
316 dev
->core
->pll_desc
= &dvb_pll_thomson_dtt7579
;
317 dev
->dvb
.frontend
= mt352_attach(&dvico_fusionhdtv
,
318 &dev
->core
->i2c_adap
);
320 case CX88_BOARD_KWORLD_DVB_T
:
321 case CX88_BOARD_DNTV_LIVE_DVB_T
:
322 case CX88_BOARD_ADSTECH_DVB_T_PCI
:
323 dev
->core
->pll_addr
= 0x61;
324 dev
->core
->pll_desc
= &dvb_pll_unknown_1
;
325 dev
->dvb
.frontend
= mt352_attach(&dntv_live_dvbt_config
,
326 &dev
->core
->i2c_adap
);
330 case CX88_BOARD_PCHDTV_HD3000
:
331 dev
->dvb
.frontend
= or51132_attach(&pchdtv_hd3000
,
332 &dev
->core
->i2c_adap
);
336 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q
:
337 dev
->ts_gen_cntrl
= 0x08;
339 /* Do a hardware reset of chip before using it. */
340 struct cx88_core
*core
= dev
->core
;
342 cx_clear(MO_GP0_IO
, 1);
344 cx_set(MO_GP0_IO
, 1);
347 /* Select RF connector callback */
348 fusionhdtv_3_gold
.pll_rf_set
= lgdt330x_pll_rf_set
;
349 dev
->core
->pll_addr
= 0x61;
350 dev
->core
->pll_desc
= &dvb_pll_microtune_4042
;
351 dev
->dvb
.frontend
= lgdt330x_attach(&fusionhdtv_3_gold
,
352 &dev
->core
->i2c_adap
);
355 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T
:
356 dev
->ts_gen_cntrl
= 0x08;
358 /* Do a hardware reset of chip before using it. */
359 struct cx88_core
*core
= dev
->core
;
361 cx_clear(MO_GP0_IO
, 1);
363 cx_set(MO_GP0_IO
, 9);
365 dev
->core
->pll_addr
= 0x61;
366 dev
->core
->pll_desc
= &dvb_pll_thomson_dtt7611
;
367 dev
->dvb
.frontend
= lgdt330x_attach(&fusionhdtv_3_gold
,
368 &dev
->core
->i2c_adap
);
371 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD
:
372 dev
->ts_gen_cntrl
= 0x08;
374 /* Do a hardware reset of chip before using it. */
375 struct cx88_core
*core
= dev
->core
;
377 cx_clear(MO_GP0_IO
, 1);
379 cx_set(MO_GP0_IO
, 1);
381 dev
->core
->pll_addr
= 0x61;
382 dev
->core
->pll_desc
= &dvb_pll_tdvs_tua6034
;
383 dev
->dvb
.frontend
= lgdt330x_attach(&fusionhdtv_5_gold
,
384 &dev
->core
->i2c_adap
);
389 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
393 if (NULL
== dev
->dvb
.frontend
) {
394 printk("%s: frontend initialization failed\n",dev
->core
->name
);
398 if (dev
->core
->pll_desc
) {
399 dev
->dvb
.frontend
->ops
->info
.frequency_min
= dev
->core
->pll_desc
->min
;
400 dev
->dvb
.frontend
->ops
->info
.frequency_max
= dev
->core
->pll_desc
->max
;
403 /* Put the analog decoder in standby to keep it quiet */
404 cx88_call_i2c_clients (dev
->core
, TUNER_SET_STANDBY
, NULL
);
406 /* register everything */
407 return videobuf_dvb_register(&dev
->dvb
, THIS_MODULE
, dev
);
410 /* ----------------------------------------------------------- */
412 static int __devinit
dvb_probe(struct pci_dev
*pci_dev
,
413 const struct pci_device_id
*pci_id
)
415 struct cx8802_dev
*dev
;
416 struct cx88_core
*core
;
420 core
= cx88_core_get(pci_dev
);
425 if (!cx88_boards
[core
->board
].dvb
)
429 dev
= kmalloc(sizeof(*dev
),GFP_KERNEL
);
432 memset(dev
,0,sizeof(*dev
));
436 err
= cx8802_init_common(dev
);
441 printk("%s/2: cx2388x based dvb card\n", core
->name
);
442 videobuf_queue_init(&dev
->dvb
.dvbq
, &dvb_qops
,
443 dev
->pci
, &dev
->slock
,
444 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
446 sizeof(struct cx88_buffer
),
448 err
= dvb_register(dev
);
454 cx8802_fini_common(dev
);
458 cx88_core_put(core
,pci_dev
);
462 static void __devexit
dvb_remove(struct pci_dev
*pci_dev
)
464 struct cx8802_dev
*dev
= pci_get_drvdata(pci_dev
);
467 videobuf_dvb_unregister(&dev
->dvb
);
470 cx8802_fini_common(dev
);
471 cx88_core_put(dev
->core
,dev
->pci
);
475 static struct pci_device_id cx8802_pci_tbl
[] = {
479 .subvendor
= PCI_ANY_ID
,
480 .subdevice
= PCI_ANY_ID
,
482 /* --- end of list --- */
485 MODULE_DEVICE_TABLE(pci
, cx8802_pci_tbl
);
487 static struct pci_driver dvb_pci_driver
= {
489 .id_table
= cx8802_pci_tbl
,
491 .remove
= __devexit_p(dvb_remove
),
492 .suspend
= cx8802_suspend_common
,
493 .resume
= cx8802_resume_common
,
496 static int dvb_init(void)
498 printk(KERN_INFO
"cx2388x dvb driver version %d.%d.%d loaded\n",
499 (CX88_VERSION_CODE
>> 16) & 0xff,
500 (CX88_VERSION_CODE
>> 8) & 0xff,
501 CX88_VERSION_CODE
& 0xff);
503 printk(KERN_INFO
"cx2388x: snapshot date %04d-%02d-%02d\n",
504 SNAPSHOT
/10000, (SNAPSHOT
/100)%100, SNAPSHOT
%100);
506 return pci_register_driver(&dvb_pci_driver
);
509 static void dvb_fini(void)
511 pci_unregister_driver(&dvb_pci_driver
);
514 module_init(dvb_init
);
515 module_exit(dvb_fini
);
520 * compile-command: "make DVB=1"