blob: 6ad1458ab652c02a5fe04935baa35108e3c0de68 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Mauro Carvalho Chehabc5287ba2005-07-15 03:56:28 -07002 * $Id: cx88-dvb.c,v 1.42 2005/07/12 15:44:55 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
Michael Krufky55ee3b82005-07-12 13:59:08 -070033#define CONFIG_DVB_MT352 1
34#define CONFIG_DVB_CX22702 1
35#define CONFIG_DVB_OR51132 1
36#define CONFIG_DVB_LGDT3302 1
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include "cx88.h"
39#include "dvb-pll.h"
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070040
41#if CONFIG_DVB_MT352
42# include "mt352.h"
43# include "mt352_priv.h"
44#endif
45#if CONFIG_DVB_CX22702
Linus Torvalds1da177e2005-04-16 15:20:36 -070046# include "cx22702.h"
47#endif
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070048#if CONFIG_DVB_OR51132
Linus Torvalds1da177e2005-04-16 15:20:36 -070049# include "or51132.h"
50#endif
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070051#if CONFIG_DVB_LGDT3302
Michael Krufkyf1798492005-07-07 17:58:39 -070052# include "lgdt3302.h"
53#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
56MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
57MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
58MODULE_LICENSE("GPL");
59
60static unsigned int debug = 0;
61module_param(debug, int, 0644);
62MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
63
64#define dprintk(level,fmt, arg...) if (debug >= level) \
65 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg)
66
67/* ------------------------------------------------------------------ */
68
69static int dvb_buf_setup(struct videobuf_queue *q,
70 unsigned int *count, unsigned int *size)
71{
72 struct cx8802_dev *dev = q->priv_data;
73
74 dev->ts_packet_size = 188 * 4;
75 dev->ts_packet_count = 32;
76
77 *size = dev->ts_packet_size * dev->ts_packet_count;
78 *count = 32;
79 return 0;
80}
81
82static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
83 enum v4l2_field field)
84{
85 struct cx8802_dev *dev = q->priv_data;
86 return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb);
87}
88
89static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
90{
91 struct cx8802_dev *dev = q->priv_data;
92 cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
93}
94
95static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
96{
97 struct cx8802_dev *dev = q->priv_data;
98 cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb);
99}
100
Adrian Bunk408b6642005-05-01 08:59:29 -0700101static struct videobuf_queue_ops dvb_qops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 .buf_setup = dvb_buf_setup,
103 .buf_prepare = dvb_buf_prepare,
104 .buf_queue = dvb_buf_queue,
105 .buf_release = dvb_buf_release,
106};
107
108/* ------------------------------------------------------------------ */
109
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700110#if CONFIG_DVB_MT352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
112{
113 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
114 static u8 reset [] = { RESET, 0x80 };
115 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
116 static u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };
117 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
118 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
119
120 mt352_write(fe, clock_config, sizeof(clock_config));
121 udelay(200);
122 mt352_write(fe, reset, sizeof(reset));
123 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
124
125 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
126 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
127 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
128 return 0;
129}
130
131static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
132{
133 static u8 clock_config [] = { 0x89, 0x38, 0x39 };
134 static u8 reset [] = { 0x50, 0x80 };
135 static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
136 static u8 agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
137 0x00, 0xFF, 0x00, 0x40, 0x40 };
138 static u8 dntv_extra[] = { 0xB5, 0x7A };
139 static u8 capt_range_cfg[] = { 0x75, 0x32 };
140
141 mt352_write(fe, clock_config, sizeof(clock_config));
142 udelay(2000);
143 mt352_write(fe, reset, sizeof(reset));
144 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
145
146 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
147 udelay(2000);
148 mt352_write(fe, dntv_extra, sizeof(dntv_extra));
149 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
150
151 return 0;
152}
153
154static int mt352_pll_set(struct dvb_frontend* fe,
155 struct dvb_frontend_parameters* params,
156 u8* pllbuf)
157{
158 struct cx8802_dev *dev= fe->dvb->priv;
159
160 pllbuf[0] = dev->core->pll_addr << 1;
161 dvb_pll_configure(dev->core->pll_desc, pllbuf+1,
162 params->frequency,
163 params->u.ofdm.bandwidth);
164 return 0;
165}
166
167static struct mt352_config dvico_fusionhdtv = {
168 .demod_address = 0x0F,
169 .demod_init = dvico_fusionhdtv_demod_init,
170 .pll_set = mt352_pll_set,
171};
172
173static struct mt352_config dntv_live_dvbt_config = {
174 .demod_address = 0x0f,
175 .demod_init = dntv_live_dvbt_demod_init,
176 .pll_set = mt352_pll_set,
177};
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700178#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700180#if CONFIG_DVB_CX22702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181static struct cx22702_config connexant_refboard_config = {
182 .demod_address = 0x43,
Patrick Boettcher38d84c32005-07-15 12:20:26 -0700183 .output_mode = CX22702_SERIAL_OUTPUT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 .pll_address = 0x60,
185 .pll_desc = &dvb_pll_thomson_dtt7579,
186};
187
188static struct cx22702_config hauppauge_novat_config = {
189 .demod_address = 0x43,
Patrick Boettcher38d84c32005-07-15 12:20:26 -0700190 .output_mode = CX22702_SERIAL_OUTPUT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 .pll_address = 0x61,
192 .pll_desc = &dvb_pll_thomson_dtt759x,
193};
194#endif
195
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700196#if CONFIG_DVB_OR51132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197static int or51132_set_ts_param(struct dvb_frontend* fe,
198 int is_punctured)
199{
200 struct cx8802_dev *dev= fe->dvb->priv;
201 dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
202 return 0;
203}
204
Adrian Bunk408b6642005-05-01 08:59:29 -0700205static struct or51132_config pchdtv_hd3000 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 .demod_address = 0x15,
207 .pll_address = 0x61,
208 .pll_desc = &dvb_pll_thomson_dtt7610,
209 .set_ts_params = or51132_set_ts_param,
210};
211#endif
212
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700213#if CONFIG_DVB_LGDT3302
Michael Krufkyf1798492005-07-07 17:58:39 -0700214static int lgdt3302_set_ts_param(struct dvb_frontend* fe, int is_punctured)
215{
216 struct cx8802_dev *dev= fe->dvb->priv;
217 if (is_punctured)
218 dev->ts_gen_cntrl |= 0x04;
219 else
220 dev->ts_gen_cntrl &= ~0x04;
221 return 0;
222}
223
224static struct lgdt3302_config fusionhdtv_3_gold_q = {
225 .demod_address = 0x0e,
226 .pll_address = 0x61,
227 .pll_desc = &dvb_pll_microtune_4042,
228 .set_ts_params = lgdt3302_set_ts_param,
229};
Michael Krufky0d723c02005-07-07 17:58:42 -0700230
231static struct lgdt3302_config fusionhdtv_3_gold_t = {
232 .demod_address = 0x0e,
233 .pll_address = 0x61,
234 .pll_desc = &dvb_pll_thomson_dtt7611,
235 .set_ts_params = lgdt3302_set_ts_param,
236};
Michael Krufkyf1798492005-07-07 17:58:39 -0700237#endif
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239static int dvb_register(struct cx8802_dev *dev)
240{
241 /* init struct videobuf_dvb */
242 dev->dvb.name = dev->core->name;
243 dev->ts_gen_cntrl = 0x0c;
244
245 /* init frontend */
246 switch (dev->core->board) {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700247#if CONFIG_DVB_CX22702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 case CX88_BOARD_HAUPPAUGE_DVB_T1:
249 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
250 &dev->core->i2c_adap);
251 break;
Michael Krufkye057ee12005-07-07 17:58:40 -0700252 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 case CX88_BOARD_CONEXANT_DVB_T1:
254 dev->dvb.frontend = cx22702_attach(&connexant_refboard_config,
255 &dev->core->i2c_adap);
256 break;
257#endif
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700258#if CONFIG_DVB_MT352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
260 dev->core->pll_addr = 0x61;
261 dev->core->pll_desc = &dvb_pll_lg_z201;
262 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
263 &dev->core->i2c_adap);
264 break;
265 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
266 dev->core->pll_addr = 0x60;
267 dev->core->pll_desc = &dvb_pll_thomson_dtt7579;
268 dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv,
269 &dev->core->i2c_adap);
270 break;
271 case CX88_BOARD_KWORLD_DVB_T:
272 case CX88_BOARD_DNTV_LIVE_DVB_T:
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -0700273 case CX88_BOARD_ADSTECH_DVB_T_PCI:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 dev->core->pll_addr = 0x61;
275 dev->core->pll_desc = &dvb_pll_unknown_1;
276 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config,
277 &dev->core->i2c_adap);
278 break;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700279#endif
280#if CONFIG_DVB_OR51132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 case CX88_BOARD_PCHDTV_HD3000:
282 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
283 &dev->core->i2c_adap);
284 break;
285#endif
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700286#if CONFIG_DVB_LGDT3302
Michael Krufkyf1798492005-07-07 17:58:39 -0700287 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
288 dev->ts_gen_cntrl = 0x08;
289 {
290 /* Do a hardware reset of chip before using it. */
291 struct cx88_core *core = dev->core;
292
293 cx_clear(MO_GP0_IO, 1);
294 mdelay(100);
295 cx_set(MO_GP0_IO, 9); // ANT connector too FIXME
296 mdelay(200);
297 dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_q,
298 &dev->core->i2c_adap);
299 }
300 break;
Michael Krufky0d723c02005-07-07 17:58:42 -0700301 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
302 dev->ts_gen_cntrl = 0x08;
303 {
304 /* Do a hardware reset of chip before using it. */
305 struct cx88_core *core = dev->core;
306
307 cx_clear(MO_GP0_IO, 1);
308 mdelay(100);
309 cx_set(MO_GP0_IO, 9); /* ANT connector too FIXME */
310 mdelay(200);
311 dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_t,
312 &dev->core->i2c_adap);
313 }
314 break;
Michael Krufkyf1798492005-07-07 17:58:39 -0700315#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 default:
Gerd Knorr1622c3f2005-05-01 08:59:19 -0700317 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
318 dev->core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 break;
320 }
321 if (NULL == dev->dvb.frontend) {
322 printk("%s: frontend initialization failed\n",dev->core->name);
323 return -1;
324 }
325
326 if (dev->core->pll_desc) {
327 dev->dvb.frontend->ops->info.frequency_min = dev->core->pll_desc->min;
328 dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max;
329 }
330
331 /* Copy the board name into the DVB structure */
332 strlcpy(dev->dvb.frontend->ops->info.name,
333 cx88_boards[dev->core->board].name,
334 sizeof(dev->dvb.frontend->ops->info.name));
335
336 /* register everything */
337 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
338}
339
340/* ----------------------------------------------------------- */
341
342static int __devinit dvb_probe(struct pci_dev *pci_dev,
343 const struct pci_device_id *pci_id)
344{
345 struct cx8802_dev *dev;
346 struct cx88_core *core;
347 int err;
348
349 /* general setup */
350 core = cx88_core_get(pci_dev);
351 if (NULL == core)
352 return -EINVAL;
353
354 err = -ENODEV;
355 if (!cx88_boards[core->board].dvb)
356 goto fail_core;
357
358 err = -ENOMEM;
359 dev = kmalloc(sizeof(*dev),GFP_KERNEL);
360 if (NULL == dev)
361 goto fail_core;
362 memset(dev,0,sizeof(*dev));
363 dev->pci = pci_dev;
364 dev->core = core;
365
366 err = cx8802_init_common(dev);
367 if (0 != err)
368 goto fail_free;
369
370 /* dvb stuff */
371 printk("%s/2: cx2388x based dvb card\n", core->name);
372 videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops,
373 dev->pci, &dev->slock,
374 V4L2_BUF_TYPE_VIDEO_CAPTURE,
375 V4L2_FIELD_TOP,
376 sizeof(struct cx88_buffer),
377 dev);
378 err = dvb_register(dev);
379 if (0 != err)
Gerd Knorr1622c3f2005-05-01 08:59:19 -0700380 goto fail_fini;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return 0;
382
Gerd Knorr1622c3f2005-05-01 08:59:19 -0700383 fail_fini:
384 cx8802_fini_common(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 fail_free:
386 kfree(dev);
387 fail_core:
388 cx88_core_put(core,pci_dev);
389 return err;
390}
391
392static void __devexit dvb_remove(struct pci_dev *pci_dev)
393{
394 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
395
396 /* dvb */
397 videobuf_dvb_unregister(&dev->dvb);
398
399 /* common */
400 cx8802_fini_common(dev);
401 cx88_core_put(dev->core,dev->pci);
402 kfree(dev);
403}
404
405static struct pci_device_id cx8802_pci_tbl[] = {
406 {
407 .vendor = 0x14f1,
408 .device = 0x8802,
409 .subvendor = PCI_ANY_ID,
410 .subdevice = PCI_ANY_ID,
411 },{
412 /* --- end of list --- */
413 }
414};
415MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
416
417static struct pci_driver dvb_pci_driver = {
418 .name = "cx88-dvb",
419 .id_table = cx8802_pci_tbl,
420 .probe = dvb_probe,
421 .remove = __devexit_p(dvb_remove),
422 .suspend = cx8802_suspend_common,
423 .resume = cx8802_resume_common,
424};
425
426static int dvb_init(void)
427{
428 printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n",
429 (CX88_VERSION_CODE >> 16) & 0xff,
430 (CX88_VERSION_CODE >> 8) & 0xff,
431 CX88_VERSION_CODE & 0xff);
432#ifdef SNAPSHOT
433 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
434 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
435#endif
436 return pci_register_driver(&dvb_pci_driver);
437}
438
439static void dvb_fini(void)
440{
441 pci_unregister_driver(&dvb_pci_driver);
442}
443
444module_init(dvb_init);
445module_exit(dvb_fini);
446
447/*
448 * Local variables:
449 * c-basic-offset: 8
450 * compile-command: "make DVB=1"
451 * End:
452 */