Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Michael Krufky | f179849 | 2005-07-07 17:58:39 -0700 | [diff] [blame^] | 2 | * $Id: cx88-dvb.c,v 1.37 2005/06/28 23:41:47 mkrufky Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 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 Krufky | f179849 | 2005-07-07 17:58:39 -0700 | [diff] [blame^] | 33 | /* these three frontends need merging via linuxtv cvs ... */ |
Gerd Knorr | 9990d74 | 2005-05-01 08:59:20 -0700 | [diff] [blame] | 34 | #define HAVE_CX22702 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define HAVE_OR51132 1 |
Michael Krufky | f179849 | 2005-07-07 17:58:39 -0700 | [diff] [blame^] | 36 | #define HAVE_LGDT3302 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #include "cx88.h" |
| 39 | #include "dvb-pll.h" |
| 40 | #include "mt352.h" |
| 41 | #include "mt352_priv.h" |
| 42 | #if HAVE_CX22702 |
| 43 | # include "cx22702.h" |
| 44 | #endif |
| 45 | #if HAVE_OR51132 |
| 46 | # include "or51132.h" |
| 47 | #endif |
Michael Krufky | f179849 | 2005-07-07 17:58:39 -0700 | [diff] [blame^] | 48 | #if HAVE_LGDT3302 |
| 49 | # include "lgdt3302.h" |
| 50 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 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"); |
| 56 | |
| 57 | static unsigned int debug = 0; |
| 58 | module_param(debug, int, 0644); |
| 59 | MODULE_PARM_DESC(debug,"enable debug messages [dvb]"); |
| 60 | |
| 61 | #define dprintk(level,fmt, arg...) if (debug >= level) \ |
| 62 | printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg) |
| 63 | |
| 64 | /* ------------------------------------------------------------------ */ |
| 65 | |
| 66 | static int dvb_buf_setup(struct videobuf_queue *q, |
| 67 | unsigned int *count, unsigned int *size) |
| 68 | { |
| 69 | struct cx8802_dev *dev = q->priv_data; |
| 70 | |
| 71 | dev->ts_packet_size = 188 * 4; |
| 72 | dev->ts_packet_count = 32; |
| 73 | |
| 74 | *size = dev->ts_packet_size * dev->ts_packet_count; |
| 75 | *count = 32; |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, |
| 80 | enum v4l2_field field) |
| 81 | { |
| 82 | struct cx8802_dev *dev = q->priv_data; |
| 83 | return cx8802_buf_prepare(dev, (struct cx88_buffer*)vb); |
| 84 | } |
| 85 | |
| 86 | static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 87 | { |
| 88 | struct cx8802_dev *dev = q->priv_data; |
| 89 | cx8802_buf_queue(dev, (struct cx88_buffer*)vb); |
| 90 | } |
| 91 | |
| 92 | static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 93 | { |
| 94 | struct cx8802_dev *dev = q->priv_data; |
| 95 | cx88_free_buffer(dev->pci, (struct cx88_buffer*)vb); |
| 96 | } |
| 97 | |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 98 | static struct videobuf_queue_ops dvb_qops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | .buf_setup = dvb_buf_setup, |
| 100 | .buf_prepare = dvb_buf_prepare, |
| 101 | .buf_queue = dvb_buf_queue, |
| 102 | .buf_release = dvb_buf_release, |
| 103 | }; |
| 104 | |
| 105 | /* ------------------------------------------------------------------ */ |
| 106 | |
| 107 | static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe) |
| 108 | { |
| 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 }; |
| 115 | |
| 116 | mt352_write(fe, clock_config, sizeof(clock_config)); |
| 117 | udelay(200); |
| 118 | mt352_write(fe, reset, sizeof(reset)); |
| 119 | mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); |
| 120 | |
| 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)); |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe) |
| 128 | { |
| 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 }; |
| 136 | |
| 137 | mt352_write(fe, clock_config, sizeof(clock_config)); |
| 138 | udelay(2000); |
| 139 | mt352_write(fe, reset, sizeof(reset)); |
| 140 | mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); |
| 141 | |
| 142 | mt352_write(fe, agc_cfg, sizeof(agc_cfg)); |
| 143 | udelay(2000); |
| 144 | mt352_write(fe, dntv_extra, sizeof(dntv_extra)); |
| 145 | mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg)); |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static int mt352_pll_set(struct dvb_frontend* fe, |
| 151 | struct dvb_frontend_parameters* params, |
| 152 | u8* pllbuf) |
| 153 | { |
| 154 | struct cx8802_dev *dev= fe->dvb->priv; |
| 155 | |
| 156 | pllbuf[0] = dev->core->pll_addr << 1; |
| 157 | dvb_pll_configure(dev->core->pll_desc, pllbuf+1, |
| 158 | params->frequency, |
| 159 | params->u.ofdm.bandwidth); |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static struct mt352_config dvico_fusionhdtv = { |
| 164 | .demod_address = 0x0F, |
| 165 | .demod_init = dvico_fusionhdtv_demod_init, |
| 166 | .pll_set = mt352_pll_set, |
| 167 | }; |
| 168 | |
| 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, |
| 173 | }; |
| 174 | |
| 175 | #if HAVE_CX22702 |
| 176 | static struct cx22702_config connexant_refboard_config = { |
| 177 | .demod_address = 0x43, |
| 178 | .pll_address = 0x60, |
| 179 | .pll_desc = &dvb_pll_thomson_dtt7579, |
| 180 | }; |
| 181 | |
| 182 | static 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 | |
| 189 | #if HAVE_OR51132 |
| 190 | static 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 Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 198 | static struct or51132_config pchdtv_hd3000 = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | .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 | |
Michael Krufky | f179849 | 2005-07-07 17:58:39 -0700 | [diff] [blame^] | 206 | #if HAVE_LGDT3302 |
| 207 | static 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 | |
| 217 | static 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 | }; |
| 223 | #endif |
| 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | static int dvb_register(struct cx8802_dev *dev) |
| 226 | { |
| 227 | /* init struct videobuf_dvb */ |
| 228 | dev->dvb.name = dev->core->name; |
| 229 | dev->ts_gen_cntrl = 0x0c; |
| 230 | |
| 231 | /* init frontend */ |
| 232 | switch (dev->core->board) { |
| 233 | #if HAVE_CX22702 |
| 234 | case CX88_BOARD_HAUPPAUGE_DVB_T1: |
| 235 | dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config, |
| 236 | &dev->core->i2c_adap); |
| 237 | break; |
| 238 | case CX88_BOARD_CONEXANT_DVB_T1: |
| 239 | dev->dvb.frontend = cx22702_attach(&connexant_refboard_config, |
| 240 | &dev->core->i2c_adap); |
| 241 | break; |
| 242 | #endif |
| 243 | case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1: |
| 244 | dev->core->pll_addr = 0x61; |
| 245 | dev->core->pll_desc = &dvb_pll_lg_z201; |
| 246 | dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv, |
| 247 | &dev->core->i2c_adap); |
| 248 | break; |
| 249 | case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS: |
| 250 | dev->core->pll_addr = 0x60; |
| 251 | dev->core->pll_desc = &dvb_pll_thomson_dtt7579; |
| 252 | dev->dvb.frontend = mt352_attach(&dvico_fusionhdtv, |
| 253 | &dev->core->i2c_adap); |
| 254 | break; |
| 255 | case CX88_BOARD_KWORLD_DVB_T: |
| 256 | case CX88_BOARD_DNTV_LIVE_DVB_T: |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 257 | case CX88_BOARD_ADSTECH_DVB_T_PCI: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | dev->core->pll_addr = 0x61; |
| 259 | dev->core->pll_desc = &dvb_pll_unknown_1; |
| 260 | dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config, |
| 261 | &dev->core->i2c_adap); |
| 262 | break; |
| 263 | #if HAVE_OR51132 |
| 264 | case CX88_BOARD_PCHDTV_HD3000: |
| 265 | dev->dvb.frontend = or51132_attach(&pchdtv_hd3000, |
| 266 | &dev->core->i2c_adap); |
| 267 | break; |
| 268 | #endif |
Michael Krufky | f179849 | 2005-07-07 17:58:39 -0700 | [diff] [blame^] | 269 | #if HAVE_LGDT3302 |
| 270 | case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q: |
| 271 | dev->ts_gen_cntrl = 0x08; |
| 272 | { |
| 273 | /* Do a hardware reset of chip before using it. */ |
| 274 | struct cx88_core *core = dev->core; |
| 275 | |
| 276 | cx_clear(MO_GP0_IO, 1); |
| 277 | mdelay(100); |
| 278 | cx_set(MO_GP0_IO, 9); // ANT connector too FIXME |
| 279 | mdelay(200); |
| 280 | dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_q, |
| 281 | &dev->core->i2c_adap); |
| 282 | } |
| 283 | break; |
| 284 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | default: |
Gerd Knorr | 1622c3f | 2005-05-01 08:59:19 -0700 | [diff] [blame] | 286 | printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n", |
| 287 | dev->core->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | break; |
| 289 | } |
| 290 | if (NULL == dev->dvb.frontend) { |
| 291 | printk("%s: frontend initialization failed\n",dev->core->name); |
| 292 | return -1; |
| 293 | } |
| 294 | |
| 295 | if (dev->core->pll_desc) { |
| 296 | dev->dvb.frontend->ops->info.frequency_min = dev->core->pll_desc->min; |
| 297 | dev->dvb.frontend->ops->info.frequency_max = dev->core->pll_desc->max; |
| 298 | } |
| 299 | |
| 300 | /* Copy the board name into the DVB structure */ |
| 301 | strlcpy(dev->dvb.frontend->ops->info.name, |
| 302 | cx88_boards[dev->core->board].name, |
| 303 | sizeof(dev->dvb.frontend->ops->info.name)); |
| 304 | |
| 305 | /* register everything */ |
| 306 | return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev); |
| 307 | } |
| 308 | |
| 309 | /* ----------------------------------------------------------- */ |
| 310 | |
| 311 | static int __devinit dvb_probe(struct pci_dev *pci_dev, |
| 312 | const struct pci_device_id *pci_id) |
| 313 | { |
| 314 | struct cx8802_dev *dev; |
| 315 | struct cx88_core *core; |
| 316 | int err; |
| 317 | |
| 318 | /* general setup */ |
| 319 | core = cx88_core_get(pci_dev); |
| 320 | if (NULL == core) |
| 321 | return -EINVAL; |
| 322 | |
| 323 | err = -ENODEV; |
| 324 | if (!cx88_boards[core->board].dvb) |
| 325 | goto fail_core; |
| 326 | |
| 327 | err = -ENOMEM; |
| 328 | dev = kmalloc(sizeof(*dev),GFP_KERNEL); |
| 329 | if (NULL == dev) |
| 330 | goto fail_core; |
| 331 | memset(dev,0,sizeof(*dev)); |
| 332 | dev->pci = pci_dev; |
| 333 | dev->core = core; |
| 334 | |
| 335 | err = cx8802_init_common(dev); |
| 336 | if (0 != err) |
| 337 | goto fail_free; |
| 338 | |
| 339 | /* dvb stuff */ |
| 340 | printk("%s/2: cx2388x based dvb card\n", core->name); |
| 341 | videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops, |
| 342 | dev->pci, &dev->slock, |
| 343 | V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 344 | V4L2_FIELD_TOP, |
| 345 | sizeof(struct cx88_buffer), |
| 346 | dev); |
| 347 | err = dvb_register(dev); |
| 348 | if (0 != err) |
Gerd Knorr | 1622c3f | 2005-05-01 08:59:19 -0700 | [diff] [blame] | 349 | goto fail_fini; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | return 0; |
| 351 | |
Gerd Knorr | 1622c3f | 2005-05-01 08:59:19 -0700 | [diff] [blame] | 352 | fail_fini: |
| 353 | cx8802_fini_common(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | fail_free: |
| 355 | kfree(dev); |
| 356 | fail_core: |
| 357 | cx88_core_put(core,pci_dev); |
| 358 | return err; |
| 359 | } |
| 360 | |
| 361 | static void __devexit dvb_remove(struct pci_dev *pci_dev) |
| 362 | { |
| 363 | struct cx8802_dev *dev = pci_get_drvdata(pci_dev); |
| 364 | |
| 365 | /* dvb */ |
| 366 | videobuf_dvb_unregister(&dev->dvb); |
| 367 | |
| 368 | /* common */ |
| 369 | cx8802_fini_common(dev); |
| 370 | cx88_core_put(dev->core,dev->pci); |
| 371 | kfree(dev); |
| 372 | } |
| 373 | |
| 374 | static struct pci_device_id cx8802_pci_tbl[] = { |
| 375 | { |
| 376 | .vendor = 0x14f1, |
| 377 | .device = 0x8802, |
| 378 | .subvendor = PCI_ANY_ID, |
| 379 | .subdevice = PCI_ANY_ID, |
| 380 | },{ |
| 381 | /* --- end of list --- */ |
| 382 | } |
| 383 | }; |
| 384 | MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl); |
| 385 | |
| 386 | static struct pci_driver dvb_pci_driver = { |
| 387 | .name = "cx88-dvb", |
| 388 | .id_table = cx8802_pci_tbl, |
| 389 | .probe = dvb_probe, |
| 390 | .remove = __devexit_p(dvb_remove), |
| 391 | .suspend = cx8802_suspend_common, |
| 392 | .resume = cx8802_resume_common, |
| 393 | }; |
| 394 | |
| 395 | static int dvb_init(void) |
| 396 | { |
| 397 | printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n", |
| 398 | (CX88_VERSION_CODE >> 16) & 0xff, |
| 399 | (CX88_VERSION_CODE >> 8) & 0xff, |
| 400 | CX88_VERSION_CODE & 0xff); |
| 401 | #ifdef SNAPSHOT |
| 402 | printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n", |
| 403 | SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100); |
| 404 | #endif |
| 405 | return pci_register_driver(&dvb_pci_driver); |
| 406 | } |
| 407 | |
| 408 | static void dvb_fini(void) |
| 409 | { |
| 410 | pci_unregister_driver(&dvb_pci_driver); |
| 411 | } |
| 412 | |
| 413 | module_init(dvb_init); |
| 414 | module_exit(dvb_fini); |
| 415 | |
| 416 | /* |
| 417 | * Local variables: |
| 418 | * c-basic-offset: 8 |
| 419 | * compile-command: "make DVB=1" |
| 420 | * End: |
| 421 | */ |