Merge master.kernel.org:/pub/scm/linux/kernel/git/acme/net-2.6
[linux-2.6] / drivers / media / video / saa7134 / saa7134-core.c
1 /*
2  *
3  * device driver for philips saa7134 based TV cards
4  * driver core
5  *
6  * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <linux/config.h>
24 #include <linux/init.h>
25 #include <linux/list.h>
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
30 #include <linux/kmod.h>
31 #include <linux/sound.h>
32 #include <linux/interrupt.h>
33 #include <linux/delay.h>
34
35 #include "saa7134-reg.h"
36 #include "saa7134.h"
37
38 MODULE_DESCRIPTION("v4l2 driver module for saa7130/34 based TV cards");
39 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
40 MODULE_LICENSE("GPL");
41
42 /* ------------------------------------------------------------------ */
43
44 static unsigned int irq_debug = 0;
45 module_param(irq_debug, int, 0644);
46 MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]");
47
48 static unsigned int core_debug = 0;
49 module_param(core_debug, int, 0644);
50 MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
51
52 static unsigned int gpio_tracking = 0;
53 module_param(gpio_tracking, int, 0644);
54 MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]");
55
56 static unsigned int oss = 0;
57 module_param(oss, int, 0444);
58 MODULE_PARM_DESC(oss,"register oss devices (default: no)");
59
60 static unsigned int latency = UNSET;
61 module_param(latency, int, 0444);
62 MODULE_PARM_DESC(latency,"pci latency timer");
63
64 static unsigned int video_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
65 static unsigned int vbi_nr[]   = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
66 static unsigned int radio_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
67 static unsigned int dsp_nr[]   = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
68 static unsigned int mixer_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
69 static unsigned int tuner[]    = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
70 static unsigned int card[]     = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
71
72 module_param_array(video_nr, int, NULL, 0444);
73 module_param_array(vbi_nr,   int, NULL, 0444);
74 module_param_array(radio_nr, int, NULL, 0444);
75 module_param_array(dsp_nr,   int, NULL, 0444);
76 module_param_array(mixer_nr, int, NULL, 0444);
77 module_param_array(tuner,    int, NULL, 0444);
78 module_param_array(card,     int, NULL, 0444);
79
80 MODULE_PARM_DESC(video_nr, "video device number");
81 MODULE_PARM_DESC(vbi_nr,   "vbi device number");
82 MODULE_PARM_DESC(radio_nr, "radio device number");
83 MODULE_PARM_DESC(dsp_nr,   "oss dsp device number");
84 MODULE_PARM_DESC(mixer_nr, "oss mixer device number");
85 MODULE_PARM_DESC(tuner,    "tuner type");
86 MODULE_PARM_DESC(card,     "card type");
87
88 static DECLARE_MUTEX(devlist_lock);
89 LIST_HEAD(saa7134_devlist);
90 static LIST_HEAD(mops_list);
91 static unsigned int saa7134_devcount;
92
93 #define dprintk(fmt, arg...)    if (core_debug) \
94         printk(KERN_DEBUG "%s/core: " fmt, dev->name , ## arg)
95
96 /* ------------------------------------------------------------------ */
97 /* debug help functions                                               */
98
99 static const char *v4l1_ioctls[] = {
100         "0", "GCAP", "GCHAN", "SCHAN", "GTUNER", "STUNER", "GPICT", "SPICT",
101         "CCAPTURE", "GWIN", "SWIN", "GFBUF", "SFBUF", "KEY", "GFREQ",
102         "SFREQ", "GAUDIO", "SAUDIO", "SYNC", "MCAPTURE", "GMBUF", "GUNIT",
103         "GCAPTURE", "SCAPTURE", "SPLAYMODE", "SWRITEMODE", "GPLAYINFO",
104         "SMICROCODE", "GVBIFMT", "SVBIFMT" };
105 #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
106
107 static const char *v4l2_ioctls[] = {
108         "QUERYCAP", "1", "ENUM_PIXFMT", "ENUM_FBUFFMT", "G_FMT", "S_FMT",
109         "G_COMP", "S_COMP", "REQBUFS", "QUERYBUF", "G_FBUF", "S_FBUF",
110         "G_WIN", "S_WIN", "PREVIEW", "QBUF", "16", "DQBUF", "STREAMON",
111         "STREAMOFF", "G_PERF", "G_PARM", "S_PARM", "G_STD", "S_STD",
112         "ENUMSTD", "ENUMINPUT", "G_CTRL", "S_CTRL", "G_TUNER", "S_TUNER",
113         "G_FREQ", "S_FREQ", "G_AUDIO", "S_AUDIO", "35", "QUERYCTRL",
114         "QUERYMENU", "G_INPUT", "S_INPUT", "ENUMCVT", "41", "42", "43",
115         "44", "45",  "G_OUTPUT", "S_OUTPUT", "ENUMOUTPUT", "G_AUDOUT",
116         "S_AUDOUT", "ENUMFX", "G_EFFECT", "S_EFFECT", "G_MODULATOR",
117         "S_MODULATOR"
118 };
119 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
120
121 static const char *osspcm_ioctls[] = {
122         "RESET", "SYNC", "SPEED", "STEREO", "GETBLKSIZE", "SETFMT",
123         "CHANNELS", "?", "POST", "SUBDIVIDE", "SETFRAGMENT", "GETFMTS",
124         "GETOSPACE", "GETISPACE", "NONBLOCK", "GETCAPS", "GET/SETTRIGGER",
125         "GETIPTR", "GETOPTR", "MAPINBUF", "MAPOUTBUF", "SETSYNCRO",
126         "SETDUPLEX", "GETODELAY"
127 };
128 #define OSSPCM_IOCTLS ARRAY_SIZE(v4l2_ioctls)
129
130 void saa7134_print_ioctl(char *name, unsigned int cmd)
131 {
132         char *dir;
133
134         switch (_IOC_DIR(cmd)) {
135         case _IOC_NONE:              dir = "--"; break;
136         case _IOC_READ:              dir = "r-"; break;
137         case _IOC_WRITE:             dir = "-w"; break;
138         case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
139         default:                     dir = "??"; break;
140         }
141         switch (_IOC_TYPE(cmd)) {
142         case 'v':
143                 printk(KERN_DEBUG "%s: ioctl 0x%08x (v4l1, %s, VIDIOC%s)\n",
144                        name, cmd, dir, (_IOC_NR(cmd) < V4L1_IOCTLS) ?
145                        v4l1_ioctls[_IOC_NR(cmd)] : "???");
146                 break;
147         case 'V':
148                 printk(KERN_DEBUG "%s: ioctl 0x%08x (v4l2, %s, VIDIOC_%s)\n",
149                        name, cmd, dir, (_IOC_NR(cmd) < V4L2_IOCTLS) ?
150                        v4l2_ioctls[_IOC_NR(cmd)] : "???");
151                 break;
152         case 'P':
153                 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss dsp, %s, SNDCTL_DSP_%s)\n",
154                        name, cmd, dir, (_IOC_NR(cmd) < OSSPCM_IOCTLS) ?
155                        osspcm_ioctls[_IOC_NR(cmd)] : "???");
156                 break;
157         case 'M':
158                 printk(KERN_DEBUG "%s: ioctl 0x%08x (oss mixer, %s, #%d)\n",
159                        name, cmd, dir, _IOC_NR(cmd));
160                 break;
161         default:
162                 printk(KERN_DEBUG "%s: ioctl 0x%08x (???, %s, #%d)\n",
163                        name, cmd, dir, _IOC_NR(cmd));
164         }
165 }
166
167 void saa7134_track_gpio(struct saa7134_dev *dev, char *msg)
168 {
169         unsigned long mode,status;
170
171         if (!gpio_tracking)
172                 return;
173         /* rising SAA7134_GPIO_GPRESCAN reads the status */
174         saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,0);
175         saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,SAA7134_GPIO_GPRESCAN);
176         mode   = saa_readl(SAA7134_GPIO_GPMODE0   >> 2) & 0xfffffff;
177         status = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & 0xfffffff;
178         printk(KERN_DEBUG
179                "%s: gpio: mode=0x%07lx in=0x%07lx out=0x%07lx [%s]\n",
180                dev->name, mode, (~mode) & status, mode & status, msg);
181 }
182
183 /* ------------------------------------------------------------------ */
184
185
186 /* ----------------------------------------------------------- */
187 /* delayed request_module                                      */
188
189 #ifdef CONFIG_MODULES
190
191 static int need_empress;
192 static int need_dvb;
193
194 static int pending_call(struct notifier_block *self, unsigned long state,
195                         void *module)
196 {
197         if (module != THIS_MODULE || state != MODULE_STATE_LIVE)
198                 return NOTIFY_DONE;
199
200         if (need_empress)
201                 request_module("saa7134-empress");
202         if (need_dvb)
203                 request_module("saa7134-dvb");
204         return NOTIFY_DONE;
205 }
206
207 static int pending_registered;
208 static struct notifier_block pending_notifier = {
209         .notifier_call = pending_call,
210 };
211
212 static void request_module_depend(char *name, int *flag)
213 {
214         switch (THIS_MODULE->state) {
215         case MODULE_STATE_COMING:
216                 if (!pending_registered) {
217                         register_module_notifier(&pending_notifier);
218                         pending_registered = 1;
219                 }
220                 *flag = 1;
221                 break;
222         case MODULE_STATE_LIVE:
223                 request_module(name);
224                 break;
225         default:
226                 /* nothing */;
227                 break;
228         }
229 }
230
231 #else
232
233 #define request_module_depend(name,flag)
234
235 #endif /* CONFIG_MODULES */
236
237 /* ------------------------------------------------------------------ */
238
239 /* nr of (saa7134-)pages for the given buffer size */
240 static int saa7134_buffer_pages(int size)
241 {
242         size  = PAGE_ALIGN(size);
243         size += PAGE_SIZE; /* for non-page-aligned buffers */
244         size /= 4096;
245         return size;
246 }
247
248 /* calc max # of buffers from size (must not exceed the 4MB virtual
249  * address space per DMA channel) */
250 int saa7134_buffer_count(unsigned int size, unsigned int count)
251 {
252         unsigned int maxcount;
253
254         maxcount = 1024 / saa7134_buffer_pages(size);
255         if (count > maxcount)
256                 count = maxcount;
257         return count;
258 }
259
260 int saa7134_buffer_startpage(struct saa7134_buf *buf)
261 {
262         return saa7134_buffer_pages(buf->vb.bsize) * buf->vb.i;
263 }
264
265 unsigned long saa7134_buffer_base(struct saa7134_buf *buf)
266 {
267         unsigned long base;
268
269         base  = saa7134_buffer_startpage(buf) * 4096;
270         base += buf->vb.dma.sglist[0].offset;
271         return base;
272 }
273
274 /* ------------------------------------------------------------------ */
275
276 int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt)
277 {
278         __le32       *cpu;
279         dma_addr_t   dma_addr;
280
281         cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr);
282         if (NULL == cpu)
283                 return -ENOMEM;
284         pt->size = SAA7134_PGTABLE_SIZE;
285         pt->cpu  = cpu;
286         pt->dma  = dma_addr;
287         return 0;
288 }
289
290 int saa7134_pgtable_build(struct pci_dev *pci, struct saa7134_pgtable *pt,
291                           struct scatterlist *list, unsigned int length,
292                           unsigned int startpage)
293 {
294         __le32        *ptr;
295         unsigned int  i,p;
296
297         BUG_ON(NULL == pt || NULL == pt->cpu);
298
299         ptr = pt->cpu + startpage;
300         for (i = 0; i < length; i++, list++)
301                 for (p = 0; p * 4096 < list->length; p++, ptr++)
302                         *ptr = cpu_to_le32(sg_dma_address(list) - list->offset);
303         return 0;
304 }
305
306 void saa7134_pgtable_free(struct pci_dev *pci, struct saa7134_pgtable *pt)
307 {
308         if (NULL == pt->cpu)
309                 return;
310         pci_free_consistent(pci, pt->size, pt->cpu, pt->dma);
311         pt->cpu = NULL;
312 }
313
314 /* ------------------------------------------------------------------ */
315
316 void saa7134_dma_free(struct saa7134_dev *dev,struct saa7134_buf *buf)
317 {
318         if (in_interrupt())
319                 BUG();
320
321         videobuf_waiton(&buf->vb,0,0);
322         videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma);
323         videobuf_dma_free(&buf->vb.dma);
324         buf->vb.state = STATE_NEEDS_INIT;
325 }
326
327 /* ------------------------------------------------------------------ */
328
329 int saa7134_buffer_queue(struct saa7134_dev *dev,
330                          struct saa7134_dmaqueue *q,
331                          struct saa7134_buf *buf)
332 {
333         struct saa7134_buf *next = NULL;
334
335         assert_spin_locked(&dev->slock);
336         dprintk("buffer_queue %p\n",buf);
337         if (NULL == q->curr) {
338                 if (!q->need_two) {
339                         q->curr = buf;
340                         buf->activate(dev,buf,NULL);
341                 } else if (list_empty(&q->queue)) {
342                         list_add_tail(&buf->vb.queue,&q->queue);
343                         buf->vb.state = STATE_QUEUED;
344                 } else {
345                         next = list_entry(q->queue.next,struct saa7134_buf,
346                                           vb.queue);
347                         q->curr = buf;
348                         buf->activate(dev,buf,next);
349                 }
350         } else {
351                 list_add_tail(&buf->vb.queue,&q->queue);
352                 buf->vb.state = STATE_QUEUED;
353         }
354         return 0;
355 }
356
357 void saa7134_buffer_finish(struct saa7134_dev *dev,
358                            struct saa7134_dmaqueue *q,
359                            unsigned int state)
360 {
361         assert_spin_locked(&dev->slock);
362         dprintk("buffer_finish %p\n",q->curr);
363
364         /* finish current buffer */
365         q->curr->vb.state = state;
366         do_gettimeofday(&q->curr->vb.ts);
367         wake_up(&q->curr->vb.done);
368         q->curr = NULL;
369 }
370
371 void saa7134_buffer_next(struct saa7134_dev *dev,
372                          struct saa7134_dmaqueue *q)
373 {
374         struct saa7134_buf *buf,*next = NULL;
375
376         assert_spin_locked(&dev->slock);
377         BUG_ON(NULL != q->curr);
378
379         if (!list_empty(&q->queue)) {
380                 /* activate next one from queue */
381                 buf = list_entry(q->queue.next,struct saa7134_buf,vb.queue);
382                 dprintk("buffer_next %p [prev=%p/next=%p]\n",
383                         buf,q->queue.prev,q->queue.next);
384                 list_del(&buf->vb.queue);
385                 if (!list_empty(&q->queue))
386                         next = list_entry(q->queue.next,struct saa7134_buf,
387                                           vb.queue);
388                 q->curr = buf;
389                 buf->activate(dev,buf,next);
390                 dprintk("buffer_next #2 prev=%p/next=%p\n",
391                         q->queue.prev,q->queue.next);
392         } else {
393                 /* nothing to do -- just stop DMA */
394                 dprintk("buffer_next %p\n",NULL);
395                 saa7134_set_dmabits(dev);
396                 del_timer(&q->timeout);
397         }
398 }
399
400 void saa7134_buffer_timeout(unsigned long data)
401 {
402         struct saa7134_dmaqueue *q = (struct saa7134_dmaqueue*)data;
403         struct saa7134_dev *dev = q->dev;
404         unsigned long flags;
405
406         spin_lock_irqsave(&dev->slock,flags);
407
408         /* try to reset the hardware (SWRST) */
409         saa_writeb(SAA7134_REGION_ENABLE, 0x00);
410         saa_writeb(SAA7134_REGION_ENABLE, 0x80);
411         saa_writeb(SAA7134_REGION_ENABLE, 0x00);
412
413         /* flag current buffer as failed,
414            try to start over with the next one. */
415         if (q->curr) {
416                 dprintk("timeout on %p\n",q->curr);
417                 saa7134_buffer_finish(dev,q,STATE_ERROR);
418         }
419         saa7134_buffer_next(dev,q);
420         spin_unlock_irqrestore(&dev->slock,flags);
421 }
422
423 /* ------------------------------------------------------------------ */
424
425 int saa7134_set_dmabits(struct saa7134_dev *dev)
426 {
427         u32 split, task=0, ctrl=0, irq=0;
428         enum v4l2_field cap = V4L2_FIELD_ANY;
429         enum v4l2_field ov  = V4L2_FIELD_ANY;
430
431         assert_spin_locked(&dev->slock);
432
433         /* video capture -- dma 0 + video task A */
434         if (dev->video_q.curr) {
435                 task |= 0x01;
436                 ctrl |= SAA7134_MAIN_CTRL_TE0;
437                 irq  |= SAA7134_IRQ1_INTE_RA0_1 |
438                         SAA7134_IRQ1_INTE_RA0_0;
439                 cap = dev->video_q.curr->vb.field;
440         }
441
442         /* video capture -- dma 1+2 (planar modes) */
443         if (dev->video_q.curr &&
444             dev->video_q.curr->fmt->planar) {
445                 ctrl |= SAA7134_MAIN_CTRL_TE4 |
446                         SAA7134_MAIN_CTRL_TE5;
447         }
448
449         /* screen overlay -- dma 0 + video task B */
450         if (dev->ovenable) {
451                 task |= 0x10;
452                 ctrl |= SAA7134_MAIN_CTRL_TE1;
453                 ov = dev->ovfield;
454         }
455
456         /* vbi capture -- dma 0 + vbi task A+B */
457         if (dev->vbi_q.curr) {
458                 task |= 0x22;
459                 ctrl |= SAA7134_MAIN_CTRL_TE2 |
460                         SAA7134_MAIN_CTRL_TE3;
461                 irq  |= SAA7134_IRQ1_INTE_RA0_7 |
462                         SAA7134_IRQ1_INTE_RA0_6 |
463                         SAA7134_IRQ1_INTE_RA0_5 |
464                         SAA7134_IRQ1_INTE_RA0_4;
465         }
466
467         /* audio capture -- dma 3 */
468         if (dev->oss.dma_running) {
469                 ctrl |= SAA7134_MAIN_CTRL_TE6;
470                 irq  |= SAA7134_IRQ1_INTE_RA3_1 |
471                         SAA7134_IRQ1_INTE_RA3_0;
472         }
473
474         /* TS capture -- dma 5 */
475         if (dev->ts_q.curr) {
476                 ctrl |= SAA7134_MAIN_CTRL_TE5;
477                 irq  |= SAA7134_IRQ1_INTE_RA2_3 |
478                         SAA7134_IRQ1_INTE_RA2_2 |
479                         SAA7134_IRQ1_INTE_RA2_1 |
480                         SAA7134_IRQ1_INTE_RA2_0;
481         }
482
483         /* set task conditions + field handling */
484         if (V4L2_FIELD_HAS_BOTH(cap) || V4L2_FIELD_HAS_BOTH(ov) || cap == ov) {
485                 /* default config -- use full frames */
486                 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A), 0x0d);
487                 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B), 0x0d);
488                 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A),  0x02);
489                 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B),  0x02);
490                 split = 0;
491         } else {
492                 /* split fields between tasks */
493                 if (V4L2_FIELD_TOP == cap) {
494                         /* odd A, even B, repeat */
495                         saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A), 0x0d);
496                         saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B), 0x0e);
497                 } else {
498                         /* odd B, even A, repeat */
499                         saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A), 0x0e);
500                         saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B), 0x0d);
501                 }
502                 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A),  0x01);
503                 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B),  0x01);
504                 split = 1;
505         }
506
507         /* irqs */
508         saa_writeb(SAA7134_REGION_ENABLE, task);
509         saa_writel(SAA7134_IRQ1,          irq);
510         saa_andorl(SAA7134_MAIN_CTRL,
511                    SAA7134_MAIN_CTRL_TE0 |
512                    SAA7134_MAIN_CTRL_TE1 |
513                    SAA7134_MAIN_CTRL_TE2 |
514                    SAA7134_MAIN_CTRL_TE3 |
515                    SAA7134_MAIN_CTRL_TE4 |
516                    SAA7134_MAIN_CTRL_TE5 |
517                    SAA7134_MAIN_CTRL_TE6,
518                    ctrl);
519         dprintk("dmabits: task=0x%02x ctrl=0x%02x irq=0x%x split=%s\n",
520                 task, ctrl, irq, split ? "no" : "yes");
521
522         return 0;
523 }
524
525 /* ------------------------------------------------------------------ */
526 /* IRQ handler + helpers                                              */
527
528 static char *irqbits[] = {
529         "DONE_RA0", "DONE_RA1", "DONE_RA2", "DONE_RA3",
530         "AR", "PE", "PWR_ON", "RDCAP", "INTL", "FIDT", "MMC",
531         "TRIG_ERR", "CONF_ERR", "LOAD_ERR",
532         "GPIO16?", "GPIO18", "GPIO22", "GPIO23"
533 };
534 #define IRQBITS ARRAY_SIZE(irqbits)
535
536 static void print_irqstatus(struct saa7134_dev *dev, int loop,
537                             unsigned long report, unsigned long status)
538 {
539         unsigned int i;
540
541         printk(KERN_DEBUG "%s/irq[%d,%ld]: r=0x%lx s=0x%02lx",
542                dev->name,loop,jiffies,report,status);
543         for (i = 0; i < IRQBITS; i++) {
544                 if (!(report & (1 << i)))
545                         continue;
546                 printk(" %s",irqbits[i]);
547         }
548         if (report & SAA7134_IRQ_REPORT_DONE_RA0) {
549                 printk(" | RA0=%s,%s,%s,%ld",
550                        (status & 0x40) ? "vbi"  : "video",
551                        (status & 0x20) ? "b"    : "a",
552                        (status & 0x10) ? "odd"  : "even",
553                        (status & 0x0f));
554         }
555         printk("\n");
556 }
557
558 static irqreturn_t saa7134_irq(int irq, void *dev_id, struct pt_regs *regs)
559 {
560         struct saa7134_dev *dev = (struct saa7134_dev*) dev_id;
561         unsigned long report,status;
562         int loop, handled = 0;
563
564         for (loop = 0; loop < 10; loop++) {
565                 report = saa_readl(SAA7134_IRQ_REPORT);
566                 status = saa_readl(SAA7134_IRQ_STATUS);
567                 if (0 == report) {
568                         if (irq_debug > 1)
569                                 printk(KERN_DEBUG "%s/irq: no (more) work\n",
570                                        dev->name);
571                         goto out;
572                 }
573                 handled = 1;
574                 saa_writel(SAA7134_IRQ_REPORT,report);
575                 if (irq_debug)
576                         print_irqstatus(dev,loop,report,status);
577
578
579                 if (report & SAA7134_IRQ_REPORT_RDCAP /* _INTL */)
580                         saa7134_irq_video_intl(dev);
581
582                 if ((report & SAA7134_IRQ_REPORT_DONE_RA0) &&
583                     (status & 0x60) == 0)
584                         saa7134_irq_video_done(dev,status);
585
586                 if ((report & SAA7134_IRQ_REPORT_DONE_RA0) &&
587                     (status & 0x40) == 0x40)
588                         saa7134_irq_vbi_done(dev,status);
589
590                 if ((report & SAA7134_IRQ_REPORT_DONE_RA2) &&
591                     card_has_mpeg(dev))
592                         saa7134_irq_ts_done(dev,status);
593
594                 if ((report & SAA7134_IRQ_REPORT_DONE_RA3))
595                         saa7134_irq_oss_done(dev,status);
596
597                 if ((report & (SAA7134_IRQ_REPORT_GPIO16 |
598                                SAA7134_IRQ_REPORT_GPIO18)) &&
599                     dev->remote)
600                         saa7134_input_irq(dev);
601         }
602
603         if (10 == loop) {
604                 print_irqstatus(dev,loop,report,status);
605                 if (report & SAA7134_IRQ_REPORT_PE) {
606                         /* disable all parity error */
607                         printk(KERN_WARNING "%s/irq: looping -- "
608                                "clearing PE (parity error!) enable bit\n",dev->name);
609                         saa_clearl(SAA7134_IRQ2,SAA7134_IRQ2_INTE_PE);
610                 } else if (report & (SAA7134_IRQ_REPORT_GPIO16 |
611                                      SAA7134_IRQ_REPORT_GPIO18)) {
612                         /* disable gpio IRQs */
613                         printk(KERN_WARNING "%s/irq: looping -- "
614                                "clearing GPIO enable bits\n",dev->name);
615                         saa_clearl(SAA7134_IRQ2, (SAA7134_IRQ2_INTE_GPIO16 |
616                                                   SAA7134_IRQ2_INTE_GPIO18));
617                 } else {
618                         /* disable all irqs */
619                         printk(KERN_WARNING "%s/irq: looping -- "
620                                "clearing all enable bits\n",dev->name);
621                         saa_writel(SAA7134_IRQ1,0);
622                         saa_writel(SAA7134_IRQ2,0);
623                 }
624         }
625
626  out:
627         return IRQ_RETVAL(handled);
628 }
629
630 /* ------------------------------------------------------------------ */
631
632 /* early init (no i2c, no irq) */
633 static int saa7134_hwinit1(struct saa7134_dev *dev)
634 {
635         dprintk("hwinit1\n");
636
637         saa_writel(SAA7134_IRQ1, 0);
638         saa_writel(SAA7134_IRQ2, 0);
639         init_MUTEX(&dev->lock);
640         spin_lock_init(&dev->slock);
641
642         saa7134_track_gpio(dev,"pre-init");
643         saa7134_video_init1(dev);
644         saa7134_vbi_init1(dev);
645         if (card_has_mpeg(dev))
646                 saa7134_ts_init1(dev);
647         saa7134_input_init1(dev);
648
649         switch (dev->pci->device) {
650         case PCI_DEVICE_ID_PHILIPS_SAA7134:
651         case PCI_DEVICE_ID_PHILIPS_SAA7133:
652         case PCI_DEVICE_ID_PHILIPS_SAA7135:
653                 saa7134_oss_init1(dev);
654                 break;
655         }
656
657         /* RAM FIFO config */
658         saa_writel(SAA7134_FIFO_SIZE, 0x08070503);
659         saa_writel(SAA7134_THRESHOULD,0x02020202);
660
661         /* enable audio + video processing */
662         saa_writel(SAA7134_MAIN_CTRL,
663                    SAA7134_MAIN_CTRL_VPLLE |
664                    SAA7134_MAIN_CTRL_APLLE |
665                    SAA7134_MAIN_CTRL_EXOSC |
666                    SAA7134_MAIN_CTRL_EVFE1 |
667                    SAA7134_MAIN_CTRL_EVFE2 |
668                    SAA7134_MAIN_CTRL_ESFE  |
669                    SAA7134_MAIN_CTRL_EBDAC);
670
671         /* enable peripheral devices */
672         saa_writeb(SAA7134_SPECIAL_MODE, 0x01);
673
674         /* set vertical line numbering start (vbi needs this) */
675         saa_writeb(SAA7134_SOURCE_TIMING2, 0x20);
676
677         return 0;
678 }
679
680 /* late init (with i2c + irq) */
681 static int saa7134_hwinit2(struct saa7134_dev *dev)
682 {
683         unsigned int irq2_mask;
684         dprintk("hwinit2\n");
685
686         saa7134_video_init2(dev);
687         saa7134_tvaudio_init2(dev);
688
689         /* enable IRQ's */
690         irq2_mask =
691                 SAA7134_IRQ2_INTE_DEC3    |
692                 SAA7134_IRQ2_INTE_DEC2    |
693                 SAA7134_IRQ2_INTE_DEC1    |
694                 SAA7134_IRQ2_INTE_DEC0    |
695                 SAA7134_IRQ2_INTE_PE      |
696                 SAA7134_IRQ2_INTE_AR;
697
698         if (dev->has_remote)
699                 irq2_mask |= (SAA7134_IRQ2_INTE_GPIO18  |
700                               SAA7134_IRQ2_INTE_GPIO18A |
701                               SAA7134_IRQ2_INTE_GPIO16  );
702
703         saa_writel(SAA7134_IRQ1, 0);
704         saa_writel(SAA7134_IRQ2, irq2_mask);
705
706         return 0;
707 }
708
709 /* shutdown */
710 static int saa7134_hwfini(struct saa7134_dev *dev)
711 {
712         dprintk("hwfini\n");
713
714         switch (dev->pci->device) {
715         case PCI_DEVICE_ID_PHILIPS_SAA7134:
716         case PCI_DEVICE_ID_PHILIPS_SAA7133:
717         case PCI_DEVICE_ID_PHILIPS_SAA7135:
718                 saa7134_oss_fini(dev);
719                 break;
720         }
721         if (card_has_mpeg(dev))
722                 saa7134_ts_fini(dev);
723         saa7134_input_fini(dev);
724         saa7134_vbi_fini(dev);
725         saa7134_video_fini(dev);
726         saa7134_tvaudio_fini(dev);
727         return 0;
728 }
729
730 static void __devinit must_configure_manually(void)
731 {
732         unsigned int i,p;
733
734         printk(KERN_WARNING
735                "saa7134: <rant>\n"
736                "saa7134:  Congratulations!  Your TV card vendor saved a few\n"
737                "saa7134:  cents for a eeprom, thus your pci board has no\n"
738                "saa7134:  subsystem ID and I can't identify it automatically\n"
739                "saa7134: </rant>\n"
740                "saa7134: I feel better now.  Ok, here are the good news:\n"
741                "saa7134: You can use the card=<nr> insmod option to specify\n"
742                "saa7134: which board do you have.  The list:\n");
743         for (i = 0; i < saa7134_bcount; i++) {
744                 printk(KERN_WARNING "saa7134:   card=%d -> %-40.40s",
745                        i,saa7134_boards[i].name);
746                 for (p = 0; saa7134_pci_tbl[p].driver_data; p++) {
747                         if (saa7134_pci_tbl[p].driver_data != i)
748                                 continue;
749                         printk(" %04x:%04x",
750                                saa7134_pci_tbl[p].subvendor,
751                                saa7134_pci_tbl[p].subdevice);
752                 }
753                 printk("\n");
754         }
755 }
756
757 static struct video_device *vdev_init(struct saa7134_dev *dev,
758                                       struct video_device *template,
759                                       char *type)
760 {
761         struct video_device *vfd;
762
763         vfd = video_device_alloc();
764         if (NULL == vfd)
765                 return NULL;
766         *vfd = *template;
767         vfd->minor   = -1;
768         vfd->dev     = &dev->pci->dev;
769         vfd->release = video_device_release;
770         snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
771                  dev->name, type, saa7134_boards[dev->board].name);
772         return vfd;
773 }
774
775 static void saa7134_unregister_video(struct saa7134_dev *dev)
776 {
777         if (dev->video_dev) {
778                 if (-1 != dev->video_dev->minor)
779                         video_unregister_device(dev->video_dev);
780                 else
781                         video_device_release(dev->video_dev);
782                 dev->video_dev = NULL;
783         }
784         if (dev->vbi_dev) {
785                 if (-1 != dev->vbi_dev->minor)
786                         video_unregister_device(dev->vbi_dev);
787                 else
788                         video_device_release(dev->vbi_dev);
789                 dev->vbi_dev = NULL;
790         }
791         if (dev->radio_dev) {
792                 if (-1 != dev->radio_dev->minor)
793                         video_unregister_device(dev->radio_dev);
794                 else
795                         video_device_release(dev->radio_dev);
796                 dev->radio_dev = NULL;
797         }
798 }
799
800 static void mpeg_ops_attach(struct saa7134_mpeg_ops *ops,
801                             struct saa7134_dev *dev)
802 {
803         int err;
804
805         if (NULL != dev->mops)
806                 return;
807         if (saa7134_boards[dev->board].mpeg != ops->type)
808                 return;
809         err = ops->init(dev);
810         if (0 != err)
811                 return;
812         dev->mops = ops;
813 }
814
815 static void mpeg_ops_detach(struct saa7134_mpeg_ops *ops,
816                             struct saa7134_dev *dev)
817 {
818         if (NULL == dev->mops)
819                 return;
820         if (dev->mops != ops)
821                 return;
822         dev->mops->fini(dev);
823         dev->mops = NULL;
824 }
825
826 static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
827                                      const struct pci_device_id *pci_id)
828 {
829         struct saa7134_dev *dev;
830         struct list_head *item;
831         struct saa7134_mpeg_ops *mops;
832         int err;
833
834         dev = kmalloc(sizeof(*dev),GFP_KERNEL);
835         if (NULL == dev)
836                 return -ENOMEM;
837         memset(dev,0,sizeof(*dev));
838
839         /* pci init */
840         dev->pci = pci_dev;
841         if (pci_enable_device(pci_dev)) {
842                 err = -EIO;
843                 goto fail1;
844         }
845
846         dev->nr = saa7134_devcount;
847         sprintf(dev->name,"saa%x[%d]",pci_dev->device,dev->nr);
848
849         /* pci quirks */
850         if (pci_pci_problems) {
851                 if (pci_pci_problems & PCIPCI_TRITON)
852                         printk(KERN_INFO "%s: quirk: PCIPCI_TRITON\n", dev->name);
853                 if (pci_pci_problems & PCIPCI_NATOMA)
854                         printk(KERN_INFO "%s: quirk: PCIPCI_NATOMA\n", dev->name);
855                 if (pci_pci_problems & PCIPCI_VIAETBF)
856                         printk(KERN_INFO "%s: quirk: PCIPCI_VIAETBF\n", dev->name);
857                 if (pci_pci_problems & PCIPCI_VSFX)
858                         printk(KERN_INFO "%s: quirk: PCIPCI_VSFX\n",dev->name);
859 #ifdef PCIPCI_ALIMAGIK
860                 if (pci_pci_problems & PCIPCI_ALIMAGIK) {
861                         printk(KERN_INFO "%s: quirk: PCIPCI_ALIMAGIK -- latency fixup\n",
862                                dev->name);
863                         latency = 0x0A;
864                 }
865 #endif
866         }
867         if (UNSET != latency) {
868                 printk(KERN_INFO "%s: setting pci latency timer to %d\n",
869                        dev->name,latency);
870                 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
871         }
872
873         /* print pci info */
874         pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
875         pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER,  &dev->pci_lat);
876         printk(KERN_INFO "%s: found at %s, rev: %d, irq: %d, "
877                "latency: %d, mmio: 0x%lx\n", dev->name,
878                pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
879                dev->pci_lat,pci_resource_start(pci_dev,0));
880         pci_set_master(pci_dev);
881         if (!pci_dma_supported(pci_dev,0xffffffff)) {
882                 printk("%s: Oops: no 32bit PCI DMA ???\n",dev->name);
883                 err = -EIO;
884                 goto fail1;
885         }
886
887         /* board config */
888         dev->board = pci_id->driver_data;
889         if (card[dev->nr] >= 0 &&
890             card[dev->nr] < saa7134_bcount)
891                 dev->board = card[dev->nr];
892         if (SAA7134_BOARD_NOAUTO == dev->board) {
893                 must_configure_manually();
894                 dev->board = SAA7134_BOARD_UNKNOWN;
895         }
896         dev->tuner_type   = saa7134_boards[dev->board].tuner_type;
897         dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf;
898         if (UNSET != tuner[dev->nr])
899                 dev->tuner_type = tuner[dev->nr];
900         printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
901                dev->name,pci_dev->subsystem_vendor,
902                pci_dev->subsystem_device,saa7134_boards[dev->board].name,
903                dev->board, card[dev->nr] == dev->board ?
904                "insmod option" : "autodetected");
905
906         /* get mmio */
907         if (!request_mem_region(pci_resource_start(pci_dev,0),
908                                 pci_resource_len(pci_dev,0),
909                                 dev->name)) {
910                 err = -EBUSY;
911                 printk(KERN_ERR "%s: can't get MMIO memory @ 0x%lx\n",
912                        dev->name,pci_resource_start(pci_dev,0));
913                 goto fail1;
914         }
915         dev->lmmio = ioremap(pci_resource_start(pci_dev,0), 0x1000);
916         dev->bmmio = (__u8 __iomem *)dev->lmmio;
917         if (NULL == dev->lmmio) {
918                 err = -EIO;
919                 printk(KERN_ERR "%s: can't ioremap() MMIO memory\n",
920                        dev->name);
921                 goto fail2;
922         }
923
924         /* initialize hardware #1 */
925         saa7134_board_init1(dev);
926         saa7134_hwinit1(dev);
927
928         /* get irq */
929         err = request_irq(pci_dev->irq, saa7134_irq,
930                           SA_SHIRQ | SA_INTERRUPT, dev->name, dev);
931         if (err < 0) {
932                 printk(KERN_ERR "%s: can't get IRQ %d\n",
933                        dev->name,pci_dev->irq);
934                 goto fail3;
935         }
936
937         /* wait a bit, register i2c bus */
938         msleep(100);
939         saa7134_i2c_register(dev);
940
941         /* initialize hardware #2 */
942         saa7134_board_init2(dev);
943         saa7134_hwinit2(dev);
944
945         /* load i2c helpers */
946         if (TUNER_ABSENT != dev->tuner_type)
947                 request_module("tuner");
948         if (dev->tda9887_conf)
949                 request_module("tda9887");
950         if (card_is_empress(dev)) {
951                 request_module("saa6752hs");
952                 request_module_depend("saa7134-empress",&need_empress);
953         }
954
955         if (card_is_dvb(dev))
956                 request_module_depend("saa7134-dvb",&need_dvb);
957
958         v4l2_prio_init(&dev->prio);
959
960         /* register v4l devices */
961         dev->video_dev = vdev_init(dev,&saa7134_video_template,"video");
962         err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
963                                     video_nr[dev->nr]);
964         if (err < 0) {
965                 printk(KERN_INFO "%s: can't register video device\n",
966                        dev->name);
967                 goto fail4;
968         }
969         printk(KERN_INFO "%s: registered device video%d [v4l2]\n",
970                dev->name,dev->video_dev->minor & 0x1f);
971
972         dev->vbi_dev = vdev_init(dev,&saa7134_vbi_template,"vbi");
973         err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
974                                     vbi_nr[dev->nr]);
975         if (err < 0)
976                 goto fail4;
977         printk(KERN_INFO "%s: registered device vbi%d\n",
978                dev->name,dev->vbi_dev->minor & 0x1f);
979
980         if (card_has_radio(dev)) {
981                 dev->radio_dev = vdev_init(dev,&saa7134_radio_template,"radio");
982                 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO,
983                                             radio_nr[dev->nr]);
984                 if (err < 0)
985                         goto fail4;
986                 printk(KERN_INFO "%s: registered device radio%d\n",
987                        dev->name,dev->radio_dev->minor & 0x1f);
988         }
989
990         /* register oss devices */
991         switch (dev->pci->device) {
992         case PCI_DEVICE_ID_PHILIPS_SAA7134:
993         case PCI_DEVICE_ID_PHILIPS_SAA7133:
994         case PCI_DEVICE_ID_PHILIPS_SAA7135:
995                 if (oss) {
996                         err = dev->oss.minor_dsp =
997                                 register_sound_dsp(&saa7134_dsp_fops,
998                                                    dsp_nr[dev->nr]);
999                         if (err < 0) {
1000                                 goto fail4;
1001                         }
1002                         printk(KERN_INFO "%s: registered device dsp%d\n",
1003                                dev->name,dev->oss.minor_dsp >> 4);
1004
1005                         err = dev->oss.minor_mixer =
1006                                 register_sound_mixer(&saa7134_mixer_fops,
1007                                                      mixer_nr[dev->nr]);
1008                         if (err < 0)
1009                                 goto fail5;
1010                         printk(KERN_INFO "%s: registered device mixer%d\n",
1011                                dev->name,dev->oss.minor_mixer >> 4);
1012                 }
1013                 break;
1014         }
1015
1016         /* everything worked */
1017         pci_set_drvdata(pci_dev,dev);
1018         saa7134_devcount++;
1019
1020         down(&devlist_lock);
1021         list_for_each(item,&mops_list) {
1022                 mops = list_entry(item, struct saa7134_mpeg_ops, next);
1023                 mpeg_ops_attach(mops, dev);
1024         }
1025         list_add_tail(&dev->devlist,&saa7134_devlist);
1026         up(&devlist_lock);
1027
1028         /* check for signal */
1029         saa7134_irq_video_intl(dev);
1030         return 0;
1031
1032  fail5:
1033         switch (dev->pci->device) {
1034         case PCI_DEVICE_ID_PHILIPS_SAA7134:
1035         case PCI_DEVICE_ID_PHILIPS_SAA7133:
1036         case PCI_DEVICE_ID_PHILIPS_SAA7135:
1037                 if (oss)
1038                         unregister_sound_dsp(dev->oss.minor_dsp);
1039                 break;
1040         }
1041  fail4:
1042         saa7134_unregister_video(dev);
1043         saa7134_i2c_unregister(dev);
1044         free_irq(pci_dev->irq, dev);
1045  fail3:
1046         saa7134_hwfini(dev);
1047         iounmap(dev->lmmio);
1048  fail2:
1049         release_mem_region(pci_resource_start(pci_dev,0),
1050                            pci_resource_len(pci_dev,0));
1051  fail1:
1052         kfree(dev);
1053         return err;
1054 }
1055
1056 static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1057 {
1058         struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
1059         struct list_head *item;
1060         struct saa7134_mpeg_ops *mops;
1061
1062         /* debugging ... */
1063         if (irq_debug) {
1064                 u32 report = saa_readl(SAA7134_IRQ_REPORT);
1065                 u32 status = saa_readl(SAA7134_IRQ_STATUS);
1066                 print_irqstatus(dev,42,report,status);
1067         }
1068
1069         /* disable peripheral devices */
1070         saa_writeb(SAA7134_SPECIAL_MODE,0);
1071
1072         /* shutdown hardware */
1073         saa_writel(SAA7134_IRQ1,0);
1074         saa_writel(SAA7134_IRQ2,0);
1075         saa_writel(SAA7134_MAIN_CTRL,0);
1076
1077         /* shutdown subsystems */
1078         saa7134_hwfini(dev);
1079
1080         /* unregister */
1081         down(&devlist_lock);
1082         list_del(&dev->devlist);
1083         list_for_each(item,&mops_list) {
1084                 mops = list_entry(item, struct saa7134_mpeg_ops, next);
1085                 mpeg_ops_detach(mops, dev);
1086         }
1087         up(&devlist_lock);
1088         saa7134_devcount--;
1089
1090         saa7134_i2c_unregister(dev);
1091         switch (dev->pci->device) {
1092         case PCI_DEVICE_ID_PHILIPS_SAA7134:
1093         case PCI_DEVICE_ID_PHILIPS_SAA7133:
1094         case PCI_DEVICE_ID_PHILIPS_SAA7135:
1095                 if (oss) {
1096                         unregister_sound_mixer(dev->oss.minor_mixer);
1097                         unregister_sound_dsp(dev->oss.minor_dsp);
1098                 }
1099                 break;
1100         }
1101         saa7134_unregister_video(dev);
1102
1103         /* release ressources */
1104         free_irq(pci_dev->irq, dev);
1105         iounmap(dev->lmmio);
1106         release_mem_region(pci_resource_start(pci_dev,0),
1107                            pci_resource_len(pci_dev,0));
1108
1109         pci_set_drvdata(pci_dev, NULL);
1110
1111         /* free memory */
1112         kfree(dev);
1113 }
1114
1115 /* ----------------------------------------------------------- */
1116
1117 int saa7134_ts_register(struct saa7134_mpeg_ops *ops)
1118 {
1119         struct list_head *item;
1120         struct saa7134_dev *dev;
1121
1122         down(&devlist_lock);
1123         list_for_each(item,&saa7134_devlist) {
1124                 dev = list_entry(item, struct saa7134_dev, devlist);
1125                 mpeg_ops_attach(ops, dev);
1126         }
1127         list_add_tail(&ops->next,&mops_list);
1128         up(&devlist_lock);
1129         return 0;
1130 }
1131
1132 void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops)
1133 {
1134         struct list_head *item;
1135         struct saa7134_dev *dev;
1136
1137         down(&devlist_lock);
1138         list_del(&ops->next);
1139         list_for_each(item,&saa7134_devlist) {
1140                 dev = list_entry(item, struct saa7134_dev, devlist);
1141                 mpeg_ops_detach(ops, dev);
1142         }
1143         up(&devlist_lock);
1144 }
1145
1146 EXPORT_SYMBOL(saa7134_ts_register);
1147 EXPORT_SYMBOL(saa7134_ts_unregister);
1148
1149 /* ----------------------------------------------------------- */
1150
1151 static struct pci_driver saa7134_pci_driver = {
1152         .name     = "saa7134",
1153         .id_table = saa7134_pci_tbl,
1154         .probe    = saa7134_initdev,
1155         .remove   = __devexit_p(saa7134_finidev),
1156 };
1157
1158 static int saa7134_init(void)
1159 {
1160         INIT_LIST_HEAD(&saa7134_devlist);
1161         printk(KERN_INFO "saa7130/34: v4l2 driver version %d.%d.%d loaded\n",
1162                (SAA7134_VERSION_CODE >> 16) & 0xff,
1163                (SAA7134_VERSION_CODE >>  8) & 0xff,
1164                SAA7134_VERSION_CODE & 0xff);
1165 #ifdef SNAPSHOT
1166         printk(KERN_INFO "saa7130/34: snapshot date %04d-%02d-%02d\n",
1167                SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
1168 #endif
1169         return pci_module_init(&saa7134_pci_driver);
1170 }
1171
1172 static void saa7134_fini(void)
1173 {
1174 #ifdef CONFIG_MODULES
1175         if (pending_registered)
1176                 unregister_module_notifier(&pending_notifier);
1177 #endif
1178         pci_unregister_driver(&saa7134_pci_driver);
1179 }
1180
1181 module_init(saa7134_init);
1182 module_exit(saa7134_fini);
1183
1184 /* ----------------------------------------------------------- */
1185
1186 EXPORT_SYMBOL(saa7134_print_ioctl);
1187 EXPORT_SYMBOL(saa7134_i2c_call_clients);
1188 EXPORT_SYMBOL(saa7134_devlist);
1189 EXPORT_SYMBOL(saa7134_boards);
1190
1191 /* ----------------------------------------------------------- */
1192 /*
1193  * Local variables:
1194  * c-basic-offset: 8
1195  * End:
1196  */