23 #include <linux/list.h>
24 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
31 #include <asm/div64.h>
86 "enable dma sanity checking for buffer overruns");
88 static unsigned int saa7164_devcount;
102 if ((*(p +
i + 0) != 0x00) || (*(p +
i + 1) != 0x00) ||
103 (*(p +
i + 2) != 0x01) || (*(p +
i + 3) != 0xBA)) {
113 #define FIXED_VIDEO_PID 0xf1
114 #define FIXED_AUDIO_PID 0xf2
129 if (*(bufcpu + i) != 0x47)
133 pid = ((*(bufcpu + i + 1) & 0x1f) << 8) | *(bufcpu + i + 2);
134 cc = *(bufcpu + i + 3) & 0x0f;
184 for (i = 0; i < 30; i++)
188 for (i = 0; i < 18; i++)
189 hg->
counter1[30 + i].val = 30 + (i * 10);
192 for (i = 0; i < 15; i++)
193 hg->
counter1[48 + i].val = 200 + (i * 200);
226 for (i = 0; i < 64; i++) {
227 if (val <= hg->counter1[i].val) {
242 for (i = 0; i < 64; i++) {
256 static void saa7164_work_enchandler_helper(
struct saa7164_port *port,
int bufnr)
269 if (i++ > port->
hwcfg.buffercount) {
275 if (buf->
idx == bufnr) {
285 if (guard_checking) {
307 saa7164_ts_verifier(buf);
309 saa7164_pack_verifier(buf);
332 list_move_tail(&ubuf->
list,
343 printk(
KERN_ERR "encirq no free buffers, increase param encoder_buffers\n");
361 static void saa7164_work_enchandler(
struct work_struct *
w)
385 "%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
395 if (wp > (port->
hwcfg.buffercount - 1)) {
402 mcb = (port->
hwcfg.buffercount - 1);
413 if ((rp < 0) || (rp > (port->
hwcfg.buffercount - 1))) {
418 saa7164_work_enchandler_helper(port, rp);
427 if (print_histogram == port->
nr) {
434 print_histogram = 64 + port->
nr;
438 static void saa7164_work_vbihandler(
struct work_struct *w)
461 "%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
471 if (wp > (port->
hwcfg.buffercount - 1)) {
478 mcb = (port->
hwcfg.buffercount - 1);
489 if ((rp < 0) || (rp > (port->
hwcfg.buffercount - 1))) {
494 saa7164_work_enchandler_helper(port, rp);
503 if (print_histogram == port->
nr) {
510 print_histogram = 64 + port->
nr;
514 static void saa7164_work_cmdhandler(
struct work_struct *w)
590 if (wp > (port->
hwcfg.buffercount - 1))
595 rp = (port->
hwcfg.buffercount - 1);
603 if (i++ > port->
hwcfg.buffercount)
606 if (buf->
idx == rp) {
610 saa7164_buffer_deliver(buf);
630 int i, handled = 0,
bit;
665 if (((intstat[i] >>
bit) & 0x00000001) == 0)
670 intid = (i * 32) +
bit;
671 if (intid == dev->
intfdesc.bInterruptId) {
674 }
else if (intid == porta->
hwcfg.interruptid) {
677 saa7164_irq_ts(porta);
679 }
else if (intid == portb->
hwcfg.interruptid) {
682 saa7164_irq_ts(portb);
684 }
else if (intid == portc->
hwcfg.interruptid) {
687 saa7164_irq_encoder(portc);
689 }
else if (intid == portd->
hwcfg.interruptid) {
692 saa7164_irq_encoder(portd);
694 }
else if (intid == porte->
hwcfg.interruptid) {
697 saa7164_irq_vbi(porte);
699 }
else if (intid == portf->
hwcfg.interruptid) {
702 saa7164_irq_vbi(portf);
707 "%s() unhandled interrupt "
710 __func__, i,
bit, intid);
735 dprintk(1,
"Firmware status:\n");
749 dprintk(1,
"Device running firmware version %d.%d.%d.%d (0x%x)\n",
750 (reg & 0x0000fc00) >> 10,
751 (reg & 0x000003e0) >> 5,
753 (reg & 0xffff0000) >> 16,
764 dprintk(1,
"--------------------> "
765 "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
767 for (i = 0; i < 0x100; i += 16)
768 dprintk(1,
"region0[0x%08x] = "
769 "%02x %02x %02x %02x %02x %02x %02x %02x"
770 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
790 static void saa7164_dump_hwdesc(
struct saa7164_dev *dev)
792 dprintk(1,
"@0x%p hwdesc sizeof(struct tmComResHWDescr) = %d bytes\n",
796 dprintk(1,
" .bDescriptorType = 0x%x\n", dev->
hwdesc.bDescriptorType);
797 dprintk(1,
" .bDescriptorSubtype = 0x%x\n",
798 dev->
hwdesc.bDescriptorSubtype);
800 dprintk(1,
" .bcdSpecVersion = 0x%x\n", dev->
hwdesc.bcdSpecVersion);
801 dprintk(1,
" .dwClockFrequency = 0x%x\n", dev->
hwdesc.dwClockFrequency);
802 dprintk(1,
" .dwClockUpdateRes = 0x%x\n", dev->
hwdesc.dwClockUpdateRes);
803 dprintk(1,
" .bCapabilities = 0x%x\n", dev->
hwdesc.bCapabilities);
804 dprintk(1,
" .dwDeviceRegistersLocation = 0x%x\n",
805 dev->
hwdesc.dwDeviceRegistersLocation);
807 dprintk(1,
" .dwHostMemoryRegion = 0x%x\n",
808 dev->
hwdesc.dwHostMemoryRegion);
810 dprintk(1,
" .dwHostMemoryRegionSize = 0x%x\n",
811 dev->
hwdesc.dwHostMemoryRegionSize);
813 dprintk(1,
" .dwHostHibernatMemRegion = 0x%x\n",
814 dev->
hwdesc.dwHostHibernatMemRegion);
816 dprintk(1,
" .dwHostHibernatMemRegionSize = 0x%x\n",
817 dev->
hwdesc.dwHostHibernatMemRegionSize);
820 static void saa7164_dump_intfdesc(
struct saa7164_dev *dev)
823 "sizeof(struct tmComResInterfaceDescr) = %d bytes\n",
827 dprintk(1,
" .bDescriptorType = 0x%x\n", dev->
intfdesc.bDescriptorType);
828 dprintk(1,
" .bDescriptorSubtype = 0x%x\n",
836 dprintk(1,
" .bDebugInterruptId = 0x%x\n",
842 static void saa7164_dump_busdesc(
struct saa7164_dev *dev)
844 dprintk(1,
"@0x%p busdesc sizeof(struct tmComResBusDescr) = %d bytes\n",
847 dprintk(1,
" .CommandRing = 0x%016Lx\n", dev->
busdesc.CommandRing);
848 dprintk(1,
" .ResponseRing = 0x%016Lx\n", dev->
busdesc.ResponseRing);
851 dprintk(1,
" .ResponseWrite = 0x%x\n", dev->
busdesc.ResponseWrite);
860 static void saa7164_get_descriptors(
struct saa7164_dev *dev)
873 saa7164_dump_hwdesc(dev);
876 printk(
KERN_ERR "struct struct tmComResInterfaceDescr is mangled\n");
880 saa7164_dump_intfdesc(dev);
882 saa7164_dump_busdesc(dev);
885 static int saa7164_pci_quirks(
struct saa7164_dev *dev)
908 static int saa7164_port_init(
struct saa7164_dev *dev,
int portnr)
915 port = &dev->
ports[portnr];
938 INIT_LIST_HEAD(&port->
dmaqueue.list);
946 saa7164_histogram_reset(&port->
irq_interval,
"irq intervals");
947 saa7164_histogram_reset(&port->
svc_interval,
"deferred intervals");
949 "irq to deferred intervals");
951 "encoder/vbi read() intervals");
953 "encoder/vbi poll() intervals");
958 static int saa7164_dev_setup(
struct saa7164_dev *dev)
964 dev->
nr = saa7164_devcount++;
979 dev->
pci->subsystem_device ==
1007 if (get_resources(dev) < 0) {
1009 "subsystem: %04x:%04x\n",
1010 dev->
name, dev->
pci->subsystem_vendor,
1011 dev->
pci->subsystem_device);
1029 dev->
int_ack = 0x183000 + 0xf90;
1032 "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
1033 dev->
name, dev->
pci->subsystem_vendor,
1036 "insmod option" :
"autodetected");
1038 saa7164_pci_quirks(dev);
1043 static void saa7164_dev_unregister(
struct saa7164_dev *dev)
1045 dprintk(1,
"%s()\n", __func__);
1062 #ifdef CONFIG_PROC_FS
1063 static int saa7164_proc_show(
struct seq_file *
m,
void *
v)
1070 if (saa7164_devcount == 0)
1081 seq_printf(m,
" .m_pdwSetWritePos = 0x%x (0x%08x)\n",
1084 seq_printf(m,
" .m_pdwSetReadPos = 0x%x (0x%08x)\n",
1087 seq_printf(m,
" .m_pdwGetWritePos = 0x%x (0x%08x)\n",
1090 seq_printf(m,
" .m_pdwGetReadPos = 0x%x (0x%08x)\n",
1094 seq_printf(m,
"\n addr 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
1109 seq_printf(m,
"\n addr 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
1129 static int saa7164_proc_open(
struct inode *
inode,
struct file *filp)
1135 .
open = saa7164_proc_open,
1141 static int saa7164_proc_create(
void)
1145 pe = proc_create(
"saa7164",
S_IRUGO,
NULL, &saa7164_proc_fops);
1153 static int saa7164_thread_function(
void *
data)
1157 u64 last_poll_time = 0;
1206 if (saa7164_dev_setup(dev) < 0) {
1215 "latency: %d, mmio: 0x%llx\n", dev->
name,
1216 pci_name(pci_dev), dev->
pci_rev, pci_dev->
irq,
1222 if (!pci_dma_supported(pci_dev, 0xffffffff)) {
1223 printk(
"%s/0: Oops: no 32bit PCI DMA ???\n", dev->
name);
1237 pci_set_drvdata(pci_dev, dev);
1242 dev->
cmds[
i].inuse = 0;
1256 "Failed to boot firmware, no features "
1261 saa7164_get_descriptors(dev);
1268 "Failed to setup the bus, will continue\n");
1276 dprintk(1,
"Bus is operating correctly using "
1277 "version %d.%d.%d.%d (0x%x)\n",
1278 (version & 0x0000fc00) >> 10,
1279 (version & 0x000003e0) >> 5,
1280 (version & 0x0000001f),
1281 (version & 0xffff0000) >> 16,
1285 "Failed to communicate with the firmware\n");
1306 "dvb adapters on porta\n",
1314 "dvb adapters on portb\n",
1322 "mpeg encoder\n", __func__);
1329 "mpeg encoder\n", __func__);
1336 "vbi device\n", __func__);
1343 "vbi device\n", __func__);
1353 "debug kernel thread\n", __func__);
1359 "registering without firmware\n", __func__);
1368 saa7164_dev_unregister(dev);
1374 static void saa7164_shutdown(
struct saa7164_dev *dev)
1376 dprintk(1,
"%s()\n", __func__);
1379 static void __devexit saa7164_finidev(
struct pci_dev *pci_dev)
1381 struct saa7164_dev *dev = pci_get_drvdata(pci_dev);
1407 saa7164_shutdown(dev);
1435 pci_set_drvdata(pci_dev,
NULL);
1441 saa7164_dev_unregister(dev);
1458 static struct pci_driver saa7164_pci_driver = {
1460 .id_table = saa7164_pci_tbl,
1461 .probe = saa7164_initdev,
1468 static int __init saa7164_init(
void)
1472 #ifdef CONFIG_PROC_FS
1473 saa7164_proc_create();
1475 return pci_register_driver(&saa7164_pci_driver);
1478 static void __exit saa7164_fini(
void)
1480 #ifdef CONFIG_PROC_FS