[media] saa7164: adjust the PS pack size handling to fill buffers 100%
[deliverable/linux.git] / drivers / media / video / saa7164 / saa7164-core.c
1 /*
2 * Driver for the NXP SAA7164 PCIe bridge
3 *
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com>
5 *
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.
10 *
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
14 *
15 * GNU General Public License for more details.
16 *
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.
20 */
21
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>
32
33 #include "saa7164.h"
34
35 MODULE_DESCRIPTION("Driver for NXP SAA7164 based TV cards");
36 MODULE_AUTHOR("Steven Toth <stoth@kernellabs.com>");
37 MODULE_LICENSE("GPL");
38
39 /*
40 1 Basic
41 2
42 4 i2c
43 8 api
44 16 cmd
45 32 bus
46 */
47
48 unsigned int saa_debug;
49 module_param_named(debug, saa_debug, int, 0644);
50 MODULE_PARM_DESC(debug, "enable debug messages");
51
52 unsigned int encoder_buffers = SAA7164_MAX_ENCODER_BUFFERS;
53 module_param(encoder_buffers, int, 0644);
54 MODULE_PARM_DESC(encoder_buffers, "Total buffers in read queue 16-512 def:64");
55
56 unsigned int waitsecs = 10;
57 module_param(waitsecs, int, 0644);
58 MODULE_PARM_DESC(waitsecs, "timeout on firmware messages");
59
60 static unsigned int card[] = {[0 ... (SAA7164_MAXBOARDS - 1)] = UNSET };
61 module_param_array(card, int, NULL, 0444);
62 MODULE_PARM_DESC(card, "card type");
63
64 unsigned int print_histogram = 64;
65 module_param(print_histogram, int, 0644);
66 MODULE_PARM_DESC(print_histogram, "print histogram values once");
67
68 static unsigned int saa7164_devcount;
69
70 static DEFINE_MUTEX(devlist);
71 LIST_HEAD(saa7164_devlist);
72
73 #define INT_SIZE 16
74
75 void saa7164_dumphex16FF(struct saa7164_dev *dev, u8 *buf, int len)
76 {
77 int i;
78 u8 tmp[16];
79 memset(&tmp[0], 0xff, sizeof(tmp));
80
81 printk(KERN_INFO "--------------------> "
82 "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
83
84 for (i = 0; i < len; i += 16) {
85 if (memcmp(&tmp, buf + i, sizeof(tmp)) != 0) {
86 printk(KERN_INFO " [0x%08x] "
87 "%02x %02x %02x %02x %02x %02x %02x %02x "
88 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
89 *(buf+i+0), *(buf+i+1), *(buf+i+2), *(buf+i+3),
90 *(buf+i+4), *(buf+i+5), *(buf+i+6), *(buf+i+7),
91 *(buf+i+8), *(buf+i+9), *(buf+i+10), *(buf+i+11),
92 *(buf+i+12), *(buf+i+13), *(buf+i+14), *(buf+i+15));
93 }
94 }
95 }
96
97 static void saa7164_pack_verifier(struct saa7164_buffer *buf)
98 {
99 u8 *p = (u8 *)buf->cpu;
100 int i;
101
102 for (i = 0; i < buf->actual_size; i += 2048) {
103
104 if ( (*(p + i + 0) != 0x00) || (*(p + i + 1) != 0x00) || (*(p + i + 2) != 0x01) || (*(p + i + 3) != 0xBA) )
105 printk(KERN_ERR "No pack at 0x%x\n", i);
106 }
107 }
108
109 static void saa7164_ts_verifier(struct saa7164_buffer *buf)
110 {
111 struct saa7164_port *port = buf->port;
112 u32 i;
113 u8 tmp, cc, a;
114 u8 *bufcpu = (u8 *)buf->cpu;
115
116 port->sync_errors = 0;
117 port->v_cc_errors = 0;
118 port->a_cc_errors = 0;
119
120 for (i = 0; i < buf->actual_size; i += 188) {
121 if (*(bufcpu + i) != 0x47)
122 port->sync_errors++;
123
124 /* Query pid lower 8 bits */
125 tmp = *(bufcpu + i + 2);
126 cc = *(bufcpu + i + 3) & 0x0f;
127
128 if (tmp == 0xf1) {
129 a = ((port->last_v_cc + 1) & 0x0f);
130 if (a != cc) {
131 printk(KERN_ERR "video cc last = %x current = %x i = %d\n", port->last_v_cc, cc, i);
132 port->v_cc_errors++;
133 }
134
135 port->last_v_cc = cc;
136 } else
137 if (tmp == 0xf2) {
138 a = ((port->last_a_cc + 1) & 0x0f);
139 if (a != cc) {
140 printk(KERN_ERR "audio cc last = %x current = %x i = %d\n", port->last_a_cc, cc, i);
141 port->a_cc_errors++;
142 }
143
144 port->last_a_cc = cc;
145 }
146
147 }
148
149 if (port->v_cc_errors)
150 printk(KERN_ERR "video pid cc, %d errors\n", port->v_cc_errors);
151
152 if (port->a_cc_errors)
153 printk(KERN_ERR "audio pid cc, %d errors\n", port->a_cc_errors);
154
155 if (port->sync_errors)
156 printk(KERN_ERR "sync_errors = %d\n", port->sync_errors);
157 }
158
159 static void saa7164_histogram_reset(struct saa7164_histogram *hg, char *name)
160 {
161 int i;
162
163 memset(hg, 0, sizeof(struct saa7164_histogram));
164 strcpy(hg->name, name);
165
166 /* First 30ms x 1ms */
167 for (i = 0; i < 30; i++) {
168 hg->counter1[0 + i].val = i;
169 }
170
171 /* 30 - 200ms x 10ms */
172 for (i = 0; i < 18; i++) {
173 hg->counter1[30 + i].val = 30 + (i * 10);
174 }
175
176 /* 200 - 2000ms x 100ms */
177 for (i = 0; i < 15; i++) {
178 hg->counter1[48 + i].val = 200 + (i * 200);
179 }
180
181 /* Catch all massive value (2secs) */
182 hg->counter1[55].val = 2000;
183
184 /* Catch all massive value (4secs) */
185 hg->counter1[56].val = 4000;
186
187 /* Catch all massive value (8secs) */
188 hg->counter1[57].val = 8000;
189
190 /* Catch all massive value (15secs) */
191 hg->counter1[58].val = 15000;
192
193 /* Catch all massive value (30secs) */
194 hg->counter1[59].val = 30000;
195
196 /* Catch all massive value (60secs) */
197 hg->counter1[60].val = 60000;
198
199 /* Catch all massive value (5mins) */
200 hg->counter1[61].val = 300000;
201
202 /* Catch all massive value (15mins) */
203 hg->counter1[62].val = 900000;
204
205 /* Catch all massive values (1hr) */
206 hg->counter1[63].val = 3600000;
207 }
208
209 void saa7164_histogram_update(struct saa7164_histogram *hg, u32 val)
210 {
211 int i;
212 for (i = 0; i < 64; i++ ) {
213 if (val <= hg->counter1[i].val) {
214 hg->counter1[i].count++;
215 hg->counter1[i].update_time = jiffies;
216 break;
217 }
218 }
219 }
220
221 static void saa7164_histogram_print(struct saa7164_port *port,
222 struct saa7164_histogram *hg)
223 {
224 u32 entries = 0;
225 int i;
226
227 printk(KERN_ERR "Histogram named %s (ms, count, last_update_jiffy)\n", hg->name);
228 for (i = 0; i < 64; i++ ) {
229 if (hg->counter1[i].count == 0)
230 continue;
231
232 printk(KERN_ERR " %4d %12d %Ld\n",
233 hg->counter1[i].val,
234 hg->counter1[i].count,
235 hg->counter1[i].update_time);
236
237 entries++;
238 }
239 printk(KERN_ERR "Total: %d\n", entries);
240 }
241
242 static void saa7164_work_enchandler(struct work_struct *w)
243 {
244 struct saa7164_port *port =
245 container_of(w, struct saa7164_port, workenc);
246 struct saa7164_dev *dev = port->dev;
247 struct saa7164_buffer *buf;
248 struct saa7164_user_buffer *ubuf;
249 struct list_head *c, *n;
250 int wp, rp, i = 0;
251 u32 crc, ok = 0;
252 u8 *p;
253
254 port->last_svc_msecs_diff = port->last_svc_msecs;
255 port->last_svc_msecs = jiffies_to_msecs(jiffies);
256 port->last_svc_wp = saa7164_readl(port->bufcounter);
257 port->last_svc_rp = port->last_irq_rp;
258 wp = port->last_svc_wp;
259 rp = port->last_svc_rp;
260
261
262 port->last_svc_msecs_diff = port->last_svc_msecs -
263 port->last_svc_msecs_diff;
264
265 saa7164_histogram_update(&port->svc_interval,
266 port->last_svc_msecs_diff);
267
268 port->last_irq_svc_msecs_diff = port->last_svc_msecs -
269 port->last_irq_msecs;
270
271 saa7164_histogram_update(&port->irq_svc_interval,
272 port->last_irq_svc_msecs_diff);
273
274 dprintk(DBGLVL_IRQ,
275 "%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
276 __func__,
277 port->last_svc_msecs_diff,
278 port->last_irq_svc_msecs_diff,
279 port->last_svc_wp,
280 port->last_svc_rp
281 );
282
283 if ((rp < 0) || (rp > 7)) {
284 printk(KERN_ERR "%s() illegal rp count %d\n", __func__, rp);
285 return;
286 }
287
288 mutex_lock(&port->dmaqueue_lock);
289
290 list_for_each_safe(c, n, &port->dmaqueue.list) {
291
292 buf = list_entry(c, struct saa7164_buffer, list);
293 if (i++ > port->hwcfg.buffercount) {
294 printk(KERN_ERR "%s() illegal i count %d\n",
295 __func__, i);
296 break;
297 }
298
299 p = (u8 *)buf->cpu;
300 if ( (*(p + buf->actual_size + 0) != 0xff) ||
301 (*(p + buf->actual_size + 1) != 0xff) ||
302 (*(p + buf->actual_size + 2) != 0xff) ||
303 (*(p + buf->actual_size + 3) != 0xff) ||
304 (*(p + buf->actual_size + 0x10) != 0xff) ||
305 (*(p + buf->actual_size + 0x11) != 0xff) ||
306 (*(p + buf->actual_size + 0x12) != 0xff) ||
307 (*(p + buf->actual_size + 0x13) != 0xff) )
308 {
309 printk(KERN_ERR "%s() buf %p failed guard check\n", __func__, buf);
310 saa7164_dumphex16(dev, p + buf->actual_size - 32, 64);
311 }
312
313 if (buf->idx == wp) {
314 /* Ignore this, it's being updated currently by the dma engine */
315 } else
316 if (buf->idx == rp) {
317
318 crc = crc32(0, buf->cpu, buf->actual_size);
319 if (crc != port->shadow_crc[rp])
320 printk(KERN_ERR "%s crc didn't match shadow was 0x%x now 0x%x\n",
321 __func__, port->shadow_crc[rp], crc);
322
323 /* Found the buffer, deal with it */
324 dprintk(DBGLVL_IRQ, "%s() wp: %d processing: %d crc32: 0x%x\n",
325 __func__, wp, rp, buf->crc);
326
327 /* Validate the incoming buffer content */
328 if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_TS)
329 saa7164_ts_verifier(buf);
330 if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS)
331 saa7164_pack_verifier(buf);
332
333 /* find a free user buffer and clone to it */
334 if (!list_empty(&port->list_buf_free.list)) {
335
336 /* Pull the first buffer from the used list */
337 ubuf = list_first_entry(&port->list_buf_free.list,
338 struct saa7164_user_buffer, list);
339
340 if (buf->actual_size <= ubuf->actual_size) {
341
342 memcpy_fromio(ubuf->data, buf->cpu, ubuf->actual_size);
343
344 /* Throw a new checksum on the read buffer */
345 ubuf->crc = crc32(0, ubuf->data, ubuf->actual_size);
346
347 if ((crc == port->shadow_crc[rp]) && (crc == ubuf->crc))
348 ok = 1;
349 else
350 ok = 0;
351
352 if (ok == 0)
353 printk(KERN_ERR
354 "rp: %d dmacrc: 0x%08x shadcrc: 0x%08x ubufcrc: 0x%08x %s\n",
355 rp, buf->crc, port->shadow_crc[rp], ubuf->crc,
356 ok ? "crcgood" : "crcbad");
357
358 /* Requeue the buffer on the free list */
359 ubuf->pos = 0;
360
361 list_move_tail(&ubuf->list,
362 &port->list_buf_used.list);
363
364 /* Flag any userland waiters */
365 wake_up_interruptible(&port->wait_read);
366
367 } else {
368 printk(KERN_ERR "buf %p bufsize fails match\n", buf);
369 }
370
371 } else
372 printk(KERN_ERR "encirq no free buffers, increase param encoder_buffers\n");
373
374 /* Ensure offset into buffer remains 0, fill buffer
375 * with known bad data. We check for this data at a later point
376 * in time. */
377 saa7164_buffer_zero_offsets(port, rp);
378 memset_io(buf->cpu, 0xff, buf->pci_size);
379 buf->crc = crc32(0, buf->cpu, buf->actual_size);
380
381 break;
382 } else {
383 /* Validate all other checksums, on previous buffers - they should never change */
384 crc = crc32(0, buf->cpu, buf->actual_size);
385 if (crc != buf->crc) {
386 printk(KERN_ERR "buf[%d].crc became invalid, was 0x%x became 0x%x rp: %d wp: %d\n",
387 buf->idx, buf->crc, crc, rp, wp);
388 //saa7164_dumphex16FF(dev, (u8 *)buf->cpu, buf->actual_size);
389 saa7164_dumphex16FF(dev, (u8 *)buf->cpu, 256);
390 buf->crc = crc;
391 }
392
393 }
394
395 }
396 mutex_unlock(&port->dmaqueue_lock);
397
398 if (print_histogram == port->nr) {
399 saa7164_histogram_print(port, &port->irq_interval);
400 saa7164_histogram_print(port, &port->svc_interval);
401 saa7164_histogram_print(port, &port->irq_svc_interval);
402 saa7164_histogram_print(port, &port->read_interval);
403 saa7164_histogram_print(port, &port->poll_interval);
404 print_histogram = 64 + port->nr;
405 }
406 }
407 static void saa7164_work_cmdhandler(struct work_struct *w)
408 {
409 struct saa7164_dev *dev = container_of(w, struct saa7164_dev, workcmd);
410
411 /* Wake up any complete commands */
412 saa7164_irq_dequeue(dev);
413 }
414
415 static void saa7164_buffer_deliver(struct saa7164_buffer *buf)
416 {
417 struct saa7164_port *port = buf->port;
418
419 /* Feed the transport payload into the kernel demux */
420 dvb_dmx_swfilter_packets(&port->dvb.demux, (u8 *)buf->cpu,
421 SAA7164_TS_NUMBER_OF_LINES);
422
423 }
424
425 static irqreturn_t saa7164_irq_encoder(struct saa7164_port *port)
426 {
427 struct saa7164_dev *dev = port->dev;
428 struct saa7164_buffer *buf;
429 struct list_head *c, *n;
430 int wp, rp, i = 0;
431 u8 *p;
432
433 /* Find the current write point from the hardware */
434 wp = saa7164_readl(port->bufcounter);
435 if (wp > (port->hwcfg.buffercount - 1)) {
436 printk(KERN_ERR "%s() illegal buf count %d\n", __func__, wp);
437 return 0;
438 }
439
440 /* Find the previous buffer to the current write point */
441 if (wp == 0)
442 rp = 7;
443 else
444 rp = wp - 1;
445
446 if ((rp < 0) || (rp > 7)) {
447 printk(KERN_ERR "%s() illegal rp count %d\n", __func__, rp);
448 return 0;
449 }
450
451 if (rp != ((port->last_irq_rp + 1) % 8)) {
452 printk(KERN_ERR "%s() Multiple bufs on interrupt, port %p\n",
453 __func__, port);
454 }
455
456 /* Store old time */
457 port->last_irq_msecs_diff = port->last_irq_msecs;
458
459 /* Collect new stats */
460 port->last_irq_msecs = jiffies_to_msecs(jiffies);
461 port->last_irq_wp = wp;
462 port->last_irq_rp = rp;
463
464 /* Calculate stats */
465 port->last_irq_msecs_diff = port->last_irq_msecs -
466 port->last_irq_msecs_diff;
467
468 saa7164_histogram_update(&port->irq_interval,
469 port->last_irq_msecs_diff);
470
471 dprintk(DBGLVL_IRQ, "%s() %Ldms elapsed wp: %d rp: %d\n",
472 __func__,
473 port->last_irq_msecs_diff,
474 port->last_irq_wp,
475 port->last_irq_rp
476 );
477 /* Find the used buffer, shadow copy it before we've
478 * acked the interrupt.
479 */
480 // mutex_lock(&port->dmaqueue_lock);
481 list_for_each_safe(c, n, &port->dmaqueue.list) {
482
483 buf = list_entry(c, struct saa7164_buffer, list);
484 if (i++ > port->hwcfg.buffercount) {
485 printk(KERN_ERR "%s() illegal i count %d\n",
486 __func__, i);
487 break;
488 }
489
490 p = (u8 *)buf->cpu;
491 if ( (*(p + buf->actual_size + 0) != 0xff) ||
492 (*(p + buf->actual_size + 1) != 0xff) ||
493 (*(p + buf->actual_size + 2) != 0xff) ||
494 (*(p + buf->actual_size + 3) != 0xff) ||
495 (*(p + buf->actual_size + 0x10) != 0xff) ||
496 (*(p + buf->actual_size + 0x11) != 0xff) ||
497 (*(p + buf->actual_size + 0x12) != 0xff) ||
498 (*(p + buf->actual_size + 0x13) != 0xff) )
499 {
500 printk(KERN_ERR "buf %p failed guard check\n", buf);
501 saa7164_dumphex16(dev, p + buf->actual_size - 32, 64);
502 }
503
504 if (buf->idx == rp) {
505
506 memcpy_fromio(port->shadow_buf[rp], buf->cpu, buf->actual_size);
507
508 port->shadow_crc[rp] = crc32(0, port->shadow_buf[rp], buf->actual_size);
509
510 buf->crc = crc32(0, buf->cpu, buf->actual_size);
511
512 if (port->shadow_crc[rp] != buf->crc)
513 printk(KERN_ERR "%s() crc check failed 0x%x vs 0x%x\n",
514 __func__, port->shadow_crc[rp], buf->crc);
515 break;
516 }
517
518 }
519 // mutex_unlock(&port->dmaqueue_lock);
520 schedule_work(&port->workenc);
521
522 return 0;
523 }
524
525 static irqreturn_t saa7164_irq_ts(struct saa7164_port *port)
526 {
527 struct saa7164_dev *dev = port->dev;
528 struct saa7164_buffer *buf;
529 struct list_head *c, *n;
530 int wp, i = 0, rp;
531
532 /* Find the current write point from the hardware */
533 wp = saa7164_readl(port->bufcounter);
534 if (wp > (port->hwcfg.buffercount - 1))
535 BUG();
536
537 /* Find the previous buffer to the current write point */
538 if (wp == 0)
539 rp = 7;
540 else
541 rp = wp - 1;
542
543 /* Lookup the WP in the buffer list */
544 /* TODO: turn this into a worker thread */
545 list_for_each_safe(c, n, &port->dmaqueue.list) {
546 buf = list_entry(c, struct saa7164_buffer, list);
547 if (i++ > port->hwcfg.buffercount)
548 BUG();
549
550 if (buf->idx == rp) {
551 /* Found the buffer, deal with it */
552 dprintk(DBGLVL_IRQ, "%s() wp: %d processing: %d\n",
553 __func__, wp, rp);
554 saa7164_buffer_deliver(buf);
555 break;
556 }
557
558 }
559 return 0;
560 }
561
562 /* Primary IRQ handler and dispatch mechanism */
563 static irqreturn_t saa7164_irq(int irq, void *dev_id)
564 {
565 struct saa7164_dev *dev = dev_id;
566 struct saa7164_port *porta = &dev->ports[ SAA7164_PORT_TS1 ];
567 struct saa7164_port *portb = &dev->ports[ SAA7164_PORT_TS2 ];
568 struct saa7164_port *portc = &dev->ports[ SAA7164_PORT_ENC1 ];
569 struct saa7164_port *portd = &dev->ports[ SAA7164_PORT_ENC2 ];
570
571 u32 intid, intstat[INT_SIZE/4];
572 int i, handled = 0, bit;
573
574 if (dev == 0) {
575 printk(KERN_ERR "%s() No device specified\n", __func__);
576 handled = 0;
577 goto out;
578 }
579
580 /* Check that the hardware is accessable. If the status bytes are
581 * 0xFF then the device is not accessable, the the IRQ belongs
582 * to another driver.
583 * 4 x u32 interrupt registers.
584 */
585 for (i = 0; i < INT_SIZE/4; i++) {
586
587 /* TODO: Convert into saa7164_readl() */
588 /* Read the 4 hardware interrupt registers */
589 intstat[i] = saa7164_readl(dev->int_status + (i * 4));
590
591 if (intstat[i])
592 handled = 1;
593 }
594 if (handled == 0)
595 goto out;
596
597 /* For each of the HW interrupt registers */
598 for (i = 0; i < INT_SIZE/4; i++) {
599
600 if (intstat[i]) {
601 /* Each function of the board has it's own interruptid.
602 * Find the function that triggered then call
603 * it's handler.
604 */
605 for (bit = 0; bit < 32; bit++) {
606
607 if (((intstat[i] >> bit) & 0x00000001) == 0)
608 continue;
609
610 /* Calculate the interrupt id (0x00 to 0x7f) */
611
612 intid = (i * 32) + bit;
613 if (intid == dev->intfdesc.bInterruptId) {
614 /* A response to an cmd/api call */
615 schedule_work(&dev->workcmd);
616 } else if (intid == porta->hwcfg.interruptid) {
617
618 /* Transport path 1 */
619 saa7164_irq_ts(porta);
620
621 } else if (intid == portb->hwcfg.interruptid) {
622
623 /* Transport path 2 */
624 saa7164_irq_ts(portb);
625
626 } else if (intid == portc->hwcfg.interruptid) {
627
628 /* Encoder path 1 */
629 saa7164_irq_encoder(portc);
630
631 } else if (intid == portd->hwcfg.interruptid) {
632
633 /* Encoder path 1 */
634 saa7164_irq_encoder(portd);
635
636 } else {
637 /* Find the function */
638 dprintk(DBGLVL_IRQ,
639 "%s() unhandled interrupt "
640 "reg 0x%x bit 0x%x "
641 "intid = 0x%x\n",
642 __func__, i, bit, intid);
643 }
644 }
645
646 /* Ack it */
647 saa7164_writel(dev->int_ack + (i * 4), intstat[i]);
648
649 }
650 }
651 out:
652 return IRQ_RETVAL(handled);
653 }
654
655 void saa7164_getfirmwarestatus(struct saa7164_dev *dev)
656 {
657 struct saa7164_fw_status *s = &dev->fw_status;
658
659 dev->fw_status.status = saa7164_readl(SAA_DEVICE_SYSINIT_STATUS);
660 dev->fw_status.mode = saa7164_readl(SAA_DEVICE_SYSINIT_MODE);
661 dev->fw_status.spec = saa7164_readl(SAA_DEVICE_SYSINIT_SPEC);
662 dev->fw_status.inst = saa7164_readl(SAA_DEVICE_SYSINIT_INST);
663 dev->fw_status.cpuload = saa7164_readl(SAA_DEVICE_SYSINIT_CPULOAD);
664 dev->fw_status.remainheap =
665 saa7164_readl(SAA_DEVICE_SYSINIT_REMAINHEAP);
666
667 dprintk(1, "Firmware status:\n");
668 dprintk(1, " .status = 0x%08x\n", s->status);
669 dprintk(1, " .mode = 0x%08x\n", s->mode);
670 dprintk(1, " .spec = 0x%08x\n", s->spec);
671 dprintk(1, " .inst = 0x%08x\n", s->inst);
672 dprintk(1, " .cpuload = 0x%08x\n", s->cpuload);
673 dprintk(1, " .remainheap = 0x%08x\n", s->remainheap);
674 }
675
676 u32 saa7164_getcurrentfirmwareversion(struct saa7164_dev *dev)
677 {
678 u32 reg;
679
680 reg = saa7164_readl(SAA_DEVICE_VERSION);
681 dprintk(1, "Device running firmware version %d.%d.%d.%d (0x%x)\n",
682 (reg & 0x0000fc00) >> 10,
683 (reg & 0x000003e0) >> 5,
684 (reg & 0x0000001f),
685 (reg & 0xffff0000) >> 16,
686 reg);
687
688 return reg;
689 }
690
691 /* TODO: Debugging func, remove */
692 void saa7164_dumphex16(struct saa7164_dev *dev, u8 *buf, int len)
693 {
694 int i;
695
696 printk(KERN_INFO "--------------------> "
697 "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
698
699 for (i = 0; i < len; i += 16)
700 printk(KERN_INFO " [0x%08x] "
701 "%02x %02x %02x %02x %02x %02x %02x %02x "
702 "%02x %02x %02x %02x %02x %02x %02x %02x\n", i,
703 *(buf+i+0), *(buf+i+1), *(buf+i+2), *(buf+i+3),
704 *(buf+i+4), *(buf+i+5), *(buf+i+6), *(buf+i+7),
705 *(buf+i+8), *(buf+i+9), *(buf+i+10), *(buf+i+11),
706 *(buf+i+12), *(buf+i+13), *(buf+i+14), *(buf+i+15));
707 }
708
709 /* TODO: Debugging func, remove */
710 void saa7164_dumpregs(struct saa7164_dev *dev, u32 addr)
711 {
712 int i;
713
714 dprintk(1, "--------------------> "
715 "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n");
716
717 for (i = 0; i < 0x100; i += 16)
718 dprintk(1, "region0[0x%08x] = "
719 "%02x %02x %02x %02x %02x %02x %02x %02x"
720 " %02x %02x %02x %02x %02x %02x %02x %02x\n", i,
721 (u8)saa7164_readb(addr + i + 0),
722 (u8)saa7164_readb(addr + i + 1),
723 (u8)saa7164_readb(addr + i + 2),
724 (u8)saa7164_readb(addr + i + 3),
725 (u8)saa7164_readb(addr + i + 4),
726 (u8)saa7164_readb(addr + i + 5),
727 (u8)saa7164_readb(addr + i + 6),
728 (u8)saa7164_readb(addr + i + 7),
729 (u8)saa7164_readb(addr + i + 8),
730 (u8)saa7164_readb(addr + i + 9),
731 (u8)saa7164_readb(addr + i + 10),
732 (u8)saa7164_readb(addr + i + 11),
733 (u8)saa7164_readb(addr + i + 12),
734 (u8)saa7164_readb(addr + i + 13),
735 (u8)saa7164_readb(addr + i + 14),
736 (u8)saa7164_readb(addr + i + 15)
737 );
738 }
739
740 static void saa7164_dump_hwdesc(struct saa7164_dev *dev)
741 {
742 dprintk(1, "@0x%p hwdesc sizeof(tmComResHWDescr_t) = %d bytes\n",
743 &dev->hwdesc, (u32)sizeof(tmComResHWDescr_t));
744
745 dprintk(1, " .bLength = 0x%x\n", dev->hwdesc.bLength);
746 dprintk(1, " .bDescriptorType = 0x%x\n", dev->hwdesc.bDescriptorType);
747 dprintk(1, " .bDescriptorSubtype = 0x%x\n",
748 dev->hwdesc.bDescriptorSubtype);
749
750 dprintk(1, " .bcdSpecVersion = 0x%x\n", dev->hwdesc.bcdSpecVersion);
751 dprintk(1, " .dwClockFrequency = 0x%x\n", dev->hwdesc.dwClockFrequency);
752 dprintk(1, " .dwClockUpdateRes = 0x%x\n", dev->hwdesc.dwClockUpdateRes);
753 dprintk(1, " .bCapabilities = 0x%x\n", dev->hwdesc.bCapabilities);
754 dprintk(1, " .dwDeviceRegistersLocation = 0x%x\n",
755 dev->hwdesc.dwDeviceRegistersLocation);
756
757 dprintk(1, " .dwHostMemoryRegion = 0x%x\n",
758 dev->hwdesc.dwHostMemoryRegion);
759
760 dprintk(1, " .dwHostMemoryRegionSize = 0x%x\n",
761 dev->hwdesc.dwHostMemoryRegionSize);
762
763 dprintk(1, " .dwHostHibernatMemRegion = 0x%x\n",
764 dev->hwdesc.dwHostHibernatMemRegion);
765
766 dprintk(1, " .dwHostHibernatMemRegionSize = 0x%x\n",
767 dev->hwdesc.dwHostHibernatMemRegionSize);
768 }
769
770 static void saa7164_dump_intfdesc(struct saa7164_dev *dev)
771 {
772 dprintk(1, "@0x%p intfdesc "
773 "sizeof(tmComResInterfaceDescr_t) = %d bytes\n",
774 &dev->intfdesc, (u32)sizeof(tmComResInterfaceDescr_t));
775
776 dprintk(1, " .bLength = 0x%x\n", dev->intfdesc.bLength);
777 dprintk(1, " .bDescriptorType = 0x%x\n", dev->intfdesc.bDescriptorType);
778 dprintk(1, " .bDescriptorSubtype = 0x%x\n",
779 dev->intfdesc.bDescriptorSubtype);
780
781 dprintk(1, " .bFlags = 0x%x\n", dev->intfdesc.bFlags);
782 dprintk(1, " .bInterfaceType = 0x%x\n", dev->intfdesc.bInterfaceType);
783 dprintk(1, " .bInterfaceId = 0x%x\n", dev->intfdesc.bInterfaceId);
784 dprintk(1, " .bBaseInterface = 0x%x\n", dev->intfdesc.bBaseInterface);
785 dprintk(1, " .bInterruptId = 0x%x\n", dev->intfdesc.bInterruptId);
786 dprintk(1, " .bDebugInterruptId = 0x%x\n",
787 dev->intfdesc.bDebugInterruptId);
788
789 dprintk(1, " .BARLocation = 0x%x\n", dev->intfdesc.BARLocation);
790 }
791
792 static void saa7164_dump_busdesc(struct saa7164_dev *dev)
793 {
794 dprintk(1, "@0x%p busdesc sizeof(tmComResBusDescr_t) = %d bytes\n",
795 &dev->busdesc, (u32)sizeof(tmComResBusDescr_t));
796
797 dprintk(1, " .CommandRing = 0x%016Lx\n", dev->busdesc.CommandRing);
798 dprintk(1, " .ResponseRing = 0x%016Lx\n", dev->busdesc.ResponseRing);
799 dprintk(1, " .CommandWrite = 0x%x\n", dev->busdesc.CommandWrite);
800 dprintk(1, " .CommandRead = 0x%x\n", dev->busdesc.CommandRead);
801 dprintk(1, " .ResponseWrite = 0x%x\n", dev->busdesc.ResponseWrite);
802 dprintk(1, " .ResponseRead = 0x%x\n", dev->busdesc.ResponseRead);
803 }
804
805 /* Much of the hardware configuration and PCI registers are configured
806 * dynamically depending on firmware. We have to cache some initial
807 * structures then use these to locate other important structures
808 * from PCI space.
809 */
810 static void saa7164_get_descriptors(struct saa7164_dev *dev)
811 {
812 memcpy_fromio(&dev->hwdesc, dev->bmmio, sizeof(tmComResHWDescr_t));
813 memcpy_fromio(&dev->intfdesc, dev->bmmio + sizeof(tmComResHWDescr_t),
814 sizeof(tmComResInterfaceDescr_t));
815 memcpy_fromio(&dev->busdesc, dev->bmmio + dev->intfdesc.BARLocation,
816 sizeof(tmComResBusDescr_t));
817
818 if (dev->hwdesc.bLength != sizeof(tmComResHWDescr_t)) {
819 printk(KERN_ERR "Structure tmComResHWDescr_t is mangled\n");
820 printk(KERN_ERR "Need %x got %d\n", dev->hwdesc.bLength,
821 (u32)sizeof(tmComResHWDescr_t));
822 } else
823 saa7164_dump_hwdesc(dev);
824
825 if (dev->intfdesc.bLength != sizeof(tmComResInterfaceDescr_t)) {
826 printk(KERN_ERR "struct tmComResInterfaceDescr_t is mangled\n");
827 printk(KERN_ERR "Need %x got %d\n", dev->intfdesc.bLength,
828 (u32)sizeof(tmComResInterfaceDescr_t));
829 } else
830 saa7164_dump_intfdesc(dev);
831
832 saa7164_dump_busdesc(dev);
833 }
834
835 static int saa7164_pci_quirks(struct saa7164_dev *dev)
836 {
837 return 0;
838 }
839
840 static int get_resources(struct saa7164_dev *dev)
841 {
842 if (request_mem_region(pci_resource_start(dev->pci, 0),
843 pci_resource_len(dev->pci, 0), dev->name)) {
844
845 if (request_mem_region(pci_resource_start(dev->pci, 2),
846 pci_resource_len(dev->pci, 2), dev->name))
847 return 0;
848 }
849
850 printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx or 0x%llx\n",
851 dev->name,
852 (u64)pci_resource_start(dev->pci, 0),
853 (u64)pci_resource_start(dev->pci, 2));
854
855 return -EBUSY;
856 }
857
858 static int saa7164_port_init(struct saa7164_dev *dev, int portnr)
859 {
860 struct saa7164_port *port = 0;
861 int i;
862
863 if ((portnr < 0) || (portnr >= SAA7164_MAX_PORTS))
864 BUG();
865
866 port = &dev->ports[ portnr ];
867
868 port->dev = dev;
869 port->nr = portnr;
870
871 if ((portnr == SAA7164_PORT_TS1) || (portnr == SAA7164_PORT_TS2))
872 port->type = SAA7164_MPEG_DVB;
873 else
874 if ((portnr == SAA7164_PORT_ENC1) || (portnr == SAA7164_PORT_ENC2))
875 port->type = SAA7164_MPEG_ENCODER;
876 else
877 BUG();
878
879 /* Init all the critical resources */
880 mutex_init(&port->dvb.lock);
881 INIT_LIST_HEAD(&port->dmaqueue.list);
882 mutex_init(&port->dmaqueue_lock);
883
884 INIT_LIST_HEAD(&port->list_buf_used.list);
885 INIT_LIST_HEAD(&port->list_buf_free.list);
886 init_waitqueue_head(&port->wait_read);
887
888 /* We need a deferred interrupt handler for cmd handling */
889 INIT_WORK(&port->workenc, saa7164_work_enchandler);
890
891 saa7164_histogram_reset(&port->irq_interval, "irq intervals");
892 saa7164_histogram_reset(&port->svc_interval, "deferred intervals");
893 saa7164_histogram_reset(&port->irq_svc_interval,
894 "irq to deferred intervals");
895 saa7164_histogram_reset(&port->read_interval,
896 "encoder read() intervals");
897 saa7164_histogram_reset(&port->poll_interval,
898 "encoder poll() intervals");
899
900 if (port->type == SAA7164_MPEG_ENCODER) {
901 for (i = 0; i < 8; i ++) {
902 port->shadow_buf[i] = kzalloc(256 * 128, GFP_KERNEL);
903 if (port->shadow_buf[i] == 0)
904 printk(KERN_ERR "%s() shadow_buf ENOMEM\n", __func__);
905 else {
906 memset(port->shadow_buf[i], 0xff, 256 * 128);
907 port->shadow_crc[i] = crc32(0, port->shadow_buf[i], 256 * 128);
908 }
909 }
910 }
911
912 return 0;
913 }
914
915 static int saa7164_dev_setup(struct saa7164_dev *dev)
916 {
917 int i;
918
919 mutex_init(&dev->lock);
920 atomic_inc(&dev->refcount);
921 dev->nr = saa7164_devcount++;
922
923 sprintf(dev->name, "saa7164[%d]", dev->nr);
924
925 mutex_lock(&devlist);
926 list_add_tail(&dev->devlist, &saa7164_devlist);
927 mutex_unlock(&devlist);
928
929 /* board config */
930 dev->board = UNSET;
931 if (card[dev->nr] < saa7164_bcount)
932 dev->board = card[dev->nr];
933
934 for (i = 0; UNSET == dev->board && i < saa7164_idcount; i++)
935 if (dev->pci->subsystem_vendor == saa7164_subids[i].subvendor &&
936 dev->pci->subsystem_device ==
937 saa7164_subids[i].subdevice)
938 dev->board = saa7164_subids[i].card;
939
940 if (UNSET == dev->board) {
941 dev->board = SAA7164_BOARD_UNKNOWN;
942 saa7164_card_list(dev);
943 }
944
945 dev->pci_bus = dev->pci->bus->number;
946 dev->pci_slot = PCI_SLOT(dev->pci->devfn);
947
948 /* I2C Defaults / setup */
949 dev->i2c_bus[0].dev = dev;
950 dev->i2c_bus[0].nr = 0;
951 dev->i2c_bus[1].dev = dev;
952 dev->i2c_bus[1].nr = 1;
953 dev->i2c_bus[2].dev = dev;
954 dev->i2c_bus[2].nr = 2;
955
956 /* Transport + Encoder ports 1, 2, 3, 4 - Defaults / setup */
957 saa7164_port_init(dev, SAA7164_PORT_TS1);
958 saa7164_port_init(dev, SAA7164_PORT_TS2);
959 saa7164_port_init(dev, SAA7164_PORT_ENC1);
960 saa7164_port_init(dev, SAA7164_PORT_ENC2);
961
962 if (get_resources(dev) < 0) {
963 printk(KERN_ERR "CORE %s No more PCIe resources for "
964 "subsystem: %04x:%04x\n",
965 dev->name, dev->pci->subsystem_vendor,
966 dev->pci->subsystem_device);
967
968 saa7164_devcount--;
969 return -ENODEV;
970 }
971
972 /* PCI/e allocations */
973 dev->lmmio = ioremap(pci_resource_start(dev->pci, 0),
974 pci_resource_len(dev->pci, 0));
975
976 dev->lmmio2 = ioremap(pci_resource_start(dev->pci, 2),
977 pci_resource_len(dev->pci, 2));
978
979 dev->bmmio = (u8 __iomem *)dev->lmmio;
980 dev->bmmio2 = (u8 __iomem *)dev->lmmio2;
981
982 /* Inerrupt and ack register locations offset of bmmio */
983 dev->int_status = 0x183000 + 0xf80;
984 dev->int_ack = 0x183000 + 0xf90;
985
986 printk(KERN_INFO
987 "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
988 dev->name, dev->pci->subsystem_vendor,
989 dev->pci->subsystem_device, saa7164_boards[dev->board].name,
990 dev->board, card[dev->nr] == dev->board ?
991 "insmod option" : "autodetected");
992
993 saa7164_pci_quirks(dev);
994
995 return 0;
996 }
997
998 static void saa7164_dev_unregister(struct saa7164_dev *dev)
999 {
1000 dprintk(1, "%s()\n", __func__);
1001
1002 release_mem_region(pci_resource_start(dev->pci, 0),
1003 pci_resource_len(dev->pci, 0));
1004
1005 release_mem_region(pci_resource_start(dev->pci, 2),
1006 pci_resource_len(dev->pci, 2));
1007
1008 if (!atomic_dec_and_test(&dev->refcount))
1009 return;
1010
1011 iounmap(dev->lmmio);
1012 iounmap(dev->lmmio2);
1013
1014 return;
1015 }
1016
1017 static int __devinit saa7164_initdev(struct pci_dev *pci_dev,
1018 const struct pci_device_id *pci_id)
1019 {
1020 struct saa7164_dev *dev;
1021 int err, i;
1022 u32 version;
1023
1024 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1025 if (NULL == dev)
1026 return -ENOMEM;
1027
1028 /* pci init */
1029 dev->pci = pci_dev;
1030 if (pci_enable_device(pci_dev)) {
1031 err = -EIO;
1032 goto fail_free;
1033 }
1034
1035 if (saa7164_dev_setup(dev) < 0) {
1036 err = -EINVAL;
1037 goto fail_free;
1038 }
1039
1040 /* print pci info */
1041 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
1042 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
1043 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
1044 "latency: %d, mmio: 0x%llx\n", dev->name,
1045 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
1046 dev->pci_lat,
1047 (unsigned long long)pci_resource_start(pci_dev, 0));
1048
1049 pci_set_master(pci_dev);
1050 /* TODO */
1051 if (!pci_dma_supported(pci_dev, 0xffffffff)) {
1052 printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name);
1053 err = -EIO;
1054 goto fail_irq;
1055 }
1056
1057 err = request_irq(pci_dev->irq, saa7164_irq,
1058 IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
1059 if (err < 0) {
1060 printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name,
1061 pci_dev->irq);
1062 err = -EIO;
1063 goto fail_irq;
1064 }
1065
1066 pci_set_drvdata(pci_dev, dev);
1067
1068 /* Init the internal command list */
1069 for (i = 0; i < SAA_CMD_MAX_MSG_UNITS; i++) {
1070 dev->cmds[i].seqno = i;
1071 dev->cmds[i].inuse = 0;
1072 mutex_init(&dev->cmds[i].lock);
1073 init_waitqueue_head(&dev->cmds[i].wait);
1074 }
1075
1076 /* We need a deferred interrupt handler for cmd handling */
1077 INIT_WORK(&dev->workcmd, saa7164_work_cmdhandler);
1078
1079 /* Only load the firmware if we know the board */
1080 if (dev->board != SAA7164_BOARD_UNKNOWN) {
1081
1082 err = saa7164_downloadfirmware(dev);
1083 if (err < 0) {
1084 printk(KERN_ERR
1085 "Failed to boot firmware, no features "
1086 "registered\n");
1087 goto fail_fw;
1088 }
1089
1090 saa7164_get_descriptors(dev);
1091 saa7164_dumpregs(dev, 0);
1092 saa7164_getcurrentfirmwareversion(dev);
1093 saa7164_getfirmwarestatus(dev);
1094 err = saa7164_bus_setup(dev);
1095 if (err < 0)
1096 printk(KERN_ERR
1097 "Failed to setup the bus, will continue\n");
1098 saa7164_bus_dump(dev);
1099
1100 /* Ping the running firmware via the command bus and get the
1101 * firmware version, this checks the bus is running OK.
1102 */
1103 version = 0;
1104 if (saa7164_api_get_fw_version(dev, &version) == SAA_OK)
1105 dprintk(1, "Bus is operating correctly using "
1106 "version %d.%d.%d.%d (0x%x)\n",
1107 (version & 0x0000fc00) >> 10,
1108 (version & 0x000003e0) >> 5,
1109 (version & 0x0000001f),
1110 (version & 0xffff0000) >> 16,
1111 version);
1112 else
1113 printk(KERN_ERR
1114 "Failed to communicate with the firmware\n");
1115
1116 /* Bring up the I2C buses */
1117 saa7164_i2c_register(&dev->i2c_bus[0]);
1118 saa7164_i2c_register(&dev->i2c_bus[1]);
1119 saa7164_i2c_register(&dev->i2c_bus[2]);
1120 saa7164_gpio_setup(dev);
1121 saa7164_card_setup(dev);
1122
1123
1124 /* Parse the dynamic device configuration, find various
1125 * media endpoints (MPEG, WMV, PS, TS) and cache their
1126 * configuration details into the driver, so we can
1127 * reference them later during simething_register() func,
1128 * interrupt handlers, deferred work handlers etc.
1129 */
1130 saa7164_api_enum_subdevs(dev);
1131
1132 /* Begin to create the video sub-systems and register funcs */
1133 if (saa7164_boards[dev->board].porta == SAA7164_MPEG_DVB) {
1134 if (saa7164_dvb_register(&dev->ports[ SAA7164_PORT_TS1 ]) < 0) {
1135 printk(KERN_ERR "%s() Failed to register "
1136 "dvb adapters on porta\n",
1137 __func__);
1138 }
1139 }
1140
1141 if (saa7164_boards[dev->board].portb == SAA7164_MPEG_DVB) {
1142 if (saa7164_dvb_register(&dev->ports[ SAA7164_PORT_TS2 ]) < 0) {
1143 printk(KERN_ERR"%s() Failed to register "
1144 "dvb adapters on portb\n",
1145 __func__);
1146 }
1147 }
1148
1149 if (saa7164_boards[dev->board].portc == SAA7164_MPEG_ENCODER) {
1150 if (saa7164_encoder_register(&dev->ports[ SAA7164_PORT_ENC1 ]) < 0) {
1151 printk(KERN_ERR"%s() Failed to register "
1152 "mpeg encoder\n", __func__);
1153 }
1154 }
1155
1156 if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER) {
1157 if (saa7164_encoder_register(&dev->ports[ SAA7164_PORT_ENC2 ]) < 0) {
1158 printk(KERN_ERR"%s() Failed to register "
1159 "mpeg encoder\n", __func__);
1160 }
1161 }
1162
1163 } /* != BOARD_UNKNOWN */
1164 else
1165 printk(KERN_ERR "%s() Unsupported board detected, "
1166 "registering without firmware\n", __func__);
1167
1168 dprintk(1, "%s() parameter debug = %d\n", __func__, saa_debug);
1169 dprintk(1, "%s() parameter waitsecs = %d\n", __func__, waitsecs);
1170
1171 fail_fw:
1172 return 0;
1173
1174 fail_irq:
1175 saa7164_dev_unregister(dev);
1176 fail_free:
1177 kfree(dev);
1178 return err;
1179 }
1180
1181 static void saa7164_shutdown(struct saa7164_dev *dev)
1182 {
1183 dprintk(1, "%s()\n", __func__);
1184 }
1185
1186 static void __devexit saa7164_finidev(struct pci_dev *pci_dev)
1187 {
1188 struct saa7164_dev *dev = pci_get_drvdata(pci_dev);
1189 struct saa7164_port *port;
1190 int i;
1191
1192 saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
1193 &dev->ports[ SAA7164_PORT_ENC1 ].irq_interval);
1194 saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
1195 &dev->ports[ SAA7164_PORT_ENC1 ].svc_interval);
1196 saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
1197 &dev->ports[ SAA7164_PORT_ENC1 ].irq_svc_interval);
1198 saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
1199 &dev->ports[ SAA7164_PORT_ENC1 ].read_interval);
1200 saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
1201 &dev->ports[ SAA7164_PORT_ENC1 ].poll_interval);
1202
1203 saa7164_shutdown(dev);
1204
1205 port = &dev->ports[ SAA7164_PORT_ENC1 ];
1206 if (port->type == SAA7164_MPEG_ENCODER) {
1207 for (i = 0; i < 8; i ++) {
1208 kfree(port->shadow_buf[i]);
1209 port->shadow_buf[i] = 0;
1210 }
1211 }
1212 port = &dev->ports[ SAA7164_PORT_ENC2 ];
1213 if (port->type == SAA7164_MPEG_ENCODER) {
1214 for (i = 0; i < 8; i ++) {
1215 kfree(port->shadow_buf[i]);
1216 port->shadow_buf[i] = 0;
1217 }
1218 }
1219
1220
1221 if (saa7164_boards[dev->board].porta == SAA7164_MPEG_DVB)
1222 saa7164_dvb_unregister(&dev->ports[ SAA7164_PORT_TS1 ]);
1223
1224 if (saa7164_boards[dev->board].portb == SAA7164_MPEG_DVB)
1225 saa7164_dvb_unregister(&dev->ports[ SAA7164_PORT_TS2 ]);
1226
1227 if (saa7164_boards[dev->board].portc == SAA7164_MPEG_ENCODER)
1228 saa7164_encoder_unregister(&dev->ports[ SAA7164_PORT_ENC1 ]);
1229
1230 if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER)
1231 saa7164_encoder_unregister(&dev->ports[ SAA7164_PORT_ENC2 ]);
1232
1233 saa7164_i2c_unregister(&dev->i2c_bus[0]);
1234 saa7164_i2c_unregister(&dev->i2c_bus[1]);
1235 saa7164_i2c_unregister(&dev->i2c_bus[2]);
1236
1237 pci_disable_device(pci_dev);
1238
1239 /* unregister stuff */
1240 free_irq(pci_dev->irq, dev);
1241 pci_set_drvdata(pci_dev, NULL);
1242
1243 mutex_lock(&devlist);
1244 list_del(&dev->devlist);
1245 mutex_unlock(&devlist);
1246
1247 saa7164_dev_unregister(dev);
1248 kfree(dev);
1249 }
1250
1251 static struct pci_device_id saa7164_pci_tbl[] = {
1252 {
1253 /* SAA7164 */
1254 .vendor = 0x1131,
1255 .device = 0x7164,
1256 .subvendor = PCI_ANY_ID,
1257 .subdevice = PCI_ANY_ID,
1258 }, {
1259 /* --- end of list --- */
1260 }
1261 };
1262 MODULE_DEVICE_TABLE(pci, saa7164_pci_tbl);
1263
1264 static struct pci_driver saa7164_pci_driver = {
1265 .name = "saa7164",
1266 .id_table = saa7164_pci_tbl,
1267 .probe = saa7164_initdev,
1268 .remove = __devexit_p(saa7164_finidev),
1269 /* TODO */
1270 .suspend = NULL,
1271 .resume = NULL,
1272 };
1273
1274 static int __init saa7164_init(void)
1275 {
1276 printk(KERN_INFO "saa7164 driver loaded\n");
1277 return pci_register_driver(&saa7164_pci_driver);
1278 }
1279
1280 static void __exit saa7164_fini(void)
1281 {
1282 pci_unregister_driver(&saa7164_pci_driver);
1283 }
1284
1285 module_init(saa7164_init);
1286 module_exit(saa7164_fini);
1287
This page took 0.099337 seconds and 6 git commands to generate.