V4L/DVB (8523): v4l2-dev: remove unused type and type2 field from video_device
[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/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/kmod.h>
29 #include <linux/sound.h>
30 #include <linux/interrupt.h>
31 #include <linux/delay.h>
32 #include <linux/mutex.h>
33 #include <linux/dma-mapping.h>
34 #include <linux/pm.h>
35
36 #include "saa7134-reg.h"
37 #include "saa7134.h"
38
39 MODULE_DESCRIPTION("v4l2 driver module for saa7130/34 based TV cards");
40 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
41 MODULE_LICENSE("GPL");
42
43 /* ------------------------------------------------------------------ */
44
45 static unsigned int irq_debug;
46 module_param(irq_debug, int, 0644);
47 MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]");
48
49 static unsigned int core_debug;
50 module_param(core_debug, int, 0644);
51 MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
52
53 static unsigned int gpio_tracking;
54 module_param(gpio_tracking, int, 0644);
55 MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]");
56
57 static unsigned int alsa;
58 module_param(alsa, int, 0644);
59 MODULE_PARM_DESC(alsa,"enable ALSA DMA sound [dmasound]");
60
61 static unsigned int oss;
62 module_param(oss, int, 0644);
63 MODULE_PARM_DESC(oss,"enable OSS DMA sound [dmasound]");
64
65 static unsigned int latency = UNSET;
66 module_param(latency, int, 0444);
67 MODULE_PARM_DESC(latency,"pci latency timer");
68
69 int saa7134_no_overlay=-1;
70 module_param_named(no_overlay, saa7134_no_overlay, int, 0444);
71 MODULE_PARM_DESC(no_overlay,"allow override overlay default (0 disables, 1 enables)"
72                 " [some VIA/SIS chipsets are known to have problem with overlay]");
73
74 static unsigned int video_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
75 static unsigned int vbi_nr[]   = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
76 static unsigned int radio_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
77 static unsigned int tuner[]    = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
78 static unsigned int card[]     = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
79
80
81 module_param_array(video_nr, int, NULL, 0444);
82 module_param_array(vbi_nr,   int, NULL, 0444);
83 module_param_array(radio_nr, int, NULL, 0444);
84 module_param_array(tuner,    int, NULL, 0444);
85 module_param_array(card,     int, NULL, 0444);
86
87 MODULE_PARM_DESC(video_nr, "video device number");
88 MODULE_PARM_DESC(vbi_nr,   "vbi device number");
89 MODULE_PARM_DESC(radio_nr, "radio device number");
90 MODULE_PARM_DESC(tuner,    "tuner type");
91 MODULE_PARM_DESC(card,     "card type");
92
93 static DEFINE_MUTEX(devlist_lock);
94 LIST_HEAD(saa7134_devlist);
95 static LIST_HEAD(mops_list);
96 static unsigned int saa7134_devcount;
97
98 int (*saa7134_dmasound_init)(struct saa7134_dev *dev);
99 int (*saa7134_dmasound_exit)(struct saa7134_dev *dev);
100
101 #define dprintk(fmt, arg...)    if (core_debug) \
102         printk(KERN_DEBUG "%s/core: " fmt, dev->name , ## arg)
103
104 void saa7134_track_gpio(struct saa7134_dev *dev, char *msg)
105 {
106         unsigned long mode,status;
107
108         if (!gpio_tracking)
109                 return;
110         /* rising SAA7134_GPIO_GPRESCAN reads the status */
111         saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,0);
112         saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,SAA7134_GPIO_GPRESCAN);
113         mode   = saa_readl(SAA7134_GPIO_GPMODE0   >> 2) & 0xfffffff;
114         status = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & 0xfffffff;
115         printk(KERN_DEBUG
116                "%s: gpio: mode=0x%07lx in=0x%07lx out=0x%07lx [%s]\n",
117                dev->name, mode, (~mode) & status, mode & status, msg);
118 }
119
120 void saa7134_set_gpio(struct saa7134_dev *dev, int bit_no, int value)
121 {
122         u32 index, bitval;
123
124         index = 1 << bit_no;
125         switch (value) {
126         case 0: /* static value */
127         case 1: dprintk("setting GPIO%d to static %d\n", bit_no, value);
128                 /* turn sync mode off if necessary */
129                 if (index & 0x00c00000)
130                         saa_andorb(SAA7134_VIDEO_PORT_CTRL6, 0x0f, 0x00);
131                 if (value)
132                         bitval = index;
133                 else
134                         bitval = 0;
135                 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, index, index);
136                 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, index, bitval);
137                 break;
138         case 3: /* tristate */
139                 dprintk("setting GPIO%d to tristate\n", bit_no);
140                 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, index, 0);
141                 break;
142         }
143 }
144
145 /* ------------------------------------------------------------------ */
146
147
148 /* ----------------------------------------------------------- */
149 /* delayed request_module                                      */
150
151 #if defined(CONFIG_MODULES) && defined(MODULE)
152
153 static void request_module_async(struct work_struct *work){
154         struct saa7134_dev* dev = container_of(work, struct saa7134_dev, request_module_wk);
155         if (card_is_empress(dev))
156                 request_module("saa7134-empress");
157         if (card_is_dvb(dev))
158                 request_module("saa7134-dvb");
159         if (alsa)
160                 request_module("saa7134-alsa");
161         if (oss)
162                 request_module("saa7134-oss");
163 }
164
165 static void request_submodules(struct saa7134_dev *dev)
166 {
167         INIT_WORK(&dev->request_module_wk, request_module_async);
168         schedule_work(&dev->request_module_wk);
169 }
170
171 #else
172 #define request_submodules(dev)
173 #endif /* CONFIG_MODULES */
174
175 /* ------------------------------------------------------------------ */
176
177 /* nr of (saa7134-)pages for the given buffer size */
178 static int saa7134_buffer_pages(int size)
179 {
180         size  = PAGE_ALIGN(size);
181         size += PAGE_SIZE; /* for non-page-aligned buffers */
182         size /= 4096;
183         return size;
184 }
185
186 /* calc max # of buffers from size (must not exceed the 4MB virtual
187  * address space per DMA channel) */
188 int saa7134_buffer_count(unsigned int size, unsigned int count)
189 {
190         unsigned int maxcount;
191
192         maxcount = 1024 / saa7134_buffer_pages(size);
193         if (count > maxcount)
194                 count = maxcount;
195         return count;
196 }
197
198 int saa7134_buffer_startpage(struct saa7134_buf *buf)
199 {
200         return saa7134_buffer_pages(buf->vb.bsize) * buf->vb.i;
201 }
202
203 unsigned long saa7134_buffer_base(struct saa7134_buf *buf)
204 {
205         unsigned long base;
206         struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
207
208         base  = saa7134_buffer_startpage(buf) * 4096;
209         base += dma->sglist[0].offset;
210         return base;
211 }
212
213 /* ------------------------------------------------------------------ */
214
215 int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt)
216 {
217         __le32       *cpu;
218         dma_addr_t   dma_addr;
219
220         cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr);
221         if (NULL == cpu)
222                 return -ENOMEM;
223         pt->size = SAA7134_PGTABLE_SIZE;
224         pt->cpu  = cpu;
225         pt->dma  = dma_addr;
226         return 0;
227 }
228
229 int saa7134_pgtable_build(struct pci_dev *pci, struct saa7134_pgtable *pt,
230                           struct scatterlist *list, unsigned int length,
231                           unsigned int startpage)
232 {
233         __le32        *ptr;
234         unsigned int  i,p;
235
236         BUG_ON(NULL == pt || NULL == pt->cpu);
237
238         ptr = pt->cpu + startpage;
239         for (i = 0; i < length; i++, list++)
240                 for (p = 0; p * 4096 < list->length; p++, ptr++)
241                         *ptr = cpu_to_le32(sg_dma_address(list) - list->offset);
242         return 0;
243 }
244
245 void saa7134_pgtable_free(struct pci_dev *pci, struct saa7134_pgtable *pt)
246 {
247         if (NULL == pt->cpu)
248                 return;
249         pci_free_consistent(pci, pt->size, pt->cpu, pt->dma);
250         pt->cpu = NULL;
251 }
252
253 /* ------------------------------------------------------------------ */
254
255 void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf)
256 {
257         struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
258         BUG_ON(in_interrupt());
259
260         videobuf_waiton(&buf->vb,0,0);
261         videobuf_dma_unmap(q, dma);
262         videobuf_dma_free(dma);
263         buf->vb.state = VIDEOBUF_NEEDS_INIT;
264 }
265
266 /* ------------------------------------------------------------------ */
267
268 int saa7134_buffer_queue(struct saa7134_dev *dev,
269                          struct saa7134_dmaqueue *q,
270                          struct saa7134_buf *buf)
271 {
272         struct saa7134_buf *next = NULL;
273
274         assert_spin_locked(&dev->slock);
275         dprintk("buffer_queue %p\n",buf);
276         if (NULL == q->curr) {
277                 if (!q->need_two) {
278                         q->curr = buf;
279                         buf->activate(dev,buf,NULL);
280                 } else if (list_empty(&q->queue)) {
281                         list_add_tail(&buf->vb.queue,&q->queue);
282                         buf->vb.state = VIDEOBUF_QUEUED;
283                 } else {
284                         next = list_entry(q->queue.next,struct saa7134_buf,
285                                           vb.queue);
286                         q->curr = buf;
287                         buf->activate(dev,buf,next);
288                 }
289         } else {
290                 list_add_tail(&buf->vb.queue,&q->queue);
291                 buf->vb.state = VIDEOBUF_QUEUED;
292         }
293         return 0;
294 }
295
296 void saa7134_buffer_finish(struct saa7134_dev *dev,
297                            struct saa7134_dmaqueue *q,
298                            unsigned int state)
299 {
300         assert_spin_locked(&dev->slock);
301         dprintk("buffer_finish %p\n",q->curr);
302
303         /* finish current buffer */
304         q->curr->vb.state = state;
305         do_gettimeofday(&q->curr->vb.ts);
306         wake_up(&q->curr->vb.done);
307         q->curr = NULL;
308 }
309
310 void saa7134_buffer_next(struct saa7134_dev *dev,
311                          struct saa7134_dmaqueue *q)
312 {
313         struct saa7134_buf *buf,*next = NULL;
314
315         assert_spin_locked(&dev->slock);
316         BUG_ON(NULL != q->curr);
317
318         if (!list_empty(&q->queue)) {
319                 /* activate next one from queue */
320                 buf = list_entry(q->queue.next,struct saa7134_buf,vb.queue);
321                 dprintk("buffer_next %p [prev=%p/next=%p]\n",
322                         buf,q->queue.prev,q->queue.next);
323                 list_del(&buf->vb.queue);
324                 if (!list_empty(&q->queue))
325                         next = list_entry(q->queue.next,struct saa7134_buf,
326                                           vb.queue);
327                 q->curr = buf;
328                 buf->activate(dev,buf,next);
329                 dprintk("buffer_next #2 prev=%p/next=%p\n",
330                         q->queue.prev,q->queue.next);
331         } else {
332                 /* nothing to do -- just stop DMA */
333                 dprintk("buffer_next %p\n",NULL);
334                 saa7134_set_dmabits(dev);
335                 del_timer(&q->timeout);
336         }
337 }
338
339 void saa7134_buffer_timeout(unsigned long data)
340 {
341         struct saa7134_dmaqueue *q = (struct saa7134_dmaqueue*)data;
342         struct saa7134_dev *dev = q->dev;
343         unsigned long flags;
344
345         spin_lock_irqsave(&dev->slock,flags);
346
347         /* try to reset the hardware (SWRST) */
348         saa_writeb(SAA7134_REGION_ENABLE, 0x00);
349         saa_writeb(SAA7134_REGION_ENABLE, 0x80);
350         saa_writeb(SAA7134_REGION_ENABLE, 0x00);
351
352         /* flag current buffer as failed,
353            try to start over with the next one. */
354         if (q->curr) {
355                 dprintk("timeout on %p\n",q->curr);
356                 saa7134_buffer_finish(dev,q,VIDEOBUF_ERROR);
357         }
358         saa7134_buffer_next(dev,q);
359         spin_unlock_irqrestore(&dev->slock,flags);
360 }
361
362 /* resends a current buffer in queue after resume */
363
364 static int saa7134_buffer_requeue(struct saa7134_dev *dev,
365                                   struct saa7134_dmaqueue *q)
366 {
367         struct saa7134_buf *buf, *next;
368
369         assert_spin_locked(&dev->slock);
370
371         buf  = q->curr;
372         next = buf;
373         dprintk("buffer_requeue\n");
374
375         if (!buf)
376                 return 0;
377
378         dprintk("buffer_requeue : resending active buffers \n");
379
380         if (!list_empty(&q->queue))
381                 next = list_entry(q->queue.next, struct saa7134_buf,
382                                           vb.queue);
383         buf->activate(dev, buf, next);
384
385         return 0;
386 }
387
388 /* ------------------------------------------------------------------ */
389
390 int saa7134_set_dmabits(struct saa7134_dev *dev)
391 {
392         u32 split, task=0, ctrl=0, irq=0;
393         enum v4l2_field cap = V4L2_FIELD_ANY;
394         enum v4l2_field ov  = V4L2_FIELD_ANY;
395
396         assert_spin_locked(&dev->slock);
397
398         if (dev->insuspend)
399                 return 0;
400
401         /* video capture -- dma 0 + video task A */
402         if (dev->video_q.curr) {
403                 task |= 0x01;
404                 ctrl |= SAA7134_MAIN_CTRL_TE0;
405                 irq  |= SAA7134_IRQ1_INTE_RA0_1 |
406                         SAA7134_IRQ1_INTE_RA0_0;
407                 cap = dev->video_q.curr->vb.field;
408         }
409
410         /* video capture -- dma 1+2 (planar modes) */
411         if (dev->video_q.curr &&
412             dev->video_q.curr->fmt->planar) {
413                 ctrl |= SAA7134_MAIN_CTRL_TE4 |
414                         SAA7134_MAIN_CTRL_TE5;
415         }
416
417         /* screen overlay -- dma 0 + video task B */
418         if (dev->ovenable) {
419                 task |= 0x10;
420                 ctrl |= SAA7134_MAIN_CTRL_TE1;
421                 ov = dev->ovfield;
422         }
423
424         /* vbi capture -- dma 0 + vbi task A+B */
425         if (dev->vbi_q.curr) {
426                 task |= 0x22;
427                 ctrl |= SAA7134_MAIN_CTRL_TE2 |
428                         SAA7134_MAIN_CTRL_TE3;
429                 irq  |= SAA7134_IRQ1_INTE_RA0_7 |
430                         SAA7134_IRQ1_INTE_RA0_6 |
431                         SAA7134_IRQ1_INTE_RA0_5 |
432                         SAA7134_IRQ1_INTE_RA0_4;
433         }
434
435         /* audio capture -- dma 3 */
436         if (dev->dmasound.dma_running) {
437                 ctrl |= SAA7134_MAIN_CTRL_TE6;
438                 irq  |= SAA7134_IRQ1_INTE_RA3_1 |
439                         SAA7134_IRQ1_INTE_RA3_0;
440         }
441
442         /* TS capture -- dma 5 */
443         if (dev->ts_q.curr) {
444                 ctrl |= SAA7134_MAIN_CTRL_TE5;
445                 irq  |= SAA7134_IRQ1_INTE_RA2_3 |
446                         SAA7134_IRQ1_INTE_RA2_2 |
447                         SAA7134_IRQ1_INTE_RA2_1 |
448                         SAA7134_IRQ1_INTE_RA2_0;
449         }
450
451         /* set task conditions + field handling */
452         if (V4L2_FIELD_HAS_BOTH(cap) || V4L2_FIELD_HAS_BOTH(ov) || cap == ov) {
453                 /* default config -- use full frames */
454                 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A), 0x0d);
455                 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B), 0x0d);
456                 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A),  0x02);
457                 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B),  0x02);
458                 split = 0;
459         } else {
460                 /* split fields between tasks */
461                 if (V4L2_FIELD_TOP == cap) {
462                         /* odd A, even B, repeat */
463                         saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A), 0x0d);
464                         saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B), 0x0e);
465                 } else {
466                         /* odd B, even A, repeat */
467                         saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A), 0x0e);
468                         saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B), 0x0d);
469                 }
470                 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A),  0x01);
471                 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B),  0x01);
472                 split = 1;
473         }
474
475         /* irqs */
476         saa_writeb(SAA7134_REGION_ENABLE, task);
477         saa_writel(SAA7134_IRQ1,          irq);
478         saa_andorl(SAA7134_MAIN_CTRL,
479                    SAA7134_MAIN_CTRL_TE0 |
480                    SAA7134_MAIN_CTRL_TE1 |
481                    SAA7134_MAIN_CTRL_TE2 |
482                    SAA7134_MAIN_CTRL_TE3 |
483                    SAA7134_MAIN_CTRL_TE4 |
484                    SAA7134_MAIN_CTRL_TE5 |
485                    SAA7134_MAIN_CTRL_TE6,
486                    ctrl);
487         dprintk("dmabits: task=0x%02x ctrl=0x%02x irq=0x%x split=%s\n",
488                 task, ctrl, irq, split ? "no" : "yes");
489
490         return 0;
491 }
492
493 /* ------------------------------------------------------------------ */
494 /* IRQ handler + helpers                                              */
495
496 static char *irqbits[] = {
497         "DONE_RA0", "DONE_RA1", "DONE_RA2", "DONE_RA3",
498         "AR", "PE", "PWR_ON", "RDCAP", "INTL", "FIDT", "MMC",
499         "TRIG_ERR", "CONF_ERR", "LOAD_ERR",
500         "GPIO16?", "GPIO18", "GPIO22", "GPIO23"
501 };
502 #define IRQBITS ARRAY_SIZE(irqbits)
503
504 static void print_irqstatus(struct saa7134_dev *dev, int loop,
505                             unsigned long report, unsigned long status)
506 {
507         unsigned int i;
508
509         printk(KERN_DEBUG "%s/irq[%d,%ld]: r=0x%lx s=0x%02lx",
510                dev->name,loop,jiffies,report,status);
511         for (i = 0; i < IRQBITS; i++) {
512                 if (!(report & (1 << i)))
513                         continue;
514                 printk(" %s",irqbits[i]);
515         }
516         if (report & SAA7134_IRQ_REPORT_DONE_RA0) {
517                 printk(" | RA0=%s,%s,%s,%ld",
518                        (status & 0x40) ? "vbi"  : "video",
519                        (status & 0x20) ? "b"    : "a",
520                        (status & 0x10) ? "odd"  : "even",
521                        (status & 0x0f));
522         }
523         printk("\n");
524 }
525
526 static irqreturn_t saa7134_irq(int irq, void *dev_id)
527 {
528         struct saa7134_dev *dev = (struct saa7134_dev*) dev_id;
529         unsigned long report,status;
530         int loop, handled = 0;
531
532         if (dev->insuspend)
533                 goto out;
534
535         for (loop = 0; loop < 10; loop++) {
536                 report = saa_readl(SAA7134_IRQ_REPORT);
537                 status = saa_readl(SAA7134_IRQ_STATUS);
538
539                 /* If dmasound support is active and we get a sound report,
540                  * mask out the report and let the saa7134-alsa module deal
541                  * with it */
542                 if ((report & SAA7134_IRQ_REPORT_DONE_RA3) &&
543                         (dev->dmasound.priv_data != NULL) )
544                 {
545                         if (irq_debug > 1)
546                                 printk(KERN_DEBUG "%s/irq: preserving DMA sound interrupt\n",
547                                        dev->name);
548                         report &= ~SAA7134_IRQ_REPORT_DONE_RA3;
549                 }
550
551                 if (0 == report) {
552                         if (irq_debug > 1)
553                                 printk(KERN_DEBUG "%s/irq: no (more) work\n",
554                                        dev->name);
555                         goto out;
556                 }
557
558                 handled = 1;
559                 saa_writel(SAA7134_IRQ_REPORT,report);
560                 if (irq_debug)
561                         print_irqstatus(dev,loop,report,status);
562
563
564                 if ((report & SAA7134_IRQ_REPORT_RDCAP) ||
565                         (report & SAA7134_IRQ_REPORT_INTL))
566                                 saa7134_irq_video_signalchange(dev);
567
568
569                 if ((report & SAA7134_IRQ_REPORT_DONE_RA0) &&
570                     (status & 0x60) == 0)
571                         saa7134_irq_video_done(dev,status);
572
573                 if ((report & SAA7134_IRQ_REPORT_DONE_RA0) &&
574                     (status & 0x40) == 0x40)
575                         saa7134_irq_vbi_done(dev,status);
576
577                 if ((report & SAA7134_IRQ_REPORT_DONE_RA2) &&
578                     card_has_mpeg(dev))
579                         saa7134_irq_ts_done(dev,status);
580
581                 if (report & SAA7134_IRQ_REPORT_GPIO16) {
582                         switch (dev->has_remote) {
583                                 case SAA7134_REMOTE_GPIO:
584                                         if (!dev->remote)
585                                                 break;
586                                         if  (dev->remote->mask_keydown & 0x10000) {
587                                                 saa7134_input_irq(dev);
588                                         }
589                                         break;
590
591                                 case SAA7134_REMOTE_I2C:
592                                         break;                  /* FIXME: invoke I2C get_key() */
593
594                                 default:                        /* GPIO16 not used by IR remote */
595                                         break;
596                         }
597                 }
598
599                 if (report & SAA7134_IRQ_REPORT_GPIO18) {
600                         switch (dev->has_remote) {
601                                 case SAA7134_REMOTE_GPIO:
602                                         if (!dev->remote)
603                                                 break;
604                                         if ((dev->remote->mask_keydown & 0x40000) ||
605                                             (dev->remote->mask_keyup & 0x40000)) {
606                                                 saa7134_input_irq(dev);
607                                         }
608                                         break;
609
610                                 case SAA7134_REMOTE_I2C:
611                                         break;                  /* FIXME: invoke I2C get_key() */
612
613                                 default:                        /* GPIO18 not used by IR remote */
614                                         break;
615                         }
616                 }
617         }
618
619         if (10 == loop) {
620                 print_irqstatus(dev,loop,report,status);
621                 if (report & SAA7134_IRQ_REPORT_PE) {
622                         /* disable all parity error */
623                         printk(KERN_WARNING "%s/irq: looping -- "
624                                "clearing PE (parity error!) enable bit\n",dev->name);
625                         saa_clearl(SAA7134_IRQ2,SAA7134_IRQ2_INTE_PE);
626                 } else if (report & SAA7134_IRQ_REPORT_GPIO16) {
627                         /* disable gpio16 IRQ */
628                         printk(KERN_WARNING "%s/irq: looping -- "
629                                "clearing GPIO16 enable bit\n",dev->name);
630                         saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16);
631                 } else if (report & SAA7134_IRQ_REPORT_GPIO18) {
632                         /* disable gpio18 IRQs */
633                         printk(KERN_WARNING "%s/irq: looping -- "
634                                "clearing GPIO18 enable bit\n",dev->name);
635                         saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
636                 } else {
637                         /* disable all irqs */
638                         printk(KERN_WARNING "%s/irq: looping -- "
639                                "clearing all enable bits\n",dev->name);
640                         saa_writel(SAA7134_IRQ1,0);
641                         saa_writel(SAA7134_IRQ2,0);
642                 }
643         }
644
645  out:
646         return IRQ_RETVAL(handled);
647 }
648
649 /* ------------------------------------------------------------------ */
650
651 /* early init (no i2c, no irq) */
652
653 static int saa7134_hw_enable1(struct saa7134_dev *dev)
654 {
655         /* RAM FIFO config */
656         saa_writel(SAA7134_FIFO_SIZE, 0x08070503);
657         saa_writel(SAA7134_THRESHOULD, 0x02020202);
658
659         /* enable audio + video processing */
660         saa_writel(SAA7134_MAIN_CTRL,
661                         SAA7134_MAIN_CTRL_VPLLE |
662                         SAA7134_MAIN_CTRL_APLLE |
663                         SAA7134_MAIN_CTRL_EXOSC |
664                         SAA7134_MAIN_CTRL_EVFE1 |
665                         SAA7134_MAIN_CTRL_EVFE2 |
666                         SAA7134_MAIN_CTRL_ESFE  |
667                         SAA7134_MAIN_CTRL_EBDAC);
668
669         /*
670         * Initialize OSS _after_ enabling audio clock PLL and audio processing.
671         * OSS initialization writes to registers via the audio DSP; these
672         * writes will fail unless the audio clock has been started.  At worst,
673         * audio will not work.
674         */
675
676         /* enable peripheral devices */
677         saa_writeb(SAA7134_SPECIAL_MODE, 0x01);
678
679         /* set vertical line numbering start (vbi needs this) */
680         saa_writeb(SAA7134_SOURCE_TIMING2, 0x20);
681
682         return 0;
683 }
684
685 static int saa7134_hwinit1(struct saa7134_dev *dev)
686 {
687         dprintk("hwinit1\n");
688
689         saa_writel(SAA7134_IRQ1, 0);
690         saa_writel(SAA7134_IRQ2, 0);
691         mutex_init(&dev->lock);
692         spin_lock_init(&dev->slock);
693
694         saa7134_track_gpio(dev,"pre-init");
695         saa7134_video_init1(dev);
696         saa7134_vbi_init1(dev);
697         if (card_has_mpeg(dev))
698                 saa7134_ts_init1(dev);
699         saa7134_input_init1(dev);
700
701         saa7134_hw_enable1(dev);
702
703         return 0;
704 }
705
706 /* late init (with i2c + irq) */
707 static int saa7134_hw_enable2(struct saa7134_dev *dev)
708 {
709
710         unsigned int irq2_mask;
711
712         /* enable IRQ's */
713         irq2_mask =
714                 SAA7134_IRQ2_INTE_DEC3    |
715                 SAA7134_IRQ2_INTE_DEC2    |
716                 SAA7134_IRQ2_INTE_DEC1    |
717                 SAA7134_IRQ2_INTE_DEC0    |
718                 SAA7134_IRQ2_INTE_PE      |
719                 SAA7134_IRQ2_INTE_AR;
720
721         if (dev->has_remote == SAA7134_REMOTE_GPIO && dev->remote) {
722                 if (dev->remote->mask_keydown & 0x10000)
723                         irq2_mask |= SAA7134_IRQ2_INTE_GPIO16;
724                 else if (dev->remote->mask_keydown & 0x40000)
725                         irq2_mask |= SAA7134_IRQ2_INTE_GPIO18;
726                 else if (dev->remote->mask_keyup & 0x40000)
727                         irq2_mask |= SAA7134_IRQ2_INTE_GPIO18A;
728         }
729
730         saa_writel(SAA7134_IRQ1, 0);
731         saa_writel(SAA7134_IRQ2, irq2_mask);
732
733         return 0;
734 }
735
736 static int saa7134_hwinit2(struct saa7134_dev *dev)
737 {
738
739         dprintk("hwinit2\n");
740
741         saa7134_video_init2(dev);
742         saa7134_tvaudio_init2(dev);
743
744         saa7134_hw_enable2(dev);
745
746         return 0;
747 }
748
749
750 /* shutdown */
751 static int saa7134_hwfini(struct saa7134_dev *dev)
752 {
753         dprintk("hwfini\n");
754
755         if (card_has_mpeg(dev))
756                 saa7134_ts_fini(dev);
757         saa7134_input_fini(dev);
758         saa7134_vbi_fini(dev);
759         saa7134_tvaudio_fini(dev);
760         return 0;
761 }
762
763 static void __devinit must_configure_manually(void)
764 {
765         unsigned int i,p;
766
767         printk(KERN_WARNING
768                "saa7134: <rant>\n"
769                "saa7134:  Congratulations!  Your TV card vendor saved a few\n"
770                "saa7134:  cents for a eeprom, thus your pci board has no\n"
771                "saa7134:  subsystem ID and I can't identify it automatically\n"
772                "saa7134: </rant>\n"
773                "saa7134: I feel better now.  Ok, here are the good news:\n"
774                "saa7134: You can use the card=<nr> insmod option to specify\n"
775                "saa7134: which board do you have.  The list:\n");
776         for (i = 0; i < saa7134_bcount; i++) {
777                 printk(KERN_WARNING "saa7134:   card=%d -> %-40.40s",
778                        i,saa7134_boards[i].name);
779                 for (p = 0; saa7134_pci_tbl[p].driver_data; p++) {
780                         if (saa7134_pci_tbl[p].driver_data != i)
781                                 continue;
782                         printk(" %04x:%04x",
783                                saa7134_pci_tbl[p].subvendor,
784                                saa7134_pci_tbl[p].subdevice);
785                 }
786                 printk("\n");
787         }
788 }
789
790 static struct video_device *vdev_init(struct saa7134_dev *dev,
791                                       struct video_device *template,
792                                       char *type)
793 {
794         struct video_device *vfd;
795
796         vfd = video_device_alloc();
797         if (NULL == vfd)
798                 return NULL;
799         *vfd = *template;
800         vfd->minor   = -1;
801         vfd->parent  = &dev->pci->dev;
802         vfd->release = video_device_release;
803         vfd->debug   = video_debug;
804         snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
805                  dev->name, type, saa7134_boards[dev->board].name);
806         return vfd;
807 }
808
809 static void saa7134_unregister_video(struct saa7134_dev *dev)
810 {
811         if (dev->video_dev) {
812                 if (-1 != dev->video_dev->minor)
813                         video_unregister_device(dev->video_dev);
814                 else
815                         video_device_release(dev->video_dev);
816                 dev->video_dev = NULL;
817         }
818         if (dev->vbi_dev) {
819                 if (-1 != dev->vbi_dev->minor)
820                         video_unregister_device(dev->vbi_dev);
821                 else
822                         video_device_release(dev->vbi_dev);
823                 dev->vbi_dev = NULL;
824         }
825         if (dev->radio_dev) {
826                 if (-1 != dev->radio_dev->minor)
827                         video_unregister_device(dev->radio_dev);
828                 else
829                         video_device_release(dev->radio_dev);
830                 dev->radio_dev = NULL;
831         }
832 }
833
834 static void mpeg_ops_attach(struct saa7134_mpeg_ops *ops,
835                             struct saa7134_dev *dev)
836 {
837         int err;
838
839         if (NULL != dev->mops)
840                 return;
841         if (saa7134_boards[dev->board].mpeg != ops->type)
842                 return;
843         err = ops->init(dev);
844         if (0 != err)
845                 return;
846         dev->mops = ops;
847 }
848
849 static void mpeg_ops_detach(struct saa7134_mpeg_ops *ops,
850                             struct saa7134_dev *dev)
851 {
852         if (NULL == dev->mops)
853                 return;
854         if (dev->mops != ops)
855                 return;
856         dev->mops->fini(dev);
857         dev->mops = NULL;
858 }
859
860 static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
861                                      const struct pci_device_id *pci_id)
862 {
863         struct saa7134_dev *dev;
864         struct saa7134_mpeg_ops *mops;
865         int err;
866
867         if (saa7134_devcount == SAA7134_MAXBOARDS)
868                 return -ENOMEM;
869
870         dev = kzalloc(sizeof(*dev),GFP_KERNEL);
871         if (NULL == dev)
872                 return -ENOMEM;
873
874         /* pci init */
875         dev->pci = pci_dev;
876         if (pci_enable_device(pci_dev)) {
877                 err = -EIO;
878                 goto fail1;
879         }
880
881         dev->nr = saa7134_devcount;
882         sprintf(dev->name,"saa%x[%d]",pci_dev->device,dev->nr);
883
884         /* pci quirks */
885         if (pci_pci_problems) {
886                 if (pci_pci_problems & PCIPCI_TRITON)
887                         printk(KERN_INFO "%s: quirk: PCIPCI_TRITON\n", dev->name);
888                 if (pci_pci_problems & PCIPCI_NATOMA)
889                         printk(KERN_INFO "%s: quirk: PCIPCI_NATOMA\n", dev->name);
890                 if (pci_pci_problems & PCIPCI_VIAETBF)
891                         printk(KERN_INFO "%s: quirk: PCIPCI_VIAETBF\n", dev->name);
892                 if (pci_pci_problems & PCIPCI_VSFX)
893                         printk(KERN_INFO "%s: quirk: PCIPCI_VSFX\n",dev->name);
894 #ifdef PCIPCI_ALIMAGIK
895                 if (pci_pci_problems & PCIPCI_ALIMAGIK) {
896                         printk(KERN_INFO "%s: quirk: PCIPCI_ALIMAGIK -- latency fixup\n",
897                                dev->name);
898                         latency = 0x0A;
899                 }
900 #endif
901                 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL)) {
902                         printk(KERN_INFO "%s: quirk: this driver and your "
903                                         "chipset may not work together"
904                                         " in overlay mode.\n",dev->name);
905                         if (!saa7134_no_overlay) {
906                                 printk(KERN_INFO "%s: quirk: overlay "
907                                                 "mode will be disabled.\n",
908                                                 dev->name);
909                                 saa7134_no_overlay = 1;
910                         } else {
911                                 printk(KERN_INFO "%s: quirk: overlay "
912                                                 "mode will be forced. Use this"
913                                                 " option at your own risk.\n",
914                                                 dev->name);
915                         }
916                 }
917         }
918         if (UNSET != latency) {
919                 printk(KERN_INFO "%s: setting pci latency timer to %d\n",
920                        dev->name,latency);
921                 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
922         }
923
924         /* print pci info */
925         pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
926         pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER,  &dev->pci_lat);
927         printk(KERN_INFO "%s: found at %s, rev: %d, irq: %d, "
928                "latency: %d, mmio: 0x%llx\n", dev->name,
929                pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
930                dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0));
931         pci_set_master(pci_dev);
932         if (!pci_dma_supported(pci_dev, DMA_32BIT_MASK)) {
933                 printk("%s: Oops: no 32bit PCI DMA ???\n",dev->name);
934                 err = -EIO;
935                 goto fail1;
936         }
937
938         /* board config */
939         dev->board = pci_id->driver_data;
940         if (card[dev->nr] >= 0 &&
941             card[dev->nr] < saa7134_bcount)
942                 dev->board = card[dev->nr];
943         if (SAA7134_BOARD_NOAUTO == dev->board) {
944                 must_configure_manually();
945                 dev->board = SAA7134_BOARD_UNKNOWN;
946         }
947         dev->autodetected = card[dev->nr] != dev->board;
948         dev->tuner_type = saa7134_boards[dev->board].tuner_type;
949         dev->tuner_addr = saa7134_boards[dev->board].tuner_addr;
950         dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf;
951         if (UNSET != tuner[dev->nr])
952                 dev->tuner_type = tuner[dev->nr];
953         printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
954                 dev->name,pci_dev->subsystem_vendor,
955                 pci_dev->subsystem_device,saa7134_boards[dev->board].name,
956                 dev->board, dev->autodetected ?
957                 "autodetected" : "insmod option");
958
959         /* get mmio */
960         if (!request_mem_region(pci_resource_start(pci_dev,0),
961                                 pci_resource_len(pci_dev,0),
962                                 dev->name)) {
963                 err = -EBUSY;
964                 printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx\n",
965                        dev->name,(unsigned long long)pci_resource_start(pci_dev,0));
966                 goto fail1;
967         }
968         dev->lmmio = ioremap(pci_resource_start(pci_dev,0), 0x1000);
969         dev->bmmio = (__u8 __iomem *)dev->lmmio;
970         if (NULL == dev->lmmio) {
971                 err = -EIO;
972                 printk(KERN_ERR "%s: can't ioremap() MMIO memory\n",
973                        dev->name);
974                 goto fail2;
975         }
976
977         /* initialize hardware #1 */
978         saa7134_board_init1(dev);
979         saa7134_hwinit1(dev);
980
981         /* get irq */
982         err = request_irq(pci_dev->irq, saa7134_irq,
983                           IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
984         if (err < 0) {
985                 printk(KERN_ERR "%s: can't get IRQ %d\n",
986                        dev->name,pci_dev->irq);
987                 goto fail3;
988         }
989
990         /* wait a bit, register i2c bus */
991         msleep(100);
992         saa7134_i2c_register(dev);
993
994         /* initialize hardware #2 */
995         if (TUNER_ABSENT != dev->tuner_type)
996                 request_module("tuner");
997         saa7134_board_init2(dev);
998
999         saa7134_hwinit2(dev);
1000
1001         /* load i2c helpers */
1002         if (card_is_empress(dev)) {
1003                 request_module("saa6752hs");
1004         }
1005
1006         request_submodules(dev);
1007
1008         v4l2_prio_init(&dev->prio);
1009
1010         /* register v4l devices */
1011         if (saa7134_no_overlay > 0)
1012                 printk(KERN_INFO "%s: Overlay support disabled.\n", dev->name);
1013
1014         dev->video_dev = vdev_init(dev,&saa7134_video_template,"video");
1015         err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
1016                                     video_nr[dev->nr]);
1017         if (err < 0) {
1018                 printk(KERN_INFO "%s: can't register video device\n",
1019                        dev->name);
1020                 goto fail4;
1021         }
1022         printk(KERN_INFO "%s: registered device video%d [v4l2]\n",
1023                dev->name,dev->video_dev->minor & 0x1f);
1024
1025         dev->vbi_dev = vdev_init(dev, &saa7134_video_template, "vbi");
1026
1027         err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
1028                                     vbi_nr[dev->nr]);
1029         if (err < 0)
1030                 goto fail4;
1031         printk(KERN_INFO "%s: registered device vbi%d\n",
1032                dev->name,dev->vbi_dev->minor & 0x1f);
1033
1034         if (card_has_radio(dev)) {
1035                 dev->radio_dev = vdev_init(dev,&saa7134_radio_template,"radio");
1036                 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO,
1037                                             radio_nr[dev->nr]);
1038                 if (err < 0)
1039                         goto fail4;
1040                 printk(KERN_INFO "%s: registered device radio%d\n",
1041                        dev->name,dev->radio_dev->minor & 0x1f);
1042         }
1043
1044         /* everything worked */
1045         pci_set_drvdata(pci_dev,dev);
1046         saa7134_devcount++;
1047
1048         mutex_lock(&devlist_lock);
1049         list_for_each_entry(mops, &mops_list, next)
1050                 mpeg_ops_attach(mops, dev);
1051         list_add_tail(&dev->devlist,&saa7134_devlist);
1052         mutex_unlock(&devlist_lock);
1053
1054         /* check for signal */
1055         saa7134_irq_video_signalchange(dev);
1056
1057         if (saa7134_dmasound_init && !dev->dmasound.priv_data) {
1058                 saa7134_dmasound_init(dev);
1059         }
1060
1061         if (TUNER_ABSENT != dev->tuner_type)
1062                 saa7134_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL);
1063
1064         return 0;
1065
1066  fail4:
1067         saa7134_unregister_video(dev);
1068         saa7134_i2c_unregister(dev);
1069         free_irq(pci_dev->irq, dev);
1070  fail3:
1071         saa7134_hwfini(dev);
1072         iounmap(dev->lmmio);
1073  fail2:
1074         release_mem_region(pci_resource_start(pci_dev,0),
1075                            pci_resource_len(pci_dev,0));
1076  fail1:
1077         kfree(dev);
1078         return err;
1079 }
1080
1081 static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1082 {
1083         struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
1084         struct saa7134_mpeg_ops *mops;
1085
1086         /* Release DMA sound modules if present */
1087         if (saa7134_dmasound_exit && dev->dmasound.priv_data) {
1088                 saa7134_dmasound_exit(dev);
1089         }
1090
1091         /* debugging ... */
1092         if (irq_debug) {
1093                 u32 report = saa_readl(SAA7134_IRQ_REPORT);
1094                 u32 status = saa_readl(SAA7134_IRQ_STATUS);
1095                 print_irqstatus(dev,42,report,status);
1096         }
1097
1098         /* disable peripheral devices */
1099         saa_writeb(SAA7134_SPECIAL_MODE,0);
1100
1101         /* shutdown hardware */
1102         saa_writel(SAA7134_IRQ1,0);
1103         saa_writel(SAA7134_IRQ2,0);
1104         saa_writel(SAA7134_MAIN_CTRL,0);
1105
1106         /* shutdown subsystems */
1107         saa7134_hwfini(dev);
1108
1109         /* unregister */
1110         mutex_lock(&devlist_lock);
1111         list_del(&dev->devlist);
1112         list_for_each_entry(mops, &mops_list, next)
1113                 mpeg_ops_detach(mops, dev);
1114         mutex_unlock(&devlist_lock);
1115         saa7134_devcount--;
1116
1117         saa7134_i2c_unregister(dev);
1118         saa7134_unregister_video(dev);
1119
1120
1121         /* the DMA sound modules should be unloaded before reaching
1122            this, but just in case they are still present... */
1123         if (dev->dmasound.priv_data != NULL) {
1124                 free_irq(pci_dev->irq, &dev->dmasound);
1125                 dev->dmasound.priv_data = NULL;
1126         }
1127
1128
1129         /* release resources */
1130         free_irq(pci_dev->irq, dev);
1131         iounmap(dev->lmmio);
1132         release_mem_region(pci_resource_start(pci_dev,0),
1133                            pci_resource_len(pci_dev,0));
1134
1135         pci_set_drvdata(pci_dev, NULL);
1136
1137         /* free memory */
1138         kfree(dev);
1139 }
1140
1141 #ifdef CONFIG_PM
1142 static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
1143 {
1144
1145         struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
1146
1147         /* disable overlay - apps should enable it explicitly on resume*/
1148         dev->ovenable = 0;
1149
1150         /* Disable interrupts, DMA, and rest of the chip*/
1151         saa_writel(SAA7134_IRQ1, 0);
1152         saa_writel(SAA7134_IRQ2, 0);
1153         saa_writel(SAA7134_MAIN_CTRL, 0);
1154
1155         dev->insuspend = 1;
1156         synchronize_irq(pci_dev->irq);
1157
1158         /* ACK interrupts once more, just in case,
1159                 since the IRQ handler won't ack them anymore*/
1160
1161         saa_writel(SAA7134_IRQ_REPORT, saa_readl(SAA7134_IRQ_REPORT));
1162
1163         /* Disable timeout timers - if we have active buffers, we will
1164            fill them on resume*/
1165
1166         del_timer(&dev->video_q.timeout);
1167         del_timer(&dev->vbi_q.timeout);
1168         del_timer(&dev->ts_q.timeout);
1169
1170         if (dev->remote)
1171                 saa7134_ir_stop(dev);
1172
1173         pci_save_state(pci_dev);
1174         pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
1175
1176         return 0;
1177 }
1178
1179 static int saa7134_resume(struct pci_dev *pci_dev)
1180 {
1181         struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
1182         unsigned long flags;
1183
1184         pci_set_power_state(pci_dev, PCI_D0);
1185         pci_restore_state(pci_dev);
1186
1187         /* Do things that are done in saa7134_initdev ,
1188                 except of initializing memory structures.*/
1189
1190         saa7134_board_init1(dev);
1191
1192         /* saa7134_hwinit1 */
1193         if (saa7134_boards[dev->board].video_out)
1194                 saa7134_videoport_init(dev);
1195         if (card_has_mpeg(dev))
1196                 saa7134_ts_init_hw(dev);
1197         if (dev->remote)
1198                 saa7134_ir_start(dev, dev->remote);
1199         saa7134_hw_enable1(dev);
1200
1201         msleep(100);
1202
1203         saa7134_board_init2(dev);
1204
1205         /*saa7134_hwinit2*/
1206         saa7134_set_tvnorm_hw(dev);
1207         saa7134_tvaudio_setmute(dev);
1208         saa7134_tvaudio_setvolume(dev, dev->ctl_volume);
1209         saa7134_tvaudio_init(dev);
1210         saa7134_tvaudio_do_scan(dev);
1211         saa7134_enable_i2s(dev);
1212         saa7134_hw_enable2(dev);
1213
1214         saa7134_irq_video_signalchange(dev);
1215
1216         /*resume unfinished buffer(s)*/
1217         spin_lock_irqsave(&dev->slock, flags);
1218         saa7134_buffer_requeue(dev, &dev->video_q);
1219         saa7134_buffer_requeue(dev, &dev->vbi_q);
1220         saa7134_buffer_requeue(dev, &dev->ts_q);
1221
1222         /* FIXME: Disable DMA audio sound - temporary till proper support
1223                   is implemented*/
1224
1225         dev->dmasound.dma_running = 0;
1226
1227         /* start DMA now*/
1228         dev->insuspend = 0;
1229         smp_wmb();
1230         saa7134_set_dmabits(dev);
1231         spin_unlock_irqrestore(&dev->slock, flags);
1232
1233         return 0;
1234 }
1235 #endif
1236
1237 /* ----------------------------------------------------------- */
1238
1239 int saa7134_ts_register(struct saa7134_mpeg_ops *ops)
1240 {
1241         struct saa7134_dev *dev;
1242
1243         mutex_lock(&devlist_lock);
1244         list_for_each_entry(dev, &saa7134_devlist, devlist)
1245                 mpeg_ops_attach(ops, dev);
1246         list_add_tail(&ops->next,&mops_list);
1247         mutex_unlock(&devlist_lock);
1248         return 0;
1249 }
1250
1251 void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops)
1252 {
1253         struct saa7134_dev *dev;
1254
1255         mutex_lock(&devlist_lock);
1256         list_del(&ops->next);
1257         list_for_each_entry(dev, &saa7134_devlist, devlist)
1258                 mpeg_ops_detach(ops, dev);
1259         mutex_unlock(&devlist_lock);
1260 }
1261
1262 EXPORT_SYMBOL(saa7134_ts_register);
1263 EXPORT_SYMBOL(saa7134_ts_unregister);
1264
1265 /* ----------------------------------------------------------- */
1266
1267 static struct pci_driver saa7134_pci_driver = {
1268         .name     = "saa7134",
1269         .id_table = saa7134_pci_tbl,
1270         .probe    = saa7134_initdev,
1271         .remove   = __devexit_p(saa7134_finidev),
1272 #ifdef CONFIG_PM
1273         .suspend  = saa7134_suspend,
1274         .resume   = saa7134_resume
1275 #endif
1276 };
1277
1278 static int saa7134_init(void)
1279 {
1280         INIT_LIST_HEAD(&saa7134_devlist);
1281         printk(KERN_INFO "saa7130/34: v4l2 driver version %d.%d.%d loaded\n",
1282                (SAA7134_VERSION_CODE >> 16) & 0xff,
1283                (SAA7134_VERSION_CODE >>  8) & 0xff,
1284                SAA7134_VERSION_CODE & 0xff);
1285 #ifdef SNAPSHOT
1286         printk(KERN_INFO "saa7130/34: snapshot date %04d-%02d-%02d\n",
1287                SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
1288 #endif
1289         return pci_register_driver(&saa7134_pci_driver);
1290 }
1291
1292 static void saa7134_fini(void)
1293 {
1294         pci_unregister_driver(&saa7134_pci_driver);
1295 }
1296
1297 module_init(saa7134_init);
1298 module_exit(saa7134_fini);
1299
1300 /* ----------------------------------------------------------- */
1301
1302 EXPORT_SYMBOL(saa7134_set_gpio);
1303 EXPORT_SYMBOL(saa7134_i2c_call_clients);
1304 EXPORT_SYMBOL(saa7134_devlist);
1305 EXPORT_SYMBOL(saa7134_boards);
1306
1307 /* ----------------- for the DMA sound modules --------------- */
1308
1309 EXPORT_SYMBOL(saa7134_dmasound_init);
1310 EXPORT_SYMBOL(saa7134_dmasound_exit);
1311 EXPORT_SYMBOL(saa7134_pgtable_free);
1312 EXPORT_SYMBOL(saa7134_pgtable_build);
1313 EXPORT_SYMBOL(saa7134_pgtable_alloc);
1314 EXPORT_SYMBOL(saa7134_set_dmabits);
1315
1316 /* ----------------------------------------------------------- */
1317 /*
1318  * Local variables:
1319  * c-basic-offset: 8
1320  * End:
1321  */