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
= 2;
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 /* Validate the incoming buffer content */
323 if (port
->encoder_params
.stream_type
== V4L2_MPEG_STREAM_TYPE_MPEG2_TS
)
324 saa7164_ts_verifier(buf
);
325 else if (port
->encoder_params
.stream_type
== V4L2_MPEG_STREAM_TYPE_MPEG2_PS
)
326 saa7164_pack_verifier(buf
);
328 /* find a free user buffer and clone to it */
329 if (!list_empty(&port
->list_buf_free
.list
)) {
331 /* Pull the first buffer from the used list */
332 ubuf
= list_first_entry(&port
->list_buf_free
.list
,
333 struct saa7164_user_buffer
, list
);
335 if (buf
->actual_size
<= ubuf
->actual_size
) {
337 memcpy_fromio(ubuf
->data
, buf
->cpu
,
341 /* Throw a new checksum on the read buffer */
342 ubuf
->crc
= crc32(0, ubuf
->data
, ubuf
->actual_size
);
345 /* Requeue the buffer on the free list */
348 list_move_tail(&ubuf
->list
,
349 &port
->list_buf_used
.list
);
351 /* Flag any userland waiters */
352 wake_up_interruptible(&port
->wait_read
);
355 printk(KERN_ERR
"buf %p bufsize fails match\n", buf
);
359 printk(KERN_ERR
"encirq no free buffers, increase param encoder_buffers\n");
361 /* Ensure offset into buffer remains 0, fill buffer
362 * with known bad data. We check for this data at a later point
364 saa7164_buffer_zero_offsets(port
, bufnr
);
365 memset_io(buf
->cpu
, 0xff, buf
->pci_size
);
367 /* Throw yet aanother new checksum on the dma buffer */
368 buf
->crc
= crc32(0, buf
->cpu
, buf
->actual_size
);
374 mutex_unlock(&port
->dmaqueue_lock
);
377 static void saa7164_work_enchandler(struct work_struct
*w
)
379 struct saa7164_port
*port
=
380 container_of(w
, struct saa7164_port
, workenc
);
381 struct saa7164_dev
*dev
= port
->dev
;
383 u32 wp
, mcb
, rp
, cnt
= 0;
385 port
->last_svc_msecs_diff
= port
->last_svc_msecs
;
386 port
->last_svc_msecs
= jiffies_to_msecs(jiffies
);
388 port
->last_svc_msecs_diff
= port
->last_svc_msecs
-
389 port
->last_svc_msecs_diff
;
391 saa7164_histogram_update(&port
->svc_interval
,
392 port
->last_svc_msecs_diff
);
394 port
->last_irq_svc_msecs_diff
= port
->last_svc_msecs
-
395 port
->last_irq_msecs
;
397 saa7164_histogram_update(&port
->irq_svc_interval
,
398 port
->last_irq_svc_msecs_diff
);
401 "%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
403 port
->last_svc_msecs_diff
,
404 port
->last_irq_svc_msecs_diff
,
409 /* Current write position */
410 wp
= saa7164_readl(port
->bufcounter
);
411 if (wp
> (port
->hwcfg
.buffercount
- 1)) {
412 printk(KERN_ERR
"%s() illegal buf count %d\n", __func__
, wp
);
416 /* Most current complete buffer */
418 mcb
= (port
->hwcfg
.buffercount
- 1);
423 if (port
->done_first_interrupt
== 0) {
424 port
->done_first_interrupt
++;
427 rp
= (port
->last_svc_rp
+ 1) % 8;
429 if ((rp
< 0) || (rp
> (port
->hwcfg
.buffercount
- 1))) {
430 printk(KERN_ERR
"%s() illegal rp count %d\n", __func__
, rp
);
434 saa7164_work_enchandler_helper(port
, rp
);
435 port
->last_svc_rp
= rp
;
442 /* TODO: Convert this into a /proc/saa7164 style readable file */
443 if (print_histogram
== port
->nr
) {
444 saa7164_histogram_print(port
, &port
->irq_interval
);
445 saa7164_histogram_print(port
, &port
->svc_interval
);
446 saa7164_histogram_print(port
, &port
->irq_svc_interval
);
447 saa7164_histogram_print(port
, &port
->read_interval
);
448 saa7164_histogram_print(port
, &port
->poll_interval
);
449 /* TODO: fix this to preserve any previous state */
450 print_histogram
= 64 + port
->nr
;
454 static void saa7164_work_vbihandler(struct work_struct
*w
)
456 struct saa7164_port
*port
=
457 container_of(w
, struct saa7164_port
, workenc
);
458 struct saa7164_dev
*dev
= port
->dev
;
460 u32 wp
, mcb
, rp
, cnt
= 0;
462 port
->last_svc_msecs_diff
= port
->last_svc_msecs
;
463 port
->last_svc_msecs
= jiffies_to_msecs(jiffies
);
464 port
->last_svc_msecs_diff
= port
->last_svc_msecs
-
465 port
->last_svc_msecs_diff
;
467 saa7164_histogram_update(&port
->svc_interval
,
468 port
->last_svc_msecs_diff
);
470 port
->last_irq_svc_msecs_diff
= port
->last_svc_msecs
-
471 port
->last_irq_msecs
;
473 saa7164_histogram_update(&port
->irq_svc_interval
,
474 port
->last_irq_svc_msecs_diff
);
477 "%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
479 port
->last_svc_msecs_diff
,
480 port
->last_irq_svc_msecs_diff
,
485 /* Current write position */
486 wp
= saa7164_readl(port
->bufcounter
);
487 if (wp
> (port
->hwcfg
.buffercount
- 1)) {
488 printk(KERN_ERR
"%s() illegal buf count %d\n", __func__
, wp
);
492 /* Most current complete buffer */
494 mcb
= (port
->hwcfg
.buffercount
- 1);
497 /* TODO: Convert this into a /proc/saa7164 style readable file */
498 if (print_histogram
== port
->nr
) {
499 saa7164_histogram_print(port
, &port
->irq_interval
);
500 saa7164_histogram_print(port
, &port
->svc_interval
);
501 saa7164_histogram_print(port
, &port
->irq_svc_interval
);
502 saa7164_histogram_print(port
, &port
->read_interval
);
503 saa7164_histogram_print(port
, &port
->poll_interval
);
504 /* TODO: fix this to preserve any previous state */
505 print_histogram
= 64 + port
->nr
;
509 static void saa7164_work_cmdhandler(struct work_struct
*w
)
511 struct saa7164_dev
*dev
= container_of(w
, struct saa7164_dev
, workcmd
);
513 /* Wake up any complete commands */
514 saa7164_irq_dequeue(dev
);
517 static void saa7164_buffer_deliver(struct saa7164_buffer
*buf
)
519 struct saa7164_port
*port
= buf
->port
;
521 /* Feed the transport payload into the kernel demux */
522 dvb_dmx_swfilter_packets(&port
->dvb
.demux
, (u8
*)buf
->cpu
,
523 SAA7164_TS_NUMBER_OF_LINES
);
527 static irqreturn_t
saa7164_irq_vbi(struct saa7164_port
*port
)
529 struct saa7164_dev
*dev
= port
->dev
;
532 port
->last_irq_msecs_diff
= port
->last_irq_msecs
;
534 /* Collect new stats */
535 port
->last_irq_msecs
= jiffies_to_msecs(jiffies
);
537 /* Calculate stats */
538 port
->last_irq_msecs_diff
= port
->last_irq_msecs
-
539 port
->last_irq_msecs_diff
;
541 saa7164_histogram_update(&port
->irq_interval
,
542 port
->last_irq_msecs_diff
);
544 dprintk(DBGLVL_IRQ
, "%s() %Ldms elapsed\n", __func__
,
545 port
->last_irq_msecs_diff
);
547 /* Tis calls the vbi irq handler */
548 schedule_work(&port
->workenc
);
552 static irqreturn_t
saa7164_irq_encoder(struct saa7164_port
*port
)
554 struct saa7164_dev
*dev
= port
->dev
;
557 port
->last_irq_msecs_diff
= port
->last_irq_msecs
;
559 /* Collect new stats */
560 port
->last_irq_msecs
= jiffies_to_msecs(jiffies
);
562 /* Calculate stats */
563 port
->last_irq_msecs_diff
= port
->last_irq_msecs
-
564 port
->last_irq_msecs_diff
;
566 saa7164_histogram_update(&port
->irq_interval
,
567 port
->last_irq_msecs_diff
);
569 dprintk(DBGLVL_IRQ
, "%s() %Ldms elapsed\n", __func__
,
570 port
->last_irq_msecs_diff
);
572 schedule_work(&port
->workenc
);
576 static irqreturn_t
saa7164_irq_ts(struct saa7164_port
*port
)
578 struct saa7164_dev
*dev
= port
->dev
;
579 struct saa7164_buffer
*buf
;
580 struct list_head
*c
, *n
;
583 /* Find the current write point from the hardware */
584 wp
= saa7164_readl(port
->bufcounter
);
585 if (wp
> (port
->hwcfg
.buffercount
- 1))
588 /* Find the previous buffer to the current write point */
590 rp
= (port
->hwcfg
.buffercount
- 1);
594 /* Lookup the WP in the buffer list */
595 /* TODO: turn this into a worker thread */
596 list_for_each_safe(c
, n
, &port
->dmaqueue
.list
) {
597 buf
= list_entry(c
, struct saa7164_buffer
, list
);
598 if (i
++ > port
->hwcfg
.buffercount
)
601 if (buf
->idx
== rp
) {
602 /* Found the buffer, deal with it */
603 dprintk(DBGLVL_IRQ
, "%s() wp: %d processing: %d\n",
605 saa7164_buffer_deliver(buf
);
613 /* Primary IRQ handler and dispatch mechanism */
614 static irqreturn_t
saa7164_irq(int irq
, void *dev_id
)
616 struct saa7164_dev
*dev
= dev_id
;
617 struct saa7164_port
*porta
= &dev
->ports
[ SAA7164_PORT_TS1
];
618 struct saa7164_port
*portb
= &dev
->ports
[ SAA7164_PORT_TS2
];
619 struct saa7164_port
*portc
= &dev
->ports
[ SAA7164_PORT_ENC1
];
620 struct saa7164_port
*portd
= &dev
->ports
[ SAA7164_PORT_ENC2
];
621 struct saa7164_port
*porte
= &dev
->ports
[ SAA7164_PORT_VBI1
];
622 struct saa7164_port
*portf
= &dev
->ports
[ SAA7164_PORT_VBI2
];
624 u32 intid
, intstat
[INT_SIZE
/4];
625 int i
, handled
= 0, bit
;
628 printk(KERN_ERR
"%s() No device specified\n", __func__
);
633 /* Check that the hardware is accessable. If the status bytes are
634 * 0xFF then the device is not accessable, the the IRQ belongs
636 * 4 x u32 interrupt registers.
638 for (i
= 0; i
< INT_SIZE
/4; i
++) {
640 /* TODO: Convert into saa7164_readl() */
641 /* Read the 4 hardware interrupt registers */
642 intstat
[i
] = saa7164_readl(dev
->int_status
+ (i
* 4));
650 /* For each of the HW interrupt registers */
651 for (i
= 0; i
< INT_SIZE
/4; i
++) {
654 /* Each function of the board has it's own interruptid.
655 * Find the function that triggered then call
658 for (bit
= 0; bit
< 32; bit
++) {
660 if (((intstat
[i
] >> bit
) & 0x00000001) == 0)
663 /* Calculate the interrupt id (0x00 to 0x7f) */
665 intid
= (i
* 32) + bit
;
666 if (intid
== dev
->intfdesc
.bInterruptId
) {
667 /* A response to an cmd/api call */
668 schedule_work(&dev
->workcmd
);
669 } else if (intid
== porta
->hwcfg
.interruptid
) {
671 /* Transport path 1 */
672 saa7164_irq_ts(porta
);
674 } else if (intid
== portb
->hwcfg
.interruptid
) {
676 /* Transport path 2 */
677 saa7164_irq_ts(portb
);
679 } else if (intid
== portc
->hwcfg
.interruptid
) {
682 saa7164_irq_encoder(portc
);
684 } else if (intid
== portd
->hwcfg
.interruptid
) {
687 saa7164_irq_encoder(portd
);
689 } else if (intid
== porte
->hwcfg
.interruptid
) {
692 saa7164_irq_vbi(porte
);
694 } else if (intid
== portf
->hwcfg
.interruptid
) {
697 saa7164_irq_vbi(portf
);
700 /* Find the function */
702 "%s() unhandled interrupt "
705 __func__
, i
, bit
, intid
);
710 saa7164_writel(dev
->int_ack
+ (i
* 4), intstat
[i
]);
715 return IRQ_RETVAL(handled
);
718 void saa7164_getfirmwarestatus(struct saa7164_dev
*dev
)
720 struct saa7164_fw_status
*s
= &dev
->fw_status
;
722 dev
->fw_status
.status
= saa7164_readl(SAA_DEVICE_SYSINIT_STATUS
);
723 dev
->fw_status
.mode
= saa7164_readl(SAA_DEVICE_SYSINIT_MODE
);
724 dev
->fw_status
.spec
= saa7164_readl(SAA_DEVICE_SYSINIT_SPEC
);
725 dev
->fw_status
.inst
= saa7164_readl(SAA_DEVICE_SYSINIT_INST
);
726 dev
->fw_status
.cpuload
= saa7164_readl(SAA_DEVICE_SYSINIT_CPULOAD
);
727 dev
->fw_status
.remainheap
=
728 saa7164_readl(SAA_DEVICE_SYSINIT_REMAINHEAP
);
730 dprintk(1, "Firmware status:\n");
731 dprintk(1, " .status = 0x%08x\n", s
->status
);
732 dprintk(1, " .mode = 0x%08x\n", s
->mode
);
733 dprintk(1, " .spec = 0x%08x\n", s
->spec
);
734 dprintk(1, " .inst = 0x%08x\n", s
->inst
);
735 dprintk(1, " .cpuload = 0x%08x\n", s
->cpuload
);
736 dprintk(1, " .remainheap = 0x%08x\n", s
->remainheap
);
739 u32
saa7164_getcurrentfirmwareversion(struct saa7164_dev
*dev
)
743 reg
= saa7164_readl(SAA_DEVICE_VERSION
);
744 dprintk(1, "Device running firmware version %d.%d.%d.%d (0x%x)\n",
745 (reg
& 0x0000fc00) >> 10,
746 (reg
& 0x000003e0) >> 5,
748 (reg
& 0xffff0000) >> 16,
754 /* TODO: Debugging func, remove */
755 void saa7164_dumphex16(struct saa7164_dev
*dev
, u8
*buf
, int len
)
759 printk(KERN_INFO
"--------------------> "
760 "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
762 for (i
= 0; i
< len
; i
+= 16)
763 printk(KERN_INFO
" [0x%08x] "
764 "%02x %02x %02x %02x %02x %02x %02x %02x "
765 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i
,
766 *(buf
+i
+0), *(buf
+i
+1), *(buf
+i
+2), *(buf
+i
+3),
767 *(buf
+i
+4), *(buf
+i
+5), *(buf
+i
+6), *(buf
+i
+7),
768 *(buf
+i
+8), *(buf
+i
+9), *(buf
+i
+10), *(buf
+i
+11),
769 *(buf
+i
+12), *(buf
+i
+13), *(buf
+i
+14), *(buf
+i
+15));
772 /* TODO: Debugging func, remove */
773 void saa7164_dumpregs(struct saa7164_dev
*dev
, u32 addr
)
777 dprintk(1, "--------------------> "
778 "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
780 for (i
= 0; i
< 0x100; i
+= 16)
781 dprintk(1, "region0[0x%08x] = "
782 "%02x %02x %02x %02x %02x %02x %02x %02x"
783 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i
,
784 (u8
)saa7164_readb(addr
+ i
+ 0),
785 (u8
)saa7164_readb(addr
+ i
+ 1),
786 (u8
)saa7164_readb(addr
+ i
+ 2),
787 (u8
)saa7164_readb(addr
+ i
+ 3),
788 (u8
)saa7164_readb(addr
+ i
+ 4),
789 (u8
)saa7164_readb(addr
+ i
+ 5),
790 (u8
)saa7164_readb(addr
+ i
+ 6),
791 (u8
)saa7164_readb(addr
+ i
+ 7),
792 (u8
)saa7164_readb(addr
+ i
+ 8),
793 (u8
)saa7164_readb(addr
+ i
+ 9),
794 (u8
)saa7164_readb(addr
+ i
+ 10),
795 (u8
)saa7164_readb(addr
+ i
+ 11),
796 (u8
)saa7164_readb(addr
+ i
+ 12),
797 (u8
)saa7164_readb(addr
+ i
+ 13),
798 (u8
)saa7164_readb(addr
+ i
+ 14),
799 (u8
)saa7164_readb(addr
+ i
+ 15)
803 static void saa7164_dump_hwdesc(struct saa7164_dev
*dev
)
805 dprintk(1, "@0x%p hwdesc sizeof(tmComResHWDescr_t) = %d bytes\n",
806 &dev
->hwdesc
, (u32
)sizeof(tmComResHWDescr_t
));
808 dprintk(1, " .bLength = 0x%x\n", dev
->hwdesc
.bLength
);
809 dprintk(1, " .bDescriptorType = 0x%x\n", dev
->hwdesc
.bDescriptorType
);
810 dprintk(1, " .bDescriptorSubtype = 0x%x\n",
811 dev
->hwdesc
.bDescriptorSubtype
);
813 dprintk(1, " .bcdSpecVersion = 0x%x\n", dev
->hwdesc
.bcdSpecVersion
);
814 dprintk(1, " .dwClockFrequency = 0x%x\n", dev
->hwdesc
.dwClockFrequency
);
815 dprintk(1, " .dwClockUpdateRes = 0x%x\n", dev
->hwdesc
.dwClockUpdateRes
);
816 dprintk(1, " .bCapabilities = 0x%x\n", dev
->hwdesc
.bCapabilities
);
817 dprintk(1, " .dwDeviceRegistersLocation = 0x%x\n",
818 dev
->hwdesc
.dwDeviceRegistersLocation
);
820 dprintk(1, " .dwHostMemoryRegion = 0x%x\n",
821 dev
->hwdesc
.dwHostMemoryRegion
);
823 dprintk(1, " .dwHostMemoryRegionSize = 0x%x\n",
824 dev
->hwdesc
.dwHostMemoryRegionSize
);
826 dprintk(1, " .dwHostHibernatMemRegion = 0x%x\n",
827 dev
->hwdesc
.dwHostHibernatMemRegion
);
829 dprintk(1, " .dwHostHibernatMemRegionSize = 0x%x\n",
830 dev
->hwdesc
.dwHostHibernatMemRegionSize
);
833 static void saa7164_dump_intfdesc(struct saa7164_dev
*dev
)
835 dprintk(1, "@0x%p intfdesc "
836 "sizeof(tmComResInterfaceDescr_t) = %d bytes\n",
837 &dev
->intfdesc
, (u32
)sizeof(tmComResInterfaceDescr_t
));
839 dprintk(1, " .bLength = 0x%x\n", dev
->intfdesc
.bLength
);
840 dprintk(1, " .bDescriptorType = 0x%x\n", dev
->intfdesc
.bDescriptorType
);
841 dprintk(1, " .bDescriptorSubtype = 0x%x\n",
842 dev
->intfdesc
.bDescriptorSubtype
);
844 dprintk(1, " .bFlags = 0x%x\n", dev
->intfdesc
.bFlags
);
845 dprintk(1, " .bInterfaceType = 0x%x\n", dev
->intfdesc
.bInterfaceType
);
846 dprintk(1, " .bInterfaceId = 0x%x\n", dev
->intfdesc
.bInterfaceId
);
847 dprintk(1, " .bBaseInterface = 0x%x\n", dev
->intfdesc
.bBaseInterface
);
848 dprintk(1, " .bInterruptId = 0x%x\n", dev
->intfdesc
.bInterruptId
);
849 dprintk(1, " .bDebugInterruptId = 0x%x\n",
850 dev
->intfdesc
.bDebugInterruptId
);
852 dprintk(1, " .BARLocation = 0x%x\n", dev
->intfdesc
.BARLocation
);
855 static void saa7164_dump_busdesc(struct saa7164_dev
*dev
)
857 dprintk(1, "@0x%p busdesc sizeof(tmComResBusDescr_t) = %d bytes\n",
858 &dev
->busdesc
, (u32
)sizeof(tmComResBusDescr_t
));
860 dprintk(1, " .CommandRing = 0x%016Lx\n", dev
->busdesc
.CommandRing
);
861 dprintk(1, " .ResponseRing = 0x%016Lx\n", dev
->busdesc
.ResponseRing
);
862 dprintk(1, " .CommandWrite = 0x%x\n", dev
->busdesc
.CommandWrite
);
863 dprintk(1, " .CommandRead = 0x%x\n", dev
->busdesc
.CommandRead
);
864 dprintk(1, " .ResponseWrite = 0x%x\n", dev
->busdesc
.ResponseWrite
);
865 dprintk(1, " .ResponseRead = 0x%x\n", dev
->busdesc
.ResponseRead
);
868 /* Much of the hardware configuration and PCI registers are configured
869 * dynamically depending on firmware. We have to cache some initial
870 * structures then use these to locate other important structures
873 static void saa7164_get_descriptors(struct saa7164_dev
*dev
)
875 memcpy_fromio(&dev
->hwdesc
, dev
->bmmio
, sizeof(tmComResHWDescr_t
));
876 memcpy_fromio(&dev
->intfdesc
, dev
->bmmio
+ sizeof(tmComResHWDescr_t
),
877 sizeof(tmComResInterfaceDescr_t
));
878 memcpy_fromio(&dev
->busdesc
, dev
->bmmio
+ dev
->intfdesc
.BARLocation
,
879 sizeof(tmComResBusDescr_t
));
881 if (dev
->hwdesc
.bLength
!= sizeof(tmComResHWDescr_t
)) {
882 printk(KERN_ERR
"Structure tmComResHWDescr_t is mangled\n");
883 printk(KERN_ERR
"Need %x got %d\n", dev
->hwdesc
.bLength
,
884 (u32
)sizeof(tmComResHWDescr_t
));
886 saa7164_dump_hwdesc(dev
);
888 if (dev
->intfdesc
.bLength
!= sizeof(tmComResInterfaceDescr_t
)) {
889 printk(KERN_ERR
"struct tmComResInterfaceDescr_t is mangled\n");
890 printk(KERN_ERR
"Need %x got %d\n", dev
->intfdesc
.bLength
,
891 (u32
)sizeof(tmComResInterfaceDescr_t
));
893 saa7164_dump_intfdesc(dev
);
895 saa7164_dump_busdesc(dev
);
898 static int saa7164_pci_quirks(struct saa7164_dev
*dev
)
903 static int get_resources(struct saa7164_dev
*dev
)
905 if (request_mem_region(pci_resource_start(dev
->pci
, 0),
906 pci_resource_len(dev
->pci
, 0), dev
->name
)) {
908 if (request_mem_region(pci_resource_start(dev
->pci
, 2),
909 pci_resource_len(dev
->pci
, 2), dev
->name
))
913 printk(KERN_ERR
"%s: can't get MMIO memory @ 0x%llx or 0x%llx\n",
915 (u64
)pci_resource_start(dev
->pci
, 0),
916 (u64
)pci_resource_start(dev
->pci
, 2));
921 static int saa7164_port_init(struct saa7164_dev
*dev
, int portnr
)
923 struct saa7164_port
*port
= 0;
925 if ((portnr
< 0) || (portnr
>= SAA7164_MAX_PORTS
))
928 port
= &dev
->ports
[ portnr
];
933 if ((portnr
== SAA7164_PORT_TS1
) || (portnr
== SAA7164_PORT_TS2
))
934 port
->type
= SAA7164_MPEG_DVB
;
936 if ((portnr
== SAA7164_PORT_ENC1
) || (portnr
== SAA7164_PORT_ENC2
)) {
937 port
->type
= SAA7164_MPEG_ENCODER
;
939 /* We need a deferred interrupt handler for cmd handling */
940 INIT_WORK(&port
->workenc
, saa7164_work_enchandler
);
943 if ((portnr
== SAA7164_PORT_VBI1
) || (portnr
== SAA7164_PORT_VBI2
)) {
944 port
->type
= SAA7164_MPEG_VBI
;
946 /* We need a deferred interrupt handler for cmd handling */
947 INIT_WORK(&port
->workenc
, saa7164_work_vbihandler
);
951 /* Init all the critical resources */
952 mutex_init(&port
->dvb
.lock
);
953 INIT_LIST_HEAD(&port
->dmaqueue
.list
);
954 mutex_init(&port
->dmaqueue_lock
);
956 INIT_LIST_HEAD(&port
->list_buf_used
.list
);
957 INIT_LIST_HEAD(&port
->list_buf_free
.list
);
958 init_waitqueue_head(&port
->wait_read
);
961 saa7164_histogram_reset(&port
->irq_interval
, "irq intervals");
962 saa7164_histogram_reset(&port
->svc_interval
, "deferred intervals");
963 saa7164_histogram_reset(&port
->irq_svc_interval
,
964 "irq to deferred intervals");
965 saa7164_histogram_reset(&port
->read_interval
,
966 "encoder/vbi read() intervals");
967 saa7164_histogram_reset(&port
->poll_interval
,
968 "encoder/vbi poll() intervals");
973 static int saa7164_dev_setup(struct saa7164_dev
*dev
)
977 mutex_init(&dev
->lock
);
978 atomic_inc(&dev
->refcount
);
979 dev
->nr
= saa7164_devcount
++;
981 sprintf(dev
->name
, "saa7164[%d]", dev
->nr
);
983 mutex_lock(&devlist
);
984 list_add_tail(&dev
->devlist
, &saa7164_devlist
);
985 mutex_unlock(&devlist
);
989 if (card
[dev
->nr
] < saa7164_bcount
)
990 dev
->board
= card
[dev
->nr
];
992 for (i
= 0; UNSET
== dev
->board
&& i
< saa7164_idcount
; i
++)
993 if (dev
->pci
->subsystem_vendor
== saa7164_subids
[i
].subvendor
&&
994 dev
->pci
->subsystem_device
==
995 saa7164_subids
[i
].subdevice
)
996 dev
->board
= saa7164_subids
[i
].card
;
998 if (UNSET
== dev
->board
) {
999 dev
->board
= SAA7164_BOARD_UNKNOWN
;
1000 saa7164_card_list(dev
);
1003 dev
->pci_bus
= dev
->pci
->bus
->number
;
1004 dev
->pci_slot
= PCI_SLOT(dev
->pci
->devfn
);
1006 /* I2C Defaults / setup */
1007 dev
->i2c_bus
[0].dev
= dev
;
1008 dev
->i2c_bus
[0].nr
= 0;
1009 dev
->i2c_bus
[1].dev
= dev
;
1010 dev
->i2c_bus
[1].nr
= 1;
1011 dev
->i2c_bus
[2].dev
= dev
;
1012 dev
->i2c_bus
[2].nr
= 2;
1014 /* Transport + Encoder ports 1, 2, 3, 4 - Defaults / setup */
1015 saa7164_port_init(dev
, SAA7164_PORT_TS1
);
1016 saa7164_port_init(dev
, SAA7164_PORT_TS2
);
1017 saa7164_port_init(dev
, SAA7164_PORT_ENC1
);
1018 saa7164_port_init(dev
, SAA7164_PORT_ENC2
);
1019 saa7164_port_init(dev
, SAA7164_PORT_VBI1
);
1020 saa7164_port_init(dev
, SAA7164_PORT_VBI2
);
1022 if (get_resources(dev
) < 0) {
1023 printk(KERN_ERR
"CORE %s No more PCIe resources for "
1024 "subsystem: %04x:%04x\n",
1025 dev
->name
, dev
->pci
->subsystem_vendor
,
1026 dev
->pci
->subsystem_device
);
1032 /* PCI/e allocations */
1033 dev
->lmmio
= ioremap(pci_resource_start(dev
->pci
, 0),
1034 pci_resource_len(dev
->pci
, 0));
1036 dev
->lmmio2
= ioremap(pci_resource_start(dev
->pci
, 2),
1037 pci_resource_len(dev
->pci
, 2));
1039 dev
->bmmio
= (u8 __iomem
*)dev
->lmmio
;
1040 dev
->bmmio2
= (u8 __iomem
*)dev
->lmmio2
;
1042 /* Inerrupt and ack register locations offset of bmmio */
1043 dev
->int_status
= 0x183000 + 0xf80;
1044 dev
->int_ack
= 0x183000 + 0xf90;
1047 "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
1048 dev
->name
, dev
->pci
->subsystem_vendor
,
1049 dev
->pci
->subsystem_device
, saa7164_boards
[dev
->board
].name
,
1050 dev
->board
, card
[dev
->nr
] == dev
->board
?
1051 "insmod option" : "autodetected");
1053 saa7164_pci_quirks(dev
);
1058 static void saa7164_dev_unregister(struct saa7164_dev
*dev
)
1060 dprintk(1, "%s()\n", __func__
);
1062 release_mem_region(pci_resource_start(dev
->pci
, 0),
1063 pci_resource_len(dev
->pci
, 0));
1065 release_mem_region(pci_resource_start(dev
->pci
, 2),
1066 pci_resource_len(dev
->pci
, 2));
1068 if (!atomic_dec_and_test(&dev
->refcount
))
1071 iounmap(dev
->lmmio
);
1072 iounmap(dev
->lmmio2
);
1077 #ifdef CONFIG_PROC_FS
1078 static int saa7164_proc_show(struct seq_file
*m
, void *v
)
1080 struct saa7164_dev
*dev
;
1081 tmComResBusInfo_t
*b
;
1082 struct list_head
*list
;
1085 if (saa7164_devcount
== 0)
1088 list_for_each(list
, &saa7164_devlist
) {
1089 dev
= list_entry(list
, struct saa7164_dev
, devlist
);
1090 seq_printf(m
, "%s = %p\n", dev
->name
, dev
);
1092 if (dev
->board
!= SAA7164_BOARD_UNKNOWN
) {
1093 seq_printf(m
, "Firmware messages ----->\n");
1094 saa7164_api_collect_debug(dev
, m
);
1095 seq_printf(m
, "<---- Firmware messages\n");
1098 /* Lock the bus from any other access */
1100 mutex_lock(&b
->lock
);
1103 mutex_unlock(&b
->lock
);
1110 static int saa7164_proc_open(struct inode
*inode
, struct file
*filp
)
1112 return single_open(filp
, saa7164_proc_show
, NULL
);
1115 static struct file_operations saa7164_proc_fops
= {
1116 .open
= saa7164_proc_open
,
1118 .llseek
= seq_lseek
,
1119 .release
= single_release
,
1122 static int saa7164_proc_create(void)
1124 struct proc_dir_entry
*pe
;
1126 pe
= proc_create("saa7164", S_IRUGO
, NULL
, &saa7164_proc_fops
);
1134 static int __devinit
saa7164_initdev(struct pci_dev
*pci_dev
,
1135 const struct pci_device_id
*pci_id
)
1137 struct saa7164_dev
*dev
;
1141 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
1147 if (pci_enable_device(pci_dev
)) {
1152 if (saa7164_dev_setup(dev
) < 0) {
1157 /* print pci info */
1158 pci_read_config_byte(pci_dev
, PCI_CLASS_REVISION
, &dev
->pci_rev
);
1159 pci_read_config_byte(pci_dev
, PCI_LATENCY_TIMER
, &dev
->pci_lat
);
1160 printk(KERN_INFO
"%s/0: found at %s, rev: %d, irq: %d, "
1161 "latency: %d, mmio: 0x%llx\n", dev
->name
,
1162 pci_name(pci_dev
), dev
->pci_rev
, pci_dev
->irq
,
1164 (unsigned long long)pci_resource_start(pci_dev
, 0));
1166 pci_set_master(pci_dev
);
1168 if (!pci_dma_supported(pci_dev
, 0xffffffff)) {
1169 printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev
->name
);
1174 err
= request_irq(pci_dev
->irq
, saa7164_irq
,
1175 IRQF_SHARED
| IRQF_DISABLED
, dev
->name
, dev
);
1177 printk(KERN_ERR
"%s: can't get IRQ %d\n", dev
->name
,
1183 pci_set_drvdata(pci_dev
, dev
);
1185 /* Init the internal command list */
1186 for (i
= 0; i
< SAA_CMD_MAX_MSG_UNITS
; i
++) {
1187 dev
->cmds
[i
].seqno
= i
;
1188 dev
->cmds
[i
].inuse
= 0;
1189 mutex_init(&dev
->cmds
[i
].lock
);
1190 init_waitqueue_head(&dev
->cmds
[i
].wait
);
1193 /* We need a deferred interrupt handler for cmd handling */
1194 INIT_WORK(&dev
->workcmd
, saa7164_work_cmdhandler
);
1196 /* Only load the firmware if we know the board */
1197 if (dev
->board
!= SAA7164_BOARD_UNKNOWN
) {
1199 err
= saa7164_downloadfirmware(dev
);
1202 "Failed to boot firmware, no features "
1207 saa7164_get_descriptors(dev
);
1208 saa7164_dumpregs(dev
, 0);
1209 saa7164_getcurrentfirmwareversion(dev
);
1210 saa7164_getfirmwarestatus(dev
);
1211 err
= saa7164_bus_setup(dev
);
1214 "Failed to setup the bus, will continue\n");
1215 saa7164_bus_dump(dev
);
1217 /* Ping the running firmware via the command bus and get the
1218 * firmware version, this checks the bus is running OK.
1221 if (saa7164_api_get_fw_version(dev
, &version
) == SAA_OK
)
1222 dprintk(1, "Bus is operating correctly using "
1223 "version %d.%d.%d.%d (0x%x)\n",
1224 (version
& 0x0000fc00) >> 10,
1225 (version
& 0x000003e0) >> 5,
1226 (version
& 0x0000001f),
1227 (version
& 0xffff0000) >> 16,
1231 "Failed to communicate with the firmware\n");
1233 /* Bring up the I2C buses */
1234 saa7164_i2c_register(&dev
->i2c_bus
[0]);
1235 saa7164_i2c_register(&dev
->i2c_bus
[1]);
1236 saa7164_i2c_register(&dev
->i2c_bus
[2]);
1237 saa7164_gpio_setup(dev
);
1238 saa7164_card_setup(dev
);
1241 /* Parse the dynamic device configuration, find various
1242 * media endpoints (MPEG, WMV, PS, TS) and cache their
1243 * configuration details into the driver, so we can
1244 * reference them later during simething_register() func,
1245 * interrupt handlers, deferred work handlers etc.
1247 saa7164_api_enum_subdevs(dev
);
1249 /* Begin to create the video sub-systems and register funcs */
1250 if (saa7164_boards
[dev
->board
].porta
== SAA7164_MPEG_DVB
) {
1251 if (saa7164_dvb_register(&dev
->ports
[ SAA7164_PORT_TS1
]) < 0) {
1252 printk(KERN_ERR
"%s() Failed to register "
1253 "dvb adapters on porta\n",
1258 if (saa7164_boards
[dev
->board
].portb
== SAA7164_MPEG_DVB
) {
1259 if (saa7164_dvb_register(&dev
->ports
[ SAA7164_PORT_TS2
]) < 0) {
1260 printk(KERN_ERR
"%s() Failed to register "
1261 "dvb adapters on portb\n",
1266 if (saa7164_boards
[dev
->board
].portc
== SAA7164_MPEG_ENCODER
) {
1267 if (saa7164_encoder_register(&dev
->ports
[ SAA7164_PORT_ENC1
]) < 0) {
1268 printk(KERN_ERR
"%s() Failed to register "
1269 "mpeg encoder\n", __func__
);
1273 if (saa7164_boards
[dev
->board
].portd
== SAA7164_MPEG_ENCODER
) {
1274 if (saa7164_encoder_register(&dev
->ports
[ SAA7164_PORT_ENC2
]) < 0) {
1275 printk(KERN_ERR
"%s() Failed to register "
1276 "mpeg encoder\n", __func__
);
1280 if (saa7164_boards
[dev
->board
].porte
== SAA7164_MPEG_VBI
) {
1281 if (saa7164_vbi_register(&dev
->ports
[ SAA7164_PORT_VBI1
]) < 0) {
1282 printk(KERN_ERR
"%s() Failed to register "
1283 "vbi device\n", __func__
);
1287 if (saa7164_boards
[dev
->board
].portf
== SAA7164_MPEG_VBI
) {
1288 if (saa7164_vbi_register(&dev
->ports
[ SAA7164_PORT_VBI2
]) < 0) {
1289 printk(KERN_ERR
"%s() Failed to register "
1290 "vbi device\n", __func__
);
1293 saa7164_api_set_debug(dev
, fw_debug
);
1295 } /* != BOARD_UNKNOWN */
1297 printk(KERN_ERR
"%s() Unsupported board detected, "
1298 "registering without firmware\n", __func__
);
1300 dprintk(1, "%s() parameter debug = %d\n", __func__
, saa_debug
);
1301 dprintk(1, "%s() parameter waitsecs = %d\n", __func__
, waitsecs
);
1307 saa7164_dev_unregister(dev
);
1313 static void saa7164_shutdown(struct saa7164_dev
*dev
)
1315 dprintk(1, "%s()\n", __func__
);
1318 static void __devexit
saa7164_finidev(struct pci_dev
*pci_dev
)
1320 struct saa7164_dev
*dev
= pci_get_drvdata(pci_dev
);
1322 if (dev
->board
!= SAA7164_BOARD_UNKNOWN
)
1323 saa7164_api_set_debug(dev
, 0x00);
1325 saa7164_histogram_print(&dev
->ports
[ SAA7164_PORT_ENC1
],
1326 &dev
->ports
[ SAA7164_PORT_ENC1
].irq_interval
);
1327 saa7164_histogram_print(&dev
->ports
[ SAA7164_PORT_ENC1
],
1328 &dev
->ports
[ SAA7164_PORT_ENC1
].svc_interval
);
1329 saa7164_histogram_print(&dev
->ports
[ SAA7164_PORT_ENC1
],
1330 &dev
->ports
[ SAA7164_PORT_ENC1
].irq_svc_interval
);
1331 saa7164_histogram_print(&dev
->ports
[ SAA7164_PORT_ENC1
],
1332 &dev
->ports
[ SAA7164_PORT_ENC1
].read_interval
);
1333 saa7164_histogram_print(&dev
->ports
[ SAA7164_PORT_ENC1
],
1334 &dev
->ports
[ SAA7164_PORT_ENC1
].poll_interval
);
1335 saa7164_histogram_print(&dev
->ports
[ SAA7164_PORT_VBI1
],
1336 &dev
->ports
[ SAA7164_PORT_VBI1
].read_interval
);
1337 saa7164_histogram_print(&dev
->ports
[ SAA7164_PORT_VBI2
],
1338 &dev
->ports
[ SAA7164_PORT_VBI2
].poll_interval
);
1340 saa7164_shutdown(dev
);
1342 if (saa7164_boards
[dev
->board
].porta
== SAA7164_MPEG_DVB
)
1343 saa7164_dvb_unregister(&dev
->ports
[ SAA7164_PORT_TS1
]);
1345 if (saa7164_boards
[dev
->board
].portb
== SAA7164_MPEG_DVB
)
1346 saa7164_dvb_unregister(&dev
->ports
[ SAA7164_PORT_TS2
]);
1348 if (saa7164_boards
[dev
->board
].portc
== SAA7164_MPEG_ENCODER
)
1349 saa7164_encoder_unregister(&dev
->ports
[ SAA7164_PORT_ENC1
]);
1351 if (saa7164_boards
[dev
->board
].portd
== SAA7164_MPEG_ENCODER
)
1352 saa7164_encoder_unregister(&dev
->ports
[ SAA7164_PORT_ENC2
]);
1354 if (saa7164_boards
[dev
->board
].porte
== SAA7164_MPEG_VBI
)
1355 saa7164_vbi_unregister(&dev
->ports
[ SAA7164_PORT_VBI1
]);
1357 if (saa7164_boards
[dev
->board
].portf
== SAA7164_MPEG_VBI
)
1358 saa7164_vbi_unregister(&dev
->ports
[ SAA7164_PORT_VBI2
]);
1360 saa7164_i2c_unregister(&dev
->i2c_bus
[0]);
1361 saa7164_i2c_unregister(&dev
->i2c_bus
[1]);
1362 saa7164_i2c_unregister(&dev
->i2c_bus
[2]);
1364 pci_disable_device(pci_dev
);
1366 /* unregister stuff */
1367 free_irq(pci_dev
->irq
, dev
);
1368 pci_set_drvdata(pci_dev
, NULL
);
1370 mutex_lock(&devlist
);
1371 list_del(&dev
->devlist
);
1372 mutex_unlock(&devlist
);
1374 saa7164_dev_unregister(dev
);
1378 static struct pci_device_id saa7164_pci_tbl
[] = {
1383 .subvendor
= PCI_ANY_ID
,
1384 .subdevice
= PCI_ANY_ID
,
1386 /* --- end of list --- */
1389 MODULE_DEVICE_TABLE(pci
, saa7164_pci_tbl
);
1391 static struct pci_driver saa7164_pci_driver
= {
1393 .id_table
= saa7164_pci_tbl
,
1394 .probe
= saa7164_initdev
,
1395 .remove
= __devexit_p(saa7164_finidev
),
1401 static int __init
saa7164_init(void)
1403 printk(KERN_INFO
"saa7164 driver loaded\n");
1405 #ifdef CONFIG_PROC_FS
1406 saa7164_proc_create();
1408 return pci_register_driver(&saa7164_pci_driver
);
1411 static void __exit
saa7164_fini(void)
1413 #ifdef CONFIG_PROC_FS
1414 remove_proc_entry("saa7164", NULL
);
1416 pci_unregister_driver(&saa7164_pci_driver
);
1419 module_init(saa7164_init
);
1420 module_exit(saa7164_fini
);