cx23885-dvb.c revision dfc1c08aab447d49230dacb390d3f2263584d28f
1/* 2 * Driver for the Conexant CX23885 PCIe bridge 3 * 4 * Copyright (c) 2006 Steven Toth <stoth@hauppauge.com> 5 * 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. 10 * 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 14 * 15 * GNU General Public License for more details. 16 * 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. 20 */ 21 22#include <linux/module.h> 23#include <linux/init.h> 24#include <linux/device.h> 25#include <linux/fs.h> 26#include <linux/kthread.h> 27#include <linux/file.h> 28#include <linux/suspend.h> 29 30#include "cx23885.h" 31#include <media/v4l2-common.h> 32 33#include "s5h1409.h" 34#include "mt2131.h" 35#include "tda8290.h" 36#include "tda18271.h" 37#include "lgdt330x.h" 38#include "xc5000.h" 39#include "dvb-pll.h" 40#include "tuner-xc2028.h" 41#include "tuner-xc2028-types.h" 42 43static unsigned int debug; 44 45#define dprintk(level, fmt, arg...)\ 46 do { if (debug >= level)\ 47 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\ 48 } while (0) 49 50/* ------------------------------------------------------------------ */ 51 52static unsigned int alt_tuner; 53module_param(alt_tuner, int, 0644); 54MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration"); 55 56/* ------------------------------------------------------------------ */ 57 58static int dvb_buf_setup(struct videobuf_queue *q, 59 unsigned int *count, unsigned int *size) 60{ 61 struct cx23885_tsport *port = q->priv_data; 62 63 port->ts_packet_size = 188 * 4; 64 port->ts_packet_count = 32; 65 66 *size = port->ts_packet_size * port->ts_packet_count; 67 *count = 32; 68 return 0; 69} 70 71static int dvb_buf_prepare(struct videobuf_queue *q, 72 struct videobuf_buffer *vb, enum v4l2_field field) 73{ 74 struct cx23885_tsport *port = q->priv_data; 75 return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field); 76} 77 78static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) 79{ 80 struct cx23885_tsport *port = q->priv_data; 81 cx23885_buf_queue(port, (struct cx23885_buffer*)vb); 82} 83 84static void dvb_buf_release(struct videobuf_queue *q, 85 struct videobuf_buffer *vb) 86{ 87 cx23885_free_buffer(q, (struct cx23885_buffer*)vb); 88} 89 90static int cx23885_request_firmware(struct dvb_frontend *fe, 91 const struct firmware **fw, char *name) 92{ 93 struct cx23885_tsport *port = fe->dvb->priv; 94 struct cx23885_dev *dev = port->dev; 95 96 dprintk(1, "%s(?,?,%s)\n", __FUNCTION__, name); 97 98 return request_firmware(fw, name, &dev->pci->dev); 99} 100 101static int hauppauge_hvr1500q_tuner_reset(struct dvb_frontend *fe) 102{ 103 struct cx23885_tsport *port = fe->dvb->priv; 104 struct cx23885_dev *dev = port->dev; 105 106 dprintk(1, "%s()\n", __FUNCTION__); 107 108 /* Drive the tuner into reset back back */ 109 cx_clear(GP0_IO, 0x00000004); 110 mdelay(200); 111 cx_set(GP0_IO, 0x00000004); 112 113 return 0; 114} 115 116static struct videobuf_queue_ops dvb_qops = { 117 .buf_setup = dvb_buf_setup, 118 .buf_prepare = dvb_buf_prepare, 119 .buf_queue = dvb_buf_queue, 120 .buf_release = dvb_buf_release, 121}; 122 123static struct s5h1409_config hauppauge_generic_config = { 124 .demod_address = 0x32 >> 1, 125 .output_mode = S5H1409_SERIAL_OUTPUT, 126 .gpio = S5H1409_GPIO_ON, 127 .qam_if = 44000, 128 .inversion = S5H1409_INVERSION_OFF, 129 .status_mode = S5H1409_DEMODLOCKING, 130 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 131}; 132 133static struct s5h1409_config hauppauge_ezqam_config = { 134 .demod_address = 0x32 >> 1, 135 .output_mode = S5H1409_SERIAL_OUTPUT, 136 .gpio = S5H1409_GPIO_OFF, 137 .qam_if = 4000, 138 .inversion = S5H1409_INVERSION_ON, 139 .status_mode = S5H1409_DEMODLOCKING, 140 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 141}; 142 143static struct s5h1409_config hauppauge_hvr1800lp_config = { 144 .demod_address = 0x32 >> 1, 145 .output_mode = S5H1409_SERIAL_OUTPUT, 146 .gpio = S5H1409_GPIO_OFF, 147 .qam_if = 44000, 148 .inversion = S5H1409_INVERSION_OFF, 149 .status_mode = S5H1409_DEMODLOCKING, 150 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 151}; 152 153static struct s5h1409_config hauppauge_hvr1500_config = { 154 .demod_address = 0x32 >> 1, 155 .output_mode = S5H1409_SERIAL_OUTPUT, 156 .gpio = S5H1409_GPIO_OFF, 157 .inversion = S5H1409_INVERSION_OFF, 158 .status_mode = S5H1409_DEMODLOCKING, 159 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 160}; 161 162static struct mt2131_config hauppauge_generic_tunerconfig = { 163 0x61 164}; 165 166static struct lgdt330x_config fusionhdtv_5_express = { 167 .demod_address = 0x0e, 168 .demod_chip = LGDT3303, 169 .serial_mpeg = 0x40, 170}; 171 172static struct s5h1409_config hauppauge_hvr1500q_config = { 173 .demod_address = 0x32 >> 1, 174 .output_mode = S5H1409_SERIAL_OUTPUT, 175 .gpio = S5H1409_GPIO_ON, 176 .qam_if = 44000, 177 .inversion = S5H1409_INVERSION_OFF, 178 .status_mode = S5H1409_DEMODLOCKING, 179 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 180}; 181 182static struct xc5000_config hauppauge_hvr1500q_tunerconfig = { 183 .i2c_address = 0x61, 184 .if_khz = 5380, 185 .request_firmware = cx23885_request_firmware, 186 .tuner_reset = hauppauge_hvr1500q_tuner_reset 187}; 188 189static struct tda829x_config tda829x_no_probe = { 190 .probe_tuner = TDA829X_DONT_PROBE, 191}; 192 193static struct tda18271_std_map hauppauge_tda18271_std_map = { 194 .atsc_6 = { .if_freq = 5380, .std_bits = 0x1b }, 195 .qam_6 = { .if_freq = 4000, .std_bits = 0x18 }, 196}; 197 198static struct tda18271_config hauppauge_tda18271_config = { 199 .std_map = &hauppauge_tda18271_std_map, 200 .gate = TDA18271_GATE_ANALOG, 201}; 202 203static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg) 204{ 205 struct cx23885_tsport *port = ptr; 206 struct cx23885_dev *dev = port->dev; 207 208 switch (command) { 209 case XC2028_TUNER_RESET: 210 /* Send the tuner in then out of reset */ 211 /* GPIO-2 xc3028 tuner */ 212 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg); 213 214 cx_set(GP0_IO, 0x00040000); 215 cx_clear(GP0_IO, 0x00000004); 216 msleep(5); 217 218 cx_set(GP0_IO, 0x00040004); 219 msleep(5); 220 break; 221 case XC2028_RESET_CLK: 222 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg); 223 break; 224 default: 225 dprintk(1, "%s: unknown command %d, arg %d\n", __FUNCTION__, 226 command, arg); 227 return -EINVAL; 228 } 229 230 return 0; 231} 232 233static int dvb_register(struct cx23885_tsport *port) 234{ 235 struct cx23885_dev *dev = port->dev; 236 struct cx23885_i2c *i2c_bus = NULL; 237 238 /* init struct videobuf_dvb */ 239 port->dvb.name = dev->name; 240 241 /* init frontend */ 242 switch (dev->board) { 243 case CX23885_BOARD_HAUPPAUGE_HVR1250: 244 i2c_bus = &dev->i2c_bus[0]; 245 port->dvb.frontend = dvb_attach(s5h1409_attach, 246 &hauppauge_generic_config, 247 &i2c_bus->i2c_adap); 248 if (port->dvb.frontend != NULL) { 249 dvb_attach(mt2131_attach, port->dvb.frontend, 250 &i2c_bus->i2c_adap, 251 &hauppauge_generic_tunerconfig, 0); 252 } 253 break; 254 case CX23885_BOARD_HAUPPAUGE_HVR1800: 255 i2c_bus = &dev->i2c_bus[0]; 256 switch (alt_tuner) { 257 case 1: 258 port->dvb.frontend = 259 dvb_attach(s5h1409_attach, 260 &hauppauge_ezqam_config, 261 &i2c_bus->i2c_adap); 262 if (port->dvb.frontend != NULL) { 263 dvb_attach(tda829x_attach, port->dvb.frontend, 264 &dev->i2c_bus[1].i2c_adap, 0x42, 265 &tda829x_no_probe); 266 dvb_attach(tda18271_attach, port->dvb.frontend, 267 0x60, &dev->i2c_bus[1].i2c_adap, 268 &hauppauge_tda18271_config); 269 } 270 break; 271 case 0: 272 default: 273 port->dvb.frontend = 274 dvb_attach(s5h1409_attach, 275 &hauppauge_generic_config, 276 &i2c_bus->i2c_adap); 277 if (port->dvb.frontend != NULL) 278 dvb_attach(mt2131_attach, port->dvb.frontend, 279 &i2c_bus->i2c_adap, 280 &hauppauge_generic_tunerconfig, 0); 281 break; 282 } 283 break; 284 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 285 i2c_bus = &dev->i2c_bus[0]; 286 port->dvb.frontend = dvb_attach(s5h1409_attach, 287 &hauppauge_hvr1800lp_config, 288 &i2c_bus->i2c_adap); 289 if (port->dvb.frontend != NULL) { 290 dvb_attach(mt2131_attach, port->dvb.frontend, 291 &i2c_bus->i2c_adap, 292 &hauppauge_generic_tunerconfig, 0); 293 } 294 break; 295 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP: 296 i2c_bus = &dev->i2c_bus[0]; 297 port->dvb.frontend = dvb_attach(lgdt330x_attach, 298 &fusionhdtv_5_express, 299 &i2c_bus->i2c_adap); 300 if (port->dvb.frontend != NULL) { 301 dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61, 302 &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF); 303 } 304 break; 305 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 306 i2c_bus = &dev->i2c_bus[1]; 307 port->dvb.frontend = dvb_attach(s5h1409_attach, 308 &hauppauge_hvr1500q_config, 309 &dev->i2c_bus[0].i2c_adap); 310 if (port->dvb.frontend != NULL) { 311 dvb_attach(xc5000_attach, port->dvb.frontend, 312 &i2c_bus->i2c_adap, 313 &hauppauge_hvr1500q_tunerconfig); 314 } 315 break; 316 case CX23885_BOARD_HAUPPAUGE_HVR1500: 317 i2c_bus = &dev->i2c_bus[1]; 318 port->dvb.frontend = dvb_attach(s5h1409_attach, 319 &hauppauge_hvr1500_config, 320 &dev->i2c_bus[0].i2c_adap); 321 if (port->dvb.frontend != NULL) { 322 struct dvb_frontend *fe; 323 struct xc2028_config cfg = { 324 .i2c_adap = &i2c_bus->i2c_adap, 325 .i2c_addr = 0x61, 326 .video_dev = port, 327 .callback = cx23885_hvr1500_xc3028_callback, 328 }; 329 static struct xc2028_ctrl ctl = { 330 .fname = "xc3028-v27.fw", 331 .max_len = 64, 332 .scode_table = OREN538, 333 }; 334 335 fe = dvb_attach(xc2028_attach, 336 port->dvb.frontend, &cfg); 337 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL) 338 fe->ops.tuner_ops.set_config(fe, &ctl); 339 } 340 break; 341 default: 342 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n", 343 dev->name); 344 break; 345 } 346 if (NULL == port->dvb.frontend) { 347 printk("%s: frontend initialization failed\n", dev->name); 348 return -1; 349 } 350 351 /* Put the analog decoder in standby to keep it quiet */ 352 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL); 353 354 if (port->dvb.frontend->ops.analog_ops.standby) 355 port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend); 356 357 /* register everything */ 358 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port, 359 &dev->pci->dev); 360} 361 362int cx23885_dvb_register(struct cx23885_tsport *port) 363{ 364 struct cx23885_dev *dev = port->dev; 365 int err; 366 367 dprintk(1, "%s\n", __FUNCTION__); 368 dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n", 369 dev->board, 370 dev->name, 371 dev->pci_bus, 372 dev->pci_slot); 373 374 err = -ENODEV; 375 376 /* dvb stuff */ 377 printk("%s: cx23885 based dvb card\n", dev->name); 378 videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock, 379 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP, 380 sizeof(struct cx23885_buffer), port); 381 err = dvb_register(port); 382 if (err != 0) 383 printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err); 384 385 return err; 386} 387 388int cx23885_dvb_unregister(struct cx23885_tsport *port) 389{ 390 /* dvb */ 391 if(port->dvb.frontend) 392 videobuf_dvb_unregister(&port->dvb); 393 394 return 0; 395} 396 397/* 398 * Local variables: 399 * c-basic-offset: 8 400 * End: 401 * 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 402*/ 403