Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Conexant CX25821 PCIe bridge |
| 3 | * |
| 4 | * Copyright (C) 2009 Conexant Systems Inc. |
| 5 | * Authors <hiep.huynh@conexant.com>, <shu.lin@conexant.com> |
| 6 | * |
| 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. |
| 11 | * |
| 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 |
| 15 | * |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 25 | #include "cx25821-video.h" |
| 26 | #include "cx25821-video-upstream.h" |
| 27 | |
| 28 | #include <linux/fs.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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 37 | #include <linux/uaccess.h> |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 38 | |
| 39 | MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); |
| 40 | MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); |
| 41 | MODULE_LICENSE("GPL"); |
| 42 | |
Leonid V. Fedorenchik | 2b2d039 | 2011-09-02 11:55:46 +0800 | [diff] [blame] | 43 | static int _intr_msk = FLD_VID_SRC_RISC1 | FLD_VID_SRC_UF | FLD_VID_SRC_SYNC | |
| 44 | FLD_VID_SRC_OPC_ERR; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 45 | |
| 46 | int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 47 | const struct sram_channel *ch, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 48 | unsigned int bpl, u32 risc) |
| 49 | { |
| 50 | unsigned int i, lines; |
| 51 | u32 cdt; |
| 52 | |
| 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); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | bpl = (bpl + 7) & ~7; /* alignment */ |
| 62 | cdt = ch->cdt; |
| 63 | lines = ch->fifo_size / bpl; |
| 64 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 65 | if (lines > 4) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 66 | lines = 4; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 67 | |
| 68 | BUG_ON(lines < 2); |
| 69 | |
| 70 | /* write CDT */ |
| 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); |
| 76 | } |
| 77 | |
| 78 | /* write CMDS */ |
| 79 | cx_write(ch->cmds_start + 0, risc); |
| 80 | |
| 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); |
| 85 | |
| 86 | cx_write(ch->cmds_start + 20, VID_IQ_SIZE_DW); |
| 87 | |
| 88 | for (i = 24; i < 80; i += 4) |
| 89 | cx_write(ch->cmds_start + i, 0); |
| 90 | |
| 91 | /* fill registers */ |
| 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); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 100 | static __le32 *cx25821_update_riscprogram(struct cx25821_channel *chan, |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 101 | __le32 *rp, unsigned int offset, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 102 | unsigned int bpl, u32 sync_line, |
| 103 | unsigned int lines, int fifo_enable, |
| 104 | int field_type) |
| 105 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 106 | struct cx25821_video_out_data *out = chan->out; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 107 | unsigned int line, i; |
| 108 | int dist_betwn_starts = bpl * 2; |
| 109 | |
| 110 | *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line); |
| 111 | |
| 112 | if (USE_RISC_NOOP_VIDEO) { |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 113 | for (i = 0; i < NUM_NO_OPS; i++) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 114 | *(rp++) = cpu_to_le32(RISC_NOOP); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* scan lines */ |
| 118 | for (line = 0; line < lines; line++) { |
| 119 | *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl); |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 120 | *(rp++) = cpu_to_le32(out->_data_buf_phys_addr + offset); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 121 | *(rp++) = cpu_to_le32(0); /* bits 63-32 */ |
| 122 | |
| 123 | if ((lines <= NTSC_FIELD_HEIGHT) |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 124 | || (line < (NTSC_FIELD_HEIGHT - 1)) || !(out->is_60hz)) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 125 | offset += dist_betwn_starts; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return rp; |
| 130 | } |
| 131 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 132 | static __le32 *cx25821_risc_field_upstream(struct cx25821_channel *chan, __le32 *rp, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 133 | dma_addr_t databuf_phys_addr, |
| 134 | unsigned int offset, u32 sync_line, |
| 135 | unsigned int bpl, unsigned int lines, |
| 136 | int fifo_enable, int field_type) |
| 137 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 138 | struct cx25821_video_out_data *out = chan->out; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 139 | unsigned int line, i; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 140 | const struct sram_channel *sram_ch = chan->sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 141 | int dist_betwn_starts = bpl * 2; |
| 142 | |
| 143 | /* sync instruction */ |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 144 | if (sync_line != NO_SYNC_LINE) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 145 | *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 146 | |
| 147 | if (USE_RISC_NOOP_VIDEO) { |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 148 | for (i = 0; i < NUM_NO_OPS; i++) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 149 | *(rp++) = cpu_to_le32(RISC_NOOP); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* scan lines */ |
| 153 | for (line = 0; line < lines; line++) { |
| 154 | *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl); |
| 155 | *(rp++) = cpu_to_le32(databuf_phys_addr + offset); |
| 156 | *(rp++) = cpu_to_le32(0); /* bits 63-32 */ |
| 157 | |
| 158 | if ((lines <= NTSC_FIELD_HEIGHT) |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 159 | || (line < (NTSC_FIELD_HEIGHT - 1)) || !(out->is_60hz)) |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 160 | /* to skip the other field line */ |
| 161 | offset += dist_betwn_starts; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 162 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 163 | /* check if we need to enable the FIFO after the first 4 lines |
| 164 | * For the upstream video channel, the risc engine will enable |
| 165 | * the FIFO. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 166 | if (fifo_enable && line == 3) { |
| 167 | *(rp++) = RISC_WRITECR; |
| 168 | *(rp++) = sram_ch->dma_ctl; |
| 169 | *(rp++) = FLD_VID_FIFO_EN; |
| 170 | *(rp++) = 0x00000001; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | return rp; |
| 175 | } |
| 176 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 177 | static int cx25821_risc_buffer_upstream(struct cx25821_channel *chan, |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 178 | struct pci_dev *pci, |
| 179 | unsigned int top_offset, |
| 180 | unsigned int bpl, unsigned int lines) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 181 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 182 | struct cx25821_video_out_data *out = chan->out; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 183 | __le32 *rp; |
| 184 | int fifo_enable = 0; |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 185 | /* get line count for single field */ |
| 186 | int singlefield_lines = lines >> 1; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 187 | int odd_num_lines = singlefield_lines; |
| 188 | int frame = 0; |
| 189 | int frame_size = 0; |
| 190 | int databuf_offset = 0; |
| 191 | int risc_program_size = 0; |
| 192 | int risc_flag = RISC_CNT_RESET; |
| 193 | unsigned int bottom_offset = bpl; |
| 194 | dma_addr_t risc_phys_jump_addr; |
| 195 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 196 | if (out->is_60hz) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 197 | odd_num_lines = singlefield_lines + 1; |
| 198 | risc_program_size = FRAME1_VID_PROG_SIZE; |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 199 | frame_size = (bpl == Y411_LINE_SZ) ? |
| 200 | FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 201 | } else { |
| 202 | risc_program_size = PAL_VID_PROG_SIZE; |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 203 | frame_size = (bpl == Y411_LINE_SZ) ? |
| 204 | FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /* Virtual address of Risc buffer program */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 208 | rp = out->_dma_virt_addr; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 209 | |
| 210 | for (frame = 0; frame < NUM_FRAMES; frame++) { |
| 211 | databuf_offset = frame_size * frame; |
| 212 | |
| 213 | if (UNSET != top_offset) { |
| 214 | fifo_enable = (frame == 0) ? FIFO_ENABLE : FIFO_DISABLE; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 215 | rp = cx25821_risc_field_upstream(chan, rp, |
| 216 | out->_data_buf_phys_addr + |
Leonid V. Fedorenchik | 2c68e93 | 2011-10-22 01:43:47 -0300 | [diff] [blame] | 217 | databuf_offset, top_offset, 0, bpl, |
| 218 | odd_num_lines, fifo_enable, ODD_FIELD); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | fifo_enable = FIFO_DISABLE; |
| 222 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 223 | /* Even Field */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 224 | rp = cx25821_risc_field_upstream(chan, rp, |
| 225 | out->_data_buf_phys_addr + |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 226 | databuf_offset, bottom_offset, |
| 227 | 0x200, bpl, singlefield_lines, |
| 228 | fifo_enable, EVEN_FIELD); |
| 229 | |
| 230 | if (frame == 0) { |
| 231 | risc_flag = RISC_CNT_RESET; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 232 | risc_phys_jump_addr = out->_dma_phys_start_addr + |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 233 | risc_program_size; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 234 | } else { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 235 | risc_phys_jump_addr = out->_dma_phys_start_addr; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 236 | risc_flag = RISC_CNT_INC; |
| 237 | } |
| 238 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 239 | /* Loop to 2ndFrameRISC or to Start of Risc |
| 240 | * program & generate IRQ |
| 241 | */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 242 | *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag); |
| 243 | *(rp++) = cpu_to_le32(risc_phys_jump_addr); |
| 244 | *(rp++) = cpu_to_le32(0); |
| 245 | } |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 250 | void cx25821_stop_upstream_video(struct cx25821_channel *chan) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 251 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 252 | struct cx25821_video_out_data *out = chan->out; |
| 253 | struct cx25821_dev *dev = chan->dev; |
| 254 | const struct sram_channel *sram_ch = chan->sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 255 | u32 tmp = 0; |
| 256 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 257 | if (!out->_is_running) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 258 | pr_info("No video file is currently running so return!\n"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 259 | return; |
| 260 | } |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 261 | /* Disable RISC interrupts */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 262 | tmp = cx_read(sram_ch->int_msk); |
| 263 | cx_write(sram_ch->int_msk, tmp & ~_intr_msk); |
| 264 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 265 | /* Turn OFF risc and fifo enable */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 266 | tmp = cx_read(sram_ch->dma_ctl); |
| 267 | cx_write(sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN)); |
| 268 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 269 | /* Clear data buffer memory */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 270 | if (out->_data_buf_virt_addr) |
| 271 | memset(out->_data_buf_virt_addr, 0, out->_data_buf_size); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 272 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 273 | out->_is_running = 0; |
| 274 | out->_is_first_frame = 0; |
| 275 | out->_frame_count = 0; |
| 276 | out->_file_status = END_OF_FILE; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 277 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 278 | destroy_workqueue(out->_irq_queues); |
| 279 | out->_irq_queues = NULL; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 280 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 281 | kfree(out->_filename); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 282 | |
| 283 | tmp = cx_read(VID_CH_MODE_SEL); |
| 284 | cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00); |
| 285 | } |
| 286 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 287 | void cx25821_free_mem_upstream(struct cx25821_channel *chan) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 288 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 289 | struct cx25821_video_out_data *out = chan->out; |
| 290 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 291 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 292 | if (out->_is_running) |
| 293 | cx25821_stop_upstream_video(chan); |
| 294 | |
| 295 | if (out->_dma_virt_addr) { |
| 296 | pci_free_consistent(dev->pci, out->_risc_size, |
| 297 | out->_dma_virt_addr, out->_dma_phys_addr); |
| 298 | out->_dma_virt_addr = NULL; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 299 | } |
| 300 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 301 | if (out->_data_buf_virt_addr) { |
| 302 | pci_free_consistent(dev->pci, out->_data_buf_size, |
| 303 | out->_data_buf_virt_addr, |
| 304 | out->_data_buf_phys_addr); |
| 305 | out->_data_buf_virt_addr = NULL; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 309 | static int cx25821_get_frame(struct cx25821_channel *chan, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 310 | const struct sram_channel *sram_ch) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 311 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 312 | struct cx25821_video_out_data *out = chan->out; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 313 | struct file *myfile; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 314 | int frame_index_temp = out->_frame_index; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 315 | int i = 0; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 316 | int line_size = (out->_pixel_format == PIXEL_FRMT_411) ? |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 317 | Y411_LINE_SZ : Y422_LINE_SZ; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 318 | int frame_size = 0; |
| 319 | int frame_offset = 0; |
| 320 | ssize_t vfs_read_retval = 0; |
| 321 | char mybuf[line_size]; |
| 322 | loff_t file_offset; |
| 323 | loff_t pos; |
| 324 | mm_segment_t old_fs; |
| 325 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 326 | if (out->_file_status == END_OF_FILE) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 327 | return 0; |
| 328 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 329 | if (out->is_60hz) |
Leonid V. Fedorenchik | 16f0fda | 2011-10-22 01:43:46 -0300 | [diff] [blame] | 330 | frame_size = (line_size == Y411_LINE_SZ) ? |
| 331 | FRAME_SIZE_NTSC_Y411 : FRAME_SIZE_NTSC_Y422; |
| 332 | else |
| 333 | frame_size = (line_size == Y411_LINE_SZ) ? |
| 334 | FRAME_SIZE_PAL_Y411 : FRAME_SIZE_PAL_Y422; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 335 | |
| 336 | frame_offset = (frame_index_temp > 0) ? frame_size : 0; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 337 | file_offset = out->_frame_count * frame_size; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 338 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 339 | myfile = filp_open(out->_filename, O_RDONLY | O_LARGEFILE, 0); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 340 | |
| 341 | if (IS_ERR(myfile)) { |
| 342 | const int open_errno = -PTR_ERR(myfile); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 343 | pr_err("%s(): ERROR opening file(%s) with errno = %d!\n", |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 344 | __func__, out->_filename, open_errno); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 345 | return PTR_ERR(myfile); |
| 346 | } else { |
| 347 | if (!(myfile->f_op)) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 348 | pr_err("%s(): File has no file operations registered!\n", |
| 349 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 350 | filp_close(myfile, NULL); |
| 351 | return -EIO; |
| 352 | } |
| 353 | |
| 354 | if (!myfile->f_op->read) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 355 | pr_err("%s(): File has no READ operations registered!\n", |
| 356 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 357 | filp_close(myfile, NULL); |
| 358 | return -EIO; |
| 359 | } |
| 360 | |
| 361 | pos = myfile->f_pos; |
| 362 | old_fs = get_fs(); |
| 363 | set_fs(KERNEL_DS); |
| 364 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 365 | for (i = 0; i < out->_lines_count; i++) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 366 | pos = file_offset; |
| 367 | |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 368 | vfs_read_retval = vfs_read(myfile, mybuf, line_size, |
| 369 | &pos); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 370 | |
| 371 | if (vfs_read_retval > 0 && vfs_read_retval == line_size |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 372 | && out->_data_buf_virt_addr != NULL) { |
| 373 | memcpy((void *)(out->_data_buf_virt_addr + |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 374 | frame_offset / 4), mybuf, |
| 375 | vfs_read_retval); |
| 376 | } |
| 377 | |
| 378 | file_offset += vfs_read_retval; |
| 379 | frame_offset += vfs_read_retval; |
| 380 | |
| 381 | if (vfs_read_retval < line_size) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 382 | pr_info("Done: exit %s() since no more bytes to read from Video file\n", |
| 383 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 384 | break; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | if (i > 0) |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 389 | out->_frame_count++; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 390 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 391 | out->_file_status = (vfs_read_retval == line_size) ? |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 392 | IN_PROGRESS : END_OF_FILE; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 393 | |
| 394 | set_fs(old_fs); |
| 395 | filp_close(myfile, NULL); |
| 396 | } |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static void cx25821_vidups_handler(struct work_struct *work) |
| 402 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 403 | struct cx25821_video_out_data *out = |
| 404 | container_of(work, struct cx25821_video_out_data, _irq_work_entry); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 405 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 406 | cx25821_get_frame(out->chan, out->chan->sram_channels); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 407 | } |
| 408 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 409 | static int cx25821_openfile(struct cx25821_channel *chan, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 410 | const struct sram_channel *sram_ch) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 411 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 412 | struct cx25821_video_out_data *out = chan->out; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 413 | struct file *myfile; |
| 414 | int i = 0, j = 0; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 415 | int line_size = (out->_pixel_format == PIXEL_FRMT_411) ? |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 416 | Y411_LINE_SZ : Y422_LINE_SZ; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 417 | ssize_t vfs_read_retval = 0; |
| 418 | char mybuf[line_size]; |
| 419 | loff_t pos; |
| 420 | loff_t offset = (unsigned long)0; |
| 421 | mm_segment_t old_fs; |
| 422 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 423 | myfile = filp_open(out->_filename, O_RDONLY | O_LARGEFILE, 0); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 424 | |
| 425 | if (IS_ERR(myfile)) { |
| 426 | const int open_errno = -PTR_ERR(myfile); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 427 | pr_err("%s(): ERROR opening file(%s) with errno = %d!\n", |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 428 | __func__, out->_filename, open_errno); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 429 | return PTR_ERR(myfile); |
| 430 | } else { |
| 431 | if (!(myfile->f_op)) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 432 | pr_err("%s(): File has no file operations registered!\n", |
| 433 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 434 | filp_close(myfile, NULL); |
| 435 | return -EIO; |
| 436 | } |
| 437 | |
| 438 | if (!myfile->f_op->read) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 439 | pr_err("%s(): File has no READ operations registered! Returning\n", |
| 440 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 441 | filp_close(myfile, NULL); |
| 442 | return -EIO; |
| 443 | } |
| 444 | |
| 445 | pos = myfile->f_pos; |
| 446 | old_fs = get_fs(); |
| 447 | set_fs(KERNEL_DS); |
| 448 | |
| 449 | for (j = 0; j < NUM_FRAMES; j++) { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 450 | for (i = 0; i < out->_lines_count; i++) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 451 | pos = offset; |
| 452 | |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 453 | vfs_read_retval = vfs_read(myfile, mybuf, |
| 454 | line_size, &pos); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 455 | |
| 456 | if (vfs_read_retval > 0 |
| 457 | && vfs_read_retval == line_size |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 458 | && out->_data_buf_virt_addr != NULL) { |
| 459 | memcpy((void *)(out-> |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 460 | _data_buf_virt_addr + |
| 461 | offset / 4), mybuf, |
| 462 | vfs_read_retval); |
| 463 | } |
| 464 | |
| 465 | offset += vfs_read_retval; |
| 466 | |
| 467 | if (vfs_read_retval < line_size) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 468 | pr_info("Done: exit %s() since no more bytes to read from Video file\n", |
| 469 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 470 | break; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if (i > 0) |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 475 | out->_frame_count++; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 476 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 477 | if (vfs_read_retval < line_size) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 478 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 479 | } |
| 480 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 481 | out->_file_status = (vfs_read_retval == line_size) ? |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 482 | IN_PROGRESS : END_OF_FILE; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 483 | |
| 484 | set_fs(old_fs); |
| 485 | myfile->f_pos = 0; |
| 486 | filp_close(myfile, NULL); |
| 487 | } |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 492 | static int cx25821_upstream_buffer_prepare(struct cx25821_channel *chan, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 493 | const struct sram_channel *sram_ch, |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 494 | int bpl) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 495 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 496 | struct cx25821_video_out_data *out = chan->out; |
| 497 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 498 | int ret = 0; |
| 499 | dma_addr_t dma_addr; |
| 500 | dma_addr_t data_dma_addr; |
| 501 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 502 | if (out->_dma_virt_addr != NULL) |
| 503 | pci_free_consistent(dev->pci, out->upstream_riscbuf_size, |
| 504 | out->_dma_virt_addr, out->_dma_phys_addr); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 505 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 506 | out->_dma_virt_addr = pci_alloc_consistent(dev->pci, |
| 507 | out->upstream_riscbuf_size, &dma_addr); |
| 508 | out->_dma_virt_start_addr = out->_dma_virt_addr; |
| 509 | out->_dma_phys_start_addr = dma_addr; |
| 510 | out->_dma_phys_addr = dma_addr; |
| 511 | out->_risc_size = out->upstream_riscbuf_size; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 512 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 513 | if (!out->_dma_virt_addr) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 514 | pr_err("FAILED to allocate memory for Risc buffer! Returning\n"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 515 | return -ENOMEM; |
| 516 | } |
| 517 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 518 | /* Clear memory at address */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 519 | memset(out->_dma_virt_addr, 0, out->_risc_size); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 520 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 521 | if (out->_data_buf_virt_addr != NULL) |
| 522 | pci_free_consistent(dev->pci, out->upstream_databuf_size, |
| 523 | out->_data_buf_virt_addr, |
| 524 | out->_data_buf_phys_addr); |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 525 | /* For Video Data buffer allocation */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 526 | out->_data_buf_virt_addr = pci_alloc_consistent(dev->pci, |
| 527 | out->upstream_databuf_size, &data_dma_addr); |
| 528 | out->_data_buf_phys_addr = data_dma_addr; |
| 529 | out->_data_buf_size = out->upstream_databuf_size; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 530 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 531 | if (!out->_data_buf_virt_addr) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 532 | pr_err("FAILED to allocate memory for data buffer! Returning\n"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 533 | return -ENOMEM; |
| 534 | } |
| 535 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 536 | /* Clear memory at address */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 537 | memset(out->_data_buf_virt_addr, 0, out->_data_buf_size); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 538 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 539 | ret = cx25821_openfile(chan, sram_ch); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 540 | if (ret < 0) |
| 541 | return ret; |
| 542 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 543 | /* Create RISC programs */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 544 | ret = cx25821_risc_buffer_upstream(chan, dev->pci, 0, bpl, |
| 545 | out->_lines_count); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 546 | if (ret < 0) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 547 | pr_info("Failed creating Video Upstream Risc programs!\n"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 548 | goto error; |
| 549 | } |
| 550 | |
| 551 | return 0; |
| 552 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 553 | error: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 554 | return ret; |
| 555 | } |
| 556 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 557 | static int cx25821_video_upstream_irq(struct cx25821_channel *chan, u32 status) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 558 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 559 | struct cx25821_video_out_data *out = chan->out; |
| 560 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 561 | u32 int_msk_tmp; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 562 | const struct sram_channel *channel = chan->sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 563 | int singlefield_lines = NTSC_FIELD_HEIGHT; |
| 564 | int line_size_in_bytes = Y422_LINE_SZ; |
| 565 | int odd_risc_prog_size = 0; |
| 566 | dma_addr_t risc_phys_jump_addr; |
| 567 | __le32 *rp; |
| 568 | |
| 569 | if (status & FLD_VID_SRC_RISC1) { |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 570 | /* We should only process one program per call */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 571 | u32 prog_cnt = cx_read(channel->gpcnt); |
| 572 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 573 | /* Since we've identified our IRQ, clear our bits from the |
| 574 | * interrupt mask and interrupt status registers */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 575 | int_msk_tmp = cx_read(channel->int_msk); |
| 576 | cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk); |
| 577 | cx_write(channel->int_stat, _intr_msk); |
| 578 | |
| 579 | spin_lock(&dev->slock); |
| 580 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 581 | out->_frame_index = prog_cnt; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 582 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 583 | queue_work(out->_irq_queues, &out->_irq_work_entry); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 584 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 585 | if (out->_is_first_frame) { |
| 586 | out->_is_first_frame = 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 587 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 588 | if (out->is_60hz) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 589 | singlefield_lines += 1; |
| 590 | odd_risc_prog_size = ODD_FLD_NTSC_PROG_SIZE; |
| 591 | } else { |
| 592 | singlefield_lines = PAL_FIELD_HEIGHT; |
| 593 | odd_risc_prog_size = ODD_FLD_PAL_PROG_SIZE; |
| 594 | } |
| 595 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 596 | if (out->_dma_virt_start_addr != NULL) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 597 | line_size_in_bytes = |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 598 | (out->_pixel_format == |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 599 | PIXEL_FRMT_411) ? Y411_LINE_SZ : |
| 600 | Y422_LINE_SZ; |
| 601 | risc_phys_jump_addr = |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 602 | out->_dma_phys_start_addr + |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 603 | odd_risc_prog_size; |
| 604 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 605 | rp = cx25821_update_riscprogram(chan, |
| 606 | out->_dma_virt_start_addr, TOP_OFFSET, |
Leonid V. Fedorenchik | 2b2d039 | 2011-09-02 11:55:46 +0800 | [diff] [blame] | 607 | line_size_in_bytes, 0x0, |
| 608 | singlefield_lines, FIFO_DISABLE, |
| 609 | ODD_FIELD); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 610 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 611 | /* Jump to Even Risc program of 1st Frame */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 612 | *(rp++) = cpu_to_le32(RISC_JUMP); |
| 613 | *(rp++) = cpu_to_le32(risc_phys_jump_addr); |
| 614 | *(rp++) = cpu_to_le32(0); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | spin_unlock(&dev->slock); |
| 619 | } else { |
| 620 | if (status & FLD_VID_SRC_UF) |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 621 | pr_err("%s(): Video Received Underflow Error Interrupt!\n", |
| 622 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 623 | |
| 624 | if (status & FLD_VID_SRC_SYNC) |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 625 | pr_err("%s(): Video Received Sync Error Interrupt!\n", |
| 626 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 627 | |
| 628 | if (status & FLD_VID_SRC_OPC_ERR) |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 629 | pr_err("%s(): Video Received OpCode Error Interrupt!\n", |
| 630 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 631 | } |
| 632 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 633 | if (out->_file_status == END_OF_FILE) { |
| 634 | pr_err("EOF Channel 1 Framecount = %d\n", out->_frame_count); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 635 | return -1; |
| 636 | } |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 637 | /* ElSE, set the interrupt mask register, re-enable irq. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 638 | int_msk_tmp = cx_read(channel->int_msk); |
| 639 | cx_write(channel->int_msk, int_msk_tmp |= _intr_msk); |
| 640 | |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | static irqreturn_t cx25821_upstream_irq(int irq, void *dev_id) |
| 645 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 646 | struct cx25821_channel *chan = dev_id; |
| 647 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | 30fdf03 | 2012-04-20 06:26:19 -0300 | [diff] [blame] | 648 | u32 vid_status; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 649 | int handled = 0; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 650 | const struct sram_channel *sram_ch; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 651 | |
| 652 | if (!dev) |
| 653 | return -1; |
| 654 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 655 | sram_ch = chan->sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 656 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 657 | vid_status = cx_read(sram_ch->int_stat); |
| 658 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 659 | /* Only deal with our interrupt */ |
Leonid V. Fedorenchik | 16f0fda | 2011-10-22 01:43:46 -0300 | [diff] [blame] | 660 | if (vid_status) |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 661 | handled = cx25821_video_upstream_irq(chan, vid_status); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 662 | |
| 663 | return IRQ_RETVAL(handled); |
| 664 | } |
| 665 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 666 | static void cx25821_set_pixelengine(struct cx25821_channel *chan, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 667 | const struct sram_channel *ch, |
Mauro Carvalho Chehab | dafc456 | 2012-10-27 12:42:59 -0300 | [diff] [blame] | 668 | int pix_format) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 669 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 670 | struct cx25821_video_out_data *out = chan->out; |
| 671 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 672 | int width = WIDTH_D1; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 673 | int height = out->_lines_count; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 674 | int num_lines, odd_num_lines; |
| 675 | u32 value; |
| 676 | int vip_mode = OUTPUT_FRMT_656; |
| 677 | |
| 678 | value = ((pix_format & 0x3) << 12) | (vip_mode & 0x7); |
| 679 | value &= 0xFFFFFFEF; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 680 | value |= out->is_60hz ? 0 : 0x10; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 681 | cx_write(ch->vid_fmt_ctl, value); |
| 682 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 683 | /* set number of active pixels in each line. |
| 684 | * Default is 720 pixels in both NTSC and PAL format */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 685 | cx_write(ch->vid_active_ctl1, width); |
| 686 | |
| 687 | num_lines = (height / 2) & 0x3FF; |
| 688 | odd_num_lines = num_lines; |
| 689 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 690 | if (out->is_60hz) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 691 | odd_num_lines += 1; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 692 | |
| 693 | value = (num_lines << 16) | odd_num_lines; |
| 694 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 695 | /* set number of active lines in field 0 (top) and field 1 (bottom) */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 696 | cx_write(ch->vid_active_ctl2, value); |
| 697 | |
| 698 | cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3); |
| 699 | } |
| 700 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 701 | static int cx25821_start_video_dma_upstream(struct cx25821_channel *chan, |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 702 | const struct sram_channel *sram_ch) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 703 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 704 | struct cx25821_video_out_data *out = chan->out; |
| 705 | struct cx25821_dev *dev = chan->dev; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 706 | u32 tmp = 0; |
| 707 | int err = 0; |
| 708 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 709 | /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for |
| 710 | * channel A-C |
| 711 | */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 712 | tmp = cx_read(VID_CH_MODE_SEL); |
| 713 | cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); |
| 714 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 715 | /* Set the physical start address of the RISC program in the initial |
| 716 | * program counter(IPC) member of the cmds. |
| 717 | */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 718 | cx_write(sram_ch->cmds_start + 0, out->_dma_phys_addr); |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 719 | /* Risc IPC High 64 bits 63-32 */ |
| 720 | cx_write(sram_ch->cmds_start + 4, 0); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 721 | |
| 722 | /* reset counter */ |
| 723 | cx_write(sram_ch->gpcnt_ctl, 3); |
| 724 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 725 | /* Clear our bits from the interrupt status register. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 726 | cx_write(sram_ch->int_stat, _intr_msk); |
| 727 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 728 | /* Set the interrupt mask register, enable irq. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 729 | cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit)); |
| 730 | tmp = cx_read(sram_ch->int_msk); |
| 731 | cx_write(sram_ch->int_msk, tmp |= _intr_msk); |
| 732 | |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 733 | err = request_irq(dev->pci->irq, cx25821_upstream_irq, |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 734 | IRQF_SHARED, dev->name, chan); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 735 | if (err < 0) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 736 | pr_err("%s: can't get upstream IRQ %d\n", |
| 737 | dev->name, dev->pci->irq); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 738 | goto fail_irq; |
| 739 | } |
| 740 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 741 | /* Start the DMA engine */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 742 | tmp = cx_read(sram_ch->dma_ctl); |
| 743 | cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN); |
| 744 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 745 | out->_is_running = 1; |
| 746 | out->_is_first_frame = 1; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 747 | |
| 748 | return 0; |
| 749 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 750 | fail_irq: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 751 | cx25821_dev_unregister(dev); |
| 752 | return err; |
| 753 | } |
| 754 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 755 | int cx25821_vidupstream_init(struct cx25821_channel *chan, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 756 | int pixel_format) |
| 757 | { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 758 | struct cx25821_video_out_data *out = chan->out; |
| 759 | struct cx25821_dev *dev = chan->dev; |
Hans Verkuil | bfef0d3 | 2013-04-13 06:28:54 -0300 | [diff] [blame] | 760 | const struct sram_channel *sram_ch; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 761 | u32 tmp; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 762 | int err = 0; |
| 763 | int data_frame_size = 0; |
| 764 | int risc_buffer_size = 0; |
| 765 | int str_length = 0; |
| 766 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 767 | if (out->_is_running) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 768 | pr_info("Video Channel is still running so return!\n"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 769 | return 0; |
| 770 | } |
| 771 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 772 | sram_ch = chan->sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 773 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 774 | INIT_WORK(&out->_irq_work_entry, cx25821_vidups_handler); |
| 775 | out->_irq_queues = create_singlethread_workqueue("cx25821_workqueue"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 776 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 777 | if (!out->_irq_queues) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 778 | pr_err("create_singlethread_workqueue() for Video FAILED!\n"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 779 | return -ENOMEM; |
| 780 | } |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 781 | /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for |
| 782 | * channel A-C |
| 783 | */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 784 | tmp = cx_read(VID_CH_MODE_SEL); |
| 785 | cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); |
| 786 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 787 | out->_is_running = 0; |
| 788 | out->_frame_count = 0; |
| 789 | out->_file_status = RESET_STATUS; |
| 790 | out->_lines_count = out->is_60hz ? 480 : 576; |
| 791 | out->_pixel_format = pixel_format; |
| 792 | out->_line_size = (out->_pixel_format == PIXEL_FRMT_422) ? |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 793 | (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2; |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 794 | data_frame_size = out->is_60hz ? NTSC_DATA_BUF_SZ : PAL_DATA_BUF_SZ; |
| 795 | risc_buffer_size = out->is_60hz ? |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 796 | NTSC_RISC_BUF_SIZE : PAL_RISC_BUF_SIZE; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 797 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 798 | if (out->input_filename) { |
| 799 | str_length = strlen(out->input_filename); |
| 800 | out->_filename = kmemdup(out->input_filename, str_length + 1, |
Thomas Meyer | 0ceaec1 | 2011-11-17 19:12:18 -0300 | [diff] [blame] | 801 | GFP_KERNEL); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 802 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 803 | if (!out->_filename) { |
Peter Senna Tschudin | 216f393 | 2012-09-06 11:23:56 -0300 | [diff] [blame] | 804 | err = -ENOENT; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 805 | goto error; |
Peter Senna Tschudin | 216f393 | 2012-09-06 11:23:56 -0300 | [diff] [blame] | 806 | } |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 807 | } else { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 808 | str_length = strlen(out->_defaultname); |
| 809 | out->_filename = kmemdup(out->_defaultname, str_length + 1, |
Thomas Meyer | 0ceaec1 | 2011-11-17 19:12:18 -0300 | [diff] [blame] | 810 | GFP_KERNEL); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 811 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 812 | if (!out->_filename) { |
Peter Senna Tschudin | 216f393 | 2012-09-06 11:23:56 -0300 | [diff] [blame] | 813 | err = -ENOENT; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 814 | goto error; |
Peter Senna Tschudin | 216f393 | 2012-09-06 11:23:56 -0300 | [diff] [blame] | 815 | } |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 816 | } |
| 817 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 818 | /* Default if filename is empty string */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 819 | if (strcmp(out->_filename, "") == 0) { |
| 820 | if (out->is_60hz) { |
| 821 | out->_filename = |
| 822 | (out->_pixel_format == PIXEL_FRMT_411) ? |
Leonid V. Fedorenchik | 2c68e93 | 2011-10-22 01:43:47 -0300 | [diff] [blame] | 823 | "/root/vid411.yuv" : "/root/vidtest.yuv"; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 824 | } else { |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 825 | out->_filename = |
| 826 | (out->_pixel_format == PIXEL_FRMT_411) ? |
Leonid V. Fedorenchik | 2c68e93 | 2011-10-22 01:43:47 -0300 | [diff] [blame] | 827 | "/root/pal411.yuv" : "/root/pal422.yuv"; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 831 | out->_is_running = 0; |
| 832 | out->_frame_count = 0; |
| 833 | out->_file_status = RESET_STATUS; |
| 834 | out->_lines_count = out->is_60hz ? 480 : 576; |
| 835 | out->_pixel_format = pixel_format; |
| 836 | out->_line_size = (out->_pixel_format == PIXEL_FRMT_422) ? |
Leonid V. Fedorenchik | 8eb1fdf | 2011-10-22 01:43:48 -0300 | [diff] [blame] | 837 | (WIDTH_D1 * 2) : (WIDTH_D1 * 3) / 2; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 838 | |
Peter Senna Tschudin | 216f393 | 2012-09-06 11:23:56 -0300 | [diff] [blame] | 839 | err = cx25821_sram_channel_setup_upstream(dev, sram_ch, |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 840 | out->_line_size, 0); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 841 | |
| 842 | /* setup fifo + format */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 843 | cx25821_set_pixelengine(chan, sram_ch, out->_pixel_format); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 844 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 845 | out->upstream_riscbuf_size = risc_buffer_size * 2; |
| 846 | out->upstream_databuf_size = data_frame_size * 2; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 847 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 848 | /* Allocating buffers and prepare RISC program */ |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 849 | err = cx25821_upstream_buffer_prepare(chan, sram_ch, out->_line_size); |
Peter Senna Tschudin | 216f393 | 2012-09-06 11:23:56 -0300 | [diff] [blame] | 850 | if (err < 0) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 851 | pr_err("%s: Failed to set up Video upstream buffers!\n", |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 852 | dev->name); |
| 853 | goto error; |
| 854 | } |
| 855 | |
Hans Verkuil | 7087d31 | 2013-04-14 12:10:32 -0300 | [diff] [blame^] | 856 | cx25821_start_video_dma_upstream(chan, sram_ch); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 857 | |
| 858 | return 0; |
| 859 | |
Olimpiu Pascariu | 1099123 | 2010-04-06 02:09:00 -0300 | [diff] [blame] | 860 | error: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 861 | cx25821_dev_unregister(dev); |
| 862 | |
| 863 | return err; |
| 864 | } |