1 /* 2 * 3 * device driver for philips saa7134 based TV cards 4 * driver core 5 * 6 * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 */ 22 23 #include "saa7134.h" 24 #include "saa7134-reg.h" 25 26 #include <linux/init.h> 27 #include <linux/list.h> 28 #include <linux/module.h> 29 #include <linux/kernel.h> 30 #include <linux/slab.h> 31 #include <linux/kmod.h> 32 #include <linux/sound.h> 33 #include <linux/interrupt.h> 34 #include <linux/delay.h> 35 #include <linux/mutex.h> 36 #include <linux/dma-mapping.h> 37 #include <linux/pm.h> 38 39 MODULE_DESCRIPTION("v4l2 driver module for saa7130/34 based TV cards"); 40 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 41 MODULE_LICENSE("GPL"); 42 MODULE_VERSION(SAA7134_VERSION); 43 44 45 /* ------------------------------------------------------------------ */ 46 47 static unsigned int irq_debug; 48 module_param(irq_debug, int, 0644); 49 MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]"); 50 51 static unsigned int core_debug; 52 module_param(core_debug, int, 0644); 53 MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 54 55 static unsigned int gpio_tracking; 56 module_param(gpio_tracking, int, 0644); 57 MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]"); 58 59 static unsigned int alsa = 1; 60 module_param(alsa, int, 0644); 61 MODULE_PARM_DESC(alsa,"enable/disable ALSA DMA sound [dmasound]"); 62 63 static unsigned int latency = UNSET; 64 module_param(latency, int, 0444); 65 MODULE_PARM_DESC(latency,"pci latency timer"); 66 67 int saa7134_no_overlay=-1; 68 module_param_named(no_overlay, saa7134_no_overlay, int, 0444); 69 MODULE_PARM_DESC(no_overlay,"allow override overlay default (0 disables, 1 enables)" 70 " [some VIA/SIS chipsets are known to have problem with overlay]"); 71 72 bool saa7134_userptr; 73 module_param(saa7134_userptr, bool, 0644); 74 MODULE_PARM_DESC(saa7134_userptr, "enable page-aligned userptr support"); 75 76 static unsigned int video_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 77 static unsigned int vbi_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 78 static unsigned int radio_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 79 static unsigned int tuner[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 80 static unsigned int card[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; 81 82 83 module_param_array(video_nr, int, NULL, 0444); 84 module_param_array(vbi_nr, int, NULL, 0444); 85 module_param_array(radio_nr, int, NULL, 0444); 86 module_param_array(tuner, int, NULL, 0444); 87 module_param_array(card, int, NULL, 0444); 88 89 MODULE_PARM_DESC(video_nr, "video device number"); 90 MODULE_PARM_DESC(vbi_nr, "vbi device number"); 91 MODULE_PARM_DESC(radio_nr, "radio device number"); 92 MODULE_PARM_DESC(tuner, "tuner type"); 93 MODULE_PARM_DESC(card, "card type"); 94 95 DEFINE_MUTEX(saa7134_devlist_lock); 96 EXPORT_SYMBOL(saa7134_devlist_lock); 97 LIST_HEAD(saa7134_devlist); 98 EXPORT_SYMBOL(saa7134_devlist); 99 static LIST_HEAD(mops_list); 100 static unsigned int saa7134_devcount; 101 102 int (*saa7134_dmasound_init)(struct saa7134_dev *dev); 103 int (*saa7134_dmasound_exit)(struct saa7134_dev *dev); 104 105 #define core_dbg(fmt, arg...) do { \ 106 if (core_debug) \ 107 printk(KERN_DEBUG pr_fmt("core: " fmt), ## arg); \ 108 } while (0) 109 110 #define irq_dbg(level, fmt, arg...) do {\ 111 if (irq_debug > level) \ 112 printk(KERN_DEBUG pr_fmt("irq: " fmt), ## arg); \ 113 } while (0) 114 115 void saa7134_track_gpio(struct saa7134_dev *dev, char *msg) 116 { 117 unsigned long mode,status; 118 119 if (!gpio_tracking) 120 return; 121 /* rising SAA7134_GPIO_GPRESCAN reads the status */ 122 saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,0); 123 saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,SAA7134_GPIO_GPRESCAN); 124 mode = saa_readl(SAA7134_GPIO_GPMODE0 >> 2) & 0xfffffff; 125 status = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & 0xfffffff; 126 core_dbg("%s: gpio: mode=0x%07lx in=0x%07lx out=0x%07lx [%s]\n", 127 dev->name, mode, (~mode) & status, mode & status, msg); 128 } 129 130 void saa7134_set_gpio(struct saa7134_dev *dev, int bit_no, int value) 131 { 132 u32 index, bitval; 133 134 index = 1 << bit_no; 135 switch (value) { 136 case 0: /* static value */ 137 case 1: 138 core_dbg("setting GPIO%d to static %d\n", bit_no, value); 139 /* turn sync mode off if necessary */ 140 if (index & 0x00c00000) 141 saa_andorb(SAA7134_VIDEO_PORT_CTRL6, 0x0f, 0x00); 142 if (value) 143 bitval = index; 144 else 145 bitval = 0; 146 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, index, index); 147 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, index, bitval); 148 break; 149 case 3: /* tristate */ 150 core_dbg("setting GPIO%d to tristate\n", bit_no); 151 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, index, 0); 152 break; 153 } 154 } 155 156 /* ------------------------------------------------------------------ */ 157 158 159 /* ----------------------------------------------------------- */ 160 /* delayed request_module */ 161 162 #if defined(CONFIG_MODULES) && defined(MODULE) 163 164 static void request_module_async(struct work_struct *work){ 165 struct saa7134_dev* dev = container_of(work, struct saa7134_dev, request_module_wk); 166 if (card_is_empress(dev)) 167 request_module("saa7134-empress"); 168 if (card_is_dvb(dev)) 169 request_module("saa7134-dvb"); 170 if (card_is_go7007(dev)) 171 request_module("saa7134-go7007"); 172 if (alsa) { 173 if (dev->pci->device != PCI_DEVICE_ID_PHILIPS_SAA7130) 174 request_module("saa7134-alsa"); 175 } 176 } 177 178 static void request_submodules(struct saa7134_dev *dev) 179 { 180 INIT_WORK(&dev->request_module_wk, request_module_async); 181 schedule_work(&dev->request_module_wk); 182 } 183 184 static void flush_request_submodules(struct saa7134_dev *dev) 185 { 186 flush_work(&dev->request_module_wk); 187 } 188 189 #else 190 #define request_submodules(dev) 191 #define flush_request_submodules(dev) 192 #endif /* CONFIG_MODULES */ 193 194 /* ------------------------------------------------------------------ */ 195 196 /* nr of (saa7134-)pages for the given buffer size */ 197 static int saa7134_buffer_pages(int size) 198 { 199 size = PAGE_ALIGN(size); 200 size += PAGE_SIZE; /* for non-page-aligned buffers */ 201 size /= 4096; 202 return size; 203 } 204 205 /* calc max # of buffers from size (must not exceed the 4MB virtual 206 * address space per DMA channel) */ 207 int saa7134_buffer_count(unsigned int size, unsigned int count) 208 { 209 unsigned int maxcount; 210 211 maxcount = 1024 / saa7134_buffer_pages(size); 212 if (count > maxcount) 213 count = maxcount; 214 return count; 215 } 216 217 int saa7134_buffer_startpage(struct saa7134_buf *buf) 218 { 219 return saa7134_buffer_pages(vb2_plane_size(&buf->vb2.vb2_buf, 0)) 220 * buf->vb2.vb2_buf.index; 221 } 222 223 unsigned long saa7134_buffer_base(struct saa7134_buf *buf) 224 { 225 unsigned long base; 226 struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2.vb2_buf, 0); 227 228 base = saa7134_buffer_startpage(buf) * 4096; 229 base += dma->sgl[0].offset; 230 return base; 231 } 232 233 /* ------------------------------------------------------------------ */ 234 235 int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt) 236 { 237 __le32 *cpu; 238 dma_addr_t dma_addr = 0; 239 240 cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr); 241 if (NULL == cpu) 242 return -ENOMEM; 243 pt->size = SAA7134_PGTABLE_SIZE; 244 pt->cpu = cpu; 245 pt->dma = dma_addr; 246 return 0; 247 } 248 249 int saa7134_pgtable_build(struct pci_dev *pci, struct saa7134_pgtable *pt, 250 struct scatterlist *list, unsigned int length, 251 unsigned int startpage) 252 { 253 __le32 *ptr; 254 unsigned int i, p; 255 256 BUG_ON(NULL == pt || NULL == pt->cpu); 257 258 ptr = pt->cpu + startpage; 259 for (i = 0; i < length; i++, list = sg_next(list)) { 260 for (p = 0; p * 4096 < list->length; p++, ptr++) 261 *ptr = cpu_to_le32(sg_dma_address(list) + 262 list->offset + p * 4096); 263 } 264 return 0; 265 } 266 267 void saa7134_pgtable_free(struct pci_dev *pci, struct saa7134_pgtable *pt) 268 { 269 if (NULL == pt->cpu) 270 return; 271 pci_free_consistent(pci, pt->size, pt->cpu, pt->dma); 272 pt->cpu = NULL; 273 } 274 275 /* ------------------------------------------------------------------ */ 276 277 int saa7134_buffer_queue(struct saa7134_dev *dev, 278 struct saa7134_dmaqueue *q, 279 struct saa7134_buf *buf) 280 { 281 struct saa7134_buf *next = NULL; 282 unsigned long flags; 283 284 spin_lock_irqsave(&dev->slock, flags); 285 core_dbg("buffer_queue %p\n", buf); 286 if (NULL == q->curr) { 287 if (!q->need_two) { 288 q->curr = buf; 289 buf->activate(dev, buf, NULL); 290 } else if (list_empty(&q->queue)) { 291 list_add_tail(&buf->entry, &q->queue); 292 } else { 293 next = list_entry(q->queue.next, struct saa7134_buf, 294 entry); 295 q->curr = buf; 296 buf->activate(dev, buf, next); 297 } 298 } else { 299 list_add_tail(&buf->entry, &q->queue); 300 } 301 spin_unlock_irqrestore(&dev->slock, flags); 302 return 0; 303 } 304 305 void saa7134_buffer_finish(struct saa7134_dev *dev, 306 struct saa7134_dmaqueue *q, 307 unsigned int state) 308 { 309 core_dbg("buffer_finish %p\n", q->curr); 310 311 /* finish current buffer */ 312 v4l2_get_timestamp(&q->curr->vb2.timestamp); 313 q->curr->vb2.sequence = q->seq_nr++; 314 vb2_buffer_done(&q->curr->vb2.vb2_buf, state); 315 q->curr = NULL; 316 } 317 318 void saa7134_buffer_next(struct saa7134_dev *dev, 319 struct saa7134_dmaqueue *q) 320 { 321 struct saa7134_buf *buf,*next = NULL; 322 323 assert_spin_locked(&dev->slock); 324 BUG_ON(NULL != q->curr); 325 326 if (!list_empty(&q->queue)) { 327 /* activate next one from queue */ 328 buf = list_entry(q->queue.next, struct saa7134_buf, entry); 329 core_dbg("buffer_next %p [prev=%p/next=%p]\n", 330 buf, q->queue.prev, q->queue.next); 331 list_del(&buf->entry); 332 if (!list_empty(&q->queue)) 333 next = list_entry(q->queue.next, struct saa7134_buf, entry); 334 q->curr = buf; 335 buf->activate(dev, buf, next); 336 core_dbg("buffer_next #2 prev=%p/next=%p\n", 337 q->queue.prev, q->queue.next); 338 } else { 339 /* nothing to do -- just stop DMA */ 340 core_dbg("buffer_next %p\n", NULL); 341 saa7134_set_dmabits(dev); 342 del_timer(&q->timeout); 343 } 344 } 345 346 void saa7134_buffer_timeout(unsigned long data) 347 { 348 struct saa7134_dmaqueue *q = (struct saa7134_dmaqueue *)data; 349 struct saa7134_dev *dev = q->dev; 350 unsigned long flags; 351 352 spin_lock_irqsave(&dev->slock, flags); 353 354 /* try to reset the hardware (SWRST) */ 355 saa_writeb(SAA7134_REGION_ENABLE, 0x00); 356 saa_writeb(SAA7134_REGION_ENABLE, 0x80); 357 saa_writeb(SAA7134_REGION_ENABLE, 0x00); 358 359 /* flag current buffer as failed, 360 try to start over with the next one. */ 361 if (q->curr) { 362 core_dbg("timeout on %p\n", q->curr); 363 saa7134_buffer_finish(dev, q, VB2_BUF_STATE_ERROR); 364 } 365 saa7134_buffer_next(dev, q); 366 spin_unlock_irqrestore(&dev->slock, flags); 367 } 368 369 void saa7134_stop_streaming(struct saa7134_dev *dev, struct saa7134_dmaqueue *q) 370 { 371 unsigned long flags; 372 struct list_head *pos, *n; 373 struct saa7134_buf *tmp; 374 375 spin_lock_irqsave(&dev->slock, flags); 376 if (!list_empty(&q->queue)) { 377 list_for_each_safe(pos, n, &q->queue) { 378 tmp = list_entry(pos, struct saa7134_buf, entry); 379 vb2_buffer_done(&tmp->vb2.vb2_buf, 380 VB2_BUF_STATE_ERROR); 381 list_del(pos); 382 tmp = NULL; 383 } 384 } 385 spin_unlock_irqrestore(&dev->slock, flags); 386 saa7134_buffer_timeout((unsigned long)q); /* also calls del_timer(&q->timeout) */ 387 } 388 EXPORT_SYMBOL_GPL(saa7134_stop_streaming); 389 390 /* ------------------------------------------------------------------ */ 391 392 int saa7134_set_dmabits(struct saa7134_dev *dev) 393 { 394 u32 split, task=0, ctrl=0, irq=0; 395 enum v4l2_field cap = V4L2_FIELD_ANY; 396 enum v4l2_field ov = V4L2_FIELD_ANY; 397 398 assert_spin_locked(&dev->slock); 399 400 if (dev->insuspend) 401 return 0; 402 403 /* video capture -- dma 0 + video task A */ 404 if (dev->video_q.curr) { 405 task |= 0x01; 406 ctrl |= SAA7134_MAIN_CTRL_TE0; 407 irq |= SAA7134_IRQ1_INTE_RA0_1 | 408 SAA7134_IRQ1_INTE_RA0_0; 409 cap = dev->field; 410 } 411 412 /* video capture -- dma 1+2 (planar modes) */ 413 if (dev->video_q.curr && dev->fmt->planar) { 414 ctrl |= SAA7134_MAIN_CTRL_TE4 | 415 SAA7134_MAIN_CTRL_TE5; 416 } 417 418 /* screen overlay -- dma 0 + video task B */ 419 if (dev->ovenable) { 420 task |= 0x10; 421 ctrl |= SAA7134_MAIN_CTRL_TE1; 422 ov = dev->ovfield; 423 } 424 425 /* vbi capture -- dma 0 + vbi task A+B */ 426 if (dev->vbi_q.curr) { 427 task |= 0x22; 428 ctrl |= SAA7134_MAIN_CTRL_TE2 | 429 SAA7134_MAIN_CTRL_TE3; 430 irq |= SAA7134_IRQ1_INTE_RA0_7 | 431 SAA7134_IRQ1_INTE_RA0_6 | 432 SAA7134_IRQ1_INTE_RA0_5 | 433 SAA7134_IRQ1_INTE_RA0_4; 434 } 435 436 /* audio capture -- dma 3 */ 437 if (dev->dmasound.dma_running) { 438 ctrl |= SAA7134_MAIN_CTRL_TE6; 439 irq |= SAA7134_IRQ1_INTE_RA3_1 | 440 SAA7134_IRQ1_INTE_RA3_0; 441 } 442 443 /* TS capture -- dma 5 */ 444 if (dev->ts_q.curr) { 445 ctrl |= SAA7134_MAIN_CTRL_TE5; 446 irq |= SAA7134_IRQ1_INTE_RA2_1 | 447 SAA7134_IRQ1_INTE_RA2_0; 448 } 449 450 /* set task conditions + field handling */ 451 if (V4L2_FIELD_HAS_BOTH(cap) || V4L2_FIELD_HAS_BOTH(ov) || cap == ov) { 452 /* default config -- use full frames */ 453 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A), 0x0d); 454 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B), 0x0d); 455 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A), 0x02); 456 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B), 0x02); 457 split = 0; 458 } else { 459 /* split fields between tasks */ 460 if (V4L2_FIELD_TOP == cap) { 461 /* odd A, even B, repeat */ 462 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A), 0x0d); 463 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B), 0x0e); 464 } else { 465 /* odd B, even A, repeat */ 466 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A), 0x0e); 467 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B), 0x0d); 468 } 469 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A), 0x01); 470 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B), 0x01); 471 split = 1; 472 } 473 474 /* irqs */ 475 saa_writeb(SAA7134_REGION_ENABLE, task); 476 saa_writel(SAA7134_IRQ1, irq); 477 saa_andorl(SAA7134_MAIN_CTRL, 478 SAA7134_MAIN_CTRL_TE0 | 479 SAA7134_MAIN_CTRL_TE1 | 480 SAA7134_MAIN_CTRL_TE2 | 481 SAA7134_MAIN_CTRL_TE3 | 482 SAA7134_MAIN_CTRL_TE4 | 483 SAA7134_MAIN_CTRL_TE5 | 484 SAA7134_MAIN_CTRL_TE6, 485 ctrl); 486 core_dbg("dmabits: task=0x%02x ctrl=0x%02x irq=0x%x split=%s\n", 487 task, ctrl, irq, split ? "no" : "yes"); 488 489 return 0; 490 } 491 492 /* ------------------------------------------------------------------ */ 493 /* IRQ handler + helpers */ 494 495 static char *irqbits[] = { 496 "DONE_RA0", "DONE_RA1", "DONE_RA2", "DONE_RA3", 497 "AR", "PE", "PWR_ON", "RDCAP", "INTL", "FIDT", "MMC", 498 "TRIG_ERR", "CONF_ERR", "LOAD_ERR", 499 "GPIO16", "GPIO18", "GPIO22", "GPIO23" 500 }; 501 #define IRQBITS ARRAY_SIZE(irqbits) 502 503 static void print_irqstatus(struct saa7134_dev *dev, int loop, 504 unsigned long report, unsigned long status) 505 { 506 unsigned int i; 507 508 irq_dbg(1, "[%d,%ld]: r=0x%lx s=0x%02lx", 509 loop, jiffies, report, status); 510 for (i = 0; i < IRQBITS; i++) { 511 if (!(report & (1 << i))) 512 continue; 513 pr_cont(" %s", irqbits[i]); 514 } 515 if (report & SAA7134_IRQ_REPORT_DONE_RA0) { 516 pr_cont(" | RA0=%s,%s,%s,%ld", 517 (status & 0x40) ? "vbi" : "video", 518 (status & 0x20) ? "b" : "a", 519 (status & 0x10) ? "odd" : "even", 520 (status & 0x0f)); 521 } 522 pr_cont("\n"); 523 } 524 525 static irqreturn_t saa7134_irq(int irq, void *dev_id) 526 { 527 struct saa7134_dev *dev = (struct saa7134_dev*) dev_id; 528 unsigned long report,status; 529 int loop, handled = 0; 530 531 if (dev->insuspend) 532 goto out; 533 534 for (loop = 0; loop < 10; loop++) { 535 report = saa_readl(SAA7134_IRQ_REPORT); 536 status = saa_readl(SAA7134_IRQ_STATUS); 537 538 /* If dmasound support is active and we get a sound report, 539 * mask out the report and let the saa7134-alsa module deal 540 * with it */ 541 if ((report & SAA7134_IRQ_REPORT_DONE_RA3) && 542 (dev->dmasound.priv_data != NULL) ) 543 { 544 irq_dbg(2, "preserving DMA sound interrupt\n"); 545 report &= ~SAA7134_IRQ_REPORT_DONE_RA3; 546 } 547 548 if (0 == report) { 549 irq_dbg(2, "no (more) work\n"); 550 goto out; 551 } 552 553 handled = 1; 554 saa_writel(SAA7134_IRQ_REPORT,report); 555 if (irq_debug) 556 print_irqstatus(dev,loop,report,status); 557 558 559 if ((report & SAA7134_IRQ_REPORT_RDCAP) || 560 (report & SAA7134_IRQ_REPORT_INTL)) 561 saa7134_irq_video_signalchange(dev); 562 563 564 if ((report & SAA7134_IRQ_REPORT_DONE_RA0) && 565 (status & 0x60) == 0) 566 saa7134_irq_video_done(dev,status); 567 568 if ((report & SAA7134_IRQ_REPORT_DONE_RA0) && 569 (status & 0x40) == 0x40) 570 saa7134_irq_vbi_done(dev,status); 571 572 if ((report & SAA7134_IRQ_REPORT_DONE_RA2) && 573 card_has_mpeg(dev)) { 574 if (dev->mops->irq_ts_done != NULL) 575 dev->mops->irq_ts_done(dev, status); 576 else 577 saa7134_irq_ts_done(dev, status); 578 } 579 580 if (report & SAA7134_IRQ_REPORT_GPIO16) { 581 switch (dev->has_remote) { 582 case SAA7134_REMOTE_GPIO: 583 if (!dev->remote) 584 break; 585 if (dev->remote->mask_keydown & 0x10000) { 586 saa7134_input_irq(dev); 587 } 588 break; 589 590 case SAA7134_REMOTE_I2C: 591 break; /* FIXME: invoke I2C get_key() */ 592 593 default: /* GPIO16 not used by IR remote */ 594 break; 595 } 596 } 597 598 if (report & SAA7134_IRQ_REPORT_GPIO18) { 599 switch (dev->has_remote) { 600 case SAA7134_REMOTE_GPIO: 601 if (!dev->remote) 602 break; 603 if ((dev->remote->mask_keydown & 0x40000) || 604 (dev->remote->mask_keyup & 0x40000)) { 605 saa7134_input_irq(dev); 606 } 607 break; 608 609 case SAA7134_REMOTE_I2C: 610 break; /* FIXME: invoke I2C get_key() */ 611 612 default: /* GPIO18 not used by IR remote */ 613 break; 614 } 615 } 616 } 617 618 if (10 == loop) { 619 print_irqstatus(dev,loop,report,status); 620 if (report & SAA7134_IRQ_REPORT_PE) { 621 /* disable all parity error */ 622 pr_warn("%s/irq: looping -- " 623 "clearing PE (parity error!) enable bit\n",dev->name); 624 saa_clearl(SAA7134_IRQ2,SAA7134_IRQ2_INTE_PE); 625 } else if (report & SAA7134_IRQ_REPORT_GPIO16) { 626 /* disable gpio16 IRQ */ 627 pr_warn("%s/irq: looping -- " 628 "clearing GPIO16 enable bit\n",dev->name); 629 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16_P); 630 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16_N); 631 } else if (report & SAA7134_IRQ_REPORT_GPIO18) { 632 /* disable gpio18 IRQs */ 633 pr_warn("%s/irq: looping -- " 634 "clearing GPIO18 enable bit\n",dev->name); 635 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P); 636 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_N); 637 } else { 638 /* disable all irqs */ 639 pr_warn("%s/irq: looping -- " 640 "clearing all enable bits\n",dev->name); 641 saa_writel(SAA7134_IRQ1,0); 642 saa_writel(SAA7134_IRQ2,0); 643 } 644 } 645 646 out: 647 return IRQ_RETVAL(handled); 648 } 649 650 /* ------------------------------------------------------------------ */ 651 652 /* early init (no i2c, no irq) */ 653 654 static int saa7134_hw_enable1(struct saa7134_dev *dev) 655 { 656 /* RAM FIFO config */ 657 saa_writel(SAA7134_FIFO_SIZE, 0x08070503); 658 saa_writel(SAA7134_THRESHOULD, 0x02020202); 659 660 /* enable audio + video processing */ 661 saa_writel(SAA7134_MAIN_CTRL, 662 SAA7134_MAIN_CTRL_VPLLE | 663 SAA7134_MAIN_CTRL_APLLE | 664 SAA7134_MAIN_CTRL_EXOSC | 665 SAA7134_MAIN_CTRL_EVFE1 | 666 SAA7134_MAIN_CTRL_EVFE2 | 667 SAA7134_MAIN_CTRL_ESFE | 668 SAA7134_MAIN_CTRL_EBDAC); 669 670 /* 671 * Initialize OSS _after_ enabling audio clock PLL and audio processing. 672 * OSS initialization writes to registers via the audio DSP; these 673 * writes will fail unless the audio clock has been started. At worst, 674 * audio will not work. 675 */ 676 677 /* enable peripheral devices */ 678 saa_writeb(SAA7134_SPECIAL_MODE, 0x01); 679 680 /* set vertical line numbering start (vbi needs this) */ 681 saa_writeb(SAA7134_SOURCE_TIMING2, 0x20); 682 683 return 0; 684 } 685 686 static int saa7134_hwinit1(struct saa7134_dev *dev) 687 { 688 core_dbg("hwinit1\n"); 689 690 saa_writel(SAA7134_IRQ1, 0); 691 saa_writel(SAA7134_IRQ2, 0); 692 693 /* Clear any stale IRQ reports */ 694 saa_writel(SAA7134_IRQ_REPORT, saa_readl(SAA7134_IRQ_REPORT)); 695 696 mutex_init(&dev->lock); 697 spin_lock_init(&dev->slock); 698 699 saa7134_track_gpio(dev,"pre-init"); 700 saa7134_video_init1(dev); 701 saa7134_vbi_init1(dev); 702 if (card_has_mpeg(dev)) 703 saa7134_ts_init1(dev); 704 saa7134_input_init1(dev); 705 706 saa7134_hw_enable1(dev); 707 708 return 0; 709 } 710 711 /* late init (with i2c + irq) */ 712 static int saa7134_hw_enable2(struct saa7134_dev *dev) 713 { 714 715 unsigned int irq2_mask; 716 717 /* enable IRQ's */ 718 irq2_mask = 719 SAA7134_IRQ2_INTE_DEC3 | 720 SAA7134_IRQ2_INTE_DEC2 | 721 SAA7134_IRQ2_INTE_DEC1 | 722 SAA7134_IRQ2_INTE_DEC0 | 723 SAA7134_IRQ2_INTE_PE | 724 SAA7134_IRQ2_INTE_AR; 725 726 if (dev->has_remote == SAA7134_REMOTE_GPIO && dev->remote) { 727 if (dev->remote->mask_keydown & 0x10000) 728 irq2_mask |= SAA7134_IRQ2_INTE_GPIO16_N; 729 else { /* Allow enabling both IRQ edge triggers */ 730 if (dev->remote->mask_keydown & 0x40000) 731 irq2_mask |= SAA7134_IRQ2_INTE_GPIO18_P; 732 if (dev->remote->mask_keyup & 0x40000) 733 irq2_mask |= SAA7134_IRQ2_INTE_GPIO18_N; 734 } 735 } 736 737 if (dev->has_remote == SAA7134_REMOTE_I2C) { 738 request_module("ir-kbd-i2c"); 739 } 740 741 saa_writel(SAA7134_IRQ1, 0); 742 saa_writel(SAA7134_IRQ2, irq2_mask); 743 744 return 0; 745 } 746 747 static int saa7134_hwinit2(struct saa7134_dev *dev) 748 { 749 750 core_dbg("hwinit2\n"); 751 752 saa7134_video_init2(dev); 753 saa7134_tvaudio_init2(dev); 754 755 saa7134_hw_enable2(dev); 756 757 return 0; 758 } 759 760 761 /* shutdown */ 762 static int saa7134_hwfini(struct saa7134_dev *dev) 763 { 764 core_dbg("hwfini\n"); 765 766 if (card_has_mpeg(dev)) 767 saa7134_ts_fini(dev); 768 saa7134_input_fini(dev); 769 saa7134_vbi_fini(dev); 770 saa7134_tvaudio_fini(dev); 771 saa7134_video_fini(dev); 772 return 0; 773 } 774 775 static void must_configure_manually(int has_eeprom) 776 { 777 unsigned int i,p; 778 779 if (!has_eeprom) 780 pr_warn("saa7134: <rant>\n" 781 "saa7134: Congratulations! Your TV card vendor saved a few\n" 782 "saa7134: cents for a eeprom, thus your pci board has no\n" 783 "saa7134: subsystem ID and I can't identify it automatically\n" 784 "saa7134: </rant>\n" 785 "saa7134: I feel better now. Ok, here are the good news:\n" 786 "saa7134: You can use the card=<nr> insmod option to specify\n" 787 "saa7134: which board do you have. The list:\n"); 788 else 789 pr_warn("saa7134: Board is currently unknown. You might try to use the card=<nr>\n" 790 "saa7134: insmod option to specify which board do you have, but this is\n" 791 "saa7134: somewhat risky, as might damage your card. It is better to ask\n" 792 "saa7134: for support at linux-media@vger.kernel.org.\n" 793 "saa7134: The supported cards are:\n"); 794 795 for (i = 0; i < saa7134_bcount; i++) { 796 pr_warn("saa7134: card=%d -> %-40.40s", 797 i,saa7134_boards[i].name); 798 for (p = 0; saa7134_pci_tbl[p].driver_data; p++) { 799 if (saa7134_pci_tbl[p].driver_data != i) 800 continue; 801 pr_cont(" %04x:%04x", 802 saa7134_pci_tbl[p].subvendor, 803 saa7134_pci_tbl[p].subdevice); 804 } 805 pr_cont("\n"); 806 } 807 } 808 809 static struct video_device *vdev_init(struct saa7134_dev *dev, 810 struct video_device *template, 811 char *type) 812 { 813 struct video_device *vfd; 814 815 vfd = video_device_alloc(); 816 if (NULL == vfd) 817 return NULL; 818 *vfd = *template; 819 vfd->v4l2_dev = &dev->v4l2_dev; 820 vfd->release = video_device_release; 821 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 822 dev->name, type, saa7134_boards[dev->board].name); 823 video_set_drvdata(vfd, dev); 824 return vfd; 825 } 826 827 static void saa7134_unregister_video(struct saa7134_dev *dev) 828 { 829 if (dev->video_dev) { 830 if (video_is_registered(dev->video_dev)) 831 video_unregister_device(dev->video_dev); 832 else 833 video_device_release(dev->video_dev); 834 dev->video_dev = NULL; 835 } 836 if (dev->vbi_dev) { 837 if (video_is_registered(dev->vbi_dev)) 838 video_unregister_device(dev->vbi_dev); 839 else 840 video_device_release(dev->vbi_dev); 841 dev->vbi_dev = NULL; 842 } 843 if (dev->radio_dev) { 844 if (video_is_registered(dev->radio_dev)) 845 video_unregister_device(dev->radio_dev); 846 else 847 video_device_release(dev->radio_dev); 848 dev->radio_dev = NULL; 849 } 850 } 851 852 static void mpeg_ops_attach(struct saa7134_mpeg_ops *ops, 853 struct saa7134_dev *dev) 854 { 855 int err; 856 857 if (NULL != dev->mops) 858 return; 859 if (saa7134_boards[dev->board].mpeg != ops->type) 860 return; 861 err = ops->init(dev); 862 if (0 != err) 863 return; 864 dev->mops = ops; 865 } 866 867 static void mpeg_ops_detach(struct saa7134_mpeg_ops *ops, 868 struct saa7134_dev *dev) 869 { 870 if (NULL == dev->mops) 871 return; 872 if (dev->mops != ops) 873 return; 874 dev->mops->fini(dev); 875 dev->mops = NULL; 876 } 877 878 static int saa7134_initdev(struct pci_dev *pci_dev, 879 const struct pci_device_id *pci_id) 880 { 881 struct saa7134_dev *dev; 882 struct saa7134_mpeg_ops *mops; 883 int err; 884 885 if (saa7134_devcount == SAA7134_MAXBOARDS) 886 return -ENOMEM; 887 888 dev = kzalloc(sizeof(*dev),GFP_KERNEL); 889 if (NULL == dev) 890 return -ENOMEM; 891 892 err = v4l2_device_register(&pci_dev->dev, &dev->v4l2_dev); 893 if (err) 894 goto fail0; 895 896 /* pci init */ 897 dev->pci = pci_dev; 898 if (pci_enable_device(pci_dev)) { 899 err = -EIO; 900 goto fail1; 901 } 902 903 dev->nr = saa7134_devcount; 904 sprintf(dev->name,"saa%x[%d]",pci_dev->device,dev->nr); 905 906 /* pci quirks */ 907 if (pci_pci_problems) { 908 if (pci_pci_problems & PCIPCI_TRITON) 909 pr_info("%s: quirk: PCIPCI_TRITON\n", dev->name); 910 if (pci_pci_problems & PCIPCI_NATOMA) 911 pr_info("%s: quirk: PCIPCI_NATOMA\n", dev->name); 912 if (pci_pci_problems & PCIPCI_VIAETBF) 913 pr_info("%s: quirk: PCIPCI_VIAETBF\n", dev->name); 914 if (pci_pci_problems & PCIPCI_VSFX) 915 pr_info("%s: quirk: PCIPCI_VSFX\n", dev->name); 916 #ifdef PCIPCI_ALIMAGIK 917 if (pci_pci_problems & PCIPCI_ALIMAGIK) { 918 pr_info("%s: quirk: PCIPCI_ALIMAGIK -- latency fixup\n", 919 dev->name); 920 latency = 0x0A; 921 } 922 #endif 923 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL)) { 924 pr_info("%s: quirk: this driver and your " 925 "chipset may not work together" 926 " in overlay mode.\n",dev->name); 927 if (!saa7134_no_overlay) { 928 pr_info("%s: quirk: overlay " 929 "mode will be disabled.\n", 930 dev->name); 931 saa7134_no_overlay = 1; 932 } else { 933 pr_info("%s: quirk: overlay " 934 "mode will be forced. Use this" 935 " option at your own risk.\n", 936 dev->name); 937 } 938 } 939 } 940 if (UNSET != latency) { 941 pr_info("%s: setting pci latency timer to %d\n", 942 dev->name,latency); 943 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency); 944 } 945 946 /* print pci info */ 947 dev->pci_rev = pci_dev->revision; 948 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat); 949 pr_info("%s: found at %s, rev: %d, irq: %d, " 950 "latency: %d, mmio: 0x%llx\n", dev->name, 951 pci_name(pci_dev), dev->pci_rev, pci_dev->irq, 952 dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0)); 953 pci_set_master(pci_dev); 954 err = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32)); 955 if (err) { 956 pr_warn("%s: Oops: no 32bit PCI DMA ???\n", dev->name); 957 goto fail1; 958 } 959 960 /* board config */ 961 dev->board = pci_id->driver_data; 962 if ((unsigned)card[dev->nr] < saa7134_bcount) 963 dev->board = card[dev->nr]; 964 if (SAA7134_BOARD_UNKNOWN == dev->board) 965 must_configure_manually(0); 966 else if (SAA7134_BOARD_NOAUTO == dev->board) { 967 must_configure_manually(1); 968 dev->board = SAA7134_BOARD_UNKNOWN; 969 } 970 dev->autodetected = card[dev->nr] != dev->board; 971 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 972 dev->tuner_addr = saa7134_boards[dev->board].tuner_addr; 973 dev->radio_type = saa7134_boards[dev->board].radio_type; 974 dev->radio_addr = saa7134_boards[dev->board].radio_addr; 975 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf; 976 if (UNSET != tuner[dev->nr]) 977 dev->tuner_type = tuner[dev->nr]; 978 pr_info("%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n", 979 dev->name,pci_dev->subsystem_vendor, 980 pci_dev->subsystem_device,saa7134_boards[dev->board].name, 981 dev->board, dev->autodetected ? 982 "autodetected" : "insmod option"); 983 984 /* get mmio */ 985 if (!request_mem_region(pci_resource_start(pci_dev,0), 986 pci_resource_len(pci_dev,0), 987 dev->name)) { 988 err = -EBUSY; 989 pr_err("%s: can't get MMIO memory @ 0x%llx\n", 990 dev->name,(unsigned long long)pci_resource_start(pci_dev,0)); 991 goto fail1; 992 } 993 dev->lmmio = ioremap(pci_resource_start(pci_dev, 0), 994 pci_resource_len(pci_dev, 0)); 995 dev->bmmio = (__u8 __iomem *)dev->lmmio; 996 if (NULL == dev->lmmio) { 997 err = -EIO; 998 pr_err("%s: can't ioremap() MMIO memory\n", 999 dev->name); 1000 goto fail2; 1001 } 1002 1003 /* initialize hardware #1 */ 1004 saa7134_board_init1(dev); 1005 saa7134_hwinit1(dev); 1006 1007 dev->alloc_ctx = vb2_dma_sg_init_ctx(&pci_dev->dev); 1008 if (IS_ERR(dev->alloc_ctx)) { 1009 err = PTR_ERR(dev->alloc_ctx); 1010 goto fail3; 1011 } 1012 /* get irq */ 1013 err = request_irq(pci_dev->irq, saa7134_irq, 1014 IRQF_SHARED, dev->name, dev); 1015 if (err < 0) { 1016 pr_err("%s: can't get IRQ %d\n", 1017 dev->name,pci_dev->irq); 1018 goto fail4; 1019 } 1020 1021 /* wait a bit, register i2c bus */ 1022 msleep(100); 1023 saa7134_i2c_register(dev); 1024 saa7134_board_init2(dev); 1025 1026 saa7134_hwinit2(dev); 1027 1028 /* load i2c helpers */ 1029 if (card_is_empress(dev)) { 1030 dev->empress_sd = 1031 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 1032 "saa6752hs", 1033 saa7134_boards[dev->board].empress_addr, NULL); 1034 1035 if (dev->empress_sd) 1036 dev->empress_sd->grp_id = GRP_EMPRESS; 1037 } 1038 1039 if (saa7134_boards[dev->board].rds_addr) { 1040 struct v4l2_subdev *sd; 1041 1042 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1043 &dev->i2c_adap, "saa6588", 1044 0, I2C_ADDRS(saa7134_boards[dev->board].rds_addr)); 1045 if (sd) { 1046 pr_info("%s: found RDS decoder\n", dev->name); 1047 dev->has_rds = 1; 1048 } 1049 } 1050 1051 mutex_lock(&saa7134_devlist_lock); 1052 list_for_each_entry(mops, &mops_list, next) 1053 mpeg_ops_attach(mops, dev); 1054 list_add_tail(&dev->devlist, &saa7134_devlist); 1055 mutex_unlock(&saa7134_devlist_lock); 1056 1057 /* check for signal */ 1058 saa7134_irq_video_signalchange(dev); 1059 1060 if (TUNER_ABSENT != dev->tuner_type) 1061 saa_call_all(dev, core, s_power, 0); 1062 1063 /* register v4l devices */ 1064 if (saa7134_no_overlay > 0) 1065 pr_info("%s: Overlay support disabled.\n", dev->name); 1066 1067 dev->video_dev = vdev_init(dev,&saa7134_video_template,"video"); 1068 dev->video_dev->ctrl_handler = &dev->ctrl_handler; 1069 dev->video_dev->lock = &dev->lock; 1070 dev->video_dev->queue = &dev->video_vbq; 1071 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER, 1072 video_nr[dev->nr]); 1073 if (err < 0) { 1074 pr_info("%s: can't register video device\n", 1075 dev->name); 1076 goto fail5; 1077 } 1078 pr_info("%s: registered device %s [v4l2]\n", 1079 dev->name, video_device_node_name(dev->video_dev)); 1080 1081 dev->vbi_dev = vdev_init(dev, &saa7134_video_template, "vbi"); 1082 dev->vbi_dev->ctrl_handler = &dev->ctrl_handler; 1083 dev->vbi_dev->lock = &dev->lock; 1084 dev->vbi_dev->queue = &dev->vbi_vbq; 1085 1086 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, 1087 vbi_nr[dev->nr]); 1088 if (err < 0) 1089 goto fail5; 1090 pr_info("%s: registered device %s\n", 1091 dev->name, video_device_node_name(dev->vbi_dev)); 1092 1093 if (card_has_radio(dev)) { 1094 dev->radio_dev = vdev_init(dev,&saa7134_radio_template,"radio"); 1095 dev->radio_dev->ctrl_handler = &dev->radio_ctrl_handler; 1096 dev->radio_dev->lock = &dev->lock; 1097 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO, 1098 radio_nr[dev->nr]); 1099 if (err < 0) 1100 goto fail5; 1101 pr_info("%s: registered device %s\n", 1102 dev->name, video_device_node_name(dev->radio_dev)); 1103 } 1104 1105 /* everything worked */ 1106 saa7134_devcount++; 1107 1108 if (saa7134_dmasound_init && !dev->dmasound.priv_data) 1109 saa7134_dmasound_init(dev); 1110 1111 request_submodules(dev); 1112 return 0; 1113 1114 fail5: 1115 saa7134_unregister_video(dev); 1116 saa7134_i2c_unregister(dev); 1117 free_irq(pci_dev->irq, dev); 1118 fail4: 1119 vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); 1120 fail3: 1121 saa7134_hwfini(dev); 1122 iounmap(dev->lmmio); 1123 fail2: 1124 release_mem_region(pci_resource_start(pci_dev,0), 1125 pci_resource_len(pci_dev,0)); 1126 fail1: 1127 v4l2_device_unregister(&dev->v4l2_dev); 1128 fail0: 1129 kfree(dev); 1130 return err; 1131 } 1132 1133 static void saa7134_finidev(struct pci_dev *pci_dev) 1134 { 1135 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); 1136 struct saa7134_dev *dev = container_of(v4l2_dev, struct saa7134_dev, v4l2_dev); 1137 struct saa7134_mpeg_ops *mops; 1138 1139 flush_request_submodules(dev); 1140 1141 /* Release DMA sound modules if present */ 1142 if (saa7134_dmasound_exit && dev->dmasound.priv_data) { 1143 saa7134_dmasound_exit(dev); 1144 } 1145 1146 /* debugging ... */ 1147 if (irq_debug) { 1148 u32 report = saa_readl(SAA7134_IRQ_REPORT); 1149 u32 status = saa_readl(SAA7134_IRQ_STATUS); 1150 print_irqstatus(dev,42,report,status); 1151 } 1152 1153 /* disable peripheral devices */ 1154 saa_writeb(SAA7134_SPECIAL_MODE,0); 1155 1156 /* shutdown hardware */ 1157 saa_writel(SAA7134_IRQ1,0); 1158 saa_writel(SAA7134_IRQ2,0); 1159 saa_writel(SAA7134_MAIN_CTRL,0); 1160 1161 /* shutdown subsystems */ 1162 saa7134_hwfini(dev); 1163 1164 /* unregister */ 1165 mutex_lock(&saa7134_devlist_lock); 1166 list_del(&dev->devlist); 1167 list_for_each_entry(mops, &mops_list, next) 1168 mpeg_ops_detach(mops, dev); 1169 mutex_unlock(&saa7134_devlist_lock); 1170 saa7134_devcount--; 1171 1172 saa7134_i2c_unregister(dev); 1173 saa7134_unregister_video(dev); 1174 1175 1176 /* the DMA sound modules should be unloaded before reaching 1177 this, but just in case they are still present... */ 1178 if (dev->dmasound.priv_data != NULL) { 1179 free_irq(pci_dev->irq, &dev->dmasound); 1180 dev->dmasound.priv_data = NULL; 1181 } 1182 1183 1184 /* release resources */ 1185 free_irq(pci_dev->irq, dev); 1186 vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); 1187 iounmap(dev->lmmio); 1188 release_mem_region(pci_resource_start(pci_dev,0), 1189 pci_resource_len(pci_dev,0)); 1190 1191 1192 v4l2_device_unregister(&dev->v4l2_dev); 1193 1194 /* free memory */ 1195 kfree(dev); 1196 } 1197 1198 #ifdef CONFIG_PM 1199 1200 /* resends a current buffer in queue after resume */ 1201 static int saa7134_buffer_requeue(struct saa7134_dev *dev, 1202 struct saa7134_dmaqueue *q) 1203 { 1204 struct saa7134_buf *buf, *next; 1205 1206 assert_spin_locked(&dev->slock); 1207 1208 buf = q->curr; 1209 next = buf; 1210 core_dbg("buffer_requeue\n"); 1211 1212 if (!buf) 1213 return 0; 1214 1215 core_dbg("buffer_requeue : resending active buffer\n"); 1216 1217 if (!list_empty(&q->queue)) 1218 next = list_entry(q->queue.next, struct saa7134_buf, 1219 entry); 1220 buf->activate(dev, buf, next); 1221 1222 return 0; 1223 } 1224 1225 static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state) 1226 { 1227 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); 1228 struct saa7134_dev *dev = container_of(v4l2_dev, struct saa7134_dev, v4l2_dev); 1229 1230 /* disable overlay - apps should enable it explicitly on resume*/ 1231 dev->ovenable = 0; 1232 1233 /* Disable interrupts, DMA, and rest of the chip*/ 1234 saa_writel(SAA7134_IRQ1, 0); 1235 saa_writel(SAA7134_IRQ2, 0); 1236 saa_writel(SAA7134_MAIN_CTRL, 0); 1237 1238 dev->insuspend = 1; 1239 synchronize_irq(pci_dev->irq); 1240 1241 /* ACK interrupts once more, just in case, 1242 since the IRQ handler won't ack them anymore*/ 1243 1244 saa_writel(SAA7134_IRQ_REPORT, saa_readl(SAA7134_IRQ_REPORT)); 1245 1246 /* Disable timeout timers - if we have active buffers, we will 1247 fill them on resume*/ 1248 1249 del_timer(&dev->video_q.timeout); 1250 del_timer(&dev->vbi_q.timeout); 1251 del_timer(&dev->ts_q.timeout); 1252 1253 if (dev->remote) 1254 saa7134_ir_stop(dev); 1255 1256 pci_save_state(pci_dev); 1257 pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state)); 1258 1259 return 0; 1260 } 1261 1262 static int saa7134_resume(struct pci_dev *pci_dev) 1263 { 1264 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); 1265 struct saa7134_dev *dev = container_of(v4l2_dev, struct saa7134_dev, v4l2_dev); 1266 unsigned long flags; 1267 1268 pci_set_power_state(pci_dev, PCI_D0); 1269 pci_restore_state(pci_dev); 1270 1271 /* Do things that are done in saa7134_initdev , 1272 except of initializing memory structures.*/ 1273 1274 saa7134_board_init1(dev); 1275 1276 /* saa7134_hwinit1 */ 1277 if (saa7134_boards[dev->board].video_out) 1278 saa7134_videoport_init(dev); 1279 if (card_has_mpeg(dev)) 1280 saa7134_ts_init_hw(dev); 1281 if (dev->remote) 1282 saa7134_ir_start(dev); 1283 saa7134_hw_enable1(dev); 1284 1285 msleep(100); 1286 1287 saa7134_board_init2(dev); 1288 1289 /*saa7134_hwinit2*/ 1290 saa7134_set_tvnorm_hw(dev); 1291 saa7134_tvaudio_setmute(dev); 1292 saa7134_tvaudio_setvolume(dev, dev->ctl_volume); 1293 saa7134_tvaudio_init(dev); 1294 saa7134_enable_i2s(dev); 1295 saa7134_hw_enable2(dev); 1296 1297 saa7134_irq_video_signalchange(dev); 1298 1299 /*resume unfinished buffer(s)*/ 1300 spin_lock_irqsave(&dev->slock, flags); 1301 saa7134_buffer_requeue(dev, &dev->video_q); 1302 saa7134_buffer_requeue(dev, &dev->vbi_q); 1303 saa7134_buffer_requeue(dev, &dev->ts_q); 1304 1305 /* FIXME: Disable DMA audio sound - temporary till proper support 1306 is implemented*/ 1307 1308 dev->dmasound.dma_running = 0; 1309 1310 /* start DMA now*/ 1311 dev->insuspend = 0; 1312 smp_wmb(); 1313 saa7134_set_dmabits(dev); 1314 spin_unlock_irqrestore(&dev->slock, flags); 1315 1316 return 0; 1317 } 1318 #endif 1319 1320 /* ----------------------------------------------------------- */ 1321 1322 int saa7134_ts_register(struct saa7134_mpeg_ops *ops) 1323 { 1324 struct saa7134_dev *dev; 1325 1326 mutex_lock(&saa7134_devlist_lock); 1327 list_for_each_entry(dev, &saa7134_devlist, devlist) 1328 mpeg_ops_attach(ops, dev); 1329 list_add_tail(&ops->next,&mops_list); 1330 mutex_unlock(&saa7134_devlist_lock); 1331 return 0; 1332 } 1333 1334 void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops) 1335 { 1336 struct saa7134_dev *dev; 1337 1338 mutex_lock(&saa7134_devlist_lock); 1339 list_del(&ops->next); 1340 list_for_each_entry(dev, &saa7134_devlist, devlist) 1341 mpeg_ops_detach(ops, dev); 1342 mutex_unlock(&saa7134_devlist_lock); 1343 } 1344 1345 EXPORT_SYMBOL(saa7134_ts_register); 1346 EXPORT_SYMBOL(saa7134_ts_unregister); 1347 1348 /* ----------------------------------------------------------- */ 1349 1350 static struct pci_driver saa7134_pci_driver = { 1351 .name = "saa7134", 1352 .id_table = saa7134_pci_tbl, 1353 .probe = saa7134_initdev, 1354 .remove = saa7134_finidev, 1355 #ifdef CONFIG_PM 1356 .suspend = saa7134_suspend, 1357 .resume = saa7134_resume 1358 #endif 1359 }; 1360 1361 static int __init saa7134_init(void) 1362 { 1363 INIT_LIST_HEAD(&saa7134_devlist); 1364 pr_info("saa7130/34: v4l2 driver version %s loaded\n", 1365 SAA7134_VERSION); 1366 return pci_register_driver(&saa7134_pci_driver); 1367 } 1368 1369 static void __exit saa7134_fini(void) 1370 { 1371 pci_unregister_driver(&saa7134_pci_driver); 1372 } 1373 1374 module_init(saa7134_init); 1375 module_exit(saa7134_fini); 1376 1377 /* ----------------------------------------------------------- */ 1378 1379 EXPORT_SYMBOL(saa7134_set_gpio); 1380 EXPORT_SYMBOL(saa7134_boards); 1381 1382 /* ----------------- for the DMA sound modules --------------- */ 1383 1384 EXPORT_SYMBOL(saa7134_dmasound_init); 1385 EXPORT_SYMBOL(saa7134_dmasound_exit); 1386 EXPORT_SYMBOL(saa7134_pgtable_free); 1387 EXPORT_SYMBOL(saa7134_pgtable_build); 1388 EXPORT_SYMBOL(saa7134_pgtable_alloc); 1389 EXPORT_SYMBOL(saa7134_set_dmabits); 1390