2 * Driver for the Conexant CX25821 PCIe bridge
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <hiep.huynh@conexant.com>, <shu.lin@conexant.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * 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.
23 #include "cx25821-video.h"
24 #include "cx25821-video-upstream.h"
27 #include <linux/errno.h>
28 #include <linux/kernel.h>
29 #include <linux/init.h>
30 #include <linux/module.h>
31 #include <linux/syscalls.h>
32 #include <linux/file.h>
33 #include <linux/fcntl.h>
34 #include <linux/slab.h>
35 #include <linux/uaccess.h>
37 MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
38 MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
39 MODULE_LICENSE("GPL");
41 static int _intr_msk
=
42 FLD_VID_SRC_RISC1
| FLD_VID_SRC_UF
| FLD_VID_SRC_SYNC
| FLD_VID_SRC_OPC_ERR
;
44 int cx25821_sram_channel_setup_upstream(struct cx25821_dev
*dev
,
45 struct sram_channel
*ch
,
46 unsigned int bpl
, u32 risc
)
48 unsigned int i
, lines
;
51 if (ch
->cmds_start
== 0) {
52 cx_write(ch
->ptr1_reg
, 0);
53 cx_write(ch
->ptr2_reg
, 0);
54 cx_write(ch
->cnt2_reg
, 0);
55 cx_write(ch
->cnt1_reg
, 0);
59 bpl
= (bpl
+ 7) & ~7; /* alignment */
61 lines
= ch
->fifo_size
/ bpl
;
69 for (i
= 0; i
< lines
; i
++) {
70 cx_write(cdt
+ 16 * i
, ch
->fifo_start
+ bpl
* i
);
71 cx_write(cdt
+ 16 * i
+ 4, 0);
72 cx_write(cdt
+ 16 * i
+ 8, 0);
73 cx_write(cdt
+ 16 * i
+ 12, 0);
77 cx_write(ch
->cmds_start
+ 0, risc
);
79 cx_write(ch
->cmds_start
+ 4, 0);
80 cx_write(ch
->cmds_start
+ 8, cdt
);
81 cx_write(ch
->cmds_start
+ 12, (lines
* 16) >> 3);
82 cx_write(ch
->cmds_start
+ 16, ch
->ctrl_start
);
84 cx_write(ch
->cmds_start
+ 20, VID_IQ_SIZE_DW
);
86 for (i
= 24; i
< 80; i
+= 4)
87 cx_write(ch
->cmds_start
+ i
, 0);
90 cx_write(ch
->ptr1_reg
, ch
->fifo_start
);
91 cx_write(ch
->ptr2_reg
, cdt
);
92 cx_write(ch
->cnt2_reg
, (lines
* 16) >> 3);
93 cx_write(ch
->cnt1_reg
, (bpl
>> 3) - 1);
98 static __le32
*cx25821_update_riscprogram(struct cx25821_dev
*dev
,
99 __le32
*rp
, unsigned int offset
,
100 unsigned int bpl
, u32 sync_line
,
101 unsigned int lines
, int fifo_enable
,
104 unsigned int line
, i
;
105 int dist_betwn_starts
= bpl
* 2;
107 *(rp
++) = cpu_to_le32(RISC_RESYNC
| sync_line
);
109 if (USE_RISC_NOOP_VIDEO
) {
110 for (i
= 0; i
< NUM_NO_OPS
; i
++)
111 *(rp
++) = cpu_to_le32(RISC_NOOP
);
115 for (line
= 0; line
< lines
; line
++) {
116 *(rp
++) = cpu_to_le32(RISC_READ
| RISC_SOL
| RISC_EOL
| bpl
);
117 *(rp
++) = cpu_to_le32(dev
->_data_buf_phys_addr
+ offset
);
118 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
120 if ((lines
<= NTSC_FIELD_HEIGHT
)
121 || (line
< (NTSC_FIELD_HEIGHT
- 1)) || !(dev
->_isNTSC
)) {
122 offset
+= dist_betwn_starts
;
129 static __le32
*cx25821_risc_field_upstream(struct cx25821_dev
*dev
, __le32
* rp
,
130 dma_addr_t databuf_phys_addr
,
131 unsigned int offset
, u32 sync_line
,
132 unsigned int bpl
, unsigned int lines
,
133 int fifo_enable
, int field_type
)
135 unsigned int line
, i
;
136 struct sram_channel
*sram_ch
=
137 &dev
->sram_channels
[dev
->_channel_upstream_select
];
138 int dist_betwn_starts
= bpl
* 2;
140 /* sync instruction */
141 if (sync_line
!= NO_SYNC_LINE
)
142 *(rp
++) = cpu_to_le32(RISC_RESYNC
| sync_line
);
144 if (USE_RISC_NOOP_VIDEO
) {
145 for (i
= 0; i
< NUM_NO_OPS
; i
++)
146 *(rp
++) = cpu_to_le32(RISC_NOOP
);
150 for (line
= 0; line
< lines
; line
++) {
151 *(rp
++) = cpu_to_le32(RISC_READ
| RISC_SOL
| RISC_EOL
| bpl
);
152 *(rp
++) = cpu_to_le32(databuf_phys_addr
+ offset
);
153 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
155 if ((lines
<= NTSC_FIELD_HEIGHT
)
156 || (line
< (NTSC_FIELD_HEIGHT
- 1)) || !(dev
->_isNTSC
))
157 /* to skip the other field line */
158 offset
+= dist_betwn_starts
;
160 /* check if we need to enable the FIFO after the first 4 lines
161 * For the upstream video channel, the risc engine will enable
163 if (fifo_enable
&& line
== 3) {
164 *(rp
++) = RISC_WRITECR
;
165 *(rp
++) = sram_ch
->dma_ctl
;
166 *(rp
++) = FLD_VID_FIFO_EN
;
167 *(rp
++) = 0x00000001;
174 int cx25821_risc_buffer_upstream(struct cx25821_dev
*dev
,
176 unsigned int top_offset
,
177 unsigned int bpl
, unsigned int lines
)
181 /* get line count for single field */
182 int singlefield_lines
= lines
>> 1;
183 int odd_num_lines
= singlefield_lines
;
186 int databuf_offset
= 0;
187 int risc_program_size
= 0;
188 int risc_flag
= RISC_CNT_RESET
;
189 unsigned int bottom_offset
= bpl
;
190 dma_addr_t risc_phys_jump_addr
;
193 odd_num_lines
= singlefield_lines
+ 1;
194 risc_program_size
= FRAME1_VID_PROG_SIZE
;
197 Y411_LINE_SZ
) ? FRAME_SIZE_NTSC_Y411
:
198 FRAME_SIZE_NTSC_Y422
;
200 risc_program_size
= PAL_VID_PROG_SIZE
;
203 Y411_LINE_SZ
) ? FRAME_SIZE_PAL_Y411
: FRAME_SIZE_PAL_Y422
;
206 /* Virtual address of Risc buffer program */
207 rp
= dev
->_dma_virt_addr
;
209 for (frame
= 0; frame
< NUM_FRAMES
; frame
++) {
210 databuf_offset
= frame_size
* frame
;
212 if (UNSET
!= top_offset
) {
213 fifo_enable
= (frame
== 0) ? FIFO_ENABLE
: FIFO_DISABLE
;
214 rp
= cx25821_risc_field_upstream(dev
, rp
,
216 _data_buf_phys_addr
+
224 fifo_enable
= FIFO_DISABLE
;
227 rp
= cx25821_risc_field_upstream(dev
, rp
,
228 dev
->_data_buf_phys_addr
+
229 databuf_offset
, bottom_offset
,
230 0x200, bpl
, singlefield_lines
,
231 fifo_enable
, EVEN_FIELD
);
234 risc_flag
= RISC_CNT_RESET
;
235 risc_phys_jump_addr
=
236 dev
->_dma_phys_start_addr
+ risc_program_size
;
238 risc_phys_jump_addr
= dev
->_dma_phys_start_addr
;
239 risc_flag
= RISC_CNT_INC
;
242 /* Loop to 2ndFrameRISC or to Start of Risc
243 * program & generate IRQ
245 *(rp
++) = cpu_to_le32(RISC_JUMP
| RISC_IRQ1
| risc_flag
);
246 *(rp
++) = cpu_to_le32(risc_phys_jump_addr
);
247 *(rp
++) = cpu_to_le32(0);
253 void cx25821_stop_upstream_video_ch1(struct cx25821_dev
*dev
)
255 struct sram_channel
*sram_ch
=
256 &dev
->sram_channels
[VID_UPSTREAM_SRAM_CHANNEL_I
];
259 if (!dev
->_is_running
) {
261 (KERN_INFO
"cx25821: No video file is currently running so return!\n");
264 /* Disable RISC interrupts */
265 tmp
= cx_read(sram_ch
->int_msk
);
266 cx_write(sram_ch
->int_msk
, tmp
& ~_intr_msk
);
268 /* Turn OFF risc and fifo enable */
269 tmp
= cx_read(sram_ch
->dma_ctl
);
270 cx_write(sram_ch
->dma_ctl
, tmp
& ~(FLD_VID_FIFO_EN
| FLD_VID_RISC_EN
));
272 /* Clear data buffer memory */
273 if (dev
->_data_buf_virt_addr
)
274 memset(dev
->_data_buf_virt_addr
, 0, dev
->_data_buf_size
);
276 dev
->_is_running
= 0;
277 dev
->_is_first_frame
= 0;
278 dev
->_frame_count
= 0;
279 dev
->_file_status
= END_OF_FILE
;
281 if (dev
->_irq_queues
) {
282 kfree(dev
->_irq_queues
);
283 dev
->_irq_queues
= NULL
;
286 if (dev
->_filename
!= NULL
)
287 kfree(dev
->_filename
);
289 tmp
= cx_read(VID_CH_MODE_SEL
);
290 cx_write(VID_CH_MODE_SEL
, tmp
& 0xFFFFFE00);
293 void cx25821_free_mem_upstream_ch1(struct cx25821_dev
*dev
)
295 if (dev
->_is_running
)
296 cx25821_stop_upstream_video_ch1(dev
);
298 if (dev
->_dma_virt_addr
) {
299 pci_free_consistent(dev
->pci
, dev
->_risc_size
,
300 dev
->_dma_virt_addr
, dev
->_dma_phys_addr
);
301 dev
->_dma_virt_addr
= NULL
;
304 if (dev
->_data_buf_virt_addr
) {
305 pci_free_consistent(dev
->pci
, dev
->_data_buf_size
,
306 dev
->_data_buf_virt_addr
,
307 dev
->_data_buf_phys_addr
);
308 dev
->_data_buf_virt_addr
= NULL
;
312 int cx25821_get_frame(struct cx25821_dev
*dev
, struct sram_channel
*sram_ch
)
315 int frame_index_temp
= dev
->_frame_index
;
318 (dev
->_pixel_format
==
319 PIXEL_FRMT_411
) ? Y411_LINE_SZ
: Y422_LINE_SZ
;
321 int frame_offset
= 0;
322 ssize_t vfs_read_retval
= 0;
323 char mybuf
[line_size
];
328 if (dev
->_file_status
== END_OF_FILE
)
334 Y411_LINE_SZ
) ? FRAME_SIZE_NTSC_Y411
:
335 FRAME_SIZE_NTSC_Y422
;
339 Y411_LINE_SZ
) ? FRAME_SIZE_PAL_Y411
: FRAME_SIZE_PAL_Y422
;
342 frame_offset
= (frame_index_temp
> 0) ? frame_size
: 0;
343 file_offset
= dev
->_frame_count
* frame_size
;
345 myfile
= filp_open(dev
->_filename
, O_RDONLY
| O_LARGEFILE
, 0);
347 if (IS_ERR(myfile
)) {
348 const int open_errno
= -PTR_ERR(myfile
);
349 printk(KERN_ERR
"%s(): ERROR opening file(%s) with errno = %d!\n",
350 __func__
, dev
->_filename
, open_errno
);
351 return PTR_ERR(myfile
);
353 if (!(myfile
->f_op
)) {
354 printk(KERN_ERR
"%s: File has no file operations registered!",
356 filp_close(myfile
, NULL
);
360 if (!myfile
->f_op
->read
) {
361 printk(KERN_ERR
"%s: File has no READ operations registered!",
363 filp_close(myfile
, NULL
);
371 for (i
= 0; i
< dev
->_lines_count
; i
++) {
375 vfs_read(myfile
, mybuf
, line_size
, &pos
);
377 if (vfs_read_retval
> 0 && vfs_read_retval
== line_size
378 && dev
->_data_buf_virt_addr
!= NULL
) {
379 memcpy((void *)(dev
->_data_buf_virt_addr
+
380 frame_offset
/ 4), mybuf
,
384 file_offset
+= vfs_read_retval
;
385 frame_offset
+= vfs_read_retval
;
387 if (vfs_read_retval
< line_size
) {
389 "Done: exit %s() since no more bytes to read from Video file.\n",
399 (vfs_read_retval
== line_size
) ? IN_PROGRESS
: END_OF_FILE
;
402 filp_close(myfile
, NULL
);
408 static void cx25821_vidups_handler(struct work_struct
*work
)
410 struct cx25821_dev
*dev
=
411 container_of(work
, struct cx25821_dev
, _irq_work_entry
);
414 printk(KERN_ERR
"ERROR %s(): since container_of(work_struct) FAILED!\n",
419 cx25821_get_frame(dev
,
420 &dev
->sram_channels
[dev
->_channel_upstream_select
]);
423 int cx25821_openfile(struct cx25821_dev
*dev
, struct sram_channel
*sram_ch
)
428 (dev
->_pixel_format
==
429 PIXEL_FRMT_411
) ? Y411_LINE_SZ
: Y422_LINE_SZ
;
430 ssize_t vfs_read_retval
= 0;
431 char mybuf
[line_size
];
433 loff_t offset
= (unsigned long)0;
436 myfile
= filp_open(dev
->_filename
, O_RDONLY
| O_LARGEFILE
, 0);
438 if (IS_ERR(myfile
)) {
439 const int open_errno
= -PTR_ERR(myfile
);
440 printk(KERN_ERR
"%s(): ERROR opening file(%s) with errno = %d!\n",
441 __func__
, dev
->_filename
, open_errno
);
442 return PTR_ERR(myfile
);
444 if (!(myfile
->f_op
)) {
445 printk(KERN_ERR
"%s: File has no file operations registered!",
447 filp_close(myfile
, NULL
);
451 if (!myfile
->f_op
->read
) {
453 (KERN_ERR
"%s: File has no READ operations registered! Returning.",
455 filp_close(myfile
, NULL
);
463 for (j
= 0; j
< NUM_FRAMES
; j
++) {
464 for (i
= 0; i
< dev
->_lines_count
; i
++) {
468 vfs_read(myfile
, mybuf
, line_size
, &pos
);
470 if (vfs_read_retval
> 0
471 && vfs_read_retval
== line_size
472 && dev
->_data_buf_virt_addr
!= NULL
) {
473 memcpy((void *)(dev
->
474 _data_buf_virt_addr
+
479 offset
+= vfs_read_retval
;
481 if (vfs_read_retval
< line_size
) {
483 "Done: exit %s() since no more bytes to read from Video file.\n",
492 if (vfs_read_retval
< line_size
)
497 (vfs_read_retval
== line_size
) ? IN_PROGRESS
: END_OF_FILE
;
501 filp_close(myfile
, NULL
);
507 int cx25821_upstream_buffer_prepare(struct cx25821_dev
*dev
,
508 struct sram_channel
*sram_ch
, int bpl
)
512 dma_addr_t data_dma_addr
;
514 if (dev
->_dma_virt_addr
!= NULL
) {
515 pci_free_consistent(dev
->pci
, dev
->upstream_riscbuf_size
,
516 dev
->_dma_virt_addr
, dev
->_dma_phys_addr
);
519 dev
->_dma_virt_addr
=
520 pci_alloc_consistent(dev
->pci
, dev
->upstream_riscbuf_size
,
522 dev
->_dma_virt_start_addr
= dev
->_dma_virt_addr
;
523 dev
->_dma_phys_start_addr
= dma_addr
;
524 dev
->_dma_phys_addr
= dma_addr
;
525 dev
->_risc_size
= dev
->upstream_riscbuf_size
;
527 if (!dev
->_dma_virt_addr
) {
529 (KERN_ERR
"cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
533 /* Clear memory at address */
534 memset(dev
->_dma_virt_addr
, 0, dev
->_risc_size
);
536 if (dev
->_data_buf_virt_addr
!= NULL
) {
537 pci_free_consistent(dev
->pci
, dev
->upstream_databuf_size
,
538 dev
->_data_buf_virt_addr
,
539 dev
->_data_buf_phys_addr
);
541 /* For Video Data buffer allocation */
542 dev
->_data_buf_virt_addr
=
543 pci_alloc_consistent(dev
->pci
, dev
->upstream_databuf_size
,
545 dev
->_data_buf_phys_addr
= data_dma_addr
;
546 dev
->_data_buf_size
= dev
->upstream_databuf_size
;
548 if (!dev
->_data_buf_virt_addr
) {
550 (KERN_ERR
"cx25821: FAILED to allocate memory for data buffer! Returning.\n");
554 /* Clear memory at address */
555 memset(dev
->_data_buf_virt_addr
, 0, dev
->_data_buf_size
);
557 ret
= cx25821_openfile(dev
, sram_ch
);
561 /* Create RISC programs */
563 cx25821_risc_buffer_upstream(dev
, dev
->pci
, 0, bpl
,
567 "cx25821: Failed creating Video Upstream Risc programs!\n");
577 int cx25821_video_upstream_irq(struct cx25821_dev
*dev
, int chan_num
,
581 struct sram_channel
*channel
= &dev
->sram_channels
[chan_num
];
582 int singlefield_lines
= NTSC_FIELD_HEIGHT
;
583 int line_size_in_bytes
= Y422_LINE_SZ
;
584 int odd_risc_prog_size
= 0;
585 dma_addr_t risc_phys_jump_addr
;
588 if (status
& FLD_VID_SRC_RISC1
) {
589 /* We should only process one program per call */
590 u32 prog_cnt
= cx_read(channel
->gpcnt
);
592 /* Since we've identified our IRQ, clear our bits from the
593 * interrupt mask and interrupt status registers */
594 int_msk_tmp
= cx_read(channel
->int_msk
);
595 cx_write(channel
->int_msk
, int_msk_tmp
& ~_intr_msk
);
596 cx_write(channel
->int_stat
, _intr_msk
);
598 spin_lock(&dev
->slock
);
600 dev
->_frame_index
= prog_cnt
;
602 queue_work(dev
->_irq_queues
, &dev
->_irq_work_entry
);
604 if (dev
->_is_first_frame
) {
605 dev
->_is_first_frame
= 0;
608 singlefield_lines
+= 1;
609 odd_risc_prog_size
= ODD_FLD_NTSC_PROG_SIZE
;
611 singlefield_lines
= PAL_FIELD_HEIGHT
;
612 odd_risc_prog_size
= ODD_FLD_PAL_PROG_SIZE
;
615 if (dev
->_dma_virt_start_addr
!= NULL
) {
617 (dev
->_pixel_format
==
618 PIXEL_FRMT_411
) ? Y411_LINE_SZ
:
620 risc_phys_jump_addr
=
621 dev
->_dma_phys_start_addr
+
624 rp
= cx25821_update_riscprogram(dev
,
626 _dma_virt_start_addr
,
634 /* Jump to Even Risc program of 1st Frame */
635 *(rp
++) = cpu_to_le32(RISC_JUMP
);
636 *(rp
++) = cpu_to_le32(risc_phys_jump_addr
);
637 *(rp
++) = cpu_to_le32(0);
641 spin_unlock(&dev
->slock
);
643 if (status
& FLD_VID_SRC_UF
)
645 (KERN_ERR
"%s: Video Received Underflow Error Interrupt!\n",
648 if (status
& FLD_VID_SRC_SYNC
)
649 printk(KERN_ERR
"%s: Video Received Sync Error Interrupt!\n",
652 if (status
& FLD_VID_SRC_OPC_ERR
)
653 printk(KERN_ERR
"%s: Video Received OpCode Error Interrupt!\n",
657 if (dev
->_file_status
== END_OF_FILE
) {
658 printk(KERN_ERR
"cx25821: EOF Channel 1 Framecount = %d\n",
662 /* ElSE, set the interrupt mask register, re-enable irq. */
663 int_msk_tmp
= cx_read(channel
->int_msk
);
664 cx_write(channel
->int_msk
, int_msk_tmp
|= _intr_msk
);
669 static irqreturn_t
cx25821_upstream_irq(int irq
, void *dev_id
)
671 struct cx25821_dev
*dev
= dev_id
;
672 u32 msk_stat
, vid_status
;
675 struct sram_channel
*sram_ch
;
680 channel_num
= VID_UPSTREAM_SRAM_CHANNEL_I
;
682 sram_ch
= &dev
->sram_channels
[channel_num
];
684 msk_stat
= cx_read(sram_ch
->int_mstat
);
685 vid_status
= cx_read(sram_ch
->int_stat
);
687 /* Only deal with our interrupt */
690 cx25821_video_upstream_irq(dev
, channel_num
, vid_status
);
694 cx25821_stop_upstream_video_ch1(dev
);
698 return IRQ_RETVAL(handled
);
701 void cx25821_set_pixelengine(struct cx25821_dev
*dev
, struct sram_channel
*ch
,
704 int width
= WIDTH_D1
;
705 int height
= dev
->_lines_count
;
706 int num_lines
, odd_num_lines
;
708 int vip_mode
= OUTPUT_FRMT_656
;
710 value
= ((pix_format
& 0x3) << 12) | (vip_mode
& 0x7);
712 value
|= dev
->_isNTSC
? 0 : 0x10;
713 cx_write(ch
->vid_fmt_ctl
, value
);
715 /* set number of active pixels in each line.
716 * Default is 720 pixels in both NTSC and PAL format */
717 cx_write(ch
->vid_active_ctl1
, width
);
719 num_lines
= (height
/ 2) & 0x3FF;
720 odd_num_lines
= num_lines
;
725 value
= (num_lines
<< 16) | odd_num_lines
;
727 /* set number of active lines in field 0 (top) and field 1 (bottom) */
728 cx_write(ch
->vid_active_ctl2
, value
);
730 cx_write(ch
->vid_cdt_size
, VID_CDT_SIZE
>> 3);
733 int cx25821_start_video_dma_upstream(struct cx25821_dev
*dev
,
734 struct sram_channel
*sram_ch
)
739 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
742 tmp
= cx_read(VID_CH_MODE_SEL
);
743 cx_write(VID_CH_MODE_SEL
, tmp
| 0x1B0001FF);
745 /* Set the physical start address of the RISC program in the initial
746 * program counter(IPC) member of the cmds.
748 cx_write(sram_ch
->cmds_start
+ 0, dev
->_dma_phys_addr
);
749 /* Risc IPC High 64 bits 63-32 */
750 cx_write(sram_ch
->cmds_start
+ 4, 0);
753 cx_write(sram_ch
->gpcnt_ctl
, 3);
755 /* Clear our bits from the interrupt status register. */
756 cx_write(sram_ch
->int_stat
, _intr_msk
);
758 /* Set the interrupt mask register, enable irq. */
759 cx_set(PCI_INT_MSK
, cx_read(PCI_INT_MSK
) | (1 << sram_ch
->irq_bit
));
760 tmp
= cx_read(sram_ch
->int_msk
);
761 cx_write(sram_ch
->int_msk
, tmp
|= _intr_msk
);
764 request_irq(dev
->pci
->irq
, cx25821_upstream_irq
,
765 IRQF_SHARED
| IRQF_DISABLED
, dev
->name
, dev
);
767 printk(KERN_ERR
"%s: can't get upstream IRQ %d\n", dev
->name
,
772 /* Start the DMA engine */
773 tmp
= cx_read(sram_ch
->dma_ctl
);
774 cx_set(sram_ch
->dma_ctl
, tmp
| FLD_VID_RISC_EN
);
776 dev
->_is_running
= 1;
777 dev
->_is_first_frame
= 1;
782 cx25821_dev_unregister(dev
);
786 int cx25821_vidupstream_init_ch1(struct cx25821_dev
*dev
, int channel_select
,
789 struct sram_channel
*sram_ch
;
793 int data_frame_size
= 0;
794 int risc_buffer_size
= 0;
797 if (dev
->_is_running
) {
798 printk(KERN_INFO
"Video Channel is still running so return!\n");
802 dev
->_channel_upstream_select
= channel_select
;
803 sram_ch
= &dev
->sram_channels
[channel_select
];
805 INIT_WORK(&dev
->_irq_work_entry
, cx25821_vidups_handler
);
806 dev
->_irq_queues
= create_singlethread_workqueue("cx25821_workqueue");
808 if (!dev
->_irq_queues
) {
810 (KERN_ERR
"cx25821: create_singlethread_workqueue() for Video FAILED!\n");
813 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
816 tmp
= cx_read(VID_CH_MODE_SEL
);
817 cx_write(VID_CH_MODE_SEL
, tmp
| 0x1B0001FF);
819 dev
->_is_running
= 0;
820 dev
->_frame_count
= 0;
821 dev
->_file_status
= RESET_STATUS
;
822 dev
->_lines_count
= dev
->_isNTSC
? 480 : 576;
823 dev
->_pixel_format
= pixel_format
;
825 (dev
->_pixel_format
==
826 PIXEL_FRMT_422
) ? (WIDTH_D1
* 2) : (WIDTH_D1
* 3) / 2;
827 data_frame_size
= dev
->_isNTSC
? NTSC_DATA_BUF_SZ
: PAL_DATA_BUF_SZ
;
829 dev
->_isNTSC
? NTSC_RISC_BUF_SIZE
: PAL_RISC_BUF_SIZE
;
831 if (dev
->input_filename
) {
832 str_length
= strlen(dev
->input_filename
);
833 dev
->_filename
= kmalloc(str_length
+ 1, GFP_KERNEL
);
838 memcpy(dev
->_filename
, dev
->input_filename
, str_length
+ 1);
840 str_length
= strlen(dev
->_defaultname
);
841 dev
->_filename
= kmalloc(str_length
+ 1, GFP_KERNEL
);
846 memcpy(dev
->_filename
, dev
->_defaultname
, str_length
+ 1);
849 /* Default if filename is empty string */
850 if (strcmp(dev
->input_filename
, "") == 0) {
853 (dev
->_pixel_format
==
854 PIXEL_FRMT_411
) ? "/root/vid411.yuv" :
858 (dev
->_pixel_format
==
859 PIXEL_FRMT_411
) ? "/root/pal411.yuv" :
864 dev
->_is_running
= 0;
865 dev
->_frame_count
= 0;
866 dev
->_file_status
= RESET_STATUS
;
867 dev
->_lines_count
= dev
->_isNTSC
? 480 : 576;
868 dev
->_pixel_format
= pixel_format
;
870 (dev
->_pixel_format
==
871 PIXEL_FRMT_422
) ? (WIDTH_D1
* 2) : (WIDTH_D1
* 3) / 2;
874 cx25821_sram_channel_setup_upstream(dev
, sram_ch
, dev
->_line_size
,
877 /* setup fifo + format */
878 cx25821_set_pixelengine(dev
, sram_ch
, dev
->_pixel_format
);
880 dev
->upstream_riscbuf_size
= risc_buffer_size
* 2;
881 dev
->upstream_databuf_size
= data_frame_size
* 2;
883 /* Allocating buffers and prepare RISC program */
884 retval
= cx25821_upstream_buffer_prepare(dev
, sram_ch
, dev
->_line_size
);
887 "%s: Failed to set up Video upstream buffers!\n",
892 cx25821_start_video_dma_upstream(dev
, sram_ch
);
897 cx25821_dev_unregister(dev
);