1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * device driver for philips saa7134 based TV cards
7 * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
11 #include "saa7134-reg.h"
13 #include <linux/init.h>
14 #include <linux/list.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/kmod.h>
19 #include <linux/sound.h>
20 #include <linux/interrupt.h>
21 #include <linux/delay.h>
22 #include <linux/mutex.h>
23 #include <linux/dma-mapping.h>
26 MODULE_DESCRIPTION("v4l2 driver module for saa7130/34 based TV cards");
27 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
28 MODULE_LICENSE("GPL");
29 MODULE_VERSION(SAA7134_VERSION
);
32 /* ------------------------------------------------------------------ */
34 static unsigned int irq_debug
;
35 module_param(irq_debug
, int, 0644);
36 MODULE_PARM_DESC(irq_debug
,"enable debug messages [IRQ handler]");
38 static unsigned int core_debug
;
39 module_param(core_debug
, int, 0644);
40 MODULE_PARM_DESC(core_debug
,"enable debug messages [core]");
42 static unsigned int gpio_tracking
;
43 module_param(gpio_tracking
, int, 0644);
44 MODULE_PARM_DESC(gpio_tracking
,"enable debug messages [gpio]");
46 static unsigned int alsa
= 1;
47 module_param(alsa
, int, 0644);
48 MODULE_PARM_DESC(alsa
,"enable/disable ALSA DMA sound [dmasound]");
50 static unsigned int latency
= UNSET
;
51 module_param(latency
, int, 0444);
52 MODULE_PARM_DESC(latency
,"pci latency timer");
55 module_param(saa7134_userptr
, bool, 0644);
56 MODULE_PARM_DESC(saa7134_userptr
, "enable page-aligned userptr support");
58 static unsigned int video_nr
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
59 static unsigned int vbi_nr
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
60 static unsigned int radio_nr
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
61 static unsigned int tuner
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
62 static unsigned int card
[] = {[0 ... (SAA7134_MAXBOARDS
- 1)] = UNSET
};
65 module_param_array(video_nr
, int, NULL
, 0444);
66 module_param_array(vbi_nr
, int, NULL
, 0444);
67 module_param_array(radio_nr
, int, NULL
, 0444);
68 module_param_array(tuner
, int, NULL
, 0444);
69 module_param_array(card
, int, NULL
, 0444);
71 MODULE_PARM_DESC(video_nr
, "video device number");
72 MODULE_PARM_DESC(vbi_nr
, "vbi device number");
73 MODULE_PARM_DESC(radio_nr
, "radio device number");
74 MODULE_PARM_DESC(tuner
, "tuner type");
75 MODULE_PARM_DESC(card
, "card type");
77 DEFINE_MUTEX(saa7134_devlist_lock
);
78 EXPORT_SYMBOL(saa7134_devlist_lock
);
79 LIST_HEAD(saa7134_devlist
);
80 EXPORT_SYMBOL(saa7134_devlist
);
81 static LIST_HEAD(mops_list
);
82 static unsigned int saa7134_devcount
;
84 int (*saa7134_dmasound_init
)(struct saa7134_dev
*dev
);
85 int (*saa7134_dmasound_exit
)(struct saa7134_dev
*dev
);
87 #define core_dbg(fmt, arg...) do { \
89 printk(KERN_DEBUG pr_fmt("core: " fmt), ## arg); \
92 #define irq_dbg(level, fmt, arg...) do {\
93 if (irq_debug > level) \
94 printk(KERN_DEBUG pr_fmt("irq: " fmt), ## arg); \
97 void saa7134_track_gpio(struct saa7134_dev
*dev
, const char *msg
)
99 unsigned long mode
,status
;
103 /* rising SAA7134_GPIO_GPRESCAN reads the status */
104 saa_andorb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
,0);
105 saa_andorb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
,SAA7134_GPIO_GPRESCAN
);
106 mode
= saa_readl(SAA7134_GPIO_GPMODE0
>> 2) & 0xfffffff;
107 status
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2) & 0xfffffff;
108 core_dbg("%s: gpio: mode=0x%07lx in=0x%07lx out=0x%07lx [%s]\n",
109 dev
->name
, mode
, (~mode
) & status
, mode
& status
, msg
);
112 void saa7134_set_gpio(struct saa7134_dev
*dev
, int bit_no
, int value
)
118 case 0: /* static value */
120 core_dbg("setting GPIO%d to static %d\n", bit_no
, value
);
121 /* turn sync mode off if necessary */
122 if (index
& 0x00c00000)
123 saa_andorb(SAA7134_VIDEO_PORT_CTRL6
, 0x0f, 0x00);
128 saa_andorl(SAA7134_GPIO_GPMODE0
>> 2, index
, index
);
129 saa_andorl(SAA7134_GPIO_GPSTATUS0
>> 2, index
, bitval
);
131 case 3: /* tristate */
132 core_dbg("setting GPIO%d to tristate\n", bit_no
);
133 saa_andorl(SAA7134_GPIO_GPMODE0
>> 2, index
, 0);
138 /* ------------------------------------------------------------------ */
141 /* ----------------------------------------------------------- */
142 /* delayed request_module */
144 #if defined(CONFIG_MODULES) && defined(MODULE)
146 static void request_module_async(struct work_struct
*work
){
147 struct saa7134_dev
* dev
= container_of(work
, struct saa7134_dev
, request_module_wk
);
148 if (card_is_empress(dev
))
149 request_module("saa7134-empress");
150 if (card_is_dvb(dev
))
151 request_module("saa7134-dvb");
152 if (card_is_go7007(dev
))
153 request_module("saa7134-go7007");
155 if (dev
->pci
->device
!= PCI_DEVICE_ID_PHILIPS_SAA7130
)
156 request_module("saa7134-alsa");
160 static void request_submodules(struct saa7134_dev
*dev
)
162 INIT_WORK(&dev
->request_module_wk
, request_module_async
);
163 schedule_work(&dev
->request_module_wk
);
166 static void flush_request_submodules(struct saa7134_dev
*dev
)
168 flush_work(&dev
->request_module_wk
);
172 #define request_submodules(dev)
173 #define flush_request_submodules(dev)
174 #endif /* CONFIG_MODULES */
176 /* ------------------------------------------------------------------ */
178 /* nr of (saa7134-)pages for the given buffer size */
179 static int saa7134_buffer_pages(int size
)
181 size
= PAGE_ALIGN(size
);
182 size
+= PAGE_SIZE
; /* for non-page-aligned buffers */
187 /* calc max # of buffers from size (must not exceed the 4MB virtual
188 * address space per DMA channel) */
189 int saa7134_buffer_count(unsigned int size
, unsigned int count
)
191 unsigned int maxcount
;
193 maxcount
= 1024 / saa7134_buffer_pages(size
);
194 if (count
> maxcount
)
199 int saa7134_buffer_startpage(struct saa7134_buf
*buf
)
201 return saa7134_buffer_pages(vb2_plane_size(&buf
->vb2
.vb2_buf
, 0))
202 * buf
->vb2
.vb2_buf
.index
;
205 unsigned long saa7134_buffer_base(struct saa7134_buf
*buf
)
208 struct sg_table
*dma
= vb2_dma_sg_plane_desc(&buf
->vb2
.vb2_buf
, 0);
210 base
= saa7134_buffer_startpage(buf
) * 4096;
211 base
+= dma
->sgl
[0].offset
;
215 /* ------------------------------------------------------------------ */
217 int saa7134_pgtable_alloc(struct pci_dev
*pci
, struct saa7134_pgtable
*pt
)
220 dma_addr_t dma_addr
= 0;
222 cpu
= dma_alloc_coherent(&pci
->dev
, SAA7134_PGTABLE_SIZE
, &dma_addr
,
226 pt
->size
= SAA7134_PGTABLE_SIZE
;
232 int saa7134_pgtable_build(struct pci_dev
*pci
, struct saa7134_pgtable
*pt
,
233 struct scatterlist
*list
, unsigned int length
,
234 unsigned int startpage
)
239 BUG_ON(NULL
== pt
|| NULL
== pt
->cpu
);
241 ptr
= pt
->cpu
+ startpage
;
242 for (i
= 0; i
< length
; i
++, list
= sg_next(list
)) {
243 for (p
= 0; p
* 4096 < sg_dma_len(list
); p
++, ptr
++)
244 *ptr
= cpu_to_le32(sg_dma_address(list
) +
245 list
->offset
+ p
* 4096);
250 void saa7134_pgtable_free(struct pci_dev
*pci
, struct saa7134_pgtable
*pt
)
254 dma_free_coherent(&pci
->dev
, pt
->size
, pt
->cpu
, pt
->dma
);
258 /* ------------------------------------------------------------------ */
260 int saa7134_buffer_queue(struct saa7134_dev
*dev
,
261 struct saa7134_dmaqueue
*q
,
262 struct saa7134_buf
*buf
)
264 struct saa7134_buf
*next
= NULL
;
267 spin_lock_irqsave(&dev
->slock
, flags
);
268 core_dbg("buffer_queue %p\n", buf
);
269 if (NULL
== q
->curr
) {
272 buf
->activate(dev
, buf
, NULL
);
273 } else if (list_empty(&q
->queue
)) {
274 list_add_tail(&buf
->entry
, &q
->queue
);
276 next
= list_entry(q
->queue
.next
, struct saa7134_buf
,
279 buf
->activate(dev
, buf
, next
);
282 list_add_tail(&buf
->entry
, &q
->queue
);
284 spin_unlock_irqrestore(&dev
->slock
, flags
);
288 void saa7134_buffer_finish(struct saa7134_dev
*dev
,
289 struct saa7134_dmaqueue
*q
,
292 core_dbg("buffer_finish %p\n", q
->curr
);
294 /* finish current buffer */
295 q
->curr
->vb2
.vb2_buf
.timestamp
= ktime_get_ns();
296 q
->curr
->vb2
.sequence
= q
->seq_nr
++;
297 vb2_buffer_done(&q
->curr
->vb2
.vb2_buf
, state
);
301 void saa7134_buffer_next(struct saa7134_dev
*dev
,
302 struct saa7134_dmaqueue
*q
)
304 struct saa7134_buf
*buf
,*next
= NULL
;
306 assert_spin_locked(&dev
->slock
);
307 BUG_ON(NULL
!= q
->curr
);
309 if (!list_empty(&q
->queue
)) {
310 /* activate next one from queue */
311 buf
= list_entry(q
->queue
.next
, struct saa7134_buf
, entry
);
312 core_dbg("buffer_next %p [prev=%p/next=%p]\n",
313 buf
, q
->queue
.prev
, q
->queue
.next
);
314 list_del(&buf
->entry
);
315 if (!list_empty(&q
->queue
))
316 next
= list_entry(q
->queue
.next
, struct saa7134_buf
, entry
);
318 buf
->activate(dev
, buf
, next
);
319 core_dbg("buffer_next #2 prev=%p/next=%p\n",
320 q
->queue
.prev
, q
->queue
.next
);
322 /* nothing to do -- just stop DMA */
323 core_dbg("buffer_next %p\n", NULL
);
324 saa7134_set_dmabits(dev
);
325 del_timer(&q
->timeout
);
329 void saa7134_buffer_timeout(struct timer_list
*t
)
331 struct saa7134_dmaqueue
*q
= from_timer(q
, t
, timeout
);
332 struct saa7134_dev
*dev
= q
->dev
;
335 spin_lock_irqsave(&dev
->slock
, flags
);
337 /* try to reset the hardware (SWRST) */
338 saa_writeb(SAA7134_REGION_ENABLE
, 0x00);
339 saa_writeb(SAA7134_REGION_ENABLE
, 0x80);
340 saa_writeb(SAA7134_REGION_ENABLE
, 0x00);
342 /* flag current buffer as failed,
343 try to start over with the next one. */
345 core_dbg("timeout on %p\n", q
->curr
);
346 saa7134_buffer_finish(dev
, q
, VB2_BUF_STATE_ERROR
);
348 saa7134_buffer_next(dev
, q
);
349 spin_unlock_irqrestore(&dev
->slock
, flags
);
352 void saa7134_stop_streaming(struct saa7134_dev
*dev
, struct saa7134_dmaqueue
*q
)
355 struct list_head
*pos
, *n
;
356 struct saa7134_buf
*tmp
;
358 spin_lock_irqsave(&dev
->slock
, flags
);
359 list_for_each_safe(pos
, n
, &q
->queue
) {
360 tmp
= list_entry(pos
, struct saa7134_buf
, entry
);
361 vb2_buffer_done(&tmp
->vb2
.vb2_buf
,
362 VB2_BUF_STATE_ERROR
);
366 spin_unlock_irqrestore(&dev
->slock
, flags
);
367 saa7134_buffer_timeout(&q
->timeout
); /* also calls del_timer(&q->timeout) */
369 EXPORT_SYMBOL_GPL(saa7134_stop_streaming
);
371 /* ------------------------------------------------------------------ */
373 int saa7134_set_dmabits(struct saa7134_dev
*dev
)
375 u32 split
, task
=0, ctrl
=0, irq
=0;
376 enum v4l2_field cap
= V4L2_FIELD_ANY
;
377 enum v4l2_field ov
= V4L2_FIELD_ANY
;
379 assert_spin_locked(&dev
->slock
);
384 /* video capture -- dma 0 + video task A */
385 if (dev
->video_q
.curr
) {
387 ctrl
|= SAA7134_MAIN_CTRL_TE0
;
388 irq
|= SAA7134_IRQ1_INTE_RA0_1
|
389 SAA7134_IRQ1_INTE_RA0_0
;
393 /* video capture -- dma 1+2 (planar modes) */
394 if (dev
->video_q
.curr
&& dev
->fmt
->planar
) {
395 ctrl
|= SAA7134_MAIN_CTRL_TE4
|
396 SAA7134_MAIN_CTRL_TE5
;
399 /* vbi capture -- dma 0 + vbi task A+B */
400 if (dev
->vbi_q
.curr
) {
402 ctrl
|= SAA7134_MAIN_CTRL_TE2
|
403 SAA7134_MAIN_CTRL_TE3
;
404 irq
|= SAA7134_IRQ1_INTE_RA0_7
|
405 SAA7134_IRQ1_INTE_RA0_6
|
406 SAA7134_IRQ1_INTE_RA0_5
|
407 SAA7134_IRQ1_INTE_RA0_4
;
410 /* audio capture -- dma 3 */
411 if (dev
->dmasound
.dma_running
) {
412 ctrl
|= SAA7134_MAIN_CTRL_TE6
;
413 irq
|= SAA7134_IRQ1_INTE_RA3_1
|
414 SAA7134_IRQ1_INTE_RA3_0
;
417 /* TS capture -- dma 5 */
418 if (dev
->ts_q
.curr
) {
419 ctrl
|= SAA7134_MAIN_CTRL_TE5
;
420 irq
|= SAA7134_IRQ1_INTE_RA2_1
|
421 SAA7134_IRQ1_INTE_RA2_0
;
424 /* set task conditions + field handling */
425 if (V4L2_FIELD_HAS_BOTH(cap
) || V4L2_FIELD_HAS_BOTH(ov
) || cap
== ov
) {
426 /* default config -- use full frames */
427 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A
), 0x0d);
428 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B
), 0x0d);
429 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A
), 0x02);
430 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B
), 0x02);
433 /* split fields between tasks */
434 if (V4L2_FIELD_TOP
== cap
) {
435 /* odd A, even B, repeat */
436 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A
), 0x0d);
437 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B
), 0x0e);
439 /* odd B, even A, repeat */
440 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_A
), 0x0e);
441 saa_writeb(SAA7134_TASK_CONDITIONS(TASK_B
), 0x0d);
443 saa_writeb(SAA7134_FIELD_HANDLING(TASK_A
), 0x01);
444 saa_writeb(SAA7134_FIELD_HANDLING(TASK_B
), 0x01);
449 saa_writeb(SAA7134_REGION_ENABLE
, task
);
450 saa_writel(SAA7134_IRQ1
, irq
);
451 saa_andorl(SAA7134_MAIN_CTRL
,
452 SAA7134_MAIN_CTRL_TE0
|
453 SAA7134_MAIN_CTRL_TE1
|
454 SAA7134_MAIN_CTRL_TE2
|
455 SAA7134_MAIN_CTRL_TE3
|
456 SAA7134_MAIN_CTRL_TE4
|
457 SAA7134_MAIN_CTRL_TE5
|
458 SAA7134_MAIN_CTRL_TE6
,
460 core_dbg("dmabits: task=0x%02x ctrl=0x%02x irq=0x%x split=%s\n",
461 task
, ctrl
, irq
, split
? "no" : "yes");
466 /* ------------------------------------------------------------------ */
467 /* IRQ handler + helpers */
469 static char *irqbits
[] = {
470 "DONE_RA0", "DONE_RA1", "DONE_RA2", "DONE_RA3",
471 "AR", "PE", "PWR_ON", "RDCAP", "INTL", "FIDT", "MMC",
472 "TRIG_ERR", "CONF_ERR", "LOAD_ERR",
473 "GPIO16", "GPIO18", "GPIO22", "GPIO23"
475 #define IRQBITS ARRAY_SIZE(irqbits)
477 static void print_irqstatus(struct saa7134_dev
*dev
, int loop
,
478 unsigned long report
, unsigned long status
)
482 irq_dbg(1, "[%d,%ld]: r=0x%lx s=0x%02lx",
483 loop
, jiffies
, report
, status
);
484 for (i
= 0; i
< IRQBITS
; i
++) {
485 if (!(report
& (1 << i
)))
487 pr_cont(" %s", irqbits
[i
]);
489 if (report
& SAA7134_IRQ_REPORT_DONE_RA0
) {
490 pr_cont(" | RA0=%s,%s,%s,%ld",
491 (status
& 0x40) ? "vbi" : "video",
492 (status
& 0x20) ? "b" : "a",
493 (status
& 0x10) ? "odd" : "even",
499 static irqreturn_t
saa7134_irq(int irq
, void *dev_id
)
501 struct saa7134_dev
*dev
= (struct saa7134_dev
*) dev_id
;
502 unsigned long report
,status
;
503 int loop
, handled
= 0;
508 for (loop
= 0; loop
< 10; loop
++) {
509 report
= saa_readl(SAA7134_IRQ_REPORT
);
510 status
= saa_readl(SAA7134_IRQ_STATUS
);
512 /* If dmasound support is active and we get a sound report,
513 * mask out the report and let the saa7134-alsa module deal
515 if ((report
& SAA7134_IRQ_REPORT_DONE_RA3
) &&
516 (dev
->dmasound
.priv_data
!= NULL
) )
518 irq_dbg(2, "preserving DMA sound interrupt\n");
519 report
&= ~SAA7134_IRQ_REPORT_DONE_RA3
;
523 irq_dbg(2, "no (more) work\n");
528 saa_writel(SAA7134_IRQ_REPORT
,report
);
530 print_irqstatus(dev
,loop
,report
,status
);
533 if ((report
& SAA7134_IRQ_REPORT_RDCAP
) ||
534 (report
& SAA7134_IRQ_REPORT_INTL
))
535 saa7134_irq_video_signalchange(dev
);
538 if ((report
& SAA7134_IRQ_REPORT_DONE_RA0
) &&
539 (status
& 0x60) == 0)
540 saa7134_irq_video_done(dev
,status
);
542 if ((report
& SAA7134_IRQ_REPORT_DONE_RA0
) &&
543 (status
& 0x40) == 0x40)
544 saa7134_irq_vbi_done(dev
,status
);
546 if ((report
& SAA7134_IRQ_REPORT_DONE_RA2
) &&
547 card_has_mpeg(dev
)) {
548 if (dev
->mops
->irq_ts_done
!= NULL
)
549 dev
->mops
->irq_ts_done(dev
, status
);
551 saa7134_irq_ts_done(dev
, status
);
554 if (report
& SAA7134_IRQ_REPORT_GPIO16
) {
555 switch (dev
->has_remote
) {
556 case SAA7134_REMOTE_GPIO
:
559 if (dev
->remote
->mask_keydown
& 0x10000) {
560 saa7134_input_irq(dev
);
564 case SAA7134_REMOTE_I2C
:
565 break; /* FIXME: invoke I2C get_key() */
567 default: /* GPIO16 not used by IR remote */
572 if (report
& SAA7134_IRQ_REPORT_GPIO18
) {
573 switch (dev
->has_remote
) {
574 case SAA7134_REMOTE_GPIO
:
577 if ((dev
->remote
->mask_keydown
& 0x40000) ||
578 (dev
->remote
->mask_keyup
& 0x40000)) {
579 saa7134_input_irq(dev
);
583 case SAA7134_REMOTE_I2C
:
584 break; /* FIXME: invoke I2C get_key() */
586 default: /* GPIO18 not used by IR remote */
593 print_irqstatus(dev
,loop
,report
,status
);
594 if (report
& SAA7134_IRQ_REPORT_PE
) {
595 /* disable all parity error */
596 pr_warn("%s/irq: looping -- clearing PE (parity error!) enable bit\n",
598 saa_clearl(SAA7134_IRQ2
,SAA7134_IRQ2_INTE_PE
);
599 } else if (report
& SAA7134_IRQ_REPORT_GPIO16
) {
600 /* disable gpio16 IRQ */
601 pr_warn("%s/irq: looping -- clearing GPIO16 enable bit\n",
603 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO16_P
);
604 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO16_N
);
605 } else if (report
& SAA7134_IRQ_REPORT_GPIO18
) {
606 /* disable gpio18 IRQs */
607 pr_warn("%s/irq: looping -- clearing GPIO18 enable bit\n",
609 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO18_P
);
610 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO18_N
);
612 /* disable all irqs */
613 pr_warn("%s/irq: looping -- clearing all enable bits\n",
615 saa_writel(SAA7134_IRQ1
,0);
616 saa_writel(SAA7134_IRQ2
,0);
621 return IRQ_RETVAL(handled
);
624 /* ------------------------------------------------------------------ */
626 /* early init (no i2c, no irq) */
628 static int saa7134_hw_enable1(struct saa7134_dev
*dev
)
630 /* RAM FIFO config */
631 saa_writel(SAA7134_FIFO_SIZE
, 0x08070503);
632 saa_writel(SAA7134_THRESHOULD
, 0x02020202);
634 /* enable audio + video processing */
635 saa_writel(SAA7134_MAIN_CTRL
,
636 SAA7134_MAIN_CTRL_VPLLE
|
637 SAA7134_MAIN_CTRL_APLLE
|
638 SAA7134_MAIN_CTRL_EXOSC
|
639 SAA7134_MAIN_CTRL_EVFE1
|
640 SAA7134_MAIN_CTRL_EVFE2
|
641 SAA7134_MAIN_CTRL_ESFE
|
642 SAA7134_MAIN_CTRL_EBDAC
);
645 * Initialize OSS _after_ enabling audio clock PLL and audio processing.
646 * OSS initialization writes to registers via the audio DSP; these
647 * writes will fail unless the audio clock has been started. At worst,
648 * audio will not work.
651 /* enable peripheral devices */
652 saa_writeb(SAA7134_SPECIAL_MODE
, 0x01);
654 /* set vertical line numbering start (vbi needs this) */
655 saa_writeb(SAA7134_SOURCE_TIMING2
, 0x20);
660 static int saa7134_hwinit1(struct saa7134_dev
*dev
)
662 core_dbg("hwinit1\n");
664 saa_writel(SAA7134_IRQ1
, 0);
665 saa_writel(SAA7134_IRQ2
, 0);
667 /* Clear any stale IRQ reports */
668 saa_writel(SAA7134_IRQ_REPORT
, saa_readl(SAA7134_IRQ_REPORT
));
670 mutex_init(&dev
->lock
);
671 spin_lock_init(&dev
->slock
);
673 saa7134_track_gpio(dev
,"pre-init");
674 saa7134_video_init1(dev
);
675 saa7134_vbi_init1(dev
);
676 if (card_has_mpeg(dev
))
677 saa7134_ts_init1(dev
);
678 saa7134_input_init1(dev
);
680 saa7134_hw_enable1(dev
);
685 /* late init (with i2c + irq) */
686 static int saa7134_hw_enable2(struct saa7134_dev
*dev
)
689 unsigned int irq2_mask
;
693 SAA7134_IRQ2_INTE_DEC3
|
694 SAA7134_IRQ2_INTE_DEC2
|
695 SAA7134_IRQ2_INTE_DEC1
|
696 SAA7134_IRQ2_INTE_DEC0
|
697 SAA7134_IRQ2_INTE_PE
|
698 SAA7134_IRQ2_INTE_AR
;
700 if (dev
->has_remote
== SAA7134_REMOTE_GPIO
&& dev
->remote
) {
701 if (dev
->remote
->mask_keydown
& 0x10000)
702 irq2_mask
|= SAA7134_IRQ2_INTE_GPIO16_N
;
703 else { /* Allow enabling both IRQ edge triggers */
704 if (dev
->remote
->mask_keydown
& 0x40000)
705 irq2_mask
|= SAA7134_IRQ2_INTE_GPIO18_P
;
706 if (dev
->remote
->mask_keyup
& 0x40000)
707 irq2_mask
|= SAA7134_IRQ2_INTE_GPIO18_N
;
711 if (dev
->has_remote
== SAA7134_REMOTE_I2C
) {
712 request_module("ir-kbd-i2c");
715 saa_writel(SAA7134_IRQ1
, 0);
716 saa_writel(SAA7134_IRQ2
, irq2_mask
);
721 static int saa7134_hwinit2(struct saa7134_dev
*dev
)
724 core_dbg("hwinit2\n");
726 saa7134_video_init2(dev
);
727 saa7134_tvaudio_init2(dev
);
729 saa7134_hw_enable2(dev
);
736 static int saa7134_hwfini(struct saa7134_dev
*dev
)
738 core_dbg("hwfini\n");
740 if (card_has_mpeg(dev
))
741 saa7134_ts_fini(dev
);
742 saa7134_input_fini(dev
);
743 saa7134_vbi_fini(dev
);
744 saa7134_tvaudio_fini(dev
);
745 saa7134_video_fini(dev
);
749 static void must_configure_manually(int has_eeprom
)
754 pr_warn("saa7134: <rant>\n"
755 "saa7134: Congratulations! Your TV card vendor saved a few\n"
756 "saa7134: cents for a eeprom, thus your pci board has no\n"
757 "saa7134: subsystem ID and I can't identify it automatically\n"
759 "saa7134: I feel better now. Ok, here are the good news:\n"
760 "saa7134: You can use the card=<nr> insmod option to specify\n"
761 "saa7134: which board do you have. The list:\n");
763 pr_warn("saa7134: Board is currently unknown. You might try to use the card=<nr>\n"
764 "saa7134: insmod option to specify which board do you have, but this is\n"
765 "saa7134: somewhat risky, as might damage your card. It is better to ask\n"
766 "saa7134: for support at linux-media@vger.kernel.org.\n"
767 "saa7134: The supported cards are:\n");
769 for (i
= 0; i
< saa7134_bcount
; i
++) {
770 pr_warn("saa7134: card=%d -> %-40.40s",
771 i
,saa7134_boards
[i
].name
);
772 for (p
= 0; saa7134_pci_tbl
[p
].driver_data
; p
++) {
773 if (saa7134_pci_tbl
[p
].driver_data
!= i
)
775 pr_cont(" %04x:%04x",
776 saa7134_pci_tbl
[p
].subvendor
,
777 saa7134_pci_tbl
[p
].subdevice
);
783 static void saa7134_unregister_media_device(struct saa7134_dev
*dev
)
786 #ifdef CONFIG_MEDIA_CONTROLLER
789 media_device_unregister(dev
->media_dev
);
790 media_device_cleanup(dev
->media_dev
);
791 kfree(dev
->media_dev
);
792 dev
->media_dev
= NULL
;
796 static void saa7134_media_release(struct saa7134_dev
*dev
)
798 #ifdef CONFIG_MEDIA_CONTROLLER
801 for (i
= 0; i
< SAA7134_INPUT_MAX
+ 1; i
++)
802 media_device_unregister_entity(&dev
->input_ent
[i
]);
806 #if defined(CONFIG_MEDIA_CONTROLLER)
807 static void saa7134_create_entities(struct saa7134_dev
*dev
)
810 struct media_entity
*entity
;
811 struct media_entity
*decoder
= NULL
;
813 /* Check if it is using an external analog TV demod */
814 media_device_for_each_entity(entity
, dev
->media_dev
) {
815 if (entity
->function
== MEDIA_ENT_F_ATV_DECODER
) {
822 * saa713x is not using an external ATV demod.
823 * Register the internal one
826 dev
->demod
.name
= "saa713x";
827 dev
->demod_pad
[SAA7134_PAD_IF_INPUT
].flags
= MEDIA_PAD_FL_SINK
;
828 dev
->demod_pad
[SAA7134_PAD_IF_INPUT
].sig_type
= PAD_SIGNAL_ANALOG
;
829 dev
->demod_pad
[SAA7134_PAD_VID_OUT
].flags
= MEDIA_PAD_FL_SOURCE
;
830 dev
->demod_pad
[SAA7134_PAD_VID_OUT
].sig_type
= PAD_SIGNAL_DV
;
831 dev
->demod
.function
= MEDIA_ENT_F_ATV_DECODER
;
833 ret
= media_entity_pads_init(&dev
->demod
, SAA7134_NUM_PADS
,
836 pr_err("failed to initialize demod pad!\n");
838 ret
= media_device_register_entity(dev
->media_dev
, &dev
->demod
);
840 pr_err("failed to register demod entity!\n");
842 dev
->decoder
= &dev
->demod
;
844 dev
->decoder
= decoder
;
847 /* Initialize Video, VBI and Radio pads */
848 dev
->video_pad
.flags
= MEDIA_PAD_FL_SINK
;
849 ret
= media_entity_pads_init(&dev
->video_dev
->entity
, 1,
852 pr_err("failed to initialize video media entity!\n");
854 dev
->vbi_pad
.flags
= MEDIA_PAD_FL_SINK
;
855 ret
= media_entity_pads_init(&dev
->vbi_dev
->entity
, 1,
858 pr_err("failed to initialize vbi media entity!\n");
860 /* Create entities for each input connector */
861 for (i
= 0; i
< SAA7134_INPUT_MAX
; i
++) {
862 struct media_entity
*ent
= &dev
->input_ent
[i
];
863 struct saa7134_input
*in
= &card_in(dev
, i
);
865 if (in
->type
== SAA7134_NO_INPUT
)
868 /* This input uses the S-Video connector */
869 if (in
->type
== SAA7134_INPUT_COMPOSITE_OVER_SVIDEO
)
872 ent
->name
= saa7134_input_name
[in
->type
];
873 ent
->flags
= MEDIA_ENT_FL_CONNECTOR
;
874 dev
->input_pad
[i
].flags
= MEDIA_PAD_FL_SOURCE
;
877 case SAA7134_INPUT_COMPOSITE
:
878 case SAA7134_INPUT_COMPOSITE0
:
879 case SAA7134_INPUT_COMPOSITE1
:
880 case SAA7134_INPUT_COMPOSITE2
:
881 case SAA7134_INPUT_COMPOSITE3
:
882 case SAA7134_INPUT_COMPOSITE4
:
883 ent
->function
= MEDIA_ENT_F_CONN_COMPOSITE
;
885 case SAA7134_INPUT_SVIDEO
:
886 case SAA7134_INPUT_SVIDEO0
:
887 case SAA7134_INPUT_SVIDEO1
:
888 ent
->function
= MEDIA_ENT_F_CONN_SVIDEO
;
892 * SAA7134_INPUT_TV and SAA7134_INPUT_TV_MONO.
894 * Please notice that neither SAA7134_INPUT_MUTE or
895 * SAA7134_INPUT_RADIO are defined at
896 * saa7134_board.input.
898 ent
->function
= MEDIA_ENT_F_CONN_RF
;
902 ret
= media_entity_pads_init(ent
, 1, &dev
->input_pad
[i
]);
904 pr_err("failed to initialize input pad[%d]!\n", i
);
906 ret
= media_device_register_entity(dev
->media_dev
, ent
);
908 pr_err("failed to register input entity %d!\n", i
);
911 /* Create input for Radio RF connector */
912 if (card_has_radio(dev
)) {
913 struct saa7134_input
*in
= &saa7134_boards
[dev
->board
].radio
;
914 struct media_entity
*ent
= &dev
->input_ent
[i
];
916 ent
->name
= saa7134_input_name
[in
->type
];
917 ent
->flags
= MEDIA_ENT_FL_CONNECTOR
;
918 dev
->input_pad
[i
].flags
= MEDIA_PAD_FL_SOURCE
;
919 ent
->function
= MEDIA_ENT_F_CONN_RF
;
921 ret
= media_entity_pads_init(ent
, 1, &dev
->input_pad
[i
]);
923 pr_err("failed to initialize input pad[%d]!\n", i
);
925 ret
= media_device_register_entity(dev
->media_dev
, ent
);
927 pr_err("failed to register input entity %d!\n", i
);
932 static struct video_device
*vdev_init(struct saa7134_dev
*dev
,
933 struct video_device
*template,
936 struct video_device
*vfd
;
938 vfd
= video_device_alloc();
942 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
943 vfd
->release
= video_device_release
;
944 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s (%s)",
945 dev
->name
, type
, saa7134_boards
[dev
->board
].name
);
946 video_set_drvdata(vfd
, dev
);
950 static void saa7134_unregister_video(struct saa7134_dev
*dev
)
952 saa7134_media_release(dev
);
954 if (dev
->video_dev
) {
955 if (video_is_registered(dev
->video_dev
))
956 vb2_video_unregister_device(dev
->video_dev
);
958 video_device_release(dev
->video_dev
);
959 dev
->video_dev
= NULL
;
962 if (video_is_registered(dev
->vbi_dev
))
963 vb2_video_unregister_device(dev
->vbi_dev
);
965 video_device_release(dev
->vbi_dev
);
968 if (dev
->radio_dev
) {
969 if (video_is_registered(dev
->radio_dev
))
970 video_unregister_device(dev
->radio_dev
);
972 video_device_release(dev
->radio_dev
);
973 dev
->radio_dev
= NULL
;
977 static void mpeg_ops_attach(struct saa7134_mpeg_ops
*ops
,
978 struct saa7134_dev
*dev
)
982 if (NULL
!= dev
->mops
)
984 if (saa7134_boards
[dev
->board
].mpeg
!= ops
->type
)
986 err
= ops
->init(dev
);
992 static void mpeg_ops_detach(struct saa7134_mpeg_ops
*ops
,
993 struct saa7134_dev
*dev
)
995 if (NULL
== dev
->mops
)
997 if (dev
->mops
!= ops
)
999 dev
->mops
->fini(dev
);
1003 static int saa7134_initdev(struct pci_dev
*pci_dev
,
1004 const struct pci_device_id
*pci_id
)
1006 struct saa7134_dev
*dev
;
1007 struct saa7134_mpeg_ops
*mops
;
1010 if (saa7134_devcount
== SAA7134_MAXBOARDS
)
1013 dev
= kzalloc(sizeof(*dev
),GFP_KERNEL
);
1017 dev
->nr
= saa7134_devcount
;
1018 sprintf(dev
->name
, "saa%x[%d]", pci_dev
->device
, dev
->nr
);
1020 #ifdef CONFIG_MEDIA_CONTROLLER
1021 dev
->media_dev
= kzalloc(sizeof(*dev
->media_dev
), GFP_KERNEL
);
1022 if (!dev
->media_dev
) {
1026 media_device_pci_init(dev
->media_dev
, pci_dev
, dev
->name
);
1027 dev
->v4l2_dev
.mdev
= dev
->media_dev
;
1030 err
= v4l2_device_register(&pci_dev
->dev
, &dev
->v4l2_dev
);
1036 if (pci_enable_device(pci_dev
)) {
1038 goto err_v4l2_unregister
;
1042 if (pci_pci_problems
) {
1043 if (pci_pci_problems
& PCIPCI_TRITON
)
1044 pr_info("%s: quirk: PCIPCI_TRITON\n", dev
->name
);
1045 if (pci_pci_problems
& PCIPCI_NATOMA
)
1046 pr_info("%s: quirk: PCIPCI_NATOMA\n", dev
->name
);
1047 if (pci_pci_problems
& PCIPCI_VIAETBF
)
1048 pr_info("%s: quirk: PCIPCI_VIAETBF\n", dev
->name
);
1049 if (pci_pci_problems
& PCIPCI_VSFX
)
1050 pr_info("%s: quirk: PCIPCI_VSFX\n", dev
->name
);
1051 #ifdef PCIPCI_ALIMAGIK
1052 if (pci_pci_problems
& PCIPCI_ALIMAGIK
) {
1053 pr_info("%s: quirk: PCIPCI_ALIMAGIK -- latency fixup\n",
1059 if (UNSET
!= latency
) {
1060 pr_info("%s: setting pci latency timer to %d\n",
1062 pci_write_config_byte(pci_dev
, PCI_LATENCY_TIMER
, latency
);
1065 /* print pci info */
1066 dev
->pci_rev
= pci_dev
->revision
;
1067 pci_read_config_byte(pci_dev
, PCI_LATENCY_TIMER
, &dev
->pci_lat
);
1068 pr_info("%s: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
1069 dev
->name
, pci_name(pci_dev
), dev
->pci_rev
, pci_dev
->irq
,
1071 (unsigned long long)pci_resource_start(pci_dev
, 0));
1072 pci_set_master(pci_dev
);
1073 err
= dma_set_mask(&pci_dev
->dev
, DMA_BIT_MASK(32));
1075 pr_warn("%s: Oops: no 32bit PCI DMA ???\n", dev
->name
);
1076 goto err_v4l2_unregister
;
1080 dev
->board
= pci_id
->driver_data
;
1081 if ((unsigned)card
[dev
->nr
] < saa7134_bcount
)
1082 dev
->board
= card
[dev
->nr
];
1083 if (SAA7134_BOARD_UNKNOWN
== dev
->board
)
1084 must_configure_manually(0);
1085 else if (SAA7134_BOARD_NOAUTO
== dev
->board
) {
1086 must_configure_manually(1);
1087 dev
->board
= SAA7134_BOARD_UNKNOWN
;
1089 dev
->autodetected
= card
[dev
->nr
] != dev
->board
;
1090 dev
->tuner_type
= saa7134_boards
[dev
->board
].tuner_type
;
1091 dev
->tuner_addr
= saa7134_boards
[dev
->board
].tuner_addr
;
1092 dev
->radio_type
= saa7134_boards
[dev
->board
].radio_type
;
1093 dev
->radio_addr
= saa7134_boards
[dev
->board
].radio_addr
;
1094 dev
->tda9887_conf
= saa7134_boards
[dev
->board
].tda9887_conf
;
1095 if (UNSET
!= tuner
[dev
->nr
])
1096 dev
->tuner_type
= tuner
[dev
->nr
];
1097 pr_info("%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
1098 dev
->name
,pci_dev
->subsystem_vendor
,
1099 pci_dev
->subsystem_device
,saa7134_boards
[dev
->board
].name
,
1100 dev
->board
, dev
->autodetected
?
1101 "autodetected" : "insmod option");
1104 if (!request_mem_region(pci_resource_start(pci_dev
,0),
1105 pci_resource_len(pci_dev
,0),
1108 pr_err("%s: can't get MMIO memory @ 0x%llx\n",
1109 dev
->name
,(unsigned long long)pci_resource_start(pci_dev
,0));
1110 goto err_v4l2_unregister
;
1112 dev
->lmmio
= ioremap(pci_resource_start(pci_dev
, 0),
1113 pci_resource_len(pci_dev
, 0));
1114 dev
->bmmio
= (__u8 __iomem
*)dev
->lmmio
;
1115 if (NULL
== dev
->lmmio
) {
1117 pr_err("%s: can't ioremap() MMIO memory\n",
1119 goto err_release_mem_reg
;
1122 /* initialize hardware #1 */
1123 saa7134_board_init1(dev
);
1124 saa7134_hwinit1(dev
);
1127 err
= request_irq(pci_dev
->irq
, saa7134_irq
,
1128 IRQF_SHARED
, dev
->name
, dev
);
1130 pr_err("%s: can't get IRQ %d\n",
1131 dev
->name
,pci_dev
->irq
);
1135 /* wait a bit, register i2c bus */
1137 saa7134_i2c_register(dev
);
1138 saa7134_board_init2(dev
);
1140 saa7134_hwinit2(dev
);
1142 /* load i2c helpers */
1143 if (card_is_empress(dev
)) {
1145 v4l2_i2c_new_subdev(&dev
->v4l2_dev
, &dev
->i2c_adap
,
1147 saa7134_boards
[dev
->board
].empress_addr
, NULL
);
1149 if (dev
->empress_sd
)
1150 dev
->empress_sd
->grp_id
= GRP_EMPRESS
;
1153 if (saa7134_boards
[dev
->board
].rds_addr
) {
1154 struct v4l2_subdev
*sd
;
1156 sd
= v4l2_i2c_new_subdev(&dev
->v4l2_dev
,
1157 &dev
->i2c_adap
, "saa6588",
1158 0, I2C_ADDRS(saa7134_boards
[dev
->board
].rds_addr
));
1160 pr_info("%s: found RDS decoder\n", dev
->name
);
1165 mutex_lock(&saa7134_devlist_lock
);
1166 list_for_each_entry(mops
, &mops_list
, next
)
1167 mpeg_ops_attach(mops
, dev
);
1168 list_add_tail(&dev
->devlist
, &saa7134_devlist
);
1169 mutex_unlock(&saa7134_devlist_lock
);
1171 /* check for signal */
1172 saa7134_irq_video_signalchange(dev
);
1174 if (TUNER_ABSENT
!= dev
->tuner_type
)
1175 saa_call_all(dev
, core
, s_power
, 0);
1177 /* register v4l devices */
1178 dev
->video_dev
= vdev_init(dev
,&saa7134_video_template
,"video");
1179 dev
->video_dev
->ctrl_handler
= &dev
->ctrl_handler
;
1180 dev
->video_dev
->lock
= &dev
->lock
;
1181 dev
->video_dev
->queue
= &dev
->video_vbq
;
1182 dev
->video_dev
->device_caps
= V4L2_CAP_READWRITE
| V4L2_CAP_STREAMING
|
1183 V4L2_CAP_VIDEO_CAPTURE
;
1184 if (dev
->tuner_type
!= TUNER_ABSENT
&& dev
->tuner_type
!= UNSET
)
1185 dev
->video_dev
->device_caps
|= V4L2_CAP_TUNER
;
1187 err
= video_register_device(dev
->video_dev
,VFL_TYPE_VIDEO
,
1190 pr_info("%s: can't register video device\n",
1192 goto err_unregister_video
;
1194 pr_info("%s: registered device %s [v4l2]\n",
1195 dev
->name
, video_device_node_name(dev
->video_dev
));
1197 dev
->vbi_dev
= vdev_init(dev
, &saa7134_video_template
, "vbi");
1198 dev
->vbi_dev
->ctrl_handler
= &dev
->ctrl_handler
;
1199 dev
->vbi_dev
->lock
= &dev
->lock
;
1200 dev
->vbi_dev
->queue
= &dev
->vbi_vbq
;
1201 dev
->vbi_dev
->device_caps
= V4L2_CAP_READWRITE
| V4L2_CAP_STREAMING
|
1202 V4L2_CAP_VBI_CAPTURE
;
1203 if (dev
->tuner_type
!= TUNER_ABSENT
&& dev
->tuner_type
!= UNSET
)
1204 dev
->vbi_dev
->device_caps
|= V4L2_CAP_TUNER
;
1206 err
= video_register_device(dev
->vbi_dev
,VFL_TYPE_VBI
,
1209 goto err_unregister_video
;
1210 pr_info("%s: registered device %s\n",
1211 dev
->name
, video_device_node_name(dev
->vbi_dev
));
1213 if (card_has_radio(dev
)) {
1214 dev
->radio_dev
= vdev_init(dev
,&saa7134_radio_template
,"radio");
1215 dev
->radio_dev
->ctrl_handler
= &dev
->radio_ctrl_handler
;
1216 dev
->radio_dev
->lock
= &dev
->lock
;
1217 dev
->radio_dev
->device_caps
= V4L2_CAP_RADIO
| V4L2_CAP_TUNER
;
1219 dev
->radio_dev
->device_caps
|= V4L2_CAP_RDS_CAPTURE
;
1220 err
= video_register_device(dev
->radio_dev
,VFL_TYPE_RADIO
,
1223 goto err_unregister_video
;
1224 pr_info("%s: registered device %s\n",
1225 dev
->name
, video_device_node_name(dev
->radio_dev
));
1228 #ifdef CONFIG_MEDIA_CONTROLLER
1229 saa7134_create_entities(dev
);
1231 err
= v4l2_mc_create_media_graph(dev
->media_dev
);
1233 pr_err("failed to create media graph\n");
1234 goto err_unregister_video
;
1237 /* everything worked */
1240 if (saa7134_dmasound_init
&& !dev
->dmasound
.priv_data
)
1241 saa7134_dmasound_init(dev
);
1243 request_submodules(dev
);
1246 * Do it at the end, to reduce dynamic configuration changes during
1247 * the device init. Yet, as request_modules() can be async, the
1248 * topology will likely change after load the saa7134 subdrivers.
1250 #ifdef CONFIG_MEDIA_CONTROLLER
1251 err
= media_device_register(dev
->media_dev
);
1253 media_device_cleanup(dev
->media_dev
);
1254 goto err_unregister_video
;
1260 err_unregister_video
:
1261 saa7134_unregister_video(dev
);
1262 list_del(&dev
->devlist
);
1263 saa7134_i2c_unregister(dev
);
1264 free_irq(pci_dev
->irq
, dev
);
1266 saa7134_hwfini(dev
);
1267 iounmap(dev
->lmmio
);
1268 err_release_mem_reg
:
1269 release_mem_region(pci_resource_start(pci_dev
,0),
1270 pci_resource_len(pci_dev
,0));
1271 err_v4l2_unregister
:
1272 v4l2_device_unregister(&dev
->v4l2_dev
);
1274 #ifdef CONFIG_MEDIA_CONTROLLER
1275 kfree(dev
->media_dev
);
1281 static void saa7134_finidev(struct pci_dev
*pci_dev
)
1283 struct v4l2_device
*v4l2_dev
= pci_get_drvdata(pci_dev
);
1284 struct saa7134_dev
*dev
= container_of(v4l2_dev
, struct saa7134_dev
, v4l2_dev
);
1285 struct saa7134_mpeg_ops
*mops
;
1287 flush_request_submodules(dev
);
1289 /* Release DMA sound modules if present */
1290 if (saa7134_dmasound_exit
&& dev
->dmasound
.priv_data
) {
1291 saa7134_dmasound_exit(dev
);
1296 u32 report
= saa_readl(SAA7134_IRQ_REPORT
);
1297 u32 status
= saa_readl(SAA7134_IRQ_STATUS
);
1298 print_irqstatus(dev
,42,report
,status
);
1301 /* disable peripheral devices */
1302 saa_writeb(SAA7134_SPECIAL_MODE
,0);
1304 /* shutdown hardware */
1305 saa_writel(SAA7134_IRQ1
,0);
1306 saa_writel(SAA7134_IRQ2
,0);
1307 saa_writel(SAA7134_MAIN_CTRL
,0);
1309 /* shutdown subsystems */
1310 saa7134_hwfini(dev
);
1313 mutex_lock(&saa7134_devlist_lock
);
1314 list_del(&dev
->devlist
);
1315 list_for_each_entry(mops
, &mops_list
, next
)
1316 mpeg_ops_detach(mops
, dev
);
1317 mutex_unlock(&saa7134_devlist_lock
);
1320 saa7134_i2c_unregister(dev
);
1321 saa7134_unregister_video(dev
);
1324 /* the DMA sound modules should be unloaded before reaching
1325 this, but just in case they are still present... */
1326 if (dev
->dmasound
.priv_data
!= NULL
) {
1327 free_irq(pci_dev
->irq
, &dev
->dmasound
);
1328 dev
->dmasound
.priv_data
= NULL
;
1332 /* release resources */
1333 free_irq(pci_dev
->irq
, dev
);
1334 iounmap(dev
->lmmio
);
1335 release_mem_region(pci_resource_start(pci_dev
,0),
1336 pci_resource_len(pci_dev
,0));
1338 v4l2_device_unregister(&dev
->v4l2_dev
);
1340 saa7134_unregister_media_device(dev
);
1346 /* resends a current buffer in queue after resume */
1347 static int __maybe_unused
saa7134_buffer_requeue(struct saa7134_dev
*dev
,
1348 struct saa7134_dmaqueue
*q
)
1350 struct saa7134_buf
*buf
, *next
;
1352 assert_spin_locked(&dev
->slock
);
1356 core_dbg("buffer_requeue\n");
1361 core_dbg("buffer_requeue : resending active buffer\n");
1363 if (!list_empty(&q
->queue
))
1364 next
= list_entry(q
->queue
.next
, struct saa7134_buf
,
1366 buf
->activate(dev
, buf
, next
);
1371 static int __maybe_unused
saa7134_suspend(struct device
*dev_d
)
1373 struct pci_dev
*pci_dev
= to_pci_dev(dev_d
);
1374 struct v4l2_device
*v4l2_dev
= pci_get_drvdata(pci_dev
);
1375 struct saa7134_dev
*dev
= container_of(v4l2_dev
, struct saa7134_dev
, v4l2_dev
);
1377 /* Disable interrupts, DMA, and rest of the chip*/
1378 saa_writel(SAA7134_IRQ1
, 0);
1379 saa_writel(SAA7134_IRQ2
, 0);
1380 saa_writel(SAA7134_MAIN_CTRL
, 0);
1383 synchronize_irq(pci_dev
->irq
);
1385 /* ACK interrupts once more, just in case,
1386 since the IRQ handler won't ack them anymore*/
1388 saa_writel(SAA7134_IRQ_REPORT
, saa_readl(SAA7134_IRQ_REPORT
));
1390 /* Disable timeout timers - if we have active buffers, we will
1391 fill them on resume*/
1393 del_timer(&dev
->video_q
.timeout
);
1394 del_timer(&dev
->vbi_q
.timeout
);
1395 del_timer(&dev
->ts_q
.timeout
);
1397 if (dev
->remote
&& dev
->remote
->dev
->users
)
1398 saa7134_ir_close(dev
->remote
->dev
);
1403 static int __maybe_unused
saa7134_resume(struct device
*dev_d
)
1405 struct v4l2_device
*v4l2_dev
= dev_get_drvdata(dev_d
);
1406 struct saa7134_dev
*dev
= container_of(v4l2_dev
, struct saa7134_dev
, v4l2_dev
);
1407 unsigned long flags
;
1409 /* Do things that are done in saa7134_initdev ,
1410 except of initializing memory structures.*/
1412 saa7134_board_init1(dev
);
1414 /* saa7134_hwinit1 */
1415 if (saa7134_boards
[dev
->board
].video_out
)
1416 saa7134_videoport_init(dev
);
1417 if (card_has_mpeg(dev
))
1418 saa7134_ts_init_hw(dev
);
1419 if (dev
->remote
&& dev
->remote
->dev
->users
)
1420 saa7134_ir_open(dev
->remote
->dev
);
1421 saa7134_hw_enable1(dev
);
1425 saa7134_board_init2(dev
);
1428 saa7134_set_tvnorm_hw(dev
);
1429 saa7134_tvaudio_setmute(dev
);
1430 saa7134_tvaudio_setvolume(dev
, dev
->ctl_volume
);
1431 saa7134_tvaudio_init(dev
);
1432 saa7134_enable_i2s(dev
);
1433 saa7134_hw_enable2(dev
);
1435 saa7134_irq_video_signalchange(dev
);
1437 /*resume unfinished buffer(s)*/
1438 spin_lock_irqsave(&dev
->slock
, flags
);
1439 saa7134_buffer_requeue(dev
, &dev
->video_q
);
1440 saa7134_buffer_requeue(dev
, &dev
->vbi_q
);
1441 saa7134_buffer_requeue(dev
, &dev
->ts_q
);
1443 /* FIXME: Disable DMA audio sound - temporary till proper support
1446 dev
->dmasound
.dma_running
= 0;
1451 saa7134_set_dmabits(dev
);
1452 spin_unlock_irqrestore(&dev
->slock
, flags
);
1457 /* ----------------------------------------------------------- */
1459 int saa7134_ts_register(struct saa7134_mpeg_ops
*ops
)
1461 struct saa7134_dev
*dev
;
1463 mutex_lock(&saa7134_devlist_lock
);
1464 list_for_each_entry(dev
, &saa7134_devlist
, devlist
)
1465 mpeg_ops_attach(ops
, dev
);
1466 list_add_tail(&ops
->next
,&mops_list
);
1467 mutex_unlock(&saa7134_devlist_lock
);
1471 void saa7134_ts_unregister(struct saa7134_mpeg_ops
*ops
)
1473 struct saa7134_dev
*dev
;
1475 mutex_lock(&saa7134_devlist_lock
);
1476 list_del(&ops
->next
);
1477 list_for_each_entry(dev
, &saa7134_devlist
, devlist
)
1478 mpeg_ops_detach(ops
, dev
);
1479 mutex_unlock(&saa7134_devlist_lock
);
1482 EXPORT_SYMBOL(saa7134_ts_register
);
1483 EXPORT_SYMBOL(saa7134_ts_unregister
);
1485 /* ----------------------------------------------------------- */
1487 static SIMPLE_DEV_PM_OPS(saa7134_pm_ops
, saa7134_suspend
, saa7134_resume
);
1489 static struct pci_driver saa7134_pci_driver
= {
1491 .id_table
= saa7134_pci_tbl
,
1492 .probe
= saa7134_initdev
,
1493 .remove
= saa7134_finidev
,
1494 .driver
.pm
= &saa7134_pm_ops
,
1497 static int __init
saa7134_init(void)
1499 pr_info("saa7130/34: v4l2 driver version %s loaded\n",
1501 return pci_register_driver(&saa7134_pci_driver
);
1504 static void __exit
saa7134_fini(void)
1506 pci_unregister_driver(&saa7134_pci_driver
);
1509 module_init(saa7134_init
);
1510 module_exit(saa7134_fini
);
1512 /* ----------------------------------------------------------- */
1514 EXPORT_SYMBOL(saa7134_set_gpio
);
1515 EXPORT_SYMBOL(saa7134_boards
);
1517 /* ----------------- for the DMA sound modules --------------- */
1519 EXPORT_SYMBOL(saa7134_dmasound_init
);
1520 EXPORT_SYMBOL(saa7134_dmasound_exit
);
1521 EXPORT_SYMBOL(saa7134_pgtable_free
);
1522 EXPORT_SYMBOL(saa7134_pgtable_build
);
1523 EXPORT_SYMBOL(saa7134_pgtable_alloc
);
1524 EXPORT_SYMBOL(saa7134_set_dmabits
);