3 * device driver for philips saa7134 based TV cards
6 * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
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.
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.
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.
24 #include "saa7134-reg.h"
26 #include <linux/init.h>
27 #include <linux/list.h>
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/slab.h>
31 #include <linux/kmod.h>
32 #include <linux/sound.h>
33 #include <linux/interrupt.h>
34 #include <linux/delay.h>
35 #include <linux/mutex.h>
36 #include <linux/dma-mapping.h>
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 MODULE_VERSION(SAA7134_VERSION
);
45 /* ------------------------------------------------------------------ */
47 static unsigned int irq_debug
;
48 module_param(irq_debug
, int, 0644);
49 MODULE_PARM_DESC(irq_debug
,"enable debug messages [IRQ handler]");
51 static unsigned int core_debug
;
52 module_param(core_debug
, int, 0644);
53 MODULE_PARM_DESC(core_debug
,"enable debug messages [core]");
55 static unsigned int gpio_tracking
;
56 module_param(gpio_tracking
, int, 0644);
57 MODULE_PARM_DESC(gpio_tracking
,"enable debug messages [gpio]");
59 static unsigned int alsa
= 1;
60 module_param(alsa
, int, 0644);
61 MODULE_PARM_DESC(alsa
,"enable/disable ALSA DMA sound [dmasound]");
63 static unsigned int latency
= UNSET
;
64 module_param(latency
, int, 0444);
65 MODULE_PARM_DESC(latency
,"pci latency timer");
67 int saa7134_no_overlay
=-1;
68 module_param_named(no_overlay
, saa7134_no_overlay
, int, 0444);
69 MODULE_PARM_DESC(no_overlay
,"allow override overlay default (0 disables, 1 enables)"
70 " [some VIA/SIS chipsets are known to have problem with overlay]");
73 module_param(saa7134_userptr
, bool, 0644);
74 MODULE_PARM_DESC(saa7134_userptr
, "enable page-aligned userptr support");
76 static unsigned int video_nr
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
77 static unsigned int vbi_nr
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
78 static unsigned int radio_nr
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
79 static unsigned int tuner
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
80 static unsigned int card
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
83 module_param_array(video_nr
, int, NULL
, 0444);
84 module_param_array(vbi_nr
, int, NULL
, 0444);
85 module_param_array(radio_nr
, int, NULL
, 0444);
86 module_param_array(tuner
, int, NULL
, 0444);
87 module_param_array(card
, int, NULL
, 0444);
89 MODULE_PARM_DESC(video_nr
, "video device number");
90 MODULE_PARM_DESC(vbi_nr
, "vbi device number");
91 MODULE_PARM_DESC(radio_nr
, "radio device number");
92 MODULE_PARM_DESC(tuner
, "tuner type");
93 MODULE_PARM_DESC(card
, "card type");
95 DEFINE_MUTEX(saa7134_devlist_lock
);
96 EXPORT_SYMBOL(saa7134_devlist_lock
);
97 LIST_HEAD(saa7134_devlist
);
98 EXPORT_SYMBOL(saa7134_devlist
);
99 static LIST_HEAD(mops_list
);
100 static unsigned int saa7134_devcount
;
102 int (*saa7134_dmasound_init
)(struct saa7134_dev
*dev
);
103 int (*saa7134_dmasound_exit
)(struct saa7134_dev
*dev
);
105 #define core_dbg(fmt, arg...) do { \
107 printk(KERN_DEBUG pr_fmt("core: " fmt), ## arg); \
110 #define irq_dbg(level, fmt, arg...) do {\
111 if (irq_debug > level) \
112 printk(KERN_DEBUG pr_fmt("irq: " fmt), ## arg); \
115 void saa7134_track_gpio(struct saa7134_dev
*dev
, const char *msg
)
117 unsigned long mode
,status
;
121 /* rising SAA7134_GPIO_GPRESCAN reads the status */
122 saa_andorb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
,0);
123 saa_andorb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
,SAA7134_GPIO_GPRESCAN
);
124 mode
= saa_readl(SAA7134_GPIO_GPMODE0
>> 2) & 0xfffffff;
125 status
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2) & 0xfffffff;
126 core_dbg("%s: gpio: mode=0x%07lx in=0x%07lx out=0x%07lx [%s]\n",
127 dev
->name
, mode
, (~mode
) & status
, mode
& status
, msg
);
130 void saa7134_set_gpio(struct saa7134_dev
*dev
, int bit_no
, int value
)
136 case 0: /* static value */
138 core_dbg("setting GPIO%d to static %d\n", bit_no
, value
);
139 /* turn sync mode off if necessary */
140 if (index
& 0x00c00000)
141 saa_andorb(SAA7134_VIDEO_PORT_CTRL6
, 0x0f, 0x00);
146 saa_andorl(SAA7134_GPIO_GPMODE0
>> 2, index
, index
);
147 saa_andorl(SAA7134_GPIO_GPSTATUS0
>> 2, index
, bitval
);
149 case 3: /* tristate */
150 core_dbg("setting GPIO%d to tristate\n", bit_no
);
151 saa_andorl(SAA7134_GPIO_GPMODE0
>> 2, index
, 0);
156 /* ------------------------------------------------------------------ */
159 /* ----------------------------------------------------------- */
160 /* delayed request_module */
162 #if defined(CONFIG_MODULES) && defined(MODULE)
164 static void request_module_async(struct work_struct
*work
){
165 struct saa7134_dev
* dev
= container_of(work
, struct saa7134_dev
, request_module_wk
);
166 if (card_is_empress(dev
))
167 request_module("saa7134-empress");
168 if (card_is_dvb(dev
))
169 request_module("saa7134-dvb");
170 if (card_is_go7007(dev
))
171 request_module("saa7134-go7007");
173 if (dev
->pci
->device
!= PCI_DEVICE_ID_PHILIPS_SAA7130
)
174 request_module("saa7134-alsa");
178 static void request_submodules(struct saa7134_dev
*dev
)
180 INIT_WORK(&dev
->request_module_wk
, request_module_async
);
181 schedule_work(&dev
->request_module_wk
);
184 static void flush_request_submodules(struct saa7134_dev
*dev
)
186 flush_work(&dev
->request_module_wk
);
190 #define request_submodules(dev)
191 #define flush_request_submodules(dev)
192 #endif /* CONFIG_MODULES */
194 /* ------------------------------------------------------------------ */
196 /* nr of (saa7134-)pages for the given buffer size */
197 static int saa7134_buffer_pages(int size
)
199 size
= PAGE_ALIGN(size
);
200 size
+= PAGE_SIZE
; /* for non-page-aligned buffers */
205 /* calc max # of buffers from size (must not exceed the 4MB virtual
206 * address space per DMA channel) */
207 int saa7134_buffer_count(unsigned int size
, unsigned int count
)
209 unsigned int maxcount
;
211 maxcount
= 1024 / saa7134_buffer_pages(size
);
212 if (count
> maxcount
)
217 int saa7134_buffer_startpage(struct saa7134_buf
*buf
)
219 return saa7134_buffer_pages(vb2_plane_size(&buf
->vb2
.vb2_buf
, 0))
220 * buf
->vb2
.vb2_buf
.index
;
223 unsigned long saa7134_buffer_base(struct saa7134_buf
*buf
)
226 struct sg_table
*dma
= vb2_dma_sg_plane_desc(&buf
->vb2
.vb2_buf
, 0);
228 base
= saa7134_buffer_startpage(buf
) * 4096;
229 base
+= dma
->sgl
[0].offset
;
233 /* ------------------------------------------------------------------ */
235 int saa7134_pgtable_alloc(struct pci_dev
*pci
, struct saa7134_pgtable
*pt
)
238 dma_addr_t dma_addr
= 0;
240 cpu
= pci_alloc_consistent(pci
, SAA7134_PGTABLE_SIZE
, &dma_addr
);
243 pt
->size
= SAA7134_PGTABLE_SIZE
;
249 int saa7134_pgtable_build(struct pci_dev
*pci
, struct saa7134_pgtable
*pt
,
250 struct scatterlist
*list
, unsigned int length
,
251 unsigned int startpage
)
256 BUG_ON(NULL
== pt
|| NULL
== pt
->cpu
);
258 ptr
= pt
->cpu
+ startpage
;
259 for (i
= 0; i
< length
; i
++, list
= sg_next(list
)) {
260 for (p
= 0; p
* 4096 < list
->length
; p
++, ptr
++)
261 *ptr
= cpu_to_le32(sg_dma_address(list
) +
262 list
->offset
+ p
* 4096);
267 void saa7134_pgtable_free(struct pci_dev
*pci
, struct saa7134_pgtable
*pt
)
271 pci_free_consistent(pci
, pt
->size
, pt
->cpu
, pt
->dma
);
275 /* ------------------------------------------------------------------ */
277 int saa7134_buffer_queue(struct saa7134_dev
*dev
,
278 struct saa7134_dmaqueue
*q
,
279 struct saa7134_buf
*buf
)
281 struct saa7134_buf
*next
= NULL
;
284 spin_lock_irqsave(&dev
->slock
, flags
);
285 core_dbg("buffer_queue %p\n", buf
);
286 if (NULL
== q
->curr
) {
289 buf
->activate(dev
, buf
, NULL
);
290 } else if (list_empty(&q
->queue
)) {
291 list_add_tail(&buf
->entry
, &q
->queue
);
293 next
= list_entry(q
->queue
.next
, struct saa7134_buf
,
296 buf
->activate(dev
, buf
, next
);
299 list_add_tail(&buf
->entry
, &q
->queue
);
301 spin_unlock_irqrestore(&dev
->slock
, flags
);
305 void saa7134_buffer_finish(struct saa7134_dev
*dev
,
306 struct saa7134_dmaqueue
*q
,
309 core_dbg("buffer_finish %p\n", q
->curr
);
311 /* finish current buffer */
312 q
->curr
->vb2
.vb2_buf
.timestamp
= ktime_get_ns();
313 q
->curr
->vb2
.sequence
= q
->seq_nr
++;
314 vb2_buffer_done(&q
->curr
->vb2
.vb2_buf
, state
);
318 void saa7134_buffer_next(struct saa7134_dev
*dev
,
319 struct saa7134_dmaqueue
*q
)
321 struct saa7134_buf
*buf
,*next
= NULL
;
323 assert_spin_locked(&dev
->slock
);
324 BUG_ON(NULL
!= q
->curr
);
326 if (!list_empty(&q
->queue
)) {
327 /* activate next one from queue */
328 buf
= list_entry(q
->queue
.next
, struct saa7134_buf
, entry
);
329 core_dbg("buffer_next %p [prev=%p/next=%p]\n",
330 buf
, q
->queue
.prev
, q
->queue
.next
);
331 list_del(&buf
->entry
);
332 if (!list_empty(&q
->queue
))
333 next
= list_entry(q
->queue
.next
, struct saa7134_buf
, entry
);
335 buf
->activate(dev
, buf
, next
);
336 core_dbg("buffer_next #2 prev=%p/next=%p\n",
337 q
->queue
.prev
, q
->queue
.next
);
339 /* nothing to do -- just stop DMA */
340 core_dbg("buffer_next %p\n", NULL
);
341 saa7134_set_dmabits(dev
);
342 del_timer(&q
->timeout
);
346 void saa7134_buffer_timeout(unsigned long data
)
348 struct saa7134_dmaqueue
*q
= (struct saa7134_dmaqueue
*)data
;
349 struct saa7134_dev
*dev
= q
->dev
;
352 spin_lock_irqsave(&dev
->slock
, flags
);
354 /* try to reset the hardware (SWRST) */
355 saa_writeb(SAA7134_REGION_ENABLE
, 0x00);
356 saa_writeb(SAA7134_REGION_ENABLE
, 0x80);
357 saa_writeb(SAA7134_REGION_ENABLE
, 0x00);
359 /* flag current buffer as failed,
360 try to start over with the next one. */
362 core_dbg("timeout on %p\n", q
->curr
);
363 saa7134_buffer_finish(dev
, q
, VB2_BUF_STATE_ERROR
);
365 saa7134_buffer_next(dev
, q
);
366 spin_unlock_irqrestore(&dev
->slock
, flags
);
369 void saa7134_stop_streaming(struct saa7134_dev
*dev
, struct saa7134_dmaqueue
*q
)
372 struct list_head
*pos
, *n
;
373 struct saa7134_buf
*tmp
;
375 spin_lock_irqsave(&dev
->slock
, flags
);
376 if (!list_empty(&q
->queue
)) {
377 list_for_each_safe(pos
, n
, &q
->queue
) {
378 tmp
= list_entry(pos
, struct saa7134_buf
, entry
);
379 vb2_buffer_done(&tmp
->vb2
.vb2_buf
,
380 VB2_BUF_STATE_ERROR
);
385 spin_unlock_irqrestore(&dev
->slock
, flags
);
386 saa7134_buffer_timeout((unsigned long)q
); /* also calls del_timer(&q->timeout) */
388 EXPORT_SYMBOL_GPL(saa7134_stop_streaming
);
390 /* ------------------------------------------------------------------ */
392 int saa7134_set_dmabits(struct saa7134_dev
*dev
)
394 u32 split
, task
=0, ctrl
=0, irq
=0;
395 enum v4l2_field cap
= V4L2_FIELD_ANY
;
396 enum v4l2_field ov
= V4L2_FIELD_ANY
;
398 assert_spin_locked(&dev
->slock
);
403 /* video capture -- dma 0 + video task A */
404 if (dev
->video_q
.curr
) {
406 ctrl
|= SAA7134_MAIN_CTRL_TE0
;
407 irq
|= SAA7134_IRQ1_INTE_RA0_1
|
408 SAA7134_IRQ1_INTE_RA0_0
;
412 /* video capture -- dma 1+2 (planar modes) */
413 if (dev
->video_q
.curr
&& dev
->fmt
->planar
) {
414 ctrl
|= SAA7134_MAIN_CTRL_TE4
|
415 SAA7134_MAIN_CTRL_TE5
;
418 /* screen overlay -- dma 0 + video task B */
421 ctrl
|= SAA7134_MAIN_CTRL_TE1
;
425 /* vbi capture -- dma 0 + vbi task A+B */
426 if (dev
->vbi_q
.curr
) {
428 ctrl
|= SAA7134_MAIN_CTRL_TE2
|
429 SAA7134_MAIN_CTRL_TE3
;
430 irq
|= SAA7134_IRQ1_INTE_RA0_7
|
431 SAA7134_IRQ1_INTE_RA0_6
|
432 SAA7134_IRQ1_INTE_RA0_5
|
433 SAA7134_IRQ1_INTE_RA0_4
;
436 /* audio capture -- dma 3 */
437 if (dev
->dmasound
.dma_running
) {
438 ctrl
|= SAA7134_MAIN_CTRL_TE6
;
439 irq
|= SAA7134_IRQ1_INTE_RA3_1
|
440 SAA7134_IRQ1_INTE_RA3_0
;
443 /* TS capture -- dma 5 */
444 if (dev
->ts_q
.curr
) {
445 ctrl
|= SAA7134_MAIN_CTRL_TE5
;
446 irq
|= SAA7134_IRQ1_INTE_RA2_1
|
447 SAA7134_IRQ1_INTE_RA2_0
;
450 /* set task conditions + field handling */
451 if (V4L2_FIELD_HAS_BOTH(cap
) || V4L2_FIELD_HAS_BOTH(ov
) || cap
== ov
) {
452 /* default config -- use full frames */
453 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A
), 0x0d);
454 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B
), 0x0d);
455 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A
), 0x02);
456 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B
), 0x02);
459 /* split fields between tasks */
460 if (V4L2_FIELD_TOP
== cap
) {
461 /* odd A, even B, repeat */
462 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A
), 0x0d);
463 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B
), 0x0e);
465 /* odd B, even A, repeat */
466 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A
), 0x0e);
467 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B
), 0x0d);
469 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A
), 0x01);
470 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B
), 0x01);
475 saa_writeb(SAA7134_REGION_ENABLE
, task
);
476 saa_writel(SAA7134_IRQ1
, irq
);
477 saa_andorl(SAA7134_MAIN_CTRL
,
478 SAA7134_MAIN_CTRL_TE0
|
479 SAA7134_MAIN_CTRL_TE1
|
480 SAA7134_MAIN_CTRL_TE2
|
481 SAA7134_MAIN_CTRL_TE3
|
482 SAA7134_MAIN_CTRL_TE4
|
483 SAA7134_MAIN_CTRL_TE5
|
484 SAA7134_MAIN_CTRL_TE6
,
486 core_dbg("dmabits: task=0x%02x ctrl=0x%02x irq=0x%x split=%s\n",
487 task
, ctrl
, irq
, split
? "no" : "yes");
492 /* ------------------------------------------------------------------ */
493 /* IRQ handler + helpers */
495 static char *irqbits
[] = {
496 "DONE_RA0", "DONE_RA1", "DONE_RA2", "DONE_RA3",
497 "AR", "PE", "PWR_ON", "RDCAP", "INTL", "FIDT", "MMC",
498 "TRIG_ERR", "CONF_ERR", "LOAD_ERR",
499 "GPIO16", "GPIO18", "GPIO22", "GPIO23"
501 #define IRQBITS ARRAY_SIZE(irqbits)
503 static void print_irqstatus(struct saa7134_dev
*dev
, int loop
,
504 unsigned long report
, unsigned long status
)
508 irq_dbg(1, "[%d,%ld]: r=0x%lx s=0x%02lx",
509 loop
, jiffies
, report
, status
);
510 for (i
= 0; i
< IRQBITS
; i
++) {
511 if (!(report
& (1 << i
)))
513 pr_cont(" %s", irqbits
[i
]);
515 if (report
& SAA7134_IRQ_REPORT_DONE_RA0
) {
516 pr_cont(" | RA0=%s,%s,%s,%ld",
517 (status
& 0x40) ? "vbi" : "video",
518 (status
& 0x20) ? "b" : "a",
519 (status
& 0x10) ? "odd" : "even",
525 static irqreturn_t
saa7134_irq(int irq
, void *dev_id
)
527 struct saa7134_dev
*dev
= (struct saa7134_dev
*) dev_id
;
528 unsigned long report
,status
;
529 int loop
, handled
= 0;
534 for (loop
= 0; loop
< 10; loop
++) {
535 report
= saa_readl(SAA7134_IRQ_REPORT
);
536 status
= saa_readl(SAA7134_IRQ_STATUS
);
538 /* If dmasound support is active and we get a sound report,
539 * mask out the report and let the saa7134-alsa module deal
541 if ((report
& SAA7134_IRQ_REPORT_DONE_RA3
) &&
542 (dev
->dmasound
.priv_data
!= NULL
) )
544 irq_dbg(2, "preserving DMA sound interrupt\n");
545 report
&= ~SAA7134_IRQ_REPORT_DONE_RA3
;
549 irq_dbg(2, "no (more) work\n");
554 saa_writel(SAA7134_IRQ_REPORT
,report
);
556 print_irqstatus(dev
,loop
,report
,status
);
559 if ((report
& SAA7134_IRQ_REPORT_RDCAP
) ||
560 (report
& SAA7134_IRQ_REPORT_INTL
))
561 saa7134_irq_video_signalchange(dev
);
564 if ((report
& SAA7134_IRQ_REPORT_DONE_RA0
) &&
565 (status
& 0x60) == 0)
566 saa7134_irq_video_done(dev
,status
);
568 if ((report
& SAA7134_IRQ_REPORT_DONE_RA0
) &&
569 (status
& 0x40) == 0x40)
570 saa7134_irq_vbi_done(dev
,status
);
572 if ((report
& SAA7134_IRQ_REPORT_DONE_RA2
) &&
573 card_has_mpeg(dev
)) {
574 if (dev
->mops
->irq_ts_done
!= NULL
)
575 dev
->mops
->irq_ts_done(dev
, status
);
577 saa7134_irq_ts_done(dev
, status
);
580 if (report
& SAA7134_IRQ_REPORT_GPIO16
) {
581 switch (dev
->has_remote
) {
582 case SAA7134_REMOTE_GPIO
:
585 if (dev
->remote
->mask_keydown
& 0x10000) {
586 saa7134_input_irq(dev
);
590 case SAA7134_REMOTE_I2C
:
591 break; /* FIXME: invoke I2C get_key() */
593 default: /* GPIO16 not used by IR remote */
598 if (report
& SAA7134_IRQ_REPORT_GPIO18
) {
599 switch (dev
->has_remote
) {
600 case SAA7134_REMOTE_GPIO
:
603 if ((dev
->remote
->mask_keydown
& 0x40000) ||
604 (dev
->remote
->mask_keyup
& 0x40000)) {
605 saa7134_input_irq(dev
);
609 case SAA7134_REMOTE_I2C
:
610 break; /* FIXME: invoke I2C get_key() */
612 default: /* GPIO18 not used by IR remote */
619 print_irqstatus(dev
,loop
,report
,status
);
620 if (report
& SAA7134_IRQ_REPORT_PE
) {
621 /* disable all parity error */
622 pr_warn("%s/irq: looping -- "
623 "clearing PE (parity error!) enable bit\n",dev
->name
);
624 saa_clearl(SAA7134_IRQ2
,SAA7134_IRQ2_INTE_PE
);
625 } else if (report
& SAA7134_IRQ_REPORT_GPIO16
) {
626 /* disable gpio16 IRQ */
627 pr_warn("%s/irq: looping -- "
628 "clearing GPIO16 enable bit\n",dev
->name
);
629 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO16_P
);
630 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO16_N
);
631 } else if (report
& SAA7134_IRQ_REPORT_GPIO18
) {
632 /* disable gpio18 IRQs */
633 pr_warn("%s/irq: looping -- "
634 "clearing GPIO18 enable bit\n",dev
->name
);
635 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO18_P
);
636 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO18_N
);
638 /* disable all irqs */
639 pr_warn("%s/irq: looping -- "
640 "clearing all enable bits\n",dev
->name
);
641 saa_writel(SAA7134_IRQ1
,0);
642 saa_writel(SAA7134_IRQ2
,0);
647 return IRQ_RETVAL(handled
);
650 /* ------------------------------------------------------------------ */
652 /* early init (no i2c, no irq) */
654 static int saa7134_hw_enable1(struct saa7134_dev
*dev
)
656 /* RAM FIFO config */
657 saa_writel(SAA7134_FIFO_SIZE
, 0x08070503);
658 saa_writel(SAA7134_THRESHOULD
, 0x02020202);
660 /* enable audio + video processing */
661 saa_writel(SAA7134_MAIN_CTRL
,
662 SAA7134_MAIN_CTRL_VPLLE
|
663 SAA7134_MAIN_CTRL_APLLE
|
664 SAA7134_MAIN_CTRL_EXOSC
|
665 SAA7134_MAIN_CTRL_EVFE1
|
666 SAA7134_MAIN_CTRL_EVFE2
|
667 SAA7134_MAIN_CTRL_ESFE
|
668 SAA7134_MAIN_CTRL_EBDAC
);
671 * Initialize OSS _after_ enabling audio clock PLL and audio processing.
672 * OSS initialization writes to registers via the audio DSP; these
673 * writes will fail unless the audio clock has been started. At worst,
674 * audio will not work.
677 /* enable peripheral devices */
678 saa_writeb(SAA7134_SPECIAL_MODE
, 0x01);
680 /* set vertical line numbering start (vbi needs this) */
681 saa_writeb(SAA7134_SOURCE_TIMING2
, 0x20);
686 static int saa7134_hwinit1(struct saa7134_dev
*dev
)
688 core_dbg("hwinit1\n");
690 saa_writel(SAA7134_IRQ1
, 0);
691 saa_writel(SAA7134_IRQ2
, 0);
693 /* Clear any stale IRQ reports */
694 saa_writel(SAA7134_IRQ_REPORT
, saa_readl(SAA7134_IRQ_REPORT
));
696 mutex_init(&dev
->lock
);
697 spin_lock_init(&dev
->slock
);
699 saa7134_track_gpio(dev
,"pre-init");
700 saa7134_video_init1(dev
);
701 saa7134_vbi_init1(dev
);
702 if (card_has_mpeg(dev
))
703 saa7134_ts_init1(dev
);
704 saa7134_input_init1(dev
);
706 saa7134_hw_enable1(dev
);
711 /* late init (with i2c + irq) */
712 static int saa7134_hw_enable2(struct saa7134_dev
*dev
)
715 unsigned int irq2_mask
;
719 SAA7134_IRQ2_INTE_DEC3
|
720 SAA7134_IRQ2_INTE_DEC2
|
721 SAA7134_IRQ2_INTE_DEC1
|
722 SAA7134_IRQ2_INTE_DEC0
|
723 SAA7134_IRQ2_INTE_PE
|
724 SAA7134_IRQ2_INTE_AR
;
726 if (dev
->has_remote
== SAA7134_REMOTE_GPIO
&& dev
->remote
) {
727 if (dev
->remote
->mask_keydown
& 0x10000)
728 irq2_mask
|= SAA7134_IRQ2_INTE_GPIO16_N
;
729 else { /* Allow enabling both IRQ edge triggers */
730 if (dev
->remote
->mask_keydown
& 0x40000)
731 irq2_mask
|= SAA7134_IRQ2_INTE_GPIO18_P
;
732 if (dev
->remote
->mask_keyup
& 0x40000)
733 irq2_mask
|= SAA7134_IRQ2_INTE_GPIO18_N
;
737 if (dev
->has_remote
== SAA7134_REMOTE_I2C
) {
738 request_module("ir-kbd-i2c");
741 saa_writel(SAA7134_IRQ1
, 0);
742 saa_writel(SAA7134_IRQ2
, irq2_mask
);
747 static int saa7134_hwinit2(struct saa7134_dev
*dev
)
750 core_dbg("hwinit2\n");
752 saa7134_video_init2(dev
);
753 saa7134_tvaudio_init2(dev
);
755 saa7134_hw_enable2(dev
);
762 static int saa7134_hwfini(struct saa7134_dev
*dev
)
764 core_dbg("hwfini\n");
766 if (card_has_mpeg(dev
))
767 saa7134_ts_fini(dev
);
768 saa7134_input_fini(dev
);
769 saa7134_vbi_fini(dev
);
770 saa7134_tvaudio_fini(dev
);
771 saa7134_video_fini(dev
);
775 static void must_configure_manually(int has_eeprom
)
780 pr_warn("saa7134: <rant>\n"
781 "saa7134: Congratulations! Your TV card vendor saved a few\n"
782 "saa7134: cents for a eeprom, thus your pci board has no\n"
783 "saa7134: subsystem ID and I can't identify it automatically\n"
785 "saa7134: I feel better now. Ok, here are the good news:\n"
786 "saa7134: You can use the card=<nr> insmod option to specify\n"
787 "saa7134: which board do you have. The list:\n");
789 pr_warn("saa7134: Board is currently unknown. You might try to use the card=<nr>\n"
790 "saa7134: insmod option to specify which board do you have, but this is\n"
791 "saa7134: somewhat risky, as might damage your card. It is better to ask\n"
792 "saa7134: for support at linux-media@vger.kernel.org.\n"
793 "saa7134: The supported cards are:\n");
795 for (i
= 0; i
< saa7134_bcount
; i
++) {
796 pr_warn("saa7134: card=%d -> %-40.40s",
797 i
,saa7134_boards
[i
].name
);
798 for (p
= 0; saa7134_pci_tbl
[p
].driver_data
; p
++) {
799 if (saa7134_pci_tbl
[p
].driver_data
!= i
)
801 pr_cont(" %04x:%04x",
802 saa7134_pci_tbl
[p
].subvendor
,
803 saa7134_pci_tbl
[p
].subdevice
);
809 static void saa7134_unregister_media_device(struct saa7134_dev
*dev
)
812 #ifdef CONFIG_MEDIA_CONTROLLER
815 media_device_unregister(dev
->media_dev
);
816 media_device_cleanup(dev
->media_dev
);
817 kfree(dev
->media_dev
);
818 dev
->media_dev
= NULL
;
822 static void saa7134_media_release(struct saa7134_dev
*dev
)
824 #ifdef CONFIG_MEDIA_CONTROLLER
827 for (i
= 0; i
< SAA7134_INPUT_MAX
+ 1; i
++)
828 media_device_unregister_entity(&dev
->input_ent
[i
]);
832 #if defined(CONFIG_MEDIA_CONTROLLER)
833 static void saa7134_create_entities(struct saa7134_dev
*dev
)
836 struct media_entity
*entity
;
837 struct media_entity
*decoder
= NULL
;
839 /* Check if it is using an external analog TV demod */
840 media_device_for_each_entity(entity
, dev
->media_dev
) {
841 if (entity
->function
== MEDIA_ENT_F_ATV_DECODER
) {
848 * saa713x is not using an external ATV demod.
849 * Register the internal one
852 dev
->demod
.name
= "saa713x";
853 dev
->demod_pad
[DEMOD_PAD_IF_INPUT
].flags
= MEDIA_PAD_FL_SINK
;
854 dev
->demod_pad
[DEMOD_PAD_VID_OUT
].flags
= MEDIA_PAD_FL_SOURCE
;
855 dev
->demod_pad
[DEMOD_PAD_VBI_OUT
].flags
= MEDIA_PAD_FL_SOURCE
;
856 dev
->demod
.function
= MEDIA_ENT_F_ATV_DECODER
;
858 ret
= media_entity_pads_init(&dev
->demod
, DEMOD_NUM_PADS
,
861 pr_err("failed to initialize demod pad!\n");
863 ret
= media_device_register_entity(dev
->media_dev
, &dev
->demod
);
865 pr_err("failed to register demod entity!\n");
867 dev
->decoder
= &dev
->demod
;
869 dev
->decoder
= decoder
;
872 /* Initialize Video, VBI and Radio pads */
873 dev
->video_pad
.flags
= MEDIA_PAD_FL_SINK
;
874 ret
= media_entity_pads_init(&dev
->video_dev
->entity
, 1,
877 pr_err("failed to initialize video media entity!\n");
879 dev
->vbi_pad
.flags
= MEDIA_PAD_FL_SINK
;
880 ret
= media_entity_pads_init(&dev
->vbi_dev
->entity
, 1,
883 pr_err("failed to initialize vbi media entity!\n");
885 /* Create entities for each input connector */
886 for (i
= 0; i
< SAA7134_INPUT_MAX
; i
++) {
887 struct media_entity
*ent
= &dev
->input_ent
[i
];
888 struct saa7134_input
*in
= &card_in(dev
, i
);
890 if (in
->type
== SAA7134_NO_INPUT
)
893 /* This input uses the S-Video connector */
894 if (in
->type
== SAA7134_INPUT_COMPOSITE_OVER_SVIDEO
)
897 ent
->name
= saa7134_input_name
[in
->type
];
898 ent
->flags
= MEDIA_ENT_FL_CONNECTOR
;
899 dev
->input_pad
[i
].flags
= MEDIA_PAD_FL_SOURCE
;
902 case SAA7134_INPUT_COMPOSITE
:
903 case SAA7134_INPUT_COMPOSITE0
:
904 case SAA7134_INPUT_COMPOSITE1
:
905 case SAA7134_INPUT_COMPOSITE2
:
906 case SAA7134_INPUT_COMPOSITE3
:
907 case SAA7134_INPUT_COMPOSITE4
:
908 ent
->function
= MEDIA_ENT_F_CONN_COMPOSITE
;
910 case SAA7134_INPUT_SVIDEO
:
911 case SAA7134_INPUT_SVIDEO0
:
912 case SAA7134_INPUT_SVIDEO1
:
913 ent
->function
= MEDIA_ENT_F_CONN_SVIDEO
;
917 * SAA7134_INPUT_TV and SAA7134_INPUT_TV_MONO.
919 * Please notice that neither SAA7134_INPUT_MUTE or
920 * SAA7134_INPUT_RADIO are defined at
921 * saa7134_board.input.
923 ent
->function
= MEDIA_ENT_F_CONN_RF
;
927 ret
= media_entity_pads_init(ent
, 1, &dev
->input_pad
[i
]);
929 pr_err("failed to initialize input pad[%d]!\n", i
);
931 ret
= media_device_register_entity(dev
->media_dev
, ent
);
933 pr_err("failed to register input entity %d!\n", i
);
936 /* Create input for Radio RF connector */
937 if (card_has_radio(dev
)) {
938 struct saa7134_input
*in
= &saa7134_boards
[dev
->board
].radio
;
939 struct media_entity
*ent
= &dev
->input_ent
[i
];
941 ent
->name
= saa7134_input_name
[in
->type
];
942 ent
->flags
= MEDIA_ENT_FL_CONNECTOR
;
943 dev
->input_pad
[i
].flags
= MEDIA_PAD_FL_SOURCE
;
944 ent
->function
= MEDIA_ENT_F_CONN_RF
;
946 ret
= media_entity_pads_init(ent
, 1, &dev
->input_pad
[i
]);
948 pr_err("failed to initialize input pad[%d]!\n", i
);
950 ret
= media_device_register_entity(dev
->media_dev
, ent
);
952 pr_err("failed to register input entity %d!\n", i
);
957 static struct video_device
*vdev_init(struct saa7134_dev
*dev
,
958 struct video_device
*template,
961 struct video_device
*vfd
;
963 vfd
= video_device_alloc();
967 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
968 vfd
->release
= video_device_release
;
969 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s (%s)",
970 dev
->name
, type
, saa7134_boards
[dev
->board
].name
);
971 video_set_drvdata(vfd
, dev
);
975 static void saa7134_unregister_video(struct saa7134_dev
*dev
)
977 saa7134_media_release(dev
);
979 if (dev
->video_dev
) {
980 if (video_is_registered(dev
->video_dev
))
981 video_unregister_device(dev
->video_dev
);
983 video_device_release(dev
->video_dev
);
984 dev
->video_dev
= NULL
;
987 if (video_is_registered(dev
->vbi_dev
))
988 video_unregister_device(dev
->vbi_dev
);
990 video_device_release(dev
->vbi_dev
);
993 if (dev
->radio_dev
) {
994 if (video_is_registered(dev
->radio_dev
))
995 video_unregister_device(dev
->radio_dev
);
997 video_device_release(dev
->radio_dev
);
998 dev
->radio_dev
= NULL
;
1002 static void mpeg_ops_attach(struct saa7134_mpeg_ops
*ops
,
1003 struct saa7134_dev
*dev
)
1007 if (NULL
!= dev
->mops
)
1009 if (saa7134_boards
[dev
->board
].mpeg
!= ops
->type
)
1011 err
= ops
->init(dev
);
1017 static void mpeg_ops_detach(struct saa7134_mpeg_ops
*ops
,
1018 struct saa7134_dev
*dev
)
1020 if (NULL
== dev
->mops
)
1022 if (dev
->mops
!= ops
)
1024 dev
->mops
->fini(dev
);
1028 static int saa7134_initdev(struct pci_dev
*pci_dev
,
1029 const struct pci_device_id
*pci_id
)
1031 struct saa7134_dev
*dev
;
1032 struct saa7134_mpeg_ops
*mops
;
1035 if (saa7134_devcount
== SAA7134_MAXBOARDS
)
1038 dev
= kzalloc(sizeof(*dev
),GFP_KERNEL
);
1042 dev
->nr
= saa7134_devcount
;
1043 sprintf(dev
->name
, "saa%x[%d]", pci_dev
->device
, dev
->nr
);
1045 #ifdef CONFIG_MEDIA_CONTROLLER
1046 dev
->media_dev
= kzalloc(sizeof(*dev
->media_dev
), GFP_KERNEL
);
1047 if (!dev
->media_dev
) {
1051 media_device_pci_init(dev
->media_dev
, pci_dev
, dev
->name
);
1052 dev
->v4l2_dev
.mdev
= dev
->media_dev
;
1055 err
= v4l2_device_register(&pci_dev
->dev
, &dev
->v4l2_dev
);
1061 if (pci_enable_device(pci_dev
)) {
1067 if (pci_pci_problems
) {
1068 if (pci_pci_problems
& PCIPCI_TRITON
)
1069 pr_info("%s: quirk: PCIPCI_TRITON\n", dev
->name
);
1070 if (pci_pci_problems
& PCIPCI_NATOMA
)
1071 pr_info("%s: quirk: PCIPCI_NATOMA\n", dev
->name
);
1072 if (pci_pci_problems
& PCIPCI_VIAETBF
)
1073 pr_info("%s: quirk: PCIPCI_VIAETBF\n", dev
->name
);
1074 if (pci_pci_problems
& PCIPCI_VSFX
)
1075 pr_info("%s: quirk: PCIPCI_VSFX\n", dev
->name
);
1076 #ifdef PCIPCI_ALIMAGIK
1077 if (pci_pci_problems
& PCIPCI_ALIMAGIK
) {
1078 pr_info("%s: quirk: PCIPCI_ALIMAGIK -- latency fixup\n",
1083 if (pci_pci_problems
& (PCIPCI_FAIL
|PCIAGP_FAIL
)) {
1084 pr_info("%s: quirk: this driver and your "
1085 "chipset may not work together"
1086 " in overlay mode.\n",dev
->name
);
1087 if (!saa7134_no_overlay
) {
1088 pr_info("%s: quirk: overlay "
1089 "mode will be disabled.\n",
1091 saa7134_no_overlay
= 1;
1093 pr_info("%s: quirk: overlay "
1094 "mode will be forced. Use this"
1095 " option at your own risk.\n",
1100 if (UNSET
!= latency
) {
1101 pr_info("%s: setting pci latency timer to %d\n",
1103 pci_write_config_byte(pci_dev
, PCI_LATENCY_TIMER
, latency
);
1106 /* print pci info */
1107 dev
->pci_rev
= pci_dev
->revision
;
1108 pci_read_config_byte(pci_dev
, PCI_LATENCY_TIMER
, &dev
->pci_lat
);
1109 pr_info("%s: found at %s, rev: %d, irq: %d, "
1110 "latency: %d, mmio: 0x%llx\n", dev
->name
,
1111 pci_name(pci_dev
), dev
->pci_rev
, pci_dev
->irq
,
1112 dev
->pci_lat
,(unsigned long long)pci_resource_start(pci_dev
,0));
1113 pci_set_master(pci_dev
);
1114 err
= pci_set_dma_mask(pci_dev
, DMA_BIT_MASK(32));
1116 pr_warn("%s: Oops: no 32bit PCI DMA ???\n", dev
->name
);
1121 dev
->board
= pci_id
->driver_data
;
1122 if ((unsigned)card
[dev
->nr
] < saa7134_bcount
)
1123 dev
->board
= card
[dev
->nr
];
1124 if (SAA7134_BOARD_UNKNOWN
== dev
->board
)
1125 must_configure_manually(0);
1126 else if (SAA7134_BOARD_NOAUTO
== dev
->board
) {
1127 must_configure_manually(1);
1128 dev
->board
= SAA7134_BOARD_UNKNOWN
;
1130 dev
->autodetected
= card
[dev
->nr
] != dev
->board
;
1131 dev
->tuner_type
= saa7134_boards
[dev
->board
].tuner_type
;
1132 dev
->tuner_addr
= saa7134_boards
[dev
->board
].tuner_addr
;
1133 dev
->radio_type
= saa7134_boards
[dev
->board
].radio_type
;
1134 dev
->radio_addr
= saa7134_boards
[dev
->board
].radio_addr
;
1135 dev
->tda9887_conf
= saa7134_boards
[dev
->board
].tda9887_conf
;
1136 if (UNSET
!= tuner
[dev
->nr
])
1137 dev
->tuner_type
= tuner
[dev
->nr
];
1138 pr_info("%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
1139 dev
->name
,pci_dev
->subsystem_vendor
,
1140 pci_dev
->subsystem_device
,saa7134_boards
[dev
->board
].name
,
1141 dev
->board
, dev
->autodetected
?
1142 "autodetected" : "insmod option");
1145 if (!request_mem_region(pci_resource_start(pci_dev
,0),
1146 pci_resource_len(pci_dev
,0),
1149 pr_err("%s: can't get MMIO memory @ 0x%llx\n",
1150 dev
->name
,(unsigned long long)pci_resource_start(pci_dev
,0));
1153 dev
->lmmio
= ioremap(pci_resource_start(pci_dev
, 0),
1154 pci_resource_len(pci_dev
, 0));
1155 dev
->bmmio
= (__u8 __iomem
*)dev
->lmmio
;
1156 if (NULL
== dev
->lmmio
) {
1158 pr_err("%s: can't ioremap() MMIO memory\n",
1163 /* initialize hardware #1 */
1164 saa7134_board_init1(dev
);
1165 saa7134_hwinit1(dev
);
1167 dev
->alloc_ctx
= vb2_dma_sg_init_ctx(&pci_dev
->dev
);
1168 if (IS_ERR(dev
->alloc_ctx
)) {
1169 err
= PTR_ERR(dev
->alloc_ctx
);
1173 err
= request_irq(pci_dev
->irq
, saa7134_irq
,
1174 IRQF_SHARED
, dev
->name
, dev
);
1176 pr_err("%s: can't get IRQ %d\n",
1177 dev
->name
,pci_dev
->irq
);
1181 /* wait a bit, register i2c bus */
1183 saa7134_i2c_register(dev
);
1184 saa7134_board_init2(dev
);
1186 saa7134_hwinit2(dev
);
1188 /* load i2c helpers */
1189 if (card_is_empress(dev
)) {
1191 v4l2_i2c_new_subdev(&dev
->v4l2_dev
, &dev
->i2c_adap
,
1193 saa7134_boards
[dev
->board
].empress_addr
, NULL
);
1195 if (dev
->empress_sd
)
1196 dev
->empress_sd
->grp_id
= GRP_EMPRESS
;
1199 if (saa7134_boards
[dev
->board
].rds_addr
) {
1200 struct v4l2_subdev
*sd
;
1202 sd
= v4l2_i2c_new_subdev(&dev
->v4l2_dev
,
1203 &dev
->i2c_adap
, "saa6588",
1204 0, I2C_ADDRS(saa7134_boards
[dev
->board
].rds_addr
));
1206 pr_info("%s: found RDS decoder\n", dev
->name
);
1211 mutex_lock(&saa7134_devlist_lock
);
1212 list_for_each_entry(mops
, &mops_list
, next
)
1213 mpeg_ops_attach(mops
, dev
);
1214 list_add_tail(&dev
->devlist
, &saa7134_devlist
);
1215 mutex_unlock(&saa7134_devlist_lock
);
1217 /* check for signal */
1218 saa7134_irq_video_signalchange(dev
);
1220 if (TUNER_ABSENT
!= dev
->tuner_type
)
1221 saa_call_all(dev
, core
, s_power
, 0);
1223 /* register v4l devices */
1224 if (saa7134_no_overlay
> 0)
1225 pr_info("%s: Overlay support disabled.\n", dev
->name
);
1227 dev
->video_dev
= vdev_init(dev
,&saa7134_video_template
,"video");
1228 dev
->video_dev
->ctrl_handler
= &dev
->ctrl_handler
;
1229 dev
->video_dev
->lock
= &dev
->lock
;
1230 dev
->video_dev
->queue
= &dev
->video_vbq
;
1231 err
= video_register_device(dev
->video_dev
,VFL_TYPE_GRABBER
,
1234 pr_info("%s: can't register video device\n",
1238 pr_info("%s: registered device %s [v4l2]\n",
1239 dev
->name
, video_device_node_name(dev
->video_dev
));
1241 dev
->vbi_dev
= vdev_init(dev
, &saa7134_video_template
, "vbi");
1242 dev
->vbi_dev
->ctrl_handler
= &dev
->ctrl_handler
;
1243 dev
->vbi_dev
->lock
= &dev
->lock
;
1244 dev
->vbi_dev
->queue
= &dev
->vbi_vbq
;
1246 err
= video_register_device(dev
->vbi_dev
,VFL_TYPE_VBI
,
1250 pr_info("%s: registered device %s\n",
1251 dev
->name
, video_device_node_name(dev
->vbi_dev
));
1253 if (card_has_radio(dev
)) {
1254 dev
->radio_dev
= vdev_init(dev
,&saa7134_radio_template
,"radio");
1255 dev
->radio_dev
->ctrl_handler
= &dev
->radio_ctrl_handler
;
1256 dev
->radio_dev
->lock
= &dev
->lock
;
1257 err
= video_register_device(dev
->radio_dev
,VFL_TYPE_RADIO
,
1261 pr_info("%s: registered device %s\n",
1262 dev
->name
, video_device_node_name(dev
->radio_dev
));
1265 #ifdef CONFIG_MEDIA_CONTROLLER
1266 saa7134_create_entities(dev
);
1268 err
= v4l2_mc_create_media_graph(dev
->media_dev
);
1270 pr_err("failed to create media graph\n");
1274 /* everything worked */
1277 if (saa7134_dmasound_init
&& !dev
->dmasound
.priv_data
)
1278 saa7134_dmasound_init(dev
);
1280 request_submodules(dev
);
1283 * Do it at the end, to reduce dynamic configuration changes during
1284 * the device init. Yet, as request_modules() can be async, the
1285 * topology will likely change after load the saa7134 subdrivers.
1287 #ifdef CONFIG_MEDIA_CONTROLLER
1288 err
= media_device_register(dev
->media_dev
);
1296 saa7134_unregister_video(dev
);
1297 saa7134_i2c_unregister(dev
);
1298 free_irq(pci_dev
->irq
, dev
);
1300 vb2_dma_sg_cleanup_ctx(dev
->alloc_ctx
);
1302 saa7134_hwfini(dev
);
1303 iounmap(dev
->lmmio
);
1305 release_mem_region(pci_resource_start(pci_dev
,0),
1306 pci_resource_len(pci_dev
,0));
1308 v4l2_device_unregister(&dev
->v4l2_dev
);
1310 #ifdef CONFIG_MEDIA_CONTROLLER
1311 kfree(dev
->media_dev
);
1317 static void saa7134_finidev(struct pci_dev
*pci_dev
)
1319 struct v4l2_device
*v4l2_dev
= pci_get_drvdata(pci_dev
);
1320 struct saa7134_dev
*dev
= container_of(v4l2_dev
, struct saa7134_dev
, v4l2_dev
);
1321 struct saa7134_mpeg_ops
*mops
;
1323 flush_request_submodules(dev
);
1325 /* Release DMA sound modules if present */
1326 if (saa7134_dmasound_exit
&& dev
->dmasound
.priv_data
) {
1327 saa7134_dmasound_exit(dev
);
1332 u32 report
= saa_readl(SAA7134_IRQ_REPORT
);
1333 u32 status
= saa_readl(SAA7134_IRQ_STATUS
);
1334 print_irqstatus(dev
,42,report
,status
);
1337 /* disable peripheral devices */
1338 saa_writeb(SAA7134_SPECIAL_MODE
,0);
1340 /* shutdown hardware */
1341 saa_writel(SAA7134_IRQ1
,0);
1342 saa_writel(SAA7134_IRQ2
,0);
1343 saa_writel(SAA7134_MAIN_CTRL
,0);
1345 /* shutdown subsystems */
1346 saa7134_hwfini(dev
);
1349 mutex_lock(&saa7134_devlist_lock
);
1350 list_del(&dev
->devlist
);
1351 list_for_each_entry(mops
, &mops_list
, next
)
1352 mpeg_ops_detach(mops
, dev
);
1353 mutex_unlock(&saa7134_devlist_lock
);
1356 saa7134_i2c_unregister(dev
);
1357 saa7134_unregister_video(dev
);
1360 /* the DMA sound modules should be unloaded before reaching
1361 this, but just in case they are still present... */
1362 if (dev
->dmasound
.priv_data
!= NULL
) {
1363 free_irq(pci_dev
->irq
, &dev
->dmasound
);
1364 dev
->dmasound
.priv_data
= NULL
;
1368 /* release resources */
1369 free_irq(pci_dev
->irq
, dev
);
1370 vb2_dma_sg_cleanup_ctx(dev
->alloc_ctx
);
1371 iounmap(dev
->lmmio
);
1372 release_mem_region(pci_resource_start(pci_dev
,0),
1373 pci_resource_len(pci_dev
,0));
1375 v4l2_device_unregister(&dev
->v4l2_dev
);
1377 saa7134_unregister_media_device(dev
);
1385 /* resends a current buffer in queue after resume */
1386 static int saa7134_buffer_requeue(struct saa7134_dev
*dev
,
1387 struct saa7134_dmaqueue
*q
)
1389 struct saa7134_buf
*buf
, *next
;
1391 assert_spin_locked(&dev
->slock
);
1395 core_dbg("buffer_requeue\n");
1400 core_dbg("buffer_requeue : resending active buffer\n");
1402 if (!list_empty(&q
->queue
))
1403 next
= list_entry(q
->queue
.next
, struct saa7134_buf
,
1405 buf
->activate(dev
, buf
, next
);
1410 static int saa7134_suspend(struct pci_dev
*pci_dev
, pm_message_t state
)
1412 struct v4l2_device
*v4l2_dev
= pci_get_drvdata(pci_dev
);
1413 struct saa7134_dev
*dev
= container_of(v4l2_dev
, struct saa7134_dev
, v4l2_dev
);
1415 /* disable overlay - apps should enable it explicitly on resume*/
1418 /* Disable interrupts, DMA, and rest of the chip*/
1419 saa_writel(SAA7134_IRQ1
, 0);
1420 saa_writel(SAA7134_IRQ2
, 0);
1421 saa_writel(SAA7134_MAIN_CTRL
, 0);
1424 synchronize_irq(pci_dev
->irq
);
1426 /* ACK interrupts once more, just in case,
1427 since the IRQ handler won't ack them anymore*/
1429 saa_writel(SAA7134_IRQ_REPORT
, saa_readl(SAA7134_IRQ_REPORT
));
1431 /* Disable timeout timers - if we have active buffers, we will
1432 fill them on resume*/
1434 del_timer(&dev
->video_q
.timeout
);
1435 del_timer(&dev
->vbi_q
.timeout
);
1436 del_timer(&dev
->ts_q
.timeout
);
1439 saa7134_ir_stop(dev
);
1441 pci_save_state(pci_dev
);
1442 pci_set_power_state(pci_dev
, pci_choose_state(pci_dev
, state
));
1447 static int saa7134_resume(struct pci_dev
*pci_dev
)
1449 struct v4l2_device
*v4l2_dev
= pci_get_drvdata(pci_dev
);
1450 struct saa7134_dev
*dev
= container_of(v4l2_dev
, struct saa7134_dev
, v4l2_dev
);
1451 unsigned long flags
;
1453 pci_set_power_state(pci_dev
, PCI_D0
);
1454 pci_restore_state(pci_dev
);
1456 /* Do things that are done in saa7134_initdev ,
1457 except of initializing memory structures.*/
1459 saa7134_board_init1(dev
);
1461 /* saa7134_hwinit1 */
1462 if (saa7134_boards
[dev
->board
].video_out
)
1463 saa7134_videoport_init(dev
);
1464 if (card_has_mpeg(dev
))
1465 saa7134_ts_init_hw(dev
);
1467 saa7134_ir_start(dev
);
1468 saa7134_hw_enable1(dev
);
1472 saa7134_board_init2(dev
);
1475 saa7134_set_tvnorm_hw(dev
);
1476 saa7134_tvaudio_setmute(dev
);
1477 saa7134_tvaudio_setvolume(dev
, dev
->ctl_volume
);
1478 saa7134_tvaudio_init(dev
);
1479 saa7134_enable_i2s(dev
);
1480 saa7134_hw_enable2(dev
);
1482 saa7134_irq_video_signalchange(dev
);
1484 /*resume unfinished buffer(s)*/
1485 spin_lock_irqsave(&dev
->slock
, flags
);
1486 saa7134_buffer_requeue(dev
, &dev
->video_q
);
1487 saa7134_buffer_requeue(dev
, &dev
->vbi_q
);
1488 saa7134_buffer_requeue(dev
, &dev
->ts_q
);
1490 /* FIXME: Disable DMA audio sound - temporary till proper support
1493 dev
->dmasound
.dma_running
= 0;
1498 saa7134_set_dmabits(dev
);
1499 spin_unlock_irqrestore(&dev
->slock
, flags
);
1505 /* ----------------------------------------------------------- */
1507 int saa7134_ts_register(struct saa7134_mpeg_ops
*ops
)
1509 struct saa7134_dev
*dev
;
1511 mutex_lock(&saa7134_devlist_lock
);
1512 list_for_each_entry(dev
, &saa7134_devlist
, devlist
)
1513 mpeg_ops_attach(ops
, dev
);
1514 list_add_tail(&ops
->next
,&mops_list
);
1515 mutex_unlock(&saa7134_devlist_lock
);
1519 void saa7134_ts_unregister(struct saa7134_mpeg_ops
*ops
)
1521 struct saa7134_dev
*dev
;
1523 mutex_lock(&saa7134_devlist_lock
);
1524 list_del(&ops
->next
);
1525 list_for_each_entry(dev
, &saa7134_devlist
, devlist
)
1526 mpeg_ops_detach(ops
, dev
);
1527 mutex_unlock(&saa7134_devlist_lock
);
1530 EXPORT_SYMBOL(saa7134_ts_register
);
1531 EXPORT_SYMBOL(saa7134_ts_unregister
);
1533 /* ----------------------------------------------------------- */
1535 static struct pci_driver saa7134_pci_driver
= {
1537 .id_table
= saa7134_pci_tbl
,
1538 .probe
= saa7134_initdev
,
1539 .remove
= saa7134_finidev
,
1541 .suspend
= saa7134_suspend
,
1542 .resume
= saa7134_resume
1546 static int __init
saa7134_init(void)
1548 INIT_LIST_HEAD(&saa7134_devlist
);
1549 pr_info("saa7130/34: v4l2 driver version %s loaded\n",
1551 return pci_register_driver(&saa7134_pci_driver
);
1554 static void __exit
saa7134_fini(void)
1556 pci_unregister_driver(&saa7134_pci_driver
);
1559 module_init(saa7134_init
);
1560 module_exit(saa7134_fini
);
1562 /* ----------------------------------------------------------- */
1564 EXPORT_SYMBOL(saa7134_set_gpio
);
1565 EXPORT_SYMBOL(saa7134_boards
);
1567 /* ----------------- for the DMA sound modules --------------- */
1569 EXPORT_SYMBOL(saa7134_dmasound_init
);
1570 EXPORT_SYMBOL(saa7134_dmasound_exit
);
1571 EXPORT_SYMBOL(saa7134_pgtable_free
);
1572 EXPORT_SYMBOL(saa7134_pgtable_build
);
1573 EXPORT_SYMBOL(saa7134_pgtable_alloc
);
1574 EXPORT_SYMBOL(saa7134_set_dmabits
);