[media] saa7164: allow DMA engine buffers to vary in size between analog and digital
[deliverable/linux.git] / drivers / media / video / saa7164 / saa7164-core.c
index 1bd1e62f9896f2cfea2f9e47e4b88d453b8d27dc..8879517d974a52fec133bf3e1b71fcd6c67a21af 100644 (file)
@@ -49,14 +49,30 @@ unsigned int saa_debug;
 module_param_named(debug, saa_debug, int, 0644);
 MODULE_PARM_DESC(debug, "enable debug messages");
 
+unsigned int encoder_buffers = SAA7164_MAX_ENCODER_BUFFERS;
+module_param(encoder_buffers, int, 0644);
+MODULE_PARM_DESC(encoder_buffers, "Total buffers in read queue 16-512 def:64");
+
 unsigned int waitsecs = 10;
 module_param(waitsecs, int, 0644);
-MODULE_PARM_DESC(debug, "timeout on firmware messages");
+MODULE_PARM_DESC(waitsecs, "timeout on firmware messages");
 
 static unsigned int card[]  = {[0 ... (SAA7164_MAXBOARDS - 1)] = UNSET };
 module_param_array(card,  int, NULL, 0444);
 MODULE_PARM_DESC(card, "card type");
 
+unsigned int print_histogram = 64;
+module_param(print_histogram, int, 0644);
+MODULE_PARM_DESC(print_histogram, "print histogram values once");
+
+unsigned int crc_checking = 1;
+module_param(crc_checking, int, 0644);
+MODULE_PARM_DESC(crc_checking, "enable crc sanity checking on buffers");
+
+unsigned int guard_checking = 1;
+module_param(guard_checking, int, 0644);
+MODULE_PARM_DESC(guard_checking, "enable dma sanity checking for buffer overruns");
+
 static unsigned int saa7164_devcount;
 
 static DEFINE_MUTEX(devlist);
@@ -64,6 +80,359 @@ LIST_HEAD(saa7164_devlist);
 
 #define INT_SIZE 16
 
+void saa7164_dumphex16FF(struct saa7164_dev *dev, u8 *buf, int len)
+{
+       int i;
+       u8 tmp[16];
+       memset(&tmp[0], 0xff, sizeof(tmp));
+
+       printk(KERN_INFO "--------------------> "
+               "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
+
+       for (i = 0; i < len; i += 16) {
+               if (memcmp(&tmp, buf + i, sizeof(tmp)) != 0) {
+                       printk(KERN_INFO "         [0x%08x] "
+                               "%02x %02x %02x %02x %02x %02x %02x %02x "
+                               "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
+                       *(buf+i+0), *(buf+i+1), *(buf+i+2), *(buf+i+3),
+                       *(buf+i+4), *(buf+i+5), *(buf+i+6), *(buf+i+7),
+                       *(buf+i+8), *(buf+i+9), *(buf+i+10), *(buf+i+11),
+                       *(buf+i+12), *(buf+i+13), *(buf+i+14), *(buf+i+15));
+               }
+       }
+}
+
+static void saa7164_pack_verifier(struct saa7164_buffer *buf)
+{
+       u8 *p = (u8 *)buf->cpu;
+       int i;
+
+       for (i = 0; i < buf->actual_size; i += 2048) {
+
+               if ( (*(p + i + 0) != 0x00) || (*(p + i + 1) != 0x00) ||
+                       (*(p + i + 2) != 0x01) || (*(p + i + 3) != 0xBA) ) {
+                       printk(KERN_ERR "No pack at 0x%x\n", i);
+//                     saa7164_dumphex16FF(buf->port->dev, (p + i), 32);
+               }
+       }
+}
+
+#define FIXED_VIDEO_PID 0xf1
+#define FIXED_AUDIO_PID 0xf2
+
+static void saa7164_ts_verifier(struct saa7164_buffer *buf)
+{
+       struct saa7164_port *port = buf->port;
+       u32 i;
+       u8 cc, a;
+       u16 pid;
+       u8 __iomem *bufcpu = (u8 *)buf->cpu;
+
+       port->sync_errors = 0;
+       port->v_cc_errors = 0;
+       port->a_cc_errors = 0;
+
+       for (i = 0; i < buf->actual_size; i += 188) {
+               if (*(bufcpu + i) != 0x47)
+                       port->sync_errors++;
+
+               /* TODO: Query pid lower 8 bits, ignoring upper bits intensionally */
+               pid = ((*(bufcpu + i + 1) & 0x1f) << 8) | *(bufcpu + i + 2);
+               cc = *(bufcpu + i + 3) & 0x0f;
+
+               if (pid == FIXED_VIDEO_PID) {
+                       a = ((port->last_v_cc + 1) & 0x0f);
+                       if (a != cc) {
+                               printk(KERN_ERR "video cc last = %x current = %x i = %d\n",
+                                       port->last_v_cc, cc, i);
+                               port->v_cc_errors++;
+                       }
+
+                       port->last_v_cc = cc;
+               } else
+               if (pid == FIXED_AUDIO_PID) {
+                       a = ((port->last_a_cc + 1) & 0x0f);
+                       if (a != cc) {
+                               printk(KERN_ERR "audio cc last = %x current = %x i = %d\n",
+                                       port->last_a_cc, cc, i);
+                               port->a_cc_errors++;
+                       }
+
+                       port->last_a_cc = cc;
+               }
+
+       }
+
+       if (port->v_cc_errors)
+               printk(KERN_ERR "video pid cc, %d errors\n", port->v_cc_errors);
+
+       if (port->a_cc_errors)
+               printk(KERN_ERR "audio pid cc, %d errors\n", port->a_cc_errors);
+
+       if (port->sync_errors)
+               printk(KERN_ERR "sync_errors = %d\n", port->sync_errors);
+}
+
+static void saa7164_histogram_reset(struct saa7164_histogram *hg, char *name)
+{
+       int i;
+
+       memset(hg, 0, sizeof(struct saa7164_histogram));
+       strcpy(hg->name, name);
+
+       /* First 30ms x 1ms */
+       for (i = 0; i < 30; i++) {
+               hg->counter1[0 + i].val = i;
+       }
+
+       /* 30 - 200ms x 10ms  */
+       for (i = 0; i < 18; i++) {
+               hg->counter1[30 + i].val = 30 + (i * 10);
+       }
+
+       /* 200 - 2000ms x 100ms  */
+       for (i = 0; i < 15; i++) {
+               hg->counter1[48 + i].val = 200 + (i * 200);
+       }
+
+       /* Catch all massive value (2secs) */
+       hg->counter1[55].val = 2000;
+
+       /* Catch all massive value (4secs) */
+       hg->counter1[56].val = 4000;
+
+       /* Catch all massive value (8secs) */
+       hg->counter1[57].val = 8000;
+
+       /* Catch all massive value (15secs) */
+       hg->counter1[58].val = 15000;
+
+       /* Catch all massive value (30secs) */
+       hg->counter1[59].val = 30000;
+
+       /* Catch all massive value (60secs) */
+       hg->counter1[60].val = 60000;
+
+       /* Catch all massive value (5mins) */
+       hg->counter1[61].val = 300000;
+
+       /* Catch all massive value (15mins) */
+       hg->counter1[62].val = 900000;
+
+       /* Catch all massive values (1hr) */
+       hg->counter1[63].val = 3600000;
+}
+
+void saa7164_histogram_update(struct saa7164_histogram *hg, u32 val)
+{
+       int i;
+       for (i = 0; i < 64; i++ ) {
+               if (val <= hg->counter1[i].val) {
+                       hg->counter1[i].count++;
+                       hg->counter1[i].update_time = jiffies;
+                       break;
+               }
+       }
+}
+
+static void saa7164_histogram_print(struct saa7164_port *port,
+       struct saa7164_histogram *hg)
+{
+       u32 entries = 0;
+       int i;
+
+       printk(KERN_ERR "Histogram named %s (ms, count, last_update_jiffy)\n", hg->name);
+       for (i = 0; i < 64; i++ ) {
+               if (hg->counter1[i].count == 0)
+                       continue;
+
+               printk(KERN_ERR " %4d %12d %Ld\n",
+                       hg->counter1[i].val,
+                       hg->counter1[i].count,
+                       hg->counter1[i].update_time);
+
+               entries++;
+       }
+       printk(KERN_ERR "Total: %d\n", entries);
+}
+
+static void saa7164_work_enchandler_helper(struct saa7164_port *port, int bufnr)
+{
+       struct saa7164_dev *dev = port->dev;
+       struct saa7164_buffer *buf = 0;
+       struct saa7164_user_buffer *ubuf = 0;
+       struct list_head *c, *n;
+       int i = 0;
+       u8 __iomem *p;
+
+       mutex_lock(&port->dmaqueue_lock);
+       list_for_each_safe(c, n, &port->dmaqueue.list) {
+
+               buf = list_entry(c, struct saa7164_buffer, list);
+               if (i++ > port->hwcfg.buffercount) {
+                       printk(KERN_ERR "%s() illegal i count %d\n",
+                               __func__, i);
+                       break;
+               }
+
+               if (buf->idx == bufnr) {
+
+                       /* Found the buffer, deal with it */
+                       dprintk(DBGLVL_IRQ, "%s() bufnr: %d\n", __func__, bufnr);
+
+                       if (crc_checking) {
+                               /* Throw a new checksum on the dma buffer */
+                               buf->crc = crc32(0, buf->cpu, buf->actual_size);
+                       }
+
+                       if (guard_checking) {
+                               p = (u8 *)buf->cpu;
+                               if ( (*(p + buf->actual_size + 0) != 0xff) ||
+                                       (*(p + buf->actual_size + 1) != 0xff) ||
+                                       (*(p + buf->actual_size + 2) != 0xff) ||
+                                       (*(p + buf->actual_size + 3) != 0xff) ||
+                                       (*(p + buf->actual_size + 0x10) != 0xff) ||
+                                       (*(p + buf->actual_size + 0x11) != 0xff) ||
+                                       (*(p + buf->actual_size + 0x12) != 0xff) ||
+                                       (*(p + buf->actual_size + 0x13) != 0xff) ) {
+                                               printk(KERN_ERR "%s() buf %p guard buffer breach\n",
+                                                       __func__, buf);
+//                                             saa7164_dumphex16FF(dev, (p + buf->actual_size) - 32 , 64);
+                               }
+                       }
+
+                       /* Validate the incoming buffer content */
+                       if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_TS)
+                               saa7164_ts_verifier(buf);
+                       else if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS)
+                               saa7164_pack_verifier(buf);
+
+                       /* find a free user buffer and clone to it */
+                       if (!list_empty(&port->list_buf_free.list)) {
+
+                               /* Pull the first buffer from the used list */
+                               ubuf = list_first_entry(&port->list_buf_free.list,
+                                       struct saa7164_user_buffer, list);
+
+                               if (buf->actual_size <= ubuf->actual_size) {
+
+                                       memcpy_fromio(ubuf->data, buf->cpu,
+                                               ubuf->actual_size);
+
+                                       if (crc_checking) {
+                                               /* Throw a new checksum on the read buffer */
+                                               ubuf->crc = crc32(0, ubuf->data, ubuf->actual_size);
+                                       }
+
+                                       /* Requeue the buffer on the free list */
+                                       ubuf->pos = 0;
+
+                                       list_move_tail(&ubuf->list,
+                                               &port->list_buf_used.list);
+
+                                       /* Flag any userland waiters */
+                                       wake_up_interruptible(&port->wait_read);
+
+                               } else {
+                                       printk(KERN_ERR "buf %p bufsize fails match\n", buf);
+                               }
+
+                       } else
+                               printk(KERN_ERR "encirq no free buffers, increase param encoder_buffers\n");
+
+                       /* Ensure offset into buffer remains 0, fill buffer
+                        * with known bad data. We check for this data at a later point
+                        * in time. */
+                       saa7164_buffer_zero_offsets(port, bufnr);
+                       memset_io(buf->cpu, 0xff, buf->pci_size);
+                       if (crc_checking) {
+                               /* Throw yet aanother new checksum on the dma buffer */
+                               buf->crc = crc32(0, buf->cpu, buf->actual_size);
+                       }
+
+                       break;
+               }
+       }
+       mutex_unlock(&port->dmaqueue_lock);
+}
+
+static void saa7164_work_enchandler(struct work_struct *w)
+{
+       struct saa7164_port *port =
+               container_of(w, struct saa7164_port, workenc);
+       struct saa7164_dev *dev = port->dev;
+
+       u32 wp, mcb, rp, cnt = 0;
+
+       port->last_svc_msecs_diff = port->last_svc_msecs;
+       port->last_svc_msecs = jiffies_to_msecs(jiffies);
+
+       port->last_svc_msecs_diff = port->last_svc_msecs -
+               port->last_svc_msecs_diff;
+
+       saa7164_histogram_update(&port->svc_interval,
+               port->last_svc_msecs_diff);
+
+       port->last_irq_svc_msecs_diff = port->last_svc_msecs -
+               port->last_irq_msecs;
+
+       saa7164_histogram_update(&port->irq_svc_interval,
+               port->last_irq_svc_msecs_diff);
+
+       dprintk(DBGLVL_IRQ,
+               "%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
+               __func__,
+               port->last_svc_msecs_diff,
+               port->last_irq_svc_msecs_diff,
+               port->last_svc_wp,
+               port->last_svc_rp
+               );
+
+       /* Current write position */
+       wp = saa7164_readl(port->bufcounter);
+       if (wp > (port->hwcfg.buffercount - 1)) {
+               printk(KERN_ERR "%s() illegal buf count %d\n", __func__, wp);
+               return;
+       }
+
+       /* Most current complete buffer */
+       if (wp == 0)
+               mcb = (port->hwcfg.buffercount - 1);
+       else
+               mcb = wp - 1;
+
+       while (1) {
+               if (port->done_first_interrupt == 0) {
+                       port->done_first_interrupt++;
+                       rp = mcb;
+               } else
+                       rp = (port->last_svc_rp + 1) % 8;
+
+               if ((rp < 0) || (rp > (port->hwcfg.buffercount - 1))) {
+                       printk(KERN_ERR "%s() illegal rp count %d\n", __func__, rp);
+                       break;
+               }
+
+               saa7164_work_enchandler_helper(port, rp);
+               port->last_svc_rp = rp;
+               cnt++;
+
+               if (rp == mcb)
+                       break;
+       }
+
+       /* TODO: Convert this into a /proc/saa7164 style readable file */
+       if (print_histogram == port->nr) {
+               saa7164_histogram_print(port, &port->irq_interval);
+               saa7164_histogram_print(port, &port->svc_interval);
+               saa7164_histogram_print(port, &port->irq_svc_interval);
+               saa7164_histogram_print(port, &port->read_interval);
+               saa7164_histogram_print(port, &port->poll_interval);
+               /* TODO: fix this to preserve any previous state */
+               print_histogram = 64 + port->nr;
+       }
+}
+
 static void saa7164_work_cmdhandler(struct work_struct *w)
 {
        struct saa7164_dev *dev = container_of(w, struct saa7164_dev, workcmd);
@@ -74,7 +443,7 @@ static void saa7164_work_cmdhandler(struct work_struct *w)
 
 static void saa7164_buffer_deliver(struct saa7164_buffer *buf)
 {
-       struct saa7164_tsport *port = buf->port;
+       struct saa7164_port *port = buf->port;
 
        /* Feed the transport payload into the kernel demux */
        dvb_dmx_swfilter_packets(&port->dvb.demux, (u8 *)buf->cpu,
@@ -82,7 +451,31 @@ static void saa7164_buffer_deliver(struct saa7164_buffer *buf)
 
 }
 
-static irqreturn_t saa7164_irq_ts(struct saa7164_tsport *port)
+static irqreturn_t saa7164_irq_encoder(struct saa7164_port *port)
+{
+       struct saa7164_dev *dev = port->dev;
+
+       /* Store old time */
+       port->last_irq_msecs_diff = port->last_irq_msecs;
+
+       /* Collect new stats */
+       port->last_irq_msecs = jiffies_to_msecs(jiffies);
+
+       /* Calculate stats */
+       port->last_irq_msecs_diff = port->last_irq_msecs -
+               port->last_irq_msecs_diff;
+
+       saa7164_histogram_update(&port->irq_interval,
+               port->last_irq_msecs_diff);
+
+       dprintk(DBGLVL_IRQ, "%s() %Ldms elapsed\n", __func__,
+               port->last_irq_msecs_diff);
+
+       schedule_work(&port->workenc);
+       return 0;
+}
+
+static irqreturn_t saa7164_irq_ts(struct saa7164_port *port)
 {
        struct saa7164_dev *dev = port->dev;
        struct saa7164_buffer *buf;
@@ -96,7 +489,7 @@ static irqreturn_t saa7164_irq_ts(struct saa7164_tsport *port)
 
        /* Find the previous buffer to the current write point */
        if (wp == 0)
-               rp = 7;
+               rp = (port->hwcfg.buffercount - 1);
        else
                rp = wp - 1;
 
@@ -107,7 +500,7 @@ static irqreturn_t saa7164_irq_ts(struct saa7164_tsport *port)
                if (i++ > port->hwcfg.buffercount)
                        BUG();
 
-               if (buf->nr == rp) {
+               if (buf->idx == rp) {
                        /* Found the buffer, deal with it */
                        dprintk(DBGLVL_IRQ, "%s() wp: %d processing: %d\n",
                                __func__, wp, rp);
@@ -123,6 +516,11 @@ static irqreturn_t saa7164_irq_ts(struct saa7164_tsport *port)
 static irqreturn_t saa7164_irq(int irq, void *dev_id)
 {
        struct saa7164_dev *dev = dev_id;
+       struct saa7164_port *porta = &dev->ports[ SAA7164_PORT_TS1 ];
+       struct saa7164_port *portb = &dev->ports[ SAA7164_PORT_TS2 ];
+       struct saa7164_port *portc = &dev->ports[ SAA7164_PORT_ENC1 ];
+       struct saa7164_port *portd = &dev->ports[ SAA7164_PORT_ENC2 ];
+
        u32 intid, intstat[INT_SIZE/4];
        int i, handled = 0, bit;
 
@@ -168,17 +566,25 @@ static irqreturn_t saa7164_irq(int irq, void *dev_id)
                                if (intid == dev->intfdesc.bInterruptId) {
                                        /* A response to an cmd/api call */
                                        schedule_work(&dev->workcmd);
-                               } else if (intid ==
-                                       dev->ts1.hwcfg.interruptid) {
+                               } else if (intid == porta->hwcfg.interruptid) {
 
                                        /* Transport path 1 */
-                                       saa7164_irq_ts(&dev->ts1);
+                                       saa7164_irq_ts(porta);
 
-                               } else if (intid ==
-                                       dev->ts2.hwcfg.interruptid) {
+                               } else if (intid == portb->hwcfg.interruptid) {
 
                                        /* Transport path 2 */
-                                       saa7164_irq_ts(&dev->ts2);
+                                       saa7164_irq_ts(portb);
+
+                               } else if (intid == portc->hwcfg.interruptid) {
+
+                                       /* Encoder path 1 */
+                                       saa7164_irq_encoder(portc);
+
+                               } else if (intid == portd->hwcfg.interruptid) {
+
+                                       /* Encoder path 1 */
+                                       saa7164_irq_encoder(portd);
 
                                } else {
                                        /* Find the function */
@@ -356,10 +762,10 @@ static void saa7164_dump_busdesc(struct saa7164_dev *dev)
  */
 static void saa7164_get_descriptors(struct saa7164_dev *dev)
 {
-       memcpy(&dev->hwdesc, dev->bmmio, sizeof(tmComResHWDescr_t));
-       memcpy(&dev->intfdesc, dev->bmmio + sizeof(tmComResHWDescr_t),
+       memcpy_fromio(&dev->hwdesc, dev->bmmio, sizeof(tmComResHWDescr_t));
+       memcpy_fromio(&dev->intfdesc, dev->bmmio + sizeof(tmComResHWDescr_t),
                sizeof(tmComResInterfaceDescr_t));
-       memcpy(&dev->busdesc, dev->bmmio + dev->intfdesc.BARLocation,
+       memcpy_fromio(&dev->busdesc, dev->bmmio + dev->intfdesc.BARLocation,
                sizeof(tmComResBusDescr_t));
 
        if (dev->hwdesc.bLength != sizeof(tmComResHWDescr_t)) {
@@ -402,6 +808,50 @@ static int get_resources(struct saa7164_dev *dev)
        return -EBUSY;
 }
 
+static int saa7164_port_init(struct saa7164_dev *dev, int portnr)
+{
+       struct saa7164_port *port = 0;
+
+       if ((portnr < 0) || (portnr >= SAA7164_MAX_PORTS))
+               BUG();
+
+       port = &dev->ports[ portnr ];
+
+       port->dev = dev;
+       port->nr = portnr;
+
+       if ((portnr == SAA7164_PORT_TS1) || (portnr == SAA7164_PORT_TS2))
+               port->type = SAA7164_MPEG_DVB;
+       else
+       if ((portnr == SAA7164_PORT_ENC1) || (portnr == SAA7164_PORT_ENC2))
+               port->type = SAA7164_MPEG_ENCODER;
+       else
+               BUG();
+
+       /* Init all the critical resources */
+       mutex_init(&port->dvb.lock);
+       INIT_LIST_HEAD(&port->dmaqueue.list);
+       mutex_init(&port->dmaqueue_lock);
+
+       INIT_LIST_HEAD(&port->list_buf_used.list);
+       INIT_LIST_HEAD(&port->list_buf_free.list);
+       init_waitqueue_head(&port->wait_read);
+
+       /* We need a deferred interrupt handler for cmd handling */
+       INIT_WORK(&port->workenc, saa7164_work_enchandler);
+
+       saa7164_histogram_reset(&port->irq_interval, "irq intervals");
+       saa7164_histogram_reset(&port->svc_interval, "deferred intervals");
+       saa7164_histogram_reset(&port->irq_svc_interval,
+               "irq to deferred intervals");
+       saa7164_histogram_reset(&port->read_interval,
+               "encoder read() intervals");
+       saa7164_histogram_reset(&port->poll_interval,
+               "encoder poll() intervals");
+
+       return 0;
+}
+
 static int saa7164_dev_setup(struct saa7164_dev *dev)
 {
        int i;
@@ -443,23 +893,11 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)
        dev->i2c_bus[2].dev = dev;
        dev->i2c_bus[2].nr = 2;
 
-       /* Transport port A Defaults / setup */
-       dev->ts1.dev = dev;
-       dev->ts1.nr = 0;
-       mutex_init(&dev->ts1.dvb.lock);
-       INIT_LIST_HEAD(&dev->ts1.dmaqueue.list);
-       INIT_LIST_HEAD(&dev->ts1.dummy_dmaqueue.list);
-       mutex_init(&dev->ts1.dmaqueue_lock);
-       mutex_init(&dev->ts1.dummy_dmaqueue_lock);
-
-       /* Transport port B Defaults / setup */
-       dev->ts2.dev = dev;
-       dev->ts2.nr = 1;
-       mutex_init(&dev->ts2.dvb.lock);
-       INIT_LIST_HEAD(&dev->ts2.dmaqueue.list);
-       INIT_LIST_HEAD(&dev->ts2.dummy_dmaqueue.list);
-       mutex_init(&dev->ts2.dmaqueue_lock);
-       mutex_init(&dev->ts2.dummy_dmaqueue_lock);
+       /* Transport + Encoder ports 1, 2, 3, 4 - Defaults / setup */
+       saa7164_port_init(dev, SAA7164_PORT_TS1);
+       saa7164_port_init(dev, SAA7164_PORT_TS2);
+       saa7164_port_init(dev, SAA7164_PORT_ENC1);
+       saa7164_port_init(dev, SAA7164_PORT_ENC2);
 
        if (get_resources(dev) < 0) {
                printk(KERN_ERR "CORE %s No more PCIe resources for "
@@ -633,7 +1071,7 @@ static int __devinit saa7164_initdev(struct pci_dev *pci_dev,
 
                /* Begin to create the video sub-systems and register funcs */
                if (saa7164_boards[dev->board].porta == SAA7164_MPEG_DVB) {
-                       if (saa7164_dvb_register(&dev->ts1) < 0) {
+                       if (saa7164_dvb_register(&dev->ports[ SAA7164_PORT_TS1 ]) < 0) {
                                printk(KERN_ERR "%s() Failed to register "
                                        "dvb adapters on porta\n",
                                        __func__);
@@ -641,13 +1079,27 @@ static int __devinit saa7164_initdev(struct pci_dev *pci_dev,
                }
 
                if (saa7164_boards[dev->board].portb == SAA7164_MPEG_DVB) {
-                       if (saa7164_dvb_register(&dev->ts2) < 0) {
+                       if (saa7164_dvb_register(&dev->ports[ SAA7164_PORT_TS2 ]) < 0) {
                                printk(KERN_ERR"%s() Failed to register "
                                        "dvb adapters on portb\n",
                                        __func__);
                        }
                }
 
+               if (saa7164_boards[dev->board].portc == SAA7164_MPEG_ENCODER) {
+                       if (saa7164_encoder_register(&dev->ports[ SAA7164_PORT_ENC1 ]) < 0) {
+                               printk(KERN_ERR"%s() Failed to register "
+                                       "mpeg encoder\n", __func__);
+                       }
+               }
+
+               if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER) {
+                       if (saa7164_encoder_register(&dev->ports[ SAA7164_PORT_ENC2 ]) < 0) {
+                               printk(KERN_ERR"%s() Failed to register "
+                                       "mpeg encoder\n", __func__);
+                       }
+               }
+
        } /* != BOARD_UNKNOWN */
        else
                printk(KERN_ERR "%s() Unsupported board detected, "
@@ -675,13 +1127,30 @@ static void __devexit saa7164_finidev(struct pci_dev *pci_dev)
 {
        struct saa7164_dev *dev = pci_get_drvdata(pci_dev);
 
+       saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
+               &dev->ports[ SAA7164_PORT_ENC1 ].irq_interval);
+       saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
+               &dev->ports[ SAA7164_PORT_ENC1 ].svc_interval);
+       saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
+               &dev->ports[ SAA7164_PORT_ENC1 ].irq_svc_interval);
+       saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
+               &dev->ports[ SAA7164_PORT_ENC1 ].read_interval);
+       saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
+               &dev->ports[ SAA7164_PORT_ENC1 ].poll_interval);
+
        saa7164_shutdown(dev);
 
        if (saa7164_boards[dev->board].porta == SAA7164_MPEG_DVB)
-               saa7164_dvb_unregister(&dev->ts1);
+               saa7164_dvb_unregister(&dev->ports[ SAA7164_PORT_TS1 ]);
 
        if (saa7164_boards[dev->board].portb == SAA7164_MPEG_DVB)
-               saa7164_dvb_unregister(&dev->ts2);
+               saa7164_dvb_unregister(&dev->ports[ SAA7164_PORT_TS2 ]);
+
+       if (saa7164_boards[dev->board].portc == SAA7164_MPEG_ENCODER)
+               saa7164_encoder_unregister(&dev->ports[ SAA7164_PORT_ENC1 ]);
+
+       if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER)
+               saa7164_encoder_unregister(&dev->ports[ SAA7164_PORT_ENC2 ]);
 
        saa7164_i2c_unregister(&dev->i2c_bus[0]);
        saa7164_i2c_unregister(&dev->i2c_bus[1]);
This page took 0.046158 seconds and 5 git commands to generate.