2 * Driver for the NXP SAA7164 PCIe bridge
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/init.h>
23 #include <linux/list.h>
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/kmod.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
30 #include <linux/delay.h>
31 #include <asm/div64.h>
34 #include <linux/proc_fs.h>
38 MODULE_DESCRIPTION("Driver for NXP SAA7164 based TV cards");
39 MODULE_AUTHOR("Steven Toth <stoth@kernellabs.com>");
40 MODULE_LICENSE("GPL");
51 unsigned int saa_debug;
52 module_param_named(debug, saa_debug, int, 0644);
53 MODULE_PARM_DESC(debug, "enable debug messages");
55 unsigned int fw_debug;
56 module_param(fw_debug, int, 0644);
57 MODULE_PARM_DESC(fw_debug, "Firware debug level def:2");
59 unsigned int encoder_buffers = SAA7164_MAX_ENCODER_BUFFERS;
60 module_param(encoder_buffers, int, 0644);
61 MODULE_PARM_DESC(encoder_buffers, "Total buffers in read queue 16-512 def:64");
63 unsigned int vbi_buffers = SAA7164_MAX_VBI_BUFFERS;
64 module_param(vbi_buffers, int, 0644);
65 MODULE_PARM_DESC(vbi_buffers, "Total buffers in read queue 16-512 def:64");
67 unsigned int waitsecs = 10;
68 module_param(waitsecs, int, 0644);
69 MODULE_PARM_DESC(waitsecs, "timeout on firmware messages");
71 static unsigned int card[] = {[0 ... (SAA7164_MAXBOARDS - 1)] = UNSET };
72 module_param_array(card, int, NULL, 0444);
73 MODULE_PARM_DESC(card, "card type");
75 unsigned int print_histogram = 64;
76 module_param(print_histogram, int, 0644);
77 MODULE_PARM_DESC(print_histogram, "print histogram values once");
79 unsigned int crc_checking = 1;
80 module_param(crc_checking, int, 0644);
81 MODULE_PARM_DESC(crc_checking, "enable crc sanity checking on buffers");
83 unsigned int guard_checking = 1;
84 module_param(guard_checking, int, 0644);
85 MODULE_PARM_DESC(guard_checking, "enable dma sanity checking for buffer overruns");
87 static unsigned int saa7164_devcount;
89 static DEFINE_MUTEX(devlist);
90 LIST_HEAD(saa7164_devlist);
94 void saa7164_dumphex16FF(struct saa7164_dev *dev, u8 *buf, int len)
98 memset(&tmp[0], 0xff, sizeof(tmp));
100 printk(KERN_INFO "--------------------> "
101 "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
103 for (i = 0; i < len; i += 16) {
104 if (memcmp(&tmp, buf + i, sizeof(tmp)) != 0) {
105 printk(KERN_INFO " [0x%08x] "
106 "%02x %02x %02x %02x %02x %02x %02x %02x "
107 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
108 *(buf+i+0), *(buf+i+1), *(buf+i+2), *(buf+i+3),
109 *(buf+i+4), *(buf+i+5), *(buf+i+6), *(buf+i+7),
110 *(buf+i+8), *(buf+i+9), *(buf+i+10), *(buf+i+11),
111 *(buf+i+12), *(buf+i+13), *(buf+i+14), *(buf+i+15));
116 static void saa7164_pack_verifier(struct saa7164_buffer *buf)
118 u8 *p = (u8 *)buf->cpu;
121 for (i = 0; i < buf->actual_size; i += 2048) {
123 if ((*(p + i + 0) != 0x00) || (*(p + i + 1) != 0x00) ||
124 (*(p + i + 2) != 0x01) || (*(p + i + 3) != 0xBA)) {
125 printk(KERN_ERR "No pack at 0x%x\n", i);
126 // saa7164_dumphex16FF(buf->port->dev, (p + i), 32);
131 #define FIXED_VIDEO_PID 0xf1
132 #define FIXED_AUDIO_PID 0xf2
134 static void saa7164_ts_verifier(struct saa7164_buffer *buf)
136 struct saa7164_port *port = buf->port;
140 u8 __iomem *bufcpu = (u8 *)buf->cpu;
142 port->sync_errors = 0;
143 port->v_cc_errors = 0;
144 port->a_cc_errors = 0;
146 for (i = 0; i < buf->actual_size; i += 188) {
147 if (*(bufcpu + i) != 0x47)
150 /* TODO: Query pid lower 8 bits, ignoring upper bits intensionally */
151 pid = ((*(bufcpu + i + 1) & 0x1f) << 8) | *(bufcpu + i + 2);
152 cc = *(bufcpu + i + 3) & 0x0f;
154 if (pid == FIXED_VIDEO_PID) {
155 a = ((port->last_v_cc + 1) & 0x0f);
157 printk(KERN_ERR "video cc last = %x current = %x i = %d\n",
158 port->last_v_cc, cc, i);
162 port->last_v_cc = cc;
164 if (pid == FIXED_AUDIO_PID) {
165 a = ((port->last_a_cc + 1) & 0x0f);
167 printk(KERN_ERR "audio cc last = %x current = %x i = %d\n",
168 port->last_a_cc, cc, i);
172 port->last_a_cc = cc;
177 /* Only report errors if we've been through this function atleast
178 * once already and the cached cc values are primed. First time through
179 * always generates errors.
181 if (port->v_cc_errors && (port->done_first_interrupt > 1))
182 printk(KERN_ERR "video pid cc, %d errors\n", port->v_cc_errors);
184 if (port->a_cc_errors && (port->done_first_interrupt > 1))
185 printk(KERN_ERR "audio pid cc, %d errors\n", port->a_cc_errors);
187 if (port->sync_errors && (port->done_first_interrupt > 1))
188 printk(KERN_ERR "sync_errors = %d\n", port->sync_errors);
190 if (port->done_first_interrupt == 1)
191 port->done_first_interrupt++;
194 static void saa7164_histogram_reset(struct saa7164_histogram *hg, char *name)
198 memset(hg, 0, sizeof(struct saa7164_histogram));
199 strcpy(hg->name, name);
201 /* First 30ms x 1ms */
202 for (i = 0; i < 30; i++) {
203 hg->counter1[0 + i].val = i;
206 /* 30 - 200ms x 10ms */
207 for (i = 0; i < 18; i++) {
208 hg->counter1[30 + i].val = 30 + (i * 10);
211 /* 200 - 2000ms x 100ms */
212 for (i = 0; i < 15; i++) {
213 hg->counter1[48 + i].val = 200 + (i * 200);
216 /* Catch all massive value (2secs) */
217 hg->counter1[55].val = 2000;
219 /* Catch all massive value (4secs) */
220 hg->counter1[56].val = 4000;
222 /* Catch all massive value (8secs) */
223 hg->counter1[57].val = 8000;
225 /* Catch all massive value (15secs) */
226 hg->counter1[58].val = 15000;
228 /* Catch all massive value (30secs) */
229 hg->counter1[59].val = 30000;
231 /* Catch all massive value (60secs) */
232 hg->counter1[60].val = 60000;
234 /* Catch all massive value (5mins) */
235 hg->counter1[61].val = 300000;
237 /* Catch all massive value (15mins) */
238 hg->counter1[62].val = 900000;
240 /* Catch all massive values (1hr) */
241 hg->counter1[63].val = 3600000;
244 void saa7164_histogram_update(struct saa7164_histogram *hg, u32 val)
247 for (i = 0; i < 64; i++) {
248 if (val <= hg->counter1[i].val) {
249 hg->counter1[i].count++;
250 hg->counter1[i].update_time = jiffies;
256 static void saa7164_histogram_print(struct saa7164_port *port,
257 struct saa7164_histogram *hg)
262 printk(KERN_ERR "Histogram named %s (ms, count, last_update_jiffy)\n", hg->name);
263 for (i = 0; i < 64; i++) {
264 if (hg->counter1[i].count == 0)
267 printk(KERN_ERR " %4d %12d %Ld\n",
269 hg->counter1[i].count,
270 hg->counter1[i].update_time);
274 printk(KERN_ERR "Total: %d\n", entries);
277 static void saa7164_work_enchandler_helper(struct saa7164_port *port, int bufnr)
279 struct saa7164_dev *dev = port->dev;
280 struct saa7164_buffer *buf = 0;
281 struct saa7164_user_buffer *ubuf = 0;
282 struct list_head *c, *n;
286 mutex_lock(&port->dmaqueue_lock);
287 list_for_each_safe(c, n, &port->dmaqueue.list) {
289 buf = list_entry(c, struct saa7164_buffer, list);
290 if (i++ > port->hwcfg.buffercount) {
291 printk(KERN_ERR "%s() illegal i count %d\n",
296 if (buf->idx == bufnr) {
298 /* Found the buffer, deal with it */
299 dprintk(DBGLVL_IRQ, "%s() bufnr: %d\n", __func__, bufnr);
302 /* Throw a new checksum on the dma buffer */
303 buf->crc = crc32(0, buf->cpu, buf->actual_size);
306 if (guard_checking) {
308 if ((*(p + buf->actual_size + 0) != 0xff) ||
309 (*(p + buf->actual_size + 1) != 0xff) ||
310 (*(p + buf->actual_size + 2) != 0xff) ||
311 (*(p + buf->actual_size + 3) != 0xff) ||
312 (*(p + buf->actual_size + 0x10) != 0xff) ||
313 (*(p + buf->actual_size + 0x11) != 0xff) ||
314 (*(p + buf->actual_size + 0x12) != 0xff) ||
315 (*(p + buf->actual_size + 0x13) != 0xff)) {
316 printk(KERN_ERR "%s() buf %p guard buffer breach\n",
318 // saa7164_dumphex16FF(dev, (p + buf->actual_size) - 32 , 64);
322 if ((port->nr != SAA7164_PORT_VBI1) && (port->nr != SAA7164_PORT_VBI2)) {
323 /* Validate the incoming buffer content */
324 if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_TS)
325 saa7164_ts_verifier(buf);
326 else if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS)
327 saa7164_pack_verifier(buf);
330 /* find a free user buffer and clone to it */
331 if (!list_empty(&port->list_buf_free.list)) {
333 /* Pull the first buffer from the used list */
334 ubuf = list_first_entry(&port->list_buf_free.list,
335 struct saa7164_user_buffer, list);
337 if (buf->actual_size <= ubuf->actual_size) {
339 memcpy_fromio(ubuf->data, buf->cpu,
343 /* Throw a new checksum on the read buffer */
344 ubuf->crc = crc32(0, ubuf->data, ubuf->actual_size);
347 /* Requeue the buffer on the free list */
350 list_move_tail(&ubuf->list,
351 &port->list_buf_used.list);
353 /* Flag any userland waiters */
354 wake_up_interruptible(&port->wait_read);
357 printk(KERN_ERR "buf %p bufsize fails match\n", buf);
361 printk(KERN_ERR "encirq no free buffers, increase param encoder_buffers\n");
363 /* Ensure offset into buffer remains 0, fill buffer
364 * with known bad data. We check for this data at a later point
366 saa7164_buffer_zero_offsets(port, bufnr);
367 memset_io(buf->cpu, 0xff, buf->pci_size);
369 /* Throw yet aanother new checksum on the dma buffer */
370 buf->crc = crc32(0, buf->cpu, buf->actual_size);
376 mutex_unlock(&port->dmaqueue_lock);
379 static void saa7164_work_enchandler(struct work_struct *w)
381 struct saa7164_port *port =
382 container_of(w, struct saa7164_port, workenc);
383 struct saa7164_dev *dev = port->dev;
385 u32 wp, mcb, rp, cnt = 0;
387 port->last_svc_msecs_diff = port->last_svc_msecs;
388 port->last_svc_msecs = jiffies_to_msecs(jiffies);
390 port->last_svc_msecs_diff = port->last_svc_msecs -
391 port->last_svc_msecs_diff;
393 saa7164_histogram_update(&port->svc_interval,
394 port->last_svc_msecs_diff);
396 port->last_irq_svc_msecs_diff = port->last_svc_msecs -
397 port->last_irq_msecs;
399 saa7164_histogram_update(&port->irq_svc_interval,
400 port->last_irq_svc_msecs_diff);
403 "%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
405 port->last_svc_msecs_diff,
406 port->last_irq_svc_msecs_diff,
411 /* Current write position */
412 wp = saa7164_readl(port->bufcounter);
413 if (wp > (port->hwcfg.buffercount - 1)) {
414 printk(KERN_ERR "%s() illegal buf count %d\n", __func__, wp);
418 /* Most current complete buffer */
420 mcb = (port->hwcfg.buffercount - 1);
425 if (port->done_first_interrupt == 0) {
426 port->done_first_interrupt++;
429 rp = (port->last_svc_rp + 1) % 8;
431 if ((rp < 0) || (rp > (port->hwcfg.buffercount - 1))) {
432 printk(KERN_ERR "%s() illegal rp count %d\n", __func__, rp);
436 saa7164_work_enchandler_helper(port, rp);
437 port->last_svc_rp = rp;
444 /* TODO: Convert this into a /proc/saa7164 style readable file */
445 if (print_histogram == port->nr) {
446 saa7164_histogram_print(port, &port->irq_interval);
447 saa7164_histogram_print(port, &port->svc_interval);
448 saa7164_histogram_print(port, &port->irq_svc_interval);
449 saa7164_histogram_print(port, &port->read_interval);
450 saa7164_histogram_print(port, &port->poll_interval);
451 /* TODO: fix this to preserve any previous state */
452 print_histogram = 64 + port->nr;
456 static void saa7164_work_vbihandler(struct work_struct *w)
458 struct saa7164_port *port =
459 container_of(w, struct saa7164_port, workenc);
460 struct saa7164_dev *dev = port->dev;
462 u32 wp, mcb, rp, cnt = 0;
464 port->last_svc_msecs_diff = port->last_svc_msecs;
465 port->last_svc_msecs = jiffies_to_msecs(jiffies);
466 port->last_svc_msecs_diff = port->last_svc_msecs -
467 port->last_svc_msecs_diff;
469 saa7164_histogram_update(&port->svc_interval,
470 port->last_svc_msecs_diff);
472 port->last_irq_svc_msecs_diff = port->last_svc_msecs -
473 port->last_irq_msecs;
475 saa7164_histogram_update(&port->irq_svc_interval,
476 port->last_irq_svc_msecs_diff);
479 "%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
481 port->last_svc_msecs_diff,
482 port->last_irq_svc_msecs_diff,
487 /* Current write position */
488 wp = saa7164_readl(port->bufcounter);
489 if (wp > (port->hwcfg.buffercount - 1)) {
490 printk(KERN_ERR "%s() illegal buf count %d\n", __func__, wp);
494 /* Most current complete buffer */
496 mcb = (port->hwcfg.buffercount - 1);
501 if (port->done_first_interrupt == 0) {
502 port->done_first_interrupt++;
505 rp = (port->last_svc_rp + 1) % 8;
507 if ((rp < 0) || (rp > (port->hwcfg.buffercount - 1))) {
508 printk(KERN_ERR "%s() illegal rp count %d\n", __func__, rp);
512 saa7164_work_enchandler_helper(port, rp);
513 port->last_svc_rp = rp;
520 /* TODO: Convert this into a /proc/saa7164 style readable file */
521 if (print_histogram == port->nr) {
522 saa7164_histogram_print(port, &port->irq_interval);
523 saa7164_histogram_print(port, &port->svc_interval);
524 saa7164_histogram_print(port, &port->irq_svc_interval);
525 saa7164_histogram_print(port, &port->read_interval);
526 saa7164_histogram_print(port, &port->poll_interval);
527 /* TODO: fix this to preserve any previous state */
528 print_histogram = 64 + port->nr;
532 static void saa7164_work_cmdhandler(struct work_struct *w)
534 struct saa7164_dev *dev = container_of(w, struct saa7164_dev, workcmd);
536 /* Wake up any complete commands */
537 saa7164_irq_dequeue(dev);
540 static void saa7164_buffer_deliver(struct saa7164_buffer *buf)
542 struct saa7164_port *port = buf->port;
544 /* Feed the transport payload into the kernel demux */
545 dvb_dmx_swfilter_packets(&port->dvb.demux, (u8 *)buf->cpu,
546 SAA7164_TS_NUMBER_OF_LINES);
550 static irqreturn_t saa7164_irq_vbi(struct saa7164_port *port)
552 struct saa7164_dev *dev = port->dev;
555 port->last_irq_msecs_diff = port->last_irq_msecs;
557 /* Collect new stats */
558 port->last_irq_msecs = jiffies_to_msecs(jiffies);
560 /* Calculate stats */
561 port->last_irq_msecs_diff = port->last_irq_msecs -
562 port->last_irq_msecs_diff;
564 saa7164_histogram_update(&port->irq_interval,
565 port->last_irq_msecs_diff);
567 dprintk(DBGLVL_IRQ, "%s() %Ldms elapsed\n", __func__,
568 port->last_irq_msecs_diff);
570 /* Tis calls the vbi irq handler */
571 schedule_work(&port->workenc);
575 static irqreturn_t saa7164_irq_encoder(struct saa7164_port *port)
577 struct saa7164_dev *dev = port->dev;
580 port->last_irq_msecs_diff = port->last_irq_msecs;
582 /* Collect new stats */
583 port->last_irq_msecs = jiffies_to_msecs(jiffies);
585 /* Calculate stats */
586 port->last_irq_msecs_diff = port->last_irq_msecs -
587 port->last_irq_msecs_diff;
589 saa7164_histogram_update(&port->irq_interval,
590 port->last_irq_msecs_diff);
592 dprintk(DBGLVL_IRQ, "%s() %Ldms elapsed\n", __func__,
593 port->last_irq_msecs_diff);
595 schedule_work(&port->workenc);
599 static irqreturn_t saa7164_irq_ts(struct saa7164_port *port)
601 struct saa7164_dev *dev = port->dev;
602 struct saa7164_buffer *buf;
603 struct list_head *c, *n;
606 /* Find the current write point from the hardware */
607 wp = saa7164_readl(port->bufcounter);
608 if (wp > (port->hwcfg.buffercount - 1))
611 /* Find the previous buffer to the current write point */
613 rp = (port->hwcfg.buffercount - 1);
617 /* Lookup the WP in the buffer list */
618 /* TODO: turn this into a worker thread */
619 list_for_each_safe(c, n, &port->dmaqueue.list) {
620 buf = list_entry(c, struct saa7164_buffer, list);
621 if (i++ > port->hwcfg.buffercount)
624 if (buf->idx == rp) {
625 /* Found the buffer, deal with it */
626 dprintk(DBGLVL_IRQ, "%s() wp: %d processing: %d\n",
628 saa7164_buffer_deliver(buf);
636 /* Primary IRQ handler and dispatch mechanism */
637 static irqreturn_t saa7164_irq(int irq, void *dev_id)
639 struct saa7164_dev *dev = dev_id;
640 struct saa7164_port *porta = &dev->ports[SAA7164_PORT_TS1];
641 struct saa7164_port *portb = &dev->ports[SAA7164_PORT_TS2];
642 struct saa7164_port *portc = &dev->ports[SAA7164_PORT_ENC1];
643 struct saa7164_port *portd = &dev->ports[SAA7164_PORT_ENC2];
644 struct saa7164_port *porte = &dev->ports[SAA7164_PORT_VBI1];
645 struct saa7164_port *portf = &dev->ports[SAA7164_PORT_VBI2];
647 u32 intid, intstat[INT_SIZE/4];
648 int i, handled = 0, bit;
651 printk(KERN_ERR "%s() No device specified\n", __func__);
656 /* Check that the hardware is accessable. If the status bytes are
657 * 0xFF then the device is not accessable, the the IRQ belongs
659 * 4 x u32 interrupt registers.
661 for (i = 0; i < INT_SIZE/4; i++) {
663 /* TODO: Convert into saa7164_readl() */
664 /* Read the 4 hardware interrupt registers */
665 intstat[i] = saa7164_readl(dev->int_status + (i * 4));
673 /* For each of the HW interrupt registers */
674 for (i = 0; i < INT_SIZE/4; i++) {
677 /* Each function of the board has it's own interruptid.
678 * Find the function that triggered then call
681 for (bit = 0; bit < 32; bit++) {
683 if (((intstat[i] >> bit) & 0x00000001) == 0)
686 /* Calculate the interrupt id (0x00 to 0x7f) */
688 intid = (i * 32) + bit;
689 if (intid == dev->intfdesc.bInterruptId) {
690 /* A response to an cmd/api call */
691 schedule_work(&dev->workcmd);
692 } else if (intid == porta->hwcfg.interruptid) {
694 /* Transport path 1 */
695 saa7164_irq_ts(porta);
697 } else if (intid == portb->hwcfg.interruptid) {
699 /* Transport path 2 */
700 saa7164_irq_ts(portb);
702 } else if (intid == portc->hwcfg.interruptid) {
705 saa7164_irq_encoder(portc);
707 } else if (intid == portd->hwcfg.interruptid) {
710 saa7164_irq_encoder(portd);
712 } else if (intid == porte->hwcfg.interruptid) {
715 saa7164_irq_vbi(porte);
717 } else if (intid == portf->hwcfg.interruptid) {
720 saa7164_irq_vbi(portf);
723 /* Find the function */
725 "%s() unhandled interrupt "
728 __func__, i, bit, intid);
733 saa7164_writel(dev->int_ack + (i * 4), intstat[i]);
738 return IRQ_RETVAL(handled);
741 void saa7164_getfirmwarestatus(struct saa7164_dev *dev)
743 struct saa7164_fw_status *s = &dev->fw_status;
745 dev->fw_status.status = saa7164_readl(SAA_DEVICE_SYSINIT_STATUS);
746 dev->fw_status.mode = saa7164_readl(SAA_DEVICE_SYSINIT_MODE);
747 dev->fw_status.spec = saa7164_readl(SAA_DEVICE_SYSINIT_SPEC);
748 dev->fw_status.inst = saa7164_readl(SAA_DEVICE_SYSINIT_INST);
749 dev->fw_status.cpuload = saa7164_readl(SAA_DEVICE_SYSINIT_CPULOAD);
750 dev->fw_status.remainheap =
751 saa7164_readl(SAA_DEVICE_SYSINIT_REMAINHEAP);
753 dprintk(1, "Firmware status:\n");
754 dprintk(1, " .status = 0x%08x\n", s->status);
755 dprintk(1, " .mode = 0x%08x\n", s->mode);
756 dprintk(1, " .spec = 0x%08x\n", s->spec);
757 dprintk(1, " .inst = 0x%08x\n", s->inst);
758 dprintk(1, " .cpuload = 0x%08x\n", s->cpuload);
759 dprintk(1, " .remainheap = 0x%08x\n", s->remainheap);
762 u32 saa7164_getcurrentfirmwareversion(struct saa7164_dev *dev)
766 reg = saa7164_readl(SAA_DEVICE_VERSION);
767 dprintk(1, "Device running firmware version %d.%d.%d.%d (0x%x)\n",
768 (reg & 0x0000fc00) >> 10,
769 (reg & 0x000003e0) >> 5,
771 (reg & 0xffff0000) >> 16,
777 /* TODO: Debugging func, remove */
778 void saa7164_dumphex16(struct saa7164_dev *dev, u8 *buf, int len)
782 printk(KERN_INFO "--------------------> "
783 "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
785 for (i = 0; i < len; i += 16)
786 printk(KERN_INFO " [0x%08x] "
787 "%02x %02x %02x %02x %02x %02x %02x %02x "
788 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
789 *(buf+i+0), *(buf+i+1), *(buf+i+2), *(buf+i+3),
790 *(buf+i+4), *(buf+i+5), *(buf+i+6), *(buf+i+7),
791 *(buf+i+8), *(buf+i+9), *(buf+i+10), *(buf+i+11),
792 *(buf+i+12), *(buf+i+13), *(buf+i+14), *(buf+i+15));
795 /* TODO: Debugging func, remove */
796 void saa7164_dumpregs(struct saa7164_dev *dev, u32 addr)
800 dprintk(1, "--------------------> "
801 "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
803 for (i = 0; i < 0x100; i += 16)
804 dprintk(1, "region0[0x%08x] = "
805 "%02x %02x %02x %02x %02x %02x %02x %02x"
806 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
807 (u8)saa7164_readb(addr + i + 0),
808 (u8)saa7164_readb(addr + i + 1),
809 (u8)saa7164_readb(addr + i + 2),
810 (u8)saa7164_readb(addr + i + 3),
811 (u8)saa7164_readb(addr + i + 4),
812 (u8)saa7164_readb(addr + i + 5),
813 (u8)saa7164_readb(addr + i + 6),
814 (u8)saa7164_readb(addr + i + 7),
815 (u8)saa7164_readb(addr + i + 8),
816 (u8)saa7164_readb(addr + i + 9),
817 (u8)saa7164_readb(addr + i + 10),
818 (u8)saa7164_readb(addr + i + 11),
819 (u8)saa7164_readb(addr + i + 12),
820 (u8)saa7164_readb(addr + i + 13),
821 (u8)saa7164_readb(addr + i + 14),
822 (u8)saa7164_readb(addr + i + 15)
826 static void saa7164_dump_hwdesc(struct saa7164_dev *dev)
828 dprintk(1, "@0x%p hwdesc sizeof(struct tmComResHWDescr) = %d bytes\n",
829 &dev->hwdesc, (u32)sizeof(struct tmComResHWDescr));
831 dprintk(1, " .bLength = 0x%x\n", dev->hwdesc.bLength);
832 dprintk(1, " .bDescriptorType = 0x%x\n", dev->hwdesc.bDescriptorType);
833 dprintk(1, " .bDescriptorSubtype = 0x%x\n",
834 dev->hwdesc.bDescriptorSubtype);
836 dprintk(1, " .bcdSpecVersion = 0x%x\n", dev->hwdesc.bcdSpecVersion);
837 dprintk(1, " .dwClockFrequency = 0x%x\n", dev->hwdesc.dwClockFrequency);
838 dprintk(1, " .dwClockUpdateRes = 0x%x\n", dev->hwdesc.dwClockUpdateRes);
839 dprintk(1, " .bCapabilities = 0x%x\n", dev->hwdesc.bCapabilities);
840 dprintk(1, " .dwDeviceRegistersLocation = 0x%x\n",
841 dev->hwdesc.dwDeviceRegistersLocation);
843 dprintk(1, " .dwHostMemoryRegion = 0x%x\n",
844 dev->hwdesc.dwHostMemoryRegion);
846 dprintk(1, " .dwHostMemoryRegionSize = 0x%x\n",
847 dev->hwdesc.dwHostMemoryRegionSize);
849 dprintk(1, " .dwHostHibernatMemRegion = 0x%x\n",
850 dev->hwdesc.dwHostHibernatMemRegion);
852 dprintk(1, " .dwHostHibernatMemRegionSize = 0x%x\n",
853 dev->hwdesc.dwHostHibernatMemRegionSize);
856 static void saa7164_dump_intfdesc(struct saa7164_dev *dev)
858 dprintk(1, "@0x%p intfdesc "
859 "sizeof(struct tmComResInterfaceDescr) = %d bytes\n",
860 &dev->intfdesc, (u32)sizeof(struct tmComResInterfaceDescr));
862 dprintk(1, " .bLength = 0x%x\n", dev->intfdesc.bLength);
863 dprintk(1, " .bDescriptorType = 0x%x\n", dev->intfdesc.bDescriptorType);
864 dprintk(1, " .bDescriptorSubtype = 0x%x\n",
865 dev->intfdesc.bDescriptorSubtype);
867 dprintk(1, " .bFlags = 0x%x\n", dev->intfdesc.bFlags);
868 dprintk(1, " .bInterfaceType = 0x%x\n", dev->intfdesc.bInterfaceType);
869 dprintk(1, " .bInterfaceId = 0x%x\n", dev->intfdesc.bInterfaceId);
870 dprintk(1, " .bBaseInterface = 0x%x\n", dev->intfdesc.bBaseInterface);
871 dprintk(1, " .bInterruptId = 0x%x\n", dev->intfdesc.bInterruptId);
872 dprintk(1, " .bDebugInterruptId = 0x%x\n",
873 dev->intfdesc.bDebugInterruptId);
875 dprintk(1, " .BARLocation = 0x%x\n", dev->intfdesc.BARLocation);
878 static void saa7164_dump_busdesc(struct saa7164_dev *dev)
880 dprintk(1, "@0x%p busdesc sizeof(struct tmComResBusDescr) = %d bytes\n",
881 &dev->busdesc, (u32)sizeof(struct tmComResBusDescr));
883 dprintk(1, " .CommandRing = 0x%016Lx\n", dev->busdesc.CommandRing);
884 dprintk(1, " .ResponseRing = 0x%016Lx\n", dev->busdesc.ResponseRing);
885 dprintk(1, " .CommandWrite = 0x%x\n", dev->busdesc.CommandWrite);
886 dprintk(1, " .CommandRead = 0x%x\n", dev->busdesc.CommandRead);
887 dprintk(1, " .ResponseWrite = 0x%x\n", dev->busdesc.ResponseWrite);
888 dprintk(1, " .ResponseRead = 0x%x\n", dev->busdesc.ResponseRead);
891 /* Much of the hardware configuration and PCI registers are configured
892 * dynamically depending on firmware. We have to cache some initial
893 * structures then use these to locate other important structures
896 static void saa7164_get_descriptors(struct saa7164_dev *dev)
898 memcpy_fromio(&dev->hwdesc, dev->bmmio, sizeof(struct tmComResHWDescr));
899 memcpy_fromio(&dev->intfdesc, dev->bmmio + sizeof(struct tmComResHWDescr),
900 sizeof(struct tmComResInterfaceDescr));
901 memcpy_fromio(&dev->busdesc, dev->bmmio + dev->intfdesc.BARLocation,
902 sizeof(struct tmComResBusDescr));
904 if (dev->hwdesc.bLength != sizeof(struct tmComResHWDescr)) {
905 printk(KERN_ERR "Structure struct tmComResHWDescr is mangled\n");
906 printk(KERN_ERR "Need %x got %d\n", dev->hwdesc.bLength,
907 (u32)sizeof(struct tmComResHWDescr));
909 saa7164_dump_hwdesc(dev);
911 if (dev->intfdesc.bLength != sizeof(struct tmComResInterfaceDescr)) {
912 printk(KERN_ERR "struct struct tmComResInterfaceDescr is mangled\n");
913 printk(KERN_ERR "Need %x got %d\n", dev->intfdesc.bLength,
914 (u32)sizeof(struct tmComResInterfaceDescr));
916 saa7164_dump_intfdesc(dev);
918 saa7164_dump_busdesc(dev);
921 static int saa7164_pci_quirks(struct saa7164_dev *dev)
926 static int get_resources(struct saa7164_dev *dev)
928 if (request_mem_region(pci_resource_start(dev->pci, 0),
929 pci_resource_len(dev->pci, 0), dev->name)) {
931 if (request_mem_region(pci_resource_start(dev->pci, 2),
932 pci_resource_len(dev->pci, 2), dev->name))
936 printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx or 0x%llx\n",
938 (u64)pci_resource_start(dev->pci, 0),
939 (u64)pci_resource_start(dev->pci, 2));
944 static int saa7164_port_init(struct saa7164_dev *dev, int portnr)
946 struct saa7164_port *port = 0;
948 if ((portnr < 0) || (portnr >= SAA7164_MAX_PORTS))
951 port = &dev->ports[portnr];
956 if ((portnr == SAA7164_PORT_TS1) || (portnr == SAA7164_PORT_TS2))
957 port->type = SAA7164_MPEG_DVB;
959 if ((portnr == SAA7164_PORT_ENC1) || (portnr == SAA7164_PORT_ENC2)) {
960 port->type = SAA7164_MPEG_ENCODER;
962 /* We need a deferred interrupt handler for cmd handling */
963 INIT_WORK(&port->workenc, saa7164_work_enchandler);
966 if ((portnr == SAA7164_PORT_VBI1) || (portnr == SAA7164_PORT_VBI2)) {
967 port->type = SAA7164_MPEG_VBI;
969 /* We need a deferred interrupt handler for cmd handling */
970 INIT_WORK(&port->workenc, saa7164_work_vbihandler);
974 /* Init all the critical resources */
975 mutex_init(&port->dvb.lock);
976 INIT_LIST_HEAD(&port->dmaqueue.list);
977 mutex_init(&port->dmaqueue_lock);
979 INIT_LIST_HEAD(&port->list_buf_used.list);
980 INIT_LIST_HEAD(&port->list_buf_free.list);
981 init_waitqueue_head(&port->wait_read);
984 saa7164_histogram_reset(&port->irq_interval, "irq intervals");
985 saa7164_histogram_reset(&port->svc_interval, "deferred intervals");
986 saa7164_histogram_reset(&port->irq_svc_interval,
987 "irq to deferred intervals");
988 saa7164_histogram_reset(&port->read_interval,
989 "encoder/vbi read() intervals");
990 saa7164_histogram_reset(&port->poll_interval,
991 "encoder/vbi poll() intervals");
996 static int saa7164_dev_setup(struct saa7164_dev *dev)
1000 mutex_init(&dev->lock);
1001 atomic_inc(&dev->refcount);
1002 dev->nr = saa7164_devcount++;
1004 sprintf(dev->name, "saa7164[%d]", dev->nr);
1006 mutex_lock(&devlist);
1007 list_add_tail(&dev->devlist, &saa7164_devlist);
1008 mutex_unlock(&devlist);
1012 if (card[dev->nr] < saa7164_bcount)
1013 dev->board = card[dev->nr];
1015 for (i = 0; UNSET == dev->board && i < saa7164_idcount; i++)
1016 if (dev->pci->subsystem_vendor == saa7164_subids[i].subvendor &&
1017 dev->pci->subsystem_device ==
1018 saa7164_subids[i].subdevice)
1019 dev->board = saa7164_subids[i].card;
1021 if (UNSET == dev->board) {
1022 dev->board = SAA7164_BOARD_UNKNOWN;
1023 saa7164_card_list(dev);
1026 dev->pci_bus = dev->pci->bus->number;
1027 dev->pci_slot = PCI_SLOT(dev->pci->devfn);
1029 /* I2C Defaults / setup */
1030 dev->i2c_bus[0].dev = dev;
1031 dev->i2c_bus[0].nr = 0;
1032 dev->i2c_bus[1].dev = dev;
1033 dev->i2c_bus[1].nr = 1;
1034 dev->i2c_bus[2].dev = dev;
1035 dev->i2c_bus[2].nr = 2;
1037 /* Transport + Encoder ports 1, 2, 3, 4 - Defaults / setup */
1038 saa7164_port_init(dev, SAA7164_PORT_TS1);
1039 saa7164_port_init(dev, SAA7164_PORT_TS2);
1040 saa7164_port_init(dev, SAA7164_PORT_ENC1);
1041 saa7164_port_init(dev, SAA7164_PORT_ENC2);
1042 saa7164_port_init(dev, SAA7164_PORT_VBI1);
1043 saa7164_port_init(dev, SAA7164_PORT_VBI2);
1045 if (get_resources(dev) < 0) {
1046 printk(KERN_ERR "CORE %s No more PCIe resources for "
1047 "subsystem: %04x:%04x\n",
1048 dev->name, dev->pci->subsystem_vendor,
1049 dev->pci->subsystem_device);
1055 /* PCI/e allocations */
1056 dev->lmmio = ioremap(pci_resource_start(dev->pci, 0),
1057 pci_resource_len(dev->pci, 0));
1059 dev->lmmio2 = ioremap(pci_resource_start(dev->pci, 2),
1060 pci_resource_len(dev->pci, 2));
1062 dev->bmmio = (u8 __iomem *)dev->lmmio;
1063 dev->bmmio2 = (u8 __iomem *)dev->lmmio2;
1065 /* Inerrupt and ack register locations offset of bmmio */
1066 dev->int_status = 0x183000 + 0xf80;
1067 dev->int_ack = 0x183000 + 0xf90;
1070 "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
1071 dev->name, dev->pci->subsystem_vendor,
1072 dev->pci->subsystem_device, saa7164_boards[dev->board].name,
1073 dev->board, card[dev->nr] == dev->board ?
1074 "insmod option" : "autodetected");
1076 saa7164_pci_quirks(dev);
1081 static void saa7164_dev_unregister(struct saa7164_dev *dev)
1083 dprintk(1, "%s()\n", __func__);
1085 release_mem_region(pci_resource_start(dev->pci, 0),
1086 pci_resource_len(dev->pci, 0));
1088 release_mem_region(pci_resource_start(dev->pci, 2),
1089 pci_resource_len(dev->pci, 2));
1091 if (!atomic_dec_and_test(&dev->refcount))
1094 iounmap(dev->lmmio);
1095 iounmap(dev->lmmio2);
1100 #ifdef CONFIG_PROC_FS
1101 static int saa7164_proc_show(struct seq_file *m, void *v)
1103 struct saa7164_dev *dev;
1104 struct tmComResBusInfo *b;
1105 struct list_head *list;
1108 if (saa7164_devcount == 0)
1111 list_for_each(list, &saa7164_devlist) {
1112 dev = list_entry(list, struct saa7164_dev, devlist);
1113 seq_printf(m, "%s = %p\n", dev->name, dev);
1115 /* Lock the bus from any other access */
1117 mutex_lock(&b->lock);
1119 seq_printf(m, " .m_pdwSetWritePos = 0x%x (0x%08x)\n",
1120 b->m_dwSetReadPos, saa7164_readl(b->m_dwSetReadPos));
1122 seq_printf(m, " .m_pdwSetReadPos = 0x%x (0x%08x)\n",
1123 b->m_dwSetWritePos, saa7164_readl(b->m_dwSetWritePos));
1125 seq_printf(m, " .m_pdwGetWritePos = 0x%x (0x%08x)\n",
1126 b->m_dwGetReadPos, saa7164_readl(b->m_dwGetReadPos));
1128 seq_printf(m, " .m_pdwGetReadPos = 0x%x (0x%08x)\n",
1129 b->m_dwGetWritePos, saa7164_readl(b->m_dwGetWritePos));
1131 seq_printf(m, "\n Set Ring:\n");
1132 seq_printf(m, "\n addr 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
1133 for (i = 0; i < b->m_dwSizeSetRing; i++) {
1135 seq_printf(m, " %04x:", i);
1137 seq_printf(m, " %02x", *(b->m_pdwSetRing + i));
1140 seq_printf(m, "\n");
1146 seq_printf(m, "\n Get Ring:\n");
1147 seq_printf(m, "\n addr 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
1148 for (i = 0; i < b->m_dwSizeGetRing; i++) {
1150 seq_printf(m, " %04x:", i);
1152 seq_printf(m, " %02x", *(b->m_pdwGetRing + i));
1155 seq_printf(m, "\n");
1160 mutex_unlock(&b->lock);
1167 static int saa7164_proc_open(struct inode *inode, struct file *filp)
1169 return single_open(filp, saa7164_proc_show, NULL);
1172 static struct file_operations saa7164_proc_fops = {
1173 .open = saa7164_proc_open,
1175 .llseek = seq_lseek,
1176 .release = single_release,
1179 static int saa7164_proc_create(void)
1181 struct proc_dir_entry *pe;
1183 pe = proc_create("saa7164", S_IRUGO, NULL, &saa7164_proc_fops);
1191 static int saa7164_thread_function(void *data)
1193 struct saa7164_dev *dev = data;
1194 struct tmFwInfoStruct fwinfo;
1195 u64 last_poll_time = 0;
1197 dprintk(DBGLVL_THR, "thread started\n");
1202 msleep_interruptible(100);
1203 if (kthread_should_stop())
1207 dprintk(DBGLVL_THR, "thread running\n");
1209 /* Dump the firmware debug message to console */
1210 /* Polling this costs us 1-2% of the arm CPU */
1211 /* convert this into a respnde to interrupt 0x7a */
1212 saa7164_api_collect_debug(dev);
1214 /* Monitor CPU load every 1 second */
1215 if ((last_poll_time + 1000 /* ms */) < jiffies_to_msecs(jiffies)) {
1216 saa7164_api_get_load_info(dev, &fwinfo);
1217 last_poll_time = jiffies_to_msecs(jiffies);
1222 dprintk(DBGLVL_THR, "thread exiting\n");
1226 static int __devinit saa7164_initdev(struct pci_dev *pci_dev,
1227 const struct pci_device_id *pci_id)
1229 struct saa7164_dev *dev;
1233 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1239 if (pci_enable_device(pci_dev)) {
1244 if (saa7164_dev_setup(dev) < 0) {
1249 /* print pci info */
1250 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
1251 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
1252 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
1253 "latency: %d, mmio: 0x%llx\n", dev->name,
1254 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
1256 (unsigned long long)pci_resource_start(pci_dev, 0));
1258 pci_set_master(pci_dev);
1260 if (!pci_dma_supported(pci_dev, 0xffffffff)) {
1261 printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name);
1266 err = request_irq(pci_dev->irq, saa7164_irq,
1267 IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
1269 printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name,
1275 pci_set_drvdata(pci_dev, dev);
1277 /* Init the internal command list */
1278 for (i = 0; i < SAA_CMD_MAX_MSG_UNITS; i++) {
1279 dev->cmds[i].seqno = i;
1280 dev->cmds[i].inuse = 0;
1281 mutex_init(&dev->cmds[i].lock);
1282 init_waitqueue_head(&dev->cmds[i].wait);
1285 /* We need a deferred interrupt handler for cmd handling */
1286 INIT_WORK(&dev->workcmd, saa7164_work_cmdhandler);
1288 /* Only load the firmware if we know the board */
1289 if (dev->board != SAA7164_BOARD_UNKNOWN) {
1291 err = saa7164_downloadfirmware(dev);
1294 "Failed to boot firmware, no features "
1299 saa7164_get_descriptors(dev);
1300 saa7164_dumpregs(dev, 0);
1301 saa7164_getcurrentfirmwareversion(dev);
1302 saa7164_getfirmwarestatus(dev);
1303 err = saa7164_bus_setup(dev);
1306 "Failed to setup the bus, will continue\n");
1307 saa7164_bus_dump(dev);
1309 /* Ping the running firmware via the command bus and get the
1310 * firmware version, this checks the bus is running OK.
1313 if (saa7164_api_get_fw_version(dev, &version) == SAA_OK)
1314 dprintk(1, "Bus is operating correctly using "
1315 "version %d.%d.%d.%d (0x%x)\n",
1316 (version & 0x0000fc00) >> 10,
1317 (version & 0x000003e0) >> 5,
1318 (version & 0x0000001f),
1319 (version & 0xffff0000) >> 16,
1323 "Failed to communicate with the firmware\n");
1325 /* Bring up the I2C buses */
1326 saa7164_i2c_register(&dev->i2c_bus[0]);
1327 saa7164_i2c_register(&dev->i2c_bus[1]);
1328 saa7164_i2c_register(&dev->i2c_bus[2]);
1329 saa7164_gpio_setup(dev);
1330 saa7164_card_setup(dev);
1332 /* Parse the dynamic device configuration, find various
1333 * media endpoints (MPEG, WMV, PS, TS) and cache their
1334 * configuration details into the driver, so we can
1335 * reference them later during simething_register() func,
1336 * interrupt handlers, deferred work handlers etc.
1338 saa7164_api_enum_subdevs(dev);
1340 /* Begin to create the video sub-systems and register funcs */
1341 if (saa7164_boards[dev->board].porta == SAA7164_MPEG_DVB) {
1342 if (saa7164_dvb_register(&dev->ports[SAA7164_PORT_TS1]) < 0) {
1343 printk(KERN_ERR "%s() Failed to register "
1344 "dvb adapters on porta\n",
1349 if (saa7164_boards[dev->board].portb == SAA7164_MPEG_DVB) {
1350 if (saa7164_dvb_register(&dev->ports[SAA7164_PORT_TS2]) < 0) {
1351 printk(KERN_ERR"%s() Failed to register "
1352 "dvb adapters on portb\n",
1357 if (saa7164_boards[dev->board].portc == SAA7164_MPEG_ENCODER) {
1358 if (saa7164_encoder_register(&dev->ports[SAA7164_PORT_ENC1]) < 0) {
1359 printk(KERN_ERR"%s() Failed to register "
1360 "mpeg encoder\n", __func__);
1364 if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER) {
1365 if (saa7164_encoder_register(&dev->ports[SAA7164_PORT_ENC2]) < 0) {
1366 printk(KERN_ERR"%s() Failed to register "
1367 "mpeg encoder\n", __func__);
1371 if (saa7164_boards[dev->board].porte == SAA7164_MPEG_VBI) {
1372 if (saa7164_vbi_register(&dev->ports[SAA7164_PORT_VBI1]) < 0) {
1373 printk(KERN_ERR"%s() Failed to register "
1374 "vbi device\n", __func__);
1378 if (saa7164_boards[dev->board].portf == SAA7164_MPEG_VBI) {
1379 if (saa7164_vbi_register(&dev->ports[SAA7164_PORT_VBI2]) < 0) {
1380 printk(KERN_ERR"%s() Failed to register "
1381 "vbi device\n", __func__);
1384 saa7164_api_set_debug(dev, fw_debug);
1387 dev->kthread = kthread_run(saa7164_thread_function, dev,
1390 printk(KERN_ERR "%s() Failed to create "
1391 "debug kernel thread\n", __func__);
1394 } /* != BOARD_UNKNOWN */
1396 printk(KERN_ERR "%s() Unsupported board detected, "
1397 "registering without firmware\n", __func__);
1399 dprintk(1, "%s() parameter debug = %d\n", __func__, saa_debug);
1400 dprintk(1, "%s() parameter waitsecs = %d\n", __func__, waitsecs);
1406 saa7164_dev_unregister(dev);
1412 static void saa7164_shutdown(struct saa7164_dev *dev)
1414 dprintk(1, "%s()\n", __func__);
1417 static void __devexit saa7164_finidev(struct pci_dev *pci_dev)
1419 struct saa7164_dev *dev = pci_get_drvdata(pci_dev);
1421 if (dev->board != SAA7164_BOARD_UNKNOWN) {
1422 if (fw_debug && dev->kthread) {
1423 kthread_stop(dev->kthread);
1424 dev->kthread = NULL;
1426 if (dev->firmwareloaded)
1427 saa7164_api_set_debug(dev, 0x00);
1430 saa7164_histogram_print(&dev->ports[SAA7164_PORT_ENC1],
1431 &dev->ports[SAA7164_PORT_ENC1].irq_interval);
1432 saa7164_histogram_print(&dev->ports[SAA7164_PORT_ENC1],
1433 &dev->ports[SAA7164_PORT_ENC1].svc_interval);
1434 saa7164_histogram_print(&dev->ports[SAA7164_PORT_ENC1],
1435 &dev->ports[SAA7164_PORT_ENC1].irq_svc_interval);
1436 saa7164_histogram_print(&dev->ports[SAA7164_PORT_ENC1],
1437 &dev->ports[SAA7164_PORT_ENC1].read_interval);
1438 saa7164_histogram_print(&dev->ports[SAA7164_PORT_ENC1],
1439 &dev->ports[SAA7164_PORT_ENC1].poll_interval);
1440 saa7164_histogram_print(&dev->ports[SAA7164_PORT_VBI1],
1441 &dev->ports[SAA7164_PORT_VBI1].read_interval);
1442 saa7164_histogram_print(&dev->ports[SAA7164_PORT_VBI2],
1443 &dev->ports[SAA7164_PORT_VBI2].poll_interval);
1445 saa7164_shutdown(dev);
1447 if (saa7164_boards[dev->board].porta == SAA7164_MPEG_DVB)
1448 saa7164_dvb_unregister(&dev->ports[SAA7164_PORT_TS1]);
1450 if (saa7164_boards[dev->board].portb == SAA7164_MPEG_DVB)
1451 saa7164_dvb_unregister(&dev->ports[SAA7164_PORT_TS2]);
1453 if (saa7164_boards[dev->board].portc == SAA7164_MPEG_ENCODER)
1454 saa7164_encoder_unregister(&dev->ports[SAA7164_PORT_ENC1]);
1456 if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER)
1457 saa7164_encoder_unregister(&dev->ports[SAA7164_PORT_ENC2]);
1459 if (saa7164_boards[dev->board].porte == SAA7164_MPEG_VBI)
1460 saa7164_vbi_unregister(&dev->ports[SAA7164_PORT_VBI1]);
1462 if (saa7164_boards[dev->board].portf == SAA7164_MPEG_VBI)
1463 saa7164_vbi_unregister(&dev->ports[SAA7164_PORT_VBI2]);
1465 saa7164_i2c_unregister(&dev->i2c_bus[0]);
1466 saa7164_i2c_unregister(&dev->i2c_bus[1]);
1467 saa7164_i2c_unregister(&dev->i2c_bus[2]);
1469 pci_disable_device(pci_dev);
1471 /* unregister stuff */
1472 free_irq(pci_dev->irq, dev);
1473 pci_set_drvdata(pci_dev, NULL);
1475 mutex_lock(&devlist);
1476 list_del(&dev->devlist);
1477 mutex_unlock(&devlist);
1479 saa7164_dev_unregister(dev);
1483 static struct pci_device_id saa7164_pci_tbl[] = {
1488 .subvendor = PCI_ANY_ID,
1489 .subdevice = PCI_ANY_ID,
1491 /* --- end of list --- */
1494 MODULE_DEVICE_TABLE(pci, saa7164_pci_tbl);
1496 static struct pci_driver saa7164_pci_driver = {
1498 .id_table = saa7164_pci_tbl,
1499 .probe = saa7164_initdev,
1500 .remove = __devexit_p(saa7164_finidev),
1506 static int __init saa7164_init(void)
1508 printk(KERN_INFO "saa7164 driver loaded\n");
1510 #ifdef CONFIG_PROC_FS
1511 saa7164_proc_create();
1513 return pci_register_driver(&saa7164_pci_driver);
1516 static void __exit saa7164_fini(void)
1518 #ifdef CONFIG_PROC_FS
1519 remove_proc_entry("saa7164", NULL);
1521 pci_unregister_driver(&saa7164_pci_driver);
1524 module_init(saa7164_init);
1525 module_exit(saa7164_fini);