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