2 * Driver for the Conexant CX23885 PCIe bridge
4 * Copyright (c) 2006 Steven Toth <stoth@linuxtv.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/device.h>
26 #include <linux/kthread.h>
27 #include <linux/file.h>
28 #include <linux/suspend.h>
31 #include <media/v4l2-common.h>
41 #include "tuner-xc2028.h"
42 #include "tuner-simple.h"
44 #include "dibx000_common.h"
47 static unsigned int debug;
49 #define dprintk(level, fmt, arg...)\
50 do { if (debug >= level)\
51 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
54 /* ------------------------------------------------------------------ */
56 static unsigned int alt_tuner;
57 module_param(alt_tuner, int, 0644);
58 MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
60 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
62 /* ------------------------------------------------------------------ */
64 static int dvb_buf_setup(struct videobuf_queue *q,
65 unsigned int *count, unsigned int *size)
67 struct cx23885_tsport *port = q->priv_data;
69 port->ts_packet_size = 188 * 4;
70 port->ts_packet_count = 32;
72 *size = port->ts_packet_size * port->ts_packet_count;
77 static int dvb_buf_prepare(struct videobuf_queue *q,
78 struct videobuf_buffer *vb, enum v4l2_field field)
80 struct cx23885_tsport *port = q->priv_data;
81 return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
84 static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
86 struct cx23885_tsport *port = q->priv_data;
87 cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
90 static void dvb_buf_release(struct videobuf_queue *q,
91 struct videobuf_buffer *vb)
93 cx23885_free_buffer(q, (struct cx23885_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 static struct s5h1409_config hauppauge_generic_config = {
104 .demod_address = 0x32 >> 1,
105 .output_mode = S5H1409_SERIAL_OUTPUT,
106 .gpio = S5H1409_GPIO_ON,
108 .inversion = S5H1409_INVERSION_OFF,
109 .status_mode = S5H1409_DEMODLOCKING,
110 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
113 static struct tda10048_config hauppauge_hvr1200_config = {
114 .demod_address = 0x10 >> 1,
115 .output_mode = TDA10048_SERIAL_OUTPUT,
116 .fwbulkwritelen = TDA10048_BULKWRITE_200,
117 .inversion = TDA10048_INVERSION_ON
120 static struct s5h1409_config hauppauge_ezqam_config = {
121 .demod_address = 0x32 >> 1,
122 .output_mode = S5H1409_SERIAL_OUTPUT,
123 .gpio = S5H1409_GPIO_OFF,
125 .inversion = S5H1409_INVERSION_ON,
126 .status_mode = S5H1409_DEMODLOCKING,
127 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
130 static struct s5h1409_config hauppauge_hvr1800lp_config = {
131 .demod_address = 0x32 >> 1,
132 .output_mode = S5H1409_SERIAL_OUTPUT,
133 .gpio = S5H1409_GPIO_OFF,
135 .inversion = S5H1409_INVERSION_OFF,
136 .status_mode = S5H1409_DEMODLOCKING,
137 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
140 static struct s5h1409_config hauppauge_hvr1500_config = {
141 .demod_address = 0x32 >> 1,
142 .output_mode = S5H1409_SERIAL_OUTPUT,
143 .gpio = S5H1409_GPIO_OFF,
144 .inversion = S5H1409_INVERSION_OFF,
145 .status_mode = S5H1409_DEMODLOCKING,
146 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
149 static struct mt2131_config hauppauge_generic_tunerconfig = {
153 static struct lgdt330x_config fusionhdtv_5_express = {
154 .demod_address = 0x0e,
155 .demod_chip = LGDT3303,
159 static struct s5h1409_config hauppauge_hvr1500q_config = {
160 .demod_address = 0x32 >> 1,
161 .output_mode = S5H1409_SERIAL_OUTPUT,
162 .gpio = S5H1409_GPIO_ON,
164 .inversion = S5H1409_INVERSION_OFF,
165 .status_mode = S5H1409_DEMODLOCKING,
166 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
169 static struct s5h1409_config dvico_s5h1409_config = {
170 .demod_address = 0x32 >> 1,
171 .output_mode = S5H1409_SERIAL_OUTPUT,
172 .gpio = S5H1409_GPIO_ON,
174 .inversion = S5H1409_INVERSION_OFF,
175 .status_mode = S5H1409_DEMODLOCKING,
176 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
179 static struct s5h1411_config dvico_s5h1411_config = {
180 .output_mode = S5H1411_SERIAL_OUTPUT,
181 .gpio = S5H1411_GPIO_ON,
182 .qam_if = S5H1411_IF_44000,
183 .vsb_if = S5H1411_IF_44000,
184 .inversion = S5H1411_INVERSION_OFF,
185 .status_mode = S5H1411_DEMODLOCKING,
186 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
189 static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
194 static struct xc5000_config dvico_xc5000_tunerconfig = {
199 static struct tda829x_config tda829x_no_probe = {
200 .probe_tuner = TDA829X_DONT_PROBE,
203 static struct tda18271_std_map hauppauge_tda18271_std_map = {
204 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
205 .if_lvl = 6, .rfagc_top = 0x37 },
206 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
207 .if_lvl = 6, .rfagc_top = 0x37 },
210 static struct tda18271_config hauppauge_tda18271_config = {
211 .std_map = &hauppauge_tda18271_std_map,
212 .gate = TDA18271_GATE_ANALOG,
215 static struct tda18271_config hauppauge_hvr1200_tuner_config = {
216 .gate = TDA18271_GATE_ANALOG,
219 static struct dibx000_agc_config xc3028_agc_config = {
220 BAND_VHF | BAND_UHF, /* band_caps */
222 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
223 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
224 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
225 * P_agc_nb_est=2, P_agc_write=0
227 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
228 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
231 21, /* time_stabiliz */
243 39718, /* agc2_max */
252 29, /* agc2_slope1 */
253 29, /* agc2_slope2 */
260 1, /* perform_agc_softsplit */
263 /* PLL Configuration for COFDM BW_MHz = 8.000000
264 * With external clock = 30.000000 */
265 static struct dibx000_bandwidth_config xc3028_bw_config = {
266 60000, /* internal */
267 30000, /* sampling */
268 1, /* pll_cfg: prediv */
269 8, /* pll_cfg: ratio */
270 3, /* pll_cfg: range */
271 1, /* pll_cfg: reset */
272 0, /* pll_cfg: bypass */
273 0, /* misc: refdiv */
274 0, /* misc: bypclk_div */
275 1, /* misc: IO_CLK_en_core */
276 1, /* misc: ADClkSrc */
277 0, /* misc: modulo */
278 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
279 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
281 30000000 /* xtal_hz */
284 static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
285 .output_mpeg2_in_188_bytes = 1,
286 .hostbus_diversity = 1,
287 .tuner_is_baseband = 0,
290 .agc_config_count = 1,
291 .agc = &xc3028_agc_config,
292 .bw = &xc3028_bw_config,
294 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
295 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
296 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
302 .output_mode = OUTMODE_MPEG2_SERIAL,
305 static struct zl10353_config dvico_fusionhdtv_xc3028 = {
306 .demod_address = 0x0f,
311 static int dvb_register(struct cx23885_tsport *port)
313 struct cx23885_dev *dev = port->dev;
314 struct cx23885_i2c *i2c_bus = NULL;
315 struct videobuf_dvb_frontend *fe0;
317 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
321 /* init struct videobuf_dvb */
322 fe0->dvb.name = dev->name;
325 switch (dev->board) {
326 case CX23885_BOARD_HAUPPAUGE_HVR1250:
327 i2c_bus = &dev->i2c_bus[0];
328 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
329 &hauppauge_generic_config,
331 if (fe0->dvb.frontend != NULL) {
332 dvb_attach(mt2131_attach, fe0->dvb.frontend,
334 &hauppauge_generic_tunerconfig, 0);
337 case CX23885_BOARD_HAUPPAUGE_HVR1800:
338 i2c_bus = &dev->i2c_bus[0];
342 dvb_attach(s5h1409_attach,
343 &hauppauge_ezqam_config,
345 if (fe0->dvb.frontend != NULL) {
346 dvb_attach(tda829x_attach, fe0->dvb.frontend,
347 &dev->i2c_bus[1].i2c_adap, 0x42,
349 dvb_attach(tda18271_attach, fe0->dvb.frontend,
350 0x60, &dev->i2c_bus[1].i2c_adap,
351 &hauppauge_tda18271_config);
357 dvb_attach(s5h1409_attach,
358 &hauppauge_generic_config,
360 if (fe0->dvb.frontend != NULL)
361 dvb_attach(mt2131_attach, fe0->dvb.frontend,
363 &hauppauge_generic_tunerconfig, 0);
367 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
368 i2c_bus = &dev->i2c_bus[0];
369 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
370 &hauppauge_hvr1800lp_config,
372 if (fe0->dvb.frontend != NULL) {
373 dvb_attach(mt2131_attach, fe0->dvb.frontend,
375 &hauppauge_generic_tunerconfig, 0);
378 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
379 i2c_bus = &dev->i2c_bus[0];
380 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
381 &fusionhdtv_5_express,
383 if (fe0->dvb.frontend != NULL) {
384 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
385 &i2c_bus->i2c_adap, 0x61,
386 TUNER_LG_TDVS_H06XF);
389 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
390 i2c_bus = &dev->i2c_bus[1];
391 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
392 &hauppauge_hvr1500q_config,
393 &dev->i2c_bus[0].i2c_adap);
394 if (fe0->dvb.frontend != NULL)
395 dvb_attach(xc5000_attach, fe0->dvb.frontend,
397 &hauppauge_hvr1500q_tunerconfig);
399 case CX23885_BOARD_HAUPPAUGE_HVR1500:
400 i2c_bus = &dev->i2c_bus[1];
401 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
402 &hauppauge_hvr1500_config,
403 &dev->i2c_bus[0].i2c_adap);
404 if (fe0->dvb.frontend != NULL) {
405 struct dvb_frontend *fe;
406 struct xc2028_config cfg = {
407 .i2c_adap = &i2c_bus->i2c_adap,
410 static struct xc2028_ctrl ctl = {
411 .fname = XC2028_DEFAULT_FIRMWARE,
413 .scode_table = XC3028_FE_OREN538,
416 fe = dvb_attach(xc2028_attach,
417 fe0->dvb.frontend, &cfg);
418 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
419 fe->ops.tuner_ops.set_config(fe, &ctl);
422 case CX23885_BOARD_HAUPPAUGE_HVR1200:
423 case CX23885_BOARD_HAUPPAUGE_HVR1700:
424 i2c_bus = &dev->i2c_bus[0];
425 fe0->dvb.frontend = dvb_attach(tda10048_attach,
426 &hauppauge_hvr1200_config,
428 if (fe0->dvb.frontend != NULL) {
429 dvb_attach(tda829x_attach, fe0->dvb.frontend,
430 &dev->i2c_bus[1].i2c_adap, 0x42,
432 dvb_attach(tda18271_attach, fe0->dvb.frontend,
433 0x60, &dev->i2c_bus[1].i2c_adap,
434 &hauppauge_hvr1200_tuner_config);
437 case CX23885_BOARD_HAUPPAUGE_HVR1400:
438 i2c_bus = &dev->i2c_bus[0];
439 fe0->dvb.frontend = dvb_attach(dib7000p_attach,
441 0x12, &hauppauge_hvr1400_dib7000_config);
442 if (fe0->dvb.frontend != NULL) {
443 struct dvb_frontend *fe;
444 struct xc2028_config cfg = {
445 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
448 static struct xc2028_ctrl ctl = {
449 .fname = XC3028L_DEFAULT_FIRMWARE,
452 /* This is true for all demods with v36 firmware? */
453 .type = XC2028_D2633,
456 fe = dvb_attach(xc2028_attach,
457 fe0->dvb.frontend, &cfg);
458 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
459 fe->ops.tuner_ops.set_config(fe, &ctl);
462 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
463 i2c_bus = &dev->i2c_bus[port->nr - 1];
465 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
466 &dvico_s5h1409_config,
468 if (fe0->dvb.frontend == NULL)
469 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
470 &dvico_s5h1411_config,
472 if (fe0->dvb.frontend != NULL)
473 dvb_attach(xc5000_attach, fe0->dvb.frontend,
475 &dvico_xc5000_tunerconfig);
477 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
478 i2c_bus = &dev->i2c_bus[port->nr - 1];
480 fe0->dvb.frontend = dvb_attach(zl10353_attach,
481 &dvico_fusionhdtv_xc3028,
483 if (fe0->dvb.frontend != NULL) {
484 struct dvb_frontend *fe;
485 struct xc2028_config cfg = {
486 .i2c_adap = &i2c_bus->i2c_adap,
489 static struct xc2028_ctrl ctl = {
490 .fname = XC2028_DEFAULT_FIRMWARE,
492 .demod = XC3028_FE_ZARLINK456,
495 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
497 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
498 fe->ops.tuner_ops.set_config(fe, &ctl);
502 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
503 i2c_bus = &dev->i2c_bus[0];
505 fe0->dvb.frontend = dvb_attach(zl10353_attach,
506 &dvico_fusionhdtv_xc3028,
508 if (fe0->dvb.frontend != NULL) {
509 struct dvb_frontend *fe;
510 struct xc2028_config cfg = {
511 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
514 static struct xc2028_ctrl ctl = {
515 .fname = XC2028_DEFAULT_FIRMWARE,
517 .demod = XC3028_FE_ZARLINK456,
520 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
522 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
523 fe->ops.tuner_ops.set_config(fe, &ctl);
527 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
531 if (NULL == fe0->dvb.frontend) {
532 printk("%s: frontend initialization failed\n", dev->name);
535 /* define general-purpose callback pointer */
536 fe0->dvb.frontend->callback = cx23885_tuner_callback;
538 /* Put the analog decoder in standby to keep it quiet */
539 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
541 if (fe0->dvb.frontend->ops.analog_ops.standby)
542 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
544 /* register everything */
545 return videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
546 &dev->pci->dev, adapter_nr);
550 int cx23885_dvb_register(struct cx23885_tsport *port)
553 struct videobuf_dvb_frontend *fe0;
554 struct cx23885_dev *dev = port->dev;
557 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
561 dprintk(1, "%s\n", __func__);
562 dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
571 printk("%s: cx23885 based dvb card\n", dev->name);
572 videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops, &dev->pci->dev, &port->slock,
573 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
574 sizeof(struct cx23885_buffer), port);
575 err = dvb_register(port);
577 printk("%s() dvb_register failed err = %d\n", __func__, err);
582 int cx23885_dvb_unregister(struct cx23885_tsport *port)
584 struct videobuf_dvb_frontend *fe0;
586 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
588 if(fe0->dvb.frontend)
589 videobuf_dvb_unregister_bus(&port->frontends);
598 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off