24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
29 #include <linux/sound.h>
47 static unsigned int irq_debug;
51 static unsigned int core_debug;
55 static unsigned int gpio_tracking;
59 static unsigned int alsa = 1;
70 " [some VIA/SIS chipsets are known to have problem with overlay]");
96 static unsigned int saa7134_devcount;
101 #define dprintk(fmt, arg...) if (core_debug) \
102 printk(KERN_DEBUG "%s/core: " fmt, dev->name , ## arg)
116 "%s: gpio: mode=0x%07lx in=0x%07lx out=0x%07lx [%s]\n",
117 dev->
name, mode, (~mode) & status, mode & status, msg);
127 case 1:
dprintk(
"setting GPIO%d to static %d\n", bit_no, value);
129 if (index & 0x00c00000)
139 dprintk(
"setting GPIO%d to tristate\n", bit_no);
151 #if defined(CONFIG_MODULES) && defined(MODULE)
156 request_module(
"saa7134-empress");
158 request_module(
"saa7134-dvb");
161 request_module(
"saa7134-alsa");
177 #define request_submodules(dev)
178 #define flush_request_submodules(dev)
184 static int saa7134_buffer_pages(
int size)
196 unsigned int maxcount;
198 maxcount = 1024 / saa7134_buffer_pages(size);
199 if (count > maxcount)
206 return saa7134_buffer_pages(buf->
vb.bsize) * buf->
vb.i;
215 base += dma->
sglist[0].offset;
237 unsigned int startpage)
244 ptr = pt->
cpu + startpage;
245 for (i = 0; i <
length; i++, list++)
246 for (p = 0; p * 4096 < list->
length; p++, ptr++)
281 dprintk(
"buffer_queue %p\n",buf);
286 }
else if (list_empty(&q->
queue)) {
324 if (!list_empty(&q->
queue)) {
327 dprintk(
"buffer_next %p [prev=%p/next=%p]\n",
330 if (!list_empty(&q->
queue))
335 dprintk(
"buffer_next #2 prev=%p/next=%p\n",
369 spin_unlock_irqrestore(&dev->
slock,flags);
391 cap = dev->
video_q.curr->vb.field;
396 dev->
video_q.curr->fmt->planar) {
409 if (dev->
vbi_q.curr) {
427 if (dev->
ts_q.curr) {
469 dprintk(
"dmabits: task=0x%02x ctrl=0x%02x irq=0x%x split=%s\n",
470 task,
ctrl,
irq, split ?
"no" :
"yes");
478 static char *irqbits[] = {
479 "DONE_RA0",
"DONE_RA1",
"DONE_RA2",
"DONE_RA3",
480 "AR",
"PE",
"PWR_ON",
"RDCAP",
"INTL",
"FIDT",
"MMC",
481 "TRIG_ERR",
"CONF_ERR",
"LOAD_ERR",
482 "GPIO16",
"GPIO18",
"GPIO22",
"GPIO23"
484 #define IRQBITS ARRAY_SIZE(irqbits)
486 static void print_irqstatus(
struct saa7134_dev *dev,
int loop,
493 for (i = 0; i <
IRQBITS; i++) {
494 if (!(report & (1 << i)))
499 printk(
" | RA0=%s,%s,%s,%ld",
500 (status & 0x40) ?
"vbi" :
"video",
501 (status & 0x20) ?
"b" :
"a",
502 (status & 0x10) ?
"odd" :
"even",
512 int loop, handled = 0;
517 for (loop = 0; loop < 10; loop++) {
530 report &= ~SAA7134_IRQ_REPORT_DONE_RA3;
543 print_irqstatus(dev,loop,report,status);
552 (status & 0x60) == 0)
555 if ((report & SAA7134_IRQ_REPORT_DONE_RA0) &&
556 (status & 0x40) == 0x40)
568 if (dev->
remote->mask_keydown & 0x10000) {
586 if ((dev->
remote->mask_keydown & 0x40000) ||
587 (dev->
remote->mask_keyup & 0x40000)) {
602 print_irqstatus(dev,loop,report,status);
606 "clearing PE (parity error!) enable bit\n",dev->
name);
608 }
else if (report & SAA7134_IRQ_REPORT_GPIO16) {
611 "clearing GPIO16 enable bit\n",dev->
name);
614 }
else if (report & SAA7134_IRQ_REPORT_GPIO18) {
617 "clearing GPIO18 enable bit\n",dev->
name);
623 "clearing all enable bits\n",dev->
name);
637 static int saa7134_hw_enable1(
struct saa7134_dev *dev)
669 static int saa7134_hwinit1(
struct saa7134_dev *dev)
689 saa7134_hw_enable1(dev);
695 static int saa7134_hw_enable2(
struct saa7134_dev *dev)
698 unsigned int irq2_mask;
710 if (dev->
remote->mask_keydown & 0x10000)
713 if (dev->
remote->mask_keydown & 0x40000)
715 if (dev->
remote->mask_keyup & 0x40000)
721 request_module(
"ir-kbd-i2c");
730 static int saa7134_hwinit2(
struct saa7134_dev *dev)
738 saa7134_hw_enable2(dev);
757 static void __devinit must_configure_manually(
int has_eeprom)
764 "saa7134: Congratulations! Your TV card vendor saved a few\n"
765 "saa7134: cents for a eeprom, thus your pci board has no\n"
766 "saa7134: subsystem ID and I can't identify it automatically\n"
768 "saa7134: I feel better now. Ok, here are the good news:\n"
769 "saa7134: You can use the card=<nr> insmod option to specify\n"
770 "saa7134: which board do you have. The list:\n");
773 "saa7134: Board is currently unknown. You might try to use the card=<nr>\n"
774 "saa7134: insmod option to specify which board do you have, but this is\n"
775 "saa7134: somewhat risky, as might damage your card. It is better to ask\n"
777 "saa7134: The supported cards are:\n");
808 video_set_drvdata(vfd, dev);
812 static void saa7134_unregister_video(
struct saa7134_dev *dev)
822 if (video_is_registered(dev->
vbi_dev))
846 err = ops->
init(dev);
857 if (dev->
mops != ops)
859 dev->
mops->fini(dev);
888 dev->
nr = saa7134_devcount;
901 #ifdef PCIPCI_ALIMAGIK
910 "chipset may not work together"
911 " in overlay mode.\n",dev->
name);
914 "mode will be disabled.\n",
919 "mode will be forced. Use this"
920 " option at your own risk.\n",
935 "latency: %d, mmio: 0x%llx\n", dev->
name,
936 pci_name(pci_dev), dev->
pci_rev, pci_dev->
irq,
940 printk(
"%s: Oops: no 32bit PCI DMA ???\n",dev->
name);
947 if (card[dev->
nr] >= 0 &&
948 card[dev->
nr] < saa7134_bcount)
951 must_configure_manually(0);
953 must_configure_manually(1);
968 "autodetected" :
"insmod option");
991 saa7134_hwinit1(dev);
1007 saa7134_hwinit2(dev);
1036 mpeg_ops_attach(mops, dev);
1043 if (TUNER_ABSENT != dev->tuner_type)
1090 saa7134_unregister_video(dev);
1094 saa7134_hwfini(dev);
1106 static void __devexit saa7134_finidev(
struct pci_dev *pci_dev)
1123 print_irqstatus(dev,42,report,status);
1135 saa7134_hwfini(dev);
1141 mpeg_ops_detach(mops, dev);
1146 saa7134_unregister_video(dev);
1153 dev->dmasound.priv_data =
NULL;
1173 static int saa7134_buffer_requeue(
struct saa7134_dev *dev,
1187 dprintk(
"buffer_requeue : resending active buffers \n");
1189 if (!list_empty(&q->
queue))
1199 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
1234 static int saa7134_resume(
struct pci_dev *pci_dev)
1236 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
1238 unsigned long flags;
1255 saa7134_hw_enable1(dev);
1267 saa7134_hw_enable2(dev);
1273 saa7134_buffer_requeue(dev, &dev->
video_q);
1274 saa7134_buffer_requeue(dev, &dev->
vbi_q);
1275 saa7134_buffer_requeue(dev, &dev->
ts_q);
1286 spin_unlock_irqrestore(&dev->
slock, flags);
1300 mpeg_ops_attach(ops, dev);
1313 mpeg_ops_detach(ops, dev);
1322 static struct pci_driver saa7134_pci_driver = {
1325 .probe = saa7134_initdev,
1328 .suspend = saa7134_suspend,
1329 .resume = saa7134_resume
1333 static int __init saa7134_init(
void)
1335 INIT_LIST_HEAD(&saa7134_devlist);
1338 return pci_register_driver(&saa7134_pci_driver);
1341 static void __exit saa7134_fini(
void)