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