blob: 5544e1d6a34491e909ad9c23aa04f741a2b274b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -07002 * $Id: cx88-dvb.c,v 1.41 2005/07/04 19:35:05 mkrufky Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * device driver for Conexant 2388x based TV cards
5 * MPEG Transport Stream (DVB) routines
6 *
7 * (c) 2004 Chris Pascoe <c.pascoe@itee.uq.edu.au>
8 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
9 *
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.
14 *
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.
19 *
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.
23 */
24
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/device.h>
28#include <linux/fs.h>
29#include <linux/kthread.h>
30#include <linux/file.h>
31#include <linux/suspend.h>
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "cx88.h"
34#include "dvb-pll.h"
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070035
36#if CONFIG_DVB_MT352
37# include "mt352.h"
38# include "mt352_priv.h"
39#endif
40#if CONFIG_DVB_CX22702
Linus Torvalds1da177e2005-04-16 15:20:36 -070041# include "cx22702.h"
42#endif
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070043#if CONFIG_DVB_OR51132
Linus Torvalds1da177e2005-04-16 15:20:36 -070044# include "or51132.h"
45#endif
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070046#if CONFIG_DVB_LGDT3302
Michael Krufkyf1798492005-07-07 17:58:39 -070047# include "lgdt3302.h"
48#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
51MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
52MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
53MODULE_LICENSE("GPL");
54
55static unsigned int debug = 0;
56module_param(debug, int, 0644);
57MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
58
59#define dprintk(level,fmt, arg...) if (debug >= level) \
60 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg)
61
62/* ------------------------------------------------------------------ */
63
64static int dvb_buf_setup(struct videobuf_queue *q,
65 unsigned int *count, unsigned int *size)
66{
67 struct cx8802_dev *dev = q->priv_data;
68
69 dev->ts_packet_size = 188 * 4;
70 dev->ts_packet_count = 32;
71
72 *size = dev->ts_packet_size * dev->ts_packet_count;
73 *count = 32;
74 return 0;
75}
76
77static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
78 enum v4l2_field field)
79{
80 struct cx8802_dev *dev = q->priv_data;
81 return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb);
82}
83
84static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
85{
86 struct cx8802_dev *dev = q->priv_data;
87 cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
88}
89
90static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
91{
92 struct cx8802_dev *dev = q->priv_data;
93 cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb);
94}
95
Adrian Bunk408b6642005-05-01 08:59:29 -070096static struct videobuf_queue_ops dvb_qops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 .buf_setup = dvb_buf_setup,
98 .buf_prepare = dvb_buf_prepare,
99 .buf_queue = dvb_buf_queue,
100 .buf_release = dvb_buf_release,
101};
102
103/* ------------------------------------------------------------------ */
104
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700105#if CONFIG_DVB_MT352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
107{
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 };
114
115 mt352_write(fe, clock_config, sizeof(clock_config));
116 udelay(200);
117 mt352_write(fe, reset, sizeof(reset));
118 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
119
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));
123 return 0;
124}
125
126static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
127{
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 };
135
136 mt352_write(fe, clock_config, sizeof(clock_config));
137 udelay(2000);
138 mt352_write(fe, reset, sizeof(reset));
139 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
140
141 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
142 udelay(2000);
143 mt352_write(fe, dntv_extra, sizeof(dntv_extra));
144 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
145
146 return 0;
147}
148
149static int mt352_pll_set(struct dvb_frontend* fe,
150 struct dvb_frontend_parameters* params,
151 u8* pllbuf)
152{
153 struct cx8802_dev *dev= fe->dvb->priv;
154
155 pllbuf[0] = dev->core->pll_addr << 1;
156 dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
157 params->frequency,
158 params->u.ofdm.bandwidth);
159 return 0;
160}
161
162static struct mt352_config dvico_fusionhdtv = {
163 .demod_address = 0x0F,
164 .demod_init = dvico_fusionhdtv_demod_init,
165 .pll_set = mt352_pll_set,
166};
167
168static 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,
172};
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700173#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700175#if CONFIG_DVB_CX22702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static struct cx22702_config connexant_refboard_config = {
177 .demod_address = 0x43,
178 .pll_address = 0x60,
179 .pll_desc = &dvb_pll_thomson_dtt7579,
180};
181
182static struct cx22702_config hauppauge_novat_config = {
183 .demod_address = 0x43,
184 .pll_address = 0x61,
185 .pll_desc = &dvb_pll_thomson_dtt759x,
186};
187#endif
188
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700189#if CONFIG_DVB_OR51132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190static int or51132_set_ts_param(struct dvb_frontend* fe,
191 int is_punctured)
192{
193 struct cx8802_dev *dev= fe->dvb->priv;
194 dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
195 return 0;
196}
197
Adrian Bunk408b6642005-05-01 08:59:29 -0700198static struct or51132_config pchdtv_hd3000 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 .demod_address = 0x15,
200 .pll_address = 0x61,
201 .pll_desc = &dvb_pll_thomson_dtt7610,
202 .set_ts_params = or51132_set_ts_param,
203};
204#endif
205
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700206#if CONFIG_DVB_LGDT3302
Michael Krufkyf1798492005-07-07 17:58:39 -0700207static int lgdt3302_set_ts_param(struct dvb_frontend* fe, int is_punctured)
208{
209 struct cx8802_dev *dev= fe->dvb->priv;
210 if (is_punctured)
211 dev->ts_gen_cntrl |= 0x04;
212 else
213 dev->ts_gen_cntrl &= ~0x04;
214 return 0;
215}
216
217static struct lgdt3302_config fusionhdtv_3_gold_q = {
218 .demod_address = 0x0e,
219 .pll_address = 0x61,
220 .pll_desc = &dvb_pll_microtune_4042,
221 .set_ts_params = lgdt3302_set_ts_param,
222};
Michael Krufky0d723c02005-07-07 17:58:42 -0700223
224static struct lgdt3302_config fusionhdtv_3_gold_t = {
225 .demod_address = 0x0e,
226 .pll_address = 0x61,
227 .pll_desc = &dvb_pll_thomson_dtt7611,
228 .set_ts_params = lgdt3302_set_ts_param,
229};
Michael Krufkyf1798492005-07-07 17:58:39 -0700230#endif
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232static int dvb_register(struct cx8802_dev *dev)
233{
234 /* init struct videobuf_dvb */
235 dev->dvb.name = dev->core->name;
236 dev->ts_gen_cntrl = 0x0c;
237
238 /* init frontend */
239 switch (dev->core->board) {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700240#if CONFIG_DVB_CX22702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 case CX88_BOARD_HAUPPAUGE_DVB_T1:
242 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
243 &dev->core->i2c_adap);
244 break;
Michael Krufkye057ee12005-07-07 17:58:40 -0700245 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 case CX88_BOARD_CONEXANT_DVB_T1:
247 dev->dvb.frontend = cx22702_attach(&connexant_refboard_config,
248 &dev->core->i2c_adap);
249 break;
250#endif
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700251#if CONFIG_DVB_MT352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
253 dev->core->pll_addr = 0x61;
254 dev->core->pll_desc = &dvb_pll_lg_z201;
255 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
256 &dev->core->i2c_adap);
257 break;
258 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
259 dev->core->pll_addr = 0x60;
260 dev->core->pll_desc = &dvb_pll_thomson_dtt7579;
261 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
262 &dev->core->i2c_adap);
263 break;
264 case CX88_BOARD_KWORLD_DVB_T:
265 case CX88_BOARD_DNTV_LIVE_DVB_T:
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -0700266 case CX88_BOARD_ADSTECH_DVB_T_PCI:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 dev->core->pll_addr = 0x61;
268 dev->core->pll_desc = &dvb_pll_unknown_1;
269 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config,
270 &dev->core->i2c_adap);
271 break;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700272#endif
273#if CONFIG_DVB_OR51132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 case CX88_BOARD_PCHDTV_HD3000:
275 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
276 &dev->core->i2c_adap);
277 break;
278#endif
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700279#if CONFIG_DVB_LGDT3302
Michael Krufkyf1798492005-07-07 17:58:39 -0700280 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
281 dev->ts_gen_cntrl = 0x08;
282 {
283 /* Do a hardware reset of chip before using it. */
284 struct cx88_core *core = dev->core;
285
286 cx_clear(MO_GP0_IO, 1);
287 mdelay(100);
288 cx_set(MO_GP0_IO, 9); // ANT connector too FIXME
289 mdelay(200);
290 dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_q,
291 &dev->core->i2c_adap);
292 }
293 break;
Michael Krufky0d723c02005-07-07 17:58:42 -0700294 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
295 dev->ts_gen_cntrl = 0x08;
296 {
297 /* Do a hardware reset of chip before using it. */
298 struct cx88_core *core = dev->core;
299
300 cx_clear(MO_GP0_IO, 1);
301 mdelay(100);
302 cx_set(MO_GP0_IO, 9); /* ANT connector too FIXME */
303 mdelay(200);
304 dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_t,
305 &dev->core->i2c_adap);
306 }
307 break;
Michael Krufkyf1798492005-07-07 17:58:39 -0700308#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 default:
Gerd Knorr1622c3f2005-05-01 08:59:19 -0700310 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
311 dev->core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 break;
313 }
314 if (NULL == dev->dvb.frontend) {
315 printk("%s: frontend initialization failed\n",dev->core->name);
316 return -1;
317 }
318
319 if (dev->core->pll_desc) {
320 dev->dvb.frontend->ops->info.frequency_min = dev->core->pll_desc->min;
321 dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max;
322 }
323
324 /* Copy the board name into the DVB structure */
325 strlcpy(dev->dvb.frontend->ops->info.name,
326 cx88_boards[dev->core->board].name,
327 sizeof(dev->dvb.frontend->ops->info.name));
328
329 /* register everything */
330 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
331}
332
333/* ----------------------------------------------------------- */
334
335static int __devinit dvb_probe(struct pci_dev *pci_dev,
336 const struct pci_device_id *pci_id)
337{
338 struct cx8802_dev *dev;
339 struct cx88_core *core;
340 int err;
341
342 /* general setup */
343 core = cx88_core_get(pci_dev);
344 if (NULL == core)
345 return -EINVAL;
346
347 err = -ENODEV;
348 if (!cx88_boards[core->board].dvb)
349 goto fail_core;
350
351 err = -ENOMEM;
352 dev = kmalloc(sizeof(*dev),GFP_KERNEL);
353 if (NULL == dev)
354 goto fail_core;
355 memset(dev,0,sizeof(*dev));
356 dev->pci = pci_dev;
357 dev->core = core;
358
359 err = cx8802_init_common(dev);
360 if (0 != err)
361 goto fail_free;
362
363 /* dvb stuff */
364 printk("%s/2: cx2388x based dvb card\n", core->name);
365 videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops,
366 dev->pci, &dev->slock,
367 V4L2_BUF_TYPE_VIDEO_CAPTURE,
368 V4L2_FIELD_TOP,
369 sizeof(struct cx88_buffer),
370 dev);
371 err = dvb_register(dev);
372 if (0 != err)
Gerd Knorr1622c3f2005-05-01 08:59:19 -0700373 goto fail_fini;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 return 0;
375
Gerd Knorr1622c3f2005-05-01 08:59:19 -0700376 fail_fini:
377 cx8802_fini_common(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 fail_free:
379 kfree(dev);
380 fail_core:
381 cx88_core_put(core,pci_dev);
382 return err;
383}
384
385static void __devexit dvb_remove(struct pci_dev *pci_dev)
386{
387 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
388
389 /* dvb */
390 videobuf_dvb_unregister(&dev->dvb);
391
392 /* common */
393 cx8802_fini_common(dev);
394 cx88_core_put(dev->core,dev->pci);
395 kfree(dev);
396}
397
398static struct pci_device_id cx8802_pci_tbl[] = {
399 {
400 .vendor = 0x14f1,
401 .device = 0x8802,
402 .subvendor = PCI_ANY_ID,
403 .subdevice = PCI_ANY_ID,
404 },{
405 /* --- end of list --- */
406 }
407};
408MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
409
410static struct pci_driver dvb_pci_driver = {
411 .name = "cx88-dvb",
412 .id_table = cx8802_pci_tbl,
413 .probe = dvb_probe,
414 .remove = __devexit_p(dvb_remove),
415 .suspend = cx8802_suspend_common,
416 .resume = cx8802_resume_common,
417};
418
419static int dvb_init(void)
420{
421 printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n",
422 (CX88_VERSION_CODE >> 16) & 0xff,
423 (CX88_VERSION_CODE >> 8) & 0xff,
424 CX88_VERSION_CODE & 0xff);
425#ifdef SNAPSHOT
426 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
427 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
428#endif
429 return pci_register_driver(&dvb_pci_driver);
430}
431
432static void dvb_fini(void)
433{
434 pci_unregister_driver(&dvb_pci_driver);
435}
436
437module_init(dvb_init);
438module_exit(dvb_fini);
439
440/*
441 * Local variables:
442 * c-basic-offset: 8
443 * compile-command: "make DVB=1"
444 * End:
445 */