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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include "cx25821-video.h"
26 #include "cx25821-video-upstream.h"
29 #include <linux/errno.h>
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32 #include <linux/module.h>
33 #include <linux/syscalls.h>
34 #include <linux/file.h>
35 #include <linux/fcntl.h>
36 #include <linux/slab.h>
37 #include <linux/uaccess.h>
39 MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
40 MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
41 MODULE_LICENSE("GPL");
43 static int _intr_msk
=
44 FLD_VID_SRC_RISC1
| FLD_VID_SRC_UF
| FLD_VID_SRC_SYNC
| FLD_VID_SRC_OPC_ERR
;
46 int cx25821_sram_channel_setup_upstream(struct cx25821_dev
*dev
,
47 struct sram_channel
*ch
,
48 unsigned int bpl
, u32 risc
)
50 unsigned int i
, lines
;
53 if (ch
->cmds_start
== 0) {
54 cx_write(ch
->ptr1_reg
, 0);
55 cx_write(ch
->ptr2_reg
, 0);
56 cx_write(ch
->cnt2_reg
, 0);
57 cx_write(ch
->cnt1_reg
, 0);
61 bpl
= (bpl
+ 7) & ~7; /* alignment */
63 lines
= ch
->fifo_size
/ bpl
;
71 for (i
= 0; i
< lines
; i
++) {
72 cx_write(cdt
+ 16 * i
, ch
->fifo_start
+ bpl
* i
);
73 cx_write(cdt
+ 16 * i
+ 4, 0);
74 cx_write(cdt
+ 16 * i
+ 8, 0);
75 cx_write(cdt
+ 16 * i
+ 12, 0);
79 cx_write(ch
->cmds_start
+ 0, risc
);
81 cx_write(ch
->cmds_start
+ 4, 0);
82 cx_write(ch
->cmds_start
+ 8, cdt
);
83 cx_write(ch
->cmds_start
+ 12, (lines
* 16) >> 3);
84 cx_write(ch
->cmds_start
+ 16, ch
->ctrl_start
);
86 cx_write(ch
->cmds_start
+ 20, VID_IQ_SIZE_DW
);
88 for (i
= 24; i
< 80; i
+= 4)
89 cx_write(ch
->cmds_start
+ i
, 0);
92 cx_write(ch
->ptr1_reg
, ch
->fifo_start
);
93 cx_write(ch
->ptr2_reg
, cdt
);
94 cx_write(ch
->cnt2_reg
, (lines
* 16) >> 3);
95 cx_write(ch
->cnt1_reg
, (bpl
>> 3) - 1);
100 static __le32
*cx25821_update_riscprogram(struct cx25821_dev
*dev
,
101 __le32
*rp
, unsigned int offset
,
102 unsigned int bpl
, u32 sync_line
,
103 unsigned int lines
, int fifo_enable
,
106 unsigned int line
, i
;
107 int dist_betwn_starts
= bpl
* 2;
109 *(rp
++) = cpu_to_le32(RISC_RESYNC
| sync_line
);
111 if (USE_RISC_NOOP_VIDEO
) {
112 for (i
= 0; i
< NUM_NO_OPS
; i
++)
113 *(rp
++) = cpu_to_le32(RISC_NOOP
);
117 for (line
= 0; line
< lines
; line
++) {
118 *(rp
++) = cpu_to_le32(RISC_READ
| RISC_SOL
| RISC_EOL
| bpl
);
119 *(rp
++) = cpu_to_le32(dev
->_data_buf_phys_addr
+ offset
);
120 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
122 if ((lines
<= NTSC_FIELD_HEIGHT
)
123 || (line
< (NTSC_FIELD_HEIGHT
- 1)) || !(dev
->_isNTSC
)) {
124 offset
+= dist_betwn_starts
;
131 static __le32
*cx25821_risc_field_upstream(struct cx25821_dev
*dev
, __le32
* rp
,
132 dma_addr_t databuf_phys_addr
,
133 unsigned int offset
, u32 sync_line
,
134 unsigned int bpl
, unsigned int lines
,
135 int fifo_enable
, int field_type
)
137 unsigned int line
, i
;
138 struct sram_channel
*sram_ch
=
139 dev
->channels
[dev
->_channel_upstream_select
].sram_channels
;
140 int dist_betwn_starts
= bpl
* 2;
142 /* sync instruction */
143 if (sync_line
!= NO_SYNC_LINE
)
144 *(rp
++) = cpu_to_le32(RISC_RESYNC
| sync_line
);
146 if (USE_RISC_NOOP_VIDEO
) {
147 for (i
= 0; i
< NUM_NO_OPS
; i
++)
148 *(rp
++) = cpu_to_le32(RISC_NOOP
);
152 for (line
= 0; line
< lines
; line
++) {
153 *(rp
++) = cpu_to_le32(RISC_READ
| RISC_SOL
| RISC_EOL
| bpl
);
154 *(rp
++) = cpu_to_le32(databuf_phys_addr
+ offset
);
155 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
157 if ((lines
<= NTSC_FIELD_HEIGHT
)
158 || (line
< (NTSC_FIELD_HEIGHT
- 1)) || !(dev
->_isNTSC
))
159 /* to skip the other field line */
160 offset
+= dist_betwn_starts
;
162 /* check if we need to enable the FIFO after the first 4 lines
163 * For the upstream video channel, the risc engine will enable
165 if (fifo_enable
&& line
== 3) {
166 *(rp
++) = RISC_WRITECR
;
167 *(rp
++) = sram_ch
->dma_ctl
;
168 *(rp
++) = FLD_VID_FIFO_EN
;
169 *(rp
++) = 0x00000001;
176 int cx25821_risc_buffer_upstream(struct cx25821_dev
*dev
,
178 unsigned int top_offset
,
179 unsigned int bpl
, unsigned int lines
)
183 /* get line count for single field */
184 int singlefield_lines
= lines
>> 1;
185 int odd_num_lines
= singlefield_lines
;
188 int databuf_offset
= 0;
189 int risc_program_size
= 0;
190 int risc_flag
= RISC_CNT_RESET
;
191 unsigned int bottom_offset
= bpl
;
192 dma_addr_t risc_phys_jump_addr
;
195 odd_num_lines
= singlefield_lines
+ 1;
196 risc_program_size
= FRAME1_VID_PROG_SIZE
;
199 Y411_LINE_SZ
) ? FRAME_SIZE_NTSC_Y411
:
200 FRAME_SIZE_NTSC_Y422
;
202 risc_program_size
= PAL_VID_PROG_SIZE
;
205 Y411_LINE_SZ
) ? FRAME_SIZE_PAL_Y411
: FRAME_SIZE_PAL_Y422
;
208 /* Virtual address of Risc buffer program */
209 rp
= dev
->_dma_virt_addr
;
211 for (frame
= 0; frame
< NUM_FRAMES
; frame
++) {
212 databuf_offset
= frame_size
* frame
;
214 if (UNSET
!= top_offset
) {
215 fifo_enable
= (frame
== 0) ? FIFO_ENABLE
: FIFO_DISABLE
;
216 rp
= cx25821_risc_field_upstream(dev
, rp
,
218 _data_buf_phys_addr
+
226 fifo_enable
= FIFO_DISABLE
;
229 rp
= cx25821_risc_field_upstream(dev
, rp
,
230 dev
->_data_buf_phys_addr
+
231 databuf_offset
, bottom_offset
,
232 0x200, bpl
, singlefield_lines
,
233 fifo_enable
, EVEN_FIELD
);
236 risc_flag
= RISC_CNT_RESET
;
237 risc_phys_jump_addr
=
238 dev
->_dma_phys_start_addr
+ risc_program_size
;
240 risc_phys_jump_addr
= dev
->_dma_phys_start_addr
;
241 risc_flag
= RISC_CNT_INC
;
244 /* Loop to 2ndFrameRISC or to Start of Risc
245 * program & generate IRQ
247 *(rp
++) = cpu_to_le32(RISC_JUMP
| RISC_IRQ1
| risc_flag
);
248 *(rp
++) = cpu_to_le32(risc_phys_jump_addr
);
249 *(rp
++) = cpu_to_le32(0);
255 void cx25821_stop_upstream_video_ch1(struct cx25821_dev
*dev
)
257 struct sram_channel
*sram_ch
=
258 dev
->channels
[VID_UPSTREAM_SRAM_CHANNEL_I
].sram_channels
;
261 if (!dev
->_is_running
) {
262 pr_info("No video file is currently running so return!\n");
265 /* Disable RISC interrupts */
266 tmp
= cx_read(sram_ch
->int_msk
);
267 cx_write(sram_ch
->int_msk
, tmp
& ~_intr_msk
);
269 /* Turn OFF risc and fifo enable */
270 tmp
= cx_read(sram_ch
->dma_ctl
);
271 cx_write(sram_ch
->dma_ctl
, tmp
& ~(FLD_VID_FIFO_EN
| FLD_VID_RISC_EN
));
273 /* Clear data buffer memory */
274 if (dev
->_data_buf_virt_addr
)
275 memset(dev
->_data_buf_virt_addr
, 0, dev
->_data_buf_size
);
277 dev
->_is_running
= 0;
278 dev
->_is_first_frame
= 0;
279 dev
->_frame_count
= 0;
280 dev
->_file_status
= END_OF_FILE
;
282 if (dev
->_irq_queues
) {
283 kfree(dev
->_irq_queues
);
284 dev
->_irq_queues
= NULL
;
287 if (dev
->_filename
!= NULL
)
288 kfree(dev
->_filename
);
290 tmp
= cx_read(VID_CH_MODE_SEL
);
291 cx_write(VID_CH_MODE_SEL
, tmp
& 0xFFFFFE00);
294 void cx25821_free_mem_upstream_ch1(struct cx25821_dev
*dev
)
296 if (dev
->_is_running
)
297 cx25821_stop_upstream_video_ch1(dev
);
299 if (dev
->_dma_virt_addr
) {
300 pci_free_consistent(dev
->pci
, dev
->_risc_size
,
301 dev
->_dma_virt_addr
, dev
->_dma_phys_addr
);
302 dev
->_dma_virt_addr
= NULL
;
305 if (dev
->_data_buf_virt_addr
) {
306 pci_free_consistent(dev
->pci
, dev
->_data_buf_size
,
307 dev
->_data_buf_virt_addr
,
308 dev
->_data_buf_phys_addr
);
309 dev
->_data_buf_virt_addr
= NULL
;
313 int cx25821_get_frame(struct cx25821_dev
*dev
, struct sram_channel
*sram_ch
)
316 int frame_index_temp
= dev
->_frame_index
;
319 (dev
->_pixel_format
==
320 PIXEL_FRMT_411
) ? Y411_LINE_SZ
: Y422_LINE_SZ
;
322 int frame_offset
= 0;
323 ssize_t vfs_read_retval
= 0;
324 char mybuf
[line_size
];
329 if (dev
->_file_status
== END_OF_FILE
)
335 Y411_LINE_SZ
) ? FRAME_SIZE_NTSC_Y411
:
336 FRAME_SIZE_NTSC_Y422
;
340 Y411_LINE_SZ
) ? FRAME_SIZE_PAL_Y411
: FRAME_SIZE_PAL_Y422
;
343 frame_offset
= (frame_index_temp
> 0) ? frame_size
: 0;
344 file_offset
= dev
->_frame_count
* frame_size
;
346 myfile
= filp_open(dev
->_filename
, O_RDONLY
| O_LARGEFILE
, 0);
348 if (IS_ERR(myfile
)) {
349 const int open_errno
= -PTR_ERR(myfile
);
350 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
351 __func__
, dev
->_filename
, open_errno
);
352 return PTR_ERR(myfile
);
354 if (!(myfile
->f_op
)) {
355 pr_err("%s(): File has no file operations registered!\n",
357 filp_close(myfile
, NULL
);
361 if (!myfile
->f_op
->read
) {
362 pr_err("%s(): File has no READ operations registered!\n",
364 filp_close(myfile
, NULL
);
372 for (i
= 0; i
< dev
->_lines_count
; i
++) {
376 vfs_read(myfile
, mybuf
, line_size
, &pos
);
378 if (vfs_read_retval
> 0 && vfs_read_retval
== line_size
379 && dev
->_data_buf_virt_addr
!= NULL
) {
380 memcpy((void *)(dev
->_data_buf_virt_addr
+
381 frame_offset
/ 4), mybuf
,
385 file_offset
+= vfs_read_retval
;
386 frame_offset
+= vfs_read_retval
;
388 if (vfs_read_retval
< line_size
) {
389 pr_info("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 pr_err("ERROR %s(): since container_of(work_struct) FAILED!\n",
419 cx25821_get_frame(dev
,
420 dev
->channels
[dev
->_channel_upstream_select
].
424 int cx25821_openfile(struct cx25821_dev
*dev
, struct sram_channel
*sram_ch
)
429 (dev
->_pixel_format
==
430 PIXEL_FRMT_411
) ? Y411_LINE_SZ
: Y422_LINE_SZ
;
431 ssize_t vfs_read_retval
= 0;
432 char mybuf
[line_size
];
434 loff_t offset
= (unsigned long)0;
437 myfile
= filp_open(dev
->_filename
, O_RDONLY
| O_LARGEFILE
, 0);
439 if (IS_ERR(myfile
)) {
440 const int open_errno
= -PTR_ERR(myfile
);
441 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
442 __func__
, dev
->_filename
, open_errno
);
443 return PTR_ERR(myfile
);
445 if (!(myfile
->f_op
)) {
446 pr_err("%s(): File has no file operations registered!\n",
448 filp_close(myfile
, NULL
);
452 if (!myfile
->f_op
->read
) {
453 pr_err("%s(): File has no READ operations registered! Returning\n",
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
) {
482 pr_info("Done: exit %s() since no more bytes to read from Video file\n",
491 if (vfs_read_retval
< line_size
)
496 (vfs_read_retval
== line_size
) ? IN_PROGRESS
: END_OF_FILE
;
500 filp_close(myfile
, NULL
);
506 int cx25821_upstream_buffer_prepare(struct cx25821_dev
*dev
,
507 struct sram_channel
*sram_ch
, int bpl
)
511 dma_addr_t data_dma_addr
;
513 if (dev
->_dma_virt_addr
!= NULL
) {
514 pci_free_consistent(dev
->pci
, dev
->upstream_riscbuf_size
,
515 dev
->_dma_virt_addr
, dev
->_dma_phys_addr
);
518 dev
->_dma_virt_addr
=
519 pci_alloc_consistent(dev
->pci
, dev
->upstream_riscbuf_size
,
521 dev
->_dma_virt_start_addr
= dev
->_dma_virt_addr
;
522 dev
->_dma_phys_start_addr
= dma_addr
;
523 dev
->_dma_phys_addr
= dma_addr
;
524 dev
->_risc_size
= dev
->upstream_riscbuf_size
;
526 if (!dev
->_dma_virt_addr
) {
527 pr_err("FAILED to allocate memory for Risc buffer! Returning\n");
531 /* Clear memory at address */
532 memset(dev
->_dma_virt_addr
, 0, dev
->_risc_size
);
534 if (dev
->_data_buf_virt_addr
!= NULL
) {
535 pci_free_consistent(dev
->pci
, dev
->upstream_databuf_size
,
536 dev
->_data_buf_virt_addr
,
537 dev
->_data_buf_phys_addr
);
539 /* For Video Data buffer allocation */
540 dev
->_data_buf_virt_addr
=
541 pci_alloc_consistent(dev
->pci
, dev
->upstream_databuf_size
,
543 dev
->_data_buf_phys_addr
= data_dma_addr
;
544 dev
->_data_buf_size
= dev
->upstream_databuf_size
;
546 if (!dev
->_data_buf_virt_addr
) {
547 pr_err("FAILED to allocate memory for data buffer! Returning\n");
551 /* Clear memory at address */
552 memset(dev
->_data_buf_virt_addr
, 0, dev
->_data_buf_size
);
554 ret
= cx25821_openfile(dev
, sram_ch
);
558 /* Create RISC programs */
560 cx25821_risc_buffer_upstream(dev
, dev
->pci
, 0, bpl
,
563 pr_info("Failed creating Video Upstream Risc programs!\n");
573 int cx25821_video_upstream_irq(struct cx25821_dev
*dev
, int chan_num
,
577 struct sram_channel
*channel
= dev
->channels
[chan_num
].sram_channels
;
578 int singlefield_lines
= NTSC_FIELD_HEIGHT
;
579 int line_size_in_bytes
= Y422_LINE_SZ
;
580 int odd_risc_prog_size
= 0;
581 dma_addr_t risc_phys_jump_addr
;
584 if (status
& FLD_VID_SRC_RISC1
) {
585 /* We should only process one program per call */
586 u32 prog_cnt
= cx_read(channel
->gpcnt
);
588 /* Since we've identified our IRQ, clear our bits from the
589 * interrupt mask and interrupt status registers */
590 int_msk_tmp
= cx_read(channel
->int_msk
);
591 cx_write(channel
->int_msk
, int_msk_tmp
& ~_intr_msk
);
592 cx_write(channel
->int_stat
, _intr_msk
);
594 spin_lock(&dev
->slock
);
596 dev
->_frame_index
= prog_cnt
;
598 queue_work(dev
->_irq_queues
, &dev
->_irq_work_entry
);
600 if (dev
->_is_first_frame
) {
601 dev
->_is_first_frame
= 0;
604 singlefield_lines
+= 1;
605 odd_risc_prog_size
= ODD_FLD_NTSC_PROG_SIZE
;
607 singlefield_lines
= PAL_FIELD_HEIGHT
;
608 odd_risc_prog_size
= ODD_FLD_PAL_PROG_SIZE
;
611 if (dev
->_dma_virt_start_addr
!= NULL
) {
613 (dev
->_pixel_format
==
614 PIXEL_FRMT_411
) ? Y411_LINE_SZ
:
616 risc_phys_jump_addr
=
617 dev
->_dma_phys_start_addr
+
620 rp
= cx25821_update_riscprogram(dev
,
622 _dma_virt_start_addr
,
630 /* Jump to Even Risc program of 1st Frame */
631 *(rp
++) = cpu_to_le32(RISC_JUMP
);
632 *(rp
++) = cpu_to_le32(risc_phys_jump_addr
);
633 *(rp
++) = cpu_to_le32(0);
637 spin_unlock(&dev
->slock
);
639 if (status
& FLD_VID_SRC_UF
)
640 pr_err("%s(): Video Received Underflow Error Interrupt!\n",
643 if (status
& FLD_VID_SRC_SYNC
)
644 pr_err("%s(): Video Received Sync Error Interrupt!\n",
647 if (status
& FLD_VID_SRC_OPC_ERR
)
648 pr_err("%s(): Video Received OpCode Error Interrupt!\n",
652 if (dev
->_file_status
== END_OF_FILE
) {
653 pr_err("EOF Channel 1 Framecount = %d\n", dev
->_frame_count
);
656 /* ElSE, set the interrupt mask register, re-enable irq. */
657 int_msk_tmp
= cx_read(channel
->int_msk
);
658 cx_write(channel
->int_msk
, int_msk_tmp
|= _intr_msk
);
663 static irqreturn_t
cx25821_upstream_irq(int irq
, void *dev_id
)
665 struct cx25821_dev
*dev
= dev_id
;
666 u32 msk_stat
, vid_status
;
669 struct sram_channel
*sram_ch
;
674 channel_num
= VID_UPSTREAM_SRAM_CHANNEL_I
;
676 sram_ch
= dev
->channels
[channel_num
].sram_channels
;
678 msk_stat
= cx_read(sram_ch
->int_mstat
);
679 vid_status
= cx_read(sram_ch
->int_stat
);
681 /* Only deal with our interrupt */
684 cx25821_video_upstream_irq(dev
, channel_num
, vid_status
);
688 cx25821_stop_upstream_video_ch1(dev
);
692 return IRQ_RETVAL(handled
);
695 void cx25821_set_pixelengine(struct cx25821_dev
*dev
, struct sram_channel
*ch
,
698 int width
= WIDTH_D1
;
699 int height
= dev
->_lines_count
;
700 int num_lines
, odd_num_lines
;
702 int vip_mode
= OUTPUT_FRMT_656
;
704 value
= ((pix_format
& 0x3) << 12) | (vip_mode
& 0x7);
706 value
|= dev
->_isNTSC
? 0 : 0x10;
707 cx_write(ch
->vid_fmt_ctl
, value
);
709 /* set number of active pixels in each line.
710 * Default is 720 pixels in both NTSC and PAL format */
711 cx_write(ch
->vid_active_ctl1
, width
);
713 num_lines
= (height
/ 2) & 0x3FF;
714 odd_num_lines
= num_lines
;
719 value
= (num_lines
<< 16) | odd_num_lines
;
721 /* set number of active lines in field 0 (top) and field 1 (bottom) */
722 cx_write(ch
->vid_active_ctl2
, value
);
724 cx_write(ch
->vid_cdt_size
, VID_CDT_SIZE
>> 3);
727 int cx25821_start_video_dma_upstream(struct cx25821_dev
*dev
,
728 struct sram_channel
*sram_ch
)
733 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
736 tmp
= cx_read(VID_CH_MODE_SEL
);
737 cx_write(VID_CH_MODE_SEL
, tmp
| 0x1B0001FF);
739 /* Set the physical start address of the RISC program in the initial
740 * program counter(IPC) member of the cmds.
742 cx_write(sram_ch
->cmds_start
+ 0, dev
->_dma_phys_addr
);
743 /* Risc IPC High 64 bits 63-32 */
744 cx_write(sram_ch
->cmds_start
+ 4, 0);
747 cx_write(sram_ch
->gpcnt_ctl
, 3);
749 /* Clear our bits from the interrupt status register. */
750 cx_write(sram_ch
->int_stat
, _intr_msk
);
752 /* Set the interrupt mask register, enable irq. */
753 cx_set(PCI_INT_MSK
, cx_read(PCI_INT_MSK
) | (1 << sram_ch
->irq_bit
));
754 tmp
= cx_read(sram_ch
->int_msk
);
755 cx_write(sram_ch
->int_msk
, tmp
|= _intr_msk
);
758 request_irq(dev
->pci
->irq
, cx25821_upstream_irq
,
759 IRQF_SHARED
| IRQF_DISABLED
, dev
->name
, dev
);
761 pr_err("%s: can't get upstream IRQ %d\n",
762 dev
->name
, dev
->pci
->irq
);
766 /* Start the DMA engine */
767 tmp
= cx_read(sram_ch
->dma_ctl
);
768 cx_set(sram_ch
->dma_ctl
, tmp
| FLD_VID_RISC_EN
);
770 dev
->_is_running
= 1;
771 dev
->_is_first_frame
= 1;
776 cx25821_dev_unregister(dev
);
780 int cx25821_vidupstream_init_ch1(struct cx25821_dev
*dev
, int channel_select
,
783 struct sram_channel
*sram_ch
;
787 int data_frame_size
= 0;
788 int risc_buffer_size
= 0;
791 if (dev
->_is_running
) {
792 pr_info("Video Channel is still running so return!\n");
796 dev
->_channel_upstream_select
= channel_select
;
797 sram_ch
= dev
->channels
[channel_select
].sram_channels
;
799 INIT_WORK(&dev
->_irq_work_entry
, cx25821_vidups_handler
);
800 dev
->_irq_queues
= create_singlethread_workqueue("cx25821_workqueue");
802 if (!dev
->_irq_queues
) {
803 pr_err("create_singlethread_workqueue() for Video FAILED!\n");
806 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
809 tmp
= cx_read(VID_CH_MODE_SEL
);
810 cx_write(VID_CH_MODE_SEL
, tmp
| 0x1B0001FF);
812 dev
->_is_running
= 0;
813 dev
->_frame_count
= 0;
814 dev
->_file_status
= RESET_STATUS
;
815 dev
->_lines_count
= dev
->_isNTSC
? 480 : 576;
816 dev
->_pixel_format
= pixel_format
;
818 (dev
->_pixel_format
==
819 PIXEL_FRMT_422
) ? (WIDTH_D1
* 2) : (WIDTH_D1
* 3) / 2;
820 data_frame_size
= dev
->_isNTSC
? NTSC_DATA_BUF_SZ
: PAL_DATA_BUF_SZ
;
822 dev
->_isNTSC
? NTSC_RISC_BUF_SIZE
: PAL_RISC_BUF_SIZE
;
824 if (dev
->input_filename
) {
825 str_length
= strlen(dev
->input_filename
);
826 dev
->_filename
= kmalloc(str_length
+ 1, GFP_KERNEL
);
831 memcpy(dev
->_filename
, dev
->input_filename
, str_length
+ 1);
833 str_length
= strlen(dev
->_defaultname
);
834 dev
->_filename
= kmalloc(str_length
+ 1, GFP_KERNEL
);
839 memcpy(dev
->_filename
, dev
->_defaultname
, str_length
+ 1);
842 /* Default if filename is empty string */
843 if (strcmp(dev
->input_filename
, "") == 0) {
846 (dev
->_pixel_format
==
847 PIXEL_FRMT_411
) ? "/root/vid411.yuv" :
851 (dev
->_pixel_format
==
852 PIXEL_FRMT_411
) ? "/root/pal411.yuv" :
857 dev
->_is_running
= 0;
858 dev
->_frame_count
= 0;
859 dev
->_file_status
= RESET_STATUS
;
860 dev
->_lines_count
= dev
->_isNTSC
? 480 : 576;
861 dev
->_pixel_format
= pixel_format
;
863 (dev
->_pixel_format
==
864 PIXEL_FRMT_422
) ? (WIDTH_D1
* 2) : (WIDTH_D1
* 3) / 2;
867 cx25821_sram_channel_setup_upstream(dev
, sram_ch
, dev
->_line_size
,
870 /* setup fifo + format */
871 cx25821_set_pixelengine(dev
, sram_ch
, dev
->_pixel_format
);
873 dev
->upstream_riscbuf_size
= risc_buffer_size
* 2;
874 dev
->upstream_databuf_size
= data_frame_size
* 2;
876 /* Allocating buffers and prepare RISC program */
877 retval
= cx25821_upstream_buffer_prepare(dev
, sram_ch
, dev
->_line_size
);
879 pr_err("%s: Failed to set up Video upstream buffers!\n",
884 cx25821_start_video_dma_upstream(dev
, sram_ch
);
889 cx25821_dev_unregister(dev
);