2 * $Id: cx88-dvb.c,v 1.39 2005/07/02 20:00:46 mkrufky Exp $
4 * device driver for Conexant 2388x based TV cards
5 * MPEG Transport Stream (DVB) routines
7 * (c) 2004 Chris Pascoe <c.pascoe@itee.uq.edu.au>
8 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/device.h>
29 #include <linux/kthread.h>
30 #include <linux/file.h>
31 #include <linux/suspend.h>
33 /* these three frontends need merging via linuxtv cvs ... */
34 #define HAVE_CX22702 1
35 #define HAVE_OR51132 1
36 #define HAVE_LGDT3302 1
41 #include "mt352_priv.h"
49 # include "lgdt3302.h"
52 MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
53 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
54 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
55 MODULE_LICENSE("GPL");
57 static unsigned int debug = 0;
58 module_param(debug, int, 0644);
59 MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
61 #define dprintk(level,fmt, arg...) if (debug >= level) \
62 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg)
64 /* ------------------------------------------------------------------ */
66 static int dvb_buf_setup(struct videobuf_queue *q,
67 unsigned int *count, unsigned int *size)
69 struct cx8802_dev *dev = q->priv_data;
71 dev->ts_packet_size = 188 * 4;
72 dev->ts_packet_count = 32;
74 *size = dev->ts_packet_size * dev->ts_packet_count;
79 static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
80 enum v4l2_field field)
82 struct cx8802_dev *dev = q->priv_data;
83 return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb);
86 static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
88 struct cx8802_dev *dev = q->priv_data;
89 cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
92 static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
94 struct cx8802_dev *dev = q->priv_data;
95 cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb);
98 static struct videobuf_queue_ops dvb_qops = {
99 .buf_setup = dvb_buf_setup,
100 .buf_prepare = dvb_buf_prepare,
101 .buf_queue = dvb_buf_queue,
102 .buf_release = dvb_buf_release,
105 /* ------------------------------------------------------------------ */
107 static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
109 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
110 static u8 reset [] = { RESET, 0x80 };
111 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
112 static u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };
113 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
114 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
116 mt352_write(fe, clock_config, sizeof(clock_config));
118 mt352_write(fe, reset, sizeof(reset));
119 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
121 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
122 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
123 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
127 static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
129 static u8 clock_config [] = { 0x89, 0x38, 0x39 };
130 static u8 reset [] = { 0x50, 0x80 };
131 static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
132 static u8 agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
133 0x00, 0xFF, 0x00, 0x40, 0x40 };
134 static u8 dntv_extra[] = { 0xB5, 0x7A };
135 static u8 capt_range_cfg[] = { 0x75, 0x32 };
137 mt352_write(fe, clock_config, sizeof(clock_config));
139 mt352_write(fe, reset, sizeof(reset));
140 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
142 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
144 mt352_write(fe, dntv_extra, sizeof(dntv_extra));
145 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
150 static int mt352_pll_set(struct dvb_frontend* fe,
151 struct dvb_frontend_parameters* params,
154 struct cx8802_dev *dev= fe->dvb->priv;
156 pllbuf[0] = dev->core->pll_addr << 1;
157 dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
159 params->u.ofdm.bandwidth);
163 static struct mt352_config dvico_fusionhdtv = {
164 .demod_address = 0x0F,
165 .demod_init = dvico_fusionhdtv_demod_init,
166 .pll_set = mt352_pll_set,
169 static struct mt352_config dntv_live_dvbt_config = {
170 .demod_address = 0x0f,
171 .demod_init = dntv_live_dvbt_demod_init,
172 .pll_set = mt352_pll_set,
176 static struct cx22702_config connexant_refboard_config = {
177 .demod_address = 0x43,
179 .pll_desc = &dvb_pll_thomson_dtt7579,
182 static struct cx22702_config hauppauge_novat_config = {
183 .demod_address = 0x43,
185 .pll_desc = &dvb_pll_thomson_dtt759x,
190 static int or51132_set_ts_param(struct dvb_frontend* fe,
193 struct cx8802_dev *dev= fe->dvb->priv;
194 dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
198 static struct or51132_config pchdtv_hd3000 = {
199 .demod_address = 0x15,
201 .pll_desc = &dvb_pll_thomson_dtt7610,
202 .set_ts_params = or51132_set_ts_param,
207 static int lgdt3302_set_ts_param(struct dvb_frontend* fe, int is_punctured)
209 struct cx8802_dev *dev= fe->dvb->priv;
211 dev->ts_gen_cntrl |= 0x04;
213 dev->ts_gen_cntrl &= ~0x04;
217 static struct lgdt3302_config fusionhdtv_3_gold_q = {
218 .demod_address = 0x0e,
220 .pll_desc = &dvb_pll_microtune_4042,
221 .set_ts_params = lgdt3302_set_ts_param,
225 static int dvb_register(struct cx8802_dev *dev)
227 /* init struct videobuf_dvb */
228 dev->dvb.name = dev->core->name;
229 dev->ts_gen_cntrl = 0x0c;
232 switch (dev->core->board) {
234 case CX88_BOARD_HAUPPAUGE_DVB_T1:
235 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
236 &dev->core->i2c_adap);
238 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
239 case CX88_BOARD_CONEXANT_DVB_T1:
240 dev->dvb.frontend = cx22702_attach(&connexant_refboard_config,
241 &dev->core->i2c_adap);
244 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
245 dev->core->pll_addr = 0x61;
246 dev->core->pll_desc = &dvb_pll_lg_z201;
247 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
248 &dev->core->i2c_adap);
250 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
251 dev->core->pll_addr = 0x60;
252 dev->core->pll_desc = &dvb_pll_thomson_dtt7579;
253 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
254 &dev->core->i2c_adap);
256 case CX88_BOARD_KWORLD_DVB_T:
257 case CX88_BOARD_DNTV_LIVE_DVB_T:
258 case CX88_BOARD_ADSTECH_DVB_T_PCI:
259 dev->core->pll_addr = 0x61;
260 dev->core->pll_desc = &dvb_pll_unknown_1;
261 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config,
262 &dev->core->i2c_adap);
265 case CX88_BOARD_PCHDTV_HD3000:
266 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
267 &dev->core->i2c_adap);
271 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
272 dev->ts_gen_cntrl = 0x08;
274 /* Do a hardware reset of chip before using it. */
275 struct cx88_core *core = dev->core;
277 cx_clear(MO_GP0_IO, 1);
279 cx_set(MO_GP0_IO, 9); // ANT connector too FIXME
281 dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_q,
282 &dev->core->i2c_adap);
287 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
291 if (NULL == dev->dvb.frontend) {
292 printk("%s: frontend initialization failed\n",dev->core->name);
296 if (dev->core->pll_desc) {
297 dev->dvb.frontend->ops->info.frequency_min = dev->core->pll_desc->min;
298 dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max;
301 /* Copy the board name into the DVB structure */
302 strlcpy(dev->dvb.frontend->ops->info.name,
303 cx88_boards[dev->core->board].name,
304 sizeof(dev->dvb.frontend->ops->info.name));
306 /* register everything */
307 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
310 /* ----------------------------------------------------------- */
312 static int __devinit dvb_probe(struct pci_dev *pci_dev,
313 const struct pci_device_id *pci_id)
315 struct cx8802_dev *dev;
316 struct cx88_core *core;
320 core = cx88_core_get(pci_dev);
325 if (!cx88_boards[core->board].dvb)
329 dev = kmalloc(sizeof(*dev),GFP_KERNEL);
332 memset(dev,0,sizeof(*dev));
336 err = cx8802_init_common(dev);
341 printk("%s/2: cx2388x based dvb card\n", core->name);
342 videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops,
343 dev->pci, &dev->slock,
344 V4L2_BUF_TYPE_VIDEO_CAPTURE,
346 sizeof(struct cx88_buffer),
348 err = dvb_register(dev);
354 cx8802_fini_common(dev);
358 cx88_core_put(core,pci_dev);
362 static void __devexit dvb_remove(struct pci_dev *pci_dev)
364 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
367 videobuf_dvb_unregister(&dev->dvb);
370 cx8802_fini_common(dev);
371 cx88_core_put(dev->core,dev->pci);
375 static struct pci_device_id cx8802_pci_tbl[] = {
379 .subvendor = PCI_ANY_ID,
380 .subdevice = PCI_ANY_ID,
382 /* --- end of list --- */
385 MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
387 static struct pci_driver dvb_pci_driver = {
389 .id_table = cx8802_pci_tbl,
391 .remove = __devexit_p(dvb_remove),
392 .suspend = cx8802_suspend_common,
393 .resume = cx8802_resume_common,
396 static int dvb_init(void)
398 printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n",
399 (CX88_VERSION_CODE >> 16) & 0xff,
400 (CX88_VERSION_CODE >> 8) & 0xff,
401 CX88_VERSION_CODE & 0xff);
403 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
404 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
406 return pci_register_driver(&dvb_pci_driver);
409 static void dvb_fini(void)
411 pci_unregister_driver(&dvb_pci_driver);
414 module_init(dvb_init);
415 module_exit(dvb_fini);
420 * compile-command: "make DVB=1"